export type CreateApiV2LoginAzureCallbackArgs = {body: {code?: string | undefined, client_info?: string | undefined, state?: string | undefined, session_state?: string | undefined}}; export type CreateApiV2LoginAzureCallbackOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Azure Auth Callback * * POST /v2/login/azure/callback * * Also accepts auth: OrgApiKeyAuth, BearerAuth + OrgApiKeyAuth */ export const createApiV2LoginAzureCallback = async (args: CreateApiV2LoginAzureCallbackArgs, options?: CreateApiV2LoginAzureCallbackOptions) => { const {baseUrl = "https://api.studio.prisme.ai", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/login/azure/callback${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };