import {z} from 'zod' export type AccountType = 'MMDA' | 'DDA'; export type PhoneNumberData = {number: string, is_primary?: boolean | undefined}; export type EmailData = {email_address: 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 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 CreateDepositorRequest = {tin: string, first_name?: (string | null) | undefined, last_name?: (string | null) | undefined, entity_name?: (string | null) | undefined, is_organization?: boolean | undefined, institution_depositor_id?: (string | null) | undefined, phone_numbers?: (Array | null) | undefined, emails?: (Array | null) | undefined, addresses?: (Array | null) | undefined, account_ids?: (Array | null) | undefined, depositor_type?: (DepositorType | null) | undefined, ownership_category?: (OwnershipCategory | null) | undefined, account_officer?: (string | null) | undefined, notes?: (string | null) | undefined, institution_opt_out_federal_ids?: (Array | null) | undefined}; export type ReferenceRateType = 'EFFR' | 'CU_RECEIVE_DEFAULT' | 'BANK_RECEIVE_DEFAULT' | 'EFFR_UPPER_BAND' | 'EFFR_LOWER_BAND' | 'SOFR_OVERNIGHT' | 'SOFR_1M' | 'SOFR_3M' | 'SOFR_6M' | 'SOFR_12M' | 'CMT_1M' | 'CMT_3M' | 'CMT_6M' | 'FIDELITY_FISXX' | 'FIDELITY_SPAXX' | 'FIDELITY_FCIXX' | 'WSJ_PRIME' | 'IORB'; export type InterestRateTierRequest = {min_balance: number | string, max_balance: number | string, rate?: (number | string | null) | undefined, floating_spread?: (number | string | null) | undefined, rate_index_type?: (ReferenceRateType | null) | undefined, floating_rate_percentage?: (number | string | null) | undefined}; export type ShadowAccountRequest = {account_number: string, account_type: AccountType}; export type CreateAccountRequest = {signer_primary?: (string | null) | undefined, signer_primary_tin?: (string | null) | undefined, account_title: string, account_type: AccountType, depositor_ids: Array, depositor?: (CreateDepositorRequest | null) | undefined, interest_rate_tiers?: Array | undefined, program_tags?: Array | undefined, is_apy?: boolean | undefined, interest_rate?: (number | null) | undefined, signer_secondary?: (string | null) | undefined, beneficiary_name?: (string | null) | undefined, beneficiary_tin?: (string | null) | undefined, institution_account_id?: (string | null) | undefined, institution_sweep_account_id?: (string | null) | undefined, institution_return_account_id?: (string | null) | undefined, institution_branch_id?: (string | null) | undefined, institution_cost_center_id?: (string | null) | undefined, cost_center_id?: (string | null) | undefined, managed_sweep_target_balance?: (number | string | null) | undefined, shadow_account?: (ShadowAccountRequest | null) | undefined, account_agreement_file_data?: (string | null) | undefined, notes?: (string | null) | undefined, pricing_group_id?: (string | null) | undefined, is_reciprocation_prioritized?: boolean | undefined, is_receiving_printed_statements?: boolean | undefined, account_officer?: (string | null) | undefined, is_non_interest_bearing?: boolean | undefined, custom_field_1?: (string | null) | undefined, custom_field_2?: (string | null) | undefined, custom_field_3?: (string | null) | undefined, custom_field_4?: (string | null) | undefined}; export type CreateApiDigitalBankingV1AccountsArgs = {'idempotency-key': string, body: CreateAccountRequest}; export type CreateApiDigitalBankingV1AccountsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const referenceRateType = z.enum(["EFFR", "CU_RECEIVE_DEFAULT", "BANK_RECEIVE_DEFAULT", "EFFR_UPPER_BAND", "EFFR_LOWER_BAND", "SOFR_OVERNIGHT", "SOFR_1M", "SOFR_3M", "SOFR_6M", "SOFR_12M", "CMT_1M", "CMT_3M", "CMT_6M", "FIDELITY_FISXX", "FIDELITY_SPAXX", "FIDELITY_FCIXX", "WSJ_PRIME", "IORB"]); export const interestRateTierResponse = z.object({min_balance: z.string(), max_balance: z.string(), rate: z.string().nullable().optional(), floating_spread: z.string().nullable().optional(), rate_index_type: referenceRateType.nullable().optional(), floating_rate_percentage: z.string().nullable().optional(), custom_benchmark_id: z.string().nullable().optional()}); export const accountType = z.enum(["MMDA", "DDA"]); 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 shadowAccountResponse = z.object({id: z.string(), account_number: z.string(), account_type: accountType, closed_at: z.string().nullable().optional()}); export const rateConfiguration = z.enum(["FIXED", "FLOATING_MARKET", "FLOATING_CUSTOM", "TIERED", "MIXED"]); export const accountResponse = z.object({id: z.string(), institution_id: z.string(), signer_primary: z.string().nullable(), signer_primary_tin_last4: z.string().nullable().optional(), account_title: z.string(), interest_rate: z.string(), interest_rate_apy: z.string(), mtd_accrued_interest: z.string(), interest_rate_tiers: z.array(interestRateTierResponse), insurance_limit: z.string(), account_type: accountType, created_at: z.string(), is_joint_account: z.boolean(), total_balance: z.string(), total_balance_updated_at: z.string().nullable().optional(), pending_balance: z.string(), closed_at: z.string().nullable().optional(), signer_secondary: z.string().nullable().optional(), beneficiary_name: z.string().nullable().optional(), beneficiary_tin: z.string().nullable().optional(), beneficiary_tin_last4: z.string().nullable().optional(), institution_account_id: z.string().nullable().optional(), institution_sweep_account_id: z.string().nullable().optional(), institution_return_account_id: z.string().nullable().optional(), institution_branch_id: z.string().nullable().optional(), institution_alternative_id: z.string().nullable().optional(), cost_center_id: z.string().nullable().optional(), cost_center_code: z.string().nullable().optional(), depositors: z.array(depositorResponse).nullable().optional(), managed_sweep_target_balance: z.string().nullable().optional(), shadow_account: shadowAccountResponse.nullable().optional(), notes: z.string().nullable().optional(), pricing_group_id: z.string().nullable().optional(), is_reciprocation_prioritized: z.boolean(), is_receiving_printed_statements: z.boolean(), rate: z.string().nullable().optional(), floating_spread: z.string().nullable().optional(), floating_spread_bps: z.string().nullable().optional(), rate_index_type: referenceRateType.nullable().optional(), floating_rate_percentage: z.string().nullable().optional(), index_rate: z.string().nullable().optional(), custom_benchmark_id: z.string().nullable().optional(), custom_benchmark_rate: z.string().nullable().optional(), rate_configuration: rateConfiguration, account_officer: z.string().nullable().optional(), is_non_interest_bearing: z.boolean().optional(), custom_field_1: z.string().nullable().optional(), custom_field_2: z.string().nullable().optional(), custom_field_3: z.string().nullable().optional(), custom_field_4: z.string().nullable().optional(), is_q2_funds_transfer_enabled: 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 }; /** * Create Account * * POST /digital-banking/v1/accounts */ export const createApiDigitalBankingV1Accounts = async (args: CreateApiDigitalBankingV1AccountsArgs, options: CreateApiDigitalBankingV1AccountsOptions) => { 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 (args['idempotency-key'] != null) headers.set("idempotency-key", String(args['idempotency-key'])) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/digital-banking/v1/accounts${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(accountResponse, await res.json()) };