import {z} from 'zod' export type GetApiExceptionsTguidPguidArgs = {tguid: string, pguid: string}; export type GetApiExceptionsTguidPguidOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const minutiae = z.object({query: z.number().int().optional(), reference: z.number().int().optional()}); export const biometricMatch = z.object({score: z.number().int().optional(), queryIndex: z.number().int().optional(), referenceIndex: z.number().int().optional(), minutia: z.array(minutiae).optional()}); export const match = z.object({matchedPersonPguid: z.string().optional(), matchedPersonTguid: z.string().optional(), biometricMatches: z.array(biometricMatch).optional()}); export const exceptionAnalysis = z.object({status: z.enum(["ANALYSIS", "DIFFERENT_FINGERS", "SAME_FINGERS", "INCORRECT_ENROLL", "RECOLLECT", "MERGE_TRANSACTIONS", "APPROVE", "REJECT", "ERROR"]).optional(), exceptionTimestamp: z.number().int().optional(), user: z.string().optional(), comments: z.string().optional()}); export const exception = z.object({enrollPguid: z.string().optional(), enrollTguid: z.string().optional(), transactionTimestamp: z.number().int().optional(), match: match.optional(), assignedUser: z.string().optional(), exceptionAnalysis: exceptionAnalysis.optional(), transactionType: z.enum(["ENROLL", "UPDATE"]).optional()}); export const getExceptionsResponse = z.object({data: exception.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 }; /** * getException * * GET /exceptions/{tguid}/{pguid} */ export const getApiExceptionsTguidPguid = async (args: GetApiExceptionsTguidPguidArgs, options?: GetApiExceptionsTguidPguidOptions) => { const {baseUrl = "http://:8085/gbds/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/exceptions/${encodeURIComponent(String(args.tguid))}/${encodeURIComponent(String(args.pguid))}${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(getExceptionsResponse, await res.json()) };