From 4f6f8cac09465bebad815ebecf1484ad6847d592 Mon Sep 17 00:00:00 2001 From: Anton Arnautov Date: Fri, 21 Feb 2025 16:31:43 +0100 Subject: [PATCH] Add missing types --- src/client.ts | 8 +- src/types.ts | 257 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 219 insertions(+), 46 deletions(-) diff --git a/src/client.ts b/src/client.ts index 990f8e19a..073ea3220 100644 --- a/src/client.ts +++ b/src/client.ts @@ -193,8 +193,8 @@ import { TokenOrProvider, TranslateResponse, UnBanUserOptions, - UpdateChannelOptions, - UpdateChannelResponse, + UpdateChannelTypeRequest, + UpdateChannelTypeResponse, UpdateCommandOptions, UpdateCommandResponse, UpdatedMessage, @@ -2490,8 +2490,8 @@ export class StreamChat { return this.get(this.baseURL + `/channeltypes/${encodeURIComponent(channelType)}`); } - updateChannelType(channelType: string, data: UpdateChannelOptions) { - return this.put(this.baseURL + `/channeltypes/${encodeURIComponent(channelType)}`, data); + updateChannelType(channelType: string, data: UpdateChannelTypeRequest) { + return this.put(this.baseURL + `/channeltypes/${encodeURIComponent(channelType)}`, data); } deleteChannelType(channelType: string) { diff --git a/src/types.ts b/src/types.ts index bf7c1b3a9..1a6f8f67b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -477,14 +477,6 @@ export type FormatMessageResponse = Omit< updated_at: Date; }; -export type GetChannelTypeResponse = APIResponse & - Omit & { - created_at: string; - updated_at: string; - commands?: CommandResponse[]; - grants?: Record; - }; - export type GetCommandResponse = APIResponse & CreateCommandOptions & CreatedAtUpdatedAt; export type GetMessageAPIResponse = SendMessageAPIResponse; @@ -1004,22 +996,173 @@ export type DeactivateUsersOptions = { export type NewMemberPayload = CustomMemberData & Pick; -export type UpdateChannelOptions = { - accept_invite?: boolean; - add_members?: string[]; - add_moderators?: string[]; - client_id?: string; - connection_id?: string; - data?: Omit; - 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; + 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; + 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; + 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; + 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; @@ -1461,11 +1604,18 @@ export type ReactionFilters = QueryFilters< export type ChannelFilters = QueryFilters< ContainsOperator & { + archived?: boolean; + 'member.user.name'?: + | RequireOnlyOne<{ + $autocomplete?: string; + $eq?: string; + }> + | string; + members?: | RequireOnlyOne, '$in'>> | RequireOnlyOne, '$eq'>> | PrimitiveFilter; - } & { name?: | RequireOnlyOne< { @@ -1473,13 +1623,11 @@ export type ChannelFilters = QueryFilters< } & QueryFilter > | PrimitiveFilter; + pinned?: boolean; } & { [Key in keyof Omit]: | RequireOnlyOne> | PrimitiveFilter; - } & { - archived?: boolean; - pinned?: boolean; } >; @@ -1591,6 +1739,13 @@ export type ContainsOperator = { export type MessageFilters = QueryFilters< ContainsOperator & { + 'attachments.type'?: + | RequireOnlyOne<{ + $eq: PrimitiveFilter; + $in: PrimitiveFilter[]; + }> + | PrimitiveFilter; + 'mentioned_users.id'?: RequireOnlyOne<{ $contains: PrimitiveFilter }>; text?: | RequireOnlyOne< { @@ -1599,6 +1754,13 @@ export type MessageFilters = QueryFilters< } & QueryFilter > | PrimitiveFilter; + 'user.id'?: + | RequireOnlyOne< + { + $autocomplete?: UserResponse['id']; + } & QueryFilter + > + | PrimitiveFilter; } & { [Key in keyof Omit]?: | RequireOnlyOne> @@ -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?: | { @@ -1711,6 +1876,9 @@ export type MemberFilters = QueryFilters< $q?: NonNullable['name']; }> | PrimitiveFilter['name']>; + notifications_muted?: + | RequireOnlyOne<{ $eq?: ChannelMemberResponse['notifications_muted'] }> + | ChannelMemberResponse['notifications_muted']; updated_at?: | { $eq?: ChannelMemberResponse['updated_at']; @@ -1732,7 +1900,7 @@ export type MemberFilters = QueryFilters< $eq?: ChannelMemberResponse['user_id']; $in?: ChannelMemberResponse['user_id'][]; }> - | PrimitiveFilter['id'][]>; + | PrimitiveFilter; } & { [Key in keyof ContainsOperator]?: | RequireOnlyOne[Key]>> @@ -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; @@ -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; @@ -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; @@ -2628,7 +2797,10 @@ export type ReservedMessageFields = | 'updated_at' | 'user'; -export type UpdatedMessage = Omit & { mentioned_users?: string[] }; +export type UpdatedMessage = Omit & { + mentioned_users?: string[]; + type?: MessageLabel; +}; export type User = CustomUserData & { id: string; @@ -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;