diff --git a/.babelrc b/.babelrc index bf56b662..b58808be 100644 --- a/.babelrc +++ b/.babelrc @@ -1,19 +1,10 @@ { - "presets": [ - "es2017", - "es2016", - "es2015" - ], + "presets": ["es2017", "es2016", "es2015"], "env": { "development": { "presets": [] } }, - "plugins": [ - "transform-runtime", - "transform-object-rest-spread" - ], - "ignore": [ - "./node_modules/**/*.js" - ] + "plugins": ["transform-runtime", "transform-object-rest-spread"], + "ignore": ["./node_modules/**/*.js"] } diff --git a/.eslintignore b/.eslintignore index d205a34a..4f3a4ff9 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,6 @@ node_modules/** -sample-app/** \ No newline at end of file +integration/** +sample-app/** +build/** +test/** +dist/** \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index d5821378..a1f0b30a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,7 +7,8 @@ "mocha": true }, "rules": { - "jsx-a11y/href-no-hash": "off" + "jsx-a11y/href-no-hash": "off", + "import/no-extraneous-dependencies": "off" }, "plugins": [] } diff --git a/api/admin/get_index.js b/api/admin/get_index.js index e790a43b..a83b71b0 100644 --- a/api/admin/get_index.js +++ b/api/admin/get_index.js @@ -1,6 +1,3 @@ -import tools from 'auth0-extension-tools'; -import config from '../../lib/config'; - module.exports = () => ({ method: 'GET', path: '/admin', diff --git a/api/admin/get_settings.js b/api/admin/get_settings.js index c0783290..0605f838 100644 --- a/api/admin/get_settings.js +++ b/api/admin/get_settings.js @@ -1,3 +1,5 @@ +/* eslint-disable no-underscore-dangle */ + import { getSettings } from '../../lib/storage'; import { allLocales as locales } from '../../lib/locale'; @@ -8,8 +10,11 @@ module.exports = () => ({ }, path: '/admin/settings', handler: (req, reply) => { - const availableLocales = Object.keys(locales).map(locale => ({ code: locale, name: locales[locale]._name })); - + const availableLocales = Object.keys(locales).map(locale => ({ + code: locale, + name: locales[locale]._name + })); + getSettings().then((settings) => { reply({ ...settings, availableLocales }); }); diff --git a/api/admin/get_user_details.js b/api/admin/get_user_details.js index a80ab8ca..537abde9 100644 --- a/api/admin/get_user_details.js +++ b/api/admin/get_user_details.js @@ -1,5 +1,3 @@ -import tools from 'auth0-extension-tools'; -import config from '../../lib/config'; import avatarUrl from '../../lib/avatar'; module.exports = () => ({ diff --git a/api/admin/put_settings.js b/api/admin/put_settings.js index 39a10d7f..24bdd795 100644 --- a/api/admin/put_settings.js +++ b/api/admin/put_settings.js @@ -1,3 +1,5 @@ +/* eslint-disable no-useless-escape */ + import Joi from 'joi'; import { setSettings } from '../../lib/storage'; @@ -13,8 +15,12 @@ module.exports = () => ({ template: Joi.string().required(), locale: Joi.string().required(), title: Joi.string().required(), - color: Joi.string().regex(colorRegex).required(), - logoPath: Joi.string().regex(urlRegex).allow(''), + color: Joi.string() + .regex(colorRegex) + .required(), + logoPath: Joi.string() + .regex(urlRegex) + .allow(''), removeOverlay: Joi.bool().default(false) } } diff --git a/api/get_index.js b/api/get_index.js index 2d4025aa..4cf558bd 100644 --- a/api/get_index.js +++ b/api/get_index.js @@ -1,72 +1,78 @@ -import config from '../lib/config'; import { decode } from 'jsonwebtoken'; +import config from '../lib/config'; import findUsersByEmail from '../lib/findUsersByEmail'; import indexTemplate from '../templates/index'; +import logger from '../lib/console'; const version = require('../package.json').version; const CDN_CSS = `https://cdn.auth0.com/extensions/auth0-account-link-extension/${version}/link.min.css`; -const decodeToken = (token) => ( +const decodeToken = token => new Promise((resolve, reject) => { try { resolve(decode(token)); - } catch(e) { + } catch (e) { reject(e); } - }) -); + }); -const fetchUsersFromToken = ({sub, email}) => ( +const fetchUsersFromToken = ({ sub, email }) => findUsersByEmail(email).then(users => ({ currentUser: users.find(u => u.user_id === sub), matchingUsers: users.filter(u => u.user_id !== sub) - })) -); + })); -module.exports = _ => ({ +module.exports = () => ({ method: 'GET', path: '/', config: { auth: false }, handler: (req, reply) => { - - const state = req.state['account-linking-admin-state']; - if (typeof state !== 'undefined' && state !== '') { - return reply.redirect('/admin').state('account-linking-admin-state', ''); + const linkingState = req.state['account-linking-admin-state']; + if (typeof linkingState !== 'undefined' && linkingState !== '') { + reply.redirect('/admin').state('account-linking-admin-state', ''); + return; } const stylesheetLink = config('NODE_ENV') === 'production' ? CDN_CSS : '/css/link.css'; - decodeToken(req.query.child_token).then(token => { - fetchUsersFromToken(token).then(({currentUser, matchingUsers}) => { - reply(indexTemplate({ - stylesheetLink, - currentUser, - matchingUsers, - customCSS: config('CUSTOM_CSS') - })); - }) - .catch(err => { - const state = req.query.state; - console.error("An error was encountered: ", err); - console.info(`Redirecting to failed link to /continue: ${token.iss}continue?state=${req.query.state}`); + decodeToken(req.query.child_token) + .then((token) => { + fetchUsersFromToken(token) + .then(({ currentUser, matchingUsers }) => { + reply( + indexTemplate({ + stylesheetLink, + currentUser, + matchingUsers, + customCSS: config('CUSTOM_CSS') + }) + ); + }) + .catch((err) => { + const state = req.query.state; + logger.error('An error was encountered: ', err); + logger.info( + `Redirecting to failed link to /continue: ${token.iss}continue?state=${req.query + .state}` + ); - reply.redirect(`${token.iss}continue?state=${state}`); - }); - }).catch(err => { - console.error("An invalid token was provided", err); + reply.redirect(`${token.iss}continue?state=${state}`); + }); + }) + .catch((err) => { + logger.error('An invalid token was provided', err); - indexTemplate({ - stylesheetLink, - currentUser: null, - matchingUsers: [], - customCSS: config('CUSTOM_CSS') - }).then((template) => { - reply(template).code(400); + indexTemplate({ + stylesheetLink, + currentUser: null, + matchingUsers: [], + customCSS: config('CUSTOM_CSS') + }).then((template) => { + reply(template).code(400); + }); }); - - }); } }); diff --git a/api/get_meta.js b/api/get_meta.js index 84be5da9..184216dc 100644 --- a/api/get_meta.js +++ b/api/get_meta.js @@ -1,7 +1,6 @@ -import config from '../lib/config'; import metadata from '../webtask.json'; -module.exports = _ => ({ +module.exports = () => ({ method: 'GET', path: '/meta', config: { auth: false }, diff --git a/api/hooks/delete_uninstall.js b/api/hooks/delete_uninstall.js index 21ca23c1..a5442371 100644 --- a/api/hooks/delete_uninstall.js +++ b/api/hooks/delete_uninstall.js @@ -1,7 +1,8 @@ import { uninstall } from '../../modifyRule'; import config from '../../lib/config'; +import logger from '../../lib/console'; -module.exports = (server) => ({ +module.exports = server => ({ method: 'DELETE', path: '/.extensions/on-uninstall', config: { @@ -12,15 +13,15 @@ module.exports = (server) => ({ ] }, handler: (req, reply) => { - console.log("Starting uninstall..."); + logger.log('Starting uninstall...'); Promise.all([ uninstall(req.pre.auth0.rules), - req.pre.auth0.deleteClient({ client_id: config('AUTH0_CLIENT_ID')}) + req.pre.auth0.deleteClient({ client_id: config('AUTH0_CLIENT_ID') }) ]) - .then(_ => reply().code(204)) + .then(() => reply().code(204)) .catch((err) => { - console.error("Something went wrong while uninstalling Account Link Extension: ", err); + logger.error('Something went wrong while uninstalling Account Link Extension: ', err); // Swallow the error so we do not break the experience for the user reply().code(204); diff --git a/api/hooks/post_install.js b/api/hooks/post_install.js index 54bde546..40338da5 100644 --- a/api/hooks/post_install.js +++ b/api/hooks/post_install.js @@ -1,7 +1,8 @@ import { install } from '../../modifyRule'; import config from '../../lib/config'; +import logger from '../../lib/console'; -module.exports = (server) => ({ +module.exports = server => ({ method: 'POST', path: '/.extensions/on-install', config: { @@ -12,19 +13,21 @@ module.exports = (server) => ({ ] }, handler: (req, reply) => { - console.log("Starting rule installation..."); + logger.log('Starting rule installation...'); install(req.pre.auth0.rules, { extensionURL: config('PUBLIC_WT_URL'), clientID: config('AUTH0_CLIENT_ID'), clientSecret: config('AUTH0_CLIENT_SECRET') }) - .then(_ => reply().code(204)) - .then(_ => { console.log("Rule successfully installed"); }) + .then(() => reply().code(204)) + .then(() => { + logger.log('Rule successfully installed'); + }) .catch((err) => { - console.error("Something went wrong, ", err); + logger.error('Something went wrong, ', err); throw err; }) - .catch((err) => reply.error(err)); + .catch(err => reply.error(err)); } }); diff --git a/gulpfile.js b/gulpfile.js index acece079..f0ac2008 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,12 +1,12 @@ 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 { install } = require('./modifyRule'); const managementAdapter = require('./lib/managementAdapter'); + const ManagementClientAdapter = managementAdapter.default; const { getCurrentConfig } = managementAdapter; diff --git a/index.js b/index.js index da15f815..61de6c60 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ const nconf = require('nconf'); const path = require('path'); +const logger = require('./lib/console').default; // Load babel require('./lib/babel')(); @@ -19,8 +20,9 @@ nconf }); const createServer = require('./server/init'); -const startServer = (server) => { - return new Promise((resolve, reject) => { + +const startServer = server => + new Promise((resolve, reject) => { server.start((err) => { if (err) { reject(err); @@ -28,20 +30,17 @@ const startServer = (server) => { resolve(server); - console.info(`Server running at: ${server.info.uri}`); + logger.info(`Server running at: ${server.info.uri}`); }); }); -}; const server = createServer(key => nconf.get(key), null); -startServer(server) - .catch((err) => { - console.error(err); - console.error('Server could not be started. Aborting...'); - - process.exit(1); - }); +startServer(server).catch((err) => { + logger.error(err); + logger.error('Server could not be started. Aborting...'); + process.exit(1); +}); module.exports = server; diff --git a/lib/api.js b/lib/api.js index c54abeac..3ee22ab7 100644 --- a/lib/api.js +++ b/lib/api.js @@ -1,6 +1,7 @@ import { managementApi } from 'auth0-extension-tools'; -import config from './config'; import request from 'request'; +import config from './config'; +import logger from '../lib/console'; // Memoized because config unavailable at this point const urlHelper = { @@ -17,37 +18,39 @@ const urlHelper = { } }; -const getToken = () => ( +const getToken = () => managementApi.getAccessTokenCached( config('AUTH0_DOMAIN'), config('AUTH0_CLIENT_ID'), config('AUTH0_CLIENT_SECRET') - ) -); + ); -const apiCall = ({ path, ...options } = {}) => ( - getToken().then(token => { - return new Promise((resolve, reject) => { - request({ - url: urlHelper.endpoint(path), - headers: { - Authorization: `Bearer ${token}`, - Accept: 'application/json' - }, - json: true, - ...options - }, (err, response, body) => { - if (err) { - reject(err); - } else if (response.statusCode < 200 || response.statusCode >= 300) { - console.error('API call failed: ', response.status, body); - reject(new Error(body)); - } else { - resolve(response.body); - } - }); - }); - }) -); +const apiCall = ({ path, ...options } = {}) => + getToken().then( + token => + new Promise((resolve, reject) => { + request( + { + url: urlHelper.endpoint(path), + headers: { + Authorization: `Bearer ${token}`, + Accept: 'application/json' + }, + json: true, + ...options + }, + (err, response, body) => { + if (err) { + reject(err); + } else if (response.statusCode < 200 || response.statusCode >= 300) { + logger.error('API call failed: ', response.status, body); + reject(new Error(body)); + } else { + resolve(response.body); + } + } + ); + }) + ); export default apiCall; diff --git a/lib/avatar.js b/lib/avatar.js index 41c01d3d..d885e6a2 100644 --- a/lib/avatar.js +++ b/lib/avatar.js @@ -1,8 +1,8 @@ import md5 from 'md5'; export default (email) => { - const md5email = md5(email); - const letters = email.substr(0, 2); - - return `https://s.gravatar.com/avatar/${md5email}?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2F${letters}.png`; -} \ No newline at end of file + const md5email = md5(email); + const letters = email.substr(0, 2); + + return `https://s.gravatar.com/avatar/${md5email}?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2F${letters}.png`; +}; diff --git a/lib/babel.js b/lib/babel.js index 638194c5..e1e43e98 100644 --- a/lib/babel.js +++ b/lib/babel.js @@ -1,3 +1,4 @@ +/* eslint-disable global-require */ // Initialize Babel for the rest of the app module.exports = function loadBabel() { diff --git a/lib/console.js b/lib/console.js new file mode 100644 index 00000000..c21ec45e --- /dev/null +++ b/lib/console.js @@ -0,0 +1,9 @@ +/* eslint-disable no-console */ + +const logger = { + log: (message, ...args) => console.log(message, ...args), + error: (message, ...args) => console.error(message, ...args), + info: (message, ...args) => console.info(message, ...args) +}; + +module.exports = { default: logger }; diff --git a/lib/db.js b/lib/db.js index c5730161..4f0d842d 100644 --- a/lib/db.js +++ b/lib/db.js @@ -4,7 +4,7 @@ let _db = null; module.exports.init = (db) => { _db = db; -} +}; module.exports.get = () => { if (!_db) { @@ -12,4 +12,4 @@ module.exports.get = () => { } return _db; -} +}; diff --git a/lib/findUsersByEmail.js b/lib/findUsersByEmail.js index 019c6124..a5ebf541 100644 --- a/lib/findUsersByEmail.js +++ b/lib/findUsersByEmail.js @@ -1,11 +1,9 @@ -import request from 'request'; import apiCall from './api'; -const findUsersByEmail = (email, excludeID = null) => { - return apiCall({ +const findUsersByEmail = email => + apiCall({ path: 'users-by-email', qs: { email } }); -}; export default findUsersByEmail; diff --git a/lib/locale.js b/lib/locale.js index f6252f5a..cd865355 100644 --- a/lib/locale.js +++ b/lib/locale.js @@ -3,10 +3,10 @@ import jsonLocales from '../locales.json'; export const allLocales = jsonLocales; -let _settings = null; +let cachedSettings = null; function resolveLocale(key) { - const locales = allLocales[_settings.locale]; + const locales = allLocales[cachedSettings.locale]; let locale = locales[key]; @@ -21,7 +21,7 @@ export default () => new Promise((resolve) => { getSettings() .then((settings) => { - _settings = settings; + cachedSettings = settings; }) .then(resolve(resolveLocale)); }); diff --git a/lib/managementAdapter.js b/lib/managementAdapter.js index c97ca8b1..657186e6 100644 --- a/lib/managementAdapter.js +++ b/lib/managementAdapter.js @@ -8,7 +8,9 @@ const readFileAsync = promisify(readFile); /** * Reads the current configuration file and returns its contents. */ -export async function getCurrentConfig(configFilePath = path.join(__dirname, '../server/config.json')) { +export async function getCurrentConfig( + configFilePath = path.join(__dirname, '../server/config.json') +) { const fileContents = await readFileAsync(configFilePath); return JSON.parse(fileContents); } @@ -26,7 +28,7 @@ export default class ManagementClientAdapter { }); } - /** + /** * Gets all rules from Auth0 */ async getAll() { @@ -44,7 +46,7 @@ export default class ManagementClientAdapter { /** * Updates a rule in Auth0 * @param {object} options - * @param {object} generatedRule + * @param {object} generatedRule */ async update({ id }, { name, script, enabled }) { return this.client.updateRule({ id }, { name, script, enabled }); diff --git a/lib/svgDimensions.js b/lib/svgDimensions.js index 7993e75b..593575cc 100644 --- a/lib/svgDimensions.js +++ b/lib/svgDimensions.js @@ -1,6 +1,8 @@ const svgDimensions = { - text: 'M246.517,0.11 C238.439,0.11 231.607,3.916 226.759,11.115 C221.94,18.271 219.393,28.26 219.393,40 C219.393,51.74 221.94,61.729 226.759,68.884 C231.607,76.084 238.439,79.889 246.517,79.889 C254.595,79.889 261.427,76.084 266.275,68.884 C271.093,61.729 273.64,51.74 273.64,40 C273.64,28.26 271.093,18.271 266.275,11.115 C261.427,3.916 254.595,0.11 246.517,0.11 L246.517,0.11 Z M246.517,70.005 C242.655,70.005 239.604,67.82 237.187,63.324 C234.268,57.893 232.66,49.61 232.66,40 C232.66,30.39 234.268,22.106 237.187,16.676 C239.604,12.18 242.655,9.994 246.517,9.994 C250.378,9.994 253.43,12.18 255.847,16.676 C258.766,22.106 260.373,30.389 260.373,40 C260.373,49.611 258.766,57.895 255.847,63.324 C253.43,67.82 250.378,70.005 246.517,70.005 L246.517,70.005 Z M71.45,29.172 L71.45,63.484 C71.45,72.53 78.81,79.889 87.856,79.889 C95.746,79.889 101.707,75.975 103.902,74.291 C104.024,74.197 104.184,74.169 104.331,74.216 C104.478,74.263 104.592,74.379 104.637,74.527 L105.961,78.86 L115.737,78.86 L115.737,29.172 L103.175,29.172 L103.175,66.326 C103.175,66.501 103.076,66.662 102.921,66.743 C100.559,67.961 95.899,70.006 91.231,70.006 C87.252,70.006 84.012,66.768 84.012,62.787 L84.012,29.172 L71.45,29.172 L71.45,29.172 Z M197.237,78.859 L209.8,78.859 L209.8,44.547 C209.8,35.501 202.44,28.141 193.394,28.141 C186.735,28.141 181.393,31.004 178.802,32.71 C178.657,32.805 178.473,32.813 178.322,32.731 C178.171,32.649 178.075,32.491 178.075,32.318 L178.075,1.141 L165.513,1.141 L165.513,78.859 L178.075,78.859 L178.075,41.704 C178.075,41.529 178.174,41.368 178.33,41.288 C180.691,40.069 185.352,38.025 190.019,38.025 C191.947,38.025 193.76,38.776 195.123,40.139 C196.486,41.502 197.236,43.316 197.236,45.243 L197.236,78.859 L197.237,78.859 Z M124.792,39.055 L132.438,39.055 C132.697,39.055 132.907,39.265 132.907,39.524 L132.907,66.858 C132.907,74.043 138.753,79.888 145.938,79.888 C148.543,79.888 151.113,79.512 153.585,78.77 L153.585,69.796 C152.143,69.923 150.485,70.005 149.313,70.005 C147.193,70.005 145.469,68.28 145.469,66.161 L145.469,39.523 C145.469,39.264 145.679,39.054 145.938,39.054 L153.585,39.054 L153.585,29.171 L145.938,29.171 C145.679,29.171 145.469,28.961 145.469,28.702 L145.469,12.295 L132.907,12.295 L132.907,28.702 C132.907,28.961 132.697,29.171 132.438,29.171 L124.792,29.171 L124.792,39.055 L124.792,39.055 Z M51.361,78.859 L64.429,78.859 L44.555,9.55 C42.962,3.992 37.811,0.11 32.029,0.11 C26.247,0.11 21.096,3.992 19.502,9.55 L-0.372,78.859 L12.697,78.859 L18.449,58.798 C18.507,58.597 18.691,58.459 18.9,58.459 L45.158,58.459 C45.367,58.459 45.552,58.597 45.609,58.798 L51.361,78.859 L51.361,78.859 Z M42.056,48.576 L22.004,48.576 C21.857,48.576 21.718,48.507 21.629,48.388 C21.541,48.272 21.513,48.119 21.553,47.978 L31.579,13.012 C31.637,12.811 31.821,12.673 32.03,12.673 C32.239,12.673 32.423,12.811 32.48,13.012 L42.507,47.978 C42.547,48.12 42.519,48.272 42.43,48.388 C42.342,48.507 42.203,48.576 42.056,48.576 L42.056,48.576 Z', - badge: 'M119.555,135.861 L102.705,83.997 L146.813,51.952 L92.291,51.952 L75.44,0.09 L75.435,0.076 L129.965,0.076 L146.82,51.947 L146.821,51.946 L146.835,51.938 C156.623,82.03 146.542,116.256 119.555,135.861 L119.555,135.861 Z M31.321,135.861 L31.307,135.871 L75.426,167.924 L119.555,135.862 L75.44,103.808 L31.321,135.861 L31.321,135.861 Z M4.052,51.939 L4.052,51.939 C-6.252,83.66 5.709,117.272 31.312,135.867 L31.316,135.851 L48.168,83.99 L4.07,51.951 L58.579,51.951 L75.431,0.089 L75.435,0.075 L20.902,0.075 L4.052,51.939 L4.052,51.939 Z' + text: + 'M246.517,0.11 C238.439,0.11 231.607,3.916 226.759,11.115 C221.94,18.271 219.393,28.26 219.393,40 C219.393,51.74 221.94,61.729 226.759,68.884 C231.607,76.084 238.439,79.889 246.517,79.889 C254.595,79.889 261.427,76.084 266.275,68.884 C271.093,61.729 273.64,51.74 273.64,40 C273.64,28.26 271.093,18.271 266.275,11.115 C261.427,3.916 254.595,0.11 246.517,0.11 L246.517,0.11 Z M246.517,70.005 C242.655,70.005 239.604,67.82 237.187,63.324 C234.268,57.893 232.66,49.61 232.66,40 C232.66,30.39 234.268,22.106 237.187,16.676 C239.604,12.18 242.655,9.994 246.517,9.994 C250.378,9.994 253.43,12.18 255.847,16.676 C258.766,22.106 260.373,30.389 260.373,40 C260.373,49.611 258.766,57.895 255.847,63.324 C253.43,67.82 250.378,70.005 246.517,70.005 L246.517,70.005 Z M71.45,29.172 L71.45,63.484 C71.45,72.53 78.81,79.889 87.856,79.889 C95.746,79.889 101.707,75.975 103.902,74.291 C104.024,74.197 104.184,74.169 104.331,74.216 C104.478,74.263 104.592,74.379 104.637,74.527 L105.961,78.86 L115.737,78.86 L115.737,29.172 L103.175,29.172 L103.175,66.326 C103.175,66.501 103.076,66.662 102.921,66.743 C100.559,67.961 95.899,70.006 91.231,70.006 C87.252,70.006 84.012,66.768 84.012,62.787 L84.012,29.172 L71.45,29.172 L71.45,29.172 Z M197.237,78.859 L209.8,78.859 L209.8,44.547 C209.8,35.501 202.44,28.141 193.394,28.141 C186.735,28.141 181.393,31.004 178.802,32.71 C178.657,32.805 178.473,32.813 178.322,32.731 C178.171,32.649 178.075,32.491 178.075,32.318 L178.075,1.141 L165.513,1.141 L165.513,78.859 L178.075,78.859 L178.075,41.704 C178.075,41.529 178.174,41.368 178.33,41.288 C180.691,40.069 185.352,38.025 190.019,38.025 C191.947,38.025 193.76,38.776 195.123,40.139 C196.486,41.502 197.236,43.316 197.236,45.243 L197.236,78.859 L197.237,78.859 Z M124.792,39.055 L132.438,39.055 C132.697,39.055 132.907,39.265 132.907,39.524 L132.907,66.858 C132.907,74.043 138.753,79.888 145.938,79.888 C148.543,79.888 151.113,79.512 153.585,78.77 L153.585,69.796 C152.143,69.923 150.485,70.005 149.313,70.005 C147.193,70.005 145.469,68.28 145.469,66.161 L145.469,39.523 C145.469,39.264 145.679,39.054 145.938,39.054 L153.585,39.054 L153.585,29.171 L145.938,29.171 C145.679,29.171 145.469,28.961 145.469,28.702 L145.469,12.295 L132.907,12.295 L132.907,28.702 C132.907,28.961 132.697,29.171 132.438,29.171 L124.792,29.171 L124.792,39.055 L124.792,39.055 Z M51.361,78.859 L64.429,78.859 L44.555,9.55 C42.962,3.992 37.811,0.11 32.029,0.11 C26.247,0.11 21.096,3.992 19.502,9.55 L-0.372,78.859 L12.697,78.859 L18.449,58.798 C18.507,58.597 18.691,58.459 18.9,58.459 L45.158,58.459 C45.367,58.459 45.552,58.597 45.609,58.798 L51.361,78.859 L51.361,78.859 Z M42.056,48.576 L22.004,48.576 C21.857,48.576 21.718,48.507 21.629,48.388 C21.541,48.272 21.513,48.119 21.553,47.978 L31.579,13.012 C31.637,12.811 31.821,12.673 32.03,12.673 C32.239,12.673 32.423,12.811 32.48,13.012 L42.507,47.978 C42.547,48.12 42.519,48.272 42.43,48.388 C42.342,48.507 42.203,48.576 42.056,48.576 L42.056,48.576 Z', + badge: + 'M119.555,135.861 L102.705,83.997 L146.813,51.952 L92.291,51.952 L75.44,0.09 L75.435,0.076 L129.965,0.076 L146.82,51.947 L146.821,51.946 L146.835,51.938 C156.623,82.03 146.542,116.256 119.555,135.861 L119.555,135.861 Z M31.321,135.861 L31.307,135.871 L75.426,167.924 L119.555,135.862 L75.44,103.808 L31.321,135.861 L31.321,135.861 Z M4.052,51.939 L4.052,51.939 C-6.252,83.66 5.709,117.272 31.312,135.867 L31.316,135.851 L48.168,83.99 L4.07,51.951 L58.579,51.951 L75.431,0.089 L75.435,0.075 L20.902,0.075 L4.052,51.939 L4.052,51.939 Z' }; export default svgDimensions; diff --git a/modifyRule.js b/modifyRule.js index 7ea64147..6534962b 100644 --- a/modifyRule.js +++ b/modifyRule.js @@ -16,7 +16,7 @@ const persistRule = (api, generatedRule) => (rules = []) => { return api.create({ stage: RULE_STAGE, ...generatedRule }); }; -const destroyRule = (api) => (rules = []) => { +const destroyRule = api => (rules = []) => { const existingRule = findIn(rules); if (existingRule) { @@ -29,6 +29,6 @@ const install = (api, config) => { return api.getAll().then(persistRule(api, rule)); }; -const uninstall = (api) => api.getAll().then(destroyRule(api)); +const uninstall = api => api.getAll().then(destroyRule(api)); export { install, uninstall }; diff --git a/package.json b/package.json index fb388ed5..1caa5400 100644 --- a/package.json +++ b/package.json @@ -8,15 +8,12 @@ }, "scripts": { "start": "node ./index.js", - "test": - "nyc --require babel-register --require babel-polyfill mocha test --recursive", - "test:integration": - "mocha integration --compilers js:babel-core/register --recursive --timeout 50000", + "test": "nyc --require babel-register --require babel-polyfill mocha test --recursive", + "test:integration": "mocha integration --compilers js:babel-core/register --recursive --timeout 50000", "lint": "eslint .", "serve:dev": "gulp run", "client:build": "minify --clean public/css/link.css", - "extension:build": - "a0-ext build:server ./webtask.js ./dist && cp ./dist/auth0-account-link.extension.$npm_package_version.js ./build/bundle.js", + "extension:build": "a0-ext build:server ./webtask.js ./dist && cp ./dist/auth0-account-link.extension.$npm_package_version.js ./build/bundle.js", "build": "yarn run client:build && yarn run extension:build" }, "author": "Auth0", @@ -90,6 +87,7 @@ "auth0-extensions-cli": "^1.0.5", "babel": "^6.23.0", "babel-core": "^6.25.0", + "babel-plugin-transform-es2015-parameters": "^6.24.1", "babel-plugin-transform-object-rest-spread": "^6.23.0", "babel-plugin-transform-runtime": "^6.23.0", "babel-polyfill": "^6.23.0", diff --git a/public/index.js b/public/index.js index 19ffd9cb..42ac0b01 100644 --- a/public/index.js +++ b/public/index.js @@ -1,3 +1,7 @@ +/* eslint-disable */ +// Ignoring this file since it has to be written in ES5 +// and eslint is configured to lint ES6. + export default function(currentUser, matchingUsers) { var params = window.Qs.parse(window.location.search, { ignoreQueryPrefix: true }); diff --git a/public/js/admin.js b/public/js/admin.js index 8ebf49b3..7dd5c9ba 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -1,4 +1,4 @@ -/* eslint-disable no-var, func-names, prefer-arrow-callback */ +/* eslint-disable */ /* global CodeMirror, $ */ (function () { diff --git a/rules/link.js b/rules/link.js index 0aa450a4..cc4026d8 100644 --- a/rules/link.js +++ b/rules/link.js @@ -1,9 +1,7 @@ -/* global configuration, auth0, jwt */ - /** * This file is meant to be included as a string template */ -export default ({extensionURL = '', username = 'Unknown', clientID = '', clientSecret = ''}) => { +export default ({ extensionURL = '', username = 'Unknown', clientID = '', clientSecret = '' }) => { const template = `function (user, context, callback) { /** * This rule has been automatically generated by diff --git a/server/auth.js b/server/auth.js index dbeebb90..5a9fe26f 100644 --- a/server/auth.js +++ b/server/auth.js @@ -1,5 +1,6 @@ +/* eslint-disable no-param-reassign */ + import Boom from 'boom'; -import crypto from 'crypto'; import jwksRsa from 'jwks-rsa'; import jwt from 'jsonwebtoken'; import * as tools from 'auth0-extension-hapi-tools'; @@ -8,9 +9,7 @@ import config from '../lib/config'; const scopes = [{ value: 'openid' }, { value: 'profile' }]; - module.exports.register = (server, options, next) => { - const jwtOptions = { dashboardAdmin: { key: config('EXTENSION_SECRET'), @@ -91,7 +90,7 @@ module.exports.register = (server, options, next) => { return callback(Boom.unauthorized('Invalid token', 'Token'), null, null); } - decoded.payload.scope = scopes.map(scope => scope.value); // eslint-disable-line no-param-reassign + decoded.payload.scope = scopes.map(scope => scope.value); return callback(null, true, decoded.payload); } ); diff --git a/server/handlers.js b/server/handlers.js index 1efc7a81..32f302cf 100644 --- a/server/handlers.js +++ b/server/handlers.js @@ -1,6 +1,6 @@ import { handlers } from 'auth0-extension-hapi-tools'; import config from '../lib/config'; -import logger from '../lib/logger'; +import logger from '../lib/console'; const register = (server, options, next) => { server.decorate('server', 'handlers', { diff --git a/server/index.js b/server/index.js index 57e4a0c6..906c6827 100644 --- a/server/index.js +++ b/server/index.js @@ -1,9 +1,11 @@ +/* eslint-disable global-require */ + import path from 'path'; import Hapi from 'hapi'; import Inert from 'inert'; import jwt from 'hapi-auth-jwt2'; import config from '../lib/config'; -import logger from '../lib/logger'; +import logger from '../lib/console'; import routes from './routes'; import defaultHandlers from './handlers'; import auth from './auth'; @@ -25,7 +27,7 @@ const createServer = (cb, handlers = defaultHandlers) => { server.register([jwt, Inert], () => {}); - server.register(require('vision'), (err) => { + server.register(require('vision'), () => { server.views({ engines: { hbs: require('handlebars') diff --git a/server/init.js b/server/init.js index 81ab3116..0878c7ea 100644 --- a/server/init.js +++ b/server/init.js @@ -2,7 +2,7 @@ import path from 'path'; import { FileStorageContext, WebtaskStorageContext } from 'auth0-extension-tools'; import config from '../lib/config'; import createServer from './index'; -import logger from '../lib/logger'; +import logger from '../lib/console'; import { init as initStorage } from '../lib/db'; const defaultCallback = (err) => { diff --git a/templates/index.js b/templates/index.js index d85a6222..41f38c09 100644 --- a/templates/index.js +++ b/templates/index.js @@ -1,5 +1,4 @@ import { render } from 'micromustache'; -import svgDimensions from '../lib/svgDimensions'; import defaultTemplate from './utils/defaultTemplate'; import { get as getStorage } from '../lib/db'; @@ -10,16 +9,20 @@ const stylesheetTag = href => (href ? `` export default ({ stylesheetLink, customCSS, currentUser, matchingUsers }) => new Promise((resolve) => { - getStorage().read().then((data) => { - const template = data.settings ? data.settings.template : defaultTemplate; - - buildAuth0Widget().then((Auth0Widget) => { - resolve(render(template, { - ExtensionCSS: stylesheetTag(stylesheetLink), - CustomCSS: stylesheetTag(customCSS), - Auth0Widget, - ExtensionScripts: buildExtensionScripts(currentUser, matchingUsers) - })); + getStorage() + .read() + .then((data) => { + const template = data.settings ? data.settings.template : defaultTemplate; + + buildAuth0Widget().then((Auth0Widget) => { + resolve( + render(template, { + ExtensionCSS: stylesheetTag(stylesheetLink), + CustomCSS: stylesheetTag(customCSS), + Auth0Widget, + ExtensionScripts: buildExtensionScripts(currentUser, matchingUsers) + }) + ); + }); }); - }); - }) + }); diff --git a/templates/utils/auth0widget.js b/templates/utils/auth0widget.js index c1025ee6..5e277a27 100644 --- a/templates/utils/auth0widget.js +++ b/templates/utils/auth0widget.js @@ -9,7 +9,9 @@ export default () => getSettings().then(settings => { resolve(`
-
+
${settings.removeOverlay ? '' : ` @@ -44,11 +46,13 @@ export default () =>
- ${settings.logoPath !== '' ? ` + ${settings.logoPath !== '' + ? ` - ` : ` + ` + : ` `} -
${settings.title !== '' ? settings.title : t('accountLinking')}
+
${settings.title !== '' + ? settings.title + : t('accountLinking')}
@@ -96,7 +102,9 @@ export default () =>
-