import {z} from 'zod' export type CountryCode = 'AF' | 'AX' | 'AL' | 'DZ' | 'AS' | 'AD' | 'AO' | 'AI' | 'AQ' | 'AG' | 'AR' | 'AM' | 'AW' | 'AU' | 'AT' | 'AZ' | 'BS' | 'BH' | 'BD' | 'BB' | 'BY' | 'BE' | 'BZ' | 'BJ' | 'BM' | 'BT' | 'BO' | 'BQ' | 'BA' | 'BW' | 'BV' | 'BR' | 'IO' | 'BN' | 'BG' | 'BF' | 'BI' | 'CV' | 'KH' | 'CM' | 'CA' | 'KY' | 'CF' | 'TD' | 'CL' | 'CN' | 'CX' | 'CC' | 'CO' | 'KM' | 'CG' | 'CD' | 'CK' | 'CR' | 'CI' | 'HR' | 'CU' | 'CW' | 'CY' | 'CZ' | 'DK' | 'DJ' | 'DM' | 'DO' | 'EC' | 'EG' | 'SV' | 'GQ' | 'ER' | 'EE' | 'SZ' | 'ET' | 'FK' | 'FO' | 'FJ' | 'FI' | 'FR' | 'GF' | 'PF' | 'TF' | 'GA' | 'GM' | 'GE' | 'DE' | 'GH' | 'GI' | 'GR' | 'GL' | 'GD' | 'GP' | 'GU' | 'GT' | 'GG' | 'GN' | 'GW' | 'GY' | 'HT' | 'HM' | 'VA' | 'HN' | 'HK' | 'HU' | 'IS' | 'IN' | 'ID' | 'IR' | 'IQ' | 'IE' | 'IM' | 'IL' | 'IT' | 'JM' | 'JP' | 'JE' | 'JO' | 'KZ' | 'KE' | 'KI' | 'KP' | 'KR' | 'XK' | 'KW' | 'KG' | 'LA' | 'LV' | 'LB' | 'LS' | 'LR' | 'LY' | 'LI' | 'LT' | 'LU' | 'MO' | 'MG' | 'MW' | 'MY' | 'MV' | 'ML' | 'MT' | 'MH' | 'MQ' | 'MR' | 'MU' | 'YT' | 'MX' | 'FM' | 'MD' | 'MC' | 'MN' | 'ME' | 'MS' | 'MA' | 'MZ' | 'MM' | 'NA' | 'NR' | 'NP' | 'NL' | 'NC' | 'NZ' | 'NI' | 'NE' | 'NG' | 'NU' | 'NF' | 'MK' | 'MP' | 'NO' | 'OM' | 'PK' | 'PW' | 'PS' | 'PA' | 'PG' | 'PY' | 'PE' | 'PH' | 'PN' | 'PL' | 'PT' | 'PR' | 'QA' | 'RE' | 'RO' | 'RU' | 'RW' | 'BL' | 'SH' | 'KN' | 'LC' | 'MF' | 'PM' | 'VC' | 'WS' | 'SM' | 'ST' | 'SA' | 'SN' | 'RS' | 'SC' | 'SL' | 'SG' | 'SX' | 'SK' | 'SI' | 'SB' | 'SO' | 'ZA' | 'GS' | 'SS' | 'ES' | 'LK' | 'SD' | 'SR' | 'SJ' | 'SE' | 'CH' | 'SY' | 'TW' | 'TJ' | 'TZ' | 'TH' | 'TL' | 'TG' | 'TK' | 'TO' | 'TT' | 'TN' | 'TR' | 'TM' | 'TC' | 'TV' | 'UG' | 'UA' | 'AE' | 'GB' | 'US' | 'UM' | 'UY' | 'UZ' | 'VU' | 'VE' | 'VN' | 'VG' | 'VI' | 'WF' | 'EH' | 'YE' | 'ZM' | 'ZW'; export type PlatformKybAddress = {streetAddress?: (string | null) | undefined, addressLine2?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, zip?: (string | null) | undefined, country?: (CountryCode | null) | undefined}; export type FiatEntityType = 'llc' | 'corporation' | 's_corporation' | 'c_corporation' | 'partnership' | 'limited_partnership' | 'sole_proprietorship' | 'nonprofit' | 'trust' | 'cooperative' | 'dao' | 'foundation' | 'other'; export type FiatCryptoIndustrySubtype = 'protocol' | 'exchange' | 'investment' | 'lender' | 'market_maker' | 'saas' | 'miner'; export type FiatPrimaryTargetMarket = 'retail' | 'commercial' | 'government' | 'other'; export type FiatTransactionCount = '<10' | '10-50' | '50-200' | '200-1,000' | '1,000+'; export type RevenueCoverage = 'all_operating_expenses' | 'most' | 'some' | 'minimal'; export type FiatBusinessType = 'technology' | 'finance' | 'healthcare' | 'retail' | 'e_commerce' | 'manufacturing' | 'real_estate' | 'consulting' | 'hospitality' | 'education' | 'transportation' | 'entertainment' | 'agriculture' | 'construction' | 'professional_services' | 'crypto_web3' | 'other'; export type FiatVerifierRole = 'officer' | 'employer' | 'accountant' | 'agent'; export type FiatSourceOfFunds = 'business_revenue' | 'investment' | 'loan' | 'personal_savings' | 'third_party_funds' | 'grant' | 'other'; export type FiatPurposeOfFunds = 'operations' | 'payroll' | 'vendor_payments' | 'investment' | 'treasury_management' | 'international_transfers' | 'other'; export type HighRiskActivity = 'MONEY_SERVICES' | 'LENDING_BANKING' | 'OTC_FX_CRYPTO_BROKERAGE' | 'HOLD_CLIENT_FUNDS' | 'INVESTMENT_SERVICES' | 'SAFE_DEPOSIT_BOX' | 'PRECIOUS_METALS_STONES_JEWELRY' | 'NICOTINE_TOBACCO' | 'MARIJUANA' | 'PHARMACEUTICALS' | 'THIRD_PARTY_PAYMENT_PROCESSING' | 'ADULT_ENTERTAINMENT' | 'WEAPONS_FIREARMS_EXPLOSIVES' | 'GAMBLING'; export type FiatIdentityDocumentType = 'passport' | 'id_card' | 'drivers_license' | 'driver_license' | 'residence_permit' | 'government_id' | 'state_or_provincial_id' | 'visa'; export type PlatformKybIdentityDocument = {type?: (FiatIdentityDocumentType | null) | undefined, issuingCountry?: (CountryCode | null) | undefined, number?: (string | null) | undefined}; export type PlatformKybCompany = {legalName?: (string | null) | undefined, tradeName?: (string | null) | undefined, country?: (CountryCode | null) | undefined, registrationNumber?: (string | null) | undefined, linkedinUrl?: (string | null) | undefined, taxId?: (string | null) | undefined, phone?: (string | null) | undefined, email?: (string | null) | undefined, address?: (PlatformKybAddress | null) | undefined, entityType?: (FiatEntityType | null) | undefined, entityTypeDescription?: (string | null) | undefined, incorporationDate?: (string | null) | undefined, industry?: (string | null) | undefined, websites?: (Array | null) | undefined, operatingCountries?: (Array | null) | undefined, expectedMonthlyVolumeUsd?: (string | null) | undefined, expectedCryptoMonthlyVolumeUsd?: (string | null) | undefined, expectedMonthlyAchUsd?: (string | null) | undefined, expectedMonthlyWireUsd?: (string | null) | undefined, cryptoIndustrySubtype?: (FiatCryptoIndustrySubtype | null) | undefined, hasIntermediateEntityOwnership?: (boolean | null) | undefined, primaryTargetMarket?: (FiatPrimaryTargetMarket | null) | undefined, estimatedAnnualRevenue?: (string | null) | undefined, hasUsBank?: (boolean | null) | undefined, deniedUsBank?: (boolean | null) | undefined, hasPep?: (boolean | null) | undefined, bizAdverse?: (Array | null) | undefined, ownersAdverse?: (Array | null) | undefined, publicListed?: (boolean | null) | undefined, txPerMonth?: (FiatTransactionCount | null) | undefined, usesBlockchain?: (boolean | null) | undefined, revenueCovers?: (RevenueCoverage | null) | undefined, institutionalInvestors?: (boolean | null) | undefined, isRegulated?: (boolean | null) | undefined, regulatorCountry?: (CountryCode | null) | undefined, regulatoryLicenseType?: (string | null) | undefined, verifiesCustomerIdentity?: (boolean | null) | undefined, hasTransactionMonitoring?: (boolean | null) | undefined, productsServices?: (Array | null) | undefined, businessDescription?: (string | null) | undefined, businessType?: (FiatBusinessType | null) | undefined, businessIndustry?: (string | null) | undefined, verifierRole?: (FiatVerifierRole | null) | undefined, sourceOfFunds?: (FiatSourceOfFunds | null) | undefined, sourceOfFundsDetails?: (string | null) | undefined, purposeOfFunds?: (FiatPurposeOfFunds | null) | undefined, purposeOfFundsDetails?: (string | null) | undefined, flowOfFunds?: (string | null) | undefined, complianceScreening?: (string | null) | undefined, moneyServicesDescription?: (string | null) | undefined, handlesCustomerFunds?: (boolean | null) | undefined, actingAsIntermediary?: (boolean | null) | undefined, sanctionedCountryOperations?: (boolean | null) | undefined, highRiskActivities?: (Array | null) | undefined, depositMethods?: (Array | null) | undefined, contactInfo?: (string | null) | undefined, identityDocuments?: (Array | null) | undefined}; export type DocumentType = 'certificate_of_incorporation' | 'certificate_of_registration' | 'formation_document' | 'articles_of_incorporation' | 'power_of_attorney' | 'corporate_structure' | 'org_structure_chart' | 'company_registry_extract' | 'corporate_registry_extract' | 'shareholder_registry' | 'cap_table' | 'director_structure' | 'proof_of_address' | 'utility_bill' | 'aml_policy' | 'annual_financial_statements' | 'articles_of_association' | 'audit_report' | 'independent_aml_audit_report' | 'identity_verification_attestation' | 'institutional_investor_documentation' | 'audited_financial_statement' | 'bank_reference_letter' | 'bank_verification_letter' | 'bank_statement' | 'banking_details' | 'birth_certificate' | 'business_license' | 'operating_license' | 'business_plan' | 'certificate_of_good_standing' | 'corporate_resolution' | 'proof_of_registered_address' | 'proof_of_operating_address' | 'crypto_statement' | 'credit_report' | 'criminal_record_check' | 'cv_resume' | 'driving_license' | 'education_certificate' | 'financial_projections' | 'investment_statement' | 'insurance_policy' | 'lease_agreement' | 'marriage_certificate' | 'national_id' | 'national_id_front' | 'national_id_back' | 'operating_agreement' | 'partnership_agreement' | 'professional_license' | 'regulatory_license' | 'reference_letter' | 'register_of_members' | 'residence_permit' | 'shareholding_structure' | 'shareholders_agreement' | 'social_security_document' | 'source_of_funds_declaration' | 'tax_identification_document' | 'ein_letter' | 'tax_certificate' | 'tax_compliance_form' | 'tax_returns' | 'payslip' | 'pitch_deck' | 'savings_statement' | 'trade_references' | 'vat_registration' | 'vendor_contracts' | 'visa' | 'wealth_statement' | 'contract' | 'invoice' | 'loan_agreement' | 'subscription_agreement' | 'safe_agreement' | 'convertible_note' | 'promissory_note' | 'marketing_material' | 'employment_contract' | 'authorization_to_act' | 'authority_to_bind' | 'ubo_declaration' | 'income_verification_letter' | 'source_of_funds' | 'flow_of_funds' | 'payroll_register' | 'investment_agreement' | 'source_of_wealth' | 'supporting_document' | 'memorandum' | 'passport_front' | 'passport_back' | 'id_card_front' | 'id_card_back' | 'drivers_license_front' | 'drivers_license_back' | 'residence_permit_front' | 'residence_permit_back' | 'other'; export type PlatformKybDocument = {slot: DocumentType, uploadId: string}; export type PlatformKybPerson = {key?: (string | null) | undefined, id?: (string | null) | undefined, firstName?: (string | null) | undefined, middleName?: (string | null) | undefined, lastName?: (string | null) | undefined, dateOfBirth?: (string | null) | undefined, birthCountry?: (CountryCode | null) | undefined, nationalities?: (Array | null) | undefined, title?: (string | null) | undefined, country?: (CountryCode | null) | undefined, linkedinUrl?: (string | null) | undefined, email?: (string | null) | undefined, phone?: (string | null) | undefined, address?: (PlatformKybAddress | null) | undefined, taxIdCountry?: (CountryCode | null) | undefined, taxId?: (string | null) | undefined, identityDocuments?: (Array | null) | undefined, ownershipPercentage?: (number | string | null) | undefined, hasControl?: (boolean | null) | undefined, isDirector?: (boolean | null) | undefined, isSigner?: (boolean | null) | undefined, documents?: (Array | null) | undefined}; export type PlatformKybWriteRequest = {company?: (PlatformKybCompany | null) | undefined, people?: (Array | null) | undefined, documents?: (Array | null) | undefined}; export type UpdateApiClientKybArgs = {'Idempotency-Key'?: (string | null) | undefined, 'X-Hevn-Account': string, body: PlatformKybWriteRequest}; export type UpdateApiClientKybOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const platformKybPersonRef = z.object({key: z.string().nullable().optional(), id: z.string()}); export const platformKybWriteResponse = z.object({ready: z.boolean(), missing: z.array(z.string()).optional(), people: z.array(platformKybPersonRef).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 }; /** * Provide applicant information * * PUT /client/kyb */ export const updateApiClientKyb = async (args: UpdateApiClientKybArgs, options: UpdateApiClientKybOptions) => { 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 (args['X-Hevn-Account'] != null) headers.set("X-Hevn-Account", String(args['X-Hevn-Account'])) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/client/kyb${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(platformKybWriteResponse, await res.json()) };