Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
Merge branch 'rc'
Browse files Browse the repository at this point in the history
  • Loading branch information
fyockm committed Jun 4, 2018
2 parents 8607ba7 + 12e78a6 commit 5efd8ab
Show file tree
Hide file tree
Showing 68 changed files with 3,200 additions and 1,821 deletions.
10 changes: 0 additions & 10 deletions .babelrc

This file was deleted.

3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:6.10
- image: node:carbon

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
Expand All @@ -34,5 +34,6 @@ jobs:
key: v1-dependencies-{{ checksum "package.json" }}

# run tests!
- run: yarn run lint
- run: yarn test
- run: ./test/bundle_test.sh
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
.idea
.DS_Store
.nyc_output
server/config.json
Expand All @@ -10,3 +11,6 @@ dist/*
tags
TAGS
data.json
*.swp
yarn-error.log
secrets
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ Update the configuration file under `./server/config.json`:

```json
{
"EXTENSION_SECRET": "mysecret",
"AUTH0_DOMAIN": "me.auth0.com",
"AUTH0_CLIENT_ID": "myclientid",
"AUTH0_CLIENT_SECRET": "myclientsecret",
"WT_URL": "http://localhost:3000"
"EXTENSION_SECRET": "mysecret",
"AUTH0_DOMAIN": "me.auth0.com",
"AUTH0_CLIENT_ID": "myclientid",
"AUTH0_CLIENT_SECRET": "myclientsecret",
"WT_URL": "http://localhost:3000",
"AUTH0_CALLBACK_URL": "http://localhost:3000/callback"
}
```

Expand Down
6 changes: 3 additions & 3 deletions api/admin/get_index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import template from '../../templates/server/admin';
import config from '../../lib/config';
import stylesheet from '../../lib/stylesheet';
const template = require('../../templates/server/admin');
const config = require('../../lib/config');
const stylesheet = require('../../lib/stylesheet');

module.exports = () => ({
method: 'GET',
Expand Down
6 changes: 3 additions & 3 deletions api/admin/get_locale_index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import template from '../../templates/server/locale';
import config from '../../lib/config';
import stylesheet from '../../lib/stylesheet';
const template = require('../../templates/server/locale');
const config = require('../../lib/config');
const stylesheet = require('../../lib/stylesheet');

module.exports = () => ({
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion api/admin/get_locales.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-underscore-dangle */

import { getLocales } from '../../lib/storage';
const { getLocales } = require('../../lib/storage');

module.exports = () => ({
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion api/admin/get_settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-underscore-dangle */

import { getSettings, getLocales } from '../../lib/storage';
const { getSettings, getLocales } = require('../../lib/storage');

module.exports = () => ({
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion api/admin/get_user_details.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import avatarUrl from '../../lib/avatar';
const avatarUrl = require('../../lib/avatar');

module.exports = () => ({
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion api/admin/put_locales.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-useless-escape */

import { setLocales } from '../../lib/storage';
const { setLocales } = require('../../lib/storage');

module.exports = () => ({
method: 'PUT',
Expand Down
4 changes: 2 additions & 2 deletions api/admin/put_settings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-useless-escape */

import Joi from 'joi';
import { setSettings } from '../../lib/storage';
const Joi = require('joi');
const { setSettings } = require('../../lib/storage');

const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
const colorRegex = /^#[A-Fa-f0-9]{6}/;
Expand Down
24 changes: 13 additions & 11 deletions api/get_index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { decode } from 'jsonwebtoken';
import config from '../lib/config';
import findUsersByEmail from '../lib/findUsersByEmail';
import indexTemplate from '../templates/index';
import logger from '../lib/logger';
import stylesheet from '../lib/stylesheet';
import getIdentityProviderPublicName from '../lib/idProviders';
import humanizeArray from '../lib/humanize';
import resolveLocale from '../lib/locale';
import { getSettings } from '../lib/storage';
const { decode } = require('jsonwebtoken');
const config = require('../lib/config');
const findUsersByEmail = require('../lib/findUsersByEmail');
const indexTemplate = require('../templates/index');
const logger = require('../lib/logger');
const stylesheet = require('../lib/stylesheet');
const getIdentityProviderPublicName = require('../lib/idProviders');
const humanizeArray = require('../lib/humanize');
const { resolveLocale } = require('../lib/locale');
const { getSettings } = require('../lib/storage');

const decodeToken = token =>
new Promise((resolve, reject) => {
Expand Down Expand Up @@ -53,7 +53,8 @@ module.exports = () => ({
fetchUsersFromToken(token)
.then(({ currentUser, matchingUsers }) => {
getSettings().then((settings) => {
resolveLocale(settings.locale).then((t) => {
const locale = matchingUsers[0].user_metadata.locale || settings.locale;
resolveLocale(locale).then((t) => {
const rawIdentities = matchingUsers.length > 0 ? matchingUsers[0].identities : [];
const identities = rawIdentities
.map(id => id.provider)
Expand All @@ -67,6 +68,7 @@ module.exports = () => ({
currentUser,
matchingUsers,
customCSSTag,
locale,
identities: humanizedIdentities
})
);
Expand Down
2 changes: 1 addition & 1 deletion api/get_meta.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import metadata from '../webtask.json';
const metadata = require('../webtask.json');

module.exports = () => ({
method: 'GET',
Expand Down
6 changes: 3 additions & 3 deletions api/hooks/delete_uninstall.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { uninstall } from '../../modifyRule';
import config from '../../lib/config';
import logger from '../../lib/logger';
const { uninstall } = require('../../modifyRule');
const config = require('../../lib/config');
const logger = require('../../lib/logger');

module.exports = server => ({
method: 'DELETE',
Expand Down
6 changes: 3 additions & 3 deletions api/hooks/post_install.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { install } from '../../modifyRule';
import config from '../../lib/config';
import logger from '../../lib/logger';
const { install } = require('../../modifyRule');
const config = require('../../lib/config');
const logger = require('../../lib/logger');

module.exports = server => ({
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion build/bundle.js

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
require('babel-register')();

const gulp = require('gulp');
const util = require('gulp-util');
const ngrok = require('ngrok');
const nodemon = require('gulp-nodemon');
const { install } = require('./modifyRule');
const managementAdapter = require('./lib/managementAdapter');

const ManagementClientAdapter = managementAdapter.default;
const { getCurrentConfig } = managementAdapter;
const { ManagementClientAdapter, getCurrentConfig } = managementAdapter;

gulp.task('run', () => {
ngrok.connect(3001, (ngrokError, url) => {
ngrok.connect(3000, (ngrokError, url) => {
if (ngrokError) {
throw ngrokError;
}
Expand Down
3 changes: 0 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ const nconf = require('nconf');
const path = require('path');
const logger = require('./lib/logger');

// Load babel
require('./lib/babel')();

nconf
.argv()
.env()
Expand Down
7 changes: 3 additions & 4 deletions integration/index_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'babel-polyfill';
import puppeteer from 'puppeteer';
import { expect } from 'chai';
import { deleteTestUsers, usersWithSameEmailCount, wait, buildQueryString } from './utils';
const puppeteer = require('puppeteer');
const { expect } = require('chai');
const { deleteTestUsers, usersWithSameEmailCount, wait, buildQueryString } = require('./utils');

const SAMPLE_APP_BASE = 'http://localhost:3000';

Expand Down
22 changes: 15 additions & 7 deletions integration/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import { ManagementClient } from 'auth0';
const fs = require('fs');
const path = require('path');
const { ManagementClient } = require('auth0');

const configFileContent = fs.readFileSync(
path.join(__dirname, '../server/config.test.json'),
Expand All @@ -19,14 +19,14 @@ const mgmtApi = new ManagementClient({
* Waits X seconds and resolves.
* @param {number} secs
*/
export const wait = (secs = 1) => new Promise(cont => setTimeout(cont, secs * 1000));
const wait = (secs = 1) => new Promise(cont => setTimeout(cont, secs * 1000));

/**
* Looks up for the test-created users and
* removes them from the tenant.
* @param {string} email
*/
export const deleteTestUsers = email =>
const deleteTestUsers = email =>
new Promise((resolve, reject) => {
mgmtApi.getUsers({ q: `email:"${email}"` }, (err, users) => {
if (err) return reject(err);
Expand All @@ -52,7 +52,7 @@ export const deleteTestUsers = email =>
* and returns the count of them.
* @param {string} email
*/
export const usersWithSameEmailCount = email =>
const usersWithSameEmailCount = email =>
new Promise((resolve, reject) => {
mgmtApi.getUsers({ q: `email:"${email}"` }, (err, users) => {
if (err) return reject(err);
Expand All @@ -66,7 +66,7 @@ export const usersWithSameEmailCount = email =>
* from an object with the parameters
* @param {object} params
*/
export const buildQueryString = ({
const buildQueryString = ({
childToken = '',
clientId = '',
redirectUri = '',
Expand All @@ -79,3 +79,11 @@ export const buildQueryString = ({
state = ''
}) =>
`/?child_token=${childToken}&client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=${responseType}&auth0Client=${auth0Client}&original_state=${originalState}&nonce=${nonce}&error_type=${errorType}&state=${state}`;

module.exports = {
wait,
deleteTestUsers,
usersWithSameEmailCount,
buildQueryString
};

10 changes: 5 additions & 5 deletions lib/api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { managementApi } from 'auth0-extension-tools';
import request from 'request';
import config from './config';
import logger from '../lib/logger';
const { managementApi } = require('auth0-extension-tools');
const request = require('request');
const config = require('./config');
const logger = require('../lib/logger');

// Memoized because config unavailable at this point
const urlHelper = {
Expand Down Expand Up @@ -53,4 +53,4 @@ const apiCall = ({ path, ...options } = {}) =>
})
);

export default apiCall;
module.exports = apiCall;
4 changes: 2 additions & 2 deletions lib/avatar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import crypto from 'crypto';
const crypto = require('crypto');

const avatarUrl = (email) => {
const hashedEmail = crypto.createHash('md5').update(email).digest('hex');
Expand All @@ -7,4 +7,4 @@ const avatarUrl = (email) => {
return `https://s.gravatar.com/avatar/${hashedEmail}?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2F${letters}.png`;
};

export default avatarUrl;
module.exports = avatarUrl;
9 changes: 0 additions & 9 deletions lib/babel.js

This file was deleted.

4 changes: 2 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { config } from 'auth0-extension-tools';
const { config } = require('auth0-extension-tools');

export default config();
module.exports = config();
4 changes: 2 additions & 2 deletions lib/findUsersByEmail.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import apiCall from './api';
const apiCall = require('./api');

const findUsersByEmail = email =>
apiCall({
path: 'users-by-email',
qs: { email }
});

export default findUsersByEmail;
module.exports = findUsersByEmail;
6 changes: 3 additions & 3 deletions lib/humanize.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

export default function humanizeArray(items, beforeLast = 'and', oxfordComma = '') {
module.exports = function humanizeArray(items, beforeLast = 'and', oxfordComma = '') {
const ensuredItems = items ? [...items] : [];
if (items.length <= 1) return ensuredItems.join('');
if (items.length === 2) return items.join(` ${beforeLast} `);

const lastItem = ensuredItems.pop();

return ensuredItems.join(', ') + `${oxfordComma} ${beforeLast} ${lastItem}`;
}
return `${ensuredItems.join(', ')}${oxfordComma} ${beforeLast} ${lastItem}`;
};
6 changes: 3 additions & 3 deletions lib/idProviders.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const providers = {
'Username-Password-Authentication': 'Username and Password',
auth0: 'Auth0',
'google-oauth2': 'Google',
facebook: 'Facebook',
windowslive: 'Microsoft',
Expand Down Expand Up @@ -42,8 +42,8 @@ const providers = {
email: 'E-mail Code'
};

export default function getIdentityProviderPublicName(slug) {
module.exports = function getIdentityProviderPublicName(slug) {
const provider = providers[slug];

return typeof provider !== 'undefined' ? provider : slug;
}
};
Loading

0 comments on commit 5efd8ab

Please sign in to comment.