import {z} from 'zod' export type StatusPageV3ThemeColorsGroup = {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 StatusPageV3ThemeColors = {light: StatusPageV3ThemeColorsGroup, dark: StatusPageV3ThemeColorsGroup} | null; export type DefaultTheme = 'LIGHT' | 'DARK' | 'AUTO'; export type PublicStatusPageV3Mutation = {name: string, description?: (string | null) | undefined, url: string, customDomain?: (string | null) | undefined, themeColors?: StatusPageV3ThemeColors | undefined, logo?: (string | null) | undefined, logoDark?: (string | null) | undefined, redirectTo?: (string | null) | undefined, favicon?: (string | null) | undefined, defaultTheme?: DefaultTheme | undefined, privacyPolicyLink?: (string | null) | undefined, termsOfServiceLink?: (string | null) | undefined, supportLink?: (string | null) | undefined, footerText?: (string | null) | undefined, googleAnalyticsTag?: (string | null) | undefined, allowIndexing?: boolean | undefined, isPrivate?: boolean | undefined}; export type CreateApiV3StatusPagesArgs = {'x-checkly-account'?: string | undefined, body: PublicStatusPageV3Mutation}; export type CreateApiV3StatusPagesOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const statusPageV3ThemeColorsGroup = 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 statusPageV3ThemeColors = z.object({light: statusPageV3ThemeColorsGroup, dark: statusPageV3ThemeColorsGroup}).nullable(); export const defaultTheme = z.enum(["LIGHT", "DARK", "AUTO"]); export const publicStatusPageV3 = z.object({name: z.string(), description: z.string().max(500).nullable().optional(), url: z.string(), customDomain: z.string().nullable().optional(), themeColors: statusPageV3ThemeColors.optional(), logo: z.string().nullable().optional(), logoDark: z.string().nullable().optional(), redirectTo: z.string().nullable().optional(), favicon: z.string().nullable().optional(), defaultTheme: defaultTheme.optional(), privacyPolicyLink: z.string().max(255).nullable().optional(), termsOfServiceLink: z.string().max(255).nullable().optional(), supportLink: z.string().max(255).nullable().optional(), footerText: z.string().max(1000).nullable().optional(), googleAnalyticsTag: z.string().max(255).nullable().optional(), allowIndexing: z.boolean().optional(), isPrivate: z.boolean().optional(), id: z.string(), accountId: z.string(), version: z.literal(3), 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 }; /** * Create a new v3 status page. * * POST /v3/status-pages */ export const createApiV3StatusPages = async (args: CreateApiV3StatusPagesArgs, options?: CreateApiV3StatusPagesOptions) => { 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${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(publicStatusPageV3, await res.json()) };