export type ChargebackExportFormat = 'csv'; export type GetApiPublicV1ChargebackV3ExportArgs = {from: string, to: string, granularity?: string | undefined, format?: ChargebackExportFormat | undefined}; export type GetApiPublicV1ChargebackV3ExportOptions = {baseUrl: string, httpAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Stream the full chargeback cost dataset as a gzipped CSV file over a user-specified date range. * * GET /public/v1/chargeback/v3/export */ export const getApiPublicV1ChargebackV3Export = async (args: GetApiPublicV1ChargebackV3ExportArgs, options: GetApiPublicV1ChargebackV3ExportOptions) => { const {baseUrl, fetch: fetchFn = fetch, httpAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/plain") if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.granularity != null) query.append("granularity", String(args.granularity)) if (args.format != null) query.append("format", String(args.format)) if (httpAuth !== undefined) headers.set('authorization', `Bearer ${httpAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/public/v1/chargeback/v3/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() };