import {z} from 'zod' export type CreateApiOnboardingArgs = {productId?: string | undefined, body: {accountType: 'business' | 'personal', affiliateId?: string | undefined, companyId?: string | undefined, contact: {firstName: string, lastName: string, nationality?: ('AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' | 'AO' | 'AQ' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BV' | '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' | 'HM' | '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' | 'TF' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' | 'UM' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' | 'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'XK' | 'YE' | 'YT' | 'ZA' | 'ZM' | 'ZW' | null) | undefined, annualIncome?: ({currencyCode: 'AED' | 'AFN' | 'ALL' | 'AMD' | 'ANG' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' | 'BAM' | 'BBD' | 'BDT' | 'BGN' | 'BHD' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BOV' | 'BRL' | 'BSD' | 'BTN' | 'BWP' | 'BYN' | 'BZD' | 'CAD' | 'CDF' | 'CHF' | 'CLP' | 'CNY' | 'COP' | 'CRC' | 'CUC' | 'CUP' | 'CVE' | 'CZK' | 'DJF' | 'DKK' | 'DOP' | 'DZD' | 'EGP' | 'ERN' | 'ETB' | 'EUR' | 'FJD' | 'FKP' | 'GBP' | 'GEL' | 'GGP' | 'GHS' | 'GIP' | 'GMD' | 'GNF' | 'GTQ' | 'GYD' | 'HKD' | 'HNL' | 'HRK' | 'HTG' | 'HUF' | 'IDR' | 'ILS' | 'INR' | 'IQD' | 'IRR' | 'ISK' | 'JMD' | 'JOD' | 'JPY' | 'KES' | 'KGS' | 'KHR' | 'KMF' | 'KPW' | 'KRW' | 'KWD' | 'KYD' | 'KZT' | 'LAK' | 'LBP' | 'LKR' | 'LRD' | 'LSL' | 'LTL' | 'LVL' | 'LYD' | 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | 'MYR' | 'MZN' | 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' | 'NZD' | 'OMR' | 'PAB' | 'PEN' | 'PGK' | 'PHP' | 'PKR' | 'PLN' | 'PYG' | 'QAR' | 'RON' | 'RSD' | 'RUB' | 'RWF' | 'SAR' | 'SBD' | 'SCR' | 'SEK' | 'SGD' | 'SHN' | 'SLL' | 'SOS' | 'SRD' | 'SSP' | 'STN' | 'SYP' | 'SZL' | 'THB' | 'TJS' | 'TMT' | 'TND' | 'TOP' | 'TRY' | 'TTD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' | 'USD' | 'UYU' | 'UZS' | 'VND' | 'VUV' | 'WST' | 'XAF' | 'XAG' | 'XAU' | 'XCD' | 'XOF' | 'XPD' | 'XPF' | 'XPT' | 'YER' | 'ZAR' | 'ZMK' | 'ZMW' | 'ZWD', value: number} | null) | undefined, email: string, phone: string, dob?: (string | null) | undefined, address: {addressLine1: string, addressLine2?: (string | null) | undefined, townCity: string, postCode: string, countryCode: string}}, account?: ({companyName?: (string | null) | undefined, companyNumber?: (string | null) | undefined, incorporationDate?: (string | null) | undefined, type?: ('ltd' | 'private-limited-guarant-nsc-limited-exemption' | 'private-limited-guarant-nsc' | 'llp' | 'plc' | 'sole_trader' | 'charity' | 'charitable-incorporated-organisation' | 'partnership' | 'assurance-company' | 'converted-or-closed' | 'limited_by_guarantee' | 'limited-partnership' | 'oversea-company' | 'private-unlimited' | 'royal-charter' | 'registered-society-non-jurisdictional' | 'trust' | 'uk-establishment' | 'other' | null) | undefined, website?: (string | null) | undefined, onboardingDetail?: (string | null) | undefined, address: {addressLine1: string, addressLine2?: (string | null) | undefined, townCity: string, postCode: string, countryCode: string}} | {companyName: string, companyNumber: string, incorporationDate?: (string | null) | undefined, type: 'ltd' | 'private-limited-guarant-nsc-limited-exemption' | 'private-limited-guarant-nsc' | 'llp' | 'plc' | 'sole_trader' | 'charity' | 'charitable-incorporated-organisation' | 'partnership' | 'assurance-company' | 'converted-or-closed' | 'limited_by_guarantee' | 'limited-partnership' | 'oversea-company' | 'private-unlimited' | 'royal-charter' | 'registered-society-non-jurisdictional' | 'trust' | 'uk-establishment' | 'other', website?: (string | null) | undefined, onboardingDetail?: (string | null) | undefined, address: {addressLine1: string, addressLine2?: (string | null) | undefined, townCity: string, postCode: string, countryCode: string}}) | undefined, kyc: {mainPurpose: Array<'Business acquisition' | 'Business costs/revenue' | 'Charity' | 'Currency purchase/sale' | 'Dividend payments' | 'Inheritance' | 'Intercompany Transfers' | 'Investment' | 'Legal fees' | 'Loan' | 'Mortgage payments' | 'On-going payments to family' | 'One off payment' | 'Payment of services' | 'Payment to suppliers' | 'Property maintenance' | 'Property purchase' | 'Property sale' | 'Purchase of goods' | 'Relocating abroad' | 'Repatriation' | 'Royalties' | 'Sale of shares' | 'Study fees/tuition' | 'Vehicle purchase' | 'Incentives/Grants' | 'Tax payments' | 'Director's fees'>, sourceOfFunds: Array<'salary' | 'savings' | 'property' | 'cryptocurrency' | 'inheritance' | 'other'>, destinationOfFunds: Array, currenciesRequired: Array, annualVolume: string, numberOfPayments: string, expectedCardUse: Array<'advertising_and_marketing' | 'bills_and_utilities' | 'client_entertainment' | 'customer_incentives' | 'employee_incentives' | 'fuel_and_mileage_domestic' | 'fuel_and_mileage_overseas' | 'location_expenses__film__tv' | 'office_equipment' | 'online_subscriptions' | 'other' | 'payment_terminal_testing' | 'payroll' | 'per_diems' | 'petty_cash' | 'procurement__purchasing' | 'procurement__sourcing_' | 'travel_expenses_domestic' | 'travel_expenses_overseas'>, averageLoad: string, numberOfCards: string, cardFourthLine: string, employeeCards: boolean, atmWithdrawals: boolean, cardProducts?: ({individualVirtual?: string | undefined, individualPhysical?: string | undefined, shared?: string | undefined}) | undefined} | {[key: string]: unknown} | {expectedCardUse: Array<'advertising_and_marketing' | 'bills_and_utilities' | 'client_entertainment' | 'customer_incentives' | 'employee_incentives' | 'fuel_and_mileage_domestic' | 'fuel_and_mileage_overseas' | 'location_expenses__film__tv' | 'office_equipment' | 'online_subscriptions' | 'other' | 'payment_terminal_testing' | 'payroll' | 'per_diems' | 'petty_cash' | 'procurement__purchasing' | 'procurement__sourcing_' | 'travel_expenses_domestic' | 'travel_expenses_overseas'>, sourceOfFunds: Array<'salary' | 'savings' | 'property' | 'cryptocurrency' | 'inheritance' | 'other'>, currenciesRequired: Array, averageLoad: string, numberOfCards: string, cardFourthLine: string, employeeCards: boolean, atmWithdrawals: boolean, cardProducts?: ({individualVirtual?: string | undefined, individualPhysical?: string | undefined, shared?: string | undefined}) | undefined} | {[key: string]: unknown} | {mainPurpose: Array<'Business acquisition' | 'Business costs/revenue' | 'Charity' | 'Currency purchase/sale' | 'Dividend payments' | 'Inheritance' | 'Intercompany Transfers' | 'Investment' | 'Legal fees' | 'Loan' | 'Mortgage payments' | 'On-going payments to family' | 'One off payment' | 'Payment of services' | 'Payment to suppliers' | 'Property maintenance' | 'Property purchase' | 'Property sale' | 'Purchase of goods' | 'Relocating abroad' | 'Repatriation' | 'Royalties' | 'Sale of shares' | 'Study fees/tuition' | 'Vehicle purchase' | 'Incentives/Grants' | 'Tax payments' | 'Director's fees'>, sourceOfFunds: Array<'salary' | 'savings' | 'property' | 'cryptocurrency' | 'inheritance' | 'other'>, destinationOfFunds: Array, currenciesRequired: Array, annualVolume: string, numberOfPayments: string} | {[key: string]: unknown}, market?: ('UK' | 'EU' | 'US' | 'UP') | undefined, features?: (Array<'payments' | 'cards'>) | undefined, preferredLanguage?: ('EN' | 'FR' | 'DE' | 'ES' | 'IT' | 'NL' | 'PT') | undefined}}; export type CreateApiOnboardingOptions = {baseUrl?: string | undefined, CommonAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiOnboardingResponse = z.object({ok: z.boolean(), correlationId: z.string(), account: z.object({product: z.string(), market: z.enum(["UK", "EU", "US", "UP"]), features: z.array(z.string()), accountType: z.string(), affiliateId: z.string().optional(), companyId: z.string().optional(), preferredLanguage: z.enum(["EN", "FR", "DE", "ES", "IT", "NL", "PT"]).nullable(), contact: z.object({firstName: z.string(), lastName: z.string(), nationality: z.enum(["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "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", "HM", "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", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "XK", "YE", "YT", "ZA", "ZM", "ZW"]).nullable().optional(), annualIncome: z.object({currencyCode: z.enum(["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SEK", "SGD", "SHN", "SLL", "SOS", "SRD", "SSP", "STN", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XCD", "XOF", "XPD", "XPF", "XPT", "YER", "ZAR", "ZMK", "ZMW", "ZWD"]), value: z.number()}).nullable().optional(), email: z.string(), phone: z.string(), dob: z.string().nullable().optional(), address: z.object({addressLine1: z.string(), addressLine2: z.string().nullable().optional(), townCity: z.string(), postCode: z.string(), countryCode: z.string()})}), account: z.object({companyName: z.string(), companyNumber: z.string(), incorporationDate: z.string(), type: z.enum(["ltd", "private-limited-guarant-nsc-limited-exemption", "private-limited-guarant-nsc", "llp", "plc", "sole_trader", "charity", "charitable-incorporated-organisation", "partnership", "assurance-company", "converted-or-closed", "limited_by_guarantee", "limited-partnership", "oversea-company", "private-unlimited", "royal-charter", "registered-society-non-jurisdictional", "trust", "uk-establishment", "other"]), website: z.string().optional(), onboardingDetail: z.string(), address: z.object({addressLine1: z.string(), addressLine2: z.string().nullable().optional(), townCity: z.string(), postCode: z.string(), countryCode: z.string()})}), kyc: z.object({expectedCardUse: z.array(z.enum(["advertising_and_marketing", "bills_and_utilities", "client_entertainment", "customer_incentives", "employee_incentives", "fuel_and_mileage_domestic", "fuel_and_mileage_overseas", "location_expenses__film__tv", "office_equipment", "online_subscriptions", "other", "payment_terminal_testing", "payroll", "per_diems", "petty_cash", "procurement__purchasing", "procurement__sourcing_", "travel_expenses_domestic", "travel_expenses_overseas"])), onboardingDetail: z.string().optional(), sourceOfFunds: z.array(z.enum(["salary", "savings", "property", "cryptocurrency", "inheritance", "other"])), currenciesRequired: z.array(z.string()), averageLoad: z.string(), numberOfCards: z.string(), numberOfPayments: z.string().optional(), destinationOfFunds: z.array(z.string()).optional(), mainPurpose: z.array(z.enum(["Business acquisition", "Business costs/revenue", "Charity", "Currency purchase/sale", "Dividend payments", "Inheritance", "Intercompany Transfers", "Investment", "Legal fees", "Loan", "Mortgage payments", "On-going payments to family", "One off payment", "Payment of services", "Payment to suppliers", "Property maintenance", "Property purchase", "Property sale", "Purchase of goods", "Relocating abroad", "Repatriation", "Royalties", "Sale of shares", "Study fees/tuition", "Vehicle purchase", "Incentives/Grants", "Tax payments", "Director's fees"])).optional(), cardFourthLine: z.string(), employeeCards: z.boolean(), atmWithdrawals: z.boolean(), annualVolume: z.string().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 an account * * POST /onboarding */ export const createApiOnboarding = async (args: CreateApiOnboardingArgs, options?: CreateApiOnboardingOptions) => { const {baseUrl = "https://api.equalsmoney.com/v2", fetch: fetchFn = fetch, CommonAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.productId != null) query.append("productId", String(args.productId)) if (CommonAuth !== undefined) headers.set("Authorization", CommonAuth) const url = `${baseUrl.replace(/\/+$/, '')}/onboarding${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(createApiOnboardingResponse, await res.json()) };