stream-chat 9.55.0 → 9.56.1

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.
@@ -52,6 +52,12 @@ var require_zlib = __commonJS({
52
52
  }
53
53
  });
54
54
 
55
+ // (disabled):buffer
56
+ var require_buffer = __commonJS({
57
+ "(disabled):buffer"() {
58
+ }
59
+ });
60
+
55
61
  // src/base64.ts
56
62
  import { fromByteArray } from "base64-js";
57
63
  function isString(arrayOrString) {
@@ -9083,9 +9089,9 @@ var MessageDeliveryReporter = class _MessageDeliveryReporter {
9083
9089
  if (!_MessageDeliveryReporter.hasPermissionToReportDeliveryFor(collection)) return;
9084
9090
  const candidate = this.getNextDeliveryReportCandidate(collection);
9085
9091
  if (!candidate?.key) return;
9086
- const buffer = this.markDeliveredRequestInFlight ? this.nextDeliveryReportCandidates : this.deliveryReportCandidates;
9087
- if (candidate.id === null) buffer.delete(candidate.key);
9088
- else buffer.set(candidate.key, candidate.id);
9092
+ const buffer2 = this.markDeliveredRequestInFlight ? this.nextDeliveryReportCandidates : this.deliveryReportCandidates;
9093
+ if (candidate.id === null) buffer2.delete(candidate.key);
9094
+ else buffer2.set(candidate.key, candidate.id);
9089
9095
  }
9090
9096
  /**
9091
9097
  * Removes candidate from the delivery report buffer
@@ -9366,6 +9372,26 @@ var MessageReceiptsTracker = class {
9366
9372
  }
9367
9373
  };
9368
9374
 
9375
+ // src/utils/activeMemberCount.ts
9376
+ var withCarriedActiveMemberCount = ({
9377
+ next,
9378
+ previous
9379
+ }) => {
9380
+ const { active_member_count: nextActiveMemberCount, member_count: nextMemberCount } = next;
9381
+ const {
9382
+ active_member_count: previousActiveMemberCount,
9383
+ member_count: previousMemberCount
9384
+ } = previous ?? {};
9385
+ const hasOwnActiveMemberCount = typeof nextActiveMemberCount === "number";
9386
+ const hasPreviousActiveMemberCount = typeof previousActiveMemberCount === "number";
9387
+ if (hasOwnActiveMemberCount || !hasPreviousActiveMemberCount) return next;
9388
+ const memberCount = nextMemberCount ?? previousMemberCount;
9389
+ const delta = typeof nextMemberCount === "number" && typeof previousMemberCount === "number" ? nextMemberCount - previousMemberCount : 0;
9390
+ const shifted = Math.max(0, previousActiveMemberCount + delta);
9391
+ const carriedActiveMemberCount = typeof memberCount === "number" ? Math.min(shifted, memberCount) : shifted;
9392
+ return { ...next, active_member_count: carriedActiveMemberCount };
9393
+ };
9394
+
9369
9395
  // src/channel.ts
9370
9396
  var Channel = class {
9371
9397
  /**
@@ -9451,6 +9477,13 @@ var Channel = class {
9451
9477
  });
9452
9478
  this.cooldownTimer = new CooldownTimer({ channel: this });
9453
9479
  }
9480
+ get data() {
9481
+ return this._channelData;
9482
+ }
9483
+ set data(next) {
9484
+ const previous = this._channelData;
9485
+ this._channelData = next && withCarriedActiveMemberCount({ next, previous });
9486
+ }
9454
9487
  /**
9455
9488
  * getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
9456
9489
  *
@@ -11962,6 +11995,7 @@ var StableWSConnection = class {
11962
11995
  var import_jsonwebtoken = __toESM(require_jsonwebtoken());
11963
11996
  var import_crypto = __toESM(require_crypto());
11964
11997
  var import_zlib = __toESM(require_zlib());
11998
+ var import_buffer = __toESM(require_buffer());
11965
11999
  function JWTUserToken(apiSecret, userId, extraData = {}, jwtOptions = {}) {
11966
12000
  if (typeof userId !== "string") {
11967
12001
  throw new TypeError("userId should be a string");
@@ -12037,13 +12071,29 @@ var InvalidWebhookError = class extends Error {
12037
12071
  this.name = "InvalidWebhookError";
12038
12072
  }
12039
12073
  };
12074
+ var webhookConfig = {
12075
+ maxPayloadBytes: 10 * 1024 * 1024
12076
+ };
12040
12077
  function gunzipPayload(rawBody) {
12041
12078
  const GZIP_MAGIC = Buffer.from([31, 139]);
12042
12079
  const body = Buffer.isBuffer(rawBody) ? rawBody : Buffer.from(rawBody);
12043
12080
  if (body.length >= 2 && body.subarray(0, 2).equals(GZIP_MAGIC)) {
12081
+ const max = webhookConfig.maxPayloadBytes;
12082
+ if (!Number.isInteger(max) || max < 1) {
12083
+ const got = typeof max === "string" ? JSON.stringify(max) : String(max);
12084
+ throw new RangeError(
12085
+ `webhookConfig.maxPayloadBytes must be a positive integer, got ${got}`
12086
+ );
12087
+ }
12088
+ const limit = Math.min(max, import_buffer.default.constants.MAX_LENGTH);
12044
12089
  try {
12045
- return import_zlib.default.gunzipSync(body);
12046
- } catch {
12090
+ return import_zlib.default.gunzipSync(body, { maxOutputLength: limit });
12091
+ } catch (err) {
12092
+ if (err.code === "ERR_BUFFER_TOO_LARGE") {
12093
+ throw new InvalidWebhookError(
12094
+ `${InvalidWebhookErrorMessages.gzipFailed}: payload exceeds ${limit} bytes`
12095
+ );
12096
+ }
12047
12097
  throw new InvalidWebhookError(InvalidWebhookErrorMessages.gzipFailed);
12048
12098
  }
12049
12099
  }
@@ -15316,7 +15366,7 @@ var StreamChat = class _StreamChat {
15316
15366
  return this.userAgent;
15317
15367
  }
15318
15368
  if (!this.cachedUserAgent) {
15319
- const version = "9.55.0";
15369
+ const version = "9.56.1";
15320
15370
  const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
15321
15371
  const { name: appName, version: appVersion } = this.appIdentifier ?? {};
15322
15372
  const { os, model: deviceModel } = this.deviceIdentifier ?? {};
@@ -16375,10 +16425,17 @@ var StreamChat = class _StreamChat {
16375
16425
  * @return {<UpsertPushPreferencesResponse>}
16376
16426
  */
16377
16427
  async setPushPreferences(preferences) {
16378
- return await this.post(
16428
+ const result = await this.post(
16379
16429
  this.baseURL + "/push_preferences",
16380
16430
  { preferences }
16381
16431
  );
16432
+ const { user } = this;
16433
+ if (!user) return result;
16434
+ const updated = result.user_preferences[user.id];
16435
+ if (updated) {
16436
+ this.user = { ...user, push_preferences: updated };
16437
+ }
16438
+ return result;
16382
16439
  }
16383
16440
  /**
16384
16441
  * removeDevice - Removes the device with the given id. Clientside users can only delete their own devices
@@ -20170,6 +20227,7 @@ export {
20170
20227
  timeLeftMs,
20171
20228
  verifyAndParseWebhook,
20172
20229
  verifySignature,
20230
+ webhookConfig,
20173
20231
  withCancellation,
20174
20232
  withoutConcurrency
20175
20233
  };