stream-chat 4.4.1 → 4.4.3-dev.2
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/CHANGELOG.md +844 -0
- package/dist/browser.es.js +86 -65
- package/dist/browser.es.js.map +1 -1
- package/dist/browser.full-bundle.min.js +1 -1
- package/dist/browser.full-bundle.min.js.map +1 -1
- package/dist/browser.js +86 -65
- package/dist/browser.js.map +1 -1
- package/dist/index.es.js +86 -65
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +86 -65
- package/dist/index.js.map +1 -1
- package/dist/types/client.d.ts +1 -8
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/connection.d.ts.map +1 -1
- package/dist/types/insights.d.ts +7 -10
- package/dist/types/insights.d.ts.map +1 -1
- package/dist/types/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/client.ts +24 -16
- package/src/connection.ts +20 -12
- package/src/insights.ts +7 -8
- package/src/types.ts +2 -0
- package/src/utils.ts +13 -0
package/src/connection.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
|
-
import { chatCodes, sleep, retryInterval, randomId } from './utils';
|
|
2
|
+
import { chatCodes, convertErrorToJson, sleep, retryInterval, randomId } from './utils';
|
|
3
3
|
import { TokenManager } from './token_manager';
|
|
4
4
|
import {
|
|
5
5
|
buildWsFatalInsight,
|
|
@@ -270,7 +270,7 @@ export class StableWSConnection<
|
|
|
270
270
|
user_token: this.tokenManager.getToken(),
|
|
271
271
|
server_determines_connection_id: true,
|
|
272
272
|
device: this.device,
|
|
273
|
-
|
|
273
|
+
client_request_id: reqID,
|
|
274
274
|
};
|
|
275
275
|
const qs = encodeURIComponent(JSON.stringify(params));
|
|
276
276
|
const token = this.tokenManager.getToken();
|
|
@@ -388,8 +388,8 @@ export class StableWSConnection<
|
|
|
388
388
|
|
|
389
389
|
if (response) {
|
|
390
390
|
this.connectionID = response.connection_id;
|
|
391
|
-
if (this.insightMetrics.wsConsecutiveFailures > 0) {
|
|
392
|
-
this.postInsights
|
|
391
|
+
if (this.insightMetrics.wsConsecutiveFailures > 0 && this.postInsights) {
|
|
392
|
+
this.postInsights(
|
|
393
393
|
'ws_success_after_failure',
|
|
394
394
|
buildWsSuccessAfterFailureInsight(this),
|
|
395
395
|
);
|
|
@@ -399,6 +399,15 @@ export class StableWSConnection<
|
|
|
399
399
|
}
|
|
400
400
|
} catch (err) {
|
|
401
401
|
this.isConnecting = false;
|
|
402
|
+
|
|
403
|
+
if (this.postInsights) {
|
|
404
|
+
this.insightMetrics.wsConsecutiveFailures++;
|
|
405
|
+
this.insightMetrics.wsTotalFailures++;
|
|
406
|
+
|
|
407
|
+
// @ts-ignore
|
|
408
|
+
const insights = buildWsFatalInsight(this, convertErrorToJson(err));
|
|
409
|
+
this.postInsights?.('ws_fatal', insights);
|
|
410
|
+
}
|
|
402
411
|
throw err;
|
|
403
412
|
}
|
|
404
413
|
}
|
|
@@ -587,11 +596,7 @@ export class StableWSConnection<
|
|
|
587
596
|
};
|
|
588
597
|
|
|
589
598
|
onclose = (wsID: number, event: WebSocket.CloseEvent) => {
|
|
590
|
-
if (
|
|
591
|
-
this.insightMetrics.wsConsecutiveFailures++;
|
|
592
|
-
this.insightMetrics.wsTotalFailures++;
|
|
593
|
-
this.postInsights?.('ws_fatal', buildWsFatalInsight(this, event));
|
|
594
|
-
}
|
|
599
|
+
if (this.wsID !== wsID) return;
|
|
595
600
|
|
|
596
601
|
this.logger('info', 'connection:onclose() - onclose callback - ' + event.code, {
|
|
597
602
|
tags: ['connection'],
|
|
@@ -599,15 +604,18 @@ export class StableWSConnection<
|
|
|
599
604
|
wsID,
|
|
600
605
|
});
|
|
601
606
|
|
|
602
|
-
if (this.wsID !== wsID) return;
|
|
603
|
-
|
|
604
607
|
if (event.code === chatCodes.WS_CLOSED_SUCCESS) {
|
|
605
608
|
// this is a permanent error raised by stream..
|
|
606
609
|
// usually caused by invalid auth details
|
|
607
610
|
const error = new Error(
|
|
608
611
|
`WS connection reject with error ${event.reason}`,
|
|
609
|
-
) as Error &
|
|
612
|
+
) as Error & WebSocket.CloseEvent;
|
|
613
|
+
|
|
610
614
|
error.reason = event.reason;
|
|
615
|
+
error.code = event.code;
|
|
616
|
+
error.wasClean = event.wasClean;
|
|
617
|
+
error.target = event.target;
|
|
618
|
+
|
|
611
619
|
this.rejectPromise?.(error);
|
|
612
620
|
this.logger(
|
|
613
621
|
'info',
|
package/src/insights.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { StableWSConnection } from './connection';
|
|
2
|
-
import WebSocket from 'isomorphic-ws';
|
|
3
2
|
import { LiteralStringForUnion, UnknownType } from './types';
|
|
3
|
+
import { randomId } from './utils';
|
|
4
4
|
|
|
5
|
-
export type InsightTypes = 'ws_fatal' | 'ws_success_after_failure';
|
|
5
|
+
export type InsightTypes = 'ws_fatal' | 'ws_success_after_failure' | 'http_beacon_failed';
|
|
6
6
|
export class InsightMetrics {
|
|
7
7
|
connectionStartTimestamp: number | null;
|
|
8
8
|
wsConsecutiveFailures: number;
|
|
9
9
|
wsTotalFailures: number;
|
|
10
|
+
instanceClientId: string;
|
|
10
11
|
|
|
11
12
|
constructor() {
|
|
12
13
|
this.connectionStartTimestamp = null;
|
|
13
14
|
this.wsTotalFailures = 0;
|
|
14
15
|
this.wsConsecutiveFailures = 0;
|
|
16
|
+
this.instanceClientId = randomId();
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
|
|
@@ -21,14 +23,10 @@ export function buildWsFatalInsight<
|
|
|
21
23
|
UserType extends UnknownType = UnknownType
|
|
22
24
|
>(
|
|
23
25
|
connection: StableWSConnection<ChannelType, CommandType, UserType>,
|
|
24
|
-
event:
|
|
26
|
+
event: Record<string, unknown>,
|
|
25
27
|
) {
|
|
26
28
|
return {
|
|
27
|
-
|
|
28
|
-
wasClean: event.wasClean,
|
|
29
|
-
code: event.code,
|
|
30
|
-
reason: event.reason,
|
|
31
|
-
},
|
|
29
|
+
...event,
|
|
32
30
|
...buildWsBaseInsight(connection),
|
|
33
31
|
};
|
|
34
32
|
}
|
|
@@ -56,6 +54,7 @@ function buildWsBaseInsight<
|
|
|
56
54
|
request_id: connection.requestID,
|
|
57
55
|
online: typeof navigator !== 'undefined' ? navigator?.onLine : null,
|
|
58
56
|
user_agent: typeof navigator !== 'undefined' ? navigator?.userAgent : null,
|
|
57
|
+
instance_client_id: connection.insightMetrics.instanceClientId,
|
|
59
58
|
};
|
|
60
59
|
}
|
|
61
60
|
|
package/src/types.ts
CHANGED
|
@@ -2163,11 +2163,13 @@ export type DeleteType = 'soft' | 'hard';
|
|
|
2163
2163
|
implies that all related objects (messages, flags, etc) will be hard-deleted as well.
|
|
2164
2164
|
`conversations` soft|hard will delete any 1to1 channels that the user was a member of.
|
|
2165
2165
|
`messages` soft-hard will delete any messages that the user has sent.
|
|
2166
|
+
`new_channel_owner_id` any channels owned by the hard-deleted user will be transferred to this user ID
|
|
2166
2167
|
*/
|
|
2167
2168
|
export type DeleteUserOptions = {
|
|
2168
2169
|
user: DeleteType;
|
|
2169
2170
|
conversations?: DeleteType;
|
|
2170
2171
|
messages?: DeleteType;
|
|
2172
|
+
new_channel_owner_id?: string;
|
|
2171
2173
|
};
|
|
2172
2174
|
|
|
2173
2175
|
export type SegmentData = {
|
package/src/utils.ts
CHANGED
|
@@ -198,3 +198,16 @@ function getRandomBytes(length: number): Uint8Array {
|
|
|
198
198
|
getRandomValues(bytes);
|
|
199
199
|
return bytes;
|
|
200
200
|
}
|
|
201
|
+
|
|
202
|
+
export function convertErrorToJson(err: unknown) {
|
|
203
|
+
const jsonObj = {} as Record<string, unknown>;
|
|
204
|
+
|
|
205
|
+
if (!err) return jsonObj;
|
|
206
|
+
|
|
207
|
+
Object.getOwnPropertyNames(err).forEach((key) => {
|
|
208
|
+
// @ts-ignore
|
|
209
|
+
jsonObj[key] = err[key];
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
return jsonObj;
|
|
213
|
+
}
|