stream-chat 10.0.1 → 10.1.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 +104 -14
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +105 -14
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +104 -14
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/channel.d.ts +10 -5
- package/dist/types/channel_state.d.ts +1 -0
- package/dist/types/client.d.ts +7 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/types.d.ts +2 -2
- package/dist/types/utils/activeMemberCount.d.ts +5 -0
- package/dist/types/version.d.ts +60 -0
- package/package.json +1 -1
- package/src/channel.ts +27 -7
- package/src/channel_state.ts +1 -0
- package/src/client.ts +42 -8
- package/src/index.ts +2 -0
- package/src/types.ts +2 -2
- package/src/utils/activeMemberCount.ts +30 -0
- package/src/version.ts +98 -0
package/dist/esm/index.mjs
CHANGED
|
@@ -1375,6 +1375,38 @@ var errorIsApiError = (error) => {
|
|
|
1375
1375
|
};
|
|
1376
1376
|
var isTokenExpiredError = (error) => errorIsApiError(error) && error.response?.data.code === chatCodes.TOKEN_EXPIRED;
|
|
1377
1377
|
|
|
1378
|
+
// src/version.ts
|
|
1379
|
+
var SEMVER_PATTERN = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+?)(?:\.(\d+))?)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
1380
|
+
var parseVersion = (raw) => {
|
|
1381
|
+
const input = raw || "0.0.0-development";
|
|
1382
|
+
const [, major = 0, minor = 0, patch = 0, prerelease = null, prereleaseNumber] = SEMVER_PATTERN.exec(input) ?? [];
|
|
1383
|
+
return Object.freeze({
|
|
1384
|
+
major: Number(major),
|
|
1385
|
+
minor: Number(minor),
|
|
1386
|
+
patch: Number(patch),
|
|
1387
|
+
prerelease,
|
|
1388
|
+
prereleaseNumber: prereleaseNumber ? Number(prereleaseNumber) : null,
|
|
1389
|
+
raw: input
|
|
1390
|
+
});
|
|
1391
|
+
};
|
|
1392
|
+
var readInjectedVersion = () => {
|
|
1393
|
+
try {
|
|
1394
|
+
return "10.1.0";
|
|
1395
|
+
} catch {
|
|
1396
|
+
return void 0;
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
var readInjectedClientBundle = () => {
|
|
1400
|
+
try {
|
|
1401
|
+
return "browser-esm";
|
|
1402
|
+
} catch {
|
|
1403
|
+
return void 0;
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1406
|
+
var version = /* @__PURE__ */ parseVersion(
|
|
1407
|
+
/* @__PURE__ */ readInjectedVersion()
|
|
1408
|
+
);
|
|
1409
|
+
|
|
1378
1410
|
// src/errors.ts
|
|
1379
1411
|
import { isAxiosError as isAxiosError2, isCancel } from "axios";
|
|
1380
1412
|
|
|
@@ -15083,6 +15115,25 @@ var reflectReactionEvent = (client, {
|
|
|
15083
15115
|
});
|
|
15084
15116
|
};
|
|
15085
15117
|
|
|
15118
|
+
// src/utils/activeMemberCount.ts
|
|
15119
|
+
var getCarriedActiveMemberCount = ({
|
|
15120
|
+
next,
|
|
15121
|
+
previous
|
|
15122
|
+
}) => {
|
|
15123
|
+
const { active_member_count: nextActiveMemberCount } = next;
|
|
15124
|
+
const {
|
|
15125
|
+
active_member_count: previousActiveMemberCount,
|
|
15126
|
+
member_count: previousMemberCount
|
|
15127
|
+
} = previous ?? {};
|
|
15128
|
+
const hasOwnActiveMemberCount = typeof nextActiveMemberCount === "number";
|
|
15129
|
+
const hasPreviousActiveMemberCount = typeof previousActiveMemberCount === "number";
|
|
15130
|
+
if (hasOwnActiveMemberCount || !hasPreviousActiveMemberCount) return void 0;
|
|
15131
|
+
const memberCount = next.member_count ?? previousMemberCount;
|
|
15132
|
+
const delta = typeof next.member_count === "number" && typeof previousMemberCount === "number" ? next.member_count - previousMemberCount : 0;
|
|
15133
|
+
const shifted = Math.max(0, previousActiveMemberCount + delta);
|
|
15134
|
+
return typeof memberCount === "number" ? Math.min(shifted, memberCount) : shifted;
|
|
15135
|
+
};
|
|
15136
|
+
|
|
15086
15137
|
// src/utils/abort.ts
|
|
15087
15138
|
var abortError = (signal, message) => {
|
|
15088
15139
|
const reason = signal.reason;
|
|
@@ -16332,33 +16383,48 @@ var Channel = class extends ChannelApi {
|
|
|
16332
16383
|
this.state.partialNext({ offlineMode });
|
|
16333
16384
|
}
|
|
16334
16385
|
/**
|
|
16335
|
-
* Reads `state.data`. Assigning publishes `data`, `memberCount
|
|
16336
|
-
* If the object omits `member_count` or
|
|
16337
|
-
* a copy (the assigned object is not
|
|
16338
|
-
*
|
|
16339
|
-
*
|
|
16386
|
+
* Reads `state.data`. Assigning publishes `data`, `memberCount`, `activeMemberCount` and
|
|
16387
|
+
* `ownCapabilities` in one update. If the object omits `member_count`, `active_member_count` or
|
|
16388
|
+
* `own_capabilities`, the last known values are carried onto a copy (the assigned object is not
|
|
16389
|
+
* changed). A carried `active_member_count` moves with `member_count` (shifted by the change in
|
|
16390
|
+
* membership, clamped to `member_count`), since only Query Channels returns it; treat it as a
|
|
16391
|
+
* last-known estimate, refreshed on the next query — it can lag a (de)activation or an
|
|
16392
|
+
* already-deactivated member being added or removed. Editing
|
|
16393
|
+
* `channel.data.x` in place does not reach the state. `ownCapabilities` keeps its array while the
|
|
16394
|
+
* capabilities stay the same (in any order), so a subscriber to it is notified only when they
|
|
16395
|
+
* change.
|
|
16340
16396
|
*/
|
|
16341
16397
|
get data() {
|
|
16342
16398
|
return this.state.getLatestValue().data;
|
|
16343
16399
|
}
|
|
16344
16400
|
set data(next) {
|
|
16345
16401
|
const {
|
|
16402
|
+
activeMemberCount: previousActiveMemberCount,
|
|
16346
16403
|
data: previous,
|
|
16347
16404
|
memberCount: previousMemberCount,
|
|
16348
16405
|
ownCapabilities: previousOwnCapabilities
|
|
16349
16406
|
} = this.state.getLatestValue();
|
|
16350
16407
|
const carriedMemberCount = typeof next?.member_count !== "number" && typeof previous?.member_count === "number" ? previous.member_count : void 0;
|
|
16408
|
+
const carriedActiveMemberCount = next ? getCarriedActiveMemberCount({ next, previous }) : void 0;
|
|
16351
16409
|
const carriedCapabilities = !Array.isArray(next?.own_capabilities) && Array.isArray(previous?.own_capabilities) ? [...previous.own_capabilities] : void 0;
|
|
16352
|
-
const
|
|
16410
|
+
const carriesMemberCount = carriedMemberCount !== void 0;
|
|
16411
|
+
const carriesActiveMemberCount = carriedActiveMemberCount !== void 0;
|
|
16412
|
+
const carriesValues = carriesMemberCount || carriesActiveMemberCount || !!carriedCapabilities;
|
|
16413
|
+
const data = next && carriesValues ? {
|
|
16353
16414
|
...next,
|
|
16354
|
-
...
|
|
16415
|
+
...carriesMemberCount && { member_count: carriedMemberCount },
|
|
16416
|
+
...carriesActiveMemberCount && {
|
|
16417
|
+
active_member_count: carriedActiveMemberCount
|
|
16418
|
+
},
|
|
16355
16419
|
...carriedCapabilities && { own_capabilities: carriedCapabilities }
|
|
16356
16420
|
} : next;
|
|
16357
16421
|
const memberCount = data?.member_count ?? carriedMemberCount;
|
|
16422
|
+
const activeMemberCount = data ? data.active_member_count : previousActiveMemberCount;
|
|
16358
16423
|
const ownCapabilities = data?.own_capabilities ?? carriedCapabilities ?? [];
|
|
16359
16424
|
const toKey = (capabilities) => [...capabilities].sort().join();
|
|
16360
16425
|
const haveSameOwnCapabilities = toKey(previousOwnCapabilities) === toKey(ownCapabilities);
|
|
16361
16426
|
this.state.partialNext({
|
|
16427
|
+
activeMemberCount,
|
|
16362
16428
|
data,
|
|
16363
16429
|
memberCount: memberCount ?? previousMemberCount,
|
|
16364
16430
|
ownCapabilities: haveSameOwnCapabilities ? previousOwnCapabilities : [...ownCapabilities]
|
|
@@ -25046,11 +25112,11 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
25046
25112
|
return this.userAgent;
|
|
25047
25113
|
}
|
|
25048
25114
|
if (!this.cachedUserAgent) {
|
|
25049
|
-
const
|
|
25115
|
+
const version2 = readInjectedVersion();
|
|
25050
25116
|
const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
|
|
25051
25117
|
const { name: appName, version: appVersion } = this.appIdentifier ?? {};
|
|
25052
25118
|
const { os, model: deviceModel } = this.deviceIdentifier ?? {};
|
|
25053
|
-
const head = sdkName ? `stream-chat-${sdkName}-v${sdkVersion}-llc-v${
|
|
25119
|
+
const head = sdkName ? `stream-chat-${sdkName}-v${sdkVersion}-llc-v${version2}` : `stream-chat-js-v${version2}-${this.node ? "node" : "browser"}`;
|
|
25054
25120
|
this.cachedUserAgent = [
|
|
25055
25121
|
head,
|
|
25056
25122
|
// Each only when a value is present.
|
|
@@ -25059,7 +25125,7 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
25059
25125
|
app_version: appVersion,
|
|
25060
25126
|
os,
|
|
25061
25127
|
device_model: deviceModel,
|
|
25062
|
-
client_bundle:
|
|
25128
|
+
client_bundle: readInjectedClientBundle()
|
|
25063
25129
|
}).filter(([, value]) => value && value.length > 0).map(([key, value]) => `${key}=${value}`)
|
|
25064
25130
|
].join("|");
|
|
25065
25131
|
}
|
|
@@ -25722,16 +25788,29 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
25722
25788
|
};
|
|
25723
25789
|
}
|
|
25724
25790
|
/**
|
|
25725
|
-
* Revokes a global ban.
|
|
25791
|
+
* Revokes a global ban, or a channel ban when `options.type` and `options.id` name a channel.
|
|
25792
|
+
*
|
|
25793
|
+
* Goes through V2 `client.moderation.unban()`. The one exception is
|
|
25794
|
+
* `remove_future_channels_ban`, which that endpoint does not accept, so a call with it set still
|
|
25795
|
+
* goes to v1 `DELETE /moderation/ban`. `shadow` is accepted for compatibility but ignored: the
|
|
25796
|
+
* server lifts whichever ban is in place, shadow or not, on both endpoints.
|
|
25726
25797
|
*
|
|
25727
25798
|
* @param targetUserId - The user to unban.
|
|
25728
25799
|
* @param options - Unban options (optional).
|
|
25729
25800
|
* @returns The server response.
|
|
25730
25801
|
*/
|
|
25731
25802
|
async unbanUser(targetUserId, options) {
|
|
25732
|
-
|
|
25733
|
-
|
|
25734
|
-
|
|
25803
|
+
const { id, remove_future_channels_ban, type } = options ?? {};
|
|
25804
|
+
const target_user_id = options?.target_user_id ?? targetUserId;
|
|
25805
|
+
if (remove_future_channels_ban) {
|
|
25806
|
+
return await this.api.delete(this.baseURL + "/moderation/ban", {
|
|
25807
|
+
...options,
|
|
25808
|
+
target_user_id
|
|
25809
|
+
});
|
|
25810
|
+
}
|
|
25811
|
+
return await this.moderation.unban({
|
|
25812
|
+
target_user_id,
|
|
25813
|
+
channel_cid: type && id ? `${type}:${id}` : void 0
|
|
25735
25814
|
});
|
|
25736
25815
|
}
|
|
25737
25816
|
async blockUser(blockedUserId, requestOptions) {
|
|
@@ -25753,6 +25832,16 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
25753
25832
|
});
|
|
25754
25833
|
return result;
|
|
25755
25834
|
}
|
|
25835
|
+
async updatePushNotificationPreferences(...args) {
|
|
25836
|
+
const result = await super.updatePushNotificationPreferences(...args);
|
|
25837
|
+
const { user } = this;
|
|
25838
|
+
if (!user) return result;
|
|
25839
|
+
const updated = result.user_preferences[user.id];
|
|
25840
|
+
if (updated) {
|
|
25841
|
+
this.user = { ...user, push_preferences: updated };
|
|
25842
|
+
}
|
|
25843
|
+
return result;
|
|
25844
|
+
}
|
|
25756
25845
|
async unblockUser(blockedUserId, requestOptions) {
|
|
25757
25846
|
const result = await this.unblockUsers(
|
|
25758
25847
|
{
|
|
@@ -28107,6 +28196,7 @@ export {
|
|
|
28107
28196
|
textIsEmpty,
|
|
28108
28197
|
textStartsWithCommand,
|
|
28109
28198
|
timeLeftMs,
|
|
28199
|
+
version,
|
|
28110
28200
|
withCancellation,
|
|
28111
28201
|
withoutConcurrency
|
|
28112
28202
|
};
|