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

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Franco Correa committed Nov 7, 2017
1 parent e966f28 commit 6ca5d2c
Show file tree
Hide file tree
Showing 35 changed files with 213 additions and 174 deletions.
15 changes: 3 additions & 12 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -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"]
}
6 changes: 5 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
node_modules/**
sample-app/**
integration/**
sample-app/**
build/**
test/**
dist/**
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
3 changes: 0 additions & 3 deletions api/admin/get_index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import tools from 'auth0-extension-tools';
import config from '../../lib/config';

module.exports = () => ({
method: 'GET',
path: '/admin',
Expand Down
9 changes: 7 additions & 2 deletions api/admin/get_settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-underscore-dangle */

import { getSettings } from '../../lib/storage';
import { allLocales as locales } from '../../lib/locale';

Expand All @@ -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 });
});
Expand Down
2 changes: 0 additions & 2 deletions api/admin/get_user_details.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import tools from 'auth0-extension-tools';
import config from '../../lib/config';
import avatarUrl from '../../lib/avatar';

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

import Joi from 'joi';
import { setSettings } from '../../lib/storage';

Expand All @@ -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)
}
}
Expand Down
84 changes: 45 additions & 39 deletions api/get_index.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

});
}
});
3 changes: 1 addition & 2 deletions api/get_meta.js
Original file line number Diff line number Diff line change
@@ -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 },
Expand Down
11 changes: 6 additions & 5 deletions api/hooks/delete_uninstall.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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);
Expand Down
15 changes: 9 additions & 6 deletions api/hooks/post_install.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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));
}
});
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
21 changes: 10 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const nconf = require('nconf');
const path = require('path');
const logger = require('./lib/console').default;

// Load babel
require('./lib/babel')();
Expand All @@ -19,29 +20,27 @@ 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);
}

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;
Loading

0 comments on commit 6ca5d2c

Please sign in to comment.