export type GetApiV2LoginCallbackArgs = {state?: string | undefined, code?: string | undefined, scope?: string | undefined, query?: {[key: string]: unknown} | undefined}; export type GetApiV2LoginCallbackOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * OAuth Callback (GET) * * GET /v2/login/callback * * Also accepts auth: OrgApiKeyAuth, BearerAuth + OrgApiKeyAuth */ export const getApiV2LoginCallback = async (args: GetApiV2LoginCallbackArgs, options?: GetApiV2LoginCallbackOptions) => { 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };