import {z} from 'zod' export type GalleryId = string; export type FacialTemplate = string; export type LongDetail = boolean; export type ElapsedSeconds = number; export type FutureSeconds = number; export type FacialDetectionType = 'Frontal' | 'FrontalFast'; export type MinFaceSize = number; export type MinFaceRel = number; export type MinIOD = number; export type MaxPoseDegrees = number; export type FacialQuality = 'None' | 'Bad' | 'Regular' | 'Good'; export type Analytics = boolean; export type TemplateRawExtraction = boolean; export type FalseDetectRate = number; export type MaxCandidates = number; export type MinSimilarity = number; export type AuthThreshold = number; export type LivenessDepth = 'None' | 'Partial' | 'Full'; export type SdkOptions = {longDetail?: LongDetail | undefined, elapsedAllowedSeconds?: ElapsedSeconds | undefined, futureAllowedSeconds?: FutureSeconds | undefined, facialDetection?: FacialDetectionType | undefined, minFaceAbsPx?: MinFaceSize | undefined, minFaceRel?: MinFaceRel | undefined, minIodPx?: MinIOD | undefined, maxPoseDegrees?: MaxPoseDegrees | undefined, minFacialQuality?: FacialQuality | undefined, analyticsDetection?: Analytics | undefined, templateRawExtraction?: TemplateRawExtraction | undefined, falseDetectRate?: FalseDetectRate | undefined, maxCantidates?: MaxCandidates | undefined, minSimilarity?: MinSimilarity | undefined, authThreshold?: AuthThreshold | undefined, livenessDepth?: LivenessDepth | undefined}; export type IdentifyTemplate = {facialTemplate: FacialTemplate, options?: SdkOptions | undefined}; export type CreateApiApiV1SelphidIdentifyTemplateGalleryIdArgs = {galleryId: GalleryId, body: IdentifyTemplate}; export type CreateApiApiV1SelphidIdentifyTemplateGalleryIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const galleryIndex = z.number().int(); export const facialTemplateId = z.string(); export const similarity = z.number().gte(0).lte(100); export const facialAuthenticationStatus = z.enum(["None", "Negative", "Uncertain", "Positive", "NoneBecausePoseExceed", "NoneBecauseInvalidExtractions"]); export const facialAuthenticationDetail = z.enum(["None", "PositiveLowSecurityLevel", "PositiveMediumSecurityLevel", "PositiveHighSecurityLevel"]); export const sdkDuration = z.number(); export const searchResult = z.object({galleryIndex: galleryIndex.optional(), templateId: facialTemplateId.optional(), similarity: similarity.optional(), facialAuthenticationStatus: facialAuthenticationStatus.optional(), facialAuthenticationDetail: facialAuthenticationDetail.optional(), sdkDuration: sdkDuration.optional()}); export const createApiApiV1SelphidIdentifyTemplateGalleryIdResponse = z.array(searchResult); 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 }; /** * Busca una plantilla facial en una galerĂ­a. * * POST /api/v1/selphid/identify/template/{galleryId} * * Also accepts auth: ApiKeyAuth */ export const createApiApiV1SelphidIdentifyTemplateGalleryId = async (args: CreateApiApiV1SelphidIdentifyTemplateGalleryIdArgs, options: CreateApiApiV1SelphidIdentifyTemplateGalleryIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/selphid/identify/template/${encodeURIComponent(String(args.galleryId))}${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(createApiApiV1SelphidIdentifyTemplateGalleryIdResponse, await res.json()) };