stream-chat 9.50.3 → 10.0.0-rc.2

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.
Files changed (242) hide show
  1. package/dist/cjs/index.browser.js +19798 -14472
  2. package/dist/cjs/index.browser.js.map +4 -4
  3. package/dist/cjs/index.node.js +19817 -14482
  4. package/dist/cjs/index.node.js.map +4 -4
  5. package/dist/esm/index.mjs +19795 -14469
  6. package/dist/esm/index.mjs.map +4 -4
  7. package/dist/types/ChannelManager.d.ts +221 -0
  8. package/dist/types/EventHandlerPipeline.d.ts +104 -0
  9. package/dist/types/api-client.d.ts +26 -0
  10. package/dist/types/campaign.d.ts +0 -44
  11. package/dist/types/channel.d.ts +454 -479
  12. package/dist/types/channel_batch_updater.d.ts +0 -93
  13. package/dist/types/channel_state.d.ts +53 -201
  14. package/dist/types/client.d.ts +451 -1920
  15. package/dist/types/client_state.d.ts +4 -4
  16. package/dist/types/configuration/InstanceConfigurationService.d.ts +26 -0
  17. package/dist/types/configuration/index.d.ts +1 -0
  18. package/dist/types/configuration/types.d.ts +53 -0
  19. package/dist/types/connection.d.ts +49 -41
  20. package/dist/types/connection_fallback.d.ts +6 -4
  21. package/dist/types/constants.d.ts +0 -4
  22. package/dist/types/custom_types.d.ts +2 -0
  23. package/dist/types/entityStore/EntityStore.d.ts +111 -0
  24. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +60 -0
  25. package/dist/types/entityStore/applyReactionLocally.d.ts +26 -0
  26. package/dist/types/entityStore/index.d.ts +2 -0
  27. package/dist/types/errors.d.ts +10 -2
  28. package/dist/types/gen/chat/ChannelApi.d.ts +45 -0
  29. package/dist/types/gen/chat/ChatApi.d.ts +334 -0
  30. package/dist/types/gen/model-decoders/decoders.d.ts +3 -0
  31. package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +6 -0
  32. package/dist/types/gen/models/index.d.ts +8836 -0
  33. package/dist/types/gen/moderation/ModerationApi.d.ts +50 -0
  34. package/dist/types/gen-imports.d.ts +3 -0
  35. package/dist/types/index.d.ts +8 -7
  36. package/dist/types/insights.d.ts +9 -8
  37. package/dist/types/logger.d.ts +9 -0
  38. package/dist/types/messageComposer/LocationComposer.d.ts +7 -4
  39. package/dist/types/messageComposer/attachmentIdentity.d.ts +2 -2
  40. package/dist/types/messageComposer/attachmentManager.d.ts +8 -4
  41. package/dist/types/messageComposer/configuration/types.d.ts +11 -11
  42. package/dist/types/messageComposer/linkPreviewsManager.d.ts +25 -13
  43. package/dist/types/messageComposer/messageComposer.d.ts +10 -10
  44. package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +3 -3
  45. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +4 -7
  46. package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +3 -3
  47. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +7 -7
  48. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +218 -4
  49. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +9 -4
  50. package/dist/types/messageComposer/pollComposer.d.ts +5 -4
  51. package/dist/types/messageComposer/textComposer.d.ts +8 -3
  52. package/dist/types/messageComposer/types.d.ts +6 -28
  53. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +40 -25
  54. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +53 -12
  55. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +19 -0
  56. package/dist/types/messageOperations/MessageOperations.d.ts +17 -0
  57. package/dist/types/messageOperations/index.d.ts +3 -0
  58. package/dist/types/messageOperations/types.d.ts +49 -0
  59. package/dist/types/moderation.d.ts +21 -203
  60. package/dist/types/notifications/types.d.ts +8 -7
  61. package/dist/types/offline-support/offline_support_api.d.ts +111 -87
  62. package/dist/types/offline-support/offline_sync_manager.d.ts +0 -7
  63. package/dist/types/offline-support/types.d.ts +19 -23
  64. package/dist/types/offline-support/util.d.ts +4 -2
  65. package/dist/types/pagination/FilterBuilder.d.ts +1 -1
  66. package/dist/types/pagination/ItemIndex.d.ts +25 -0
  67. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +9 -0
  68. package/dist/types/pagination/cursorDerivation/idAroundPaginationFlags.d.ts +6 -0
  69. package/dist/types/pagination/cursorDerivation/index.d.ts +1 -0
  70. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +6 -0
  71. package/dist/types/pagination/filterCompiler.d.ts +7 -0
  72. package/dist/types/pagination/index.d.ts +1 -3
  73. package/dist/types/pagination/paginators/BasePaginator.d.ts +848 -0
  74. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +212 -0
  75. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +282 -0
  76. package/dist/types/pagination/paginators/MessagePaginator.d.ts +208 -0
  77. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +39 -0
  78. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +19 -0
  79. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +24 -0
  80. package/dist/types/pagination/paginators/index.d.ts +7 -0
  81. package/dist/types/pagination/paginators/stateThrottling.d.ts +2 -0
  82. package/dist/types/pagination/sortCompiler.d.ts +49 -0
  83. package/dist/types/pagination/types.normalization.d.ts +11 -0
  84. package/dist/types/pagination/utility.normalization.d.ts +18 -0
  85. package/dist/types/pagination/utility.queryChannel.d.ts +26 -0
  86. package/dist/types/pagination/utility.search.d.ts +13 -0
  87. package/dist/types/permissions.d.ts +1 -1
  88. package/dist/types/poll.d.ts +29 -32
  89. package/dist/types/poll_manager.d.ts +2 -2
  90. package/dist/types/reminders/Reminder.d.ts +2 -5
  91. package/dist/types/reminders/ReminderManager.d.ts +2 -9
  92. package/dist/types/search/MessageSearchSource.d.ts +4 -4
  93. package/dist/types/search/UserSearchSource.d.ts +1 -1
  94. package/dist/types/search/types.d.ts +3 -3
  95. package/dist/types/segment.d.ts +0 -34
  96. package/dist/types/signing.d.ts +105 -65
  97. package/dist/types/store.d.ts +1 -0
  98. package/dist/types/thread.d.ts +70 -34
  99. package/dist/types/thread_manager.d.ts +3 -3
  100. package/dist/types/token_manager.d.ts +15 -10
  101. package/dist/types/types.d.ts +197 -3404
  102. package/dist/types/utils/FixedSizeQueueCache.d.ts +12 -6
  103. package/dist/types/utils/WithSubscriptions.d.ts +2 -1
  104. package/dist/types/utils/concurrency.d.ts +4 -4
  105. package/dist/types/utils/mergeWith/mergeWith.d.ts +3 -3
  106. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +8 -3
  107. package/dist/types/utils/retryable.d.ts +34 -0
  108. package/dist/types/utils/throttling/throttle.d.ts +36 -0
  109. package/dist/types/utils.d.ts +100 -194
  110. package/package.json +7 -3
  111. package/src/ChannelManager.ts +724 -0
  112. package/src/CooldownTimer.ts +2 -2
  113. package/src/EventHandlerPipeline.ts +228 -0
  114. package/src/LiveLocationManager.ts +12 -11
  115. package/src/api-client.ts +275 -0
  116. package/src/campaign.ts +1 -77
  117. package/src/channel.ts +1344 -1282
  118. package/src/channel_batch_updater.ts +1 -211
  119. package/src/channel_state.ts +144 -1013
  120. package/src/client.ts +936 -3995
  121. package/src/client_state.ts +4 -4
  122. package/src/configuration/InstanceConfigurationService.ts +73 -0
  123. package/src/configuration/index.ts +1 -0
  124. package/src/configuration/types.ts +81 -0
  125. package/src/connection.ts +145 -94
  126. package/src/connection_fallback.ts +29 -27
  127. package/src/constants.ts +1 -5
  128. package/src/custom_types.ts +4 -1
  129. package/src/entityStore/EntityStore.ts +208 -0
  130. package/src/entityStore/StoreBackedItemIndex.ts +115 -0
  131. package/src/entityStore/applyReactionLocally.ts +113 -0
  132. package/src/entityStore/index.ts +2 -0
  133. package/src/errors.ts +14 -2
  134. package/src/gen/chat/ChannelApi.ts +275 -0
  135. package/src/gen/chat/ChatApi.ts +2554 -0
  136. package/src/gen/model-decoders/decoders.ts +2680 -0
  137. package/src/gen/model-decoders/event-decoder-mapping.ts +198 -0
  138. package/src/gen/models/index.ts +12673 -0
  139. package/src/gen/moderation/ModerationApi.ts +607 -0
  140. package/src/gen-imports.ts +3 -0
  141. package/src/index.ts +11 -12
  142. package/src/insights.ts +6 -5
  143. package/src/logger.ts +28 -0
  144. package/src/messageComposer/LocationComposer.ts +9 -5
  145. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -0
  146. package/src/messageComposer/attachmentIdentity.ts +16 -9
  147. package/src/messageComposer/attachmentManager.ts +13 -8
  148. package/src/messageComposer/configuration/types.ts +11 -11
  149. package/src/messageComposer/linkPreviewsManager.ts +9 -10
  150. package/src/messageComposer/messageComposer.ts +57 -53
  151. package/src/messageComposer/middleware/messageComposer/attachments.ts +1 -2
  152. package/src/messageComposer/middleware/messageComposer/cleanData.ts +1 -1
  153. package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +2 -2
  154. package/src/messageComposer/middleware/messageComposer/messageComposerState.ts +2 -2
  155. package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +4 -3
  156. package/src/messageComposer/middleware/messageComposer/textComposer.ts +2 -2
  157. package/src/messageComposer/middleware/messageComposer/types.ts +3 -4
  158. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +9 -5
  159. package/src/messageComposer/middleware/pollComposer/state.ts +0 -2
  160. package/src/messageComposer/middleware/pollComposer/types.ts +4 -7
  161. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +10 -1
  162. package/src/messageComposer/middleware/textComposer/commandEffects.ts +4 -4
  163. package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -6
  164. package/src/messageComposer/middleware/textComposer/commands.ts +3 -3
  165. package/src/messageComposer/middleware/textComposer/mentionUtils.ts +1 -1
  166. package/src/messageComposer/middleware/textComposer/mentions.ts +31 -15
  167. package/src/messageComposer/middleware/textComposer/types.ts +9 -4
  168. package/src/messageComposer/pollComposer.ts +6 -8
  169. package/src/messageComposer/textComposer.ts +27 -2
  170. package/src/messageComposer/types.ts +6 -28
  171. package/src/messageDelivery/MessageDeliveryReporter.ts +101 -45
  172. package/src/messageDelivery/MessageReceiptsTracker.ts +294 -21
  173. package/src/messageOperations/MessageOperationStatePolicy.ts +77 -0
  174. package/src/messageOperations/MessageOperations.ts +212 -0
  175. package/src/messageOperations/index.ts +10 -0
  176. package/src/messageOperations/types.ts +64 -0
  177. package/src/moderation.ts +38 -431
  178. package/src/notifications/types.ts +8 -7
  179. package/src/offline-support/offline_support_api.ts +200 -133
  180. package/src/offline-support/offline_sync_manager.ts +23 -44
  181. package/src/offline-support/types.ts +23 -26
  182. package/src/offline-support/util.ts +5 -4
  183. package/src/pagination/FilterBuilder.ts +4 -1
  184. package/src/pagination/ItemIndex.ts +25 -0
  185. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +73 -0
  186. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +53 -0
  187. package/src/pagination/cursorDerivation/index.ts +1 -0
  188. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +86 -0
  189. package/src/pagination/filterCompiler.ts +196 -0
  190. package/src/pagination/index.ts +1 -3
  191. package/src/pagination/paginators/BasePaginator.ts +2859 -0
  192. package/src/pagination/paginators/ChannelPaginator.ts +729 -0
  193. package/src/pagination/paginators/MessageIntervalPaginator.ts +1116 -0
  194. package/src/pagination/paginators/MessagePaginator.ts +508 -0
  195. package/src/pagination/paginators/PinnedMessagePaginator.ts +108 -0
  196. package/src/pagination/paginators/ReminderPaginator.ts +107 -0
  197. package/src/pagination/paginators/UserGroupPaginator.ts +127 -0
  198. package/src/pagination/paginators/index.ts +7 -0
  199. package/src/pagination/paginators/stateThrottling.ts +31 -0
  200. package/src/pagination/sortCompiler.ts +193 -0
  201. package/src/pagination/types.normalization.ts +14 -0
  202. package/src/pagination/utility.normalization.ts +106 -0
  203. package/src/pagination/utility.queryChannel.ts +84 -0
  204. package/src/pagination/utility.search.ts +80 -0
  205. package/src/permissions.ts +7 -8
  206. package/src/poll.ts +101 -110
  207. package/src/poll_manager.ts +14 -8
  208. package/src/reminders/Reminder.ts +2 -5
  209. package/src/reminders/ReminderManager.ts +19 -21
  210. package/src/search/BaseSearchSource.ts +0 -3
  211. package/src/search/ChannelMemberSearchSource.ts +7 -1
  212. package/src/search/ChannelSearchSource.ts +10 -3
  213. package/src/search/MessageSearchSource.ts +29 -30
  214. package/src/search/UserSearchSource.ts +12 -8
  215. package/src/search/types.ts +3 -4
  216. package/src/segment.ts +1 -95
  217. package/src/signing.ts +107 -67
  218. package/src/store.ts +2 -1
  219. package/src/thread.ts +562 -238
  220. package/src/thread_manager.ts +37 -16
  221. package/src/token_manager.ts +21 -10
  222. package/src/types.ts +364 -4533
  223. package/src/uploadManager.ts +8 -0
  224. package/src/utils/FixedSizeQueueCache.ts +12 -6
  225. package/src/utils/WithSubscriptions.ts +2 -1
  226. package/src/utils/concurrency.ts +4 -4
  227. package/src/utils/mergeWith/mergeWith.ts +3 -3
  228. package/src/utils/mergeWith/mergeWithCore.ts +140 -164
  229. package/src/utils/mergeWith/mergeWithDiff.ts +3 -3
  230. package/src/utils/retryable.ts +117 -0
  231. package/src/utils/throttling/throttle.ts +130 -0
  232. package/src/utils.ts +208 -754
  233. package/dist/types/channel_manager.d.ts +0 -122
  234. package/dist/types/events.d.ts +0 -72
  235. package/dist/types/pagination/BasePaginator.d.ts +0 -69
  236. package/dist/types/pagination/ReminderPaginator.d.ts +0 -16
  237. package/dist/types/pagination/UserGroupPaginator.d.ts +0 -21
  238. package/src/channel_manager.ts +0 -830
  239. package/src/events.ts +0 -75
  240. package/src/pagination/BasePaginator.ts +0 -184
  241. package/src/pagination/ReminderPaginator.ts +0 -56
  242. package/src/pagination/UserGroupPaginator.ts +0 -93
@@ -9,12 +9,12 @@ export type SearchSourceState<T = any> = {
9
9
  offset?: number;
10
10
  };
11
11
  export type SearchSourceOptions = {
12
- /** The number of milliseconds to debounce the search query. The default interval is 300ms. */
12
+ /** The number of milliseconds to debounce the search query (defaults to `300`). */
13
13
  debounceMs?: number;
14
14
  pageSize?: number;
15
- /** When true, the source can execute queries with an empty search string. Defaults to false. */
15
+ /** When `true`, the source can execute queries with an empty search string (defaults to `false`). */
16
16
  allowEmptySearchString?: boolean;
17
- /** When true, previously loaded items are cleared at the start of a new search query. Defaults to true. */
17
+ /** When `true`, previously loaded items are cleared at the start of a new search query (defaults to `true`). */
18
18
  resetOnNewSearchQuery?: boolean;
19
19
  };
20
20
  export type SearchSourceType = 'channels' | 'users' | 'messages' | (string & {});
@@ -1,34 +0,0 @@
1
- import type { StreamChat } from './client';
2
- import type { QuerySegmentTargetsFilter, SegmentData, SegmentResponse, SortParam } from './types';
3
- type SegmentType = 'user' | 'channel';
4
- type SegmentUpdatableFields = {
5
- description?: string;
6
- filter?: {};
7
- name?: string;
8
- };
9
- export declare class Segment {
10
- type: SegmentType;
11
- id: string | null;
12
- client: StreamChat;
13
- data?: SegmentData | SegmentResponse;
14
- constructor(client: StreamChat, type: SegmentType, id: string | null, data?: SegmentData);
15
- create(): Promise<{
16
- segment: SegmentResponse;
17
- }>;
18
- verifySegmentId(): void;
19
- get(): Promise<{
20
- segment: SegmentResponse;
21
- } & import("./types").APIResponse>;
22
- update(data: Partial<SegmentUpdatableFields>): Promise<{
23
- segment: SegmentResponse;
24
- }>;
25
- addTargets(targets: string[]): Promise<import("./types").APIResponse>;
26
- removeTargets(targets: string[]): Promise<import("./types").APIResponse>;
27
- delete(): Promise<import("./types").APIResponse>;
28
- targetExists(targetId: string): Promise<import("./types").APIResponse>;
29
- queryTargets(filter?: QuerySegmentTargetsFilter | null, sort?: SortParam[] | null | [], options?: {}): Promise<{
30
- targets: import("./types").SegmentTargetsResponse[];
31
- next?: string;
32
- } & import("./types").APIResponse>;
33
- }
34
- export {};
@@ -1,42 +1,64 @@
1
1
  import jwt from 'jsonwebtoken';
2
- import type { Event, UR } from './types';
2
+ import type { UR } from './types';
3
+ import type { WSEvent } from './gen/models';
3
4
  /**
4
- * Creates the JWT token that can be used for a UserSession
5
- * @method JWTUserToken
6
- * @memberof signing
7
- * @private
8
- * @param {Secret} apiSecret - API Secret key
9
- * @param {string} userId - The user_id key in the JWT payload
10
- * @param {UR} [extraData] - Extra that should be part of the JWT token
11
- * @param {SignOptions} [jwtOptions] - Options that can be past to jwt.sign
12
- * @return {string} JWT Token
5
+ * Creates the JWT token that can be used for a user session.
6
+ *
7
+ * @param apiSecret - API secret key.
8
+ * @param userId - The `user_id` key in the JWT payload.
9
+ * @param extraData - Extra data that should be part of the JWT token (optional, defaults to `{}`).
10
+ * @param jwtOptions - Options that can be passed to `jwt.sign` (optional, defaults to `{}`).
11
+ * @returns The signed JWT token.
13
12
  */
14
13
  export declare function JWTUserToken(apiSecret: jwt.Secret, userId: string, extraData?: UR, jwtOptions?: jwt.SignOptions): string;
14
+ /**
15
+ * Creates the JWT token that can be used for a server-side session.
16
+ *
17
+ * @param apiSecret - API secret key.
18
+ * @param jwtOptions - Options that can be passed to `jwt.sign` (optional, defaults to `{}`).
19
+ * @returns The signed JWT token.
20
+ */
15
21
  export declare function JWTServerToken(apiSecret: jwt.Secret, jwtOptions?: jwt.SignOptions): string;
22
+ /**
23
+ * Decodes a JWT token and returns the embedded `user_id`.
24
+ *
25
+ * @param token - The JWT token to decode.
26
+ * @returns The `user_id` extracted from the token's payload, or an empty string when the token is malformed.
27
+ */
16
28
  export declare function UserFromToken(token: string): string;
17
29
  /**
30
+ * Generates a development token for the given user.
31
+ *
32
+ * Development tokens are unsigned and must only be used in environments where token validation is disabled.
18
33
  *
19
- * @param {string} userId the id of the user
20
- * @return {string}
34
+ * @param userId - The ID of the user.
35
+ * @returns The development token.
21
36
  */
22
37
  export declare function DevToken(userId: string): string;
23
38
  /**
24
- * Constant-time HMAC-SHA256 verification of `signature` against the
25
- * digest of `body` using `secret` as the key. The signature is always
26
- * computed over the **uncompressed** JSON bytes, so callers that
27
- * decoded a gzipped or base64-wrapped payload must pass the inflated
28
- * bytes here.
29
- *
30
- * The legacy `client.verifyWebhook` helper wraps this function, so
31
- * callers that have already migrated to `verifyAndParseWebhook`,
32
- * `parseSqs`, or `parseSns` rarely need to invoke this
33
- * directly.
39
+ * Constant-time HMAC-SHA256 verification of `signature` against the digest of `body` using `secret`
40
+ * as the key. The signature is always computed over the **uncompressed** JSON bytes, so callers that
41
+ * decoded a gzipped or base64-wrapped payload must pass the inflated bytes here.
42
+ *
43
+ * The legacy `client.verifyWebhook` helper wraps this function, so callers that have already
44
+ * migrated to {@link verifyAndParseWebhook}, {@link parseSqs}, or {@link parseSns} rarely need to
45
+ * invoke this directly.
46
+ *
47
+ * @param body - The uncompressed payload bytes that Stream signed.
48
+ * @param signature - The HMAC-SHA256 signature delivered alongside the payload.
49
+ * @param secret - Your app's API secret used as the HMAC key.
50
+ * @returns `true` when the signature matches the digest of `body`, otherwise `false`.
34
51
  */
35
52
  export declare function verifySignature(body: string | Buffer, signature: string, secret: string): boolean;
36
53
  /**
37
- * @deprecated Use {@link verifySignature} - same logic, parameters
38
- * reordered to match the cross-SDK contract
39
- * (`verifySignature(body, signature, secret)`).
54
+ * Verifies an HMAC-SHA256 signature with the legacy parameter order.
55
+ *
56
+ * @param body - The uncompressed payload bytes that Stream signed.
57
+ * @param secret - Your app's API secret used as the HMAC key.
58
+ * @param signature - The HMAC-SHA256 signature delivered alongside the payload.
59
+ * @returns `true` when the signature matches the digest of `body`, otherwise `false`.
60
+ * @deprecated Use {@link verifySignature} instead — same logic, parameters reordered to match the
61
+ * cross-SDK contract (`verifySignature(body, signature, secret)`).
40
62
  */
41
63
  export declare function CheckSignature(body: string | Buffer, secret: string, signature: string): boolean;
42
64
  /**
@@ -65,60 +87,78 @@ export declare class InvalidWebhookError extends Error {
65
87
  constructor(message?: string);
66
88
  }
67
89
  /**
68
- * Returns `body` as a `Buffer`, gzip-decompressed when its first two
69
- * bytes match the gzip magic (`1f 8b`, per RFC 1952). When the body is
70
- * plain JSON (no compression, or middleware already decompressed), the
71
- * bytes are returned unchanged.
72
- *
73
- * Magic-byte detection (rather than relying on a header) keeps the
74
- * same handler correct when middleware - Express, Next.js, AWS Lambda
75
- * - auto-decompresses the request before your code sees it.
90
+ * Returns `body` as a `Buffer`, gzip-decompressed when its first two bytes match the gzip magic
91
+ * (`1f 8b`, per RFC 1952). When the body is plain JSON (no compression, or middleware already
92
+ * decompressed), the bytes are returned unchanged.
93
+ *
94
+ * Magic-byte detection (rather than relying on a header) keeps the same handler correct when
95
+ * middleware — Express, Next.js, AWS Lambda — auto-decompresses the request before your code sees it.
96
+ *
97
+ * @param rawBody - The raw HTTP request body, either as a string or a `Buffer`.
98
+ * @returns The uncompressed payload bytes.
99
+ * @throws {@link InvalidWebhookError} when the gzip envelope is malformed.
76
100
  */
77
101
  export declare function gunzipPayload(rawBody: string | Buffer): Buffer;
78
102
  /**
79
- * Reverses the SQS firehose envelope: the message `Body` is
80
- * base64-decoded, then the result is gzip-decompressed when it begins
81
- * with the gzip magic. Returns the raw JSON `Buffer` Stream signed.
103
+ * Reverses the SQS firehose envelope: the message `Body` is base64-decoded, then the result is
104
+ * gzip-decompressed when it begins with the gzip magic. Returns the raw JSON `Buffer` Stream signed.
82
105
  *
83
- * SQS bodies are always base64-encoded so they remain valid UTF-8 over
84
- * the queue. The same call works whether or not Stream is currently
85
- * compressing payloads for this app.
106
+ * SQS bodies are always base64-encoded so they remain valid UTF-8 over the queue. The same call
107
+ * works whether or not Stream is currently compressing payloads for this app.
108
+ *
109
+ * @param body - The base64-encoded SQS message body.
110
+ * @returns The decoded (and decompressed, when gzipped) payload bytes.
111
+ * @throws {@link InvalidWebhookError} when the body is not canonical base64 or the gzip envelope is malformed.
86
112
  */
87
113
  export declare function decodeSqsPayload(body: string): Buffer;
88
114
  /**
89
- * Reverses an SNS HTTP notification envelope. When `notificationBody`
90
- * is a JSON envelope (`{"Type":"Notification","Message":"..."}`), the
91
- * inner `Message` field is extracted and run through the SQS pipeline
92
- * (base64-decode, then gzip-if-magic). When the input is not a JSON
93
- * envelope it is treated as the already-extracted `Message` string,
94
- * so call sites that pre-unwrap continue to work.
115
+ * Reverses an SNS HTTP notification envelope. When `notificationBody` is a JSON envelope
116
+ * (`{"Type":"Notification","MessageRequest":"..."}`), the inner `MessageRequest` field is extracted and run
117
+ * through the SQS pipeline (base64-decode, then gzip-if-magic). When the input is not a JSON
118
+ * envelope it is treated as the already-extracted `MessageRequest` string, so call sites that pre-unwrap
119
+ * continue to work.
120
+ *
121
+ * @param notificationBody - The raw SNS notification body, or a pre-extracted `MessageRequest` string.
122
+ * @returns The decoded (and decompressed, when gzipped) payload bytes.
123
+ * @throws {@link InvalidWebhookError} when the body is not canonical base64 or the gzip envelope is malformed.
95
124
  */
96
125
  export declare function decodeSnsPayload(notificationBody: string): Buffer;
97
126
  /**
98
- * Parse a JSON-encoded webhook event into a typed {@link Event}. New
99
- * event types Stream introduces still parse successfully - the runtime
100
- * shape is the JSON Stream sent and the `type` field stays preserved.
127
+ * Parses a JSON-encoded webhook event into a typed {@link WSEvent}. New event types Stream
128
+ * introduces still parse successfully — the runtime shape is the JSON Stream sent and the `type`
129
+ * field stays preserved.
130
+ *
131
+ * @param payload - The raw event payload bytes or string.
132
+ * @returns The parsed WebSocket event.
133
+ * @throws {@link InvalidWebhookError} when the payload is not valid JSON.
101
134
  */
102
- export declare function parseEvent(payload: Buffer | string): Event;
135
+ export declare function parseEvent(payload: Buffer | string): WSEvent;
103
136
  /**
104
- * Decompress (when gzipped), verify the HMAC `signature`, and return
105
- * the parsed {@link Event}.
106
- *
107
- * @param rawBody Raw HTTP request body bytes Stream signed
108
- * @param signature Value of the `X-Signature` header
109
- * @param secret Your app's API secret
110
- * @throws {InvalidWebhookError} When the signature does not match or
111
- * the gzip envelope is malformed.
137
+ * Decompress (when gzipped), verify the HMAC `signature`, and return the parsed {@link WSEvent}.
138
+ *
139
+ * @param rawBody - Raw HTTP request body bytes Stream signed.
140
+ * @param signature - Value of the `X-Signature` header.
141
+ * @param secret - Your app's API secret.
142
+ * @returns The parsed WebSocket event.
143
+ * @throws {@link InvalidWebhookError} when the signature does not match or the gzip envelope is malformed.
112
144
  */
113
- export declare function verifyAndParseWebhook(rawBody: string | Buffer, signature: string, secret: string): Event;
145
+ export declare function verifyAndParseWebhook(rawBody: string | Buffer, signature: string, secret: string): WSEvent;
114
146
  /**
115
- * Decode the SQS message `Body` (base64, then gzip-if-magic) and return
116
- * the parsed {@link Event}. Stream does not attach an application-level HMAC
117
- * to SQS deliveries — use {@link verifyAndParseWebhook} for HTTP webhooks.
147
+ * Decodes the SQS message `Body` (base64, then gzip-if-magic) and returns the parsed {@link WSEvent}.
148
+ * Stream does not attach an application-level HMAC to SQS deliveries — use
149
+ * {@link verifyAndParseWebhook} for HTTP webhooks.
150
+ *
151
+ * @param messageBody - The base64-encoded SQS message body.
152
+ * @returns The parsed WebSocket event.
153
+ * @throws {@link InvalidWebhookError} when the body is malformed.
118
154
  */
119
- export declare function parseSqs(messageBody: string): Event;
155
+ export declare function parseSqs(messageBody: string): WSEvent;
120
156
  /**
121
- * Decode an SNS notification (unwrap the JSON envelope when needed; same
122
- * inner format as SQS). No application-level HMAC verification.
157
+ * Decodes an SNS notification (unwraps the JSON envelope when needed; same inner format as SQS).
158
+ * No application-level HMAC verification.
159
+ *
160
+ * @param notificationBody - The raw SNS notification body, or a pre-extracted `MessageRequest` string.
161
+ * @returns The parsed WebSocket event.
162
+ * @throws {@link InvalidWebhookError} when the body is malformed.
123
163
  */
124
- export declare function parseSns(notificationBody: string): Event;
164
+ export declare function parseSns(notificationBody: string): WSEvent;
@@ -12,6 +12,7 @@ export declare class StateStore<T extends Record<string, unknown>> {
12
12
  constructor(value: T);
13
13
  /**
14
14
  * Allows merging two stores only if their keys differ otherwise there's no way to ensure the data type stability.
15
+ *
15
16
  * @experimental
16
17
  * This method is experimental and may change in future versions.
17
18
  */
@@ -1,18 +1,12 @@
1
1
  import { StateStore } from './store';
2
- import type { AscDesc, LocalMessage, MessagePaginationOptions, MessageResponse, ThreadResponse, UserResponse } from './types';
3
- import type { Channel } from './channel';
2
+ import type { DraftResponse, EventAPIResponse, LocalMessage, MarkReadRequest, MessageResponse, ReactionRequest, SendReactionRequest, ThreadStateResponse, UserResponse } from './types';
3
+ import type { Channel, DeleteMessageWithStateUpdateParams, SendMessageWithStateUpdateParams, UpdateMessageWithStateUpdateParams } from './channel';
4
4
  import type { StreamChat } from './client';
5
5
  import type { CustomThreadData } from './custom_types';
6
6
  import { MessageComposer } from './messageComposer';
7
+ import { MessageOperations } from './messageOperations';
7
8
  import { WithSubscriptions } from './utils/WithSubscriptions';
8
- type QueryRepliesOptions = {
9
- sort?: {
10
- created_at: AscDesc;
11
- }[];
12
- } & MessagePaginationOptions & {
13
- user?: UserResponse;
14
- user_id?: string;
15
- };
9
+ import { MessagePaginator } from './pagination';
16
10
  export type ThreadState = {
17
11
  /**
18
12
  * Determines if the thread is currently opened and on-screen. When the thread is active,
@@ -25,25 +19,17 @@ export type ThreadState = {
25
19
  deletedAt: Date | null;
26
20
  isLoading: boolean;
27
21
  isStateStale: boolean;
28
- pagination: ThreadRepliesPagination;
29
22
  /**
30
23
  * Thread is identified by and has a one-to-one relation with its parent message.
31
24
  * We use parent message id as a thread id.
32
25
  */
33
26
  parentMessage: LocalMessage;
34
- participants: ThreadResponse['thread_participants'];
27
+ participants: ThreadStateResponse['thread_participants'];
35
28
  read: ThreadReadState;
36
- replies: Array<LocalMessage>;
37
29
  replyCount: number;
38
30
  title: string;
39
31
  updatedAt: Date | null;
40
32
  };
41
- export type ThreadRepliesPagination = {
42
- isLoadingNext: boolean;
43
- isLoadingPrev: boolean;
44
- nextCursor: string | null;
45
- prevCursor: string | null;
46
- };
47
33
  export type ThreadUserReadState = {
48
34
  lastReadAt: Date;
49
35
  unreadMessageCount: number;
@@ -52,16 +38,30 @@ export type ThreadUserReadState = {
52
38
  firstUnreadMessageId?: string;
53
39
  };
54
40
  export type ThreadReadState = Record<string, ThreadUserReadState | undefined>;
55
- export declare const THREAD_RESPONSE_RESERVED_KEYS: Record<keyof ThreadResponse, true>;
41
+ export type CustomThreadMarkReadRequestFn = (params: {
42
+ thread: Thread;
43
+ options?: MarkReadRequest;
44
+ }) => Promise<EventAPIResponse | null> | void;
45
+ export type ThreadInstanceConfig = {
46
+ requestHandlers?: {
47
+ markReadRequest?: CustomThreadMarkReadRequestFn;
48
+ };
49
+ };
56
50
  export declare class Thread extends WithSubscriptions {
51
+ readonly configState: StateStore<ThreadInstanceConfig>;
57
52
  readonly state: StateStore<ThreadState>;
58
53
  readonly id: string;
59
54
  readonly messageComposer: MessageComposer;
55
+ readonly messagePaginator: MessagePaginator;
56
+ readonly messageOperations: MessageOperations;
60
57
  private client;
61
58
  private failedRepliesMap;
62
- constructor({ client, threadData, }: {
59
+ constructor({ client, threadData, channel, parentMessage, draft, }: {
63
60
  client: StreamChat;
64
- threadData: ThreadResponse;
61
+ threadData?: ThreadStateResponse;
62
+ channel?: Channel;
63
+ parentMessage?: MessageResponse | LocalMessage;
64
+ draft?: DraftResponse;
65
65
  });
66
66
  get channel(): Channel;
67
67
  get hasStaleState(): boolean;
@@ -80,11 +80,13 @@ export declare class Thread extends WithSubscriptions {
80
80
  private subscribeRepliesRead;
81
81
  private subscribeMessageDeleted;
82
82
  private subscribeMessageUpdated;
83
+ private subscribeUserMessagesDeleted;
84
+ private subscribeParentMessageFromStore;
83
85
  unregisterSubscriptions: () => symbol;
84
86
  deleteReplyLocally: ({ message }: {
85
87
  message: MessageResponse;
86
88
  }) => void;
87
- upsertReplyLocally: ({ message, timestampChanged, }: {
89
+ upsertReplyLocally: ({ message, }: {
88
90
  message: MessageResponse | LocalMessage;
89
91
  timestampChanged?: boolean;
90
92
  }) => void;
@@ -92,17 +94,51 @@ export declare class Thread extends WithSubscriptions {
92
94
  message: MessageResponse;
93
95
  }) => void;
94
96
  updateParentMessageOrReplyLocally: (message: MessageResponse) => void;
97
+ /**
98
+ * Sends a message with optimistic local state update.
99
+ */
100
+ sendMessageWithLocalUpdate({ localMessage, message, options, sendMessageRequestFn, }: SendMessageWithStateUpdateParams): Promise<void>;
101
+ /**
102
+ * Retry sending a failed message.
103
+ */
104
+ retrySendMessageWithLocalUpdate(params: Omit<SendMessageWithStateUpdateParams, 'message'>): Promise<void>;
105
+ /**
106
+ * Updates a message with optimistic local state update.
107
+ *
108
+ * The update flows through `messagePaginator`, which is the sole reply source.
109
+ */
110
+ updateMessageWithLocalUpdate(params: UpdateMessageWithStateUpdateParams): Promise<void>;
111
+ /**
112
+ * Deletes a message with local state update.
113
+ */
114
+ deleteMessageWithLocalUpdate(params: DeleteMessageWithStateUpdateParams): Promise<void>;
115
+ /**
116
+ * Adds a reaction to a reply with an optimistic local state update, mirroring
117
+ * {@link Channel.addReactionWithLocalUpdate}. The optimistic message is applied to THIS thread's
118
+ * paginator (so pure replies get optimism the channel paginator can't give); the request routes
119
+ * through the parent channel since reactions are channel-level.
120
+ */
121
+ addReactionWithLocalUpdate({ messageId, reaction, options, }: {
122
+ messageId: string;
123
+ reaction: ReactionRequest;
124
+ options?: Pick<SendReactionRequest, 'enforce_unique' | 'skip_push'>;
125
+ }): Promise<void>;
126
+ /**
127
+ * Removes the current user's reaction from a reply with an optimistic local state update,
128
+ * mirroring {@link Thread.addReactionWithLocalUpdate}.
129
+ */
130
+ deleteReactionWithLocalUpdate({ messageId, type, }: {
131
+ messageId: string;
132
+ type: string;
133
+ }): Promise<void>;
134
+ markRead: ({ force }?: {
135
+ force?: boolean;
136
+ }) => Promise<EventAPIResponse | import("./types").StreamResponse<import(".").MarkReadResponse> | null>;
137
+ private throttledMarkRead;
138
+ /**
139
+ * @deprecated Use `thread.markRead` instead.
140
+ */
95
141
  markAsRead: ({ force }?: {
96
142
  force?: boolean;
97
- }) => Promise<import("./types").EventAPIResponse | null>;
98
- private throttledMarkAsRead;
99
- queryReplies: ({ limit, sort, ...otherOptions }?: QueryRepliesOptions) => Promise<import("./types").GetRepliesAPIResponse>;
100
- loadNextPage: ({ limit }?: {
101
- limit?: number;
102
- }) => Promise<void>;
103
- loadPrevPage: ({ limit }?: {
104
- limit?: number;
105
- }) => Promise<void>;
106
- private loadPage;
143
+ }) => Promise<EventAPIResponse | import("./types").StreamResponse<import(".").MarkReadResponse> | null>;
107
144
  }
108
- export {};
@@ -1,7 +1,7 @@
1
1
  import { StateStore } from './store';
2
2
  import type { StreamChat } from './client';
3
3
  import type { Thread } from './thread';
4
- import type { QueryThreadsOptions } from './types';
4
+ import type { QueryThreadsRequest } from './types';
5
5
  import { WithSubscriptions } from './utils/WithSubscriptions';
6
6
  export declare const THREAD_MANAGER_INITIAL_STATE: {
7
7
  active: boolean;
@@ -65,9 +65,9 @@ export declare class ThreadManager extends WithSubscriptions {
65
65
  reload: ({ force }?: {
66
66
  force?: boolean | undefined;
67
67
  }) => Promise<void>;
68
- queryThreads: (options?: QueryThreadsOptions) => Promise<{
68
+ queryThreads: (options?: QueryThreadsRequest) => Promise<{
69
69
  threads: Thread[];
70
70
  next: string | undefined;
71
71
  }>;
72
- loadNextPage: (options?: Omit<QueryThreadsOptions, "next">) => Promise<void>;
72
+ loadNextPage: (options?: Omit<QueryThreadsRequest, "next">) => Promise<void>;
73
73
  }
@@ -1,5 +1,9 @@
1
1
  import type jwt from 'jsonwebtoken';
2
- import type { TokenOrProvider, UserResponse } from './types';
2
+ import type { TokenOrProvider } from './types';
3
+ export type TokenManagerMinimalUser = {
4
+ id: string;
5
+ anon?: boolean;
6
+ };
3
7
  /**
4
8
  * TokenManager
5
9
  *
@@ -11,27 +15,28 @@ export declare class TokenManager {
11
15
  secret?: jwt.Secret;
12
16
  token?: string;
13
17
  tokenProvider?: TokenOrProvider;
14
- user?: UserResponse;
18
+ user?: TokenManagerMinimalUser;
15
19
  /**
16
- * Constructor
20
+ * Initializes the token manager, optionally with a server-side API secret used to mint tokens
21
+ * locally.
17
22
  *
18
- * @param {Secret} secret
23
+ * @param secret - Optional API secret. When provided, the manager will sign server tokens locally.
19
24
  */
20
25
  constructor(secret?: jwt.Secret);
21
26
  /**
22
- * Set the static string token or token provider.
23
- * Token provider should return a token string or a promise which resolves to string token.
27
+ * Sets the static string token or token provider. A token provider should return a token string
28
+ * or a promise that resolves to a token string.
24
29
  *
25
- * @param {TokenOrProvider} tokenOrProvider
26
- * @param {UserResponse} user
30
+ * @param tokenOrProvider - A token string or an async provider that returns one.
31
+ * @param user - The user the token belongs to.
27
32
  */
28
- setTokenOrProvider: (tokenOrProvider: TokenOrProvider, user: UserResponse) => Promise<void>;
33
+ setTokenOrProvider: (tokenOrProvider: TokenOrProvider, user: TokenManagerMinimalUser) => Promise<void>;
29
34
  /**
30
35
  * Resets the token manager.
31
36
  * Useful for client disconnection or switching user.
32
37
  */
33
38
  reset: () => void;
34
- validateToken: (tokenOrProvider: TokenOrProvider, user: UserResponse) => void;
39
+ validateToken: (tokenOrProvider: TokenOrProvider, user: TokenManagerMinimalUser) => void;
35
40
  tokenReady: () => Promise<string> | null;
36
41
  loadToken: () => Promise<string>;
37
42
  getToken: () => string | undefined;