import {z} from 'zod' export type UpdateAccountRequest = {depositor_ids?: (Array | null) | undefined, account_title?: (string | null) | undefined, institution_sweep_account_id?: (string | null) | undefined, institution_return_account_id?: (string | null) | undefined, is_reciprocation_prioritized?: (boolean | null) | undefined, is_receiving_printed_statements?: (boolean | null) | undefined, signer_primary?: (string | null) | undefined, signer_secondary?: (string | null) | undefined, beneficiary_name?: (string | null) | undefined, institution_cost_center_id?: (string | null) | undefined, cost_center_id?: (string | null) | undefined, notes?: (string | null) | undefined, managed_sweep_target_balance?: (number | string | null) | undefined, program_tags?: (Array | null) | undefined, institution_alternative_id?: (string | null) | undefined, account_officer?: (string | null) | 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 PatchApiDigitalBankingV1AccountsAccountIdArgs = {account_id: string, body: UpdateAccountRequest}; export type PatchApiDigitalBankingV1AccountsAccountIdOptions = {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 }; /** * Update Account * * PATCH /digital-banking/v1/accounts/{account_id} */ export const patchApiDigitalBankingV1AccountsAccountId = async (args: PatchApiDigitalBankingV1AccountsAccountIdArgs, options: PatchApiDigitalBankingV1AccountsAccountIdOptions) => { 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/accounts/${encodeURIComponent(String(args.account_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(accountResponse, await res.json()) };