import {z} from 'zod' export type CreateApiPayablesPayerAccountsPayerIdPayeesArgs = {Authorization: string, payer_id: string, body: {name: string, entity_type: 'c_corporation' | 's_corporation' | 'partnership' | 'limited_liability_company' | 'sole_proprietorship', tax_id: string, address: {line1?: string | undefined, line2?: (string | null) | undefined, city?: string | undefined, state?: string | undefined, postal_code?: string | undefined, country?: 'USA' | undefined}, email?: string | undefined, metadata?: Record | undefined}}; export type CreateApiPayablesPayerAccountsPayerIdPayeesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiPayablesPayerAccountsPayerIdPayeesResponse = z.object({id: z.string(), type: z.string(), data: 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.unknown()}); 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 }; /** * Create a Payee * * POST /payables/payer_accounts/{payer_id}/payees */ export const createApiPayablesPayerAccountsPayerIdPayees = async (args: CreateApiPayablesPayerAccountsPayerIdPayeesArgs, options?: CreateApiPayablesPayerAccountsPayerIdPayeesOptions) => { const {baseUrl = "https://api.justifi.ai/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/payables/payer_accounts/${encodeURIComponent(String(args.payer_id))}/payees${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiPayablesPayerAccountsPayerIdPayeesResponse, await res.json()) };