stream-chat 4.4.2 → 4.4.3-dev.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.
@@ -930,6 +930,16 @@ function getRandomBytes(length) {
930
930
  return bytes;
931
931
  }
932
932
 
933
+ function convertErrorToJson(err) {
934
+ var jsonObj = {};
935
+ if (!err) return jsonObj;
936
+ Object.getOwnPropertyNames(err).forEach(function (key) {
937
+ // @ts-ignore
938
+ jsonObj[key] = err[key];
939
+ });
940
+ return jsonObj;
941
+ }
942
+
933
943
  function _createForOfIteratorHelper$2(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$2(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
934
944
 
935
945
  function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$2(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen); }
@@ -3441,13 +3451,7 @@ var InsightMetrics = function InsightMetrics() {
3441
3451
  this.instanceClientId = randomId();
3442
3452
  };
3443
3453
  function buildWsFatalInsight(connection, event) {
3444
- return _objectSpread$2({
3445
- err: {
3446
- wasClean: event.wasClean,
3447
- code: event.code,
3448
- reason: event.reason
3449
- }
3450
- }, buildWsBaseInsight(connection));
3454
+ return _objectSpread$2(_objectSpread$2({}, event), buildWsBaseInsight(connection));
3451
3455
  }
3452
3456
 
3453
3457
  function buildWsBaseInsight(connection) {
@@ -3685,13 +3689,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3685
3689
  });
3686
3690
 
3687
3691
  _defineProperty(this, "onclose", function (wsID, event) {
3688
- if (event.code !== chatCodes.WS_CLOSED_SUCCESS) {
3689
- var _this$postInsights;
3690
-
3691
- _this.insightMetrics.wsConsecutiveFailures++;
3692
- _this.insightMetrics.wsTotalFailures++;
3693
- (_this$postInsights = _this.postInsights) === null || _this$postInsights === void 0 ? void 0 : _this$postInsights.call(_this, 'ws_fatal', buildWsFatalInsight(_this, event));
3694
- }
3692
+ if (_this.wsID !== wsID) return;
3695
3693
 
3696
3694
  _this.logger('info', 'connection:onclose() - onclose callback - ' + event.code, {
3697
3695
  tags: ['connection'],
@@ -3699,8 +3697,6 @@ var StableWSConnection = /*#__PURE__*/function () {
3699
3697
  wsID: wsID
3700
3698
  });
3701
3699
 
3702
- if (_this.wsID !== wsID) return;
3703
-
3704
3700
  if (event.code === chatCodes.WS_CLOSED_SUCCESS) {
3705
3701
  var _this$rejectPromise2;
3706
3702
 
@@ -3708,6 +3704,9 @@ var StableWSConnection = /*#__PURE__*/function () {
3708
3704
  // usually caused by invalid auth details
3709
3705
  var error = new Error("WS connection reject with error ".concat(event.reason));
3710
3706
  error.reason = event.reason;
3707
+ error.code = event.code;
3708
+ error.wasClean = event.wasClean;
3709
+ error.target = event.target;
3711
3710
  (_this$rejectPromise2 = _this.rejectPromise) === null || _this$rejectPromise2 === void 0 ? void 0 : _this$rejectPromise2.call(_this, error);
3712
3711
 
3713
3712
  _this.logger('info', "connection:onclose() - WS connection reject with error ".concat(event.reason), {
@@ -4238,7 +4237,7 @@ var StableWSConnection = /*#__PURE__*/function () {
4238
4237
  key: "_connect",
4239
4238
  value: function () {
4240
4239
  var _connect3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
4241
- var wsURL, response, _this$postInsights2;
4240
+ var wsURL, response, _this$postInsights, insights;
4242
4241
 
4243
4242
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
4244
4243
  while (1) {
@@ -4283,24 +4282,33 @@ var StableWSConnection = /*#__PURE__*/function () {
4283
4282
 
4284
4283
  this.connectionID = response.connection_id;
4285
4284
 
4286
- if (this.insightMetrics.wsConsecutiveFailures > 0) {
4287
- (_this$postInsights2 = this.postInsights) === null || _this$postInsights2 === void 0 ? void 0 : _this$postInsights2.call(this, 'ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
4285
+ if (this.insightMetrics.wsConsecutiveFailures > 0 && this.postInsights) {
4286
+ this.postInsights('ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
4288
4287
  this.insightMetrics.wsConsecutiveFailures = 0;
4289
4288
  }
4290
4289
 
4291
4290
  return _context5.abrupt("return", response);
4292
4291
 
4293
4292
  case 23:
4294
- _context5.next = 29;
4293
+ _context5.next = 30;
4295
4294
  break;
4296
4295
 
4297
4296
  case 25:
4298
4297
  _context5.prev = 25;
4299
4298
  _context5.t0 = _context5["catch"](5);
4300
4299
  this.isConnecting = false;
4300
+
4301
+ if (this.postInsights) {
4302
+ this.insightMetrics.wsConsecutiveFailures++;
4303
+ this.insightMetrics.wsTotalFailures++; // @ts-ignore
4304
+
4305
+ insights = buildWsFatalInsight(this, convertErrorToJson(_context5.t0));
4306
+ (_this$postInsights = this.postInsights) === null || _this$postInsights === void 0 ? void 0 : _this$postInsights.call(this, 'ws_fatal', insights);
4307
+ }
4308
+
4301
4309
  throw _context5.t0;
4302
4310
 
4303
- case 29:
4311
+ case 30:
4304
4312
  case "end":
4305
4313
  return _context5.stop();
4306
4314
  }
@@ -8349,7 +8357,7 @@ var StreamChat = /*#__PURE__*/function () {
8349
8357
  }, {
8350
8358
  key: "getUserAgent",
8351
8359
  value: function getUserAgent() {
8352
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.2");
8360
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.3-dev.0");
8353
8361
  }
8354
8362
  }, {
8355
8363
  key: "setUserAgent",