import {z} from 'zod' export type GetApiV20AuditeventsAuditEventIdArgs = {Accept?: ('application/json' | 'application/hal+json' | 'application/xml' | 'text/xml' | 'text/csv') | undefined, auditEventId: string}; export type GetApiV20AuditeventsAuditEventIdOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV20AuditeventsAuditEventIdResponse = z.object({id: z.string().min(24).max(24).optional(), timestamp: z.string().optional(), type: z.enum(["action", "create", "replace", "patch", "delete", "authentication", "authorization"]).optional(), user: z.string().optional(), modifiedResources: z.array(z.object({resourceId: z.string().optional(), resourceType: z.enum(["aiAgent", "agentassistconfig", "agentSettings", "chart", "connection", "connectionSchema", "endpoint", "extension", "file", "flow", "flowSettings", "flowState", "function", "handoverProvider", "intent", "intentDefaultReply", "intentLearningSentence", "intentRelation", "intentSentence", "intentTrainGroup", "knowledgeStore", "largeLanguageModel", "lexicon", "lexiconEntry", "lexiconKeyphrase", "lexiconSlot", "locale", "goal", "nluconnector", "nodeData", "nodeDescriptorSet", "package", "playbook", "slotFiller", "snapshot", "snippet", "simulation", "aicopilotconfig", "apiKey", "analytics", "connectionField", "conversation", "examplesentence", "functionInstance", "keyphrase", "learningsentence", "node", "playbookStep", "playbookStepAssert", "profile", "profileSchema", "project", "projectsettings", "synonym", "tag", "task", "trainerRecord", "user", "yesNoIntent"]).optional()})).optional(), payload: z.object({}).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 }; /** * Get an Audit Event * * GET /v2.0/auditevents/{auditEventId} * * Also accepts auth: APIKeyQueryParam, CXoneTokenHeader, OAuth2 */ export const getApiV20AuditeventsAuditEventId = async (args: GetApiV20AuditeventsAuditEventIdArgs, options?: GetApiV20AuditeventsAuditEventIdOptions) => { const {baseUrl = "https://api-trial.cognigy.ai/testing", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v2.0/auditevents/${encodeURIComponent(String(args.auditEventId))}${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(getApiV20AuditeventsAuditEventIdResponse, await res.json()) };