@absolutejs/beacon 0.6.48 → 0.6.50
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 +12 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +87 -2
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,6 +39,12 @@ initBeacon({
|
|
|
39
39
|
endpoint: "https://api.example.com/ingest",
|
|
40
40
|
release: import.meta.env.VITE_RELEASE,
|
|
41
41
|
environment: "production",
|
|
42
|
+
// Optional: detect a tab that stayed open across a deployment. The endpoint
|
|
43
|
+
// may return either `{ commit: "..." }` or `{ release: "..." }`.
|
|
44
|
+
releaseProbe: {
|
|
45
|
+
endpoint: "/version",
|
|
46
|
+
onStale: () => window.location.reload(),
|
|
47
|
+
},
|
|
42
48
|
});
|
|
43
49
|
|
|
44
50
|
// Uncaught errors + unhandled rejections are captured automatically.
|
|
@@ -143,6 +149,12 @@ beacon.captureMessage("checkout started", "info");
|
|
|
143
149
|
Reload loops require repeated loads of the same normalized route; ordinary
|
|
144
150
|
navigation across several pages does not qualify. Occlusion scans exclude
|
|
145
151
|
hidden, inert, transparent, and pointer-disabled control subtrees.
|
|
152
|
+
Applications can also configure `releaseProbe` to compare a long-lived page's
|
|
153
|
+
embedded release with a same-origin server endpoint. After a mismatch Beacon
|
|
154
|
+
reports one `stale_release`, suppresses synthetic issue signals from the
|
|
155
|
+
obsolete detector bundle, and invokes `onStale` after flushing. Every event
|
|
156
|
+
carries `sdkVersion` and `pageStartedAt` in `extra` for collector-side stale
|
|
157
|
+
evidence policy.
|
|
146
158
|
- **Theme and loading contracts** — mark an application boundary with
|
|
147
159
|
`data-beacon-theme="adaptive"` to report large opaque surfaces whose
|
|
148
160
|
luminance polarity contradicts the active light/dark mode. Interactive
|
package/dist/index.d.ts
CHANGED
|
@@ -103,6 +103,8 @@ export declare const BEACON_ATTRIBUTE: {
|
|
|
103
103
|
};
|
|
104
104
|
/** Response header used to correlate a browser signal with its server request. */
|
|
105
105
|
export declare const BEACON_TRACE_HEADER = "x-absolute-trace-id";
|
|
106
|
+
/** Beacon package version retained with every captured event. */
|
|
107
|
+
export declare const BEACON_SDK_VERSION = "0.6.50";
|
|
106
108
|
/** Arbitrary event tags, with Beacon's reserved `signal` tag type-checked. */
|
|
107
109
|
export type BeaconTags = Record<string, string> & {
|
|
108
110
|
signal?: BeaconSignal;
|
|
@@ -437,6 +439,17 @@ export type BeaconSignals = {
|
|
|
437
439
|
/** Cursor direction reversals inside the detection window. Default 8. */
|
|
438
440
|
thrashedCursorReversals?: number;
|
|
439
441
|
};
|
|
442
|
+
export type BeaconReleaseProbe = {
|
|
443
|
+
/** Same-origin endpoint returning `{ commit }` or `{ release }`. */
|
|
444
|
+
endpoint: string;
|
|
445
|
+
/** Visible-page polling interval. Default 60000ms. */
|
|
446
|
+
intervalMs?: number;
|
|
447
|
+
/** Called after the stale-release event has been flushed. */
|
|
448
|
+
onStale?: (input: {
|
|
449
|
+
currentRelease: string;
|
|
450
|
+
newestRelease: string;
|
|
451
|
+
}) => void;
|
|
452
|
+
};
|
|
440
453
|
export type BeaconNetworkFailure = {
|
|
441
454
|
at: number;
|
|
442
455
|
durationMs: number;
|
|
@@ -464,6 +477,10 @@ export type BeaconOptions = {
|
|
|
464
477
|
/** Ingest endpoint URL. Default `/ingest`. */
|
|
465
478
|
endpoint?: string;
|
|
466
479
|
release?: string;
|
|
480
|
+
/** Compare this page's embedded release with the currently served release.
|
|
481
|
+
* Once they differ, Beacon emits one stale-release event and suppresses
|
|
482
|
+
* ambient issue signals from the obsolete page. */
|
|
483
|
+
releaseProbe?: BeaconReleaseProbe;
|
|
467
484
|
environment?: string;
|
|
468
485
|
/** Auth key, sent as `x-beacon-key` (forces `fetch` over `sendBeacon`). */
|
|
469
486
|
key?: string;
|
package/dist/index.js
CHANGED
|
@@ -75,6 +75,7 @@ var BEACON_ATTRIBUTE = {
|
|
|
75
75
|
THEME: "data-beacon-theme"
|
|
76
76
|
};
|
|
77
77
|
var BEACON_TRACE_HEADER = "x-absolute-trace-id";
|
|
78
|
+
var BEACON_SDK_VERSION = "0.6.50";
|
|
78
79
|
var inBrowser = () => typeof window !== "undefined";
|
|
79
80
|
var newId = () => {
|
|
80
81
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
@@ -705,6 +706,7 @@ var defaultTransport = ({ url, body, key, useBeacon }) => {
|
|
|
705
706
|
var createBeacon = (options) => {
|
|
706
707
|
if (!inBrowser())
|
|
707
708
|
return noopBeacon;
|
|
709
|
+
const pageStartedAt = Date.now();
|
|
708
710
|
const endpoint = options.endpoint ?? "/ingest";
|
|
709
711
|
const maxBatch = options.maxBatch ?? 30;
|
|
710
712
|
const flushIntervalMs = options.flushIntervalMs ?? 5000;
|
|
@@ -715,6 +717,8 @@ var createBeacon = (options) => {
|
|
|
715
717
|
const transport = options.transport ?? defaultTransport;
|
|
716
718
|
const instrument = options.instrument ?? {};
|
|
717
719
|
const sessionId = newId();
|
|
720
|
+
const releaseProbeFetch = options.releaseProbe !== undefined && typeof window.fetch === "function" ? window.fetch.bind(window) : undefined;
|
|
721
|
+
let staleClientRelease = false;
|
|
718
722
|
const signals = options.signals === undefined || options.signals === false ? null : options.signals === true ? {} : options.signals;
|
|
719
723
|
const SLOW_RESPONSE_DEFAULT_MS = 8000;
|
|
720
724
|
const RAGE_COUNT_DEFAULT = 3;
|
|
@@ -989,7 +993,12 @@ var createBeacon = (options) => {
|
|
|
989
993
|
};
|
|
990
994
|
if (Object.keys(mergedTags).length > 0)
|
|
991
995
|
enriched.tags = mergedTags;
|
|
992
|
-
const extra = {
|
|
996
|
+
const extra = {
|
|
997
|
+
...event.extra,
|
|
998
|
+
pageStartedAt,
|
|
999
|
+
sdkVersion: BEACON_SDK_VERSION,
|
|
1000
|
+
sessionId
|
|
1001
|
+
};
|
|
993
1002
|
if (breadcrumbs.length > 0)
|
|
994
1003
|
extra.breadcrumbs = [...breadcrumbs];
|
|
995
1004
|
if (user !== undefined)
|
|
@@ -1051,6 +1060,8 @@ var createBeacon = (options) => {
|
|
|
1051
1060
|
push(event);
|
|
1052
1061
|
};
|
|
1053
1062
|
const emitSignal = (message, signalTags, traceId, extra, stackBoundary, fallbackFramesToDrop = 1, useDefaultFingerprint = false) => {
|
|
1063
|
+
if (staleClientRelease && signalTags.signal !== BEACON_SIGNAL.STALE_RELEASE)
|
|
1064
|
+
return;
|
|
1054
1065
|
const error = new Error(message);
|
|
1055
1066
|
const captureStackTrace = Error.captureStackTrace;
|
|
1056
1067
|
if (captureStackTrace !== undefined) {
|
|
@@ -1075,6 +1086,76 @@ var createBeacon = (options) => {
|
|
|
1075
1086
|
...extra !== undefined ? { extra } : {}
|
|
1076
1087
|
});
|
|
1077
1088
|
};
|
|
1089
|
+
if (options.releaseProbe !== undefined && releaseProbeFetch !== undefined && typeof options.release === "string" && options.release !== "") {
|
|
1090
|
+
const probe = options.releaseProbe;
|
|
1091
|
+
const embeddedRelease = options.release;
|
|
1092
|
+
let probeUrl;
|
|
1093
|
+
try {
|
|
1094
|
+
probeUrl = new URL(probe.endpoint, location.href);
|
|
1095
|
+
} catch {}
|
|
1096
|
+
if (probeUrl !== undefined && (location.origin === "null" || probeUrl.origin === location.origin)) {
|
|
1097
|
+
let checking = false;
|
|
1098
|
+
let reported = false;
|
|
1099
|
+
const checkServingRelease = async () => {
|
|
1100
|
+
if (checking || staleClientRelease)
|
|
1101
|
+
return;
|
|
1102
|
+
checking = true;
|
|
1103
|
+
try {
|
|
1104
|
+
const response = await releaseProbeFetch(probeUrl.href, {
|
|
1105
|
+
cache: "no-store",
|
|
1106
|
+
credentials: "same-origin"
|
|
1107
|
+
});
|
|
1108
|
+
if (!response.ok)
|
|
1109
|
+
return;
|
|
1110
|
+
const body = await response.json();
|
|
1111
|
+
if (body === null || typeof body !== "object")
|
|
1112
|
+
return;
|
|
1113
|
+
const candidate = "commit" in body && typeof body.commit === "string" ? body.commit : ("release" in body) && typeof body.release === "string" ? body.release : undefined;
|
|
1114
|
+
if (candidate === undefined || candidate === "" || candidate === embeddedRelease)
|
|
1115
|
+
return;
|
|
1116
|
+
staleClientRelease = true;
|
|
1117
|
+
for (let index = buffer.length - 1;index >= 0; index -= 1) {
|
|
1118
|
+
if (buffer[index]?.tags?.signal !== undefined) {
|
|
1119
|
+
buffer.splice(index, 1);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
if (reported)
|
|
1123
|
+
return;
|
|
1124
|
+
reported = true;
|
|
1125
|
+
emitSignal(`Stale release — this page is running an older build than the server — ${shortUrl(location.href)}`, {
|
|
1126
|
+
currentRelease: embeddedRelease,
|
|
1127
|
+
newestRelease: candidate,
|
|
1128
|
+
signal: BEACON_SIGNAL.STALE_RELEASE,
|
|
1129
|
+
staleDetection: "release-probe"
|
|
1130
|
+
});
|
|
1131
|
+
await flush(true);
|
|
1132
|
+
probe.onStale?.({
|
|
1133
|
+
currentRelease: embeddedRelease,
|
|
1134
|
+
newestRelease: candidate
|
|
1135
|
+
});
|
|
1136
|
+
} catch {} finally {
|
|
1137
|
+
checking = false;
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
const checkWhenVisible = () => {
|
|
1141
|
+
if (document.visibilityState === "visible") {
|
|
1142
|
+
checkServingRelease();
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
const interval = window.setInterval(checkWhenVisible, Math.max(1000, probe.intervalMs ?? 60000));
|
|
1146
|
+
const onVisibilityChange2 = () => checkWhenVisible();
|
|
1147
|
+
window.addEventListener("focus", checkWhenVisible);
|
|
1148
|
+
window.addEventListener("online", checkWhenVisible);
|
|
1149
|
+
document.addEventListener("visibilitychange", onVisibilityChange2);
|
|
1150
|
+
cleanups.push(() => {
|
|
1151
|
+
window.clearInterval(interval);
|
|
1152
|
+
window.removeEventListener("focus", checkWhenVisible);
|
|
1153
|
+
window.removeEventListener("online", checkWhenVisible);
|
|
1154
|
+
document.removeEventListener("visibilitychange", onVisibilityChange2);
|
|
1155
|
+
});
|
|
1156
|
+
checkServingRelease();
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1078
1159
|
if (signals !== null && signals.errorClicks !== false) {
|
|
1079
1160
|
const windowMs = signals.errorClickWindowMs ?? ERROR_CLICK_WINDOW_DEFAULT_MS;
|
|
1080
1161
|
reportErrorClick = (errorName) => {
|
|
@@ -3810,6 +3891,9 @@ var createBeacon = (options) => {
|
|
|
3810
3891
|
return registration;
|
|
3811
3892
|
} catch (error) {
|
|
3812
3893
|
const registrationError = toError(error);
|
|
3894
|
+
if (filterKnownNoise && isKnownBeaconNoise(registrationError)) {
|
|
3895
|
+
throw error;
|
|
3896
|
+
}
|
|
3813
3897
|
if (transientRegistrationErrors.has(registrationError.name)) {
|
|
3814
3898
|
const existing = pendingRegistrationFailures.get(endpointLabel);
|
|
3815
3899
|
if (existing !== undefined) {
|
|
@@ -4307,8 +4391,9 @@ export {
|
|
|
4307
4391
|
addBreadcrumb,
|
|
4308
4392
|
BEACON_TRACE_HEADER,
|
|
4309
4393
|
BEACON_SIGNAL,
|
|
4394
|
+
BEACON_SDK_VERSION,
|
|
4310
4395
|
BEACON_ATTRIBUTE
|
|
4311
4396
|
};
|
|
4312
4397
|
|
|
4313
|
-
//# debugId=
|
|
4398
|
+
//# debugId=429074B23CDFDDC864756E2164756E21
|
|
4314
4399
|
//# sourceMappingURL=index.js.map
|