export type CreateApiUsersAuthArgs = {getCompanySession?: boolean | undefined, body: {email: string, password: string, companyName?: string | undefined}}; export type CreateApiUsersAuthOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Authenticate a user. * * POST /users/auth */ export const createApiUsersAuth = async (args: CreateApiUsersAuthArgs, options: CreateApiUsersAuthOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") headers.set('accept', "application/json") if (args.getCompanySession != null) query.append("getCompanySession", String(args.getCompanySession)) const url = `${baseUrl.replace(/\/+$/, '')}/users/auth${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return (await res.json()) as unknown };