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.
@@ -159,6 +159,7 @@ var Campaign = class {
159
159
  };
160
160
 
161
161
  // src/channel_batch_updater.ts
162
+ var isChannelBatchDataUpdateOptions = (update) => "data" in update || "custom_set" in update || "custom_unset" in update;
162
163
  var ChannelBatchUpdater = class {
163
164
  constructor(client) {
164
165
  this.client = client;
@@ -297,19 +298,14 @@ var ChannelBatchUpdater = class {
297
298
  filter
298
299
  });
299
300
  }
300
- // Data operations
301
- /**
302
- * updateData - Update data on channels matching the filter
303
- *
304
- * @param {UpdateChannelsBatchFilters} filter Filter to select channels
305
- * @param {BatchChannelDataUpdate} data Data to update
306
- * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
307
- */
308
- async updateData(filter, data) {
301
+ async updateData(filter, update) {
302
+ const { data, custom_set, custom_unset } = isChannelBatchDataUpdateOptions(update) ? update : { data: update };
309
303
  return await this.client.updateChannelsBatch({
310
304
  operation: "updateData",
311
305
  filter,
312
- data
306
+ ...data && { data },
307
+ ...custom_set && { custom_set },
308
+ ...custom_unset && { custom_unset }
313
309
  });
314
310
  }
315
311
  };
@@ -14364,6 +14360,8 @@ var StreamChat = class _StreamChat {
14364
14360
  * The main use case for SDKs who do independent state recovery for channels.
14365
14361
  */
14366
14362
  this.preventThreadCleanup = false;
14363
+ this._wsPromiseSettled = true;
14364
+ this._wsConnectId = 0;
14367
14365
  this.nextRequestAbortController = null;
14368
14366
  /**
14369
14367
  * @private
@@ -14409,17 +14407,20 @@ var StreamChat = class _StreamChat {
14409
14407
  const setTokenPromise = this._setToken(user, userTokenOrProvider);
14410
14408
  this._setUser(user);
14411
14409
  const wsPromise = this.openConnection();
14412
- this.setUserPromise = Promise.all([setTokenPromise, wsPromise]).then(
14410
+ const setUserPromise = Promise.all([setTokenPromise, wsPromise]).then(
14413
14411
  (result) => result[1]
14414
14412
  // We only return connection promise;
14415
14413
  );
14414
+ this.setUserPromise = setUserPromise;
14416
14415
  try {
14417
- return await this.setUserPromise;
14416
+ return await setUserPromise;
14418
14417
  } catch (err) {
14419
- if (this.persistUserOnConnectionFailure) {
14420
- this.closeConnection();
14421
- } else {
14422
- this.disconnectUser();
14418
+ if (this.setUserPromise === setUserPromise && this.userID === user.id) {
14419
+ if (this.persistUserOnConnectionFailure) {
14420
+ this.closeConnection();
14421
+ } else {
14422
+ this.disconnectUser();
14423
+ }
14423
14424
  }
14424
14425
  throw err;
14425
14426
  }
@@ -14515,9 +14516,50 @@ var StreamChat = class _StreamChat {
14515
14516
  return;
14516
14517
  }
14517
14518
  this.clientID = `${this.userID}--${randomId()}`;
14518
- this.wsPromise = this.connect();
14519
+ const wsPromise = this._bindWsPromise(this.connect());
14519
14520
  this._startCleaning();
14520
- return this.wsPromise;
14521
+ return wsPromise;
14522
+ };
14523
+ /**
14524
+ * Rejects the shared `wsPromise`, invalidates any in-flight connect attempt
14525
+ */
14526
+ this._rejectPendingWsPromise = (reason) => {
14527
+ if (!this._wsPromiseSettled) {
14528
+ this._wsConnectId += 1;
14529
+ this._wsPromiseSettled = true;
14530
+ this.wsPromise?.catch(() => {
14531
+ });
14532
+ this._rejectWsPromise?.(reason);
14533
+ }
14534
+ };
14535
+ /**
14536
+ * Keep a single pending `wsPromise` across close/reopen so callers that already
14537
+ * `await this.wsPromise` are not stranded when `openConnection` starts a new connect.
14538
+ */
14539
+ this._bindWsPromise = (connectPromise) => {
14540
+ const connectId = ++this._wsConnectId;
14541
+ let pending = this.wsPromise;
14542
+ if (this._wsPromiseSettled || !pending) {
14543
+ this._wsPromiseSettled = false;
14544
+ pending = new Promise((resolve, reject) => {
14545
+ this._resolveWsPromise = resolve;
14546
+ this._rejectWsPromise = reject;
14547
+ });
14548
+ this.wsPromise = pending;
14549
+ }
14550
+ connectPromise.then(
14551
+ (value) => {
14552
+ if (connectId !== this._wsConnectId) return;
14553
+ this._wsPromiseSettled = true;
14554
+ this._resolveWsPromise?.(value);
14555
+ },
14556
+ (error) => {
14557
+ if (connectId !== this._wsConnectId) return;
14558
+ this._wsPromiseSettled = true;
14559
+ this._rejectWsPromise?.(error);
14560
+ }
14561
+ );
14562
+ return pending;
14521
14563
  };
14522
14564
  /**
14523
14565
  * @deprecated Please use client.openConnction instead.
@@ -14551,6 +14593,10 @@ var StreamChat = class _StreamChat {
14551
14593
  delete this._user;
14552
14594
  delete this.userID;
14553
14595
  this.anonymous = false;
14596
+ this._rejectPendingWsPromise(
14597
+ new Error("Connection was closed because disconnectUser() was called")
14598
+ );
14599
+ this.wsPromise = null;
14554
14600
  const closePromise = this.closeConnection(timeout);
14555
14601
  for (const channel of Object.values(this.activeChannels)) {
14556
14602
  channel._disconnect();
@@ -14821,7 +14867,9 @@ var StreamChat = class _StreamChat {
14821
14867
  type: "connection.recovered"
14822
14868
  });
14823
14869
  }
14824
- this.wsPromise = Promise.resolve();
14870
+ if (this._wsPromiseSettled) {
14871
+ this.wsPromise = Promise.resolve();
14872
+ }
14825
14873
  this.setUserPromise = Promise.resolve();
14826
14874
  };
14827
14875
  /**
@@ -14939,7 +14987,7 @@ var StreamChat = class _StreamChat {
14939
14987
  return this.userAgent;
14940
14988
  }
14941
14989
  if (!this.cachedUserAgent) {
14942
- const version = "9.52.1";
14990
+ const version = "9.53.0";
14943
14991
  const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
14944
14992
  const { name: appName, version: appVersion } = this.appIdentifier ?? {};
14945
14993
  const { os, model: deviceModel } = this.deviceIdentifier ?? {};
@@ -18181,6 +18229,10 @@ var StreamChat = class _StreamChat {
18181
18229
  /**
18182
18230
  * Update Channels Batch
18183
18231
  *
18232
+ * For the `updateData` operation, `data.custom` replaces the channel's whole
18233
+ * custom object, while the root-level `custom_set` / `custom_unset` patch
18234
+ * individual keys and leave the rest untouched.
18235
+ *
18184
18236
  * @param {UpdateChannelsBatchOptions} payload for updating channels in batch
18185
18237
  * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
18186
18238
  */