Skip to content

Commit

Permalink
Add missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Feb 25, 2025
1 parent bc2023b commit 4f6f8ca
Show file tree
Hide file tree
Showing 2 changed files with 219 additions and 46 deletions.
8 changes: 4 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ import {
TokenOrProvider,
TranslateResponse,
UnBanUserOptions,
UpdateChannelOptions,
UpdateChannelResponse,
UpdateChannelTypeRequest,
UpdateChannelTypeResponse,
UpdateCommandOptions,
UpdateCommandResponse,
UpdatedMessage,
Expand Down Expand Up @@ -2490,8 +2490,8 @@ export class StreamChat {
return this.get<GetChannelTypeResponse>(this.baseURL + `/channeltypes/${encodeURIComponent(channelType)}`);
}

updateChannelType(channelType: string, data: UpdateChannelOptions) {
return this.put<UpdateChannelResponse>(this.baseURL + `/channeltypes/${encodeURIComponent(channelType)}`, data);
updateChannelType(channelType: string, data: UpdateChannelTypeRequest) {
return this.put<UpdateChannelTypeResponse>(this.baseURL + `/channeltypes/${encodeURIComponent(channelType)}`, data);
}

deleteChannelType(channelType: string) {
Expand Down
257 changes: 215 additions & 42 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,6 @@ export type FormatMessageResponse = Omit<
updated_at: Date;
};

export type GetChannelTypeResponse = APIResponse &
Omit<CreateChannelOptions, 'client_id' | 'connection_id' | 'commands'> & {
created_at: string;
updated_at: string;
commands?: CommandResponse[];
grants?: Record<string, string[]>;
};

export type GetCommandResponse = APIResponse & CreateCommandOptions & CreatedAtUpdatedAt;

export type GetMessageAPIResponse = SendMessageAPIResponse;
Expand Down Expand Up @@ -1004,22 +996,173 @@ export type DeactivateUsersOptions = {

export type NewMemberPayload = CustomMemberData & Pick<ChannelMemberResponse, 'user_id' | 'channel_role'>;

export type UpdateChannelOptions = {
accept_invite?: boolean;
add_members?: string[];
add_moderators?: string[];
client_id?: string;
connection_id?: string;
data?: Omit<ChannelResponse, 'id' | 'cid'>;
demote_moderators?: string[];
invites?: string[];
message?: MessageResponse;
reject_invite?: boolean;
remove_members?: string[];
user?: UserResponse;
user_id?: string;
export type Thresholds = Record<'explicit' | 'spam' | 'toxic', { block: number; flag: number }>;

export type BlockListOptions = {
behavior: BlocklistBehavior;
blocklist: string;
};

export type PolicyRequest = {
action: 'Deny' | 'Allow' | (string & {});
/**
* @description User-friendly policy name
*/
name: string;
/**
* @description Whether policy applies to resource owner or not
*/
owner: boolean;
priority: number;
/**
* @description List of resources to apply policy to
*/
resources: string[];
/**
* @description List of roles to apply policy to
*/
roles: string[];
};

export type Automod = 'disabled' | 'simple' | 'AI' | (string & {});
export type AutomodBehavior = 'flag' | 'block' | 'shadow_block' | (string & {});
export type BlocklistBehavior = AutomodBehavior;

export type UpdateChannelTypeRequest =
// these three properties are required in OpenAPI spec but omitted in some QA tests
Partial<{
automod: Automod;
automod_behavior: AutomodBehavior;
max_message_length: number;
}> & {
allowed_flag_reasons?: string[];
automod_thresholds?: Thresholds;
blocklist?: string;
blocklist_behavior?: BlocklistBehavior;
blocklists?: BlockListOptions[];
commands?: CommandVariants[];
connect_events?: boolean;
custom_events?: boolean;
grants?: Record<string, string[]>;
mark_messages_pending?: boolean;
mutes?: boolean;
partition_size?: number;
/**
* @example 24h
*/
partition_ttl?: string | null;
permissions?: PolicyRequest[];
polls?: boolean;
push_notifications?: boolean;
quotes?: boolean;
reactions?: boolean;
read_events?: boolean;
reminders?: boolean;
replies?: boolean;
search?: boolean;
skip_last_msg_update_for_system_msgs?: boolean;
typing_events?: boolean;
uploads?: boolean;
url_enrichment?: boolean;
};

export type UpdateChannelTypeResponse = {
automod: Automod;
automod_behavior: AutomodBehavior;
commands: CommandVariants[];
connect_events: boolean;
created_at: string;
custom_events: boolean;
duration: string;
grants: Record<string, string[]>;
mark_messages_pending: boolean;
max_message_length: number;
mutes: boolean;
name: string;
permissions: PolicyRequest[];
polls: boolean;
push_notifications: boolean;
quotes: boolean;
reactions: boolean;
read_events: boolean;
reminders: boolean;
replies: boolean;
search: boolean;
skip_last_msg_update_for_system_msgs: boolean;
typing_events: boolean;
updated_at: string;
uploads: boolean;
url_enrichment: boolean;
allowed_flag_reasons?: string[];
automod_thresholds?: Thresholds;
blocklist?: string;
blocklist_behavior?: BlocklistBehavior;
blocklists?: BlockListOptions[];
partition_size?: number;
partition_ttl?: string;
};

export type Command = {
args: string;
description: string;
name: string;
set: string;
created_at?: string;
updated_at?: string;
};

export type GetChannelTypeResponse = {
automod: Automod;
automod_behavior: AutomodBehavior;
commands: Command[];
connect_events: boolean;
created_at: string;
custom_events: boolean;
duration: string;
grants: Record<string, string[]>;
mark_messages_pending: boolean;
max_message_length: number;
mutes: boolean;
name: string;
permissions: PolicyRequest[];
polls: boolean;
push_notifications: boolean;
quotes: boolean;
reactions: boolean;
read_events: boolean;
reminders: boolean;
replies: boolean;
search: boolean;
skip_last_msg_update_for_system_msgs: boolean;
typing_events: boolean;
updated_at: string;
uploads: boolean;
url_enrichment: boolean;
allowed_flag_reasons?: string[];
automod_thresholds?: Thresholds;
blocklist?: string;
blocklist_behavior?: BlocklistBehavior;
blocklists?: BlockListOptions[];
partition_size?: number;
partition_ttl?: string;
};

export type UpdateChannelOptions = Partial<{
accept_invite: boolean;
add_members: string[];
add_moderators: string[];
client_id: string;
connection_id: string;
data: Omit<ChannelResponse, 'id' | 'cid'>;
demote_moderators: string[];
invites: string[];
message: MessageResponse;
reject_invite: boolean;
remove_members: string[];
user: UserResponse;
user_id: string;
}>;

export type MarkChannelsReadOptions = {
client_id?: string;
connection_id?: string;
Expand Down Expand Up @@ -1461,25 +1604,30 @@ export type ReactionFilters = QueryFilters<

export type ChannelFilters = QueryFilters<
ContainsOperator<CustomChannelData> & {
archived?: boolean;
'member.user.name'?:
| RequireOnlyOne<{
$autocomplete?: string;
$eq?: string;
}>
| string;

members?:
| RequireOnlyOne<Pick<QueryFilter<string>, '$in'>>
| RequireOnlyOne<Pick<QueryFilter<string[]>, '$eq'>>
| PrimitiveFilter<string[]>;
} & {
name?:
| RequireOnlyOne<
{
$autocomplete?: ChannelResponse['name'];
} & QueryFilter<ChannelResponse['name']>
>
| PrimitiveFilter<ChannelResponse['name']>;
pinned?: boolean;
} & {
[Key in keyof Omit<ChannelResponse, 'name' | 'members' | keyof CustomChannelData>]:
| RequireOnlyOne<QueryFilter<ChannelResponse[Key]>>
| PrimitiveFilter<ChannelResponse[Key]>;
} & {
archived?: boolean;
pinned?: boolean;
}
>;

Expand Down Expand Up @@ -1591,6 +1739,13 @@ export type ContainsOperator<CustomType = {}> = {

export type MessageFilters = QueryFilters<
ContainsOperator<CustomMessageData> & {
'attachments.type'?:
| RequireOnlyOne<{
$eq: PrimitiveFilter<Attachment['type']>;
$in: PrimitiveFilter<Attachment['type']>[];
}>
| PrimitiveFilter<Attachment['type']>;
'mentioned_users.id'?: RequireOnlyOne<{ $contains: PrimitiveFilter<UserResponse['id']> }>;
text?:
| RequireOnlyOne<
{
Expand All @@ -1599,6 +1754,13 @@ export type MessageFilters = QueryFilters<
} & QueryFilter<MessageResponse['text']>
>
| PrimitiveFilter<MessageResponse['text']>;
'user.id'?:
| RequireOnlyOne<
{
$autocomplete?: UserResponse['id'];
} & QueryFilter<UserResponse['id']>
>
| PrimitiveFilter<UserResponse['id']>;
} & {
[Key in keyof Omit<MessageResponse, 'text' | keyof CustomMessageData>]?:
| RequireOnlyOne<QueryFilter<MessageResponse[Key]>>
Expand Down Expand Up @@ -1693,6 +1855,9 @@ export type MemberFilters = QueryFilters<
}>
| UserResponse['id'];
invite?: { $eq?: ChannelMemberResponse['status'] } | ChannelMemberResponse['status'];
is_moderator?:
| RequireOnlyOne<{ $eq?: ChannelMemberResponse['is_moderator'] }>
| ChannelMemberResponse['is_moderator'];
joined?: { $eq?: boolean } | boolean;
last_active?:
| {
Expand All @@ -1711,6 +1876,9 @@ export type MemberFilters = QueryFilters<
$q?: NonNullable<ChannelMemberResponse['user']>['name'];
}>
| PrimitiveFilter<NonNullable<ChannelMemberResponse['user']>['name']>;
notifications_muted?:
| RequireOnlyOne<{ $eq?: ChannelMemberResponse['notifications_muted'] }>
| ChannelMemberResponse['notifications_muted'];
updated_at?:
| {
$eq?: ChannelMemberResponse['updated_at'];
Expand All @@ -1732,7 +1900,7 @@ export type MemberFilters = QueryFilters<
$eq?: ChannelMemberResponse['user_id'];
$in?: ChannelMemberResponse['user_id'][];
}>
| PrimitiveFilter<NonNullable<ChannelMemberResponse['user']>['id'][]>;
| PrimitiveFilter<ChannelMemberResponse['user_id']>;
} & {
[Key in keyof ContainsOperator<CustomMemberData>]?:
| RequireOnlyOne<QueryFilter<ContainsOperator<CustomMemberData>[Key]>>
Expand Down Expand Up @@ -1956,6 +2124,7 @@ export type Attachment = CustomAttachmentData & {
original_height?: number;
original_width?: number;
pretext?: string;
stopped_sharing?: boolean;
text?: string;
thumb_url?: string;
title?: string;
Expand Down Expand Up @@ -1990,15 +2159,13 @@ export type ChannelConfig = ChannelConfigFields &
commands?: CommandVariants[];
};

export type ChannelConfigAutomod = '' | 'AI' | 'disabled' | 'simple';
export type ChannelConfigAutomod = 'AI' | 'disabled' | 'simple' | (string & {});

export type ChannelConfigAutomodBehavior = '' | 'block' | 'flag';
export type ChannelConfigAutomodBehavior = 'block' | 'flag' | (string & {});

export type ChannelConfigAutomodThresholds = null | {
explicit?: { block?: number; flag?: number };
spam?: { block?: number; flag?: number };
toxic?: { block?: number; flag?: number };
};
export type ChannelConfigAutomodThresholds = null | Partial<
Record<'explicit' | 'spam' | 'toxic', { block?: number; flag?: number }>
>;

export type ChannelConfigFields = {
reminders: boolean;
Expand Down Expand Up @@ -2283,13 +2450,15 @@ export type EndpointName =
| 'ListPushProviders'
| 'CreatePoll';

export type ExportChannelRequest = {
id: string;
type: string;
cid?: string;
messages_since?: Date;
messages_until?: Date;
};
export type ExportChannelRequest = (
| {
id: string;
type: string;
}
| {
cid: string;
}
) & { messages_since?: Date; messages_until?: Date };

export type ExportChannelOptions = {
clear_deleted_message_text?: boolean;
Expand Down Expand Up @@ -2628,7 +2797,10 @@ export type ReservedMessageFields =
| 'updated_at'
| 'user';

export type UpdatedMessage = Omit<MessageResponse, 'mentioned_users'> & { mentioned_users?: string[] };
export type UpdatedMessage = Omit<MessageResponse, 'mentioned_users' | 'type'> & {
mentioned_users?: string[];
type?: MessageLabel;
};

export type User = CustomUserData & {
id: string;
Expand Down Expand Up @@ -2953,6 +3125,7 @@ export type UpdatePollAPIResponse = {

export type PollResponse = CustomPollData &
PollEnrichData & {
cid: string;
created_at: string;
created_by: UserResponse | null;
created_by_id: string;
Expand Down

0 comments on commit 4f6f8ca

Please sign in to comment.