import {z} from 'zod' export type AddressDocumentVerificationId = string; export type GetApiV2AddressDocumentVerificationsAddressDocumentVerificationIdArgs = {address_document_verification_id: AddressDocumentVerificationId}; export type GetApiV2AddressDocumentVerificationsAddressDocumentVerificationIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const addressDocumentVerificationId = z.string(); export const addressDocumentVerificationStatus = z.enum(["created", "quality_checks_in_progress", "checks_in_progress", "approved", "declined", "retry_required", "inconclusive"]); 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 riskLabel = z.enum(["multiple_faces_detected", "mcc_not_confident", "risky_document_format", "no_uk_footprint"]); export const riskLabels = z.array(riskLabel); export const countryCodeIso2 = z.string(); export const address = z.object({address_line1: z.string().max(250).optional(), address_line2: z.string().max(250).optional(), city: z.string().max(50).optional(), state: z.string().max(50).optional(), zip: z.string().max(50).optional(), country: countryCodeIso2.optional()}); export const proofOfAddressDocument = z.object({document_type: z.string().optional(), issuer: z.string().optional(), full_names: z.array(z.string()).optional(), address: address.optional(), issue_date: z.string().optional()}); export const halLink = z.object({href: z.string()}); export const addressDocumentVerificationLinks = z.object({self: halLink}); export const userJourneyId = z.string(); export const applicantId = z.string(); export const declaredData = z.object({name: z.string().min(2).max(255), birth_date: z.string().optional()}); export const addressDocumentVerificationOutputGet = z.object({created_on: z.string(), modified_on: z.string(), id: addressDocumentVerificationId, status: addressDocumentVerificationStatus, response_codes: z.array(responseCodes), risk_labels: riskLabels.optional(), address_document: proofOfAddressDocument.optional(), _links: addressDocumentVerificationLinks, user_journey_id: userJourneyId, applicant_id: applicantId, webhook_url: z.string().optional(), declared_data: declaredData.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 }; /** * Retrieve an Address Document Verification * * GET /v2/address-document-verifications/{address_document_verification_id} */ export const getApiV2AddressDocumentVerificationsAddressDocumentVerificationId = async (args: GetApiV2AddressDocumentVerificationsAddressDocumentVerificationIdArgs, options?: GetApiV2AddressDocumentVerificationsAddressDocumentVerificationIdOptions) => { const {baseUrl = "https://api.ubble.ai", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/address-document-verifications/${encodeURIComponent(String(args.address_document_verification_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(addressDocumentVerificationOutputGet, await res.json()) };