import {z} from 'zod' export type TenantId = string; export type GetApiFacesArgs = {tenantId: TenantId}; export type GetApiFacesOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createAt = z.string(); export const faceDescription = z.string(); export const facialTemplateRaw = z.string(); export const faceId = z.string(); export const mediaId = z.string(); export const tenantId = z.string(); export const updateAt = z.string(); export const faceResponse = z.object({createAt: createAt.optional(), description: faceDescription.optional(), facialTemplateRaw: facialTemplateRaw.optional(), id: faceId.optional(), mediaId: mediaId.optional(), tenantId: tenantId.optional(), updateAt: updateAt.optional()}); export const facesResponse = z.array(faceResponse); 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 }; /** * Recupera todos los especímenes (rostros) de la base de datos que coinciden con el tenantId. Si se omite, se devolverán todos los elementos. * * GET /faces * * Also accepts auth: ApiKeyAuth */ export const getApiFaces = async (args: GetApiFacesArgs, options: GetApiFacesOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.tenantId != null) query.append("tenantId", String(args.tenantId)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/faces${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(facesResponse, await res.json()) };