import {z} from 'zod' export type StatusPagePostPutRequest = {type: 'status_page_post', title: string, post_type: 'incident' | 'maintenance', starts_at: string | null, ends_at: string | null, status_page: {id: string, type?: string | undefined}}; export type UpdateApiStatusPagesIdPostsPostIdArgs = {Accept: string, id: string, post_id: string, body: {post: StatusPagePostPutRequest}}; export type UpdateApiStatusPagesIdPostsPostIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const statusPagePost = z.object({id: z.string().optional(), self: z.string().optional(), type: z.string().optional(), post_type: z.enum(["incident", "maintenance"]).optional(), status_page: z.object({id: z.string(), type: z.string().optional()}).optional(), linked_resource: z.object({id: z.string(), type: z.string().optional()}).optional(), postmortem: z.object({id: z.string(), type: z.string().optional()}).optional(), title: z.string().optional(), starts_at: z.string().nullable().optional(), ends_at: z.string().nullable().optional(), updates: z.array(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()})).optional()}); export const updateApiStatusPagesIdPostsPostIdResponse = z.object({post: statusPagePost.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 }; /** * Update a Status Page Post * * PUT /status_pages/{id}/posts/{post_id} */ export const updateApiStatusPagesIdPostsPostId = async (args: UpdateApiStatusPagesIdPostsPostIdArgs, options?: UpdateApiStatusPagesIdPostsPostIdOptions) => { const {baseUrl = "https://api.pagerduty.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/status_pages/${encodeURIComponent(String(args.id))}/posts/${encodeURIComponent(String(args.post_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiStatusPagesIdPostsPostIdResponse, await res.json()) };