import {z} from 'zod' export type GetApiV2CheckResultsCheckIdArgs = {checkId: string, limit?: number | undefined, location?: ('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') | undefined, checkType?: ('AGENTIC' | 'API' | 'BROWSER' | 'HEARTBEAT' | 'ICMP' | 'MULTI_STEP' | 'TCP' | 'PLAYWRIGHT' | 'TRACEROUTE' | 'URL' | 'DNS' | 'SSL' | 'GRPC') | undefined, hasFailures?: boolean | undefined, resultType?: ('FINAL' | 'ATTEMPT' | 'ALL') | undefined, from?: number | undefined, to?: number | undefined, nextId?: string | undefined, fields?: (Array<'id' | 'name' | 'checkId' | 'hasFailures' | 'hasErrors' | 'isDegraded' | 'isCancelled' | 'overMaxResponseTime' | 'runLocation' | 'startedAt' | 'stoppedAt' | 'created_at' | 'createdAt' | 'responseTime' | 'apiCheckResult' | 'browserCheckResult' | 'multiStepCheckResult' | 'agenticCheckResult' | 'playwrightCheckResult' | 'tracerouteCheckResult' | 'grpcCheckResult' | 'sslCheckResult' | 'checkRunId' | 'attempts' | 'resultType' | 'sequenceId' | 'traceId' | 'errorGroupIds'>) | undefined, 'x-checkly-account'?: string | undefined}; export type GetApiV2CheckResultsCheckIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const checkResultFreeformObject = z.record(z.string(), z.unknown()); export const checkResultAPI = z.object({assertions: z.array(checkResultFreeformObject).nullable().optional(), request: z.object({method: z.string().optional(), url: z.string().optional(), data: z.string().optional(), headers: checkResultFreeformObject.optional(), params: checkResultFreeformObject.optional()}).optional(), response: z.object({status: z.number().optional(), statusText: z.string().optional(), body: z.string().optional(), bodyEncoding: z.literal("base64").optional(), headers: z.record(z.string(), z.unknown()).nullable().optional(), timings: z.record(z.string(), z.unknown()).nullable().optional(), timingPhases: z.record(z.string(), z.unknown()).nullable().optional()}).optional(), requestError: z.string().nullable().optional(), jobLog: z.record(z.string(), z.unknown()).nullable().optional(), jobAssets: z.array(z.unknown()).nullable().optional(), pcapDataUrl: z.string().nullable().optional()}).nullable(); export const checkResultBrowser = z.object({type: z.string().optional(), traceSummary: z.record(z.string(), z.unknown()).optional(), pages: z.array(checkResultFreeformObject).optional(), playwrightTestVideos: z.array(z.string()).optional(), errors: z.array(z.unknown()).optional(), endTime: z.number().optional(), startTime: z.number().optional(), runtimeVersion: z.string().optional(), jobLog: z.array(z.unknown()).nullable().optional(), jobAssets: z.array(z.unknown()).nullable().optional(), playwrightTestTraces: z.array(z.string()).optional(), playwrightTestJsonReportFile: z.string().optional()}).nullable(); export const multiStepResultBrowser = z.object({errors: z.array(z.unknown()).optional(), endTime: z.number().optional(), startTime: z.number().optional(), runtimeVersion: z.string().optional(), jobLog: z.array(z.unknown()).nullable().optional(), jobAssets: z.array(z.unknown()).nullable().optional(), playwrightTestTraces: z.array(z.string()).optional(), playwrightTestJsonReportFile: z.string().optional()}).nullable(); export const agenticAssertion = z.object({condition: z.string().optional(), passed: z.boolean().optional(), actual: z.string().optional(), expected: z.string().optional()}); export const agenticSuggestion = z.object({summary: z.string().optional(), prompt: z.string().optional(), promptReplacement: z.string().optional(), secrets: z.array(z.string()).optional(), category: z.enum(["credentials", "endpoint", "configuration"]).optional()}); export const agenticStep = z.object({type: z.enum(["tool_call", "tool_result", "message"]).optional(), name: z.string().optional(), input: z.record(z.string(), z.unknown()).optional(), output: z.string().optional(), timestamp: z.string().optional(), sequenceNumber: z.number().int().optional()}); export const checkResultAgentic = z.object({summary: z.string().nullable().optional(), prompt: z.string().nullable().optional(), assertions: z.array(agenticAssertion).nullable().optional(), suggestions: z.array(agenticSuggestion).nullable().optional(), steps: z.array(agenticStep).nullable().optional(), errors: z.array(checkResultFreeformObject).nullable().optional(), artifactManifest: z.record(z.string(), z.unknown()).nullable().optional()}).nullable(); export const checkResultPlaywrightTraceFile = z.object({url: z.string().optional(), name: z.string().optional(), filename: z.string().optional()}).and(z.record(z.string(), z.unknown())); export const checkResultPlaywright = z.object({errors: z.array(checkResultFreeformObject).nullable().optional(), playwrightTraceFiles: z.array(checkResultPlaywrightTraceFile).nullable().optional(), jobLog: z.array(z.unknown()).nullable().optional(), jobAssets: z.array(z.unknown()).nullable().optional(), playwrightTestVideos: z.array(z.string()).nullable().optional(), playwrightTestTraces: z.array(z.string()).nullable().optional(), playwrightTestJsonReportFile: z.string().nullable().optional()}).nullable(); export const checkResultTraceroute = z.object({totalHops: z.number().optional(), destinationReached: z.boolean().optional(), finalHopLatency: z.record(z.string(), z.unknown()).nullable().optional(), timingPhases: z.record(z.string(), z.unknown()).nullable().optional(), requestError: z.string().nullable().optional(), request: z.record(z.string(), z.unknown()).nullable().optional(), assertions: z.array(checkResultFreeformObject).nullable().optional(), response: z.object({hostname: z.string().optional(), resolvedIp: z.string().optional(), totalHops: z.number().optional(), destinationReached: z.boolean().optional(), truncationReason: z.string().optional(), finalHopLatency: z.record(z.string(), z.unknown()).nullable().optional(), hops: z.array(checkResultFreeformObject).nullable().optional(), protocol: z.string().optional(), probeProtocol: z.string().optional()}).nullable().optional()}).nullable(); export const checkResultGrpc = z.object({grpcStatusCode: z.number().optional(), healthStatus: z.number().nullable().optional(), timingPhases: z.record(z.string(), z.unknown()).nullable().optional(), requestError: z.string().nullable().optional(), request: z.record(z.string(), z.unknown()).nullable().optional(), assertions: z.array(checkResultFreeformObject).nullable().optional(), response: z.object({grpcMode: z.string().optional(), host: z.string().optional(), resolvedIp: z.string().optional(), port: z.number().optional(), grpcMethod: z.string().optional(), responseMessage: z.string().optional(), grpcStatusCode: z.number().optional(), grpcStatusMessage: z.string().optional(), healthStatus: z.number().nullable().optional(), healthStatusLabel: z.string().optional(), metadata: z.array(checkResultFreeformObject).nullable().optional(), discoveredMethods: z.array(z.string()).nullable().optional(), requestError: z.string().nullable().optional(), timingPhases: z.record(z.string(), z.unknown()).nullable().optional()}).nullable().optional()}).nullable(); export const checkResultSsl = z.object({tlsVersion: z.string().optional(), cipherSuite: z.string().optional(), daysUntilExpiry: z.number().optional(), handshakeTimeMs: z.number().optional(), chainTrusted: z.boolean().optional(), hostnameVerified: z.boolean().optional(), baselineVerdict: z.string().optional(), baselineGrade: z.string().optional(), failureCategory: z.string().nullable().optional(), requestError: z.string().nullable().optional(), request: z.record(z.string(), z.unknown()).nullable().optional(), assertions: z.array(checkResultFreeformObject).nullable().optional(), response: z.object({resolvedIp: z.string().optional(), protocol: z.string().optional(), cipherSuite: z.string().optional(), handshakeTimeMs: z.number().optional(), hostnameVerified: z.boolean().optional(), chainTrusted: z.boolean().optional(), daysUntilExpiry: z.number().optional(), ocspStapled: z.boolean().optional(), ocspStatus: z.string().optional(), chainTrustReason: z.string().optional(), chainTrustDetail: z.string().optional(), incompleteChain: z.boolean().optional(), missingIntermediate: z.string().optional(), securityBaseline: z.record(z.string(), z.unknown()).nullable().optional(), certificate: z.record(z.string(), z.unknown()).nullable().optional(), chain: z.array(checkResultFreeformObject).nullable().optional()}).nullable().optional()}).nullable(); export const checkResult = z.object({id: z.string().optional(), name: z.string().optional(), checkId: z.string().optional(), hasFailures: z.boolean().optional(), hasErrors: z.boolean().optional(), isDegraded: z.boolean().nullable().optional(), isCancelled: z.boolean().optional(), overMaxResponseTime: z.boolean().nullable().optional(), runLocation: z.string().optional(), startedAt: z.string().nullable().optional(), stoppedAt: z.string().nullable().optional(), created_at: z.string().optional(), responseTime: z.number().optional(), apiCheckResult: checkResultAPI.optional(), browserCheckResult: checkResultBrowser.optional(), multiStepCheckResult: multiStepResultBrowser.optional(), agenticCheckResult: checkResultAgentic.optional(), playwrightCheckResult: checkResultPlaywright.optional(), tracerouteCheckResult: checkResultTraceroute.optional(), grpcCheckResult: checkResultGrpc.optional(), sslCheckResult: checkResultSsl.optional(), checkRunId: z.number().optional(), attempts: z.number().optional(), resultType: z.enum(["FINAL", "ATTEMPT", "ALL"]), sequenceId: z.string().nullable().optional(), traceId: z.string().nullable(), errorGroupIds: z.array(z.string()).nullable().optional()}); export const checkResultProjection = z.object({id: z.string().optional(), name: z.string().optional(), checkId: z.string().optional(), hasFailures: z.boolean().optional(), hasErrors: z.boolean().optional(), isDegraded: z.boolean().nullable().optional(), isCancelled: z.boolean().optional(), overMaxResponseTime: z.boolean().nullable().optional(), runLocation: z.string().optional(), startedAt: z.string().nullable().optional(), stoppedAt: z.string().nullable().optional(), created_at: z.string().optional(), responseTime: z.number().optional(), apiCheckResult: checkResultAPI.optional(), browserCheckResult: checkResultBrowser.optional(), multiStepCheckResult: multiStepResultBrowser.optional(), agenticCheckResult: checkResultAgentic.optional(), playwrightCheckResult: checkResultPlaywright.optional(), tracerouteCheckResult: checkResultTraceroute.optional(), grpcCheckResult: checkResultGrpc.optional(), sslCheckResult: checkResultSsl.optional(), checkRunId: z.number().optional(), attempts: z.number().optional(), resultType: z.enum(["FINAL", "ATTEMPT", "ALL"]).optional(), sequenceId: z.string().nullable().optional(), traceId: z.string().nullable().optional(), errorGroupIds: z.array(z.string()).nullable().optional(), createdAt: z.string().optional()}); export const checkResultListEntry = z.union([checkResult, checkResultProjection]); export const checkResultListV2 = z.object({length: z.number(), entries: z.array(checkResultListEntry).optional(), 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 }; /** * Lists all check results * * GET /v2/check-results/{checkId} */ export const getApiV2CheckResultsCheckId = async (args: GetApiV2CheckResultsCheckIdArgs, options?: GetApiV2CheckResultsCheckIdOptions) => { 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.limit != null) query.append("limit", String(args.limit)) if (args.location != null) query.append("location", String(args.location)) if (args.checkType != null) query.append("checkType", String(args.checkType)) if (args.hasFailures != null) query.append("hasFailures", String(args.hasFailures)) if (args.resultType != null) query.append("resultType", String(args.resultType)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.nextId != null) query.append("nextId", String(args.nextId)) for (const item of args.fields ?? []) query.append("fields", String(item)) 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(/\/+$/, '')}/v2/check-results/${encodeURIComponent(String(args.checkId))}${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(checkResultListV2, await res.json()) };