import {z} from 'zod' export type FavFaceAuthenticationId = string; export type GetApiFaceAuthenticationsFaceAuthenticationIdArgs = {face_authentication_id: FavFaceAuthenticationId}; export type GetApiFaceAuthenticationsFaceAuthenticationIdOptions = {baseUrl: string, OAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const applicantId = z.string(); export const idvUserJourneyId = z.string(); export const favVerificationStatuses = z.enum(["approved", "capture_in_progress", "checks_in_progress", "created", "declined", "inconclusive", "pending", "refused", "retry_required"]); export const idvPreSignedUrl = z.string(); export const idvFace = z.object({image_signed_url: idvPreSignedUrl}); export const idvResponseCodeCode = z.number().int().gte(10000).lte(69999); export const idvResponseCodeSummary = z.string(); export const idvResponseCode = z.object({code: idvResponseCodeCode, summary: idvResponseCodeSummary}); export const idvResponseCodes = z.array(idvResponseCode); export const idvRiskLabel = z.enum(["multiple_faces_detected", "mcc_not_confident", "risky_document_format"]); export const idvRiskLabels = z.array(idvRiskLabel); export const idvHalLink = z.object({href: z.string()}); export const favFaceAuthenticationLinks = z.object({self: idvHalLink, applicant: idvHalLink}); export const favFaceAuthenticationId = z.string(); export const favFaceAuthenticationOutput = z.object({created_on: z.string(), modified_on: z.string(), applicant_id: applicantId, user_journey_id: idvUserJourneyId.optional(), status: favVerificationStatuses, face: idvFace.optional(), response_codes: idvResponseCodes, risk_labels: idvRiskLabels, _links: favFaceAuthenticationLinks, id: favFaceAuthenticationId}); 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 a face authentication * * GET /face-authentications/{face_authentication_id} * * Also accepts auth: ApiSecretKey */ export const getApiFaceAuthenticationsFaceAuthenticationId = async (args: GetApiFaceAuthenticationsFaceAuthenticationIdArgs, options: GetApiFaceAuthenticationsFaceAuthenticationIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (OAuth !== undefined) headers.set('authorization', `Bearer ${OAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/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(favFaceAuthenticationOutput, await res.json()) };