diff --git a/package-lock.json b/package-lock.json index cc7048f..45b1500 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@thoughtspot/rest-api-sdk": "^2.13.1", "agents": "^0.0.95", "hono": "^4.7.8", + "rxjs": "^7.8.2", "yaml": "^2.7.1", "zod": "^3.24.3", "zod-to-json-schema": "^3.24.5" @@ -4852,6 +4853,15 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/rxjs": { + "version": "7.8.2", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz", + "integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.1.0" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -5493,9 +5503,7 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "dev": true, - "license": "0BSD", - "optional": true + "license": "0BSD" }, "node_modules/tsx": { "version": "4.19.3", diff --git a/package.json b/package.json index 3d17fc3..4edf55c 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "@thoughtspot/rest-api-sdk": "^2.13.1", "agents": "^0.0.95", "hono": "^4.7.8", + "rxjs": "^7.8.2", "yaml": "^2.7.1", "zod": "^3.24.3", "zod-to-json-schema": "^3.24.5" diff --git a/src/thoughtspot/thoughtspot-client.ts b/src/thoughtspot/thoughtspot-client.ts index 8c5908a..abe82d6 100644 --- a/src/thoughtspot/thoughtspot-client.ts +++ b/src/thoughtspot/thoughtspot-client.ts @@ -1,11 +1,28 @@ import { createBearerAuthenticationConfig, ThoughtSpotRestApi } from "@thoughtspot/rest-api-sdk" +import type { RequestContext, ResponseContext } from "@thoughtspot/rest-api-sdk" import YAML from "yaml"; +import type { Observable } from "rxjs"; +import { of } from "rxjs"; export const getThoughtSpotClient = (instanceUrl: string, bearerToken: string) => { - const client = new ThoughtSpotRestApi(createBearerAuthenticationConfig( + const config = createBearerAuthenticationConfig( instanceUrl, () => Promise.resolve(bearerToken), - )); + ); + + config.middleware.push({ + pre: (context: RequestContext): Observable => { + const headers = context.getHeaders(); + if (!headers || !headers["Accept-Language"]) { + context.setHeaderParam('Accept-Language', 'en-US'); + } + return of(context); + }, + post: (context: ResponseContext): Observable => { + return of(context); + } + }); + const client = new ThoughtSpotRestApi(config); (client as any).instanceUrl = instanceUrl; addExportUnsavedAnswerTML(client, instanceUrl, bearerToken); addGetSessionInfo(client, instanceUrl, bearerToken);