export type GetApiV3OrdersArgs = {MID: string, page?: number | undefined, limit?: number | undefined, status?: string | undefined, orderType?: ('onramp' | 'offramp' | 'payin' | 'payout' | 'fiat_prefund' | 'crypto_prefund' | 'swap' | 'gaming') | undefined, fromDate?: string | undefined, toDate?: string | undefined, userId?: string | undefined, currency?: string | undefined}; export type GetApiV3OrdersOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * List Orders * * GET /v3/orders */ export const getApiV3Orders = async (args: GetApiV3OrdersArgs, options?: GetApiV3OrdersOptions) => { const {baseUrl = "https://sandbox-api.transfi.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.MID != null) headers.set("MID", String(args.MID)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.status != null) query.append("status", String(args.status)) if (args.orderType != null) query.append("orderType", String(args.orderType)) if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.toDate != null) query.append("toDate", String(args.toDate)) if (args.userId != null) query.append("userId", String(args.userId)) if (args.currency != null) query.append("currency", String(args.currency)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/orders${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 (await res.json()) as unknown };