export type GetApiAuthCallbackKcArgs = {code: string, state?: string | undefined, redirect_uri?: string | undefined}; export type GetApiAuthCallbackKcOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Callback endpoint, used for final redirect from the OpenID connect provider * * GET /auth/callback/kc */ export const getApiAuthCallbackKc = async (args: GetApiAuthCallbackKcArgs, options?: GetApiAuthCallbackKcOptions) => { const {baseUrl = "https://api.anaconda.cloud/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.code != null) query.append("code", String(args.code)) if (args.state != null) query.append("state", String(args.state)) if (args.redirect_uri != null) query.append("redirect_uri", String(args.redirect_uri)) const url = `${baseUrl.replace(/\/+$/, '')}/auth/callback/kc${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 };