import {z} from 'zod' 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 CreateVerificationURLForBusinessOfficerRequestSchema = {business_profile_id: string, person_reference_id: string, template_id: string, redirect_uri: string, client_reference_id?: string | undefined, client_reference_data?: Record | undefined, theme_options?: ThemeOptions | undefined, ui_options?: UIOptions | undefined, verification_options?: VerificationOptions | undefined}; export type CreateApiVerifyCreateVerificationSessionUrlForBusinessOfficerArgs = {body: CreateVerificationURLForBusinessOfficerRequestSchema}; export type CreateApiVerifyCreateVerificationSessionUrlForBusinessOfficerOptions = {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 }; /** * KYC Business Officer- Create Session URL * * POST /verify/create_verification_session_url_for_business_officer */ export const createApiVerifyCreateVerificationSessionUrlForBusinessOfficer = async (args: CreateApiVerifyCreateVerificationSessionUrlForBusinessOfficerArgs, options?: CreateApiVerifyCreateVerificationSessionUrlForBusinessOfficerOptions) => { 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/create_verification_session_url_for_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(userVerificationUrlResponse, await res.json()) };