Skip to content
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuzzle-sdk",
"version": "7.10.3",
"version": "7.10.4",
"description": "Official Javascript SDK for Kuzzle",
"author": "The Kuzzle Team <[email protected]>",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ export interface ArgsDocumentControllerDelete extends ArgsDefault {
}

export interface ArgsDocumentControllerDeleteByQuery extends ArgsDefault {
refresh?: string;
refresh?: "wait_for" | "false";
silent?: boolean;
lang?: string;
}
Expand Down Expand Up @@ -933,7 +933,7 @@ export interface ArgsDocumentControllerUpdateByQuery extends ArgsDefault {
export interface ArgsDocumentControllerUpsert<TKDocumentContent>
extends ArgsDefault {
default?: Partial<TKDocumentContent>;
refresh?: string;
refresh?: "wait_for" | "false";
silent?: boolean;
retryOnConflict?: boolean;
source?: boolean;
Expand Down
13 changes: 5 additions & 8 deletions src/core/searchResult/SearchResultBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,11 @@ export class SearchResultBase<T> implements SearchResult<T> {
}

return this._kuzzle
.query(
{
...this._request,
action: this._searchAction,
from: this.fetched,
},
this._options
)
.query({
...this._request,
action: this._searchAction,
from: this.fetched,
})
.then(({ result }) => this._buildNextSearchResult(result));
}

Expand Down
8 changes: 8 additions & 0 deletions src/protocols/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ export default class HttpProtocol extends KuzzleAbstractProtocol {
payload.headers.authorization = "Bearer " + value;
} else if (key === "volatile") {
payload.headers["x-kuzzle-volatile"] = JSON.stringify(value);
} else if (key === "index" || key === "collection") {
// If we're calling a non-native route that answer to a GET request
// we need to add the index and collection (if provided) to the query string
if (!staticHttpRoutes[request.controller] && method === "GET") {
queryArgs[key] = value;
} else {
payload[key] = value;
}
} else if (Object.prototype.hasOwnProperty.call(payload, key)) {
payload[key] = value;
} else if (value !== undefined && value !== null) {
Expand Down
7 changes: 4 additions & 3 deletions src/protocols/abstract/Realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ export abstract class BaseProtocolRealtime extends KuzzleAbstractProtocol {
this.retrying = true;

if (
window !== null &&
typeof window === "object" &&
typeof window.navigator === "object" &&
window.navigator.onLine === false
typeof window!.navigator === "object" &&
window!.navigator.onLine === false
) {
window.addEventListener(
window!.addEventListener(
"online",
() => {
this.retrying = false;
Expand Down
34 changes: 24 additions & 10 deletions src/utils/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,33 @@ let NODE_DEBUG;
/* eslint no-undef: 0 */

function shouldDebug() {
if (typeof window === "undefined") {
// Avoid multiple calls to process.env
if (!NODE_DEBUG) {
NODE_DEBUG = (process.env.DEBUG || "").includes("kuzzle-sdk");
/**
* Some framework like react-native or other might emulate the window object
* but when on plateforms like iOS / Android, the window.location is undefined.
*
* So we need to check if window.location is defined before using it otherwise
* we will get an error.
*
* If something went wrong, be sure to return false to avoid any error.
*/
try {
if (typeof window === "undefined") {
// Avoid multiple calls to process.env
if (!NODE_DEBUG) {
NODE_DEBUG = (process.env.DEBUG || "").includes("kuzzle-sdk");
}

return NODE_DEBUG;
}

return NODE_DEBUG;
return (
window.debugKuzzleSdk ||
(window.location &&
new URL(window.location).searchParams.get("debugKuzzleSdk") !== null)
);
} catch (e) {
return false;
}

return (
window.debugKuzzleSdk ||
new URL(window.location).searchParams.get("debugKuzzleSdk") !== null
);
}

/**
Expand Down
21 changes: 9 additions & 12 deletions test/core/searchResult/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,15 @@ describe("DocumentSearchResult", () => {
return searchResult.next().then((nextSearchResult) => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith(
{
index: "index",
collection: "collection",
body: { query: { foo: "bar" } },
controller: "document",
action: "search",
size: 2,
from: 2,
},
options
);
.be.calledWith({
index: "index",
collection: "collection",
body: { query: { foo: "bar" } },
controller: "document",
action: "search",
size: 2,
from: 2,
});
should(nextSearchResult).not.be.equal(searchResult);
should(nextSearchResult).be.instanceOf(DocumentSearchResult);
});
Expand Down
17 changes: 7 additions & 10 deletions test/core/searchResult/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,13 @@ describe("ProfileSearchResult", () => {
return searchResult.next().then((nextSearchResult) => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith(
{
body: { query: { foo: "bar" } },
controller: "security",
action: "searchProfiles",
size: 2,
from: 2,
},
options
);
.be.calledWith({
body: { query: { foo: "bar" } },
controller: "security",
action: "searchProfiles",
size: 2,
from: 2,
});
should(nextSearchResult).not.be.equal(searchResult);
should(nextSearchResult).be.instanceOf(ProfileSearchResult);
});
Expand Down
17 changes: 7 additions & 10 deletions test/core/searchResult/role.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,13 @@ describe("RoleSearchResult", () => {
return searchResult.next().then((nextSearchResult) => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith(
{
body: { foo: "bar" },
controller: "security",
action: "searchRoles",
size: 2,
from: 2,
},
options
);
.be.calledWith({
body: { foo: "bar" },
controller: "security",
action: "searchRoles",
size: 2,
from: 2,
});
should(nextSearchResult).not.be.equal(searchResult);
should(nextSearchResult).be.instanceOf(RoleSearchResult);
});
Expand Down
17 changes: 7 additions & 10 deletions test/core/searchResult/specifications.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,13 @@ describe("SpecificationsSearchResult", () => {
return searchResult.next().then((nextSearchResult) => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith(
{
body: { query: { foo: "bar" } },
controller: "collection",
action: "searchSpecifications",
size: 2,
from: 2,
},
options
);
.be.calledWith({
body: { query: { foo: "bar" } },
controller: "collection",
action: "searchSpecifications",
size: 2,
from: 2,
});
should(nextSearchResult).not.be.equal(searchResult);
should(nextSearchResult).be.instanceOf(SpecificationsSearchResult);
});
Expand Down
17 changes: 7 additions & 10 deletions test/core/searchResult/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,13 @@ describe("UserSearchResult", () => {
return searchResult.next().then((nextSearchResult) => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith(
{
body: { query: { foo: "bar" } },
controller: "security",
action: "searchUsers",
size: 2,
from: 2,
},
options
);
.be.calledWith({
body: { query: { foo: "bar" } },
controller: "security",
action: "searchUsers",
size: 2,
from: 2,
});
should(nextSearchResult).not.be.equal(searchResult);
should(nextSearchResult).be.instanceOf(UserSearchResult);
});
Expand Down
27 changes: 27 additions & 0 deletions test/protocol/Http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,33 @@ describe("HTTP networking module", () => {

protocol.send(data);
});

it("should add index and collection to the query args if they are defined when using a custom GET route", (done) => {
const data = {
requestId: "requestId",
controller: "foo",
action: "bar",
index: "index",
collection: "collection",
};

protocol._routes = {
foo: { bar: { verb: "GET", url: "/foo/bar" } },
};

protocol.on("requestId", () => {
should(protocol._sendHttpRequest)
.be.calledOnce()
.and.be.calledWithMatch({
method: "GET",
path: "/foo/bar?index=index&collection=collection",
});

done();
});

protocol.send(data);
});
});

describe("#sendHttpRequest NodeJS", () => {
Expand Down