export type CreateApiFanoutProxyArgs = {az_name?: string | undefined, az_physical_uuid?: unknown | undefined, remote_cluster_uuid?: unknown | undefined, method: string, url_path: string, content_type?: string | undefined, kind?: string | undefined, entity_uuid?: unknown | undefined, tenant_uuid?: unknown | undefined, timeout_ms?: number | undefined, body: unknown}; export type CreateApiFanoutProxyOptions = {baseUrl: string, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Proxies request to remote cluster * * POST /fanout_proxy */ export const createApiFanoutProxy = async (args: CreateApiFanoutProxyArgs, options: CreateApiFanoutProxyOptions) => { const {baseUrl, fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.az_name != null) query.append("az_name", String(args.az_name)) if (args.az_physical_uuid != null) query.append("az_physical_uuid", String(args.az_physical_uuid)) if (args.remote_cluster_uuid != null) query.append("remote_cluster_uuid", String(args.remote_cluster_uuid)) if (args.method != null) query.append("method", String(args.method)) if (args.url_path != null) query.append("url_path", String(args.url_path)) if (args.content_type != null) query.append("content_type", String(args.content_type)) if (args.kind != null) query.append("kind", String(args.kind)) if (args.entity_uuid != null) query.append("entity_uuid", String(args.entity_uuid)) if (args.tenant_uuid != null) query.append("tenant_uuid", String(args.tenant_uuid)) if (args.timeout_ms != null) query.append("timeout_ms", String(args.timeout_ms)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/fanout_proxy${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };