export type CreateApiV2LoginCallbackArgs = {state?: string | undefined, code?: string | undefined, scope?: string | undefined, query?: {[key: string]: unknown} | undefined}; export type CreateApiV2LoginCallbackOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * OAuth Callback (POST) * * POST /v2/login/callback * * Also accepts auth: OrgApiKeyAuth, BearerAuth + OrgApiKeyAuth */ export const createApiV2LoginCallback = async (args: CreateApiV2LoginCallbackArgs, options?: CreateApiV2LoginCallbackOptions) => { const {baseUrl = "https://api.studio.prisme.ai", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.state != null) query.append("state", String(args.state)) if (args.code != null) query.append("code", String(args.code)) if (args.scope != null) query.append("scope", String(args.scope)) if (args.query != null) query.append("query", JSON.stringify(args.query)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/login/callback${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };