import {z} from 'zod' export type GetApiPaymentBatchesOrdersArgs = {accountId: string, sort?: ('asc' | 'desc') | undefined, offset?: number | undefined, limit?: number | undefined, ids?: (string | Array) | undefined, paymentBatchIds?: (string | Array) | undefined, statuses?: ('created' | 'started' | 'completed' | 'failed' | Array<'created' | 'started' | 'completed' | 'failed'>) | undefined, paymentBatchStatuses?: ('draft' | 'validated' | 'confirmed' | 'started' | 'completed' | 'failed' | 'cancelled' | Array<'draft' | 'validated' | 'confirmed' | 'started' | 'completed' | 'failed' | 'cancelled'>) | undefined, budgetIds?: (string | Array) | undefined}; export type GetApiPaymentBatchesOrdersOptions = {baseUrl?: string | undefined, CommonAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPaymentBatchesOrdersResponse = z.object({limit: z.number().int().gte(1).lte(1000).optional(), offset: z.number().int().optional(), count: z.number().int(), rows: z.array(z.object({id: z.string().max(36), paymentBatchId: z.string().max(36), status: z.enum(["created", "started", "completed", "failed"]), budget: z.object({id: z.string().max(36), name: z.string().max(128)}), totalPayments: z.number().gt(0).nullable(), totalAmount: z.string().nullable(), totalDebitedAmount: z.string().nullable(), totalFees: z.string().nullable(), totalDebitedFees: z.string().nullable(), currencyCode: z.enum(["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SEK", "SGD", "SHN", "SLL", "SOS", "SRD", "SSP", "STN", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XCD", "XOF", "XPD", "XPF", "XPT", "YER", "ZAR", "ZMK", "ZMW", "ZWD"]), orderSentAt: z.string().nullable(), createdAt: z.string(), updatedAt: z.string()}))}); 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 }; /** * List orders * * GET /payment-batches/orders */ export const getApiPaymentBatchesOrders = async (args: GetApiPaymentBatchesOrdersArgs, options?: GetApiPaymentBatchesOrdersOptions) => { const {baseUrl = "https://api.equalsmoney.com/v2", fetch: fetchFn = fetch, CommonAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.accountId != null) query.append("accountId", String(args.accountId)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.ids != null) query.append("ids", String(args.ids)) if (args.paymentBatchIds != null) query.append("paymentBatchIds", String(args.paymentBatchIds)) if (args.statuses != null) query.append("statuses", String(args.statuses)) if (args.paymentBatchStatuses != null) query.append("paymentBatchStatuses", String(args.paymentBatchStatuses)) if (args.budgetIds != null) query.append("budgetIds", String(args.budgetIds)) if (CommonAuth !== undefined) headers.set("Authorization", CommonAuth) const url = `${baseUrl.replace(/\/+$/, '')}/payment-batches/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 validateResponse(getApiPaymentBatchesOrdersResponse, await res.json()) };