@absolutejs/beacon 0.3.15 → 0.3.17
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/README.md +9 -2
- package/dist/index.d.ts +15 -0
- package/dist/index.js +124 -23
- package/dist/index.js.map +3 -3
- package/dist/manifest.d.ts +2 -0
- package/dist/manifest.js +25 -8542
- package/dist/manifest.js.map +4 -117
- package/dist/manifest.json +13 -0
- package/package.json +28 -13
package/README.md
CHANGED
|
@@ -69,8 +69,15 @@ beacon.captureMessage("checkout started", "info");
|
|
|
69
69
|
- **Context** — `setTags`, `setUser`, per-call `tags`/`extra`, a per-session id.
|
|
70
70
|
- **Cause chains** — preserves nested `Error.cause` stacks and diagnostic fields
|
|
71
71
|
in `extra.errorCauses`, including database driver error codes and details.
|
|
72
|
-
- **Sampling + redaction** — `sampleRate
|
|
73
|
-
(return `null` to drop)
|
|
72
|
+
- **Sampling + redaction** — `sampleRate`, a `beforeSend(event)` hook
|
|
73
|
+
(return `null` to drop), and default credential/context redaction after the
|
|
74
|
+
hook so host customization cannot accidentally reintroduce secrets. URL
|
|
75
|
+
query/hash values, secret-bearing fields, bearer/JWT values, and breadcrumb
|
|
76
|
+
text are sanitized. Set `redact: false` only when a trusted boundary replaces
|
|
77
|
+
it.
|
|
78
|
+
- **Noise filtering** — known browser-host/scanner failures such as CefSharp's
|
|
79
|
+
`Object Not Found Matching Id` rejection are dropped by default
|
|
80
|
+
(`filterKnownNoise: false` opts out).
|
|
74
81
|
- **Resource policy** — `instrument.resourceErrors` accepts a predicate so
|
|
75
82
|
expected failures such as optional cross-origin images can become grouped
|
|
76
83
|
warnings while same-origin assets and critical scripts/styles remain errors.
|
package/dist/index.d.ts
CHANGED
|
@@ -171,6 +171,17 @@ export type BeaconOptions = {
|
|
|
171
171
|
sampleRate?: number;
|
|
172
172
|
/** Mutate or drop (return null) each event before it's buffered. */
|
|
173
173
|
beforeSend?: (event: BeaconEvent) => BeaconEvent | null;
|
|
174
|
+
/**
|
|
175
|
+
* Redact credentials, secret-bearing fields, and URL query/hash values after
|
|
176
|
+
* `beforeSend` and before buffering. Default true. Disable only when an
|
|
177
|
+
* equivalent trusted boundary owns redaction.
|
|
178
|
+
*/
|
|
179
|
+
redact?: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Drop signatures known to come from browser hosts/scanners rather than the
|
|
182
|
+
* page, such as CefSharp's JavaScript bridge rejections. Default true.
|
|
183
|
+
*/
|
|
184
|
+
filterKnownNoise?: boolean;
|
|
174
185
|
/** Supply the active session-replay id (wired by @absolutejs/replay). */
|
|
175
186
|
getReplayId?: () => string | undefined;
|
|
176
187
|
/** Auto-instrumentation toggles (all default true). */
|
|
@@ -246,6 +257,10 @@ export type Beacon = {
|
|
|
246
257
|
/** Remove all listeners + do a final flush. */
|
|
247
258
|
close: () => Promise<void>;
|
|
248
259
|
};
|
|
260
|
+
/** Redact an event without mutating the caller's object. */
|
|
261
|
+
export declare const redactBeaconEvent: (event: BeaconEvent) => BeaconEvent;
|
|
262
|
+
/** Known browser-host/scanner failures that do not originate in page code. */
|
|
263
|
+
export declare const isKnownBeaconNoise: (event: Pick<BeaconEvent, "message" | "name">) => boolean;
|
|
249
264
|
export declare const createBeacon: (options: BeaconOptions) => Beacon;
|
|
250
265
|
/** Initialize the global beacon. Returns the instance. */
|
|
251
266
|
export declare const initBeacon: (options: BeaconOptions) => Beacon;
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __returnValue = (v) => v;
|
|
3
|
-
function __exportSetter(name, newValue) {
|
|
4
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
5
|
-
}
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
set: __exportSetter.bind(all, name)
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
1
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
16
2
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
17
3
|
}) : x)(function(x) {
|
|
@@ -178,6 +164,89 @@ var safeStringify = (value) => {
|
|
|
178
164
|
return String(value);
|
|
179
165
|
}
|
|
180
166
|
};
|
|
167
|
+
var REDACTED = "[REDACTED]";
|
|
168
|
+
var SENSITIVE_KEY_NAMES = new Set([
|
|
169
|
+
"accesstoken",
|
|
170
|
+
"apikey",
|
|
171
|
+
"authorization",
|
|
172
|
+
"clientsecret",
|
|
173
|
+
"cookie",
|
|
174
|
+
"csrftoken",
|
|
175
|
+
"idtoken",
|
|
176
|
+
"password",
|
|
177
|
+
"passwd",
|
|
178
|
+
"proxyauthorization",
|
|
179
|
+
"refreshtoken",
|
|
180
|
+
"secret",
|
|
181
|
+
"setcookie",
|
|
182
|
+
"token"
|
|
183
|
+
]);
|
|
184
|
+
var URL_KEY_NAMES = new Set([
|
|
185
|
+
"endpoint",
|
|
186
|
+
"errorfilename",
|
|
187
|
+
"resourceurl",
|
|
188
|
+
"url"
|
|
189
|
+
]);
|
|
190
|
+
var normalizeFieldName = (key) => key.replace(/[^a-z0-9]/gi, "").toLowerCase();
|
|
191
|
+
var isSensitiveField = (key) => SENSITIVE_KEY_NAMES.has(normalizeFieldName(key));
|
|
192
|
+
var isUrlField = (key) => URL_KEY_NAMES.has(normalizeFieldName(key));
|
|
193
|
+
var redactUrl = (value) => {
|
|
194
|
+
try {
|
|
195
|
+
const absolute = /^[a-z][a-z\d+.-]*:/i.test(value);
|
|
196
|
+
const url = new URL(value, "https://beacon.invalid");
|
|
197
|
+
url.search = "";
|
|
198
|
+
url.hash = "";
|
|
199
|
+
return absolute ? url.toString() : `${url.pathname}`;
|
|
200
|
+
} catch {
|
|
201
|
+
return value.replace(/[?#].*$/, "");
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
var redactString = (value) => value.replace(/\b(Bearer)\s+[A-Za-z0-9._~+/-]+=*/gi, (_match, scheme) => `${scheme} ${REDACTED}`).replace(/([?&](?:access_token|api_?key|authorization|code|id_token|password|refresh_token|secret|token)=)[^&#\s]*/gi, `$1${REDACTED}`).replace(/\b((?:access_?token|api_?key|authorization|client_?secret|cookie|id_?token|password|passwd|refresh_?token|secret|token)\s*[:=]\s*)(?!Bearer\b|\[REDACTED\])[^,\s;]+/gi, `$1${REDACTED}`).replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g, REDACTED);
|
|
205
|
+
var redactValue = (value, key, seen, depth = 0) => {
|
|
206
|
+
if (key !== undefined && isSensitiveField(key))
|
|
207
|
+
return REDACTED;
|
|
208
|
+
if (typeof value === "string") {
|
|
209
|
+
return redactString(key !== undefined && isUrlField(key) ? redactUrl(value) : value);
|
|
210
|
+
}
|
|
211
|
+
if (value === null || typeof value === "number" || typeof value === "boolean") {
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
214
|
+
if (typeof value === "bigint")
|
|
215
|
+
return String(value);
|
|
216
|
+
if (typeof value !== "object")
|
|
217
|
+
return String(value);
|
|
218
|
+
if (depth >= 12)
|
|
219
|
+
return "[Truncated]";
|
|
220
|
+
if (seen.has(value))
|
|
221
|
+
return "[Circular]";
|
|
222
|
+
seen.add(value);
|
|
223
|
+
const redacted = Array.isArray(value) ? value.map((entry) => redactValue(entry, undefined, seen, depth + 1)) : Object.fromEntries(Object.entries(value).map(([field, entry]) => [
|
|
224
|
+
field,
|
|
225
|
+
redactValue(entry, field, seen, depth + 1)
|
|
226
|
+
]));
|
|
227
|
+
seen.delete(value);
|
|
228
|
+
return redacted;
|
|
229
|
+
};
|
|
230
|
+
var redactBeaconEvent = (event) => {
|
|
231
|
+
const redacted = {
|
|
232
|
+
...event,
|
|
233
|
+
message: redactString(event.message)
|
|
234
|
+
};
|
|
235
|
+
if (event.stack !== undefined)
|
|
236
|
+
redacted.stack = redactString(event.stack);
|
|
237
|
+
if (event.tags !== undefined) {
|
|
238
|
+
redacted.tags = Object.fromEntries(Object.entries(event.tags).map(([key, value]) => [
|
|
239
|
+
key,
|
|
240
|
+
redactValue(value, key, new Set)
|
|
241
|
+
]));
|
|
242
|
+
}
|
|
243
|
+
if (event.extra !== undefined) {
|
|
244
|
+
redacted.extra = redactValue(event.extra, undefined, new Set);
|
|
245
|
+
}
|
|
246
|
+
return redacted;
|
|
247
|
+
};
|
|
248
|
+
var CEF_SHARP_REJECTION = /^Object Not Found Matching Id:\d+, MethodName:[A-Za-z_$][\w$]*, ParamCount:\d+$/;
|
|
249
|
+
var isKnownBeaconNoise = (event) => event.name === "UnhandledRejection" && CEF_SHARP_REJECTION.test(event.message);
|
|
181
250
|
var errorWithStack = (name, message, location2) => {
|
|
182
251
|
const error = new Error(message);
|
|
183
252
|
error.name = name;
|
|
@@ -409,6 +478,8 @@ var createBeacon = (options) => {
|
|
|
409
478
|
const flushIntervalMs = options.flushIntervalMs ?? 5000;
|
|
410
479
|
const maxBreadcrumbs = options.maxBreadcrumbs ?? 30;
|
|
411
480
|
const sampleRate = options.sampleRate ?? 1;
|
|
481
|
+
const redact = options.redact !== false;
|
|
482
|
+
const filterKnownNoise = options.filterKnownNoise !== false;
|
|
412
483
|
const transport = options.transport ?? defaultTransport;
|
|
413
484
|
const instrument = options.instrument ?? {};
|
|
414
485
|
const sessionId = newId();
|
|
@@ -513,9 +584,12 @@ var createBeacon = (options) => {
|
|
|
513
584
|
if (user !== undefined)
|
|
514
585
|
extra.user = user;
|
|
515
586
|
enriched.extra = extra;
|
|
516
|
-
|
|
587
|
+
const customized = options.beforeSend !== undefined ? options.beforeSend(enriched) : enriched;
|
|
588
|
+
return customized === null || !redact ? customized : redactBeaconEvent(customized);
|
|
517
589
|
};
|
|
518
590
|
const push = (event) => {
|
|
591
|
+
if (filterKnownNoise && isKnownBeaconNoise(event))
|
|
592
|
+
return;
|
|
519
593
|
const enriched = enrich(event);
|
|
520
594
|
if (enriched === null)
|
|
521
595
|
return;
|
|
@@ -550,8 +624,24 @@ var createBeacon = (options) => {
|
|
|
550
624
|
const captureMessage = (message, level = "info") => {
|
|
551
625
|
push({ level, message, name: "Message" });
|
|
552
626
|
};
|
|
553
|
-
const emitSignal = (message, signalTags, traceId, extra) => {
|
|
554
|
-
|
|
627
|
+
const emitSignal = (message, signalTags, traceId, extra, stackBoundary, fallbackFramesToDrop = 1) => {
|
|
628
|
+
const error = new Error(message);
|
|
629
|
+
const captureStackTrace = Error.captureStackTrace;
|
|
630
|
+
if (captureStackTrace !== undefined) {
|
|
631
|
+
captureStackTrace(error, stackBoundary ?? emitSignal);
|
|
632
|
+
} else if (error.stack !== undefined) {
|
|
633
|
+
let remaining = fallbackFramesToDrop;
|
|
634
|
+
error.stack = error.stack.split(`
|
|
635
|
+
`).filter((line) => {
|
|
636
|
+
const isFrame = /^\s*at\b/u.test(line) || /@.+:\d+:\d+\s*$/u.test(line);
|
|
637
|
+
if (!isFrame || remaining === 0)
|
|
638
|
+
return true;
|
|
639
|
+
remaining -= 1;
|
|
640
|
+
return false;
|
|
641
|
+
}).join(`
|
|
642
|
+
`);
|
|
643
|
+
}
|
|
644
|
+
captureException(error, {
|
|
555
645
|
level: "warning",
|
|
556
646
|
tags: signalTags,
|
|
557
647
|
...traceId !== undefined ? { traceId } : {},
|
|
@@ -751,9 +841,17 @@ var createBeacon = (options) => {
|
|
|
751
841
|
captureException(reason, { level: "error" });
|
|
752
842
|
return;
|
|
753
843
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
844
|
+
if (typeof reason === "object" && reason !== null && typeof reason.stack === "string") {
|
|
845
|
+
captureException(reason, { level: "error" });
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
const message = typeof reason === "string" ? reason : safeStringify(reason);
|
|
849
|
+
captureException(errorWithoutStack("UnhandledRejection", message), {
|
|
850
|
+
extra: {
|
|
851
|
+
rejectionType: reason === null ? "null" : Array.isArray(reason) ? "array" : typeof reason
|
|
852
|
+
},
|
|
853
|
+
level: "error"
|
|
854
|
+
});
|
|
757
855
|
};
|
|
758
856
|
window.addEventListener("unhandledrejection", onRejection);
|
|
759
857
|
cleanups.push(() => window.removeEventListener("unhandledrejection", onRejection));
|
|
@@ -761,7 +859,7 @@ var createBeacon = (options) => {
|
|
|
761
859
|
if (instrument.console !== false && typeof console !== "undefined") {
|
|
762
860
|
for (const method of ["error", "warn"]) {
|
|
763
861
|
const original = console[method];
|
|
764
|
-
|
|
862
|
+
const wrappedConsole = (...args) => {
|
|
765
863
|
addBreadcrumb({
|
|
766
864
|
message: `console.${method}: ${args.map(String).join(" ")}`,
|
|
767
865
|
type: "console"
|
|
@@ -770,11 +868,12 @@ var createBeacon = (options) => {
|
|
|
770
868
|
inSignalConsole = true;
|
|
771
869
|
const text = args.map(String).join(" ").trim().slice(0, SIGNAL_TEXT_MAX);
|
|
772
870
|
if (text !== "")
|
|
773
|
-
emitSignal(text, { signal: BEACON_SIGNAL.CONSOLE_ERROR });
|
|
871
|
+
emitSignal(text, { signal: BEACON_SIGNAL.CONSOLE_ERROR }, undefined, undefined, wrappedConsole, 2);
|
|
774
872
|
inSignalConsole = false;
|
|
775
873
|
}
|
|
776
874
|
original.apply(console, args);
|
|
777
875
|
};
|
|
876
|
+
console[method] = wrappedConsole;
|
|
778
877
|
cleanups.push(() => {
|
|
779
878
|
console[method] = original;
|
|
780
879
|
});
|
|
@@ -985,6 +1084,8 @@ var captureException = (error, context) => current?.captureException(error, cont
|
|
|
985
1084
|
var captureMessage = (message, level) => current?.captureMessage(message, level);
|
|
986
1085
|
var addBreadcrumb = (crumb) => current?.addBreadcrumb(crumb);
|
|
987
1086
|
export {
|
|
1087
|
+
redactBeaconEvent,
|
|
1088
|
+
isKnownBeaconNoise,
|
|
988
1089
|
initBeacon,
|
|
989
1090
|
getBeacon,
|
|
990
1091
|
createBeacon,
|
|
@@ -996,5 +1097,5 @@ export {
|
|
|
996
1097
|
BEACON_ATTRIBUTE
|
|
997
1098
|
};
|
|
998
1099
|
|
|
999
|
-
//# debugId=
|
|
1100
|
+
//# debugId=ACD2A0D595BEEB5764756E2164756E21
|
|
1000
1101
|
//# sourceMappingURL=index.js.map
|