export type GetApiOauthLoginArgs = {companyName: string, redirectUri?: string | undefined}; export type GetApiOauthLoginOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Initiates a OAuth login. * * GET /oauth/login */ export const getApiOauthLogin = async (args: GetApiOauthLoginArgs, options: GetApiOauthLoginOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/plain") if (args.companyName != null) query.append("companyName", String(args.companyName)) if (args.redirectUri != null) query.append("redirectUri", String(args.redirectUri)) const url = `${baseUrl.replace(/\/+$/, '')}/oauth/login${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() };