import {z} from 'zod' export type GetApiObjectQueryPaymentRunsArgs = {'Idempotency-Key'?: string | undefined, 'Accept-Encoding'?: string | undefined, 'Content-Encoding'?: string | undefined, 'Zuora-Track-Id'?: string | undefined, 'Zuora-Entity-Ids'?: string | undefined, 'Zuora-Org-Ids'?: string | undefined, 'Zuora-Version'?: string | undefined, pageSize?: number | undefined, cursor?: string | undefined, 'sort[]'?: Array | undefined, 'expand[]'?: Array | undefined, 'filter[]'?: Array | undefined, 'fields[]'?: Array | undefined, includeNullFields?: boolean | undefined}; export type GetApiObjectQueryPaymentRunsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const expandedPaymentRun = z.object({id: z.string().optional(), createdById: z.string().optional(), createdDate: z.string().optional(), updatedById: z.string().optional(), updatedDate: z.string().optional(), endDate: z.string().optional(), executedDate: z.string().optional(), numberOfCreditBalanceAdjustments: z.number().int().optional(), numberOfErrors: z.number().int().optional(), numberOfInvoices: z.number().int().optional(), numberOfPayments: z.number().int().optional(), numberOfUnprocessed: z.number().int().optional(), paymentRunNumber: z.string().optional(), status: z.enum(["Pending", "Processing", "Completed", "Error", "Canceled"]).optional(), targetDate: z.string().optional(), applyCreditBalance: z.boolean().optional(), consolidatedPayment: z.boolean().optional(), processPaymentWithClosedPM: z.boolean().optional(), collectPayment: z.boolean().optional(), autoApplyCreditMemo: z.boolean().optional(), autoApplyUnappliedPayment: z.boolean().optional(), numberOfCreditMemos: z.number().int().optional(), numberOfDebitMemos: z.number().int().optional(), numberOfDebitMemosUnprocessed: z.number().int().optional(), numberofUnappliedPayments: z.number().int().optional(), totalExecutionTime: z.number().int().optional(), errorMessage: z.string().optional(), runDate: z.string().optional(), nextRunOn: z.string().optional(), repeatType: z.enum(["None", "Daily", "Weekly", "Monthly"]).optional(), repeatFrom: z.string().optional(), repeatTo: z.string().optional(), runTime: z.number().int().gte(0).lte(23).optional(), timeZone: z.string().optional(), monthlyOnDay: z.string().optional(), weeklyOnDay: z.enum(["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]).optional(), accountId: z.string().optional(), batch: z.string().optional(), billingCycleDay: z.string().optional(), currency: z.string().optional(), paymentGatewayId: z.string().nullable().optional(), billingRunId: z.string().optional()}).and(z.record(z.string(), z.object({}))); export const getApiObjectQueryPaymentRunsResponse = z.object({nextPage: z.string().nullable().optional(), data: z.array(expandedPaymentRun).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 }; /** * List payment runs * * GET /object-query/payment-runs */ export const getApiObjectQueryPaymentRuns = async (args: GetApiObjectQueryPaymentRunsArgs, options?: GetApiObjectQueryPaymentRunsOptions) => { const {baseUrl = "https://rest.test.zuora.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (args['Accept-Encoding'] != null) headers.set("Accept-Encoding", String(args['Accept-Encoding'])) if (args['Content-Encoding'] != null) headers.set("Content-Encoding", String(args['Content-Encoding'])) if (args['Zuora-Track-Id'] != null) headers.set("Zuora-Track-Id", String(args['Zuora-Track-Id'])) if (args['Zuora-Entity-Ids'] != null) headers.set("Zuora-Entity-Ids", String(args['Zuora-Entity-Ids'])) if (args['Zuora-Org-Ids'] != null) headers.set("Zuora-Org-Ids", String(args['Zuora-Org-Ids'])) if (args['Zuora-Version'] != null) headers.set("Zuora-Version", String(args['Zuora-Version'])) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.cursor != null) query.append("cursor", String(args.cursor)) for (const item of args['sort[]'] ?? []) query.append("sort[]", String(item)) for (const item of args['expand[]'] ?? []) query.append("expand[]", String(item)) for (const item of args['filter[]'] ?? []) query.append("filter[]", String(item)) for (const item of args['fields[]'] ?? []) query.append("fields[]", String(item)) if (args.includeNullFields != null) query.append("includeNullFields", String(args.includeNullFields)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/object-query/payment-runs${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(getApiObjectQueryPaymentRunsResponse, await res.json()) };