import {z} from 'zod' export type GetInvestmentHoldingsRequest = {access_token: string, options?: ({remote_account_ids?: Array | undefined}) | undefined}; export type CreateApiV1FinancialConnectionsInvestmentsHoldingsArgs = {'Fuse-Client-Id': string, 'Fuse-Api-Key': string, 'Plaid-Client-Id'?: string | undefined, 'Plaid-Secret'?: string | undefined, 'Teller-Application-Id'?: string | undefined, 'Teller-Certificate'?: string | undefined, 'Teller-Private-Key'?: string | undefined, 'Teller-Token-Signing-Key'?: string | undefined, 'Teller-Signing-Secret'?: string | undefined, 'Mx-Client-Id'?: string | undefined, 'Mx-Api-Key'?: string | undefined, 'Snaptrade-Client-Id'?: string | undefined, 'Snaptrade-Consumer-Key'?: string | undefined, 'Flinks-Ca-Customer-Id'?: string | undefined, 'Flinks-Us-Customer-Id'?: string | undefined, 'Flinks-Us-Instance-Id'?: string | undefined, 'Flinks-Ca-Instance-Id'?: string | undefined, 'Mono-Public-Key'?: string | undefined, 'Mono-Secret-Key'?: string | undefined, 'Mono-Webhook-Secret'?: string | undefined, 'TrueLayer-Client-Id'?: string | undefined, 'TrueLayer-Client-Secret'?: string | undefined, 'Finverse-Client-Id'?: string | undefined, 'Finverse-Client-Secret'?: string | undefined, 'Belvo-Secret-Id'?: string | undefined, 'Belvo-Secret-Password'?: string | undefined, 'Finicity-Partner-Secret'?: string | undefined, 'Finicity-Partner-Id'?: string | undefined, 'Finicity-App-Key'?: string | undefined, 'Basiq-Api-Key'?: string | undefined, 'Akoya-Client-Id'?: string | undefined, 'Akoya-Client-Secret'?: string | undefined, 'SaltEdge-App-Id'?: string | undefined, 'SaltEdge-App-Secret'?: string | undefined, body: GetInvestmentHoldingsRequest}; export type CreateApiV1FinancialConnectionsInvestmentsHoldingsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const financialConnectionsInvestmentSecurityType = z.enum(["cash", "cryptocurrency", "derivative", "equity", "etf", "fixed_income", "loan", "mutual_fund", "other", "global_depositary_receipt", "open_ended_fund", "right", "temporary", "warrant", "closed_ended_fund", "common_stock", "exchange_traded_fund", "bond", "american_depositary_receipt", "unit", "structured_product", "preferred_stock", "real_estate", "automobile", "delisted_or_defunct_asset", "-"]); export const financialConnectionsInvestmentSecurity = z.object({remote_id: z.string(), symbol: z.string(), isin: z.string().optional(), sedol: z.string().optional(), cusip: z.string().optional(), close_price: z.number().optional(), currency: z.object({code: z.string(), name: z.string().optional()}), name: z.string().optional(), type: financialConnectionsInvestmentSecurityType.optional(), exchange: z.object({mic_code: z.string().optional(), suffix: z.string().optional()}).optional()}); export const financialConnectionsHolding = z.object({remote_account_id: z.string(), cost_basis: z.number(), value: z.number(), quantity: z.number(), institution_price: z.number(), security: financialConnectionsInvestmentSecurity}); export const getInvestmentHoldingsResponse = z.object({accounts: z.array(z.object({remote_id: z.string(), currency: z.string(), fingerprint: z.string(), institution: z.object({name: z.string().optional()}).optional(), mask: z.string().nullable().optional(), name: z.string(), type: z.enum(["depository", "credit", "loan", "investment", "insurance", "property", "annuity", "other", "-"]), subtype: z.enum(["checking", "savings", "checking_or_savings", "business_checking_or_savings", "business_savings", "money_market", "certificate_of_deposit", "treasury", "credit_card", "debit_card", "bonds", "hsa", "paypal", "prepaid", "cash_management", "ebt", "auto", "business", "commercial", "construction", "consumer", "home_equity", "foreign", "loan", "mortgage", "overdraft", "line_of_credit", "student", "529", "401_a", "401_k", "403_b", "457_b", "funds", "brokerage", "securities", "stocks", "cash_isa", "crypto_exchange", "education_saving_account", "fixed_annuity", "gic", "health_reimbursement_arrangement", "ira", "isa", "keogh", "lif", "life_insurance", "lira", "lrif", "lrsp", "mutual_fund", "non_custodial_wallet", "non_taxable_brokerage_account", "other_annuity", "other_insurance", "pension", "prif", "profit_sharing_plan", "qshr", "rdsp", "resp", "retirement", "rlif", "roth_ira", "roth_401_k", "rrif", "rrsp", "sarsep", "sep_ira", "simple_ira", "sipp", "stock_plan", "tfsa", "trust", "ugma", "utma", "variable_annuity", "small_business", "personal", "personal_with_collateral", "457", "rollover_ira", "taxable", "non_taxable", "employee_stock_ownership_plan", "individual", "cash_management_account", "employee_stock_purchase_plan", "registered_education_savings_plan", "fixed_annuity_traditional_ira", "inherited_traditional_ira", "fixed_annuity_roth_ira", "variable_annuity_roth_ira", "inherited_roth_ira", "advisory_account", "brokerage_margin", "charitable_gift_account", "church_account", "conservatorship", "custodial", "defined_benefit_plan", "defined_contribution_plan", "educational", "estate", "executor", "group_retirement_savings_plan", "guaranteed_investment_certificate", "indexed_annuity", "investment_club", "irrevocable_trust", "joint_tenants_by_entirety", "joint_tenants_community_property", "joint_tenants_in_common", "joint_tenants_with_rights_of_survivorship", "keough_plan", "living_trust", "locked_in_retirement_account", "locked_in_retirement_investment_fund", "locked_in_retirement_savings_account", "money_purchase_plan", "partnership", "409_a", "rpp", "revocable_trust", "roth_conversion", "sole_proprietorship", "spousal_ira", "spousal_roth_ira", "testamentary_trust", "thrift_savings_plan", "inherited_annuity", "corporate_account", "limited_liability_account", "boat", "powersports", "rv", "heloc", "vehicle_insurance", "disability", "health", "long_term_care", "property_and_casualty", "universal_life", "term_life", "whole_life", "accidental_death_and_dismemberment", "variable_universal_life", "revolving", "other", "time_deposit", "roth", "military", "installment", "institutional_trust", "home_line_of_credit", "guardian", "commercial_line_of_credit", "charge", "coverdell", "escrow", "-"]).nullable().optional(), balance: z.object({available: z.number().nullable().optional(), current: z.number().nullable().optional(), buying_power: z.number().nullable().optional(), iso_currency_code: z.string().nullable().optional(), last_updated_date: z.string().nullable().optional()}), additional_balances: z.array(z.unknown()).optional(), remote_data: z.unknown()})), holdings: z.array(financialConnectionsHolding), request_id: z.string()}); 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 investment holdings * * POST /v1/financial_connections/investments/holdings */ export const createApiV1FinancialConnectionsInvestmentsHoldings = async (args: CreateApiV1FinancialConnectionsInvestmentsHoldingsArgs, options?: CreateApiV1FinancialConnectionsInvestmentsHoldingsOptions) => { const {baseUrl = "https://sandbox-api.letsfuse.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Fuse-Client-Id'] != null) headers.set("Fuse-Client-Id", String(args['Fuse-Client-Id'])) if (args['Fuse-Api-Key'] != null) headers.set("Fuse-Api-Key", String(args['Fuse-Api-Key'])) if (args['Plaid-Client-Id'] != null) headers.set("Plaid-Client-Id", String(args['Plaid-Client-Id'])) if (args['Plaid-Secret'] != null) headers.set("Plaid-Secret", String(args['Plaid-Secret'])) if (args['Teller-Application-Id'] != null) headers.set("Teller-Application-Id", String(args['Teller-Application-Id'])) if (args['Teller-Certificate'] != null) headers.set("Teller-Certificate", String(args['Teller-Certificate'])) if (args['Teller-Private-Key'] != null) headers.set("Teller-Private-Key", String(args['Teller-Private-Key'])) if (args['Teller-Token-Signing-Key'] != null) headers.set("Teller-Token-Signing-Key", String(args['Teller-Token-Signing-Key'])) if (args['Teller-Signing-Secret'] != null) headers.set("Teller-Signing-Secret", String(args['Teller-Signing-Secret'])) if (args['Mx-Client-Id'] != null) headers.set("Mx-Client-Id", String(args['Mx-Client-Id'])) if (args['Mx-Api-Key'] != null) headers.set("Mx-Api-Key", String(args['Mx-Api-Key'])) if (args['Snaptrade-Client-Id'] != null) headers.set("Snaptrade-Client-Id", String(args['Snaptrade-Client-Id'])) if (args['Snaptrade-Consumer-Key'] != null) headers.set("Snaptrade-Consumer-Key", String(args['Snaptrade-Consumer-Key'])) if (args['Flinks-Ca-Customer-Id'] != null) headers.set("Flinks-Ca-Customer-Id", String(args['Flinks-Ca-Customer-Id'])) if (args['Flinks-Us-Customer-Id'] != null) headers.set("Flinks-Us-Customer-Id", String(args['Flinks-Us-Customer-Id'])) if (args['Flinks-Us-Instance-Id'] != null) headers.set("Flinks-Us-Instance-Id", String(args['Flinks-Us-Instance-Id'])) if (args['Flinks-Ca-Instance-Id'] != null) headers.set("Flinks-Ca-Instance-Id", String(args['Flinks-Ca-Instance-Id'])) if (args['Mono-Public-Key'] != null) headers.set("Mono-Public-Key", String(args['Mono-Public-Key'])) if (args['Mono-Secret-Key'] != null) headers.set("Mono-Secret-Key", String(args['Mono-Secret-Key'])) if (args['Mono-Webhook-Secret'] != null) headers.set("Mono-Webhook-Secret", String(args['Mono-Webhook-Secret'])) if (args['TrueLayer-Client-Id'] != null) headers.set("TrueLayer-Client-Id", String(args['TrueLayer-Client-Id'])) if (args['TrueLayer-Client-Secret'] != null) headers.set("TrueLayer-Client-Secret", String(args['TrueLayer-Client-Secret'])) if (args['Finverse-Client-Id'] != null) headers.set("Finverse-Client-Id", String(args['Finverse-Client-Id'])) if (args['Finverse-Client-Secret'] != null) headers.set("Finverse-Client-Secret", String(args['Finverse-Client-Secret'])) if (args['Belvo-Secret-Id'] != null) headers.set("Belvo-Secret-Id", String(args['Belvo-Secret-Id'])) if (args['Belvo-Secret-Password'] != null) headers.set("Belvo-Secret-Password", String(args['Belvo-Secret-Password'])) if (args['Finicity-Partner-Secret'] != null) headers.set("Finicity-Partner-Secret", String(args['Finicity-Partner-Secret'])) if (args['Finicity-Partner-Id'] != null) headers.set("Finicity-Partner-Id", String(args['Finicity-Partner-Id'])) if (args['Finicity-App-Key'] != null) headers.set("Finicity-App-Key", String(args['Finicity-App-Key'])) if (args['Basiq-Api-Key'] != null) headers.set("Basiq-Api-Key", String(args['Basiq-Api-Key'])) if (args['Akoya-Client-Id'] != null) headers.set("Akoya-Client-Id", String(args['Akoya-Client-Id'])) if (args['Akoya-Client-Secret'] != null) headers.set("Akoya-Client-Secret", String(args['Akoya-Client-Secret'])) if (args['SaltEdge-App-Id'] != null) headers.set("SaltEdge-App-Id", String(args['SaltEdge-App-Id'])) if (args['SaltEdge-App-Secret'] != null) headers.set("SaltEdge-App-Secret", String(args['SaltEdge-App-Secret'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/financial_connections/investments/holdings${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(getInvestmentHoldingsResponse, await res.json()) };