export type GetApiConfirmArgs = {change_email_token?: string | undefined, new_email_token?: string | undefined}; export type GetApiConfirmOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Confirm new or changed user email * * GET /confirm * * Also accepts auth: API-Key */ export const getApiConfirm = async (args: GetApiConfirmArgs, options: GetApiConfirmOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.change_email_token != null) query.append("change_email_token", String(args.change_email_token)) if (args.new_email_token != null) query.append("new_email_token", String(args.new_email_token)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/confirm${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 };