import {z} from 'zod' export type GetApiApiV1StatuspagesStatuspageIdIncidentsArgs = {statuspage_id: string, page?: number | undefined, page_size?: number | undefined, search?: string | undefined, incident_type?: ('INCIDENT' | 'SCHEDULED_MAINTENANCE') | undefined, start_date?: string | undefined, end_date?: string | undefined, ordering?: ('pk' | '-pk' | 'starts_at' | '-starts_at') | undefined}; export type GetApiApiV1StatuspagesStatuspageIdIncidentsOptions = {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 getApiApiV1StatuspagesStatuspageIdIncidentsResponse = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(incident)}); 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 }; /** * List all status page incidents or maintenance windows * * GET /api/v1/statuspages/{statuspage_id}/incidents/ */ export const getApiApiV1StatuspagesStatuspageIdIncidents = async (args: GetApiApiV1StatuspagesStatuspageIdIncidentsArgs, options: GetApiApiV1StatuspagesStatuspageIdIncidentsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.search != null) query.append("search", String(args.search)) if (args.incident_type != null) query.append("incident_type", String(args.incident_type)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.ordering != null) query.append("ordering", String(args.ordering)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/statuspages/${encodeURIComponent(String(args.statuspage_id))}/incidents/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiV1StatuspagesStatuspageIdIncidentsResponse, await res.json()) };