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/index.es.js CHANGED
@@ -15,6 +15,11 @@ import FormData from 'form-data';
15
15
  import WebSocket from 'isomorphic-ws';
16
16
  import jwt from 'jsonwebtoken';
17
17
  import crypto$1 from 'crypto';
18
+ import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
19
+ import _inherits from '@babel/runtime/helpers/inherits';
20
+ import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
21
+ import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
22
+ import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper';
18
23
 
19
24
  function isString$1(arrayOrString) {
20
25
  return typeof arrayOrString === 'string';
@@ -1066,6 +1071,7 @@ var EVENT_MAP = {
1066
1071
  'user.deleted': true,
1067
1072
  'user.presence.changed': true,
1068
1073
  'user.unbanned': true,
1074
+ 'user.unread_message_reminder': true,
1069
1075
  'user.updated': true,
1070
1076
  'user.watching.start': true,
1071
1077
  'user.watching.stop': true,
@@ -5376,6 +5382,9 @@ function isWSFailure(err) {
5376
5382
  return false;
5377
5383
  }
5378
5384
  }
5385
+ function isErrorResponse(res) {
5386
+ return !res.status || res.status < 200 || 300 <= res.status;
5387
+ }
5379
5388
 
5380
5389
  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; }
5381
5390
 
@@ -5753,6 +5762,82 @@ var WSConnectionFallback = /*#__PURE__*/function () {
5753
5762
  return WSConnectionFallback;
5754
5763
  }();
5755
5764
 
5765
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
5766
+
5767
+ 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; } }
5768
+
5769
+ /**
5770
+ * Utility Types
5771
+ */
5772
+
5773
+ /* Unknown Record */
5774
+ //alias to avoid breaking change
5775
+
5776
+ /**
5777
+ * Response Types
5778
+ */
5779
+
5780
+ /**
5781
+ * Option Types
5782
+ */
5783
+ // TODO: rename to UpdateChannelOptions in the next major update and use it in channel._update and/or channel.update
5784
+
5785
+ /** @deprecated use MarkChannelsReadOptions instead */
5786
+ // TODO: rename to UpdateChannelTypeOptions in the next major update
5787
+
5788
+ /**
5789
+ * Event Types
5790
+ */
5791
+
5792
+ /**
5793
+ * Filter Types
5794
+ */
5795
+
5796
+ /**
5797
+ * Sort Types
5798
+ */
5799
+
5800
+ /**
5801
+ * Base Types
5802
+ */
5803
+
5804
+ /*
5805
+ DeleteUserOptions specifies a collection of one or more `user_ids` to be deleted.
5806
+
5807
+ `user` soft|hard determines if the user needs to be hard- or soft-deleted, where hard-delete
5808
+ implies that all related objects (messages, flags, etc) will be hard-deleted as well.
5809
+ `conversations` soft|hard will delete any 1to1 channels that the user was a member of.
5810
+ `messages` soft-hard will delete any messages that the user has sent.
5811
+ `new_channel_owner_id` any channels owned by the hard-deleted user will be transferred to this user ID
5812
+ */
5813
+ var ErrorFromResponse = /*#__PURE__*/function (_Error) {
5814
+ _inherits(ErrorFromResponse, _Error);
5815
+
5816
+ var _super = _createSuper(ErrorFromResponse);
5817
+
5818
+ function ErrorFromResponse() {
5819
+ var _this;
5820
+
5821
+ _classCallCheck(this, ErrorFromResponse);
5822
+
5823
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5824
+ args[_key] = arguments[_key];
5825
+ }
5826
+
5827
+ _this = _super.call.apply(_super, [this].concat(args));
5828
+
5829
+ _defineProperty(_assertThisInitialized(_this), "code", void 0);
5830
+
5831
+ _defineProperty(_assertThisInitialized(_this), "response", void 0);
5832
+
5833
+ _defineProperty(_assertThisInitialized(_this), "status", void 0);
5834
+
5835
+ return _this;
5836
+ }
5837
+
5838
+ return ErrorFromResponse;
5839
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
5840
+
5756
5841
  var _excluded = ["created_at", "updated_at", "last_active", "online"];
5757
5842
 
5758
5843
  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; } } }; }
@@ -5965,7 +6050,7 @@ var StreamChat = /*#__PURE__*/function () {
5965
6050
  }());
5966
6051
 
5967
6052
  _defineProperty(this, "openConnection", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
5968
- var _this$wsConnection3, _this$wsFallback3;
6053
+ var _this$wsConnection3, _this$wsConnection4, _this$wsFallback3;
5969
6054
 
5970
6055
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
5971
6056
  while (1) {
@@ -5979,18 +6064,30 @@ var StreamChat = /*#__PURE__*/function () {
5979
6064
  throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
5980
6065
 
5981
6066
  case 2:
5982
- 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())) {
6067
+ if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting)) {
5983
6068
  _context3.next = 5;
5984
6069
  break;
5985
6070
  }
5986
6071
 
5987
- _this.logger('info', 'client:openConnection() - openConnection called twice, healthy connection already exists', {
6072
+ _this.logger('info', 'client:openConnection() - connection already in progress', {
5988
6073
  tags: ['connection', 'client']
5989
6074
  });
5990
6075
 
5991
6076
  return _context3.abrupt("return", Promise.resolve());
5992
6077
 
5993
6078
  case 5:
6079
+ 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())) {
6080
+ _context3.next = 8;
6081
+ break;
6082
+ }
6083
+
6084
+ _this.logger('info', 'client:openConnection() - openConnection called twice, healthy connection already exists', {
6085
+ tags: ['connection', 'client']
6086
+ });
6087
+
6088
+ return _context3.abrupt("return", Promise.resolve());
6089
+
6090
+ case 8:
5994
6091
  _this.clientID = "".concat(_this.userID, "--").concat(randomId());
5995
6092
  _this.wsPromise = _this.connect();
5996
6093
 
@@ -5998,7 +6095,7 @@ var StreamChat = /*#__PURE__*/function () {
5998
6095
 
5999
6096
  return _context3.abrupt("return", _this.wsPromise);
6000
6097
 
6001
- case 9:
6098
+ case 12:
6002
6099
  case "end":
6003
6100
  return _context3.stop();
6004
6101
  }
@@ -6708,26 +6805,27 @@ var StreamChat = /*#__PURE__*/function () {
6708
6805
  * updateAppSettings - updates application settings
6709
6806
  *
6710
6807
  * @param {AppSettings} options App settings.
6711
- * IE: {
6712
- "apn_config": {
6713
- "auth_type": "token",
6714
- "auth_key": fs.readFileSync(
6715
- './apn-push-auth-key.p8',
6716
- 'utf-8',
6717
- ),
6718
- "key_id": "keyid",
6719
- "team_id": "teamid", //either ALL these 3
6720
- "notification_template": "notification handlebars template",
6721
- "bundle_id": "com.apple.your.app",
6722
- "development": true
6723
- },
6724
- "firebase_config": {
6725
- "server_key": "server key from fcm",
6726
- "notification_template": "notification handlebars template"
6727
- "data_template": "data handlebars template"
6728
- },
6729
- "webhook_url": "https://acme.com/my/awesome/webhook/"
6730
- }
6808
+ * IE: {
6809
+ 'apn_config': {
6810
+ 'auth_type': 'token',
6811
+ 'auth_key": fs.readFileSync(
6812
+ './apn-push-auth-key.p8',
6813
+ 'utf-8',
6814
+ ),
6815
+ 'key_id': 'keyid',
6816
+ 'team_id': 'teamid',
6817
+ 'notification_template": 'notification handlebars template',
6818
+ 'bundle_id': 'com.apple.your.app',
6819
+ 'development': true
6820
+ },
6821
+ 'firebase_config': {
6822
+ 'server_key': 'server key from fcm',
6823
+ 'notification_template': 'notification handlebars template',
6824
+ 'data_template': 'data handlebars template',
6825
+ 'apn_template': 'apn notification handlebars template under v2'
6826
+ },
6827
+ 'webhook_url': 'https://acme.com/my/awesome/webhook/'
6828
+ }
6731
6829
  */
6732
6830
  function () {
6733
6831
  var _updateAppSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(options) {
@@ -7092,7 +7190,7 @@ var StreamChat = /*#__PURE__*/function () {
7092
7190
  }()
7093
7191
  /**
7094
7192
  * createToken - Creates a token to authenticate this user. This function is used server side.
7095
- * The resulting token should be passed to the client side when the users registers or logs in
7193
+ * The resulting token should be passed to the client side when the users registers or logs in.
7096
7194
  *
7097
7195
  * @param {string} userID The User ID
7098
7196
  * @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
@@ -7270,7 +7368,7 @@ var StreamChat = /*#__PURE__*/function () {
7270
7368
  key: "errorFromResponse",
7271
7369
  value: function errorFromResponse(response) {
7272
7370
  var err;
7273
- err = new Error("StreamChat error HTTP code: ".concat(response.status));
7371
+ err = new ErrorFromResponse("StreamChat error HTTP code: ".concat(response.status));
7274
7372
 
7275
7373
  if (response.data && response.data.code) {
7276
7374
  err = new Error("StreamChat error code ".concat(response.data.code, ": ").concat(response.data.message));
@@ -7286,7 +7384,7 @@ var StreamChat = /*#__PURE__*/function () {
7286
7384
  value: function handleResponse(response) {
7287
7385
  var data = response.data;
7288
7386
 
7289
- if ((response.status + '')[0] !== '2') {
7387
+ if (isErrorResponse(response)) {
7290
7388
  throw this.errorFromResponse(response);
7291
7389
  }
7292
7390
 
@@ -7344,7 +7442,7 @@ var StreamChat = /*#__PURE__*/function () {
7344
7442
  this.mutedUsers = event.me.mutes;
7345
7443
  }
7346
7444
 
7347
- if (event.type === 'notification.mark_read') {
7445
+ if (event.type === 'notification.mark_read' && event.unread_channels === 0) {
7348
7446
  var activeChannelKeys = Object.keys(this.activeChannels);
7349
7447
  activeChannelKeys.forEach(function (activeChannelKey) {
7350
7448
  return _this3.activeChannels[activeChannelKey].state.unreadCount = 0;
@@ -9528,7 +9626,7 @@ var StreamChat = /*#__PURE__*/function () {
9528
9626
  }, {
9529
9627
  key: "getUserAgent",
9530
9628
  value: function getUserAgent() {
9531
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.4.0");
9629
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.6.0");
9532
9630
  }
9533
9631
  }, {
9534
9632
  key: "setUserAgent",
@@ -10197,7 +10295,7 @@ var StreamChat = /*#__PURE__*/function () {
10197
10295
  * scheduleCampaign - Schedule a Campaign
10198
10296
  *
10199
10297
  * @param {string} id Campaign ID
10200
- * @param {{sendAt: number}} params Schedule params
10298
+ * @param {{scheduledFor: number}} params Schedule params
10201
10299
  *
10202
10300
  * @return {Campaign} Scheduled Campaign
10203
10301
  */
@@ -10206,16 +10304,16 @@ var StreamChat = /*#__PURE__*/function () {
10206
10304
  key: "scheduleCampaign",
10207
10305
  value: function () {
10208
10306
  var _scheduleCampaign = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee63(id, params) {
10209
- var sendAt, _yield$this$patch, campaign;
10307
+ var scheduledFor, _yield$this$patch, campaign;
10210
10308
 
10211
10309
  return _regeneratorRuntime.wrap(function _callee63$(_context63) {
10212
10310
  while (1) {
10213
10311
  switch (_context63.prev = _context63.next) {
10214
10312
  case 0:
10215
- sendAt = params.sendAt;
10313
+ scheduledFor = params.scheduledFor;
10216
10314
  _context63.next = 3;
10217
10315
  return this.patch(this.baseURL + "/campaigns/".concat(id, "/schedule"), {
10218
- send_at: sendAt
10316
+ scheduled_for: scheduledFor
10219
10317
  });
10220
10318
 
10221
10319
  case 3:
@@ -10322,15 +10420,15 @@ var StreamChat = /*#__PURE__*/function () {
10322
10420
  *
10323
10421
  * @param {string} id Campaign ID
10324
10422
  * @param {{users: string[]}} params Test params
10325
- * @return {Campaign} Test Campaign
10423
+ *
10424
+ * @return {TestCampaignResponse} Test campaign response
10326
10425
  */
10327
10426
 
10328
10427
  }, {
10329
10428
  key: "testCampaign",
10330
10429
  value: function () {
10331
10430
  var _testCampaign = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee66(id, params) {
10332
- var users, _yield$this$post3, campaign;
10333
-
10431
+ var users;
10334
10432
  return _regeneratorRuntime.wrap(function _callee66$(_context66) {
10335
10433
  while (1) {
10336
10434
  switch (_context66.prev = _context66.next) {
@@ -10342,11 +10440,9 @@ var StreamChat = /*#__PURE__*/function () {
10342
10440
  });
10343
10441
 
10344
10442
  case 3:
10345
- _yield$this$post3 = _context66.sent;
10346
- campaign = _yield$this$post3.campaign;
10347
- return _context66.abrupt("return", campaign);
10443
+ return _context66.abrupt("return", _context66.sent);
10348
10444
 
10349
- case 6:
10445
+ case 4:
10350
10446
  case "end":
10351
10447
  return _context66.stop();
10352
10448
  }
@@ -10912,5 +11008,5 @@ var BuiltinPermissions = {
10912
11008
  UseFrozenChannel: 'Send messages and reactions to frozen channels'
10913
11009
  };
10914
11010
 
10915
- 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, postInsights };
11011
+ export { Allow, AllowAll, AnyResource, AnyRole, BuiltinPermissions, BuiltinRoles, Channel, ChannelState, CheckSignature, ClientState, Deny, DenyAll, DevToken, EVENT_MAP, ErrorFromResponse, InsightMetrics, JWTServerToken, JWTUserToken, MaxPriority, MinPriority, Permission, StableWSConnection, StreamChat, TokenManager, UserFromToken, buildWsFatalInsight, buildWsSuccessAfterFailureInsight, chatCodes, decodeBase64, encodeBase64, isOwnUser, isValidEventType, logChatPromiseExecution, postInsights };
10916
11012
  //# sourceMappingURL=index.es.js.map