@stream-io/node-sdk 0.9.2 → 0.9.4
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/CHANGELOG.md +14 -0
- package/dist/index.cjs.js +24 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.es.mjs +24 -6
- package/dist/index.es.mjs.map +1 -1
- package/dist/src/gen/models/index.d.ts +4 -0
- package/dist/src/utils/webhook.d.ts +15 -0
- package/index.ts +1 -0
- package/package.json +1 -1
- package/src/gen/feeds/FeedsApi.ts +1 -0
- package/src/gen/models/index.ts +4 -0
- package/src/utils/webhook.ts +24 -2
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))
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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.
|
|
4827
|
+
"X-Stream-Client": "stream-node-0.9.4",
|
|
4811
4828
|
"Accept-Encoding": "gzip",
|
|
4812
4829
|
"x-client-request-id": clientRequestId
|
|
4813
4830
|
};
|
|
@@ -5680,6 +5697,7 @@ var FeedsApi = class {
|
|
|
5680
5697
|
next: request?.next,
|
|
5681
5698
|
overwrite_interest_weights: request?.overwrite_interest_weights,
|
|
5682
5699
|
prev: request?.prev,
|
|
5700
|
+
skip_feed_creation: request?.skip_feed_creation,
|
|
5683
5701
|
user_id: request?.user_id,
|
|
5684
5702
|
view: request?.view,
|
|
5685
5703
|
watch: request?.watch,
|
|
@@ -6906,6 +6924,6 @@ var convertTimestampToDate = (timestamp) => {
|
|
|
6906
6924
|
if (timestamp == null || !Number.isFinite(timestamp)) return void 0;
|
|
6907
6925
|
return nsToDate(timestamp);
|
|
6908
6926
|
};
|
|
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 };
|
|
6927
|
+
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
6928
|
|
|
6911
6929
|
//# sourceMappingURL=index.es.mjs.map
|