Skip to content

expose connection details #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/connection/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -183,6 +191,12 @@ export default class ConnectionREST {
}
return this.oidcAuth.getAccessToken();
};

getDetails = async (): Promise<ConnectionDetails> => ({
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';
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -110,6 +110,7 @@ export interface WeaviateClient {

close: () => Promise<void>;
getMeta: () => Promise<Meta>;
getConnectionDetails: () => Promise<ConnectionDetails>;
getOpenIDConfig?: () => Promise<any>;
getWeaviateVersion: () => Promise<DbVersion>;
isLive: () => Promise<boolean>;
Expand Down Expand Up @@ -229,6 +230,7 @@ async function client(params: ClientParams): Promise<WeaviateClient> {
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(),
Expand Down
Loading