export type CreateApiLoginArgs = {email: string, password: string, code?: string | undefined}; export type CreateApiLoginOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Login * * POST /login */ export const createApiLogin = async (args: CreateApiLoginArgs, options?: CreateApiLoginOptions) => { const {baseUrl = "https://api.sinao.app/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.email != null) query.append("email", String(args.email)) if (args.password != null) query.append("password", String(args.password)) if (args.code != null) query.append("code", String(args.code)) const url = `${baseUrl.replace(/\/+$/, '')}/login${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };