cross-tab-worker-databus 0.20.89 → 0.20.91

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.
@@ -851,10 +851,12 @@ var WorkerClusterRuntime = class {
851
851
  const channel = this.channel;
852
852
  this.channel = null;
853
853
  this.handlers.onSuspend?.();
854
- if (typeof globalThis.setTimeout === "function") {
855
- globalThis.setTimeout(() => channel?.close(), 0);
856
- } else {
857
- channel?.close();
854
+ if (channel) {
855
+ if (typeof globalThis.setTimeout === "function") {
856
+ globalThis.setTimeout(() => channel.close(), 0);
857
+ } else {
858
+ channel.close();
859
+ }
858
860
  }
859
861
  }
860
862
  /** Update the worker's connection status and persist the change. */
@@ -2338,7 +2340,7 @@ var DedupManager = class {
2338
2340
  };
2339
2341
 
2340
2342
  // src/core/version.ts
2341
- var SDK_VERSION = true ? "0.20.89" : "";
2343
+ var SDK_VERSION = true ? "0.20.91" : "";
2342
2344
 
2343
2345
  // src/core/data-bus.ts
2344
2346
  var DEFAULT_REPLAY_MAX_PER_TOPIC = 100;
@@ -2520,6 +2522,7 @@ var CrossTabDataBus = class {
2520
2522
  // own broadcastEvent call, which always posts a DataBusMessage.
2521
2523
  onEvent: (eventType, payload, _sourceWorkerId, originTabId) => {
2522
2524
  if (eventType !== PUBLICATION_EVENT) return;
2525
+ if (typeof payload !== "object" || payload === null || typeof payload.topic !== "string") return;
2523
2526
  const incoming = payload;
2524
2527
  const message = incoming.originTabId !== void 0 ? incoming : originTabId !== void 0 ? { ...incoming, originTabId } : incoming;
2525
2528
  if (this.cluster.hasLocalSubscriber(message.topic)) this.dispatch(message);
@@ -3528,8 +3531,8 @@ var CentrifugeSession = class {
3528
3531
  // Route credential fetches back to the main thread, where the
3529
3532
  // application's credentialProvider lives (config must stay
3530
3533
  // structured-cloneable, so functions cannot cross the boundary).
3531
- getToken: () => this.requestToken("token"),
3532
- getChannelToken: (channel) => this.requestToken("channelToken", channel)
3534
+ getToken: () => this.requestToken("token", lifecycle),
3535
+ getChannelToken: (channel) => this.requestToken("channelToken", lifecycle, channel)
3533
3536
  } : config;
3534
3537
  const client = new import_centrifuge.Centrifuge(url, clientOptions);
3535
3538
  this.client = client;
@@ -3648,15 +3651,13 @@ var CentrifugeSession = class {
3648
3651
  /** Issue a credential request to the main thread and await the response.
3649
3652
  * Used as Centrifuge's `getToken` / `getChannelToken` when token bridging is
3650
3653
  * enabled; resolved or rejected by a matching TOKEN_RESPONSE / TOKEN_ERROR. */
3651
- requestToken(kind, channel) {
3652
- const lifecycle = this.lifecycle;
3654
+ requestToken(kind, lifecycle, channel) {
3655
+ if (this.lifecycle !== lifecycle) {
3656
+ return Promise.reject(new Error("Centrifuge client lifecycle has ended before the credential was requested."));
3657
+ }
3653
3658
  const requestId = this.nextRequestId;
3654
3659
  this.nextRequestId += 1;
3655
3660
  return new Promise((resolve, reject) => {
3656
- if (this.lifecycle !== lifecycle) {
3657
- reject(new Error("Centrifuge session stopped before the credential was requested."));
3658
- return;
3659
- }
3660
3661
  this.pendingTokenRequests.set(requestId, { resolve, reject });
3661
3662
  this.post({
3662
3663
  type: CENTRIFUGE_OUTPUT_TYPE.TOKEN_REQUEST,