export type GetApiV1AuthenticationAuthenticateArgs = {redirect_uri: string, redirect_host: string, device_token: string, platform_type?: string | undefined}; export type GetApiV1AuthenticationAuthenticateOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Authenticate user and generate tokens * * GET /v1/authentication/authenticate */ export const getApiV1AuthenticationAuthenticate = async (args: GetApiV1AuthenticationAuthenticateArgs, options?: GetApiV1AuthenticationAuthenticateOptions) => { const {baseUrl = "http://api.floik.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.redirect_uri != null) query.append("redirect_uri", String(args.redirect_uri)) if (args.redirect_host != null) query.append("redirect_host", String(args.redirect_host)) if (args.device_token != null) query.append("device_token", String(args.device_token)) if (args.platform_type != null) query.append("platform_type", String(args.platform_type)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/authentication/authenticate${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 undefined };