import {z} from 'zod' export type DepositorType = 'CONSUMER' | 'BUSINESS' | 'NONPROFIT' | 'LOCAL_GOVERNMENT' | 'FEDERAL_GOVERNMENT' | 'US_DEPOSITORY' | 'FOREIGN_DEPOSITORY' | 'FOREIGN_GOVERNMENT'; export type GetApiDigitalBankingV1DepositorsArgs = {name?: (string | null) | undefined, institution_depositor_id?: (string | null) | undefined, depositor_type?: (DepositorType | null) | undefined}; export type GetApiDigitalBankingV1DepositorsOptions = {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 getApiDigitalBankingV1DepositorsResponse = z.array(depositorResponse); 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 Depositors * * GET /digital-banking/v1/depositors */ export const getApiDigitalBankingV1Depositors = async (args: GetApiDigitalBankingV1DepositorsArgs, options: GetApiDigitalBankingV1DepositorsOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.name != null) query.append("name", String(args.name)) if (args.institution_depositor_id != null) query.append("institution_depositor_id", String(args.institution_depositor_id)) if (args.depositor_type != null) query.append("depositor_type", String(args.depositor_type)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/digital-banking/v1/depositors${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(getApiDigitalBankingV1DepositorsResponse, await res.json()) };