@tracelog/lib 0.0.2 → 0.0.4

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.
@@ -158,11 +158,11 @@ const ke = () => {
158
158
  error: n instanceof Error ? n.message : n
159
159
  }), E.Desktop;
160
160
  }
161
- }, Ne = 2, Ue = 10, Ie = 1, ne = 500, Z = 3e4, ee = 864e5, re = 120, ae = 8 * 1024, oe = 10, ce = 10, _ = 255, M = 1e3, W = 100, le = 3, N = 2, Pe = 4, He = 0.75, De = 0.2, xe = 2e3, Oe = 1e3, Fe = 10, F = 10, R = 15 * 60 * 1e3, ze = 3e4, Te = 1e3, Me = 250, Ve = 2e3, de = 1e3, $e = 1e4, je = 2500, he = 1e3, ue = 3e4, ge = 1e3, Ge = 24, Qe = 24 * 60 * 60 * 1e3, Be = Te, qe = 5e3, We = 2e3, Xe = 2, Ke = 3, X = 24 * 60 * 60 * 1e3, K = 2 * 60 * 1e3, Ye = "https://api.tracelog.io", Ae = {
161
+ }, Ne = 2, Ue = 10, Ie = 1, ne = 500, Z = 3e4, ee = 864e5, re = 120, ae = 8 * 1024, oe = 10, ce = 10, _ = 255, M = 1e3, W = 100, le = 3, N = 2, Pe = 4, He = 0.75, De = 0.2, xe = 2e3, Oe = 1e3, Fe = 10, F = 10, R = 15 * 60 * 1e3, ze = 3e4, Te = 1e3, Me = 250, Ve = 2e3, de = 1e3, $e = 1e4, je = 2500, he = 1e3, ue = 3e4, ge = 1e3, Ge = 24, Qe = 24 * 60 * 60 * 1e3, Be = Te, qe = 5e3, We = 2e3, Xe = 2, Ke = 3, X = 24 * 60 * 60 * 1e3, K = 2 * 60 * 1e3, Ae = {
162
162
  samplingRate: Ie,
163
163
  tags: [],
164
164
  excludedUrlPaths: []
165
- }, Je = (n) => ({
165
+ }, Ye = (n) => ({
166
166
  ...Ae,
167
167
  ...n,
168
168
  sessionTimeout: R,
@@ -199,7 +199,7 @@ const ke = () => {
199
199
  ".menu-item",
200
200
  "[data-testid]",
201
201
  '[tabindex="0"]'
202
- ], Ze = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"], me = {
202
+ ], Je = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"], me = {
203
203
  /** Maximum number of retries when waiting for concurrent initialization */
204
204
  MAX_CONCURRENT_RETRIES: 20,
205
205
  /** Delay between retries when waiting for concurrent initialization (ms) */
@@ -223,7 +223,7 @@ const ke = () => {
223
223
  SYNC_TIMEOUT_MS: 2e3,
224
224
  /** Maximum retry attempts for session operations */
225
225
  MAX_RETRY_ATTEMPTS: 3
226
- }, et = {
226
+ }, Ze = {
227
227
  /** Multiplier for scroll debounce time when suppressing scroll events */
228
228
  SUPPRESS_MULTIPLIER: 2
229
229
  }, _e = [
@@ -233,7 +233,7 @@ const ke = () => {
233
233
  /<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
234
234
  /<embed\b[^>]*>/gi,
235
235
  /<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi
236
- ], S = "tl", ve = (n) => n ? `${S}:${n}:uid` : `${S}:uid`, tt = (n) => n ? `${S}:${n}:queue` : `${S}:queue`, st = (n) => n ? `${S}:${n}:session` : `${S}:session`, Y = (n) => n ? `${S}:${n}:cross_tab_session` : `${S}:cross_tab_session`, Se = (n, e) => `${S}:${n}:tab:${e}:info`, V = (n) => n ? `${S}:${n}:recovery` : `${S}:recovery`, it = (n) => n ? `${S}:${n}:broadcast` : `${S}:broadcast`, nt = /* @__PURE__ */ new Set([
236
+ ], S = "tl", ve = (n) => n ? `${S}:${n}:uid` : `${S}:uid`, et = (n) => n ? `${S}:${n}:queue` : `${S}:queue`, tt = (n) => n ? `${S}:${n}:session` : `${S}:session`, Y = (n) => n ? `${S}:${n}:cross_tab_session` : `${S}:cross_tab_session`, Se = (n, e) => `${S}:${n}:tab:${e}:info`, V = (n) => n ? `${S}:${n}:recovery` : `${S}:recovery`, st = (n) => n ? `${S}:${n}:broadcast` : `${S}:broadcast`, it = /* @__PURE__ */ new Set([
237
237
  "mode",
238
238
  "tags",
239
239
  "samplingRate",
@@ -254,13 +254,13 @@ const ke = () => {
254
254
  INVALID_GLOBAL_METADATA: "Global metadata must be an object",
255
255
  // Array validation
256
256
  INVALID_SENSITIVE_QUERY_PARAMS: "Sensitive query params must be an array of strings"
257
- }, rt = () => {
257
+ }, nt = () => {
258
258
  i.debug("UTMParams", "Extracting UTM parameters from URL", {
259
259
  url: window.location.href,
260
260
  search: window.location.search
261
261
  });
262
262
  const n = new URLSearchParams(window.location.search), e = {};
263
- Ze.forEach((s) => {
263
+ Je.forEach((s) => {
264
264
  const r = n.get(s);
265
265
  if (r) {
266
266
  const a = s.split("utm_")[1];
@@ -295,12 +295,12 @@ class H extends x {
295
295
  super(e, "APP_CONFIG_INVALID", t);
296
296
  }
297
297
  }
298
- class at extends x {
298
+ class rt extends x {
299
299
  constructor(e, t = "config") {
300
300
  super(e, "SESSION_TIMEOUT_INVALID", t);
301
301
  }
302
302
  }
303
- class ot extends x {
303
+ class at extends x {
304
304
  constructor(e, t = "config") {
305
305
  super(e, "SAMPLING_RATE_INVALID", t);
306
306
  }
@@ -310,7 +310,7 @@ class ye extends x {
310
310
  super(e, "INTEGRATION_INVALID", t);
311
311
  }
312
312
  }
313
- const ct = (n) => {
313
+ const ot = (n) => {
314
314
  if (!n || typeof n != "object")
315
315
  throw i.clientError("ConfigValidation", "Configuration must be an object", { config: n }), new H("Configuration must be an object", "config");
316
316
  if (!("id" in n))
@@ -325,13 +325,13 @@ const ct = (n) => {
325
325
  provided: n.sessionTimeout,
326
326
  min: Z,
327
327
  max: ee
328
- }), new at(w.INVALID_SESSION_TIMEOUT, "config");
328
+ }), new rt(w.INVALID_SESSION_TIMEOUT, "config");
329
329
  if (n.globalMetadata !== void 0 && (typeof n.globalMetadata != "object" || n.globalMetadata === null))
330
330
  throw i.clientError("ConfigValidation", "Global metadata must be an object", {
331
331
  provided: n.globalMetadata,
332
332
  type: typeof n.globalMetadata
333
333
  }), new H(w.INVALID_GLOBAL_METADATA, "config");
334
- if (n.scrollContainerSelectors !== void 0 && lt(n.scrollContainerSelectors), n.integrations && dt(n.integrations), n.sensitiveQueryParams !== void 0) {
334
+ if (n.scrollContainerSelectors !== void 0 && ct(n.scrollContainerSelectors), n.integrations && lt(n.integrations), n.sensitiveQueryParams !== void 0) {
335
335
  if (!Array.isArray(n.sensitiveQueryParams))
336
336
  throw i.clientError("ConfigValidation", "Sensitive query params must be an array", {
337
337
  provided: n.sensitiveQueryParams,
@@ -348,8 +348,8 @@ const ct = (n) => {
348
348
  throw i.clientError("ConfigValidation", "Invalid error sampling rate", {
349
349
  provided: n.errorSampling,
350
350
  expected: "0-1"
351
- }), new ot(w.INVALID_ERROR_SAMPLING_RATE, "config");
352
- }, lt = (n) => {
351
+ }), new at(w.INVALID_ERROR_SAMPLING_RATE, "config");
352
+ }, ct = (n) => {
353
353
  const e = Array.isArray(n) ? n : [n];
354
354
  for (const t of e) {
355
355
  if (typeof t != "string" || t.trim() === "")
@@ -365,7 +365,7 @@ const ct = (n) => {
365
365
  i.clientWarn("ConfigValidation", `Invalid CSS selector will be ignored: "${t}"`);
366
366
  }
367
367
  }
368
- }, dt = (n) => {
368
+ }, lt = (n) => {
369
369
  if (n && n.googleAnalytics) {
370
370
  if (!n.googleAnalytics.measurementId || typeof n.googleAnalytics.measurementId != "string" || n.googleAnalytics.measurementId.trim() === "")
371
371
  throw i.clientError("ConfigValidation", "Invalid Google Analytics measurement ID", {
@@ -378,8 +378,8 @@ const ct = (n) => {
378
378
  provided: e
379
379
  }), new ye('Google Analytics measurement ID must start with "G-" or "UA-"', "config");
380
380
  }
381
- }, ht = (n) => {
382
- ct(n);
381
+ }, dt = (n) => {
382
+ ot(n);
383
383
  const e = {
384
384
  ...n,
385
385
  id: n.id.trim(),
@@ -419,7 +419,7 @@ const ct = (n) => {
419
419
  xssPatternMatches: s,
420
420
  wasTruncated: e > M
421
421
  }), r;
422
- }, ut = (n) => {
422
+ }, ht = (n) => {
423
423
  if (typeof n != "string")
424
424
  return "";
425
425
  n.length > M && (n = n.slice(0, Math.max(0, M)));
@@ -474,7 +474,7 @@ const ct = (n) => {
474
474
  }), t;
475
475
  }
476
476
  return i.debug("Sanitize", "Unknown value type sanitized to null", { type: typeof n, depth: e }), null;
477
- }, gt = (n) => {
477
+ }, ut = (n) => {
478
478
  i.debug("Sanitize", "Starting API config sanitization");
479
479
  const e = {};
480
480
  if (typeof n != "object" || n === null)
@@ -483,11 +483,11 @@ const ct = (n) => {
483
483
  const t = Object.keys(n);
484
484
  let s = 0, r = 0;
485
485
  for (const a of t)
486
- if (nt.has(a)) {
486
+ if (it.has(a)) {
487
487
  const o = n[a];
488
488
  if (a === "excludedUrlPaths") {
489
489
  const l = Array.isArray(o) ? o : typeof o == "string" ? [o] : [], c = l.length;
490
- e.excludedUrlPaths = l.map((u) => ut(String(u))).filter(Boolean);
490
+ e.excludedUrlPaths = l.map((u) => ht(String(u))).filter(Boolean);
491
491
  const d = c - e.excludedUrlPaths.length;
492
492
  d > 0 && i.warn("Sanitize", "Some excluded URL paths were filtered during sanitization", {
493
493
  originalCount: c,
@@ -514,7 +514,7 @@ const ct = (n) => {
514
514
  }), new Error(`API config sanitization failed: ${t instanceof Error ? t.message : "Unknown error"}`);
515
515
  }
516
516
  return e;
517
- }, ft = (n) => {
517
+ }, gt = (n) => {
518
518
  if (i.debug("Sanitize", "Starting metadata sanitization", { hasMetadata: n != null }), typeof n != "object" || n === null)
519
519
  return i.debug("Sanitize", "Metadata is not an object, returning empty object", {
520
520
  metadata: n,
@@ -532,7 +532,7 @@ const ct = (n) => {
532
532
  error: e instanceof Error ? e.message : e
533
533
  }), new Error(`Metadata sanitization failed: ${e instanceof Error ? e.message : "Unknown error"}`);
534
534
  }
535
- }, mt = (n) => {
535
+ }, ft = (n) => {
536
536
  if (typeof n != "object" || n === null)
537
537
  return !1;
538
538
  for (const e of Object.values(n)) {
@@ -549,7 +549,7 @@ const ct = (n) => {
549
549
  }
550
550
  }
551
551
  return !0;
552
- }, pt = (n) => typeof n != "string" ? {
552
+ }, mt = (n) => typeof n != "string" ? {
553
553
  valid: !1,
554
554
  error: "Event name must be a string"
555
555
  } : n.length === 0 ? {
@@ -564,9 +564,9 @@ const ct = (n) => {
564
564
  } : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(n.toLowerCase()) ? {
565
565
  valid: !1,
566
566
  error: "Event name cannot be a reserved word"
567
- } : { valid: !0 }, vt = (n, e, t) => {
568
- const s = ft(e), r = `${t} "${n}" metadata error`;
569
- if (!mt(s))
567
+ } : { valid: !0 }, pt = (n, e, t) => {
568
+ const s = gt(e), r = `${t} "${n}" metadata error`;
569
+ if (!ft(s))
570
570
  return {
571
571
  valid: !1,
572
572
  error: `${r}: object has invalid types. Valid types are string, number, boolean or string arrays.`
@@ -614,13 +614,13 @@ const ct = (n) => {
614
614
  valid: !0,
615
615
  sanitizedMetadata: s
616
616
  };
617
- }, St = (n, e) => {
618
- const t = pt(n);
617
+ }, vt = (n, e) => {
618
+ const t = mt(n);
619
619
  if (!t.valid)
620
620
  return i.clientError("EventValidation", "Event name validation failed", { eventName: n, error: t.error }), t;
621
621
  if (!e)
622
622
  return { valid: !0 };
623
- const s = vt(n, e, "customEvent");
623
+ const s = pt(n, e, "customEvent");
624
624
  return s.valid || i.clientError("EventValidation", "Event metadata validation failed", {
625
625
  eventName: n,
626
626
  error: s.error
@@ -632,7 +632,7 @@ const ct = (n) => {
632
632
  } catch {
633
633
  return !1;
634
634
  }
635
- }, yt = (n, e = !1) => {
635
+ }, St = (n, e = !1) => {
636
636
  i.debug("URLUtils", "Generating API URL", { projectId: n, allowHttp: e });
637
637
  const t = new URL(window.location.href), s = t.hostname, r = s.split(".");
638
638
  if (r.length === 0)
@@ -681,7 +681,7 @@ const ct = (n) => {
681
681
  error: t instanceof Error ? t.message : t
682
682
  }), n;
683
683
  }
684
- }, bt = (n, e = []) => {
684
+ }, yt = (n, e = []) => {
685
685
  if (i.debug("URLUtils", "Checking if URL path is excluded", {
686
686
  urlLength: n.length,
687
687
  excludedPathsCount: e.length
@@ -725,15 +725,15 @@ const ct = (n) => {
725
725
  totalPatternsChecked: e.length
726
726
  }), l;
727
727
  };
728
- class Et {
728
+ class bt {
729
729
  getUrl(e, t = !1) {
730
- const s = yt(e, t);
730
+ const s = St(e, t);
731
731
  if (!te(s, t))
732
732
  throw new Error("Invalid URL");
733
733
  return s;
734
734
  }
735
735
  }
736
- class wt {
736
+ class Et {
737
737
  async get(e, t) {
738
738
  if (t.id === C.HttpSkip)
739
739
  return i.debug("ConfigManager", "Using special project id"), this.getDefaultConfig(t);
@@ -769,7 +769,7 @@ class wt {
769
769
  responseType: typeof o,
770
770
  isArray: Array.isArray(o)
771
771
  }), new Error("Invalid config API response: expected object");
772
- const l = gt(o), d = { ...{ ...Ae, ...l }, ...t };
772
+ const l = ut(o), d = { ...{ ...Ae, ...l }, ...t };
773
773
  new URLSearchParams(window.location.search).get("qaMode") === "true" && !d.mode && (d.mode = L.QA, i.info("ConfigManager", "QA mode enabled via URL parameter"));
774
774
  const y = Object.values(L).includes(d.mode) ? 1 : d.errorSampling ?? 0.1;
775
775
  return { ...d, errorSampling: y };
@@ -786,14 +786,14 @@ class wt {
786
786
  return r;
787
787
  }
788
788
  getDefaultConfig(e) {
789
- return Je({
789
+ return Ye({
790
790
  ...e,
791
791
  errorSampling: 1,
792
792
  ...Object.values(C).includes(e.id) && { mode: L.DEBUG }
793
793
  });
794
794
  }
795
795
  }
796
- class It extends p {
796
+ class wt extends p {
797
797
  storeManager;
798
798
  queueStorageKey;
799
799
  retryDelay = he;
@@ -801,7 +801,7 @@ class It extends p {
801
801
  lastAsyncSend = 0;
802
802
  lastSyncSend = 0;
803
803
  constructor(e) {
804
- super(), this.storeManager = e, this.queueStorageKey = `${tt(this.get("config")?.id)}:${this.get("userId")}`, this.recoverPersistedEvents();
804
+ super(), this.storeManager = e, this.queueStorageKey = `${et(this.get("config")?.id)}:${this.get("userId")}`, this.recoverPersistedEvents();
805
805
  }
806
806
  async sendEventsQueueAsync(e) {
807
807
  return this.executeSend(e, () => this.sendQueueAsync(e));
@@ -887,7 +887,7 @@ class It extends p {
887
887
  }
888
888
  prepareRequest(e) {
889
889
  return {
890
- url: `${this.get("config").id === C.HttpLocal ? window.location.origin : this.get("apiUrl") ?? Ye}/events`,
890
+ url: this.get("config").id === C.HttpLocal ? window.location.origin : this.get("apiUrl"),
891
891
  payload: JSON.stringify(e)
892
892
  };
893
893
  }
@@ -1006,7 +1006,7 @@ class It extends p {
1006
1006
  this.retryTimeoutId !== null && (clearTimeout(this.retryTimeoutId), this.retryTimeoutId = null);
1007
1007
  }
1008
1008
  }
1009
- class Tt extends p {
1009
+ class It extends p {
1010
1010
  shouldSampleEvent(e, t) {
1011
1011
  return this.get("config")?.mode === "qa" || this.get("config")?.mode === "debug" ? !0 : e === h.WEB_VITALS ? this.isWebVitalEventSampledIn(t?.type) : this.isSampledIn();
1012
1012
  }
@@ -1030,7 +1030,7 @@ class Tt extends p {
1030
1030
  return Math.abs(t);
1031
1031
  }
1032
1032
  }
1033
- class Mt extends p {
1033
+ class Tt extends p {
1034
1034
  getEventTagsIds(e, t) {
1035
1035
  switch (e.type) {
1036
1036
  case h.PAGE_VIEW:
@@ -1253,7 +1253,7 @@ class Mt extends p {
1253
1253
  return !1;
1254
1254
  }
1255
1255
  }
1256
- class At extends p {
1256
+ class Mt extends p {
1257
1257
  googleAnalytics;
1258
1258
  samplingManager;
1259
1259
  tagsManager;
@@ -1275,7 +1275,7 @@ class At extends p {
1275
1275
  // Persistence storage key
1276
1276
  PERSISTENCE_KEY = "tl:circuit_breaker_events";
1277
1277
  constructor(e, t = null) {
1278
- super(), this.storageManager = e, this.googleAnalytics = t, this.samplingManager = new Tt(), this.tagsManager = new Mt(), this.dataSender = new It(e), this.restoreEventsFromStorage(), i.debug("EventManager", "EventManager initialized", {
1278
+ super(), this.storageManager = e, this.googleAnalytics = t, this.samplingManager = new It(), this.tagsManager = new Tt(), this.dataSender = new wt(e), this.restoreEventsFromStorage(), i.debug("EventManager", "EventManager initialized", {
1279
1279
  hasGoogleAnalytics: !!t,
1280
1280
  restoredEventsCount: this.eventsQueue.length
1281
1281
  });
@@ -1323,14 +1323,14 @@ class At extends p {
1323
1323
  });
1324
1324
  return;
1325
1325
  }
1326
- const g = t || this.get("pageUrl"), y = bt(g, this.get("config").excludedUrlPaths), I = this.get("hasStartSession"), A = e == h.SESSION_END;
1326
+ const g = t || this.get("pageUrl"), y = yt(g, this.get("config").excludedUrlPaths), I = this.get("hasStartSession"), A = e == h.SESSION_END;
1327
1327
  if (y && (!A || A && !I)) {
1328
1328
  (this.get("config")?.mode === "qa" || this.get("config")?.mode === "debug") && i.debug("EventManager", `Event ${e} on excluded route: ${t}`);
1329
1329
  return;
1330
1330
  }
1331
1331
  const U = e === h.SESSION_START;
1332
1332
  U && this.set("hasStartSession", !0);
1333
- const ie = U ? rt() : void 0, O = {
1333
+ const ie = U ? nt() : void 0, O = {
1334
1334
  type: e,
1335
1335
  page_url: y ? "excluded" : g,
1336
1336
  timestamp: Date.now(),
@@ -1584,7 +1584,7 @@ class At extends p {
1584
1584
  }
1585
1585
  }
1586
1586
  }
1587
- class _t extends p {
1587
+ class At extends p {
1588
1588
  storageManager;
1589
1589
  constructor(e) {
1590
1590
  super(), this.storageManager = e;
@@ -1597,7 +1597,7 @@ class _t extends p {
1597
1597
  return this.storageManager.setItem(ve(this.get("config")?.id), t), t;
1598
1598
  }
1599
1599
  }
1600
- class Ct {
1600
+ class _t {
1601
1601
  onActivity;
1602
1602
  options = { passive: !0 };
1603
1603
  constructor(e) {
@@ -1618,7 +1618,7 @@ class Ct {
1618
1618
  }
1619
1619
  }
1620
1620
  }
1621
- class Lt {
1621
+ class Ct {
1622
1622
  onActivity;
1623
1623
  options = { passive: !0 };
1624
1624
  motionThreshold;
@@ -1648,7 +1648,7 @@ class Lt {
1648
1648
  }
1649
1649
  };
1650
1650
  }
1651
- class Rt {
1651
+ class Lt {
1652
1652
  onActivity;
1653
1653
  options = { passive: !0 };
1654
1654
  constructor(e) {
@@ -1669,7 +1669,7 @@ class Rt {
1669
1669
  }
1670
1670
  }
1671
1671
  }
1672
- class kt {
1672
+ class Rt {
1673
1673
  onActivity;
1674
1674
  options = { passive: !0 };
1675
1675
  constructor(e) {
@@ -1690,7 +1690,7 @@ class kt {
1690
1690
  }
1691
1691
  }
1692
1692
  }
1693
- class Nt {
1693
+ class kt {
1694
1694
  onActivity;
1695
1695
  onVisibilityChange;
1696
1696
  isMobile;
@@ -1727,7 +1727,7 @@ class Nt {
1727
1727
  }
1728
1728
  }
1729
1729
  }
1730
- class Ut {
1730
+ class Nt {
1731
1731
  onInactivity;
1732
1732
  options = { passive: !0 };
1733
1733
  constructor(e) {
@@ -1911,7 +1911,7 @@ class Ce extends p {
1911
1911
  this.storageManager.removeItem(V(this.projectId)), this.debugMode && i.debug("SessionRecovery", "Cleared all recovery data");
1912
1912
  }
1913
1913
  }
1914
- class Pt extends p {
1914
+ class Ut extends p {
1915
1915
  config;
1916
1916
  eventManager = null;
1917
1917
  storageManager = null;
@@ -2052,9 +2052,9 @@ class Pt extends p {
2052
2052
  return { hasTouch: e, hasMouse: t, hasKeyboard: s, isMobile: r };
2053
2053
  }
2054
2054
  initializeListenerManagers() {
2055
- this.listenerManagers.push(new Ct(this.handleActivity)), this.deviceCapabilities.hasTouch && this.listenerManagers.push(new Lt(this.handleActivity, this.config.motionThreshold)), this.deviceCapabilities.hasMouse && this.listenerManagers.push(new Rt(this.handleActivity)), this.deviceCapabilities.hasKeyboard && this.listenerManagers.push(new kt(this.handleActivity)), this.listenerManagers.push(
2056
- new Nt(this.handleActivity, this.handleVisibilityChange, this.deviceCapabilities.isMobile)
2057
- ), this.listenerManagers.push(new Ut(this.handleInactivity));
2055
+ this.listenerManagers.push(new _t(this.handleActivity)), this.deviceCapabilities.hasTouch && this.listenerManagers.push(new Ct(this.handleActivity, this.config.motionThreshold)), this.deviceCapabilities.hasMouse && this.listenerManagers.push(new Lt(this.handleActivity)), this.deviceCapabilities.hasKeyboard && this.listenerManagers.push(new Rt(this.handleActivity)), this.listenerManagers.push(
2056
+ new kt(this.handleActivity, this.handleVisibilityChange, this.deviceCapabilities.isMobile)
2057
+ ), this.listenerManagers.push(new Nt(this.handleInactivity));
2058
2058
  }
2059
2059
  setupAllListeners() {
2060
2060
  this.listenerManagers.forEach((e) => e.setup());
@@ -2282,7 +2282,7 @@ class Pt extends p {
2282
2282
  );
2283
2283
  }
2284
2284
  }
2285
- class Ht extends p {
2285
+ class Pt extends p {
2286
2286
  constructor(e, t, s, r) {
2287
2287
  super(), this.callbacks = r, this.storageManager = e, this.projectId = t, this.tabId = $(), this.config = {
2288
2288
  tabHeartbeatIntervalMs: qe,
@@ -2323,7 +2323,7 @@ class Ht extends p {
2323
2323
  if (!this.isBroadcastChannelSupported())
2324
2324
  return null;
2325
2325
  try {
2326
- const e = new BroadcastChannel(it(this.projectId));
2326
+ const e = new BroadcastChannel(st(this.projectId));
2327
2327
  return this.setupBroadcastListeners(e), e;
2328
2328
  } catch (e) {
2329
2329
  return this.config.debugMode && i.warn("CrossTabSession", "Failed to initialize BroadcastChannel", { error: e }), null;
@@ -2729,7 +2729,7 @@ class Ht extends p {
2729
2729
  this.heartbeatInterval && (clearInterval(this.heartbeatInterval), this.heartbeatInterval = null), this.electionTimeout && (clearTimeout(this.electionTimeout), this.electionTimeout = null), this.cleanupTimeout && (clearTimeout(this.cleanupTimeout), this.cleanupTimeout = null), this.fallbackLeadershipTimeout && (clearTimeout(this.fallbackLeadershipTimeout), this.fallbackLeadershipTimeout = null), this.electionDelayTimeout && (clearTimeout(this.electionDelayTimeout), this.electionDelayTimeout = null), this.tabInfoCleanupTimeout && (clearTimeout(this.tabInfoCleanupTimeout), this.tabInfoCleanupTimeout = null), this.closingAnnouncementTimeout && (clearTimeout(this.closingAnnouncementTimeout), this.closingAnnouncementTimeout = null), this.leaderHealthCheckInterval && (clearInterval(this.leaderHealthCheckInterval), this.leaderHealthCheckInterval = null), this.endSession("manual_stop"), this.broadcastChannel && this.broadcastChannel.close();
2730
2730
  }
2731
2731
  }
2732
- class Dt extends p {
2732
+ class Ht extends p {
2733
2733
  eventManager;
2734
2734
  storageManager;
2735
2735
  sessionStorageKey;
@@ -2758,7 +2758,7 @@ class Dt extends p {
2758
2758
  return typeof BroadcastChannel < "u" && typeof navigator < "u" && "serviceWorker" in navigator;
2759
2759
  }
2760
2760
  constructor(e, t) {
2761
- super(), this.eventManager = t, this.storageManager = e, this.sessionStorageKey = st(this.get("config")?.id);
2761
+ super(), this.eventManager = t, this.storageManager = e, this.sessionStorageKey = tt(this.get("config")?.id);
2762
2762
  const s = this.get("config")?.id;
2763
2763
  s && this.initializeSessionRecoveryManager(s);
2764
2764
  }
@@ -2809,7 +2809,7 @@ class Dt extends p {
2809
2809
  syncTimeoutMs: pe.SYNC_TIMEOUT_MS,
2810
2810
  maxRetries: pe.MAX_RETRY_ATTEMPTS
2811
2811
  };
2812
- this.sessionManager = new Pt(
2812
+ this.sessionManager = new Ut(
2813
2813
  e,
2814
2814
  t,
2815
2815
  this.eventManager,
@@ -2852,7 +2852,7 @@ class Dt extends p {
2852
2852
  (this.get("config")?.mode === "qa" || this.get("config")?.mode === "debug") && i.warn("SessionHandler", "Cross-tab conflict detected"), this.sessionManager && this.sessionManager.trackSessionHealth("conflict");
2853
2853
  }
2854
2854
  };
2855
- this._crossTabSessionManager = new Ht(this.storageManager, e, t, l), i.debug("SessionHandler", "Cross-tab session manager initialized", { projectId: e });
2855
+ this._crossTabSessionManager = new Pt(this.storageManager, e, t, l), i.debug("SessionHandler", "Cross-tab session manager initialized", { projectId: e });
2856
2856
  }
2857
2857
  async createOrJoinSession() {
2858
2858
  if (this.crossTabSessionManager) {
@@ -2966,7 +2966,7 @@ class Dt extends p {
2966
2966
  this.heartbeatInterval && (clearInterval(this.heartbeatInterval), this.heartbeatInterval = null);
2967
2967
  }
2968
2968
  }
2969
- class xt extends p {
2969
+ class Dt extends p {
2970
2970
  eventManager;
2971
2971
  onTrack;
2972
2972
  originalPushState;
@@ -3017,7 +3017,7 @@ class xt extends p {
3017
3017
  return Object.values(t).some((s) => !!s) ? t : void 0;
3018
3018
  }
3019
3019
  }
3020
- class Ot extends p {
3020
+ class xt extends p {
3021
3021
  eventManager;
3022
3022
  clickHandler;
3023
3023
  constructor(e) {
@@ -3148,7 +3148,7 @@ class Ot extends p {
3148
3148
  };
3149
3149
  }
3150
3150
  }
3151
- class Ft extends p {
3151
+ class Ot extends p {
3152
3152
  eventManager;
3153
3153
  containers = [];
3154
3154
  constructor(e) {
@@ -3223,7 +3223,7 @@ class Ft extends p {
3223
3223
  }
3224
3224
  }
3225
3225
  }
3226
- class zt extends p {
3226
+ class Ft extends p {
3227
3227
  isInitialized = !1;
3228
3228
  constructor() {
3229
3229
  super();
@@ -3348,7 +3348,7 @@ class zt extends p {
3348
3348
  }
3349
3349
  }
3350
3350
  }
3351
- class Vt {
3351
+ class zt {
3352
3352
  storage = null;
3353
3353
  fallbackStorage = /* @__PURE__ */ new Map();
3354
3354
  storageAvailable = !1;
@@ -3403,7 +3403,7 @@ class Vt {
3403
3403
  }
3404
3404
  }
3405
3405
  }
3406
- class $t extends p {
3406
+ class Vt extends p {
3407
3407
  eventManager;
3408
3408
  reportedByNav = /* @__PURE__ */ new Map();
3409
3409
  observers = [];
@@ -3571,7 +3571,7 @@ class $t extends p {
3571
3571
  }
3572
3572
  }
3573
3573
  }
3574
- class jt extends p {
3574
+ class $t extends p {
3575
3575
  eventManager;
3576
3576
  piiPatterns = [
3577
3577
  /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
@@ -3648,7 +3648,7 @@ class jt extends p {
3648
3648
  return Math.random() < e;
3649
3649
  }
3650
3650
  }
3651
- class Gt extends p {
3651
+ class jt extends p {
3652
3652
  eventManager;
3653
3653
  originalFetch;
3654
3654
  originalXHROpen;
@@ -3763,7 +3763,7 @@ class Gt extends p {
3763
3763
  return Math.random() < e;
3764
3764
  }
3765
3765
  }
3766
- class Qt extends p {
3766
+ class Gt extends p {
3767
3767
  isInitialized = !1;
3768
3768
  googleAnalytics = null;
3769
3769
  storageManager;
@@ -3815,7 +3815,7 @@ class Qt extends p {
3815
3815
  i.warn("App", "Custom event attempted before eventManager initialization", { eventName: e });
3816
3816
  return;
3817
3817
  }
3818
- const { valid: s, error: r, sanitizedMetadata: a } = St(e, t);
3818
+ const { valid: s, error: r, sanitizedMetadata: a } = vt(e, t);
3819
3819
  if (s)
3820
3820
  i.debug("App", "Custom event validated and queued", { eventName: e, hasMetadata: !!a }), this.eventManager.track({
3821
3821
  type: h.CUSTOM,
@@ -3848,15 +3848,15 @@ class Qt extends p {
3848
3848
  this.setApiUrl(e.id, e.allowHttp), await this.setConfig(e), this.setUserId(), this.setDevice(), this.setPageUrl();
3849
3849
  }
3850
3850
  setApiUrl(e, t = !1) {
3851
- const s = new Et();
3851
+ const s = new bt();
3852
3852
  this.set("apiUrl", s.getUrl(e, t));
3853
3853
  }
3854
3854
  async setConfig(e) {
3855
- const s = await new wt().get(this.get("apiUrl"), e);
3855
+ const s = await new Et().get(this.get("apiUrl"), e);
3856
3856
  this.set("config", s);
3857
3857
  }
3858
3858
  setUserId() {
3859
- const t = new _t(this.storageManager).getId();
3859
+ const t = new At(this.storageManager).getId();
3860
3860
  this.set("userId", t);
3861
3861
  }
3862
3862
  setDevice() {
@@ -3869,7 +3869,7 @@ class Qt extends p {
3869
3869
  }
3870
3870
  async setIntegrations() {
3871
3871
  const e = this.get("config").ipExcluded, t = this.get("config").integrations?.googleAnalytics?.measurementId;
3872
- !e && t?.trim() && (this.googleAnalytics = new zt(), await this.googleAnalytics.initialize());
3872
+ !e && t?.trim() && (this.googleAnalytics = new Ft(), await this.googleAnalytics.initialize());
3873
3873
  }
3874
3874
  async initHandlers() {
3875
3875
  if (!this.eventManager)
@@ -3879,56 +3879,56 @@ class Qt extends p {
3879
3879
  this.initSessionHandler(), this.initPageViewHandler(), this.initClickHandler(), this.initScrollHandler(), await this.initPerformanceHandler(), this.initErrorHandler(), this.initNetworkHandler();
3880
3880
  }
3881
3881
  initStorage() {
3882
- this.storageManager = new Vt();
3882
+ this.storageManager = new zt();
3883
3883
  }
3884
3884
  setEventManager() {
3885
3885
  if (!this.storageManager)
3886
3886
  throw new Error("StorageManager must be initialized before EventManager");
3887
- this.eventManager = new At(this.storageManager, this.googleAnalytics);
3887
+ this.eventManager = new Mt(this.storageManager, this.googleAnalytics);
3888
3888
  }
3889
3889
  initSessionHandler() {
3890
3890
  if (!this.storageManager || !this.eventManager)
3891
3891
  throw new Error("StorageManager and EventManager must be initialized before SessionHandler");
3892
- this.sessionHandler = new Dt(this.storageManager, this.eventManager), this.sessionHandler.startTracking();
3892
+ this.sessionHandler = new Ht(this.storageManager, this.eventManager), this.sessionHandler.startTracking();
3893
3893
  }
3894
3894
  initPageViewHandler() {
3895
3895
  if (!this.eventManager)
3896
3896
  throw new Error("EventManager must be initialized before PageViewHandler");
3897
3897
  const e = () => this.onPageViewTrack();
3898
- this.pageViewHandler = new xt(this.eventManager, e), this.pageViewHandler.startTracking();
3898
+ this.pageViewHandler = new Dt(this.eventManager, e), this.pageViewHandler.startTracking();
3899
3899
  }
3900
3900
  onPageViewTrack() {
3901
3901
  this.set("suppressNextScroll", !0), this.suppressNextScrollTimer && (clearTimeout(this.suppressNextScrollTimer), this.suppressNextScrollTimer = null), this.suppressNextScrollTimer = window.setTimeout(() => {
3902
3902
  this.set("suppressNextScroll", !1);
3903
- }, Me * et.SUPPRESS_MULTIPLIER);
3903
+ }, Me * Ze.SUPPRESS_MULTIPLIER);
3904
3904
  }
3905
3905
  initClickHandler() {
3906
3906
  if (!this.eventManager)
3907
3907
  throw new Error("EventManager must be initialized before ClickHandler");
3908
- this.clickHandler = new Ot(this.eventManager), this.clickHandler.startTracking();
3908
+ this.clickHandler = new xt(this.eventManager), this.clickHandler.startTracking();
3909
3909
  }
3910
3910
  initScrollHandler() {
3911
3911
  if (!this.eventManager)
3912
3912
  throw new Error("EventManager must be initialized before ScrollHandler");
3913
- this.scrollHandler = new Ft(this.eventManager), this.scrollHandler.startTracking();
3913
+ this.scrollHandler = new Ot(this.eventManager), this.scrollHandler.startTracking();
3914
3914
  }
3915
3915
  async initPerformanceHandler() {
3916
3916
  if (!this.eventManager)
3917
3917
  throw new Error("EventManager must be initialized before PerformanceHandler");
3918
- this.performanceHandler = new $t(this.eventManager), await this.performanceHandler.startTracking();
3918
+ this.performanceHandler = new Vt(this.eventManager), await this.performanceHandler.startTracking();
3919
3919
  }
3920
3920
  initErrorHandler() {
3921
3921
  if (!this.eventManager)
3922
3922
  throw new Error("EventManager must be initialized before ErrorHandler");
3923
- this.errorHandler = new jt(this.eventManager), this.errorHandler.startTracking();
3923
+ this.errorHandler = new $t(this.eventManager), this.errorHandler.startTracking();
3924
3924
  }
3925
3925
  initNetworkHandler() {
3926
3926
  if (!this.eventManager)
3927
3927
  throw new Error("EventManager must be initialized before NetworkHandler");
3928
- this.networkHandler = new Gt(this.eventManager), this.networkHandler.startTracking();
3928
+ this.networkHandler = new jt(this.eventManager), this.networkHandler.startTracking();
3929
3929
  }
3930
3930
  }
3931
- const Bt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3931
+ const Qt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3932
3932
  __proto__: null,
3933
3933
  DeviceType: E,
3934
3934
  ErrorType: D,
@@ -3938,12 +3938,12 @@ const Bt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3938
3938
  TagConditionOperator: f,
3939
3939
  TagConditionType: m,
3940
3940
  TagLogicalOperator: G
3941
- }, Symbol.toStringTag, { value: "Module" })), qt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3941
+ }, Symbol.toStringTag, { value: "Module" })), Bt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3942
3942
  __proto__: null,
3943
3943
  DEFAULT_SESSION_TIMEOUT_MS: R
3944
3944
  }, Symbol.toStringTag, { value: "Module" }));
3945
3945
  let v = null, T = !1;
3946
- const Wt = async (n) => {
3946
+ const qt = async (n) => {
3947
3947
  try {
3948
3948
  if (i.info("API", "Library initialization started", { id: n.id }), typeof window > "u" || typeof document > "u")
3949
3949
  throw i.clientError(
@@ -3981,9 +3981,9 @@ const Wt = async (n) => {
3981
3981
  }), new Error("App initialization timeout - concurrent initialization took too long");
3982
3982
  }
3983
3983
  T = !0, i.debug("API", "Validating and normalizing configuration", { projectId: n.id });
3984
- const e = ht(n);
3984
+ const e = dt(n);
3985
3985
  i.debug("API", "Creating App instance", { projectId: e.id });
3986
- const t = new Qt();
3986
+ const t = new Gt();
3987
3987
  await t.init(e), v = t, i.info("API", "Library initialization completed successfully", {
3988
3988
  projectId: e.id
3989
3989
  });
@@ -3998,7 +3998,7 @@ const Wt = async (n) => {
3998
3998
  } finally {
3999
3999
  T = !1;
4000
4000
  }
4001
- }, Xt = (n, e) => {
4001
+ }, Wt = (n, e) => {
4002
4002
  try {
4003
4003
  if (!v)
4004
4004
  throw i.clientError("API", "Custom event failed - Library not initialized. Please call TraceLog.init() first", {
@@ -4014,11 +4014,11 @@ const Wt = async (n) => {
4014
4014
  if (i.error("API", "Event tracking failed", { eventName: n, error: t, hasMetadata: !!e }), t instanceof Error && (t.message === "App not initialized" || t.message.includes("validation failed")))
4015
4015
  throw t;
4016
4016
  }
4017
- }, Kt = () => v !== null, Yt = () => ({
4017
+ }, Xt = () => v !== null, Kt = () => ({
4018
4018
  isInitialized: v !== null,
4019
4019
  isInitializing: T,
4020
4020
  hasInstance: v !== null
4021
- }), Jt = () => {
4021
+ }), Yt = () => {
4022
4022
  try {
4023
4023
  if (i.info("API", "Library cleanup initiated"), !v)
4024
4024
  throw i.warn("API", "Cleanup called but Library was not initialized"), new Error("App not initialized");
@@ -4026,16 +4026,16 @@ const Wt = async (n) => {
4026
4026
  } catch (n) {
4027
4027
  i.error("API", "Cleanup failed", { error: n, hadApp: !!v, wasInitializing: T });
4028
4028
  }
4029
- }, Zt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4029
+ }, Jt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4030
4030
  __proto__: null,
4031
- Constants: qt,
4032
- Types: Bt,
4033
- destroy: Jt,
4034
- event: Xt,
4035
- getInitializationStatus: Yt,
4036
- init: Wt,
4037
- isInitialized: Kt
4031
+ Constants: Bt,
4032
+ Types: Qt,
4033
+ destroy: Yt,
4034
+ event: Wt,
4035
+ getInitializationStatus: Kt,
4036
+ init: qt,
4037
+ isInitialized: Xt
4038
4038
  }, Symbol.toStringTag, { value: "Module" }));
4039
4039
  export {
4040
- Zt as TraceLog
4040
+ Jt as TraceLog
4041
4041
  };
@@ -1,4 +1,3 @@
1
1
  import { ApiConfig, Config } from '../types';
2
- export declare const API_BASE_URL = "https://api.tracelog.io";
3
2
  export declare const DEFAULT_API_CONFIG: ApiConfig;
4
3
  export declare const DEFAULT_CONFIG: (config: Config) => Config;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_CONFIG = exports.DEFAULT_API_CONFIG = exports.API_BASE_URL = void 0;
3
+ exports.DEFAULT_CONFIG = exports.DEFAULT_API_CONFIG = void 0;
4
4
  const limits_constants_1 = require("./limits.constants");
5
5
  const timing_constants_1 = require("./timing.constants");
6
- exports.API_BASE_URL = 'https://api.tracelog.io';
7
6
  exports.DEFAULT_API_CONFIG = {
8
7
  samplingRate: limits_constants_1.DEFAULT_SAMPLING_RATE,
9
8
  tags: [],
@@ -128,9 +128,9 @@ class SenderManager extends state_manager_1.StateManager {
128
128
  }
129
129
  prepareRequest(body) {
130
130
  const useLocalServer = this.get('config').id === types_1.SpecialProjectId.HttpLocal;
131
- const baseUrl = useLocalServer ? window.location.origin : (this.get('apiUrl') ?? constants_1.API_BASE_URL);
131
+ const url = useLocalServer ? window.location.origin : this.get('apiUrl');
132
132
  return {
133
- url: `${baseUrl}/events`,
133
+ url,
134
134
  payload: JSON.stringify(body),
135
135
  };
136
136
  }
@@ -1,4 +1,3 @@
1
1
  import { ApiConfig, Config } from '../types';
2
- export declare const API_BASE_URL = "https://api.tracelog.io";
3
2
  export declare const DEFAULT_API_CONFIG: ApiConfig;
4
3
  export declare const DEFAULT_CONFIG: (config: Config) => Config;
@@ -1,6 +1,5 @@
1
1
  import { DEFAULT_SAMPLING_RATE } from './limits.constants';
2
2
  import { DEFAULT_SESSION_TIMEOUT_MS } from './timing.constants';
3
- export const API_BASE_URL = 'https://api.tracelog.io';
4
3
  export const DEFAULT_API_CONFIG = {
5
4
  samplingRate: DEFAULT_SAMPLING_RATE,
6
5
  tags: [],
@@ -1,4 +1,4 @@
1
- import { QUEUE_KEY, RETRY_BACKOFF_INITIAL, RETRY_BACKOFF_MAX, RATE_LIMIT_INTERVAL, EVENT_EXPIRY_HOURS, SYNC_XHR_TIMEOUT_MS, API_BASE_URL, } from '../constants';
1
+ import { QUEUE_KEY, RETRY_BACKOFF_INITIAL, RETRY_BACKOFF_MAX, RATE_LIMIT_INTERVAL, EVENT_EXPIRY_HOURS, SYNC_XHR_TIMEOUT_MS, } from '../constants';
2
2
  import { SpecialProjectId, Mode } from '../types';
3
3
  import { debugLog } from '../utils/logging';
4
4
  import { StateManager } from './state.manager';
@@ -125,9 +125,9 @@ export class SenderManager extends StateManager {
125
125
  }
126
126
  prepareRequest(body) {
127
127
  const useLocalServer = this.get('config').id === SpecialProjectId.HttpLocal;
128
- const baseUrl = useLocalServer ? window.location.origin : (this.get('apiUrl') ?? API_BASE_URL);
128
+ const url = useLocalServer ? window.location.origin : this.get('apiUrl');
129
129
  return {
130
- url: `${baseUrl}/events`,
130
+ url,
131
131
  payload: JSON.stringify(body),
132
132
  };
133
133
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tracelog/lib",
3
3
  "description": "JavaScript library for web analytics and real-time event tracking",
4
4
  "license": "MIT",
5
- "version": "0.0.2",
5
+ "version": "0.0.4",
6
6
  "main": "./dist/cjs/public-api.js",
7
7
  "module": "./dist/esm/public-api.js",
8
8
  "types": "./dist/esm/public-api.d.ts",