From 82642043fa8d5359323a0c87d1499ce5fb280624 Mon Sep 17 00:00:00 2001 From: Pedro Romano Date: Wed, 31 May 2017 23:18:33 +0100 Subject: [PATCH 1/4] Trivial dependency updates. --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ca280baf..5445074a 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,12 @@ "dependencies": { "express-graphql": "^0.5.4", "graphql": "^0.7.0", - "async": "2.4.0", + "async": "2.4.1", "body-parser": "1.17.2", "cookie-parser": "1.4.3", "debug": "2.6.8", "express": "4.15.3", - "joi": "10.5.0", + "joi": "10.5.2", "lodash.assign": "4.2.0", "lodash.isequal": "4.5.0", "lodash.omit": "4.5.0", @@ -47,7 +47,7 @@ "jscpd": "0.6.11", "lokka": "1.7.0", "lokka-transport-http": "1.6.1", - "mocha": "3.4.1", + "mocha": "3.4.2", "mocha-performance": "0.1.1", "node-inspector": "1.1.1", "plato": "1.7.0", From 709e39259b1a9b8a1c4d310f0a7a1c857cf089c4 Mon Sep 17 00:00:00 2001 From: Pedro Romano Date: Wed, 31 May 2017 23:21:19 +0100 Subject: [PATCH 2/4] Updated graphql dependencies to latest versions that don't regress. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5445074a..3fb81831 100644 --- a/package.json +++ b/package.json @@ -19,13 +19,13 @@ "node": "*" }, "dependencies": { - "express-graphql": "^0.5.4", - "graphql": "^0.7.0", "async": "2.4.1", "body-parser": "1.17.2", "cookie-parser": "1.4.3", "debug": "2.6.8", "express": "4.15.3", + "express-graphql": "0.5.4", + "graphql": "0.7.2", "joi": "10.5.2", "lodash.assign": "4.2.0", "lodash.isequal": "4.5.0", From b8dc9a63a31a116ebdfe8d3e2670a5260549d5cf Mon Sep 17 00:00:00 2001 From: Pedro Romano Date: Wed, 31 May 2017 23:44:40 +0100 Subject: [PATCH 3/4] Use safe, non-deprecated `Buffer.from` instead of `new Buffer`. --- lib/router.js | 4 ++-- package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/router.js b/lib/router.js index ad67c51c..a6537b45 100644 --- a/lib/router.js +++ b/lib/router.js @@ -133,7 +133,7 @@ router.authenticate = (request, res, callback) => { detail: err || 'You are not authorised to access this resource.' } const payload = responseHelper.generateError(request, errorWrapper) - res.status(401).end(new Buffer(JSON.stringify(payload))) + res.status(401).end(Buffer.from(JSON.stringify(payload))) }) } @@ -199,7 +199,7 @@ router._getParams = req => { router.sendResponse = (res, payload, httpCode) => { const timeDiff = (new Date()) - res._startDate metrics.processResponse(res._request, httpCode, payload, timeDiff) - res.status(httpCode).end(new Buffer(JSON.stringify(payload))) + res.status(httpCode).end(Buffer.from(JSON.stringify(payload))) } router.getExpressServer = () => { diff --git a/package.json b/package.json index 3fb81831..b485c8cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jsonapi-server", - "version": "2.3.2", + "version": "3.0.0", "description": "A config driven NodeJS framework implementing json:api", "keywords": [ "jsonapi", @@ -16,7 +16,7 @@ "url": "https://github.com/holidayextras/jsonapi-server" }, "engines": { - "node": "*" + "node": ">=4.5" }, "dependencies": { "async": "2.4.1", From a9b49faa0b898a358c653fe1b663108d7ac965d1 Mon Sep 17 00:00:00 2001 From: Pedro Romano Date: Wed, 31 May 2017 23:53:57 +0100 Subject: [PATCH 4/4] Update eslint/standard dev dependencies and fix issues. --- example/server.js | 4 ++-- lib/MemoryHandler.js | 4 ++-- lib/postProcessing/fields.js | 4 ++-- lib/postProcessing/sort.js | 2 +- lib/routes/_foreignKeySearch.js | 4 ++-- lib/routes/find.js | 2 +- lib/routes/helper.js | 6 +++--- lib/routes/related.js | 4 ++-- lib/routes/relationships.js | 4 ++-- lib/routes/removeRelation.js | 4 ++-- package.json | 6 ++++-- 11 files changed, 23 insertions(+), 21 deletions(-) diff --git a/example/server.js b/example/server.js index 1b777f11..09454b7a 100644 --- a/example/server.js +++ b/example/server.js @@ -32,10 +32,10 @@ jsonApi.setConfig({ jsonApi.authenticate((request, callback) => { // If a "blockMe" header is provided, block access. - if (request.headers.blockme) return callback('Fail') + if (request.headers.blockme) return callback(new Error('Fail')) // If a "blockMe" cookie is provided, block access. - if (request.cookies.blockMe) return callback('Fail') + if (request.cookies.blockMe) return callback(new Error('Fail')) return callback() }) diff --git a/lib/MemoryHandler.js b/lib/MemoryHandler.js index 90bef224..e50f3df4 100644 --- a/lib/MemoryHandler.js +++ b/lib/MemoryHandler.js @@ -47,7 +47,7 @@ MemoryStore.prototype.find = (request, callback) => { // If the resource doesn't exist, error if (!theResource) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '404', code: 'ENOTFOUND', title: 'Requested resource does not exist', @@ -66,7 +66,7 @@ MemoryStore.prototype.create = (request, newResource, callback) => { // Check to see if the ID already exists const index = MemoryStore._indexOf(resources[request.params.type], newResource) if (index !== -1) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '403', code: 'EFORBIDDEN', title: 'Requested resource already exists', diff --git a/lib/postProcessing/fields.js b/lib/postProcessing/fields.js index 5a62dc59..8843d543 100644 --- a/lib/postProcessing/fields.js +++ b/lib/postProcessing/fields.js @@ -11,7 +11,7 @@ fields.action = (request, response, callback) => { for (const resource in resourceList) { if (!jsonApi._resources[resource]) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '403', code: 'EFORBIDDEN', title: 'Invalid field resource', @@ -23,7 +23,7 @@ fields.action = (request, response, callback) => { for (const j of field) { if (!jsonApi._resources[resource].attributes[j]) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '403', code: 'EFORBIDDEN', title: 'Invalid field selection', diff --git a/lib/postProcessing/sort.js b/lib/postProcessing/sort.js index caa7e3c0..2e491d8f 100644 --- a/lib/postProcessing/sort.js +++ b/lib/postProcessing/sort.js @@ -12,7 +12,7 @@ sort.action = (request, response, callback) => { } if (!request.resourceConfig.attributes[attribute]) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '403', code: 'EFORBIDDEN', title: 'Invalid sort', diff --git a/lib/routes/_foreignKeySearch.js b/lib/routes/_foreignKeySearch.js index 4f0730b7..ea577744 100644 --- a/lib/routes/_foreignKeySearch.js +++ b/lib/routes/_foreignKeySearch.js @@ -30,7 +30,7 @@ foreignKeySearchRoute.register = () => { callback => { const foreignKeySchema = resourceConfig.attributes[foreignKey] if (!foreignKeySchema || !foreignKeySchema._settings) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '403', code: 'EFORBIDDEN', title: 'Invalid foreign key lookup', @@ -38,7 +38,7 @@ foreignKeySearchRoute.register = () => { }) } if (!(foreignKeySchema._settings.__one || foreignKeySchema._settings.__many)) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '403', code: 'EFORBIDDEN', title: 'Invalid foreign key lookup', diff --git a/lib/routes/find.js b/lib/routes/find.js index fa70e5f5..80040fad 100644 --- a/lib/routes/find.js +++ b/lib/routes/find.js @@ -35,7 +35,7 @@ findRoute.register = () => { }, (sanitisedData, callback) => { if (!sanitisedData) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '404', code: 'EVERSION', title: 'Resource is not valid', diff --git a/lib/routes/helper.js b/lib/routes/helper.js index bcbbfd13..3f9a8f97 100644 --- a/lib/routes/helper.js +++ b/lib/routes/helper.js @@ -13,7 +13,7 @@ helper.validate = (someObject, someDefinition, callback) => { debug.validationInput(JSON.stringify(someObject)) Joi.validate(someObject, someDefinition, { abortEarly: false }, (err, sanitisedObject) => { if (err) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '403', code: 'EFORBIDDEN', title: 'Param validation failed', @@ -27,7 +27,7 @@ helper.validate = (someObject, someDefinition, callback) => { helper.checkForBody = (request, callback) => { if (!request.params.data) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '403', code: 'EFORBIDDEN', title: 'Request validation failed', @@ -36,7 +36,7 @@ helper.checkForBody = (request, callback) => { } // data can be {} or [] both of which are typeof === 'object' if (typeof request.params.data !== 'object') { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '403', code: 'EFORBIDDEN', title: 'Request validation failed', diff --git a/lib/routes/related.js b/lib/routes/related.js index bec933f4..2a429a26 100644 --- a/lib/routes/related.js +++ b/lib/routes/related.js @@ -25,7 +25,7 @@ relatedRoute.register = () => { callback => { relation = resourceConfig.attributes[request.params.relation] if (!relation || !relation._settings || !(relation._settings.__one || relation._settings.__many)) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '404', code: 'ENOTFOUND', title: 'Resource not found', @@ -33,7 +33,7 @@ relatedRoute.register = () => { }) } if (relation._settings.__as) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '404', code: 'EFOREIGN', title: 'Relation is Foreign', diff --git a/lib/routes/relationships.js b/lib/routes/relationships.js index 537b221b..1f6fda3d 100644 --- a/lib/routes/relationships.js +++ b/lib/routes/relationships.js @@ -22,7 +22,7 @@ relationshipsRoute.register = () => { callback => { const relation = resourceConfig.attributes[request.params.relation] if (!relation || !(relation._settings.__one || relation._settings.__many)) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '404', code: 'ENOTFOUND', title: 'Resource not found', @@ -43,7 +43,7 @@ relationshipsRoute.register = () => { }, (sanitisedData, callback) => { if (!sanitisedData) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '404', code: 'EVERSION', title: 'Resource is not valid', diff --git a/lib/routes/removeRelation.js b/lib/routes/removeRelation.js index 52cdd25c..8fbcf027 100644 --- a/lib/routes/removeRelation.js +++ b/lib/routes/removeRelation.js @@ -44,7 +44,7 @@ removeRelationRoute.register = () => { for (let i = 0; i < theirs.length; i++) { if (relationType.indexOf(theirs[i].type) === -1) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '403', code: 'EFORBIDDEN', title: 'Invalid Request', @@ -54,7 +54,7 @@ removeRelationRoute.register = () => { const someId = theirs[i].id const indexOfTheirs = keys.indexOf(someId) if (indexOfTheirs === -1) { - return callback({ + return callback({ // eslint-disable-line standard/no-callback-literal status: '403', code: 'EFORBIDDEN', title: 'Invalid Request', diff --git a/package.json b/package.json index b485c8cc..f1cb3701 100644 --- a/package.json +++ b/package.json @@ -40,9 +40,11 @@ }, "devDependencies": { "eslint": "^3.6.1", - "eslint-config-standard": "^6.1.0", + "eslint-config-standard": "10.2.1", + "eslint-plugin-import": "2.3.0", + "eslint-plugin-node": "4.2.2", "eslint-plugin-promise": "^3.3.0", - "eslint-plugin-standard": "^2.0.0", + "eslint-plugin-standard": "3.0.1", "istanbul": "0.4.5", "jscpd": "0.6.11", "lokka": "1.7.0",