import {z} from 'zod' export type NormalisedRole = 'ULTIMATE_BENEFICIAL_OWNER' | 'CONTROLLING_PERSON' | 'DIRECTOR' | 'LEGAL_REPRESENTATIVE' | 'SHAREHOLDER' | 'EMPLOYEE' | 'UNKNOWN' | null; export type CompanyRoleDetails = {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 ExtractedAddress = {full_address?: string | undefined, parsed_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, address_type?: string | undefined}) | undefined, source?: (Array<{type?: string | undefined, state?: string | undefined, status?: string | undefined, file_number?: string | undefined, labels?: Array | undefined}>) | undefined, additional_info?: {[key: string]: unknown} | undefined}; export type AddRelatedCompanyRequestSchema = {business_profile_id: string, name: string, country_code?: (string | null) | undefined, status?: (string | null) | undefined, description?: (string | null) | undefined, ownership_percent?: (number | null) | undefined, shares_allocated?: (number | null) | undefined, roles?: Array | undefined, addresses?: Array | undefined, alternate_name?: string | undefined, tax_identification_number?: string | undefined, website?: string | undefined, formation_date?: string | undefined, state_code?: string | undefined, business_entity_id?: string | undefined, phone_numbers?: Array | undefined, email_addresses?: Array | undefined, additional_fields?: Record | undefined}; export type CreateApiVerifyAddRelatedCompanyArgs = {body: AddRelatedCompanyRequestSchema}; export type CreateApiVerifyAddRelatedCompanyOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiVerifyAddRelatedCompanyResponse = z.object({business_profile_id: z.string().optional(), company_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 }; /** * Add Related Company * * POST /verify/add_related_company */ export const createApiVerifyAddRelatedCompany = async (args: CreateApiVerifyAddRelatedCompanyArgs, options?: CreateApiVerifyAddRelatedCompanyOptions) => { 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/add_related_company${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(createApiVerifyAddRelatedCompanyResponse, await res.json()) };