export type ExportFormat = 'csv' | 'xlsx' | 'pdf'; export type ExportKind = 'statement' | 'confirmation' | 'receipt'; export type GetApiTransactionsExportArgs = {format?: ExportFormat | undefined, kind?: (ExportKind | null) | undefined, bankId?: (string | null) | undefined, transactionId?: (string | null) | undefined, type?: (string | null) | undefined, status?: (string | null) | undefined, tag?: (string | null) | undefined, contactId?: (string | null) | undefined, incomeOnly?: (boolean | null) | undefined, q?: (string | null) | undefined, from?: (string | null) | undefined, to?: (string | null) | undefined, 'X-Hevn-Account'?: (string | null) | undefined}; export type GetApiTransactionsExportOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Export transactions, a statement, a confirmation or a receipt * * GET /transactions/export */ export const getApiTransactionsExport = async (args: GetApiTransactionsExportArgs, options: GetApiTransactionsExportOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/csv") if (args.format != null) query.append("format", String(args.format)) if (args.kind != null) query.append("kind", String(args.kind)) if (args.bankId != null) query.append("bankId", String(args.bankId)) if (args.transactionId != null) query.append("transactionId", String(args.transactionId)) if (args.type != null) query.append("type", String(args.type)) if (args.status != null) query.append("status", String(args.status)) if (args.tag != null) query.append("tag", String(args.tag)) if (args.contactId != null) query.append("contactId", String(args.contactId)) if (args.incomeOnly != null) query.append("incomeOnly", String(args.incomeOnly)) if (args.q != null) query.append("q", String(args.q)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args['X-Hevn-Account'] != null) headers.set("X-Hevn-Account", String(args['X-Hevn-Account'])) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/transactions/export${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 res.text() };