stream-chat 6.4.0 → 6.6.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.
package/dist/browser.js CHANGED
@@ -16,6 +16,11 @@ var axios = require('axios');
16
16
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
17
17
  var FormData = require('form-data');
18
18
  var WebSocket = require('isomorphic-ws');
19
+ var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
20
+ var _inherits = require('@babel/runtime/helpers/inherits');
21
+ var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn');
22
+ var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
23
+ var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
19
24
 
20
25
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
26
 
@@ -32,6 +37,11 @@ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
32
37
  var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
33
38
  var FormData__default = /*#__PURE__*/_interopDefaultLegacy(FormData);
34
39
  var WebSocket__default = /*#__PURE__*/_interopDefaultLegacy(WebSocket);
40
+ var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
41
+ var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
42
+ var _possibleConstructorReturn__default = /*#__PURE__*/_interopDefaultLegacy(_possibleConstructorReturn);
43
+ var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeOf);
44
+ var _wrapNativeSuper__default = /*#__PURE__*/_interopDefaultLegacy(_wrapNativeSuper);
35
45
 
36
46
  function isString$1(arrayOrString) {
37
47
  return typeof arrayOrString === 'string';
@@ -1085,6 +1095,7 @@ var EVENT_MAP = {
1085
1095
  'user.deleted': true,
1086
1096
  'user.presence.changed': true,
1087
1097
  'user.unbanned': true,
1098
+ 'user.unread_message_reminder': true,
1088
1099
  'user.updated': true,
1089
1100
  'user.watching.start': true,
1090
1101
  'user.watching.stop': true,
@@ -5393,6 +5404,9 @@ function isWSFailure(err) {
5393
5404
  return false;
5394
5405
  }
5395
5406
  }
5407
+ function isErrorResponse(res) {
5408
+ return !res.status || res.status < 200 || 300 <= res.status;
5409
+ }
5396
5410
 
5397
5411
  function ownKeys$1(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; }
5398
5412
 
@@ -5770,6 +5784,82 @@ var WSConnectionFallback = /*#__PURE__*/function () {
5770
5784
  return WSConnectionFallback;
5771
5785
  }();
5772
5786
 
5787
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
5788
+
5789
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
5790
+
5791
+ /**
5792
+ * Utility Types
5793
+ */
5794
+
5795
+ /* Unknown Record */
5796
+ //alias to avoid breaking change
5797
+
5798
+ /**
5799
+ * Response Types
5800
+ */
5801
+
5802
+ /**
5803
+ * Option Types
5804
+ */
5805
+ // TODO: rename to UpdateChannelOptions in the next major update and use it in channel._update and/or channel.update
5806
+
5807
+ /** @deprecated use MarkChannelsReadOptions instead */
5808
+ // TODO: rename to UpdateChannelTypeOptions in the next major update
5809
+
5810
+ /**
5811
+ * Event Types
5812
+ */
5813
+
5814
+ /**
5815
+ * Filter Types
5816
+ */
5817
+
5818
+ /**
5819
+ * Sort Types
5820
+ */
5821
+
5822
+ /**
5823
+ * Base Types
5824
+ */
5825
+
5826
+ /*
5827
+ DeleteUserOptions specifies a collection of one or more `user_ids` to be deleted.
5828
+
5829
+ `user` soft|hard determines if the user needs to be hard- or soft-deleted, where hard-delete
5830
+ implies that all related objects (messages, flags, etc) will be hard-deleted as well.
5831
+ `conversations` soft|hard will delete any 1to1 channels that the user was a member of.
5832
+ `messages` soft-hard will delete any messages that the user has sent.
5833
+ `new_channel_owner_id` any channels owned by the hard-deleted user will be transferred to this user ID
5834
+ */
5835
+ var ErrorFromResponse = /*#__PURE__*/function (_Error) {
5836
+ _inherits__default['default'](ErrorFromResponse, _Error);
5837
+
5838
+ var _super = _createSuper(ErrorFromResponse);
5839
+
5840
+ function ErrorFromResponse() {
5841
+ var _this;
5842
+
5843
+ _classCallCheck__default['default'](this, ErrorFromResponse);
5844
+
5845
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5846
+ args[_key] = arguments[_key];
5847
+ }
5848
+
5849
+ _this = _super.call.apply(_super, [this].concat(args));
5850
+
5851
+ _defineProperty__default['default'](_assertThisInitialized__default['default'](_this), "code", void 0);
5852
+
5853
+ _defineProperty__default['default'](_assertThisInitialized__default['default'](_this), "response", void 0);
5854
+
5855
+ _defineProperty__default['default'](_assertThisInitialized__default['default'](_this), "status", void 0);
5856
+
5857
+ return _this;
5858
+ }
5859
+
5860
+ return ErrorFromResponse;
5861
+ }( /*#__PURE__*/_wrapNativeSuper__default['default'](Error));
5862
+
5773
5863
  var _excluded = ["created_at", "updated_at", "last_active", "online"];
5774
5864
 
5775
5865
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(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 = it.call(o); }, 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; } } }; }
@@ -5982,7 +6072,7 @@ var StreamChat = /*#__PURE__*/function () {
5982
6072
  }());
5983
6073
 
5984
6074
  _defineProperty__default['default'](this, "openConnection", /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3() {
5985
- var _this$wsConnection3, _this$wsFallback3;
6075
+ var _this$wsConnection3, _this$wsConnection4, _this$wsFallback3;
5986
6076
 
5987
6077
  return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
5988
6078
  while (1) {
@@ -5996,18 +6086,30 @@ var StreamChat = /*#__PURE__*/function () {
5996
6086
  throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
5997
6087
 
5998
6088
  case 2:
5999
- if (!(((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isHealthy || (_this$wsFallback3 = _this.wsFallback) !== null && _this$wsFallback3 !== void 0 && _this$wsFallback3.isHealthy()) && _this._hasConnectionID())) {
6089
+ if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting)) {
6000
6090
  _context3.next = 5;
6001
6091
  break;
6002
6092
  }
6003
6093
 
6004
- _this.logger('info', 'client:openConnection() - openConnection called twice, healthy connection already exists', {
6094
+ _this.logger('info', 'client:openConnection() - connection already in progress', {
6005
6095
  tags: ['connection', 'client']
6006
6096
  });
6007
6097
 
6008
6098
  return _context3.abrupt("return", Promise.resolve());
6009
6099
 
6010
6100
  case 5:
6101
+ if (!(((_this$wsConnection4 = _this.wsConnection) !== null && _this$wsConnection4 !== void 0 && _this$wsConnection4.isHealthy || (_this$wsFallback3 = _this.wsFallback) !== null && _this$wsFallback3 !== void 0 && _this$wsFallback3.isHealthy()) && _this._hasConnectionID())) {
6102
+ _context3.next = 8;
6103
+ break;
6104
+ }
6105
+
6106
+ _this.logger('info', 'client:openConnection() - openConnection called twice, healthy connection already exists', {
6107
+ tags: ['connection', 'client']
6108
+ });
6109
+
6110
+ return _context3.abrupt("return", Promise.resolve());
6111
+
6112
+ case 8:
6011
6113
  _this.clientID = "".concat(_this.userID, "--").concat(randomId());
6012
6114
  _this.wsPromise = _this.connect();
6013
6115
 
@@ -6015,7 +6117,7 @@ var StreamChat = /*#__PURE__*/function () {
6015
6117
 
6016
6118
  return _context3.abrupt("return", _this.wsPromise);
6017
6119
 
6018
- case 9:
6120
+ case 12:
6019
6121
  case "end":
6020
6122
  return _context3.stop();
6021
6123
  }
@@ -6725,26 +6827,27 @@ var StreamChat = /*#__PURE__*/function () {
6725
6827
  * updateAppSettings - updates application settings
6726
6828
  *
6727
6829
  * @param {AppSettings} options App settings.
6728
- * IE: {
6729
- "apn_config": {
6730
- "auth_type": "token",
6731
- "auth_key": fs.readFileSync(
6732
- './apn-push-auth-key.p8',
6733
- 'utf-8',
6734
- ),
6735
- "key_id": "keyid",
6736
- "team_id": "teamid", //either ALL these 3
6737
- "notification_template": "notification handlebars template",
6738
- "bundle_id": "com.apple.your.app",
6739
- "development": true
6740
- },
6741
- "firebase_config": {
6742
- "server_key": "server key from fcm",
6743
- "notification_template": "notification handlebars template"
6744
- "data_template": "data handlebars template"
6745
- },
6746
- "webhook_url": "https://acme.com/my/awesome/webhook/"
6747
- }
6830
+ * IE: {
6831
+ 'apn_config': {
6832
+ 'auth_type': 'token',
6833
+ 'auth_key": fs.readFileSync(
6834
+ './apn-push-auth-key.p8',
6835
+ 'utf-8',
6836
+ ),
6837
+ 'key_id': 'keyid',
6838
+ 'team_id': 'teamid',
6839
+ 'notification_template": 'notification handlebars template',
6840
+ 'bundle_id': 'com.apple.your.app',
6841
+ 'development': true
6842
+ },
6843
+ 'firebase_config': {
6844
+ 'server_key': 'server key from fcm',
6845
+ 'notification_template': 'notification handlebars template',
6846
+ 'data_template': 'data handlebars template',
6847
+ 'apn_template': 'apn notification handlebars template under v2'
6848
+ },
6849
+ 'webhook_url': 'https://acme.com/my/awesome/webhook/'
6850
+ }
6748
6851
  */
6749
6852
  function () {
6750
6853
  var _updateAppSettings = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee7(options) {
@@ -7109,7 +7212,7 @@ var StreamChat = /*#__PURE__*/function () {
7109
7212
  }()
7110
7213
  /**
7111
7214
  * createToken - Creates a token to authenticate this user. This function is used server side.
7112
- * The resulting token should be passed to the client side when the users registers or logs in
7215
+ * The resulting token should be passed to the client side when the users registers or logs in.
7113
7216
  *
7114
7217
  * @param {string} userID The User ID
7115
7218
  * @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
@@ -7287,7 +7390,7 @@ var StreamChat = /*#__PURE__*/function () {
7287
7390
  key: "errorFromResponse",
7288
7391
  value: function errorFromResponse(response) {
7289
7392
  var err;
7290
- err = new Error("StreamChat error HTTP code: ".concat(response.status));
7393
+ err = new ErrorFromResponse("StreamChat error HTTP code: ".concat(response.status));
7291
7394
 
7292
7395
  if (response.data && response.data.code) {
7293
7396
  err = new Error("StreamChat error code ".concat(response.data.code, ": ").concat(response.data.message));
@@ -7303,7 +7406,7 @@ var StreamChat = /*#__PURE__*/function () {
7303
7406
  value: function handleResponse(response) {
7304
7407
  var data = response.data;
7305
7408
 
7306
- if ((response.status + '')[0] !== '2') {
7409
+ if (isErrorResponse(response)) {
7307
7410
  throw this.errorFromResponse(response);
7308
7411
  }
7309
7412
 
@@ -7361,7 +7464,7 @@ var StreamChat = /*#__PURE__*/function () {
7361
7464
  this.mutedUsers = event.me.mutes;
7362
7465
  }
7363
7466
 
7364
- if (event.type === 'notification.mark_read') {
7467
+ if (event.type === 'notification.mark_read' && event.unread_channels === 0) {
7365
7468
  var activeChannelKeys = Object.keys(this.activeChannels);
7366
7469
  activeChannelKeys.forEach(function (activeChannelKey) {
7367
7470
  return _this3.activeChannels[activeChannelKey].state.unreadCount = 0;
@@ -9545,7 +9648,7 @@ var StreamChat = /*#__PURE__*/function () {
9545
9648
  }, {
9546
9649
  key: "getUserAgent",
9547
9650
  value: function getUserAgent() {
9548
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.4.0");
9651
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.6.0");
9549
9652
  }
9550
9653
  }, {
9551
9654
  key: "setUserAgent",
@@ -10214,7 +10317,7 @@ var StreamChat = /*#__PURE__*/function () {
10214
10317
  * scheduleCampaign - Schedule a Campaign
10215
10318
  *
10216
10319
  * @param {string} id Campaign ID
10217
- * @param {{sendAt: number}} params Schedule params
10320
+ * @param {{scheduledFor: number}} params Schedule params
10218
10321
  *
10219
10322
  * @return {Campaign} Scheduled Campaign
10220
10323
  */
@@ -10223,16 +10326,16 @@ var StreamChat = /*#__PURE__*/function () {
10223
10326
  key: "scheduleCampaign",
10224
10327
  value: function () {
10225
10328
  var _scheduleCampaign = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee63(id, params) {
10226
- var sendAt, _yield$this$patch, campaign;
10329
+ var scheduledFor, _yield$this$patch, campaign;
10227
10330
 
10228
10331
  return _regeneratorRuntime__default['default'].wrap(function _callee63$(_context63) {
10229
10332
  while (1) {
10230
10333
  switch (_context63.prev = _context63.next) {
10231
10334
  case 0:
10232
- sendAt = params.sendAt;
10335
+ scheduledFor = params.scheduledFor;
10233
10336
  _context63.next = 3;
10234
10337
  return this.patch(this.baseURL + "/campaigns/".concat(id, "/schedule"), {
10235
- send_at: sendAt
10338
+ scheduled_for: scheduledFor
10236
10339
  });
10237
10340
 
10238
10341
  case 3:
@@ -10339,15 +10442,15 @@ var StreamChat = /*#__PURE__*/function () {
10339
10442
  *
10340
10443
  * @param {string} id Campaign ID
10341
10444
  * @param {{users: string[]}} params Test params
10342
- * @return {Campaign} Test Campaign
10445
+ *
10446
+ * @return {TestCampaignResponse} Test campaign response
10343
10447
  */
10344
10448
 
10345
10449
  }, {
10346
10450
  key: "testCampaign",
10347
10451
  value: function () {
10348
10452
  var _testCampaign = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee66(id, params) {
10349
- var users, _yield$this$post3, campaign;
10350
-
10453
+ var users;
10351
10454
  return _regeneratorRuntime__default['default'].wrap(function _callee66$(_context66) {
10352
10455
  while (1) {
10353
10456
  switch (_context66.prev = _context66.next) {
@@ -10359,11 +10462,9 @@ var StreamChat = /*#__PURE__*/function () {
10359
10462
  });
10360
10463
 
10361
10464
  case 3:
10362
- _yield$this$post3 = _context66.sent;
10363
- campaign = _yield$this$post3.campaign;
10364
- return _context66.abrupt("return", campaign);
10465
+ return _context66.abrupt("return", _context66.sent);
10365
10466
 
10366
- case 6:
10467
+ case 4:
10367
10468
  case "end":
10368
10469
  return _context66.stop();
10369
10470
  }
@@ -10943,6 +11044,7 @@ exports.Deny = Deny;
10943
11044
  exports.DenyAll = DenyAll;
10944
11045
  exports.DevToken = DevToken;
10945
11046
  exports.EVENT_MAP = EVENT_MAP;
11047
+ exports.ErrorFromResponse = ErrorFromResponse;
10946
11048
  exports.InsightMetrics = InsightMetrics;
10947
11049
  exports.JWTServerToken = JWTServerToken;
10948
11050
  exports.JWTUserToken = JWTUserToken;