@stream-io/node-sdk 0.9.1 → 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/CHANGELOG.md +14 -0
- package/dist/index.cjs.js +173 -62
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.es.mjs +172 -61
- package/dist/index.es.mjs.map +1 -1
- package/dist/src/ApiClient.d.ts +1 -1
- package/dist/src/gen/chat/ChannelApi.d.ts +1 -0
- package/dist/src/gen/chat/ChatApi.d.ts +3 -1
- package/dist/src/gen/common/CommonApi.d.ts +4 -1
- package/dist/src/gen/feeds/FeedsApi.d.ts +1 -0
- package/dist/src/gen/models/index.d.ts +683 -17
- package/dist/src/gen/moderation/ModerationApi.d.ts +23 -1
- package/dist/src/utils/webhook.d.ts +15 -0
- package/index.ts +1 -0
- package/package.json +11 -11
- package/src/ApiClient.ts +5 -2
- package/src/gen/chat/ChannelApi.ts +1 -0
- package/src/gen/chat/ChatApi.ts +27 -0
- package/src/gen/common/CommonApi.ts +11 -2
- package/src/gen/feeds/FeedsApi.ts +2 -0
- package/src/gen/models/index.ts +772 -17
- package/src/gen/moderation/ModerationApi.ts +222 -0
- package/src/utils/webhook.ts +24 -2
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
CheckResponse,
|
|
20
20
|
CheckS3AccessRequest,
|
|
21
21
|
CheckS3AccessResponse,
|
|
22
|
+
CountReviewQueueRequest,
|
|
23
|
+
CountReviewQueueResponse,
|
|
22
24
|
CreatePolicyTestSetRequest,
|
|
23
25
|
CreateQueueRequest,
|
|
24
26
|
CustomCheckRequest,
|
|
@@ -31,8 +33,10 @@ import {
|
|
|
31
33
|
FlagItemResponse,
|
|
32
34
|
FlagRequest,
|
|
33
35
|
GetActionConfigResponse,
|
|
36
|
+
GetAgentReviewStatusResponse,
|
|
34
37
|
GetAppealResponse,
|
|
35
38
|
GetConfigResponse,
|
|
39
|
+
GetConfigVersionResponse,
|
|
36
40
|
GetFlagCountRequest,
|
|
37
41
|
GetFlagCountResponse,
|
|
38
42
|
GetModerationRuleResponse,
|
|
@@ -42,6 +46,8 @@ import {
|
|
|
42
46
|
InsertActionLogResponse,
|
|
43
47
|
LabelsRequest,
|
|
44
48
|
LabelsResponse,
|
|
49
|
+
ListAgentFeedbackResponse,
|
|
50
|
+
ListConfigVersionsResponse,
|
|
45
51
|
ListQueuesResponse,
|
|
46
52
|
ModerationBanResponse,
|
|
47
53
|
MuteRequest,
|
|
@@ -49,6 +55,8 @@ import {
|
|
|
49
55
|
PolicyTestRunResponse,
|
|
50
56
|
PolicyTestSetListResponse,
|
|
51
57
|
PolicyTestSetResponse,
|
|
58
|
+
PublishConfigVersionRequest,
|
|
59
|
+
PublishConfigVersionResponse,
|
|
52
60
|
QueryAppealsRequest,
|
|
53
61
|
QueryAppealsResponse,
|
|
54
62
|
QueryFeedModerationTemplatesResponse,
|
|
@@ -70,8 +78,12 @@ import {
|
|
|
70
78
|
Response,
|
|
71
79
|
RevealMediaRequest,
|
|
72
80
|
RevealMediaResponse,
|
|
81
|
+
SaveConfigVersionRequest,
|
|
82
|
+
SaveConfigVersionResponse,
|
|
73
83
|
SubmitActionRequest,
|
|
74
84
|
SubmitActionResponse,
|
|
85
|
+
SubmitAgentFeedbackRequest,
|
|
86
|
+
SubmitAgentFeedbackResponse,
|
|
75
87
|
SubmitModerationFeedbackRequest,
|
|
76
88
|
SubmitModerationFeedbackResponse,
|
|
77
89
|
UnbanRequest,
|
|
@@ -249,6 +261,70 @@ export class ModerationApi {
|
|
|
249
261
|
return response;
|
|
250
262
|
}
|
|
251
263
|
|
|
264
|
+
async listAgentFeedback(request?: {
|
|
265
|
+
limit?: number;
|
|
266
|
+
next?: string;
|
|
267
|
+
}): Promise<StreamResponse<ListAgentFeedbackResponse>> {
|
|
268
|
+
const queryParams = {
|
|
269
|
+
limit: request?.limit,
|
|
270
|
+
next: request?.next,
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const response =
|
|
274
|
+
await this.apiClient.sendRequest<ListAgentFeedbackResponse>(
|
|
275
|
+
'GET',
|
|
276
|
+
'/api/v2/moderation/agent_feedback',
|
|
277
|
+
undefined,
|
|
278
|
+
queryParams,
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
decoders['ListAgentFeedbackResponse']?.(response);
|
|
282
|
+
|
|
283
|
+
return response;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async submitAgentFeedback(
|
|
287
|
+
request: SubmitAgentFeedbackRequest,
|
|
288
|
+
): Promise<StreamResponse<SubmitAgentFeedbackResponse>> {
|
|
289
|
+
const body = {
|
|
290
|
+
item_id: request?.item_id,
|
|
291
|
+
moderator_action: request?.moderator_action,
|
|
292
|
+
improvement: request?.improvement,
|
|
293
|
+
reason: request?.reason,
|
|
294
|
+
user_id: request?.user_id,
|
|
295
|
+
user: request?.user,
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const response =
|
|
299
|
+
await this.apiClient.sendRequest<SubmitAgentFeedbackResponse>(
|
|
300
|
+
'POST',
|
|
301
|
+
'/api/v2/moderation/agent_feedback',
|
|
302
|
+
undefined,
|
|
303
|
+
undefined,
|
|
304
|
+
body,
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
decoders['SubmitAgentFeedbackResponse']?.(response);
|
|
308
|
+
|
|
309
|
+
return response;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async getAgentReviewStatus(): Promise<
|
|
313
|
+
StreamResponse<GetAgentReviewStatusResponse>
|
|
314
|
+
> {
|
|
315
|
+
const response =
|
|
316
|
+
await this.apiClient.sendRequest<GetAgentReviewStatusResponse>(
|
|
317
|
+
'GET',
|
|
318
|
+
'/api/v2/moderation/agent_review_status',
|
|
319
|
+
undefined,
|
|
320
|
+
undefined,
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
decoders['GetAgentReviewStatusResponse']?.(response);
|
|
324
|
+
|
|
325
|
+
return response;
|
|
326
|
+
}
|
|
327
|
+
|
|
252
328
|
async analyze(
|
|
253
329
|
request?: AnalyzeRequest,
|
|
254
330
|
): Promise<StreamResponse<AnalyzeResponse>> {
|
|
@@ -548,6 +624,51 @@ export class ModerationApi {
|
|
|
548
624
|
return response;
|
|
549
625
|
}
|
|
550
626
|
|
|
627
|
+
async saveConfigVersion(
|
|
628
|
+
request: SaveConfigVersionRequest,
|
|
629
|
+
): Promise<StreamResponse<SaveConfigVersionResponse>> {
|
|
630
|
+
const body = {
|
|
631
|
+
base_version: request?.base_version,
|
|
632
|
+
key: request?.key,
|
|
633
|
+
async: request?.async,
|
|
634
|
+
team: request?.team,
|
|
635
|
+
user_id: request?.user_id,
|
|
636
|
+
ai_audio_config: request?.ai_audio_config,
|
|
637
|
+
ai_image_config: request?.ai_image_config,
|
|
638
|
+
ai_text_config: request?.ai_text_config,
|
|
639
|
+
ai_video_config: request?.ai_video_config,
|
|
640
|
+
automod_platform_circumvention_config:
|
|
641
|
+
request?.automod_platform_circumvention_config,
|
|
642
|
+
automod_semantic_filters_config: request?.automod_semantic_filters_config,
|
|
643
|
+
automod_toxicity_config: request?.automod_toxicity_config,
|
|
644
|
+
aws_rekognition_config: request?.aws_rekognition_config,
|
|
645
|
+
block_list_config: request?.block_list_config,
|
|
646
|
+
bodyguard_config: request?.bodyguard_config,
|
|
647
|
+
engine: request?.engine,
|
|
648
|
+
flood_config: request?.flood_config,
|
|
649
|
+
google_vision_config: request?.google_vision_config,
|
|
650
|
+
intent_config: request?.intent_config,
|
|
651
|
+
llm_config: request?.llm_config,
|
|
652
|
+
rule_builder_config: request?.rule_builder_config,
|
|
653
|
+
user: request?.user,
|
|
654
|
+
velocity_filter_config: request?.velocity_filter_config,
|
|
655
|
+
video_call_rule_config: request?.video_call_rule_config,
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
const response =
|
|
659
|
+
await this.apiClient.sendRequest<SaveConfigVersionResponse>(
|
|
660
|
+
'POST',
|
|
661
|
+
'/api/v2/moderation/config/versions',
|
|
662
|
+
undefined,
|
|
663
|
+
undefined,
|
|
664
|
+
body,
|
|
665
|
+
);
|
|
666
|
+
|
|
667
|
+
decoders['SaveConfigVersionResponse']?.(response);
|
|
668
|
+
|
|
669
|
+
return response;
|
|
670
|
+
}
|
|
671
|
+
|
|
551
672
|
async deleteConfig(request: {
|
|
552
673
|
key: string;
|
|
553
674
|
team?: string;
|
|
@@ -597,6 +718,82 @@ export class ModerationApi {
|
|
|
597
718
|
return response;
|
|
598
719
|
}
|
|
599
720
|
|
|
721
|
+
async listConfigVersions(request: {
|
|
722
|
+
key: string;
|
|
723
|
+
team?: string;
|
|
724
|
+
}): Promise<StreamResponse<ListConfigVersionsResponse>> {
|
|
725
|
+
const queryParams = {
|
|
726
|
+
team: request?.team,
|
|
727
|
+
};
|
|
728
|
+
const pathParams = {
|
|
729
|
+
key: request?.key,
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
const response =
|
|
733
|
+
await this.apiClient.sendRequest<ListConfigVersionsResponse>(
|
|
734
|
+
'GET',
|
|
735
|
+
'/api/v2/moderation/config/{key}/versions',
|
|
736
|
+
pathParams,
|
|
737
|
+
queryParams,
|
|
738
|
+
);
|
|
739
|
+
|
|
740
|
+
decoders['ListConfigVersionsResponse']?.(response);
|
|
741
|
+
|
|
742
|
+
return response;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
async getConfigVersion(request: {
|
|
746
|
+
key: string;
|
|
747
|
+
version: number;
|
|
748
|
+
team?: string;
|
|
749
|
+
}): Promise<StreamResponse<GetConfigVersionResponse>> {
|
|
750
|
+
const queryParams = {
|
|
751
|
+
team: request?.team,
|
|
752
|
+
};
|
|
753
|
+
const pathParams = {
|
|
754
|
+
key: request?.key,
|
|
755
|
+
version: request?.version,
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
const response = await this.apiClient.sendRequest<GetConfigVersionResponse>(
|
|
759
|
+
'GET',
|
|
760
|
+
'/api/v2/moderation/config/{key}/versions/{version}',
|
|
761
|
+
pathParams,
|
|
762
|
+
queryParams,
|
|
763
|
+
);
|
|
764
|
+
|
|
765
|
+
decoders['GetConfigVersionResponse']?.(response);
|
|
766
|
+
|
|
767
|
+
return response;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
async publishConfigVersion(
|
|
771
|
+
request: PublishConfigVersionRequest & { key: string; version: number },
|
|
772
|
+
): Promise<StreamResponse<PublishConfigVersionResponse>> {
|
|
773
|
+
const pathParams = {
|
|
774
|
+
key: request?.key,
|
|
775
|
+
version: request?.version,
|
|
776
|
+
};
|
|
777
|
+
const body = {
|
|
778
|
+
team: request?.team,
|
|
779
|
+
user_id: request?.user_id,
|
|
780
|
+
user: request?.user,
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
const response =
|
|
784
|
+
await this.apiClient.sendRequest<PublishConfigVersionResponse>(
|
|
785
|
+
'POST',
|
|
786
|
+
'/api/v2/moderation/config/{key}/versions/{version}/publish',
|
|
787
|
+
pathParams,
|
|
788
|
+
undefined,
|
|
789
|
+
body,
|
|
790
|
+
);
|
|
791
|
+
|
|
792
|
+
decoders['PublishConfigVersionResponse']?.(response);
|
|
793
|
+
|
|
794
|
+
return response;
|
|
795
|
+
}
|
|
796
|
+
|
|
600
797
|
async queryModerationConfigs(
|
|
601
798
|
request?: QueryModerationConfigsRequest,
|
|
602
799
|
): Promise<StreamResponse<QueryModerationConfigsResponse>> {
|
|
@@ -1309,6 +1506,28 @@ export class ModerationApi {
|
|
|
1309
1506
|
return response;
|
|
1310
1507
|
}
|
|
1311
1508
|
|
|
1509
|
+
async countReviewQueue(
|
|
1510
|
+
request?: CountReviewQueueRequest,
|
|
1511
|
+
): Promise<StreamResponse<CountReviewQueueResponse>> {
|
|
1512
|
+
const body = {
|
|
1513
|
+
user_id: request?.user_id,
|
|
1514
|
+
filter: request?.filter,
|
|
1515
|
+
user: request?.user,
|
|
1516
|
+
};
|
|
1517
|
+
|
|
1518
|
+
const response = await this.apiClient.sendRequest<CountReviewQueueResponse>(
|
|
1519
|
+
'POST',
|
|
1520
|
+
'/api/v2/moderation/review_queue/count',
|
|
1521
|
+
undefined,
|
|
1522
|
+
undefined,
|
|
1523
|
+
body,
|
|
1524
|
+
);
|
|
1525
|
+
|
|
1526
|
+
decoders['CountReviewQueueResponse']?.(response);
|
|
1527
|
+
|
|
1528
|
+
return response;
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1312
1531
|
async getReviewQueueItem(request: {
|
|
1313
1532
|
id: string;
|
|
1314
1533
|
}): Promise<StreamResponse<GetReviewQueueItemResponse>> {
|
|
@@ -1373,6 +1592,7 @@ export class ModerationApi {
|
|
|
1373
1592
|
appeal_id: request?.appeal_id,
|
|
1374
1593
|
item_id: request?.item_id,
|
|
1375
1594
|
user_id: request?.user_id,
|
|
1595
|
+
agent_recommendation: request?.agent_recommendation,
|
|
1376
1596
|
ban: request?.ban,
|
|
1377
1597
|
block: request?.block,
|
|
1378
1598
|
bypass: request?.bypass,
|
|
@@ -1454,12 +1674,14 @@ export class ModerationApi {
|
|
|
1454
1674
|
target_user_id: string;
|
|
1455
1675
|
channel_cid?: string;
|
|
1456
1676
|
created_by?: string;
|
|
1677
|
+
remove_future_channels_ban?: boolean;
|
|
1457
1678
|
},
|
|
1458
1679
|
): Promise<StreamResponse<UnbanResponse>> {
|
|
1459
1680
|
const queryParams = {
|
|
1460
1681
|
target_user_id: request?.target_user_id,
|
|
1461
1682
|
channel_cid: request?.channel_cid,
|
|
1462
1683
|
created_by: request?.created_by,
|
|
1684
|
+
remove_future_channels_ban: request?.remove_future_channels_ban,
|
|
1463
1685
|
};
|
|
1464
1686
|
const body = {
|
|
1465
1687
|
unbanned_by_id: request?.unbanned_by_id,
|
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
|
}
|