import {z} from 'zod' export type GetApiV1StatusPagesStatusPageIdArgs = {'x-checkly-account'?: string | undefined, statusPageId: string}; export type GetApiV1StatusPagesStatusPageIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const statusPageThemeColors = z.object({bodyBackgroundColor: z.string(), headerBackgroundColor: z.string(), headerFontColor: z.string(), titleFontColor: z.string(), bodyFontColor: z.string(), bodyFontColorMuted: z.string(), navigationFontColor: z.string(), linkFontColor: z.string(), cardBackgroundColor: z.string(), borderColor: z.string(), primaryButtonBackgroundColor: z.string(), primaryButtonFontColor: z.string()}); export const statusPageV2ThemeColors = z.object({light: statusPageThemeColors, dark: statusPageThemeColors}).nullable(); export const defaultTheme = z.enum(["LIGHT", "DARK", "AUTO"]); export const statusPageV2Service = z.object({name: z.string(), id: z.string(), accountId: z.string(), created_at: z.string(), updated_at: z.string().nullable().optional()}); export const statusPageV2CardServices = z.array(statusPageV2Service); export const statusPageV2Card = z.object({id: z.string(), name: z.string(), services: statusPageV2CardServices.optional(), created_at: z.string(), updated_at: z.string().nullable().optional()}); export const statusPageV2Cards = z.array(statusPageV2Card); export const bindingProjectV1 = z.object({id: z.string(), logicalId: z.string(), name: z.string()}); export const projectBindingDetailsV1 = z.object({logicalId: z.string(), pending: z.boolean(), sourceFile: z.string().nullable().optional()}); export const projectBindingOwnerV1 = z.object({project: bindingProjectV1, binding: projectBindingDetailsV1}).nullable(); export const projectBindingV1 = z.object({project: bindingProjectV1, binding: projectBindingDetailsV1}); export const projectBindingReferencesV1 = z.array(projectBindingV1); export const projectBindingsV1 = z.object({owner: projectBindingOwnerV1, references: projectBindingReferencesV1}); export const statusPageV2WithIdRead = z.object({name: z.string(), description: z.string().max(500).nullable().optional(), url: z.string(), customDomain: z.string().nullable().optional(), themeColors: statusPageV2ThemeColors.optional(), logo: z.string().nullable().optional(), logoDark: z.string().nullable().optional(), redirectTo: z.string().nullable().optional(), favicon: z.string().nullable().optional(), defaultTheme: defaultTheme.optional(), cards: statusPageV2Cards.optional(), version: z.number().nullable().optional(), id: z.string(), whiteLabel: z.boolean().optional(), isPrivate: z.boolean().optional(), projectBindings: projectBindingsV1.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 }; /** * Retrieve a single status page by id. * * GET /v1/status-pages/{statusPageId} */ export const getApiV1StatusPagesStatusPageId = async (args: GetApiV1StatusPagesStatusPageIdArgs, options?: GetApiV1StatusPagesStatusPageIdOptions) => { const {baseUrl = "https://api.checklyhq.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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(/\/+$/, '')}/v1/status-pages/${encodeURIComponent(String(args.statusPageId))}${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(statusPageV2WithIdRead, await res.json()) };