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.es.js CHANGED
@@ -931,6 +931,16 @@ function getRandomBytes(length) {
931
931
  return bytes;
932
932
  }
933
933
 
934
+ function convertErrorToJson(err) {
935
+ var jsonObj = {};
936
+ if (!err) return jsonObj;
937
+ Object.getOwnPropertyNames(err).forEach(function (key) {
938
+ // @ts-ignore
939
+ jsonObj[key] = err[key];
940
+ });
941
+ return jsonObj;
942
+ }
943
+
934
944
  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; } } }; }
935
945
 
936
946
  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); }
@@ -3425,7 +3435,6 @@ var ClientState = /*#__PURE__*/function () {
3425
3435
  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; }
3426
3436
 
3427
3437
  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; }
3428
-
3429
3438
  var InsightMetrics = function InsightMetrics() {
3430
3439
  _classCallCheck(this, InsightMetrics);
3431
3440
 
@@ -3435,18 +3444,15 @@ var InsightMetrics = function InsightMetrics() {
3435
3444
 
3436
3445
  _defineProperty(this, "wsTotalFailures", void 0);
3437
3446
 
3447
+ _defineProperty(this, "instanceClientId", void 0);
3448
+
3438
3449
  this.connectionStartTimestamp = null;
3439
3450
  this.wsTotalFailures = 0;
3440
3451
  this.wsConsecutiveFailures = 0;
3452
+ this.instanceClientId = randomId();
3441
3453
  };
3442
3454
  function buildWsFatalInsight(connection, event) {
3443
- return _objectSpread$2({
3444
- err: {
3445
- wasClean: event.wasClean,
3446
- code: event.code,
3447
- reason: event.reason
3448
- }
3449
- }, buildWsBaseInsight(connection));
3455
+ return _objectSpread$2(_objectSpread$2({}, event), buildWsBaseInsight(connection));
3450
3456
  }
3451
3457
 
3452
3458
  function buildWsBaseInsight(connection) {
@@ -3469,7 +3475,8 @@ function buildWsBaseInsight(connection) {
3469
3475
  ws_total_failures: connection.insightMetrics.wsTotalFailures,
3470
3476
  request_id: connection.requestID,
3471
3477
  online: typeof navigator !== 'undefined' ? (_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.onLine : null,
3472
- user_agent: typeof navigator !== 'undefined' ? (_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.userAgent : null
3478
+ user_agent: typeof navigator !== 'undefined' ? (_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.userAgent : null,
3479
+ instance_client_id: connection.insightMetrics.instanceClientId
3473
3480
  };
3474
3481
  }
3475
3482
 
@@ -3683,13 +3690,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3683
3690
  });
3684
3691
 
3685
3692
  _defineProperty(this, "onclose", function (wsID, event) {
3686
- if (event.code !== chatCodes.WS_CLOSED_SUCCESS) {
3687
- var _this$postInsights;
3688
-
3689
- _this.insightMetrics.wsConsecutiveFailures++;
3690
- _this.insightMetrics.wsTotalFailures++;
3691
- (_this$postInsights = _this.postInsights) === null || _this$postInsights === void 0 ? void 0 : _this$postInsights.call(_this, 'ws_fatal', buildWsFatalInsight(_this, event));
3692
- }
3693
+ if (_this.wsID !== wsID) return;
3693
3694
 
3694
3695
  _this.logger('info', 'connection:onclose() - onclose callback - ' + event.code, {
3695
3696
  tags: ['connection'],
@@ -3697,8 +3698,6 @@ var StableWSConnection = /*#__PURE__*/function () {
3697
3698
  wsID: wsID
3698
3699
  });
3699
3700
 
3700
- if (_this.wsID !== wsID) return;
3701
-
3702
3701
  if (event.code === chatCodes.WS_CLOSED_SUCCESS) {
3703
3702
  var _this$rejectPromise2;
3704
3703
 
@@ -3706,6 +3705,9 @@ var StableWSConnection = /*#__PURE__*/function () {
3706
3705
  // usually caused by invalid auth details
3707
3706
  var error = new Error("WS connection reject with error ".concat(event.reason));
3708
3707
  error.reason = event.reason;
3708
+ error.code = event.code;
3709
+ error.wasClean = event.wasClean;
3710
+ error.target = event.target;
3709
3711
  (_this$rejectPromise2 = _this.rejectPromise) === null || _this$rejectPromise2 === void 0 ? void 0 : _this$rejectPromise2.call(_this, error);
3710
3712
 
3711
3713
  _this.logger('info', "connection:onclose() - WS connection reject with error ".concat(event.reason), {
@@ -4236,7 +4238,7 @@ var StableWSConnection = /*#__PURE__*/function () {
4236
4238
  key: "_connect",
4237
4239
  value: function () {
4238
4240
  var _connect3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
4239
- var wsURL, response, _this$postInsights2;
4241
+ var wsURL, response, _this$postInsights, insights;
4240
4242
 
4241
4243
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
4242
4244
  while (1) {
@@ -4281,24 +4283,33 @@ var StableWSConnection = /*#__PURE__*/function () {
4281
4283
 
4282
4284
  this.connectionID = response.connection_id;
4283
4285
 
4284
- if (this.insightMetrics.wsConsecutiveFailures > 0) {
4285
- (_this$postInsights2 = this.postInsights) === null || _this$postInsights2 === void 0 ? void 0 : _this$postInsights2.call(this, 'ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
4286
+ if (this.insightMetrics.wsConsecutiveFailures > 0 && this.postInsights) {
4287
+ this.postInsights('ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
4286
4288
  this.insightMetrics.wsConsecutiveFailures = 0;
4287
4289
  }
4288
4290
 
4289
4291
  return _context5.abrupt("return", response);
4290
4292
 
4291
4293
  case 23:
4292
- _context5.next = 29;
4294
+ _context5.next = 30;
4293
4295
  break;
4294
4296
 
4295
4297
  case 25:
4296
4298
  _context5.prev = 25;
4297
4299
  _context5.t0 = _context5["catch"](5);
4298
4300
  this.isConnecting = false;
4301
+
4302
+ if (this.postInsights) {
4303
+ this.insightMetrics.wsConsecutiveFailures++;
4304
+ this.insightMetrics.wsTotalFailures++; // @ts-ignore
4305
+
4306
+ insights = buildWsFatalInsight(this, convertErrorToJson(_context5.t0));
4307
+ (_this$postInsights = this.postInsights) === null || _this$postInsights === void 0 ? void 0 : _this$postInsights.call(this, 'ws_fatal', insights);
4308
+ }
4309
+
4299
4310
  throw _context5.t0;
4300
4311
 
4301
- case 29:
4312
+ case 30:
4302
4313
  case "end":
4303
4314
  return _context5.stop();
4304
4315
  }
@@ -5537,7 +5548,7 @@ var StreamChat = /*#__PURE__*/function () {
5537
5548
 
5538
5549
  _context6.prev = 3;
5539
5550
  _context6.next = 6;
5540
- return _this.axiosInstance.post("https://insights.stream-io-api.com/insights/".concat(insightType), insights);
5551
+ return _this.axiosInstance.post("https://chat-insights.getstream.io/insights/".concat(insightType), insights);
5541
5552
 
5542
5553
  case 6:
5543
5554
  _context6.next = 14;
@@ -8349,7 +8360,7 @@ var StreamChat = /*#__PURE__*/function () {
8349
8360
  }, {
8350
8361
  key: "getUserAgent",
8351
8362
  value: function getUserAgent() {
8352
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.0");
8363
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.3-dev.1");
8353
8364
  }
8354
8365
  }, {
8355
8366
  key: "setUserAgent",
@@ -9426,5 +9437,5 @@ var BuiltinPermissions = {
9426
9437
  UseFrozenChannel: 'Send messages and reactions to frozen channels'
9427
9438
  };
9428
9439
 
9429
- 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 };
9440
+ 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 };
9430
9441
  //# sourceMappingURL=index.es.js.map