Skip to content

Commit 2584867

Browse files
fix: fix the response types for moderation (#1681)
## CLA - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required). - [ ] Code changes are tested ## Description of the changes, What, Why and How? Fix typescript for moderation endpoints - https://linear.app/stream/issue/MOD2-631/inconsistent-type-declaration-for-submitaction-response - https://linear.app/stream/issue/MOD2-632/fix-typescript-for-reviewqueuefilters-type
1 parent 876599b commit 2584867

2 files changed

Lines changed: 96 additions & 22 deletions

File tree

src/moderation.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type {
22
APIResponse,
3+
CheckResponse,
34
CustomCheckFlag,
5+
CustomCheckResponse,
46
GetConfigResponse,
57
GetUserModerationReportOptions,
68
GetUserModerationReportResponse,
@@ -19,11 +21,12 @@ import type {
1921
QueryModerationRulesSort,
2022
RequireAtLeastOne,
2123
ReviewQueueFilters,
22-
ReviewQueueItem,
2324
ReviewQueuePaginationOptions,
2425
ReviewQueueResponse,
2526
ReviewQueueSort,
2627
SubmitActionOptions,
28+
SubmitActionResponse,
29+
UnmuteUserResponse,
2730
UpsertConfigResponse,
2831
UpsertModerationRuleResponse,
2932
} from './types';
@@ -135,7 +138,7 @@ export class Moderation {
135138
user_id?: string;
136139
},
137140
) {
138-
return await this.client.post<{ item_id: string } & APIResponse>(
141+
return await this.client.post<UnmuteUserResponse>(
139142
this.client.baseURL + '/api/v2/moderation/unmute',
140143
{
141144
target_ids: [targetID],
@@ -209,7 +212,7 @@ export class Moderation {
209212
}
210213

211214
async deleteConfig(key: string, data?: { team?: string }) {
212-
return await this.client.delete(
215+
return await this.client.delete<APIResponse>(
213216
this.client.baseURL + '/api/v2/moderation/config/' + key,
214217
data,
215218
);
@@ -241,7 +244,7 @@ export class Moderation {
241244
itemID: string,
242245
options: SubmitActionOptions = {},
243246
) {
244-
return await this.client.post<{ item_id: string } & APIResponse>(
247+
return await this.client.post<SubmitActionResponse>(
245248
this.client.baseURL + '/api/v2/moderation/submit_action',
246249
{
247250
action_type: actionType,
@@ -281,14 +284,17 @@ export class Moderation {
281284
test_mode?: boolean;
282285
},
283286
) {
284-
return await this.client.post(this.client.baseURL + `/api/v2/moderation/check`, {
285-
entity_type: entityType,
286-
entity_id: entityID,
287-
entity_creator_id: entityCreatorID,
288-
moderation_payload: moderationPayload,
289-
config_key: configKey,
290-
options,
291-
});
287+
return await this.client.post<CheckResponse>(
288+
this.client.baseURL + `/api/v2/moderation/check`,
289+
{
290+
entity_type: entityType,
291+
entity_id: entityID,
292+
entity_creator_id: entityCreatorID,
293+
moderation_payload: moderationPayload,
294+
config_key: configKey,
295+
options,
296+
},
297+
);
292298
}
293299

294300
/**
@@ -368,15 +374,16 @@ export class Moderation {
368374
},
369375
flags: CustomCheckFlag[],
370376
) {
371-
return await this.client.post<
372-
{ id: string; item: ReviewQueueItem; status: string } & APIResponse
373-
>(this.client.baseURL + `/api/v2/moderation/custom_check`, {
374-
entity_type: entityType,
375-
entity_id: entityID,
376-
entity_creator_id: entityCreatorID,
377-
moderation_payload: moderationPayload,
378-
flags,
379-
});
377+
return await this.client.post<CustomCheckResponse>(
378+
this.client.baseURL + `/api/v2/moderation/custom_check`,
379+
{
380+
entity_type: entityType,
381+
entity_id: entityID,
382+
entity_creator_id: entityCreatorID,
383+
moderation_payload: moderationPayload,
384+
flags,
385+
},
386+
);
380387
}
381388

382389
/**
@@ -446,7 +453,7 @@ export class Moderation {
446453
* @returns
447454
*/
448455
async deleteModerationRule(id: string) {
449-
return await this.client.delete(
456+
return await this.client.delete<APIResponse>(
450457
this.client.baseURL + '/api/v2/moderation/moderation_rule/' + id,
451458
);
452459
}

src/types.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,11 @@ export type MuteUserResponse = APIResponse & {
801801
mute?: MuteResponse;
802802
mutes?: Array<Mute>;
803803
own_user?: OwnUserResponse;
804+
non_existing_users?: string[];
805+
};
806+
807+
export type UnmuteUserResponse = APIResponse & {
808+
non_existing_users?: string[];
804809
};
805810

806811
export type BlockUserAPIResponse = APIResponse & {
@@ -3670,6 +3675,7 @@ export type ReviewQueueItem = {
36703675
created_by: string;
36713676
entity_id: string;
36723677
entity_type: string;
3678+
entity_creator_id?: string;
36733679
flags: ModerationFlag[];
36743680
has_image: boolean;
36753681
has_text: boolean;
@@ -3685,6 +3691,7 @@ export type ReviewQueueItem = {
36853691
reviewed_at: string;
36863692
status: string;
36873693
updated_at: string;
3694+
latest_moderator_action?: string;
36883695
};
36893696

36903697
export type CustomCheckFlag = {
@@ -3726,6 +3733,10 @@ export type SubmitActionOptions = {
37263733
user_id?: string;
37273734
};
37283735

3736+
export type SubmitActionResponse = APIResponse & {
3737+
item?: ReviewQueueItem;
3738+
};
3739+
37293740
export type GetUserModerationReportResponse = {
37303741
user: UserResponse;
37313742
user_blocks?: Array<{
@@ -3736,6 +3747,19 @@ export type GetUserModerationReportResponse = {
37363747
user_mutes?: Mute[];
37373748
};
37383749

3750+
export type CheckResponse = APIResponse & {
3751+
status: string;
3752+
task_id?: string;
3753+
recommended_action: string;
3754+
item?: ReviewQueueItem;
3755+
};
3756+
3757+
export type CustomCheckResponse = APIResponse & {
3758+
id: string;
3759+
item: ReviewQueueItem;
3760+
status: string;
3761+
};
3762+
37393763
export type QueryModerationConfigsFilters = QueryFilters<
37403764
{
37413765
key?: string;
@@ -3787,6 +3811,12 @@ export type ReviewQueueFilters = QueryFilters<
37873811
entity_id?:
37883812
| RequireOnlyOne<Pick<QueryFilter<ReviewQueueItem['entity_id']>, '$eq' | '$in'>>
37893813
| PrimitiveFilter<ReviewQueueItem['entity_id']>;
3814+
} & {
3815+
entity_creator_id?:
3816+
| RequireOnlyOne<
3817+
Pick<QueryFilter<ReviewQueueItem['entity_creator_id']>, '$eq' | '$in'>
3818+
>
3819+
| PrimitiveFilter<ReviewQueueItem['entity_creator_id']>;
37903820
} & {
37913821
reviewed?: boolean;
37923822
} & {
@@ -3840,6 +3870,7 @@ export type ReviewQueueFilters = QueryFilters<
38403870
} & {
38413871
recommended_action?: RequireOnlyOne<{
38423872
$eq?: string;
3873+
$in?: string[];
38433874
}>;
38443875
} & {
38453876
flagged_user_id?: RequireOnlyOne<{
@@ -3852,6 +3883,7 @@ export type ReviewQueueFilters = QueryFilters<
38523883
} & {
38533884
label?: RequireOnlyOne<{
38543885
$eq?: string;
3886+
$in?: string[];
38553887
}>;
38563888
} & {
38573889
reporter_type?: RequireOnlyOne<{
@@ -3866,6 +3898,24 @@ export type ReviewQueueFilters = QueryFilters<
38663898
date_range?: RequireOnlyOne<{
38673899
$eq?: string; // Format: "date1_date2"
38683900
}>;
3901+
} & {
3902+
latest_moderator_action?:
3903+
| RequireOnlyOne<
3904+
Pick<QueryFilter<ReviewQueueItem['latest_moderator_action']>, '$eq' | '$in'>
3905+
>
3906+
| PrimitiveFilter<ReviewQueueItem['latest_moderator_action']>;
3907+
} & {
3908+
flags_count?: RequireOnlyOne<{
3909+
$eq?: number;
3910+
}>;
3911+
} & {
3912+
ai_text_severity?: RequireOnlyOne<{
3913+
$eq?: string;
3914+
}>;
3915+
} & {
3916+
channel_cid?: RequireOnlyOne<{
3917+
$eq?: string;
3918+
}>;
38693919
}
38703920
>;
38713921

@@ -3877,8 +3927,25 @@ export type QueryModerationConfigsSort = Array<Sort<'key' | 'created_at' | 'upda
38773927

38783928
export type ReviewQueuePaginationOptions = Pager;
38793929

3930+
export type FilterConfigResponse = {
3931+
llm_labels: string[];
3932+
ai_text_labels?: string[];
3933+
};
3934+
3935+
export type ModerationActionConfig = {
3936+
entity_type: string;
3937+
order: number;
3938+
action: string;
3939+
icon: string;
3940+
description: string;
3941+
custom?: Record<string, unknown>;
3942+
};
3943+
38803944
export type ReviewQueueResponse = {
38813945
items: ReviewQueueItem[];
3946+
action_config?: Record<string, ModerationActionConfig[]>;
3947+
filter_config?: FilterConfigResponse;
3948+
stats?: Record<string, unknown>;
38823949
next?: string;
38833950
prev?: string;
38843951
};

0 commit comments

Comments
 (0)