import {z} from 'zod' export type PhonePrefix = unknown; export type DomesticPhoneNumber = unknown; export type PhoneNumber = {country_code: PhonePrefix, number: DomesticPhoneNumber}; export type CountryCodeIso2 = unknown; export type DocumentTypes = 'Driving licence' | 'ID' | 'Other' | 'Passport' | 'Residence Permit' | 'Travel Document' | 'Visa'; export type LanguageCode = unknown; export type IdentityClientInformation = {pre_selected_residence_country?: CountryCodeIso2 | undefined, pre_selected_document_issuing_country?: CountryCodeIso2 | undefined, pre_selected_document_type?: DocumentTypes | undefined, pre_selected_language?: LanguageCode | undefined}; export type IdentityAttemptBase = {phone_number?: PhoneNumber | undefined, client_information?: IdentityClientInformation | undefined, redirect_url?: string | undefined, mobile_handoff_url?: (string | null) | undefined}; export type IdentityVerificationAttemptInputPost = IdentityAttemptBase; export type CreateApiV2IdentityVerificationsIdentityVerificationIdAttemptsArgs = {identity_verification_id: string, body: IdentityVerificationAttemptInputPost}; export type CreateApiV2IdentityVerificationsIdentityVerificationIdAttemptsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const attemptStates = z.enum(["pending_redirection", "capture_in_progress", "checks_in_progress", "completed", "expired", "capture_aborted", "capture_refused", "checks_inconclusive", "terminated"]); export const responseCode = z.number().int().gte(10000).lte(69999); export const responseSummary = z.string(); export const responseCodes = z.object({code: responseCode, summary: responseSummary}); export const initialDevices = z.enum(["mobile", "desktop"]); export const identityVerificationApplicantSessionInformation = z.object({ip_address: z.string().optional(), number_of_sessions: z.number().int().optional(), user_agent: z.string().optional(), initial_device: initialDevices.optional()}); export const halLink = z.object({href: z.string()}); export const attemptLinks = z.object({verification_url: halLink, self: halLink}); export const phonePrefix = z.string(); export const domesticPhoneNumber = z.string(); export const phoneNumber = z.object({country_code: phonePrefix, number: domesticPhoneNumber}); export const countryCodeIso2 = z.string(); export const documentTypes = z.enum(["Driving licence", "ID", "Other", "Passport", "Residence Permit", "Travel Document", "Visa"]); export const languageCode = z.string(); export const identityClientInformation = z.object({pre_selected_residence_country: countryCodeIso2.optional(), pre_selected_document_issuing_country: countryCodeIso2.optional(), pre_selected_document_type: documentTypes.optional(), pre_selected_language: languageCode.optional()}); export const identityVerificationAttemptOutputPost = z.object({id: z.string().optional(), status: attemptStates.optional(), response_codes: z.array(responseCodes).optional(), applicant_session_information: identityVerificationApplicantSessionInformation.optional(), _links: attemptLinks.optional(), created_on: z.string(), modified_on: z.string(), phone_number: phoneNumber.optional(), client_information: identityClientInformation.optional(), redirect_url: z.string().optional(), mobile_handoff_url: z.string().max(512).nullable().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 }; /** * Create an attempt * * POST /v2/identity-verifications/{identity_verification_id}/attempts */ export const createApiV2IdentityVerificationsIdentityVerificationIdAttempts = async (args: CreateApiV2IdentityVerificationsIdentityVerificationIdAttemptsArgs, options?: CreateApiV2IdentityVerificationsIdentityVerificationIdAttemptsOptions) => { const {baseUrl = "https://api.ubble.ai", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/identity-verifications/${encodeURIComponent(String(args.identity_verification_id))}/attempts${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(identityVerificationAttemptOutputPost, await res.json()) };