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.
@@ -239,6 +239,7 @@ __export(index_exports, {
239
239
  timeLeftMs: () => timeLeftMs,
240
240
  verifyAndParseWebhook: () => verifyAndParseWebhook,
241
241
  verifySignature: () => verifySignature,
242
+ webhookConfig: () => webhookConfig,
242
243
  withCancellation: () => withCancellation,
243
244
  withoutConcurrency: () => withoutConcurrency
244
245
  });
@@ -9275,9 +9276,9 @@ var MessageDeliveryReporter = class _MessageDeliveryReporter {
9275
9276
  if (!_MessageDeliveryReporter.hasPermissionToReportDeliveryFor(collection)) return;
9276
9277
  const candidate = this.getNextDeliveryReportCandidate(collection);
9277
9278
  if (!candidate?.key) return;
9278
- const buffer = this.markDeliveredRequestInFlight ? this.nextDeliveryReportCandidates : this.deliveryReportCandidates;
9279
- if (candidate.id === null) buffer.delete(candidate.key);
9280
- else buffer.set(candidate.key, candidate.id);
9279
+ const buffer2 = this.markDeliveredRequestInFlight ? this.nextDeliveryReportCandidates : this.deliveryReportCandidates;
9280
+ if (candidate.id === null) buffer2.delete(candidate.key);
9281
+ else buffer2.set(candidate.key, candidate.id);
9281
9282
  }
9282
9283
  /**
9283
9284
  * Removes candidate from the delivery report buffer
@@ -9558,6 +9559,26 @@ var MessageReceiptsTracker = class {
9558
9559
  }
9559
9560
  };
9560
9561
 
9562
+ // src/utils/activeMemberCount.ts
9563
+ var withCarriedActiveMemberCount = ({
9564
+ next,
9565
+ previous
9566
+ }) => {
9567
+ const { active_member_count: nextActiveMemberCount, member_count: nextMemberCount } = next;
9568
+ const {
9569
+ active_member_count: previousActiveMemberCount,
9570
+ member_count: previousMemberCount
9571
+ } = previous ?? {};
9572
+ const hasOwnActiveMemberCount = typeof nextActiveMemberCount === "number";
9573
+ const hasPreviousActiveMemberCount = typeof previousActiveMemberCount === "number";
9574
+ if (hasOwnActiveMemberCount || !hasPreviousActiveMemberCount) return next;
9575
+ const memberCount = nextMemberCount ?? previousMemberCount;
9576
+ const delta = typeof nextMemberCount === "number" && typeof previousMemberCount === "number" ? nextMemberCount - previousMemberCount : 0;
9577
+ const shifted = Math.max(0, previousActiveMemberCount + delta);
9578
+ const carriedActiveMemberCount = typeof memberCount === "number" ? Math.min(shifted, memberCount) : shifted;
9579
+ return { ...next, active_member_count: carriedActiveMemberCount };
9580
+ };
9581
+
9561
9582
  // src/channel.ts
9562
9583
  var Channel = class {
9563
9584
  /**
@@ -9643,6 +9664,13 @@ var Channel = class {
9643
9664
  });
9644
9665
  this.cooldownTimer = new CooldownTimer({ channel: this });
9645
9666
  }
9667
+ get data() {
9668
+ return this._channelData;
9669
+ }
9670
+ set data(next) {
9671
+ const previous = this._channelData;
9672
+ this._channelData = next && withCarriedActiveMemberCount({ next, previous });
9673
+ }
9646
9674
  /**
9647
9675
  * getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
9648
9676
  *
@@ -12154,6 +12182,7 @@ var StableWSConnection = class {
12154
12182
  var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
12155
12183
  var import_crypto = __toESM(require("crypto"));
12156
12184
  var import_zlib = __toESM(require("zlib"));
12185
+ var import_buffer = __toESM(require("buffer"));
12157
12186
  function JWTUserToken(apiSecret, userId, extraData = {}, jwtOptions = {}) {
12158
12187
  if (typeof userId !== "string") {
12159
12188
  throw new TypeError("userId should be a string");
@@ -12229,13 +12258,29 @@ var InvalidWebhookError = class extends Error {
12229
12258
  this.name = "InvalidWebhookError";
12230
12259
  }
12231
12260
  };
12261
+ var webhookConfig = {
12262
+ maxPayloadBytes: 10 * 1024 * 1024
12263
+ };
12232
12264
  function gunzipPayload(rawBody) {
12233
12265
  const GZIP_MAGIC = Buffer.from([31, 139]);
12234
12266
  const body = Buffer.isBuffer(rawBody) ? rawBody : Buffer.from(rawBody);
12235
12267
  if (body.length >= 2 && body.subarray(0, 2).equals(GZIP_MAGIC)) {
12268
+ const max = webhookConfig.maxPayloadBytes;
12269
+ if (!Number.isInteger(max) || max < 1) {
12270
+ const got = typeof max === "string" ? JSON.stringify(max) : String(max);
12271
+ throw new RangeError(
12272
+ `webhookConfig.maxPayloadBytes must be a positive integer, got ${got}`
12273
+ );
12274
+ }
12275
+ const limit = Math.min(max, import_buffer.default.constants.MAX_LENGTH);
12236
12276
  try {
12237
- return import_zlib.default.gunzipSync(body);
12238
- } catch {
12277
+ return import_zlib.default.gunzipSync(body, { maxOutputLength: limit });
12278
+ } catch (err) {
12279
+ if (err.code === "ERR_BUFFER_TOO_LARGE") {
12280
+ throw new InvalidWebhookError(
12281
+ `${InvalidWebhookErrorMessages.gzipFailed}: payload exceeds ${limit} bytes`
12282
+ );
12283
+ }
12239
12284
  throw new InvalidWebhookError(InvalidWebhookErrorMessages.gzipFailed);
12240
12285
  }
12241
12286
  }
@@ -15508,7 +15553,7 @@ var StreamChat = class _StreamChat {
15508
15553
  return this.userAgent;
15509
15554
  }
15510
15555
  if (!this.cachedUserAgent) {
15511
- const version = "9.55.0";
15556
+ const version = "9.56.1";
15512
15557
  const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
15513
15558
  const { name: appName, version: appVersion } = this.appIdentifier ?? {};
15514
15559
  const { os, model: deviceModel } = this.deviceIdentifier ?? {};
@@ -16567,10 +16612,17 @@ var StreamChat = class _StreamChat {
16567
16612
  * @return {<UpsertPushPreferencesResponse>}
16568
16613
  */
16569
16614
  async setPushPreferences(preferences) {
16570
- return await this.post(
16615
+ const result = await this.post(
16571
16616
  this.baseURL + "/push_preferences",
16572
16617
  { preferences }
16573
16618
  );
16619
+ const { user } = this;
16620
+ if (!user) return result;
16621
+ const updated = result.user_preferences[user.id];
16622
+ if (updated) {
16623
+ this.user = { ...user, push_preferences: updated };
16624
+ }
16625
+ return result;
16574
16626
  }
16575
16627
  /**
16576
16628
  * removeDevice - Removes the device with the given id. Clientside users can only delete their own devices
@@ -20363,6 +20415,7 @@ var LiveLocationManager = _LiveLocationManager;
20363
20415
  timeLeftMs,
20364
20416
  verifyAndParseWebhook,
20365
20417
  verifySignature,
20418
+ webhookConfig,
20366
20419
  withCancellation,
20367
20420
  withoutConcurrency
20368
20421
  });