stream-chat 4.2.0 → 4.4.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/types.ts CHANGED
@@ -69,6 +69,7 @@ export type AppSettingsAPIResponse<
69
69
  mutes?: boolean;
70
70
  name?: string;
71
71
  push_notifications?: boolean;
72
+ quotes?: boolean;
72
73
  reactions?: boolean;
73
74
  read_events?: boolean;
74
75
  replies?: boolean;
@@ -79,6 +80,7 @@ export type AppSettingsAPIResponse<
79
80
  url_enrichment?: boolean;
80
81
  }
81
82
  >;
83
+ async_url_enrich_enabled?: boolean;
82
84
  auto_translation_enabled?: boolean;
83
85
  before_message_send_hook_url?: string;
84
86
  campaign_enabled?: boolean;
@@ -99,14 +101,17 @@ export type AppSettingsAPIResponse<
99
101
  version: string;
100
102
  apn?: APNConfig;
101
103
  firebase?: FirebaseConfig;
104
+ huawei?: HuaweiConfig;
102
105
  };
103
106
  revoke_tokens_issued_before?: string | null;
107
+ search_backend?: 'disabled' | 'elasticsearch' | 'postgres';
104
108
  sqs_key?: string;
105
109
  sqs_secret?: string;
106
110
  sqs_url?: string;
107
111
  suspended?: boolean;
108
112
  suspended_explanation?: string;
109
- user_search_disallowed_roles?: string[];
113
+ user_search_disallowed_roles?: string[] | null;
114
+ webhook_events?: Array<string>;
110
115
  webhook_url?: string;
111
116
  };
112
117
  };
@@ -191,6 +196,7 @@ export type ChannelResponse<
191
196
  created_by?: UserResponse<UserType> | null;
192
197
  created_by_id?: string;
193
198
  deleted_at?: string;
199
+ hidden?: boolean;
194
200
  invites?: string[];
195
201
  last_message_at?: string;
196
202
  member_count?: number;
@@ -262,6 +268,7 @@ export type CheckPushResponse = APIResponse & {
262
268
  general_errors?: string[];
263
269
  rendered_apn_template?: string;
264
270
  rendered_firebase_template?: string;
271
+ rendered_huawei_template?: string;
265
272
  };
266
273
 
267
274
  export type CheckSQSResponse = APIResponse & {
@@ -824,7 +831,7 @@ export type ChannelQueryOptions<
824
831
  connection_id?: string;
825
832
  data?: ChannelResponse<ChannelType, CommandType, UserType>;
826
833
  members?: PaginationOptions;
827
- messages?: PaginationOptions;
834
+ messages?: MessagePaginationOptions;
828
835
  presence?: boolean;
829
836
  state?: boolean;
830
837
  watch?: boolean;
@@ -853,6 +860,7 @@ export type CreateChannelOptions<CommandType extends string = LiteralStringForUn
853
860
  name?: string;
854
861
  permissions?: PermissionObject[];
855
862
  push_notifications?: boolean;
863
+ quotes?: boolean;
856
864
  reactions?: boolean;
857
865
  read_events?: boolean;
858
866
  replies?: boolean;
@@ -871,9 +879,9 @@ export type CreateCommandOptions<CommandType extends string = LiteralStringForUn
871
879
 
872
880
  export type CustomPermissionOptions = {
873
881
  action: string;
882
+ condition: object;
874
883
  id: string;
875
884
  name: string;
876
- condition?: string;
877
885
  description?: string;
878
886
  owner?: boolean;
879
887
  same_team?: boolean;
@@ -910,9 +918,15 @@ export type InviteOptions<
910
918
  user_id?: string;
911
919
  };
912
920
 
913
- export type MarkAllReadOptions<UserType = UnknownType> = {
921
+ /** @deprecated use MarkChannelsReadOptions instead */
922
+ export type MarkAllReadOptions<
923
+ UserType = UnknownType
924
+ > = MarkChannelsReadOptions<UserType>;
925
+
926
+ export type MarkChannelsReadOptions<UserType = UnknownType> = {
914
927
  client_id?: string;
915
928
  connection_id?: string;
929
+ read_by_channel?: Record<string, string>;
916
930
  user?: UserResponse<UserType>;
917
931
  user_id?: string;
918
932
  };
@@ -950,6 +964,11 @@ export type PaginationOptions = {
950
964
  offset?: number;
951
965
  };
952
966
 
967
+ export type MessagePaginationOptions = PaginationOptions & {
968
+ created_at_around?: string | Date;
969
+ id_around?: string;
970
+ };
971
+
953
972
  export type QueryMembersOptions = {
954
973
  limit?: number;
955
974
  offset?: number;
@@ -978,6 +997,7 @@ export type StreamChatOptions = AxiosRequestConfig & {
978
997
  baseURL?: string;
979
998
  browser?: boolean;
980
999
  device?: BaseDeviceFields;
1000
+ enableInsights?: boolean;
981
1001
  logger?: Logger;
982
1002
  /**
983
1003
  * When network is recovered, we re-query the active channels on client. But in single query, you can recover
@@ -1442,6 +1462,10 @@ export type UserSort<UserType = UnknownType> =
1442
1462
  | Sort<UserResponse<UserType>>
1443
1463
  | Array<Sort<UserResponse<UserType>>>;
1444
1464
 
1465
+ export type MemberSort<UserType = UnknownType> =
1466
+ | Sort<Pick<UserResponse<UserType>, 'id' | 'created_at' | 'name'>>
1467
+ | Array<Sort<Pick<UserResponse<UserType>, 'id' | 'created_at' | 'name'>>>;
1468
+
1445
1469
  export type SearchMessageSortBase<MessageType = UnknownType> = Sort<MessageType> & {
1446
1470
  attachments?: AscDesc;
1447
1471
  'attachments.type'?: AscDesc;
@@ -1509,6 +1533,7 @@ export type AppSettings = {
1509
1533
  p12_cert?: string;
1510
1534
  team_id?: string;
1511
1535
  };
1536
+ async_url_enrich_enabled?: boolean;
1512
1537
  auto_translation_enabled?: boolean;
1513
1538
  custom_action_handler_url?: string;
1514
1539
  disable_auth_checks?: boolean;
@@ -1523,6 +1548,11 @@ export type AppSettings = {
1523
1548
  server_key?: string;
1524
1549
  };
1525
1550
  grants?: Record<string, string[]>;
1551
+ huawei_config?: {
1552
+ id: string;
1553
+ secret: string;
1554
+ data_template?: string;
1555
+ };
1526
1556
  image_moderation_enabled?: boolean;
1527
1557
  image_upload_config?: FileUploadConfig;
1528
1558
  multi_tenant_enabled?: boolean;
@@ -1533,6 +1563,7 @@ export type AppSettings = {
1533
1563
  sqs_key?: string;
1534
1564
  sqs_secret?: string;
1535
1565
  sqs_url?: string;
1566
+ webhook_events?: Array<string> | null;
1536
1567
  webhook_url?: string;
1537
1568
  };
1538
1569
 
@@ -1557,6 +1588,19 @@ export type Attachment<T = UnknownType> = T & {
1557
1588
  type?: string;
1558
1589
  };
1559
1590
 
1591
+ export type OGAttachment = {
1592
+ og_scrape_url: string;
1593
+ asset_url?: string; // og:video | og:audio
1594
+ author_link?: string; // og:site
1595
+ author_name?: string; // og:site_name
1596
+ image_url?: string; // og:image
1597
+ text?: string; // og:description
1598
+ thumb_url?: string; // og:image
1599
+ title?: string; // og:title
1600
+ title_link?: string; // og:url
1601
+ type?: string | 'video' | 'audio' | 'image';
1602
+ };
1603
+
1560
1604
  export type BlockList = {
1561
1605
  name: string;
1562
1606
  words: string[];
@@ -1590,6 +1634,7 @@ export type ChannelConfigFields = {
1590
1634
  mutes?: boolean;
1591
1635
  name?: string;
1592
1636
  push_notifications?: boolean;
1637
+ quotes?: boolean;
1593
1638
  reactions?: boolean;
1594
1639
  read_events?: boolean;
1595
1640
  replies?: boolean;
@@ -1653,10 +1698,11 @@ export type CheckPushInput<UserType = UnknownType> = {
1653
1698
  user_id?: string;
1654
1699
  };
1655
1700
 
1701
+ export type PushProvider = 'apn' | 'firebase' | 'huawei';
1702
+
1656
1703
  export type CommandVariants<CommandType extends string = LiteralStringForUnion> =
1657
1704
  | 'all'
1658
1705
  | 'ban'
1659
- | 'flag'
1660
1706
  | 'fun_set'
1661
1707
  | 'giphy'
1662
1708
  | 'imgur'
@@ -1695,7 +1741,7 @@ export type Device<UserType = UnknownType> = DeviceFields & {
1695
1741
 
1696
1742
  export type BaseDeviceFields = {
1697
1743
  id: string;
1698
- push_provider: 'apn' | 'firebase';
1744
+ push_provider: PushProvider;
1699
1745
  };
1700
1746
 
1701
1747
  export type DeviceFields = BaseDeviceFields & {
@@ -1799,6 +1845,7 @@ export type ExportChannelRequest = {
1799
1845
 
1800
1846
  export type ExportChannelOptions = {
1801
1847
  clear_deleted_message_text?: boolean;
1848
+ include_truncated_messages?: boolean;
1802
1849
  };
1803
1850
 
1804
1851
  export type Field = {
@@ -1808,10 +1855,10 @@ export type Field = {
1808
1855
  };
1809
1856
 
1810
1857
  export type FileUploadConfig = {
1811
- allowed_file_extensions?: string[];
1812
- allowed_mime_types?: string[];
1813
- blocked_file_extensions?: string[];
1814
- blocked_mime_types?: string[];
1858
+ allowed_file_extensions?: string[] | null;
1859
+ allowed_mime_types?: string[] | null;
1860
+ blocked_file_extensions?: string[] | null;
1861
+ blocked_mime_types?: string[] | null;
1815
1862
  };
1816
1863
 
1817
1864
  export type FirebaseConfig = {
@@ -1821,6 +1868,11 @@ export type FirebaseConfig = {
1821
1868
  notification_template?: string;
1822
1869
  };
1823
1870
 
1871
+ export type HuaweiConfig = {
1872
+ data_template?: string;
1873
+ enabled?: boolean;
1874
+ };
1875
+
1824
1876
  export type LiteralStringForUnion = string & {};
1825
1877
 
1826
1878
  export type Logger = (
@@ -1893,6 +1945,7 @@ export type PartialMessageUpdate<MessageType = UnknownType> = {
1893
1945
 
1894
1946
  export type PermissionAPIObject = {
1895
1947
  action?: string;
1948
+ condition?: object;
1896
1949
  custom?: boolean;
1897
1950
  description?: string;
1898
1951
  id?: string;
@@ -1990,6 +2043,7 @@ export type TestPushDataInput = {
1990
2043
  apnTemplate?: string;
1991
2044
  firebaseDataTemplate?: string;
1992
2045
  firebaseTemplate?: string;
2046
+ huaweiDataTemplate?: string;
1993
2047
  messageID?: string;
1994
2048
  skipDevices?: boolean;
1995
2049
  };
@@ -2092,6 +2146,30 @@ export type User<UserType = UnknownType> = UserType & {
2092
2146
  username?: string;
2093
2147
  };
2094
2148
 
2149
+ export type TaskResponse = {
2150
+ task_id: string;
2151
+ };
2152
+
2153
+ export type DeleteChannelsResponse = {
2154
+ result: Record<string, string>;
2155
+ } & Partial<TaskResponse>;
2156
+
2157
+ export type DeleteType = 'soft' | 'hard';
2158
+
2159
+ /*
2160
+ DeleteUserOptions specifies a collection of one or more `user_ids` to be deleted.
2161
+
2162
+ `user` soft|hard determines if the user needs to be hard- or soft-deleted, where hard-delete
2163
+ implies that all related objects (messages, flags, etc) will be hard-deleted as well.
2164
+ `conversations` soft|hard will delete any 1to1 channels that the user was a member of.
2165
+ `messages` soft-hard will delete any messages that the user has sent.
2166
+ */
2167
+ export type DeleteUserOptions = {
2168
+ user: DeleteType;
2169
+ conversations?: DeleteType;
2170
+ messages?: DeleteType;
2171
+ };
2172
+
2095
2173
  export type SegmentData = {
2096
2174
  description: string;
2097
2175
  // TODO: define this type in more detail
@@ -2146,3 +2224,15 @@ export type Campaign = {
2146
2224
  updated_at: string;
2147
2225
  } & CampaignData &
2148
2226
  CampaignStatus;
2227
+
2228
+ export type TaskStatus = {
2229
+ created_at: string;
2230
+ status: string;
2231
+ task_id: string;
2232
+ updated_at: string;
2233
+ error?: {
2234
+ description: string;
2235
+ type: string;
2236
+ };
2237
+ result?: UnknownType;
2238
+ };
package/src/utils.ts CHANGED
@@ -144,12 +144,57 @@ export function retryInterval(numberOfFailures: number) {
144
144
  return Math.floor(Math.random() * (max - min) + min);
145
145
  }
146
146
 
147
- /** adopted from https://github.com/ai/nanoid/blob/master/non-secure/index.js */
148
- const alphabet = 'ModuleSymbhasOwnPr0123456789ABCDEFGHNRVfgctiUvzKqYTJkLxpZXIjQW';
149
147
  export function randomId() {
150
- let id = '';
151
- for (let i = 0; i < 21; i++) {
152
- id += alphabet[(Math.random() * 64) | 0];
148
+ return generateUUIDv4();
149
+ }
150
+
151
+ function hex(bytes: Uint8Array): string {
152
+ let s = '';
153
+ for (let i = 0; i < bytes.length; i++) {
154
+ s += bytes[i].toString(16).padStart(2, '0');
153
155
  }
154
- return id;
156
+ return s;
157
+ }
158
+
159
+ // https://tools.ietf.org/html/rfc4122
160
+ export function generateUUIDv4() {
161
+ const bytes = getRandomBytes(16);
162
+ bytes[6] = (bytes[6] & 0x0f) | 0x40; // version
163
+ bytes[8] = (bytes[8] & 0xbf) | 0x80; // variant
164
+
165
+ return (
166
+ hex(bytes.subarray(0, 4)) +
167
+ '-' +
168
+ hex(bytes.subarray(4, 6)) +
169
+ '-' +
170
+ hex(bytes.subarray(6, 8)) +
171
+ '-' +
172
+ hex(bytes.subarray(8, 10)) +
173
+ '-' +
174
+ hex(bytes.subarray(10, 16))
175
+ );
176
+ }
177
+
178
+ function getRandomValuesWithMathRandom(bytes: Uint8Array): void {
179
+ const max = Math.pow(2, (8 * bytes.byteLength) / bytes.length);
180
+ for (let i = 0; i < bytes.length; i++) {
181
+ bytes[i] = Math.random() * max;
182
+ }
183
+ }
184
+ declare const msCrypto: Crypto;
185
+
186
+ const getRandomValues = (() => {
187
+ if (typeof crypto !== 'undefined') {
188
+ return crypto.getRandomValues.bind(crypto);
189
+ } else if (typeof msCrypto !== 'undefined') {
190
+ return msCrypto.getRandomValues.bind(msCrypto);
191
+ } else {
192
+ return getRandomValuesWithMathRandom;
193
+ }
194
+ })();
195
+
196
+ function getRandomBytes(length: number): Uint8Array {
197
+ const bytes = new Uint8Array(length);
198
+ getRandomValues(bytes);
199
+ return bytes;
155
200
  }