import {z} from 'zod' export type GetApiV3StatusPagesArgs = {'x-checkly-account'?: string | undefined, limit?: number | undefined, nextId?: string | undefined}; export type GetApiV3StatusPagesOptions = {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 publicStatusPagesV3Entries = z.array(publicStatusPageV3); export const publicStatusPagesV3PaginatedResponse = z.object({length: z.number().int(), entries: publicStatusPagesV3Entries, nextId: 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 }; /** * List v3 status pages. * * GET /v3/status-pages */ export const getApiV3StatusPages = async (args: GetApiV3StatusPagesArgs, options?: GetApiV3StatusPagesOptions) => { 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 (args.limit != null) query.append("limit", String(args.limit)) if (args.nextId != null) query.append("nextId", String(args.nextId)) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(publicStatusPagesV3PaginatedResponse, await res.json()) };