export type GetApiTestCallbackArgs = {code?: string | undefined, state?: string | undefined, error?: string | undefined, error_description?: string | undefined}; export type GetApiTestCallbackOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * GET /test-callback */ export const getApiTestCallback = async (args: GetApiTestCallbackArgs, options: GetApiTestCallbackOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = 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.error != null) query.append("error", String(args.error)) if (args.error_description != null) query.append("error_description", String(args.error_description)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/test-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 };