import {z} from 'zod' export type IncidentStatus = 'maintenance_scheduled' | 'in_maintenance' | 'maintenance_complete' | 'investigating' | 'identified' | 'resolving' | 'monitoring' | 'resolved'; export type IncidentSeverity = 'problem_detected' | 'degraded_performance' | 'partial_outage' | 'outage' | 'operational'; export type IncidentUpdateInput = {message?: string | undefined, status?: IncidentStatus | undefined, severity?: IncidentSeverity | undefined, start_at?: string | undefined, start_now?: boolean | undefined, should_notify?: boolean | undefined}; export type CreateApiStatusPagesStatusPageIdIncidentsIncidentIdUpdatesArgs = {status_page_id: string, incident_id: string, body: IncidentUpdateInput}; export type CreateApiStatusPagesStatusPageIdIncidentsIncidentIdUpdatesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; 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 responseMeta = z.object({request_id: z.string().optional()}); export const createApiStatusPagesStatusPageIdIncidentsIncidentIdUpdatesResponse = z.object({data: incidentUpdate, 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 }; /** * Create an incident update * * POST /status_pages/{status_page_id}/incidents/{incident_id}/updates */ export const createApiStatusPagesStatusPageIdIncidentsIncidentIdUpdates = async (args: CreateApiStatusPagesStatusPageIdIncidentsIncidentIdUpdatesArgs, options?: CreateApiStatusPagesStatusPageIdIncidentsIncidentIdUpdatesOptions) => { 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))}/updates${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiStatusPagesStatusPageIdIncidentsIncidentIdUpdatesResponse, await res.json()) };