import {z} from 'zod' export type Incident = {pk?: number | undefined, name: string, description?: string | undefined, starts_at: string, ends_at?: (string | null) | undefined, duration?: string | undefined, include_in_global_metrics?: boolean | undefined, incident_type_display?: string | undefined, updates: Array<{id?: number | undefined, created_at?: string | undefined, updated_at: string, description?: string | undefined, incident_state: 'investigating' | 'identified' | 'monitoring' | 'resolved' | 'notification' | 'maintenance', incident_state_display?: string | undefined, notify_subscribers?: boolean | undefined, resolve_components?: boolean | undefined, resolve_incident?: boolean | undefined}>, affected_components?: (Array<{id?: number | undefined, status: 'major-outage' | 'partial-outage' | 'degraded-performance' | 'under-maintenance', name?: string | undefined, description?: string | undefined, component: {id: number, name?: string | undefined}}> | null) | undefined, created_at?: string | undefined, incident_state?: string | undefined, incident_type: 'INCIDENT' | 'SCHEDULED_MAINTENANCE', url?: string | undefined, update_component_status?: boolean | undefined, notify_subscribers?: boolean | undefined, send_maintenance_start_notification?: boolean | undefined, resolve_components?: boolean | undefined}; export type PatchApiApiV1StatuspagesStatuspageIdIncidentsPkArgs = {statuspage_id: string, pk: string, body: Incident}; export type PatchApiApiV1StatuspagesStatuspageIdIncidentsPkOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const incident = z.object({pk: z.number().int().optional(), name: z.string().max(255), description: z.string().optional(), starts_at: z.string(), ends_at: z.string().nullable().optional(), duration: z.string().optional(), include_in_global_metrics: z.boolean().optional(), incident_type_display: z.string().optional(), updates: z.array(z.object({id: z.number().int().optional(), created_at: z.string().optional(), updated_at: z.string(), description: z.string().optional(), incident_state: z.enum(["investigating", "identified", "monitoring", "resolved", "notification", "maintenance"]), incident_state_display: z.string().optional(), notify_subscribers: z.boolean().optional(), resolve_components: z.boolean().optional(), resolve_incident: z.boolean().optional()})), affected_components: z.array(z.object({id: z.number().int().optional(), status: z.enum(["major-outage", "partial-outage", "degraded-performance", "under-maintenance"]), name: z.string().optional(), description: z.string().optional(), component: z.object({id: z.number().int(), name: z.string().optional()})})).nullable().optional(), created_at: z.string().optional(), incident_state: z.string().optional(), incident_type: z.enum(["INCIDENT", "SCHEDULED_MAINTENANCE"]), url: z.string().optional(), update_component_status: z.boolean().optional(), notify_subscribers: z.boolean().optional(), send_maintenance_start_notification: z.boolean().optional(), resolve_components: z.boolean().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 }; /** * Partially update a single status page incident or maintenance window * * PATCH /api/v1/statuspages/{statuspage_id}/incidents/{pk}/ */ export const patchApiApiV1StatuspagesStatuspageIdIncidentsPk = async (args: PatchApiApiV1StatuspagesStatuspageIdIncidentsPkArgs, options: PatchApiApiV1StatuspagesStatuspageIdIncidentsPkOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/statuspages/${encodeURIComponent(String(args.statuspage_id))}/incidents/${encodeURIComponent(String(args.pk))}/${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(incident, await res.json()) };