import {z} from 'zod' export type EventEnrichmentReference = {id?: string | undefined, type?: 'event_enrichment_reference' | undefined, summary?: string | undefined, self?: string | undefined}; export type EventEnrichmentRule = {id?: string | undefined, label?: string | undefined, conditions?: (Array<{expression?: string | undefined}>) | undefined, actions?: ({extractions: Array<{target?: string | undefined, template?: (string | null) | undefined, source?: string | undefined, regex?: string | undefined}>} | {enrichments: Array<{schema_to_search?: string | undefined, search_values?: (Array<{path?: string | undefined, template?: string | undefined, query_field_name?: string | undefined}>) | undefined, target?: string | undefined}>}) | undefined, disabled?: boolean | undefined}; export type EventEnrichmentOrchestrationPath = {type?: 'event_enrichment' | undefined, parent?: EventEnrichmentReference | undefined, self?: string | undefined, sets?: (Array<{id?: string | undefined, rules?: Array | undefined}>) | undefined, created_at?: string | undefined, created_by?: ({id?: string | undefined, type?: string | undefined, self?: string | undefined} | null) | undefined, updated_at?: string | undefined, updated_by?: ({id?: string | undefined, type?: string | undefined, self?: string | undefined} | null) | undefined, version?: string | undefined}; export type UpdateApiEnrichmentEventEnrichmentsIdRulesArgs = {Accept: string, 'Content-Type': 'application/json', id: string, body: {orchestration_path: EventEnrichmentOrchestrationPath}}; export type UpdateApiEnrichmentEventEnrichmentsIdRulesOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const eventEnrichmentReference = z.object({id: z.string().optional(), type: z.literal("event_enrichment_reference").optional(), summary: z.string().optional(), self: z.string().optional()}); export const eventEnrichmentRule = z.object({id: z.string().optional(), label: z.string().optional(), conditions: z.array(z.object({expression: z.string().optional()})).optional(), actions: z.union([z.object({extractions: z.array(z.object({target: z.string().optional(), template: z.string().nullable().optional(), source: z.string().optional(), regex: z.string().optional()}))}), z.object({enrichments: z.array(z.object({schema_to_search: z.string().optional(), search_values: z.array(z.object({path: z.string().optional(), template: z.string().optional(), query_field_name: z.string().optional()})).optional(), target: z.string().optional()}))})]).optional(), disabled: z.boolean().optional()}); export const eventEnrichmentOrchestrationPath = z.object({type: z.literal("event_enrichment").optional(), parent: eventEnrichmentReference.optional(), self: z.string().optional(), sets: z.array(z.object({id: z.string().optional(), rules: z.array(eventEnrichmentRule).optional()})).optional(), created_at: z.string().optional(), created_by: z.object({id: z.string().optional(), type: z.string().optional(), self: z.string().optional()}).nullable().optional(), updated_at: z.string().optional(), updated_by: z.object({id: z.string().optional(), type: z.string().optional(), self: z.string().optional()}).nullable().optional(), version: z.string().optional()}); export const updateApiEnrichmentEventEnrichmentsIdRulesResponse = z.object({orchestration_path: eventEnrichmentOrchestrationPath.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 }; /** * Update Event Enrichment rules * * PUT /enrichment/event_enrichments/{id}/rules */ export const updateApiEnrichmentEventEnrichmentsIdRules = async (args: UpdateApiEnrichmentEventEnrichmentsIdRulesArgs, options?: UpdateApiEnrichmentEventEnrichmentsIdRulesOptions) => { const {baseUrl = "https://api.pagerduty.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/enrichment/event_enrichments/${encodeURIComponent(String(args.id))}/rules${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(updateApiEnrichmentEventEnrichmentsIdRulesResponse, await res.json()) };