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
package/dist/types/channel.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class Channel {
|
|
|
13
13
|
_client: StreamChat;
|
|
14
14
|
type: string;
|
|
15
15
|
id: string | undefined;
|
|
16
|
-
|
|
16
|
+
private _channelData;
|
|
17
17
|
_data: Partial<ChannelData & ChannelResponse>;
|
|
18
18
|
cid: string;
|
|
19
19
|
/** */
|
|
@@ -55,6 +55,8 @@ export declare class Channel {
|
|
|
55
55
|
* @return {Channel} Returns a new uninitialized channel
|
|
56
56
|
*/
|
|
57
57
|
constructor(client: StreamChat, type: string, id: string | undefined, data: ChannelData);
|
|
58
|
+
get data(): Partial<ChannelData & ChannelResponse> | undefined;
|
|
59
|
+
set data(next: Partial<ChannelData & ChannelResponse> | undefined);
|
|
58
60
|
/**
|
|
59
61
|
* getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
|
|
60
62
|
*
|
package/dist/types/signing.d.ts
CHANGED
|
@@ -64,6 +64,18 @@ export declare class InvalidWebhookError extends Error {
|
|
|
64
64
|
name: string;
|
|
65
65
|
constructor(message?: string);
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Webhook helper settings.
|
|
69
|
+
*
|
|
70
|
+
* `maxPayloadBytes` caps the decompressed size of a gzip webhook body
|
|
71
|
+
* (default 10 MiB). {@link gunzipPayload} runs before the signature
|
|
72
|
+
* check, so without a cap an unsigned gzip bomb could exhaust memory.
|
|
73
|
+
* Raise it if your events are larger. It must be a positive integer;
|
|
74
|
+
* values above `buffer.constants.MAX_LENGTH` are clamped to it.
|
|
75
|
+
*/
|
|
76
|
+
export declare const webhookConfig: {
|
|
77
|
+
maxPayloadBytes: number;
|
|
78
|
+
};
|
|
67
79
|
/**
|
|
68
80
|
* Returns `body` as a `Buffer`, gzip-decompressed when its first two
|
|
69
81
|
* bytes match the gzip magic (`1f 8b`, per RFC 1952). When the body is
|
|
@@ -73,6 +85,12 @@ export declare class InvalidWebhookError extends Error {
|
|
|
73
85
|
* Magic-byte detection (rather than relying on a header) keeps the
|
|
74
86
|
* same handler correct when middleware - Express, Next.js, AWS Lambda
|
|
75
87
|
* - auto-decompresses the request before your code sees it.
|
|
88
|
+
*
|
|
89
|
+
* @throws {InvalidWebhookError} When the body has the gzip magic but is
|
|
90
|
+
* not valid gzip, or inflates to more than
|
|
91
|
+
* `webhookConfig.maxPayloadBytes`.
|
|
92
|
+
* @throws {RangeError} When the body has the gzip magic and
|
|
93
|
+
* `webhookConfig.maxPayloadBytes` is not a positive integer.
|
|
76
94
|
*/
|
|
77
95
|
export declare function gunzipPayload(rawBody: string | Buffer): Buffer;
|
|
78
96
|
/**
|
|
@@ -107,8 +125,8 @@ export declare function parseEvent(payload: Buffer | string): Event;
|
|
|
107
125
|
* @param rawBody Raw HTTP request body bytes Stream signed
|
|
108
126
|
* @param signature Value of the `X-Signature` header
|
|
109
127
|
* @param secret Your app's API secret
|
|
110
|
-
* @throws {InvalidWebhookError} When the signature does not match or
|
|
111
|
-
* the gzip envelope is malformed.
|
|
128
|
+
* @throws {InvalidWebhookError} When the signature does not match, or
|
|
129
|
+
* the gzip envelope is malformed or exceeds `webhookConfig.maxPayloadBytes`.
|
|
112
130
|
*/
|
|
113
131
|
export declare function verifyAndParseWebhook(rawBody: string | Buffer, signature: string, secret: string): Event;
|
|
114
132
|
/**
|
package/dist/types/types.d.ts
CHANGED
|
@@ -184,6 +184,7 @@ export type AppSettingsAPIResponse = APIResponse & {
|
|
|
184
184
|
sqs_url?: string;
|
|
185
185
|
suspended?: boolean;
|
|
186
186
|
suspended_explanation?: string;
|
|
187
|
+
two_way_block_effect_enabled?: boolean;
|
|
187
188
|
use_hook_v2?: boolean;
|
|
188
189
|
user_response_time_enabled?: boolean;
|
|
189
190
|
user_search_disallowed_roles?: string[] | null;
|
|
@@ -299,6 +300,7 @@ export type ChannelResponse = CustomChannelData & {
|
|
|
299
300
|
frozen: boolean;
|
|
300
301
|
id: string;
|
|
301
302
|
type: string;
|
|
303
|
+
active_member_count?: number;
|
|
302
304
|
blocked?: boolean;
|
|
303
305
|
auto_translation_enabled?: boolean;
|
|
304
306
|
auto_translation_language?: TranslationLanguages;
|
|
@@ -632,14 +634,30 @@ export type PushPreference = {
|
|
|
632
634
|
chat_preferences?: ChatPreferences;
|
|
633
635
|
disabled_until?: string;
|
|
634
636
|
remove_disable?: boolean;
|
|
637
|
+
remove_schedule?: boolean;
|
|
638
|
+
schedule?: PushScheduleInput;
|
|
635
639
|
user_id?: string;
|
|
636
640
|
};
|
|
641
|
+
export type QuietHoursRuleInput = {
|
|
642
|
+
end: string;
|
|
643
|
+
start: string;
|
|
644
|
+
days?: string[];
|
|
645
|
+
};
|
|
646
|
+
export type PushScheduleInput = {
|
|
647
|
+
quiet_hours?: QuietHoursRuleInput[];
|
|
648
|
+
timezone?: string;
|
|
649
|
+
};
|
|
650
|
+
export type PushScheduleResponse = {
|
|
651
|
+
quiet_hours: QuietHoursRuleInput[];
|
|
652
|
+
timezone: string;
|
|
653
|
+
};
|
|
637
654
|
/** Per-user push preferences returned by the API (matches OpenAPI `PushPreferencesResponse`). */
|
|
638
655
|
export type PushPreferencesResponse = {
|
|
639
656
|
call_level?: CallLevelPushPreference;
|
|
640
657
|
chat_level?: ChatLevelPushPreference;
|
|
641
658
|
chat_preferences?: ChatPreferences;
|
|
642
659
|
disabled_until?: string;
|
|
660
|
+
schedule?: PushScheduleResponse;
|
|
643
661
|
};
|
|
644
662
|
/** Per-channel push preferences returned by the API (matches OpenAPI `ChannelPushPreferencesResponse`). */
|
|
645
663
|
export type ChannelPushPreference = {
|
|
@@ -984,6 +1002,7 @@ export type BanUserOptions = UnBanUserOptions & {
|
|
|
984
1002
|
delete_reactions?: boolean;
|
|
985
1003
|
};
|
|
986
1004
|
export type ChannelOptions = {
|
|
1005
|
+
include_active_member_count?: boolean;
|
|
987
1006
|
limit?: number;
|
|
988
1007
|
member_limit?: number;
|
|
989
1008
|
message_limit?: number;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ChannelResponse } from '../types';
|
|
2
|
+
type MemberCounts = Pick<ChannelResponse, 'active_member_count' | 'member_count'>;
|
|
3
|
+
export declare const withCarriedActiveMemberCount: <TData extends MemberCounts>({ next, previous, }: {
|
|
4
|
+
next: TData;
|
|
5
|
+
previous?: MemberCounts;
|
|
6
|
+
}) => TData;
|
|
7
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.56.1",
|
|
4
4
|
"description": "JS SDK for the Stream Chat API",
|
|
5
5
|
"homepage": "https://getstream.io/chat/",
|
|
6
6
|
"author": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"browser": {
|
|
32
|
+
"buffer": false,
|
|
32
33
|
"crypto": false,
|
|
33
34
|
"https": false,
|
|
34
35
|
"jsonwebtoken": false,
|
package/src/channel.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ChannelState } from './channel_state';
|
|
|
3
3
|
import { CooldownTimer } from './CooldownTimer';
|
|
4
4
|
import { MessageComposer } from './messageComposer';
|
|
5
5
|
import { MessageReceiptsTracker } from './messageDelivery';
|
|
6
|
+
import { withCarriedActiveMemberCount } from './utils/activeMemberCount';
|
|
6
7
|
import {
|
|
7
8
|
channelHasReadEvents,
|
|
8
9
|
generateChannelTempCid,
|
|
@@ -92,7 +93,7 @@ export class Channel {
|
|
|
92
93
|
_client: StreamChat;
|
|
93
94
|
type: string;
|
|
94
95
|
id: string | undefined;
|
|
95
|
-
|
|
96
|
+
private _channelData: Partial<ChannelData & ChannelResponse> | undefined;
|
|
96
97
|
_data: Partial<ChannelData & ChannelResponse>;
|
|
97
98
|
cid: string;
|
|
98
99
|
/** */
|
|
@@ -180,6 +181,15 @@ export class Channel {
|
|
|
180
181
|
this.cooldownTimer = new CooldownTimer({ channel: this });
|
|
181
182
|
}
|
|
182
183
|
|
|
184
|
+
public get data(): Partial<ChannelData & ChannelResponse> | undefined {
|
|
185
|
+
return this._channelData;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public set data(next: Partial<ChannelData & ChannelResponse> | undefined) {
|
|
189
|
+
const previous = this._channelData;
|
|
190
|
+
this._channelData = next && withCarriedActiveMemberCount({ next, previous });
|
|
191
|
+
}
|
|
192
|
+
|
|
183
193
|
/**
|
|
184
194
|
* getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
|
|
185
195
|
*
|
package/src/client.ts
CHANGED
|
@@ -2542,10 +2542,20 @@ export class StreamChat {
|
|
|
2542
2542
|
* @return {<UpsertPushPreferencesResponse>}
|
|
2543
2543
|
*/
|
|
2544
2544
|
async setPushPreferences(preferences: PushPreference[]) {
|
|
2545
|
-
|
|
2545
|
+
const result = await this.post<UpsertPushPreferencesResponse>(
|
|
2546
2546
|
this.baseURL + '/push_preferences',
|
|
2547
2547
|
{ preferences },
|
|
2548
2548
|
);
|
|
2549
|
+
const { user } = this;
|
|
2550
|
+
if (!user) return result;
|
|
2551
|
+
|
|
2552
|
+
// The full stored preferences after the update, or null when the request only had
|
|
2553
|
+
// channel-level items for this user.
|
|
2554
|
+
const updated = result.user_preferences[user.id];
|
|
2555
|
+
if (updated) {
|
|
2556
|
+
this.user = { ...user, push_preferences: updated };
|
|
2557
|
+
}
|
|
2558
|
+
return result;
|
|
2549
2559
|
}
|
|
2550
2560
|
|
|
2551
2561
|
/**
|
package/src/signing.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import zlib from 'zlib';
|
|
4
|
+
import buffer from 'buffer';
|
|
4
5
|
import { decodeBase64, encodeBase64 } from './base64';
|
|
5
6
|
import type { Event, UR } from './types';
|
|
6
7
|
|
|
@@ -149,6 +150,19 @@ export class InvalidWebhookError extends Error {
|
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Webhook helper settings.
|
|
155
|
+
*
|
|
156
|
+
* `maxPayloadBytes` caps the decompressed size of a gzip webhook body
|
|
157
|
+
* (default 10 MiB). {@link gunzipPayload} runs before the signature
|
|
158
|
+
* check, so without a cap an unsigned gzip bomb could exhaust memory.
|
|
159
|
+
* Raise it if your events are larger. It must be a positive integer;
|
|
160
|
+
* values above `buffer.constants.MAX_LENGTH` are clamped to it.
|
|
161
|
+
*/
|
|
162
|
+
export const webhookConfig = {
|
|
163
|
+
maxPayloadBytes: 10 * 1024 * 1024,
|
|
164
|
+
};
|
|
165
|
+
|
|
152
166
|
/**
|
|
153
167
|
* Returns `body` as a `Buffer`, gzip-decompressed when its first two
|
|
154
168
|
* bytes match the gzip magic (`1f 8b`, per RFC 1952). When the body is
|
|
@@ -158,15 +172,34 @@ export class InvalidWebhookError extends Error {
|
|
|
158
172
|
* Magic-byte detection (rather than relying on a header) keeps the
|
|
159
173
|
* same handler correct when middleware - Express, Next.js, AWS Lambda
|
|
160
174
|
* - auto-decompresses the request before your code sees it.
|
|
175
|
+
*
|
|
176
|
+
* @throws {InvalidWebhookError} When the body has the gzip magic but is
|
|
177
|
+
* not valid gzip, or inflates to more than
|
|
178
|
+
* `webhookConfig.maxPayloadBytes`.
|
|
179
|
+
* @throws {RangeError} When the body has the gzip magic and
|
|
180
|
+
* `webhookConfig.maxPayloadBytes` is not a positive integer.
|
|
161
181
|
*/
|
|
162
182
|
export function gunzipPayload(rawBody: string | Buffer): Buffer {
|
|
163
183
|
const GZIP_MAGIC = Buffer.from([0x1f, 0x8b]);
|
|
164
184
|
|
|
165
185
|
const body = Buffer.isBuffer(rawBody) ? rawBody : Buffer.from(rawBody);
|
|
166
186
|
if (body.length >= 2 && body.subarray(0, 2).equals(GZIP_MAGIC)) {
|
|
187
|
+
const max = webhookConfig.maxPayloadBytes;
|
|
188
|
+
if (!Number.isInteger(max) || max < 1) {
|
|
189
|
+
const got = typeof max === 'string' ? JSON.stringify(max) : String(max);
|
|
190
|
+
throw new RangeError(
|
|
191
|
+
`webhookConfig.maxPayloadBytes must be a positive integer, got ${got}`,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
const limit = Math.min(max, buffer.constants.MAX_LENGTH);
|
|
167
195
|
try {
|
|
168
|
-
return zlib.gunzipSync(body);
|
|
169
|
-
} catch {
|
|
196
|
+
return zlib.gunzipSync(body, { maxOutputLength: limit });
|
|
197
|
+
} catch (err) {
|
|
198
|
+
if ((err as NodeJS.ErrnoException).code === 'ERR_BUFFER_TOO_LARGE') {
|
|
199
|
+
throw new InvalidWebhookError(
|
|
200
|
+
`${InvalidWebhookErrorMessages.gzipFailed}: payload exceeds ${limit} bytes`,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
170
203
|
throw new InvalidWebhookError(InvalidWebhookErrorMessages.gzipFailed);
|
|
171
204
|
}
|
|
172
205
|
}
|
|
@@ -261,8 +294,8 @@ function verifyAndParse(payload: Buffer, signature: string, secret: string): Eve
|
|
|
261
294
|
* @param rawBody Raw HTTP request body bytes Stream signed
|
|
262
295
|
* @param signature Value of the `X-Signature` header
|
|
263
296
|
* @param secret Your app's API secret
|
|
264
|
-
* @throws {InvalidWebhookError} When the signature does not match or
|
|
265
|
-
* the gzip envelope is malformed.
|
|
297
|
+
* @throws {InvalidWebhookError} When the signature does not match, or
|
|
298
|
+
* the gzip envelope is malformed or exceeds `webhookConfig.maxPayloadBytes`.
|
|
266
299
|
*/
|
|
267
300
|
export function verifyAndParseWebhook(
|
|
268
301
|
rawBody: string | Buffer,
|
package/src/types.ts
CHANGED
|
@@ -232,6 +232,7 @@ export type AppSettingsAPIResponse = APIResponse & {
|
|
|
232
232
|
sqs_url?: string;
|
|
233
233
|
suspended?: boolean;
|
|
234
234
|
suspended_explanation?: string;
|
|
235
|
+
two_way_block_effect_enabled?: boolean;
|
|
235
236
|
use_hook_v2?: boolean;
|
|
236
237
|
user_response_time_enabled?: boolean;
|
|
237
238
|
user_search_disallowed_roles?: string[] | null;
|
|
@@ -362,6 +363,7 @@ export type ChannelResponse = CustomChannelData & {
|
|
|
362
363
|
frozen: boolean;
|
|
363
364
|
id: string;
|
|
364
365
|
type: string;
|
|
366
|
+
active_member_count?: number;
|
|
365
367
|
blocked?: boolean;
|
|
366
368
|
auto_translation_enabled?: boolean;
|
|
367
369
|
auto_translation_language?: TranslationLanguages;
|
|
@@ -759,15 +761,34 @@ export type PushPreference = {
|
|
|
759
761
|
chat_preferences?: ChatPreferences;
|
|
760
762
|
disabled_until?: string; // snooze until this time
|
|
761
763
|
remove_disable?: boolean; // stop snoozing (clears disabled_until)
|
|
764
|
+
remove_schedule?: boolean;
|
|
765
|
+
schedule?: PushScheduleInput;
|
|
762
766
|
user_id?: string;
|
|
763
767
|
};
|
|
764
768
|
|
|
769
|
+
export type QuietHoursRuleInput = {
|
|
770
|
+
end: string;
|
|
771
|
+
start: string;
|
|
772
|
+
days?: string[];
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
export type PushScheduleInput = {
|
|
776
|
+
quiet_hours?: QuietHoursRuleInput[];
|
|
777
|
+
timezone?: string;
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
export type PushScheduleResponse = {
|
|
781
|
+
quiet_hours: QuietHoursRuleInput[];
|
|
782
|
+
timezone: string;
|
|
783
|
+
};
|
|
784
|
+
|
|
765
785
|
/** Per-user push preferences returned by the API (matches OpenAPI `PushPreferencesResponse`). */
|
|
766
786
|
export type PushPreferencesResponse = {
|
|
767
787
|
call_level?: CallLevelPushPreference;
|
|
768
788
|
chat_level?: ChatLevelPushPreference;
|
|
769
789
|
chat_preferences?: ChatPreferences;
|
|
770
790
|
disabled_until?: string;
|
|
791
|
+
schedule?: PushScheduleResponse;
|
|
771
792
|
};
|
|
772
793
|
|
|
773
794
|
/** Per-channel push preferences returned by the API (matches OpenAPI `ChannelPushPreferencesResponse`). */
|
|
@@ -1165,6 +1186,7 @@ export type BanUserOptions = UnBanUserOptions & {
|
|
|
1165
1186
|
};
|
|
1166
1187
|
|
|
1167
1188
|
export type ChannelOptions = {
|
|
1189
|
+
include_active_member_count?: boolean;
|
|
1168
1190
|
limit?: number;
|
|
1169
1191
|
member_limit?: number;
|
|
1170
1192
|
message_limit?: number;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ChannelResponse } from '../types';
|
|
2
|
+
|
|
3
|
+
type MemberCounts = Pick<ChannelResponse, 'active_member_count' | 'member_count'>;
|
|
4
|
+
|
|
5
|
+
export const withCarriedActiveMemberCount = <TData extends MemberCounts>({
|
|
6
|
+
next,
|
|
7
|
+
previous,
|
|
8
|
+
}: {
|
|
9
|
+
next: TData;
|
|
10
|
+
previous?: MemberCounts;
|
|
11
|
+
}) => {
|
|
12
|
+
const { active_member_count: nextActiveMemberCount, member_count: nextMemberCount } =
|
|
13
|
+
next;
|
|
14
|
+
const {
|
|
15
|
+
active_member_count: previousActiveMemberCount,
|
|
16
|
+
member_count: previousMemberCount,
|
|
17
|
+
} = previous ?? {};
|
|
18
|
+
const hasOwnActiveMemberCount = typeof nextActiveMemberCount === 'number';
|
|
19
|
+
const hasPreviousActiveMemberCount = typeof previousActiveMemberCount === 'number';
|
|
20
|
+
if (hasOwnActiveMemberCount || !hasPreviousActiveMemberCount) return next;
|
|
21
|
+
|
|
22
|
+
// Only Query Channels returns the count, so between queries shift the last known value
|
|
23
|
+
// by the change in member_count (an estimate, clamped to [0, member_count]).
|
|
24
|
+
const memberCount = nextMemberCount ?? previousMemberCount;
|
|
25
|
+
const delta =
|
|
26
|
+
typeof nextMemberCount === 'number' && typeof previousMemberCount === 'number'
|
|
27
|
+
? nextMemberCount - previousMemberCount
|
|
28
|
+
: 0;
|
|
29
|
+
const shifted = Math.max(0, previousActiveMemberCount + delta);
|
|
30
|
+
const carriedActiveMemberCount =
|
|
31
|
+
typeof memberCount === 'number' ? Math.min(shifted, memberCount) : shifted;
|
|
32
|
+
|
|
33
|
+
return { ...next, active_member_count: carriedActiveMemberCount };
|
|
34
|
+
};
|