import {z} from 'zod' export type CreateApiOmniAuthenticationsExternalSearchArgs = {offset?: number | undefined, limit?: number | undefined, 'api-version': string, body: {[key: string]: Record}}; export type CreateApiOmniAuthenticationsExternalSearchOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, IncodeHardwareIdAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const authenticationAttemptExternalDto = z.object({customerId: z.string().optional(), deviceType: z.enum(["IOS", "ANDROID", "WEBAPP"]).optional(), deviceName: z.string().optional(), version: z.string().optional(), isSpoof: z.boolean().optional(), get_updatedAt: z.number().int().optional(), url: z.string().optional(), isAuthenticated: z.boolean().optional(), recognitionConfidence: z.number().optional(), source: z.string().optional(), transactionId: z.string().optional(), authenticationType: z.enum(["ONE_TO_ONE", "ONE_TO_N"]).optional(), authenticationMethod: z.enum(["server", "local", "hybrid"]).optional(), faceEnrollmentForced: z.boolean().optional(), isBlocklisted: z.boolean().optional(), clientRecognitionThreshold: z.number().optional(), clientLivenessThreshold: z.number().optional(), blocklistConfidence: z.number().optional(), videoRecordingUrl: z.string().optional()}); export const customerAuthenticationsExternalResponse = z.object({authenticationAttempts: z.array(authenticationAttemptExternalDto).optional(), total: z.number().int().optional(), more: z.boolean().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 }; /** * Fetch authentication attempts * * POST /omni/authentications/external/search */ export const createApiOmniAuthenticationsExternalSearch = async (args: CreateApiOmniAuthenticationsExternalSearchArgs, options?: CreateApiOmniAuthenticationsExternalSearchOptions) => { const {baseUrl = "https://demo-api.incodesmile.com", fetch: fetchFn = fetch, ApiKeyAuth, IncodeHardwareIdAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args['api-version'] != null) headers.set("api-version", String(args['api-version'])) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) if (IncodeHardwareIdAuth !== undefined) headers.set("X-Incode-Hardware-Id", IncodeHardwareIdAuth) const url = `${baseUrl.replace(/\/+$/, '')}/omni/authentications/external/search${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(customerAuthenticationsExternalResponse, await res.json()) };