import {z} from 'zod' export type IncidentUpdate = {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}; export type CreateApiApiV1StatuspagesStatuspageIdIncidentsIncidentIdUpdatesArgs = {statuspage_id: string, incident_id: string, body: IncidentUpdate}; export type CreateApiApiV1StatuspagesStatuspageIdIncidentsIncidentIdUpdatesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const incidentUpdate = 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()}); 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 a new incident update * * POST /api/v1/statuspages/{statuspage_id}/incidents/{incident_id}/updates/ */ export const createApiApiV1StatuspagesStatuspageIdIncidentsIncidentIdUpdates = async (args: CreateApiApiV1StatuspagesStatuspageIdIncidentsIncidentIdUpdatesArgs, options: CreateApiApiV1StatuspagesStatuspageIdIncidentsIncidentIdUpdatesOptions) => { 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.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(incidentUpdate, await res.json()) };