import {z} from 'zod' export type GetApiObjectQueryPaymentSchedulesArgs = {'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 GetApiObjectQueryPaymentSchedulesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const expandedPaymentSchedule = z.object({id: z.string().optional(), createdById: z.string().optional(), createdDate: z.string().optional(), updatedById: z.string().optional(), updatedDate: z.string().optional(), number: z.string().optional(), accountId: z.string().optional(), invoiceId: z.string().optional(), debitmemoId: z.string().optional(), paymentOptionId: z.string().optional(), startDate: z.string().optional(), runHour: z.number().int().gte(0).lte(23).optional(), period: z.enum(["Monthly", "Weekly", "BiWeekly", "null"]).nullable().optional(), prepayment: z.boolean().optional(), occurrences: z.number().int().optional(), status: z.enum(["Active", "Canceled", "Completed"]).optional(), description: z.string().optional(), nextPaymentDate: z.string().optional(), recentPaymentDate: z.string().optional(), totalPaymentsProcessed: z.number().int().optional(), totalPaymentsErrored: z.number().int().optional(), totalAmount: z.number().optional()}).and(z.record(z.string(), z.object({}))); export const getApiObjectQueryPaymentSchedulesResponse = z.object({nextPage: z.string().nullable().optional(), data: z.array(expandedPaymentSchedule).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 schedules * * GET /object-query/payment-schedules */ export const getApiObjectQueryPaymentSchedules = async (args: GetApiObjectQueryPaymentSchedulesArgs, options?: GetApiObjectQueryPaymentSchedulesOptions) => { 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-schedules${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(getApiObjectQueryPaymentSchedulesResponse, await res.json()) };