stream-chat 4.4.0-insights.0 → 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); }
@@ -3424,7 +3434,6 @@ var ClientState = /*#__PURE__*/function () {
3424
3434
  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; }
3425
3435
 
3426
3436
  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(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; }
3427
-
3428
3437
  var InsightMetrics = function InsightMetrics() {
3429
3438
  _classCallCheck(this, InsightMetrics);
3430
3439
 
@@ -3434,18 +3443,15 @@ var InsightMetrics = function InsightMetrics() {
3434
3443
 
3435
3444
  _defineProperty(this, "wsTotalFailures", void 0);
3436
3445
 
3446
+ _defineProperty(this, "instanceClientId", void 0);
3447
+
3437
3448
  this.connectionStartTimestamp = null;
3438
3449
  this.wsTotalFailures = 0;
3439
3450
  this.wsConsecutiveFailures = 0;
3451
+ this.instanceClientId = randomId();
3440
3452
  };
3441
3453
  function buildWsFatalInsight(connection, event) {
3442
- return _objectSpread$2({
3443
- err: {
3444
- wasClean: event.wasClean,
3445
- code: event.code,
3446
- reason: event.reason
3447
- }
3448
- }, buildWsBaseInsight(connection));
3454
+ return _objectSpread$2(_objectSpread$2({}, event), buildWsBaseInsight(connection));
3449
3455
  }
3450
3456
 
3451
3457
  function buildWsBaseInsight(connection) {
@@ -3468,7 +3474,8 @@ function buildWsBaseInsight(connection) {
3468
3474
  ws_total_failures: connection.insightMetrics.wsTotalFailures,
3469
3475
  request_id: connection.requestID,
3470
3476
  online: typeof navigator !== 'undefined' ? (_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.onLine : null,
3471
- user_agent: typeof navigator !== 'undefined' ? (_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.userAgent : null
3477
+ user_agent: typeof navigator !== 'undefined' ? (_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.userAgent : null,
3478
+ instance_client_id: connection.insightMetrics.instanceClientId
3472
3479
  };
3473
3480
  }
3474
3481
 
@@ -3682,13 +3689,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3682
3689
  });
3683
3690
 
3684
3691
  _defineProperty(this, "onclose", function (wsID, event) {
3685
- if (event.code !== chatCodes.WS_CLOSED_SUCCESS) {
3686
- var _this$postInsights;
3687
-
3688
- _this.insightMetrics.wsConsecutiveFailures++;
3689
- _this.insightMetrics.wsTotalFailures++;
3690
- (_this$postInsights = _this.postInsights) === null || _this$postInsights === void 0 ? void 0 : _this$postInsights.call(_this, 'ws_fatal', buildWsFatalInsight(_this, event));
3691
- }
3692
+ if (_this.wsID !== wsID) return;
3692
3693
 
3693
3694
  _this.logger('info', 'connection:onclose() - onclose callback - ' + event.code, {
3694
3695
  tags: ['connection'],
@@ -3696,8 +3697,6 @@ var StableWSConnection = /*#__PURE__*/function () {
3696
3697
  wsID: wsID
3697
3698
  });
3698
3699
 
3699
- if (_this.wsID !== wsID) return;
3700
-
3701
3700
  if (event.code === chatCodes.WS_CLOSED_SUCCESS) {
3702
3701
  var _this$rejectPromise2;
3703
3702
 
@@ -3705,6 +3704,9 @@ var StableWSConnection = /*#__PURE__*/function () {
3705
3704
  // usually caused by invalid auth details
3706
3705
  var error = new Error("WS connection reject with error ".concat(event.reason));
3707
3706
  error.reason = event.reason;
3707
+ error.code = event.code;
3708
+ error.wasClean = event.wasClean;
3709
+ error.target = event.target;
3708
3710
  (_this$rejectPromise2 = _this.rejectPromise) === null || _this$rejectPromise2 === void 0 ? void 0 : _this$rejectPromise2.call(_this, error);
3709
3711
 
3710
3712
  _this.logger('info', "connection:onclose() - WS connection reject with error ".concat(event.reason), {
@@ -4235,7 +4237,7 @@ var StableWSConnection = /*#__PURE__*/function () {
4235
4237
  key: "_connect",
4236
4238
  value: function () {
4237
4239
  var _connect3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
4238
- var wsURL, response, _this$postInsights2;
4240
+ var wsURL, response, _this$postInsights, insights;
4239
4241
 
4240
4242
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
4241
4243
  while (1) {
@@ -4280,24 +4282,33 @@ var StableWSConnection = /*#__PURE__*/function () {
4280
4282
 
4281
4283
  this.connectionID = response.connection_id;
4282
4284
 
4283
- if (this.insightMetrics.wsConsecutiveFailures > 0) {
4284
- (_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));
4285
4287
  this.insightMetrics.wsConsecutiveFailures = 0;
4286
4288
  }
4287
4289
 
4288
4290
  return _context5.abrupt("return", response);
4289
4291
 
4290
4292
  case 23:
4291
- _context5.next = 29;
4293
+ _context5.next = 30;
4292
4294
  break;
4293
4295
 
4294
4296
  case 25:
4295
4297
  _context5.prev = 25;
4296
4298
  _context5.t0 = _context5["catch"](5);
4297
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
+
4298
4309
  throw _context5.t0;
4299
4310
 
4300
- case 29:
4311
+ case 30:
4301
4312
  case "end":
4302
4313
  return _context5.stop();
4303
4314
  }
@@ -8346,7 +8357,7 @@ var StreamChat = /*#__PURE__*/function () {
8346
8357
  }, {
8347
8358
  key: "getUserAgent",
8348
8359
  value: function getUserAgent() {
8349
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.0-insights.0");
8360
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.3-dev.0");
8350
8361
  }
8351
8362
  }, {
8352
8363
  key: "setUserAgent",
@@ -9423,5 +9434,5 @@ var BuiltinPermissions = {
9423
9434
  UseFrozenChannel: 'Send messages and reactions to frozen channels'
9424
9435
  };
9425
9436
 
9426
- export { Allow, AllowAll, AnyResource, AnyRole, BuiltinPermissions, BuiltinRoles, Channel, ChannelState, CheckSignature, ClientState, Deny, DenyAll, DevToken, EVENT_MAP, JWTServerToken, JWTUserToken, MaxPriority, MinPriority, Permission, StableWSConnection, StreamChat, TokenManager, UserFromToken, chatCodes, decodeBase64, encodeBase64, isOwnUser, isValidEventType, logChatPromiseExecution };
9437
+ export { Allow, AllowAll, AnyResource, AnyRole, BuiltinPermissions, BuiltinRoles, Channel, ChannelState, CheckSignature, ClientState, Deny, DenyAll, DevToken, EVENT_MAP, InsightMetrics, JWTServerToken, JWTUserToken, MaxPriority, MinPriority, Permission, StableWSConnection, StreamChat, TokenManager, UserFromToken, buildWsFatalInsight, buildWsSuccessAfterFailureInsight, chatCodes, decodeBase64, encodeBase64, isOwnUser, isValidEventType, logChatPromiseExecution };
9427
9438
  //# sourceMappingURL=browser.es.js.map