From 0f3f17ce4bfa34c3044e146643f0354e05941c0c Mon Sep 17 00:00:00 2001 From: Augustas Date: Tue, 29 Apr 2025 10:16:12 +0300 Subject: [PATCH] expose connection details --- src/connection/http.ts | 14 ++++++++++++++ src/index.ts | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/connection/http.ts b/src/connection/http.ts index 1af076fd..c4f5e6a9 100644 --- a/src/connection/http.ts +++ b/src/connection/http.ts @@ -52,8 +52,15 @@ export type InternalConnectionParams = { skipInitChecks?: boolean; }; +export interface ConnectionDetails { + host: string; + bearerToken?: string; + headers?: HeadersInit; +} + export default class ConnectionREST { private apiKey?: string; + private headers?: HeadersInit; protected authEnabled: boolean; public readonly host: string; public readonly http: HttpClient; @@ -62,6 +69,7 @@ export default class ConnectionREST { constructor(params: InternalConnectionParams) { params = this.sanitizeParams(params); this.host = params.host; + this.headers = params.headers; this.http = httpClient(params); this.authEnabled = this.parseAuthParams(params); } @@ -183,6 +191,12 @@ export default class ConnectionREST { } return this.oidcAuth.getAccessToken(); }; + + getDetails = async (): Promise => ({ + host: new URL(this.host).host, // removes default port + bearerToken: this.authEnabled ? await this.login().then((token) => `Bearer ${token}`) : undefined, + headers: this.headers, + }); } export * from './auth.js'; diff --git a/src/index.ts b/src/index.ts index 653b9c60..775d5f1f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,7 +25,7 @@ import { ConnectToWCSOptions, ConnectToWeaviateCloudOptions, } from './connection/helpers.js'; -import { ProxiesParams, TimeoutParams } from './connection/http.js'; +import { ConnectionDetails, ProxiesParams, TimeoutParams } from './connection/http.js'; import { ConnectionGRPC } from './connection/index.js'; import MetaGetter from './misc/metaGetter.js'; import { Meta } from './openapi/types.js'; @@ -110,6 +110,7 @@ export interface WeaviateClient { close: () => Promise; getMeta: () => Promise; + getConnectionDetails: () => Promise; getOpenIDConfig?: () => Promise; getWeaviateVersion: () => Promise; isLive: () => Promise; @@ -229,6 +230,7 @@ async function client(params: ClientParams): Promise { users: users(connection), close: () => Promise.resolve(connection.close()), // hedge against future changes to add I/O to .close() getMeta: () => new MetaGetter(connection).do(), + getConnectionDetails: connection.getDetails, getOpenIDConfig: () => new OpenidConfigurationGetter(connection.http).do(), getWeaviateVersion: () => dbVersionSupport.getVersion(), isLive: () => new LiveChecker(connection, dbVersionProvider).do(),