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

Update to new plugin infrastructure, drop Node 4 support #50

Merged
merged 1 commit into from
Apr 20, 2018
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.

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

# The compiled/babelified modules
lib/
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]
5 changes: 3 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.istanbul.yml
.babelrc
.idea/
src/
.vscode/
test/
!lib/
coverage/
.github/
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ language: node_js
node_js:
- 'node'
- '6'
- '4'
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import get from 'lodash.get';
import set from 'lodash.set';
const get = require('lodash.get');
const set = require('lodash.set');

const defaults = {
idField: '_id',
as: 'userId'
};

export default function (options = {}) {
module.exports = function (options = {}) {
return function (hook) {
if (hook.type !== 'before') {
throw new Error(`The 'associateCurrentUser' hook should only be used as a 'before' hook.`);
Expand Down Expand Up @@ -41,4 +41,4 @@ export default function (options = {}) {
setId(hook.data);
}
};
}
};
14 changes: 7 additions & 7 deletions src/has-role-or-restrict.js → lib/has-role-or-restrict.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import errors from '@feathersjs/errors';
import isPlainObject from 'lodash.isplainobject';
import get from 'lodash.get';
import set from 'lodash.set';
const errors = require('@feathersjs/errors');
const isPlainObject = require('lodash.isplainobject');
const get = require('lodash.get');
const set = require('lodash.set');

const defaults = {
fieldName: 'roles',
Expand All @@ -10,7 +10,7 @@ const defaults = {
owner: false
};

export default function (options = {}) {
module.exports = function (options = {}) {
if (!options.roles || !options.roles.length) {
throw new Error(`You need to provide an array of 'roles' to check against.`);
}
Expand Down Expand Up @@ -131,7 +131,7 @@ export default function (options = {}) {
if (hook.result) {
return hook;
}

return hook.service.find(Object.assign({}, params, { query })).then(page => {
const results = page.data ? page.data : page;
if (hook.method === 'get' && Array.isArray(results) && results.length === 1) {
Expand All @@ -146,4 +146,4 @@ export default function (options = {}) {
});
}
};
}
};
17 changes: 17 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const associateCurrentUser = require('./associate-current-user');
const queryWithCurrentUser = require('./query-with-current-user');
const restrictToAuthenticated = require('./restrict-to-authenticated');
const restrictToOwner = require('./restrict-to-owner');
const restrictToRoles = require('./restrict-to-roles');
const hasRoleOrRestrict = require('./has-role-or-restrict');

let hooks = {
associateCurrentUser,
queryWithCurrentUser,
restrictToAuthenticated,
restrictToOwner,
restrictToRoles,
hasRoleOrRestrict
};

module.exports = hooks;
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import get from 'lodash.get';
import set from 'lodash.set';
const get = require('lodash.get');
const set = require('lodash.set');

const defaults = {
idField: '_id',
as: 'userId',
expandPaths: true
};

export default function (options = {}) {
module.exports = function (options = {}) {
return function (hook) {
if (hook.type !== 'before') {
throw new Error(`The 'queryWithCurrentUser' hook should only be used as a 'before' hook.`);
Expand Down Expand Up @@ -35,4 +35,4 @@ export default function (options = {}) {
hook.params.query[options.as] = id;
}
};
}
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import errors from '@feathersjs/errors';
import get from 'lodash.get';
const errors = require('@feathersjs/errors');
const get = require('lodash.get');

export default function (options = { entity: 'user' }) {
module.exports = function (options = { entity: 'user' }) {
console.error('The restrictToAuthenticated hook is deprecated. The latest feathers-authentication authenticate hook handles this already.');

return function (hook) {
Expand All @@ -14,4 +14,4 @@ export default function (options = { entity: 'user' }) {
// TODO (EK): Add debug log to check to see if the user is populated, if the token was verified and warn appropriately
}
};
}
};
12 changes: 6 additions & 6 deletions src/restrict-to-owner.js → lib/restrict-to-owner.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import errors from '@feathersjs/errors';
import isPlainObject from 'lodash.isplainobject';
import get from 'lodash.get';
import queryWithCurrentUser from './query-with-current-user';
const errors = require('@feathersjs/errors');
const isPlainObject = require('lodash.isplainobject');
const get = require('lodash.get');
const queryWithCurrentUser = require('./query-with-current-user');

const defaults = {
idField: '_id',
ownerField: 'userId',
expandPaths: true
};

export default function (options = {}) {
module.exports = function (options = {}) {
return function (hook) {
if (hook.type !== 'before') {
throw new Error(`The 'restrictToOwner' hook should only be used as a 'before' hook.`);
Expand Down Expand Up @@ -78,4 +78,4 @@ export default function (options = {}) {
return hook;
});
};
}
};
10 changes: 5 additions & 5 deletions src/restrict-to-roles.js → lib/restrict-to-roles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import errors from '@feathersjs/errors';
import isPlainObject from 'lodash.isplainobject';
import get from 'lodash.get';
const errors = require('@feathersjs/errors');
const isPlainObject = require('lodash.isplainobject');
const get = require('lodash.get');

const defaults = {
fieldName: 'roles',
Expand All @@ -9,7 +9,7 @@ const defaults = {
owner: false
};

export default function (options = {}) {
module.exports = function (options = {}) {
if (!options.roles || !options.roles.length) {
throw new Error(`You need to provide an array of 'roles' to check against.`);
}
Expand Down Expand Up @@ -103,4 +103,4 @@ export default function (options = {}) {
throw error;
}
};
}
};
1 change: 0 additions & 1 deletion mocha.opts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
--recursive test/
--compilers js:babel-core/register
Loading