import {z} from 'zod' export type GetApiV2AccountsMainAccountIdBusinessesArgs = {main_account_id: string, page?: number | undefined, size?: number | undefined, external_id?: string | undefined, parent_account_id?: string | undefined, main_only?: boolean | undefined}; export type GetApiV2AccountsMainAccountIdBusinessesOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const accountId = z.string(); export const organizationType = z.enum(["CORPORATION", "LLC", "PARTNERSHIP", "SOLE_PROPRIETORSHIP", "INVESTMENT_FUND", "SOCIETIES", "TRUST", "GOVERNMENT", "DAO"]); export const industry = z.enum(["ACCOMMODATION_AND_FOOD_SERVICE", "ADMINISTRATIVE_SUPPORT_SERVICES", "ADULT_ENTERTAINMENT", "ADVERTISING_MARKETING_PR", "AGRICULTURE_FORESTRY_FISHING", "ARMS_INDUSTRY", "ART_ANTIQUITIES_DEALERS", "ARTS_ENTERTAINMENT_RECREATION", "BANKING_RFI", "BROKERAGE_OTC", "CEX_DEX", "CHARITIES_NON_PROFIT", "COMMODITY_TRADING", "COMPANY_FORMATION_TCSP", "CONSTRUCTION", "OIL_GAS", "CRYPTO_ATM", "CRYPTO_CARDS", "CRYPTO_GIFT_CARDS", "CRYPTO_MINING", "CRYPTO_CUSTODY", "DEFI", "EDUCATION", "FAMILY_OFFICE", "DAO_FOUNDATION", "FREIGHT_FORWARDING", "GAMBLING", "GAMING_METAVERSE", "MANUFACTURING", "WHOLESALERS", "HEALTHCARE", "IMPORT_EXPORT_TRADE_FINANCE", "INVESTMENT_FUND", "HOLDING_COMPANY", "MARIJUANA", "MEDIA", "MINING_EXTRACTION", "MSB_PSP", "NFT_MARKETPLACE", "NON_BANK_FI", "NON_CUSTODIAL_WALLET", "P2P_MERCHANTS", "PAWN_SHOPS", "PAYROLL_PEO_EOR", "PERSONAL_INVESTMENT", "PLAY_TO_EARN", "PRECIOUS_METALS", "PROFESSIONAL_SERVICES", "PROP_TRADING_MARKET_MAKING", "PUBLIC_ADMIN", "REAL_ESTATE", "RETAIL_ELECTRONICS", "RETAIL_FNB", "RETAIL_JEWELRY", "RETAIL_OTHER", "PHARMACEUTICALS", "SCIENTIFIC_TECHNICAL", "SOFTWARE_DEVELOPMENT", "SOVEREIGN_WEALTH", "STABLECOIN_ISSUER", "TECHNOLOGY_ECOMMERCE", "TOBACCO", "TRANSPORTATION", "TRAVEL_AGENCIES_AND_TOURISM", "UNLICENSED_GAMBLING", "UTILITIES", "VENTURE_CAPITAL_PE", "WEB3_CRYPTO_NATIVE"]); export const isoCountryAlpha2 = z.enum(["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AR", "AS", "AT", "AU", "AW", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "XK", "YE", "YT", "ZA", "ZM", "ZW"]); export const address = z.object({street_line_1: z.string(), street_line_2: z.string().nullable().optional(), city: z.string(), state: z.string(), country: isoCountryAlpha2, postal_code: z.string()}); export const businessRegistrationRequest = z.object({incorporated_at: z.string(), address: address, tax_id: z.string()}); export const operatingAddress = z.object({street_line_1: z.string(), street_line_2: z.string().nullable().optional(), city: z.string(), state: z.string(), country: isoCountryAlpha2, postal_code: z.string(), is_remote_company: z.boolean().optional()}); export const accountPurpose = z.enum(["CHARITABLE_DONATIONS", "ECOMMERCE_RETAIL_PAYMENTS", "INVESTMENT_PURPOSES", "OTHER", "PAYMENTS_TO_FRIENDS_OR_FAMILY_ABROAD", "PAYROLL", "PERSONAL_OR_LIVING_EXPENSES", "PROTECT_WEALTH", "PURCHASE_GOODS_AND_SERVICES", "RECEIVE_PAYMENTS_FOR_GOODS_AND_SERVICES", "TAX_OPTIMIZATION", "THIRD_PARTY_MONEY_TRANSMISSION", "TREASURY_MANAGEMENT"]); export const sourceOfFunds = z.enum(["BUSINESS_LOANS", "GRANTS", "INTER_COMPANY_FUNDS", "INVESTMENT_PROCEEDS", "LEGAL_SETTLEMENT", "OWNERS_CAPITAL", "PENSION_RETIREMENT", "SALE_OF_ASSETS", "SALES_OF_GOODS_AND_SERVICES", "TAX_REFUND", "THIRD_PARTY_FUNDS", "TREASURY_RESERVES"]); export const sourceOfWealth = z.enum(["BUSINESS_DIVIDENDS_OR_PROFITS", "INVESTMENTS", "ASSET_SALES", "CLIENT_INVESTOR_CONTRIBUTIONS", "GAMBLING", "CHARITABLE_CONTRIBUTIONS", "INHERITANCE", "AFFILIATE_OR_ROYALTY_INCOME"]); export const usdRange = z.enum(["0_99999", "100000_999999", "1000000_9999999", "10000000_49999999", "50000000_249999999", "2500000000_plus"]); export const ownershipStructure = z.enum(["PUBLICLY_LISTED_COMPANY", "WHOLLY_OWNED_SUBSIDIARY_OF_PUBLICLY_LISTED_COMPANY", "MAJORITY_OWNED_SUBSIDIARY_OF_PUBLICLY_LISTED_COMPANY", "WHOLLY_OWNED_SUBSIDIARY_OF_FI_OR_NBFI", "MAJORITY_OWNED_SUBSIDIARY_OF_FI_OR_NBFI", "PRIVATELY_OWNED", "FUND", "OWNED_BY_TRUST", "BEARER_SHARES_OR_UNDISCLOSED_NOMINEE_ARRANGEMENT"]); export const businessProfileRequest = z.object({account_purpose: accountPurpose, account_purpose_other: z.string().nullable().optional(), source_of_funds: z.array(sourceOfFunds), source_of_funds_details: z.string().nullable().optional(), source_of_wealth: z.array(sourceOfWealth), source_of_wealth_details: z.string().nullable().optional(), estimated_annual_revenue_usd: usdRange, anticipated_monthly_fiat_activity: usdRange, ownership_structure: ownershipStructure.nullable().optional(), is_regulated_vasp: z.boolean().nullable().optional()}); export const taxInfoRequest = z.object({country: isoCountryAlpha2, number: z.string()}); export const idType = z.enum(["DRIVERS_LICENSE", "NATIONAL_ID", "PASSPORT", "RESIDENCE_PERMIT"]); export const identificationRequest = z.object({type: idType, issuing_country: isoCountryAlpha2, id_number: z.string()}); export const controllerProfileRequest = z.object({has_ownership: z.boolean(), ownership_percentage: z.number().nullable().optional(), has_control: z.boolean(), is_signer: z.boolean(), is_director: z.boolean()}); export const documentStatus = z.enum(["PENDING", "UPLOADED", "REJECTED", "REMOVED"]); export const onboardingDocumentResponse = z.object({document_id: z.string().nullable().optional(), type: z.string(), status: documentStatus, required: z.boolean(), filename: z.string().nullable().optional(), uploaded_at: z.string().nullable().optional()}); export const controllerResponse = z.object({id: z.string(), first_name: z.string(), last_name: z.string(), email: z.string(), dob: z.string().nullable().optional(), primary_nationality: isoCountryAlpha2.nullable().optional(), dual_nationality: isoCountryAlpha2.nullable().optional(), residential_address: address.nullable().optional(), tax_info: taxInfoRequest.nullable().optional(), identification: identificationRequest.nullable().optional(), profile: controllerProfileRequest.nullable().optional(), documents: z.array(onboardingDocumentResponse).optional()}); export const intermediaryResponse = z.object({id: z.string().nullable().optional(), entity_name: z.string(), country: isoCountryAlpha2, ownership: z.number()}); export const agreementType = z.enum(["BUSINESS_ONBOARDING", "INDIVIDUAL_ONBOARDING", "PRIVACY_POLICY", "COOKIE_POLICY", "E_SIGN_CONSENT", "COMMERCIAL_ACCOUNT_TERMS_AND_CONDITIONS", "INTERNATIONAL_CUSTOMER_ONBOARDING_DISCLOSURE"]); export const termStatus = z.enum(["pending", "signed"]); export const termResponse = z.object({url: z.string(), type: agreementType, name: z.string(), status: termStatus}); export const openApiAccountStatus = z.enum(["DRAFT", "PROCESSING", "ACTION_REQUIRED", "UNDER_REVIEW", "APPROVED", "REJECTED"]); export const issueTargetDataV2 = z.object({account_id: accountId.nullable().optional(), controller_id: z.string().nullable().optional(), intermediary_id: z.string().nullable().optional(), property: z.string().nullable().optional(), document_type: z.string().nullable().optional()}); export const issueTargetV2 = z.object({scope: z.string(), data: issueTargetDataV2}); export const openApiIssueV2 = z.object({type: z.string().nullable().optional(), description: z.string(), target: issueTargetV2.nullable().optional()}); export const businessAccountResponse = z.object({account_id: accountId, parent_account_id: accountId, external_id: z.string().nullable().optional(), legal_name: z.string(), trading_name: z.string().nullable().optional(), description: z.string().nullable().optional(), type: organizationType.nullable().optional(), industry: industry.nullable().optional(), business_email: z.string(), website: z.string().nullable().optional(), registration: businessRegistrationRequest.nullable().optional(), operating_address: operatingAddress.nullable().optional(), profile: businessProfileRequest.nullable().optional(), controllers: z.array(controllerResponse), intermediaries: z.array(intermediaryResponse), terms: z.array(termResponse).optional(), documents: z.array(onboardingDocumentResponse).optional(), status: openApiAccountStatus, errors: z.array(openApiIssueV2).optional(), submitted_at: z.string().nullable().optional(), created_at: z.string(), updated_at: z.string(), deleted_at: z.string().nullable().optional()}); export const businessAccountListResponse = z.object({accounts: z.array(businessAccountResponse), total: z.number().int().gte(0)}); 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 /v2/accounts/{main_account_id}/businesses */ export const getApiV2AccountsMainAccountIdBusinesses = async (args: GetApiV2AccountsMainAccountIdBusinessesArgs, options?: GetApiV2AccountsMainAccountIdBusinessesOptions) => { const {baseUrl = "https://api.1money.com", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (args.external_id != null) query.append("external_id", String(args.external_id)) if (args.parent_account_id != null) query.append("parent_account_id", String(args.parent_account_id)) if (args.main_only != null) query.append("main_only", String(args.main_only)) if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/accounts/${encodeURIComponent(String(args.main_account_id))}/businesses${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(businessAccountListResponse, await res.json()) };