@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
|
@@ -11556,6 +11556,10 @@ export interface GetOrCreateFeedRequest {
|
|
|
11556
11556
|
next?: string;
|
|
11557
11557
|
overwrite_interest_weights?: boolean;
|
|
11558
11558
|
prev?: string;
|
|
11559
|
+
/**
|
|
11560
|
+
* Default: false. When true, a missing feed returns 404 instead of being created. Cannot be combined with data.
|
|
11561
|
+
*/
|
|
11562
|
+
skip_feed_creation?: boolean;
|
|
11559
11563
|
user_id?: string;
|
|
11560
11564
|
view?: string;
|
|
11561
11565
|
watch?: boolean;
|
|
@@ -25,6 +25,17 @@ export declare class InvalidWebhookError extends Error {
|
|
|
25
25
|
name: string;
|
|
26
26
|
constructor(message?: string);
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Webhook helper settings.
|
|
30
|
+
*
|
|
31
|
+
* `maxPayloadBytes` caps the decompressed size of a gzip webhook body
|
|
32
|
+
* (default 10 MiB). {@link gunzipPayload} runs before the signature
|
|
33
|
+
* check, so without a cap an unsigned gzip bomb could exhaust memory.
|
|
34
|
+
* Raise it if your events are larger.
|
|
35
|
+
*/
|
|
36
|
+
export declare const webhookConfig: {
|
|
37
|
+
maxPayloadBytes: number;
|
|
38
|
+
};
|
|
28
39
|
/**
|
|
29
40
|
* Returns `body` as a `Buffer`, gzip-decompressed when its first two
|
|
30
41
|
* bytes match the gzip magic (`1f 8b`, per RFC 1952). When the body is
|
|
@@ -34,6 +45,10 @@ export declare class InvalidWebhookError extends Error {
|
|
|
34
45
|
* Magic-byte detection (rather than relying on a header) keeps the same
|
|
35
46
|
* handler correct when middleware - Express, Next.js, AWS Lambda -
|
|
36
47
|
* auto-decompresses the request before your code sees it.
|
|
48
|
+
*
|
|
49
|
+
* @throws {InvalidWebhookError} When the body has the gzip magic but is
|
|
50
|
+
* not valid gzip, or inflates to more than
|
|
51
|
+
* `webhookConfig.maxPayloadBytes`.
|
|
37
52
|
*/
|
|
38
53
|
export declare function gunzipPayload(rawBody: string | Buffer): Buffer;
|
|
39
54
|
/**
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1852,6 +1852,7 @@ export class FeedsApi {
|
|
|
1852
1852
|
next: request?.next,
|
|
1853
1853
|
overwrite_interest_weights: request?.overwrite_interest_weights,
|
|
1854
1854
|
prev: request?.prev,
|
|
1855
|
+
skip_feed_creation: request?.skip_feed_creation,
|
|
1855
1856
|
user_id: request?.user_id,
|
|
1856
1857
|
view: request?.view,
|
|
1857
1858
|
watch: request?.watch,
|
package/src/gen/models/index.ts
CHANGED
|
@@ -12389,6 +12389,10 @@ export interface GetOrCreateFeedRequest {
|
|
|
12389
12389
|
next?: string;
|
|
12390
12390
|
overwrite_interest_weights?: boolean;
|
|
12391
12391
|
prev?: string;
|
|
12392
|
+
/**
|
|
12393
|
+
* Default: false. When true, a missing feed returns 404 instead of being created. Cannot be combined with data.
|
|
12394
|
+
*/
|
|
12395
|
+
skip_feed_creation?: boolean;
|
|
12392
12396
|
user_id?: string;
|
|
12393
12397
|
view?: string;
|
|
12394
12398
|
watch?: boolean;
|
package/src/utils/webhook.ts
CHANGED
|
@@ -35,6 +35,18 @@ export class InvalidWebhookError extends Error {
|
|
|
35
35
|
|
|
36
36
|
const GZIP_MAGIC = Buffer.from([0x1f, 0x8b]);
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Webhook helper settings.
|
|
40
|
+
*
|
|
41
|
+
* `maxPayloadBytes` caps the decompressed size of a gzip webhook body
|
|
42
|
+
* (default 10 MiB). {@link gunzipPayload} runs before the signature
|
|
43
|
+
* check, so without a cap an unsigned gzip bomb could exhaust memory.
|
|
44
|
+
* Raise it if your events are larger.
|
|
45
|
+
*/
|
|
46
|
+
export const webhookConfig = {
|
|
47
|
+
maxPayloadBytes: 10 * 1024 * 1024,
|
|
48
|
+
};
|
|
49
|
+
|
|
38
50
|
/**
|
|
39
51
|
* Returns `body` as a `Buffer`, gzip-decompressed when its first two
|
|
40
52
|
* bytes match the gzip magic (`1f 8b`, per RFC 1952). When the body is
|
|
@@ -44,13 +56,23 @@ const GZIP_MAGIC = Buffer.from([0x1f, 0x8b]);
|
|
|
44
56
|
* Magic-byte detection (rather than relying on a header) keeps the same
|
|
45
57
|
* handler correct when middleware - Express, Next.js, AWS Lambda -
|
|
46
58
|
* auto-decompresses the request before your code sees it.
|
|
59
|
+
*
|
|
60
|
+
* @throws {InvalidWebhookError} When the body has the gzip magic but is
|
|
61
|
+
* not valid gzip, or inflates to more than
|
|
62
|
+
* `webhookConfig.maxPayloadBytes`.
|
|
47
63
|
*/
|
|
48
64
|
export function gunzipPayload(rawBody: string | Buffer): Buffer {
|
|
49
65
|
const body = Buffer.isBuffer(rawBody) ? rawBody : Buffer.from(rawBody);
|
|
50
66
|
if (body.length >= 2 && body.subarray(0, 2).equals(GZIP_MAGIC)) {
|
|
67
|
+
const limit = webhookConfig.maxPayloadBytes;
|
|
51
68
|
try {
|
|
52
|
-
return zlib.gunzipSync(body);
|
|
53
|
-
} catch {
|
|
69
|
+
return zlib.gunzipSync(body, { maxOutputLength: limit });
|
|
70
|
+
} catch (err) {
|
|
71
|
+
if ((err as NodeJS.ErrnoException).code === 'ERR_BUFFER_TOO_LARGE') {
|
|
72
|
+
throw new InvalidWebhookError(
|
|
73
|
+
`${InvalidWebhookErrorMessages.gzipFailed}: payload exceeds ${limit} bytes`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
54
76
|
throw new InvalidWebhookError(InvalidWebhookErrorMessages.gzipFailed);
|
|
55
77
|
}
|
|
56
78
|
}
|