export type GetApiAuthLoginArgs = {clientId: string, state?: string | undefined}; export type GetApiAuthLoginOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, PayloadAuth?: string | undefined, SignatureAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * OAuth 2.0 Authorization * * GET /auth/login */ export const getApiAuthLogin = async (args: GetApiAuthLoginArgs, options?: GetApiAuthLoginOptions) => { const {baseUrl = "https://whitebit.com", fetch: fetchFn = fetch, ApiKeyAuth, PayloadAuth, SignatureAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.clientId != null) query.append("clientId", String(args.clientId)) if (args.state != null) query.append("state", String(args.state)) if (ApiKeyAuth !== undefined) headers.set("X-TXC-APIKEY", ApiKeyAuth) if (PayloadAuth !== undefined) headers.set("X-TXC-PAYLOAD", PayloadAuth) if (SignatureAuth !== undefined) headers.set("X-TXC-SIGNATURE", SignatureAuth) const url = `${baseUrl.replace(/\/+$/, '')}/auth/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 undefined };