export type CreateApiEmailsArgs = {body: {address: string}}; export type CreateApiEmailsOptions = {baseUrl?: string | undefined, CookieAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Add a new email address to the current user. * * POST /emails * * Also accepts auth: BearerTokenAuth */ export const createApiEmails = async (args: CreateApiEmailsArgs, options?: CreateApiEmailsOptions) => { const {baseUrl = "https://.hanko.io/admin", fetch: fetchFn = fetch, CookieAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (CookieAuth !== undefined) cookies.push("hanko=" + encodeURIComponent(CookieAuth)) const url = `${baseUrl.replace(/\/+$/, '')}/emails${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };