kuzzle-sdk
Advanced tools
Comparing version 7.7.4 to 7.7.5
@@ -1,1 +0,1 @@ | ||
/*! Kuzzle Javascript SDK version 7.7.4 */ | ||
/*! Kuzzle Javascript SDK version 7.7.5 */ |
{ | ||
"name": "kuzzle-sdk", | ||
"version": "7.7.4", | ||
"version": "7.7.5", | ||
"description": "Official Javascript SDK for Kuzzle", | ||
@@ -5,0 +5,0 @@ "author": "The Kuzzle Team <support@kuzzle.io>", |
@@ -498,2 +498,3 @@ import { BaseController } from './Base'; | ||
* - `retryOnConflict` Number of times the database layer should retry in case of version conflict | ||
* - `strict` If true, an error will occur if a document was not updated | ||
* | ||
@@ -520,2 +521,3 @@ * @returns An object containing 2 arrays: "successes" and "errors" | ||
retryOnConflict?: number; | ||
strict?: boolean; | ||
}): Promise<{ | ||
@@ -679,3 +681,3 @@ /** | ||
* @param [options] | ||
* - `defaults` Fields to add to the document if it gets created | ||
* - `default` Fields to add to the document if it gets created | ||
* - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed | ||
@@ -689,3 +691,3 @@ * - `silent` If true, then Kuzzle will not generate notifications | ||
upsert(index: string, collection: string, _id: string, changes: JSONObject, options?: { | ||
defaults?: JSONObject; | ||
default?: JSONObject; | ||
refresh?: string; | ||
@@ -692,0 +694,0 @@ silent?: boolean; |
@@ -258,2 +258,3 @@ "use strict"; | ||
silent: options.silent, | ||
strict: options.strict, | ||
}; | ||
@@ -287,2 +288,3 @@ return this.query(request, options) | ||
silent: options.silent, | ||
strict: options.strict, | ||
}; | ||
@@ -316,2 +318,3 @@ return this.query(request, options) | ||
silent: options.silent, | ||
strict: options.strict, | ||
}; | ||
@@ -370,2 +373,3 @@ return this.query(request, options) | ||
silent: options.silent, | ||
strict: options.strict, | ||
}; | ||
@@ -403,2 +407,3 @@ return this.query(request, options) | ||
silent: options.silent, | ||
strict: options.strict, | ||
}; | ||
@@ -422,2 +427,3 @@ return this.query(request, options) | ||
* - `retryOnConflict` Number of times the database layer should retry in case of version conflict | ||
* - `strict` If true, an error will occur if a document was not updated | ||
* | ||
@@ -433,2 +439,3 @@ * @returns An object containing 2 arrays: "successes" and "errors" | ||
silent: options.silent, | ||
strict: options.strict, | ||
}; | ||
@@ -585,3 +592,3 @@ return this.query(request, options) | ||
* @param [options] | ||
* - `defaults` Fields to add to the document if it gets created | ||
* - `default` Fields to add to the document if it gets created | ||
* - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed | ||
@@ -599,3 +606,3 @@ * - `silent` If true, then Kuzzle will not generate notifications | ||
_id, | ||
body: { changes, defaults: options.defaults }, | ||
body: { changes, default: options.default }, | ||
action: 'upsert', | ||
@@ -602,0 +609,0 @@ source: options.source, |
@@ -13,2 +13,3 @@ import { KuzzleAbstractProtocol } from './abstract/Base'; | ||
private _customRoutes; | ||
private _defaultHeaders; | ||
/** | ||
@@ -18,2 +19,3 @@ * @param host Kuzzle server hostname or IP | ||
* - `customRoutes` Add custom routes | ||
* - `headers` Default headers sent with each HTTP request (default: `{}`) | ||
* - `port` Kuzzle server port (default: `7512`) | ||
@@ -32,2 +34,3 @@ * - `ssl` Use SSL to connect to Kuzzle server. Default `false` unless port is 443 or 7443. | ||
timeout?: number; | ||
headers?: JSONObject; | ||
}); | ||
@@ -82,8 +85,5 @@ /** | ||
_sendHttpRequest({ method, path, payload }: { | ||
method: any; | ||
path: any; | ||
payload?: { | ||
headers: any; | ||
body: any; | ||
}; | ||
method: string; | ||
path: string; | ||
payload: JSONObject; | ||
}): any; | ||
@@ -90,0 +90,0 @@ _constructRoutes(publicApi: any): {}; |
@@ -18,2 +18,3 @@ 'use strict'; | ||
* - `customRoutes` Add custom routes | ||
* - `headers` Default headers sent with each HTTP request (default: `{}`) | ||
* - `port` Kuzzle server port (default: `7512`) | ||
@@ -31,2 +32,3 @@ * - `ssl` Use SSL to connect to Kuzzle server. Default `false` unless port is 443 or 7443. | ||
this._customRoutes = options.customRoutes || {}; | ||
this._defaultHeaders = options.headers || {}; | ||
for (const controller of Object.keys(this._customRoutes)) { | ||
@@ -85,3 +87,10 @@ const definition = this._customRoutes[controller]; | ||
} | ||
return this._sendHttpRequest({ method: 'GET', path: '/_publicApi' }) | ||
const publicApiRequest = { | ||
method: 'GET', | ||
path: '/_publicApi', | ||
payload: { | ||
headers: this._defaultHeaders, | ||
} | ||
}; | ||
return this._sendHttpRequest(publicApiRequest) | ||
.then(({ result, error }) => { | ||
@@ -103,3 +112,10 @@ if (!error) { | ||
// server:publicApi is only available since Kuzzle 1.9.0 | ||
return this._sendHttpRequest({ method: 'GET', path: '/' }) | ||
const serverInfoRequest = { | ||
method: 'GET', | ||
path: '/', | ||
payload: { | ||
headers: this._defaultHeaders, | ||
} | ||
}; | ||
return this._sendHttpRequest(serverInfoRequest) | ||
.then(({ result: res, error: err }) => { | ||
@@ -165,3 +181,4 @@ if (!err) { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
'Content-Type': 'application/json', | ||
...this._defaultHeaders, | ||
}, | ||
@@ -256,3 +273,3 @@ index: undefined, | ||
} | ||
_sendHttpRequest({ method, path, payload = { headers: undefined, body: undefined } }) { | ||
_sendHttpRequest({ method, path, payload }) { | ||
if (typeof XMLHttpRequest === 'undefined') { | ||
@@ -266,7 +283,7 @@ // NodeJS implementation, using http.request: | ||
const url = `${this.protocol}://${this.host}:${this.port}${path}`; | ||
const headers = payload.headers || {}; | ||
headers['Content-Length'] = Buffer.byteLength(payload.body || ''); | ||
const headers = payload && payload.headers || {}; | ||
headers['Content-Length'] = Buffer.byteLength(payload && payload.body || ''); | ||
return httpClient.request(url, method, { | ||
headers, | ||
body: payload.body, | ||
body: payload && payload.body, | ||
headers: headers, | ||
timeout: this._timeout | ||
@@ -293,4 +310,4 @@ }) | ||
xhr.withCredentials = this.cookieSupport; | ||
for (const header of Object.keys(payload.headers || {})) { | ||
xhr.setRequestHeader(header, payload.headers[header]); | ||
for (const [header, value] of Object.entries(payload && payload.headers || {})) { | ||
xhr.setRequestHeader(header, value); | ||
} | ||
@@ -306,3 +323,3 @@ xhr.onload = () => { | ||
}; | ||
xhr.send(payload.body); | ||
xhr.send(payload && payload.body); | ||
}); | ||
@@ -309,0 +326,0 @@ } |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
444779
10505