import {z} from 'zod' export type GetApiPayablesPayerAccountsPayerIdBankAccountsArgs = {Authorization: string, payer_id: string, after_cursor?: string | undefined, before_cursor?: string | undefined, limit?: number | undefined, payee_id?: string | undefined, funding?: boolean | undefined}; export type GetApiPayablesPayerAccountsPayerIdBankAccountsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPayablesPayerAccountsPayerIdBankAccountsResponse = z.object({id: z.unknown(), type: z.string(), data: z.array(z.object({id: z.string().optional(), type: z.string().optional(), payer_account_id: z.string().nullable().optional(), account_holder_name: z.string().optional(), routing_number: z.string().optional(), account_number_last4: z.string().optional(), account_type: z.enum(["checking", "savings"]).optional(), payee_id: z.string().nullable().optional(), verification_status: z.enum(["not_required", "pending", "verified", "failed"]).optional(), created_at: z.string().optional(), updated_at: z.string().optional()})), page_info: z.object({start_cursor: z.string().optional(), end_cursor: z.string().optional(), has_next: z.boolean().optional(), has_previous: z.boolean().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 Bank Accounts * * GET /payables/payer_accounts/{payer_id}/bank_accounts */ export const getApiPayablesPayerAccountsPayerIdBankAccounts = async (args: GetApiPayablesPayerAccountsPayerIdBankAccountsArgs, options?: GetApiPayablesPayerAccountsPayerIdBankAccountsOptions) => { const {baseUrl = "https://api.justifi.ai/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.after_cursor != null) query.append("after_cursor", String(args.after_cursor)) if (args.before_cursor != null) query.append("before_cursor", String(args.before_cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.payee_id != null) query.append("payee_id", String(args.payee_id)) if (args.funding != null) query.append("funding", String(args.funding)) const url = `${baseUrl.replace(/\/+$/, '')}/payables/payer_accounts/${encodeURIComponent(String(args.payer_id))}/bank_accounts${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(getApiPayablesPayerAccountsPayerIdBankAccountsResponse, await res.json()) };