stream-chat 4.4.2 → 4.4.3-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/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
- request_id: reqID,
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 (event.code !== chatCodes.WS_CLOSED_SUCCESS) {
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 & { reason?: string };
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,9 +1,8 @@
1
1
  import { StableWSConnection } from './connection';
2
- import WebSocket from 'isomorphic-ws';
3
2
  import { LiteralStringForUnion, UnknownType } from './types';
4
3
  import { randomId } from './utils';
5
4
 
6
- export type InsightTypes = 'ws_fatal' | 'ws_success_after_failure';
5
+ export type InsightTypes = 'ws_fatal' | 'ws_success_after_failure' | 'http_hi_failed';
7
6
  export class InsightMetrics {
8
7
  connectionStartTimestamp: number | null;
9
8
  wsConsecutiveFailures: number;
@@ -24,14 +23,10 @@ export function buildWsFatalInsight<
24
23
  UserType extends UnknownType = UnknownType
25
24
  >(
26
25
  connection: StableWSConnection<ChannelType, CommandType, UserType>,
27
- event: WebSocket.CloseEvent,
26
+ event: Record<string, unknown>,
28
27
  ) {
29
28
  return {
30
- err: {
31
- wasClean: event.wasClean,
32
- code: event.code,
33
- reason: event.reason,
34
- },
29
+ ...event,
35
30
  ...buildWsBaseInsight(connection),
36
31
  };
37
32
  }
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
+ }