import {z} from 'zod' export type GetApiV1TestSessionsTestSessionIdResultsTestSessionResultIdArgs = {testSessionId: string, testSessionResultId: string, 'x-checkly-account'?: string | undefined}; export type GetApiV1TestSessionsTestSessionIdResultsTestSessionResultIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const testSessionApiResultDetails = z.object({assertions: z.array(z.record(z.string(), z.unknown())).nullable().optional(), request: z.record(z.string(), z.unknown()).optional(), response: z.record(z.string(), z.unknown()).optional(), requestError: z.string().nullable().optional(), jobLog: z.unknown(), jobAssets: z.array(z.string()).nullable().optional(), pcapDataUrl: z.string().nullable().optional()}).and(z.record(z.string(), z.unknown())).nullable(); export const testSessionBrowserResultDetails = z.object({type: z.string().optional(), traceSummary: z.record(z.string(), z.unknown()).optional(), pages: z.array(z.record(z.string(), z.unknown())).optional(), errors: z.array(z.unknown()).optional(), endTime: z.number().optional(), startTime: z.number().optional(), runtimeVersion: z.string().optional(), jobLog: z.unknown(), jobAssets: z.array(z.string()).nullable().optional(), pcapDataUrl: z.string().nullable().optional(), playwrightTestVideos: z.array(z.string()).optional(), playwrightTestTraces: z.array(z.string()).optional(), playwrightTestJsonReportFile: z.string().optional()}).and(z.record(z.string(), z.unknown())).nullable(); export const testSessionMultiStepResultDetails = z.object({errors: z.array(z.unknown()).optional(), endTime: z.number().optional(), startTime: z.number().optional(), runtimeVersion: z.string().optional(), jobLog: z.unknown(), jobAssets: z.array(z.string()).nullable().optional(), pcapDataUrl: z.string().nullable().optional(), playwrightTestVideos: z.array(z.string()).optional(), playwrightTestTraces: z.array(z.string()).optional(), playwrightTestJsonReportFile: z.string().optional()}).and(z.record(z.string(), z.unknown())).nullable(); export const testSessionPlaywrightResultDetails = z.object({errors: z.array(z.unknown()).nullable().optional(), playwrightTraceFiles: z.array(z.record(z.string(), z.unknown())).nullable().optional(), jobLog: z.unknown(), jobAssets: z.array(z.string()).nullable().optional(), pcapDataUrl: z.string().nullable().optional(), playwrightTestVideos: z.array(z.string()).optional(), playwrightTestTraces: z.array(z.string()).optional(), playwrightTestJsonReportFile: z.string().optional()}).and(z.record(z.string(), z.unknown())).nullable(); export const testSessionAgenticResultDetails = z.object({summary: z.string().nullable().optional(), prompt: z.string().nullable().optional(), assertions: z.array(z.record(z.string(), z.unknown())).nullable().optional(), suggestions: z.array(z.record(z.string(), z.unknown())).nullable().optional(), steps: z.array(z.record(z.string(), z.unknown())).nullable().optional(), errors: z.array(z.unknown()).nullable().optional(), artifactManifest: z.record(z.string(), z.unknown()).nullable().optional(), jobLog: z.unknown(), jobAssets: z.array(z.string()).nullable().optional(), pcapDataUrl: z.string().nullable().optional()}).and(z.record(z.string(), z.unknown())).nullable(); export const findOneTestSessionResultResponse = z.object({testSessionResultId: z.string(), testSessionResultLink: z.string(), checkId: z.string().nullable().optional(), checkType: z.enum(["AGENTIC", "API", "BROWSER", "HEARTBEAT", "ICMP", "MULTI_STEP", "TCP", "PLAYWRIGHT", "URL", "DNS", "SSL", "GRPC", "TRACEROUTE"]), name: z.string().optional(), runLocation: z.string().optional(), errorGroupIds: z.array(z.string()), resultType: z.enum(["FINAL", "ATTEMPT", "PENDING"]).optional(), status: z.enum(["RUNNING", "FAILED", "PASSED", "CANCELLED"]), hasErrors: z.boolean(), hasFailures: z.boolean(), isDegraded: z.boolean(), aborted: z.boolean(), responseTime: z.number().nullable().optional(), startedAt: z.string().nullable().optional(), stoppedAt: z.string().nullable().optional(), id: z.string(), privateLocationId: z.string().nullable().optional(), filePath: z.string().nullable().optional(), isCancelled: z.boolean(), overMaxResponseTime: z.boolean(), attempts: z.number().int().gte(0), sequenceId: z.string().nullable().optional(), scheduleError: z.string().nullable().optional(), traceId: z.string().nullable(), created_at: z.string(), updated_at: z.string().nullable().optional(), apiCheckResult: testSessionApiResultDetails.optional(), browserCheckResult: testSessionBrowserResultDetails.optional(), multiStepCheckResult: testSessionMultiStepResultDetails.optional(), playwrightCheckResult: testSessionPlaywrightResultDetails.optional(), agenticCheckResult: testSessionAgenticResultDetails.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 }; /** * Retrieve a test session result * * GET /v1/test-sessions/{testSessionId}/results/{testSessionResultId} */ export const getApiV1TestSessionsTestSessionIdResultsTestSessionResultId = async (args: GetApiV1TestSessionsTestSessionIdResultsTestSessionResultIdArgs, options?: GetApiV1TestSessionsTestSessionIdResultsTestSessionResultIdOptions) => { 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 (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/test-sessions/${encodeURIComponent(String(args.testSessionId))}/results/${encodeURIComponent(String(args.testSessionResultId))}${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(findOneTestSessionResultResponse, await res.json()) };