import {z} from 'zod' export type GetApiProfilesProfileIdVersionsVersionArgs = {profile_id: string, version: number}; export type GetApiProfilesProfileIdVersionsVersionOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const piiLevers = z.object({mode: z.enum(["off", "anonymize", "block"]).optional(), contextual_entities: z.array(z.enum(["NAME", "ADDRESS", "AGE", "USERNAME"])).nullable().optional(), structured_entities: z.array(z.enum(["EMAIL", "PHONE", "CREDIT_DEBIT_CARD_NUMBER", "CREDIT_DEBIT_CARD_CVV", "CREDIT_DEBIT_CARD_EXPIRY", "PIN", "PASSWORD", "INTERNATIONAL_BANK_ACCOUNT_NUMBER", "IP_ADDRESS", "AWS_ACCESS_KEY", "AWS_SECRET_KEY", "LICENSE_PLATE", "VEHICLE_IDENTIFICATION_NUMBER", "DRIVER_ID", "ES_DNI", "ES_NIE", "ES_NIF", "ES_NSS"])).nullable().optional(), reversible: z.boolean().optional()}); export const extractionProfileVersion = z.object({profile_id: z.string(), workspace_id: z.string(), version: z.number().int().gte(1), name: z.string().min(1).max(100), description: z.string().nullable().optional(), language: z.string().nullable().optional(), scope_aware: z.boolean().nullable().optional(), granularity: z.enum(["fine", "standard", "coarse"]).nullable().optional(), additional_instructions: z.string().max(1000).nullable().optional(), business_relevance: z.string().max(500).nullable().optional(), initial_pot_score: z.number().gte(0.1).lte(0.79).nullable().optional(), pii: piiLevers.nullable().optional(), created_at: z.string()}); 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 }; /** * Get one version of an extraction profile * * GET /profiles/{profile_id}/versions/{version} */ export const getApiProfilesProfileIdVersionsVersion = async (args: GetApiProfilesProfileIdVersionsVersionArgs, options: GetApiProfilesProfileIdVersionsVersionOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/profiles/${encodeURIComponent(String(args.profile_id))}/versions/${encodeURIComponent(String(args.version))}${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(extractionProfileVersion, await res.json()) };