import {z} from 'zod' export type IncidentUpdateSchema = {title?: string | undefined, description?: string | undefined, declaredAt?: Record | undefined, impactStartedAt?: Record | undefined, monitors?: (Array<{id?: string | undefined}>) | undefined, hosts?: (Array<{id?: string | undefined}>) | undefined, networkDevices?: (Array<{id?: string | undefined}>) | undefined, kubernetesClusters?: (Array<{id?: string | undefined}>) | undefined, kubernetesResources?: (Array<{id?: string | undefined}>) | undefined, kubernetesContainers?: (Array<{id?: string | undefined}>) | undefined, dockerHosts?: (Array<{id?: string | undefined}>) | undefined, podmanHosts?: (Array<{id?: string | undefined}>) | undefined, proxmoxClusters?: (Array<{id?: string | undefined}>) | undefined, openStackClouds?: (Array<{id?: string | undefined}>) | undefined, vmwareVCenters?: (Array<{id?: string | undefined}>) | undefined, iotFleets?: (Array<{id?: string | undefined}>) | undefined, dockerSwarmClusters?: (Array<{id?: string | undefined}>) | undefined, cephClusters?: (Array<{id?: string | undefined}>) | undefined, storageArrays?: (Array<{id?: string | undefined}>) | undefined, cloudResources?: (Array<{id?: string | undefined}>) | undefined, databaseServers?: (Array<{id?: string | undefined}>) | undefined, dockerResources?: (Array<{id?: string | undefined}>) | undefined, podmanResources?: (Array<{id?: string | undefined}>) | undefined, services?: (Array<{id?: string | undefined}>) | undefined, serviceLevelObjectives?: (Array<{id?: string | undefined}>) | undefined, onCallDutyPolicies?: (Array<{id?: string | undefined}>) | undefined, labels?: (Array<{id?: string | undefined}>) | undefined, currentIncidentStateId?: string | undefined, incidentSeverityId?: string | undefined, changeMonitorStatusToId?: string | undefined, customFields?: Record | undefined, rootCause?: string | undefined, postmortemNote?: string | undefined, showPostmortemOnStatusPage?: boolean | undefined, notifySubscribersOnPostmortemPublished?: boolean | undefined, postmortemPostedAt?: Record | undefined, postmortemAttachments?: (Array<{id?: string | undefined}>) | undefined, postmortemStatusId?: string | undefined, remediationNotes?: string | undefined, telemetryQuery?: Record | undefined, isVisibleOnStatusPage?: boolean | undefined, statusPages?: (Array<{id?: string | undefined}>) | undefined, isPrivate?: boolean | undefined, enableReminders?: boolean | undefined}; export type UpdateApiIncidentIdArgs = {id: string, body: {data: IncidentUpdateSchema}}; export type UpdateApiIncidentIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const incidentReadSchema = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), projectId: z.string().optional(), title: z.string(), description: z.string().optional(), declaredAt: z.object({}).optional(), impactStartedAt: z.object({}).optional(), firstPagedAt: z.object({}).optional(), slug: z.string().optional(), createdByUserId: z.string().optional(), monitors: z.array(z.object({id: z.string().optional()})).optional(), hosts: z.array(z.object({id: z.string().optional()})).optional(), networkDevices: z.array(z.object({id: z.string().optional()})).optional(), kubernetesClusters: z.array(z.object({id: z.string().optional()})).optional(), kubernetesResources: z.array(z.object({id: z.string().optional()})).optional(), kubernetesContainers: z.array(z.object({id: z.string().optional()})).optional(), dockerHosts: z.array(z.object({id: z.string().optional()})).optional(), podmanHosts: z.array(z.object({id: z.string().optional()})).optional(), proxmoxClusters: z.array(z.object({id: z.string().optional()})).optional(), openStackClouds: z.array(z.object({id: z.string().optional()})).optional(), vmwareVCenters: z.array(z.object({id: z.string().optional()})).optional(), iotFleets: z.array(z.object({id: z.string().optional()})).optional(), dockerSwarmClusters: z.array(z.object({id: z.string().optional()})).optional(), cephClusters: z.array(z.object({id: z.string().optional()})).optional(), storageArrays: z.array(z.object({id: z.string().optional()})).optional(), cloudResources: z.array(z.object({id: z.string().optional()})).optional(), databaseServers: z.array(z.object({id: z.string().optional()})).optional(), dockerResources: z.array(z.object({id: z.string().optional()})).optional(), podmanResources: z.array(z.object({id: z.string().optional()})).optional(), services: z.array(z.object({id: z.string().optional()})).optional(), serviceLevelObjectives: z.array(z.object({id: z.string().optional()})).optional(), onCallDutyPolicies: z.array(z.object({id: z.string().optional()})).optional(), labels: z.array(z.object({id: z.string().optional()})).optional(), currentIncidentStateId: z.string().optional(), incidentSeverityId: z.string(), changeMonitorStatusToId: z.string().optional(), subscriberNotificationStatusMessage: z.string().optional(), subscriberNotificationStatusMessageOnPostmortemPublished: z.string().optional(), shouldStatusPageSubscribersBeNotifiedOnIncidentCreated: z.boolean().optional(), customFields: z.object({}).optional(), rootCause: z.string().optional(), postmortemNote: z.string().optional(), showPostmortemOnStatusPage: z.boolean().optional(), notifySubscribersOnPostmortemPublished: z.boolean().optional(), postmortemPostedAt: z.object({}).optional(), postmortemAttachments: z.array(z.object({id: z.string().optional()})).optional(), postmortemStatusId: z.string().optional(), createdStateLog: z.object({}).optional(), createdCriteriaId: z.string().optional(), createdIncidentTemplateId: z.string().optional(), seriesFingerprint: z.string().optional(), seriesLabels: z.object({}).optional(), monitorSummary: z.object({}).optional(), createdByProbeId: z.string().optional(), isCreatedAutomatically: z.boolean().optional(), holdsMonitors: z.boolean().optional(), postmortemDraftWaitingSince: z.object({}).optional(), remediationNotes: z.string().optional(), telemetryQuery: z.object({}).optional(), incidentNumber: z.number().optional(), incidentNumberWithPrefix: z.string().optional(), isVisibleOnStatusPage: z.boolean().optional(), statusPages: z.array(z.object({id: z.string().optional()})).optional(), isPrivate: z.boolean().optional(), enableReminders: z.boolean().optional(), nextReminderNotificationAt: z.object({}).optional(), reminderNotificationSentCount: z.number().optional(), incidentEpisodeId: z.string().optional()}); export const updateApiIncidentIdResponse = z.object({data: incidentReadSchema.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 Incident * * PUT /incident/{id} */ export const updateApiIncidentId = async (args: UpdateApiIncidentIdArgs, options?: UpdateApiIncidentIdOptions) => { const {baseUrl = "https://oneuptime.com/api", 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 (ApiKey !== undefined) headers.set("APIKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/incident/${encodeURIComponent(String(args.id))}${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(updateApiIncidentIdResponse, await res.json()) };