import {z} from 'zod' export type CheckGroupTagList = Array; export type Model9 = 'us-east-1' | 'us-east-2' | 'us-west-1' | 'us-west-2' | 'ca-central-1' | 'sa-east-1' | 'eu-west-1' | 'eu-central-1' | 'eu-west-2' | 'eu-west-3' | 'eu-north-1' | 'eu-south-1' | 'me-south-1' | 'ap-southeast-1' | 'ap-northeast-1' | 'ap-east-1' | 'ap-southeast-2' | 'ap-southeast-3' | 'ap-northeast-2' | 'ap-northeast-3' | 'ap-south-1' | 'af-south-1'; export type Model10 = Array; export type KeyValue = {key: string, value: string, locked?: boolean | undefined}; export type HeaderList = Array; export type QueryParameterList = Array; export type AssertionSource = 'STATUS_CODE' | 'JSON_BODY' | 'HEADERS' | 'TEXT_BODY' | 'RESPONSE_TIME'; export type AssertionComparison = 'EQUALS' | 'NOT_EQUALS' | 'HAS_KEY' | 'NOT_HAS_KEY' | 'HAS_VALUE' | 'NOT_HAS_VALUE' | 'IS_EMPTY' | 'NOT_EMPTY' | 'GREATER_THAN' | 'LESS_THAN' | 'CONTAINS' | 'NOT_CONTAINS' | 'IS_NULL' | 'NOT_NULL'; export type Assertion = {source?: AssertionSource | undefined, comparison?: AssertionComparison | undefined, property?: string | undefined, target?: string | undefined, regex?: (string | null) | undefined}; export type AssertionList = Array; export type BasicAuth = {username: string, password: string} | null; export type CheckGroupCreateAPICheckDefaults = {url?: (string | null) | undefined, headers?: HeaderList | undefined, queryParameters?: QueryParameterList | undefined, assertions?: AssertionList | undefined, basicAuth?: BasicAuth | undefined}; export type Model11 = '2026.04' | '2025.04' | '2024.09' | '2024.02' | '2023.09' | '2023.02' | '2022.10' | null; export type EnvironmentVariableUpdate = {key?: string | undefined, value: string, locked?: boolean | undefined, secret?: boolean | undefined}; export type EnvironmentVariables = Array | null; export type EscalationType = 'RUN_BASED' | 'TIME_BASED'; export type AlertSettingsReminders = {amount?: number | undefined, interval?: number | undefined}; export type AlertSettingsSSLCertificates = {enabled?: boolean | undefined, alertThreshold?: number | undefined}; export type AlertSettingsRunBasedEscalation = {failedRunThreshold?: number | undefined}; export type AlertSettingsTimeBasedEscalation = {minutesFailingThreshold?: number | undefined}; export type ParallelRunFailureThreshold = {enabled?: boolean | undefined, percentage?: number | undefined}; export type AlertSettings = {escalationType?: EscalationType | undefined, reminders?: AlertSettingsReminders | undefined, sslCertificates?: AlertSettingsSSLCertificates | undefined, runBasedEscalation?: AlertSettingsRunBasedEscalation | undefined, timeBasedEscalation?: AlertSettingsTimeBasedEscalation | undefined, parallelRunFailureThreshold?: ParallelRunFailureThreshold | undefined}; export type Model8 = {alertChannelId: number, activated: boolean}; export type Model12 = Array; export type Model13 = Array | null; export type RetryStrategyType = 'FIXED' | 'LINEAR' | 'EXPONENTIAL' | 'SINGLE_RETRY'; export type RetryOnlyOnValue = 'NETWORK_ERROR'; export type RetryOnlyOn = Array; export type RetryStrategy = {type: RetryStrategyType, baseBackoffSeconds?: number | undefined, sameRegion?: boolean | undefined, maxRetries?: number | undefined, maxDurationSeconds?: number | undefined, onlyOn?: RetryOnlyOn | undefined} | null; export type FallbackRetryStrategy = 'FALLBACK'; export type CheckGroupCreate = {name: string, activated?: boolean | undefined, muted?: boolean | undefined, tags?: CheckGroupTagList | undefined, locations?: Model10 | undefined, concurrency?: number | undefined, apiCheckDefaults?: CheckGroupCreateAPICheckDefaults | undefined, browserCheckDefaults?: string | undefined, runtimeId?: Model11 | undefined, environmentVariables?: EnvironmentVariables | undefined, doubleCheck?: boolean | undefined, useGlobalAlertSettings?: boolean | undefined, alertSettings?: AlertSettings | undefined, alertChannelSubscriptions?: Model12 | undefined, setupSnippetId?: (number | null) | undefined, tearDownSnippetId?: (number | null) | undefined, localSetupScript?: (string | null) | undefined, localTearDownScript?: (string | null) | undefined, privateLocations?: Model13 | undefined, runParallel?: boolean | undefined, retryStrategy?: (RetryStrategy | FallbackRetryStrategy) | undefined}; export type CreateApiV1CheckGroupsArgs = {'x-checkly-account'?: string | undefined, autoAssignAlerts?: boolean | undefined, body: CheckGroupCreate}; export type CreateApiV1CheckGroupsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const checkGroupTagList = z.array(z.string()); export const model14 = z.enum(["us-east-1", "us-east-2", "us-west-1", "us-west-2", "ca-central-1", "sa-east-1", "eu-west-1", "eu-central-1", "eu-west-2", "eu-west-3", "eu-north-1", "eu-south-1", "me-south-1", "ap-southeast-1", "ap-northeast-1", "ap-east-1", "ap-southeast-2", "ap-southeast-3", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "af-south-1"]); export const model15 = z.array(model14); export const keyValue = z.object({key: z.string(), value: z.string(), locked: z.boolean().optional()}); export const headerList = z.array(keyValue); export const queryParameterList = z.array(keyValue); export const assertionSource = z.enum(["STATUS_CODE", "JSON_BODY", "HEADERS", "TEXT_BODY", "RESPONSE_TIME"]); export const assertionComparison = z.enum(["EQUALS", "NOT_EQUALS", "HAS_KEY", "NOT_HAS_KEY", "HAS_VALUE", "NOT_HAS_VALUE", "IS_EMPTY", "NOT_EMPTY", "GREATER_THAN", "LESS_THAN", "CONTAINS", "NOT_CONTAINS", "IS_NULL", "NOT_NULL"]); export const assertion = z.object({source: assertionSource.optional(), comparison: assertionComparison.optional(), property: z.string().optional(), target: z.string().optional(), regex: z.string().nullable().optional()}); export const assertionList = z.array(assertion); export const basicAuth = z.object({username: z.string(), password: z.string()}).nullable(); export const checkGroupAPICheckDefaults = z.object({url: z.string().nullable().optional(), headers: headerList.optional(), queryParameters: queryParameterList.optional(), assertions: assertionList.optional(), basicAuth: basicAuth.optional()}); export const environmentVariableGet = z.object({key: z.string(), value: z.string(), locked: z.boolean().optional(), secret: z.boolean().optional()}); export const environmentVariableList = z.array(environmentVariableGet).nullable(); export const escalationType = z.enum(["RUN_BASED", "TIME_BASED"]); export const alertSettingsReminders = z.object({amount: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(100000)]).optional(), interval: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(10), z.literal(15), z.literal(30)]).optional()}); export const alertSettingsSSLCertificates = z.object({enabled: z.boolean().optional(), alertThreshold: z.number().int().optional()}); export const alertSettingsRunBasedEscalation = z.object({failedRunThreshold: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5)]).optional()}); export const alertSettingsTimeBasedEscalation = z.object({minutesFailingThreshold: z.union([z.literal(5), z.literal(10), z.literal(15), z.literal(30)]).optional()}); export const parallelRunFailureThreshold = z.object({enabled: z.boolean().optional(), percentage: z.union([z.literal(10), z.literal(20), z.literal(30), z.literal(40), z.literal(50), z.literal(60), z.literal(70), z.literal(80), z.literal(90), z.literal(100)]).optional()}); export const checkGroupAlertSettings = z.object({escalationType: escalationType.optional(), reminders: alertSettingsReminders.optional(), sslCertificates: alertSettingsSSLCertificates.optional(), runBasedEscalation: alertSettingsRunBasedEscalation.optional(), timeBasedEscalation: alertSettingsTimeBasedEscalation.optional(), parallelRunFailureThreshold: parallelRunFailureThreshold.optional()}); export const model8 = z.object({alertChannelId: z.number(), activated: z.boolean()}); export const alertChannelSubscriptionCreateList = z.array(model8); export const runtimeId = z.enum(["2026.04", "2025.04", "2024.09", "2024.02", "2023.09", "2023.02", "2022.10"]).nullable(); export const privateLocations = z.array(z.string()).nullable(); export const retryStrategyType = z.enum(["FIXED", "LINEAR", "EXPONENTIAL", "SINGLE_RETRY"]); export const retryOnlyOnValue = z.literal("NETWORK_ERROR"); export const retryOnlyOn = z.array(retryOnlyOnValue); export const retryStrategy = z.object({type: retryStrategyType, baseBackoffSeconds: z.number().optional(), sameRegion: z.boolean().optional(), maxRetries: z.number().gte(1).lte(10).optional(), maxDurationSeconds: z.number().gte(0).lte(600).optional(), onlyOn: retryOnlyOn.optional()}).nullable(); export const fallbackRetryStrategy = z.literal("FALLBACK"); export const checkGroup = z.object({id: z.number().optional(), name: z.string(), activated: z.boolean(), muted: z.boolean().optional(), tags: checkGroupTagList.optional(), locations: model15.optional(), concurrency: z.number().gte(1), apiCheckDefaults: checkGroupAPICheckDefaults, browserCheckDefaults: z.string().optional(), environmentVariables: environmentVariableList.optional(), doubleCheck: z.boolean().optional(), useGlobalAlertSettings: z.boolean().nullable().optional(), alertSettings: checkGroupAlertSettings.optional(), alertChannelSubscriptions: alertChannelSubscriptionCreateList.optional(), setupSnippetId: z.number().nullable().optional(), tearDownSnippetId: z.number().nullable().optional(), localSetupScript: z.string().nullable().optional(), localTearDownScript: z.string().nullable().optional(), runtimeId: runtimeId.optional(), privateLocations: privateLocations.optional(), retryStrategy: z.union([retryStrategy, fallbackRetryStrategy]).optional(), created_at: z.string().optional(), updated_at: z.string().nullable().optional(), runParallel: z.boolean().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 check group * * POST /v1/check-groups */ export const createApiV1CheckGroups = async (args: CreateApiV1CheckGroupsArgs, options?: CreateApiV1CheckGroupsOptions) => { 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 (args.autoAssignAlerts != null) query.append("autoAssignAlerts", String(args.autoAssignAlerts)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/check-groups${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(checkGroup, await res.json()) };