import {z} from 'zod' export type CreateApiBusinessArgs = {body: {owner_id?: string | undefined, name: string, business_type?: ('soleProprietor' | 'singleMemberLLC' | 'limitedLiabilityCompany' | 'generalPartnership' | 'unlistedCorporation' | 'publiclyTradedCorporation' | 'association' | 'nonProfit' | 'governmentOrganization' | 'revocableTrust' | 'irrevocableTrust' | 'estate' | 'limitedPartnership' | 'limitedLiabilityPartnership') | undefined, industry: 'hotelMotel' | 'otherFoodServices' | 'restaurants' | 'artPhotography' | 'artsEntertainment' | 'fitnessSportsCenters' | 'sportsTeamsClubs' | 'construction' | 'buildingMaterialsHardware' | 'otherTradeContractor' | 'plumbingHVAC' | 'healthServices' | 'otherEducationServices' | 'otherHealthFitness' | 'accountingTaxPrep' | 'realEstate' | 'homeFurnishing' | 'beautyOrBarberShops' | 'carWash' | 'computerServiceRepair' | 'freelanceProfessional' | 'landscapeServices' | 'legalServices' | 'massageTanningServices' | 'otherProfessionalServices' | 'autoDealers' | 'onlineRetailer' | 'retail' | 'gasolineServiceStation' | 'otherTransportServices' | 'otherTravelServices' | 'parkingGarages' | 'taxi' | 'travelAgency' | 'truckingShipping' | 'wholesale' | 'warehouseDistribution' | 'otherAccomodations' | 'animalFarmingProduction' | 'cropFarming' | 'forestryActivities' | 'fishingHuntingTrapping' | 'otherAgricultureForestryFishing' | 'museumsHistoricalSites' | 'hospitals' | 'collegesUniversitiesSchools' | 'bankFinancialInstitution' | 'financialInvestments' | 'fundsTrustsOther' | 'insurance' | 'moneyTransferRemittance' | 'privateInvestmentCompanies' | 'otherManufacturing' | 'industrialCommercialMachinery' | 'employmentServices' | 'governmentAgency' | 'nonGovernmentOrganization' | 'religiousOrganization' | 'unions' | 'retailJewelerDiamondsGemsGold' | 'retailCash' | 'usedClothesDealers' | 'tourOperator' | 'wholesaleJeweler ‍', id_type: 'ein' | 'cac', id_number: string, id_country?: ('AD' | 'AE' | 'AG' | 'AI' | 'AM' | 'AO' | 'AQ' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BV' | 'BW' | 'BZ' | 'CA' | 'CC' | 'CG' | 'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CO' | 'CR' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'EC' | 'EE' | 'EG' | 'EH' | 'ES' | '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' | 'IS' | 'IT' | 'JE' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KN' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'MC' | 'MD' | 'ME' | 'MF' | 'MG' | 'MH' | 'MN' | 'MO' | 'MP' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' | 'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' | 'NF' | 'NG' | 'NL' | 'NO' | 'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' | 'PG' | 'PH' | 'PL' | 'PM' | 'PN' | 'PR' | 'PT' | 'PW' | 'PY' | 'RE' | 'RO' | 'RS' | 'RW' | 'SA' | 'SB' | 'SC' | 'SE' | 'SG' | 'SH' | 'SJ' | 'SK' | 'SL' | 'SM' | 'SN' | 'SR' | 'ST' | 'SV' | 'SX' | 'SZ' | 'TC' | 'TD' | 'TF' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UG' | 'UM' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'YT' | 'ZA' | 'ZM') | undefined, dof: string, contact_phone?: string | undefined, contact_email?: string | undefined, address: {line1: string, line2?: string | undefined, city: string, state: string, country: string, postal_code: string}, service_information?: {estimated_annual_revenue: number, expected_monthly_inflow: number, financial_services_usage: boolean, third_party_usage: boolean} | undefined, documents?: (Array<{type: 'passport' | 'national_id' | 'drivers_licence' | 'residence_permit' | 'voters_card' | 'bank_statement' | 'utility_bill' | 'incorporation_certificate' | 'registration_certificate' | 'memorandum_articles' | 'business_licence' | 'cac', url: string, issue_date?: string | undefined, expiry_date?: string | undefined}>) | undefined, beneficial_owners?: Array<{person_id: string, share: number}> | undefined}}; export type CreateApiBusinessOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiBusinessResponse = z.object({data: z.object({id: z.string().optional(), owner_id: z.string().optional(), name: z.string().optional(), business_type: z.string().optional(), industry: z.string().optional(), dof: z.string().optional(), is_master: z.boolean().optional(), id_type: z.string().optional(), id_number: z.string().optional(), address_line1: z.string().optional(), address_city: z.string().optional(), address_state: z.string().optional(), address_country: z.string().optional(), address_zip: z.string().optional(), status: z.string().optional(), kyb_status: z.string().optional(), is_deleted: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional(), message: z.string().optional(), meta: z.unknown(), status: 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 Business * * POST /business */ export const createApiBusiness = async (args: CreateApiBusinessArgs, options?: CreateApiBusinessOptions) => { const {baseUrl = "https://api.useoval.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/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(createApiBusinessResponse, await res.json()) };