import {z} from 'zod' export type PatchApiPaymentBatchesPaymentBatchIdArgs = {paymentBatchId: string, accountId: string, body: {name?: string | undefined, visible?: boolean | undefined}}; export type PatchApiPaymentBatchesPaymentBatchIdOptions = {baseUrl?: string | undefined, CommonAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiPaymentBatchesPaymentBatchIdResponse = z.object({id: z.string().max(36), accountId: z.string().max(16), name: z.string().max(256).nullable(), createdBy: z.object({id: z.string().max(36), type: z.enum(["person", "product"])}), product: z.object({id: z.string().max(36), name: z.string()}), status: z.enum(["draft", "validated", "confirmed", "started", "completed", "failed", "cancelled"]), visible: z.boolean().nullable(), visibleAt: z.string().nullable(), confirmedBy: z.object({id: z.string().max(36), type: z.enum(["person", "product"])}).nullable(), confirmedAt: z.string().nullable(), passedMfaCheckAt: z.string().nullable(), riskCheckedAt: z.string().nullable(), ordersSentAt: z.string().nullable(), createdAt: z.string(), updatedAt: z.string(), alerts: z.array(z.object({timestamp: z.string(), type: z.enum(["Error", "Warning"]), code: z.string(), message: z.string().nullable()})).nullable().optional(), ordersSummary: z.object({numberOfOrders: z.number().int(), uniqueCurrencyCodes: z.array(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"]))}).nullable().optional(), input: z.object({format: z.enum(["json", "csv"]), status: z.enum(["accepted", "uploaded", "validated", "failed"]), createdAt: z.string(), updatedAt: z.string()}).nullable()}); 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 }; /** * Update a payment batch * * PATCH /payment-batches/{paymentBatchId} */ export const patchApiPaymentBatchesPaymentBatchId = async (args: PatchApiPaymentBatchesPaymentBatchIdArgs, options?: PatchApiPaymentBatchesPaymentBatchIdOptions) => { const {baseUrl = "https://api.equalsmoney.com/v2", fetch: fetchFn = fetch, CommonAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.accountId != null) query.append("accountId", String(args.accountId)) if (CommonAuth !== undefined) headers.set("Authorization", CommonAuth) const url = `${baseUrl.replace(/\/+$/, '')}/payment-batches/${encodeURIComponent(String(args.paymentBatchId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(patchApiPaymentBatchesPaymentBatchIdResponse, await res.json()) };