@tracelog/lib 0.11.5 → 0.12.0

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.
@@ -204,12 +204,12 @@ var Mode = /* @__PURE__ */ ((Mode2) => {
204
204
  })(Mode || {});
205
205
 
206
206
  // src/types/scroll.types.ts
207
- function isPrimaryScrollEvent(event2) {
207
+ var isPrimaryScrollEvent = (event2) => {
208
208
  return event2.type === "scroll" /* SCROLL */ && "scroll_data" in event2 && event2.scroll_data.is_primary === true;
209
- }
210
- function isSecondaryScrollEvent(event2) {
209
+ };
210
+ var isSecondaryScrollEvent = (event2) => {
211
211
  return event2.type === "scroll" /* SCROLL */ && "scroll_data" in event2 && event2.scroll_data.is_primary === false;
212
- }
212
+ };
213
213
 
214
214
  // src/types/validation-error.types.ts
215
215
  var TraceLogValidationError = class extends Error {
@@ -346,14 +346,59 @@ var SESSION_STORAGE_KEY = (id) => id ? `${STORAGE_BASE_KEY}:${id}:session` : `${
346
346
  var BROADCAST_CHANNEL_NAME = (id) => id ? `${STORAGE_BASE_KEY}:${id}:broadcast` : `${STORAGE_BASE_KEY}:broadcast`;
347
347
 
348
348
  // src/constants/performance.constants.ts
349
- var WEB_VITALS_THRESHOLDS = {
350
- LCP: 4e3,
349
+ var WEB_VITALS_GOOD_THRESHOLDS = {
350
+ LCP: 2500,
351
+ // Good: ≤ 2.5s
351
352
  FCP: 1800,
352
- CLS: 0.25,
353
+ // Good: ≤ 1.8s
354
+ CLS: 0.1,
355
+ // Good: ≤ 0.1
356
+ INP: 200,
357
+ // Good: ≤ 200ms
358
+ TTFB: 800,
359
+ // Good: ≤ 800ms
360
+ LONG_TASK: 50
361
+ };
362
+ var WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS = {
363
+ LCP: 2500,
364
+ // Needs improvement: > 2.5s (same as good boundary)
365
+ FCP: 1800,
366
+ // Needs improvement: > 1.8s
367
+ CLS: 0.1,
368
+ // Needs improvement: > 0.1
353
369
  INP: 200,
370
+ // Needs improvement: > 200ms
354
371
  TTFB: 800,
372
+ // Needs improvement: > 800ms
355
373
  LONG_TASK: 50
356
374
  };
375
+ var WEB_VITALS_POOR_THRESHOLDS = {
376
+ LCP: 4e3,
377
+ // Poor: > 4s
378
+ FCP: 3e3,
379
+ // Poor: > 3s
380
+ CLS: 0.25,
381
+ // Poor: > 0.25
382
+ INP: 500,
383
+ // Poor: > 500ms
384
+ TTFB: 1800,
385
+ // Poor: > 1800ms
386
+ LONG_TASK: 50
387
+ };
388
+ var DEFAULT_WEB_VITALS_MODE = "needs-improvement";
389
+ var getWebVitalsThresholds = (mode = DEFAULT_WEB_VITALS_MODE) => {
390
+ switch (mode) {
391
+ case "all":
392
+ return { LCP: 0, FCP: 0, CLS: 0, INP: 0, TTFB: 0, LONG_TASK: 0 };
393
+ // Track everything
394
+ case "needs-improvement":
395
+ return WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS;
396
+ case "poor":
397
+ return WEB_VITALS_POOR_THRESHOLDS;
398
+ default:
399
+ return WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS;
400
+ }
401
+ };
357
402
  var LONG_TASK_THROTTLE_MS = 1e3;
358
403
  var MAX_NAVIGATION_HISTORY = 50;
359
404
 
@@ -695,6 +740,41 @@ var validateAppConfig = (config) => {
695
740
  if (config.viewport !== void 0) {
696
741
  validateViewportConfig(config.viewport);
697
742
  }
743
+ if (config.webVitalsMode !== void 0) {
744
+ if (typeof config.webVitalsMode !== "string") {
745
+ throw new AppConfigValidationError(
746
+ `Invalid webVitalsMode type: ${typeof config.webVitalsMode}. Must be a string`,
747
+ "config"
748
+ );
749
+ }
750
+ const validModes = ["all", "needs-improvement", "poor"];
751
+ if (!validModes.includes(config.webVitalsMode)) {
752
+ throw new AppConfigValidationError(
753
+ `Invalid webVitalsMode: "${config.webVitalsMode}". Must be one of: ${validModes.join(", ")}`,
754
+ "config"
755
+ );
756
+ }
757
+ }
758
+ if (config.webVitalsThresholds !== void 0) {
759
+ if (typeof config.webVitalsThresholds !== "object" || config.webVitalsThresholds === null || Array.isArray(config.webVitalsThresholds)) {
760
+ throw new AppConfigValidationError("webVitalsThresholds must be an object", "config");
761
+ }
762
+ const validKeys = ["LCP", "FCP", "CLS", "INP", "TTFB", "LONG_TASK"];
763
+ for (const [key, value] of Object.entries(config.webVitalsThresholds)) {
764
+ if (!validKeys.includes(key)) {
765
+ throw new AppConfigValidationError(
766
+ `Invalid Web Vitals threshold key: "${key}". Must be one of: ${validKeys.join(", ")}`,
767
+ "config"
768
+ );
769
+ }
770
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
771
+ throw new AppConfigValidationError(
772
+ `Invalid Web Vitals threshold value for ${key}: ${value}. Must be a non-negative finite number`,
773
+ "config"
774
+ );
775
+ }
776
+ }
777
+ }
698
778
  };
699
779
  var validateViewportConfig = (viewport) => {
700
780
  if (typeof viewport !== "object" || viewport === null) {
@@ -3461,13 +3541,20 @@ var PerformanceHandler = class extends StateManager {
3461
3541
  navigationHistory = [];
3462
3542
  // FIFO queue for tracking navigation order
3463
3543
  observers = [];
3464
- vitalThresholds = WEB_VITALS_THRESHOLDS;
3544
+ vitalThresholds;
3465
3545
  lastLongTaskSentAt = 0;
3466
3546
  constructor(eventManager) {
3467
3547
  super();
3468
3548
  this.eventManager = eventManager;
3549
+ this.vitalThresholds = getWebVitalsThresholds(DEFAULT_WEB_VITALS_MODE);
3469
3550
  }
3470
3551
  async startTracking() {
3552
+ const config = this.get("config");
3553
+ const mode = config?.webVitalsMode ?? DEFAULT_WEB_VITALS_MODE;
3554
+ this.vitalThresholds = getWebVitalsThresholds(mode);
3555
+ if (config?.webVitalsThresholds) {
3556
+ this.vitalThresholds = { ...this.vitalThresholds, ...config.webVitalsThresholds };
3557
+ }
3471
3558
  await this.initWebVitals();
3472
3559
  this.observeLongTasks();
3473
3560
  }
@@ -4285,14 +4372,6 @@ if (process.env.NODE_ENV === "development" && typeof window !== "undefined" && t
4285
4372
  }
4286
4373
 
4287
4374
  // src/app.constants.ts
4288
- var PERFORMANCE_CONFIG = {
4289
- WEB_VITALS_THRESHOLDS
4290
- // Business thresholds for performance analysis
4291
- };
4292
- var DATA_PROTECTION = {
4293
- PII_PATTERNS
4294
- // Patterns for sensitive data protection
4295
- };
4296
4375
  var ENGAGEMENT_THRESHOLDS = {
4297
4376
  LOW_ACTIVITY_EVENT_COUNT: 50,
4298
4377
  HIGH_ACTIVITY_EVENT_COUNT: 1e3,
@@ -4389,7 +4468,7 @@ exports.ANALYTICS_QUERY_LIMITS = ANALYTICS_QUERY_LIMITS;
4389
4468
  exports.ANOMALY_DETECTION = ANOMALY_DETECTION;
4390
4469
  exports.AppConfigValidationError = AppConfigValidationError;
4391
4470
  exports.CONTENT_ANALYTICS = CONTENT_ANALYTICS;
4392
- exports.DATA_PROTECTION = DATA_PROTECTION;
4471
+ exports.DEFAULT_WEB_VITALS_MODE = DEFAULT_WEB_VITALS_MODE;
4393
4472
  exports.DEVICE_ANALYTICS = DEVICE_ANALYTICS;
4394
4473
  exports.DeviceType = DeviceType;
4395
4474
  exports.ENGAGEMENT_THRESHOLDS = ENGAGEMENT_THRESHOLDS;
@@ -4409,7 +4488,7 @@ exports.MAX_NESTED_OBJECT_KEYS = MAX_NESTED_OBJECT_KEYS;
4409
4488
  exports.MAX_STRING_LENGTH = MAX_STRING_LENGTH;
4410
4489
  exports.MAX_STRING_LENGTH_IN_ARRAY = MAX_STRING_LENGTH_IN_ARRAY;
4411
4490
  exports.Mode = Mode;
4412
- exports.PERFORMANCE_CONFIG = PERFORMANCE_CONFIG;
4491
+ exports.PII_PATTERNS = PII_PATTERNS;
4413
4492
  exports.PermanentError = PermanentError;
4414
4493
  exports.SEGMENTATION_ANALYTICS = SEGMENTATION_ANALYTICS;
4415
4494
  exports.SESSION_ANALYTICS = SESSION_ANALYTICS;
@@ -4420,6 +4499,10 @@ exports.SessionTimeoutValidationError = SessionTimeoutValidationError;
4420
4499
  exports.SpecialApiUrl = SpecialApiUrl;
4421
4500
  exports.TEMPORAL_ANALYSIS = TEMPORAL_ANALYSIS;
4422
4501
  exports.TraceLogValidationError = TraceLogValidationError;
4502
+ exports.WEB_VITALS_GOOD_THRESHOLDS = WEB_VITALS_GOOD_THRESHOLDS;
4503
+ exports.WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS = WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS;
4504
+ exports.WEB_VITALS_POOR_THRESHOLDS = WEB_VITALS_POOR_THRESHOLDS;
4505
+ exports.getWebVitalsThresholds = getWebVitalsThresholds;
4423
4506
  exports.isPrimaryScrollEvent = isPrimaryScrollEvent;
4424
4507
  exports.isSecondaryScrollEvent = isSecondaryScrollEvent;
4425
4508
  exports.tracelog = tracelog;