diff --git a/.travis.yml b/.travis.yml index 2157c2fb2..00cca6849 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ jobs: name: Unit Tests if: type = pull_request OR type = push AND branch =~ /^master|[0-9]+-(dev|stable)$/ OR type = cron language: node_js - node_js: 8 + node_js: 6 env: # Codecov token @@ -43,7 +43,7 @@ jobs: name: Integration Tests if: type = pull_request OR type = push AND branch =~ /^master|[0-9]+-(dev|stable)$/ OR type = cron language: node_js - node_js: 8 + node_js: 6 addons: apt: @@ -69,7 +69,7 @@ jobs: name: Documentation Tests if: type = pull_request OR type = push AND branch =~ /^master|[0-9]+-(dev|stable)$/ OR type = cron language: node_js - node_js: 8 + node_js: 10 before_script: - sudo apt-get install libgconf-2-4 @@ -158,7 +158,7 @@ jobs: if: tag IS present AND type != cron sudo: false language: node_js - node_js: 8 + node_js: 6 addons: apt: @@ -191,7 +191,7 @@ jobs: if: type = push && branch =~ /^[0-9]+-dev$/ sudo: false language: node_js - node_js: 8 + node_js: 6 addons: apt: diff --git a/doc/6/controllers/security/update-profile/snippets/update-profile.test.yml b/doc/6/controllers/security/update-profile/snippets/update-profile.test.yml index 153b82ecb..945d3707e 100644 --- a/doc/6/controllers/security/update-profile/snippets/update-profile.test.yml +++ b/doc/6/controllers/security/update-profile/snippets/update-profile.test.yml @@ -1,10 +1,23 @@ name: security#updateProfile -description: update profile +description: updates a security profile definition hooks: - before: > - curl -H "Content-type: application/json" -d '{ - "policies": [] - }' kuzzle:7512/profiles/myProfile/_create - after: curl -XDELETE kuzzle:7512/profiles/myProfile + before: + - > + curl -H "Content-type: application/json" -d '{ + "policies": [] + }' kuzzle:7512/profiles/myProfile/_create + - > + curl -H "Content-type: application/json" -d '{ + "controllers": { + "*": { + "actions": { + "*": true + } + } + } + }' kuzzle:7512/roles/privileged/_create + after: + - curl -XDELETE kuzzle:7512/profiles/myProfile?refresh=wait_for + - curl -XDELETE kuzzle:7512/roles/privileged template: default expected: '^ { roleId: ''privileged'', restrictedTo: \[Array\] } \] }$' diff --git a/doc/6/controllers/security/update-role/snippets/update-role.js b/doc/6/controllers/security/update-role/snippets/update-role.js index ca54743d2..642e74578 100644 --- a/doc/6/controllers/security/update-role/snippets/update-role.js +++ b/doc/6/controllers/security/update-role/snippets/update-role.js @@ -1,39 +1,36 @@ try { - const response = await kuzzle.security.updateRole( - 'read-only', - { - controllers: { - auth: { - actions: { - getCurrentUser: true, - getMyCredentials: true, - getMyRights: true, - logout: true - } - }, - collection: { - actions: { - getMapping: true, - list: true - } - }, - document: { - actions: { - count: true, - get: true, - mGet: true, - scroll: true, - search: true - } - }, - index: { - actions: { - list: true - } + const response = await kuzzle.security.updateRole('read-only', { + controllers: { + auth: { + actions: { + getCurrentUser: true, + getMyCredentials: true, + getMyRights: true, + logout: true + } + }, + collection: { + actions: { + getMapping: true, + list: true + } + }, + document: { + actions: { + count: true, + get: true, + mGet: true, + scroll: true, + search: true + } + }, + index: { + actions: { + list: true } } } - ); + }); console.log(response); /* diff --git a/doc/6/controllers/security/update-role/snippets/update-role.test.yml b/doc/6/controllers/security/update-role/snippets/update-role.test.yml index e865c6c1b..5a9f5472f 100644 --- a/doc/6/controllers/security/update-role/snippets/update-role.test.yml +++ b/doc/6/controllers/security/update-role/snippets/update-role.test.yml @@ -4,9 +4,9 @@ hooks: before: > curl -f -H "Content-type: application/json" -d '{ "controllers": { - "*": { + "auth": { "actions": { - "*": false + "login": true } } } diff --git a/doc/6/controllers/server/get-config/snippets/get-config.test.yml b/doc/6/controllers/server/get-config/snippets/get-config.test.yml index 9d79d6cfa..55cca6169 100644 --- a/doc/6/controllers/server/get-config/snippets/get-config.test.yml +++ b/doc/6/controllers/server/get-config/snippets/get-config.test.yml @@ -4,7 +4,6 @@ hooks: before: after: template: default -expected: ^(Kuzzle Server configuration:) {("dump":{.*}),("limits":{.*}),("plugins":{.*}),("queues":{.*}),("repositories":{.*}),("server":{.*}),("services":{.*}),("stats":{.*}),("validation":{.*}),("_":.*),("internal":{.*}),("version":"[0-9]\.[0-9]\.[0-9]")}$ - +expected: ^(Kuzzle Server configuration:) {("dump":{.*}),("limits":{.*}),("plugins":{.*}),("queues":{.*}),("repositories":{.*}),("server":{.*}),("services":{.*}),("stats":{.*}),("validation":{.*}),("_":.*),("internal":{.*}),("version":"[0-9]+\.[0-9]+\.[0-9]+")}$ sdk: js version: 6 diff --git a/doc/6/controllers/server/info/snippets/info.test.yml b/doc/6/controllers/server/info/snippets/info.test.yml index f33e1acc7..154a171d8 100644 --- a/doc/6/controllers/server/info/snippets/info.test.yml +++ b/doc/6/controllers/server/info/snippets/info.test.yml @@ -4,6 +4,6 @@ hooks: before: after: template: default -expected: "^Kuzzle Server information: {\"serverInfo\":{\"kuzzle\":{\"version\":\"[0-9]\\.[0-9]\\.[0-9]\",\"api\":{.*" +expected: "^Kuzzle Server information: {\"serverInfo\":{\"kuzzle\":{\"version\":\"[0-9]+\\.[0-9]+\\.[0-9]+\",\"api\":{.*" sdk: js version: 6 diff --git a/features/steps/auth.js b/features/steps/auth.js index b61abb20a..a8d4d2316 100644 --- a/features/steps/auth.js +++ b/features/steps/auth.js @@ -3,22 +3,19 @@ const should = require('should'), retry = require('retry'); -Given('I log in as {string}:{string}', async function (username, password) { - try { - this.jwt = await this.kuzzle.auth.login('local', { - username, - password +Given('I log in as {string}:{string}', function (username, password) { + return this.kuzzle.auth.login('local', { username, password }) + .then(jwt => { + this.jwt = jwt; + }) + .catch(error => { + this.jwt = 'invalid'; + this.error = error; }); - this.error = null; - } - catch (error) { - this.jwt = 'invalid'; - this.error = error; - } }); -When('I logout', async function () { - await this.kuzzle.auth.logout(); +When('I logout', function () { + return this.kuzzle.auth.logout(); }); When('I refresh the JWT', function (cb) { @@ -27,11 +24,16 @@ When('I refresh the JWT', function (cb) { // we have to wait for at least 1s: if we ask Kuzzle to refresh a JWT that // has been generated during the same second, then the new JWT will be // identical to the one being refreshed - setTimeout(async () => { - const token = await this.kuzzle.auth.refreshToken(); - this.jwt = token.jwt; - cb(); - }, 1000); + setTimeout( + () => { + this.kuzzle.auth.refreshToken() + .then(token => { + this.jwt = token.jwt; + cb(); + }) + .catch(err => cb(err)); + }, + 1000); }); Then('the previous JWT is now invalid', function (cb) { @@ -56,19 +58,23 @@ Then('the previous JWT is now invalid', function (cb) { }); }); -Then(/^the JWT is (in)?valid$/, async function (not) { - const response = await this.kuzzle.auth.checkToken(this.jwt); - - if (not) { - should(response.valid).be.false(); - } - else { - should(response.valid).be.true(); - } +Then(/^the JWT is (in)?valid$/, function (not) { + return this.kuzzle.auth.checkToken(this.jwt) + .then(response => { + if (not) { + should(response.valid).be.false(); + } + else { + should(response.valid).be.true(); + } + }); }); -Given('I get my rights', async function () { - this.rights = await this.kuzzle.auth.getMyRights(); +Given('I get my rights', function () { + return this.kuzzle.auth.getMyRights() + .then(rights => { + this.rights = rights; + }); }); Then('I have a vector with {int} rights', function (nbRights) { diff --git a/features/steps/collection.js b/features/steps/collection.js index 202d1906a..f80a7ebb5 100644 --- a/features/steps/collection.js +++ b/features/steps/collection.js @@ -1,135 +1,148 @@ const { Given, When, Then } = require('cucumber'); const should = require('should'); -Given('has specifications', async function () { - await this.kuzzle.collection.updateSpecifications(this.index, this.collection, {strict: true}); +Given('has specifications', function () { + return this.kuzzle.collection.updateSpecifications( + this.index, + this.collection, + { strict: true }); }); -Given('it has a collection {string}', async function (collection) { - await this.kuzzle.collection.create(this.index, collection); - this.collection = collection; +Given('it has a collection {string}', function (collection) { + return this.kuzzle.collection.create(this.index, collection) + .then(() => { + this.collection = collection; + }); }); -Given('I truncate the collection {string}', async function (collection) { - await this.kuzzle.collection.truncate(this.index, collection, {refresh: 'wait_for'}); +Given('I truncate the collection {string}', function (collection) { + return this.kuzzle.collection.truncate( + this.index, + collection, + { refresh: 'wait_for' }); }); -When('I check if the collection {string} exists', async function (collection) { - try { - this.content = await this.kuzzle.collection.exist(this.index, collection); - } - catch (error) { - this.error = error; - } +When('I check if the collection {string} exists', function (collection) { + return this.kuzzle.collection.exists(this.index, collection) + .then(content => { + this.content = content; + }) + .catch(error => { + this.error = error; + }); }); -When(/^I create a collection '(.*?)'( with a mapping)?$/, async function (collection, withMapping) { - try { - const mapping = { - properties: { - gordon: {type: 'keyword'} - } - }; - - this.content = await this.kuzzle.collection.create( - this.index, - collection, - withMapping ? mapping : undefined - ); - } - catch (error) { - this.error = error; - } +When(/^I create a collection '(.*?)'( with a mapping)?$/, function (collection, withMapping) { + const mapping = withMapping + ? { properties: { gordon: {type: 'keyword'} } } + : undefined; + return this.kuzzle.collection.create(this.index, collection, mapping) + .then(content => { + this.content = content; + }) + .catch (error => { + this.error = error; + }); }); -When('I delete the specifications of {string}', async function (collection) { - try { - await this.kuzzle.collection.deleteSpecifications(this.index, collection); - } - catch (error) { - this.error = error; - } - +When('I delete the specifications of {string}', function (collection) { + return this.kuzzle.collection.deleteSpecifications(this.index, collection) + .catch(error => { + this.error = error; + }); }); -When('I list the collections of {string}', async function (index) { - try { - this.content = await this.kuzzle.collection.list(index); - this.total = this.content.collections.length; - } - catch (error) { - this.error = error; - } +When('I list the collections of {string}', function (index) { + return this.kuzzle.collection.list(index) + .then(content => { + this.content = content; + this.total = this.content.collections.length; + }) + .catch(error => { + this.error = error; + }); }); -When('I update the mapping of collection {string}', async function (collection) { - try { - this.content = await this.kuzzle.collection.updateMapping(this.index, collection, { +When('I update the mapping of collection {string}', function (collection) { + return this.kuzzle.collection + .updateMapping(this.index, collection, { properties: { gordon: {type: 'keyword'} } + }) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; }); - } - catch (error) { - this.error = error; - } - }); -When('I update the specifications of the collection {string}', async function (collection) { - try { - this.content = await this.kuzzle.collection.updateSpecifications(this.index, collection, {strict: false}); - } - catch (error) { - this.error = error; - } +When('I update the specifications of the collection {string}', function (collection) { + return this.kuzzle.collection + .updateSpecifications(this.index, collection, {strict: false}) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); }); -When('I validate the specifications of {string}', async function (collection) { - this.content = await this.kuzzle.collection.validateSpecifications(this.index, collection, {strict: true}); +When('I validate the specifications of {string}', function (collection) { + return this.kuzzle.collection + .validateSpecifications(this.index, collection, {strict: true}) + .then(content => { + this.content = content; + }); }); -Then('the collection {string} should be empty', async function (collection) { - const result = await this.kuzzle.document.search(this.index, collection, {}); - should(result.total).eql(0); -}); - -Then(/^the collection(?: '(.*?)')? should exist$/, async function (collection) { - if (!collection) { - collection = this.collection; - } - const exists = await this.kuzzle.collection.exists(this.index, collection); - should(exists).be.true(); +Then('the collection {string} should be empty', function (collection) { + return this.kuzzle.document.search(this.index, collection, {}) + .then(result => should(result.total).eql(0)); }); -Then('the mapping of {string} should be updated', async function (collection) { - const mapping = await this.kuzzle.collection.getMapping(this.index, collection); +Then(/^the collection(?: '(.*?)')? should exist$/, function (collection) { + const c = collection || this.collection; - should(mapping[this.index].mappings[collection]).eql({ - dynamic: 'true', - properties: { - gordon: {type: 'keyword'} - } - }); + return this.kuzzle.collection.exists(this.index, c) + .then(exists => should(exists).be.true()); }); -Then('the specifications of {string} should be updated', async function (collection) { - const specifications = await this.kuzzle.collection.getSpecifications(this.index, collection); +Then('the mapping of {string} should be updated', function (collection) { + return this.kuzzle.collection.getMapping(this.index, collection) + .then(mapping => { + should(mapping[this.index].mappings[collection]).eql({ + dynamic: 'true', + properties: { + gordon: {type: 'keyword'} + } + }); + }); +}); - should(specifications.validation).eql({strict: false}); +Then('the specifications of {string} should be updated', function (collection) { + return this.kuzzle.collection.getSpecifications(this.index, collection) + .then(specifications => { + should(specifications.validation).eql({strict: false}); + }); }); -Then('the specifications of {string} must not exist', async function (collection) { - try { - await this.kuzzle.collection.getSpecifications(this.index, collection); - should(true).be.false(); - } - catch (error) { - should(error.status).eql(404); - } +Then('the specifications of {string} must not exist', function (collection, cb) { + this.kuzzle.collection.getSpecifications(this.index, collection) + .then(() => cb(new Error('Expected promise to be rejected'))) + .catch(error => { + try { + should(error.status).eql(404); + cb(); + } + catch (e) { + cb(e); + } + }); }); Then('they should be validated', function () { diff --git a/features/steps/document.js b/features/steps/document.js index 922daefb9..8f58873db 100644 --- a/features/steps/document.js +++ b/features/steps/document.js @@ -1,65 +1,80 @@ const { Given, When, Then } = require('cucumber'); const should = require('should'); -Given(/^the collection doesn't have a document with id '(.*?)'$/, async function (id) { - try { - this.content = await this.kuzzle.document.delete(this.index, this.collection, id); - } - catch (error) { - this.error = error; - } -}); - -Given('the collection has a document with id {string}', async function (id) { - this.content = await this.kuzzle.document.create( - this.index, - this.collection, - { a: 'document' }, - id, - { refresh: 'wait_for'} - ); +Given(/^the collection doesn't have a document with id '(.*?)'$/, function (id) { + return this.kuzzle.document.delete(this.index, this.collection, id) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); +}); + +Given('the collection has a document with id {string}', function (id) { + return this.kuzzle.document + .create( + this.index, + this.collection, + { a: 'document' }, + id, + { refresh: 'wait_for'}) + .then(content => { + this.content = content; + }); }); -When('I check if {string} exists', async function (id) { - this.content = await this.kuzzle.document.exists(this.index, this.collection, id); +When('I check if {string} exists', function (id) { + return this.kuzzle.document.exists(this.index, this.collection, id) + .then(content => { + this.content = content; + }); }); -When('I count how many documents there is in the collection', async function () { - this.content = await this.kuzzle.document.count(this.index, this.collection, {}); +When('I count how many documents there is in the collection', function () { + return this.kuzzle.document.count(this.index, this.collection, {}) + .then(content => { + this.content = content; + }); }); -When('I create a document in {string}', async function (collection) { - this.content = await this.kuzzle.document.create( - this.index, - collection, - {a: 'document'}, - 'some-id', - {refresh: true} - ); +When('I create a document in {string}', function (collection) { + return this.kuzzle.document + .create( + this.index, + collection, + {a: 'document'}, + 'some-id', + {refresh: true}) + .then(content => { + this.content = content; + }); }); -When('I create a document with id {string}', async function (id) { +When('I create a document with id {string}', function (id) { this.ids = [id]; - try { - this.content = await this.kuzzle.document.create( + return this.kuzzle.document + .create( this.index, this.collection, {a: 'document'}, id, - {refresh: true}); - } - catch (error) { - this.error = error; - } + {refresh: true}) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); }); -When('I create the documents [{string}, {string}]', async function (id1, id2) { +When('I create the documents [{string}, {string}]', function (id1, id2) { this.ids = [id1, id2]; - try { - this.content = await this.kuzzle.document.mCreate( + return this.kuzzle.document + .mCreate( this.index, this.collection, [ @@ -68,37 +83,38 @@ When('I create the documents [{string}, {string}]', async function (id1, id2) { ], { refresh: 'wait_for' - } - ); - } - catch (error) { - this.error = error; - } - + }) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); }); -When('I createOrReplace a document with id {string}', async function (id) { +When('I createOrReplace a document with id {string}', function (id) { this.ids = [id]; - try { - this.content = await this.kuzzle.document.createOrReplace( + return this.kuzzle.document + .createOrReplace( this.index, this.collection, id, {a: 'replaced document'}, - {refresh: true} - ); - } - catch (error) { - this.error = error; - } + {refresh: true}) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); }); -When('I createOrReplace the documents [{string}, {string}]', async function (id1, id2) { +When('I createOrReplace the documents [{string}, {string}]', function (id1, id2) { this.ids = [id1, id2]; - try { - this.content = await this.kuzzle.document.mCreateOrReplace( + return this.kuzzle.document + .mCreateOrReplace( this.index, this.collection, [ @@ -107,85 +123,93 @@ When('I createOrReplace the documents [{string}, {string}]', async function (id1 ], { refresh: 'wait_for' - } - ); - } - catch (error) { - this.error = error; - } + }) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); }); -When('I delete the document with id {string}', async function (id) { +When('I delete the document with id {string}', function (id) { this.ids = [id]; - try { - this.content = await this.kuzzle.document.delete(this.index, this.collection, id); - } - catch (error) { - this.error = error; - } + return this.kuzzle.document.delete(this.index, this.collection, id) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); }); -When('I delete the documents [{string}, {string}]', async function (id1, id2) { +When('I delete the documents [{string}, {string}]', function (id1, id2) { this.ids = [id1, id2]; - try { - this.content = await this.kuzzle.document.mDelete( + return this.kuzzle.document + .mDelete( this.index, this.collection, [id1, id2], - {refresh: true} - ); - } - catch (error) { - this.error = error; - } + {refresh: true}) + .then(content => { + this.content = content; + }) + .catch(error => { + this.error = error; + }); }); -When('I replace a document with id {string}', async function (id) { +When('I replace a document with id {string}', function (id) { this.ids = [id]; - try { - this.content = await this.kuzzle.document.replace( + return this.kuzzle.document + .replace( this.index, this.collection, id, {a: 'replaced document'}, - {refresh: true} - ); - } - catch (error) { - this.error = error; - } + {refresh: true}) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); }); -When('I replace the documents [{string}, {string}]', async function (id1, id2) { +When('I replace the documents [{string}, {string}]', function (id1, id2) { this.ids = [id1, id2]; - try { - this.content = await this.kuzzle.document.mReplace( + return this.kuzzle.document + .mReplace( this.index, this.collection, [ {_id: id1, body: {a: 'replaced document'}}, {_id: id2, body: {a: 'replaced document'}} ], - {refresh: true} - ); - } - catch (error) { - this.error = error; - } + {refresh: true}) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); }); -When('I get documents [{string}, {string}]', async function (id1, id2) { +When('I get documents [{string}, {string}]', function (id1, id2) { this.ids = [id1, id2]; - this.content = await this.kuzzle.document.mGet(this.index, this.collection, [id1, id2]); + return this.kuzzle.document.mGet(this.index, this.collection, [id1, id2]) + .then(content => { + this.content = content; + }); }); -When('I search a document with id {string}', async function (id) { - try { - this.content = await this.kuzzle.document.search( +When('I search a document with id {string}', function (id) { + return this.kuzzle.document + .search( this.index, this.collection, { @@ -194,71 +218,81 @@ When('I search a document with id {string}', async function (id) { _id: id } } - }); - } - catch (error) { - this.error = error; - } -}); - -When('I search documents matching {string} with from {int} and size {int}', async function (query, from, size) { - this.content = await this.kuzzle.document.search( - this.index, - this.collection, - JSON.parse(query), - { - from, - size - } - ); + }) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); +}); + +When('I search documents matching {string} with from {int} and size {int}', function (query, from, size) { + return this.kuzzle.document + .search( + this.index, + this.collection, + JSON.parse(query), + { from, size }) + .then(content => { + this.content = content; + }); }); -When('I search the next documents', async function () { - this.content = await this.content.next(); +When('I search the next documents', function () { + return this.content.next() + .then(content => { + this.content = content; + }); }); -When('I update a document with id {string}', async function (id) { +When('I update a document with id {string}', function (id) { this.ids = [id]; - try { - this.content = await this.kuzzle.document.update( + return this.kuzzle.document + .update( this.index, this.collection, id, - {some: 'update'} - ); - } - catch (error) { - this.error = error; - } -}); - -When('I update the document with id {string} and content {string} = {string}', async function (id, key, val) { - this.content = await this.kuzzle.document.update( - this.index, - this.collection, - id, - {[key]: val} - ); + {some: 'update'}) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); +}); + +When('I update the document with id {string} and content {string} = {string}', function (id, key, val) { + return this.kuzzle.document + .update( + this.index, + this.collection, + id, + { [key]: val }) + .then(content => { + this.content = content; + }); }); -When('I update the documents [{string}, {string}]', async function (id1, id2) { +When('I update the documents [{string}, {string}]', function (id1, id2) { this.ids = [id1, id2]; - try { - this.content = await this.kuzzle.document.mUpdate( + return this.kuzzle.document + .mUpdate( this.index, this.collection, [ {_id: id1, body: {a: 'replaced document', some: 'update'}}, {_id: id2, body: {a: 'replaced document', some: 'update'}} ], - {refresh: true} - ); - } - catch (error) { - this.error = error; - } + { refresh: true }) + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); }); @@ -267,26 +301,28 @@ Then('I get an error with message {string}', function (message) { should(this.error.message).eql(message); }); -Then('I must have {int} documents in the collection', async function (number) { - const count = await this.kuzzle.document.count(this.index, this.collection, {}); - should(count).eql(number); +Then('I must have {int} documents in the collection', function (number) { + return this.kuzzle.document.count(this.index, this.collection, {}) + .then(count => should(count).eql(number)); }); -Then('the document is successfully created', async function () { - const document = await this.kuzzle.document.get(this.index, this.collection, this.ids[0]); - should(document) - .be.an.Object(); +Then('the document is successfully created', function () { + return this.kuzzle.document.get(this.index, this.collection, this.ids[0]) + .then(document => should(document).be.an.Object()); }); -Then('the document is successfully deleted', async function () { - try { - await this.kuzzle.document.get(this.index, this.collection, this.ids[0]); - // should fail - should(true).be.false(); - } - catch (error) { - should(error.status).eql(404); - } +Then('the document is successfully deleted', function (cb) { + this.kuzzle.document.get(this.index, this.collection, this.ids[0]) + .then(() => cb(new Error('Expected promise to be rejected'))) + .catch(error => { + try { + should(error.status).eql(404); + cb(); + } + catch (e) { + cb(e); + } + }); }); Then(/^the document is (successfully|not) found$/, function (yesno) { @@ -295,36 +331,29 @@ Then(/^the document is (successfully|not) found$/, function (yesno) { should(this.content.total).eql(yesno === 'successfully' ? 1 : 0); }); -Then('the document is successfully replaced', async function () { - const document = await this.kuzzle.document.get(this.index, this.collection, this.ids[0]); - should(document._source.a).eql('replaced document'); +Then('the document is successfully replaced', function () { + return this.kuzzle.document.get(this.index, this.collection, this.ids[0]) + .then(document => should(document._source.a).eql('replaced document')); }); -Then('the document is successfully updated', async function () { - const document = await this.kuzzle.document.get(this.index, this.collection, this.ids[0]); - - should(document._source.some).eql('update'); +Then('the document is successfully updated', function () { + return this.kuzzle.document.get(this.index, this.collection, this.ids[0]) + .then(document => should(document._source.some).eql('update')); }); -Then('the document {string} should be created', async function (id) { - const document = await this.kuzzle.document.get(this.index, this.collection, id); - - should(document) - .not.be.null(); +Then('the document {string} should be created', function (id) { + return this.kuzzle.document.get(this.index, this.collection, id) + .then(document => should(document).not.be.null()); }); -Then('the document {string} should be replaced', async function (id) { - const document = await this.kuzzle.document.get(this.index, this.collection, id); - - should(document._source.a) - .eql('replaced document'); +Then('the document {string} should be replaced', function (id) { + return this.kuzzle.document.get(this.index, this.collection, id) + .then(document => should(document._source.a).eql('replaced document')); }); -Then('the document {string} should be updated', async function (id) { - const document = await this.kuzzle.document.get(this.index, this.collection, id); - - should(document._source.some) - .eql('update'); +Then('the document {string} should be updated', function (id) { + return this.kuzzle.document.get(this.index, this.collection, id) + .then(document => should(document._source.some).eql('update')); }); Then(/^the document should (not )?exist$/, function (not) { diff --git a/features/steps/index.js b/features/steps/index.js index e88a51774..451269e7c 100644 --- a/features/steps/index.js +++ b/features/steps/index.js @@ -1,68 +1,84 @@ const { Given, When, Then } = require('cucumber'); const should = require('should'); -Given('there is an index {string}', async function (index) { - exists = await this.kuzzle.index.exists(index); +Given('there is an index {string}', function (index) { + return this.kuzzle.index.exists(index) + .then(exists => { + if (!exists) { + return this.kuzzle.index.create(index); + } - if (!exists) { - await this.kuzzle.index.create(index); - } - - this.index = index; + return null; + }) + .then(() => { + this.index = index; + }); }); -Given('there is no index called {string}', async function (index) { - try { - this.content = await this.kuzzle.index.delete(index); - } - catch (error) { - // do nothing - } +Given('there is no index called {string}', function (index) { + return this.kuzzle.index.delete(index) + .then(content => { + this.content = content; + }) + .catch(() => { /* do nothing */ }); }); -Given('there is the indexes {string} and {string}', async function (index1, index2) { - for (const index of [index1, index2]) { - const exists = await this.kuzzle.index.exists(index); - +Given('there is the indexes {string} and {string}', function (index1, index2) { + const createIndex = (index, exists) => { if (!exists) { - await this.kuzzle.index.create(index); + return this.kuzzle.index.create(index); } - } + + return null; + }; + + return this.kuzzle.index.exists(index1) + .then(exists => createIndex(index1, exists)) + .then(() => this.kuzzle.index.exists(index2)) + .then(exists => createIndex(index2, exists)); }); -When('I create an index called {string}', async function (index) { - try { - this.content = await this.kuzzle.index.create(index); - this.index = index; - } - catch (error) { - this.error = error; - } +When('I create an index called {string}', function (index) { + return this.kuzzle.index.create(index) + .then(content => { + this.content = content; + this.index = index; + }) + .catch(err => { + this.error = err; + }); }); -When('I delete the indexes {string} and {string}', async function (index1, index2) { - this.content = await this.kuzzle.index.mDelete([index1, index2]); +When('I delete the indexes {string} and {string}', function (index1, index2) { + return this.kuzzle.index.mDelete([index1, index2]) + .then(content => { + this.content = content; + }); }); -When('I list indexes', async function () { - try { - this.content = await this.kuzzle.index.list(); - } - catch (error) { - this.error = error; - } +When('I list indexes', function () { + return this.kuzzle.index.list() + .then(content => { + this.content = content; + }) + .catch(err => { + this.error = err; + }); }); -Then('the index should exist', async function () { - const exists = await this.kuzzle.index.exists(this.index); - should(exists).be.true(); +Then('the index should exist', function () { + return this.kuzzle.index.exists(this.index) + .then(exists =>should(exists).be.true()); }); -Then('indexes {string} and {string} don\'t exist', async function (index1, index2) { - for (const index of [index1, index2]) { - const exists = await this.kuzzle.index.exists(index); - should(exists).be.false(); - } +Then('indexes {string} and {string} don\'t exist', function (index1, index2) { + const check = index => { + return this.kuzzle.index.exists(index) + .then(exists => should(exists).be.false()); + }; + + return check(index1) + .then(() => check(index2)); }); diff --git a/features/steps/realtime.js b/features/steps/realtime.js index b8ee6007b..058e062d0 100644 --- a/features/steps/realtime.js +++ b/features/steps/realtime.js @@ -1,20 +1,24 @@ const {Given, When, Then} = require('cucumber'); const should = require('should'); -Given(/^I subscribe to '(.*?)'(?: with '(.*)' as filter)?$/, async function (collection, filter) { +Given(/^I subscribe to '(.*?)'(?: with '(.*)' as filter)?$/, function (collection, filter) { if (!filter) { filter = '{}'; } - this.content = await this.kuzzle.realtime.subscribe(this.index, collection, JSON.parse(filter), this.callback); + return this.kuzzle.realtime + .subscribe(this.index, collection, JSON.parse(filter), this.callback) + .then(content => { + this.content = content; + }); }); -Given('I unsubscribe', async function () { - await this.kuzzle.realtime.unsubscribe(this.content); +Given('I unsubscribe', function () { + return this.kuzzle.realtime.unsubscribe(this.content); }); -When('I publish a document', async function () { - await this.kuzzle.realtime.publish(this.index, this.collection, { +When('I publish a document', function () { + return this.kuzzle.realtime.publish(this.index, this.collection, { a: 'document' }); }); @@ -22,14 +26,24 @@ When('I publish a document', async function () { Then('I receive a notification', function (cb) { setTimeout(() => { - should(this.notifications.length).eql(1); - cb(); + try { + should(this.notifications.length).eql(1); + cb(); + } + catch (e) { + cb(e); + } }, 1000); }); Then('I do not receive a notification', function (cb) { setTimeout(() => { - should(this.notifications.length).eql(0); - cb(); + try { + should(this.notifications.length).eql(0); + cb(); + } + catch (e) { + cb(e); + } }, 1000); }); diff --git a/features/steps/security.js b/features/steps/security.js index da0c8c0d2..2ec6166a0 100644 --- a/features/steps/security.js +++ b/features/steps/security.js @@ -1,47 +1,47 @@ const {Given, When} = require('cucumber'); -Given('there is an user with id {string}', async function (id) { +Given('there is an user with id {string}', function (id) { this.user = id; - try { - await this.kuzzle.security.createOrReplaceProfile('test', { - policies: [{roleId: 'admin'}] - }); - - this.content = await this.kuzzle.security.createUser(id, { + return this.kuzzle.security + .createOrReplaceProfile( + 'test', + { policies: [{roleId: 'admin'}] }) + .then(() => this.kuzzle.security.createUser(id, { content: { profileIds: ['test'] }, credentials: {} - }); - } - catch (error) { - // do nothing - } + })) + .then(content => { + this.content = content; + }) + .catch(() => { /* do nothing */ }); }); -Given('the user has {string} credentials with name {string} and password {string}', async function (strategy, username, password) { - try { - await this.kuzzle.security.createCredentials( +Given('the user has {string} credentials with name {string} and password {string}', function (strategy, username, password) { + return this.kuzzle.security + .createCredentials( strategy, this.user, - { username, password }); - } - catch (error) { - await this.kuzzle.security.updateCredentials( + { username, password }) + .catch(() => this.kuzzle.security.updateCredentials( strategy, this.user, - { username, password }); - } + { username, password })); }); -When('I get my user info', async function () { - this.content = await this.kuzzle.security.getUser(this.user); +When('I get my user info', function () { + return this.kuzzle.security.getUser(this.user) + .then(content => { + this.content = content; + }); }); -When('I update my user custom data with the pair {string}:{string}', async function (key, val) { - this.content = await this.kuzzle.security.updateUser(this.user, { - [key]: val - }); +When('I update my user custom data with the pair {string}:{string}', function (key, val) { + return this.kuzzle.security.updateUser(this.user, { [key]: val }) + .then(content => { + this.content = content; + }); }); diff --git a/features/support/hooks.js b/features/support/hooks.js index d913f0669..e36da61f6 100644 --- a/features/support/hooks.js +++ b/features/support/hooks.js @@ -2,9 +2,9 @@ const { Before, AfterAll, BeforeAll } = require('cucumber'); let _world; -Before(async function () { +Before(function () { _world = this; - await clean(); + return clean(); }); BeforeAll(function () { @@ -19,26 +19,21 @@ BeforeAll(function () { this.notifications = []; }); -AfterAll(async function () { - await clean(); +AfterAll(function () { + return clean(); }); -async function clean () { +function clean () { const kuzzle = _world.kuzzle; - try { - await kuzzle.connect(); - const indices = await kuzzle.index.list(); - - for (const index of indices) { - await kuzzle.index.delete(index); - } - } - catch (error) { - // rethrow to get a readable error - // eslint-disable-next-line no-console - console.error(error); - throw error; - } + return kuzzle.connect() + .then(() => kuzzle.index.list()) + .then(indices => Promise.all(indices.map(i => kuzzle.index.delete(i)))) + .catch(error => { + // rethrow to get a readable error + // eslint-disable-next-line no-console + console.error(error); + throw error; + }); } diff --git a/package-lock.json b/package-lock.json index 459660593..9ab7562bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "kuzzle-sdk", - "version": "6.2.3", + "version": "6.2.4", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2535,48 +2535,47 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "eslint": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.3.0.tgz", - "integrity": "sha512-ZvZTKaqDue+N8Y9g0kp6UPZtS4FSY3qARxBs7p4f0H0iof381XHduqVerFWtK8DPtKmemqbqCFENWSQgPR/Gow==", + "version": "5.16.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.16.0.tgz", + "integrity": "sha512-S3Rz11i7c8AA5JPv7xAH+dOyq/Cu/VXHiHXBPOU1k/JAM5dXqQPt3qcrhpHSorXmrpu2g0gkIBVXAqCpzfoZIg==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", - "ajv": "^6.10.0", + "ajv": "^6.9.1", "chalk": "^2.1.0", "cross-spawn": "^6.0.5", "debug": "^4.0.1", "doctrine": "^3.0.0", - "eslint-scope": "^5.0.0", - "eslint-utils": "^1.4.2", - "eslint-visitor-keys": "^1.1.0", - "espree": "^6.1.1", + "eslint-scope": "^4.0.3", + "eslint-utils": "^1.3.1", + "eslint-visitor-keys": "^1.0.0", + "espree": "^5.0.1", "esquery": "^1.0.1", "esutils": "^2.0.2", "file-entry-cache": "^5.0.1", "functional-red-black-tree": "^1.0.1", - "glob-parent": "^5.0.0", + "glob": "^7.1.2", "globals": "^11.7.0", "ignore": "^4.0.6", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", - "inquirer": "^6.4.1", - "is-glob": "^4.0.0", - "js-yaml": "^3.13.1", + "inquirer": "^6.2.2", + "js-yaml": "^3.13.0", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.3.0", - "lodash": "^4.17.14", + "lodash": "^4.17.11", "minimatch": "^3.0.4", "mkdirp": "^0.5.1", "natural-compare": "^1.4.0", "optionator": "^0.8.2", + "path-is-inside": "^1.0.2", "progress": "^2.0.0", "regexpp": "^2.0.1", - "semver": "^6.1.2", - "strip-ansi": "^5.2.0", - "strip-json-comments": "^3.0.1", + "semver": "^5.5.1", + "strip-ansi": "^4.0.0", + "strip-json-comments": "^2.0.1", "table": "^5.2.3", - "text-table": "^0.2.0", - "v8-compile-cache": "^2.0.3" + "text-table": "^0.2.0" }, "dependencies": { "ajv": { @@ -2592,9 +2591,9 @@ } }, "ansi-regex": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", - "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", "dev": true }, "ansi-styles": { @@ -2626,22 +2625,6 @@ "esutils": "^2.0.2" } }, - "eslint-scope": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.0.0.tgz", - "integrity": "sha512-oYrhJW7S0bxAFDvWqzvMPRm6pcgcnWc4QnofCAqRTRfQC0JcwenzGglTtsLyIuuWFfkqDG9vz67cnttSd53djw==", - "dev": true, - "requires": { - "esrecurse": "^4.1.0", - "estraverse": "^4.1.1" - } - }, - "eslint-visitor-keys": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz", - "integrity": "sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==", - "dev": true - }, "fast-deep-equal": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", @@ -2668,25 +2651,6 @@ "write": "1.0.3" } }, - "glob-parent": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.0.0.tgz", - "integrity": "sha512-Z2RwiujPRGluePM6j699ktJYxmPpJKCfpGA13jz2hmFZC7gKetzrWvg5KN3+OsIFmydGyZ1AVwERCq1w/ZZwRg==", - "dev": true, - "requires": { - "is-glob": "^4.0.1" - } - }, - "js-yaml": { - "version": "3.13.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", - "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", - "dev": true, - "requires": { - "argparse": "^1.0.7", - "esprima": "^4.0.0" - } - }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -2702,27 +2666,15 @@ "glob": "^7.1.3" } }, - "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "dev": true - }, "strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", "dev": true, "requires": { - "ansi-regex": "^4.1.0" + "ansi-regex": "^3.0.0" } }, - "strip-json-comments": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.0.1.tgz", - "integrity": "sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw==", - "dev": true - }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -2810,57 +2762,16 @@ } }, "eslint-loader": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/eslint-loader/-/eslint-loader-3.0.0.tgz", - "integrity": "sha512-rdxyQ0i9VlhwVlR6oEzrIft8WNKYSD2/cOAJ1YVH/F76gAta7Zv1Dr5xJOUyx0fAsHB5cKNz9hwlUVLMFsQlPA==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/eslint-loader/-/eslint-loader-2.2.1.tgz", + "integrity": "sha512-RLgV9hoCVsMLvOxCuNjdqOrUqIj9oJg8hF44vzJaYqsAHuY9G2YAeN3joQ9nxP0p5Th9iFSIpKo+SD8KISxXRg==", "dev": true, "requires": { - "loader-fs-cache": "^1.0.2", - "loader-utils": "^1.2.3", - "object-hash": "^1.3.1", - "schema-utils": "^2.1.0" - }, - "dependencies": { - "ajv": { - "version": "6.10.2", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.2.tgz", - "integrity": "sha512-TXtUUEYHuaTEbLZWIKUr5pmBuhDLy+8KYtPYdcV8qC+pOZL+NKqYwvWSRrVXHn+ZmRRAu8vJTAznH7Oag6RVRw==", - "dev": true, - "requires": { - "fast-deep-equal": "^2.0.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" - } - }, - "ajv-keywords": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.4.1.tgz", - "integrity": "sha512-RO1ibKvd27e6FEShVFfPALuHI3WjSVNeK5FIsmme/LYRNxjKuNj+Dt7bucLa6NdSv3JcVTyMlm9kGR84z1XpaQ==", - "dev": true - }, - "fast-deep-equal": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", - "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", - "dev": true - }, - "json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true - }, - "schema-utils": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-2.2.0.tgz", - "integrity": "sha512-5EwsCNhfFTZvUreQhx/4vVQpJ/lnCAkgoIHLhSpp4ZirE+4hzFvdJi0FMub6hxbFVBJYSpeVVmon+2e7uEGRrA==", - "dev": true, - "requires": { - "ajv": "^6.10.2", - "ajv-keywords": "^3.4.1" - } - } + "loader-fs-cache": "^1.0.0", + "loader-utils": "^1.0.2", + "object-assign": "^4.0.1", + "object-hash": "^1.1.4", + "rimraf": "^2.6.1" } }, "eslint-scope": { @@ -2888,26 +2799,20 @@ "dev": true }, "espree": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-6.1.1.tgz", - "integrity": "sha512-EYbr8XZUhWbYCqQRW0duU5LxzL5bETN6AjKBGy1302qqzPaCH10QbRg3Wvco79Z8x9WbiE8HYB4e75xl6qUYvQ==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-5.0.1.tgz", + "integrity": "sha512-qWAZcWh4XE/RwzLJejfcofscgMc9CamR6Tn1+XRXNzrvUSSbiAjGOI/fggztjIi7y9VLPqnICMIPiGyr8JaZ0A==", "dev": true, "requires": { - "acorn": "^7.0.0", - "acorn-jsx": "^5.0.2", - "eslint-visitor-keys": "^1.1.0" + "acorn": "^6.0.7", + "acorn-jsx": "^5.0.0", + "eslint-visitor-keys": "^1.0.0" }, "dependencies": { "acorn": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.0.0.tgz", - "integrity": "sha512-PaF/MduxijYYt7unVGRuds1vBC9bFxbNf+VWqhOClfdgy7RlVkQqt610ig1/yxTgsDIfW1cWDel5EBbOy3jdtQ==", - "dev": true - }, - "eslint-visitor-keys": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz", - "integrity": "sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==", + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.3.0.tgz", + "integrity": "sha512-/czfa8BwS88b9gWQVhc8eknunSA2DoJpJyTQkhheIf5E48u1N0R4q/YxxsAeqRrmK9TQ/uYfgLDfZo91UlANIA==", "dev": true } } @@ -3331,8 +3236,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -3350,13 +3254,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3369,18 +3271,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -3483,8 +3382,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -3494,7 +3392,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3507,20 +3404,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.3.5", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -3537,7 +3431,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -3610,8 +3503,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -3621,7 +3513,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -3697,8 +3588,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -3728,7 +3618,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3746,7 +3635,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3785,13 +3673,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.3", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -4565,8 +4451,9 @@ "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=" }, "js-yaml": { - "version": "3.13.0", - "resolved": "", + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", + "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", "dev": true, "requires": { "argparse": "^1.0.7", @@ -7641,12 +7528,6 @@ "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==", "dev": true }, - "v8-compile-cache": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz", - "integrity": "sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g==", - "dev": true - }, "validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", diff --git a/package.json b/package.json index 10aac06ca..a59a7e716 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kuzzle-sdk", - "version": "6.2.3", + "version": "6.2.4", "description": "Official Javascript SDK for Kuzzle", "author": "The Kuzzle Team ", "repository": { @@ -51,9 +51,9 @@ "devDependencies": { "codecov": "^3.5.0", "cucumber": "^5.1.0", - "eslint": "^6.3.0", + "eslint": "^5.16.0", "eslint-friendly-formatter": "^4.0.1", - "eslint-loader": "^3.0.0", + "eslint-loader": "^2.2.1", "mocha": "6.2.0", "mock-require": "^3.0.3", "nyc": "^14.1.1", diff --git a/src/protocols/http.js b/src/protocols/http.js index 00e5ab8b0..cff3e36d6 100644 --- a/src/protocols/http.js +++ b/src/protocols/http.js @@ -18,8 +18,12 @@ class HttpWrapper extends KuzzleAbstractProtocol { this.customRoutes = options.customRoutes || {}; - for (const [controller, definition] of Object.entries(this.customRoutes)) { - for (const [action, route] of Object.entries(definition)) { + for (const controller of Object.keys(this.customRoutes)) { + const definition = this.customRoutes[controller]; + + for (const action of Object.keys(definition)) { + const route = definition[action]; + if (!(typeof route.url === 'string' && route.url.length > 0)) { throw new Error( `Incorrect URL for custom route ${controller}:${action}.`); @@ -281,11 +285,14 @@ class HttpWrapper extends KuzzleAbstractProtocol { } _constructRoutes (publicApi) { - const apiRoutes = Object.entries(publicApi) + const apiRoutes = Object.keys(publicApi) + .map(key => [key, publicApi[key]]) .reduce((routes, [controller, definition]) => { routes[controller] = {}; - for (const [action, { http }] of Object.entries(definition)) { + for (const action of Object.keys(definition)) { + const { http } = definition[action]; + if (http && http.length === 1) { routes[controller][action] = http[0]; } else if (http && http.length > 1) { @@ -296,8 +303,8 @@ class HttpWrapper extends KuzzleAbstractProtocol { return routes; }, {}); - for (const [controller, definition] of Object.entries(this.customRoutes)) { - apiRoutes[controller] = definition; + for (const controller of Object.keys(this.customRoutes)) { + apiRoutes[controller] = this.customRoutes[controller]; } return apiRoutes;