export type GetApiApiOauthCallbackArgs = {state: string, code?: string | undefined, error?: string | undefined, error_description?: string | undefined}; export type GetApiApiOauthCallbackOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * OAuth callback endpoint * * GET /api/oauth/callback */ export const getApiApiOauthCallback = async (args: GetApiApiOauthCallbackArgs, options?: GetApiApiOauthCallbackOptions) => { const {baseUrl = "http://localhost:8080", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/html") if (args.state != null) query.append("state", String(args.state)) if (args.code != null) query.append("code", String(args.code)) if (args.error != null) query.append("error", String(args.error)) if (args.error_description != null) query.append("error_description", String(args.error_description)) const url = `${baseUrl.replace(/\/+$/, '')}/api/oauth/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 res.text() };