From 0aa42224e0684bed46c14b4810d0e210b3df1ec2 Mon Sep 17 00:00:00 2001 From: Cyril Nguyen Date: Wed, 16 Oct 2024 09:43:36 +0200 Subject: [PATCH] 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;