UNPKG

stream-chat

Version:

JS SDK for the Stream Chat API

1,567 lines (1,404 loc) 116 kB
import { AxiosRequestConfig, AxiosResponse } from 'axios'; import { StableWSConnection } from './connection'; import { EVENT_MAP } from './events'; import { Role } from './permissions'; import type { Channel } from './channel'; /** * Utility Types */ export type ArrayOneOrMore<T> = { 0: T; } & Array<T>; export type ArrayTwoOrMore<T> = { 0: T; 1: T; } & Array<T>; export type KnownKeys<T> = { [K in keyof T]: string extends K ? never : number extends K ? never : K; } extends { [_ in keyof T]: infer U } ? U : never; export type RequireAtLeastOne<T> = { [K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>; }[keyof T]; export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & { [K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>; }[Keys]; /* Unknown Record */ export type UR = Record<string, unknown>; export type UnknownType = UR; //alias to avoid breaking change export type DefaultGenerics = { attachmentType: UR; channelType: UR; commandType: LiteralStringForUnion; eventType: UR; memberType: UR; messageType: UR; pollOptionType: UR; pollType: UR; reactionType: UR; userType: UR; }; export type ExtendableGenerics = { attachmentType: UR; channelType: UR; commandType: string; eventType: UR; memberType: UR; messageType: UR; pollOptionType: UR; pollType: UR; reactionType: UR; userType: UR; }; export type Unpacked<T> = T extends (infer U)[] ? U // eslint-disable-next-line @typescript-eslint/no-explicit-any : T extends (...args: any[]) => infer U ? U : T extends Promise<infer U> ? U : T; /** * Response Types */ export type APIResponse = { duration: string; }; export type TranslateResponse = { language: string; translated_text: string; }; export type AppSettingsAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { app?: { // TODO // eslint-disable-next-line @typescript-eslint/no-explicit-any call_types: any; channel_configs: Record< string, { reminders: boolean; automod?: ChannelConfigAutomod; automod_behavior?: ChannelConfigAutomodBehavior; automod_thresholds?: ChannelConfigAutomodThresholds; blocklist_behavior?: ChannelConfigAutomodBehavior; commands?: CommandVariants<StreamChatGenerics>[]; connect_events?: boolean; created_at?: string; custom_events?: boolean; mark_messages_pending?: boolean; max_message_length?: number; message_retention?: string; mutes?: boolean; name?: string; polls?: boolean; push_notifications?: boolean; quotes?: boolean; reactions?: boolean; read_events?: boolean; replies?: boolean; search?: boolean; typing_events?: boolean; updated_at?: string; uploads?: boolean; url_enrichment?: boolean; } >; reminders_interval: number; agora_options?: AgoraOptions | null; async_moderation_config?: AsyncModerationOptions; async_url_enrich_enabled?: boolean; auto_translation_enabled?: boolean; before_message_send_hook_url?: string; campaign_enabled?: boolean; cdn_expiration_seconds?: number; custom_action_handler_url?: string; datadog_info?: { api_key: string; site: string; enabled?: boolean; }; disable_auth_checks?: boolean; disable_permissions_checks?: boolean; enforce_unique_usernames?: 'no' | 'app' | 'team'; file_upload_config?: FileUploadConfig; geofences?: Array<{ country_codes: Array<string>; description: string; name: string; type: string; }>; grants?: Record<string, string[]>; hms_options?: HMSOptions | null; image_moderation_enabled?: boolean; image_upload_config?: FileUploadConfig; multi_tenant_enabled?: boolean; name?: string; organization?: string; permission_version?: string; policies?: Record<string, Policy[]>; poll_enabled?: boolean; push_notifications?: { offline_only: boolean; version: string; apn?: APNConfig; firebase?: FirebaseConfig; huawei?: HuaweiConfig; providers?: PushProviderConfig[]; xiaomi?: XiaomiConfig; }; revoke_tokens_issued_before?: string | null; search_backend?: 'disabled' | 'elasticsearch' | 'postgres'; sns_key?: string; sns_secret?: string; sns_topic_arn?: string; sqs_key?: string; sqs_secret?: string; sqs_url?: string; suspended?: boolean; suspended_explanation?: string; user_search_disallowed_roles?: string[] | null; video_provider?: string; webhook_events?: Array<string>; webhook_url?: string; }; }; export type ModerationResult = { action: string; created_at: string; message_id: string; updated_at: string; user_bad_karma: boolean; user_karma: number; blocked_word?: string; blocklist_name?: string; moderated_by?: string; }; export type AutomodDetails = { action?: string; image_labels?: Array<string>; original_message_type?: string; result?: ModerationResult; }; export type FlagDetails = { automod?: AutomodDetails; }; export type Flag<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { created_at: string; created_by_automod: boolean; updated_at: string; details?: FlagDetails; target_message?: MessageResponse<StreamChatGenerics>; target_user?: UserResponse<StreamChatGenerics>; user?: UserResponse<StreamChatGenerics>; }; export type FlagsResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { flags?: Array<Flag<StreamChatGenerics>>; }; export type MessageFlagsResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { flags?: Array<{ message: MessageResponse<StreamChatGenerics>; user: UserResponse<StreamChatGenerics>; approved_at?: string; created_at?: string; created_by_automod?: boolean; moderation_result?: ModerationResult; rejected_at?: string; reviewed_at?: string; reviewed_by?: UserResponse<StreamChatGenerics>; updated_at?: string; }>; }; export type FlagReport<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { flags_count: number; id: string; message: MessageResponse<StreamChatGenerics>; user: UserResponse<StreamChatGenerics>; created_at?: string; details?: FlagDetails; first_reporter?: UserResponse<StreamChatGenerics>; review_result?: string; reviewed_at?: string; reviewed_by?: UserResponse<StreamChatGenerics>; updated_at?: string; }; export type FlagReportsResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { flag_reports: Array<FlagReport<StreamChatGenerics>>; }; export type ReviewFlagReportResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { flag_report: FlagReport<StreamChatGenerics>; }; export type BannedUsersResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { bans?: Array<{ user: UserResponse<StreamChatGenerics>; banned_by?: UserResponse<StreamChatGenerics>; channel?: ChannelResponse<StreamChatGenerics>; expires?: string; ip_ban?: boolean; reason?: string; timeout?: number; }>; }; export type BlockListResponse = BlockList & { created_at?: string; type?: string; updated_at?: string; }; export type ChannelResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = StreamChatGenerics['channelType'] & { cid: string; disabled: boolean; frozen: boolean; id: string; type: string; auto_translation_enabled?: boolean; auto_translation_language?: TranslationLanguages | ''; config?: ChannelConfigWithInfo<StreamChatGenerics>; cooldown?: number; created_at?: string; created_by?: UserResponse<StreamChatGenerics> | null; created_by_id?: string; deleted_at?: string; hidden?: boolean; invites?: string[]; joined?: boolean; last_message_at?: string; member_count?: number; members?: ChannelMemberResponse<StreamChatGenerics>[]; muted?: boolean; name?: string; own_capabilities?: string[]; team?: string; truncated_at?: string; truncated_by?: UserResponse<StreamChatGenerics>; truncated_by_id?: string; updated_at?: string; }; export type QueryReactionsOptions = Pager; export type QueryReactionsAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { reactions: ReactionResponse<StreamChatGenerics>[]; next?: string; }; export type QueryChannelsAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { channels: Omit<ChannelAPIResponse<StreamChatGenerics>, keyof APIResponse>[]; }; export type QueryChannelAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & ChannelAPIResponse<StreamChatGenerics>; export type ChannelAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { channel: ChannelResponse<StreamChatGenerics>; members: ChannelMemberResponse<StreamChatGenerics>[]; messages: MessageResponse<StreamChatGenerics>[]; pinned_messages: MessageResponse<StreamChatGenerics>[]; hidden?: boolean; membership?: ChannelMemberResponse<StreamChatGenerics> | null; pending_messages?: PendingMessageResponse<StreamChatGenerics>[]; push_preferences?: PushPreference; read?: ReadResponse<StreamChatGenerics>[]; threads?: ThreadResponse[]; watcher_count?: number; watchers?: UserResponse<StreamChatGenerics>[]; }; export type ChannelUpdateOptions = { hide_history?: boolean; skip_push?: boolean; }; export type ChannelMemberAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { members: ChannelMemberResponse<StreamChatGenerics>[]; }; export type ChannelMemberUpdates< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = StreamChatGenerics['memberType'] & { archived?: boolean; channel_role?: Role; pinned?: boolean; }; export type ChannelMemberResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = StreamChatGenerics['memberType'] & { archived_at?: string; ban_expires?: string; banned?: boolean; channel_role?: Role; created_at?: string; invite_accepted_at?: string; invite_rejected_at?: string; invited?: boolean; is_moderator?: boolean; notifications_muted?: boolean; pinned_at?: string; role?: string; shadow_banned?: boolean; status?: InviteStatus; updated_at?: string; user?: UserResponse<StreamChatGenerics>; user_id?: string; }; export type PartialUpdateMemberAPIResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = APIResponse & { channel_member: ChannelMemberResponse<StreamChatGenerics>; }; export type CheckPushResponse = APIResponse & { device_errors?: { [deviceID: string]: { error_message?: string; provider?: PushProvider; provider_name?: string; }; }; general_errors?: string[]; rendered_apn_template?: string; rendered_firebase_template?: string; rendered_message?: {}; skip_devices?: boolean; }; export type CheckSQSResponse = APIResponse & { status: string; data?: {}; error?: string; }; export type CheckSNSResponse = APIResponse & { status: string; data?: {}; error?: string; }; export type CommandResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = Partial<CreatedAtUpdatedAt> & { args?: string; description?: string; name?: CommandVariants<StreamChatGenerics>; set?: CommandVariants<StreamChatGenerics>; }; export type ConnectAPIResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = Promise<void | ConnectionOpen<StreamChatGenerics>>; export type CreateChannelResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & Omit<CreateChannelOptions<StreamChatGenerics>, 'client_id' | 'connection_id'> & { created_at: string; updated_at: string; grants?: Record<string, string[]>; }; export type CreateCommandResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { command: CreateCommandOptions<StreamChatGenerics> & CreatedAtUpdatedAt; }; export type DeleteChannelAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { channel: ChannelResponse<StreamChatGenerics>; }; export type DeleteCommandResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { name?: CommandVariants<StreamChatGenerics>; }; export type EventAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { event: Event<StreamChatGenerics>; }; export type ExportChannelResponse = { task_id: string; }; export type ExportUsersResponse = { task_id: string; }; export type ExportChannelStatusResponse = { created_at?: string; error?: {}; result?: {}; updated_at?: string; }; export type FlagMessageResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { flag: { created_at: string; created_by_automod: boolean; target_message_id: string; updated_at: string; user: UserResponse<StreamChatGenerics>; approved_at?: string; channel_cid?: string; details?: Object; // Any JSON message_user_id?: string; rejected_at?: string; reviewed_at?: string; reviewed_by?: string; }; review_queue_item_id?: string; }; export type FlagUserResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { flag: { created_at: string; created_by_automod: boolean; target_user: UserResponse<StreamChatGenerics>; updated_at: string; user: UserResponse<StreamChatGenerics>; approved_at?: string; details?: Object; // Any JSON rejected_at?: string; reviewed_at?: string; reviewed_by?: string; }; review_queue_item_id?: string; }; export type FormatMessageResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = Omit< MessageResponse<{ attachmentType: StreamChatGenerics['attachmentType']; channelType: StreamChatGenerics['channelType']; commandType: StreamChatGenerics['commandType']; eventType: StreamChatGenerics['eventType']; memberType: StreamChatGenerics['memberType']; messageType: {}; pollOptionType: StreamChatGenerics['pollOptionType']; pollType: StreamChatGenerics['pollType']; reactionType: StreamChatGenerics['reactionType']; userType: StreamChatGenerics['userType']; }>, 'created_at' | 'pinned_at' | 'updated_at' | 'deleted_at' | 'status' > & StreamChatGenerics['messageType'] & { created_at: Date; deleted_at: Date | null; pinned_at: Date | null; status: string; updated_at: Date; }; export type GetChannelTypeResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & Omit<CreateChannelOptions<StreamChatGenerics>, 'client_id' | 'connection_id' | 'commands'> & { created_at: string; updated_at: string; commands?: CommandResponse<StreamChatGenerics>[]; grants?: Record<string, string[]>; }; export type GetCommandResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & CreateCommandOptions<StreamChatGenerics> & CreatedAtUpdatedAt; export type GetMessageAPIResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = SendMessageAPIResponse<StreamChatGenerics>; // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface ThreadResponseCustomData {} export interface ThreadResponse<SCG extends ExtendableGenerics = DefaultGenerics> extends ThreadResponseCustomData { // FIXME: according to OpenAPI, `channel` could be undefined but since cid is provided I'll asume that it's wrong channel: ChannelResponse<SCG>; channel_cid: string; created_at: string; created_by_user_id: string; latest_replies: Array<MessageResponse<SCG>>; parent_message: MessageResponse<SCG>; parent_message_id: string; title: string; updated_at: string; active_participant_count?: number; created_by?: UserResponse<SCG>; deleted_at?: string; last_message_at?: string; participant_count?: number; read?: Array<ReadResponse<SCG>>; reply_count?: number; thread_participants?: Array<{ channel_cid: string; created_at: string; last_read_at: string; last_thread_message_at?: string; left_thread_at?: string; thread_id?: string; user?: UserResponse<SCG>; user_id?: string; }>; // TODO: when moving to API v2 we should do this instead // custom: ThreadResponseCustomData; } // TODO: Figure out a way to strongly type set and unset. export type PartialThreadUpdate = { set?: Partial<Record<string, unknown>>; unset?: Array<string>; }; export type QueryThreadsOptions = { limit?: number; member_limit?: number; next?: string; participant_limit?: number; reply_limit?: number; watch?: boolean; }; export type QueryThreadsAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { threads: ThreadResponse<StreamChatGenerics>[]; next?: string; }; export type GetThreadOptions = { member_limit?: number; participant_limit?: number; reply_limit?: number; watch?: boolean; }; export type GetThreadAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { thread: ThreadResponse<StreamChatGenerics>; }; export type GetMultipleMessagesAPIResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = APIResponse & { messages: MessageResponse<StreamChatGenerics>[]; }; export type GetRateLimitsResponse = APIResponse & { android?: RateLimitsMap; ios?: RateLimitsMap; server_side?: RateLimitsMap; web?: RateLimitsMap; }; export type GetReactionsAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { reactions: ReactionResponse<StreamChatGenerics>[]; }; export type GetRepliesAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { messages: MessageResponse<StreamChatGenerics>[]; }; export type GetUnreadCountAPIResponse = APIResponse & { channel_type: { channel_count: number; channel_type: string; unread_count: number; }[]; channels: { channel_id: string; last_read: string; unread_count: number; }[]; threads: { last_read: string; last_read_message_id: string; parent_message_id: string; unread_count: number; }[]; total_unread_count: number; total_unread_threads_count: number; }; export type ChatLevelPushPreference = 'all' | 'none' | 'mentions' | (string & {}); export type PushPreference = { callLevel?: 'all' | 'none' | (string & {}); chatLevel?: ChatLevelPushPreference; disabledUntil?: string; // snooze till this time removeDisable?: boolean; // Temporary flag for resetting disabledUntil }; export type ChannelPushPreference = { chatLevel?: ChatLevelPushPreference; // "all", "none", "mentions", or other custom strings disabledUntil?: string; removeDisable?: boolean; // Temporary flag for resetting disabledUntil }; export type UpsertPushPreferencesResponse = APIResponse & { // Mapping of user IDs to their push preferences userChannelPreferences: Record<string, Record<string, ChannelPushPreference>>; userPreferences: Record<string, PushPreference>; // Mapping of user -> channel id -> push preferences }; export type GetUnreadCountBatchAPIResponse = APIResponse & { counts_by_user: { [userId: string]: GetUnreadCountAPIResponse }; }; export type ListChannelResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { channel_types: Record< string, Omit<CreateChannelOptions<StreamChatGenerics>, 'client_id' | 'connection_id' | 'commands'> & { commands: CommandResponse<StreamChatGenerics>[]; created_at: string; updated_at: string; grants?: Record<string, string[]>; } >; }; export type ListChannelTypesAPIResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = ListChannelResponse<StreamChatGenerics>; export type ListCommandsResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { commands: Array<CreateCommandOptions<StreamChatGenerics> & Partial<CreatedAtUpdatedAt>>; }; export type MuteChannelAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { channel_mute: ChannelMute<StreamChatGenerics>; own_user: OwnUserResponse<StreamChatGenerics>; channel_mutes?: ChannelMute<StreamChatGenerics>[]; mute?: MuteResponse<StreamChatGenerics>; }; export type MessageResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = MessageResponseBase<StreamChatGenerics> & { quoted_message?: MessageResponseBase<StreamChatGenerics>; }; export type MessageResponseBase< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = MessageBase<StreamChatGenerics> & { type: MessageLabel; args?: string; before_message_send_failed?: boolean; channel?: ChannelResponse<StreamChatGenerics>; cid?: string; command?: string; command_info?: { name?: string }; created_at?: string; deleted_at?: string; deleted_reply_count?: number; i18n?: RequireAtLeastOne<Record<`${TranslationLanguages}_text`, string>> & { language: TranslationLanguages; }; latest_reactions?: ReactionResponse<StreamChatGenerics>[]; mentioned_users?: UserResponse<StreamChatGenerics>[]; message_text_updated_at?: string; moderation?: ModerationResponse; // present only with Moderation v2 moderation_details?: ModerationDetailsResponse; // present only with Moderation v1 own_reactions?: ReactionResponse<StreamChatGenerics>[] | null; pin_expires?: string | null; pinned_at?: string | null; pinned_by?: UserResponse<StreamChatGenerics> | null; poll?: PollResponse<StreamChatGenerics>; reaction_counts?: { [key: string]: number } | null; reaction_groups?: { [key: string]: ReactionGroupResponse } | null; reaction_scores?: { [key: string]: number } | null; reply_count?: number; shadowed?: boolean; status?: string; thread_participants?: UserResponse<StreamChatGenerics>[]; updated_at?: string; }; export type ReactionGroupResponse = { count: number; sum_scores: number; first_reaction_at?: string; last_reaction_at?: string; }; export type ModerationDetailsResponse = { action: 'MESSAGE_RESPONSE_ACTION_BOUNCE' | (string & {}); error_msg: string; harms: ModerationHarmResponse[]; original_text: string; }; export type ModerationHarmResponse = { name: string; phrase_list_ids: number[]; }; export type ModerationAction = 'bounce' | 'flag' | 'remove' | 'shadow'; export type ModerationResponse = { action: ModerationAction; original_text: string; }; export type MuteResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { user: UserResponse<StreamChatGenerics>; created_at?: string; expires?: string; target?: UserResponse<StreamChatGenerics>; updated_at?: string; }; export type MuteUserResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { mute?: MuteResponse<StreamChatGenerics>; mutes?: Array<Mute<StreamChatGenerics>>; own_user?: OwnUserResponse<StreamChatGenerics>; }; export type BlockUserAPIResponse = APIResponse & { blocked_at: string; blocked_by_user_id: string; blocked_user_id: string; }; export type GetBlockedUsersAPIResponse = APIResponse & { blocks: BlockedUserDetails[]; }; export type BlockedUserDetails = APIResponse & { blocked_user: UserResponse; blocked_user_id: string; created_at: string; user: UserResponse; user_id: string; }; export type OwnUserBase<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { channel_mutes: ChannelMute<StreamChatGenerics>[]; devices: Device<StreamChatGenerics>[]; mutes: Mute<StreamChatGenerics>[]; total_unread_count: number; unread_channels: number; unread_count: number; unread_threads: number; invisible?: boolean; privacy_settings?: PrivacySettings; push_preferences?: PushPreference; roles?: string[]; }; export type OwnUserResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = UserResponse<StreamChatGenerics> & OwnUserBase<StreamChatGenerics>; export type PartialUpdateChannelAPIResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = APIResponse & { channel: ChannelResponse<StreamChatGenerics>; members: ChannelMemberResponse<StreamChatGenerics>[]; }; export type PermissionAPIResponse = APIResponse & { permission?: PermissionAPIObject; }; export type PermissionsAPIResponse = APIResponse & { permissions?: PermissionAPIObject[]; }; export type ReactionAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { message: MessageResponse<StreamChatGenerics>; reaction: ReactionResponse<StreamChatGenerics>; }; export type ReactionResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = Reaction<StreamChatGenerics> & { created_at: string; message_id: string; updated_at: string; }; export type ReadResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { last_read: string; user: UserResponse<StreamChatGenerics>; last_read_message_id?: string; unread_messages?: number; }; export type SearchAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { results: { message: MessageResponse<StreamChatGenerics>; }[]; next?: string; previous?: string; results_warning?: SearchWarning | null; }; export type SearchWarning = { channel_search_cids: string[]; channel_search_count: number; warning_code: number; warning_description: string; }; // Thumb URL(thumb_url) is added considering video attachments as the backend will return the thumbnail in the response. export type SendFileAPIResponse = APIResponse & { file: string; thumb_url?: string }; export type SendMessageAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { message: MessageResponse<StreamChatGenerics>; pending_message_metadata?: Record<string, string> | null; }; export type SyncResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { events: Event<StreamChatGenerics>[]; inaccessible_cids?: string[]; }; export type TruncateChannelAPIResponse< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = APIResponse & { channel: ChannelResponse<StreamChatGenerics>; message?: MessageResponse<StreamChatGenerics>; }; export type UpdateChannelAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { channel: ChannelResponse<StreamChatGenerics>; members: ChannelMemberResponse<StreamChatGenerics>[]; message?: MessageResponse<StreamChatGenerics>; }; export type UpdateChannelResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & Omit<CreateChannelOptions<StreamChatGenerics>, 'client_id' | 'connection_id'> & { created_at: string; updated_at: string; }; export type UpdateCommandResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { command: UpdateCommandOptions<StreamChatGenerics> & CreatedAtUpdatedAt & { name: CommandVariants<StreamChatGenerics>; }; }; export type UpdateMessageAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { message: MessageResponse<StreamChatGenerics>; }; export type UsersAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { users: Array<UserResponse<StreamChatGenerics>>; }; export type UpdateUsersAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & { users: { [key: string]: UserResponse<StreamChatGenerics> }; }; export type UserResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = User<StreamChatGenerics> & { banned?: boolean; blocked_user_ids?: string[]; created_at?: string; deactivated_at?: string; deleted_at?: string; language?: TranslationLanguages | ''; last_active?: string; online?: boolean; privacy_settings?: PrivacySettings; push_notifications?: PushNotificationSettings; revoke_tokens_issued_before?: string; shadow_banned?: boolean; updated_at?: string; }; export type PrivacySettings = { read_receipts?: { enabled?: boolean; }; typing_indicators?: { enabled?: boolean; }; }; export type PushNotificationSettings = { disabled?: boolean; disabled_until?: string | null; }; /** * Option Types */ export type MessageFlagsPaginationOptions = { limit?: number; offset?: number; }; export type FlagsPaginationOptions = { limit?: number; offset?: number; }; export type FlagReportsPaginationOptions = { limit?: number; offset?: number; }; export type ReviewFlagReportOptions = { review_details?: Object; user_id?: string; }; export type BannedUsersPaginationOptions = Omit<PaginationOptions, 'id_gt' | 'id_gte' | 'id_lt' | 'id_lte'> & { exclude_expired_bans?: boolean; }; export type BanUserOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = UnBanUserOptions & { banned_by?: UserResponse<StreamChatGenerics>; banned_by_id?: string; ip_ban?: boolean; reason?: string; timeout?: number; }; export type ChannelOptions = { limit?: number; member_limit?: number; message_limit?: number; offset?: number; presence?: boolean; state?: boolean; user_id?: string; watch?: boolean; }; export type ChannelQueryOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { client_id?: string; connection_id?: string; data?: ChannelResponse<StreamChatGenerics>; hide_for_creator?: boolean; members?: PaginationOptions; messages?: MessagePaginationOptions; presence?: boolean; state?: boolean; watch?: boolean; watchers?: PaginationOptions; }; export type ChannelStateOptions = { offlineMode?: boolean; skipInitialization?: string[]; }; export type CreateChannelOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { automod?: ChannelConfigAutomod; automod_behavior?: ChannelConfigAutomodBehavior; automod_thresholds?: ChannelConfigAutomodThresholds; blocklist?: string; blocklist_behavior?: ChannelConfigAutomodBehavior; client_id?: string; commands?: CommandVariants<StreamChatGenerics>[]; connect_events?: boolean; connection_id?: string; custom_events?: boolean; grants?: Record<string, string[]>; mark_messages_pending?: boolean; max_message_length?: number; message_retention?: string; mutes?: boolean; name?: string; permissions?: PermissionObject[]; 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 CreateCommandOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { description: string; name: CommandVariants<StreamChatGenerics>; args?: string; set?: CommandVariants<StreamChatGenerics>; }; export type CustomPermissionOptions = { action: string; condition: object; id: string; name: string; description?: string; owner?: boolean; same_team?: boolean; }; export type DeactivateUsersOptions = { created_by_id?: string; mark_messages_deleted?: boolean; }; export type NewMemberPayload< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = StreamChatGenerics['memberType'] & Pick<ChannelMemberResponse<StreamChatGenerics>, 'user_id' | 'channel_role'>; // TODO: rename to UpdateChannelOptions in the next major update and use it in channel._update and/or channel.update export type InviteOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { accept_invite?: boolean; add_members?: string[]; add_moderators?: string[]; client_id?: string; connection_id?: string; data?: Omit<ChannelResponse<StreamChatGenerics>, 'id' | 'cid'>; demote_moderators?: string[]; invites?: string[]; message?: MessageResponse<StreamChatGenerics>; reject_invite?: boolean; remove_members?: string[]; user?: UserResponse<StreamChatGenerics>; user_id?: string; }; /** @deprecated use MarkChannelsReadOptions instead */ export type MarkAllReadOptions< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = MarkChannelsReadOptions<StreamChatGenerics>; export type MarkChannelsReadOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { client_id?: string; connection_id?: string; read_by_channel?: Record<string, string>; user?: UserResponse<StreamChatGenerics>; user_id?: string; }; export type MarkReadOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { client_id?: string; connection_id?: string; thread_id?: string; user?: UserResponse<StreamChatGenerics>; user_id?: string; }; export type MarkUnreadOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { client_id?: string; connection_id?: string; message_id?: string; thread_id?: string; user?: UserResponse<StreamChatGenerics>; user_id?: string; }; export type MuteUserOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { client_id?: string; connection_id?: string; id?: string; reason?: string; target_user_id?: string; timeout?: number; type?: string; user?: UserResponse<StreamChatGenerics>; user_id?: string; }; export type PaginationOptions = { created_at_after?: string | Date; created_at_after_or_equal?: string | Date; created_at_before?: string | Date; created_at_before_or_equal?: string | Date; id_gt?: string; id_gte?: string; id_lt?: string; id_lte?: string; limit?: number; offset?: number; // should be avoided with channel.query() }; export type MessagePaginationOptions = PaginationOptions & { created_at_around?: string | Date; id_around?: string; }; export type PinnedMessagePaginationOptions = { id_around?: string; id_gt?: string; id_gte?: string; id_lt?: string; id_lte?: string; limit?: number; offset?: number; pinned_at_after?: string | Date; pinned_at_after_or_equal?: string | Date; pinned_at_around?: string | Date; pinned_at_before?: string | Date; pinned_at_before_or_equal?: string | Date; }; export type QueryMembersOptions = { // Pagination option: select members created after the date (RFC399) created_at_after?: string; // Pagination option: select members created after or equal the date (RFC399) created_at_after_or_equal?: string; // Pagination option: select members created before the date (RFC399) created_at_before?: string; // Pagination option: select members created before or equal the date (RFC399) created_at_before_or_equal?: string; // Number of members to return, default 100 limit?: number; // Offset (max is 1000) offset?: number; // Pagination option: excludes members with ID less or equal the value user_id_gt?: string; // Pagination option: excludes members with ID less than the value user_id_gte?: string; // Pagination option: excludes members with ID greater or equal the value user_id_lt?: string; // Pagination option: excludes members with ID greater than the value user_id_lte?: string; }; export type ReactivateUserOptions = { created_by_id?: string; name?: string; restore_messages?: boolean; }; export type ReactivateUsersOptions = { created_by_id?: string; restore_messages?: boolean; }; export type SearchOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { limit?: number; next?: string; offset?: number; sort?: SearchMessageSort<StreamChatGenerics>; }; export type StreamChatOptions = AxiosRequestConfig & { /** * Used to disable warnings that are triggered by using connectUser or connectAnonymousUser server-side. */ allowServerSideConnect?: boolean; axiosRequestConfig?: AxiosRequestConfig; /** * Base url to use for API * such as https://chat-proxy-dublin.stream-io-api.com */ baseURL?: string; browser?: boolean; device?: BaseDeviceFields; /** * Disables the hydration of all caches within the JS Client. This includes this.activeChannels, * this.polls.pollCache and this.config. * It is mainly meant to be used for integrations where stream-chat is used as a server-side service * interacting with Stream's REST API, not depending on any state and purely serving as a wrapper * around HTTP requests. Using this property on either the client side or a backend implementation * that also relies on WS events will break these functionalities, so please use carefully. */ disableCache?: boolean; enableInsights?: boolean; /** experimental feature, please contact support if you want this feature enabled for you */ enableWSFallback?: boolean; logger?: Logger; /** * When true, user will be persisted on client. Otherwise if `connectUser` call fails, then you need to * call `connectUser` again to retry. * This is mainly useful for chat application working in offline mode, where you will need client.user to * persist even if connectUser call fails. */ persistUserOnConnectionFailure?: boolean; /** * When network is recovered, we re-query the active channels on client. But in single query, you can recover * only 30 channels. So its not guaranteed that all the channels in activeChannels object have updated state. * Thus in UI sdks, state recovery is managed by components themselves, they don't rely on js client for this. * * `recoverStateOnReconnect` parameter can be used in such cases, to disable state recovery within js client. * When false, user/consumer of this client will need to make sure all the channels present on UI by * manually calling queryChannels endpoint. */ recoverStateOnReconnect?: boolean; warmUp?: boolean; /** * Set the instance of StableWSConnection on chat client. Its purely for testing purpose and should * not be used in production apps. */ wsConnection?: StableWSConnection; /** * Sets a suffix to the wsUrl when it is being built in `wsConnection`. Is meant to be * used purely in testing suites and should not be used in production apps. */ wsUrlParams?: URLSearchParams; }; export type SyncOptions = { /** * This will behave as queryChannels option. */ watch?: boolean; /** * Return channels from request that user does not have access to in a separate * field in the response called 'inaccessible_cids' instead of * adding them as 'notification.removed_from_channel' events. */ with_inaccessible_cids?: boolean; }; export type UnBanUserOptions = { client_id?: string; connection_id?: string; id?: string; shadow?: boolean; target_user_id?: string; type?: string; }; // TODO: rename to UpdateChannelTypeOptions in the next major update export type UpdateChannelOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = Omit< CreateChannelOptions<StreamChatGenerics>, 'name' > & { created_at?: string; updated_at?: string; }; export type UpdateCommandOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = { description: string; args?: string; set?: CommandVariants<StreamChatGenerics>; }; export type UserOptions = { include_deactivated_users?: boolean; limit?: number; offset?: number; presence?: boolean; }; /** * Event Types */ export type ConnectionChangeEvent = { type: EventTypes; online?: boolean; }; export type Event<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = StreamChatGenerics['eventType'] & { type: EventTypes; ai_message?: string; ai_state?: AIState; channel?: ChannelResponse<StreamChatGenerics>; channel_id?: string; channel_type?: string; cid?: string; clear_history?: boolean; connection_id?: string; // event creation timestamp, format Date ISO string created_at?: string; // id of the message that was marked as unread - all the following messages are considered unread. (notification.mark_unread) first_unread_message_id?: string; hard_delete?: boolean; // creation date of a message with last_read_message_id, formatted as Date ISO string last_read_at?: string; last_read_message_id?: string; mark_messages_deleted?: boolean; me?: OwnUserResponse<StreamChatGenerics>; member?: ChannelMemberResponse<StreamChatGenerics>; message?: MessageResponse<StreamChatGenerics>; message_id?: string; mode?: string; online?: boolean; parent_id?: string; poll?: PollResponse<StreamChatGenerics>; poll_vote?: PollVote<StreamChatGenerics> | PollAnswer<StreamChatGenerics>; queriedChannels?: { channels: ChannelAPIResponse<StreamChatGenerics>[]; isLatestMessageSet?: boolean; }; reaction?: ReactionResponse<StreamChatGenerics>; received_at?: string | Date; team?: string; thread?: ThreadResponse<StreamChatGenerics>; // @deprecated number of all unread messages across all current user's unread channels, equals unread_count total_unread_count?: number; // number of all current user's channels with at least one unread message including the channel in this event unread_channels?: number; // number of all unread messages across all current user's unread channels unread_count?: number; // number of unread messages in the channel from this event (notification.mark_unread) unread_messages?: number; unread_thread_messages?: number; unread_threads?: number; user?: UserResponse<StreamChatGenerics>; user_id?: string; watcher_count?: number; }; export type UserCustomEvent< StreamChatGenerics extends ExtendableGenerics = DefaultGenerics > = StreamChatGenerics['eventType'] & { type: string; }; export type EventHandler<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = ( event: Event<StreamChatGenerics>, ) => void; export type EventTypes = 'all' | keyof typeof EVENT_MAP; /** * Filter Types */ export type AscDesc = 1 | -1; export type MessageFlagsFiltersOptions = { channel_cid?: string; is_reviewed?: boolean; team?: string; user_id?: string; }; export type MessageFlagsFilters = QueryFilters< { channel_cid?: | RequireOnlyOne<Pick<QueryFilter<MessageFlagsFiltersOptions['channel_cid']>, '$eq' | '$in'>> | PrimitiveFilter<MessageFlagsFiltersOptions['channel_cid']>; } & { team?: | RequireOnlyOne<Pick<QueryFilter<MessageFlagsFiltersOptions['team']>, '$eq' | '$in'>> | PrimitiveFilter<MessageFlagsFiltersOptions['team']>; } & { user_id?: | RequireOnlyOne<Pick<QueryFilter<MessageFlagsFiltersOptions['user_id']>, '$eq' | '$in'>> | PrimitiveFilter<MessageFlagsFiltersOptions['user_id']>; } & { [Key in keyof Omit<MessageFlagsFiltersOptions, 'channel_cid' | 'user_id' | 'is_reviewed'>]: | RequireOnlyOne<QueryFilter<MessageFlagsFiltersOptions[Key]>> | PrimitiveFilter<MessageFlagsFiltersOptions[Key]>; } >; export type FlagsFiltersOptions = { channel_cid?: string; message_id?: string; message_user_id?: string; reporter_id?: string; team?: string; user_id?: string; }; export type FlagsFilters = QueryFilters< { user_id?: | RequireOnlyOne<Pick<QueryFilter<FlagsFiltersOptions['user_id']>, '$eq' | '$in'>> | PrimitiveFilter<FlagsFiltersOptions['user_id']>; } & { message_id?: | RequireOnlyOne<Pick<QueryFilter<FlagsFiltersOptions['message_id']>, '$eq' | '$in'>> | PrimitiveFilter<FlagsFiltersOptions['message_id']>; } & { message_user_id?: | RequireOnlyOne<Pick<QueryFilter<FlagsFiltersOptions['message_user_id']>, '$eq' | '$in'>> | PrimitiveFilter<FlagsFiltersOptions['message_user_id']>; } & { channel_cid?: | RequireOnlyOne<Pick<QueryFilter<FlagsFiltersOptions['channel_cid']>, '$eq' | '$in'>> | PrimitiveFilter<FlagsFiltersOptions['channel_cid']>; } & { reporter_id?: | RequireOnlyOne<Pick<QueryFilter<FlagsFiltersOptions['reporter_id']>, '$eq' | '$in'>> | PrimitiveFilter<FlagsFiltersOptions['reporter_id']>; } & { team?: | RequireOnlyOne<Pick<QueryFilter<FlagsFiltersOptions['team']>, '$eq' | '$in'>> | PrimitiveFilter<FlagsFiltersOptions['team']>; } >; export type FlagReportsFiltersOptions = { channel_cid?: string; is_reviewed?: boolean; message_id?: string; message_user_id?: string; report_id?: string; review_result?: string; reviewed_by?: string; team?: string; user_id?: string; }; export type FlagReportsFilters = QueryFilters< { report_id?: | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['report_id']>, '$eq' | '$in'>> | PrimitiveFilter<FlagReportsFiltersOptions['report_id']>; } & { review_result?: | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['review_result']>, '$eq' | '$in'>> | PrimitiveFilter<FlagReportsFiltersOptions['review_result']>; } & { reviewed_by?: | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['reviewed_by']>, '$eq' | '$in'>> | PrimitiveFilter<FlagReportsFiltersOptions['reviewed_by']>; } & { user_id?: | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['user_id']>, '$eq' | '$in'>> | PrimitiveFilter<FlagReportsFiltersOptions['user_id']>; } & { message_id?: | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['message_id']>, '$eq' | '$in'>> | PrimitiveFilter<FlagReportsFiltersOptions['message_id']>; } & { message_user_id?: | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['message_user_id']>, '$eq' | '$in'>> | PrimitiveFilter<FlagReportsFiltersOptions['message_user_id']>; } & { channel_cid?: | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['channel_cid']>, '$eq' | '$in'>> | PrimitiveFilter<FlagReportsFiltersOptions['channel_cid']>; } & { team?: | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['team']>, '$eq' | '$in'>> | PrimitiveFilter<FlagReportsFiltersOptions['team']>; } & { [Key in keyof Omit< FlagReportsFiltersOptions, 'report_id' | 'user_id' | 'message_id' | 'review_result' | 'reviewed_by' >]: RequireOnlyOne<QueryFilter<FlagReportsFiltersOptions[Key]>> | PrimitiveFilter<FlagReportsFiltersOptions[Key]>; } >; export type BannedUsersFilterOptions = { banned_by_id?: string; channel_cid?: string; created_at?: string; reason?: string; user_id?: string; }; export type BannedUsersFilters = QueryFilters< { channel_cid?: | RequireOnlyOne<Pick<QueryFilter<BannedUsersFilterOptions['channel_cid']>, '$eq' | '$in'>> | PrimitiveFilter<BannedUsersFilterOptions['channel_cid']>; } & { reason?: | RequireOnlyOne< { $autocomplete?: BannedUsersFilterOptions['reason']; } & QueryFilter<BannedUsersFilterOptions['reason']> > | PrimitiveFilter<BannedUsersFilterOptions['reason']>; } & { [Key in keyof Omit<BannedUsersFilterOptions, 'channel_cid' | 'reason'>]: | RequireOnlyOne<QueryFilter<BannedUsersFilterOptions[Key]>> | PrimitiveFilter<BannedUsersFilterOptions[Key]>; } >; export type ReactionFilters<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = QueryFilters< { user_id?: | RequireOnlyOne<Pick<QueryFilter<ReactionResponse<StreamChatGenerics>['user_id']>, '$eq' | '$in'>> | PrimitiveFilter<ReactionResponse<StreamChatGenerics>['user_id']>; } & { type?: | RequireOnlyOne<Pick<QueryFilter<ReactionResponse<StreamChatGenerics>['type']>, '$eq'>> | PrimitiveFilter<ReactionResponse<StreamChatGenerics>['type']>; } & { created_at?: | RequireOnlyOne<Pick<QueryFilter<PollResponse['created_at']>, '$eq' | '$gt' | '$lt' | '$gte' | '$lte'>> | PrimitiveFilter<PollResponse['created_at']>; } >; export type ChannelFilters<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = QueryFilters< ContainsOperator<StreamChatGenerics['channelType']> & { members?: | RequireOnlyOne<Pick<QueryFilter<string>, '$in' | '$nin'>> | RequireOnlyOne<Pick<QueryFilter<string[]>, '$eq'>> | PrimitiveFilter<string[]>; } & { name?: | RequireOnlyOne< { $autocomplete?: ChannelResponse<StreamChatGenerics>['name']; } & QueryFilter<ChannelResponse<StreamChatGenerics>['name']> > | PrimitiveFilter<ChannelResponse<StreamChatGenerics>['name']>; } & { [Key in keyof Omit< ChannelResponse<{ attachmentType: StreamChatGenerics['attachmentType']; channelType: {}; commandType: StreamChatGenerics['commandType']; eventType: StreamChatGenerics['eventType']; memberType: StreamChatGenerics['memberType']; messageType: StreamChatGenerics['messageType']; pollOptionType: StreamChatGenerics['pollOptionType']; pollType: StreamChatGenerics['pollType']; reactionType: StreamChatGenerics['reactionType']; userType: StreamChatGenerics['userType']; }>, 'name' | 'members' >]: | RequireOnlyOne< QueryFilter< ChannelResponse<{