@tracelog/lib 2.8.0-rc.100.13 → 2.8.1-rc.101.2

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.
@@ -1,6 +1,6 @@
1
1
  const dr = 9e5;
2
2
  const ur = 120, hr = 49152, fr = 100, mr = 500, gr = 200;
3
- const Er = 1e3, Sr = 500, pr = 1e3;
3
+ const Er = 1e3, pr = 500, Sr = 1e3;
4
4
  const b = "data-tlog", At = [
5
5
  "button",
6
6
  "a",
@@ -301,7 +301,7 @@ const xt = () => {
301
301
  default:
302
302
  return Ke;
303
303
  }
304
- }, Yt = 1e3, qt = 50, Jt = "2.8.0", Zt = Jt, dt = () => typeof window < "u" && typeof sessionStorage < "u", es = () => {
304
+ }, Yt = 1e3, qt = 50, Jt = "2.8.1", Zt = Jt, dt = () => typeof window < "u" && typeof sessionStorage < "u", es = () => {
305
305
  try {
306
306
  const r = new URLSearchParams(window.location.search);
307
307
  r.delete(nt);
@@ -1108,6 +1108,20 @@ class et extends _ {
1108
1108
  }
1109
1109
  ), !0) : this.sendQueueSyncInternal(e);
1110
1110
  }
1111
+ /**
1112
+ * Persists events to localStorage for recovery without sending.
1113
+ *
1114
+ * Used when an async send is already in-flight to avoid generating
1115
+ * a second idempotency token for the same events via sendBeacon.
1116
+ * On next page load, `recoverPersistedEvents()` sends with the persisted token.
1117
+ *
1118
+ * @param body - Event queue to persist
1119
+ */
1120
+ persistForRecovery(e) {
1121
+ if (this.shouldSkipSend()) return;
1122
+ const t = this.ensureBatchMetadata(e);
1123
+ this.persistEventsWithFailureCount(t, 0, !0);
1124
+ }
1111
1125
  /**
1112
1126
  * Sends events asynchronously using `fetch()` API with automatic persistence on failure.
1113
1127
  *
@@ -1741,7 +1755,7 @@ class et extends _ {
1741
1755
  }), this.lastPermanentErrorLog = { statusCode: t.statusCode, timestamp: s });
1742
1756
  }
1743
1757
  }
1744
- class Ss extends _ {
1758
+ class ps extends _ {
1745
1759
  bootTime;
1746
1760
  bootTimestamp;
1747
1761
  hasPerformanceNow;
@@ -1890,7 +1904,7 @@ class Ss extends _ {
1890
1904
  };
1891
1905
  }
1892
1906
  }
1893
- const ps = new Set(Object.values(u));
1907
+ const Ss = new Set(Object.values(u));
1894
1908
  class Ts extends _ {
1895
1909
  dataSenders;
1896
1910
  emitter;
@@ -1930,7 +1944,7 @@ class Ts extends _ {
1930
1944
  * @param fetchCredentials - Fetch credentials mode for custom backend. @default 'include'
1931
1945
  */
1932
1946
  constructor(e, t = null, s = {}, n = {}, i, o = "include") {
1933
- super(), this.emitter = t, this.transformers = s, this.timeManager = new Ss(), this.dataSenders = [];
1947
+ super(), this.emitter = t, this.transformers = s, this.timeManager = new ps(), this.dataSenders = [];
1934
1948
  const l = this.get("collectApiUrls");
1935
1949
  l?.saas && this.dataSenders.push(new et(e, "saas", l.saas, s)), l?.custom && this.dataSenders.push(
1936
1950
  new et(
@@ -2061,7 +2075,7 @@ class Ts extends _ {
2061
2075
  a("error", "Event type is required - event will be ignored");
2062
2076
  return;
2063
2077
  }
2064
- if (!ps.has(e)) {
2078
+ if (!Ss.has(e)) {
2065
2079
  a("error", "Invalid event type - event will be ignored", {
2066
2080
  data: { type: e }
2067
2081
  });
@@ -2091,25 +2105,25 @@ class Ts extends _ {
2091
2105
  data: { sessionId: g }
2092
2106
  }), !T && !this.checkRateLimit())
2093
2107
  return;
2094
- const S = e;
2108
+ const p = e;
2095
2109
  if (!T) {
2096
2110
  if (this.sessionEventCounts.total >= 1e3) {
2097
2111
  a("warn", "Session event limit reached", {
2098
2112
  data: {
2099
- type: S,
2113
+ type: p,
2100
2114
  total: this.sessionEventCounts.total,
2101
2115
  limit: 1e3
2102
2116
  }
2103
2117
  });
2104
2118
  return;
2105
2119
  }
2106
- const v = this.getTypeLimitForEvent(S);
2120
+ const v = this.getTypeLimitForEvent(p);
2107
2121
  if (v) {
2108
- const he = this.sessionEventCounts[S];
2122
+ const he = this.sessionEventCounts[p];
2109
2123
  if (he !== void 0 && he >= v) {
2110
2124
  a("warn", "Session event type limit reached", {
2111
2125
  data: {
2112
- type: S,
2126
+ type: p,
2113
2127
  count: he,
2114
2128
  limit: v
2115
2129
  }
@@ -2118,13 +2132,13 @@ class Ts extends _ {
2118
2132
  }
2119
2133
  }
2120
2134
  }
2121
- if (S === u.CUSTOM && o?.name) {
2135
+ if (p === u.CUSTOM && o?.name) {
2122
2136
  const v = this.get("config")?.maxSameEventPerMinute ?? 60;
2123
2137
  if (!this.checkPerEventRateLimit(o.name, v))
2124
2138
  return;
2125
2139
  }
2126
- const Ue = S === u.SESSION_START, K = t || this.get("pageUrl"), x = this.buildEventPayload({
2127
- type: S,
2140
+ const Ue = p === u.SESSION_START, K = t || this.get("pageUrl"), x = this.buildEventPayload({
2141
+ type: p,
2128
2142
  page_url: K,
2129
2143
  from_page_url: s,
2130
2144
  scroll_data: n,
@@ -2152,7 +2166,7 @@ class Ts extends _ {
2152
2166
  }
2153
2167
  if (!this.isDuplicateEvent(x)) {
2154
2168
  if (this.get("mode") === ie.QA) {
2155
- if (S === u.CUSTOM && o) {
2169
+ if (p === u.CUSTOM && o) {
2156
2170
  a("info", `Custom Event: ${o.name}`, {
2157
2171
  visibility: "qa",
2158
2172
  data: {
@@ -2162,7 +2176,7 @@ class Ts extends _ {
2162
2176
  }), this.emitEvent(x);
2163
2177
  return;
2164
2178
  }
2165
- if (S === u.VIEWPORT_VISIBLE && d) {
2179
+ if (p === u.VIEWPORT_VISIBLE && d) {
2166
2180
  const v = d.name || d.id || d.selector;
2167
2181
  a("info", `Viewport Visible: ${v}`, {
2168
2182
  visibility: "qa",
@@ -2178,7 +2192,7 @@ class Ts extends _ {
2178
2192
  }
2179
2193
  }
2180
2194
  if (this.addToQueue(x), !T) {
2181
- this.sessionEventCounts.total++, this.sessionEventCounts[S] !== void 0 && this.sessionEventCounts[S]++;
2195
+ this.sessionEventCounts.total++, this.sessionEventCounts[p] !== void 0 && this.sessionEventCounts[p]++;
2182
2196
  const v = this.get("sessionId");
2183
2197
  v && this.saveSessionCountsDebounced && this.saveSessionCountsDebounced(v);
2184
2198
  }
@@ -2447,6 +2461,13 @@ class Ts extends _ {
2447
2461
  const t = this.buildEventsPayload(), s = [...this.eventsQueue], n = s.map((i) => i.id);
2448
2462
  if (this.dataSenders.length === 0)
2449
2463
  return this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t), e ? !0 : Promise.resolve(!0);
2464
+ if (e && this.sendInProgress) {
2465
+ for (const i of this.dataSenders)
2466
+ i.persistForRecovery(t);
2467
+ return a("debug", "Sync flush deferred: async send in progress, events persisted for recovery", {
2468
+ data: { eventCount: n.length }
2469
+ }), !0;
2470
+ }
2450
2471
  if (e) {
2451
2472
  const o = this.dataSenders.map((l) => l.sendEventsQueueSync(t)).some((l) => l);
2452
2473
  return o ? (this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t)) : (this.clearSendTimeout(), a("debug", "Sync flush complete failure, events kept in queue for retry", {
@@ -2546,9 +2567,9 @@ class Ts extends _ {
2546
2567
  ...e.page_view && { page_view: e.page_view },
2547
2568
  ...o && { utm: o }
2548
2569
  };
2549
- const c = this.get("collectApiUrls"), d = !!c?.custom, f = !!c?.saas, g = d || f, T = d && f, S = this.transformers.beforeSend;
2550
- if (S && (!g || d && !T)) {
2551
- const K = gt(l, S, "EventManager");
2570
+ const c = this.get("collectApiUrls"), d = !!c?.custom, f = !!c?.saas, g = d || f, T = d && f, p = this.transformers.beforeSend;
2571
+ if (p && (!g || d && !T)) {
2572
+ const K = gt(l, p, "EventManager");
2552
2573
  if (K === null)
2553
2574
  return null;
2554
2575
  l = K;
@@ -3816,11 +3837,11 @@ class As extends _ {
3816
3837
  const c = this.getViewportHeight(t), d = this.getScrollHeight(t), f = this.getScrollDirection(i, s), g = this.calculateScrollDepth(i, d, c);
3817
3838
  let T;
3818
3839
  n > 0 ? T = o - n : e.firstScrollEventTime !== null ? T = o - e.firstScrollEventTime : T = 250;
3819
- const S = Math.round(l / T * 1e3);
3840
+ const p = Math.round(l / T * 1e3);
3820
3841
  return g > e.maxDepthReached && (e.maxDepthReached = g), e.lastScrollPos = i, {
3821
3842
  depth: g,
3822
3843
  direction: f,
3823
- velocity: S,
3844
+ velocity: p,
3824
3845
  max_depth_reached: e.maxDepthReached
3825
3846
  };
3826
3847
  }
@@ -5088,8 +5109,8 @@ class Os extends _ {
5088
5109
  }
5089
5110
  }
5090
5111
  const k = [], M = [];
5091
- let D = null, h = null, R = !1, p = !1, P = null;
5092
- const Ps = async (r) => typeof window > "u" || typeof document > "u" ? { sessionId: "" } : (p = !1, window.__traceLogDisabled === !0 ? { sessionId: "" } : h ? { sessionId: h.getSessionId() ?? "" } : (R && P || (R = !0, P = (async () => {
5112
+ let D = null, h = null, R = !1, S = !1, P = null;
5113
+ const Ps = async (r) => typeof window > "u" || typeof document > "u" ? { sessionId: "" } : (S = !1, window.__traceLogDisabled === !0 ? { sessionId: "" } : h ? { sessionId: h.getSessionId() ?? "" } : (R && P || (R = !0, P = (async () => {
5093
5114
  try {
5094
5115
  const e = us(r ?? {}), t = new Os();
5095
5116
  try {
@@ -5121,7 +5142,7 @@ const Ps = async (r) => typeof window > "u" || typeof document > "u" ? { session
5121
5142
  if (!(typeof window > "u" || typeof document > "u")) {
5122
5143
  if (!h)
5123
5144
  throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
5124
- if (p)
5145
+ if (S)
5125
5146
  throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
5126
5147
  h.sendCustomEvent(r, e);
5127
5148
  }
@@ -5152,7 +5173,7 @@ function Us(r, e) {
5152
5173
  t !== -1 && M.splice(t, 1), M.push({ hook: r, fn: e });
5153
5174
  return;
5154
5175
  }
5155
- if (p)
5176
+ if (S)
5156
5177
  throw new Error("[TraceLog] Cannot set transformers while TraceLog is being destroyed");
5157
5178
  r === "beforeSend" ? h.setTransformer("beforeSend", e) : h.setTransformer("beforeBatch", e);
5158
5179
  }
@@ -5164,7 +5185,7 @@ const Hs = (r) => {
5164
5185
  e !== -1 && M.splice(e, 1);
5165
5186
  return;
5166
5187
  }
5167
- if (p)
5188
+ if (S)
5168
5189
  throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
5169
5190
  h.removeTransformer(r);
5170
5191
  }
@@ -5176,7 +5197,7 @@ const Hs = (r) => {
5176
5197
  D = r;
5177
5198
  return;
5178
5199
  }
5179
- if (p)
5200
+ if (S)
5180
5201
  throw new Error("[TraceLog] Cannot set custom headers while TraceLog is being destroyed");
5181
5202
  h.setCustomHeaders(r);
5182
5203
  }
@@ -5186,23 +5207,23 @@ const Hs = (r) => {
5186
5207
  D = null;
5187
5208
  return;
5188
5209
  }
5189
- if (p)
5210
+ if (S)
5190
5211
  throw new Error("[TraceLog] Cannot remove custom headers while TraceLog is being destroyed");
5191
5212
  h.removeCustomHeaders();
5192
5213
  }
5193
5214
  }, $s = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, Bs = () => typeof window > "u" || typeof document > "u" || !h ? null : h.getSessionId(), Ws = () => {
5194
5215
  if (!(typeof window > "u" || typeof document > "u")) {
5195
- if (p)
5216
+ if (S)
5196
5217
  throw new Error("[TraceLog] Destroy operation already in progress");
5197
5218
  if (!h) {
5198
- p = !1;
5219
+ S = !1;
5199
5220
  return;
5200
5221
  }
5201
- p = !0;
5222
+ S = !0;
5202
5223
  try {
5203
- h.destroy(), h = null, R = !1, P = null, k.length = 0, M.length = 0, D = null, p = !1;
5224
+ h.destroy(), h = null, R = !1, P = null, k.length = 0, M.length = 0, D = null, S = !1;
5204
5225
  } catch (r) {
5205
- h = null, R = !1, P = null, k.length = 0, M.length = 0, D = null, p = !1, a("warn", "Error during destroy, forced cleanup completed", { error: r });
5226
+ h = null, R = !1, P = null, k.length = 0, M.length = 0, D = null, S = !1, a("warn", "Error during destroy, forced cleanup completed", { error: r });
5206
5227
  }
5207
5228
  }
5208
5229
  }, Xs = (r) => {
@@ -5211,7 +5232,7 @@ const Hs = (r) => {
5211
5232
  if (!(typeof window > "u" || typeof document > "u")) {
5212
5233
  if (!h)
5213
5234
  throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
5214
- if (p)
5235
+ if (S)
5215
5236
  throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
5216
5237
  h.updateGlobalMetadata(r);
5217
5238
  }
@@ -5219,7 +5240,7 @@ const Hs = (r) => {
5219
5240
  if (!(typeof window > "u" || typeof document > "u")) {
5220
5241
  if (!h)
5221
5242
  throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
5222
- if (p)
5243
+ if (S)
5223
5244
  throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
5224
5245
  h.mergeGlobalMetadata(r);
5225
5246
  }
@@ -5233,7 +5254,7 @@ const Hs = (r) => {
5233
5254
  a("warn", "identify() userId exceeds 256 characters");
5234
5255
  return;
5235
5256
  }
5236
- if (p) {
5257
+ if (S) {
5237
5258
  a("warn", "Cannot identify while TraceLog is being destroyed");
5238
5259
  return;
5239
5260
  }
@@ -5260,7 +5281,7 @@ const Hs = (r) => {
5260
5281
  }
5261
5282
  return;
5262
5283
  }
5263
- if (p)
5284
+ if (S)
5264
5285
  throw new Error("[TraceLog] Cannot reset identity while TraceLog is being destroyed");
5265
5286
  await h.resetIdentity();
5266
5287
  }
@@ -5282,9 +5303,9 @@ const Hs = (r) => {
5282
5303
  identify: zs,
5283
5304
  resetIdentity: Qs
5284
5305
  };
5285
- var Le, C, G, St, le, pt = -1, V = function(r) {
5306
+ var Le, C, G, pt, le, St = -1, V = function(r) {
5286
5307
  addEventListener("pageshow", (function(e) {
5287
- e.persisted && (pt = e.timeStamp, r(e));
5308
+ e.persisted && (St = e.timeStamp, r(e));
5288
5309
  }), !0);
5289
5310
  }, De = function() {
5290
5311
  var r = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
@@ -5294,7 +5315,7 @@ var Le, C, G, St, le, pt = -1, V = function(r) {
5294
5315
  return r && r.activationStart || 0;
5295
5316
  }, y = function(r, e) {
5296
5317
  var t = De(), s = "navigate";
5297
- return pt >= 0 ? s = "back-forward-cache" : t && (document.prerendering || de() > 0 ? s = "prerender" : document.wasDiscarded ? s = "restore" : t.type && (s = t.type.replace(/_/g, "-"))), { name: r, value: e === void 0 ? -1 : e, rating: "good", delta: 0, entries: [], id: "v4-".concat(Date.now(), "-").concat(Math.floor(8999999999999 * Math.random()) + 1e12), navigationType: s };
5318
+ return St >= 0 ? s = "back-forward-cache" : t && (document.prerendering || de() > 0 ? s = "prerender" : document.wasDiscarded ? s = "restore" : t.type && (s = t.type.replace(/_/g, "-"))), { name: r, value: e === void 0 ? -1 : e, rating: "good", delta: 0, entries: [], id: "v4-".concat(Date.now(), "-").concat(Math.floor(8999999999999 * Math.random()) + 1e12), navigationType: s };
5298
5319
  }, F = function(r, e, t) {
5299
5320
  try {
5300
5321
  if (PerformanceObserver.supportedEntryTypes.includes(r)) {
@@ -5380,9 +5401,9 @@ var Le, C, G, St, le, pt = -1, V = function(r) {
5380
5401
  }));
5381
5402
  })), setTimeout(t, 0));
5382
5403
  })));
5383
- }, It = 0, Se = 1 / 0, J = 0, qs = function(r) {
5404
+ }, It = 0, pe = 1 / 0, J = 0, qs = function(r) {
5384
5405
  r.forEach((function(e) {
5385
- e.interactionId && (Se = Math.min(Se, e.interactionId), J = Math.max(J, e.interactionId), It = J ? (J - Se) / 7 + 1 : 0);
5406
+ e.interactionId && (pe = Math.min(pe, e.interactionId), J = Math.max(J, e.interactionId), It = J ? (J - pe) / 7 + 1 : 0);
5386
5407
  }));
5387
5408
  }, vt = function() {
5388
5409
  return Le ? It : performance.interactionCount || 0;
@@ -5429,7 +5450,7 @@ var Le, C, G, St, le, pt = -1, V = function(r) {
5429
5450
  _t = vt(), A.length = 0, te.clear(), n = y("INP"), s = w(r, n, Re, e.reportAllChanges);
5430
5451
  })));
5431
5452
  })));
5432
- }, Ne = [2500, 4e3], pe = {}, rr = function(r, e) {
5453
+ }, Ne = [2500, 4e3], Se = {}, rr = function(r, e) {
5433
5454
  e = e || {}, Q((function() {
5434
5455
  var t, s = Ve(), n = y("LCP"), i = function(c) {
5435
5456
  e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(d) {
@@ -5439,7 +5460,7 @@ var Le, C, G, St, le, pt = -1, V = function(r) {
5439
5460
  if (o) {
5440
5461
  t = w(r, n, Ne, e.reportAllChanges);
5441
5462
  var l = ue((function() {
5442
- pe[n.id] || (i(o.takeRecords()), o.disconnect(), pe[n.id] = !0, t(!0));
5463
+ Se[n.id] || (i(o.takeRecords()), o.disconnect(), Se[n.id] = !0, t(!0));
5443
5464
  }));
5444
5465
  ["keydown", "click"].forEach((function(c) {
5445
5466
  addEventListener(c, (function() {
@@ -5447,7 +5468,7 @@ var Le, C, G, St, le, pt = -1, V = function(r) {
5447
5468
  }), { once: !0, capture: !0 });
5448
5469
  })), z(l), V((function(c) {
5449
5470
  n = y("LCP"), t = w(r, n, Ne, e.reportAllChanges), ke((function() {
5450
- n.value = performance.now() - c.timeStamp, pe[n.id] = !0, t(!0);
5471
+ n.value = performance.now() - c.timeStamp, Se[n.id] = !0, t(!0);
5451
5472
  }));
5452
5473
  }));
5453
5474
  }
@@ -5468,9 +5489,9 @@ var Le, C, G, St, le, pt = -1, V = function(r) {
5468
5489
  })));
5469
5490
  }));
5470
5491
  }, W = { passive: !0, capture: !0 }, or = /* @__PURE__ */ new Date(), rt = function(r, e) {
5471
- C || (C = e, G = r, St = /* @__PURE__ */ new Date(), bt(removeEventListener), wt());
5492
+ C || (C = e, G = r, pt = /* @__PURE__ */ new Date(), bt(removeEventListener), wt());
5472
5493
  }, wt = function() {
5473
- if (G >= 0 && G < St - or) {
5494
+ if (G >= 0 && G < pt - or) {
5474
5495
  var r = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp + G };
5475
5496
  le.forEach((function(e) {
5476
5497
  e(r);
@@ -5534,14 +5555,14 @@ export {
5534
5555
  u as EventType,
5535
5556
  vr as InitializationTimeoutError,
5536
5557
  N as IntegrationValidationError,
5537
- pr as MAX_ARRAY_LENGTH,
5558
+ Sr as MAX_ARRAY_LENGTH,
5538
5559
  mr as MAX_CUSTOM_EVENT_ARRAY_SIZE,
5539
5560
  fr as MAX_CUSTOM_EVENT_KEYS,
5540
5561
  ur as MAX_CUSTOM_EVENT_NAME_LENGTH,
5541
5562
  hr as MAX_CUSTOM_EVENT_STRING_SIZE,
5542
5563
  gr as MAX_NESTED_OBJECT_KEYS,
5543
5564
  Er as MAX_STRING_LENGTH,
5544
- Sr as MAX_STRING_LENGTH_IN_ARRAY,
5565
+ pr as MAX_STRING_LENGTH_IN_ARRAY,
5545
5566
  ie as Mode,
5546
5567
  lt as PII_PATTERNS,
5547
5568
  O as PermanentError,