stream-chat 4.4.0 → 4.4.3-dev.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/index.js CHANGED
@@ -954,6 +954,16 @@ function getRandomBytes(length) {
954
954
  return bytes;
955
955
  }
956
956
 
957
+ function convertErrorToJson(err) {
958
+ var jsonObj = {};
959
+ if (!err) return jsonObj;
960
+ Object.getOwnPropertyNames(err).forEach(function (key) {
961
+ // @ts-ignore
962
+ jsonObj[key] = err[key];
963
+ });
964
+ return jsonObj;
965
+ }
966
+
957
967
  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; } } }; }
958
968
 
959
969
  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); }
@@ -3448,7 +3458,6 @@ var ClientState = /*#__PURE__*/function () {
3448
3458
  function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
3449
3459
 
3450
3460
  function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3451
-
3452
3461
  var InsightMetrics = function InsightMetrics() {
3453
3462
  _classCallCheck__default['default'](this, InsightMetrics);
3454
3463
 
@@ -3458,18 +3467,15 @@ var InsightMetrics = function InsightMetrics() {
3458
3467
 
3459
3468
  _defineProperty__default['default'](this, "wsTotalFailures", void 0);
3460
3469
 
3470
+ _defineProperty__default['default'](this, "instanceClientId", void 0);
3471
+
3461
3472
  this.connectionStartTimestamp = null;
3462
3473
  this.wsTotalFailures = 0;
3463
3474
  this.wsConsecutiveFailures = 0;
3475
+ this.instanceClientId = randomId();
3464
3476
  };
3465
3477
  function buildWsFatalInsight(connection, event) {
3466
- return _objectSpread$2({
3467
- err: {
3468
- wasClean: event.wasClean,
3469
- code: event.code,
3470
- reason: event.reason
3471
- }
3472
- }, buildWsBaseInsight(connection));
3478
+ return _objectSpread$2(_objectSpread$2({}, event), buildWsBaseInsight(connection));
3473
3479
  }
3474
3480
 
3475
3481
  function buildWsBaseInsight(connection) {
@@ -3492,7 +3498,8 @@ function buildWsBaseInsight(connection) {
3492
3498
  ws_total_failures: connection.insightMetrics.wsTotalFailures,
3493
3499
  request_id: connection.requestID,
3494
3500
  online: typeof navigator !== 'undefined' ? (_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.onLine : null,
3495
- user_agent: typeof navigator !== 'undefined' ? (_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.userAgent : null
3501
+ user_agent: typeof navigator !== 'undefined' ? (_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.userAgent : null,
3502
+ instance_client_id: connection.insightMetrics.instanceClientId
3496
3503
  };
3497
3504
  }
3498
3505
 
@@ -3706,13 +3713,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3706
3713
  });
3707
3714
 
3708
3715
  _defineProperty__default['default'](this, "onclose", function (wsID, event) {
3709
- if (event.code !== chatCodes.WS_CLOSED_SUCCESS) {
3710
- var _this$postInsights;
3711
-
3712
- _this.insightMetrics.wsConsecutiveFailures++;
3713
- _this.insightMetrics.wsTotalFailures++;
3714
- (_this$postInsights = _this.postInsights) === null || _this$postInsights === void 0 ? void 0 : _this$postInsights.call(_this, 'ws_fatal', buildWsFatalInsight(_this, event));
3715
- }
3716
+ if (_this.wsID !== wsID) return;
3716
3717
 
3717
3718
  _this.logger('info', 'connection:onclose() - onclose callback - ' + event.code, {
3718
3719
  tags: ['connection'],
@@ -3720,8 +3721,6 @@ var StableWSConnection = /*#__PURE__*/function () {
3720
3721
  wsID: wsID
3721
3722
  });
3722
3723
 
3723
- if (_this.wsID !== wsID) return;
3724
-
3725
3724
  if (event.code === chatCodes.WS_CLOSED_SUCCESS) {
3726
3725
  var _this$rejectPromise2;
3727
3726
 
@@ -3729,6 +3728,9 @@ var StableWSConnection = /*#__PURE__*/function () {
3729
3728
  // usually caused by invalid auth details
3730
3729
  var error = new Error("WS connection reject with error ".concat(event.reason));
3731
3730
  error.reason = event.reason;
3731
+ error.code = event.code;
3732
+ error.wasClean = event.wasClean;
3733
+ error.target = event.target;
3732
3734
  (_this$rejectPromise2 = _this.rejectPromise) === null || _this$rejectPromise2 === void 0 ? void 0 : _this$rejectPromise2.call(_this, error);
3733
3735
 
3734
3736
  _this.logger('info', "connection:onclose() - WS connection reject with error ".concat(event.reason), {
@@ -4259,7 +4261,7 @@ var StableWSConnection = /*#__PURE__*/function () {
4259
4261
  key: "_connect",
4260
4262
  value: function () {
4261
4263
  var _connect3 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5() {
4262
- var wsURL, response, _this$postInsights2;
4264
+ var wsURL, response, _this$postInsights, insights;
4263
4265
 
4264
4266
  return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
4265
4267
  while (1) {
@@ -4304,24 +4306,33 @@ var StableWSConnection = /*#__PURE__*/function () {
4304
4306
 
4305
4307
  this.connectionID = response.connection_id;
4306
4308
 
4307
- if (this.insightMetrics.wsConsecutiveFailures > 0) {
4308
- (_this$postInsights2 = this.postInsights) === null || _this$postInsights2 === void 0 ? void 0 : _this$postInsights2.call(this, 'ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
4309
+ if (this.insightMetrics.wsConsecutiveFailures > 0 && this.postInsights) {
4310
+ this.postInsights('ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
4309
4311
  this.insightMetrics.wsConsecutiveFailures = 0;
4310
4312
  }
4311
4313
 
4312
4314
  return _context5.abrupt("return", response);
4313
4315
 
4314
4316
  case 23:
4315
- _context5.next = 29;
4317
+ _context5.next = 30;
4316
4318
  break;
4317
4319
 
4318
4320
  case 25:
4319
4321
  _context5.prev = 25;
4320
4322
  _context5.t0 = _context5["catch"](5);
4321
4323
  this.isConnecting = false;
4324
+
4325
+ if (this.postInsights) {
4326
+ this.insightMetrics.wsConsecutiveFailures++;
4327
+ this.insightMetrics.wsTotalFailures++; // @ts-ignore
4328
+
4329
+ insights = buildWsFatalInsight(this, convertErrorToJson(_context5.t0));
4330
+ (_this$postInsights = this.postInsights) === null || _this$postInsights === void 0 ? void 0 : _this$postInsights.call(this, 'ws_fatal', insights);
4331
+ }
4332
+
4322
4333
  throw _context5.t0;
4323
4334
 
4324
- case 29:
4335
+ case 30:
4325
4336
  case "end":
4326
4337
  return _context5.stop();
4327
4338
  }
@@ -5560,7 +5571,7 @@ var StreamChat = /*#__PURE__*/function () {
5560
5571
 
5561
5572
  _context6.prev = 3;
5562
5573
  _context6.next = 6;
5563
- return _this.axiosInstance.post("https://insights.stream-io-api.com/insights/".concat(insightType), insights);
5574
+ return _this.axiosInstance.post("https://chat-insights.getstream.io/insights/".concat(insightType), insights);
5564
5575
 
5565
5576
  case 6:
5566
5577
  _context6.next = 14;
@@ -8372,7 +8383,7 @@ var StreamChat = /*#__PURE__*/function () {
8372
8383
  }, {
8373
8384
  key: "getUserAgent",
8374
8385
  value: function getUserAgent() {
8375
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.0");
8386
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.3-dev.1");
8376
8387
  }
8377
8388
  }, {
8378
8389
  key: "setUserAgent",
@@ -9463,6 +9474,7 @@ exports.Deny = Deny;
9463
9474
  exports.DenyAll = DenyAll;
9464
9475
  exports.DevToken = DevToken;
9465
9476
  exports.EVENT_MAP = EVENT_MAP;
9477
+ exports.InsightMetrics = InsightMetrics;
9466
9478
  exports.JWTServerToken = JWTServerToken;
9467
9479
  exports.JWTUserToken = JWTUserToken;
9468
9480
  exports.MaxPriority = MaxPriority;
@@ -9472,6 +9484,8 @@ exports.StableWSConnection = StableWSConnection;
9472
9484
  exports.StreamChat = StreamChat;
9473
9485
  exports.TokenManager = TokenManager;
9474
9486
  exports.UserFromToken = UserFromToken;
9487
+ exports.buildWsFatalInsight = buildWsFatalInsight;
9488
+ exports.buildWsSuccessAfterFailureInsight = buildWsSuccessAfterFailureInsight;
9475
9489
  exports.chatCodes = chatCodes;
9476
9490
  exports.decodeBase64 = decodeBase64;
9477
9491
  exports.encodeBase64 = encodeBase64;