import {z} from 'zod' export type GetApiPaymentBatchesPaymentBatchIdAlertsArgs = {paymentBatchId: string, accountId: string, sort?: ('asc' | 'desc') | undefined, offset?: number | undefined, limit?: number | undefined, from?: string | undefined, to?: string | undefined, alertType?: ('Error' | 'Warning') | undefined, alertCode?: string | undefined}; export type GetApiPaymentBatchesPaymentBatchIdAlertsOptions = {baseUrl?: string | undefined, CommonAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPaymentBatchesPaymentBatchIdAlertsResponse = 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({timestamp: z.string(), type: z.enum(["Error", "Warning"]), code: z.string(), inputIndex: z.number().int().nullable(), message: 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 }; /** * List payment batch alerts * * GET /payment-batches/{paymentBatchId}/alerts */ export const getApiPaymentBatchesPaymentBatchIdAlerts = async (args: GetApiPaymentBatchesPaymentBatchIdAlertsArgs, options?: GetApiPaymentBatchesPaymentBatchIdAlertsOptions) => { 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.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.alertType != null) query.append("alertType", String(args.alertType)) if (args.alertCode != null) query.append("alertCode", String(args.alertCode)) if (CommonAuth !== undefined) headers.set("Authorization", CommonAuth) const url = `${baseUrl.replace(/\/+$/, '')}/payment-batches/${encodeURIComponent(String(args.paymentBatchId))}/alerts${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(getApiPaymentBatchesPaymentBatchIdAlertsResponse, await res.json()) };