import {z} from 'zod' export type GetApiStatusPagesIdPostsPostIdPostUpdatesArgs = {Accept: string, id: string, post_id: string, reviewed_status?: ('approved' | 'not_reviewed') | undefined}; export type GetApiStatusPagesIdPostsPostIdPostUpdatesOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const statusPagePostUpdate = z.object({id: z.string().optional(), self: z.string().optional(), post: z.object({id: z.string(), type: z.string().optional()}).optional(), message: z.string().optional(), reviewed_status: z.enum(["approved", "not_reviewed"]).optional(), status: z.object({id: z.string(), type: z.string().optional()}).optional(), severity: z.object({id: z.string(), type: z.string().optional()}).optional(), impacted_services: z.array(z.object({service: z.object({id: z.string().optional(), type: z.string().optional()}).optional(), impact: z.object({id: z.string().optional(), type: z.string().optional()}).optional()})).optional(), update_frequency_ms: z.number().int().nullable().optional(), notify_subscribers: z.boolean().optional(), reported_at: z.string().nullable().optional(), type: z.string().optional()}); export const getApiStatusPagesIdPostsPostIdPostUpdatesResponse = z.object({offset: z.number().int().optional(), limit: z.number().int().optional(), more: z.boolean().optional(), total: z.number().int().nullable().optional(), post_updates: z.array(statusPagePostUpdate).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 }; /** * List Status Page Post Updates * * GET /status_pages/{id}/posts/{post_id}/post_updates */ export const getApiStatusPagesIdPostsPostIdPostUpdates = async (args: GetApiStatusPagesIdPostsPostIdPostUpdatesArgs, options?: GetApiStatusPagesIdPostsPostIdPostUpdatesOptions) => { const {baseUrl = "https://api.pagerduty.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args.reviewed_status != null) query.append("reviewed_status", String(args.reviewed_status)) if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/status_pages/${encodeURIComponent(String(args.id))}/posts/${encodeURIComponent(String(args.post_id))}/post_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(getApiStatusPagesIdPostsPostIdPostUpdatesResponse, await res.json()) };