From 2c1dec46cee9740386616e29a3b5eff82514a52d Mon Sep 17 00:00:00 2001 From: Nicky Bondarenko Date: Tue, 10 Sep 2024 15:49:35 +0200 Subject: [PATCH] feat!: add a custom base url for sidecase resolves --- packages/sdk/src/FlagResolverClient.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/sdk/src/FlagResolverClient.ts b/packages/sdk/src/FlagResolverClient.ts index 94dc8ef3..c65f04b7 100644 --- a/packages/sdk/src/FlagResolverClient.ts +++ b/packages/sdk/src/FlagResolverClient.ts @@ -16,7 +16,10 @@ import { SimpleFetch } from './types'; const FLAG_PREFIX = 'flags/'; export class ResolveError extends Error { - constructor(public readonly code: FlagEvaluation.ErrorCode, message: string) { + constructor( + public readonly code: FlagEvaluation.ErrorCode, + message: string, + ) { super(message); } } @@ -84,6 +87,7 @@ export type FlagResolverClientOptions = { resolveTimeout: number; environment: 'client' | 'backend'; region?: 'eu' | 'us'; + APIResolveBaseUrl?: string; }; export class FetchingFlagResolverClient implements FlagResolverClient { @@ -103,13 +107,17 @@ export class FetchingFlagResolverClient implements FlagResolverClient { // todo refactor to move out environment environment, region, + APIResolveBaseUrl, }: FlagResolverClientOptions) { // TODO think about both resolve and apply request logic for backends this.fetchImplementation = environment === 'backend' ? fetchImplementation : withRequestLogic(fetchImplementation); this.clientSecret = clientSecret; this.sdk = sdk; this.applyTimeout = applyTimeout; - this.baseUrl = region ? `https://resolver.${region}.confidence.dev/v1` : 'https://resolver.confidence.dev/v1'; + this.baseUrl = + APIResolveBaseUrl || region + ? `https://resolver.${region}.confidence.dev/v1` + : 'https://resolver.confidence.dev/v1'; this.resolveTimeout = resolveTimeout; }