The control plane proxy routes never sent an Authorization header to the dataplane API. With the tenant extension active, all GUI requests failed with "Invalid API key". Add HINDSIGHT_CP_DATAPLANE_API_KEY env var support to hindsight-client.ts and propagate auth headers to both SDK clients and all direct fetch routes.
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
/**
|
|
* Shared Hindsight API client instance for the control plane.
|
|
* Configured to connect to the dataplane API server.
|
|
*/
|
|
|
|
import { HindsightClient, createClient, createConfig, sdk } from "@vectorize-io/hindsight-client";
|
|
|
|
export const DATAPLANE_URL = process.env.HINDSIGHT_CP_DATAPLANE_API_URL || "http://localhost:8888";
|
|
const DATAPLANE_API_KEY = process.env.HINDSIGHT_CP_DATAPLANE_API_KEY || "";
|
|
|
|
/**
|
|
* Auth headers for direct fetch calls to the dataplane API.
|
|
*/
|
|
export function getDataplaneHeaders(extra?: Record<string, string>): Record<string, string> {
|
|
const headers: Record<string, string> = { ...extra };
|
|
if (DATAPLANE_API_KEY) {
|
|
headers["Authorization"] = `Bearer ${DATAPLANE_API_KEY}`;
|
|
}
|
|
return headers;
|
|
}
|
|
|
|
/**
|
|
* High-level client with convenience methods
|
|
*/
|
|
export const hindsightClient = new HindsightClient({
|
|
baseUrl: DATAPLANE_URL,
|
|
apiKey: DATAPLANE_API_KEY || undefined,
|
|
});
|
|
|
|
/**
|
|
* Low-level client for direct SDK access
|
|
*/
|
|
export const lowLevelClient = createClient(
|
|
createConfig({
|
|
baseUrl: DATAPLANE_URL,
|
|
headers: DATAPLANE_API_KEY
|
|
? { Authorization: `Bearer ${DATAPLANE_API_KEY}` }
|
|
: undefined,
|
|
}),
|
|
);
|
|
|
|
/**
|
|
* Export SDK functions for direct API access
|
|
*/
|
|
export { sdk };
|