@tracelog/lib 0.0.5 → 0.0.6
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/browser/tracelog.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var E = /* @__PURE__ */ ((r) => (r.Mobile = "mobile", r.Tablet = "tablet", r.Desktop = "desktop", r.Unknown = "unknown", r))(E || {});
|
|
2
|
-
const
|
|
2
|
+
const B = {};
|
|
3
3
|
class p {
|
|
4
4
|
get(e) {
|
|
5
|
-
return
|
|
5
|
+
return B[e];
|
|
6
6
|
}
|
|
7
7
|
set(e, t) {
|
|
8
|
-
const s =
|
|
9
|
-
|
|
8
|
+
const s = B[e];
|
|
9
|
+
B[e] = t, (e === "sessionId" || e === "config" || e === "hasStartSession") && i.debug("StateManager", "Critical state updated", {
|
|
10
10
|
key: e,
|
|
11
11
|
oldValue: e === "config" ? !!s : s,
|
|
12
12
|
newValue: e === "config" ? !!t : t
|
|
@@ -158,7 +158,7 @@ const ke = () => {
|
|
|
158
158
|
error: r instanceof Error ? r.message : r
|
|
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,
|
|
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, He = 4, Pe = 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, qe = Te, Be = 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: []
|
|
@@ -290,7 +290,7 @@ class Q extends x {
|
|
|
290
290
|
super(e, "PROJECT_ID_INVALID", t);
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
-
class
|
|
293
|
+
class P extends x {
|
|
294
294
|
constructor(e, t = "config") {
|
|
295
295
|
super(e, "APP_CONFIG_INVALID", t);
|
|
296
296
|
}
|
|
@@ -312,7 +312,7 @@ class ye extends x {
|
|
|
312
312
|
}
|
|
313
313
|
const ot = (r) => {
|
|
314
314
|
if (!r || typeof r != "object")
|
|
315
|
-
throw i.clientError("ConfigValidation", "Configuration must be an object", { config: r }), new
|
|
315
|
+
throw i.clientError("ConfigValidation", "Configuration must be an object", { config: r }), new P("Configuration must be an object", "config");
|
|
316
316
|
if (!("id" in r))
|
|
317
317
|
throw i.clientError("ConfigValidation", "Project ID is missing from configuration"), new Q(w.MISSING_PROJECT_ID, "config");
|
|
318
318
|
if (r.id === null || r.id === void 0 || typeof r.id != "string")
|
|
@@ -330,19 +330,19 @@ const ot = (r) => {
|
|
|
330
330
|
throw i.clientError("ConfigValidation", "Global metadata must be an object", {
|
|
331
331
|
provided: r.globalMetadata,
|
|
332
332
|
type: typeof r.globalMetadata
|
|
333
|
-
}), new
|
|
333
|
+
}), new P(w.INVALID_GLOBAL_METADATA, "config");
|
|
334
334
|
if (r.scrollContainerSelectors !== void 0 && ct(r.scrollContainerSelectors), r.integrations && lt(r.integrations), r.sensitiveQueryParams !== void 0) {
|
|
335
335
|
if (!Array.isArray(r.sensitiveQueryParams))
|
|
336
336
|
throw i.clientError("ConfigValidation", "Sensitive query params must be an array", {
|
|
337
337
|
provided: r.sensitiveQueryParams,
|
|
338
338
|
type: typeof r.sensitiveQueryParams
|
|
339
|
-
}), new
|
|
339
|
+
}), new P(w.INVALID_SENSITIVE_QUERY_PARAMS, "config");
|
|
340
340
|
for (const e of r.sensitiveQueryParams)
|
|
341
341
|
if (typeof e != "string")
|
|
342
342
|
throw i.clientError("ConfigValidation", "All sensitive query params must be strings", {
|
|
343
343
|
param: e,
|
|
344
344
|
type: typeof e
|
|
345
|
-
}), new
|
|
345
|
+
}), new P("All sensitive query params must be strings", "config");
|
|
346
346
|
}
|
|
347
347
|
if (r.errorSampling !== void 0 && (typeof r.errorSampling != "number" || r.errorSampling < 0 || r.errorSampling > 1))
|
|
348
348
|
throw i.clientError("ConfigValidation", "Invalid error sampling rate", {
|
|
@@ -357,7 +357,7 @@ const ot = (r) => {
|
|
|
357
357
|
selector: t,
|
|
358
358
|
type: typeof t,
|
|
359
359
|
isEmpty: t === "" || typeof t == "string" && t.trim() === ""
|
|
360
|
-
}), new
|
|
360
|
+
}), new P(w.INVALID_SCROLL_CONTAINER_SELECTORS, "config");
|
|
361
361
|
if (typeof document < "u")
|
|
362
362
|
try {
|
|
363
363
|
document.querySelector(t);
|
|
@@ -427,7 +427,7 @@ const ot = (r) => {
|
|
|
427
427
|
for (const t of _e)
|
|
428
428
|
e = e.replace(t, "");
|
|
429
429
|
return e = e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'"), e.trim();
|
|
430
|
-
},
|
|
430
|
+
}, q = (r, e = 0) => {
|
|
431
431
|
if (e > le)
|
|
432
432
|
return i.warn("Sanitize", "Maximum object depth exceeded during sanitization", {
|
|
433
433
|
depth: e,
|
|
@@ -448,7 +448,7 @@ const ot = (r) => {
|
|
|
448
448
|
maxLength: W,
|
|
449
449
|
depth: e
|
|
450
450
|
});
|
|
451
|
-
const n = s.map((a) =>
|
|
451
|
+
const n = s.map((a) => q(a, e + 1)).filter((a) => a !== null);
|
|
452
452
|
return t > 0 && n.length === 0 && i.warn("Sanitize", "All array items were filtered out during sanitization", { originalLength: t, depth: e }), n;
|
|
453
453
|
}
|
|
454
454
|
if (typeof r == "object") {
|
|
@@ -462,7 +462,7 @@ const ot = (r) => {
|
|
|
462
462
|
for (const [l, c] of a) {
|
|
463
463
|
const d = be(l);
|
|
464
464
|
if (d) {
|
|
465
|
-
const u =
|
|
465
|
+
const u = q(c, e + 1);
|
|
466
466
|
u !== null ? t[d] = u : o++;
|
|
467
467
|
} else
|
|
468
468
|
o++;
|
|
@@ -496,7 +496,7 @@ const ot = (r) => {
|
|
|
496
496
|
} else if (a === "tags")
|
|
497
497
|
Array.isArray(o) ? (e.tags = o, i.debug("Sanitize", "Tags processed", { count: o.length })) : i.warn("Sanitize", "Tags value is not an array", { value: o, type: typeof o });
|
|
498
498
|
else {
|
|
499
|
-
const l =
|
|
499
|
+
const l = q(o);
|
|
500
500
|
l !== null ? e[a] = l : i.warn("Sanitize", "API config value sanitized to null", { key: a, originalValue: o });
|
|
501
501
|
}
|
|
502
502
|
s++;
|
|
@@ -521,7 +521,7 @@ const ot = (r) => {
|
|
|
521
521
|
type: typeof r
|
|
522
522
|
}), {};
|
|
523
523
|
try {
|
|
524
|
-
const e = Object.keys(r).length, t =
|
|
524
|
+
const e = Object.keys(r).length, t = q(r), s = typeof t == "object" && t !== null ? t : {}, n = Object.keys(s).length;
|
|
525
525
|
return i.debug("Sanitize", "Metadata sanitization completed", {
|
|
526
526
|
originalKeys: e,
|
|
527
527
|
finalKeys: n,
|
|
@@ -860,10 +860,12 @@ class wt extends p {
|
|
|
860
860
|
method: "POST",
|
|
861
861
|
mode: "cors",
|
|
862
862
|
credentials: "omit",
|
|
863
|
+
body: s,
|
|
863
864
|
headers: {
|
|
864
|
-
"Content-Type": "application/json"
|
|
865
|
-
|
|
866
|
-
|
|
865
|
+
"Content-Type": "application/json",
|
|
866
|
+
Origin: window.location.origin,
|
|
867
|
+
Referer: window.location.href
|
|
868
|
+
}
|
|
867
869
|
})).ok;
|
|
868
870
|
} catch (n) {
|
|
869
871
|
const a = n instanceof Error ? n.message : String(n), o = a.includes("CORS") || a.includes("NotSameOrigin") || a.includes("blocked");
|
|
@@ -887,7 +889,7 @@ class wt extends p {
|
|
|
887
889
|
sendSyncXHR(e, t) {
|
|
888
890
|
const s = new XMLHttpRequest();
|
|
889
891
|
try {
|
|
890
|
-
return s.open("POST", e, !1), s.setRequestHeader("Content-Type", "application/json"), s.withCredentials = !1, s.timeout = xe, s.send(t), s.status >= 200 && s.status < 300;
|
|
892
|
+
return s.open("POST", e, !1), s.setRequestHeader("Content-Type", "application/json"), s.setRequestHeader("Origin", window.location.origin), s.setRequestHeader("Referer", window.location.href), s.withCredentials = !1, s.timeout = xe, s.send(t), s.status >= 200 && s.status < 300;
|
|
891
893
|
} catch (n) {
|
|
892
894
|
const a = n instanceof Error ? n.message : String(n), o = a.includes("CORS") || a.includes("NotSameOrigin") || a.includes("blocked");
|
|
893
895
|
return i.error("SenderManager", "Sync XHR failed", {
|
|
@@ -1028,7 +1030,7 @@ class It extends p {
|
|
|
1028
1030
|
return e >= 1 ? !0 : e <= 0 ? !1 : this.getHash(this.get("userId")) % 100 / 100 < e;
|
|
1029
1031
|
}
|
|
1030
1032
|
isWebVitalEventSampledIn(e) {
|
|
1031
|
-
const t = e === "LONG_TASK", s = t ? De :
|
|
1033
|
+
const t = e === "LONG_TASK", s = t ? De : Pe;
|
|
1032
1034
|
if (s >= 1) return !0;
|
|
1033
1035
|
if (s <= 0) return !1;
|
|
1034
1036
|
const n = `${this.get("userId")}|${t ? "long_task" : "web_vitals"}`;
|
|
@@ -1327,8 +1329,8 @@ class Mt extends p {
|
|
|
1327
1329
|
})) {
|
|
1328
1330
|
const k = Date.now();
|
|
1329
1331
|
if (this.eventsQueue && this.eventsQueue.length > 0) {
|
|
1330
|
-
const
|
|
1331
|
-
|
|
1332
|
+
const H = this.eventsQueue.at(-1);
|
|
1333
|
+
H && (H.timestamp = k);
|
|
1332
1334
|
}
|
|
1333
1335
|
this.lastEvent && (this.lastEvent.timestamp = k), i.debug("EventManager", "Duplicate event detected, timestamp updated", {
|
|
1334
1336
|
type: e,
|
|
@@ -1359,9 +1361,9 @@ class Mt extends p {
|
|
|
1359
1361
|
};
|
|
1360
1362
|
if (this.get("config")?.tags?.length) {
|
|
1361
1363
|
const k = this.tagsManager.getEventTagsIds(O, this.get("device"));
|
|
1362
|
-
k?.length && (O.tags = this.get("config")?.mode === "qa" || this.get("config")?.mode === "debug" ? k.map((
|
|
1363
|
-
id:
|
|
1364
|
-
key: this.get("config")?.tags?.find((Le) => Le.id ===
|
|
1364
|
+
k?.length && (O.tags = this.get("config")?.mode === "qa" || this.get("config")?.mode === "debug" ? k.map((H) => ({
|
|
1365
|
+
id: H,
|
|
1366
|
+
key: this.get("config")?.tags?.find((Le) => Le.id === H)?.key ?? ""
|
|
1365
1367
|
})) : k);
|
|
1366
1368
|
}
|
|
1367
1369
|
this.lastEvent = O, this.processAndSend(O);
|
|
@@ -2295,10 +2297,10 @@ class Ut extends p {
|
|
|
2295
2297
|
);
|
|
2296
2298
|
}
|
|
2297
2299
|
}
|
|
2298
|
-
class
|
|
2300
|
+
class Ht extends p {
|
|
2299
2301
|
constructor(e, t, s, n) {
|
|
2300
2302
|
super(), this.callbacks = n, this.storageManager = e, this.projectId = t, this.tabId = $(), this.config = {
|
|
2301
|
-
tabHeartbeatIntervalMs:
|
|
2303
|
+
tabHeartbeatIntervalMs: Be,
|
|
2302
2304
|
tabElectionTimeoutMs: We,
|
|
2303
2305
|
debugMode: (this.get("config")?.mode === "qa" || this.get("config")?.mode === "debug") ?? !1,
|
|
2304
2306
|
...s
|
|
@@ -2742,7 +2744,7 @@ class Pt extends p {
|
|
|
2742
2744
|
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();
|
|
2743
2745
|
}
|
|
2744
2746
|
}
|
|
2745
|
-
class
|
|
2747
|
+
class Pt extends p {
|
|
2746
2748
|
eventManager;
|
|
2747
2749
|
storageManager;
|
|
2748
2750
|
sessionStorageKey;
|
|
@@ -2865,7 +2867,7 @@ class Ht extends p {
|
|
|
2865
2867
|
(this.get("config")?.mode === "qa" || this.get("config")?.mode === "debug") && i.warn("SessionHandler", "Cross-tab conflict detected"), this.sessionManager && this.sessionManager.trackSessionHealth("conflict");
|
|
2866
2868
|
}
|
|
2867
2869
|
};
|
|
2868
|
-
this._crossTabSessionManager = new
|
|
2870
|
+
this._crossTabSessionManager = new Ht(this.storageManager, e, t, l), i.debug("SessionHandler", "Cross-tab session manager initialized", { projectId: e });
|
|
2869
2871
|
}
|
|
2870
2872
|
async createOrJoinSession() {
|
|
2871
2873
|
if (this.crossTabSessionManager) {
|
|
@@ -3463,7 +3465,7 @@ class Vt extends p {
|
|
|
3463
3465
|
const a = typeof n.value == "number" ? n.value : 0;
|
|
3464
3466
|
e += a;
|
|
3465
3467
|
}
|
|
3466
|
-
this.sendVital({ type: "CLS", value: Number(e.toFixed(
|
|
3468
|
+
this.sendVital({ type: "CLS", value: Number(e.toFixed(He)) });
|
|
3467
3469
|
},
|
|
3468
3470
|
{ type: "layout-shift", buffered: !0 }
|
|
3469
3471
|
), this.safeObserve(
|
|
@@ -3523,7 +3525,7 @@ class Vt extends p {
|
|
|
3523
3525
|
const t = e.getEntries();
|
|
3524
3526
|
for (const s of t) {
|
|
3525
3527
|
const n = Number(s.duration.toFixed(N)), a = Date.now();
|
|
3526
|
-
a - this.lastLongTaskSentAt >=
|
|
3528
|
+
a - this.lastLongTaskSentAt >= qe && (this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = a);
|
|
3527
3529
|
}
|
|
3528
3530
|
},
|
|
3529
3531
|
{ type: "longtask", buffered: !0 }
|
|
@@ -3902,7 +3904,7 @@ class Gt extends p {
|
|
|
3902
3904
|
initSessionHandler() {
|
|
3903
3905
|
if (!this.storageManager || !this.eventManager)
|
|
3904
3906
|
throw new Error("StorageManager and EventManager must be initialized before SessionHandler");
|
|
3905
|
-
this.sessionHandler = new
|
|
3907
|
+
this.sessionHandler = new Pt(this.storageManager, this.eventManager), this.sessionHandler.startTracking();
|
|
3906
3908
|
}
|
|
3907
3909
|
initPageViewHandler() {
|
|
3908
3910
|
if (!this.eventManager)
|
|
@@ -3951,12 +3953,12 @@ const Qt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
3951
3953
|
TagConditionOperator: f,
|
|
3952
3954
|
TagConditionType: m,
|
|
3953
3955
|
TagLogicalOperator: G
|
|
3954
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
3956
|
+
}, Symbol.toStringTag, { value: "Module" })), qt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3955
3957
|
__proto__: null,
|
|
3956
3958
|
DEFAULT_SESSION_TIMEOUT_MS: R
|
|
3957
3959
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
3958
3960
|
let v = null, T = !1;
|
|
3959
|
-
const
|
|
3961
|
+
const Bt = async (r) => {
|
|
3960
3962
|
try {
|
|
3961
3963
|
if (i.info("API", "Library initialization started", { id: r.id }), typeof window > "u" || typeof document > "u")
|
|
3962
3964
|
throw i.clientError(
|
|
@@ -4041,12 +4043,12 @@ const qt = async (r) => {
|
|
|
4041
4043
|
}
|
|
4042
4044
|
}, Jt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4043
4045
|
__proto__: null,
|
|
4044
|
-
Constants:
|
|
4046
|
+
Constants: qt,
|
|
4045
4047
|
Types: Qt,
|
|
4046
4048
|
destroy: Yt,
|
|
4047
4049
|
event: Wt,
|
|
4048
4050
|
getInitializationStatus: Kt,
|
|
4049
|
-
init:
|
|
4051
|
+
init: Bt,
|
|
4050
4052
|
isInitialized: Xt
|
|
4051
4053
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
4052
4054
|
export {
|
|
@@ -88,10 +88,12 @@ class SenderManager extends state_manager_1.StateManager {
|
|
|
88
88
|
method: 'POST',
|
|
89
89
|
mode: 'cors',
|
|
90
90
|
credentials: 'omit',
|
|
91
|
+
body: payload,
|
|
91
92
|
headers: {
|
|
92
93
|
'Content-Type': 'application/json',
|
|
94
|
+
Origin: window.location.origin,
|
|
95
|
+
Referer: window.location.href,
|
|
93
96
|
},
|
|
94
|
-
body: payload,
|
|
95
97
|
});
|
|
96
98
|
return response.ok;
|
|
97
99
|
}
|
|
@@ -125,6 +127,8 @@ class SenderManager extends state_manager_1.StateManager {
|
|
|
125
127
|
try {
|
|
126
128
|
xhr.open('POST', url, false);
|
|
127
129
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
130
|
+
xhr.setRequestHeader('Origin', window.location.origin);
|
|
131
|
+
xhr.setRequestHeader('Referer', window.location.href);
|
|
128
132
|
xhr.withCredentials = false;
|
|
129
133
|
xhr.timeout = constants_1.SYNC_XHR_TIMEOUT_MS;
|
|
130
134
|
xhr.send(payload);
|
|
@@ -85,10 +85,12 @@ export class SenderManager extends StateManager {
|
|
|
85
85
|
method: 'POST',
|
|
86
86
|
mode: 'cors',
|
|
87
87
|
credentials: 'omit',
|
|
88
|
+
body: payload,
|
|
88
89
|
headers: {
|
|
89
90
|
'Content-Type': 'application/json',
|
|
91
|
+
Origin: window.location.origin,
|
|
92
|
+
Referer: window.location.href,
|
|
90
93
|
},
|
|
91
|
-
body: payload,
|
|
92
94
|
});
|
|
93
95
|
return response.ok;
|
|
94
96
|
}
|
|
@@ -122,6 +124,8 @@ export class SenderManager extends StateManager {
|
|
|
122
124
|
try {
|
|
123
125
|
xhr.open('POST', url, false);
|
|
124
126
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
127
|
+
xhr.setRequestHeader('Origin', window.location.origin);
|
|
128
|
+
xhr.setRequestHeader('Referer', window.location.href);
|
|
125
129
|
xhr.withCredentials = false;
|
|
126
130
|
xhr.timeout = SYNC_XHR_TIMEOUT_MS;
|
|
127
131
|
xhr.send(payload);
|
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.
|
|
5
|
+
"version": "0.0.6",
|
|
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",
|