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 PartialUserData = {first_name?: string | undefined, middle_name?: string | undefined, last_name?: string | undefined, date_of_birth?: string | undefined, phone_number?: string | undefined, email_address?: string | undefined, ip_address?: string | undefined, address?: Address | undefined}; export type AdditionalInfoType = 'KBA' | 'KENYA_KRA_PIN' | 'BANK_STATEMENT_DOCUMENT' | 'BUSINESS_REGISTRATION_DOCUMENT' | 'OPERATING_LICENSE_DOCUMENT' | 'SOURCE_OF_FUNDS_DOCUMENT' | 'VISA_DOCUMENT' | 'US_AAMVA' | 'AADHAAR_DOCUMENT_FRONT' | 'AADHAAR_DOCUMENT_BACK' | 'USER_SELFIE' | 'GENDER' | 'SEON_SESSION_PAYLOAD' | 'ADDRESS_PROOF_DOCUMENT' | 'NIGERIA_BVN_NUMBER' | 'TAX_IDENTIFICATION_NUMBER' | 'PREVIOUS_VERIFICATION_SESSION_ID' | 'FRAUD_CHECK_DOCUMENT' | 'OPERATION_CARD' | 'TRANSPORTATION_PERMIT' | 'VEHICLE_OWNERSHIP_CARD' | 'TAX_CERTIFICATE' | 'OTHER'; export type AddressProofFileSubType = 'NATIONAL_ID_FRONT' | 'NATIONAL_ID_BACK' | 'UTILITY_SERVICE_BILLS' | 'FINANCIAL_STATEMENTS' | 'GOVERNMENT_CORRESPONDENCE' | 'RESIDENTIAL_DOCUMENT' | 'EMPLOYMENT_EDUCATION_DOCUMENT' | 'LEGAL_DOCUMENT' | 'ADDRESS_DOCUMENT_OTHERS'; export type IndividualAdditionalInfo = {additional_info_type?: AdditionalInfoType | undefined, additional_info_data?: (string | {file_data?: string | undefined, file_uuid?: string | undefined, document_input_title?: (string | null) | undefined} | Array<{file: string, file_sub_type?: AddressProofFileSubType | undefined}> | Array<{type: string, answer: string}>) | undefined}; export type AdditionalInfo = Array; export type ThemeOptions = {background?: ('light' | 'dark' | null) | undefined, color_page?: (string | null) | undefined, color_brand?: (string | null) | undefined, color_brand_overlay?: (string | null) | undefined, font_name?: (string | null) | undefined, font_weights?: (string | null) | undefined, button_border_radius?: (string | null) | undefined, button_padding?: (string | null) | undefined, button_font_size?: (string | null) | undefined, button_font_weight?: (string | null) | undefined, input_border_radius?: (string | null) | undefined, input_padding?: (string | null) | undefined, input_font_size?: (string | null) | undefined, input_font_weight?: (string | null) | undefined, input_label_font_size?: (string | null) | undefined, input_label_font_weight?: (string | null) | undefined, layout_border_radius?: (string | null) | undefined, modal_border_radius?: (string | null) | undefined, image_border_radius?: (string | null) | undefined}; export type UIOptions = {common?: ({default_language?: string | undefined}) | undefined, id_verification_module?: ({allowed_country_code?: string | undefined, allowed_document_type?: (Array | string) | undefined}) | undefined}; export type VerificationOptions = {aml_config?: ({exact_match?: number | undefined, fuzziness_score?: number | undefined, monitoring?: boolean | undefined, categories_filter?: Array | undefined, search_profile?: (string | null) | undefined}) | undefined}; export type UserVerificationUrlRequest = {redirect_uri: string, template_id: string, client_reference_id?: string | undefined, client_reference_data?: Record | undefined, callback_url?: string | undefined, events_callback_url?: string | undefined, user_data?: PartialUserData | undefined, additional_info?: AdditionalInfo | undefined, theme_options?: ThemeOptions | undefined, ui_options?: UIOptions | undefined, verification_options?: VerificationOptions | undefined}; export type CreateApiVerifyGetUserVerificationUrlArgs = {body: UserVerificationUrlRequest}; export type CreateApiVerifyGetUserVerificationUrlOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const userVerificationUrlResponse = z.object({message: z.string().optional(), verification_url: z.string().optional(), verification_session_id: z.string().optional(), session_expiry_time: 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 }; /** * Get user verification url * * POST /verify/get_user_verification_url */ export const createApiVerifyGetUserVerificationUrl = async (args: CreateApiVerifyGetUserVerificationUrlArgs, options?: CreateApiVerifyGetUserVerificationUrlOptions) => { 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/get_user_verification_url${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(userVerificationUrlResponse, await res.json()) };