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.
- package/dist/cjs/index.browser.js +65 -7
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +60 -7
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +65 -7
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/channel.d.ts +3 -1
- package/dist/types/signing.d.ts +20 -2
- package/dist/types/types.d.ts +19 -0
- package/dist/types/utils/activeMemberCount.d.ts +7 -0
- package/package.json +2 -1
- package/src/channel.ts +11 -1
- package/src/client.ts +11 -1
- package/src/signing.ts +37 -4
- package/src/types.ts +22 -0
- package/src/utils/activeMemberCount.ts +34 -0
|
@@ -58,6 +58,12 @@ var require_zlib = __commonJS({
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
+
// (disabled):buffer
|
|
62
|
+
var require_buffer = __commonJS({
|
|
63
|
+
"(disabled):buffer"() {
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
61
67
|
// src/index.ts
|
|
62
68
|
var index_exports = {};
|
|
63
69
|
__export(index_exports, {
|
|
@@ -270,6 +276,7 @@ __export(index_exports, {
|
|
|
270
276
|
timeLeftMs: () => timeLeftMs,
|
|
271
277
|
verifyAndParseWebhook: () => verifyAndParseWebhook,
|
|
272
278
|
verifySignature: () => verifySignature,
|
|
279
|
+
webhookConfig: () => webhookConfig,
|
|
273
280
|
withCancellation: () => withCancellation,
|
|
274
281
|
withoutConcurrency: () => withoutConcurrency
|
|
275
282
|
});
|
|
@@ -9306,9 +9313,9 @@ var MessageDeliveryReporter = class _MessageDeliveryReporter {
|
|
|
9306
9313
|
if (!_MessageDeliveryReporter.hasPermissionToReportDeliveryFor(collection)) return;
|
|
9307
9314
|
const candidate = this.getNextDeliveryReportCandidate(collection);
|
|
9308
9315
|
if (!candidate?.key) return;
|
|
9309
|
-
const
|
|
9310
|
-
if (candidate.id === null)
|
|
9311
|
-
else
|
|
9316
|
+
const buffer2 = this.markDeliveredRequestInFlight ? this.nextDeliveryReportCandidates : this.deliveryReportCandidates;
|
|
9317
|
+
if (candidate.id === null) buffer2.delete(candidate.key);
|
|
9318
|
+
else buffer2.set(candidate.key, candidate.id);
|
|
9312
9319
|
}
|
|
9313
9320
|
/**
|
|
9314
9321
|
* Removes candidate from the delivery report buffer
|
|
@@ -9589,6 +9596,26 @@ var MessageReceiptsTracker = class {
|
|
|
9589
9596
|
}
|
|
9590
9597
|
};
|
|
9591
9598
|
|
|
9599
|
+
// src/utils/activeMemberCount.ts
|
|
9600
|
+
var withCarriedActiveMemberCount = ({
|
|
9601
|
+
next,
|
|
9602
|
+
previous
|
|
9603
|
+
}) => {
|
|
9604
|
+
const { active_member_count: nextActiveMemberCount, member_count: nextMemberCount } = next;
|
|
9605
|
+
const {
|
|
9606
|
+
active_member_count: previousActiveMemberCount,
|
|
9607
|
+
member_count: previousMemberCount
|
|
9608
|
+
} = previous ?? {};
|
|
9609
|
+
const hasOwnActiveMemberCount = typeof nextActiveMemberCount === "number";
|
|
9610
|
+
const hasPreviousActiveMemberCount = typeof previousActiveMemberCount === "number";
|
|
9611
|
+
if (hasOwnActiveMemberCount || !hasPreviousActiveMemberCount) return next;
|
|
9612
|
+
const memberCount = nextMemberCount ?? previousMemberCount;
|
|
9613
|
+
const delta = typeof nextMemberCount === "number" && typeof previousMemberCount === "number" ? nextMemberCount - previousMemberCount : 0;
|
|
9614
|
+
const shifted = Math.max(0, previousActiveMemberCount + delta);
|
|
9615
|
+
const carriedActiveMemberCount = typeof memberCount === "number" ? Math.min(shifted, memberCount) : shifted;
|
|
9616
|
+
return { ...next, active_member_count: carriedActiveMemberCount };
|
|
9617
|
+
};
|
|
9618
|
+
|
|
9592
9619
|
// src/channel.ts
|
|
9593
9620
|
var Channel = class {
|
|
9594
9621
|
/**
|
|
@@ -9674,6 +9701,13 @@ var Channel = class {
|
|
|
9674
9701
|
});
|
|
9675
9702
|
this.cooldownTimer = new CooldownTimer({ channel: this });
|
|
9676
9703
|
}
|
|
9704
|
+
get data() {
|
|
9705
|
+
return this._channelData;
|
|
9706
|
+
}
|
|
9707
|
+
set data(next) {
|
|
9708
|
+
const previous = this._channelData;
|
|
9709
|
+
this._channelData = next && withCarriedActiveMemberCount({ next, previous });
|
|
9710
|
+
}
|
|
9677
9711
|
/**
|
|
9678
9712
|
* getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
|
|
9679
9713
|
*
|
|
@@ -12185,6 +12219,7 @@ var StableWSConnection = class {
|
|
|
12185
12219
|
var import_jsonwebtoken = __toESM(require_jsonwebtoken());
|
|
12186
12220
|
var import_crypto = __toESM(require_crypto());
|
|
12187
12221
|
var import_zlib = __toESM(require_zlib());
|
|
12222
|
+
var import_buffer = __toESM(require_buffer());
|
|
12188
12223
|
function JWTUserToken(apiSecret, userId, extraData = {}, jwtOptions = {}) {
|
|
12189
12224
|
if (typeof userId !== "string") {
|
|
12190
12225
|
throw new TypeError("userId should be a string");
|
|
@@ -12260,13 +12295,29 @@ var InvalidWebhookError = class extends Error {
|
|
|
12260
12295
|
this.name = "InvalidWebhookError";
|
|
12261
12296
|
}
|
|
12262
12297
|
};
|
|
12298
|
+
var webhookConfig = {
|
|
12299
|
+
maxPayloadBytes: 10 * 1024 * 1024
|
|
12300
|
+
};
|
|
12263
12301
|
function gunzipPayload(rawBody) {
|
|
12264
12302
|
const GZIP_MAGIC = Buffer.from([31, 139]);
|
|
12265
12303
|
const body = Buffer.isBuffer(rawBody) ? rawBody : Buffer.from(rawBody);
|
|
12266
12304
|
if (body.length >= 2 && body.subarray(0, 2).equals(GZIP_MAGIC)) {
|
|
12305
|
+
const max = webhookConfig.maxPayloadBytes;
|
|
12306
|
+
if (!Number.isInteger(max) || max < 1) {
|
|
12307
|
+
const got = typeof max === "string" ? JSON.stringify(max) : String(max);
|
|
12308
|
+
throw new RangeError(
|
|
12309
|
+
`webhookConfig.maxPayloadBytes must be a positive integer, got ${got}`
|
|
12310
|
+
);
|
|
12311
|
+
}
|
|
12312
|
+
const limit = Math.min(max, import_buffer.default.constants.MAX_LENGTH);
|
|
12267
12313
|
try {
|
|
12268
|
-
return import_zlib.default.gunzipSync(body);
|
|
12269
|
-
} catch {
|
|
12314
|
+
return import_zlib.default.gunzipSync(body, { maxOutputLength: limit });
|
|
12315
|
+
} catch (err) {
|
|
12316
|
+
if (err.code === "ERR_BUFFER_TOO_LARGE") {
|
|
12317
|
+
throw new InvalidWebhookError(
|
|
12318
|
+
`${InvalidWebhookErrorMessages.gzipFailed}: payload exceeds ${limit} bytes`
|
|
12319
|
+
);
|
|
12320
|
+
}
|
|
12270
12321
|
throw new InvalidWebhookError(InvalidWebhookErrorMessages.gzipFailed);
|
|
12271
12322
|
}
|
|
12272
12323
|
}
|
|
@@ -15539,7 +15590,7 @@ var StreamChat = class _StreamChat {
|
|
|
15539
15590
|
return this.userAgent;
|
|
15540
15591
|
}
|
|
15541
15592
|
if (!this.cachedUserAgent) {
|
|
15542
|
-
const version = "9.
|
|
15593
|
+
const version = "9.56.1";
|
|
15543
15594
|
const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
|
|
15544
15595
|
const { name: appName, version: appVersion } = this.appIdentifier ?? {};
|
|
15545
15596
|
const { os, model: deviceModel } = this.deviceIdentifier ?? {};
|
|
@@ -16598,10 +16649,17 @@ var StreamChat = class _StreamChat {
|
|
|
16598
16649
|
* @return {<UpsertPushPreferencesResponse>}
|
|
16599
16650
|
*/
|
|
16600
16651
|
async setPushPreferences(preferences) {
|
|
16601
|
-
|
|
16652
|
+
const result = await this.post(
|
|
16602
16653
|
this.baseURL + "/push_preferences",
|
|
16603
16654
|
{ preferences }
|
|
16604
16655
|
);
|
|
16656
|
+
const { user } = this;
|
|
16657
|
+
if (!user) return result;
|
|
16658
|
+
const updated = result.user_preferences[user.id];
|
|
16659
|
+
if (updated) {
|
|
16660
|
+
this.user = { ...user, push_preferences: updated };
|
|
16661
|
+
}
|
|
16662
|
+
return result;
|
|
16605
16663
|
}
|
|
16606
16664
|
/**
|
|
16607
16665
|
* removeDevice - Removes the device with the given id. Clientside users can only delete their own devices
|