import {z} from 'zod' export type Phone = {calling_code?: string | undefined, number?: string | undefined}; export type UpdateApiV3EntityIdArgs = {id: string, body: {name?: string | undefined, email?: string | undefined, type?: ('sole_proprietorship' | 'company' | 'non_profit' | 'government_entity' | 'individual' | 'limited_liability_partnership' | 'partnership' | 'trust' | 'other') | undefined, description?: string | undefined, metadata?: unknown | undefined, registration_address?: ({line1?: string | undefined, line2?: string | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, postal_code?: string | undefined}) | undefined, operating_address?: ({line1?: string | undefined, line2?: string | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, postal_code?: string | undefined}) | undefined, phone?: Phone | undefined, tax_id?: string | undefined, vertical?: string | undefined, website?: string | undefined, registration_number?: string | undefined, registration_date?: string | undefined, is_operating_address_same_as_registration_address?: boolean | undefined, is_shareholding_doc_same_as_registration_doc?: boolean | undefined, remarks?: string | undefined, representatives?: (Array<{person_id?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, date_of_birth?: string | undefined, address?: ({line1?: string | undefined, line2?: string | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, postal_code?: string | undefined}) | undefined, nationality?: string | undefined, phone?: ({calling_code?: string | undefined, number?: string | undefined}) | undefined, ownership_percentage?: number | undefined, roles?: Array | undefined, documents?: (Array<{type?: ('proof_of_identity' | 'proof_of_address' | 'registration_documents' | 'article_of_incorporation' | 'shareholder_registry' | 'identity' | 'address' | 'other') | undefined, sub_type?: ('drivers_license' | 'national_id' | 'passport' | 'other' | 'driving_license') | undefined, tag?: ('AddressProofDoc' | 'identityProofTypeFrontDoc' | 'identityProofTypeBackDoc' | 'additionalDocs') | undefined, description?: string | undefined, file_name?: string | undefined, url?: string | undefined}>) | undefined}>) | undefined, individual?: ({national_identification_number?: ({type?: ('passport' | 'driving_license' | 'national_id' | 'tax_id' | 'residence_permit' | 'other' | 'asylum_registration_card' | 'consular_id' | 'immigration_status_document' | 'indigenous_card' | 'insurance_card' | 'international_driving_license' | 'municipal_identity_card' | 'national_health_id' | 'postal_identity_card' | 'private_operators_card' | 'professional_qualification_card' | 'proof_of_citizenship' | 'residence_status_document' | 'service_id_card' | 'social_security_card' | 'visa' | 'voter_id' | 'work_permit') | undefined, number?: string | undefined, issuer?: ({country?: string | undefined, state?: string | undefined}) | undefined, expiration?: string | undefined, country_of_citizenship?: string | undefined}) | undefined, date_of_birth?: string | undefined, nationality?: string | undefined, profession?: ({occupation?: string | undefined, isco_code?: string | undefined, industry?: string | undefined, employment_status?: ('employed' | 'self_employed' | 'unemployed' | 'student' | 'retired' | 'homemaker' | 'other') | undefined}) | undefined, source_of_funds?: ({primary_source?: ('salary' | 'business_income' | 'investment_income' | 'inheritance' | 'savings' | 'gift' | 'pension' | 'rental_income' | 'sale_of_assets' | 'loan' | 'scholarship' | 'commission' | 'royalty' | 'other') | undefined, description?: string | undefined}) | undefined, employment_details?: {employer_name: string, designation: string} | undefined}) | undefined, transaction_profile?: ({monthly_expected_transactions_value?: number | undefined, monthly_expected_transaction_volume?: number | undefined, expected_transaction_countries?: Array | undefined, expected_transaction_currencies?: Array | undefined, customer_risk?: ('low' | 'medium' | 'high') | undefined}) | undefined, documents?: (Array<{type?: ('proof_of_identity' | 'proof_of_address' | 'registration_documents' | 'article_of_incorporation' | 'shareholder_registry' | 'identity' | 'business' | 'person' | 'other' | 'address' | 'source_of_wealth') | undefined, sub_type?: ('drivers_license' | 'national_id' | 'passport' | 'other' | 'driving_license') | undefined, tag?: ('registrationProofDoc' | 'AddressProofDoc' | 'beneficialOwnershipDoc' | 'bankStatementProofDoc' | 'previousCardStatementProofDoc' | 'sampleInvoicesDoc' | 'additionalDocs') | undefined, file_name?: string | undefined, description?: string | undefined, url?: string | undefined}>) | undefined, reference_id?: string | undefined, relationship?: ('customer' | 'vendor' | 'fourth_party' | 'other') | undefined, purpose_of_use?: Array | undefined, onboarding_package_url?: string | undefined, on_behalf_of?: string | undefined, source_of_wealth?: ({type?: ('document' | 'url') | undefined, url?: string | undefined}) | undefined}}; export type UpdateApiV3EntityIdOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const metadata = z.record(z.string(), z.string()).nullable(); export const phone = z.object({calling_code: z.string().optional(), number: z.string().optional()}); export const address = z.object({line1: z.string().optional(), line2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), country: z.string().optional(), postal_code: z.string().optional()}); export const updateApiV3EntityIdResponse = z.object({status: z.string().optional(), message: z.string().optional(), data: z.object({approval_status: z.string().optional(), approval_status_description: z.string().optional(), approved_at: z.string().optional(), created_at: z.string().optional(), description: z.string().optional(), documents: z.array(z.object({description: z.string().optional(), document_id: z.string().optional(), file_name: z.string().optional(), sub_type: z.string().optional(), tag: z.string().optional(), type: z.string().optional(), updated_at: z.string().optional(), url: z.string().optional()})).optional(), email: z.string().optional(), id: z.string().optional(), metadata: metadata.optional(), name: z.string().optional(), object: z.string().optional(), on_behalf_of: z.string().optional(), onboarding_package_url: z.string().optional(), operating_address: z.string().optional(), pending_documents: z.array(z.object({})).optional(), phone: phone.optional(), purpose_of_use: z.array(z.string()).optional(), reference_id: z.string().optional(), registration_address: address.optional(), registration_date: z.string().optional(), registration_number: z.string().optional(), rejected_at: z.string().optional(), relationship: z.string().optional(), representatives: z.array(z.object({person_id: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), date_of_birth: z.string().optional(), address: address.optional(), nationality: z.string().optional(), phone: phone.optional(), ownership_percentage: z.number().optional(), roles: z.array(z.string()).optional(), documents: z.array(z.object({description: z.string().optional(), document_id: z.string().optional(), file_name: z.string().optional(), sub_type: z.string().optional(), tag: z.string().optional(), type: z.string().optional(), updated_at: z.string().optional(), url: z.string().optional()})).optional()})).optional(), source_of_wealth: z.string().optional(), statement_descriptor: z.string().optional(), submit: z.boolean().optional(), submitted_at: z.string().optional(), tax_id: z.string().optional(), type: z.string().optional(), vertical: z.string().optional(), website: 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 }; /** * Update Entity * * PUT /v3/entity/{id} */ export const updateApiV3EntityId = async (args: UpdateApiV3EntityIdArgs, options?: UpdateApiV3EntityIdOptions) => { const {baseUrl = "https://service-sandbox.tazapay.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', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/entity/${encodeURIComponent(String(args.id))}${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(updateApiV3EntityIdResponse, await res.json()) };