import {z} from 'zod' export type FaceAuthenticationId = string; export type GetApiV2FaceAuthenticationsFaceAuthenticationIdArgs = {face_authentication_id: FaceAuthenticationId}; export type GetApiV2FaceAuthenticationsFaceAuthenticationIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const faceAuthenticationId = z.string(); export const verificationStatuses = z.enum(["created", "pending", "capture_in_progress", "checks_in_progress", "approved", "declined", "retry_required", "refused", "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 verificationFace = z.object({image_signed_url: z.string().nullable().optional()}); export const halLink = z.object({href: z.string()}); export const faceAuthenticationLinks = z.object({self: halLink, applicant: halLink}); export const userJourneyId = z.string(); export const applicantId = z.string(); export const faceAuthenticationOutputGet = z.object({id: faceAuthenticationId.optional(), status: verificationStatuses.optional(), response_codes: z.array(responseCodes).optional(), risk_labels: riskLabels.optional(), face: verificationFace.optional(), _links: faceAuthenticationLinks.optional(), user_journey_id: userJourneyId.optional(), applicant_id: applicantId.optional(), webhook_url: z.string().optional(), created_on: z.string(), modified_on: z.string()}); 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 a face authentication * * GET /v2/face-authentications/{face_authentication_id} */ export const getApiV2FaceAuthenticationsFaceAuthenticationId = async (args: GetApiV2FaceAuthenticationsFaceAuthenticationIdArgs, options?: GetApiV2FaceAuthenticationsFaceAuthenticationIdOptions) => { 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/face-authentications/${encodeURIComponent(String(args.face_authentication_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(faceAuthenticationOutputGet, await res.json()) };