import {z} from 'zod' export type ConfigParams = {FACEPHI_SELPHID_DEBUGPATH_KEY?: string | undefined, FACEPHI_SELPHID_FACIALAUTHENTICATION_THRESHOLD?: string | undefined, FACEPHI_SELPHID_FACIALEXTRACTOR_NUM_THREADS?: string | undefined, FACEPHI_SELPHID_FACIALLIVENESS_DEPTH?: string | undefined, FACEPHI_SELPHID_FACIALLIVENESS_IAD?: string | undefined, FACEPHI_SELPHID_FACIALLIVENESS_PATH_KEY?: string | undefined, FACEPHI_SELPHID_FACIALLIVENESS_THRESHOLD?: string | undefined, FACEPHI_SELPHID_FACIAL_LICPATH_KEY?: string | undefined, FACEPHI_SELPHID_FUTURE_TIME_ALLOWED?: string | undefined, FACEPHI_SELPHID_GALLERY_REMOVE_METHOD?: string | undefined, FACEPHI_SELPHID_USAGEPATH_KEY?: string | undefined, client_max_body_size?: number | undefined, connection_timeout?: number | undefined, keep_alive_request_number?: number | undefined, logger_level?: string | undefined, logger_max_files?: number | undefined, logger_path?: string | undefined, logger_rotation?: string | undefined, number_of_threads?: number | undefined, port?: number | undefined}; export type CreateApiApiV1SelphidConfigArgs = {body: ConfigParams}; export type CreateApiApiV1SelphidConfigOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1SelphidConfigResponse = z.object({message: z.string().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 }; /** * Establece los parámetros de configuración de selphId-sdk y del servicio. **Importante:** no todos los parámetros de configuración pueden modificarse en tiempo de ejecución. La configuración de autenticación JWT es solo de arranque y este endpoint la rechaza. * * POST /api/v1/selphid/config * * Also accepts auth: ApiKeyAuth */ export const createApiApiV1SelphidConfig = async (args: CreateApiApiV1SelphidConfigArgs, options: CreateApiApiV1SelphidConfigOptions) => { 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/config${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(createApiApiV1SelphidConfigResponse, await res.json()) };