stream-chat 5.6.0 → 6.2.0

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.
Files changed (40) hide show
  1. package/README.md +59 -114
  2. package/dist/browser.es.js +464 -366
  3. package/dist/browser.es.js.map +1 -1
  4. package/dist/browser.full-bundle.min.js +1 -1
  5. package/dist/browser.full-bundle.min.js.map +1 -1
  6. package/dist/browser.js +464 -366
  7. package/dist/browser.js.map +1 -1
  8. package/dist/index.es.js +464 -366
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/index.js +464 -366
  11. package/dist/index.js.map +1 -1
  12. package/dist/types/channel.d.ts +124 -124
  13. package/dist/types/channel.d.ts.map +1 -1
  14. package/dist/types/channel_state.d.ts +41 -41
  15. package/dist/types/channel_state.d.ts.map +1 -1
  16. package/dist/types/client.d.ts +190 -163
  17. package/dist/types/client.d.ts.map +1 -1
  18. package/dist/types/client_state.d.ts +6 -6
  19. package/dist/types/client_state.d.ts.map +1 -1
  20. package/dist/types/connection.d.ts +10 -10
  21. package/dist/types/connection.d.ts.map +1 -1
  22. package/dist/types/connection_fallback.d.ts +7 -7
  23. package/dist/types/connection_fallback.d.ts.map +1 -1
  24. package/dist/types/insights.d.ts +2 -2
  25. package/dist/types/token_manager.d.ts +6 -6
  26. package/dist/types/token_manager.d.ts.map +1 -1
  27. package/dist/types/types.d.ts +404 -236
  28. package/dist/types/types.d.ts.map +1 -1
  29. package/dist/types/utils.d.ts +2 -2
  30. package/dist/types/utils.d.ts.map +1 -1
  31. package/package.json +2 -2
  32. package/src/channel.ts +196 -290
  33. package/src/channel_state.ts +54 -219
  34. package/src/client.ts +297 -524
  35. package/src/client_state.ts +6 -6
  36. package/src/connection.ts +7 -22
  37. package/src/connection_fallback.ts +7 -21
  38. package/src/token_manager.ts +6 -6
  39. package/src/types.ts +540 -487
  40. package/src/utils.ts +7 -11
package/src/client.ts CHANGED
@@ -72,7 +72,6 @@ import {
72
72
  GetRateLimitsResponse,
73
73
  ListChannelResponse,
74
74
  ListCommandsResponse,
75
- LiteralStringForUnion,
76
75
  Logger,
77
76
  MarkChannelsReadOptions,
78
77
  Message,
@@ -97,7 +96,6 @@ import {
97
96
  TestSQSDataInput,
98
97
  TokenOrProvider,
99
98
  UnBanUserOptions,
100
- UR,
101
99
  UpdateChannelOptions,
102
100
  UpdateChannelResponse,
103
101
  UpdateCommandOptions,
@@ -120,6 +118,8 @@ import {
120
118
  DeleteChannelsResponse,
121
119
  TaskResponse,
122
120
  ReservedMessageFields,
121
+ ExtendableGenerics,
122
+ DefaultGenerics,
123
123
  ReviewFlagReportResponse,
124
124
  FlagReportsFilters,
125
125
  FlagReportsResponse,
@@ -128,9 +128,13 @@ import {
128
128
  ExportUsersRequest,
129
129
  ExportUsersResponse,
130
130
  CreateImportResponse,
131
+ CreateImportURLResponse,
131
132
  GetImportResponse,
132
133
  ListImportsResponse,
133
134
  ListImportsPaginationOptions,
135
+ FlagsFilters,
136
+ FlagsPaginationOptions,
137
+ FlagsResponse,
134
138
  } from './types';
135
139
  import { InsightMetrics, postInsights } from './insights';
136
140
 
@@ -138,20 +142,12 @@ function isString(x: unknown): x is string {
138
142
  return typeof x === 'string' || x instanceof String;
139
143
  }
140
144
 
141
- export class StreamChat<
142
- AttachmentType extends UR = UR,
143
- ChannelType extends UR = UR,
144
- CommandType extends string = LiteralStringForUnion,
145
- EventType extends UR = UR,
146
- MessageType extends UR = UR,
147
- ReactionType extends UR = UR,
148
- UserType extends UR = UR
149
- > {
145
+ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> {
150
146
  private static _instance?: unknown | StreamChat; // type is undefined|StreamChat, unknown is due to TS limitations with statics
151
147
 
152
- _user?: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>;
148
+ _user?: OwnUserResponse<StreamChatGenerics> | UserResponse<StreamChatGenerics>;
153
149
  activeChannels: {
154
- [key: string]: Channel<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>;
150
+ [key: string]: Channel<StreamChatGenerics>;
155
151
  };
156
152
  anonymous: boolean;
157
153
  axiosInstance: AxiosInstance;
@@ -159,12 +155,10 @@ export class StreamChat<
159
155
  browser: boolean;
160
156
  cleaningIntervalRef?: NodeJS.Timeout;
161
157
  clientID?: string;
162
- configs: Configs<CommandType>;
158
+ configs: Configs<StreamChatGenerics>;
163
159
  key: string;
164
160
  listeners: {
165
- [key: string]: Array<
166
- (event: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>) => void
167
- >;
161
+ [key: string]: Array<(event: Event<StreamChatGenerics>) => void>;
168
162
  };
169
163
  logger: Logger;
170
164
  /**
@@ -177,37 +171,21 @@ export class StreamChat<
177
171
  * manually calling queryChannels endpoint.
178
172
  */
179
173
  recoverStateOnReconnect?: boolean;
180
- mutedChannels: ChannelMute<ChannelType, CommandType, UserType>[];
181
- mutedUsers: Mute<UserType>[];
174
+ mutedChannels: ChannelMute<StreamChatGenerics>[];
175
+ mutedUsers: Mute<StreamChatGenerics>[];
182
176
  node: boolean;
183
177
  options: StreamChatOptions;
184
178
  secret?: string;
185
- setUserPromise: ConnectAPIResponse<ChannelType, CommandType, UserType> | null;
186
- state: ClientState<UserType>;
187
- tokenManager: TokenManager<UserType>;
188
- user?: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>;
179
+ setUserPromise: ConnectAPIResponse<StreamChatGenerics> | null;
180
+ state: ClientState<StreamChatGenerics>;
181
+ tokenManager: TokenManager<StreamChatGenerics>;
182
+ user?: OwnUserResponse<StreamChatGenerics> | UserResponse<StreamChatGenerics>;
189
183
  userAgent?: string;
190
184
  userID?: string;
191
185
  wsBaseURL?: string;
192
- wsConnection: StableWSConnection<
193
- ChannelType,
194
- CommandType,
195
- UserType,
196
- AttachmentType,
197
- EventType,
198
- MessageType,
199
- ReactionType
200
- > | null;
201
- wsFallback?: WSConnectionFallback<
202
- AttachmentType,
203
- ChannelType,
204
- CommandType,
205
- EventType,
206
- MessageType,
207
- ReactionType,
208
- UserType
209
- >;
210
- wsPromise: ConnectAPIResponse<ChannelType, CommandType, UserType> | null;
186
+ wsConnection: StableWSConnection<StreamChatGenerics> | null;
187
+ wsFallback?: WSConnectionFallback<StreamChatGenerics>;
188
+ wsPromise: ConnectAPIResponse<StreamChatGenerics> | null;
211
189
  consecutiveFailures: number;
212
190
  insightMetrics: InsightMetrics;
213
191
  defaultWSTimeoutWithFallback: number;
@@ -238,7 +216,7 @@ export class StreamChat<
238
216
  // set the key
239
217
  this.key = key;
240
218
  this.listeners = {};
241
- this.state = new ClientState<UserType>();
219
+ this.state = new ClientState<StreamChatGenerics>();
242
220
  // a list of channels to hide ws events from
243
221
  this.mutedChannels = [];
244
222
  this.mutedUsers = [];
@@ -374,77 +352,29 @@ export class StreamChat<
374
352
  * @example <caption>secret is optional and only used in server side mode</caption>
375
353
  * StreamChat.getInstance('api_key', "secret", { httpsAgent: customAgent })
376
354
  */
377
- public static getInstance<
378
- AttachmentType extends UR = UR,
379
- ChannelType extends UR = UR,
380
- CommandType extends string = LiteralStringForUnion,
381
- EventType extends UR = UR,
382
- MessageType extends UR = UR,
383
- ReactionType extends UR = UR,
384
- UserType extends UR = UR
385
- >(
355
+ public static getInstance<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics>(
386
356
  key: string,
387
357
  options?: StreamChatOptions,
388
- ): StreamChat<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>;
389
- public static getInstance<
390
- AttachmentType extends UR = UR,
391
- ChannelType extends UR = UR,
392
- CommandType extends string = LiteralStringForUnion,
393
- EventType extends UR = UR,
394
- MessageType extends UR = UR,
395
- ReactionType extends UR = UR,
396
- UserType extends UR = UR
397
- >(
358
+ ): StreamChat<StreamChatGenerics>;
359
+ public static getInstance<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics>(
398
360
  key: string,
399
361
  secret?: string,
400
362
  options?: StreamChatOptions,
401
- ): StreamChat<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>;
402
- public static getInstance<
403
- AttachmentType extends UR = UR,
404
- ChannelType extends UR = UR,
405
- CommandType extends string = LiteralStringForUnion,
406
- EventType extends UR = UR,
407
- MessageType extends UR = UR,
408
- ReactionType extends UR = UR,
409
- UserType extends UR = UR
410
- >(
363
+ ): StreamChat<StreamChatGenerics>;
364
+ public static getInstance<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics>(
411
365
  key: string,
412
366
  secretOrOptions?: StreamChatOptions | string,
413
367
  options?: StreamChatOptions,
414
- ): StreamChat<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType> {
368
+ ): StreamChat<StreamChatGenerics> {
415
369
  if (!StreamChat._instance) {
416
370
  if (typeof secretOrOptions === 'string') {
417
- StreamChat._instance = new StreamChat<
418
- AttachmentType,
419
- ChannelType,
420
- CommandType,
421
- EventType,
422
- MessageType,
423
- ReactionType,
424
- UserType
425
- >(key, secretOrOptions, options);
371
+ StreamChat._instance = new StreamChat<StreamChatGenerics>(key, secretOrOptions, options);
426
372
  } else {
427
- StreamChat._instance = new StreamChat<
428
- AttachmentType,
429
- ChannelType,
430
- CommandType,
431
- EventType,
432
- MessageType,
433
- ReactionType,
434
- UserType
435
- >(key, secretOrOptions);
373
+ StreamChat._instance = new StreamChat<StreamChatGenerics>(key, secretOrOptions);
436
374
  }
437
375
  }
438
376
 
439
- return StreamChat._instance as StreamChat<
440
- AttachmentType,
441
- ChannelType,
442
- CommandType,
443
- EventType,
444
- MessageType,
445
- ReactionType,
446
- UserType
447
- >;
377
+ return StreamChat._instance as StreamChat<StreamChatGenerics>;
448
378
  }
449
379
 
450
380
  devToken(userID: string) {
@@ -467,13 +397,13 @@ export class StreamChat<
467
397
  /**
468
398
  * connectUser - Set the current user and open a WebSocket connection
469
399
  *
470
- * @param {OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>} user Data about this user. IE {name: "john"}
400
+ * @param {OwnUserResponse<StreamChatGenerics> | UserResponse<StreamChatGenerics>} user Data about this user. IE {name: "john"}
471
401
  * @param {TokenOrProvider} userTokenOrProvider Token or provider
472
402
  *
473
- * @return {ConnectAPIResponse<ChannelType, CommandType, UserType>} Returns a promise that resolves when the connection is setup
403
+ * @return {ConnectAPIResponse<StreamChatGenerics>} Returns a promise that resolves when the connection is setup
474
404
  */
475
405
  connectUser = async (
476
- user: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>,
406
+ user: OwnUserResponse<StreamChatGenerics> | UserResponse<StreamChatGenerics>,
477
407
  userTokenOrProvider: TokenOrProvider,
478
408
  ) => {
479
409
  if (!user.id) {
@@ -530,17 +460,17 @@ export class StreamChat<
530
460
  *
531
461
  * setUser - Set the current user and open a WebSocket connection
532
462
  *
533
- * @param {OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>} user Data about this user. IE {name: "john"}
463
+ * @param {OwnUserResponse<StreamChatGenerics> | UserResponse<StreamChatGenerics>} user Data about this user. IE {name: "john"}
534
464
  * @param {TokenOrProvider} userTokenOrProvider Token or provider
535
465
  *
536
- * @return {ConnectAPIResponse<ChannelType, CommandType, UserType>} Returns a promise that resolves when the connection is setup
466
+ * @return {ConnectAPIResponse<StreamChatGenerics>} Returns a promise that resolves when the connection is setup
537
467
  */
538
468
  setUser = this.connectUser;
539
469
 
540
- _setToken = (user: UserResponse<UserType>, userTokenOrProvider: TokenOrProvider) =>
470
+ _setToken = (user: UserResponse<StreamChatGenerics>, userTokenOrProvider: TokenOrProvider) =>
541
471
  this.tokenManager.setTokenOrProvider(userTokenOrProvider, user);
542
472
 
543
- _setUser(user: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>) {
473
+ _setUser(user: OwnUserResponse<StreamChatGenerics> | UserResponse<StreamChatGenerics>) {
544
474
  /**
545
475
  * This one is used by the frontend. This is a copy of the current user object stored on backend.
546
476
  * It contains reserved properties and own user properties which are not present in `this._user`.
@@ -651,9 +581,7 @@ export class StreamChat<
651
581
  * Revokes all tokens on application level issued before given time
652
582
  */
653
583
  async revokeTokens(before: Date | string | null) {
654
- return await this.updateAppSettings({
655
- revoke_tokens_issued_before: this._normalizeDate(before),
656
- });
584
+ return await this.updateAppSettings({ revoke_tokens_issued_before: this._normalizeDate(before) });
657
585
  }
658
586
 
659
587
  /**
@@ -673,13 +601,11 @@ export class StreamChat<
673
601
  before = this._normalizeDate(before);
674
602
  }
675
603
 
676
- const users: PartialUserUpdate<UserType>[] = [];
604
+ const users: PartialUserUpdate<StreamChatGenerics>[] = [];
677
605
  for (const userID of userIDs) {
678
606
  users.push({
679
607
  id: userID,
680
- set: <Partial<UserResponse<UserType>>>{
681
- revoke_tokens_issued_before: before,
682
- },
608
+ set: <Partial<UserResponse<StreamChatGenerics>>>{ revoke_tokens_issued_before: before },
683
609
  });
684
610
  }
685
611
 
@@ -690,7 +616,7 @@ export class StreamChat<
690
616
  * getAppSettings - retrieves application settings
691
617
  */
692
618
  async getAppSettings() {
693
- return await this.get<AppSettingsAPIResponse<CommandType>>(this.baseURL + '/app');
619
+ return await this.get<AppSettingsAPIResponse<StreamChatGenerics>>(this.baseURL + '/app');
694
620
  }
695
621
 
696
622
  /**
@@ -786,10 +712,7 @@ export class StreamChat<
786
712
 
787
713
  this.anonymous = true;
788
714
  this.userID = randomId();
789
- const anonymousUser = {
790
- id: this.userID,
791
- anon: true,
792
- } as UserResponse<UserType>;
715
+ const anonymousUser = { id: this.userID, anon: true } as UserResponse<StreamChatGenerics>;
793
716
 
794
717
  this._setToken(anonymousUser, '');
795
718
  this._setUser(anonymousUser);
@@ -805,15 +728,15 @@ export class StreamChat<
805
728
  /**
806
729
  * setGuestUser - Setup a temporary guest user
807
730
  *
808
- * @param {UserResponse<UserType>} user Data about this user. IE {name: "john"}
731
+ * @param {UserResponse<StreamChatGenerics>} user Data about this user. IE {name: "john"}
809
732
  *
810
- * @return {ConnectAPIResponse<ChannelType, CommandType, UserType>} Returns a promise that resolves when the connection is setup
733
+ * @return {ConnectAPIResponse<StreamChatGenerics>} Returns a promise that resolves when the connection is setup
811
734
  */
812
- async setGuestUser(user: UserResponse<UserType>) {
813
- let response: { access_token: string; user: UserResponse<UserType> } | undefined;
735
+ async setGuestUser(user: UserResponse<StreamChatGenerics>) {
736
+ let response: { access_token: string; user: UserResponse<StreamChatGenerics> } | undefined;
814
737
  this.anonymous = true;
815
738
  try {
816
- response = await this.post<APIResponse & { access_token: string; user: UserResponse<UserType> }>(
739
+ response = await this.post<APIResponse & { access_token: string; user: UserResponse<StreamChatGenerics> }>(
817
740
  this.baseURL + '/guest',
818
741
  { user },
819
742
  );
@@ -824,7 +747,7 @@ export class StreamChat<
824
747
  this.anonymous = false;
825
748
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
826
749
  const { created_at, updated_at, last_active, online, ...guestUser } = response.user;
827
- return await this.connectUser(guestUser as UserResponse<UserType>, response.access_token);
750
+ return await this.connectUser(guestUser as UserResponse<StreamChatGenerics>, response.access_token);
828
751
  }
829
752
 
830
753
  /**
@@ -860,61 +783,31 @@ export class StreamChat<
860
783
  * or
861
784
  * client.on(event => {console.log(event.type)})
862
785
  *
863
- * @param {EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType> | string} callbackOrString The event type to listen for (optional)
864
- * @param {EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>} [callbackOrNothing] The callback to call
786
+ * @param {EventHandler<StreamChatGenerics> | string} callbackOrString The event type to listen for (optional)
787
+ * @param {EventHandler<StreamChatGenerics>} [callbackOrNothing] The callback to call
865
788
  *
866
789
  * @return {{ unsubscribe: () => void }} Description
867
790
  */
791
+ on(callback: EventHandler<StreamChatGenerics>): { unsubscribe: () => void };
792
+ on(eventType: string, callback: EventHandler<StreamChatGenerics>): { unsubscribe: () => void };
868
793
  on(
869
- callback: EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
870
- ): { unsubscribe: () => void };
871
- on(
872
- eventType: string,
873
- callback: EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
874
- ): { unsubscribe: () => void };
875
- on(
876
- callbackOrString:
877
- | EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
878
- | string,
879
- callbackOrNothing?: EventHandler<
880
- AttachmentType,
881
- ChannelType,
882
- CommandType,
883
- EventType,
884
- MessageType,
885
- ReactionType,
886
- UserType
887
- >,
794
+ callbackOrString: EventHandler<StreamChatGenerics> | string,
795
+ callbackOrNothing?: EventHandler<StreamChatGenerics>,
888
796
  ): { unsubscribe: () => void } {
889
797
  const key = callbackOrNothing ? (callbackOrString as string) : 'all';
890
798
  const valid = isValidEventType(key);
891
799
  if (!valid) {
892
800
  throw Error(`Invalid event type ${key}`);
893
801
  }
894
- const callback = callbackOrNothing
895
- ? callbackOrNothing
896
- : (callbackOrString as EventHandler<
897
- AttachmentType,
898
- ChannelType,
899
- CommandType,
900
- EventType,
901
- MessageType,
902
- ReactionType,
903
- UserType
904
- >);
802
+ const callback = callbackOrNothing ? callbackOrNothing : (callbackOrString as EventHandler<StreamChatGenerics>);
905
803
  if (!(key in this.listeners)) {
906
804
  this.listeners[key] = [];
907
805
  }
908
- this.logger('info', `Attaching listener for ${key} event`, {
909
- tags: ['event', 'client'],
910
- });
806
+ this.logger('info', `Attaching listener for ${key} event`, { tags: ['event', 'client'] });
911
807
  this.listeners[key].push(callback);
912
808
  return {
913
809
  unsubscribe: () => {
914
- this.logger('info', `Removing listener for ${key} event`, {
915
- tags: ['event', 'client'],
916
- });
917
-
810
+ this.logger('info', `Removing listener for ${key} event`, { tags: ['event', 'client'] });
918
811
  this.listeners[key] = this.listeners[key].filter((el) => el !== callback);
919
812
  },
920
813
  };
@@ -924,50 +817,23 @@ export class StreamChat<
924
817
  * off - Remove the event handler
925
818
  *
926
819
  */
820
+ off(callback: EventHandler<StreamChatGenerics>): void;
821
+ off(eventType: string, callback: EventHandler<StreamChatGenerics>): void;
927
822
  off(
928
- callback: EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
929
- ): void;
930
- off(
931
- eventType: string,
932
- callback: EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
933
- ): void;
934
- off(
935
- callbackOrString:
936
- | EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
937
- | string,
938
- callbackOrNothing?: EventHandler<
939
- AttachmentType,
940
- ChannelType,
941
- CommandType,
942
- EventType,
943
- MessageType,
944
- ReactionType,
945
- UserType
946
- >,
823
+ callbackOrString: EventHandler<StreamChatGenerics> | string,
824
+ callbackOrNothing?: EventHandler<StreamChatGenerics>,
947
825
  ) {
948
826
  const key = callbackOrNothing ? (callbackOrString as string) : 'all';
949
827
  const valid = isValidEventType(key);
950
828
  if (!valid) {
951
829
  throw Error(`Invalid event type ${key}`);
952
830
  }
953
- const callback = callbackOrNothing
954
- ? callbackOrNothing
955
- : (callbackOrString as EventHandler<
956
- AttachmentType,
957
- ChannelType,
958
- CommandType,
959
- EventType,
960
- MessageType,
961
- ReactionType,
962
- UserType
963
- >);
831
+ const callback = callbackOrNothing ? callbackOrNothing : (callbackOrString as EventHandler<StreamChatGenerics>);
964
832
  if (!(key in this.listeners)) {
965
833
  this.listeners[key] = [];
966
834
  }
967
835
 
968
- this.logger('info', `Removing listener for ${key} event`, {
969
- tags: ['event', 'client'],
970
- });
836
+ this.logger('info', `Removing listener for ${key} event`, { tags: ['event', 'client'] });
971
837
  this.listeners[key] = this.listeners[key].filter((value) => value !== callback);
972
838
  }
973
839
 
@@ -1007,9 +873,7 @@ export class StreamChat<
1007
873
  type: string,
1008
874
  url: string,
1009
875
  data?: unknown,
1010
- options: AxiosRequestConfig & {
1011
- config?: AxiosRequestConfig & { maxBodyLength?: number };
1012
- } = {},
876
+ options: AxiosRequestConfig & { config?: AxiosRequestConfig & { maxBodyLength?: number } } = {},
1013
877
  ): Promise<T> => {
1014
878
  await this.tokenManager.tokenReady();
1015
879
  const requestConfig = this._enrichAxiosOptions(options);
@@ -1087,7 +951,7 @@ export class StreamChat<
1087
951
  uri: string | NodeJS.ReadableStream | Buffer | File,
1088
952
  name?: string,
1089
953
  contentType?: string,
1090
- user?: UserResponse<UserType>,
954
+ user?: UserResponse<StreamChatGenerics>,
1091
955
  ) {
1092
956
  const data = addFileToFormData(uri, name, contentType);
1093
957
  if (user != null) data.append('user', JSON.stringify(user));
@@ -1122,9 +986,7 @@ export class StreamChat<
1122
986
  return data;
1123
987
  }
1124
988
 
1125
- dispatchEvent = (
1126
- event: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
1127
- ) => {
989
+ dispatchEvent = (event: Event<StreamChatGenerics>) => {
1128
990
  if (!event.received_at) event.received_at = new Date();
1129
991
 
1130
992
  // client event handlers
@@ -1149,24 +1011,16 @@ export class StreamChat<
1149
1011
  handleEvent = (messageEvent: WebSocket.MessageEvent) => {
1150
1012
  // dispatch the event to the channel listeners
1151
1013
  const jsonString = messageEvent.data as string;
1152
- const event = JSON.parse(jsonString) as Event<
1153
- AttachmentType,
1154
- ChannelType,
1155
- CommandType,
1156
- EventType,
1157
- MessageType,
1158
- ReactionType,
1159
- UserType
1160
- >;
1014
+ const event = JSON.parse(jsonString) as Event<StreamChatGenerics>;
1161
1015
  this.dispatchEvent(event);
1162
1016
  };
1163
1017
 
1164
1018
  /**
1165
1019
  * Updates the members and watchers of the currently active channels that contain this user
1166
1020
  *
1167
- * @param {UserResponse<UserType>} user
1021
+ * @param {UserResponse<StreamChatGenerics>} user
1168
1022
  */
1169
- _updateMemberWatcherReferences = (user: UserResponse<UserType>) => {
1023
+ _updateMemberWatcherReferences = (user: UserResponse<StreamChatGenerics>) => {
1170
1024
  const refMap = this.state.userChannelReferences[user.id] || {};
1171
1025
  for (const channelID in refMap) {
1172
1026
  const channel = this.activeChannels[channelID];
@@ -1194,9 +1048,9 @@ export class StreamChat<
1194
1048
  * Updates the messages from the currently active channels that contain this user,
1195
1049
  * with updated user object.
1196
1050
  *
1197
- * @param {UserResponse<UserType>} user
1051
+ * @param {UserResponse<StreamChatGenerics>} user
1198
1052
  */
1199
- _updateUserMessageReferences = (user: UserResponse<UserType>) => {
1053
+ _updateUserMessageReferences = (user: UserResponse<StreamChatGenerics>) => {
1200
1054
  const refMap = this.state.userChannelReferences[user.id] || {};
1201
1055
 
1202
1056
  for (const channelID in refMap) {
@@ -1216,10 +1070,10 @@ export class StreamChat<
1216
1070
  * If hardDelete is true, all the content of message will be stripped down.
1217
1071
  * Otherwise, only 'message.type' will be set as 'deleted'.
1218
1072
  *
1219
- * @param {UserResponse<UserType>} user
1073
+ * @param {UserResponse<StreamChatGenerics>} user
1220
1074
  * @param {boolean} hardDelete
1221
1075
  */
1222
- _deleteUserMessageReference = (user: UserResponse<UserType>, hardDelete = false) => {
1076
+ _deleteUserMessageReference = (user: UserResponse<StreamChatGenerics>, hardDelete = false) => {
1223
1077
  const refMap = this.state.userChannelReferences[user.id] || {};
1224
1078
 
1225
1079
  for (const channelID in refMap) {
@@ -1241,9 +1095,7 @@ export class StreamChat<
1241
1095
  *
1242
1096
  * @param {Event} event
1243
1097
  */
1244
- _handleUserEvent = (
1245
- event: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
1246
- ) => {
1098
+ _handleUserEvent = (event: Event<StreamChatGenerics>) => {
1247
1099
  if (!event.user) {
1248
1100
  return;
1249
1101
  }
@@ -1289,9 +1141,7 @@ export class StreamChat<
1289
1141
  }
1290
1142
  };
1291
1143
 
1292
- _handleClientEvent(
1293
- event: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
1294
- ) {
1144
+ _handleClientEvent(event: Event<StreamChatGenerics>) {
1295
1145
  const client = this;
1296
1146
  const postListenerCallbacks = [];
1297
1147
  this.logger('info', `client:_handleClientEvent - Received event of type { ${event.type} }`, {
@@ -1335,6 +1185,11 @@ export class StreamChat<
1335
1185
  this.mutedUsers = event.me.mutes;
1336
1186
  }
1337
1187
 
1188
+ if (event.type === 'notification.mark_read') {
1189
+ const activeChannelKeys = Object.keys(this.activeChannels);
1190
+ activeChannelKeys.forEach((activeChannelKey) => (this.activeChannels[activeChannelKey].state.unreadCount = 0));
1191
+ }
1192
+
1338
1193
  if ((event.type === 'channel.deleted' || event.type === 'notification.channel_deleted') && event.cid) {
1339
1194
  client.state.deleteAllChannelReference(event.cid);
1340
1195
  this.activeChannels[event.cid]?._disconnect();
@@ -1374,14 +1229,10 @@ export class StreamChat<
1374
1229
  };
1375
1230
  }
1376
1231
 
1377
- _callClientListeners = (
1378
- event: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
1379
- ) => {
1232
+ _callClientListeners = (event: Event<StreamChatGenerics>) => {
1380
1233
  const client = this;
1381
1234
  // gather and call the listeners
1382
- const listeners: Array<
1383
- (event: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>) => void
1384
- > = [];
1235
+ const listeners: Array<(event: Event<StreamChatGenerics>) => void> = [];
1385
1236
  if (client.listeners.all) {
1386
1237
  listeners.push(...client.listeners.all);
1387
1238
  }
@@ -1407,22 +1258,15 @@ export class StreamChat<
1407
1258
  });
1408
1259
 
1409
1260
  await this.queryChannels(
1410
- { cid: { $in: cids } } as ChannelFilters<ChannelType, CommandType, UserType>,
1261
+ { cid: { $in: cids } } as ChannelFilters<StreamChatGenerics>,
1411
1262
  { last_message_at: -1 },
1412
1263
  { limit: 30 },
1413
1264
  );
1414
1265
 
1415
- this.logger('info', 'client:recoverState() - Querying channels finished', {
1416
- tags: ['connection', 'client'],
1417
- });
1418
-
1419
- this.dispatchEvent({
1420
- type: 'connection.recovered',
1421
- } as Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>);
1266
+ this.logger('info', 'client:recoverState() - Querying channels finished', { tags: ['connection', 'client'] });
1267
+ this.dispatchEvent({ type: 'connection.recovered' } as Event<StreamChatGenerics>);
1422
1268
  } else {
1423
- this.dispatchEvent({
1424
- type: 'connection.recovered',
1425
- } as Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>);
1269
+ this.dispatchEvent({ type: 'connection.recovered' } as Event<StreamChatGenerics>);
1426
1270
  }
1427
1271
 
1428
1272
  this.wsPromise = Promise.resolve();
@@ -1448,15 +1292,7 @@ export class StreamChat<
1448
1292
  }
1449
1293
 
1450
1294
  // The StableWSConnection handles all the reconnection logic.
1451
- this.wsConnection = new StableWSConnection<
1452
- ChannelType,
1453
- CommandType,
1454
- UserType,
1455
- AttachmentType,
1456
- EventType,
1457
- MessageType,
1458
- ReactionType
1459
- >({ client: this });
1295
+ this.wsConnection = new StableWSConnection<StreamChatGenerics>({ client: this });
1460
1296
 
1461
1297
  try {
1462
1298
  // if fallback is used before, continue using it instead of waiting for WS to fail
@@ -1473,20 +1309,11 @@ export class StreamChat<
1473
1309
  // make sure browser is online before even trying the longpoll
1474
1310
  if (this.options.enableWSFallback && isWSFailure(err) && isOnline()) {
1475
1311
  this.logger('info', 'client:connect() - WS failed, fallback to longpoll', { tags: ['connection', 'client'] });
1476
- // @ts-expect-error
1477
1312
  this.dispatchEvent({ type: 'transport.changed', mode: 'longpoll' });
1478
1313
 
1479
1314
  this.wsConnection._destroyCurrentWSConnection();
1480
1315
  this.wsConnection.disconnect().then(); // close WS so no retry
1481
- this.wsFallback = new WSConnectionFallback<
1482
- AttachmentType,
1483
- ChannelType,
1484
- CommandType,
1485
- EventType,
1486
- MessageType,
1487
- ReactionType,
1488
- UserType
1489
- >({ client: this });
1316
+ this.wsFallback = new WSConnectionFallback<StreamChatGenerics>({ client: this });
1490
1317
  return await this.wsFallback.connect();
1491
1318
  }
1492
1319
 
@@ -1504,11 +1331,7 @@ export class StreamChat<
1504
1331
  const opts = { headers: { 'x-client-request-id': client_request_id } };
1505
1332
  this.doAxiosRequest('get', this.baseURL + '/hi', null, opts).catch((e) => {
1506
1333
  if (this.options.enableInsights) {
1507
- postInsights('http_hi_failed', {
1508
- api_key: this.key,
1509
- err: e,
1510
- client_request_id,
1511
- });
1334
+ postInsights('http_hi_failed', { api_key: this.key, err: e, client_request_id });
1512
1335
  }
1513
1336
  });
1514
1337
  }
@@ -1516,14 +1339,18 @@ export class StreamChat<
1516
1339
  /**
1517
1340
  * queryUsers - Query users and watch user presence
1518
1341
  *
1519
- * @param {UserFilters<UserType>} filterConditions MongoDB style filter conditions
1520
- * @param {UserSort<UserType>} sort Sort options, for instance [{last_active: -1}].
1342
+ * @param {UserFilters<StreamChatGenerics>} filterConditions MongoDB style filter conditions
1343
+ * @param {UserSort<StreamChatGenerics>} sort Sort options, for instance [{last_active: -1}].
1521
1344
  * When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_active: -1}, {created_at: 1}]
1522
1345
  * @param {UserOptions} options Option object, {presence: true}
1523
1346
  *
1524
- * @return {Promise<APIResponse & { users: Array<UserResponse<UserType>> }>} User Query Response
1347
+ * @return {Promise<{ users: Array<UserResponse<StreamChatGenerics>> }>} User Query Response
1525
1348
  */
1526
- async queryUsers(filterConditions: UserFilters<UserType>, sort: UserSort<UserType> = [], options: UserOptions = {}) {
1349
+ async queryUsers(
1350
+ filterConditions: UserFilters<StreamChatGenerics>,
1351
+ sort: UserSort<StreamChatGenerics> = [],
1352
+ options: UserOptions = {},
1353
+ ) {
1527
1354
  const defaultOptions = {
1528
1355
  presence: false,
1529
1356
  };
@@ -1536,18 +1363,17 @@ export class StreamChat<
1536
1363
  }
1537
1364
 
1538
1365
  // Return a list of users
1539
- const data = await this.get<
1540
- APIResponse & {
1541
- users: Array<UserResponse<UserType>>;
1542
- }
1543
- >(this.baseURL + '/users', {
1544
- payload: {
1545
- filter_conditions: filterConditions,
1546
- sort: normalizeQuerySort(sort),
1547
- ...defaultOptions,
1548
- ...options,
1366
+ const data = await this.get<APIResponse & { users: Array<UserResponse<StreamChatGenerics>> }>(
1367
+ this.baseURL + '/users',
1368
+ {
1369
+ payload: {
1370
+ filter_conditions: filterConditions,
1371
+ sort: normalizeQuerySort(sort),
1372
+ ...defaultOptions,
1373
+ ...options,
1374
+ },
1549
1375
  },
1550
- });
1376
+ );
1551
1377
 
1552
1378
  this.state.updateUsers(data.users);
1553
1379
 
@@ -1561,7 +1387,7 @@ export class StreamChat<
1561
1387
  * @param {BannedUsersSort} sort Sort options [{created_at: 1}].
1562
1388
  * @param {BannedUsersPaginationOptions} options Option object, {limit: 10, offset:0}
1563
1389
  *
1564
- * @return {Promise<BannedUsersResponse<ChannelType, CommandType, UserType>>} Ban Query Response
1390
+ * @return {Promise<BannedUsersResponse<StreamChatGenerics>>} Ban Query Response
1565
1391
  */
1566
1392
  async queryBannedUsers(
1567
1393
  filterConditions: BannedUsersFilters = {},
@@ -1569,16 +1395,13 @@ export class StreamChat<
1569
1395
  options: BannedUsersPaginationOptions = {},
1570
1396
  ) {
1571
1397
  // Return a list of user bans
1572
- return await this.get<BannedUsersResponse<ChannelType, CommandType, UserType>>(
1573
- this.baseURL + '/query_banned_users',
1574
- {
1575
- payload: {
1576
- filter_conditions: filterConditions,
1577
- sort: normalizeQuerySort(sort),
1578
- ...options,
1579
- },
1398
+ return await this.get<BannedUsersResponse<StreamChatGenerics>>(this.baseURL + '/query_banned_users', {
1399
+ payload: {
1400
+ filter_conditions: filterConditions,
1401
+ sort: normalizeQuerySort(sort),
1402
+ ...options,
1580
1403
  },
1581
- );
1404
+ });
1582
1405
  }
1583
1406
 
1584
1407
  /**
@@ -1587,45 +1410,35 @@ export class StreamChat<
1587
1410
  * @param {MessageFlagsFilters} filterConditions MongoDB style filter conditions
1588
1411
  * @param {MessageFlagsPaginationOptions} options Option object, {limit: 10, offset:0}
1589
1412
  *
1590
- * @return {Promise<MessageFlagsResponse<ChannelType, CommandType, UserType>>} Message Flags Response
1413
+ * @return {Promise<MessageFlagsResponse<StreamChatGenerics>>} Message Flags Response
1591
1414
  */
1592
1415
  async queryMessageFlags(filterConditions: MessageFlagsFilters = {}, options: MessageFlagsPaginationOptions = {}) {
1593
1416
  // Return a list of message flags
1594
- return await this.get<MessageFlagsResponse<ChannelType, CommandType, UserType>>(
1595
- this.baseURL + '/moderation/flags/message',
1596
- {
1597
- payload: {
1598
- filter_conditions: filterConditions,
1599
- ...options,
1600
- },
1601
- },
1602
- );
1417
+ return await this.get<MessageFlagsResponse<StreamChatGenerics>>(this.baseURL + '/moderation/flags/message', {
1418
+ payload: { filter_conditions: filterConditions, ...options },
1419
+ });
1603
1420
  }
1604
1421
 
1605
1422
  /**
1606
1423
  * queryChannels - Query channels
1607
1424
  *
1608
- * @param {ChannelFilters<ChannelType, CommandType, UserType>} filterConditions object MongoDB style filters
1609
- * @param {ChannelSort<ChannelType>} [sort] Sort options, for instance {created_at: -1}.
1425
+ * @param {ChannelFilters<StreamChatGenerics>} filterConditions object MongoDB style filters
1426
+ * @param {ChannelSort<StreamChatGenerics>} [sort] Sort options, for instance {created_at: -1}.
1610
1427
  * When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
1611
1428
  * @param {ChannelOptions} [options] Options object
1612
1429
  * @param {ChannelStateOptions} [stateOptions] State options object. These options will only be used for state management and won't be sent in the request.
1613
1430
  * - stateOptions.skipInitialization - Skips the initialization of the state for the channels matching the ids in the list.
1614
1431
  *
1615
- * @return {Promise<APIResponse & { channels: Array<ChannelAPIResponse<AttachmentType,ChannelType,CommandType,MessageType,ReactionType,UserType>>}> } search channels response
1432
+ * @return {Promise<{ channels: Array<ChannelAPIResponse<AStreamChatGenerics>>}> } search channels response
1616
1433
  */
1617
1434
  async queryChannels(
1618
- filterConditions: ChannelFilters<ChannelType, CommandType, UserType>,
1619
- sort: ChannelSort<ChannelType> = [],
1435
+ filterConditions: ChannelFilters<StreamChatGenerics>,
1436
+ sort: ChannelSort<StreamChatGenerics> = [],
1620
1437
  options: ChannelOptions = {},
1621
1438
  stateOptions: ChannelStateOptions = {},
1622
1439
  ) {
1623
1440
  const { skipInitialization } = stateOptions;
1624
- const defaultOptions: ChannelOptions = {
1625
- state: true,
1626
- watch: true,
1627
- presence: false,
1628
- };
1441
+ const defaultOptions: ChannelOptions = { state: true, watch: true, presence: false };
1629
1442
 
1630
1443
  // Make sure we wait for the connect promise if there is a pending one
1631
1444
  await this.setUserPromise;
@@ -1642,19 +1455,12 @@ export class StreamChat<
1642
1455
  ...options,
1643
1456
  };
1644
1457
 
1645
- const data = await this.post<{
1646
- channels: ChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[];
1647
- }>(this.baseURL + '/channels', payload);
1458
+ const data = await this.post<{ channels: ChannelAPIResponse<StreamChatGenerics>[] }>(
1459
+ this.baseURL + '/channels',
1460
+ payload,
1461
+ );
1648
1462
 
1649
- const channels: Channel<
1650
- AttachmentType,
1651
- ChannelType,
1652
- CommandType,
1653
- EventType,
1654
- MessageType,
1655
- ReactionType,
1656
- UserType
1657
- >[] = [];
1463
+ const channels: Channel<StreamChatGenerics>[] = [];
1658
1464
 
1659
1465
  // update our cache of the configs
1660
1466
  for (const channelState of data.channels) {
@@ -1681,24 +1487,24 @@ export class StreamChat<
1681
1487
  /**
1682
1488
  * search - Query messages
1683
1489
  *
1684
- * @param {ChannelFilters<ChannelType, CommandType, UserType>} filterConditions MongoDB style filter conditions
1685
- * @param {MessageFilters<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> | string} query search query or object MongoDB style filters
1686
- * @param {SearchOptions<MessageType>} [options] Option object, {user_id: 'tommaso'}
1490
+ * @param {ChannelFilters<StreamChatGenerics>} filterConditions MongoDB style filter conditions
1491
+ * @param {MessageFilters<StreamChatGenerics> | string} query search query or object MongoDB style filters
1492
+ * @param {SearchOptions<StreamChatGenerics>} [options] Option object, {user_id: 'tommaso'}
1687
1493
  *
1688
- * @return {Promise<SearchAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} search messages response
1494
+ * @return {Promise<SearchAPIResponse<StreamChatGenerics>>} search messages response
1689
1495
  */
1690
1496
  async search(
1691
- filterConditions: ChannelFilters<ChannelType, CommandType, UserType>,
1692
- query: string | MessageFilters<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>,
1693
- options: SearchOptions<MessageType> = {},
1497
+ filterConditions: ChannelFilters<StreamChatGenerics>,
1498
+ query: string | MessageFilters<StreamChatGenerics>,
1499
+ options: SearchOptions<StreamChatGenerics> = {},
1694
1500
  ) {
1695
1501
  if (options.offset && (options.sort || options.next)) {
1696
1502
  throw Error(`Cannot specify offset with sort or next parameters`);
1697
1503
  }
1698
- const payload: SearchPayload<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> = {
1504
+ const payload: SearchPayload<StreamChatGenerics> = {
1699
1505
  filter_conditions: filterConditions,
1700
1506
  ...options,
1701
- sort: options.sort ? normalizeQuerySort<SearchMessageSortBase<MessageType>>(options.sort) : undefined,
1507
+ sort: options.sort ? normalizeQuerySort<SearchMessageSortBase<StreamChatGenerics>>(options.sort) : undefined,
1702
1508
  };
1703
1509
  if (typeof query === 'string') {
1704
1510
  payload.query = query;
@@ -1711,11 +1517,7 @@ export class StreamChat<
1711
1517
  // Make sure we wait for the connect promise if there is a pending one
1712
1518
  await this.setUserPromise;
1713
1519
 
1714
- return await this.get<
1715
- SearchAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
1716
- >(this.baseURL + '/search', {
1717
- payload,
1718
- });
1520
+ return await this.get<SearchAPIResponse<StreamChatGenerics>>(this.baseURL + '/search', { payload });
1719
1521
  }
1720
1522
 
1721
1523
  /**
@@ -1755,10 +1557,10 @@ export class StreamChat<
1755
1557
  *
1756
1558
  * @param {string} [userID] User ID. Only works on serverside
1757
1559
  *
1758
- * @return {APIResponse & Device<UserType>[]} Array of devices
1560
+ * @return {Device<StreamChatGenerics>[]} Array of devices
1759
1561
  */
1760
1562
  async getDevices(userID?: string) {
1761
- return await this.get<APIResponse & { devices?: Device<UserType>[] }>(
1563
+ return await this.get<APIResponse & { devices?: Device<StreamChatGenerics>[] }>(
1762
1564
  this.baseURL + '/devices',
1763
1565
  userID ? { user_id: userID } : {},
1764
1566
  );
@@ -1802,9 +1604,7 @@ export class StreamChat<
1802
1604
  });
1803
1605
  }
1804
1606
 
1805
- _addChannelConfig(
1806
- channelState: ChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>,
1807
- ) {
1607
+ _addChannelConfig(channelState: ChannelAPIResponse<StreamChatGenerics>) {
1808
1608
  this.configs[channelState.channel.type] = channelState.channel.config;
1809
1609
  }
1810
1610
 
@@ -1817,7 +1617,7 @@ export class StreamChat<
1817
1617
  * await channel.create() to assign an ID to channel
1818
1618
  *
1819
1619
  * @param {string} channelType The channel type
1820
- * @param {string | ChannelData<ChannelType> | null} [channelIDOrCustom] The channel ID, you can leave this out if you want to create a conversation channel
1620
+ * @param {string | ChannelData<StreamChatGenerics> | null} [channelIDOrCustom] The channel ID, you can leave this out if you want to create a conversation channel
1821
1621
  * @param {object} [custom] Custom data to attach to the channel
1822
1622
  *
1823
1623
  * @return {channel} The channel object, initialize it using channel.watch()
@@ -1825,16 +1625,13 @@ export class StreamChat<
1825
1625
  channel(
1826
1626
  channelType: string,
1827
1627
  channelID?: string | null,
1828
- custom?: ChannelData<ChannelType>,
1829
- ): Channel<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>;
1830
- channel(
1831
- channelType: string,
1832
- custom?: ChannelData<ChannelType>,
1833
- ): Channel<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>;
1628
+ custom?: ChannelData<StreamChatGenerics>,
1629
+ ): Channel<StreamChatGenerics>;
1630
+ channel(channelType: string, custom?: ChannelData<StreamChatGenerics>): Channel<StreamChatGenerics>;
1834
1631
  channel(
1835
1632
  channelType: string,
1836
- channelIDOrCustom?: string | ChannelData<ChannelType> | null,
1837
- custom: ChannelData<ChannelType> = {} as ChannelData<ChannelType>,
1633
+ channelIDOrCustom?: string | ChannelData<StreamChatGenerics> | null,
1634
+ custom: ChannelData<StreamChatGenerics> = {} as ChannelData<StreamChatGenerics>,
1838
1635
  ) {
1839
1636
  if (!this.userID && !this._isUsingServerAuth()) {
1840
1637
  throw Error('Call connectUser or connectAnonymousUser before creating a channel');
@@ -1848,12 +1645,7 @@ export class StreamChat<
1848
1645
  // support channel("messaging", undefined, {options})
1849
1646
  // support channel("messaging", "", {options})
1850
1647
  if (channelIDOrCustom == null || channelIDOrCustom === '') {
1851
- return new Channel<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>(
1852
- this,
1853
- channelType,
1854
- undefined,
1855
- custom,
1856
- );
1648
+ return new Channel<StreamChatGenerics>(this, channelType, undefined, custom);
1857
1649
  }
1858
1650
 
1859
1651
  // support channel("messaging", {options})
@@ -1880,7 +1672,7 @@ export class StreamChat<
1880
1672
  *
1881
1673
  * @return {channel} The channel object, initialize it using channel.watch()
1882
1674
  */
1883
- getChannelByMembers = (channelType: string, custom: ChannelData<ChannelType>) => {
1675
+ getChannelByMembers = (channelType: string, custom: ChannelData<StreamChatGenerics>) => {
1884
1676
  // Check if the channel already exists.
1885
1677
  // Only allow 1 channel object per cid
1886
1678
  const membersStr = [...(custom.members || [])].sort().join(',');
@@ -1913,15 +1705,7 @@ export class StreamChat<
1913
1705
  }
1914
1706
  }
1915
1707
 
1916
- const channel = new Channel<
1917
- AttachmentType,
1918
- ChannelType,
1919
- CommandType,
1920
- EventType,
1921
- MessageType,
1922
- ReactionType,
1923
- UserType
1924
- >(this, channelType, undefined, custom);
1708
+ const channel = new Channel<StreamChatGenerics>(this, channelType, undefined, custom);
1925
1709
 
1926
1710
  // For the time being set the key as membersStr, since we don't know the cid yet.
1927
1711
  // In channel.query, we will replace it with 'cid'.
@@ -1945,7 +1729,7 @@ export class StreamChat<
1945
1729
  *
1946
1730
  * @return {channel} The channel object, initialize it using channel.watch()
1947
1731
  */
1948
- getChannelById = (channelType: string, channelID: string, custom: ChannelData<ChannelType>) => {
1732
+ getChannelById = (channelType: string, channelID: string, custom: ChannelData<StreamChatGenerics>) => {
1949
1733
  if (typeof channelID === 'string' && ~channelID.indexOf(':')) {
1950
1734
  throw Error(`Invalid channel id ${channelID}, can't contain the : character`);
1951
1735
  }
@@ -1960,15 +1744,7 @@ export class StreamChat<
1960
1744
  }
1961
1745
  return channel;
1962
1746
  }
1963
- const channel = new Channel<
1964
- AttachmentType,
1965
- ChannelType,
1966
- CommandType,
1967
- EventType,
1968
- MessageType,
1969
- ReactionType,
1970
- UserType
1971
- >(this, channelType, channelID, custom);
1747
+ const channel = new Channel<StreamChatGenerics>(this, channelType, channelID, custom);
1972
1748
  this.activeChannels[channel.cid] = channel;
1973
1749
 
1974
1750
  return channel;
@@ -1977,24 +1753,24 @@ export class StreamChat<
1977
1753
  /**
1978
1754
  * partialUpdateUser - Update the given user object
1979
1755
  *
1980
- * @param {PartialUserUpdate<UserType>} partialUserObject which should contain id and any of "set" or "unset" params;
1756
+ * @param {PartialUserUpdate<StreamChatGenerics>} partialUserObject which should contain id and any of "set" or "unset" params;
1981
1757
  * example: {id: "user1", set:{field: value}, unset:["field2"]}
1982
1758
  *
1983
- * @return {Promise<APIResponse & { users: { [key: string]: UserResponse<UserType> } }>} list of updated users
1759
+ * @return {Promise<{ users: { [key: string]: UserResponse<StreamChatGenerics> } }>} list of updated users
1984
1760
  */
1985
- async partialUpdateUser(partialUserObject: PartialUserUpdate<UserType>) {
1761
+ async partialUpdateUser(partialUserObject: PartialUserUpdate<StreamChatGenerics>) {
1986
1762
  return await this.partialUpdateUsers([partialUserObject]);
1987
1763
  }
1988
1764
 
1989
1765
  /**
1990
1766
  * upsertUsers - Batch upsert the list of users
1991
1767
  *
1992
- * @param {UserResponse<UserType>[]} users list of users
1768
+ * @param {UserResponse<StreamChatGenerics>[]} users list of users
1993
1769
  *
1994
- * @return {Promise<APIResponse & { users: { [key: string]: UserResponse<UserType> } }>}
1770
+ * @return {Promise<{ users: { [key: string]: UserResponse<StreamChatGenerics> } }>}
1995
1771
  */
1996
- async upsertUsers(users: UserResponse<UserType>[]) {
1997
- const userMap: { [key: string]: UserResponse<UserType> } = {};
1772
+ async upsertUsers(users: UserResponse<StreamChatGenerics>[]) {
1773
+ const userMap: { [key: string]: UserResponse<StreamChatGenerics> } = {};
1998
1774
  for (const userObject of users) {
1999
1775
  if (!userObject.id) {
2000
1776
  throw Error('User ID is required when updating a user');
@@ -2002,13 +1778,10 @@ export class StreamChat<
2002
1778
  userMap[userObject.id] = userObject;
2003
1779
  }
2004
1780
 
2005
- return await this.post<
2006
- APIResponse & {
2007
- users: { [key: string]: UserResponse<UserType> };
2008
- }
2009
- >(this.baseURL + '/users', {
2010
- users: userMap,
2011
- });
1781
+ return await this.post<APIResponse & { users: { [key: string]: UserResponse<StreamChatGenerics> } }>(
1782
+ this.baseURL + '/users',
1783
+ { users: userMap },
1784
+ );
2012
1785
  }
2013
1786
 
2014
1787
  /**
@@ -2016,19 +1789,19 @@ export class StreamChat<
2016
1789
  *
2017
1790
  * updateUsers - Batch update the list of users
2018
1791
  *
2019
- * @param {UserResponse<UserType>[]} users list of users
2020
- * @return {Promise<APIResponse & { users: { [key: string]: UserResponse<UserType> } }>}
1792
+ * @param {UserResponse<StreamChatGenerics>[]} users list of users
1793
+ * @return {Promise<{ users: { [key: string]: UserResponse<StreamChatGenerics> } }>}
2021
1794
  */
2022
1795
  updateUsers = this.upsertUsers;
2023
1796
 
2024
1797
  /**
2025
1798
  * upsertUser - Update or Create the given user object
2026
1799
  *
2027
- * @param {UserResponse<UserType>} userObject user object, the only required field is the user id. IE {id: "myuser"} is valid
1800
+ * @param {UserResponse<StreamChatGenerics>} userObject user object, the only required field is the user id. IE {id: "myuser"} is valid
2028
1801
  *
2029
- * @return {Promise<APIResponse & { users: { [key: string]: UserResponse<UserType> } }>}
1802
+ * @return {Promise<{ users: { [key: string]: UserResponse<StreamChatGenerics> } }>}
2030
1803
  */
2031
- upsertUser(userObject: UserResponse<UserType>) {
1804
+ upsertUser(userObject: UserResponse<StreamChatGenerics>) {
2032
1805
  return this.upsertUsers([userObject]);
2033
1806
  }
2034
1807
 
@@ -2037,32 +1810,29 @@ export class StreamChat<
2037
1810
  *
2038
1811
  * updateUser - Update or Create the given user object
2039
1812
  *
2040
- * @param {UserResponse<UserType>} userObject user object, the only required field is the user id. IE {id: "myuser"} is valid
2041
- * @return {Promise<APIResponse & { users: { [key: string]: UserResponse<UserType> } }>}
1813
+ * @param {UserResponse<StreamChatGenerics>} userObject user object, the only required field is the user id. IE {id: "myuser"} is valid
1814
+ * @return {Promise<{ users: { [key: string]: UserResponse<StreamChatGenerics> } }>}
2042
1815
  */
2043
1816
  updateUser = this.upsertUser;
2044
1817
 
2045
1818
  /**
2046
1819
  * partialUpdateUsers - Batch partial update of users
2047
1820
  *
2048
- * @param {PartialUserUpdate<UserType>[]} users list of partial update requests
1821
+ * @param {PartialUserUpdate<StreamChatGenerics>[]} users list of partial update requests
2049
1822
  *
2050
- * @return {Promise<APIResponse & { users: { [key: string]: UserResponse<UserType> } }>}
1823
+ * @return {Promise<{ users: { [key: string]: UserResponse<StreamChatGenerics> } }>}
2051
1824
  */
2052
- async partialUpdateUsers(users: PartialUserUpdate<UserType>[]) {
1825
+ async partialUpdateUsers(users: PartialUserUpdate<StreamChatGenerics>[]) {
2053
1826
  for (const userObject of users) {
2054
1827
  if (!userObject.id) {
2055
1828
  throw Error('User ID is required when updating a user');
2056
1829
  }
2057
1830
  }
2058
1831
 
2059
- return await this.patch<
2060
- APIResponse & {
2061
- users: { [key: string]: UserResponse<UserType> };
2062
- }
2063
- >(this.baseURL + '/users', {
2064
- users,
2065
- });
1832
+ return await this.patch<APIResponse & { users: { [key: string]: UserResponse<StreamChatGenerics> } }>(
1833
+ this.baseURL + '/users',
1834
+ { users },
1835
+ );
2066
1836
  }
2067
1837
 
2068
1838
  async deleteUser(
@@ -2073,54 +1843,46 @@ export class StreamChat<
2073
1843
  mark_messages_deleted?: boolean;
2074
1844
  },
2075
1845
  ) {
2076
- return await this.delete<
2077
- APIResponse & {
2078
- user: UserResponse<UserType>;
2079
- }
2080
- >(this.baseURL + `/users/${userID}`, params);
1846
+ return await this.delete<APIResponse & { user: UserResponse<StreamChatGenerics> }>(
1847
+ this.baseURL + `/users/${userID}`,
1848
+ params,
1849
+ );
2081
1850
  }
2082
1851
 
2083
1852
  async reactivateUser(
2084
1853
  userID: string,
2085
1854
  options?: { created_by_id?: string; name?: string; restore_messages?: boolean },
2086
1855
  ) {
2087
- return await this.post<
2088
- APIResponse & {
2089
- user: UserResponse<UserType>;
2090
- }
2091
- >(this.baseURL + `/users/${userID}/reactivate`, {
2092
- ...options,
2093
- });
1856
+ return await this.post<APIResponse & { user: UserResponse<StreamChatGenerics> }>(
1857
+ this.baseURL + `/users/${userID}/reactivate`,
1858
+ { ...options },
1859
+ );
2094
1860
  }
2095
1861
 
2096
1862
  async deactivateUser(userID: string, options?: { created_by_id?: string; mark_messages_deleted?: boolean }) {
2097
- return await this.post<APIResponse & { user: UserResponse<UserType> }>(
1863
+ return await this.post<APIResponse & { user: UserResponse<StreamChatGenerics> }>(
2098
1864
  this.baseURL + `/users/${userID}/deactivate`,
2099
- {
2100
- ...options,
2101
- },
1865
+ { ...options },
2102
1866
  );
2103
1867
  }
2104
1868
 
2105
1869
  async exportUser(userID: string, options?: Record<string, string>) {
2106
1870
  return await this.get<
2107
1871
  APIResponse & {
2108
- messages: MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>[];
2109
- reactions: ReactionResponse<ReactionType, UserType>[];
2110
- user: UserResponse<UserType>;
1872
+ messages: MessageResponse<StreamChatGenerics>[];
1873
+ reactions: ReactionResponse<StreamChatGenerics>[];
1874
+ user: UserResponse<StreamChatGenerics>;
2111
1875
  }
2112
- >(this.baseURL + `/users/${userID}/export`, {
2113
- ...options,
2114
- });
1876
+ >(this.baseURL + `/users/${userID}/export`, { ...options });
2115
1877
  }
2116
1878
 
2117
1879
  /** banUser - bans a user from all channels
2118
1880
  *
2119
1881
  * @param {string} targetUserID
2120
- * @param {BanUserOptions<UserType>} [options]
1882
+ * @param {BanUserOptions<StreamChatGenerics>} [options]
2121
1883
  * @returns {Promise<APIResponse>}
2122
1884
  */
2123
- async banUser(targetUserID: string, options?: BanUserOptions<UserType>) {
1885
+ async banUser(targetUserID: string, options?: BanUserOptions<StreamChatGenerics>) {
2124
1886
  return await this.post<APIResponse>(this.baseURL + '/moderation/ban', {
2125
1887
  target_user_id: targetUserID,
2126
1888
  ...options,
@@ -2143,10 +1905,10 @@ export class StreamChat<
2143
1905
  /** shadowBan - shadow bans a user from all channels
2144
1906
  *
2145
1907
  * @param {string} targetUserID
2146
- * @param {BanUserOptions<UserType>} [options]
1908
+ * @param {BanUserOptions<StreamChatGenerics>} [options]
2147
1909
  * @returns {Promise<APIResponse>}
2148
1910
  */
2149
- async shadowBan(targetUserID: string, options?: BanUserOptions<UserType>) {
1911
+ async shadowBan(targetUserID: string, options?: BanUserOptions<StreamChatGenerics>) {
2150
1912
  return await this.banUser(targetUserID, {
2151
1913
  shadow: true,
2152
1914
  ...options,
@@ -2170,11 +1932,11 @@ export class StreamChat<
2170
1932
  *
2171
1933
  * @param {string} targetID
2172
1934
  * @param {string} [userID] Only used with serverside auth
2173
- * @param {MuteUserOptions<UserType>} [options]
2174
- * @returns {Promise<MuteUserResponse<ChannelType, CommandType, UserType>>}
1935
+ * @param {MuteUserOptions<StreamChatGenerics>} [options]
1936
+ * @returns {Promise<MuteUserResponse<StreamChatGenerics>>}
2175
1937
  */
2176
- async muteUser(targetID: string, userID?: string, options: MuteUserOptions<UserType> = {}) {
2177
- return await this.post<MuteUserResponse<ChannelType, CommandType, UserType>>(this.baseURL + '/moderation/mute', {
1938
+ async muteUser(targetID: string, userID?: string, options: MuteUserOptions<StreamChatGenerics> = {}) {
1939
+ return await this.post<MuteUserResponse<StreamChatGenerics>>(this.baseURL + '/moderation/mute', {
2178
1940
  target_id: targetID,
2179
1941
  ...(userID ? { user_id: userID } : {}),
2180
1942
  ...options,
@@ -2217,7 +1979,7 @@ export class StreamChat<
2217
1979
  * @returns {Promise<APIResponse>}
2218
1980
  */
2219
1981
  async flagMessage(targetMessageID: string, options: { user_id?: string } = {}) {
2220
- return await this.post<FlagMessageResponse<UserType>>(this.baseURL + '/moderation/flag', {
1982
+ return await this.post<FlagMessageResponse<StreamChatGenerics>>(this.baseURL + '/moderation/flag', {
2221
1983
  target_message_id: targetMessageID,
2222
1984
  ...options,
2223
1985
  });
@@ -2230,7 +1992,7 @@ export class StreamChat<
2230
1992
  * @returns {Promise<APIResponse>}
2231
1993
  */
2232
1994
  async flagUser(targetID: string, options: { user_id?: string } = {}) {
2233
- return await this.post<FlagUserResponse<UserType>>(this.baseURL + '/moderation/flag', {
1995
+ return await this.post<FlagUserResponse<StreamChatGenerics>>(this.baseURL + '/moderation/flag', {
2234
1996
  target_user_id: targetID,
2235
1997
  ...options,
2236
1998
  });
@@ -2243,7 +2005,7 @@ export class StreamChat<
2243
2005
  * @returns {Promise<APIResponse>}
2244
2006
  */
2245
2007
  async unflagMessage(targetMessageID: string, options: { user_id?: string } = {}) {
2246
- return await this.post<FlagMessageResponse<UserType>>(this.baseURL + '/moderation/unflag', {
2008
+ return await this.post<FlagMessageResponse<StreamChatGenerics>>(this.baseURL + '/moderation/unflag', {
2247
2009
  target_message_id: targetMessageID,
2248
2010
  ...options,
2249
2011
  });
@@ -2256,12 +2018,33 @@ export class StreamChat<
2256
2018
  * @returns {Promise<APIResponse>}
2257
2019
  */
2258
2020
  async unflagUser(targetID: string, options: { user_id?: string } = {}) {
2259
- return await this.post<FlagUserResponse<UserType>>(this.baseURL + '/moderation/unflag', {
2021
+ return await this.post<FlagUserResponse<StreamChatGenerics>>(this.baseURL + '/moderation/unflag', {
2260
2022
  target_user_id: targetID,
2261
2023
  ...options,
2262
2024
  });
2263
2025
  }
2264
2026
 
2027
+ /**
2028
+ * _queryFlags - Query flags.
2029
+ *
2030
+ * Note: Do not use this.
2031
+ * It is present for internal usage only.
2032
+ * This function can, and will, break and/or be removed at any point in time.
2033
+ *
2034
+ * @private
2035
+ * @param {FlagsFilters} filterConditions MongoDB style filter conditions
2036
+ * @param {FlagsPaginationOptions} options Option object, {limit: 10, offset:0}
2037
+ *
2038
+ * @return {Promise<FlagsResponse<StreamChatGenerics>>} Flags Response
2039
+ */
2040
+ async _queryFlags(filterConditions: FlagsFilters = {}, options: FlagsPaginationOptions = {}) {
2041
+ // Return a list of flags
2042
+ return await this.post<FlagsResponse<StreamChatGenerics>>(this.baseURL + '/moderation/flags', {
2043
+ filter_conditions: filterConditions,
2044
+ ...options,
2045
+ });
2046
+ }
2047
+
2265
2048
  /**
2266
2049
  * _queryFlagReports - Query flag reports.
2267
2050
  *
@@ -2273,17 +2056,14 @@ export class StreamChat<
2273
2056
  * @param {FlagReportsFilters} filterConditions MongoDB style filter conditions
2274
2057
  * @param {FlagReportsPaginationOptions} options Option object, {limit: 10, offset:0}
2275
2058
  *
2276
- * @return {Promise<FlagReportsResponse<ChannelType, CommandType, UserType>>} Flag Reports Response
2059
+ * @return {Promise<FlagReportsResponse<StreamChatGenerics>>} Flag Reports Response
2277
2060
  */
2278
2061
  async _queryFlagReports(filterConditions: FlagReportsFilters = {}, options: FlagReportsPaginationOptions = {}) {
2279
2062
  // Return a list of message flags
2280
- return await this.post<FlagReportsResponse<ChannelType, CommandType, UserType>>(
2281
- this.baseURL + '/moderation/reports',
2282
- {
2283
- filter_conditions: filterConditions,
2284
- ...options,
2285
- },
2286
- );
2063
+ return await this.post<FlagReportsResponse<StreamChatGenerics>>(this.baseURL + '/moderation/reports', {
2064
+ filter_conditions: filterConditions,
2065
+ ...options,
2066
+ });
2287
2067
  }
2288
2068
 
2289
2069
  /**
@@ -2301,7 +2081,7 @@ export class StreamChat<
2301
2081
  * @returns {Promise<ReviewFlagReportResponse>>}
2302
2082
  */
2303
2083
  async _reviewFlagReport(id: string, reviewResult: string, options: ReviewFlagReportOptions = {}) {
2304
- return await this.patch<ReviewFlagReportResponse<UserType>>(this.baseURL + `/moderation/reports/${id}`, {
2084
+ return await this.patch<ReviewFlagReportResponse<StreamChatGenerics>>(this.baseURL + `/moderation/reports/${id}`, {
2305
2085
  review_result: reviewResult,
2306
2086
  ...options,
2307
2087
  });
@@ -2330,7 +2110,7 @@ export class StreamChat<
2330
2110
  * @deprecated use markChannelsRead instead
2331
2111
  *
2332
2112
  * markAllRead - marks all channels for this user as read
2333
- * @param {MarkAllReadOptions<UserType>} [data]
2113
+ * @param {MarkAllReadOptions<StreamChatGenerics>} [data]
2334
2114
  *
2335
2115
  * @return {Promise<APIResponse>}
2336
2116
  */
@@ -2340,47 +2120,45 @@ export class StreamChat<
2340
2120
  * markChannelsRead - marks channels read -
2341
2121
  * it accepts a map of cid:messageid pairs, if messageid is empty, the whole channel will be marked as read
2342
2122
  *
2343
- * @param {MarkChannelsReadOptions <UserType>} [data]
2123
+ * @param {MarkChannelsReadOptions <StreamChatGenerics>} [data]
2344
2124
  *
2345
2125
  * @return {Promise<APIResponse>}
2346
2126
  */
2347
- async markChannelsRead(data: MarkChannelsReadOptions<UserType> = {}) {
2348
- await this.post<APIResponse>(this.baseURL + '/channels/read', {
2349
- ...data,
2350
- });
2127
+ async markChannelsRead(data: MarkChannelsReadOptions<StreamChatGenerics> = {}) {
2128
+ await this.post<APIResponse>(this.baseURL + '/channels/read', { ...data });
2351
2129
  }
2352
2130
 
2353
- createCommand(data: CreateCommandOptions<CommandType>) {
2354
- return this.post<CreateCommandResponse<CommandType>>(this.baseURL + '/commands', data);
2131
+ createCommand(data: CreateCommandOptions<StreamChatGenerics>) {
2132
+ return this.post<CreateCommandResponse<StreamChatGenerics>>(this.baseURL + '/commands', data);
2355
2133
  }
2356
2134
 
2357
2135
  getCommand(name: string) {
2358
- return this.get<GetCommandResponse<CommandType>>(this.baseURL + `/commands/${name}`);
2136
+ return this.get<GetCommandResponse<StreamChatGenerics>>(this.baseURL + `/commands/${name}`);
2359
2137
  }
2360
2138
 
2361
- updateCommand(name: string, data: UpdateCommandOptions<CommandType>) {
2362
- return this.put<UpdateCommandResponse<CommandType>>(this.baseURL + `/commands/${name}`, data);
2139
+ updateCommand(name: string, data: UpdateCommandOptions<StreamChatGenerics>) {
2140
+ return this.put<UpdateCommandResponse<StreamChatGenerics>>(this.baseURL + `/commands/${name}`, data);
2363
2141
  }
2364
2142
 
2365
2143
  deleteCommand(name: string) {
2366
- return this.delete<DeleteCommandResponse<CommandType>>(this.baseURL + `/commands/${name}`);
2144
+ return this.delete<DeleteCommandResponse<StreamChatGenerics>>(this.baseURL + `/commands/${name}`);
2367
2145
  }
2368
2146
 
2369
2147
  listCommands() {
2370
- return this.get<ListCommandsResponse<CommandType>>(this.baseURL + `/commands`);
2148
+ return this.get<ListCommandsResponse<StreamChatGenerics>>(this.baseURL + `/commands`);
2371
2149
  }
2372
2150
 
2373
- createChannelType(data: CreateChannelOptions<CommandType>) {
2151
+ createChannelType(data: CreateChannelOptions<StreamChatGenerics>) {
2374
2152
  const channelData = Object.assign({}, { commands: ['all'] }, data);
2375
- return this.post<CreateChannelResponse<CommandType>>(this.baseURL + '/channeltypes', channelData);
2153
+ return this.post<CreateChannelResponse<StreamChatGenerics>>(this.baseURL + '/channeltypes', channelData);
2376
2154
  }
2377
2155
 
2378
2156
  getChannelType(channelType: string) {
2379
- return this.get<GetChannelTypeResponse<CommandType>>(this.baseURL + `/channeltypes/${channelType}`);
2157
+ return this.get<GetChannelTypeResponse<StreamChatGenerics>>(this.baseURL + `/channeltypes/${channelType}`);
2380
2158
  }
2381
2159
 
2382
- updateChannelType(channelType: string, data: UpdateChannelOptions<CommandType>) {
2383
- return this.put<UpdateChannelResponse<CommandType>>(this.baseURL + `/channeltypes/${channelType}`, data);
2160
+ updateChannelType(channelType: string, data: UpdateChannelOptions<StreamChatGenerics>) {
2161
+ return this.put<UpdateChannelResponse<StreamChatGenerics>>(this.baseURL + `/channeltypes/${channelType}`, data);
2384
2162
  }
2385
2163
 
2386
2164
  deleteChannelType(channelType: string) {
@@ -2388,7 +2166,7 @@ export class StreamChat<
2388
2166
  }
2389
2167
 
2390
2168
  listChannelTypes() {
2391
- return this.get<ListChannelResponse<CommandType>>(this.baseURL + `/channeltypes`);
2169
+ return this.get<ListChannelResponse<StreamChatGenerics>>(this.baseURL + `/channeltypes`);
2392
2170
  }
2393
2171
 
2394
2172
  /**
@@ -2397,14 +2175,13 @@ export class StreamChat<
2397
2175
  * @param {string} messageId
2398
2176
  * @param {string} language
2399
2177
  *
2400
- * @return {APIResponse & MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>} Response that includes the message
2178
+ * @return {MessageResponse<StreamChatGenerics>} Response that includes the message
2401
2179
  */
2402
2180
  async translateMessage(messageId: string, language: string) {
2403
- return await this.post<
2404
- APIResponse & MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
2405
- >(this.baseURL + `/messages/${messageId}/translate`, {
2406
- language,
2407
- });
2181
+ return await this.post<APIResponse & MessageResponse<StreamChatGenerics>>(
2182
+ this.baseURL + `/messages/${messageId}/translate`,
2183
+ { language },
2184
+ );
2408
2185
  }
2409
2186
 
2410
2187
  /**
@@ -2462,13 +2239,13 @@ export class StreamChat<
2462
2239
  );
2463
2240
  return this.partialUpdateMessage(
2464
2241
  messageId,
2465
- {
2242
+ ({
2466
2243
  set: {
2467
2244
  pinned: true,
2468
2245
  pin_expires: this._normalizeExpiration(timeoutOrExpirationDate),
2469
2246
  pinned_at: this._normalizeExpiration(pinnedAt),
2470
2247
  },
2471
- },
2248
+ } as unknown) as PartialMessageUpdate<StreamChatGenerics>,
2472
2249
  pinnedBy,
2473
2250
  );
2474
2251
  }
@@ -2485,11 +2262,7 @@ export class StreamChat<
2485
2262
  );
2486
2263
  return this.partialUpdateMessage(
2487
2264
  messageId,
2488
- {
2489
- set: {
2490
- pinned: false,
2491
- },
2492
- },
2265
+ ({ set: { pinned: false } } as unknown) as PartialMessageUpdate<StreamChatGenerics>,
2493
2266
  userId,
2494
2267
  );
2495
2268
  }
@@ -2497,14 +2270,14 @@ export class StreamChat<
2497
2270
  /**
2498
2271
  * updateMessage - Update the given message
2499
2272
  *
2500
- * @param {Omit<MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>, 'mentioned_users'> & { mentioned_users?: string[] }} message object, id needs to be specified
2273
+ * @param {Omit<MessageResponse<StreamChatGenerics>, 'mentioned_users'> & { mentioned_users?: string[] }} message object, id needs to be specified
2501
2274
  * @param {string | { id: string }} [userId]
2502
2275
  * @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
2503
2276
  *
2504
- * @return {APIResponse & { message: MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> }} Response that includes the message
2277
+ * @return {{ message: MessageResponse<StreamChatGenerics> }} Response that includes the message
2505
2278
  */
2506
2279
  async updateMessage(
2507
- message: UpdatedMessage<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>,
2280
+ message: UpdatedMessage<StreamChatGenerics>,
2508
2281
  userId?: string | { id: string },
2509
2282
  options?: { skip_enrich_url?: boolean },
2510
2283
  ) {
@@ -2540,7 +2313,7 @@ export class StreamChat<
2540
2313
  if (isString(userId)) {
2541
2314
  clonedMessage.user_id = userId;
2542
2315
  } else {
2543
- clonedMessage.user = { id: userId.id } as UserResponse<UserType>;
2316
+ clonedMessage.user = { id: userId.id } as UserResponse<StreamChatGenerics>;
2544
2317
  }
2545
2318
  }
2546
2319
 
@@ -2552,9 +2325,7 @@ export class StreamChat<
2552
2325
  clonedMessage.mentioned_users = clonedMessage.mentioned_users.map((mu) => ((mu as unknown) as UserResponse).id);
2553
2326
  }
2554
2327
 
2555
- return await this.post<
2556
- UpdateMessageAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
2557
- >(this.baseURL + `/messages/${message.id}`, {
2328
+ return await this.post<UpdateMessageAPIResponse<StreamChatGenerics>>(this.baseURL + `/messages/${message.id}`, {
2558
2329
  message: clonedMessage,
2559
2330
  ...options,
2560
2331
  });
@@ -2565,17 +2336,17 @@ export class StreamChat<
2565
2336
  *
2566
2337
  * @param {string} id the message id
2567
2338
  *
2568
- * @param {PartialUpdateMessage<MessageType>} partialMessageObject which should contain id and any of "set" or "unset" params;
2339
+ * @param {PartialUpdateMessage<StreamChatGenerics>} partialMessageObject which should contain id and any of "set" or "unset" params;
2569
2340
  * example: {id: "user1", set:{text: "hi"}, unset:["color"]}
2570
2341
  * @param {string | { id: string }} [userId]
2571
2342
  *
2572
2343
  * @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
2573
2344
  *
2574
- * @return {APIResponse & { message: MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> }} Response that includes the updated message
2345
+ * @return {{ message: MessageResponse<StreamChatGenerics> }} Response that includes the updated message
2575
2346
  */
2576
2347
  async partialUpdateMessage(
2577
2348
  id: string,
2578
- partialMessageObject: PartialMessageUpdate<MessageType>,
2349
+ partialMessageObject: PartialMessageUpdate<StreamChatGenerics>,
2579
2350
  userId?: string | { id: string },
2580
2351
  options?: { skip_enrich_url?: boolean },
2581
2352
  ) {
@@ -2586,9 +2357,7 @@ export class StreamChat<
2586
2357
  if (userId != null && isString(userId)) {
2587
2358
  user = { id: userId };
2588
2359
  }
2589
- return await this.put<
2590
- UpdateMessageAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
2591
- >(this.baseURL + `/messages/${id}`, {
2360
+ return await this.put<UpdateMessageAPIResponse<StreamChatGenerics>>(this.baseURL + `/messages/${id}`, {
2592
2361
  ...partialMessageObject,
2593
2362
  ...options,
2594
2363
  user,
@@ -2600,19 +2369,16 @@ export class StreamChat<
2600
2369
  if (hardDelete) {
2601
2370
  params = { hard: true };
2602
2371
  }
2603
- return await this.delete<
2604
- APIResponse & {
2605
- message: MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>;
2606
- }
2607
- >(this.baseURL + `/messages/${messageID}`, params);
2372
+ return await this.delete<APIResponse & { message: MessageResponse<StreamChatGenerics> }>(
2373
+ this.baseURL + `/messages/${messageID}`,
2374
+ params,
2375
+ );
2608
2376
  }
2609
2377
 
2610
2378
  async getMessage(messageID: string) {
2611
- return await this.get<
2612
- APIResponse & {
2613
- message: MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>;
2614
- }
2615
- >(this.baseURL + `/messages/${messageID}`);
2379
+ return await this.get<APIResponse & { message: MessageResponse<StreamChatGenerics> }>(
2380
+ this.baseURL + `/messages/${messageID}`,
2381
+ );
2616
2382
  }
2617
2383
 
2618
2384
  getUserAgent() {
@@ -2716,9 +2482,7 @@ export class StreamChat<
2716
2482
  * @returns {Promise<APIResponse>}
2717
2483
  */
2718
2484
  createPermission(permissionData: CustomPermissionOptions) {
2719
- return this.post<APIResponse>(`${this.baseURL}/permissions`, {
2720
- ...permissionData,
2721
- });
2485
+ return this.post<APIResponse>(`${this.baseURL}/permissions`, { ...permissionData });
2722
2486
  }
2723
2487
 
2724
2488
  /** updatePermission - updates an existing custom permission
@@ -2728,9 +2492,7 @@ export class StreamChat<
2728
2492
  * @returns {Promise<APIResponse>}
2729
2493
  */
2730
2494
  updatePermission(id: string, permissionData: Omit<CustomPermissionOptions, 'id'>) {
2731
- return this.put<APIResponse>(`${this.baseURL}/permissions/${id}`, {
2732
- ...permissionData,
2733
- });
2495
+ return this.put<APIResponse>(`${this.baseURL}/permissions/${id}`, { ...permissionData });
2734
2496
  }
2735
2497
 
2736
2498
  /** deletePermission - deletes a custom permission
@@ -2781,11 +2543,7 @@ export class StreamChat<
2781
2543
  * @param {string} last_sync_at last time the user was online and in sync. RFC3339 ie. "2020-05-06T15:05:01.207Z"
2782
2544
  */
2783
2545
  sync(channel_cids: string[], last_sync_at: string) {
2784
- return this.post<
2785
- APIResponse & {
2786
- events: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>[];
2787
- }
2788
- >(`${this.baseURL}/sync`, {
2546
+ return this.post<APIResponse & { events: Event<StreamChatGenerics>[] }>(`${this.baseURL}/sync`, {
2789
2547
  channel_cids,
2790
2548
  last_sync_at,
2791
2549
  });
@@ -2826,10 +2584,7 @@ export class StreamChat<
2826
2584
  }
2827
2585
 
2828
2586
  exportChannels(request: Array<ExportChannelRequest>, options: ExportChannelOptions = {}) {
2829
- const payload = {
2830
- channels: request,
2831
- ...options,
2832
- };
2587
+ const payload = { channels: request, ...options };
2833
2588
  return this.post<APIResponse & ExportChannelResponse>(`${this.baseURL}/export_channels`, payload);
2834
2589
  }
2835
2590
 
@@ -3079,7 +2834,7 @@ export class StreamChat<
3079
2834
  }
3080
2835
 
3081
2836
  /**
3082
- * _createImport - Create an Import Task.
2837
+ * _createImportURL - Create an Import upload url.
3083
2838
  *
3084
2839
  * Note: Do not use this.
3085
2840
  * It is present for internal usage only.
@@ -3090,12 +2845,30 @@ export class StreamChat<
3090
2845
  *
3091
2846
  * @return {APIResponse & CreateImportResponse} An ImportTask
3092
2847
  */
3093
- async _createImport(filename: string) {
3094
- return await this.post<APIResponse & CreateImportResponse>(this.baseURL + `/imports`, {
2848
+ async _createImportURL(filename: string) {
2849
+ return await this.post<APIResponse & CreateImportURLResponse>(this.baseURL + `/import_urls`, {
3095
2850
  filename,
3096
2851
  });
3097
2852
  }
3098
2853
 
2854
+ /**
2855
+ * _createImport - Create an Import Task.
2856
+ *
2857
+ * Note: Do not use this.
2858
+ * It is present for internal usage only.
2859
+ * This function can, and will, break and/or be removed at any point in time.
2860
+ *
2861
+ * @private
2862
+ * @param {string} path path of uploaded data
2863
+ *
2864
+ * @return {APIResponse & CreateImportResponse} An ImportTask
2865
+ */
2866
+ async _createImport(path: string) {
2867
+ return await this.post<APIResponse & CreateImportResponse>(this.baseURL + `/imports`, {
2868
+ path,
2869
+ });
2870
+ }
2871
+
3099
2872
  /**
3100
2873
  * _getImport - Get an Import Task.
3101
2874
  *