export type GetApiAuthLinkArgs = {access_token: string}; export type GetApiAuthLinkOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Link additional OAuth provider * * GET /auth/link */ export const getApiAuthLink = async (args: GetApiAuthLinkArgs, options: GetApiAuthLinkOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/html") if (args.access_token != null) query.append("access_token", String(args.access_token)) const url = `${baseUrl.replace(/\/+$/, '')}/auth/link${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() };