@absolutejs/beacon 0.6.35 → 0.6.36

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/dist/index.d.ts CHANGED
@@ -351,6 +351,11 @@ export type BeaconSignals = {
351
351
  /** Abnormal WebSocket closes (`wasClean: false` or non-normal codes).
352
352
  * Default true. */
353
353
  socketAbnormalCloses?: boolean;
354
+ /** Endpoints whose client explicitly owns reconnect/resume. An isolated
355
+ * abnormal close is suppressed for matching URLs, while every close still
356
+ * counts toward socket-flapping detection. String patterns are URL/path
357
+ * prefixes; RegExp patterns match the full URL. */
358
+ recoverableSockets?: Array<RegExp | string>;
354
359
  /** WebSocket connect/close cycles to one URL tripping a flap report.
355
360
  * Default true. */
356
361
  socketFlapping?: boolean;
package/dist/index.js CHANGED
@@ -3508,10 +3508,12 @@ var createBeacon = (options) => {
3508
3508
  const closesByUrl = new Map;
3509
3509
  const reportedSockets = new Set;
3510
3510
  const reportedAbnormalCloses = new Set;
3511
+ const recoverableSocket = (url) => (signals.recoverableSockets ?? []).some((pattern) => typeof pattern === "string" ? url.startsWith(pattern) || shortUrl(url).startsWith(pattern) : pattern.test(url));
3511
3512
  const wrappedWebSocket = new Proxy(OriginalWebSocket, {
3512
3513
  construct(target, args) {
3513
3514
  const socket = Reflect.construct(target, args);
3514
- const label = shortUrl(String(args[0]));
3515
+ const socketUrl = String(args[0]);
3516
+ const label = shortUrl(socketUrl);
3515
3517
  const socketLifecycleGeneration = pageLifecycleGeneration;
3516
3518
  let applicationClose = false;
3517
3519
  const originalClose = socket.close.bind(socket);
@@ -3523,7 +3525,7 @@ var createBeacon = (options) => {
3523
3525
  const restoredLifecycleClose = pageRestoredAt !== undefined && socketLifecycleGeneration < pageLifecycleGeneration && Date.now() - pageRestoredAt <= RESTORED_SOCKET_CLOSE_GRACE_MS;
3524
3526
  if (pageLifecycleEnding || applicationClose || restoredLifecycleClose)
3525
3527
  return;
3526
- if (signals.socketAbnormalCloses !== false && typeof CloseEvent !== "undefined" && event instanceof CloseEvent && !event.wasClean) {
3528
+ if (signals.socketAbnormalCloses !== false && typeof CloseEvent !== "undefined" && event instanceof CloseEvent && !event.wasClean && !recoverableSocket(socketUrl)) {
3527
3529
  const abnormalKey = `${label}|${event.code}`;
3528
3530
  if (!reportedAbnormalCloses.has(abnormalKey)) {
3529
3531
  reportedAbnormalCloses.add(abnormalKey);
@@ -4079,5 +4081,5 @@ export {
4079
4081
  BEACON_ATTRIBUTE
4080
4082
  };
4081
4083
 
4082
- //# debugId=C8724C190000F91564756E2164756E21
4084
+ //# debugId=76AB7EECBF8D441B64756E2164756E21
4083
4085
  //# sourceMappingURL=index.js.map