stream-chat 8.56.0 → 8.57.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 (80) hide show
  1. package/dist/cjs/index.browser.cjs +11101 -0
  2. package/dist/cjs/index.browser.cjs.map +7 -0
  3. package/dist/cjs/index.node.cjs +22510 -0
  4. package/dist/cjs/index.node.cjs.map +7 -0
  5. package/dist/esm/index.js +11097 -0
  6. package/dist/esm/index.js.map +7 -0
  7. package/dist/types/base64.d.ts +0 -1
  8. package/dist/types/campaign.d.ts +18 -3
  9. package/dist/types/channel.d.ts +3 -5
  10. package/dist/types/channel_manager.d.ts +11 -12
  11. package/dist/types/channel_state.d.ts +6 -7
  12. package/dist/types/client.d.ts +110 -141
  13. package/dist/types/client_state.d.ts +0 -1
  14. package/dist/types/connection.d.ts +3 -6
  15. package/dist/types/connection_fallback.d.ts +0 -1
  16. package/dist/types/constants.d.ts +0 -1
  17. package/dist/types/errors.d.ts +1 -2
  18. package/dist/types/events.d.ts +0 -1
  19. package/dist/types/index.d.ts +0 -1
  20. package/dist/types/insights.d.ts +3 -5
  21. package/dist/types/moderation.d.ts +0 -1
  22. package/dist/types/permissions.d.ts +2 -3
  23. package/dist/types/poll.d.ts +9 -10
  24. package/dist/types/poll_manager.d.ts +1 -2
  25. package/dist/types/search_controller.d.ts +17 -18
  26. package/dist/types/segment.d.ts +3 -4
  27. package/dist/types/signing.d.ts +3 -5
  28. package/dist/types/store.d.ts +5 -6
  29. package/dist/types/thread.d.ts +9 -10
  30. package/dist/types/thread_manager.d.ts +3 -4
  31. package/dist/types/token_manager.d.ts +4 -5
  32. package/dist/types/types.d.ts +400 -387
  33. package/dist/types/utils.d.ts +14 -15
  34. package/package.json +53 -58
  35. package/src/campaign.ts +3 -3
  36. package/src/channel_manager.ts +21 -10
  37. package/src/client.ts +69 -19
  38. package/src/connection.ts +14 -7
  39. package/src/connection_fallback.ts +9 -7
  40. package/src/signing.ts +10 -5
  41. package/src/token_manager.ts +5 -4
  42. package/src/types.ts +9 -0
  43. package/src/utils.ts +21 -0
  44. package/dist/browser.es.js +0 -19194
  45. package/dist/browser.es.js.map +0 -1
  46. package/dist/browser.full-bundle.min.js +0 -2
  47. package/dist/browser.full-bundle.min.js.map +0 -1
  48. package/dist/browser.js +0 -19275
  49. package/dist/browser.js.map +0 -1
  50. package/dist/index.es.js +0 -19197
  51. package/dist/index.es.js.map +0 -1
  52. package/dist/index.js +0 -19281
  53. package/dist/index.js.map +0 -1
  54. package/dist/types/base64.d.ts.map +0 -1
  55. package/dist/types/campaign.d.ts.map +0 -1
  56. package/dist/types/channel.d.ts.map +0 -1
  57. package/dist/types/channel_manager.d.ts.map +0 -1
  58. package/dist/types/channel_state.d.ts.map +0 -1
  59. package/dist/types/client.d.ts.map +0 -1
  60. package/dist/types/client_state.d.ts.map +0 -1
  61. package/dist/types/connection.d.ts.map +0 -1
  62. package/dist/types/connection_fallback.d.ts.map +0 -1
  63. package/dist/types/constants.d.ts.map +0 -1
  64. package/dist/types/errors.d.ts.map +0 -1
  65. package/dist/types/events.d.ts.map +0 -1
  66. package/dist/types/index.d.ts.map +0 -1
  67. package/dist/types/insights.d.ts.map +0 -1
  68. package/dist/types/moderation.d.ts.map +0 -1
  69. package/dist/types/permissions.d.ts.map +0 -1
  70. package/dist/types/poll.d.ts.map +0 -1
  71. package/dist/types/poll_manager.d.ts.map +0 -1
  72. package/dist/types/search_controller.d.ts.map +0 -1
  73. package/dist/types/segment.d.ts.map +0 -1
  74. package/dist/types/signing.d.ts.map +0 -1
  75. package/dist/types/store.d.ts.map +0 -1
  76. package/dist/types/thread.d.ts.map +0 -1
  77. package/dist/types/thread_manager.d.ts.map +0 -1
  78. package/dist/types/token_manager.d.ts.map +0 -1
  79. package/dist/types/types.d.ts.map +0 -1
  80. package/dist/types/utils.d.ts.map +0 -1
@@ -81,16 +81,17 @@ export class WSConnectionFallback<StreamChatGenerics extends ExtendableGenerics
81
81
 
82
82
  this.consecutiveFailures = 0; // always reset in case of no error
83
83
  return res;
84
- } catch (err) {
84
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
+ } catch (error: any) {
85
86
  this.consecutiveFailures += 1;
86
87
 
87
- if (retry && isErrorRetryable(err)) {
88
+ if (retry && isErrorRetryable(error)) {
88
89
  this._log(`_req() - Retryable error, retrying request`);
89
90
  await sleep(retryInterval(this.consecutiveFailures));
90
91
  return this._req<T>(params, config, retry);
91
92
  }
92
93
 
93
- throw err;
94
+ throw error;
94
95
  }
95
96
  };
96
97
 
@@ -107,22 +108,23 @@ export class WSConnectionFallback<StreamChatGenerics extends ExtendableGenerics
107
108
  this.client.dispatchEvent(data.events[i]);
108
109
  }
109
110
  }
110
- } catch (err) {
111
- if (axios.isCancel(err)) {
111
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
112
+ } catch (error: any) {
113
+ if (axios.isCancel(error)) {
112
114
  this._log(`_poll() - axios canceled request`);
113
115
  return;
114
116
  }
115
117
 
116
118
  /** client.doAxiosRequest will take care of TOKEN_EXPIRED error */
117
119
 
118
- if (isConnectionIDError(err)) {
120
+ if (isConnectionIDError(error)) {
119
121
  this._log(`_poll() - ConnectionID error, connecting without ID...`);
120
122
  this._setState(ConnectionState.Disconnected);
121
123
  this.connect(true);
122
124
  return;
123
125
  }
124
126
 
125
- if (isAPIError(err) && !isErrorRetryable(err)) {
127
+ if (isAPIError(error) && !isErrorRetryable(error)) {
126
128
  this._setState(ConnectionState.Closed);
127
129
  return;
128
130
  }
package/src/signing.ts CHANGED
@@ -1,4 +1,4 @@
1
- import jwt, { Secret, SignOptions } from 'jsonwebtoken';
1
+ import jwt from 'jsonwebtoken';
2
2
  import crypto from 'crypto';
3
3
  import { encodeBase64, decodeBase64 } from './base64';
4
4
  import { UR } from './types';
@@ -14,7 +14,12 @@ import { UR } from './types';
14
14
  * @param {SignOptions} [jwtOptions] - Options that can be past to jwt.sign
15
15
  * @return {string} JWT Token
16
16
  */
17
- export function JWTUserToken(apiSecret: Secret, userId: string, extraData: UR = {}, jwtOptions: SignOptions = {}) {
17
+ export function JWTUserToken(
18
+ apiSecret: jwt.Secret,
19
+ userId: string,
20
+ extraData: UR = {},
21
+ jwtOptions: jwt.SignOptions = {},
22
+ ) {
18
23
  if (typeof userId !== 'string') {
19
24
  throw new TypeError('userId should be a string');
20
25
  }
@@ -31,7 +36,7 @@ export function JWTUserToken(apiSecret: Secret, userId: string, extraData: UR =
31
36
  );
32
37
  }
33
38
 
34
- const opts: SignOptions = Object.assign({ algorithm: 'HS256', noTimestamp: true }, jwtOptions);
39
+ const opts: jwt.SignOptions = Object.assign({ algorithm: 'HS256', noTimestamp: true }, jwtOptions);
35
40
 
36
41
  if (payload.iat) {
37
42
  opts.noTimestamp = false;
@@ -39,12 +44,12 @@ export function JWTUserToken(apiSecret: Secret, userId: string, extraData: UR =
39
44
  return jwt.sign(payload, apiSecret, opts);
40
45
  }
41
46
 
42
- export function JWTServerToken(apiSecret: Secret, jwtOptions: SignOptions = {}) {
47
+ export function JWTServerToken(apiSecret: jwt.Secret, jwtOptions: jwt.SignOptions = {}) {
43
48
  const payload = {
44
49
  server: true,
45
50
  };
46
51
 
47
- const opts: SignOptions = Object.assign({ algorithm: 'HS256', noTimestamp: true }, jwtOptions);
52
+ const opts: jwt.SignOptions = Object.assign({ algorithm: 'HS256', noTimestamp: true }, jwtOptions);
48
53
  return jwt.sign(payload, apiSecret, opts);
49
54
  }
50
55
 
@@ -1,7 +1,8 @@
1
- import { Secret } from 'jsonwebtoken';
1
+ import jwt from 'jsonwebtoken';
2
+
2
3
  import { UserFromToken, JWTServerToken, JWTUserToken } from './signing';
3
4
  import { isFunction } from './utils';
4
- import { TokenOrProvider, ExtendableGenerics, DefaultGenerics, UserResponse } from './types';
5
+ import type { TokenOrProvider, ExtendableGenerics, DefaultGenerics, UserResponse } from './types';
5
6
 
6
7
  /**
7
8
  * TokenManager
@@ -11,7 +12,7 @@ import { TokenOrProvider, ExtendableGenerics, DefaultGenerics, UserResponse } fr
11
12
  export class TokenManager<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> {
12
13
  loadTokenPromise: Promise<string> | null;
13
14
  type: 'static' | 'provider';
14
- secret?: Secret;
15
+ secret?: jwt.Secret;
15
16
  token?: string;
16
17
  tokenProvider?: TokenOrProvider;
17
18
  user?: UserResponse<StreamChatGenerics>;
@@ -20,7 +21,7 @@ export class TokenManager<StreamChatGenerics extends ExtendableGenerics = Defaul
20
21
  *
21
22
  * @param {Secret} secret
22
23
  */
23
- constructor(secret?: Secret) {
24
+ constructor(secret?: jwt.Secret) {
24
25
  this.loadTokenPromise = null;
25
26
  if (secret) {
26
27
  this.secret = secret;
package/src/types.ts CHANGED
@@ -3000,6 +3000,10 @@ export type QuerySegmentTargetsFilter = {
3000
3000
  };
3001
3001
  export type QuerySegmentTargetsOptions = Pick<Pager, 'next' | 'limit'>;
3002
3002
 
3003
+ export type GetCampaignOptions = {
3004
+ users?: { limit?: number; next?: string; prev?: string };
3005
+ };
3006
+
3003
3007
  export type CampaignSort = {
3004
3008
  field: string;
3005
3009
  direction?: number;
@@ -3010,6 +3014,7 @@ export type CampaignQueryOptions = {
3010
3014
  next?: string;
3011
3015
  prev?: string;
3012
3016
  sort?: CampaignSort;
3017
+ user_limit?: number;
3013
3018
  };
3014
3019
 
3015
3020
  export type SegmentQueryOptions = CampaignQueryOptions;
@@ -3050,6 +3055,8 @@ export type CampaignStats = {
3050
3055
  stats_completed_at?: string;
3051
3056
  stats_messages_sent?: number;
3052
3057
  stats_started_at?: string;
3058
+ stats_users_read?: number;
3059
+ stats_users_sent?: number;
3053
3060
  };
3054
3061
  export type CampaignResponse = {
3055
3062
  created_at: string;
@@ -3808,3 +3815,5 @@ export type PromoteChannelParams<SCG extends ExtendableGenerics = DefaultGeneric
3808
3815
  */
3809
3816
  channelToMoveIndexWithinChannels?: number;
3810
3817
  };
3818
+
3819
+ export type SdkIdentifier = { name: 'react' | 'react-native' | 'angular'; version: string };
package/src/utils.ts CHANGED
@@ -602,6 +602,27 @@ export const throttle = <T extends (...args: unknown[]) => unknown>(
602
602
  };
603
603
  };
604
604
 
605
+ const get = <T>(obj: T, path: string): unknown =>
606
+ path.split('.').reduce<unknown>((acc, key) => {
607
+ if (acc && typeof acc === 'object' && key in acc) {
608
+ return (acc as Record<string, unknown>)[key];
609
+ }
610
+ return undefined;
611
+ }, obj);
612
+
613
+ // works exactly the same as lodash.uniqBy
614
+ export const uniqBy = <T>(array: T[] | unknown, iteratee: ((item: T) => unknown) | keyof T): T[] => {
615
+ if (!Array.isArray(array)) return [];
616
+
617
+ const seen = new Set<unknown>();
618
+ return array.filter((item) => {
619
+ const key = typeof iteratee === 'function' ? iteratee(item) : get(item, iteratee as string);
620
+ if (seen.has(key)) return false;
621
+ seen.add(key);
622
+ return true;
623
+ });
624
+ };
625
+
605
626
  type MessagePaginationUpdatedParams<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
606
627
  parentSet: MessageSet;
607
628
  requestedPageSize: number;