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 CHANGED
@@ -1,5 +1,5 @@
1
- import { g as t } from "./init-DeOqWgSl.js";
2
- import { V as i, i as g, a as f } from "./init-DeOqWgSl.js";
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 u = null;
2
- function T(n) {
3
- u = n;
1
+ let f = null;
2
+ function E(n) {
3
+ f = n;
4
4
  }
5
- function k() {
6
- if (!u)
5
+ function A() {
6
+ if (!f)
7
7
  throw new Error("[Vantmetry] Not initialized. Call init() before using logger.");
8
- return u;
8
+ return f;
9
9
  }
10
- function E() {
11
- return u !== null;
10
+ function T() {
11
+ return f !== null;
12
12
  }
13
- const a = {
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 c = {
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 l(n) {
96
+ function d(n) {
97
97
  let e = n;
98
- return e = e.replace(c.email, (t) => {
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, i] = s;
103
- return `${r.charAt(0)}***@${i}`;
104
- }), e = e.replace(c.creditCard, (t) => {
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(c.ssn, (t) => `***-**-${t.slice(-4)}`), e = e.replace(c.jwt, "[JWT REDACTED]"), e = e.replace(c.authHeader, "$1 [TOKEN REDACTED]"), e;
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 l(n);
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 i = s.toLowerCase();
121
- if (p.has(i) || Array.from(p).some((o) => i.includes(o))) {
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] = l(r) : typeof r == "object" && r !== null ? t[s] = h(r, e) : t[s] = r;
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, v = 2e3;
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: a.ERROR, type: "manual", message: e, details: t });
146
+ this.addToBuffer({ severity: c.ERROR, type: "manual", message: e, details: t });
147
147
  }
148
148
  warn(e, t) {
149
- this.addToBuffer({ severity: a.WARN, type: "manual", message: e, details: t });
149
+ this.addToBuffer({ severity: c.WARN, type: "manual", message: e, details: t });
150
150
  }
151
151
  info(e, t) {
152
- this.addToBuffer({ severity: a.INFO, type: "manual", message: e, details: t });
152
+ this.addToBuffer({ severity: c.INFO, type: "manual", message: e, details: t });
153
153
  }
154
154
  debug(e, t) {
155
- this.addToBuffer({ severity: a.DEBUG, type: "manual", message: e, details: t });
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 i = this.buffer.find((m) => this.getSignature(m) === s);
181
- if (i) {
182
- i.count = (i.count || 1) + 1;
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
- const { message: o, details: f, stack: d } = e, g = typeof o == "string" ? l(o) : o, y = typeof f == "object" ? h(f) : f, w = typeof d == "string" ? l(d) : d;
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
- }, v));
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 A(n) {
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 i = t.find((o) => o instanceof Error);
214
- i ? (s = i.message || String(i), r = i.stack) : s = t.map((o) => {
215
- if (typeof o == "string") return o;
216
- try {
217
- return JSON.stringify(o);
218
- } catch {
219
- return String(o);
220
- }
221
- }).join(" "), n.captureAutoError({
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: a.ERROR
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: a.ERROR
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: s instanceof Error ? s.message : String(s),
244
- stack: s instanceof Error ? s.stack : void 0,
245
- severity: a.ERROR
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 (E())
260
+ if (T())
253
261
  return;
254
- const e = new _(n);
255
- T(e), A(e);
262
+ const e = new v(n);
263
+ E(e), _(e);
256
264
  }
257
265
  export {
258
- _ as V,
259
- A as a,
260
- k as g,
266
+ v as V,
267
+ _ as a,
268
+ A as g,
261
269
  C as i
262
270
  };
package/next/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as i } from "react/jsx-runtime";
2
2
  import n from "next/script";
3
- import { i as e } from "../init-DeOqWgSl.js";
3
+ import { i as e } from "../init-DdlNmKDT.js";
4
4
  function m({ publicKey: t, ingestorUrl: r }) {
5
5
  return /* @__PURE__ */ i(
6
6
  n,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vantmetry",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Lightweight frontend error tracking with minimal browser impact.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
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-DeOqWgSl.js";
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(() => {
@@ -13,9 +13,14 @@ export function initGlobalListeners(tracker: VantmetryTracker) {
13
13
  let message: string;
14
14
  let stack: string | undefined;
15
15
 
16
- const errorObj = args.find((arg) => arg instanceof Error) as Error | undefined;
16
+ const errorIndex = args.findIndex((arg) => arg instanceof Error);
17
+ const errorObj = args[errorIndex] as Error | undefined;
17
18
  if (errorObj) {
18
- message = errorObj.message || String(errorObj);
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: reason instanceof Error ? reason.message : String(reason),
59
- stack: reason instanceof Error ? reason.stack : undefined,
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 });
@@ -106,7 +106,13 @@ export class VantmetryTracker implements VantmetryInstance {
106
106
  return;
107
107
  }
108
108
 
109
- const { message, details, stack } = payload;
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;