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.
@@ -270,6 +270,7 @@ __export(src_exports, {
270
270
  textIsEmpty: () => textIsEmpty,
271
271
  textStartsWithCommand: () => textStartsWithCommand,
272
272
  timeLeftMs: () => timeLeftMs,
273
+ version: () => version,
273
274
  withCancellation: () => withCancellation,
274
275
  withoutConcurrency: () => withoutConcurrency
275
276
  });
@@ -1652,6 +1653,38 @@ var errorIsApiError = (error) => {
1652
1653
  };
1653
1654
  var isTokenExpiredError = (error) => errorIsApiError(error) && error.response?.data.code === chatCodes.TOKEN_EXPIRED;
1654
1655
 
1656
+ // src/version.ts
1657
+ var SEMVER_PATTERN = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+?)(?:\.(\d+))?)?(?:\+[0-9A-Za-z.-]+)?$/;
1658
+ var parseVersion = (raw) => {
1659
+ const input = raw || "0.0.0-development";
1660
+ const [, major = 0, minor = 0, patch = 0, prerelease = null, prereleaseNumber] = SEMVER_PATTERN.exec(input) ?? [];
1661
+ return Object.freeze({
1662
+ major: Number(major),
1663
+ minor: Number(minor),
1664
+ patch: Number(patch),
1665
+ prerelease,
1666
+ prereleaseNumber: prereleaseNumber ? Number(prereleaseNumber) : null,
1667
+ raw: input
1668
+ });
1669
+ };
1670
+ var readInjectedVersion = () => {
1671
+ try {
1672
+ return "10.1.0";
1673
+ } catch {
1674
+ return void 0;
1675
+ }
1676
+ };
1677
+ var readInjectedClientBundle = () => {
1678
+ try {
1679
+ return "browser-cjs";
1680
+ } catch {
1681
+ return void 0;
1682
+ }
1683
+ };
1684
+ var version = /* @__PURE__ */ parseVersion(
1685
+ /* @__PURE__ */ readInjectedVersion()
1686
+ );
1687
+
1655
1688
  // src/errors.ts
1656
1689
  var import_axios3 = require("axios");
1657
1690
 
@@ -15360,6 +15393,25 @@ var reflectReactionEvent = (client, {
15360
15393
  });
15361
15394
  };
15362
15395
 
15396
+ // src/utils/activeMemberCount.ts
15397
+ var getCarriedActiveMemberCount = ({
15398
+ next,
15399
+ previous
15400
+ }) => {
15401
+ const { active_member_count: nextActiveMemberCount } = next;
15402
+ const {
15403
+ active_member_count: previousActiveMemberCount,
15404
+ member_count: previousMemberCount
15405
+ } = previous ?? {};
15406
+ const hasOwnActiveMemberCount = typeof nextActiveMemberCount === "number";
15407
+ const hasPreviousActiveMemberCount = typeof previousActiveMemberCount === "number";
15408
+ if (hasOwnActiveMemberCount || !hasPreviousActiveMemberCount) return void 0;
15409
+ const memberCount = next.member_count ?? previousMemberCount;
15410
+ const delta = typeof next.member_count === "number" && typeof previousMemberCount === "number" ? next.member_count - previousMemberCount : 0;
15411
+ const shifted = Math.max(0, previousActiveMemberCount + delta);
15412
+ return typeof memberCount === "number" ? Math.min(shifted, memberCount) : shifted;
15413
+ };
15414
+
15363
15415
  // src/utils/abort.ts
15364
15416
  var abortError = (signal, message) => {
15365
15417
  const reason = signal.reason;
@@ -16609,33 +16661,48 @@ var Channel = class extends ChannelApi {
16609
16661
  this.state.partialNext({ offlineMode });
16610
16662
  }
16611
16663
  /**
16612
- * Reads `state.data`. Assigning publishes `data`, `memberCount` and `ownCapabilities` in one update.
16613
- * If the object omits `member_count` or `own_capabilities`, the last known values are carried onto
16614
- * a copy (the assigned object is not changed). Editing `channel.data.x` in place does not reach
16615
- * the state. `ownCapabilities` keeps its array while the capabilities stay the same (in any
16616
- * order), so a subscriber to it is notified only when they change.
16664
+ * Reads `state.data`. Assigning publishes `data`, `memberCount`, `activeMemberCount` and
16665
+ * `ownCapabilities` in one update. If the object omits `member_count`, `active_member_count` or
16666
+ * `own_capabilities`, the last known values are carried onto a copy (the assigned object is not
16667
+ * changed). A carried `active_member_count` moves with `member_count` (shifted by the change in
16668
+ * membership, clamped to `member_count`), since only Query Channels returns it; treat it as a
16669
+ * last-known estimate, refreshed on the next query — it can lag a (de)activation or an
16670
+ * already-deactivated member being added or removed. Editing
16671
+ * `channel.data.x` in place does not reach the state. `ownCapabilities` keeps its array while the
16672
+ * capabilities stay the same (in any order), so a subscriber to it is notified only when they
16673
+ * change.
16617
16674
  */
16618
16675
  get data() {
16619
16676
  return this.state.getLatestValue().data;
16620
16677
  }
16621
16678
  set data(next) {
16622
16679
  const {
16680
+ activeMemberCount: previousActiveMemberCount,
16623
16681
  data: previous,
16624
16682
  memberCount: previousMemberCount,
16625
16683
  ownCapabilities: previousOwnCapabilities
16626
16684
  } = this.state.getLatestValue();
16627
16685
  const carriedMemberCount = typeof next?.member_count !== "number" && typeof previous?.member_count === "number" ? previous.member_count : void 0;
16686
+ const carriedActiveMemberCount = next ? getCarriedActiveMemberCount({ next, previous }) : void 0;
16628
16687
  const carriedCapabilities = !Array.isArray(next?.own_capabilities) && Array.isArray(previous?.own_capabilities) ? [...previous.own_capabilities] : void 0;
16629
- const data = next && (carriedMemberCount !== void 0 || carriedCapabilities) ? {
16688
+ const carriesMemberCount = carriedMemberCount !== void 0;
16689
+ const carriesActiveMemberCount = carriedActiveMemberCount !== void 0;
16690
+ const carriesValues = carriesMemberCount || carriesActiveMemberCount || !!carriedCapabilities;
16691
+ const data = next && carriesValues ? {
16630
16692
  ...next,
16631
- ...carriedMemberCount !== void 0 && { member_count: carriedMemberCount },
16693
+ ...carriesMemberCount && { member_count: carriedMemberCount },
16694
+ ...carriesActiveMemberCount && {
16695
+ active_member_count: carriedActiveMemberCount
16696
+ },
16632
16697
  ...carriedCapabilities && { own_capabilities: carriedCapabilities }
16633
16698
  } : next;
16634
16699
  const memberCount = data?.member_count ?? carriedMemberCount;
16700
+ const activeMemberCount = data ? data.active_member_count : previousActiveMemberCount;
16635
16701
  const ownCapabilities = data?.own_capabilities ?? carriedCapabilities ?? [];
16636
16702
  const toKey = (capabilities) => [...capabilities].sort().join();
16637
16703
  const haveSameOwnCapabilities = toKey(previousOwnCapabilities) === toKey(ownCapabilities);
16638
16704
  this.state.partialNext({
16705
+ activeMemberCount,
16639
16706
  data,
16640
16707
  memberCount: memberCount ?? previousMemberCount,
16641
16708
  ownCapabilities: haveSameOwnCapabilities ? previousOwnCapabilities : [...ownCapabilities]
@@ -25323,11 +25390,11 @@ var StreamChat = class _StreamChat extends ChatApi {
25323
25390
  return this.userAgent;
25324
25391
  }
25325
25392
  if (!this.cachedUserAgent) {
25326
- const version = "10.0.1";
25393
+ const version2 = readInjectedVersion();
25327
25394
  const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
25328
25395
  const { name: appName, version: appVersion } = this.appIdentifier ?? {};
25329
25396
  const { os, model: deviceModel } = this.deviceIdentifier ?? {};
25330
- const head = sdkName ? `stream-chat-${sdkName}-v${sdkVersion}-llc-v${version}` : `stream-chat-js-v${version}-${this.node ? "node" : "browser"}`;
25397
+ const head = sdkName ? `stream-chat-${sdkName}-v${sdkVersion}-llc-v${version2}` : `stream-chat-js-v${version2}-${this.node ? "node" : "browser"}`;
25331
25398
  this.cachedUserAgent = [
25332
25399
  head,
25333
25400
  // Each only when a value is present.
@@ -25336,7 +25403,7 @@ var StreamChat = class _StreamChat extends ChatApi {
25336
25403
  app_version: appVersion,
25337
25404
  os,
25338
25405
  device_model: deviceModel,
25339
- client_bundle: "browser-cjs"
25406
+ client_bundle: readInjectedClientBundle()
25340
25407
  }).filter(([, value]) => value && value.length > 0).map(([key, value]) => `${key}=${value}`)
25341
25408
  ].join("|");
25342
25409
  }
@@ -25999,16 +26066,29 @@ var StreamChat = class _StreamChat extends ChatApi {
25999
26066
  };
26000
26067
  }
26001
26068
  /**
26002
- * Revokes a global ban.
26069
+ * Revokes a global ban, or a channel ban when `options.type` and `options.id` name a channel.
26070
+ *
26071
+ * Goes through V2 `client.moderation.unban()`. The one exception is
26072
+ * `remove_future_channels_ban`, which that endpoint does not accept, so a call with it set still
26073
+ * goes to v1 `DELETE /moderation/ban`. `shadow` is accepted for compatibility but ignored: the
26074
+ * server lifts whichever ban is in place, shadow or not, on both endpoints.
26003
26075
  *
26004
26076
  * @param targetUserId - The user to unban.
26005
26077
  * @param options - Unban options (optional).
26006
26078
  * @returns The server response.
26007
26079
  */
26008
26080
  async unbanUser(targetUserId, options) {
26009
- return await this.api.delete(this.baseURL + "/moderation/ban", {
26010
- target_user_id: targetUserId,
26011
- ...options
26081
+ const { id, remove_future_channels_ban, type } = options ?? {};
26082
+ const target_user_id = options?.target_user_id ?? targetUserId;
26083
+ if (remove_future_channels_ban) {
26084
+ return await this.api.delete(this.baseURL + "/moderation/ban", {
26085
+ ...options,
26086
+ target_user_id
26087
+ });
26088
+ }
26089
+ return await this.moderation.unban({
26090
+ target_user_id,
26091
+ channel_cid: type && id ? `${type}:${id}` : void 0
26012
26092
  });
26013
26093
  }
26014
26094
  async blockUser(blockedUserId, requestOptions) {
@@ -26030,6 +26110,16 @@ var StreamChat = class _StreamChat extends ChatApi {
26030
26110
  });
26031
26111
  return result;
26032
26112
  }
26113
+ async updatePushNotificationPreferences(...args) {
26114
+ const result = await super.updatePushNotificationPreferences(...args);
26115
+ const { user } = this;
26116
+ if (!user) return result;
26117
+ const updated = result.user_preferences[user.id];
26118
+ if (updated) {
26119
+ this.user = { ...user, push_preferences: updated };
26120
+ }
26121
+ return result;
26122
+ }
26033
26123
  async unblockUser(blockedUserId, requestOptions) {
26034
26124
  const result = await this.unblockUsers(
26035
26125
  {