import {z} from 'zod' 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 ProfileAPIResultStatusV2 = 'APPROVED' | 'DECLINED' | 'REVIEW' | 'UNKNOWN' | 'DEACTIVATED'; export type QuestionType = 'SINGLE_CHOICE' | 'MULTIPLE_CHOICE' | 'BOOLEAN' | 'TEXT' | 'FILE' | 'EMAIL' | 'PHONE_NUMBER' | 'SINGLE_SELECT' | 'MULTIPLE_SELECT' | 'DATE' | 'PARAGRAPH' | 'URL'; export type Question = {question?: (string | null) | undefined, answer?: (string | null) | undefined, answer_file?: (string | null) | undefined, order?: (number | null) | undefined, answer_type?: QuestionType | undefined, answer_language?: (string | null) | undefined}; export type QuestionGroupMetaData = {template_id?: string | undefined, verification_session_id?: string | undefined, updated_at?: number | undefined}; export type QuestionGroup = {[key: string]: Question | string | QuestionGroupMetaData}; 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 AddRelatedPersonV2RequestSchema = {business_profile_id: string, user_profile: {user_profile_id?: string | undefined, first_name?: (string | null) | undefined, middle_name?: (string | null) | undefined, last_name?: (string | null) | undefined, second_last_name?: (string | null) | undefined, full_name?: (string | null) | undefined, address?: Address | undefined, date_of_birth?: string | undefined, email_address?: string | undefined, phone_number?: string | undefined, phone_number_parts?: ({countryCode?: (string | null) | undefined, phoneCode?: (string | null) | undefined, number?: (string | null) | undefined} | null) | undefined, client_reference_id?: string | undefined, client_reference_data?: Record | undefined, verification_session_ids?: Array | undefined, user_profile_result?: ProfileAPIResultStatusV2 | undefined, questions_response?: {[key: string]: QuestionGroup} | undefined, events_callback_url?: string | undefined, source?: Array | undefined}, ownership_percent?: (number | null) | undefined, shares_allocated?: (number | null) | undefined, roles?: Array | undefined, additional_fields?: Record | undefined}; export type CreateApiVerifyRelatedPersonV2Args = {body: AddRelatedPersonV2RequestSchema}; export type CreateApiVerifyRelatedPersonV2Options = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiVerifyRelatedPersonV2Response = 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 }; /** * Add Related Person V2 * * POST /verify/related_person_v2 */ export const createApiVerifyRelatedPersonV2 = async (args: CreateApiVerifyRelatedPersonV2Args, options?: CreateApiVerifyRelatedPersonV2Options) => { 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/related_person_v2${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(createApiVerifyRelatedPersonV2Response, await res.json()) };