MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / ImpersonationApiClient

Class ImpersonationApiClient

console/src/api/apiClient.ts:271–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269}
270
271export class ImpersonationApiClient
272 implements IApiClientBase, ICloudApiClient, IImpersonationApiClient
273{
274 #appConfig: Readonly<CloudAppConfig>;
275 cloudGlobalApiBasePath: string;
276 type = "cloud" as const;
277 isImpersonating = true as const;
278 isLocalImpersonation: boolean;
279 mzHttpUrlScheme: HttpScheme;
280 mzWebsocketUrlScheme: WebsocketScheme;
281
282 constructor({ appConfig }: { appConfig: Readonly<CloudAppConfig> }) {
283 this.#appConfig = appConfig;
284 this.cloudGlobalApiBasePath = this.#appConfig.cloudGlobalApiUrl;
285 this.mzHttpUrlScheme = this.#appConfig.environmentdScheme;
286 this.mzWebsocketUrlScheme = this.#appConfig.environmentdWebsocketScheme;
287 this.isLocalImpersonation = this.#appConfig.isLocalImpersonation;
288 }
289
290 #impersonationCloudApiMiddleware: Middleware = (next) => {
291 return async (...fetchArgs) => {
292 const [input, options = {}] = fetchArgs;
293 const headers = copyHeaders(fetchArgs);
294
295 if (this.#appConfig.impersonation?.organizationId) {
296 headers.set("accept", this.#appConfig.impersonation.organizationId);
297 const request = new Request(input, {
298 headers,
299 credentials: "include" as const,
300 method: "GET",
301 });
302 return next(request);
303 }
304
305 const request = new Request(input, { ...options, headers });
306 return next(request);
307 };
308 };
309
310 mzApiFetch = globalFetch;
311 cloudApiFetch = withMiddleware(
312 globalFetch,
313 this.#impersonationCloudApiMiddleware,
314 );
315 getWsAuthConfig = () => null;
316}
317
318export class CloudApiClient
319 implements IApiClientBase, ICloudApiClient, IFronteggApiClient

Callers

nothing calls this directly

Calls 3

copyHeadersFunction · 0.85
withMiddlewareFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected