stream-chat 8.57.0 → 8.57.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/dist/browser.es.js +19235 -0
- package/dist/browser.es.js.map +1 -0
- package/dist/browser.full-bundle.min.js +2 -0
- package/dist/browser.full-bundle.min.js.map +1 -0
- package/dist/browser.js +19316 -0
- package/dist/browser.js.map +1 -0
- package/dist/index.es.js +19238 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.js +19322 -0
- package/dist/index.js.map +1 -0
- package/dist/types/base64.d.ts +1 -0
- package/dist/types/base64.d.ts.map +1 -0
- package/dist/types/campaign.d.ts +9 -8
- package/dist/types/campaign.d.ts.map +1 -0
- package/dist/types/channel.d.ts +5 -3
- package/dist/types/channel.d.ts.map +1 -0
- package/dist/types/channel_manager.d.ts +12 -11
- package/dist/types/channel_manager.d.ts.map +1 -0
- package/dist/types/channel_state.d.ts +7 -6
- package/dist/types/channel_state.d.ts.map +1 -0
- package/dist/types/client.d.ts +141 -87
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/client_state.d.ts +1 -0
- package/dist/types/client_state.d.ts.map +1 -0
- package/dist/types/connection.d.ts +6 -3
- package/dist/types/connection.d.ts.map +1 -0
- package/dist/types/connection_fallback.d.ts +1 -0
- package/dist/types/connection_fallback.d.ts.map +1 -0
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/errors.d.ts +2 -1
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/events.d.ts +1 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/insights.d.ts +5 -3
- package/dist/types/insights.d.ts.map +1 -0
- package/dist/types/moderation.d.ts +1 -0
- package/dist/types/moderation.d.ts.map +1 -0
- package/dist/types/permissions.d.ts +3 -2
- package/dist/types/permissions.d.ts.map +1 -0
- package/dist/types/poll.d.ts +10 -9
- package/dist/types/poll.d.ts.map +1 -0
- package/dist/types/poll_manager.d.ts +2 -1
- package/dist/types/poll_manager.d.ts.map +1 -0
- package/dist/types/search_controller.d.ts +18 -17
- package/dist/types/search_controller.d.ts.map +1 -0
- package/dist/types/segment.d.ts +4 -3
- package/dist/types/segment.d.ts.map +1 -0
- package/dist/types/signing.d.ts +5 -3
- package/dist/types/signing.d.ts.map +1 -0
- package/dist/types/store.d.ts +6 -5
- package/dist/types/store.d.ts.map +1 -0
- package/dist/types/thread.d.ts +10 -9
- package/dist/types/thread.d.ts.map +1 -0
- package/dist/types/thread_manager.d.ts +4 -3
- package/dist/types/thread_manager.d.ts.map +1 -0
- package/dist/types/token_manager.d.ts +5 -4
- package/dist/types/token_manager.d.ts.map +1 -0
- package/dist/types/types.d.ts +389 -388
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +16 -14
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +58 -53
- package/src/client.ts +6 -18
- package/src/connection.ts +7 -14
- package/src/connection_fallback.ts +7 -9
- package/src/signing.ts +5 -10
- package/src/token_manager.ts +4 -5
- package/dist/cjs/index.browser.cjs +0 -11101
- package/dist/cjs/index.browser.cjs.map +0 -7
- package/dist/cjs/index.node.cjs +0 -22510
- package/dist/cjs/index.node.cjs.map +0 -7
- package/dist/esm/index.js +0 -11097
- package/dist/esm/index.js.map +0 -7
package/src/connection.ts
CHANGED
|
@@ -113,8 +113,7 @@ export class StableWSConnection<StreamChatGenerics extends ExtendableGenerics =
|
|
|
113
113
|
this.consecutiveFailures = 0;
|
|
114
114
|
|
|
115
115
|
this._log(`connect() - Established ws connection with healthcheck: ${healthCheck}`);
|
|
116
|
-
|
|
117
|
-
} catch (error: any) {
|
|
116
|
+
} catch (error) {
|
|
118
117
|
this.isHealthy = false;
|
|
119
118
|
this.consecutiveFailures += 1;
|
|
120
119
|
|
|
@@ -149,8 +148,7 @@ export class StableWSConnection<StreamChatGenerics extends ExtendableGenerics =
|
|
|
149
148
|
for (let i = 0; i <= timeout; i += interval) {
|
|
150
149
|
try {
|
|
151
150
|
return await this.connectionOpen;
|
|
152
|
-
|
|
153
|
-
} catch (error: any) {
|
|
151
|
+
} catch (error) {
|
|
154
152
|
if (i === timeout) {
|
|
155
153
|
throw new Error(
|
|
156
154
|
JSON.stringify({
|
|
@@ -300,21 +298,17 @@ export class StableWSConnection<StreamChatGenerics extends ExtendableGenerics =
|
|
|
300
298
|
}
|
|
301
299
|
return response;
|
|
302
300
|
}
|
|
303
|
-
|
|
304
|
-
} catch (error: any) {
|
|
301
|
+
} catch (err) {
|
|
305
302
|
this.isConnecting = false;
|
|
306
|
-
this._log(`_connect() - Error - `,
|
|
303
|
+
this._log(`_connect() - Error - `, err);
|
|
307
304
|
if (this.client.options.enableInsights) {
|
|
308
305
|
this.client.insightMetrics.wsConsecutiveFailures++;
|
|
309
306
|
this.client.insightMetrics.wsTotalFailures++;
|
|
310
307
|
|
|
311
|
-
const insights = buildWsFatalInsight(
|
|
312
|
-
(this as unknown) as StableWSConnection,
|
|
313
|
-
convertErrorToJson(error as Error),
|
|
314
|
-
);
|
|
308
|
+
const insights = buildWsFatalInsight((this as unknown) as StableWSConnection, convertErrorToJson(err as Error));
|
|
315
309
|
postInsights?.('ws_fatal', insights);
|
|
316
310
|
}
|
|
317
|
-
throw
|
|
311
|
+
throw err;
|
|
318
312
|
}
|
|
319
313
|
}
|
|
320
314
|
|
|
@@ -372,8 +366,7 @@ export class StableWSConnection<StreamChatGenerics extends ExtendableGenerics =
|
|
|
372
366
|
this._log('_reconnect() - Finished recoverCallBack');
|
|
373
367
|
|
|
374
368
|
this.consecutiveFailures = 0;
|
|
375
|
-
|
|
376
|
-
} catch (error: any) {
|
|
369
|
+
} catch (error) {
|
|
377
370
|
this.isHealthy = false;
|
|
378
371
|
this.consecutiveFailures += 1;
|
|
379
372
|
if (error.code === chatCodes.TOKEN_EXPIRED && !this.client.tokenManager.isStatic()) {
|
|
@@ -81,17 +81,16 @@ 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
|
-
|
|
85
|
-
} catch (error: any) {
|
|
84
|
+
} catch (err) {
|
|
86
85
|
this.consecutiveFailures += 1;
|
|
87
86
|
|
|
88
|
-
if (retry && isErrorRetryable(
|
|
87
|
+
if (retry && isErrorRetryable(err)) {
|
|
89
88
|
this._log(`_req() - Retryable error, retrying request`);
|
|
90
89
|
await sleep(retryInterval(this.consecutiveFailures));
|
|
91
90
|
return this._req<T>(params, config, retry);
|
|
92
91
|
}
|
|
93
92
|
|
|
94
|
-
throw
|
|
93
|
+
throw err;
|
|
95
94
|
}
|
|
96
95
|
};
|
|
97
96
|
|
|
@@ -108,23 +107,22 @@ export class WSConnectionFallback<StreamChatGenerics extends ExtendableGenerics
|
|
|
108
107
|
this.client.dispatchEvent(data.events[i]);
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (axios.isCancel(error)) {
|
|
110
|
+
} catch (err) {
|
|
111
|
+
if (axios.isCancel(err)) {
|
|
114
112
|
this._log(`_poll() - axios canceled request`);
|
|
115
113
|
return;
|
|
116
114
|
}
|
|
117
115
|
|
|
118
116
|
/** client.doAxiosRequest will take care of TOKEN_EXPIRED error */
|
|
119
117
|
|
|
120
|
-
if (isConnectionIDError(
|
|
118
|
+
if (isConnectionIDError(err)) {
|
|
121
119
|
this._log(`_poll() - ConnectionID error, connecting without ID...`);
|
|
122
120
|
this._setState(ConnectionState.Disconnected);
|
|
123
121
|
this.connect(true);
|
|
124
122
|
return;
|
|
125
123
|
}
|
|
126
124
|
|
|
127
|
-
if (isAPIError(
|
|
125
|
+
if (isAPIError(err) && !isErrorRetryable(err)) {
|
|
128
126
|
this._setState(ConnectionState.Closed);
|
|
129
127
|
return;
|
|
130
128
|
}
|
package/src/signing.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import jwt from 'jsonwebtoken';
|
|
1
|
+
import jwt, { Secret, SignOptions } from 'jsonwebtoken';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import { encodeBase64, decodeBase64 } from './base64';
|
|
4
4
|
import { UR } from './types';
|
|
@@ -14,12 +14,7 @@ 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(
|
|
18
|
-
apiSecret: jwt.Secret,
|
|
19
|
-
userId: string,
|
|
20
|
-
extraData: UR = {},
|
|
21
|
-
jwtOptions: jwt.SignOptions = {},
|
|
22
|
-
) {
|
|
17
|
+
export function JWTUserToken(apiSecret: Secret, userId: string, extraData: UR = {}, jwtOptions: SignOptions = {}) {
|
|
23
18
|
if (typeof userId !== 'string') {
|
|
24
19
|
throw new TypeError('userId should be a string');
|
|
25
20
|
}
|
|
@@ -36,7 +31,7 @@ export function JWTUserToken(
|
|
|
36
31
|
);
|
|
37
32
|
}
|
|
38
33
|
|
|
39
|
-
const opts:
|
|
34
|
+
const opts: SignOptions = Object.assign({ algorithm: 'HS256', noTimestamp: true }, jwtOptions);
|
|
40
35
|
|
|
41
36
|
if (payload.iat) {
|
|
42
37
|
opts.noTimestamp = false;
|
|
@@ -44,12 +39,12 @@ export function JWTUserToken(
|
|
|
44
39
|
return jwt.sign(payload, apiSecret, opts);
|
|
45
40
|
}
|
|
46
41
|
|
|
47
|
-
export function JWTServerToken(apiSecret:
|
|
42
|
+
export function JWTServerToken(apiSecret: Secret, jwtOptions: SignOptions = {}) {
|
|
48
43
|
const payload = {
|
|
49
44
|
server: true,
|
|
50
45
|
};
|
|
51
46
|
|
|
52
|
-
const opts:
|
|
47
|
+
const opts: SignOptions = Object.assign({ algorithm: 'HS256', noTimestamp: true }, jwtOptions);
|
|
53
48
|
return jwt.sign(payload, apiSecret, opts);
|
|
54
49
|
}
|
|
55
50
|
|
package/src/token_manager.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { Secret } from 'jsonwebtoken';
|
|
3
2
|
import { UserFromToken, JWTServerToken, JWTUserToken } from './signing';
|
|
4
3
|
import { isFunction } from './utils';
|
|
5
|
-
import
|
|
4
|
+
import { TokenOrProvider, ExtendableGenerics, DefaultGenerics, UserResponse } from './types';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* TokenManager
|
|
@@ -12,7 +11,7 @@ import type { TokenOrProvider, ExtendableGenerics, DefaultGenerics, UserResponse
|
|
|
12
11
|
export class TokenManager<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> {
|
|
13
12
|
loadTokenPromise: Promise<string> | null;
|
|
14
13
|
type: 'static' | 'provider';
|
|
15
|
-
secret?:
|
|
14
|
+
secret?: Secret;
|
|
16
15
|
token?: string;
|
|
17
16
|
tokenProvider?: TokenOrProvider;
|
|
18
17
|
user?: UserResponse<StreamChatGenerics>;
|
|
@@ -21,7 +20,7 @@ export class TokenManager<StreamChatGenerics extends ExtendableGenerics = Defaul
|
|
|
21
20
|
*
|
|
22
21
|
* @param {Secret} secret
|
|
23
22
|
*/
|
|
24
|
-
constructor(secret?:
|
|
23
|
+
constructor(secret?: Secret) {
|
|
25
24
|
this.loadTokenPromise = null;
|
|
26
25
|
if (secret) {
|
|
27
26
|
this.secret = secret;
|