Skip to content

Commit 0f3f17c

Browse files
committed
expose connection details
1 parent b9d579b commit 0f3f17c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/connection/http.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,15 @@ export type InternalConnectionParams = {
5252
skipInitChecks?: boolean;
5353
};
5454

55+
export interface ConnectionDetails {
56+
host: string;
57+
bearerToken?: string;
58+
headers?: HeadersInit;
59+
}
60+
5561
export default class ConnectionREST {
5662
private apiKey?: string;
63+
private headers?: HeadersInit;
5764
protected authEnabled: boolean;
5865
public readonly host: string;
5966
public readonly http: HttpClient;
@@ -62,6 +69,7 @@ export default class ConnectionREST {
6269
constructor(params: InternalConnectionParams) {
6370
params = this.sanitizeParams(params);
6471
this.host = params.host;
72+
this.headers = params.headers;
6573
this.http = httpClient(params);
6674
this.authEnabled = this.parseAuthParams(params);
6775
}
@@ -183,6 +191,12 @@ export default class ConnectionREST {
183191
}
184192
return this.oidcAuth.getAccessToken();
185193
};
194+
195+
getDetails = async (): Promise<ConnectionDetails> => ({
196+
host: new URL(this.host).host, // removes default port
197+
bearerToken: this.authEnabled ? await this.login().then((token) => `Bearer ${token}`) : undefined,
198+
headers: this.headers,
199+
});
186200
}
187201

188202
export * from './auth.js';

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
ConnectToWCSOptions,
2626
ConnectToWeaviateCloudOptions,
2727
} from './connection/helpers.js';
28-
import { ProxiesParams, TimeoutParams } from './connection/http.js';
28+
import { ConnectionDetails, ProxiesParams, TimeoutParams } from './connection/http.js';
2929
import { ConnectionGRPC } from './connection/index.js';
3030
import MetaGetter from './misc/metaGetter.js';
3131
import { Meta } from './openapi/types.js';
@@ -110,6 +110,7 @@ export interface WeaviateClient {
110110

111111
close: () => Promise<void>;
112112
getMeta: () => Promise<Meta>;
113+
getConnectionDetails: () => Promise<ConnectionDetails>;
113114
getOpenIDConfig?: () => Promise<any>;
114115
getWeaviateVersion: () => Promise<DbVersion>;
115116
isLive: () => Promise<boolean>;
@@ -229,6 +230,7 @@ async function client(params: ClientParams): Promise<WeaviateClient> {
229230
users: users(connection),
230231
close: () => Promise.resolve(connection.close()), // hedge against future changes to add I/O to .close()
231232
getMeta: () => new MetaGetter(connection).do(),
233+
getConnectionDetails: connection.getDetails,
232234
getOpenIDConfig: () => new OpenidConfigurationGetter(connection.http).do(),
233235
getWeaviateVersion: () => dbVersionSupport.getVersion(),
234236
isLive: () => new LiveChecker(connection, dbVersionProvider).do(),

0 commit comments

Comments
 (0)