import {z} from 'zod' export type NormalisedRole = 'ULTIMATE_BENEFICIAL_OWNER' | 'CONTROLLING_PERSON' | 'DIRECTOR' | 'LEGAL_REPRESENTATIVE' | 'SHAREHOLDER' | 'EMPLOYEE' | 'UNKNOWN' | null; export type PersonRoleDetails = {name?: (string | null) | undefined, start_date?: (string | null) | undefined, end_date?: (string | null) | undefined, is_active?: (boolean | null) | undefined, normalised_name?: NormalisedRole | undefined}; export type Address = {address_street_1?: string | undefined, address_street_2?: string | undefined, address_city?: string | undefined, address_state?: string | undefined, address_zip_code?: string | undefined, address_country?: string | undefined}; export type IdentityNumberType = 'SSN9' | 'SSN4' | 'DRIVER_LICENSE' | 'PASSPORT' | 'NATIONAL_ID' | 'VOTER_ID' | 'BVN' | 'NIN' | 'NIN_SLIP' | 'SSNIT' | 'TAX_ID' | 'KENYA_KRA_PIN' | 'ALIEN_CARD' | 'RESIDENT_ID' | 'COLOMBIA_PPT_NUMBER' | 'GHANA_CARD_NUMBER' | null; export type IdentityDocumentType = 'PASSPORT' | 'DRIVER_LICENSE' | 'NATIONAL_ID' | 'PAN_CARD' | 'ID_CARD' | 'VOTER_ID_CARD' | 'RESIDENT_CARD' | 'GHANA_CARD' | 'GHANA_SSNIT_CARD' | 'KENYA_ALIEN_CARD' | 'COLOMBIA_PPT' | null; export type Identity = {identity_country_code?: string | undefined, identity_number_type?: IdentityNumberType | undefined, identity_number?: string | undefined, identity_document_type?: IdentityDocumentType | undefined, identity_document_front?: string | undefined, identity_document_back?: string | undefined}; export type UpdateBusinessOfficerRequestSchema = {business_profile_id: string, person_reference_id: string, first_name?: string | undefined, middle_name?: (string | null) | undefined, last_name?: string | undefined, full_name?: (string | null) | undefined, birth_date?: (string | null) | undefined, ownership_percent?: (number | null) | undefined, shares_allocated?: (number | null) | undefined, roles?: Array | undefined, email?: (string | null) | undefined, phone_number?: (string | null) | undefined, phone_number_parts?: ({countryCode?: (string | null) | undefined, phoneCode?: (string | null) | undefined, number?: (string | null) | undefined} | null) | undefined, address?: Address | undefined, identity?: Identity | undefined, additional_fields?: Record | undefined}; export type CreateApiVerifyUpdateBusinessOfficerArgs = {body: UpdateBusinessOfficerRequestSchema}; export type CreateApiVerifyUpdateBusinessOfficerOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiVerifyUpdateBusinessOfficerResponse = z.object({business_profile_id: z.string().optional(), person_reference_id: 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 }; /** * Update Business Officer * * POST /verify/update_business_officer */ export const createApiVerifyUpdateBusinessOfficer = async (args: CreateApiVerifyUpdateBusinessOfficerArgs, options?: CreateApiVerifyUpdateBusinessOfficerOptions) => { const {baseUrl = "https://api-sandbox.aiprise.com/api/v1", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("X-API-KEY", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/verify/update_business_officer${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(createApiVerifyUpdateBusinessOfficerResponse, await res.json()) };