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
package/src/signing.ts CHANGED
@@ -2,18 +2,17 @@ import jwt from 'jsonwebtoken';
2
2
  import crypto from 'crypto';
3
3
  import zlib from 'zlib';
4
4
  import { decodeBase64, encodeBase64 } from './base64';
5
- import type { Event, UR } from './types';
5
+ import type { UR } from './types';
6
+ import type { WSEvent } from './gen/models';
6
7
 
7
8
  /**
8
- * Creates the JWT token that can be used for a UserSession
9
- * @method JWTUserToken
10
- * @memberof signing
11
- * @private
12
- * @param {Secret} apiSecret - API Secret key
13
- * @param {string} userId - The user_id key in the JWT payload
14
- * @param {UR} [extraData] - Extra that should be part of the JWT token
15
- * @param {SignOptions} [jwtOptions] - Options that can be past to jwt.sign
16
- * @return {string} JWT Token
9
+ * Creates the JWT token that can be used for a user session.
10
+ *
11
+ * @param apiSecret - API secret key.
12
+ * @param userId - The `user_id` key in the JWT payload.
13
+ * @param extraData - Extra data that should be part of the JWT token (optional, defaults to `{}`).
14
+ * @param jwtOptions - Options that can be passed to `jwt.sign` (optional, defaults to `{}`).
15
+ * @returns The signed JWT token.
17
16
  */
18
17
  export function JWTUserToken(
19
18
  apiSecret: jwt.Secret,
@@ -30,7 +29,7 @@ export function JWTUserToken(
30
29
  ...extraData,
31
30
  };
32
31
 
33
- // make sure we return a clear error when jwt is shimmed (ie. browser build)
32
+ // make sure we return a clear error when the JWT module is shimmed (i.e. browser build)
34
33
  if (jwt == null || jwt.sign == null) {
35
34
  throw Error(
36
35
  `Unable to find jwt crypto, if you are getting this error is probably because you are trying to generate tokens on browser or React Native (or other environment where crypto functions are not available). Please Note: token should only be generated server-side.`,
@@ -48,6 +47,13 @@ export function JWTUserToken(
48
47
  return jwt.sign(payload, apiSecret, opts);
49
48
  }
50
49
 
50
+ /**
51
+ * Creates the JWT token that can be used for a server-side session.
52
+ *
53
+ * @param apiSecret - API secret key.
54
+ * @param jwtOptions - Options that can be passed to `jwt.sign` (optional, defaults to `{}`).
55
+ * @returns The signed JWT token.
56
+ */
51
57
  export function JWTServerToken(apiSecret: jwt.Secret, jwtOptions: jwt.SignOptions = {}) {
52
58
  const payload = {
53
59
  server: true,
@@ -60,6 +66,12 @@ export function JWTServerToken(apiSecret: jwt.Secret, jwtOptions: jwt.SignOption
60
66
  return jwt.sign(payload, apiSecret, opts);
61
67
  }
62
68
 
69
+ /**
70
+ * Decodes a JWT token and returns the embedded `user_id`.
71
+ *
72
+ * @param token - The JWT token to decode.
73
+ * @returns The `user_id` extracted from the token's payload, or an empty string when the token is malformed.
74
+ */
63
75
  export function UserFromToken(token: string) {
64
76
  const fragments = token.split('.');
65
77
  if (fragments.length !== 3) {
@@ -72,9 +84,12 @@ export function UserFromToken(token: string) {
72
84
  }
73
85
 
74
86
  /**
87
+ * Generates a development token for the given user.
88
+ *
89
+ * Development tokens are unsigned and must only be used in environments where token validation is disabled.
75
90
  *
76
- * @param {string} userId the id of the user
77
- * @return {string}
91
+ * @param userId - The ID of the user.
92
+ * @returns The development token.
78
93
  */
79
94
  export function DevToken(userId: string) {
80
95
  return [
@@ -85,16 +100,18 @@ export function DevToken(userId: string) {
85
100
  }
86
101
 
87
102
  /**
88
- * Constant-time HMAC-SHA256 verification of `signature` against the
89
- * digest of `body` using `secret` as the key. The signature is always
90
- * computed over the **uncompressed** JSON bytes, so callers that
91
- * decoded a gzipped or base64-wrapped payload must pass the inflated
92
- * bytes here.
103
+ * Constant-time HMAC-SHA256 verification of `signature` against the digest of `body` using `secret`
104
+ * as the key. The signature is always computed over the **uncompressed** JSON bytes, so callers that
105
+ * decoded a gzipped or base64-wrapped payload must pass the inflated bytes here.
93
106
  *
94
- * The legacy `client.verifyWebhook` helper wraps this function, so
95
- * callers that have already migrated to `verifyAndParseWebhook`,
96
- * `parseSqs`, or `parseSns` rarely need to invoke this
97
- * directly.
107
+ * The legacy `client.verifyWebhook` helper wraps this function, so callers that have already
108
+ * migrated to {@link verifyAndParseWebhook}, {@link parseSqs}, or {@link parseSns} rarely need to
109
+ * invoke this directly.
110
+ *
111
+ * @param body - The uncompressed payload bytes that Stream signed.
112
+ * @param signature - The HMAC-SHA256 signature delivered alongside the payload.
113
+ * @param secret - Your app's API secret used as the HMAC key.
114
+ * @returns `true` when the signature matches the digest of `body`, otherwise `false`.
98
115
  */
99
116
  export function verifySignature(
100
117
  body: string | Buffer,
@@ -111,9 +128,14 @@ export function verifySignature(
111
128
  }
112
129
 
113
130
  /**
114
- * @deprecated Use {@link verifySignature} - same logic, parameters
115
- * reordered to match the cross-SDK contract
116
- * (`verifySignature(body, signature, secret)`).
131
+ * Verifies an HMAC-SHA256 signature with the legacy parameter order.
132
+ *
133
+ * @param body - The uncompressed payload bytes that Stream signed.
134
+ * @param secret - Your app's API secret used as the HMAC key.
135
+ * @param signature - The HMAC-SHA256 signature delivered alongside the payload.
136
+ * @returns `true` when the signature matches the digest of `body`, otherwise `false`.
137
+ * @deprecated Use {@link verifySignature} instead — same logic, parameters reordered to match the
138
+ * cross-SDK contract (`verifySignature(body, signature, secret)`).
117
139
  */
118
140
  export function CheckSignature(body: string | Buffer, secret: string, signature: string) {
119
141
  return verifySignature(body, signature, secret);
@@ -150,14 +172,16 @@ export class InvalidWebhookError extends Error {
150
172
  }
151
173
 
152
174
  /**
153
- * Returns `body` as a `Buffer`, gzip-decompressed when its first two
154
- * bytes match the gzip magic (`1f 8b`, per RFC 1952). When the body is
155
- * plain JSON (no compression, or middleware already decompressed), the
156
- * bytes are returned unchanged.
175
+ * Returns `body` as a `Buffer`, gzip-decompressed when its first two bytes match the gzip magic
176
+ * (`1f 8b`, per RFC 1952). When the body is plain JSON (no compression, or middleware already
177
+ * decompressed), the bytes are returned unchanged.
157
178
  *
158
- * Magic-byte detection (rather than relying on a header) keeps the
159
- * same handler correct when middleware - Express, Next.js, AWS Lambda
160
- * - auto-decompresses the request before your code sees it.
179
+ * Magic-byte detection (rather than relying on a header) keeps the same handler correct when
180
+ * middleware — Express, Next.js, AWS Lambda — auto-decompresses the request before your code sees it.
181
+ *
182
+ * @param rawBody - The raw HTTP request body, either as a string or a `Buffer`.
183
+ * @returns The uncompressed payload bytes.
184
+ * @throws {@link InvalidWebhookError} when the gzip envelope is malformed.
161
185
  */
162
186
  export function gunzipPayload(rawBody: string | Buffer): Buffer {
163
187
  const GZIP_MAGIC = Buffer.from([0x1f, 0x8b]);
@@ -174,13 +198,15 @@ export function gunzipPayload(rawBody: string | Buffer): Buffer {
174
198
  }
175
199
 
176
200
  /**
177
- * Reverses the SQS firehose envelope: the message `Body` is
178
- * base64-decoded, then the result is gzip-decompressed when it begins
179
- * with the gzip magic. Returns the raw JSON `Buffer` Stream signed.
201
+ * Reverses the SQS firehose envelope: the message `Body` is base64-decoded, then the result is
202
+ * gzip-decompressed when it begins with the gzip magic. Returns the raw JSON `Buffer` Stream signed.
203
+ *
204
+ * SQS bodies are always base64-encoded so they remain valid UTF-8 over the queue. The same call
205
+ * works whether or not Stream is currently compressing payloads for this app.
180
206
  *
181
- * SQS bodies are always base64-encoded so they remain valid UTF-8 over
182
- * the queue. The same call works whether or not Stream is currently
183
- * compressing payloads for this app.
207
+ * @param body - The base64-encoded SQS message body.
208
+ * @returns The decoded (and decompressed, when gzipped) payload bytes.
209
+ * @throws {@link InvalidWebhookError} when the body is not canonical base64 or the gzip envelope is malformed.
184
210
  */
185
211
  export function decodeSqsPayload(body: string): Buffer {
186
212
  // Reject anything that isn't canonical base64 up front. Node's base64
@@ -199,12 +225,15 @@ export function decodeSqsPayload(body: string): Buffer {
199
225
  }
200
226
 
201
227
  /**
202
- * Reverses an SNS HTTP notification envelope. When `notificationBody`
203
- * is a JSON envelope (`{"Type":"Notification","Message":"..."}`), the
204
- * inner `Message` field is extracted and run through the SQS pipeline
205
- * (base64-decode, then gzip-if-magic). When the input is not a JSON
206
- * envelope it is treated as the already-extracted `Message` string,
207
- * so call sites that pre-unwrap continue to work.
228
+ * Reverses an SNS HTTP notification envelope. When `notificationBody` is a JSON envelope
229
+ * (`{"Type":"Notification","MessageRequest":"..."}`), the inner `MessageRequest` field is extracted and run
230
+ * through the SQS pipeline (base64-decode, then gzip-if-magic). When the input is not a JSON
231
+ * envelope it is treated as the already-extracted `MessageRequest` string, so call sites that pre-unwrap
232
+ * continue to work.
233
+ *
234
+ * @param notificationBody - The raw SNS notification body, or a pre-extracted `MessageRequest` string.
235
+ * @returns The decoded (and decompressed, when gzipped) payload bytes.
236
+ * @throws {@link InvalidWebhookError} when the body is not canonical base64 or the gzip envelope is malformed.
208
237
  */
209
238
  export function decodeSnsPayload(notificationBody: string): Buffer {
210
239
  const inner = extractSnsMessage(notificationBody);
@@ -226,28 +255,32 @@ function extractSnsMessage(notificationBody: string): string | null {
226
255
  parsed === null ||
227
256
  typeof parsed !== 'object' ||
228
257
  Array.isArray(parsed) ||
229
- typeof (parsed as { Message?: unknown }).Message !== 'string'
258
+ typeof (parsed as { MessageRequest?: unknown }).MessageRequest !== 'string'
230
259
  ) {
231
260
  return null;
232
261
  }
233
- return (parsed as { Message: string }).Message;
262
+ return (parsed as { MessageRequest: string }).MessageRequest;
234
263
  }
235
264
 
236
265
  /**
237
- * Parse a JSON-encoded webhook event into a typed {@link Event}. New
238
- * event types Stream introduces still parse successfully - the runtime
239
- * shape is the JSON Stream sent and the `type` field stays preserved.
266
+ * Parses a JSON-encoded webhook event into a typed {@link WSEvent}. New event types Stream
267
+ * introduces still parse successfully — the runtime shape is the JSON Stream sent and the `type`
268
+ * field stays preserved.
269
+ *
270
+ * @param payload - The raw event payload bytes or string.
271
+ * @returns The parsed WebSocket event.
272
+ * @throws {@link InvalidWebhookError} when the payload is not valid JSON.
240
273
  */
241
- export function parseEvent(payload: Buffer | string): Event {
274
+ export function parseEvent(payload: Buffer | string): WSEvent {
242
275
  const text = Buffer.isBuffer(payload) ? payload.toString('utf8') : payload;
243
276
  try {
244
- return JSON.parse(text) as Event;
277
+ return JSON.parse(text) as WSEvent;
245
278
  } catch {
246
279
  throw new InvalidWebhookError(InvalidWebhookErrorMessages.invalidJson);
247
280
  }
248
281
  }
249
282
 
250
- function verifyAndParse(payload: Buffer, signature: string, secret: string): Event {
283
+ function verifyAndParse(payload: Buffer, signature: string, secret: string): WSEvent {
251
284
  if (!verifySignature(payload, signature, secret)) {
252
285
  throw new InvalidWebhookError(InvalidWebhookErrorMessages.signatureMismatch);
253
286
  }
@@ -255,36 +288,43 @@ function verifyAndParse(payload: Buffer, signature: string, secret: string): Eve
255
288
  }
256
289
 
257
290
  /**
258
- * Decompress (when gzipped), verify the HMAC `signature`, and return
259
- * the parsed {@link Event}.
291
+ * Decompress (when gzipped), verify the HMAC `signature`, and return the parsed {@link WSEvent}.
260
292
  *
261
- * @param rawBody Raw HTTP request body bytes Stream signed
262
- * @param signature Value of the `X-Signature` header
263
- * @param secret Your app's API secret
264
- * @throws {InvalidWebhookError} When the signature does not match or
265
- * the gzip envelope is malformed.
293
+ * @param rawBody - Raw HTTP request body bytes Stream signed.
294
+ * @param signature - Value of the `X-Signature` header.
295
+ * @param secret - Your app's API secret.
296
+ * @returns The parsed WebSocket event.
297
+ * @throws {@link InvalidWebhookError} when the signature does not match or the gzip envelope is malformed.
266
298
  */
267
299
  export function verifyAndParseWebhook(
268
300
  rawBody: string | Buffer,
269
301
  signature: string,
270
302
  secret: string,
271
- ): Event {
303
+ ): WSEvent {
272
304
  return verifyAndParse(gunzipPayload(rawBody), signature, secret);
273
305
  }
274
306
 
275
307
  /**
276
- * Decode the SQS message `Body` (base64, then gzip-if-magic) and return
277
- * the parsed {@link Event}. Stream does not attach an application-level HMAC
278
- * to SQS deliveries — use {@link verifyAndParseWebhook} for HTTP webhooks.
308
+ * Decodes the SQS message `Body` (base64, then gzip-if-magic) and returns the parsed {@link WSEvent}.
309
+ * Stream does not attach an application-level HMAC to SQS deliveries — use
310
+ * {@link verifyAndParseWebhook} for HTTP webhooks.
311
+ *
312
+ * @param messageBody - The base64-encoded SQS message body.
313
+ * @returns The parsed WebSocket event.
314
+ * @throws {@link InvalidWebhookError} when the body is malformed.
279
315
  */
280
- export function parseSqs(messageBody: string): Event {
316
+ export function parseSqs(messageBody: string): WSEvent {
281
317
  return parseEvent(decodeSqsPayload(messageBody));
282
318
  }
283
319
 
284
320
  /**
285
- * Decode an SNS notification (unwrap the JSON envelope when needed; same
286
- * inner format as SQS). No application-level HMAC verification.
321
+ * Decodes an SNS notification (unwraps the JSON envelope when needed; same inner format as SQS).
322
+ * No application-level HMAC verification.
323
+ *
324
+ * @param notificationBody - The raw SNS notification body, or a pre-extracted `MessageRequest` string.
325
+ * @returns The parsed WebSocket event.
326
+ * @throws {@link InvalidWebhookError} when the body is malformed.
287
327
  */
288
- export function parseSns(notificationBody: string): Event {
328
+ export function parseSns(notificationBody: string): WSEvent {
289
329
  return parseEvent(decodeSnsPayload(notificationBody));
290
330
  }
package/src/store.ts CHANGED
@@ -20,10 +20,11 @@ export class StateStore<T extends Record<string, unknown>> {
20
20
 
21
21
  /**
22
22
  * Allows merging two stores only if their keys differ otherwise there's no way to ensure the data type stability.
23
+ *
23
24
  * @experimental
24
25
  * This method is experimental and may change in future versions.
25
26
  */
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+
27
28
  public merge<Q extends StateStore<any>>(
28
29
  stateStore: Q extends StateStore<infer L>
29
30
  ? Extract<keyof T, keyof L> extends never