import {z} from 'zod' export type ChecksV1AlertSettingsRunBasedEscalation = {failedRunThreshold?: (1 | 2 | 3 | 4 | 5) | undefined}; export type ChecksV1AlertSettingsTimeBasedEscalation = {minutesFailingThreshold?: (5 | 10 | 15 | 30) | undefined}; export type ChecksV1AlertSettingsCreatePatch = {escalationType?: ('RUN_BASED' | 'TIME_BASED') | undefined, reminders?: ({amount?: (0 | 1 | 2 | 3 | 4 | 5 | 100000) | undefined, interval?: (1 | 2 | 3 | 4 | 5 | 10 | 15 | 30) | undefined}) | undefined, sslCertificates?: ({enabled?: boolean | undefined, alertThreshold?: number | undefined}) | undefined, runBasedEscalation?: ChecksV1AlertSettingsRunBasedEscalation | undefined, timeBasedEscalation?: ChecksV1AlertSettingsTimeBasedEscalation | undefined, parallelRunFailureThreshold?: ({enabled?: boolean | undefined, percentage?: (10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 100) | undefined}) | undefined}; export type ChecksV1AlertChannelSubscription = {alertChannelId: number, activated: boolean}; export type ChecksV1RetryStrategyPatch = {type: 'FIXED' | 'LINEAR' | 'EXPONENTIAL' | 'SINGLE_RETRY', baseBackoffSeconds?: number | undefined, sameRegion?: boolean | undefined, maxRetries?: number | undefined, maxDurationSeconds?: number | undefined, onlyOn?: Array<'NETWORK_ERROR'> | undefined} | null; export type ChecksV1TriggerIncident = {serviceId: string, severity: 'CRITICAL' | 'MAJOR' | 'MEDIUM' | 'MINOR', name: string, description: string, notifySubscribers: boolean} | null; export type ChecksV1CheckIntent = {goal: string, requiredOutcomes?: Array | undefined, mustPreserve?: Array | undefined} | null; export type ChecksV1EnvironmentVariablePatch = {key: string, value: string | null, locked?: boolean | undefined, secret?: boolean | undefined}; export type ChecksV1SslSecurityBaselinePatch = {enabled?: boolean | undefined, minTLSVersion?: ({value?: ('TLS1.2' | 'TLS1.3') | undefined, severity?: ('fail' | 'degrade' | 'ignore') | undefined}) | undefined, minKeySizeBits?: ({value?: number | undefined, severity?: ('fail' | 'degrade' | 'ignore') | undefined}) | undefined, weakSignatureAlgorithm?: ({severity?: ('fail' | 'degrade' | 'ignore') | undefined}) | undefined, weakCipherSuite?: ({severity?: ('fail' | 'degrade' | 'ignore') | undefined}) | undefined, knownBadCA?: ({severity?: ('fail' | 'degrade' | 'ignore') | undefined}) | undefined, recommendedTLSVersion?: ({value?: ('TLS1.2' | 'TLS1.3') | undefined, severity?: ('fail' | 'degrade' | 'ignore') | undefined}) | undefined, recommendedKeySizeBits?: ({value?: number | undefined, severity?: ('fail' | 'degrade' | 'ignore') | undefined}) | undefined, ocspMustStapleRespected?: ({severity?: ('fail' | 'degrade' | 'ignore') | undefined}) | undefined, sctPresent?: ({severity?: ('fail' | 'degrade' | 'ignore') | undefined}) | undefined}; export type ChecksV1SslConfigPatch = {hostname: string, port?: number | undefined, serverName?: (string | '' | unknown) | undefined, ipFamily?: ('IPv4' | 'IPv6') | undefined, skipChainValidation?: boolean | undefined, handshakeTimeoutMs?: number | undefined, alertDaysBeforeExpiry?: number | undefined, securityBaseline?: ChecksV1SslSecurityBaselinePatch | undefined, clientCertificateMode?: ('auto' | 'explicit') | undefined}; export type ChecksV1SslAssertionPatch = {source: 'CERTIFICATE' | 'CONNECTION' | 'RESPONSE_TIME' | 'JSON_RESPONSE' | 'TEXT_RESPONSE', property?: string | undefined, comparison: string, target?: string | undefined, regex?: (string | null) | undefined}; export type ChecksV1SslRequestPatch = {sslConfig: ChecksV1SslConfigPatch, sslClientCertificateId?: (string | null) | undefined, assertions?: Array | undefined}; export type ChecksV1SslMonitorUpdate = {name?: string | undefined, activated?: boolean | undefined, muted?: boolean | undefined, doubleCheck?: boolean | undefined, shouldFail?: boolean | undefined, locations?: (Array<'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'> | null) | undefined, tags?: Array | undefined, alertSettings?: ChecksV1AlertSettingsCreatePatch | undefined, useGlobalAlertSettings?: boolean | undefined, groupId?: (number | null) | undefined, groupOrder?: (number | null) | undefined, runtimeId?: ('2026.04' | '2025.04' | '2024.09' | '2024.02' | '2023.09' | '2023.02' | '2022.10' | 'null' | null) | undefined, alertChannelSubscriptions?: Array | undefined, retryStrategy?: ChecksV1RetryStrategyPatch | undefined, triggerIncident?: ChecksV1TriggerIncident | undefined, runParallel?: boolean | undefined, description?: (string | null) | undefined, intent?: ChecksV1CheckIntent | undefined, aiAutoRepairEnabled?: (boolean | null) | undefined, checkType?: 'SSL' | undefined, frequency?: (0 | 1 | 2 | 5 | 10 | 15 | 30 | 60 | 120 | 180 | 360 | 720 | 1440) | undefined, frequencyOffset?: number | undefined, heartbeat?: ({[key: string]: unknown} | null) | undefined, script?: (string | null) | undefined, scriptPath?: (string | null) | undefined, sslCheckDomain?: (string | null) | undefined, environmentVariables?: (Array | null) | undefined, setupSnippetId?: (number | null) | undefined, tearDownSnippetId?: (number | null) | undefined, localSetupScript?: (string | null) | undefined, localTearDownScript?: (string | null) | undefined, request?: ChecksV1SslRequestPatch | undefined, degradedResponseTime?: number | undefined, maxResponseTime?: number | undefined, privateLocations?: (Array | null) | undefined}; export type UpdateApiV1ChecksSslIdArgs = {id: string, autoAssignAlerts?: boolean | undefined, 'x-checkly-account'?: string | undefined, body: ChecksV1SslMonitorUpdate}; export type UpdateApiV1ChecksSslIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const checksV1AlertSettingsRunBasedEscalation = z.object({failedRunThreshold: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5)]).optional()}); export const checksV1AlertSettingsTimeBasedEscalation = z.object({minutesFailingThreshold: z.union([z.literal(5), z.literal(10), z.literal(15), z.literal(30)]).optional()}); export const checksV1AlertSettings = z.object({escalationType: z.enum(["RUN_BASED", "TIME_BASED"]).optional(), reminders: 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()}).optional(), sslCertificates: z.object({enabled: z.boolean().optional(), alertThreshold: z.number().int().optional()}).optional(), runBasedEscalation: checksV1AlertSettingsRunBasedEscalation.optional(), timeBasedEscalation: checksV1AlertSettingsTimeBasedEscalation.optional(), 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()}).optional()}).nullable(); export const checksV1AlertChannelSubscription = z.object({alertChannelId: z.number(), activated: z.boolean()}); export const checksV1RetryStrategy = z.object({type: z.enum(["FIXED", "LINEAR", "EXPONENTIAL", "SINGLE_RETRY"]), 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: z.array(z.literal("NETWORK_ERROR")).optional()}).nullable(); export const checksV1TriggerIncident = z.object({serviceId: z.string().min(1), severity: z.enum(["CRITICAL", "MAJOR", "MEDIUM", "MINOR"]), name: z.string(), description: z.string(), notifySubscribers: z.boolean()}).nullable(); export const checksV1AlertEmail = z.object({address: z.string().min(1).optional()}); export const checksV1KeyValue = z.object({key: z.string().min(1), value: z.string(), locked: z.boolean().optional()}); export const checksV1AlertWebhook = z.object({name: z.string().min(1).optional(), url: z.string().min(1).optional(), method: z.string().min(1).nullable().optional(), headers: z.array(checksV1KeyValue).optional(), queryParameters: z.array(checksV1KeyValue).optional()}); export const checksV1AlertSlack = z.object({url: z.string().min(1).optional()}); export const checksV1AlertSms = z.object({number: z.string().min(1).optional(), name: z.string()}); export const checksV1AlertChannels = z.object({email: z.array(checksV1AlertEmail).optional(), webhook: z.array(checksV1AlertWebhook).optional(), slack: z.array(checksV1AlertSlack).optional(), sms: z.array(checksV1AlertSms).optional()}).nullable(); export const checksV1SslSecurityBaselineRead = z.object({enabled: z.boolean().optional(), minTLSVersion: z.object({value: z.enum(["TLS1.2", "TLS1.3"]).optional(), severity: z.enum(["fail", "degrade", "ignore"]).optional()}).optional(), minKeySizeBits: z.object({value: z.number().int().gte(1024).lte(16384).optional(), severity: z.enum(["fail", "degrade", "ignore"]).optional()}).optional(), weakSignatureAlgorithm: z.object({severity: z.enum(["fail", "degrade", "ignore"]).optional()}).optional(), weakCipherSuite: z.object({severity: z.enum(["fail", "degrade", "ignore"]).optional()}).optional(), knownBadCA: z.object({severity: z.enum(["fail", "degrade", "ignore"]).optional()}).optional(), recommendedTLSVersion: z.object({value: z.enum(["TLS1.2", "TLS1.3"]).optional(), severity: z.enum(["fail", "degrade", "ignore"]).optional()}).optional(), recommendedKeySizeBits: z.object({value: z.number().int().gte(1024).lte(16384).optional(), severity: z.enum(["fail", "degrade", "ignore"]).optional()}).optional(), ocspMustStapleRespected: z.object({severity: z.enum(["fail", "degrade", "ignore"]).optional()}).optional(), sctPresent: z.object({severity: z.enum(["fail", "degrade", "ignore"]).optional()}).optional()}); export const checksV1SslConfigRead = z.object({hostname: z.string().min(1).max(2048), port: z.number().int().gte(1).lte(65535).optional(), serverName: z.union([z.string().min(1).max(2048), z.literal(""), z.unknown()]).optional(), ipFamily: z.enum(["IPv4", "IPv6"]).optional(), skipChainValidation: z.boolean().optional(), handshakeTimeoutMs: z.number().int().gte(1000).lte(30000).optional(), alertDaysBeforeExpiry: z.number().int().gte(1).lte(365).optional(), securityBaseline: checksV1SslSecurityBaselineRead.optional(), clientCertificateMode: z.enum(["auto", "explicit"]).optional()}); export const checksV1SslAssertionPatch = z.object({source: z.enum(["CERTIFICATE", "CONNECTION", "RESPONSE_TIME", "JSON_RESPONSE", "TEXT_RESPONSE"]), property: z.string().optional(), comparison: z.string(), target: z.string().optional(), regex: z.string().nullable().optional()}); export const checksV1SslRequestRead = z.object({sslConfig: checksV1SslConfigRead, sslClientCertificateId: z.string().min(1).nullable().optional(), assertions: z.array(checksV1SslAssertionPatch).optional()}); export const checksV1SslMonitorMutationResponse = z.object({name: z.string().min(1), activated: z.boolean().optional(), muted: z.boolean().optional(), doubleCheck: z.boolean().optional(), shouldFail: z.boolean().optional(), locations: z.array(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"])).nullable().optional(), tags: z.array(z.string().min(1)).optional(), alertSettings: checksV1AlertSettings.optional(), useGlobalAlertSettings: z.boolean().optional(), groupId: z.number().nullable().optional(), groupOrder: z.number().gte(0).nullable().optional(), runtimeId: z.enum(["2026.04", "2025.04", "2024.09", "2024.02", "2023.09", "2023.02", "2022.10", "null"]).nullable().optional(), alertChannelSubscriptions: z.array(checksV1AlertChannelSubscription).optional(), retryStrategy: checksV1RetryStrategy.optional(), triggerIncident: checksV1TriggerIncident.optional(), runParallel: z.boolean().optional(), description: z.string().max(500).nullable().optional(), intent: z.object({goal: z.string().min(1).max(2000), requiredOutcomes: z.array(z.string().min(1).max(1000)).optional(), mustPreserve: z.array(z.string().min(1).max(1000)).optional()}).nullable().optional(), aiAutoRepairEnabled: z.boolean().nullable().optional(), id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().nullable().optional(), alertChannels: checksV1AlertChannels.optional(), privateLocations: z.array(z.string().min(1)).nullable().optional(), frequency: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(5), z.literal(10), z.literal(15), z.literal(30), z.literal(60), z.literal(120), z.literal(180), z.literal(360), z.literal(720), z.literal(1440)]).optional(), frequencyOffset: z.number().int().gte(1).optional(), degradedResponseTime: z.number().nullable().optional(), maxResponseTime: z.number().nullable().optional(), checkType: z.literal("SSL").optional(), request: checksV1SslRequestRead.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 }; /** * Update an SSL Monitor * * PUT /v1/checks/ssl/{id} */ export const updateApiV1ChecksSslId = async (args: UpdateApiV1ChecksSslIdArgs, options?: UpdateApiV1ChecksSslIdOptions) => { 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.autoAssignAlerts != null) query.append("autoAssignAlerts", String(args.autoAssignAlerts)) 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/checks/ssl/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(checksV1SslMonitorMutationResponse, await res.json()) };