import {z} from 'zod' export type CountryCode = 'AFG' | 'ALB' | 'DZA' | 'ASM' | 'AND' | 'AGO' | 'AIA' | 'ATA' | 'ATG' | 'ARG' | 'ARM' | 'ABW' | 'AUS' | 'AUT' | 'AZE' | 'BHS' | 'BHR' | 'BGD' | 'BRB' | 'BLR' | 'BEL' | 'BLZ' | 'BEN' | 'BMU' | 'BTN' | 'BOL' | 'BES' | 'BIH' | 'BWA' | 'BVT' | 'BRA' | 'IOT' | 'BRN' | 'BGR' | 'BFA' | 'BDI' | 'CPV' | 'KHM' | 'CMR' | 'CAN' | 'CYM' | 'CAF' | 'TCD' | 'CHL' | 'CHN' | 'CXR' | 'CCK' | 'COL' | 'COM' | 'COD' | 'COG' | 'COK' | 'CRI' | 'HRV' | 'CUB' | 'CUW' | 'CYP' | 'CZE' | 'CIV' | 'DNK' | 'DJI' | 'DMA' | 'DOM' | 'ECU' | 'EGY' | 'SLV' | 'GNQ' | 'ERI' | 'EST' | 'SWZ' | 'ETH' | 'FLK' | 'FRO' | 'FJI' | 'FIN' | 'FRA' | 'GUF' | 'PYF' | 'ATF' | 'GAB' | 'GMB' | 'GEO' | 'DEU' | 'GHA' | 'GIB' | 'GRC' | 'GRL' | 'GRD' | 'GLP' | 'GUM' | 'GTM' | 'GGY' | 'GIN' | 'GNB' | 'GUY' | 'HTI' | 'HMD' | 'VAT' | 'HND' | 'HKG' | 'HUN' | 'ISL' | 'IND' | 'IDN' | 'IRN' | 'IRQ' | 'IRL' | 'IMN' | 'ISR' | 'ITA' | 'JAM' | 'JPN' | 'JEY' | 'JOR' | 'KAZ' | 'KEN' | 'KIR' | 'PRK' | 'KOR' | 'KWT' | 'KGZ' | 'LAO' | 'LVA' | 'LBN' | 'LSO' | 'LBR' | 'LBY' | 'LIE' | 'LTU' | 'LUX' | 'MAC' | 'MDG' | 'MWI' | 'MYS' | 'MDV' | 'MLI' | 'MLT' | 'MHL' | 'MTQ' | 'MRT' | 'MUS' | 'MYT' | 'MEX' | 'FSM' | 'MDA' | 'MCO' | 'MNG' | 'MNE' | 'MSR' | 'MAR' | 'MOZ' | 'MMR' | 'NAM' | 'NRU' | 'NPL' | 'NLD' | 'NCL' | 'NZL' | 'NIC' | 'NER' | 'NGA' | 'NIU' | 'NFK' | 'MNP' | 'NOR' | 'OMN' | 'PAK' | 'PLW' | 'PSE' | 'PAN' | 'PNG' | 'PRY' | 'PER' | 'PHL' | 'PCN' | 'POL' | 'PRT' | 'PRI' | 'QAT' | 'MKD' | 'ROU' | 'RUS' | 'RWA' | 'REU' | 'BLM' | 'SHN' | 'KNA' | 'LCA' | 'MAF' | 'SPM' | 'VCT' | 'WSM' | 'SMR' | 'STP' | 'SAU' | 'SEN' | 'SRB' | 'SYC' | 'SLE' | 'SGP' | 'SXM' | 'SVK' | 'SVN' | 'SLB' | 'SOM' | 'ZAF' | 'SGS' | 'SSD' | 'ESP' | 'LKA' | 'SDN' | 'SUR' | 'SJM' | 'SWE' | 'CHE' | 'SYR' | 'TWN' | 'TJK' | 'TZA' | 'THA' | 'TLS' | 'TGO' | 'TKL' | 'TON' | 'TTO' | 'TUN' | 'TUR' | 'TKM' | 'TCA' | 'TUV' | 'UGA' | 'UKR' | 'ARE' | 'GBR' | 'UMI' | 'USA' | 'URY' | 'UZB' | 'VUT' | 'VEN' | 'VNM' | 'VGB' | 'VIR' | 'WLF' | 'ESH' | 'YEM' | 'ZMB' | 'ZWE' | 'ALA'; export type CreateBusinessCustomerInput = {verification_type?: ('STANDARD' | 'RELIANCE') | undefined, basic_info: {business_name: string, business_trade_name?: string | undefined, description: string, entity_type: 'LIMITED_LIABILITY_COMPANY' | 'PUBLICLY_LISTED_COMPANY' | 'SOLE_PROPRIETOR' | 'PARTNERSHIP' | 'CORPORATION' | 'TRUST' | 'PRIVATE_FOUNDATION' | 'CHARITY' | 'NONPROFIT_ORGANIZATION' | 'PUBLIC_AGENCY_OR_AUTHORITY' | 'PRIVATE_LIMITED', website: string, email: string, incorporation_date: string, phone: string, country_of_incorporation: CountryCode, registration_number: string, tax_id: string}, financial_profile: {purpose_id: number, other_purpose?: string | undefined, business_industry_id: number, monthly_volume: number, source_of_fund_id: number, third_party_fund_usage: boolean}, addresses: {is_incorporated_address_same: boolean, incorporated_address: {street: string, city: string, state: string, postal_code: string, country: CountryCode}, physical_address?: {street: string, city: string, state: string, postal_code: string, country: CountryCode} | undefined}, associated_parties: Array<{basic_info: {first_name: string, last_name: string, dob: string, email: string, phone: string, country_of_residence: CountryCode, nationality: CountryCode, tin: string}, address: {street: string, city: string, state: string, postal_code: string, country: CountryCode}, ownership_info: {designation: string, percentage_of_ownership: number, relationship_establishment_date: string}}>, meta_data?: {[key: string]: unknown} | undefined}; export type CreateApiV1CustomersBusinessArgs = {body: CreateBusinessCustomerInput}; export type CreateApiV1CustomersBusinessOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1CustomersBusinessResponse = z.object({data: z.object({customer_id: z.string().optional(), tos_policies_url: z.string().optional()}).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 Business Customer * * POST /v1/customers/business */ export const createApiV1CustomersBusiness = async (args: CreateApiV1CustomersBusinessArgs, options?: CreateApiV1CustomersBusinessOptions) => { const {baseUrl = "https://sandbox.api.fin.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/business${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(createApiV1CustomersBusinessResponse, await res.json()) };