stream-chat 8.57.6 → 8.58.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
@@ -5032,6 +5032,134 @@ var Channel = /*#__PURE__*/function () {
5032
5032
 
5033
5033
  return removeVote;
5034
5034
  }()
5035
+ /**
5036
+ * createDraft - Creates or updates a draft message in a channel
5037
+ *
5038
+ * @param {string} channelType The channel type
5039
+ * @param {string} channelID The channel ID
5040
+ * @param {DraftMessagePayload<StreamChatGenerics>} message The draft message to create or update
5041
+ *
5042
+ * @return {Promise<CreateDraftResponse<StreamChatGenerics>>} Response containing the created draft
5043
+ */
5044
+
5045
+ }, {
5046
+ key: "createDraft",
5047
+ value: function () {
5048
+ var _createDraft = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee50(message) {
5049
+ return _regeneratorRuntime__default['default'].wrap(function _callee50$(_context50) {
5050
+ while (1) {
5051
+ switch (_context50.prev = _context50.next) {
5052
+ case 0:
5053
+ _context50.next = 2;
5054
+ return this.getClient().post(this._channelURL() + '/draft', {
5055
+ message: message
5056
+ });
5057
+
5058
+ case 2:
5059
+ return _context50.abrupt("return", _context50.sent);
5060
+
5061
+ case 3:
5062
+ case "end":
5063
+ return _context50.stop();
5064
+ }
5065
+ }
5066
+ }, _callee50, this);
5067
+ }));
5068
+
5069
+ function createDraft(_x53) {
5070
+ return _createDraft.apply(this, arguments);
5071
+ }
5072
+
5073
+ return createDraft;
5074
+ }()
5075
+ /**
5076
+ * deleteDraft - Deletes a draft message from a channel
5077
+ *
5078
+ * @param {Object} options
5079
+ * @param {string} options.parent_id Optional parent message ID for drafts in threads
5080
+ *
5081
+ * @return {Promise<APIResponse>} API response
5082
+ */
5083
+
5084
+ }, {
5085
+ key: "deleteDraft",
5086
+ value: function () {
5087
+ var _deleteDraft = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee51() {
5088
+ var _ref2,
5089
+ parent_id,
5090
+ _args51 = arguments;
5091
+
5092
+ return _regeneratorRuntime__default['default'].wrap(function _callee51$(_context51) {
5093
+ while (1) {
5094
+ switch (_context51.prev = _context51.next) {
5095
+ case 0:
5096
+ _ref2 = _args51.length > 0 && _args51[0] !== undefined ? _args51[0] : {}, parent_id = _ref2.parent_id;
5097
+ _context51.next = 3;
5098
+ return this.getClient().delete(this._channelURL() + '/draft', {
5099
+ parent_id: parent_id
5100
+ });
5101
+
5102
+ case 3:
5103
+ return _context51.abrupt("return", _context51.sent);
5104
+
5105
+ case 4:
5106
+ case "end":
5107
+ return _context51.stop();
5108
+ }
5109
+ }
5110
+ }, _callee51, this);
5111
+ }));
5112
+
5113
+ function deleteDraft() {
5114
+ return _deleteDraft.apply(this, arguments);
5115
+ }
5116
+
5117
+ return deleteDraft;
5118
+ }()
5119
+ /**
5120
+ * getDraft - Retrieves a draft message from a channel
5121
+ *
5122
+ * @param {Object} options
5123
+ * @param {string} options.parent_id Optional parent message ID for drafts in threads
5124
+ *
5125
+ * @return {Promise<GetDraftResponse<StreamChatGenerics>>} Response containing the draft
5126
+ */
5127
+
5128
+ }, {
5129
+ key: "getDraft",
5130
+ value: function () {
5131
+ var _getDraft = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee52() {
5132
+ var _ref3,
5133
+ parent_id,
5134
+ _args52 = arguments;
5135
+
5136
+ return _regeneratorRuntime__default['default'].wrap(function _callee52$(_context52) {
5137
+ while (1) {
5138
+ switch (_context52.prev = _context52.next) {
5139
+ case 0:
5140
+ _ref3 = _args52.length > 0 && _args52[0] !== undefined ? _args52[0] : {}, parent_id = _ref3.parent_id;
5141
+ _context52.next = 3;
5142
+ return this.getClient().get(this._channelURL() + '/draft', {
5143
+ parent_id: parent_id
5144
+ });
5145
+
5146
+ case 3:
5147
+ return _context52.abrupt("return", _context52.sent);
5148
+
5149
+ case 4:
5150
+ case "end":
5151
+ return _context52.stop();
5152
+ }
5153
+ }
5154
+ }, _callee52, this);
5155
+ }));
5156
+
5157
+ function getDraft() {
5158
+ return _getDraft.apply(this, arguments);
5159
+ }
5160
+
5161
+ return getDraft;
5162
+ }()
5035
5163
  /**
5036
5164
  * on - Listen to events on this channel.
5037
5165
  *
@@ -5242,18 +5370,18 @@ var Channel = /*#__PURE__*/function () {
5242
5370
  if ((_event$channel = event.channel) !== null && _event$channel !== void 0 && _event$channel.truncated_at) {
5243
5371
  var truncatedAt = +new Date(event.channel.truncated_at);
5244
5372
  channelState.messageSets.forEach(function (messageSet, messageSetIndex) {
5245
- messageSet.messages.forEach(function (_ref2) {
5246
- var createdAt = _ref2.created_at,
5247
- id = _ref2.id;
5373
+ messageSet.messages.forEach(function (_ref4) {
5374
+ var createdAt = _ref4.created_at,
5375
+ id = _ref4.id;
5248
5376
  if (truncatedAt > +createdAt) channelState.removeMessage({
5249
5377
  id: id,
5250
5378
  messageSetIndex: messageSetIndex
5251
5379
  });
5252
5380
  });
5253
5381
  });
5254
- channelState.pinnedMessages.forEach(function (_ref3) {
5255
- var id = _ref3.id,
5256
- createdAt = _ref3.created_at;
5382
+ channelState.pinnedMessages.forEach(function (_ref5) {
5383
+ var id = _ref5.id,
5384
+ createdAt = _ref5.created_at;
5257
5385
  if (truncatedAt > +createdAt) channelState.removePinnedMessage({
5258
5386
  id: id
5259
5387
  });
@@ -5553,10 +5681,10 @@ var Channel = /*#__PURE__*/function () {
5553
5681
  }
5554
5682
  }, {
5555
5683
  key: "_hydrateMembers",
5556
- value: function _hydrateMembers(_ref4) {
5557
- var members = _ref4.members,
5558
- _ref4$overrideCurrent = _ref4.overrideCurrentState,
5559
- overrideCurrentState = _ref4$overrideCurrent === void 0 ? true : _ref4$overrideCurrent;
5684
+ value: function _hydrateMembers(_ref6) {
5685
+ var members = _ref6.members,
5686
+ _ref6$overrideCurrent = _ref6.overrideCurrentState,
5687
+ overrideCurrentState = _ref6$overrideCurrent === void 0 ? true : _ref6$overrideCurrent;
5560
5688
  var newMembersById = members.reduce(function (membersById, member) {
5561
5689
  if (member.user) {
5562
5690
  membersById[member.user.id] = member;
@@ -5861,11 +5989,20 @@ var StableWSConnection = /*#__PURE__*/function () {
5861
5989
  _defineProperty__default['default'](this, "wsID", void 0);
5862
5990
 
5863
5991
  _defineProperty__default['default'](this, "_buildUrl", function () {
5864
- var qs = encodeURIComponent(_this.client._buildWSPayload(_this.requestID));
5992
+ var qs = _this.client._buildWSPayload(_this.requestID);
5865
5993
 
5866
5994
  var token = _this.client.tokenManager.getToken();
5867
5995
 
5868
- return "".concat(_this.client.wsBaseURL, "/connect?json=").concat(qs, "&api_key=").concat(_this.client.key, "&authorization=").concat(token, "&stream-auth-type=").concat(_this.client.getAuthType(), "&X-Stream-Client=").concat(encodeURIComponent(_this.client.getUserAgent()));
5996
+ var wsUrlParams = _this.client.options.wsUrlParams;
5997
+ var params = new URLSearchParams(wsUrlParams);
5998
+ params.set('json', qs);
5999
+ params.set('api_key', _this.client.key); // it is expected that the autorization parameter exists even if
6000
+ // the token is undefined, so we interpolate it to be safe
6001
+
6002
+ params.set('authorization', "".concat(token));
6003
+ params.set('stream-auth-type', _this.client.getAuthType());
6004
+ params.set('X-Stream-Client', _this.client.getUserAgent());
6005
+ return "".concat(_this.client.wsBaseURL, "/connect?").concat(params.toString());
5869
6006
  });
5870
6007
 
5871
6008
  _defineProperty__default['default'](this, "onlineStatusChanged", function (event) {
@@ -8702,7 +8839,8 @@ function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if
8702
8839
  function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$5(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$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8703
8840
  var MODERATION_ENTITY_TYPES = {
8704
8841
  user: 'stream:user',
8705
- message: 'stream:chat:v1:message'
8842
+ message: 'stream:chat:v1:message',
8843
+ userprofile: 'stream:v1:user_profile'
8706
8844
  }; // Moderation class provides all the endpoints related to moderation v2.
8707
8845
 
8708
8846
  var Moderation = /*#__PURE__*/function () {
@@ -9225,6 +9363,82 @@ var Moderation = /*#__PURE__*/function () {
9225
9363
 
9226
9364
  return check;
9227
9365
  }()
9366
+ /**
9367
+ * Experimental: Check user profile
9368
+ *
9369
+ * Warning: This is an experimental feature and the API is subject to change.
9370
+ *
9371
+ * This function is used to check a user profile for moderation.
9372
+ * This will not create any review queue items for the user profile.
9373
+ * You can just use this to check whether to allow a certain user profile to be created or not.
9374
+ *
9375
+ * Example:
9376
+ *
9377
+ * ```ts
9378
+ * const res = await client.moderation.checkUserProfile(userId, { username: "fuck_boy_001", image: "https://example.com/profile.jpg" });
9379
+ * if (res.recommended_action === "remove") {
9380
+ * // Block the user profile from being created
9381
+ * } else {
9382
+ * // Allow the user profile to be created
9383
+ * }
9384
+ * ```
9385
+ *
9386
+ * @param userId
9387
+ * @param profile.username
9388
+ * @param profile.image
9389
+ * @returns
9390
+ */
9391
+
9392
+ }, {
9393
+ key: "checkUserProfile",
9394
+ value: function () {
9395
+ var _checkUserProfile = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee14(userId, profile) {
9396
+ var moderationPayload;
9397
+ return _regeneratorRuntime__default['default'].wrap(function _callee14$(_context14) {
9398
+ while (1) {
9399
+ switch (_context14.prev = _context14.next) {
9400
+ case 0:
9401
+ if (!(!profile.username && !profile.image)) {
9402
+ _context14.next = 2;
9403
+ break;
9404
+ }
9405
+
9406
+ throw new Error('Either username or image must be provided');
9407
+
9408
+ case 2:
9409
+ moderationPayload = {};
9410
+
9411
+ if (profile.username) {
9412
+ moderationPayload.texts = [profile.username];
9413
+ }
9414
+
9415
+ if (profile.image) {
9416
+ moderationPayload.images = [profile.image];
9417
+ }
9418
+
9419
+ _context14.next = 7;
9420
+ return this.check(MODERATION_ENTITY_TYPES.userprofile, userId, userId, moderationPayload, 'user_profile:default', {
9421
+ force_sync: true,
9422
+ test_mode: true
9423
+ });
9424
+
9425
+ case 7:
9426
+ return _context14.abrupt("return", _context14.sent);
9427
+
9428
+ case 8:
9429
+ case "end":
9430
+ return _context14.stop();
9431
+ }
9432
+ }
9433
+ }, _callee14, this);
9434
+ }));
9435
+
9436
+ function checkUserProfile(_x28, _x29) {
9437
+ return _checkUserProfile.apply(this, arguments);
9438
+ }
9439
+
9440
+ return checkUserProfile;
9441
+ }()
9228
9442
  /**
9229
9443
  *
9230
9444
  * @param {string} entityType string Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string
@@ -9241,12 +9455,12 @@ var Moderation = /*#__PURE__*/function () {
9241
9455
  }, {
9242
9456
  key: "addCustomFlags",
9243
9457
  value: function () {
9244
- var _addCustomFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee14(entityType, entityID, entityCreatorID, moderationPayload, flags) {
9245
- return _regeneratorRuntime__default['default'].wrap(function _callee14$(_context14) {
9458
+ var _addCustomFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee15(entityType, entityID, entityCreatorID, moderationPayload, flags) {
9459
+ return _regeneratorRuntime__default['default'].wrap(function _callee15$(_context15) {
9246
9460
  while (1) {
9247
- switch (_context14.prev = _context14.next) {
9461
+ switch (_context15.prev = _context15.next) {
9248
9462
  case 0:
9249
- _context14.next = 2;
9463
+ _context15.next = 2;
9250
9464
  return this.client.post(this.client.baseURL + "/api/v2/moderation/custom_check", {
9251
9465
  entity_type: entityType,
9252
9466
  entity_id: entityID,
@@ -9256,17 +9470,17 @@ var Moderation = /*#__PURE__*/function () {
9256
9470
  });
9257
9471
 
9258
9472
  case 2:
9259
- return _context14.abrupt("return", _context14.sent);
9473
+ return _context15.abrupt("return", _context15.sent);
9260
9474
 
9261
9475
  case 3:
9262
9476
  case "end":
9263
- return _context14.stop();
9477
+ return _context15.stop();
9264
9478
  }
9265
9479
  }
9266
- }, _callee14, this);
9480
+ }, _callee15, this);
9267
9481
  }));
9268
9482
 
9269
- function addCustomFlags(_x28, _x29, _x30, _x31, _x32) {
9483
+ function addCustomFlags(_x30, _x31, _x32, _x33, _x34) {
9270
9484
  return _addCustomFlags.apply(this, arguments);
9271
9485
  }
9272
9486
 
@@ -9282,26 +9496,26 @@ var Moderation = /*#__PURE__*/function () {
9282
9496
  }, {
9283
9497
  key: "addCustomMessageFlags",
9284
9498
  value: function () {
9285
- var _addCustomMessageFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee15(messageID, flags) {
9286
- return _regeneratorRuntime__default['default'].wrap(function _callee15$(_context15) {
9499
+ var _addCustomMessageFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee16(messageID, flags) {
9500
+ return _regeneratorRuntime__default['default'].wrap(function _callee16$(_context16) {
9287
9501
  while (1) {
9288
- switch (_context15.prev = _context15.next) {
9502
+ switch (_context16.prev = _context16.next) {
9289
9503
  case 0:
9290
- _context15.next = 2;
9504
+ _context16.next = 2;
9291
9505
  return this.addCustomFlags(MODERATION_ENTITY_TYPES.message, messageID, '', {}, flags);
9292
9506
 
9293
9507
  case 2:
9294
- return _context15.abrupt("return", _context15.sent);
9508
+ return _context16.abrupt("return", _context16.sent);
9295
9509
 
9296
9510
  case 3:
9297
9511
  case "end":
9298
- return _context15.stop();
9512
+ return _context16.stop();
9299
9513
  }
9300
9514
  }
9301
- }, _callee15, this);
9515
+ }, _callee16, this);
9302
9516
  }));
9303
9517
 
9304
- function addCustomMessageFlags(_x33, _x34) {
9518
+ function addCustomMessageFlags(_x35, _x36) {
9305
9519
  return _addCustomMessageFlags.apply(this, arguments);
9306
9520
  }
9307
9521
 
@@ -12358,7 +12572,8 @@ var StreamChat = /*#__PURE__*/function () {
12358
12572
  // making sure cookies are not sent
12359
12573
  warmUp: false,
12360
12574
  recoverStateOnReconnect: true,
12361
- disableCache: false
12575
+ disableCache: false,
12576
+ wsUrlParams: new URLSearchParams({})
12362
12577
  }, inputOptions);
12363
12578
 
12364
12579
  if (this.node && !this.options.httpsAgent) {
@@ -16118,7 +16333,7 @@ var StreamChat = /*#__PURE__*/function () {
16118
16333
  return this.userAgent;
16119
16334
  }
16120
16335
 
16121
- var version = "8.57.6";
16336
+ var version = "8.58.0";
16122
16337
  var clientBundle = "";
16123
16338
  var userAgentString = '';
16124
16339
 
@@ -18364,6 +18579,51 @@ var StreamChat = /*#__PURE__*/function () {
18364
18579
 
18365
18580
  return updateFlags;
18366
18581
  }()
18582
+ /**
18583
+ * queryDrafts - Queries drafts for the current user
18584
+ *
18585
+ * @param {object} [options] Query options
18586
+ * @param {object} [options.filter] Filters for the query
18587
+ * @param {number} [options.sort] Sort parameters
18588
+ * @param {number} [options.limit] Limit the number of results
18589
+ * @param {string} [options.next] Pagination parameter
18590
+ * @param {string} [options.prev] Pagination parameter
18591
+ * @param {string} [options.user_id] Has to be provided when called server-side
18592
+ *
18593
+ * @return {Promise<APIResponse & { drafts: DraftResponse<StreamChatGenerics>[]; next?: string }>} Response containing the drafts
18594
+ */
18595
+
18596
+ }, {
18597
+ key: "queryDrafts",
18598
+ value: function () {
18599
+ var _queryDrafts = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee118() {
18600
+ var options,
18601
+ _args118 = arguments;
18602
+ return _regeneratorRuntime__default['default'].wrap(function _callee118$(_context118) {
18603
+ while (1) {
18604
+ switch (_context118.prev = _context118.next) {
18605
+ case 0:
18606
+ options = _args118.length > 0 && _args118[0] !== undefined ? _args118[0] : {};
18607
+ _context118.next = 3;
18608
+ return this.post(this.baseURL + '/drafts/query', options);
18609
+
18610
+ case 3:
18611
+ return _context118.abrupt("return", _context118.sent);
18612
+
18613
+ case 4:
18614
+ case "end":
18615
+ return _context118.stop();
18616
+ }
18617
+ }
18618
+ }, _callee118, this);
18619
+ }));
18620
+
18621
+ function queryDrafts() {
18622
+ return _queryDrafts.apply(this, arguments);
18623
+ }
18624
+
18625
+ return queryDrafts;
18626
+ }()
18367
18627
  }], [{
18368
18628
  key: "getInstance",
18369
18629
  value: function getInstance(key, secretOrOptions, options) {