Skip to content
This repository has been archived by the owner on Apr 23, 2019. It is now read-only.

Update to new plugin infrastructure #74

Merged
merged 2 commits into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,4 @@ node_modules
# Users Environment Variables
.lock-wscript

# The compiled/babelified modules
lib/

# Yarn lockfile
yarn.lock
dist/
6 changes: 2 additions & 4 deletions .istanbul.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
verbose: false
instrumentation:
root: ./src/
excludes:
- lib/
root: ./lib/
include-all-sources: true
reporting:
print: summary
Expand All @@ -14,4 +12,4 @@ reporting:
statements: [50, 80]
lines: [50, 80]
functions: [50, 80]
branches: [50, 80]
branches: [50, 80]
7 changes: 3 additions & 4 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
.istanbul.yml
.babelrc
.idea/
src/
.vscode/
test/
!lib/
coverage
.github/
coverage/
.github/
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: node_js
node_js:
- node
- '6'
- '4'
addons:
code_climate:
repo_token: 329c779628cbc55367f5ddee580bc738313b26a3ec20b3f27b08092687d50320
Expand Down
11 changes: 11 additions & 0 deletions lib/hooks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const populateHeader = require('./populate-header');
const populateAccessToken = require('./populate-access-token');
const populateEntity = require('./populate-entity');

let hooks = {
populateHeader,
populateAccessToken,
populateEntity
};

module.exports = hooks;
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/*
* Exposes the access token to the client side hooks
* under hook.params.accessToken.
*/

export default function populateAccessToken () {
module.exports = function populateAccessToken () {
return function (hook) {
const app = hook.app;

Expand All @@ -15,4 +10,4 @@ export default function populateAccessToken () {

return Promise.resolve(hook);
};
}
};
10 changes: 2 additions & 8 deletions src/hooks/populate-entity.js → lib/hooks/populate-entity.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/*
* Fetch and populate an entity by id encoded in the
* access token payload. Useful for easily getting the
* current user after authentication, or any other entity.
*/

export default function populateEntity (options = {}) {
module.exports = function populateEntity (options = {}) {
if (!options.service) {
throw new Error(`You need to pass 'options.service' to the populateEntity() hook.`);
}
Expand Down Expand Up @@ -42,4 +36,4 @@ export default function populateEntity (options = {}) {
return Promise.resolve(hook);
});
};
}
};
10 changes: 2 additions & 8 deletions src/hooks/populate-header.js → lib/hooks/populate-header.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/*
* Sets the access token in the authorization header
* under hook.params.header so that it can be picked
* up by the client side REST libraries.
*/

export default function populateHeader (options = {}) {
module.exports = function populateHeader (options = {}) {
if (!options.header) {
throw new Error(`You need to pass 'options.header' to the populateHeader() hook.`);
}
Expand All @@ -22,4 +16,4 @@ export default function populateHeader (options = {}) {

return Promise.resolve(hook);
};
}
};
10 changes: 5 additions & 5 deletions src/index.js → lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import hooks from './hooks/index';
import Passport from './passport';
const hooks = require('./hooks/index');
const Passport = require('./passport');

const defaults = {
header: 'Authorization',
Expand All @@ -12,7 +12,7 @@ const defaults = {
timeout: 5000
};

export default function init (config = {}) {
module.exports = function init (config = {}) {
const options = Object.assign({}, defaults, config);

return function () {
Expand Down Expand Up @@ -40,6 +40,6 @@ export default function init (config = {}) {
});
}
};
}
};

init.defaults = defaults;
module.exports.defaults = defaults;
18 changes: 12 additions & 6 deletions src/passport.js → lib/passport.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import errors from 'feathers-errors';
import decode from 'jwt-decode';
import Debug from 'debug';
import { Storage, payloadIsValid, getCookie, clearCookie } from './utils';
const errors = require('feathers-errors');
const decode = require('jwt-decode');
const Debug = require('debug');

const {
Storage,
payloadIsValid,
getCookie,
clearCookie
} = require('./utils');

const debug = Debug('feathers-authentication-client');

export default class Passport {
module.exports = class Passport {
constructor (app, options) {
if (app.passport) {
throw new Error('You have already registered authentication on this client app instance. You only need to do it once.');
Expand Down Expand Up @@ -292,4 +298,4 @@ export default class Passport {

return new Storage();
}
}
};
17 changes: 8 additions & 9 deletions src/utils.js → lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class Storage {
exports.Storage = class Storage {
constructor () {
this.store = {};
}
Expand All @@ -15,14 +15,13 @@ export class Storage {
delete this.store[key];
return this;
}
}
};

// Pass a decoded payload and it will return a boolean based on if it hasn't expired.
export function payloadIsValid (payload) {
exports.payloadIsValid = function payloadIsValid (payload) {
return payload && (!payload.exp || payload.exp * 1000 > new Date().getTime());
}
};

export function getCookie (name) {
exports.getCookie = function getCookie (name) {
if (typeof document !== 'undefined') {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
Expand All @@ -33,12 +32,12 @@ export function getCookie (name) {
}

return null;
}
};

export function clearCookie (name) {
exports.clearCookie = function clearCookie (name) {
if (typeof document !== 'undefined') {
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
}

return null;
}
};
2 changes: 0 additions & 2 deletions mocha.opts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
--recursive test/
--compilers js:babel-core/register
--require babel-polyfill
--exit
Loading