vantmetry 0.0.2 → 0.0.3
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/index.js +2 -2
- package/{init-DeOqWgSl.js → init-DdlNmKDT.js} +61 -53
- package/next/index.js +1 -1
- package/package.json +1 -1
- package/react/index.js +1 -1
- package/src/core/listeners.ts +10 -4
- package/src/core/tracker.ts +7 -1
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as t } from "./init-
|
|
2
|
-
import { V as i, i as g, a as f } from "./init-
|
|
1
|
+
import { g as t } from "./init-DdlNmKDT.js";
|
|
2
|
+
import { V as i, i as g, a as f } from "./init-DdlNmKDT.js";
|
|
3
3
|
const n = {
|
|
4
4
|
get isReady() {
|
|
5
5
|
return t().isReady;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
let
|
|
2
|
-
function
|
|
3
|
-
|
|
1
|
+
let f = null;
|
|
2
|
+
function E(n) {
|
|
3
|
+
f = n;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
if (!
|
|
5
|
+
function A() {
|
|
6
|
+
if (!f)
|
|
7
7
|
throw new Error("[Vantmetry] Not initialized. Call init() before using logger.");
|
|
8
|
-
return
|
|
8
|
+
return f;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
return
|
|
10
|
+
function T() {
|
|
11
|
+
return f !== null;
|
|
12
12
|
}
|
|
13
|
-
const
|
|
13
|
+
const c = {
|
|
14
14
|
ERROR: "ERROR",
|
|
15
15
|
INFO: "INFO",
|
|
16
16
|
WARN: "WARN",
|
|
@@ -65,7 +65,7 @@ class S {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
const
|
|
68
|
+
const l = {
|
|
69
69
|
// Matches standard email formats
|
|
70
70
|
email: /\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}\b/g,
|
|
71
71
|
// Matches standard CC groupings: 4-4-4-[3-4] with required separators, or Amex 4-6-5 format.
|
|
@@ -93,22 +93,22 @@ const c = {
|
|
|
93
93
|
"client_secret",
|
|
94
94
|
"auth"
|
|
95
95
|
]);
|
|
96
|
-
function
|
|
96
|
+
function d(n) {
|
|
97
97
|
let e = n;
|
|
98
|
-
return e = e.replace(
|
|
98
|
+
return e = e.replace(l.email, (t) => {
|
|
99
99
|
const s = t.split("@");
|
|
100
100
|
if (s.length !== 2)
|
|
101
101
|
return t;
|
|
102
|
-
const [r,
|
|
103
|
-
return `${r.charAt(0)}***@${
|
|
104
|
-
}), e = e.replace(
|
|
102
|
+
const [r, a] = s;
|
|
103
|
+
return `${r.charAt(0)}***@${a}`;
|
|
104
|
+
}), e = e.replace(l.creditCard, (t) => {
|
|
105
105
|
const s = t.replace(/[-\s]/g, ""), r = s.slice(-4);
|
|
106
106
|
return "*".repeat(s.length - 4) + r;
|
|
107
|
-
}), e = e.replace(
|
|
107
|
+
}), e = e.replace(l.ssn, (t) => `***-**-${t.slice(-4)}`), e = e.replace(l.jwt, "[JWT REDACTED]"), e = e.replace(l.authHeader, "$1 [TOKEN REDACTED]"), e;
|
|
108
108
|
}
|
|
109
109
|
function h(n, e = /* @__PURE__ */ new WeakSet()) {
|
|
110
110
|
if (typeof n == "string")
|
|
111
|
-
return
|
|
111
|
+
return d(n);
|
|
112
112
|
if (!n || typeof n != "object")
|
|
113
113
|
return n;
|
|
114
114
|
if (e.has(n))
|
|
@@ -117,17 +117,17 @@ function h(n, e = /* @__PURE__ */ new WeakSet()) {
|
|
|
117
117
|
return n.map((s) => h(s, e));
|
|
118
118
|
const t = {};
|
|
119
119
|
for (const [s, r] of Object.entries(n)) {
|
|
120
|
-
const
|
|
121
|
-
if (p.has(
|
|
120
|
+
const a = s.toLowerCase();
|
|
121
|
+
if (p.has(a) || Array.from(p).some((i) => a.includes(i))) {
|
|
122
122
|
t[s] = "[REDACTED]";
|
|
123
123
|
continue;
|
|
124
124
|
}
|
|
125
|
-
typeof r == "string" ? t[s] =
|
|
125
|
+
typeof r == "string" ? t[s] = d(r) : typeof r == "object" && r !== null ? t[s] = h(r, e) : t[s] = r;
|
|
126
126
|
}
|
|
127
127
|
return t;
|
|
128
128
|
}
|
|
129
|
-
const R = 50,
|
|
130
|
-
class
|
|
129
|
+
const R = 50, k = 2e3;
|
|
130
|
+
class v {
|
|
131
131
|
buffer = [];
|
|
132
132
|
flushTimer = null;
|
|
133
133
|
transport;
|
|
@@ -143,16 +143,16 @@ class _ {
|
|
|
143
143
|
}
|
|
144
144
|
// --- Public API ---
|
|
145
145
|
error(e, t) {
|
|
146
|
-
this.addToBuffer({ severity:
|
|
146
|
+
this.addToBuffer({ severity: c.ERROR, type: "manual", message: e, details: t });
|
|
147
147
|
}
|
|
148
148
|
warn(e, t) {
|
|
149
|
-
this.addToBuffer({ severity:
|
|
149
|
+
this.addToBuffer({ severity: c.WARN, type: "manual", message: e, details: t });
|
|
150
150
|
}
|
|
151
151
|
info(e, t) {
|
|
152
|
-
this.addToBuffer({ severity:
|
|
152
|
+
this.addToBuffer({ severity: c.INFO, type: "manual", message: e, details: t });
|
|
153
153
|
}
|
|
154
154
|
debug(e, t) {
|
|
155
|
-
this.addToBuffer({ severity:
|
|
155
|
+
this.addToBuffer({ severity: c.DEBUG, type: "manual", message: e, details: t });
|
|
156
156
|
}
|
|
157
157
|
async flush() {
|
|
158
158
|
if (this.buffer.length === 0)
|
|
@@ -177,12 +177,15 @@ class _ {
|
|
|
177
177
|
const s = this.getSignature(e), r = this.sentErrors.get(s);
|
|
178
178
|
if (r && t - r < this.TTL_MS)
|
|
179
179
|
return;
|
|
180
|
-
const
|
|
181
|
-
if (
|
|
182
|
-
|
|
180
|
+
const a = this.buffer.find((m) => this.getSignature(m) === s);
|
|
181
|
+
if (a) {
|
|
182
|
+
a.count = (a.count || 1) + 1;
|
|
183
183
|
return;
|
|
184
184
|
}
|
|
185
|
-
|
|
185
|
+
let { message: i, stack: o } = e;
|
|
186
|
+
const { details: u } = e;
|
|
187
|
+
i instanceof Error && (o = o ?? i.stack, i = i.message || String(i));
|
|
188
|
+
const g = typeof i == "string" ? d(i) : i, y = typeof u == "object" ? h(u) : u, w = typeof o == "string" ? d(o) : o;
|
|
186
189
|
this.buffer.push({
|
|
187
190
|
...e,
|
|
188
191
|
message: g,
|
|
@@ -194,7 +197,7 @@ class _ {
|
|
|
194
197
|
ua: navigator.userAgent
|
|
195
198
|
}), this.buffer.length >= R ? this.flush() : this.flushTimer || (this.flushTimer = setTimeout(() => {
|
|
196
199
|
this.flush();
|
|
197
|
-
},
|
|
200
|
+
}, k));
|
|
198
201
|
}
|
|
199
202
|
captureAutoError(e) {
|
|
200
203
|
this.addToBuffer(e);
|
|
@@ -203,26 +206,31 @@ class _ {
|
|
|
203
206
|
return `${e.type}:${e.severity}:${e.message}`;
|
|
204
207
|
}
|
|
205
208
|
}
|
|
206
|
-
function
|
|
209
|
+
function _(n) {
|
|
207
210
|
const e = console.error;
|
|
208
211
|
console.error = function(...t) {
|
|
209
212
|
if (e.apply(console, t), !n._isCapturingConsoleError) {
|
|
210
213
|
n._isCapturingConsoleError = !0;
|
|
211
214
|
try {
|
|
212
215
|
let s, r;
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
216
|
+
const a = t.findIndex((o) => o instanceof Error), i = t[a];
|
|
217
|
+
if (i) {
|
|
218
|
+
const o = t.slice(0, a).filter((u) => typeof u == "string").join(" ");
|
|
219
|
+
s = o ? `${o}: ${i.message || String(i)}` : i.message || String(i), r = i.stack;
|
|
220
|
+
} else
|
|
221
|
+
s = t.map((o) => {
|
|
222
|
+
if (typeof o == "string") return o;
|
|
223
|
+
try {
|
|
224
|
+
return JSON.stringify(o);
|
|
225
|
+
} catch {
|
|
226
|
+
return String(o);
|
|
227
|
+
}
|
|
228
|
+
}).join(" ");
|
|
229
|
+
n.captureAutoError({
|
|
222
230
|
type: "console.error",
|
|
223
231
|
message: s || "Unknown console.error",
|
|
224
232
|
stack: r,
|
|
225
|
-
severity:
|
|
233
|
+
severity: c.ERROR
|
|
226
234
|
});
|
|
227
235
|
} finally {
|
|
228
236
|
n._isCapturingConsoleError = !1;
|
|
@@ -234,29 +242,29 @@ function A(n) {
|
|
|
234
242
|
message: t.message || "Script error.",
|
|
235
243
|
stack: t.error?.stack,
|
|
236
244
|
loc: `${t.filename}:${t.lineno}:${t.colno}`,
|
|
237
|
-
severity:
|
|
245
|
+
severity: c.ERROR
|
|
238
246
|
});
|
|
239
247
|
}, { capture: !0 }), window.addEventListener("unhandledrejection", function(t) {
|
|
240
|
-
const s = t.reason;
|
|
248
|
+
const s = t.reason, r = s instanceof Error;
|
|
241
249
|
n.captureAutoError({
|
|
242
250
|
type: "promise",
|
|
243
|
-
message:
|
|
244
|
-
stack:
|
|
245
|
-
severity:
|
|
251
|
+
message: r ? s.message : String(s),
|
|
252
|
+
stack: r ? s.stack : new Error(`Unhandled rejection: ${String(s)}`).stack,
|
|
253
|
+
severity: c.ERROR
|
|
246
254
|
});
|
|
247
255
|
}, { capture: !0 }), document.addEventListener("visibilitychange", function() {
|
|
248
256
|
document.visibilityState === "hidden" && n.flush();
|
|
249
257
|
});
|
|
250
258
|
}
|
|
251
259
|
function C(n) {
|
|
252
|
-
if (
|
|
260
|
+
if (T())
|
|
253
261
|
return;
|
|
254
|
-
const e = new
|
|
255
|
-
|
|
262
|
+
const e = new v(n);
|
|
263
|
+
E(e), _(e);
|
|
256
264
|
}
|
|
257
265
|
export {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
266
|
+
v as V,
|
|
267
|
+
_ as a,
|
|
268
|
+
A as g,
|
|
261
269
|
C as i
|
|
262
270
|
};
|
package/next/index.js
CHANGED
package/package.json
CHANGED
package/react/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as s } from "react/jsx-runtime";
|
|
2
2
|
import { createContext as i, Component as a, useEffect as u, useContext as c } from "react";
|
|
3
3
|
import { logger as o } from "../index.js";
|
|
4
|
-
import { i as m } from "../init-
|
|
4
|
+
import { i as m } from "../init-DdlNmKDT.js";
|
|
5
5
|
const n = i(null);
|
|
6
6
|
function h({ publicKey: t, ingestorUrl: r, children: e }) {
|
|
7
7
|
return u(() => {
|
package/src/core/listeners.ts
CHANGED
|
@@ -13,9 +13,14 @@ export function initGlobalListeners(tracker: VantmetryTracker) {
|
|
|
13
13
|
let message: string;
|
|
14
14
|
let stack: string | undefined;
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const errorIndex = args.findIndex((arg) => arg instanceof Error);
|
|
17
|
+
const errorObj = args[errorIndex] as Error | undefined;
|
|
17
18
|
if (errorObj) {
|
|
18
|
-
|
|
19
|
+
const prefix = args
|
|
20
|
+
.slice(0, errorIndex)
|
|
21
|
+
.filter((a) => typeof a === 'string')
|
|
22
|
+
.join(' ');
|
|
23
|
+
message = prefix ? `${prefix}: ${errorObj.message || String(errorObj)}` : errorObj.message || String(errorObj);
|
|
19
24
|
stack = errorObj.stack;
|
|
20
25
|
} else {
|
|
21
26
|
message = args
|
|
@@ -53,10 +58,11 @@ export function initGlobalListeners(tracker: VantmetryTracker) {
|
|
|
53
58
|
|
|
54
59
|
window.addEventListener('unhandledrejection', function (event: PromiseRejectionEvent) {
|
|
55
60
|
const reason = event.reason;
|
|
61
|
+
const isError = reason instanceof Error;
|
|
56
62
|
tracker.captureAutoError({
|
|
57
63
|
type: 'promise',
|
|
58
|
-
message:
|
|
59
|
-
stack: reason
|
|
64
|
+
message: isError ? reason.message : String(reason),
|
|
65
|
+
stack: isError ? reason.stack : new Error(`Unhandled rejection: ${String(reason)}`).stack,
|
|
60
66
|
severity: LogLevel.ERROR,
|
|
61
67
|
});
|
|
62
68
|
}, { capture: true });
|
package/src/core/tracker.ts
CHANGED
|
@@ -106,7 +106,13 @@ export class VantmetryTracker implements VantmetryInstance {
|
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
let { message, stack } = payload;
|
|
110
|
+
const { details } = payload;
|
|
111
|
+
|
|
112
|
+
if (message instanceof Error) {
|
|
113
|
+
stack = stack ?? message.stack;
|
|
114
|
+
message = message.message || String(message);
|
|
115
|
+
}
|
|
110
116
|
|
|
111
117
|
const maskedMessage = typeof message === 'string' ? maskPII(message) : message;
|
|
112
118
|
const maskedDetails = typeof details === 'object' ? maskObjectPII(details) : details;
|