import {z} from 'zod' export type GetApiV2ReportsTransactionsCSVArgs = {merchantId?: string | undefined, timezone?: string | undefined, gmtOffset?: number | undefined, page?: number | undefined, size?: number | undefined, refunds?: boolean | undefined, voids?: boolean | undefined, version?: string | undefined, email?: string | undefined, dateBegin?: string | undefined, dateEnd?: string | undefined, authorization: string, 'Content-Type': string, Accept?: string | undefined}; export type GetApiV2ReportsTransactionsCSVOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2ReportsTransactionsCSVResponse = z.object({success: z.boolean().optional(), message: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Transactions CSV * * GET /v2/reports/transactions/CSV */ export const getApiV2ReportsTransactionsCSV = async (args: GetApiV2ReportsTransactionsCSVArgs, options?: GetApiV2ReportsTransactionsCSVOptions) => { const {baseUrl = "https://api.sandbox-pay.aero.inc", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.merchantId != null) query.append("merchantId", String(args.merchantId)) if (args.timezone != null) query.append("timezone", String(args.timezone)) if (args.gmtOffset != null) query.append("gmtOffset", String(args.gmtOffset)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (args.refunds != null) query.append("refunds", String(args.refunds)) if (args.voids != null) query.append("voids", String(args.voids)) if (args.version != null) query.append("version", String(args.version)) if (args.email != null) query.append("email", String(args.email)) if (args.dateBegin != null) query.append("dateBegin", String(args.dateBegin)) if (args.dateEnd != null) query.append("dateEnd", String(args.dateEnd)) if (args.authorization != null) headers.set("authorization", String(args.authorization)) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args.Accept != null) headers.set("Accept", String(args.Accept)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/reports/transactions/CSV${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 validateResponse(getApiV2ReportsTransactionsCSVResponse, await res.json()) };