From 0aa42224e0684bed46c14b4810d0e210b3df1ec2 Mon Sep 17 00:00:00 2001 From: Cyril Nguyen Date: Wed, 16 Oct 2024 09:43:36 +0200 Subject: [PATCH 1/3] feat: add options parameter to controller functions containing a query --- src/controllers/Auth.ts | 12 +++++++++--- src/controllers/Security.ts | 6 ++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/controllers/Auth.ts b/src/controllers/Auth.ts index 8aedf6c2b..b2053c710 100644 --- a/src/controllers/Auth.ts +++ b/src/controllers/Auth.ts @@ -437,7 +437,8 @@ export class AuthController extends BaseController { login( strategy: string, credentials: JSONObject, - expiresIn?: string | number + expiresIn?: string | number, + options: ArgsAuthControllerLogin = {} ): Promise { const request = { action: "login", @@ -448,7 +449,7 @@ export class AuthController extends BaseController { }; this.kuzzle.emit("beforeLogin"); - return this.query(request, { queuable: false, timeout: -1, verb: "POST" }) + return this.query(request, { queuable: false, timeout: -1, verb: "POST", ...options }) .then((response) => { if (this.kuzzle.cookieAuthentication) { if (response.result.jwt) { @@ -497,13 +498,14 @@ export class AuthController extends BaseController { * * @see https://docs.kuzzle.io/sdk/js/7/controllers/auth/logout */ - async logout(): Promise { + async logout(options: ArgsAuthControllerLogin = {}): Promise { this.kuzzle.emit("beforeLogout"); try { await this.query( { action: "logout", cookieAuth: this.kuzzle.cookieAuthentication, + ...options }, { queuable: false, timeout: -1 } ); @@ -700,6 +702,10 @@ export type ArgsAuthControllerUpdateSelf = ArgsDefault; export type ArgsAuthControllerValidateMyCredentials = ArgsDefault; +export type ArgsAuthControllerLogin = ArgsDefault; + +export type ArgsAuthControllerLogout = ArgsDefault; + export interface ArgsAuthControllerRefreshToken extends ArgsDefault { expiresIn?: number | string; } diff --git a/src/controllers/Security.ts b/src/controllers/Security.ts index b2d63c8b2..9bc836145 100644 --- a/src/controllers/Security.ts +++ b/src/controllers/Security.ts @@ -515,11 +515,11 @@ export class SecurityController extends BaseController { ); } - refresh(collection) { + refresh(collection, options: ArgsSecurityControllerRefresh = {}) { return this.query({ action: "refresh", collection, - }); + }, options); } replaceUser(_id, body, options: ArgsSecurityControllerReplaceUser = {}) { @@ -809,3 +809,5 @@ export type ArgsSecurityControllerUpdateUser = ArgsDefault; export type ArgsSecurityControllerUpdateUserMapping = ArgsDefault; export type ArgsSecurityControllerValidateCredentials = ArgsDefault; + +export type ArgsSecurityControllerRefresh = ArgsDefault; From 4acefe8bef54d92d4417bbfd7618fe02dbf04a89 Mon Sep 17 00:00:00 2001 From: Cyril Nguyen Date: Wed, 16 Oct 2024 09:48:35 +0200 Subject: [PATCH 2/3] style: format document to pass linter --- src/controllers/Auth.ts | 9 +++++++-- src/controllers/Security.ts | 11 +++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/controllers/Auth.ts b/src/controllers/Auth.ts index b2053c710..01033d175 100644 --- a/src/controllers/Auth.ts +++ b/src/controllers/Auth.ts @@ -449,7 +449,12 @@ export class AuthController extends BaseController { }; this.kuzzle.emit("beforeLogin"); - return this.query(request, { queuable: false, timeout: -1, verb: "POST", ...options }) + return this.query(request, { + queuable: false, + timeout: -1, + verb: "POST", + ...options, + }) .then((response) => { if (this.kuzzle.cookieAuthentication) { if (response.result.jwt) { @@ -505,7 +510,7 @@ export class AuthController extends BaseController { { action: "logout", cookieAuth: this.kuzzle.cookieAuthentication, - ...options + ...options, }, { queuable: false, timeout: -1 } ); diff --git a/src/controllers/Security.ts b/src/controllers/Security.ts index 9bc836145..6a8323378 100644 --- a/src/controllers/Security.ts +++ b/src/controllers/Security.ts @@ -516,10 +516,13 @@ export class SecurityController extends BaseController { } refresh(collection, options: ArgsSecurityControllerRefresh = {}) { - return this.query({ - action: "refresh", - collection, - }, options); + return this.query( + { + action: "refresh", + collection, + }, + options + ); } replaceUser(_id, body, options: ArgsSecurityControllerReplaceUser = {}) { From d193eda82f7ccc8ef155f32a872fa0a27057dc49 Mon Sep 17 00:00:00 2001 From: Cyril Nguyen Date: Wed, 16 Oct 2024 16:56:16 +0200 Subject: [PATCH 3/3] fix: change options in the right object --- src/controllers/Auth.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/controllers/Auth.ts b/src/controllers/Auth.ts index 01033d175..47581faf4 100644 --- a/src/controllers/Auth.ts +++ b/src/controllers/Auth.ts @@ -510,9 +510,8 @@ export class AuthController extends BaseController { { action: "logout", cookieAuth: this.kuzzle.cookieAuthentication, - ...options, }, - { queuable: false, timeout: -1 } + { queuable: false, timeout: -1, ...options } ); this._authenticationToken = null; /**