import {z} from 'zod' export type GetApiApiV1StatuspagesStatuspageIdIncidentsIncidentIdUpdatesArgs = {statuspage_id: string, incident_id: string, page?: number | undefined, page_size?: number | undefined, search?: string | undefined}; export type GetApiApiV1StatuspagesStatuspageIdIncidentsIncidentIdUpdatesOptions = {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 getApiApiV1StatuspagesStatuspageIdIncidentsIncidentIdUpdatesResponse = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(incidentUpdate)}); 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 incident's updates * * GET /api/v1/statuspages/{statuspage_id}/incidents/{incident_id}/updates/ */ export const getApiApiV1StatuspagesStatuspageIdIncidentsIncidentIdUpdates = async (args: GetApiApiV1StatuspagesStatuspageIdIncidentsIncidentIdUpdatesArgs, options: GetApiApiV1StatuspagesStatuspageIdIncidentsIncidentIdUpdatesOptions) => { 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)) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiV1StatuspagesStatuspageIdIncidentsIncidentIdUpdatesResponse, await res.json()) };