Skip to content
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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ Our teams will be able to meet your needs in terms of expertise and multi-techno

## Usage

## Compatibility matrice

| Kuzzle Version | SDK Version |
| -------------- | -------------- |
| 1.x.x | 5.x.x |
| 1.x.x | 6.x.x |
| 2.x.x | 7.x.x |

### Installation

This SDK can be used either in NodeJS or in a browser.
Expand Down Expand Up @@ -140,4 +148,3 @@ try {
console.error(error);
}
```

48 changes: 31 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuzzle-sdk",
"version": "6.2.5",
"version": "6.2.6",
"description": "Official Javascript SDK for Kuzzle",
"author": "The Kuzzle Team <support@kuzzle.io>",
"repository": {
Expand Down Expand Up @@ -54,6 +54,7 @@
"eslint": "^5.16.0",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^2.2.1",
"lolex": "^5.1.1",
"mocha": "6.2.0",
"mock-require": "^3.0.3",
"nyc": "^14.1.1",
Expand Down
2 changes: 2 additions & 0 deletions src/KuzzleError.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class KuzzleError extends Error {

this.status = apiError.status;
this.stack = apiError.stack;
this.id = apiError.id;
this.code = apiError.code;

// PartialError
if (this.status === 206) {
Expand Down
10 changes: 3 additions & 7 deletions src/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class AuthController extends BaseController {
/**
* Do not add the token for the checkToken route, to avoid getting a token error when
* a developer simply wish to verify his token
*
* @param {object} request
*
* @param {object} request
*/
authenticateRequest (request) {
if (!this.authenticationToken
if ( !this.authenticationToken
|| (request.controller === 'auth'
&& (request.action === 'checkToken' || request.action === 'login'))
) {
Expand Down Expand Up @@ -178,10 +178,6 @@ class AuthController extends BaseController {
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
*/
login (strategy, credentials = {}, expiresIn = null) {
if (typeof strategy !== 'string' || strategy === '') {
throw new Error('Kuzzle.auth.login: strategy is required');
}

const request = {
strategy,
expiresIn,
Expand Down
79 changes: 4 additions & 75 deletions src/controllers/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,17 @@ class CollectionController extends BaseController {
super(kuzzle, 'collection');
}

create (index, collection, body = {}, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.create: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.create: collection is required');
}

create (index, collection, mappings = {}, options = {}) {
return this.query({
index,
collection,
body,
body: mappings,
action: 'create'
}, options)
.then(response => response.result);
}

deleteSpecifications (index, collection, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.deleteSpecifications: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.deleteSpecifications: collection is required');
}

return this.query({
index,
collection,
Expand All @@ -45,13 +31,6 @@ class CollectionController extends BaseController {
}

exists (index, collection, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.exists: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.exists: collection is required');
}

return this.query({
index,
collection,
Expand All @@ -61,13 +40,6 @@ class CollectionController extends BaseController {
}

getMapping (index, collection, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.getMapping: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.getMapping: collection is required');
}

return this.query({
index,
collection,
Expand All @@ -77,13 +49,6 @@ class CollectionController extends BaseController {
}

getSpecifications (index, collection, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.getSpecifications: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.getSpecifications: collection is required');
}

return this.query({
index,
collection,
Expand All @@ -93,10 +58,6 @@ class CollectionController extends BaseController {
}

list (index, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.list: index is required');
}

const request = {
index,
action: 'list',
Expand All @@ -115,8 +76,10 @@ class CollectionController extends BaseController {
body,
action: 'searchSpecifications'
};

for (const opt of ['from', 'size', 'scroll']) {
request[opt] = options[opt];

delete options[opt];
}

Expand All @@ -125,13 +88,6 @@ class CollectionController extends BaseController {
}

truncate (index, collection, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.truncate: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.truncate: collection is required');
}

return this.query({
index,
collection,
Expand All @@ -142,13 +98,6 @@ class CollectionController extends BaseController {
}

updateMapping (index, collection, body, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.updateMapping: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.updateMapping: collection is required');
}

return this.query({
index,
collection,
Expand All @@ -159,16 +108,6 @@ class CollectionController extends BaseController {
}

updateSpecifications (index, collection, specifications, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.updateSpecifications: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.updateSpecifications: collection is required');
}
if (!specifications) {
throw new Error('Kuzzle.collection.updateSpecifications: specifications are required');
}

const body = {
[index]: {
[collection]: specifications
Expand All @@ -183,16 +122,6 @@ class CollectionController extends BaseController {
}

validateSpecifications (index, collection, specifications, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.validateSpecifications: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.validateSpecifications: collection is required');
}
if (!specifications) {
throw new Error('Kuzzle.collection.updateSpecifications: specifications are required');
}

const body = {
[index]: {
[collection]: specifications
Expand Down
Loading