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.
- package/dist/cjs/index.browser.js +72 -20
- package/dist/cjs/index.browser.js.map +2 -2
- package/dist/cjs/index.node.js +72 -20
- package/dist/cjs/index.node.js.map +2 -2
- package/dist/esm/index.mjs +72 -20
- package/dist/esm/index.mjs.map +2 -2
- package/dist/types/channel_batch_updater.d.ts +9 -2
- package/dist/types/client.d.ts +17 -0
- package/dist/types/types.d.ts +33 -0
- package/package.json +1 -1
- package/src/channel_batch_updater.ts +28 -2
- package/src/client.ts +84 -10
- package/src/types.ts +37 -0
|
@@ -382,6 +382,7 @@ var Campaign = class {
|
|
|
382
382
|
};
|
|
383
383
|
|
|
384
384
|
// src/channel_batch_updater.ts
|
|
385
|
+
var isChannelBatchDataUpdateOptions = (update) => "data" in update || "custom_set" in update || "custom_unset" in update;
|
|
385
386
|
var ChannelBatchUpdater = class {
|
|
386
387
|
constructor(client) {
|
|
387
388
|
this.client = client;
|
|
@@ -520,19 +521,14 @@ var ChannelBatchUpdater = class {
|
|
|
520
521
|
filter
|
|
521
522
|
});
|
|
522
523
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
* updateData - Update data on channels matching the filter
|
|
526
|
-
*
|
|
527
|
-
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
|
|
528
|
-
* @param {BatchChannelDataUpdate} data Data to update
|
|
529
|
-
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
|
|
530
|
-
*/
|
|
531
|
-
async updateData(filter, data) {
|
|
524
|
+
async updateData(filter, update) {
|
|
525
|
+
const { data, custom_set, custom_unset } = isChannelBatchDataUpdateOptions(update) ? update : { data: update };
|
|
532
526
|
return await this.client.updateChannelsBatch({
|
|
533
527
|
operation: "updateData",
|
|
534
528
|
filter,
|
|
535
|
-
data
|
|
529
|
+
...data && { data },
|
|
530
|
+
...custom_set && { custom_set },
|
|
531
|
+
...custom_unset && { custom_unset }
|
|
536
532
|
});
|
|
537
533
|
}
|
|
538
534
|
};
|
|
@@ -14587,6 +14583,8 @@ var StreamChat = class _StreamChat {
|
|
|
14587
14583
|
* The main use case for SDKs who do independent state recovery for channels.
|
|
14588
14584
|
*/
|
|
14589
14585
|
this.preventThreadCleanup = false;
|
|
14586
|
+
this._wsPromiseSettled = true;
|
|
14587
|
+
this._wsConnectId = 0;
|
|
14590
14588
|
this.nextRequestAbortController = null;
|
|
14591
14589
|
/**
|
|
14592
14590
|
* @private
|
|
@@ -14632,17 +14630,20 @@ var StreamChat = class _StreamChat {
|
|
|
14632
14630
|
const setTokenPromise = this._setToken(user, userTokenOrProvider);
|
|
14633
14631
|
this._setUser(user);
|
|
14634
14632
|
const wsPromise = this.openConnection();
|
|
14635
|
-
|
|
14633
|
+
const setUserPromise = Promise.all([setTokenPromise, wsPromise]).then(
|
|
14636
14634
|
(result) => result[1]
|
|
14637
14635
|
// We only return connection promise;
|
|
14638
14636
|
);
|
|
14637
|
+
this.setUserPromise = setUserPromise;
|
|
14639
14638
|
try {
|
|
14640
|
-
return await
|
|
14639
|
+
return await setUserPromise;
|
|
14641
14640
|
} catch (err) {
|
|
14642
|
-
if (this.
|
|
14643
|
-
this.
|
|
14644
|
-
|
|
14645
|
-
|
|
14641
|
+
if (this.setUserPromise === setUserPromise && this.userID === user.id) {
|
|
14642
|
+
if (this.persistUserOnConnectionFailure) {
|
|
14643
|
+
this.closeConnection();
|
|
14644
|
+
} else {
|
|
14645
|
+
this.disconnectUser();
|
|
14646
|
+
}
|
|
14646
14647
|
}
|
|
14647
14648
|
throw err;
|
|
14648
14649
|
}
|
|
@@ -14738,9 +14739,50 @@ var StreamChat = class _StreamChat {
|
|
|
14738
14739
|
return;
|
|
14739
14740
|
}
|
|
14740
14741
|
this.clientID = `${this.userID}--${randomId()}`;
|
|
14741
|
-
|
|
14742
|
+
const wsPromise = this._bindWsPromise(this.connect());
|
|
14742
14743
|
this._startCleaning();
|
|
14743
|
-
return
|
|
14744
|
+
return wsPromise;
|
|
14745
|
+
};
|
|
14746
|
+
/**
|
|
14747
|
+
* Rejects the shared `wsPromise`, invalidates any in-flight connect attempt
|
|
14748
|
+
*/
|
|
14749
|
+
this._rejectPendingWsPromise = (reason) => {
|
|
14750
|
+
if (!this._wsPromiseSettled) {
|
|
14751
|
+
this._wsConnectId += 1;
|
|
14752
|
+
this._wsPromiseSettled = true;
|
|
14753
|
+
this.wsPromise?.catch(() => {
|
|
14754
|
+
});
|
|
14755
|
+
this._rejectWsPromise?.(reason);
|
|
14756
|
+
}
|
|
14757
|
+
};
|
|
14758
|
+
/**
|
|
14759
|
+
* Keep a single pending `wsPromise` across close/reopen so callers that already
|
|
14760
|
+
* `await this.wsPromise` are not stranded when `openConnection` starts a new connect.
|
|
14761
|
+
*/
|
|
14762
|
+
this._bindWsPromise = (connectPromise) => {
|
|
14763
|
+
const connectId = ++this._wsConnectId;
|
|
14764
|
+
let pending = this.wsPromise;
|
|
14765
|
+
if (this._wsPromiseSettled || !pending) {
|
|
14766
|
+
this._wsPromiseSettled = false;
|
|
14767
|
+
pending = new Promise((resolve, reject) => {
|
|
14768
|
+
this._resolveWsPromise = resolve;
|
|
14769
|
+
this._rejectWsPromise = reject;
|
|
14770
|
+
});
|
|
14771
|
+
this.wsPromise = pending;
|
|
14772
|
+
}
|
|
14773
|
+
connectPromise.then(
|
|
14774
|
+
(value) => {
|
|
14775
|
+
if (connectId !== this._wsConnectId) return;
|
|
14776
|
+
this._wsPromiseSettled = true;
|
|
14777
|
+
this._resolveWsPromise?.(value);
|
|
14778
|
+
},
|
|
14779
|
+
(error) => {
|
|
14780
|
+
if (connectId !== this._wsConnectId) return;
|
|
14781
|
+
this._wsPromiseSettled = true;
|
|
14782
|
+
this._rejectWsPromise?.(error);
|
|
14783
|
+
}
|
|
14784
|
+
);
|
|
14785
|
+
return pending;
|
|
14744
14786
|
};
|
|
14745
14787
|
/**
|
|
14746
14788
|
* @deprecated Please use client.openConnction instead.
|
|
@@ -14774,6 +14816,10 @@ var StreamChat = class _StreamChat {
|
|
|
14774
14816
|
delete this._user;
|
|
14775
14817
|
delete this.userID;
|
|
14776
14818
|
this.anonymous = false;
|
|
14819
|
+
this._rejectPendingWsPromise(
|
|
14820
|
+
new Error("Connection was closed because disconnectUser() was called")
|
|
14821
|
+
);
|
|
14822
|
+
this.wsPromise = null;
|
|
14777
14823
|
const closePromise = this.closeConnection(timeout);
|
|
14778
14824
|
for (const channel of Object.values(this.activeChannels)) {
|
|
14779
14825
|
channel._disconnect();
|
|
@@ -15044,7 +15090,9 @@ var StreamChat = class _StreamChat {
|
|
|
15044
15090
|
type: "connection.recovered"
|
|
15045
15091
|
});
|
|
15046
15092
|
}
|
|
15047
|
-
this.
|
|
15093
|
+
if (this._wsPromiseSettled) {
|
|
15094
|
+
this.wsPromise = Promise.resolve();
|
|
15095
|
+
}
|
|
15048
15096
|
this.setUserPromise = Promise.resolve();
|
|
15049
15097
|
};
|
|
15050
15098
|
/**
|
|
@@ -15162,7 +15210,7 @@ var StreamChat = class _StreamChat {
|
|
|
15162
15210
|
return this.userAgent;
|
|
15163
15211
|
}
|
|
15164
15212
|
if (!this.cachedUserAgent) {
|
|
15165
|
-
const version = "9.
|
|
15213
|
+
const version = "9.53.0";
|
|
15166
15214
|
const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
|
|
15167
15215
|
const { name: appName, version: appVersion } = this.appIdentifier ?? {};
|
|
15168
15216
|
const { os, model: deviceModel } = this.deviceIdentifier ?? {};
|
|
@@ -18404,6 +18452,10 @@ var StreamChat = class _StreamChat {
|
|
|
18404
18452
|
/**
|
|
18405
18453
|
* Update Channels Batch
|
|
18406
18454
|
*
|
|
18455
|
+
* For the `updateData` operation, `data.custom` replaces the channel's whole
|
|
18456
|
+
* custom object, while the root-level `custom_set` / `custom_unset` patch
|
|
18457
|
+
* individual keys and leave the rest untouched.
|
|
18458
|
+
*
|
|
18407
18459
|
* @param {UpdateChannelsBatchOptions} payload for updating channels in batch
|
|
18408
18460
|
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
|
|
18409
18461
|
*/
|