import {z} from 'zod' export type AiPrivacyPresetDTO = {id?: string | undefined, projectId?: string | undefined, name?: string | undefined, elementName?: string | undefined, patternType?: ('ELEMENT_NAME' | 'REGEX' | 'BUILTIN') | undefined, regexPattern?: string | undefined, operation?: ('MASK' | 'DELETE' | 'ENCRYPT' | 'HASH' | 'DETECT') | undefined, maskMode?: ('FIXED' | 'KEEP_FIRST' | 'KEEP_LAST' | 'MASK_FIRST' | 'PLACEHOLDER_SEQUENCE' | 'SYNTHETIC') | undefined, maskPattern?: string | undefined, maskVisibleCharCount?: number | undefined, enabled?: boolean | undefined, builtIn?: boolean | undefined}; export type UpdateApiApiopsSettingsAiPrivacyPresetsPresetNameArgs = {presetName: string, projectId?: string | undefined, body: AiPrivacyPresetDTO}; export type UpdateApiApiopsSettingsAiPrivacyPresetsPresetNameOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const deploymentResult = z.object({envName: z.string().optional(), podName: z.string().optional(), podIp: z.string().optional(), success: z.boolean().optional(), detail: z.string().optional(), responseTime: z.number().int().optional(), detailList: z.array(z.unknown()).optional(), firstFromApiResultList: z.unknown()}); export const apiOpsAdvisoryDTO = z.object({level: z.string().optional(), key: z.string().optional(), params: z.record(z.string(), z.unknown()).optional()}); export const apiOpsResponseSuccess = z.object({status: z.enum(["SUCCESS", "FAILURE"]).optional(), resultMessage: z.string().optional(), resultList: z.array(z.string()).optional(), resultCount: z.number().int().optional(), deploymentResult: deploymentResult.optional(), unresolvedReferences: z.array(z.string()).optional(), advisories: z.array(apiOpsAdvisoryDTO).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 }; /** * Updates an existing AI privacy preset * * PUT /apiops/settings/ai-privacy-presets/{presetName}/ */ export const updateApiApiopsSettingsAiPrivacyPresetsPresetName = async (args: UpdateApiApiopsSettingsAiPrivacyPresetsPresetNameArgs, options?: UpdateApiApiopsSettingsAiPrivacyPresetsPresetNameOptions) => { const {baseUrl = "http://167.86.118.166:32080", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.projectId != null) query.append("projectId", String(args.projectId)) const url = `${baseUrl.replace(/\/+$/, '')}/apiops/settings/ai-privacy-presets/${encodeURIComponent(String(args.presetName))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(apiOpsResponseSuccess, await res.json()) };