import {z} from 'zod' export type GetApiV4FundsDistributionPaymentsArgs = {continuationToken?: string | undefined, size?: number | undefined, submissionId?: string | undefined, accountId?: string | undefined, processorType?: string | undefined, payeeId?: string | undefined, approverId?: string | undefined, idempotencyKey?: string | undefined}; export type GetApiV4FundsDistributionPaymentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const listFundsDistributionPaymentResponse = z.object({paymentId: z.string().optional(), friendlyPaymentId: z.string().nullable().optional(), idempotencyKey: z.string().nullable().optional(), approverId: z.string().nullable().optional(), payeeId: z.string().nullable().optional(), contextId: z.string().nullable().optional(), accountId: z.string().optional(), processor: z.string().nullable().optional(), amount: z.number().optional(), status: z.string().nullable().optional(), paidAt: z.string().nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().nullable().optional(), errorMessage: z.string().nullable().optional(), checkNumber: z.number().int().nullable().optional(), processorTransactionId: z.string().nullable().optional(), processorIdempotencyKey: z.string().nullable().optional(), eTag: z.string().nullable().optional()}); export const continuationTokenResponseListFundsDistributionPaymentResponse = z.object({continuationToken: z.string().nullable().optional(), items: z.array(listFundsDistributionPaymentResponse).nullable().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 }; /** * GET /v4/funds-distribution/payments */ export const getApiV4FundsDistributionPayments = async (args: GetApiV4FundsDistributionPaymentsArgs, options?: GetApiV4FundsDistributionPaymentsOptions) => { const {baseUrl = "https://submittable-api.submittable.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.continuationToken != null) query.append("continuationToken", String(args.continuationToken)) if (args.size != null) query.append("size", String(args.size)) if (args.submissionId != null) query.append("submissionId", String(args.submissionId)) if (args.accountId != null) query.append("accountId", String(args.accountId)) if (args.processorType != null) query.append("processorType", String(args.processorType)) if (args.payeeId != null) query.append("payeeId", String(args.payeeId)) if (args.approverId != null) query.append("approverId", String(args.approverId)) if (args.idempotencyKey != null) query.append("idempotencyKey", String(args.idempotencyKey)) const url = `${baseUrl.replace(/\/+$/, '')}/v4/funds-distribution/payments${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(continuationTokenResponseListFundsDistributionPaymentResponse, await res.json()) };