import {z} from 'zod' export type StatusPageThemeColors = {bodyBackgroundColor: string, headerBackgroundColor: string, headerFontColor: string, titleFontColor: string, bodyFontColor: string, bodyFontColorMuted: string, navigationFontColor: string, linkFontColor: string, cardBackgroundColor: string, borderColor: string, primaryButtonBackgroundColor: string, primaryButtonFontColor: string}; export type StatusPageV2ThemeColors = {light: StatusPageThemeColors, dark: StatusPageThemeColors} | null; export type DefaultTheme = 'LIGHT' | 'DARK' | 'AUTO'; export type StatusPageV2CardServiceRef = {id?: string | undefined}; export type StatusPageV2CardServiceRefs = Array; export type StatusPageV2CardUpdate = {id?: string | undefined, statusPageId?: string | undefined, name: string, services?: StatusPageV2CardServiceRefs | undefined}; export type StatusPageV2CardUpdates = Array; export type StatusPageV2PublicApiUpdate = {name: string, description?: (string | null) | undefined, url: string, customDomain?: (string | null) | undefined, themeColors?: StatusPageV2ThemeColors | undefined, logo?: (string | null) | undefined, logoDark?: (string | null) | undefined, redirectTo?: (string | null) | undefined, favicon?: (string | null) | undefined, defaultTheme?: DefaultTheme | undefined, version?: (number | null) | undefined, cards: StatusPageV2CardUpdates}; export type CreateApiV1StatusPagesArgs = {'x-checkly-account'?: string | undefined, body: StatusPageV2PublicApiUpdate}; export type CreateApiV1StatusPagesOptions = {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 statusPageV2WithId = 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()}); 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 }; /** * Create a new status page. * * POST /v1/status-pages */ export const createApiV1StatusPages = async (args: CreateApiV1StatusPagesArgs, options?: CreateApiV1StatusPagesOptions) => { 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(/\/+$/, '')}/v1/status-pages${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(statusPageV2WithId, await res.json()) };