@tracelog/lib 3.1.1-rc.120.6 → 3.1.1-rc.120.7

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/README.md CHANGED
@@ -189,7 +189,8 @@ await tracelog.init({
189
189
  integrations: {
190
190
  tracelog: {
191
191
  projectId: 'your-project-id',
192
- shopify: false // Optional: enable Shopify cart attribute linking
192
+ shopify: false, // Optional: enable Shopify cart attribute linking
193
+ healthBeacon: true // Optional (default true): diagnostic beacon when ingest is blocked (403)
193
194
  }
194
195
  }
195
196
  });
@@ -67,7 +67,7 @@ const y = {
67
67
  /<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
68
68
  /<embed\b[^>]*>/gi,
69
69
  /<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi
70
- ], g = "tlog", z = `${g}:qa_mode`, Se = `${g}:uid`, nt = "tlog_mode", Ue = "qa", Fe = "qa_off", ce = (n) => n ? `${g}:${n}:queue` : `${g}:queue`, le = (n) => n ? `${g}:${n}:rate_limit` : `${g}:rate_limit`, It = (n) => `${g}:beacon:${n}`, wt = (n) => n ? `${g}:${n}:session` : `${g}:session`, At = (n) => n ? `${g}:${n}:broadcast` : `${g}:broadcast`, Ve = (n, e) => `${g}:${n}:session_counts:${e}`, He = 10080 * 60 * 1e3, xe = `${g}:session_counts_last_cleanup`, Be = 3600 * 1e3, ue = (n) => n ? `${g}:${n}:identity` : `${g}:identity`, P = `${g}:pending_identity`;
70
+ ], g = "tlog", z = `${g}:qa_mode`, Se = `${g}:uid`, nt = "tlog_mode", Ue = "qa", Fe = "qa_off", ce = (n) => n ? `${g}:${n}:queue` : `${g}:queue`, le = (n) => n ? `${g}:${n}:rate_limit` : `${g}:rate_limit`, It = (n, e) => `${g}:beacon:${n}:${e}`, wt = (n) => n ? `${g}:${n}:session` : `${g}:session`, At = (n) => n ? `${g}:${n}:broadcast` : `${g}:broadcast`, Ve = (n, e) => `${g}:${n}:session_counts:${e}`, He = 10080 * 60 * 1e3, xe = `${g}:session_counts_last_cleanup`, $e = 3600 * 1e3, ue = (n) => n ? `${g}:${n}:identity` : `${g}:identity`, P = `${g}:pending_identity`;
71
71
  var M = /* @__PURE__ */ ((n) => (n.Localhost = "localhost:8080", n.Fail = "localhost:9999", n))(M || {}), w = /* @__PURE__ */ ((n) => (n.Mobile = "mobile", n.Tablet = "tablet", n.Desktop = "desktop", n.Unknown = "unknown", n))(w || {}), U = /* @__PURE__ */ ((n) => (n.EVENT = "event", n.QUEUE = "queue", n))(U || {});
72
72
  class C extends Error {
73
73
  constructor(e, t, s) {
@@ -87,34 +87,34 @@ class Z extends Error {
87
87
  }
88
88
  }
89
89
  var d = /* @__PURE__ */ ((n) => (n.PAGE_VIEW = "page_view", n.CLICK = "click", n.SCROLL = "scroll", n.SESSION_START = "session_start", n.CUSTOM = "custom", n.WEB_VITALS = "web_vitals", n.ERROR = "error", n))(d || {}), Ee = /* @__PURE__ */ ((n) => (n.UP = "up", n.DOWN = "down", n))(Ee || {}), V = /* @__PURE__ */ ((n) => (n.JS_ERROR = "js_error", n.PROMISE_REJECTION = "promise_rejection", n))(V || {}), ee = /* @__PURE__ */ ((n) => (n.QA = "qa", n))(ee || {});
90
- class B extends Error {
90
+ class $ extends Error {
91
91
  constructor(e, t, s) {
92
92
  super(e), this.errorCode = t, this.layer = s, this.name = this.constructor.name, Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
93
93
  }
94
94
  errorCode;
95
95
  layer;
96
96
  }
97
- class m extends B {
97
+ class m extends $ {
98
98
  constructor(e, t = "config") {
99
99
  super(e, "APP_CONFIG_INVALID", t);
100
100
  }
101
101
  }
102
- class bt extends B {
102
+ class bt extends $ {
103
103
  constructor(e, t = "config") {
104
104
  super(e, "SESSION_TIMEOUT_INVALID", t);
105
105
  }
106
106
  }
107
- class $e extends B {
107
+ class Be extends $ {
108
108
  constructor(e, t = "config") {
109
109
  super(e, "SAMPLING_RATE_INVALID", t);
110
110
  }
111
111
  }
112
- class Xe extends B {
112
+ class Xe extends $ {
113
113
  constructor(e, t = "config") {
114
114
  super(e, "INTEGRATION_INVALID", t);
115
115
  }
116
116
  }
117
- class An extends B {
117
+ class An extends $ {
118
118
  constructor(e, t, s = "runtime") {
119
119
  super(e, "INITIALIZATION_TIMEOUT", s), this.timeoutMs = t;
120
120
  }
@@ -230,7 +230,7 @@ const Ut = () => {
230
230
  browser: te
231
231
  };
232
232
  }
233
- }, je = 500, Ge = 2e3, We = 5e3, Q = 50, Bt = Q * 2, it = 1, $t = 1e3, Xt = 10, Ke = 5e3, jt = 3, Gt = 200, Wt = 6e4, Kt = 64, zt = 10 * 6e4, Qt = 200, bn = {
233
+ }, je = 500, Ge = 2e3, We = 5e3, Q = 50, $t = Q * 2, it = 1, Bt = 1e3, Xt = 10, Ke = 5e3, jt = 3, Gt = 200, Wt = 6e4, Kt = 64, zt = 10 * 6e4, Qt = 200, bn = {
234
234
  LCP: 2500,
235
235
  FCP: 1800,
236
236
  CLS: 0.1,
@@ -477,9 +477,9 @@ const is = () => {
477
477
  throw new m("All sensitive query params must be strings", "config");
478
478
  }
479
479
  if (n.errorSampling !== void 0 && (typeof n.errorSampling != "number" || n.errorSampling < 0 || n.errorSampling > 1))
480
- throw new $e(y.INVALID_ERROR_SAMPLING_RATE, "config");
480
+ throw new Be(y.INVALID_ERROR_SAMPLING_RATE, "config");
481
481
  if (n.samplingRate !== void 0 && (typeof n.samplingRate != "number" || n.samplingRate < 0 || n.samplingRate > 1))
482
- throw new $e(y.INVALID_SAMPLING_RATE, "config");
482
+ throw new Be(y.INVALID_SAMPLING_RATE, "config");
483
483
  if (n.pageViewThrottleMs !== void 0 && (typeof n.pageViewThrottleMs != "number" || n.pageViewThrottleMs < 0))
484
484
  throw new m(y.INVALID_PAGE_VIEW_THROTTLE, "config");
485
485
  if (n.clickThrottleMs !== void 0 && (typeof n.clickThrottleMs != "number" || n.clickThrottleMs < 0))
@@ -1300,8 +1300,10 @@ class Ls extends T {
1300
1300
  const s = this.get("config")?.integrations?.tracelog;
1301
1301
  if (!s?.projectId || s.healthBeacon === !1) return;
1302
1302
  const r = this.resolveBeaconUrl();
1303
- if (!r || !this.markBeaconEmitted(e)) return;
1304
- const i = typeof window < "u" && window.location ? window.location.origin : "", o = JSON.stringify({
1303
+ if (!r) return;
1304
+ const i = typeof window < "u" && window.location ? window.location.origin : "";
1305
+ if (!i || !this.markBeaconEmitted(s.projectId, e)) return;
1306
+ const o = JSON.stringify({
1305
1307
  projectId: s.projectId,
1306
1308
  reason: e,
1307
1309
  origin: i,
@@ -1321,18 +1323,18 @@ class Ls extends T {
1321
1323
  * transports fail, waiting out the window is fine for a diagnostic signal
1322
1324
  * and avoids turning transport failures into retry bursts.
1323
1325
  */
1324
- markBeaconEmitted(e) {
1325
- const t = Date.now(), s = It(e);
1326
- let r = this.lastBeaconAt[e] ?? 0;
1326
+ markBeaconEmitted(e, t) {
1327
+ const s = Date.now(), r = It(e, t);
1328
+ let i = this.lastBeaconAt[t] ?? 0;
1327
1329
  try {
1328
- const i = Number(this.storeManager.getItem(s));
1329
- Number.isFinite(i) && i > r && (r = i);
1330
+ const o = Number(this.storeManager.getItem(r));
1331
+ Number.isFinite(o) && o > i && (i = o);
1330
1332
  } catch {
1331
1333
  }
1332
- if (t - r < zt) return !1;
1333
- this.lastBeaconAt[e] = t;
1334
+ if (s - i < zt) return !1;
1335
+ this.lastBeaconAt[t] = s;
1334
1336
  try {
1335
- this.storeManager.setItem(s, String(t));
1337
+ this.storeManager.setItem(r, String(s));
1336
1338
  } catch {
1337
1339
  }
1338
1340
  return !0;
@@ -2338,9 +2340,9 @@ class Rs extends T {
2338
2340
  const e = localStorage.getItem(xe);
2339
2341
  if (e) {
2340
2342
  const i = Date.now() - parseInt(e, 10);
2341
- if (i < Be) {
2343
+ if (i < $e) {
2342
2344
  a("debug", "Skipping session counts cleanup (throttled)", {
2343
- data: { timeSinceLastCleanup: i, throttleMs: Be }
2345
+ data: { timeSinceLastCleanup: i, throttleMs: $e }
2344
2346
  });
2345
2347
  return;
2346
2348
  }
@@ -3382,7 +3384,7 @@ class xs extends T {
3382
3384
  this.visibilityHandler && (document.removeEventListener("visibilitychange", this.visibilityHandler), this.visibilityHandler = null), this.pageshowHandler && (window.removeEventListener("pageshow", this.pageshowHandler), this.pageshowHandler = null);
3383
3385
  }
3384
3386
  }
3385
- class Bs {
3387
+ class $s {
3386
3388
  storage;
3387
3389
  sessionStorageRef;
3388
3390
  fallbackStorage = /* @__PURE__ */ new Map();
@@ -3495,7 +3497,7 @@ class Bs {
3495
3497
  this.fallbackSessionStorage.delete(e);
3496
3498
  }
3497
3499
  }
3498
- class $s extends T {
3500
+ class Bs extends T {
3499
3501
  eventManager;
3500
3502
  reportedByNav = /* @__PURE__ */ new Map();
3501
3503
  navigationHistory = [];
@@ -3770,7 +3772,7 @@ class se extends T {
3770
3772
  const e = Date.now();
3771
3773
  if (e < this.burstBackoffUntil)
3772
3774
  return !1;
3773
- if (e - this.burstWindowStart > $t && (this.errorBurstCounter = 0, this.burstWindowStart = e), this.errorBurstCounter++, this.errorBurstCounter > Xt)
3775
+ if (e - this.burstWindowStart > Bt && (this.errorBurstCounter = 0, this.burstWindowStart = e), this.errorBurstCounter++, this.errorBurstCounter > Xt)
3774
3776
  return this.burstBackoffUntil = e + Ke, a("debug", "Error burst detected - entering cooldown", {
3775
3777
  data: {
3776
3778
  errorsInWindow: this.errorBurstCounter,
@@ -3860,7 +3862,7 @@ class se extends T {
3860
3862
  }
3861
3863
  shouldSuppressError(e, t) {
3862
3864
  const s = Date.now(), r = `${e}:${t}`, i = this.recentErrors.get(r);
3863
- return i !== void 0 && s - i < We ? (this.recentErrors.set(r, s), !0) : (this.recentErrors.set(r, s), this.recentErrors.size > Bt ? (this.recentErrors.clear(), this.recentErrors.set(r, s), !1) : (this.recentErrors.size > Q && this.pruneOldErrors(), !1));
3865
+ return i !== void 0 && s - i < We ? (this.recentErrors.set(r, s), !0) : (this.recentErrors.set(r, s), this.recentErrors.size > $t ? (this.recentErrors.clear(), this.recentErrors.set(r, s), !1) : (this.recentErrors.size > Q && this.pruneOldErrors(), !1));
3864
3866
  }
3865
3867
  static TRUNCATION_SUFFIX = `
3866
3868
  ...truncated`;
@@ -3904,7 +3906,7 @@ class Xs extends T {
3904
3906
  async init(e = {}) {
3905
3907
  if (this.isInitialized)
3906
3908
  return { sessionId: this.get("sessionId") ?? "" };
3907
- this.managers.storage = new Bs();
3909
+ this.managers.storage = new $s();
3908
3910
  try {
3909
3911
  return this.setupState(e), this.managers.event = new Rs(this.managers.storage, this.emitter), this.loadPersistedIdentity(), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((t) => {
3910
3912
  a("warn", "Failed to recover persisted events", { error: t });
@@ -4163,7 +4165,7 @@ class Xs extends T {
4163
4165
  this.set("suppressNextScroll", !1);
4164
4166
  }, 500);
4165
4167
  };
4166
- this.handlers.pageView = new Ds(this.managers.event, t), this.handlers.click = new Us(this.managers.event), this.handlers.scroll = new Fs(this.managers.event), this.handlers.performance = new $s(this.managers.event), this.handlers.error = new se(this.managers.event, this.emitter);
4168
+ this.handlers.pageView = new Ds(this.managers.event, t), this.handlers.click = new Us(this.managers.event), this.handlers.scroll = new Fs(this.managers.event), this.handlers.performance = new Bs(this.managers.event), this.handlers.error = new se(this.managers.event, this.emitter);
4167
4169
  const s = () => {
4168
4170
  if (this.handlers.pageView?.startTracking(), this.handlers.click?.startTracking(), this.handlers.scroll?.startTracking(), this.handlers.performance?.startTracking().catch((r) => {
4169
4171
  a("warn", "Failed to start performance tracking", { error: r });
@@ -4338,7 +4340,7 @@ var be, L, x, ct, ne, lt = -1, O = function(n) {
4338
4340
  return n();
4339
4341
  }));
4340
4342
  }));
4341
- }, $ = function(n) {
4343
+ }, B = function(n) {
4342
4344
  document.addEventListener("visibilitychange", (function() {
4343
4345
  document.visibilityState === "hidden" && n();
4344
4346
  }));
@@ -4390,7 +4392,7 @@ var be, L, x, ct, ne, lt = -1, O = function(n) {
4390
4392
  }
4391
4393
  })), r > s.value && (s.value = r, s.entries = i, t());
4392
4394
  }, c = F("layout-shift", o);
4393
- c && (t = v(n, s, Me, e.reportAllChanges), $((function() {
4395
+ c && (t = v(n, s, Me, e.reportAllChanges), B((function() {
4394
4396
  o(c.takeRecords()), t(!0);
4395
4397
  })), O((function() {
4396
4398
  r = 0, s = E("CLS", 0), t = v(n, s, Me, e.reportAllChanges), ke((function() {
@@ -4429,7 +4431,7 @@ var be, L, x, ct, ne, lt = -1, O = function(n) {
4429
4431
  }
4430
4432
  }, gt = function(n) {
4431
4433
  var e = self.requestIdleCallback || self.setTimeout, t = -1;
4432
- return n = oe(n), document.visibilityState === "hidden" ? n() : (t = e(n), $(n)), t;
4434
+ return n = oe(n), document.visibilityState === "hidden" ? n() : (t = e(n), B(n)), t;
4433
4435
  }, Ce = [200, 500], cn = function(n, e) {
4434
4436
  "PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, X((function() {
4435
4437
  var t;
@@ -4441,7 +4443,7 @@ var be, L, x, ct, ne, lt = -1, O = function(n) {
4441
4443
  l && l.latency !== r.value && (r.value = l.latency, r.entries = l.entries, s());
4442
4444
  }));
4443
4445
  }, o = F("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
4444
- s = v(n, r, Ce, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), $((function() {
4446
+ s = v(n, r, Ce, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), B((function() {
4445
4447
  i(o.takeRecords()), s(!0);
4446
4448
  })), O((function() {
4447
4449
  ft = ht(), I.length = 0, q.clear(), r = E("INP"), s = v(n, r, Ce, e.reportAllChanges);
@@ -4463,7 +4465,7 @@ var be, L, x, ct, ne, lt = -1, O = function(n) {
4463
4465
  addEventListener(l, (function() {
4464
4466
  return gt(c);
4465
4467
  }), { once: !0, capture: !0 });
4466
- })), $(c), O((function(l) {
4468
+ })), B(c), O((function(l) {
4467
4469
  r = E("LCP"), t = v(n, r, Re, e.reportAllChanges), ke((function() {
4468
4470
  r.value = performance.now() - l.timeStamp, pe[r.id] = !0, t(!0);
4469
4471
  }));
@@ -4519,7 +4521,7 @@ var be, L, x, ct, ne, lt = -1, O = function(n) {
4519
4521
  }, o = function(l) {
4520
4522
  l.forEach(i);
4521
4523
  }, c = F("first-input", o);
4522
- t = v(n, r, Oe, e.reportAllChanges), c && ($(oe((function() {
4524
+ t = v(n, r, Oe, e.reportAllChanges), c && (B(oe((function() {
4523
4525
  o(c.takeRecords()), c.disconnect();
4524
4526
  }))), O((function() {
4525
4527
  var l;
@@ -4564,12 +4566,12 @@ export {
4564
4566
  us as PII_PATTERNS,
4565
4567
  C as PermanentError,
4566
4568
  J as RateLimitError,
4567
- $e as SamplingRateValidationError,
4569
+ Be as SamplingRateValidationError,
4568
4570
  Ee as ScrollDirection,
4569
4571
  bt as SessionTimeoutValidationError,
4570
4572
  M as SpecialApiUrl,
4571
4573
  Z as TimeoutError,
4572
- B as TraceLogValidationError,
4574
+ $ as TraceLogValidationError,
4573
4575
  bn as WEB_VITALS_GOOD_THRESHOLDS,
4574
4576
  ze as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
4575
4577
  Yt as WEB_VITALS_POOR_THRESHOLDS,