@testrelic/core 2.2.2 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -28,9 +28,14 @@ __export(index_exports, {
28
28
  createError: () => createError,
29
29
  createLogger: () => createLogger,
30
30
  isTestRelicDataPayload: () => isTestRelicDataPayload,
31
+ isValidApiKeyFormat: () => isValidApiKeyFormat,
32
+ isValidCloudConfig: () => isValidCloudConfig,
31
33
  isValidConfig: () => isValidConfig,
34
+ isValidEndpointUrl: () => isValidEndpointUrl,
32
35
  isValidNavigationType: () => isValidNavigationType,
33
- isValidTestRunReport: () => isValidTestRunReport
36
+ isValidQueueEntry: () => isValidQueueEntry,
37
+ isValidTestRunReport: () => isValidTestRunReport,
38
+ isValidUploadStrategy: () => isValidUploadStrategy
34
39
  });
35
40
  module.exports = __toCommonJS(index_exports);
36
41
 
@@ -73,7 +78,11 @@ var ErrorCode = {
73
78
  MERGE_READ_FAILED: "TESTRELIC_MERGE_READ_FAILED",
74
79
  NAVIGATION_FLUSH_FAILED: "TESTRELIC_NAVIGATION_FLUSH_FAILED",
75
80
  CODE_EXTRACT_FAILED: "TESTRELIC_CODE_EXTRACT_FAILED",
76
- HTML_REPORT_FAILED: "TESTRELIC_HTML_REPORT_FAILED"
81
+ HTML_REPORT_FAILED: "TESTRELIC_HTML_REPORT_FAILED",
82
+ CLOUD_AUTH_FAILED: "TESTRELIC_CLOUD_AUTH_FAILED",
83
+ CLOUD_UPLOAD_FAILED: "TESTRELIC_CLOUD_UPLOAD_FAILED",
84
+ CLOUD_CONFIG_INVALID: "TESTRELIC_CLOUD_CONFIG_INVALID",
85
+ CLOUD_QUEUE_FAILED: "TESTRELIC_CLOUD_QUEUE_FAILED"
77
86
  };
78
87
  var TestRelicError = class extends Error {
79
88
  constructor(code, message, cause) {
@@ -180,6 +189,67 @@ function isValidConfig(input) {
180
189
  }
181
190
  return true;
182
191
  }
192
+ var API_KEY_PATTERN = /^tr[a-z]*_[a-z]+_[a-zA-Z0-9]+$/;
193
+ var UPLOAD_STRATEGIES = /* @__PURE__ */ new Set(["batch", "realtime", "both"]);
194
+ var LOCALHOST_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "0.0.0.0"]);
195
+ function isValidApiKeyFormat(value) {
196
+ return typeof value === "string" && API_KEY_PATTERN.test(value);
197
+ }
198
+ function isValidUploadStrategy(value) {
199
+ return typeof value === "string" && UPLOAD_STRATEGIES.has(value);
200
+ }
201
+ function isValidEndpointUrl(value) {
202
+ if (typeof value !== "string") return false;
203
+ try {
204
+ const url = new URL(value);
205
+ if (url.protocol === "https:") return true;
206
+ if (url.protocol === "http:" && LOCALHOST_HOSTS.has(url.hostname)) return true;
207
+ return false;
208
+ } catch {
209
+ return false;
210
+ }
211
+ }
212
+ function isValidCloudConfig(input) {
213
+ if (typeof input !== "object" || input === null) return false;
214
+ if (!hasNoPrototypePollution(input)) return false;
215
+ const obj = input;
216
+ if (obj.apiKey !== void 0 && obj.apiKey !== null) {
217
+ if (typeof obj.apiKey !== "string") return false;
218
+ if (obj.apiKey.length > 0 && !isValidApiKeyFormat(obj.apiKey)) return false;
219
+ }
220
+ if (obj.endpoint !== void 0) {
221
+ if (!isValidEndpointUrl(obj.endpoint)) return false;
222
+ }
223
+ if (obj.uploadStrategy !== void 0) {
224
+ if (!isValidUploadStrategy(obj.uploadStrategy)) return false;
225
+ }
226
+ if (obj.timeout !== void 0) {
227
+ if (typeof obj.timeout !== "number" || obj.timeout < 1e3 || obj.timeout > 12e4) return false;
228
+ }
229
+ if (obj.projectName !== void 0 && obj.projectName !== null && typeof obj.projectName !== "string") return false;
230
+ if (obj.queueMaxAge !== void 0) {
231
+ if (typeof obj.queueMaxAge !== "number" || obj.queueMaxAge < 36e5 || obj.queueMaxAge > 2592e6) return false;
232
+ }
233
+ if (obj.queueDirectory !== void 0) {
234
+ if (typeof obj.queueDirectory !== "string") return false;
235
+ if (obj.queueDirectory.startsWith("/") || obj.queueDirectory.includes("..")) return false;
236
+ }
237
+ return true;
238
+ }
239
+ function isValidQueueEntry(input) {
240
+ if (typeof input !== "object" || input === null) return false;
241
+ if (!hasNoPrototypePollution(input)) return false;
242
+ const obj = input;
243
+ if (typeof obj.version !== "string") return false;
244
+ if (typeof obj.queuedAt !== "string") return false;
245
+ if (typeof obj.reason !== "string") return false;
246
+ if (typeof obj.retryCount !== "number") return false;
247
+ if (typeof obj.targetEndpoint !== "string") return false;
248
+ if (typeof obj.method !== "string") return false;
249
+ if (typeof obj.payload !== "object" || obj.payload === null) return false;
250
+ if (typeof obj.headers !== "object" || obj.headers === null) return false;
251
+ return true;
252
+ }
183
253
  function isValidTestRunReport(value) {
184
254
  if (typeof value !== "object" || value === null) return false;
185
255
  const obj = value;
@@ -209,8 +279,13 @@ function isValidTestRunReport(value) {
209
279
  createError,
210
280
  createLogger,
211
281
  isTestRelicDataPayload,
282
+ isValidApiKeyFormat,
283
+ isValidCloudConfig,
212
284
  isValidConfig,
285
+ isValidEndpointUrl,
213
286
  isValidNavigationType,
214
- isValidTestRunReport
287
+ isValidQueueEntry,
288
+ isValidTestRunReport,
289
+ isValidUploadStrategy
215
290
  });
216
291
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/types.ts","../src/logger.ts","../src/errors.ts","../src/validation.ts"],"sourcesContent":["// @testrelic/core — barrel export\n// Re-exports only, no implementation (Constitution II)\n\nexport type {\n NavigationType,\n TestRunReport,\n Summary,\n CIMetadata,\n CIProvider,\n TimelineEntry,\n TestResult,\n TestStatus,\n TestType,\n FailureDiagnostic,\n NetworkStats,\n ResourceBreakdown,\n ResourceType,\n CapturedNetworkRequest,\n ApiCallRecord,\n ApiAssertion,\n AssertionType,\n AssertionLocation,\n ReporterConfig,\n TestArtifacts,\n NavigationAnnotation,\n MergeOptions,\n StepTestIdentity,\n ApiCallStepRequest,\n ApiCallStepResponse,\n StepAssertion,\n NavigationStep,\n ApiCallStep,\n TimelineStep,\n ActionStep,\n ActionCategory,\n TestRelicDataPayload,\n} from './types.js';\n\nexport {\n PAYLOAD_VERSION,\n ATTACHMENT_NAME,\n ATTACHMENT_CONTENT_TYPE,\n isTestRelicDataPayload,\n} from './types.js';\n\nexport type { Logger, LoggerOptions, LogLevel } from './logger.js';\nexport { createLogger } from './logger.js';\n\nexport { ErrorCode, TestRelicError, createError } from './errors.js';\n\nexport {\n isValidConfig,\n isValidNavigationType,\n isValidTestRunReport,\n} from './validation.js';\n","/**\n * @testrelic/core — Shared type definitions\n *\n * All interfaces for the JSON output schema, reporter configuration,\n * and internal fixture-to-reporter communication.\n *\n * Schema Version: 1.0.0\n */\n\n// ---------------------------------------------------------------------------\n// Navigation Types\n// ---------------------------------------------------------------------------\n\nexport type NavigationType =\n | 'goto'\n | 'navigation'\n | 'back'\n | 'forward'\n | 'refresh'\n | 'spa_route'\n | 'spa_replace'\n | 'hash_change'\n | 'link_click'\n | 'form_submit'\n | 'redirect'\n | 'popstate'\n | 'page_load'\n | 'manual_record'\n | 'fallback'\n | 'dummy';\n\n// ---------------------------------------------------------------------------\n// Output Schema Types (JSON report structure)\n// ---------------------------------------------------------------------------\n\nexport interface TestRunReport {\n readonly schemaVersion: string;\n readonly testRunId: string;\n readonly startedAt: string;\n readonly completedAt: string;\n readonly totalDuration: number;\n readonly summary: Summary;\n readonly ci: CIMetadata | null;\n readonly metadata: Record<string, unknown> | null;\n readonly timeline: readonly (TimelineEntry | TimelineStep)[];\n readonly shardRunIds: string[] | null;\n}\n\n/** Breakdown of API calls by HTTP response status range. */\nexport interface ApiCallsByStatusRange {\n readonly '2xx': number;\n readonly '3xx': number;\n readonly '4xx': number;\n readonly '5xx': number;\n readonly error: number;\n}\n\n/** Statistical distribution of API call response times in milliseconds. */\nexport interface ApiResponseTimeStats {\n readonly avg: number;\n readonly min: number;\n readonly max: number;\n readonly p50: number;\n readonly p95: number;\n readonly p99: number;\n}\n\nexport interface Summary {\n readonly total: number;\n readonly passed: number;\n readonly failed: number;\n readonly flaky: number;\n readonly skipped: number;\n readonly timedout: number;\n readonly totalApiCalls: number;\n readonly uniqueApiUrls: number;\n readonly apiCallsByMethod: Record<string, number>;\n readonly apiCallsByStatusRange: ApiCallsByStatusRange;\n readonly apiResponseTime: ApiResponseTimeStats | null;\n readonly totalAssertions: number;\n readonly passedAssertions: number;\n readonly failedAssertions: number;\n readonly totalNavigations: number;\n readonly uniqueNavigationUrls: number;\n readonly totalTimelineSteps: number;\n readonly totalActionSteps: number;\n readonly actionStepsByCategory: Record<string, number>;\n}\n\nexport interface CIMetadata {\n readonly provider: CIProvider;\n readonly buildId: string | null;\n readonly commitSha: string | null;\n readonly branch: string | null;\n}\n\nexport type CIProvider =\n | 'github-actions'\n | 'gitlab-ci'\n | 'jenkins'\n | 'circleci'\n | 'unknown';\n\nexport interface TimelineEntry {\n readonly url: string;\n readonly navigationType: NavigationType;\n readonly visitedAt: string;\n readonly duration: number;\n readonly specFile: string;\n readonly domContentLoadedAt: string | null;\n readonly networkIdleAt: string | null;\n readonly networkStats: NetworkStats | null;\n readonly tests: TestResult[];\n}\n\nexport interface TestResult {\n readonly title: string;\n readonly status: TestStatus;\n readonly duration: number;\n readonly startedAt: string;\n readonly completedAt: string;\n readonly retryCount: number;\n readonly tags: string[];\n readonly failure: FailureDiagnostic | null;\n readonly testId: string;\n readonly filePath: string;\n readonly suiteName: string;\n readonly testType: TestType;\n readonly isFlaky: boolean;\n readonly retryStatus: string | null;\n readonly expectedStatus: TestStatus;\n readonly actualStatus: TestStatus;\n readonly artifacts: TestArtifacts | null;\n readonly networkRequests: CapturedNetworkRequest[] | null;\n readonly apiCalls: readonly ApiCallRecord[] | null;\n readonly apiAssertions: readonly ApiAssertion[] | null;\n readonly actions: readonly ActionStep[] | null;\n}\n\nexport type ResourceType = 'xhr' | 'document' | 'script' | 'stylesheet' | 'image' | 'font' | 'other';\n\nexport interface CapturedNetworkRequest {\n readonly url: string;\n readonly method: string;\n readonly resourceType: ResourceType;\n readonly statusCode: number;\n readonly responseTimeMs: number;\n readonly startedAt: string;\n readonly requestHeaders: Record<string, string> | null;\n readonly requestBody: string | null;\n readonly responseBody: string | null;\n readonly responseHeaders: Record<string, string> | null;\n readonly contentType: string | null;\n readonly responseSize: number;\n readonly requestBodyTruncated: boolean;\n readonly responseBodyTruncated: boolean;\n readonly isBinary: boolean;\n readonly error: string | null;\n}\n\nexport interface TestArtifacts {\n readonly screenshot?: string;\n readonly video?: string;\n}\n\nexport type TestStatus = 'passed' | 'failed' | 'skipped' | 'flaky' | 'timedout';\n\nexport type TestType = 'e2e' | 'api' | 'unit' | 'unknown';\n\nexport interface FailureDiagnostic {\n readonly message: string;\n readonly line: number | null;\n readonly code: string | null;\n readonly stack: string | null;\n}\n\nexport interface NetworkStats {\n readonly totalRequests: number;\n readonly failedRequests: number;\n readonly failedRequestUrls: string[];\n readonly totalBytes: number;\n readonly byType: ResourceBreakdown;\n}\n\nexport interface ResourceBreakdown {\n readonly xhr: number;\n readonly document: number;\n readonly script: number;\n readonly stylesheet: number;\n readonly image: number;\n readonly font: number;\n readonly other: number;\n}\n\n// ---------------------------------------------------------------------------\n// API Call Record (captured from Playwright APIRequestContext proxy)\n// ---------------------------------------------------------------------------\n\nexport interface ApiCallRecord {\n /** Unique call identifier within the test (e.g., \"api-call-0\") */\n readonly id: string;\n /** ISO 8601 timestamp when the call was initiated */\n readonly timestamp: string;\n /** HTTP method: GET, POST, PUT, PATCH, DELETE, HEAD, or custom via fetch() */\n readonly method: string;\n /** Full resolved URL (after baseURL resolution by Playwright) */\n readonly url: string;\n /** All request headers sent, or null if unavailable */\n readonly requestHeaders: Record<string, string> | null;\n /** Request payload as string (JSON-serialized for objects). Null for bodiless methods */\n readonly requestBody: string | null;\n /** HTTP response status code, or null if request errored before response */\n readonly responseStatusCode: number | null;\n /** HTTP response status text, or null if request errored before response */\n readonly responseStatusText: string | null;\n /** All response headers received, or null if request errored before response */\n readonly responseHeaders: Record<string, string> | null;\n /** Response body: string for text/JSON, base64 for binary. Null on error */\n readonly responseBody: string | null;\n /** Duration in milliseconds from request initiation to response received */\n readonly responseTimeMs: number;\n /** Whether the response body is stored as a base64-encoded binary string */\n readonly isBinary: boolean;\n /** Error message if the call failed (network error, timeout), null on success */\n readonly error: string | null;\n}\n\n// ---------------------------------------------------------------------------\n// API Assertion Types (captured from assertion tracking)\n// ---------------------------------------------------------------------------\n\n/** Categorization of the assertion being made. */\nexport type AssertionType =\n | 'status'\n | 'statusOk'\n | 'header'\n | 'bodyField'\n | 'bodyMatch'\n | 'bodyContains'\n | 'custom';\n\n/** Source location where an assertion was made in the test file. */\nexport interface AssertionLocation {\n /** Absolute or relative file path to the test file */\n readonly file: string;\n /** Line number (1-based) */\n readonly line: number;\n /** Column number (1-based), if available */\n readonly column?: number;\n}\n\n/** A single captured assertion on API response data. */\nexport interface ApiAssertion {\n /** Links to ApiCallRecord.id from the API proxy */\n readonly callId: string;\n /** Category of assertion */\n readonly type: AssertionType;\n /** What the test expected */\n readonly expected: unknown;\n /** What was actually received */\n readonly actual: unknown;\n /** Whether the assertion passed or failed */\n readonly status: 'passed' | 'failed';\n /** Source location of the assertion in the test file */\n readonly location: AssertionLocation;\n /** String representation of the assertion expression (best-effort) */\n readonly expression?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Unified Timeline Types (navigation + API call steps)\n// ---------------------------------------------------------------------------\n\n/** Test identity block attached to every timeline step. */\nexport interface StepTestIdentity {\n readonly title: string;\n readonly fullTitle: readonly string[];\n readonly status: TestStatus;\n readonly duration: number;\n readonly retries: number;\n readonly retry: number;\n readonly tags: readonly string[];\n readonly failure: FailureDiagnostic | null;\n}\n\n/** Request details within an API call step. */\nexport interface ApiCallStepRequest {\n readonly headers: Record<string, string> | null;\n readonly body: unknown;\n}\n\n/** Response details within an API call step. */\nexport interface ApiCallStepResponse {\n readonly statusCode: number;\n readonly statusText: string;\n readonly headers: Record<string, string> | null;\n readonly body: unknown;\n}\n\n/** An assertion linked to an API call step (callId omitted — implicit from parent). */\nexport interface StepAssertion {\n readonly type: AssertionType;\n readonly expected: unknown;\n readonly actual: unknown;\n readonly status: 'passed' | 'failed';\n readonly location: AssertionLocation;\n readonly expression?: string;\n}\n\n/** A browser navigation event in the unified timeline. */\nexport interface NavigationStep {\n readonly index: number;\n readonly type: 'navigation';\n readonly url: string;\n readonly timestamp: string;\n readonly durationOnUrl: number;\n readonly navigationType: NavigationType;\n readonly domContentLoadedAt: string | null;\n readonly networkIdleAt: string | null;\n readonly networkStats: NetworkStats | null;\n readonly specFile: string;\n readonly test: StepTestIdentity;\n}\n\n/** An API request event in the unified timeline. */\nexport interface ApiCallStep {\n readonly index: number;\n readonly type: 'api_call';\n readonly callId: string;\n readonly method: string;\n readonly url: string;\n readonly timestamp: string;\n readonly responseTime: number | null;\n readonly request: ApiCallStepRequest;\n readonly response: ApiCallStepResponse | null;\n readonly error?: string | null;\n readonly assertions: readonly StepAssertion[];\n readonly specFile: string;\n readonly test: StepTestIdentity;\n}\n\n/** Discriminated union of all timeline step types. */\nexport type TimelineStep = NavigationStep | ApiCallStep;\n\n// ---------------------------------------------------------------------------\n// Action Step Types (Playwright test step capture)\n// ---------------------------------------------------------------------------\n\n/** Categorized type of a captured test action. */\nexport type ActionCategory = 'ui_action' | 'assertion' | 'custom_step';\n\n/** A single captured test action step. */\nexport interface ActionStep {\n readonly title: string;\n readonly category: ActionCategory;\n readonly timestamp: string;\n readonly duration: number;\n readonly videoOffset: number | null;\n readonly status: 'passed' | 'failed';\n readonly error: string | null;\n readonly children: readonly ActionStep[];\n}\n\n// ---------------------------------------------------------------------------\n// Configuration Types (reporter tuple options)\n// ---------------------------------------------------------------------------\n\nexport interface ReporterConfig {\n readonly outputPath?: string;\n readonly includeStackTrace?: boolean;\n readonly includeCodeSnippets?: boolean;\n readonly codeContextLines?: number;\n readonly includeNetworkStats?: boolean;\n readonly navigationTypes?: NavigationType[] | null;\n readonly redactPatterns?: (string | RegExp)[];\n readonly testRunId?: string | null;\n readonly metadata?: Record<string, unknown> | null;\n readonly openReport?: boolean;\n readonly htmlReportPath?: string;\n readonly includeArtifacts?: boolean;\n /** When false, disables API call interception in the unified fixture. Default: true */\n readonly trackApiCalls?: boolean;\n /** When true, suppresses console summary output. Default: false */\n readonly quiet?: boolean;\n /** When true, captures Playwright test steps (actions). Default: true */\n readonly includeActionSteps?: boolean;\n /** Capture request headers for API calls. Default: true */\n readonly captureRequestHeaders?: boolean;\n /** Capture response headers for API calls. Default: true */\n readonly captureResponseHeaders?: boolean;\n /** Capture request body for API calls. Default: true */\n readonly captureRequestBody?: boolean;\n /** Capture response body for API calls. Default: true */\n readonly captureResponseBody?: boolean;\n /** Capture API assertions (both pass and fail). Default: true */\n readonly captureAssertions?: boolean;\n /**\n * Header names whose values are replaced with \"[REDACTED]\".\n * Case-insensitive matching. Default: ['authorization', 'cookie', 'set-cookie', 'x-api-key']\n */\n readonly redactHeaders?: string[];\n /**\n * Body field names whose values are replaced with \"[REDACTED]\" at any depth.\n * Default: ['password', 'secret', 'token', 'apiKey', 'api_key']\n */\n readonly redactBodyFields?: string[];\n /**\n * Only track API calls matching these URL patterns.\n * Default: undefined (track all)\n */\n readonly apiIncludeUrls?: (string | RegExp)[];\n /**\n * Exclude API calls matching these URL patterns. Takes precedence over include.\n * Default: undefined (exclude none)\n */\n readonly apiExcludeUrls?: (string | RegExp)[];\n}\n\n// ---------------------------------------------------------------------------\n// Internal Types (fixture → reporter communication)\n// ---------------------------------------------------------------------------\n\nexport interface NavigationAnnotation {\n readonly url: string;\n readonly navigationType: NavigationType;\n readonly timestamp: string;\n readonly domContentLoadedAt?: string;\n readonly networkIdleAt?: string;\n readonly networkStats?: NetworkStats;\n}\n\n// ---------------------------------------------------------------------------\n// Worker-Safe Data Payload (worker → reporter communication)\n// ---------------------------------------------------------------------------\n\n/** Consolidated data payload sent from a worker fixture to the reporter. */\nexport interface TestRelicDataPayload {\n /** Marker to identify TestRelic attachments. Always `true`. */\n readonly testRelicData: true;\n /** Payload format version (semver). */\n readonly version: string;\n /** Navigation events collected during the test. */\n readonly navigations: readonly NavigationAnnotation[];\n /** Captured network requests during the test. */\n readonly networkRequests: readonly CapturedNetworkRequest[];\n /** API calls made via APIRequestContext proxy. */\n readonly apiCalls: readonly ApiCallRecord[];\n /** Assertions captured on API responses. */\n readonly apiAssertions: readonly ApiAssertion[];\n}\n\n/** Current payload format version. */\nexport const PAYLOAD_VERSION = '1.0.0';\n\n/** Attachment name used for the consolidated payload. */\nexport const ATTACHMENT_NAME = 'testrelic-data';\n\n/** Attachment content type. */\nexport const ATTACHMENT_CONTENT_TYPE = 'application/json';\n\n/** Type guard: validates that a parsed object is a TestRelicDataPayload. */\nexport function isTestRelicDataPayload(obj: unknown): obj is TestRelicDataPayload {\n if (typeof obj !== 'object' || obj === null) return false;\n const record = obj as Record<string, unknown>;\n return (\n record.testRelicData === true &&\n typeof record.version === 'string' &&\n record.version.length > 0 &&\n Array.isArray(record.navigations) &&\n Array.isArray(record.networkRequests) &&\n Array.isArray(record.apiCalls) &&\n Array.isArray(record.apiAssertions)\n );\n}\n\n// ---------------------------------------------------------------------------\n// Merge CLI Types\n// ---------------------------------------------------------------------------\n\nexport interface MergeOptions {\n readonly output: string;\n readonly testRunId?: string;\n}\n","/**\n * @testrelic/core — Configurable logger\n *\n * Provides a Logger interface with a no-op default.\n * Never uses console.* directly (Constitution SDK Constraint).\n */\n\nexport interface Logger {\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n debug(message: string, ...args: unknown[]): void;\n}\n\nexport interface LoggerOptions {\n readonly handler?: (level: LogLevel, message: string, args: unknown[]) => void;\n}\n\nexport type LogLevel = 'info' | 'warn' | 'error' | 'debug';\n\ntype LogHandler = (level: LogLevel, message: string, args: unknown[]) => void;\n\nconst noopHandler: LogHandler = () => {};\n\nexport function createLogger(options?: LoggerOptions): Logger {\n const handler = options?.handler ?? noopHandler;\n\n return {\n info(message: string, ...args: unknown[]) {\n handler('info', message, args);\n },\n warn(message: string, ...args: unknown[]) {\n handler('warn', message, args);\n },\n error(message: string, ...args: unknown[]) {\n handler('error', message, args);\n },\n debug(message: string, ...args: unknown[]) {\n handler('debug', message, args);\n },\n };\n}\n","/**\n * @testrelic/core — Structured error factory\n *\n * Machine-readable error codes for programmatic handling.\n */\n\nexport const ErrorCode = {\n CONFIG_INVALID: 'TESTRELIC_CONFIG_INVALID',\n OUTPUT_WRITE_FAILED: 'TESTRELIC_OUTPUT_WRITE_FAILED',\n MERGE_INVALID_SCHEMA: 'TESTRELIC_MERGE_INVALID_SCHEMA',\n MERGE_READ_FAILED: 'TESTRELIC_MERGE_READ_FAILED',\n NAVIGATION_FLUSH_FAILED: 'TESTRELIC_NAVIGATION_FLUSH_FAILED',\n CODE_EXTRACT_FAILED: 'TESTRELIC_CODE_EXTRACT_FAILED',\n HTML_REPORT_FAILED: 'TESTRELIC_HTML_REPORT_FAILED',\n} as const;\n\nexport type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];\n\nexport class TestRelicError extends Error {\n readonly code: ErrorCode;\n\n constructor(code: ErrorCode, message: string, cause?: unknown) {\n super(message);\n this.name = 'TestRelicError';\n this.code = code;\n if (cause !== undefined) {\n Object.defineProperty(this, 'cause', { value: cause, writable: false, enumerable: false });\n }\n }\n}\n\nexport function createError(\n code: ErrorCode,\n message: string,\n cause?: unknown,\n): TestRelicError {\n return new TestRelicError(code, message, cause);\n}\n","/**\n * @testrelic/core — Lightweight runtime type guards\n *\n * Hand-written guards, no runtime schema libraries (Constitution SDK Constraint).\n */\n\nimport type {\n ReporterConfig,\n NavigationType,\n TestRunReport,\n} from './types.js';\n\nconst NAVIGATION_TYPES = new Set<string>([\n 'goto', 'navigation', 'back', 'forward', 'refresh',\n 'spa_route', 'spa_replace', 'hash_change', 'link_click',\n 'form_submit', 'redirect', 'popstate', 'page_load',\n 'manual_record', 'fallback', 'dummy',\n]);\n\nconst DANGEROUS_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport function isValidNavigationType(value: unknown): value is NavigationType {\n return typeof value === 'string' && NAVIGATION_TYPES.has(value);\n}\n\nfunction hasNoPrototypePollution(obj: unknown): boolean {\n if (typeof obj !== 'object' || obj === null) return true;\n for (const key of Object.keys(obj)) {\n if (DANGEROUS_KEYS.has(key)) return false;\n }\n return true;\n}\n\nexport function isValidConfig(input: unknown): input is ReporterConfig {\n if (typeof input !== 'object' || input === null) return false;\n if (!hasNoPrototypePollution(input)) return false;\n\n const obj = input as Record<string, unknown>;\n\n if (obj.outputPath !== undefined && typeof obj.outputPath !== 'string') return false;\n if (obj.includeStackTrace !== undefined && typeof obj.includeStackTrace !== 'boolean') return false;\n if (obj.includeCodeSnippets !== undefined && typeof obj.includeCodeSnippets !== 'boolean') return false;\n if (obj.codeContextLines !== undefined && typeof obj.codeContextLines !== 'number') return false;\n if (obj.includeNetworkStats !== undefined && typeof obj.includeNetworkStats !== 'boolean') return false;\n\n if (obj.navigationTypes !== undefined && obj.navigationTypes !== null) {\n if (!Array.isArray(obj.navigationTypes)) return false;\n for (const t of obj.navigationTypes) {\n if (!isValidNavigationType(t)) return false;\n }\n }\n\n if (obj.redactPatterns !== undefined) {\n if (!Array.isArray(obj.redactPatterns)) return false;\n for (const p of obj.redactPatterns) {\n if (typeof p !== 'string' && !(p instanceof RegExp)) return false;\n }\n }\n\n if (obj.testRunId !== undefined && obj.testRunId !== null && typeof obj.testRunId !== 'string') return false;\n\n if (obj.metadata !== undefined && obj.metadata !== null) {\n if (typeof obj.metadata !== 'object') return false;\n if (!hasNoPrototypePollution(obj.metadata)) return false;\n }\n\n if (obj.openReport !== undefined && typeof obj.openReport !== 'boolean') return false;\n if (obj.htmlReportPath !== undefined && (typeof obj.htmlReportPath !== 'string' || obj.htmlReportPath === '')) return false;\n if (obj.includeArtifacts !== undefined && typeof obj.includeArtifacts !== 'boolean') return false;\n\n // API tracking configuration\n if (obj.trackApiCalls !== undefined && typeof obj.trackApiCalls !== 'boolean') return false;\n if (obj.captureRequestHeaders !== undefined && typeof obj.captureRequestHeaders !== 'boolean') return false;\n if (obj.captureResponseHeaders !== undefined && typeof obj.captureResponseHeaders !== 'boolean') return false;\n if (obj.captureRequestBody !== undefined && typeof obj.captureRequestBody !== 'boolean') return false;\n if (obj.captureResponseBody !== undefined && typeof obj.captureResponseBody !== 'boolean') return false;\n if (obj.captureAssertions !== undefined && typeof obj.captureAssertions !== 'boolean') return false;\n\n if (obj.redactHeaders !== undefined) {\n if (!Array.isArray(obj.redactHeaders)) return false;\n for (const h of obj.redactHeaders) {\n if (typeof h !== 'string') return false;\n }\n }\n\n if (obj.redactBodyFields !== undefined) {\n if (!Array.isArray(obj.redactBodyFields)) return false;\n for (const f of obj.redactBodyFields) {\n if (typeof f !== 'string') return false;\n }\n }\n\n if (obj.apiIncludeUrls !== undefined) {\n if (!Array.isArray(obj.apiIncludeUrls)) return false;\n for (const p of obj.apiIncludeUrls) {\n if (typeof p !== 'string' && !(p instanceof RegExp)) return false;\n }\n }\n\n if (obj.apiExcludeUrls !== undefined) {\n if (!Array.isArray(obj.apiExcludeUrls)) return false;\n for (const p of obj.apiExcludeUrls) {\n if (typeof p !== 'string' && !(p instanceof RegExp)) return false;\n }\n }\n\n return true;\n}\n\nexport function isValidTestRunReport(value: unknown): value is TestRunReport {\n if (typeof value !== 'object' || value === null) return false;\n\n const obj = value as Record<string, unknown>;\n\n if (typeof obj.schemaVersion !== 'string') return false;\n if (typeof obj.testRunId !== 'string') return false;\n if (typeof obj.startedAt !== 'string') return false;\n if (typeof obj.completedAt !== 'string') return false;\n if (typeof obj.totalDuration !== 'number') return false;\n if (typeof obj.summary !== 'object' || obj.summary === null) return false;\n if (!Array.isArray(obj.timeline)) return false;\n\n const summary = obj.summary as Record<string, unknown>;\n if (typeof summary.total !== 'number') return false;\n if (typeof summary.passed !== 'number') return false;\n if (typeof summary.failed !== 'number') return false;\n if (typeof summary.flaky !== 'number') return false;\n if (typeof summary.skipped !== 'number') return false;\n // timedout is optional for backward compat with schema 1.0.0\n if (summary.timedout !== undefined && typeof summary.timedout !== 'number') return false;\n\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACocO,IAAM,kBAAkB;AAGxB,IAAM,kBAAkB;AAGxB,IAAM,0BAA0B;AAGhC,SAAS,uBAAuB,KAA2C;AAChF,MAAI,OAAO,QAAQ,YAAY,QAAQ,KAAM,QAAO;AACpD,QAAM,SAAS;AACf,SACE,OAAO,kBAAkB,QACzB,OAAO,OAAO,YAAY,YAC1B,OAAO,QAAQ,SAAS,KACxB,MAAM,QAAQ,OAAO,WAAW,KAChC,MAAM,QAAQ,OAAO,eAAe,KACpC,MAAM,QAAQ,OAAO,QAAQ,KAC7B,MAAM,QAAQ,OAAO,aAAa;AAEtC;;;ACncA,IAAM,cAA0B,MAAM;AAAC;AAEhC,SAAS,aAAa,SAAiC;AAC5D,QAAM,UAAU,SAAS,WAAW;AAEpC,SAAO;AAAA,IACL,KAAK,YAAoB,MAAiB;AACxC,cAAQ,QAAQ,SAAS,IAAI;AAAA,IAC/B;AAAA,IACA,KAAK,YAAoB,MAAiB;AACxC,cAAQ,QAAQ,SAAS,IAAI;AAAA,IAC/B;AAAA,IACA,MAAM,YAAoB,MAAiB;AACzC,cAAQ,SAAS,SAAS,IAAI;AAAA,IAChC;AAAA,IACA,MAAM,YAAoB,MAAiB;AACzC,cAAQ,SAAS,SAAS,IAAI;AAAA,IAChC;AAAA,EACF;AACF;;;ACnCO,IAAM,YAAY;AAAA,EACvB,gBAAgB;AAAA,EAChB,qBAAqB;AAAA,EACrB,sBAAsB;AAAA,EACtB,mBAAmB;AAAA,EACnB,yBAAyB;AAAA,EACzB,qBAAqB;AAAA,EACrB,oBAAoB;AACtB;AAIO,IAAM,iBAAN,cAA6B,MAAM;AAAA,EAGxC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AAO,IAAI,YAAY,YAAY,IAAI,YAAY,KAAM,QAAO;AACpE,MAAI,CAAC,MAAM,QAAQ,IAAI,QAAQ,EAAG,QAAO;AAEzC,QAAM,UAAU,IAAI;AACpB,MAAI,OAAO,QAAQ,UAAU,SAAU,QAAO;AAC9C,MAAI,OAAO,QAAQ,WAAW,SAAU,QAAO;AAC/C,MAAI,OAAO,QAAQ,WAAW,SAAU,QAAO;AAC/C,MAAI,OAAO,QAAQ,UAAU,SAAU,QAAO;AAC9C,MAAI,OAAO,QAAQ,YAAY,SAAU,QAAO;AAEhD,MAAI,QAAQ,aAAa,UAAa,OAAO,QAAQ,aAAa,SAAU,QAAO;AAEnF,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/types.ts","../src/logger.ts","../src/errors.ts","../src/validation.ts"],"sourcesContent":["// @testrelic/core — barrel export\n// Re-exports only, no implementation (Constitution II)\n\nexport type {\n NavigationType,\n TestRunReport,\n Summary,\n CIMetadata,\n CIProvider,\n TimelineEntry,\n TestResult,\n TestStatus,\n TestType,\n FailureDiagnostic,\n NetworkStats,\n ResourceBreakdown,\n ResourceType,\n CapturedNetworkRequest,\n ApiCallRecord,\n ApiAssertion,\n AssertionType,\n AssertionLocation,\n ReporterConfig,\n TestArtifacts,\n NavigationAnnotation,\n MergeOptions,\n StepTestIdentity,\n ApiCallStepRequest,\n ApiCallStepResponse,\n StepAssertion,\n NavigationStep,\n ApiCallStep,\n TimelineStep,\n ActionStep,\n ActionCategory,\n TestRelicDataPayload,\n CloudConfig,\n AuthState,\n AuthMode,\n GitMetadata,\n ProjectResolution,\n QueueEntry,\n UploadStrategy,\n CloudReporterOptions,\n} from './types.js';\n\nexport {\n PAYLOAD_VERSION,\n ATTACHMENT_NAME,\n ATTACHMENT_CONTENT_TYPE,\n isTestRelicDataPayload,\n} from './types.js';\n\nexport type { Logger, LoggerOptions, LogLevel } from './logger.js';\nexport { createLogger } from './logger.js';\n\nexport { ErrorCode, TestRelicError, createError } from './errors.js';\n\nexport {\n isValidConfig,\n isValidNavigationType,\n isValidTestRunReport,\n isValidCloudConfig,\n isValidApiKeyFormat,\n isValidEndpointUrl,\n isValidUploadStrategy,\n isValidQueueEntry,\n} from './validation.js';\n","/**\n * @testrelic/core — Shared type definitions\n *\n * All interfaces for the JSON output schema, reporter configuration,\n * and internal fixture-to-reporter communication.\n *\n * Schema Version: 1.0.0\n */\n\n// ---------------------------------------------------------------------------\n// Navigation Types\n// ---------------------------------------------------------------------------\n\nexport type NavigationType =\n | 'goto'\n | 'navigation'\n | 'back'\n | 'forward'\n | 'refresh'\n | 'spa_route'\n | 'spa_replace'\n | 'hash_change'\n | 'link_click'\n | 'form_submit'\n | 'redirect'\n | 'popstate'\n | 'page_load'\n | 'manual_record'\n | 'fallback'\n | 'dummy';\n\n// ---------------------------------------------------------------------------\n// Output Schema Types (JSON report structure)\n// ---------------------------------------------------------------------------\n\nexport interface TestRunReport {\n readonly schemaVersion: string;\n readonly testRunId: string;\n readonly startedAt: string;\n readonly completedAt: string;\n readonly totalDuration: number;\n readonly summary: Summary;\n readonly ci: CIMetadata | null;\n readonly metadata: Record<string, unknown> | null;\n readonly timeline: readonly (TimelineEntry | TimelineStep)[];\n readonly shardRunIds: string[] | null;\n}\n\n/** Breakdown of API calls by HTTP response status range. */\nexport interface ApiCallsByStatusRange {\n readonly '2xx': number;\n readonly '3xx': number;\n readonly '4xx': number;\n readonly '5xx': number;\n readonly error: number;\n}\n\n/** Statistical distribution of API call response times in milliseconds. */\nexport interface ApiResponseTimeStats {\n readonly avg: number;\n readonly min: number;\n readonly max: number;\n readonly p50: number;\n readonly p95: number;\n readonly p99: number;\n}\n\nexport interface Summary {\n readonly total: number;\n readonly passed: number;\n readonly failed: number;\n readonly flaky: number;\n readonly skipped: number;\n readonly timedout: number;\n readonly totalApiCalls: number;\n readonly uniqueApiUrls: number;\n readonly apiCallsByMethod: Record<string, number>;\n readonly apiCallsByStatusRange: ApiCallsByStatusRange;\n readonly apiResponseTime: ApiResponseTimeStats | null;\n readonly totalAssertions: number;\n readonly passedAssertions: number;\n readonly failedAssertions: number;\n readonly totalNavigations: number;\n readonly uniqueNavigationUrls: number;\n readonly totalTimelineSteps: number;\n readonly totalActionSteps: number;\n readonly actionStepsByCategory: Record<string, number>;\n}\n\nexport interface CIMetadata {\n readonly provider: CIProvider;\n readonly buildId: string | null;\n readonly commitSha: string | null;\n readonly branch: string | null;\n readonly runUrl: string | null;\n}\n\nexport type CIProvider =\n | 'github-actions'\n | 'gitlab-ci'\n | 'jenkins'\n | 'circleci'\n | 'bitbucket-pipelines'\n | 'unknown';\n\nexport interface TimelineEntry {\n readonly url: string;\n readonly navigationType: NavigationType;\n readonly visitedAt: string;\n readonly duration: number;\n readonly specFile: string;\n readonly domContentLoadedAt: string | null;\n readonly networkIdleAt: string | null;\n readonly networkStats: NetworkStats | null;\n readonly tests: TestResult[];\n}\n\nexport interface TestResult {\n readonly title: string;\n readonly status: TestStatus;\n readonly duration: number;\n readonly startedAt: string;\n readonly completedAt: string;\n readonly retryCount: number;\n readonly tags: string[];\n readonly failure: FailureDiagnostic | null;\n readonly testId: string;\n readonly filePath: string;\n readonly suiteName: string;\n readonly testType: TestType;\n readonly isFlaky: boolean;\n readonly retryStatus: string | null;\n readonly expectedStatus: TestStatus;\n readonly actualStatus: TestStatus;\n readonly artifacts: TestArtifacts | null;\n readonly networkRequests: CapturedNetworkRequest[] | null;\n readonly apiCalls: readonly ApiCallRecord[] | null;\n readonly apiAssertions: readonly ApiAssertion[] | null;\n readonly actions: readonly ActionStep[] | null;\n}\n\nexport type ResourceType = 'xhr' | 'document' | 'script' | 'stylesheet' | 'image' | 'font' | 'other';\n\nexport interface CapturedNetworkRequest {\n readonly url: string;\n readonly method: string;\n readonly resourceType: ResourceType;\n readonly statusCode: number;\n readonly responseTimeMs: number;\n readonly startedAt: string;\n readonly requestHeaders: Record<string, string> | null;\n readonly requestBody: string | null;\n readonly responseBody: string | null;\n readonly responseHeaders: Record<string, string> | null;\n readonly contentType: string | null;\n readonly responseSize: number;\n readonly requestBodyTruncated: boolean;\n readonly responseBodyTruncated: boolean;\n readonly isBinary: boolean;\n readonly error: string | null;\n}\n\nexport interface TestArtifacts {\n readonly screenshot?: string;\n readonly video?: string;\n}\n\nexport type TestStatus = 'passed' | 'failed' | 'skipped' | 'flaky' | 'timedout';\n\nexport type TestType = 'e2e' | 'api' | 'unit' | 'unknown';\n\nexport interface FailureDiagnostic {\n readonly message: string;\n readonly line: number | null;\n readonly code: string | null;\n readonly stack: string | null;\n}\n\nexport interface NetworkStats {\n readonly totalRequests: number;\n readonly failedRequests: number;\n readonly failedRequestUrls: string[];\n readonly totalBytes: number;\n readonly byType: ResourceBreakdown;\n}\n\nexport interface ResourceBreakdown {\n readonly xhr: number;\n readonly document: number;\n readonly script: number;\n readonly stylesheet: number;\n readonly image: number;\n readonly font: number;\n readonly other: number;\n}\n\n// ---------------------------------------------------------------------------\n// API Call Record (captured from Playwright APIRequestContext proxy)\n// ---------------------------------------------------------------------------\n\nexport interface ApiCallRecord {\n /** Unique call identifier within the test (e.g., \"api-call-0\") */\n readonly id: string;\n /** ISO 8601 timestamp when the call was initiated */\n readonly timestamp: string;\n /** HTTP method: GET, POST, PUT, PATCH, DELETE, HEAD, or custom via fetch() */\n readonly method: string;\n /** Full resolved URL (after baseURL resolution by Playwright) */\n readonly url: string;\n /** All request headers sent, or null if unavailable */\n readonly requestHeaders: Record<string, string> | null;\n /** Request payload as string (JSON-serialized for objects). Null for bodiless methods */\n readonly requestBody: string | null;\n /** HTTP response status code, or null if request errored before response */\n readonly responseStatusCode: number | null;\n /** HTTP response status text, or null if request errored before response */\n readonly responseStatusText: string | null;\n /** All response headers received, or null if request errored before response */\n readonly responseHeaders: Record<string, string> | null;\n /** Response body: string for text/JSON, base64 for binary. Null on error */\n readonly responseBody: string | null;\n /** Duration in milliseconds from request initiation to response received */\n readonly responseTimeMs: number;\n /** Whether the response body is stored as a base64-encoded binary string */\n readonly isBinary: boolean;\n /** Error message if the call failed (network error, timeout), null on success */\n readonly error: string | null;\n}\n\n// ---------------------------------------------------------------------------\n// API Assertion Types (captured from assertion tracking)\n// ---------------------------------------------------------------------------\n\n/** Categorization of the assertion being made. */\nexport type AssertionType =\n | 'status'\n | 'statusOk'\n | 'header'\n | 'bodyField'\n | 'bodyMatch'\n | 'bodyContains'\n | 'custom';\n\n/** Source location where an assertion was made in the test file. */\nexport interface AssertionLocation {\n /** Absolute or relative file path to the test file */\n readonly file: string;\n /** Line number (1-based) */\n readonly line: number;\n /** Column number (1-based), if available */\n readonly column?: number;\n}\n\n/** A single captured assertion on API response data. */\nexport interface ApiAssertion {\n /** Links to ApiCallRecord.id from the API proxy */\n readonly callId: string;\n /** Category of assertion */\n readonly type: AssertionType;\n /** What the test expected */\n readonly expected: unknown;\n /** What was actually received */\n readonly actual: unknown;\n /** Whether the assertion passed or failed */\n readonly status: 'passed' | 'failed';\n /** Source location of the assertion in the test file */\n readonly location: AssertionLocation;\n /** String representation of the assertion expression (best-effort) */\n readonly expression?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Unified Timeline Types (navigation + API call steps)\n// ---------------------------------------------------------------------------\n\n/** Test identity block attached to every timeline step. */\nexport interface StepTestIdentity {\n readonly title: string;\n readonly fullTitle: readonly string[];\n readonly status: TestStatus;\n readonly duration: number;\n readonly retries: number;\n readonly retry: number;\n readonly tags: readonly string[];\n readonly failure: FailureDiagnostic | null;\n}\n\n/** Request details within an API call step. */\nexport interface ApiCallStepRequest {\n readonly headers: Record<string, string> | null;\n readonly body: unknown;\n}\n\n/** Response details within an API call step. */\nexport interface ApiCallStepResponse {\n readonly statusCode: number;\n readonly statusText: string;\n readonly headers: Record<string, string> | null;\n readonly body: unknown;\n}\n\n/** An assertion linked to an API call step (callId omitted — implicit from parent). */\nexport interface StepAssertion {\n readonly type: AssertionType;\n readonly expected: unknown;\n readonly actual: unknown;\n readonly status: 'passed' | 'failed';\n readonly location: AssertionLocation;\n readonly expression?: string;\n}\n\n/** A browser navigation event in the unified timeline. */\nexport interface NavigationStep {\n readonly index: number;\n readonly type: 'navigation';\n readonly url: string;\n readonly timestamp: string;\n readonly durationOnUrl: number;\n readonly navigationType: NavigationType;\n readonly domContentLoadedAt: string | null;\n readonly networkIdleAt: string | null;\n readonly networkStats: NetworkStats | null;\n readonly specFile: string;\n readonly test: StepTestIdentity;\n}\n\n/** An API request event in the unified timeline. */\nexport interface ApiCallStep {\n readonly index: number;\n readonly type: 'api_call';\n readonly callId: string;\n readonly method: string;\n readonly url: string;\n readonly timestamp: string;\n readonly responseTime: number | null;\n readonly request: ApiCallStepRequest;\n readonly response: ApiCallStepResponse | null;\n readonly error?: string | null;\n readonly assertions: readonly StepAssertion[];\n readonly specFile: string;\n readonly test: StepTestIdentity;\n}\n\n/** Discriminated union of all timeline step types. */\nexport type TimelineStep = NavigationStep | ApiCallStep;\n\n// ---------------------------------------------------------------------------\n// Action Step Types (Playwright test step capture)\n// ---------------------------------------------------------------------------\n\n/** Categorized type of a captured test action. */\nexport type ActionCategory = 'ui_action' | 'assertion' | 'custom_step';\n\n/** A single captured test action step. */\nexport interface ActionStep {\n readonly title: string;\n readonly category: ActionCategory;\n readonly timestamp: string;\n readonly duration: number;\n readonly videoOffset: number | null;\n readonly status: 'passed' | 'failed';\n readonly error: string | null;\n readonly children: readonly ActionStep[];\n}\n\n// ---------------------------------------------------------------------------\n// Configuration Types (reporter tuple options)\n// ---------------------------------------------------------------------------\n\nexport interface ReporterConfig {\n readonly outputPath?: string;\n readonly includeStackTrace?: boolean;\n readonly includeCodeSnippets?: boolean;\n readonly codeContextLines?: number;\n readonly includeNetworkStats?: boolean;\n readonly navigationTypes?: NavigationType[] | null;\n readonly redactPatterns?: (string | RegExp)[];\n readonly testRunId?: string | null;\n readonly metadata?: Record<string, unknown> | null;\n readonly openReport?: boolean;\n readonly htmlReportPath?: string;\n readonly includeArtifacts?: boolean;\n /** When false, disables API call interception in the unified fixture. Default: true */\n readonly trackApiCalls?: boolean;\n /** When true, suppresses console summary output. Default: false */\n readonly quiet?: boolean;\n /** When true, captures Playwright test steps (actions). Default: true */\n readonly includeActionSteps?: boolean;\n /** Capture request headers for API calls. Default: true */\n readonly captureRequestHeaders?: boolean;\n /** Capture response headers for API calls. Default: true */\n readonly captureResponseHeaders?: boolean;\n /** Capture request body for API calls. Default: true */\n readonly captureRequestBody?: boolean;\n /** Capture response body for API calls. Default: true */\n readonly captureResponseBody?: boolean;\n /** Capture API assertions (both pass and fail). Default: true */\n readonly captureAssertions?: boolean;\n /**\n * Header names whose values are replaced with \"[REDACTED]\".\n * Case-insensitive matching. Default: ['authorization', 'cookie', 'set-cookie', 'x-api-key']\n */\n readonly redactHeaders?: string[];\n /**\n * Body field names whose values are replaced with \"[REDACTED]\" at any depth.\n * Default: ['password', 'secret', 'token', 'apiKey', 'api_key']\n */\n readonly redactBodyFields?: string[];\n /**\n * Only track API calls matching these URL patterns.\n * Default: undefined (track all)\n */\n readonly apiIncludeUrls?: (string | RegExp)[];\n /**\n * Exclude API calls matching these URL patterns. Takes precedence over include.\n * Default: undefined (exclude none)\n */\n readonly apiExcludeUrls?: (string | RegExp)[];\n /** Cloud integration configuration. Default: undefined (local mode) */\n readonly cloud?: CloudReporterOptions;\n}\n\n// ---------------------------------------------------------------------------\n// Internal Types (fixture → reporter communication)\n// ---------------------------------------------------------------------------\n\nexport interface NavigationAnnotation {\n readonly url: string;\n readonly navigationType: NavigationType;\n readonly timestamp: string;\n readonly domContentLoadedAt?: string;\n readonly networkIdleAt?: string;\n readonly networkStats?: NetworkStats;\n}\n\n// ---------------------------------------------------------------------------\n// Worker-Safe Data Payload (worker → reporter communication)\n// ---------------------------------------------------------------------------\n\n/** Consolidated data payload sent from a worker fixture to the reporter. */\nexport interface TestRelicDataPayload {\n /** Marker to identify TestRelic attachments. Always `true`. */\n readonly testRelicData: true;\n /** Payload format version (semver). */\n readonly version: string;\n /** Navigation events collected during the test. */\n readonly navigations: readonly NavigationAnnotation[];\n /** Captured network requests during the test. */\n readonly networkRequests: readonly CapturedNetworkRequest[];\n /** API calls made via APIRequestContext proxy. */\n readonly apiCalls: readonly ApiCallRecord[];\n /** Assertions captured on API responses. */\n readonly apiAssertions: readonly ApiAssertion[];\n}\n\n/** Current payload format version. */\nexport const PAYLOAD_VERSION = '1.0.0';\n\n/** Attachment name used for the consolidated payload. */\nexport const ATTACHMENT_NAME = 'testrelic-data';\n\n/** Attachment content type. */\nexport const ATTACHMENT_CONTENT_TYPE = 'application/json';\n\n/** Type guard: validates that a parsed object is a TestRelicDataPayload. */\nexport function isTestRelicDataPayload(obj: unknown): obj is TestRelicDataPayload {\n if (typeof obj !== 'object' || obj === null) return false;\n const record = obj as Record<string, unknown>;\n return (\n record.testRelicData === true &&\n typeof record.version === 'string' &&\n record.version.length > 0 &&\n Array.isArray(record.navigations) &&\n Array.isArray(record.networkRequests) &&\n Array.isArray(record.apiCalls) &&\n Array.isArray(record.apiAssertions)\n );\n}\n\n// ---------------------------------------------------------------------------\n// Cloud Integration Types\n// ---------------------------------------------------------------------------\n\n/** Upload strategy for cloud timeline data. */\nexport type UploadStrategy = 'batch' | 'realtime' | 'both';\n\n/** Current cloud/local operating mode. */\nexport type AuthMode = 'cloud' | 'local' | 'pending';\n\n/** Resolved cloud configuration, immutable after initialization. */\nexport interface CloudConfig {\n readonly apiKey: string | null;\n readonly endpoint: string;\n readonly uploadStrategy: UploadStrategy;\n readonly timeout: number;\n readonly projectName: string | null;\n readonly queueMaxAge: number;\n readonly queueDirectory: string;\n}\n\n/** Mutable auth state tracked by the cloud client. */\nexport interface AuthState {\n mode: AuthMode;\n accessToken: string | null;\n refreshToken: string | null;\n expiresAt: number | null;\n orgId: string | null;\n orgName: string | null;\n userId: string | null;\n userName: string | null;\n}\n\n/** Auto-collected git information. All fields nullable. */\nexport interface GitMetadata {\n readonly branch: string | null;\n readonly commitSha: string | null;\n readonly commitMessage: string | null;\n readonly remoteUrl: string | null;\n}\n\n/** Cached project identity. */\nexport interface ProjectResolution {\n readonly projectId: string;\n readonly gitId: string;\n readonly displayName: string;\n readonly resolvedAt: number;\n readonly apiKeyHash: string;\n}\n\n/** A single queued upload payload. */\nexport interface QueueEntry {\n readonly version: string;\n readonly queuedAt: string;\n readonly reason: string;\n readonly retryCount: number;\n readonly targetEndpoint: string;\n readonly method: string;\n readonly payload: Record<string, unknown>;\n readonly headers: Record<string, string>;\n}\n\n/** Inline cloud configuration accepted via reporter options. */\nexport interface CloudReporterOptions {\n readonly apiKey?: string;\n readonly endpoint?: string;\n readonly upload?: UploadStrategy;\n readonly timeout?: number;\n readonly projectName?: string;\n readonly queueMaxAge?: string;\n readonly queueDirectory?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Merge CLI Types\n// ---------------------------------------------------------------------------\n\nexport interface MergeOptions {\n readonly output: string;\n readonly testRunId?: string;\n}\n","/**\n * @testrelic/core — Configurable logger\n *\n * Provides a Logger interface with a no-op default.\n * Never uses console.* directly (Constitution SDK Constraint).\n */\n\nexport interface Logger {\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n debug(message: string, ...args: unknown[]): void;\n}\n\nexport interface LoggerOptions {\n readonly handler?: (level: LogLevel, message: string, args: unknown[]) => void;\n}\n\nexport type LogLevel = 'info' | 'warn' | 'error' | 'debug';\n\ntype LogHandler = (level: LogLevel, message: string, args: unknown[]) => void;\n\nconst noopHandler: LogHandler = () => {};\n\nexport function createLogger(options?: LoggerOptions): Logger {\n const handler = options?.handler ?? noopHandler;\n\n return {\n info(message: string, ...args: unknown[]) {\n handler('info', message, args);\n },\n warn(message: string, ...args: unknown[]) {\n handler('warn', message, args);\n },\n error(message: string, ...args: unknown[]) {\n handler('error', message, args);\n },\n debug(message: string, ...args: unknown[]) {\n handler('debug', message, args);\n },\n };\n}\n","/**\n * @testrelic/core — Structured error factory\n *\n * Machine-readable error codes for programmatic handling.\n */\n\nexport const ErrorCode = {\n CONFIG_INVALID: 'TESTRELIC_CONFIG_INVALID',\n OUTPUT_WRITE_FAILED: 'TESTRELIC_OUTPUT_WRITE_FAILED',\n MERGE_INVALID_SCHEMA: 'TESTRELIC_MERGE_INVALID_SCHEMA',\n MERGE_READ_FAILED: 'TESTRELIC_MERGE_READ_FAILED',\n NAVIGATION_FLUSH_FAILED: 'TESTRELIC_NAVIGATION_FLUSH_FAILED',\n CODE_EXTRACT_FAILED: 'TESTRELIC_CODE_EXTRACT_FAILED',\n HTML_REPORT_FAILED: 'TESTRELIC_HTML_REPORT_FAILED',\n CLOUD_AUTH_FAILED: 'TESTRELIC_CLOUD_AUTH_FAILED',\n CLOUD_UPLOAD_FAILED: 'TESTRELIC_CLOUD_UPLOAD_FAILED',\n CLOUD_CONFIG_INVALID: 'TESTRELIC_CLOUD_CONFIG_INVALID',\n CLOUD_QUEUE_FAILED: 'TESTRELIC_CLOUD_QUEUE_FAILED',\n} as const;\n\nexport type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];\n\nexport class TestRelicError extends Error {\n readonly code: ErrorCode;\n\n constructor(code: ErrorCode, message: string, cause?: unknown) {\n super(message);\n this.name = 'TestRelicError';\n this.code = code;\n if (cause !== undefined) {\n Object.defineProperty(this, 'cause', { value: cause, writable: false, enumerable: false });\n }\n }\n}\n\nexport function createError(\n code: ErrorCode,\n message: string,\n cause?: unknown,\n): TestRelicError {\n return new TestRelicError(code, message, cause);\n}\n","/**\n * @testrelic/core — Lightweight runtime type guards\n *\n * Hand-written guards, no runtime schema libraries (Constitution SDK Constraint).\n */\n\nimport type {\n ReporterConfig,\n NavigationType,\n TestRunReport,\n CloudConfig,\n QueueEntry,\n UploadStrategy,\n} from './types.js';\n\nconst NAVIGATION_TYPES = new Set<string>([\n 'goto', 'navigation', 'back', 'forward', 'refresh',\n 'spa_route', 'spa_replace', 'hash_change', 'link_click',\n 'form_submit', 'redirect', 'popstate', 'page_load',\n 'manual_record', 'fallback', 'dummy',\n]);\n\nconst DANGEROUS_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport function isValidNavigationType(value: unknown): value is NavigationType {\n return typeof value === 'string' && NAVIGATION_TYPES.has(value);\n}\n\nfunction hasNoPrototypePollution(obj: unknown): boolean {\n if (typeof obj !== 'object' || obj === null) return true;\n for (const key of Object.keys(obj)) {\n if (DANGEROUS_KEYS.has(key)) return false;\n }\n return true;\n}\n\nexport function isValidConfig(input: unknown): input is ReporterConfig {\n if (typeof input !== 'object' || input === null) return false;\n if (!hasNoPrototypePollution(input)) return false;\n\n const obj = input as Record<string, unknown>;\n\n if (obj.outputPath !== undefined && typeof obj.outputPath !== 'string') return false;\n if (obj.includeStackTrace !== undefined && typeof obj.includeStackTrace !== 'boolean') return false;\n if (obj.includeCodeSnippets !== undefined && typeof obj.includeCodeSnippets !== 'boolean') return false;\n if (obj.codeContextLines !== undefined && typeof obj.codeContextLines !== 'number') return false;\n if (obj.includeNetworkStats !== undefined && typeof obj.includeNetworkStats !== 'boolean') return false;\n\n if (obj.navigationTypes !== undefined && obj.navigationTypes !== null) {\n if (!Array.isArray(obj.navigationTypes)) return false;\n for (const t of obj.navigationTypes) {\n if (!isValidNavigationType(t)) return false;\n }\n }\n\n if (obj.redactPatterns !== undefined) {\n if (!Array.isArray(obj.redactPatterns)) return false;\n for (const p of obj.redactPatterns) {\n if (typeof p !== 'string' && !(p instanceof RegExp)) return false;\n }\n }\n\n if (obj.testRunId !== undefined && obj.testRunId !== null && typeof obj.testRunId !== 'string') return false;\n\n if (obj.metadata !== undefined && obj.metadata !== null) {\n if (typeof obj.metadata !== 'object') return false;\n if (!hasNoPrototypePollution(obj.metadata)) return false;\n }\n\n if (obj.openReport !== undefined && typeof obj.openReport !== 'boolean') return false;\n if (obj.htmlReportPath !== undefined && (typeof obj.htmlReportPath !== 'string' || obj.htmlReportPath === '')) return false;\n if (obj.includeArtifacts !== undefined && typeof obj.includeArtifacts !== 'boolean') return false;\n\n // API tracking configuration\n if (obj.trackApiCalls !== undefined && typeof obj.trackApiCalls !== 'boolean') return false;\n if (obj.captureRequestHeaders !== undefined && typeof obj.captureRequestHeaders !== 'boolean') return false;\n if (obj.captureResponseHeaders !== undefined && typeof obj.captureResponseHeaders !== 'boolean') return false;\n if (obj.captureRequestBody !== undefined && typeof obj.captureRequestBody !== 'boolean') return false;\n if (obj.captureResponseBody !== undefined && typeof obj.captureResponseBody !== 'boolean') return false;\n if (obj.captureAssertions !== undefined && typeof obj.captureAssertions !== 'boolean') return false;\n\n if (obj.redactHeaders !== undefined) {\n if (!Array.isArray(obj.redactHeaders)) return false;\n for (const h of obj.redactHeaders) {\n if (typeof h !== 'string') return false;\n }\n }\n\n if (obj.redactBodyFields !== undefined) {\n if (!Array.isArray(obj.redactBodyFields)) return false;\n for (const f of obj.redactBodyFields) {\n if (typeof f !== 'string') return false;\n }\n }\n\n if (obj.apiIncludeUrls !== undefined) {\n if (!Array.isArray(obj.apiIncludeUrls)) return false;\n for (const p of obj.apiIncludeUrls) {\n if (typeof p !== 'string' && !(p instanceof RegExp)) return false;\n }\n }\n\n if (obj.apiExcludeUrls !== undefined) {\n if (!Array.isArray(obj.apiExcludeUrls)) return false;\n for (const p of obj.apiExcludeUrls) {\n if (typeof p !== 'string' && !(p instanceof RegExp)) return false;\n }\n }\n\n return true;\n}\n\n// ---------------------------------------------------------------------------\n// Cloud Config Validation\n// ---------------------------------------------------------------------------\n\nconst API_KEY_PATTERN = /^tr[a-z]*_[a-z]+_[a-zA-Z0-9]+$/;\n\nconst UPLOAD_STRATEGIES = new Set<string>(['batch', 'realtime', 'both']);\n\nconst LOCALHOST_HOSTS = new Set(['localhost', '127.0.0.1', '0.0.0.0']);\n\nexport function isValidApiKeyFormat(value: unknown): value is string {\n return typeof value === 'string' && API_KEY_PATTERN.test(value);\n}\n\nexport function isValidUploadStrategy(value: unknown): value is UploadStrategy {\n return typeof value === 'string' && UPLOAD_STRATEGIES.has(value);\n}\n\nexport function isValidEndpointUrl(value: unknown): boolean {\n if (typeof value !== 'string') return false;\n try {\n const url = new URL(value);\n if (url.protocol === 'https:') return true;\n if (url.protocol === 'http:' && LOCALHOST_HOSTS.has(url.hostname)) return true;\n return false;\n } catch {\n return false;\n }\n}\n\nexport function isValidCloudConfig(input: unknown): input is CloudConfig {\n if (typeof input !== 'object' || input === null) return false;\n if (!hasNoPrototypePollution(input)) return false;\n\n const obj = input as Record<string, unknown>;\n\n if (obj.apiKey !== undefined && obj.apiKey !== null) {\n if (typeof obj.apiKey !== 'string') return false;\n if (obj.apiKey.length > 0 && !isValidApiKeyFormat(obj.apiKey)) return false;\n }\n\n if (obj.endpoint !== undefined) {\n if (!isValidEndpointUrl(obj.endpoint)) return false;\n }\n\n if (obj.uploadStrategy !== undefined) {\n if (!isValidUploadStrategy(obj.uploadStrategy)) return false;\n }\n\n if (obj.timeout !== undefined) {\n if (typeof obj.timeout !== 'number' || obj.timeout < 1000 || obj.timeout > 120000) return false;\n }\n\n if (obj.projectName !== undefined && obj.projectName !== null && typeof obj.projectName !== 'string') return false;\n\n if (obj.queueMaxAge !== undefined) {\n if (typeof obj.queueMaxAge !== 'number' || obj.queueMaxAge < 3600000 || obj.queueMaxAge > 2592000000) return false;\n }\n\n if (obj.queueDirectory !== undefined) {\n if (typeof obj.queueDirectory !== 'string') return false;\n if (obj.queueDirectory.startsWith('/') || obj.queueDirectory.includes('..')) return false;\n }\n\n return true;\n}\n\nexport function isValidQueueEntry(input: unknown): input is QueueEntry {\n if (typeof input !== 'object' || input === null) return false;\n if (!hasNoPrototypePollution(input)) return false;\n\n const obj = input as Record<string, unknown>;\n\n if (typeof obj.version !== 'string') return false;\n if (typeof obj.queuedAt !== 'string') return false;\n if (typeof obj.reason !== 'string') return false;\n if (typeof obj.retryCount !== 'number') return false;\n if (typeof obj.targetEndpoint !== 'string') return false;\n if (typeof obj.method !== 'string') return false;\n if (typeof obj.payload !== 'object' || obj.payload === null) return false;\n if (typeof obj.headers !== 'object' || obj.headers === null) return false;\n\n return true;\n}\n\nexport function isValidTestRunReport(value: unknown): value is TestRunReport {\n if (typeof value !== 'object' || value === null) return false;\n\n const obj = value as Record<string, unknown>;\n\n if (typeof obj.schemaVersion !== 'string') return false;\n if (typeof obj.testRunId !== 'string') return false;\n if (typeof obj.startedAt !== 'string') return false;\n if (typeof obj.completedAt !== 'string') return false;\n if (typeof obj.totalDuration !== 'number') return false;\n if (typeof obj.summary !== 'object' || obj.summary === null) return false;\n if (!Array.isArray(obj.timeline)) return false;\n\n const summary = obj.summary as Record<string, unknown>;\n if (typeof summary.total !== 'number') return false;\n if (typeof summary.passed !== 'number') return false;\n if (typeof summary.failed !== 'number') return false;\n if (typeof summary.flaky !== 'number') return false;\n if (typeof summary.skipped !== 'number') return false;\n // timedout is optional for backward compat with schema 1.0.0\n if (summary.timedout !== undefined && typeof summary.timedout !== 'number') return false;\n\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACwcO,IAAM,kBAAkB;AAGxB,IAAM,kBAAkB;AAGxB,IAAM,0BAA0B;AAGhC,SAAS,uBAAuB,KAA2C;AAChF,MAAI,OAAO,QAAQ,YAAY,QAAQ,KAAM,QAAO;AACpD,QAAM,SAAS;AACf,SACE,OAAO,kBAAkB,QACzB,OAAO,OAAO,YAAY,YAC1B,OAAO,QAAQ,SAAS,KACxB,MAAM,QAAQ,OAAO,WAAW,KAChC,MAAM,QAAQ,OAAO,eAAe,KACpC,MAAM,QAAQ,OAAO,QAAQ,KAC7B,MAAM,QAAQ,OAAO,aAAa;AAEtC;;;ACvcA,IAAM,cAA0B,MAAM;AAAC;AAEhC,SAAS,aAAa,SAAiC;AAC5D,QAAM,UAAU,SAAS,WAAW;AAEpC,SAAO;AAAA,IACL,KAAK,YAAoB,MAAiB;AACxC,cAAQ,QAAQ,SAAS,IAAI;AAAA,IAC/B;AAAA,IACA,KAAK,Y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AI,OAAO,IAAI,kBAAkB,SAAU,QAAO;AAClD,MAAI,OAAO,IAAI,cAAc,SAAU,QAAO;AAC9C,MAAI,OAAO,IAAI,cAAc,SAAU,QAAO;AAC9C,MAAI,OAAO,IAAI,gBAAgB,SAAU,QAAO;AAChD,MAAI,OAAO,IAAI,kBAAkB,SAAU,QAAO;AAClD,MAAI,OAAO,IAAI,YAAY,YAAY,IAAI,YAAY,KAAM,QAAO;AACpE,MAAI,CAAC,MAAM,QAAQ,IAAI,QAAQ,EAAG,QAAO;AAEzC,QAAM,UAAU,IAAI;AACpB,MAAI,OAAO,QAAQ,UAAU,SAAU,QAAO;AAC9C,MAAI,OAAO,QAAQ,WAAW,SAAU,QAAO;AAC/C,MAAI,OAAO,QAAQ,WAAW,SAAU,QAAO;AAC/C,MAAI,OAAO,QAAQ,UAAU,SAAU,QAAO;AAC9C,MAAI,OAAO,QAAQ,YAAY,SAAU,QAAO;AAEhD,MAAI,QAAQ,aAAa,UAAa,OAAO,QAAQ,aAAa,SAAU,QAAO;AAEnF,SAAO;AACT;","names":[]}
package/dist/index.d.cts CHANGED
@@ -62,8 +62,9 @@ interface CIMetadata {
62
62
  readonly buildId: string | null;
63
63
  readonly commitSha: string | null;
64
64
  readonly branch: string | null;
65
+ readonly runUrl: string | null;
65
66
  }
66
- type CIProvider = 'github-actions' | 'gitlab-ci' | 'jenkins' | 'circleci' | 'unknown';
67
+ type CIProvider = 'github-actions' | 'gitlab-ci' | 'jenkins' | 'circleci' | 'bitbucket-pipelines' | 'unknown';
67
68
  interface TimelineEntry {
68
69
  readonly url: string;
69
70
  readonly navigationType: NavigationType;
@@ -327,6 +328,8 @@ interface ReporterConfig {
327
328
  * Default: undefined (exclude none)
328
329
  */
329
330
  readonly apiExcludeUrls?: (string | RegExp)[];
331
+ /** Cloud integration configuration. Default: undefined (local mode) */
332
+ readonly cloud?: CloudReporterOptions;
330
333
  }
331
334
  interface NavigationAnnotation {
332
335
  readonly url: string;
@@ -359,6 +362,67 @@ declare const ATTACHMENT_NAME = "testrelic-data";
359
362
  declare const ATTACHMENT_CONTENT_TYPE = "application/json";
360
363
  /** Type guard: validates that a parsed object is a TestRelicDataPayload. */
361
364
  declare function isTestRelicDataPayload(obj: unknown): obj is TestRelicDataPayload;
365
+ /** Upload strategy for cloud timeline data. */
366
+ type UploadStrategy = 'batch' | 'realtime' | 'both';
367
+ /** Current cloud/local operating mode. */
368
+ type AuthMode = 'cloud' | 'local' | 'pending';
369
+ /** Resolved cloud configuration, immutable after initialization. */
370
+ interface CloudConfig {
371
+ readonly apiKey: string | null;
372
+ readonly endpoint: string;
373
+ readonly uploadStrategy: UploadStrategy;
374
+ readonly timeout: number;
375
+ readonly projectName: string | null;
376
+ readonly queueMaxAge: number;
377
+ readonly queueDirectory: string;
378
+ }
379
+ /** Mutable auth state tracked by the cloud client. */
380
+ interface AuthState {
381
+ mode: AuthMode;
382
+ accessToken: string | null;
383
+ refreshToken: string | null;
384
+ expiresAt: number | null;
385
+ orgId: string | null;
386
+ orgName: string | null;
387
+ userId: string | null;
388
+ userName: string | null;
389
+ }
390
+ /** Auto-collected git information. All fields nullable. */
391
+ interface GitMetadata {
392
+ readonly branch: string | null;
393
+ readonly commitSha: string | null;
394
+ readonly commitMessage: string | null;
395
+ readonly remoteUrl: string | null;
396
+ }
397
+ /** Cached project identity. */
398
+ interface ProjectResolution {
399
+ readonly projectId: string;
400
+ readonly gitId: string;
401
+ readonly displayName: string;
402
+ readonly resolvedAt: number;
403
+ readonly apiKeyHash: string;
404
+ }
405
+ /** A single queued upload payload. */
406
+ interface QueueEntry {
407
+ readonly version: string;
408
+ readonly queuedAt: string;
409
+ readonly reason: string;
410
+ readonly retryCount: number;
411
+ readonly targetEndpoint: string;
412
+ readonly method: string;
413
+ readonly payload: Record<string, unknown>;
414
+ readonly headers: Record<string, string>;
415
+ }
416
+ /** Inline cloud configuration accepted via reporter options. */
417
+ interface CloudReporterOptions {
418
+ readonly apiKey?: string;
419
+ readonly endpoint?: string;
420
+ readonly upload?: UploadStrategy;
421
+ readonly timeout?: number;
422
+ readonly projectName?: string;
423
+ readonly queueMaxAge?: string;
424
+ readonly queueDirectory?: string;
425
+ }
362
426
  interface MergeOptions {
363
427
  readonly output: string;
364
428
  readonly testRunId?: string;
@@ -395,6 +459,10 @@ declare const ErrorCode: {
395
459
  readonly NAVIGATION_FLUSH_FAILED: "TESTRELIC_NAVIGATION_FLUSH_FAILED";
396
460
  readonly CODE_EXTRACT_FAILED: "TESTRELIC_CODE_EXTRACT_FAILED";
397
461
  readonly HTML_REPORT_FAILED: "TESTRELIC_HTML_REPORT_FAILED";
462
+ readonly CLOUD_AUTH_FAILED: "TESTRELIC_CLOUD_AUTH_FAILED";
463
+ readonly CLOUD_UPLOAD_FAILED: "TESTRELIC_CLOUD_UPLOAD_FAILED";
464
+ readonly CLOUD_CONFIG_INVALID: "TESTRELIC_CLOUD_CONFIG_INVALID";
465
+ readonly CLOUD_QUEUE_FAILED: "TESTRELIC_CLOUD_QUEUE_FAILED";
398
466
  };
399
467
  type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
400
468
  declare class TestRelicError extends Error {
@@ -411,6 +479,11 @@ declare function createError(code: ErrorCode, message: string, cause?: unknown):
411
479
 
412
480
  declare function isValidNavigationType(value: unknown): value is NavigationType;
413
481
  declare function isValidConfig(input: unknown): input is ReporterConfig;
482
+ declare function isValidApiKeyFormat(value: unknown): value is string;
483
+ declare function isValidUploadStrategy(value: unknown): value is UploadStrategy;
484
+ declare function isValidEndpointUrl(value: unknown): boolean;
485
+ declare function isValidCloudConfig(input: unknown): input is CloudConfig;
486
+ declare function isValidQueueEntry(input: unknown): input is QueueEntry;
414
487
  declare function isValidTestRunReport(value: unknown): value is TestRunReport;
415
488
 
416
- export { ATTACHMENT_CONTENT_TYPE, ATTACHMENT_NAME, type ActionCategory, type ActionStep, type ApiAssertion, type ApiCallRecord, type ApiCallStep, type ApiCallStepRequest, type ApiCallStepResponse, type AssertionLocation, type AssertionType, type CIMetadata, type CIProvider, type CapturedNetworkRequest, ErrorCode, type FailureDiagnostic, type LogLevel, type Logger, type LoggerOptions, type MergeOptions, type NavigationAnnotation, type NavigationStep, type NavigationType, type NetworkStats, PAYLOAD_VERSION, type ReporterConfig, type ResourceBreakdown, type ResourceType, type StepAssertion, type StepTestIdentity, type Summary, type TestArtifacts, type TestRelicDataPayload, TestRelicError, type TestResult, type TestRunReport, type TestStatus, type TestType, type TimelineEntry, type TimelineStep, createError, createLogger, isTestRelicDataPayload, isValidConfig, isValidNavigationType, isValidTestRunReport };
489
+ export { ATTACHMENT_CONTENT_TYPE, ATTACHMENT_NAME, type ActionCategory, type ActionStep, type ApiAssertion, type ApiCallRecord, type ApiCallStep, type ApiCallStepRequest, type ApiCallStepResponse, type AssertionLocation, type AssertionType, type AuthMode, type AuthState, type CIMetadata, type CIProvider, type CapturedNetworkRequest, type CloudConfig, type CloudReporterOptions, ErrorCode, type FailureDiagnostic, type GitMetadata, type LogLevel, type Logger, type LoggerOptions, type MergeOptions, type NavigationAnnotation, type NavigationStep, type NavigationType, type NetworkStats, PAYLOAD_VERSION, type ProjectResolution, type QueueEntry, type ReporterConfig, type ResourceBreakdown, type ResourceType, type StepAssertion, type StepTestIdentity, type Summary, type TestArtifacts, type TestRelicDataPayload, TestRelicError, type TestResult, type TestRunReport, type TestStatus, type TestType, type TimelineEntry, type TimelineStep, type UploadStrategy, createError, createLogger, isTestRelicDataPayload, isValidApiKeyFormat, isValidCloudConfig, isValidConfig, isValidEndpointUrl, isValidNavigationType, isValidQueueEntry, isValidTestRunReport, isValidUploadStrategy };
package/dist/index.d.ts CHANGED
@@ -62,8 +62,9 @@ interface CIMetadata {
62
62
  readonly buildId: string | null;
63
63
  readonly commitSha: string | null;
64
64
  readonly branch: string | null;
65
+ readonly runUrl: string | null;
65
66
  }
66
- type CIProvider = 'github-actions' | 'gitlab-ci' | 'jenkins' | 'circleci' | 'unknown';
67
+ type CIProvider = 'github-actions' | 'gitlab-ci' | 'jenkins' | 'circleci' | 'bitbucket-pipelines' | 'unknown';
67
68
  interface TimelineEntry {
68
69
  readonly url: string;
69
70
  readonly navigationType: NavigationType;
@@ -327,6 +328,8 @@ interface ReporterConfig {
327
328
  * Default: undefined (exclude none)
328
329
  */
329
330
  readonly apiExcludeUrls?: (string | RegExp)[];
331
+ /** Cloud integration configuration. Default: undefined (local mode) */
332
+ readonly cloud?: CloudReporterOptions;
330
333
  }
331
334
  interface NavigationAnnotation {
332
335
  readonly url: string;
@@ -359,6 +362,67 @@ declare const ATTACHMENT_NAME = "testrelic-data";
359
362
  declare const ATTACHMENT_CONTENT_TYPE = "application/json";
360
363
  /** Type guard: validates that a parsed object is a TestRelicDataPayload. */
361
364
  declare function isTestRelicDataPayload(obj: unknown): obj is TestRelicDataPayload;
365
+ /** Upload strategy for cloud timeline data. */
366
+ type UploadStrategy = 'batch' | 'realtime' | 'both';
367
+ /** Current cloud/local operating mode. */
368
+ type AuthMode = 'cloud' | 'local' | 'pending';
369
+ /** Resolved cloud configuration, immutable after initialization. */
370
+ interface CloudConfig {
371
+ readonly apiKey: string | null;
372
+ readonly endpoint: string;
373
+ readonly uploadStrategy: UploadStrategy;
374
+ readonly timeout: number;
375
+ readonly projectName: string | null;
376
+ readonly queueMaxAge: number;
377
+ readonly queueDirectory: string;
378
+ }
379
+ /** Mutable auth state tracked by the cloud client. */
380
+ interface AuthState {
381
+ mode: AuthMode;
382
+ accessToken: string | null;
383
+ refreshToken: string | null;
384
+ expiresAt: number | null;
385
+ orgId: string | null;
386
+ orgName: string | null;
387
+ userId: string | null;
388
+ userName: string | null;
389
+ }
390
+ /** Auto-collected git information. All fields nullable. */
391
+ interface GitMetadata {
392
+ readonly branch: string | null;
393
+ readonly commitSha: string | null;
394
+ readonly commitMessage: string | null;
395
+ readonly remoteUrl: string | null;
396
+ }
397
+ /** Cached project identity. */
398
+ interface ProjectResolution {
399
+ readonly projectId: string;
400
+ readonly gitId: string;
401
+ readonly displayName: string;
402
+ readonly resolvedAt: number;
403
+ readonly apiKeyHash: string;
404
+ }
405
+ /** A single queued upload payload. */
406
+ interface QueueEntry {
407
+ readonly version: string;
408
+ readonly queuedAt: string;
409
+ readonly reason: string;
410
+ readonly retryCount: number;
411
+ readonly targetEndpoint: string;
412
+ readonly method: string;
413
+ readonly payload: Record<string, unknown>;
414
+ readonly headers: Record<string, string>;
415
+ }
416
+ /** Inline cloud configuration accepted via reporter options. */
417
+ interface CloudReporterOptions {
418
+ readonly apiKey?: string;
419
+ readonly endpoint?: string;
420
+ readonly upload?: UploadStrategy;
421
+ readonly timeout?: number;
422
+ readonly projectName?: string;
423
+ readonly queueMaxAge?: string;
424
+ readonly queueDirectory?: string;
425
+ }
362
426
  interface MergeOptions {
363
427
  readonly output: string;
364
428
  readonly testRunId?: string;
@@ -395,6 +459,10 @@ declare const ErrorCode: {
395
459
  readonly NAVIGATION_FLUSH_FAILED: "TESTRELIC_NAVIGATION_FLUSH_FAILED";
396
460
  readonly CODE_EXTRACT_FAILED: "TESTRELIC_CODE_EXTRACT_FAILED";
397
461
  readonly HTML_REPORT_FAILED: "TESTRELIC_HTML_REPORT_FAILED";
462
+ readonly CLOUD_AUTH_FAILED: "TESTRELIC_CLOUD_AUTH_FAILED";
463
+ readonly CLOUD_UPLOAD_FAILED: "TESTRELIC_CLOUD_UPLOAD_FAILED";
464
+ readonly CLOUD_CONFIG_INVALID: "TESTRELIC_CLOUD_CONFIG_INVALID";
465
+ readonly CLOUD_QUEUE_FAILED: "TESTRELIC_CLOUD_QUEUE_FAILED";
398
466
  };
399
467
  type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
400
468
  declare class TestRelicError extends Error {
@@ -411,6 +479,11 @@ declare function createError(code: ErrorCode, message: string, cause?: unknown):
411
479
 
412
480
  declare function isValidNavigationType(value: unknown): value is NavigationType;
413
481
  declare function isValidConfig(input: unknown): input is ReporterConfig;
482
+ declare function isValidApiKeyFormat(value: unknown): value is string;
483
+ declare function isValidUploadStrategy(value: unknown): value is UploadStrategy;
484
+ declare function isValidEndpointUrl(value: unknown): boolean;
485
+ declare function isValidCloudConfig(input: unknown): input is CloudConfig;
486
+ declare function isValidQueueEntry(input: unknown): input is QueueEntry;
414
487
  declare function isValidTestRunReport(value: unknown): value is TestRunReport;
415
488
 
416
- export { ATTACHMENT_CONTENT_TYPE, ATTACHMENT_NAME, type ActionCategory, type ActionStep, type ApiAssertion, type ApiCallRecord, type ApiCallStep, type ApiCallStepRequest, type ApiCallStepResponse, type AssertionLocation, type AssertionType, type CIMetadata, type CIProvider, type CapturedNetworkRequest, ErrorCode, type FailureDiagnostic, type LogLevel, type Logger, type LoggerOptions, type MergeOptions, type NavigationAnnotation, type NavigationStep, type NavigationType, type NetworkStats, PAYLOAD_VERSION, type ReporterConfig, type ResourceBreakdown, type ResourceType, type StepAssertion, type StepTestIdentity, type Summary, type TestArtifacts, type TestRelicDataPayload, TestRelicError, type TestResult, type TestRunReport, type TestStatus, type TestType, type TimelineEntry, type TimelineStep, createError, createLogger, isTestRelicDataPayload, isValidConfig, isValidNavigationType, isValidTestRunReport };
489
+ export { ATTACHMENT_CONTENT_TYPE, ATTACHMENT_NAME, type ActionCategory, type ActionStep, type ApiAssertion, type ApiCallRecord, type ApiCallStep, type ApiCallStepRequest, type ApiCallStepResponse, type AssertionLocation, type AssertionType, type AuthMode, type AuthState, type CIMetadata, type CIProvider, type CapturedNetworkRequest, type CloudConfig, type CloudReporterOptions, ErrorCode, type FailureDiagnostic, type GitMetadata, type LogLevel, type Logger, type LoggerOptions, type MergeOptions, type NavigationAnnotation, type NavigationStep, type NavigationType, type NetworkStats, PAYLOAD_VERSION, type ProjectResolution, type QueueEntry, type ReporterConfig, type ResourceBreakdown, type ResourceType, type StepAssertion, type StepTestIdentity, type Summary, type TestArtifacts, type TestRelicDataPayload, TestRelicError, type TestResult, type TestRunReport, type TestStatus, type TestType, type TimelineEntry, type TimelineStep, type UploadStrategy, createError, createLogger, isTestRelicDataPayload, isValidApiKeyFormat, isValidCloudConfig, isValidConfig, isValidEndpointUrl, isValidNavigationType, isValidQueueEntry, isValidTestRunReport, isValidUploadStrategy };
package/dist/index.js CHANGED
@@ -37,7 +37,11 @@ var ErrorCode = {
37
37
  MERGE_READ_FAILED: "TESTRELIC_MERGE_READ_FAILED",
38
38
  NAVIGATION_FLUSH_FAILED: "TESTRELIC_NAVIGATION_FLUSH_FAILED",
39
39
  CODE_EXTRACT_FAILED: "TESTRELIC_CODE_EXTRACT_FAILED",
40
- HTML_REPORT_FAILED: "TESTRELIC_HTML_REPORT_FAILED"
40
+ HTML_REPORT_FAILED: "TESTRELIC_HTML_REPORT_FAILED",
41
+ CLOUD_AUTH_FAILED: "TESTRELIC_CLOUD_AUTH_FAILED",
42
+ CLOUD_UPLOAD_FAILED: "TESTRELIC_CLOUD_UPLOAD_FAILED",
43
+ CLOUD_CONFIG_INVALID: "TESTRELIC_CLOUD_CONFIG_INVALID",
44
+ CLOUD_QUEUE_FAILED: "TESTRELIC_CLOUD_QUEUE_FAILED"
41
45
  };
42
46
  var TestRelicError = class extends Error {
43
47
  constructor(code, message, cause) {
@@ -144,6 +148,67 @@ function isValidConfig(input) {
144
148
  }
145
149
  return true;
146
150
  }
151
+ var API_KEY_PATTERN = /^tr[a-z]*_[a-z]+_[a-zA-Z0-9]+$/;
152
+ var UPLOAD_STRATEGIES = /* @__PURE__ */ new Set(["batch", "realtime", "both"]);
153
+ var LOCALHOST_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "0.0.0.0"]);
154
+ function isValidApiKeyFormat(value) {
155
+ return typeof value === "string" && API_KEY_PATTERN.test(value);
156
+ }
157
+ function isValidUploadStrategy(value) {
158
+ return typeof value === "string" && UPLOAD_STRATEGIES.has(value);
159
+ }
160
+ function isValidEndpointUrl(value) {
161
+ if (typeof value !== "string") return false;
162
+ try {
163
+ const url = new URL(value);
164
+ if (url.protocol === "https:") return true;
165
+ if (url.protocol === "http:" && LOCALHOST_HOSTS.has(url.hostname)) return true;
166
+ return false;
167
+ } catch {
168
+ return false;
169
+ }
170
+ }
171
+ function isValidCloudConfig(input) {
172
+ if (typeof input !== "object" || input === null) return false;
173
+ if (!hasNoPrototypePollution(input)) return false;
174
+ const obj = input;
175
+ if (obj.apiKey !== void 0 && obj.apiKey !== null) {
176
+ if (typeof obj.apiKey !== "string") return false;
177
+ if (obj.apiKey.length > 0 && !isValidApiKeyFormat(obj.apiKey)) return false;
178
+ }
179
+ if (obj.endpoint !== void 0) {
180
+ if (!isValidEndpointUrl(obj.endpoint)) return false;
181
+ }
182
+ if (obj.uploadStrategy !== void 0) {
183
+ if (!isValidUploadStrategy(obj.uploadStrategy)) return false;
184
+ }
185
+ if (obj.timeout !== void 0) {
186
+ if (typeof obj.timeout !== "number" || obj.timeout < 1e3 || obj.timeout > 12e4) return false;
187
+ }
188
+ if (obj.projectName !== void 0 && obj.projectName !== null && typeof obj.projectName !== "string") return false;
189
+ if (obj.queueMaxAge !== void 0) {
190
+ if (typeof obj.queueMaxAge !== "number" || obj.queueMaxAge < 36e5 || obj.queueMaxAge > 2592e6) return false;
191
+ }
192
+ if (obj.queueDirectory !== void 0) {
193
+ if (typeof obj.queueDirectory !== "string") return false;
194
+ if (obj.queueDirectory.startsWith("/") || obj.queueDirectory.includes("..")) return false;
195
+ }
196
+ return true;
197
+ }
198
+ function isValidQueueEntry(input) {
199
+ if (typeof input !== "object" || input === null) return false;
200
+ if (!hasNoPrototypePollution(input)) return false;
201
+ const obj = input;
202
+ if (typeof obj.version !== "string") return false;
203
+ if (typeof obj.queuedAt !== "string") return false;
204
+ if (typeof obj.reason !== "string") return false;
205
+ if (typeof obj.retryCount !== "number") return false;
206
+ if (typeof obj.targetEndpoint !== "string") return false;
207
+ if (typeof obj.method !== "string") return false;
208
+ if (typeof obj.payload !== "object" || obj.payload === null) return false;
209
+ if (typeof obj.headers !== "object" || obj.headers === null) return false;
210
+ return true;
211
+ }
147
212
  function isValidTestRunReport(value) {
148
213
  if (typeof value !== "object" || value === null) return false;
149
214
  const obj = value;
@@ -172,8 +237,13 @@ export {
172
237
  createError,
173
238
  createLogger,
174
239
  isTestRelicDataPayload,
240
+ isValidApiKeyFormat,
241
+ isValidCloudConfig,
175
242
  isValidConfig,
243
+ isValidEndpointUrl,
176
244
  isValidNavigationType,
177
- isValidTestRunReport
245
+ isValidQueueEntry,
246
+ isValidTestRunReport,
247
+ isValidUploadStrategy
178
248
  };
179
249
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/logger.ts","../src/errors.ts","../src/validation.ts"],"sourcesContent":["/**\n * @testrelic/core — Shared type definitions\n *\n * All interfaces for the JSON output schema, reporter configuration,\n * and internal fixture-to-reporter communication.\n *\n * Schema Version: 1.0.0\n */\n\n// ---------------------------------------------------------------------------\n// Navigation Types\n// ---------------------------------------------------------------------------\n\nexport type NavigationType =\n | 'goto'\n | 'navigation'\n | 'back'\n | 'forward'\n | 'refresh'\n | 'spa_route'\n | 'spa_replace'\n | 'hash_change'\n | 'link_click'\n | 'form_submit'\n | 'redirect'\n | 'popstate'\n | 'page_load'\n | 'manual_record'\n | 'fallback'\n | 'dummy';\n\n// ---------------------------------------------------------------------------\n// Output Schema Types (JSON report structure)\n// ---------------------------------------------------------------------------\n\nexport interface TestRunReport {\n readonly schemaVersion: string;\n readonly testRunId: string;\n readonly startedAt: string;\n readonly completedAt: string;\n readonly totalDuration: number;\n readonly summary: Summary;\n readonly ci: CIMetadata | null;\n readonly metadata: Record<string, unknown> | null;\n readonly timeline: readonly (TimelineEntry | TimelineStep)[];\n readonly shardRunIds: string[] | null;\n}\n\n/** Breakdown of API calls by HTTP response status range. */\nexport interface ApiCallsByStatusRange {\n readonly '2xx': number;\n readonly '3xx': number;\n readonly '4xx': number;\n readonly '5xx': number;\n readonly error: number;\n}\n\n/** Statistical distribution of API call response times in milliseconds. */\nexport interface ApiResponseTimeStats {\n readonly avg: number;\n readonly min: number;\n readonly max: number;\n readonly p50: number;\n readonly p95: number;\n readonly p99: number;\n}\n\nexport interface Summary {\n readonly total: number;\n readonly passed: number;\n readonly failed: number;\n readonly flaky: number;\n readonly skipped: number;\n readonly timedout: number;\n readonly totalApiCalls: number;\n readonly uniqueApiUrls: number;\n readonly apiCallsByMethod: Record<string, number>;\n readonly apiCallsByStatusRange: ApiCallsByStatusRange;\n readonly apiResponseTime: ApiResponseTimeStats | null;\n readonly totalAssertions: number;\n readonly passedAssertions: number;\n readonly failedAssertions: number;\n readonly totalNavigations: number;\n readonly uniqueNavigationUrls: number;\n readonly totalTimelineSteps: number;\n readonly totalActionSteps: number;\n readonly actionStepsByCategory: Record<string, number>;\n}\n\nexport interface CIMetadata {\n readonly provider: CIProvider;\n readonly buildId: string | null;\n readonly commitSha: string | null;\n readonly branch: string | null;\n}\n\nexport type CIProvider =\n | 'github-actions'\n | 'gitlab-ci'\n | 'jenkins'\n | 'circleci'\n | 'unknown';\n\nexport interface TimelineEntry {\n readonly url: string;\n readonly navigationType: NavigationType;\n readonly visitedAt: string;\n readonly duration: number;\n readonly specFile: string;\n readonly domContentLoadedAt: string | null;\n readonly networkIdleAt: string | null;\n readonly networkStats: NetworkStats | null;\n readonly tests: TestResult[];\n}\n\nexport interface TestResult {\n readonly title: string;\n readonly status: TestStatus;\n readonly duration: number;\n readonly startedAt: string;\n readonly completedAt: string;\n readonly retryCount: number;\n readonly tags: string[];\n readonly failure: FailureDiagnostic | null;\n readonly testId: string;\n readonly filePath: string;\n readonly suiteName: string;\n readonly testType: TestType;\n readonly isFlaky: boolean;\n readonly retryStatus: string | null;\n readonly expectedStatus: TestStatus;\n readonly actualStatus: TestStatus;\n readonly artifacts: TestArtifacts | null;\n readonly networkRequests: CapturedNetworkRequest[] | null;\n readonly apiCalls: readonly ApiCallRecord[] | null;\n readonly apiAssertions: readonly ApiAssertion[] | null;\n readonly actions: readonly ActionStep[] | null;\n}\n\nexport type ResourceType = 'xhr' | 'document' | 'script' | 'stylesheet' | 'image' | 'font' | 'other';\n\nexport interface CapturedNetworkRequest {\n readonly url: string;\n readonly method: string;\n readonly resourceType: ResourceType;\n readonly statusCode: number;\n readonly responseTimeMs: number;\n readonly startedAt: string;\n readonly requestHeaders: Record<string, string> | null;\n readonly requestBody: string | null;\n readonly responseBody: string | null;\n readonly responseHeaders: Record<string, string> | null;\n readonly contentType: string | null;\n readonly responseSize: number;\n readonly requestBodyTruncated: boolean;\n readonly responseBodyTruncated: boolean;\n readonly isBinary: boolean;\n readonly error: string | null;\n}\n\nexport interface TestArtifacts {\n readonly screenshot?: string;\n readonly video?: string;\n}\n\nexport type TestStatus = 'passed' | 'failed' | 'skipped' | 'flaky' | 'timedout';\n\nexport type TestType = 'e2e' | 'api' | 'unit' | 'unknown';\n\nexport interface FailureDiagnostic {\n readonly message: string;\n readonly line: number | null;\n readonly code: string | null;\n readonly stack: string | null;\n}\n\nexport interface NetworkStats {\n readonly totalRequests: number;\n readonly failedRequests: number;\n readonly failedRequestUrls: string[];\n readonly totalBytes: number;\n readonly byType: ResourceBreakdown;\n}\n\nexport interface ResourceBreakdown {\n readonly xhr: number;\n readonly document: number;\n readonly script: number;\n readonly stylesheet: number;\n readonly image: number;\n readonly font: number;\n readonly other: number;\n}\n\n// ---------------------------------------------------------------------------\n// API Call Record (captured from Playwright APIRequestContext proxy)\n// ---------------------------------------------------------------------------\n\nexport interface ApiCallRecord {\n /** Unique call identifier within the test (e.g., \"api-call-0\") */\n readonly id: string;\n /** ISO 8601 timestamp when the call was initiated */\n readonly timestamp: string;\n /** HTTP method: GET, POST, PUT, PATCH, DELETE, HEAD, or custom via fetch() */\n readonly method: string;\n /** Full resolved URL (after baseURL resolution by Playwright) */\n readonly url: string;\n /** All request headers sent, or null if unavailable */\n readonly requestHeaders: Record<string, string> | null;\n /** Request payload as string (JSON-serialized for objects). Null for bodiless methods */\n readonly requestBody: string | null;\n /** HTTP response status code, or null if request errored before response */\n readonly responseStatusCode: number | null;\n /** HTTP response status text, or null if request errored before response */\n readonly responseStatusText: string | null;\n /** All response headers received, or null if request errored before response */\n readonly responseHeaders: Record<string, string> | null;\n /** Response body: string for text/JSON, base64 for binary. Null on error */\n readonly responseBody: string | null;\n /** Duration in milliseconds from request initiation to response received */\n readonly responseTimeMs: number;\n /** Whether the response body is stored as a base64-encoded binary string */\n readonly isBinary: boolean;\n /** Error message if the call failed (network error, timeout), null on success */\n readonly error: string | null;\n}\n\n// ---------------------------------------------------------------------------\n// API Assertion Types (captured from assertion tracking)\n// ---------------------------------------------------------------------------\n\n/** Categorization of the assertion being made. */\nexport type AssertionType =\n | 'status'\n | 'statusOk'\n | 'header'\n | 'bodyField'\n | 'bodyMatch'\n | 'bodyContains'\n | 'custom';\n\n/** Source location where an assertion was made in the test file. */\nexport interface AssertionLocation {\n /** Absolute or relative file path to the test file */\n readonly file: string;\n /** Line number (1-based) */\n readonly line: number;\n /** Column number (1-based), if available */\n readonly column?: number;\n}\n\n/** A single captured assertion on API response data. */\nexport interface ApiAssertion {\n /** Links to ApiCallRecord.id from the API proxy */\n readonly callId: string;\n /** Category of assertion */\n readonly type: AssertionType;\n /** What the test expected */\n readonly expected: unknown;\n /** What was actually received */\n readonly actual: unknown;\n /** Whether the assertion passed or failed */\n readonly status: 'passed' | 'failed';\n /** Source location of the assertion in the test file */\n readonly location: AssertionLocation;\n /** String representation of the assertion expression (best-effort) */\n readonly expression?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Unified Timeline Types (navigation + API call steps)\n// ---------------------------------------------------------------------------\n\n/** Test identity block attached to every timeline step. */\nexport interface StepTestIdentity {\n readonly title: string;\n readonly fullTitle: readonly string[];\n readonly status: TestStatus;\n readonly duration: number;\n readonly retries: number;\n readonly retry: number;\n readonly tags: readonly string[];\n readonly failure: FailureDiagnostic | null;\n}\n\n/** Request details within an API call step. */\nexport interface ApiCallStepRequest {\n readonly headers: Record<string, string> | null;\n readonly body: unknown;\n}\n\n/** Response details within an API call step. */\nexport interface ApiCallStepResponse {\n readonly statusCode: number;\n readonly statusText: string;\n readonly headers: Record<string, string> | null;\n readonly body: unknown;\n}\n\n/** An assertion linked to an API call step (callId omitted — implicit from parent). */\nexport interface StepAssertion {\n readonly type: AssertionType;\n readonly expected: unknown;\n readonly actual: unknown;\n readonly status: 'passed' | 'failed';\n readonly location: AssertionLocation;\n readonly expression?: string;\n}\n\n/** A browser navigation event in the unified timeline. */\nexport interface NavigationStep {\n readonly index: number;\n readonly type: 'navigation';\n readonly url: string;\n readonly timestamp: string;\n readonly durationOnUrl: number;\n readonly navigationType: NavigationType;\n readonly domContentLoadedAt: string | null;\n readonly networkIdleAt: string | null;\n readonly networkStats: NetworkStats | null;\n readonly specFile: string;\n readonly test: StepTestIdentity;\n}\n\n/** An API request event in the unified timeline. */\nexport interface ApiCallStep {\n readonly index: number;\n readonly type: 'api_call';\n readonly callId: string;\n readonly method: string;\n readonly url: string;\n readonly timestamp: string;\n readonly responseTime: number | null;\n readonly request: ApiCallStepRequest;\n readonly response: ApiCallStepResponse | null;\n readonly error?: string | null;\n readonly assertions: readonly StepAssertion[];\n readonly specFile: string;\n readonly test: StepTestIdentity;\n}\n\n/** Discriminated union of all timeline step types. */\nexport type TimelineStep = NavigationStep | ApiCallStep;\n\n// ---------------------------------------------------------------------------\n// Action Step Types (Playwright test step capture)\n// ---------------------------------------------------------------------------\n\n/** Categorized type of a captured test action. */\nexport type ActionCategory = 'ui_action' | 'assertion' | 'custom_step';\n\n/** A single captured test action step. */\nexport interface ActionStep {\n readonly title: string;\n readonly category: ActionCategory;\n readonly timestamp: string;\n readonly duration: number;\n readonly videoOffset: number | null;\n readonly status: 'passed' | 'failed';\n readonly error: string | null;\n readonly children: readonly ActionStep[];\n}\n\n// ---------------------------------------------------------------------------\n// Configuration Types (reporter tuple options)\n// ---------------------------------------------------------------------------\n\nexport interface ReporterConfig {\n readonly outputPath?: string;\n readonly includeStackTrace?: boolean;\n readonly includeCodeSnippets?: boolean;\n readonly codeContextLines?: number;\n readonly includeNetworkStats?: boolean;\n readonly navigationTypes?: NavigationType[] | null;\n readonly redactPatterns?: (string | RegExp)[];\n readonly testRunId?: string | null;\n readonly metadata?: Record<string, unknown> | null;\n readonly openReport?: boolean;\n readonly htmlReportPath?: string;\n readonly includeArtifacts?: boolean;\n /** When false, disables API call interception in the unified fixture. Default: true */\n readonly trackApiCalls?: boolean;\n /** When true, suppresses console summary output. Default: false */\n readonly quiet?: boolean;\n /** When true, captures Playwright test steps (actions). Default: true */\n readonly includeActionSteps?: boolean;\n /** Capture request headers for API calls. Default: true */\n readonly captureRequestHeaders?: boolean;\n /** Capture response headers for API calls. Default: true */\n readonly captureResponseHeaders?: boolean;\n /** Capture request body for API calls. Default: true */\n readonly captureRequestBody?: boolean;\n /** Capture response body for API calls. Default: true */\n readonly captureResponseBody?: boolean;\n /** Capture API assertions (both pass and fail). Default: true */\n readonly captureAssertions?: boolean;\n /**\n * Header names whose values are replaced with \"[REDACTED]\".\n * Case-insensitive matching. Default: ['authorization', 'cookie', 'set-cookie', 'x-api-key']\n */\n readonly redactHeaders?: string[];\n /**\n * Body field names whose values are replaced with \"[REDACTED]\" at any depth.\n * Default: ['password', 'secret', 'token', 'apiKey', 'api_key']\n */\n readonly redactBodyFields?: string[];\n /**\n * Only track API calls matching these URL patterns.\n * Default: undefined (track all)\n */\n readonly apiIncludeUrls?: (string | RegExp)[];\n /**\n * Exclude API calls matching these URL patterns. Takes precedence over include.\n * Default: undefined (exclude none)\n */\n readonly apiExcludeUrls?: (string | RegExp)[];\n}\n\n// ---------------------------------------------------------------------------\n// Internal Types (fixture → reporter communication)\n// ---------------------------------------------------------------------------\n\nexport interface NavigationAnnotation {\n readonly url: string;\n readonly navigationType: NavigationType;\n readonly timestamp: string;\n readonly domContentLoadedAt?: string;\n readonly networkIdleAt?: string;\n readonly networkStats?: NetworkStats;\n}\n\n// ---------------------------------------------------------------------------\n// Worker-Safe Data Payload (worker → reporter communication)\n// ---------------------------------------------------------------------------\n\n/** Consolidated data payload sent from a worker fixture to the reporter. */\nexport interface TestRelicDataPayload {\n /** Marker to identify TestRelic attachments. Always `true`. */\n readonly testRelicData: true;\n /** Payload format version (semver). */\n readonly version: string;\n /** Navigation events collected during the test. */\n readonly navigations: readonly NavigationAnnotation[];\n /** Captured network requests during the test. */\n readonly networkRequests: readonly CapturedNetworkRequest[];\n /** API calls made via APIRequestContext proxy. */\n readonly apiCalls: readonly ApiCallRecord[];\n /** Assertions captured on API responses. */\n readonly apiAssertions: readonly ApiAssertion[];\n}\n\n/** Current payload format version. */\nexport const PAYLOAD_VERSION = '1.0.0';\n\n/** Attachment name used for the consolidated payload. */\nexport const ATTACHMENT_NAME = 'testrelic-data';\n\n/** Attachment content type. */\nexport const ATTACHMENT_CONTENT_TYPE = 'application/json';\n\n/** Type guard: validates that a parsed object is a TestRelicDataPayload. */\nexport function isTestRelicDataPayload(obj: unknown): obj is TestRelicDataPayload {\n if (typeof obj !== 'object' || obj === null) return false;\n const record = obj as Record<string, unknown>;\n return (\n record.testRelicData === true &&\n typeof record.version === 'string' &&\n record.version.length > 0 &&\n Array.isArray(record.navigations) &&\n Array.isArray(record.networkRequests) &&\n Array.isArray(record.apiCalls) &&\n Array.isArray(record.apiAssertions)\n );\n}\n\n// ---------------------------------------------------------------------------\n// Merge CLI Types\n// ---------------------------------------------------------------------------\n\nexport interface MergeOptions {\n readonly output: string;\n readonly testRunId?: string;\n}\n","/**\n * @testrelic/core — Configurable logger\n *\n * Provides a Logger interface with a no-op default.\n * Never uses console.* directly (Constitution SDK Constraint).\n */\n\nexport interface Logger {\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n debug(message: string, ...args: unknown[]): void;\n}\n\nexport interface LoggerOptions {\n readonly handler?: (level: LogLevel, message: string, args: unknown[]) => void;\n}\n\nexport type LogLevel = 'info' | 'warn' | 'error' | 'debug';\n\ntype LogHandler = (level: LogLevel, message: string, args: unknown[]) => void;\n\nconst noopHandler: LogHandler = () => {};\n\nexport function createLogger(options?: LoggerOptions): Logger {\n const handler = options?.handler ?? noopHandler;\n\n return {\n info(message: string, ...args: unknown[]) {\n handler('info', message, args);\n },\n warn(message: string, ...args: unknown[]) {\n handler('warn', message, args);\n },\n error(message: string, ...args: unknown[]) {\n handler('error', message, args);\n },\n debug(message: string, ...args: unknown[]) {\n handler('debug', message, args);\n },\n };\n}\n","/**\n * @testrelic/core — Structured error factory\n *\n * Machine-readable error codes for programmatic handling.\n */\n\nexport const ErrorCode = {\n CONFIG_INVALID: 'TESTRELIC_CONFIG_INVALID',\n OUTPUT_WRITE_FAILED: 'TESTRELIC_OUTPUT_WRITE_FAILED',\n MERGE_INVALID_SCHEMA: 'TESTRELIC_MERGE_INVALID_SCHEMA',\n MERGE_READ_FAILED: 'TESTRELIC_MERGE_READ_FAILED',\n NAVIGATION_FLUSH_FAILED: 'TESTRELIC_NAVIGATION_FLUSH_FAILED',\n CODE_EXTRACT_FAILED: 'TESTRELIC_CODE_EXTRACT_FAILED',\n HTML_REPORT_FAILED: 'TESTRELIC_HTML_REPORT_FAILED',\n} as const;\n\nexport type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];\n\nexport class TestRelicError extends Error {\n readonly code: ErrorCode;\n\n constructor(code: ErrorCode, message: string, cause?: unknown) {\n super(message);\n this.name = 'TestRelicError';\n this.code = code;\n if (cause !== undefined) {\n Object.defineProperty(this, 'cause', { value: cause, writable: false, enumerable: false });\n }\n }\n}\n\nexport function createError(\n code: ErrorCode,\n message: string,\n cause?: unknown,\n): TestRelicError {\n return new TestRelicError(code, message, cause);\n}\n","/**\n * @testrelic/core — Lightweight runtime type guards\n *\n * Hand-written guards, no runtime schema libraries (Constitution SDK Constraint).\n */\n\nimport type {\n ReporterConfig,\n NavigationType,\n TestRunReport,\n} from './types.js';\n\nconst NAVIGATION_TYPES = new Set<string>([\n 'goto', 'navigation', 'back', 'forward', 'refresh',\n 'spa_route', 'spa_replace', 'hash_change', 'link_click',\n 'form_submit', 'redirect', 'popstate', 'page_load',\n 'manual_record', 'fallback', 'dummy',\n]);\n\nconst DANGEROUS_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport function isValidNavigationType(value: unknown): value is NavigationType {\n return typeof value === 'string' && NAVIGATION_TYPES.has(value);\n}\n\nfunction hasNoPrototypePollution(obj: unknown): boolean {\n if (typeof obj !== 'object' || obj === null) return true;\n for (const key of Object.keys(obj)) {\n if (DANGEROUS_KEYS.has(key)) return false;\n }\n return true;\n}\n\nexport function isValidConfig(input: unknown): input is ReporterConfig {\n if (typeof input !== 'object' || input === null) return false;\n if (!hasNoPrototypePollution(input)) return false;\n\n const obj = input as Record<string, unknown>;\n\n if (obj.outputPath !== undefined && typeof obj.outputPath !== 'string') return false;\n if (obj.includeStackTrace !== undefined && typeof obj.includeStackTrace !== 'boolean') return false;\n if (obj.includeCodeSnippets !== undefined && typeof obj.includeCodeSnippets !== 'boolean') return false;\n if (obj.codeContextLines !== undefined && typeof obj.codeContextLines !== 'number') return false;\n if (obj.includeNetworkStats !== undefined && typeof obj.includeNetworkStats !== 'boolean') return false;\n\n if (obj.navigationTypes !== undefined && obj.navigationTypes !== null) {\n if (!Array.isArray(obj.navigationTypes)) return false;\n for (const t of obj.navigationTypes) {\n if (!isValidNavigationType(t)) return false;\n }\n }\n\n if (obj.redactPatterns !== undefined) {\n if (!Array.isArray(obj.redactPatterns)) return false;\n for (const p of obj.redactPatterns) {\n if (typeof p !== 'string' && !(p instanceof RegExp)) return false;\n }\n }\n\n if (obj.testRunId !== undefined && obj.testRunId !== null && typeof obj.testRunId !== 'string') return false;\n\n if (obj.metadata !== undefined && obj.metadata !== null) {\n if (typeof obj.metadata !== 'object') return false;\n if (!hasNoPrototypePollution(obj.metadata)) return false;\n }\n\n if (obj.openReport !== undefined && typeof obj.openReport !== 'boolean') return false;\n if (obj.htmlReportPath !== undefined && (typeof obj.htmlReportPath !== 'string' || obj.htmlReportPath === '')) return false;\n if (obj.includeArtifacts !== undefined && typeof obj.includeArtifacts !== 'boolean') return false;\n\n // API tracking configuration\n if (obj.trackApiCalls !== undefined && typeof obj.trackApiCalls !== 'boolean') return false;\n if (obj.captureRequestHeaders !== undefined && typeof obj.captureRequestHeaders !== 'boolean') return false;\n if (obj.captureResponseHeaders !== undefined && typeof obj.captureResponseHeaders !== 'boolean') return false;\n if (obj.captureRequestBody !== undefined && typeof obj.captureRequestBody !== 'boolean') return false;\n if (obj.captureResponseBody !== undefined && typeof obj.captureResponseBody !== 'boolean') return false;\n if (obj.captureAssertions !== undefined && typeof obj.captureAssertions !== 'boolean') return false;\n\n if (obj.redactHeaders !== undefined) {\n if (!Array.isArray(obj.redactHeaders)) return false;\n for (const h of obj.redactHeaders) {\n if (typeof h !== 'string') return false;\n }\n }\n\n if (obj.redactBodyFields !== undefined) {\n if (!Array.isArray(obj.redactBodyFields)) return false;\n for (const f of obj.redactBodyFields) {\n if (typeof f !== 'string') return false;\n }\n }\n\n if (obj.apiIncludeUrls !== undefined) {\n if (!Array.isArray(obj.apiIncludeUrls)) return false;\n for (const p of obj.apiIncludeUrls) {\n if (typeof p !== 'string' && !(p instanceof RegExp)) return false;\n }\n }\n\n if (obj.apiExcludeUrls !== undefined) {\n if (!Array.isArray(obj.apiExcludeUrls)) return false;\n for (const p of obj.apiExcludeUrls) {\n if (typeof p !== 'string' && !(p instanceof RegExp)) return false;\n }\n }\n\n return true;\n}\n\nexport function isValidTestRunReport(value: unknown): value is TestRunReport {\n if (typeof value !== 'object' || value === null) return false;\n\n const obj = value as Record<string, unknown>;\n\n if (typeof obj.schemaVersion !== 'string') return false;\n if (typeof obj.testRunId !== 'string') return false;\n if (typeof obj.startedAt !== 'string') return false;\n if (typeof obj.completedAt !== 'string') return false;\n if (typeof obj.totalDuration !== 'number') return false;\n if (typeof obj.summary !== 'object' || obj.summary === null) return false;\n if (!Array.isArray(obj.timeline)) return false;\n\n const summary = obj.summary as Record<string, unknown>;\n if (typeof summary.total !== 'number') return false;\n if (typeof summary.passed !== 'number') return false;\n if (typeof summary.failed !== 'number') return false;\n if (typeof summary.flaky !== 'number') return false;\n if (typeof summary.skipped !== 'number') return false;\n // timedout is optional for backward compat with schema 1.0.0\n if (summary.timedout !== undefined && typeof summary.timedout !== 'number') return false;\n\n return true;\n}\n"],"mappings":";AAocO,IAAM,kBAAkB;AAGxB,IAAM,kBAAkB;AAGxB,IAAM,0BAA0B;AAGhC,SAAS,uBAAuB,KAA2C;AAChF,MAAI,OAAO,QAAQ,YAAY,QAAQ,KAAM,QAAO;AACpD,QAAM,SAAS;AACf,SACE,OAAO,kBAAkB,QACzB,OAAO,OAAO,YAAY,YAC1B,OAAO,QAAQ,SAAS,KACxB,MAAM,QAAQ,OAAO,WAAW,KAChC,MAAM,QAAQ,OAAO,eAAe,KACpC,MAAM,QAAQ,OAAO,QAAQ,KAC7B,MAAM,QAAQ,OAAO,aAAa;AAEtC;;;ACncA,IAAM,cAA0B,MAAM;AAAC;AAEhC,SAAS,aAAa,SAAiC;AAC5D,QAAM,UAAU,SAAS,WAAW;AAEpC,SAAO;AAAA,IACL,KAAK,YAAoB,MAAiB;AACxC,cAAQ,QAAQ,SAAS,IAAI;AAAA,IAC/B;AAAA,IACA,KAAK,YAAoB,MAAiB;AACxC,cAAQ,QAAQ,SAAS,IAAI;AAAA,IAC/B;AAAA,IACA,MAAM,YAAoB,MAAiB;AACzC,cAAQ,SAAS,SAAS,IAAI;AAAA,IAChC;AAAA,IACA,MAAM,YAAoB,MAAiB;AACzC,cAAQ,SAAS,SAAS,IAAI;AAAA,IAChC;AAAA,EACF;AACF;;;ACnCO,IAAM,YAAY;AAAA,EACvB,gBAAgB;AAAA,EAChB,qBAAqB;AAAA,EACrB,sBAAsB;AAAA,EACtB,mBAAmB;AAAA,EACnB,yBAAyB;AAAA,EACzB,qBAAqB;AAAA,EACrB,oBAAoB;AACtB;AAIO,IAAM,iBAAN,cAA6B,MAAM;AAAA,EAGxC,YAAY,MAAiB,SAAiB,OAAiB;AAC7D,UAAM,OAAO;AACb,SAAK,OA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AC,MAAM,QAAQ,IAAI,QAAQ,EAAG,QAAO;AAEzC,QAAM,UAAU,IAAI;AACpB,MAAI,OAAO,QAAQ,UAAU,SAAU,QAAO;AAC9C,MAAI,OAAO,QAAQ,WAAW,SAAU,QAAO;AAC/C,MAAI,OAAO,QAAQ,WAAW,SAAU,QAAO;AAC/C,MAAI,OAAO,QAAQ,UAAU,SAAU,QAAO;AAC9C,MAAI,OAAO,QAAQ,YAAY,SAAU,QAAO;AAEhD,MAAI,QAAQ,aAAa,UAAa,OAAO,QAAQ,aAAa,SAAU,QAAO;AAEnF,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/types.ts","../src/logger.ts","../src/errors.ts","../src/validation.ts"],"sourcesContent":["/**\n * @testrelic/core — Shared type definitions\n *\n * All interfaces for the JSON output schema, reporter configuration,\n * and internal fixture-to-reporter communication.\n *\n * Schema Version: 1.0.0\n */\n\n// ---------------------------------------------------------------------------\n// Navigation Types\n// ---------------------------------------------------------------------------\n\nexport type NavigationType =\n | 'goto'\n | 'navigation'\n | 'back'\n | 'forward'\n | 'refresh'\n | 'spa_route'\n | 'spa_replace'\n | 'hash_change'\n | 'link_click'\n | 'form_submit'\n | 'redirect'\n | 'popstate'\n | 'page_load'\n | 'manual_record'\n | 'fallback'\n | 'dummy';\n\n// ---------------------------------------------------------------------------\n// Output Schema Types (JSON report structure)\n// ---------------------------------------------------------------------------\n\nexport interface TestRunReport {\n readonly schemaVersion: string;\n readonly testRunId: string;\n readonly startedAt: string;\n readonly completedAt: string;\n readonly totalDuration: number;\n readonly summary: Summary;\n readonly ci: CIMetadata | null;\n readonly metadata: Record<string, unknown> | null;\n readonly timeline: readonly (TimelineEntry | TimelineStep)[];\n readonly shardRunIds: string[] | null;\n}\n\n/** Breakdown of API calls by HTTP response status range. */\nexport interface ApiCallsByStatusRange {\n readonly '2xx': number;\n readonly '3xx': number;\n readonly '4xx': number;\n readonly '5xx': number;\n readonly error: number;\n}\n\n/** Statistical distribution of API call response times in milliseconds. */\nexport interface ApiResponseTimeStats {\n readonly avg: number;\n readonly min: number;\n readonly max: number;\n readonly p50: number;\n readonly p95: number;\n readonly p99: number;\n}\n\nexport interface Summary {\n readonly total: number;\n readonly passed: number;\n readonly failed: number;\n readonly flaky: number;\n readonly skipped: number;\n readonly timedout: number;\n readonly totalApiCalls: number;\n readonly uniqueApiUrls: number;\n readonly apiCallsByMethod: Record<string, number>;\n readonly apiCallsByStatusRange: ApiCallsByStatusRange;\n readonly apiResponseTime: ApiResponseTimeStats | null;\n readonly totalAssertions: number;\n readonly passedAssertions: number;\n readonly failedAssertions: number;\n readonly totalNavigations: number;\n readonly uniqueNavigationUrls: number;\n readonly totalTimelineSteps: number;\n readonly totalActionSteps: number;\n readonly actionStepsByCategory: Record<string, number>;\n}\n\nexport interface CIMetadata {\n readonly provider: CIProvider;\n readonly buildId: string | null;\n readonly commitSha: string | null;\n readonly branch: string | null;\n readonly runUrl: string | null;\n}\n\nexport type CIProvider =\n | 'github-actions'\n | 'gitlab-ci'\n | 'jenkins'\n | 'circleci'\n | 'bitbucket-pipelines'\n | 'unknown';\n\nexport interface TimelineEntry {\n readonly url: string;\n readonly navigationType: NavigationType;\n readonly visitedAt: string;\n readonly duration: number;\n readonly specFile: string;\n readonly domContentLoadedAt: string | null;\n readonly networkIdleAt: string | null;\n readonly networkStats: NetworkStats | null;\n readonly tests: TestResult[];\n}\n\nexport interface TestResult {\n readonly title: string;\n readonly status: TestStatus;\n readonly duration: number;\n readonly startedAt: string;\n readonly completedAt: string;\n readonly retryCount: number;\n readonly tags: string[];\n readonly failure: FailureDiagnostic | null;\n readonly testId: string;\n readonly filePath: string;\n readonly suiteName: string;\n readonly testType: TestType;\n readonly isFlaky: boolean;\n readonly retryStatus: string | null;\n readonly expectedStatus: TestStatus;\n readonly actualStatus: TestStatus;\n readonly artifacts: TestArtifacts | null;\n readonly networkRequests: CapturedNetworkRequest[] | null;\n readonly apiCalls: readonly ApiCallRecord[] | null;\n readonly apiAssertions: readonly ApiAssertion[] | null;\n readonly actions: readonly ActionStep[] | null;\n}\n\nexport type ResourceType = 'xhr' | 'document' | 'script' | 'stylesheet' | 'image' | 'font' | 'other';\n\nexport interface CapturedNetworkRequest {\n readonly url: string;\n readonly method: string;\n readonly resourceType: ResourceType;\n readonly statusCode: number;\n readonly responseTimeMs: number;\n readonly startedAt: string;\n readonly requestHeaders: Record<string, string> | null;\n readonly requestBody: string | null;\n readonly responseBody: string | null;\n readonly responseHeaders: Record<string, string> | null;\n readonly contentType: string | null;\n readonly responseSize: number;\n readonly requestBodyTruncated: boolean;\n readonly responseBodyTruncated: boolean;\n readonly isBinary: boolean;\n readonly error: string | null;\n}\n\nexport interface TestArtifacts {\n readonly screenshot?: string;\n readonly video?: string;\n}\n\nexport type TestStatus = 'passed' | 'failed' | 'skipped' | 'flaky' | 'timedout';\n\nexport type TestType = 'e2e' | 'api' | 'unit' | 'unknown';\n\nexport interface FailureDiagnostic {\n readonly message: string;\n readonly line: number | null;\n readonly code: string | null;\n readonly stack: string | null;\n}\n\nexport interface NetworkStats {\n readonly totalRequests: number;\n readonly failedRequests: number;\n readonly failedRequestUrls: string[];\n readonly totalBytes: number;\n readonly byType: ResourceBreakdown;\n}\n\nexport interface ResourceBreakdown {\n readonly xhr: number;\n readonly document: number;\n readonly script: number;\n readonly stylesheet: number;\n readonly image: number;\n readonly font: number;\n readonly other: number;\n}\n\n// ---------------------------------------------------------------------------\n// API Call Record (captured from Playwright APIRequestContext proxy)\n// ---------------------------------------------------------------------------\n\nexport interface ApiCallRecord {\n /** Unique call identifier within the test (e.g., \"api-call-0\") */\n readonly id: string;\n /** ISO 8601 timestamp when the call was initiated */\n readonly timestamp: string;\n /** HTTP method: GET, POST, PUT, PATCH, DELETE, HEAD, or custom via fetch() */\n readonly method: string;\n /** Full resolved URL (after baseURL resolution by Playwright) */\n readonly url: string;\n /** All request headers sent, or null if unavailable */\n readonly requestHeaders: Record<string, string> | null;\n /** Request payload as string (JSON-serialized for objects). Null for bodiless methods */\n readonly requestBody: string | null;\n /** HTTP response status code, or null if request errored before response */\n readonly responseStatusCode: number | null;\n /** HTTP response status text, or null if request errored before response */\n readonly responseStatusText: string | null;\n /** All response headers received, or null if request errored before response */\n readonly responseHeaders: Record<string, string> | null;\n /** Response body: string for text/JSON, base64 for binary. Null on error */\n readonly responseBody: string | null;\n /** Duration in milliseconds from request initiation to response received */\n readonly responseTimeMs: number;\n /** Whether the response body is stored as a base64-encoded binary string */\n readonly isBinary: boolean;\n /** Error message if the call failed (network error, timeout), null on success */\n readonly error: string | null;\n}\n\n// ---------------------------------------------------------------------------\n// API Assertion Types (captured from assertion tracking)\n// ---------------------------------------------------------------------------\n\n/** Categorization of the assertion being made. */\nexport type AssertionType =\n | 'status'\n | 'statusOk'\n | 'header'\n | 'bodyField'\n | 'bodyMatch'\n | 'bodyContains'\n | 'custom';\n\n/** Source location where an assertion was made in the test file. */\nexport interface AssertionLocation {\n /** Absolute or relative file path to the test file */\n readonly file: string;\n /** Line number (1-based) */\n readonly line: number;\n /** Column number (1-based), if available */\n readonly column?: number;\n}\n\n/** A single captured assertion on API response data. */\nexport interface ApiAssertion {\n /** Links to ApiCallRecord.id from the API proxy */\n readonly callId: string;\n /** Category of assertion */\n readonly type: AssertionType;\n /** What the test expected */\n readonly expected: unknown;\n /** What was actually received */\n readonly actual: unknown;\n /** Whether the assertion passed or failed */\n readonly status: 'passed' | 'failed';\n /** Source location of the assertion in the test file */\n readonly location: AssertionLocation;\n /** String representation of the assertion expression (best-effort) */\n readonly expression?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Unified Timeline Types (navigation + API call steps)\n// ---------------------------------------------------------------------------\n\n/** Test identity block attached to every timeline step. */\nexport interface StepTestIdentity {\n readonly title: string;\n readonly fullTitle: readonly string[];\n readonly status: TestStatus;\n readonly duration: number;\n readonly retries: number;\n readonly retry: number;\n readonly tags: readonly string[];\n readonly failure: FailureDiagnostic | null;\n}\n\n/** Request details within an API call step. */\nexport interface ApiCallStepRequest {\n readonly headers: Record<string, string> | null;\n readonly body: unknown;\n}\n\n/** Response details within an API call step. */\nexport interface ApiCallStepResponse {\n readonly statusCode: number;\n readonly statusText: string;\n readonly headers: Record<string, string> | null;\n readonly body: unknown;\n}\n\n/** An assertion linked to an API call step (callId omitted — implicit from parent). */\nexport interface StepAssertion {\n readonly type: AssertionType;\n readonly expected: unknown;\n readonly actual: unknown;\n readonly status: 'passed' | 'failed';\n readonly location: AssertionLocation;\n readonly expression?: string;\n}\n\n/** A browser navigation event in the unified timeline. */\nexport interface NavigationStep {\n readonly index: number;\n readonly type: 'navigation';\n readonly url: string;\n readonly timestamp: string;\n readonly durationOnUrl: number;\n readonly navigationType: NavigationType;\n readonly domContentLoadedAt: string | null;\n readonly networkIdleAt: string | null;\n readonly networkStats: NetworkStats | null;\n readonly specFile: string;\n readonly test: StepTestIdentity;\n}\n\n/** An API request event in the unified timeline. */\nexport interface ApiCallStep {\n readonly index: number;\n readonly type: 'api_call';\n readonly callId: string;\n readonly method: string;\n readonly url: string;\n readonly timestamp: string;\n readonly responseTime: number | null;\n readonly request: ApiCallStepRequest;\n readonly response: ApiCallStepResponse | null;\n readonly error?: string | null;\n readonly assertions: readonly StepAssertion[];\n readonly specFile: string;\n readonly test: StepTestIdentity;\n}\n\n/** Discriminated union of all timeline step types. */\nexport type TimelineStep = NavigationStep | ApiCallStep;\n\n// ---------------------------------------------------------------------------\n// Action Step Types (Playwright test step capture)\n// ---------------------------------------------------------------------------\n\n/** Categorized type of a captured test action. */\nexport type ActionCategory = 'ui_action' | 'assertion' | 'custom_step';\n\n/** A single captured test action step. */\nexport interface ActionStep {\n readonly title: string;\n readonly category: ActionCategory;\n readonly timestamp: string;\n readonly duration: number;\n readonly videoOffset: number | null;\n readonly status: 'passed' | 'failed';\n readonly error: string | null;\n readonly children: readonly ActionStep[];\n}\n\n// ---------------------------------------------------------------------------\n// Configuration Types (reporter tuple options)\n// ---------------------------------------------------------------------------\n\nexport interface ReporterConfig {\n readonly outputPath?: string;\n readonly includeStackTrace?: boolean;\n readonly includeCodeSnippets?: boolean;\n readonly codeContextLines?: number;\n readonly includeNetworkStats?: boolean;\n readonly navigationTypes?: NavigationType[] | null;\n readonly redactPatterns?: (string | RegExp)[];\n readonly testRunId?: string | null;\n readonly metadata?: Record<string, unknown> | null;\n readonly openReport?: boolean;\n readonly htmlReportPath?: string;\n readonly includeArtifacts?: boolean;\n /** When false, disables API call interception in the unified fixture. Default: true */\n readonly trackApiCalls?: boolean;\n /** When true, suppresses console summary output. Default: false */\n readonly quiet?: boolean;\n /** When true, captures Playwright test steps (actions). Default: true */\n readonly includeActionSteps?: boolean;\n /** Capture request headers for API calls. Default: true */\n readonly captureRequestHeaders?: boolean;\n /** Capture response headers for API calls. Default: true */\n readonly captureResponseHeaders?: boolean;\n /** Capture request body for API calls. Default: true */\n readonly captureRequestBody?: boolean;\n /** Capture response body for API calls. Default: true */\n readonly captureResponseBody?: boolean;\n /** Capture API assertions (both pass and fail). Default: true */\n readonly captureAssertions?: boolean;\n /**\n * Header names whose values are replaced with \"[REDACTED]\".\n * Case-insensitive matching. Default: ['authorization', 'cookie', 'set-cookie', 'x-api-key']\n */\n readonly redactHeaders?: string[];\n /**\n * Body field names whose values are replaced with \"[REDACTED]\" at any depth.\n * Default: ['password', 'secret', 'token', 'apiKey', 'api_key']\n */\n readonly redactBodyFields?: string[];\n /**\n * Only track API calls matching these URL patterns.\n * Default: undefined (track all)\n */\n readonly apiIncludeUrls?: (string | RegExp)[];\n /**\n * Exclude API calls matching these URL patterns. Takes precedence over include.\n * Default: undefined (exclude none)\n */\n readonly apiExcludeUrls?: (string | RegExp)[];\n /** Cloud integration configuration. Default: undefined (local mode) */\n readonly cloud?: CloudReporterOptions;\n}\n\n// ---------------------------------------------------------------------------\n// Internal Types (fixture → reporter communication)\n// ---------------------------------------------------------------------------\n\nexport interface NavigationAnnotation {\n readonly url: string;\n readonly navigationType: NavigationType;\n readonly timestamp: string;\n readonly domContentLoadedAt?: string;\n readonly networkIdleAt?: string;\n readonly networkStats?: NetworkStats;\n}\n\n// ---------------------------------------------------------------------------\n// Worker-Safe Data Payload (worker → reporter communication)\n// ---------------------------------------------------------------------------\n\n/** Consolidated data payload sent from a worker fixture to the reporter. */\nexport interface TestRelicDataPayload {\n /** Marker to identify TestRelic attachments. Always `true`. */\n readonly testRelicData: true;\n /** Payload format version (semver). */\n readonly version: string;\n /** Navigation events collected during the test. */\n readonly navigations: readonly NavigationAnnotation[];\n /** Captured network requests during the test. */\n readonly networkRequests: readonly CapturedNetworkRequest[];\n /** API calls made via APIRequestContext proxy. */\n readonly apiCalls: readonly ApiCallRecord[];\n /** Assertions captured on API responses. */\n readonly apiAssertions: readonly ApiAssertion[];\n}\n\n/** Current payload format version. */\nexport const PAYLOAD_VERSION = '1.0.0';\n\n/** Attachment name used for the consolidated payload. */\nexport const ATTACHMENT_NAME = 'testrelic-data';\n\n/** Attachment content type. */\nexport const ATTACHMENT_CONTENT_TYPE = 'application/json';\n\n/** Type guard: validates that a parsed object is a TestRelicDataPayload. */\nexport function isTestRelicDataPayload(obj: unknown): obj is TestRelicDataPayload {\n if (typeof obj !== 'object' || obj === null) return false;\n const record = obj as Record<string, unknown>;\n return (\n record.testRelicData === true &&\n typeof record.version === 'string' &&\n record.version.length > 0 &&\n Array.isArray(record.navigations) &&\n Array.isArray(record.networkRequests) &&\n Array.isArray(record.apiCalls) &&\n Array.isArray(record.apiAssertions)\n );\n}\n\n// ---------------------------------------------------------------------------\n// Cloud Integration Types\n// ---------------------------------------------------------------------------\n\n/** Upload strategy for cloud timeline data. */\nexport type UploadStrategy = 'batch' | 'realtime' | 'both';\n\n/** Current cloud/local operating mode. */\nexport type AuthMode = 'cloud' | 'local' | 'pending';\n\n/** Resolved cloud configuration, immutable after initialization. */\nexport interface CloudConfig {\n readonly apiKey: string | null;\n readonly endpoint: string;\n readonly uploadStrategy: UploadStrategy;\n readonly timeout: number;\n readonly projectName: string | null;\n readonly queueMaxAge: number;\n readonly queueDirectory: string;\n}\n\n/** Mutable auth state tracked by the cloud client. */\nexport interface AuthState {\n mode: AuthMode;\n accessToken: string | null;\n refreshToken: string | null;\n expiresAt: number | null;\n orgId: string | null;\n orgName: string | null;\n userId: string | null;\n userName: string | null;\n}\n\n/** Auto-collected git information. All fields nullable. */\nexport interface GitMetadata {\n readonly branch: string | null;\n readonly commitSha: string | null;\n readonly commitMessage: string | null;\n readonly remoteUrl: string | null;\n}\n\n/** Cached project identity. */\nexport interface ProjectResolution {\n readonly projectId: string;\n readonly gitId: string;\n readonly displayName: string;\n readonly resolvedAt: number;\n readonly apiKeyHash: string;\n}\n\n/** A single queued upload payload. */\nexport interface QueueEntry {\n readonly version: string;\n readonly queuedAt: string;\n readonly reason: string;\n readonly retryCount: number;\n readonly targetEndpoint: string;\n readonly method: string;\n readonly payload: Record<string, unknown>;\n readonly headers: Record<string, string>;\n}\n\n/** Inline cloud configuration accepted via reporter options. */\nexport interface CloudReporterOptions {\n readonly apiKey?: string;\n readonly endpoint?: string;\n readonly upload?: UploadStrategy;\n readonly timeout?: number;\n readonly projectName?: string;\n readonly queueMaxAge?: string;\n readonly queueDirectory?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Merge CLI Types\n// ---------------------------------------------------------------------------\n\nexport interface MergeOptions {\n readonly output: string;\n readonly testRunId?: string;\n}\n","/**\n * @testrelic/core — Configurable logger\n *\n * Provides a Logger interface with a no-op default.\n * Never uses console.* directly (Constitution SDK Constraint).\n */\n\nexport interface Logger {\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n debug(message: string, ...args: unknown[]): void;\n}\n\nexport interface LoggerOptions {\n readonly handler?: (level: LogLevel, message: string, args: unknown[]) => void;\n}\n\nexport type LogLevel = 'info' | 'warn' | 'error' | 'debug';\n\ntype LogHandler = (level: LogLevel, message: string, args: unknown[]) => void;\n\nconst noopHandler: LogHandler = () => {};\n\nexport function createLogger(options?: LoggerOptions): Logger {\n const handler = options?.handler ?? noopHandler;\n\n return {\n info(message: string, ...args: unknown[]) {\n handler('info', message, args);\n },\n warn(message: string, ...args: unknown[]) {\n handler('warn', message, args);\n },\n error(message: string, ...args: unknown[]) {\n handler('error', message, args);\n },\n debug(message: string, ...args: unknown[]) {\n handler('debug', message, args);\n },\n };\n}\n","/**\n * @testrelic/core — Structured error factory\n *\n * Machine-readable error codes for programmatic handling.\n */\n\nexport const ErrorCode = {\n CONFIG_INVALID: 'TESTRELIC_CONFIG_INVALID',\n OUTPUT_WRITE_FAILED: 'TESTRELIC_OUTPUT_WRITE_FAILED',\n MERGE_INVALID_SCHEMA: 'TESTRELIC_MERGE_INVALID_SCHEMA',\n MERGE_READ_FAILED: 'TESTRELIC_MERGE_READ_FAILED',\n NAVIGATION_FLUSH_FAILED: 'TESTRELIC_NAVIGATION_FLUSH_FAILED',\n CODE_EXTRACT_FAILED: 'TESTRELIC_CODE_EXTRACT_FAILED',\n HTML_REPORT_FAILED: 'TESTRELIC_HTML_REPORT_FAILED',\n CLOUD_AUTH_FAILED: 'TESTRELIC_CLOUD_AUTH_FAILED',\n CLOUD_UPLOAD_FAILED: 'TESTRELIC_CLOUD_UPLOAD_FAILED',\n CLOUD_CONFIG_INVALID: 'TESTRELIC_CLOUD_CONFIG_INVALID',\n CLOUD_QUEUE_FAILED: 'TESTRELIC_CLOUD_QUEUE_FAILED',\n} as const;\n\nexport type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];\n\nexport class TestRelicError extends Error {\n readonly code: ErrorCode;\n\n constructor(code: ErrorCode, message: string, cause?: unknown) {\n super(message);\n this.name = 'TestRelicError';\n this.code = code;\n if (cause !== undefined) {\n Object.defineProperty(this, 'cause', { value: cause, writable: false, enumerable: false });\n }\n }\n}\n\nexport function createError(\n code: ErrorCode,\n message: string,\n cause?: unknown,\n): TestRelicError {\n return new TestRelicError(code, message, cause);\n}\n","/**\n * @testrelic/core — Lightweight runtime type guards\n *\n * Hand-written guards, no runtime schema libraries (Constitution SDK Constraint).\n */\n\nimport type {\n ReporterConfig,\n NavigationType,\n TestRunReport,\n CloudConfig,\n QueueEntry,\n UploadStrategy,\n} from './types.js';\n\nconst NAVIGATION_TYPES = new Set<string>([\n 'goto', 'navigation', 'back', 'forward', 'refresh',\n 'spa_route', 'spa_replace', 'hash_change', 'link_click',\n 'form_submit', 'redirect', 'popstate', 'page_load',\n 'manual_record', 'fallback', 'dummy',\n]);\n\nconst DANGEROUS_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport function isValidNavigationType(value: unknown): value is NavigationType {\n return typeof value === 'string' && NAVIGATION_TYPES.has(value);\n}\n\nfunction hasNoPrototypePollution(obj: unknown): boolean {\n if (typeof obj !== 'object' || obj === null) return true;\n for (const key of Object.keys(obj)) {\n if (DANGEROUS_KEYS.has(key)) return false;\n }\n return true;\n}\n\nexport function isValidConfig(input: unknown): input is ReporterConfig {\n if (typeof input !== 'object' || input === null) return false;\n if (!hasNoPrototypePollution(input)) return false;\n\n const obj = input as Record<string, unknown>;\n\n if (obj.outputPath !== undefined && typeof obj.outputPath !== 'string') return false;\n if (obj.includeStackTrace !== undefined && typeof obj.includeStackTrace !== 'boolean') return false;\n if (obj.includeCodeSnippets !== undefined && typeof obj.includeCodeSnippets !== 'boolean') return false;\n if (obj.codeContextLines !== undefined && typeof obj.codeContextLines !== 'number') return false;\n if (obj.includeNetworkStats !== undefined && typeof obj.includeNetworkStats !== 'boolean') return false;\n\n if (obj.navigationTypes !== undefined && obj.navigationTypes !== null) {\n if (!Array.isArray(obj.navigationTypes)) return false;\n for (const t of obj.navigationTypes) {\n if (!isValidNavigationType(t)) return false;\n }\n }\n\n if (obj.redactPatterns !== undefined) {\n if (!Array.isArray(obj.redactPatterns)) return false;\n for (const p of obj.redactPatterns) {\n if (typeof p !== 'string' && !(p instanceof RegExp)) return false;\n }\n }\n\n if (obj.testRunId !== undefined && obj.testRunId !== null && typeof obj.testRunId !== 'string') return false;\n\n if (obj.metadata !== undefined && obj.metadata !== null) {\n if (typeof obj.metadata !== 'object') return false;\n if (!hasNoPrototypePollution(obj.metadata)) return false;\n }\n\n if (obj.openReport !== undefined && typeof obj.openReport !== 'boolean') return false;\n if (obj.htmlReportPath !== undefined && (typeof obj.htmlReportPath !== 'string' || obj.htmlReportPath === '')) return false;\n if (obj.includeArtifacts !== undefined && typeof obj.includeArtifacts !== 'boolean') return false;\n\n // API tracking configuration\n if (obj.trackApiCalls !== undefined && typeof obj.trackApiCalls !== 'boolean') return false;\n if (obj.captureRequestHeaders !== undefined && typeof obj.captureRequestHeaders !== 'boolean') return false;\n if (obj.captureResponseHeaders !== undefined && typeof obj.captureResponseHeaders !== 'boolean') return false;\n if (obj.captureRequestBody !== undefined && typeof obj.captureRequestBody !== 'boolean') return false;\n if (obj.captureResponseBody !== undefined && typeof obj.captureResponseBody !== 'boolean') return false;\n if (obj.captureAssertions !== undefined && typeof obj.captureAssertions !== 'boolean') return false;\n\n if (obj.redactHeaders !== undefined) {\n if (!Array.isArray(obj.redactHeaders)) return false;\n for (const h of obj.redactHeaders) {\n if (typeof h !== 'string') return false;\n }\n }\n\n if (obj.redactBodyFields !== undefined) {\n if (!Array.isArray(obj.redactBodyFields)) return false;\n for (const f of obj.redactBodyFields) {\n if (typeof f !== 'string') return false;\n }\n }\n\n if (obj.apiIncludeUrls !== undefined) {\n if (!Array.isArray(obj.apiIncludeUrls)) return false;\n for (const p of obj.apiIncludeUrls) {\n if (typeof p !== 'string' && !(p instanceof RegExp)) return false;\n }\n }\n\n if (obj.apiExcludeUrls !== undefined) {\n if (!Array.isArray(obj.apiExcludeUrls)) return false;\n for (const p of obj.apiExcludeUrls) {\n if (typeof p !== 'string' && !(p instanceof RegExp)) return false;\n }\n }\n\n return true;\n}\n\n// ---------------------------------------------------------------------------\n// Cloud Config Validation\n// ---------------------------------------------------------------------------\n\nconst API_KEY_PATTERN = /^tr[a-z]*_[a-z]+_[a-zA-Z0-9]+$/;\n\nconst UPLOAD_STRATEGIES = new Set<string>(['batch', 'realtime', 'both']);\n\nconst LOCALHOST_HOSTS = new Set(['localhost', '127.0.0.1', '0.0.0.0']);\n\nexport function isValidApiKeyFormat(value: unknown): value is string {\n return typeof value === 'string' && API_KEY_PATTERN.test(value);\n}\n\nexport function isValidUploadStrategy(value: unknown): value is UploadStrategy {\n return typeof value === 'string' && UPLOAD_STRATEGIES.has(value);\n}\n\nexport function isValidEndpointUrl(value: unknown): boolean {\n if (typeof value !== 'string') return false;\n try {\n const url = new URL(value);\n if (url.protocol === 'https:') return true;\n if (url.protocol === 'http:' && LOCALHOST_HOSTS.has(url.hostname)) return true;\n return false;\n } catch {\n return false;\n }\n}\n\nexport function isValidCloudConfig(input: unknown): input is CloudConfig {\n if (typeof input !== 'object' || input === null) return false;\n if (!hasNoPrototypePollution(input)) return false;\n\n const obj = input as Record<string, unknown>;\n\n if (obj.apiKey !== undefined && obj.apiKey !== null) {\n if (typeof obj.apiKey !== 'string') return false;\n if (obj.apiKey.length > 0 && !isValidApiKeyFormat(obj.apiKey)) return false;\n }\n\n if (obj.endpoint !== undefined) {\n if (!isValidEndpointUrl(obj.endpoint)) return false;\n }\n\n if (obj.uploadStrategy !== undefined) {\n if (!isValidUploadStrategy(obj.uploadStrategy)) return false;\n }\n\n if (obj.timeout !== undefined) {\n if (typeof obj.timeout !== 'number' || obj.timeout < 1000 || obj.timeout > 120000) return false;\n }\n\n if (obj.projectName !== undefined && obj.projectName !== null && typeof obj.projectName !== 'string') return false;\n\n if (obj.queueMaxAge !== undefined) {\n if (typeof obj.queueMaxAge !== 'number' || obj.queueMaxAge < 3600000 || obj.queueMaxAge > 2592000000) return false;\n }\n\n if (obj.queueDirectory !== undefined) {\n if (typeof obj.queueDirectory !== 'string') return false;\n if (obj.queueDirectory.startsWith('/') || obj.queueDirectory.includes('..')) return false;\n }\n\n return true;\n}\n\nexport function isValidQueueEntry(input: unknown): input is QueueEntry {\n if (typeof input !== 'object' || input === null) return false;\n if (!hasNoPrototypePollution(input)) return false;\n\n const obj = input as Record<string, unknown>;\n\n if (typeof obj.version !== 'string') return false;\n if (typeof obj.queuedAt !== 'string') return false;\n if (typeof obj.reason !== 'string') return false;\n if (typeof obj.retryCount !== 'number') return false;\n if (typeof obj.targetEndpoint !== 'string') return false;\n if (typeof obj.method !== 'string') return false;\n if (typeof obj.payload !== 'object' || obj.payload === null) return false;\n if (typeof obj.headers !== 'object' || obj.headers === null) return false;\n\n return true;\n}\n\nexport function isValidTestRunReport(value: unknown): value is TestRunReport {\n if (typeof value !== 'object' || value === null) return false;\n\n const obj = value as Record<string, unknown>;\n\n if (typeof obj.schemaVersion !== 'string') return false;\n if (typeof obj.testRunId !== 'string') return false;\n if (typeof obj.startedAt !== 'string') return false;\n if (typeof obj.completedAt !== 'string') return false;\n if (typeof obj.totalDuration !== 'number') return false;\n if (typeof obj.summary !== 'object' || obj.summary === null) return false;\n if (!Array.isArray(obj.timeline)) return false;\n\n const summary = obj.summary as Record<string, unknown>;\n if (typeof summary.total !== 'number') return false;\n if (typeof summary.passed !== 'number') return false;\n if (typeof summary.failed !== 'number') return false;\n if (typeof summary.flaky !== 'number') return false;\n if (typeof summary.skipped !== 'number') return false;\n // timedout is optional for backward compat with schema 1.0.0\n if (summary.timedout !== undefined && typeof summary.timedout !== 'number') return false;\n\n return true;\n}\n"],"mappings":";AAwcO,IAAM,kBAAkB;AAGxB,IAAM,kBAAkB;AAGxB,IAAM,0BAA0B;AAGhC,SAAS,uBAAuB,KAA2C;AAChF,MAAI,OAAO,QAAQ,YAAY,QAAQ,KAAM,QAAO;AACpD,QAAM,SAAS;AACf,SACE,OAAO,kBAAkB,QACzB,OAAO,OAAO,YAAY,YAC1B,OAAO,QAAQ,SAAS,KACxB,MAAM,QAAQ,OAAO,WAAW,KAChC,MAAM,QAAQ,OAAO,eAAe,KACpC,MAAM,QAAQ,OAAO,QAAQ,KAC7B,MAAM,QAAQ,OAAO,aAAa;AAEtC;;;ACvcA,IAAM,cAA0B,MAAM;AAAC;AAEhC,SA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AY,YAAY,IAAI,YAAY,KAAM,QAAO;AAEpE,SAAO;AACT;AAEO,SAAS,qBAAqB,OAAwC;AAC3E,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AAExD,QAAM,MAAM;AAEZ,MAAI,OAAO,IAAI,kBAAkB,SAAU,QAAO;AAClD,MAAI,OAAO,IAAI,cAAc,SAAU,QAAO;AAC9C,MAAI,OAAO,IAAI,cAAc,SAAU,QAAO;AAC9C,MAAI,OAAO,IAAI,gBAAgB,SAAU,QAAO;AAChD,MAAI,OAAO,IAAI,kBAAkB,SAAU,QAAO;AAClD,MAAI,OAAO,IAAI,YAAY,YAAY,IAAI,YAAY,KAAM,QAAO;AACpE,MAAI,CAAC,MAAM,QAAQ,IAAI,QAAQ,EAAG,QAAO;AAEzC,QAAM,UAAU,IAAI;AACpB,MAAI,OAAO,QAAQ,UAAU,SAAU,QAAO;AAC9C,MAAI,OAAO,QAAQ,WAAW,SAAU,QAAO;AAC/C,MAAI,OAAO,QAAQ,WAAW,SAAU,QAAO;AAC/C,MAAI,OAAO,QAAQ,UAAU,SAAU,QAAO;AAC9C,MAAI,OAAO,QAAQ,YAAY,SAAU,QAAO;AAEhD,MAAI,QAAQ,aAAa,UAAa,OAAO,QAAQ,aAAa,SAAU,QAAO;AAEnF,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testrelic/core",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "Shared types, logger, errors, and validation for TestRelic packages",
5
5
  "keywords": [
6
6
  "testrelic",