From c4a69b22730a22b057578ccdaaa8d581abc156e6 Mon Sep 17 00:00:00 2001 From: syed waheed Date: Wed, 2 Oct 2024 00:30:56 +0530 Subject: [PATCH 1/4] Update client.ts Modified the OpenFgaClient constructor to throw a FgaRequiredParamError with a clear message when the apiUrl parameter is not provided. --- client.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client.ts b/client.ts index 0e00738..fcc243e 100644 --- a/client.ts +++ b/client.ts @@ -53,7 +53,7 @@ import { generateRandomIdWithNonUniqueFallback, setHeaderIfNotSet, } from "./utils"; -import { isWellFormedUlidString } from "./validation"; +import { assertParamExists, isWellFormedUlidString } from "./validation"; export type UserClientConfigurationParams = UserConfigurationParams & { storeId?: string; @@ -210,9 +210,10 @@ export class OpenFgaClient extends BaseAPI { } else { this.configuration = new ClientConfiguration(configuration); } + const { apiUrl } = this.configuration; + assertParamExists("OpenFgaClient", "apiUrl", apiUrl); + this.configuration.isValid(); - - this.api = new OpenFgaApi(this.configuration, axios); this.storeId = configuration.storeId; this.authorizationModelId = configuration.authorizationModelId; From efb24003510f638c8ce6b5a1c25db3178234b419 Mon Sep 17 00:00:00 2001 From: syed waheed Date: Wed, 2 Oct 2024 17:46:48 +0530 Subject: [PATCH 2/4] Refactor Configuration validation to use assertParamExists for apiUrl check --- client.ts | 3 --- configuration.ts | 7 +++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/client.ts b/client.ts index fcc243e..f3ed74f 100644 --- a/client.ts +++ b/client.ts @@ -210,9 +210,6 @@ export class OpenFgaClient extends BaseAPI { } else { this.configuration = new ClientConfiguration(configuration); } - const { apiUrl } = this.configuration; - assertParamExists("OpenFgaClient", "apiUrl", apiUrl); - this.configuration.isValid(); this.api = new OpenFgaApi(this.configuration, axios); this.storeId = configuration.storeId; diff --git a/configuration.ts b/configuration.ts index 36fb0ce..bb0d690 100644 --- a/configuration.ts +++ b/configuration.ts @@ -186,10 +186,9 @@ export class Configuration { * @throws {FgaValidationError} */ public isValid(): boolean { - if (!this.apiUrl) { - assertParamExists("Configuration", "apiScheme", this.apiScheme); - assertParamExists("Configuration", "apiHost", this.apiHost); - } + if (!this.apiUrl && !this.apiScheme && !this.apiHost) { + assertParamExists("Configuration", "apiUrl", this.apiUrl); + } if (!isWellFormedUriString(this.getBasePath())) { throw new FgaValidationError( From 435c8c1a34e53f910bd180fb4c22d418da74fc5e Mon Sep 17 00:00:00 2001 From: syed waheed Date: Wed, 2 Oct 2024 17:51:28 +0530 Subject: [PATCH 3/4] changes in client.ts --- client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.ts b/client.ts index f3ed74f..481a4a0 100644 --- a/client.ts +++ b/client.ts @@ -53,7 +53,7 @@ import { generateRandomIdWithNonUniqueFallback, setHeaderIfNotSet, } from "./utils"; -import { assertParamExists, isWellFormedUlidString } from "./validation"; +import { isWellFormedUlidString } from "./validation"; export type UserClientConfigurationParams = UserConfigurationParams & { storeId?: string; From 93a7cbecc5104dd582da852a5d8a3bebf5ec5ecc Mon Sep 17 00:00:00 2001 From: Syed Waheed <105697767+Waheedsys@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:51:55 +0530 Subject: [PATCH 4/4] Update configuration.ts Co-authored-by: Ewan Harris --- configuration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configuration.ts b/configuration.ts index bb0d690..fefb380 100644 --- a/configuration.ts +++ b/configuration.ts @@ -186,7 +186,7 @@ export class Configuration { * @throws {FgaValidationError} */ public isValid(): boolean { - if (!this.apiUrl && !this.apiScheme && !this.apiHost) { + if (!this.apiUrl && !this.apiHost) { assertParamExists("Configuration", "apiUrl", this.apiUrl); }