import {z} from 'zod' export type Model91 = 'SERVICE' | 'GROUP'; export type PublicStatusPageV3GroupComponentConfiguration = {expandedByDefault?: boolean | undefined, showHistoricalData?: boolean | undefined}; export type PublicStatusPageV3ServiceComponentConfiguration = {showHistoricalData?: boolean | undefined}; export type PublicStatusPageV3ComponentMutation = {type?: Model91 | undefined, name: string, description?: (string | null) | undefined, displayOrder: number, hidden?: boolean | undefined, configuration?: (PublicStatusPageV3GroupComponentConfiguration | PublicStatusPageV3ServiceComponentConfiguration) | undefined, parentId?: (string | null) | undefined}; export type UpdateApiV3StatusPagesStatusPageIdComponentsComponentIdArgs = {'x-checkly-account'?: string | undefined, statusPageId: string, componentId: string, body: PublicStatusPageV3ComponentMutation}; export type UpdateApiV3StatusPagesStatusPageIdComponentsComponentIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const model90 = z.enum(["SERVICE", "GROUP"]); export const publicStatusPageV3GroupComponentConfiguration = z.object({expandedByDefault: z.boolean().optional(), showHistoricalData: z.boolean().optional()}); export const publicStatusPageV3ServiceComponentConfiguration = z.object({showHistoricalData: z.boolean().optional()}); export const publicStatusPageV3Component = z.object({type: model90.optional(), name: z.string().min(1).max(255), description: z.string().nullable().optional(), displayOrder: z.number().int(), hidden: z.boolean().optional(), parentId: z.string().nullable().optional(), id: z.string(), statusPageId: z.string(), configuration: z.union([publicStatusPageV3GroupComponentConfiguration, publicStatusPageV3ServiceComponentConfiguration]), created_at: z.string(), updated_at: z.string().nullable().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 component of a v3 status page. * * PUT /v3/status-pages/{statusPageId}/components/{componentId} */ export const updateApiV3StatusPagesStatusPageIdComponentsComponentId = async (args: UpdateApiV3StatusPagesStatusPageIdComponentsComponentIdArgs, options?: UpdateApiV3StatusPagesStatusPageIdComponentsComponentIdOptions) => { const {baseUrl = "https://api.checklyhq.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-checkly-account'] != null) headers.set("x-checkly-account", String(args['x-checkly-account'])) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/status-pages/${encodeURIComponent(String(args.statusPageId))}/components/${encodeURIComponent(String(args.componentId))}${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(publicStatusPageV3Component, await res.json()) };