stream-chat 4.5.0-beta.0 → 5.1.1

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/src/errors.ts CHANGED
@@ -28,7 +28,7 @@ export const APIErrorCodes: Record<string, { name: string; retryable: boolean }>
28
28
  '99': { name: 'AppSuspendedError', retryable: false },
29
29
  };
30
30
 
31
- type APIError = Error & { code?: number; isWSFailure?: boolean };
31
+ type APIError = Error & { code: number; isWSFailure?: boolean };
32
32
 
33
33
  export function isAPIError(error: Error): error is APIError {
34
34
  return (error as APIError).code !== undefined;
package/src/types.ts CHANGED
@@ -147,6 +147,48 @@ export type MessageFlagsResponse<
147
147
  }>;
148
148
  };
149
149
 
150
+ export type FlagReport<
151
+ ChannelType extends UR = UR,
152
+ CommandType extends string = LiteralStringForUnion,
153
+ UserType extends UR = UR,
154
+ AttachmentType = UR,
155
+ MessageType = UR,
156
+ ReactionType = UR
157
+ > = {
158
+ flags_count: number;
159
+ id: string;
160
+ message: MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>;
161
+ user: UserResponse<UserType>;
162
+ created_at?: string;
163
+ review_details?: Object;
164
+ review_result?: string;
165
+ reviewed_at?: string;
166
+ reviewed_by?: UserResponse<UserType>;
167
+ updated_at?: string;
168
+ };
169
+
170
+ export type FlagReportsResponse<
171
+ ChannelType extends UR = UR,
172
+ CommandType extends string = LiteralStringForUnion,
173
+ UserType extends UR = UR,
174
+ AttachmentType = UR,
175
+ MessageType = UR,
176
+ ReactionType = UR
177
+ > = APIResponse & {
178
+ flag_reports: Array<FlagReport<ChannelType, CommandType, UserType, AttachmentType, MessageType, ReactionType>>;
179
+ };
180
+
181
+ export type ReviewFlagReportResponse<
182
+ ChannelType extends UR = UR,
183
+ CommandType extends string = LiteralStringForUnion,
184
+ UserType extends UR = UR,
185
+ AttachmentType = UR,
186
+ MessageType = UR,
187
+ ReactionType = UR
188
+ > = APIResponse & {
189
+ flag_report: FlagReport<ChannelType, CommandType, UserType, AttachmentType, MessageType, ReactionType>;
190
+ };
191
+
150
192
  export type BannedUsersResponse<
151
193
  ChannelType extends UR = UR,
152
194
  CommandType extends string = LiteralStringForUnion,
@@ -326,6 +368,7 @@ export type FlagMessageResponse<UserType = UR> = APIResponse & {
326
368
  updated_at: string;
327
369
  user: UserResponse<UserType>;
328
370
  approved_at?: string;
371
+ details?: Object; // Any JSON
329
372
  rejected_at?: string;
330
373
  reviewed_at?: string;
331
374
  reviewed_by?: string;
@@ -340,6 +383,7 @@ export type FlagUserResponse<UserType = UR> = APIResponse & {
340
383
  updated_at: string;
341
384
  user: UserResponse<UserType>;
342
385
  approved_at?: string;
386
+ details?: Object; // Any JSON
343
387
  rejected_at?: string;
344
388
  reviewed_at?: string;
345
389
  reviewed_by?: string;
@@ -426,7 +470,7 @@ export type ListChannelTypesAPIResponse<
426
470
  > = ListChannelResponse<CommandType>;
427
471
 
428
472
  export type ListCommandsResponse<CommandType extends string = LiteralStringForUnion> = APIResponse & {
429
- commands: Array<CreateCommandOptions<CommandType> & CreatedAtUpdatedAt>;
473
+ commands: Array<CreateCommandOptions<CommandType> & Partial<CreatedAtUpdatedAt>>;
430
474
  };
431
475
 
432
476
  export type MuteChannelAPIResponse<
@@ -665,11 +709,17 @@ export type UserResponse<UserType = UR> = User<UserType> & {
665
709
  language?: TranslationLanguages | '';
666
710
  last_active?: string;
667
711
  online?: boolean;
712
+ push_notifications?: PushNotificationSettings;
668
713
  revoke_tokens_issued_before?: string;
669
714
  shadow_banned?: boolean;
670
715
  updated_at?: string;
671
716
  };
672
717
 
718
+ export type PushNotificationSettings = {
719
+ disabled?: boolean;
720
+ disabled_until?: string | null;
721
+ };
722
+
673
723
  /**
674
724
  * Option Types
675
725
  */
@@ -679,6 +729,16 @@ export type MessageFlagsPaginationOptions = {
679
729
  offset?: number;
680
730
  };
681
731
 
732
+ export type FlagReportsPaginationOptions = {
733
+ limit?: number;
734
+ offset?: number;
735
+ };
736
+
737
+ export type ReviewFlagReportOptions = {
738
+ review_details?: Object;
739
+ user_id?: string;
740
+ };
741
+
682
742
  export type BannedUsersPaginationOptions = Omit<PaginationOptions, 'id_gt' | 'id_gte' | 'id_lt' | 'id_lte'>;
683
743
 
684
744
  export type BanUserOptions<UserType = UR> = UnBanUserOptions & {
@@ -687,14 +747,6 @@ export type BanUserOptions<UserType = UR> = UnBanUserOptions & {
687
747
  ip_ban?: boolean;
688
748
  reason?: string;
689
749
  timeout?: number;
690
- /**
691
- * @deprecated please use banned_by
692
- */
693
- user?: UserResponse<UserType>;
694
- /**
695
- * @deprecated please use banned_by_id
696
- */
697
- user_id?: string;
698
750
  };
699
751
 
700
752
  export type ChannelOptions = {
@@ -842,6 +894,21 @@ export type MessagePaginationOptions = PaginationOptions & {
842
894
  id_around?: string;
843
895
  };
844
896
 
897
+ export type PinnedMessagePaginationOptions = {
898
+ id_around?: string;
899
+ id_gt?: string;
900
+ id_gte?: string;
901
+ id_lt?: string;
902
+ id_lte?: string;
903
+ limit?: number;
904
+ offset?: number;
905
+ pinned_at_after?: string | Date;
906
+ pinned_at_after_or_equal?: string | Date;
907
+ pinned_at_around?: string | Date;
908
+ pinned_at_before?: string | Date;
909
+ pinned_at_before_or_equal?: string | Date;
910
+ };
911
+
845
912
  export type QueryMembersOptions = {
846
913
  limit?: number;
847
914
  offset?: number;
@@ -985,6 +1052,7 @@ export type EventTypes =
985
1052
  | 'channel.unmuted'
986
1053
  | 'channel.updated'
987
1054
  | 'channel.visible'
1055
+ | 'transport.changed' // ws vs longpoll
988
1056
  | 'connection.changed'
989
1057
  | 'connection.recovered'
990
1058
  | 'health.check'
@@ -1052,6 +1120,43 @@ export type MessageFlagsFilters = QueryFilters<
1052
1120
  }
1053
1121
  >;
1054
1122
 
1123
+ export type FlagReportsFiltersOptions = {
1124
+ is_reviewed?: boolean;
1125
+ message_id?: string;
1126
+ report_id?: string;
1127
+ review_result?: string;
1128
+ reviewed_by?: string;
1129
+ user_id?: string;
1130
+ };
1131
+
1132
+ export type FlagReportsFilters = QueryFilters<
1133
+ {
1134
+ report_id?:
1135
+ | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['report_id']>, '$eq' | '$in'>>
1136
+ | PrimitiveFilter<FlagReportsFiltersOptions['report_id']>;
1137
+ } & {
1138
+ review_result?:
1139
+ | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['review_result']>, '$eq' | '$in'>>
1140
+ | PrimitiveFilter<FlagReportsFiltersOptions['review_result']>;
1141
+ } & {
1142
+ reviewed_by?:
1143
+ | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['reviewed_by']>, '$eq' | '$in'>>
1144
+ | PrimitiveFilter<FlagReportsFiltersOptions['reviewed_by']>;
1145
+ } & {
1146
+ user_id?:
1147
+ | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['user_id']>, '$eq' | '$in'>>
1148
+ | PrimitiveFilter<FlagReportsFiltersOptions['user_id']>;
1149
+ } & {
1150
+ message_id?:
1151
+ | RequireOnlyOne<Pick<QueryFilter<FlagReportsFiltersOptions['message_id']>, '$eq' | '$in'>>
1152
+ | PrimitiveFilter<FlagReportsFiltersOptions['message_id']>;
1153
+ } & {
1154
+ [Key in keyof Omit<
1155
+ FlagReportsFiltersOptions,
1156
+ 'report_id' | 'user_id' | 'message_id' | 'review_result' | 'reviewed_by'
1157
+ >]: RequireOnlyOne<QueryFilter<FlagReportsFiltersOptions[Key]>> | PrimitiveFilter<FlagReportsFiltersOptions[Key]>;
1158
+ }
1159
+ >;
1055
1160
  export type BannedUsersFilterOptions = {
1056
1161
  banned_by_id?: string;
1057
1162
  channel_cid?: string;
@@ -1238,6 +1343,9 @@ export type ChannelSortBase<ChannelType = UR> = Sort<ChannelType> & {
1238
1343
  updated_at?: AscDesc;
1239
1344
  };
1240
1345
 
1346
+ export type PinnedMessagesSort = PinnedMessagesSortBase | Array<PinnedMessagesSortBase>;
1347
+ export type PinnedMessagesSortBase = { pinned_at?: AscDesc };
1348
+
1241
1349
  export type Sort<T> = {
1242
1350
  [P in keyof T]?: AscDesc;
1243
1351
  };
@@ -1613,13 +1721,16 @@ export type EndpointName =
1613
1721
  export type ExportChannelRequest = {
1614
1722
  id: string;
1615
1723
  type: string;
1724
+ cid?: string;
1616
1725
  messages_since?: Date;
1617
1726
  messages_until?: Date;
1618
1727
  };
1619
1728
 
1620
1729
  export type ExportChannelOptions = {
1621
1730
  clear_deleted_message_text?: boolean;
1731
+ export_users?: boolean;
1622
1732
  include_truncated_messages?: boolean;
1733
+ version?: string;
1623
1734
  };
1624
1735
 
1625
1736
  export type Field = {
@@ -1665,7 +1776,9 @@ export type MessageBase<AttachmentType = UR, MessageType = UR, UserType = UR> =
1665
1776
  html?: string;
1666
1777
  mml?: string;
1667
1778
  parent_id?: string;
1779
+ pin_expires?: string;
1668
1780
  pinned?: boolean;
1781
+ pinned_at?: string;
1669
1782
  quoted_message_id?: string;
1670
1783
  show_in_channel?: boolean;
1671
1784
  text?: string;
@@ -1709,6 +1822,7 @@ export type PermissionAPIObject = {
1709
1822
  custom?: boolean;
1710
1823
  description?: string;
1711
1824
  id?: string;
1825
+ level?: string;
1712
1826
  name?: string;
1713
1827
  owner?: boolean;
1714
1828
  same_team?: boolean;
package/src/utils.ts CHANGED
@@ -205,7 +205,7 @@ export function convertErrorToJson(err: Error) {
205
205
  }
206
206
 
207
207
  /**
208
- * isOnline safely return the navigator.online value
208
+ * isOnline safely return the navigator.online value for browser env
209
209
  * if navigator is not in global object, it always return true
210
210
  */
211
211
  export function isOnline() {
@@ -216,7 +216,16 @@ export function isOnline() {
216
216
  ? window.navigator
217
217
  : undefined;
218
218
 
219
- if (!nav) return true;
219
+ if (!nav) {
220
+ console.warn('isOnline failed to access window.navigator and assume browser is online');
221
+ return true;
222
+ }
223
+
224
+ // RN navigator has undefined for onLine
225
+ if (typeof nav.onLine !== 'boolean') {
226
+ return true;
227
+ }
228
+
220
229
  return nav.onLine;
221
230
  }
222
231