import {z} from 'zod' export type GetApiPayablesPayerAccountsPayerIdPayeesArgs = {Authorization: string, payer_id: string, after_cursor?: string | undefined, before_cursor?: string | undefined, limit?: number | undefined, created_after?: string | undefined, created_before?: string | undefined, status?: ('pending' | 'active' | 'disabled' | 'archived') | undefined}; export type GetApiPayablesPayerAccountsPayerIdPayeesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPayablesPayerAccountsPayerIdPayeesResponse = 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().optional(), name: z.string().optional(), entity_type: z.enum(["c_corporation", "s_corporation", "partnership", "limited_liability_company", "sole_proprietorship"]).optional(), email: z.string().nullable().optional(), tax_id_last4: z.string().optional(), address: z.object({line1: z.string().optional(), line2: z.string().nullable().optional(), city: z.string().optional(), state: z.string().optional(), postal_code: z.string().optional(), country: z.literal("USA").optional()}).optional(), receiving_bank_account_id: z.string().nullable().optional(), business_id: z.string().nullable().optional(), status: z.enum(["pending", "active", "disabled", "archived"]).optional(), metadata: z.object({}).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 Payees * * GET /payables/payer_accounts/{payer_id}/payees */ export const getApiPayablesPayerAccountsPayerIdPayees = async (args: GetApiPayablesPayerAccountsPayerIdPayeesArgs, options?: GetApiPayablesPayerAccountsPayerIdPayeesOptions) => { 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.created_after != null) query.append("created_after", String(args.created_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (args.status != null) query.append("status", String(args.status)) const url = `${baseUrl.replace(/\/+$/, '')}/payables/payer_accounts/${encodeURIComponent(String(args.payer_id))}/payees${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(getApiPayablesPayerAccountsPayerIdPayeesResponse, await res.json()) };