import {z} from 'zod' export type StatusPageFeatures = {home_link?: (string | null) | undefined, up_caption?: (string | null) | undefined, down_caption?: (string | null) | undefined, mixed_caption?: (string | null) | undefined, custom_css?: (string | null) | undefined}; export type StatusPageSiteInput = {site_id: string, display_name?: (string | null) | undefined, description?: (string | null) | undefined}; export type StatusPageCheckInInput = {check_in_id: string, display_name?: (string | null) | undefined, description?: (string | null) | undefined}; export type StatusPageInput = {name?: string | undefined, domain?: (string | null) | undefined, incidents_enabled?: (boolean | null) | undefined, search_engine_indexing_disabled?: (boolean | null) | undefined, message_enabled?: (boolean | null) | undefined, message_title?: (string | null) | undefined, message_body?: (string | null) | undefined, google_analytics_id?: (string | null) | undefined, hide_branding?: (boolean | null) | undefined, password_protected?: (boolean | null) | undefined, username?: (string | null) | undefined, password?: (string | null) | undefined, features?: (StatusPageFeatures | null) | undefined, sites?: (Array | null) | undefined, check_ins?: (Array | null) | undefined}; export type PatchApiStatusPagesStatusPageIdArgs = {status_page_id: string, body: StatusPageInput}; export type PatchApiStatusPagesStatusPageIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const statusPageFeatures = z.object({home_link: z.string().nullable().optional(), up_caption: z.string().nullable().optional(), down_caption: z.string().nullable().optional(), mixed_caption: z.string().nullable().optional(), custom_css: z.string().nullable().optional()}); export const statusPageSite = z.object({site_id: z.string(), display_name: z.string().nullable(), description: z.string().nullable()}); export const statusPageCheckIn = z.object({check_in_id: z.string(), display_name: z.string().nullable(), description: z.string().nullable()}); export const webLinks = z.object({web: z.string()}); export const statusPage = z.object({id: z.string(), account_id: z.string(), name: z.string(), domain: z.string().nullable(), features: statusPageFeatures, hide_branding: z.boolean(), password_protected: z.boolean(), username: z.string().nullable(), incidents_enabled: z.boolean(), search_engine_indexing_disabled: z.boolean(), message_enabled: z.boolean(), message_title: z.string().nullable(), message_body: z.string().nullable(), google_analytics_id: z.string().nullable(), url: z.string(), created_at: z.string(), domain_verified_at: z.string().nullable(), sites: z.array(statusPageSite), check_ins: z.array(statusPageCheckIn), links: webLinks}); export const responseMeta = z.object({request_id: z.string().optional()}); export const patchApiStatusPagesStatusPageIdResponse = z.object({data: statusPage, meta: responseMeta.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 * * PATCH /status_pages/{status_page_id} */ export const patchApiStatusPagesStatusPageId = async (args: PatchApiStatusPagesStatusPageIdArgs, options?: PatchApiStatusPagesStatusPageIdOptions) => { const {baseUrl = "https://app.honeybadger.io/v3", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/status_pages/${encodeURIComponent(String(args.status_page_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiStatusPagesStatusPageIdResponse, await res.json()) };