@stream-io/node-sdk 0.9.2 → 0.9.3

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/index.d.ts CHANGED
@@ -6,6 +6,6 @@ export * from './src/StreamVideoClient';
6
6
  export * from './src/gen/models';
7
7
  export * from './src/StreamFeedsClient';
8
8
  export * from './src/StreamFeed';
9
- export { InvalidWebhookError, InvalidWebhookErrorMessages, verifyAndParseWebhook, } from './src/utils/webhook';
9
+ export { InvalidWebhookError, InvalidWebhookErrorMessages, verifyAndParseWebhook, webhookConfig, } from './src/utils/webhook';
10
10
  export { convertTimestampToDate, dateToNs, msToNs, nowNs, NS_PER_MS, nsToDate, nsToMs, nsToRfc3339, } from './src/utils/time';
11
11
  export { StreamError } from './src/types';
package/dist/index.es.mjs CHANGED
@@ -50,6 +50,15 @@ var InvalidWebhookError = class extends Error {
50
50
  };
51
51
  var GZIP_MAGIC = Buffer.from([31, 139]);
52
52
  /**
53
+ * Webhook helper settings.
54
+ *
55
+ * `maxPayloadBytes` caps the decompressed size of a gzip webhook body
56
+ * (default 10 MiB). {@link gunzipPayload} runs before the signature
57
+ * check, so without a cap an unsigned gzip bomb could exhaust memory.
58
+ * Raise it if your events are larger.
59
+ */
60
+ var webhookConfig = { maxPayloadBytes: 10485760 };
61
+ /**
53
62
  * Returns `body` as a `Buffer`, gzip-decompressed when its first two
54
63
  * bytes match the gzip magic (`1f 8b`, per RFC 1952). When the body is
55
64
  * plain JSON (no compression, or middleware already decompressed), the
@@ -58,13 +67,21 @@ var GZIP_MAGIC = Buffer.from([31, 139]);
58
67
  * Magic-byte detection (rather than relying on a header) keeps the same
59
68
  * handler correct when middleware - Express, Next.js, AWS Lambda -
60
69
  * auto-decompresses the request before your code sees it.
70
+ *
71
+ * @throws {InvalidWebhookError} When the body has the gzip magic but is
72
+ * not valid gzip, or inflates to more than
73
+ * `webhookConfig.maxPayloadBytes`.
61
74
  */
62
75
  function gunzipPayload(rawBody) {
63
76
  const body = Buffer.isBuffer(rawBody) ? rawBody : Buffer.from(rawBody);
64
- if (body.length >= 2 && body.subarray(0, 2).equals(GZIP_MAGIC)) try {
65
- return zlib.gunzipSync(body);
66
- } catch {
67
- throw new InvalidWebhookError(InvalidWebhookErrorMessages.gzipFailed);
77
+ if (body.length >= 2 && body.subarray(0, 2).equals(GZIP_MAGIC)) {
78
+ const limit = webhookConfig.maxPayloadBytes;
79
+ try {
80
+ return zlib.gunzipSync(body, { maxOutputLength: limit });
81
+ } catch (err) {
82
+ if (err.code === "ERR_BUFFER_TOO_LARGE") throw new InvalidWebhookError(`${InvalidWebhookErrorMessages.gzipFailed}: payload exceeds ${limit} bytes`);
83
+ throw new InvalidWebhookError(InvalidWebhookErrorMessages.gzipFailed);
84
+ }
68
85
  }
69
86
  return body;
70
87
  }
@@ -4807,7 +4824,7 @@ var ApiClient = class {
4807
4824
  const headers = {
4808
4825
  Authorization: this.apiConfig.token,
4809
4826
  "stream-auth-type": "jwt",
4810
- "X-Stream-Client": "stream-node-0.9.2",
4827
+ "X-Stream-Client": "stream-node-0.9.3",
4811
4828
  "Accept-Encoding": "gzip",
4812
4829
  "x-client-request-id": clientRequestId
4813
4830
  };
@@ -6906,6 +6923,6 @@ var convertTimestampToDate = (timestamp) => {
6906
6923
  if (timestamp == null || !Number.isFinite(timestamp)) return void 0;
6907
6924
  return nsToDate(timestamp);
6908
6925
  };
6909
- export { ChannelOwnCapability, FeedOwnCapability, InvalidWebhookError, InvalidWebhookErrorMessages, NS_PER_MS, OwnCapability, StreamCall, StreamChannel, StreamChatClient, StreamClient, StreamError, StreamFeed, StreamFeedsClient, StreamVideoClient, convertTimestampToDate, dateToNs, msToNs, nowNs, nsToDate, nsToMs, nsToRfc3339, verifyAndParseWebhook };
6926
+ export { ChannelOwnCapability, FeedOwnCapability, InvalidWebhookError, InvalidWebhookErrorMessages, NS_PER_MS, OwnCapability, StreamCall, StreamChannel, StreamChatClient, StreamClient, StreamError, StreamFeed, StreamFeedsClient, StreamVideoClient, convertTimestampToDate, dateToNs, msToNs, nowNs, nsToDate, nsToMs, nsToRfc3339, verifyAndParseWebhook, webhookConfig };
6910
6927
 
6911
6928
  //# sourceMappingURL=index.es.mjs.map