import {z} from 'zod' export type StatusPageIncidentUpdateInput = {title?: string | undefined, retro_should_notify?: boolean | undefined, retro_notify_message?: (string | null) | undefined}; export type PatchApiStatusPagesStatusPageIdIncidentsIncidentIdArgs = {status_page_id: string, incident_id: string, body: StatusPageIncidentUpdateInput}; export type PatchApiStatusPagesStatusPageIdIncidentsIncidentIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const incidentBuildType = z.enum(["current", "retroactive", "scheduled_maintenance"]); export const incidentStatus = z.enum(["maintenance_scheduled", "in_maintenance", "maintenance_complete", "investigating", "identified", "resolving", "monitoring", "resolved"]); export const incidentSeverity = z.enum(["problem_detected", "degraded_performance", "partial_outage", "outage", "operational"]); export const incidentUpdate = z.object({id: z.string(), incident_id: z.string(), message: z.string().nullable().optional(), status: incidentStatus, severity: incidentSeverity, start_at: z.string().optional(), should_notify: z.boolean().nullable().optional(), notified_at: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const webLinks = z.object({web: z.string()}); export const statusPageIncident = z.object({id: z.string(), status_page_id: z.string(), title: z.string(), retro_should_notify: z.boolean(), retro_notify_message: z.string().nullable(), build_type: incidentBuildType, current_status: incidentStatus.nullable().optional(), current_severity: incidentSeverity.nullable().optional(), start_at: z.string().nullable().optional(), closed_at: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), updates: z.array(incidentUpdate), links: webLinks}); export const responseMeta = z.object({request_id: z.string().optional()}); export const patchApiStatusPagesStatusPageIdIncidentsIncidentIdResponse = z.object({data: statusPageIncident, meta: responseMeta.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 an incident * * PATCH /status_pages/{status_page_id}/incidents/{incident_id} */ export const patchApiStatusPagesStatusPageIdIncidentsIncidentId = async (args: PatchApiStatusPagesStatusPageIdIncidentsIncidentIdArgs, options?: PatchApiStatusPagesStatusPageIdIncidentsIncidentIdOptions) => { const {baseUrl = "https://app.honeybadger.io/v3", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/status_pages/${encodeURIComponent(String(args.status_page_id))}/incidents/${encodeURIComponent(String(args.incident_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiStatusPagesStatusPageIdIncidentsIncidentIdResponse, await res.json()) };