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/browser.js CHANGED
@@ -950,6 +950,16 @@ function getRandomBytes(length) {
950
950
  return bytes;
951
951
  }
952
952
 
953
+ function convertErrorToJson(err) {
954
+ var jsonObj = {};
955
+ if (!err) return jsonObj;
956
+ Object.getOwnPropertyNames(err).forEach(function (key) {
957
+ // @ts-ignore
958
+ jsonObj[key] = err[key];
959
+ });
960
+ return jsonObj;
961
+ }
962
+
953
963
  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; } } }; }
954
964
 
955
965
  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); }
@@ -3444,7 +3454,6 @@ var ClientState = /*#__PURE__*/function () {
3444
3454
  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; }
3445
3455
 
3446
3456
  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; }
3447
-
3448
3457
  var InsightMetrics = function InsightMetrics() {
3449
3458
  _classCallCheck__default['default'](this, InsightMetrics);
3450
3459
 
@@ -3454,18 +3463,15 @@ var InsightMetrics = function InsightMetrics() {
3454
3463
 
3455
3464
  _defineProperty__default['default'](this, "wsTotalFailures", void 0);
3456
3465
 
3466
+ _defineProperty__default['default'](this, "instanceClientId", void 0);
3467
+
3457
3468
  this.connectionStartTimestamp = null;
3458
3469
  this.wsTotalFailures = 0;
3459
3470
  this.wsConsecutiveFailures = 0;
3471
+ this.instanceClientId = randomId();
3460
3472
  };
3461
3473
  function buildWsFatalInsight(connection, event) {
3462
- return _objectSpread$2({
3463
- err: {
3464
- wasClean: event.wasClean,
3465
- code: event.code,
3466
- reason: event.reason
3467
- }
3468
- }, buildWsBaseInsight(connection));
3474
+ return _objectSpread$2(_objectSpread$2({}, event), buildWsBaseInsight(connection));
3469
3475
  }
3470
3476
 
3471
3477
  function buildWsBaseInsight(connection) {
@@ -3488,7 +3494,8 @@ function buildWsBaseInsight(connection) {
3488
3494
  ws_total_failures: connection.insightMetrics.wsTotalFailures,
3489
3495
  request_id: connection.requestID,
3490
3496
  online: typeof navigator !== 'undefined' ? (_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.onLine : null,
3491
- user_agent: typeof navigator !== 'undefined' ? (_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.userAgent : null
3497
+ user_agent: typeof navigator !== 'undefined' ? (_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.userAgent : null,
3498
+ instance_client_id: connection.insightMetrics.instanceClientId
3492
3499
  };
3493
3500
  }
3494
3501
 
@@ -3702,13 +3709,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3702
3709
  });
3703
3710
 
3704
3711
  _defineProperty__default['default'](this, "onclose", function (wsID, event) {
3705
- if (event.code !== chatCodes.WS_CLOSED_SUCCESS) {
3706
- var _this$postInsights;
3707
-
3708
- _this.insightMetrics.wsConsecutiveFailures++;
3709
- _this.insightMetrics.wsTotalFailures++;
3710
- (_this$postInsights = _this.postInsights) === null || _this$postInsights === void 0 ? void 0 : _this$postInsights.call(_this, 'ws_fatal', buildWsFatalInsight(_this, event));
3711
- }
3712
+ if (_this.wsID !== wsID) return;
3712
3713
 
3713
3714
  _this.logger('info', 'connection:onclose() - onclose callback - ' + event.code, {
3714
3715
  tags: ['connection'],
@@ -3716,8 +3717,6 @@ var StableWSConnection = /*#__PURE__*/function () {
3716
3717
  wsID: wsID
3717
3718
  });
3718
3719
 
3719
- if (_this.wsID !== wsID) return;
3720
-
3721
3720
  if (event.code === chatCodes.WS_CLOSED_SUCCESS) {
3722
3721
  var _this$rejectPromise2;
3723
3722
 
@@ -3725,6 +3724,9 @@ var StableWSConnection = /*#__PURE__*/function () {
3725
3724
  // usually caused by invalid auth details
3726
3725
  var error = new Error("WS connection reject with error ".concat(event.reason));
3727
3726
  error.reason = event.reason;
3727
+ error.code = event.code;
3728
+ error.wasClean = event.wasClean;
3729
+ error.target = event.target;
3728
3730
  (_this$rejectPromise2 = _this.rejectPromise) === null || _this$rejectPromise2 === void 0 ? void 0 : _this$rejectPromise2.call(_this, error);
3729
3731
 
3730
3732
  _this.logger('info', "connection:onclose() - WS connection reject with error ".concat(event.reason), {
@@ -4255,7 +4257,7 @@ var StableWSConnection = /*#__PURE__*/function () {
4255
4257
  key: "_connect",
4256
4258
  value: function () {
4257
4259
  var _connect3 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5() {
4258
- var wsURL, response, _this$postInsights2;
4260
+ var wsURL, response, _this$postInsights, insights;
4259
4261
 
4260
4262
  return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
4261
4263
  while (1) {
@@ -4300,24 +4302,33 @@ var StableWSConnection = /*#__PURE__*/function () {
4300
4302
 
4301
4303
  this.connectionID = response.connection_id;
4302
4304
 
4303
- if (this.insightMetrics.wsConsecutiveFailures > 0) {
4304
- (_this$postInsights2 = this.postInsights) === null || _this$postInsights2 === void 0 ? void 0 : _this$postInsights2.call(this, 'ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
4305
+ if (this.insightMetrics.wsConsecutiveFailures > 0 && this.postInsights) {
4306
+ this.postInsights('ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
4305
4307
  this.insightMetrics.wsConsecutiveFailures = 0;
4306
4308
  }
4307
4309
 
4308
4310
  return _context5.abrupt("return", response);
4309
4311
 
4310
4312
  case 23:
4311
- _context5.next = 29;
4313
+ _context5.next = 30;
4312
4314
  break;
4313
4315
 
4314
4316
  case 25:
4315
4317
  _context5.prev = 25;
4316
4318
  _context5.t0 = _context5["catch"](5);
4317
4319
  this.isConnecting = false;
4320
+
4321
+ if (this.postInsights) {
4322
+ this.insightMetrics.wsConsecutiveFailures++;
4323
+ this.insightMetrics.wsTotalFailures++; // @ts-ignore
4324
+
4325
+ insights = buildWsFatalInsight(this, convertErrorToJson(_context5.t0));
4326
+ (_this$postInsights = this.postInsights) === null || _this$postInsights === void 0 ? void 0 : _this$postInsights.call(this, 'ws_fatal', insights);
4327
+ }
4328
+
4318
4329
  throw _context5.t0;
4319
4330
 
4320
- case 29:
4331
+ case 30:
4321
4332
  case "end":
4322
4333
  return _context5.stop();
4323
4334
  }
@@ -5554,7 +5565,7 @@ var StreamChat = /*#__PURE__*/function () {
5554
5565
 
5555
5566
  _context6.prev = 3;
5556
5567
  _context6.next = 6;
5557
- return _this.axiosInstance.post("https://insights.stream-io-api.com/insights/".concat(insightType), insights);
5568
+ return _this.axiosInstance.post("https://chat-insights.getstream.io/insights/".concat(insightType), insights);
5558
5569
 
5559
5570
  case 6:
5560
5571
  _context6.next = 14;
@@ -8366,7 +8377,7 @@ var StreamChat = /*#__PURE__*/function () {
8366
8377
  }, {
8367
8378
  key: "getUserAgent",
8368
8379
  value: function getUserAgent() {
8369
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.0");
8380
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.3-dev.1");
8370
8381
  }
8371
8382
  }, {
8372
8383
  key: "setUserAgent",
@@ -9457,6 +9468,7 @@ exports.Deny = Deny;
9457
9468
  exports.DenyAll = DenyAll;
9458
9469
  exports.DevToken = DevToken;
9459
9470
  exports.EVENT_MAP = EVENT_MAP;
9471
+ exports.InsightMetrics = InsightMetrics;
9460
9472
  exports.JWTServerToken = JWTServerToken;
9461
9473
  exports.JWTUserToken = JWTUserToken;
9462
9474
  exports.MaxPriority = MaxPriority;
@@ -9466,6 +9478,8 @@ exports.StableWSConnection = StableWSConnection;
9466
9478
  exports.StreamChat = StreamChat;
9467
9479
  exports.TokenManager = TokenManager;
9468
9480
  exports.UserFromToken = UserFromToken;
9481
+ exports.buildWsFatalInsight = buildWsFatalInsight;
9482
+ exports.buildWsSuccessAfterFailureInsight = buildWsSuccessAfterFailureInsight;
9469
9483
  exports.chatCodes = chatCodes;
9470
9484
  exports.decodeBase64 = decodeBase64;
9471
9485
  exports.encodeBase64 = encodeBase64;