import {z} from 'zod' export type IdType = 'INSTITUTION'; export type GetApiDigitalBankingV1DepositorsDepositorIdArgs = {depositor_id: string | string, id_type?: (IdType | null) | undefined}; export type GetApiDigitalBankingV1DepositorsDepositorIdOptions = {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 }; /** * Get Depositor * * GET /digital-banking/v1/depositors/{depositor_id} */ export const getApiDigitalBankingV1DepositorsDepositorId = async (args: GetApiDigitalBankingV1DepositorsDepositorIdArgs, options: GetApiDigitalBankingV1DepositorsDepositorIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.id_type != null) query.append("id_type", String(args.id_type)) 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: "GET", headers}) 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()) };