import {z} from 'zod' export type DepositorType = 'CONSUMER' | 'BUSINESS' | 'NONPROFIT' | 'LOCAL_GOVERNMENT' | 'FEDERAL_GOVERNMENT' | 'US_DEPOSITORY' | 'FOREIGN_DEPOSITORY' | 'FOREIGN_GOVERNMENT'; export type OwnershipCategory = 'JOINT' | 'SINGLE' | 'RETIREMENT' | 'ESTATE_REVOCABLE_TRUST' | 'OTHER_CONSUMER' | 'CORPORATION' | 'LIMITED_LIABILITY_COMPANY' | 'LIMITED_PARTNERSHIP' | 'SOLE_PROPRIETORSHIP' | 'OTHER_BUSINESS' | 'CLUBS_ASSOCIATIONS' | 'OTHER_NONPROFIT' | 'MUNICIPALITIES' | 'SCHOOL_DISTRICTS' | 'OTHER_LOCAL_GOVERNMENT' | 'US_GOVERNMENT' | 'US_DEPOSITORY'; export type PhoneNumberData = {number: string, is_primary?: boolean | undefined}; export type AddressData = {street: string, city: string, state: string, zip: string, country_code: string, is_primary?: boolean | undefined}; export type ApprovalStatus = 'PENDING' | 'APPROVED' | 'REJECTED'; export type UpdateDepositorRequest = {first_name?: (string | null) | undefined, last_name?: (string | null) | undefined, entity_name?: (string | null) | undefined, institution_depositor_id?: (string | null) | undefined, depositor_type?: (DepositorType | null) | undefined, ownership_category?: (OwnershipCategory | null) | undefined, account_officer?: (string | null) | undefined, notes?: (string | null) | undefined, phone_numbers?: (Array | null) | undefined, addresses?: (Array | null) | undefined, approval_status?: (ApprovalStatus | null) | undefined, account_ids?: (Array | null) | undefined, institution_opt_out_federal_ids?: (Array | null) | undefined}; export type PatchApiDigitalBankingV1DepositorsDepositorIdArgs = {depositor_id: string, body: UpdateDepositorRequest}; export type PatchApiDigitalBankingV1DepositorsDepositorIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const phoneNumberData = z.object({number: z.string().max(32), is_primary: z.boolean().optional()}); export const emailData = z.object({email_address: z.string(), is_primary: z.boolean().optional()}); export const addressData = z.object({street: z.string().max(64), city: z.string().max(32), state: z.string().max(32), zip: z.string().max(32), country_code: z.string(), is_primary: z.boolean().optional()}); export const depositorType = z.enum(["CONSUMER", "BUSINESS", "NONPROFIT", "LOCAL_GOVERNMENT", "FEDERAL_GOVERNMENT", "US_DEPOSITORY", "FOREIGN_DEPOSITORY", "FOREIGN_GOVERNMENT"]); export const ownershipCategory = z.enum(["JOINT", "SINGLE", "RETIREMENT", "ESTATE_REVOCABLE_TRUST", "OTHER_CONSUMER", "CORPORATION", "LIMITED_LIABILITY_COMPANY", "LIMITED_PARTNERSHIP", "SOLE_PROPRIETORSHIP", "OTHER_BUSINESS", "CLUBS_ASSOCIATIONS", "OTHER_NONPROFIT", "MUNICIPALITIES", "SCHOOL_DISTRICTS", "OTHER_LOCAL_GOVERNMENT", "US_GOVERNMENT", "US_DEPOSITORY"]); export const depositorResponse = z.object({id: z.string(), institution_id: z.string(), institution_depositor_id: z.string().nullable(), tin: z.string().nullable().optional(), tin_last_four: z.string().nullable().optional(), first_name: z.string().nullable(), last_name: z.string().nullable(), entity_name: z.string().nullable(), is_organization: z.boolean(), phone_numbers: z.array(phoneNumberData), emails: z.array(emailData), addresses: z.array(addressData), depositor_type: depositorType, ownership_category: ownershipCategory.nullable().optional(), account_officer: z.string().nullable().optional(), notes: z.string().nullable().optional(), institution_opt_out_federal_ids: z.array(z.string()).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 }; /** * Update Depositor * * PATCH /digital-banking/v1/depositors/{depositor_id} */ export const patchApiDigitalBankingV1DepositorsDepositorId = async (args: PatchApiDigitalBankingV1DepositorsDepositorIdArgs, options: PatchApiDigitalBankingV1DepositorsDepositorIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/digital-banking/v1/depositors/${encodeURIComponent(String(args.depositor_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(depositorResponse, await res.json()) };