From 6e2648830b15b1cfffd7d5f6972a70ee9229d5aa Mon Sep 17 00:00:00 2001 From: Tobias Armbruster Date: Thu, 10 Jul 2025 08:25:38 +0200 Subject: [PATCH] make endpoint configurable --- src/client/SmartQueryClient.ts | 5 ++++- src/client/SmartSuggestClient.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/client/SmartQueryClient.ts b/src/client/SmartQueryClient.ts index 6cbf5ef..a4391ba 100644 --- a/src/client/SmartQueryClient.ts +++ b/src/client/SmartQueryClient.ts @@ -15,6 +15,7 @@ export interface SmartQueryClientConfig { abTestManager?: AbTestSegmentManager; tenant: string; apiKey?: string; + endpoint?: string; isAbTestActive: boolean; } @@ -43,6 +44,7 @@ export class SmartQueryClient { private readonly customer: string; private readonly channel: string; private readonly apiKey: string | undefined; + private readonly endpoint: string; private readonly isAbTestActive: boolean; private readonly cache?: ICache; @@ -68,6 +70,7 @@ export class SmartQueryClient { this.channel = split[1]; this.apiKey = config.apiKey; this.cache = cache; // Optional cache initialization + this.endpoint = config.endpoint || "https://saas.searchhub.io"; } /** @@ -98,7 +101,7 @@ export class SmartQueryClient { base64Credentials = btoa(this.customer + ":" + this.apiKey); } - return fetch(`https://saas.searchhub.io/smartquery/v2/${this.customer}/${this.channel}?userQuery=${userQuery}`, { + return fetch(`${this.endpoint}/smartquery/v2/${this.customer}/${this.channel}?userQuery=${userQuery}`, { method: "GET", headers: base64Credentials ? { 'Authorization': `Basic ${base64Credentials}`, diff --git a/src/client/SmartSuggestClient.ts b/src/client/SmartSuggestClient.ts index 75af2b1..0689cbb 100644 --- a/src/client/SmartSuggestClient.ts +++ b/src/client/SmartSuggestClient.ts @@ -12,6 +12,7 @@ import {MappingTarget} from "./SmartQueryClient"; export interface SmartSuggestClientConfig { tenant: string; apiKey?: string; + endpoint?: string; } /** @@ -40,6 +41,7 @@ export class SmartSuggestClient { private readonly customer: string; private readonly channel: string; private readonly apiKey: string | undefined; + private readonly endpoint: string; private readonly cache?: ICache; /** @@ -57,6 +59,7 @@ export class SmartSuggestClient { this.channel = split[1]; this.apiKey = config.apiKey; this.cache = cache; // Optional cache initialization + this.endpoint = config.endpoint || "https://saas.searchhub.io"; } /** @@ -72,7 +75,7 @@ export class SmartSuggestClient { base64Credentials = btoa(this.customer + ":" + this.apiKey); } - return fetch(`https://saas.searchhub.io/smartsuggest/v4/${this.customer}/${this.channel}?userQuery=${userQuery}`, { + return fetch(`${this.endpoint}/smartsuggest/v4/${this.customer}/${this.channel}?userQuery=${userQuery}`, { method: "GET", headers: base64Credentials ? { 'Authorization': `Basic ${base64Credentials}`,