stream-chat 9.52.1 → 9.53.0

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.
@@ -351,6 +351,7 @@ var Campaign = class {
351
351
  };
352
352
 
353
353
  // src/channel_batch_updater.ts
354
+ var isChannelBatchDataUpdateOptions = (update) => "data" in update || "custom_set" in update || "custom_unset" in update;
354
355
  var ChannelBatchUpdater = class {
355
356
  constructor(client) {
356
357
  this.client = client;
@@ -489,19 +490,14 @@ var ChannelBatchUpdater = class {
489
490
  filter
490
491
  });
491
492
  }
492
- // Data operations
493
- /**
494
- * updateData - Update data on channels matching the filter
495
- *
496
- * @param {UpdateChannelsBatchFilters} filter Filter to select channels
497
- * @param {BatchChannelDataUpdate} data Data to update
498
- * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
499
- */
500
- async updateData(filter, data) {
493
+ async updateData(filter, update) {
494
+ const { data, custom_set, custom_unset } = isChannelBatchDataUpdateOptions(update) ? update : { data: update };
501
495
  return await this.client.updateChannelsBatch({
502
496
  operation: "updateData",
503
497
  filter,
504
- data
498
+ ...data && { data },
499
+ ...custom_set && { custom_set },
500
+ ...custom_unset && { custom_unset }
505
501
  });
506
502
  }
507
503
  };
@@ -14556,6 +14552,8 @@ var StreamChat = class _StreamChat {
14556
14552
  * The main use case for SDKs who do independent state recovery for channels.
14557
14553
  */
14558
14554
  this.preventThreadCleanup = false;
14555
+ this._wsPromiseSettled = true;
14556
+ this._wsConnectId = 0;
14559
14557
  this.nextRequestAbortController = null;
14560
14558
  /**
14561
14559
  * @private
@@ -14601,17 +14599,20 @@ var StreamChat = class _StreamChat {
14601
14599
  const setTokenPromise = this._setToken(user, userTokenOrProvider);
14602
14600
  this._setUser(user);
14603
14601
  const wsPromise = this.openConnection();
14604
- this.setUserPromise = Promise.all([setTokenPromise, wsPromise]).then(
14602
+ const setUserPromise = Promise.all([setTokenPromise, wsPromise]).then(
14605
14603
  (result) => result[1]
14606
14604
  // We only return connection promise;
14607
14605
  );
14606
+ this.setUserPromise = setUserPromise;
14608
14607
  try {
14609
- return await this.setUserPromise;
14608
+ return await setUserPromise;
14610
14609
  } catch (err) {
14611
- if (this.persistUserOnConnectionFailure) {
14612
- this.closeConnection();
14613
- } else {
14614
- this.disconnectUser();
14610
+ if (this.setUserPromise === setUserPromise && this.userID === user.id) {
14611
+ if (this.persistUserOnConnectionFailure) {
14612
+ this.closeConnection();
14613
+ } else {
14614
+ this.disconnectUser();
14615
+ }
14615
14616
  }
14616
14617
  throw err;
14617
14618
  }
@@ -14707,9 +14708,50 @@ var StreamChat = class _StreamChat {
14707
14708
  return;
14708
14709
  }
14709
14710
  this.clientID = `${this.userID}--${randomId()}`;
14710
- this.wsPromise = this.connect();
14711
+ const wsPromise = this._bindWsPromise(this.connect());
14711
14712
  this._startCleaning();
14712
- return this.wsPromise;
14713
+ return wsPromise;
14714
+ };
14715
+ /**
14716
+ * Rejects the shared `wsPromise`, invalidates any in-flight connect attempt
14717
+ */
14718
+ this._rejectPendingWsPromise = (reason) => {
14719
+ if (!this._wsPromiseSettled) {
14720
+ this._wsConnectId += 1;
14721
+ this._wsPromiseSettled = true;
14722
+ this.wsPromise?.catch(() => {
14723
+ });
14724
+ this._rejectWsPromise?.(reason);
14725
+ }
14726
+ };
14727
+ /**
14728
+ * Keep a single pending `wsPromise` across close/reopen so callers that already
14729
+ * `await this.wsPromise` are not stranded when `openConnection` starts a new connect.
14730
+ */
14731
+ this._bindWsPromise = (connectPromise) => {
14732
+ const connectId = ++this._wsConnectId;
14733
+ let pending = this.wsPromise;
14734
+ if (this._wsPromiseSettled || !pending) {
14735
+ this._wsPromiseSettled = false;
14736
+ pending = new Promise((resolve, reject) => {
14737
+ this._resolveWsPromise = resolve;
14738
+ this._rejectWsPromise = reject;
14739
+ });
14740
+ this.wsPromise = pending;
14741
+ }
14742
+ connectPromise.then(
14743
+ (value) => {
14744
+ if (connectId !== this._wsConnectId) return;
14745
+ this._wsPromiseSettled = true;
14746
+ this._resolveWsPromise?.(value);
14747
+ },
14748
+ (error) => {
14749
+ if (connectId !== this._wsConnectId) return;
14750
+ this._wsPromiseSettled = true;
14751
+ this._rejectWsPromise?.(error);
14752
+ }
14753
+ );
14754
+ return pending;
14713
14755
  };
14714
14756
  /**
14715
14757
  * @deprecated Please use client.openConnction instead.
@@ -14743,6 +14785,10 @@ var StreamChat = class _StreamChat {
14743
14785
  delete this._user;
14744
14786
  delete this.userID;
14745
14787
  this.anonymous = false;
14788
+ this._rejectPendingWsPromise(
14789
+ new Error("Connection was closed because disconnectUser() was called")
14790
+ );
14791
+ this.wsPromise = null;
14746
14792
  const closePromise = this.closeConnection(timeout);
14747
14793
  for (const channel of Object.values(this.activeChannels)) {
14748
14794
  channel._disconnect();
@@ -15013,7 +15059,9 @@ var StreamChat = class _StreamChat {
15013
15059
  type: "connection.recovered"
15014
15060
  });
15015
15061
  }
15016
- this.wsPromise = Promise.resolve();
15062
+ if (this._wsPromiseSettled) {
15063
+ this.wsPromise = Promise.resolve();
15064
+ }
15017
15065
  this.setUserPromise = Promise.resolve();
15018
15066
  };
15019
15067
  /**
@@ -15131,7 +15179,7 @@ var StreamChat = class _StreamChat {
15131
15179
  return this.userAgent;
15132
15180
  }
15133
15181
  if (!this.cachedUserAgent) {
15134
- const version = "9.52.1";
15182
+ const version = "9.53.0";
15135
15183
  const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
15136
15184
  const { name: appName, version: appVersion } = this.appIdentifier ?? {};
15137
15185
  const { os, model: deviceModel } = this.deviceIdentifier ?? {};
@@ -18373,6 +18421,10 @@ var StreamChat = class _StreamChat {
18373
18421
  /**
18374
18422
  * Update Channels Batch
18375
18423
  *
18424
+ * For the `updateData` operation, `data.custom` replaces the channel's whole
18425
+ * custom object, while the root-level `custom_set` / `custom_unset` patch
18426
+ * individual keys and leave the rest untouched.
18427
+ *
18376
18428
  * @param {UpdateChannelsBatchOptions} payload for updating channels in batch
18377
18429
  * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
18378
18430
  */