@absolutejs/beacon 0.3.16 → 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 +103 -19
- 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;
|
|
@@ -767,9 +841,17 @@ var createBeacon = (options) => {
|
|
|
767
841
|
captureException(reason, { level: "error" });
|
|
768
842
|
return;
|
|
769
843
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
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
|
+
});
|
|
773
855
|
};
|
|
774
856
|
window.addEventListener("unhandledrejection", onRejection);
|
|
775
857
|
cleanups.push(() => window.removeEventListener("unhandledrejection", onRejection));
|
|
@@ -1002,6 +1084,8 @@ var captureException = (error, context) => current?.captureException(error, cont
|
|
|
1002
1084
|
var captureMessage = (message, level) => current?.captureMessage(message, level);
|
|
1003
1085
|
var addBreadcrumb = (crumb) => current?.addBreadcrumb(crumb);
|
|
1004
1086
|
export {
|
|
1087
|
+
redactBeaconEvent,
|
|
1088
|
+
isKnownBeaconNoise,
|
|
1005
1089
|
initBeacon,
|
|
1006
1090
|
getBeacon,
|
|
1007
1091
|
createBeacon,
|
|
@@ -1013,5 +1097,5 @@ export {
|
|
|
1013
1097
|
BEACON_ATTRIBUTE
|
|
1014
1098
|
};
|
|
1015
1099
|
|
|
1016
|
-
//# debugId=
|
|
1100
|
+
//# debugId=ACD2A0D595BEEB5764756E2164756E21
|
|
1017
1101
|
//# sourceMappingURL=index.js.map
|