stream-chat 8.57.5 → 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.
@@ -5007,6 +5007,134 @@ var Channel = /*#__PURE__*/function () {
5007
5007
 
5008
5008
  return removeVote;
5009
5009
  }()
5010
+ /**
5011
+ * createDraft - Creates or updates a draft message in a channel
5012
+ *
5013
+ * @param {string} channelType The channel type
5014
+ * @param {string} channelID The channel ID
5015
+ * @param {DraftMessagePayload<StreamChatGenerics>} message The draft message to create or update
5016
+ *
5017
+ * @return {Promise<CreateDraftResponse<StreamChatGenerics>>} Response containing the created draft
5018
+ */
5019
+
5020
+ }, {
5021
+ key: "createDraft",
5022
+ value: function () {
5023
+ var _createDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee50(message) {
5024
+ return _regeneratorRuntime.wrap(function _callee50$(_context50) {
5025
+ while (1) {
5026
+ switch (_context50.prev = _context50.next) {
5027
+ case 0:
5028
+ _context50.next = 2;
5029
+ return this.getClient().post(this._channelURL() + '/draft', {
5030
+ message: message
5031
+ });
5032
+
5033
+ case 2:
5034
+ return _context50.abrupt("return", _context50.sent);
5035
+
5036
+ case 3:
5037
+ case "end":
5038
+ return _context50.stop();
5039
+ }
5040
+ }
5041
+ }, _callee50, this);
5042
+ }));
5043
+
5044
+ function createDraft(_x53) {
5045
+ return _createDraft.apply(this, arguments);
5046
+ }
5047
+
5048
+ return createDraft;
5049
+ }()
5050
+ /**
5051
+ * deleteDraft - Deletes a draft message from a channel
5052
+ *
5053
+ * @param {Object} options
5054
+ * @param {string} options.parent_id Optional parent message ID for drafts in threads
5055
+ *
5056
+ * @return {Promise<APIResponse>} API response
5057
+ */
5058
+
5059
+ }, {
5060
+ key: "deleteDraft",
5061
+ value: function () {
5062
+ var _deleteDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee51() {
5063
+ var _ref2,
5064
+ parent_id,
5065
+ _args51 = arguments;
5066
+
5067
+ return _regeneratorRuntime.wrap(function _callee51$(_context51) {
5068
+ while (1) {
5069
+ switch (_context51.prev = _context51.next) {
5070
+ case 0:
5071
+ _ref2 = _args51.length > 0 && _args51[0] !== undefined ? _args51[0] : {}, parent_id = _ref2.parent_id;
5072
+ _context51.next = 3;
5073
+ return this.getClient().delete(this._channelURL() + '/draft', {
5074
+ parent_id: parent_id
5075
+ });
5076
+
5077
+ case 3:
5078
+ return _context51.abrupt("return", _context51.sent);
5079
+
5080
+ case 4:
5081
+ case "end":
5082
+ return _context51.stop();
5083
+ }
5084
+ }
5085
+ }, _callee51, this);
5086
+ }));
5087
+
5088
+ function deleteDraft() {
5089
+ return _deleteDraft.apply(this, arguments);
5090
+ }
5091
+
5092
+ return deleteDraft;
5093
+ }()
5094
+ /**
5095
+ * getDraft - Retrieves a draft message from a channel
5096
+ *
5097
+ * @param {Object} options
5098
+ * @param {string} options.parent_id Optional parent message ID for drafts in threads
5099
+ *
5100
+ * @return {Promise<GetDraftResponse<StreamChatGenerics>>} Response containing the draft
5101
+ */
5102
+
5103
+ }, {
5104
+ key: "getDraft",
5105
+ value: function () {
5106
+ var _getDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee52() {
5107
+ var _ref3,
5108
+ parent_id,
5109
+ _args52 = arguments;
5110
+
5111
+ return _regeneratorRuntime.wrap(function _callee52$(_context52) {
5112
+ while (1) {
5113
+ switch (_context52.prev = _context52.next) {
5114
+ case 0:
5115
+ _ref3 = _args52.length > 0 && _args52[0] !== undefined ? _args52[0] : {}, parent_id = _ref3.parent_id;
5116
+ _context52.next = 3;
5117
+ return this.getClient().get(this._channelURL() + '/draft', {
5118
+ parent_id: parent_id
5119
+ });
5120
+
5121
+ case 3:
5122
+ return _context52.abrupt("return", _context52.sent);
5123
+
5124
+ case 4:
5125
+ case "end":
5126
+ return _context52.stop();
5127
+ }
5128
+ }
5129
+ }, _callee52, this);
5130
+ }));
5131
+
5132
+ function getDraft() {
5133
+ return _getDraft.apply(this, arguments);
5134
+ }
5135
+
5136
+ return getDraft;
5137
+ }()
5010
5138
  /**
5011
5139
  * on - Listen to events on this channel.
5012
5140
  *
@@ -5217,18 +5345,18 @@ var Channel = /*#__PURE__*/function () {
5217
5345
  if ((_event$channel = event.channel) !== null && _event$channel !== void 0 && _event$channel.truncated_at) {
5218
5346
  var truncatedAt = +new Date(event.channel.truncated_at);
5219
5347
  channelState.messageSets.forEach(function (messageSet, messageSetIndex) {
5220
- messageSet.messages.forEach(function (_ref2) {
5221
- var createdAt = _ref2.created_at,
5222
- id = _ref2.id;
5348
+ messageSet.messages.forEach(function (_ref4) {
5349
+ var createdAt = _ref4.created_at,
5350
+ id = _ref4.id;
5223
5351
  if (truncatedAt > +createdAt) channelState.removeMessage({
5224
5352
  id: id,
5225
5353
  messageSetIndex: messageSetIndex
5226
5354
  });
5227
5355
  });
5228
5356
  });
5229
- channelState.pinnedMessages.forEach(function (_ref3) {
5230
- var id = _ref3.id,
5231
- createdAt = _ref3.created_at;
5357
+ channelState.pinnedMessages.forEach(function (_ref5) {
5358
+ var id = _ref5.id,
5359
+ createdAt = _ref5.created_at;
5232
5360
  if (truncatedAt > +createdAt) channelState.removePinnedMessage({
5233
5361
  id: id
5234
5362
  });
@@ -5528,10 +5656,10 @@ var Channel = /*#__PURE__*/function () {
5528
5656
  }
5529
5657
  }, {
5530
5658
  key: "_hydrateMembers",
5531
- value: function _hydrateMembers(_ref4) {
5532
- var members = _ref4.members,
5533
- _ref4$overrideCurrent = _ref4.overrideCurrentState,
5534
- overrideCurrentState = _ref4$overrideCurrent === void 0 ? true : _ref4$overrideCurrent;
5659
+ value: function _hydrateMembers(_ref6) {
5660
+ var members = _ref6.members,
5661
+ _ref6$overrideCurrent = _ref6.overrideCurrentState,
5662
+ overrideCurrentState = _ref6$overrideCurrent === void 0 ? true : _ref6$overrideCurrent;
5535
5663
  var newMembersById = members.reduce(function (membersById, member) {
5536
5664
  if (member.user) {
5537
5665
  membersById[member.user.id] = member;
@@ -5836,11 +5964,20 @@ var StableWSConnection = /*#__PURE__*/function () {
5836
5964
  _defineProperty(this, "wsID", void 0);
5837
5965
 
5838
5966
  _defineProperty(this, "_buildUrl", function () {
5839
- var qs = encodeURIComponent(_this.client._buildWSPayload(_this.requestID));
5967
+ var qs = _this.client._buildWSPayload(_this.requestID);
5840
5968
 
5841
5969
  var token = _this.client.tokenManager.getToken();
5842
5970
 
5843
- 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()));
5971
+ var wsUrlParams = _this.client.options.wsUrlParams;
5972
+ var params = new URLSearchParams(wsUrlParams);
5973
+ params.set('json', qs);
5974
+ params.set('api_key', _this.client.key); // it is expected that the autorization parameter exists even if
5975
+ // the token is undefined, so we interpolate it to be safe
5976
+
5977
+ params.set('authorization', "".concat(token));
5978
+ params.set('stream-auth-type', _this.client.getAuthType());
5979
+ params.set('X-Stream-Client', _this.client.getUserAgent());
5980
+ return "".concat(_this.client.wsBaseURL, "/connect?").concat(params.toString());
5844
5981
  });
5845
5982
 
5846
5983
  _defineProperty(this, "onlineStatusChanged", function (event) {
@@ -8677,7 +8814,8 @@ function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if
8677
8814
  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(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; }
8678
8815
  var MODERATION_ENTITY_TYPES = {
8679
8816
  user: 'stream:user',
8680
- message: 'stream:chat:v1:message'
8817
+ message: 'stream:chat:v1:message',
8818
+ userprofile: 'stream:v1:user_profile'
8681
8819
  }; // Moderation class provides all the endpoints related to moderation v2.
8682
8820
 
8683
8821
  var Moderation = /*#__PURE__*/function () {
@@ -9200,6 +9338,82 @@ var Moderation = /*#__PURE__*/function () {
9200
9338
 
9201
9339
  return check;
9202
9340
  }()
9341
+ /**
9342
+ * Experimental: Check user profile
9343
+ *
9344
+ * Warning: This is an experimental feature and the API is subject to change.
9345
+ *
9346
+ * This function is used to check a user profile for moderation.
9347
+ * This will not create any review queue items for the user profile.
9348
+ * You can just use this to check whether to allow a certain user profile to be created or not.
9349
+ *
9350
+ * Example:
9351
+ *
9352
+ * ```ts
9353
+ * const res = await client.moderation.checkUserProfile(userId, { username: "fuck_boy_001", image: "https://example.com/profile.jpg" });
9354
+ * if (res.recommended_action === "remove") {
9355
+ * // Block the user profile from being created
9356
+ * } else {
9357
+ * // Allow the user profile to be created
9358
+ * }
9359
+ * ```
9360
+ *
9361
+ * @param userId
9362
+ * @param profile.username
9363
+ * @param profile.image
9364
+ * @returns
9365
+ */
9366
+
9367
+ }, {
9368
+ key: "checkUserProfile",
9369
+ value: function () {
9370
+ var _checkUserProfile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(userId, profile) {
9371
+ var moderationPayload;
9372
+ return _regeneratorRuntime.wrap(function _callee14$(_context14) {
9373
+ while (1) {
9374
+ switch (_context14.prev = _context14.next) {
9375
+ case 0:
9376
+ if (!(!profile.username && !profile.image)) {
9377
+ _context14.next = 2;
9378
+ break;
9379
+ }
9380
+
9381
+ throw new Error('Either username or image must be provided');
9382
+
9383
+ case 2:
9384
+ moderationPayload = {};
9385
+
9386
+ if (profile.username) {
9387
+ moderationPayload.texts = [profile.username];
9388
+ }
9389
+
9390
+ if (profile.image) {
9391
+ moderationPayload.images = [profile.image];
9392
+ }
9393
+
9394
+ _context14.next = 7;
9395
+ return this.check(MODERATION_ENTITY_TYPES.userprofile, userId, userId, moderationPayload, 'user_profile:default', {
9396
+ force_sync: true,
9397
+ test_mode: true
9398
+ });
9399
+
9400
+ case 7:
9401
+ return _context14.abrupt("return", _context14.sent);
9402
+
9403
+ case 8:
9404
+ case "end":
9405
+ return _context14.stop();
9406
+ }
9407
+ }
9408
+ }, _callee14, this);
9409
+ }));
9410
+
9411
+ function checkUserProfile(_x28, _x29) {
9412
+ return _checkUserProfile.apply(this, arguments);
9413
+ }
9414
+
9415
+ return checkUserProfile;
9416
+ }()
9203
9417
  /**
9204
9418
  *
9205
9419
  * @param {string} entityType string Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string
@@ -9216,12 +9430,12 @@ var Moderation = /*#__PURE__*/function () {
9216
9430
  }, {
9217
9431
  key: "addCustomFlags",
9218
9432
  value: function () {
9219
- var _addCustomFlags = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(entityType, entityID, entityCreatorID, moderationPayload, flags) {
9220
- return _regeneratorRuntime.wrap(function _callee14$(_context14) {
9433
+ var _addCustomFlags = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(entityType, entityID, entityCreatorID, moderationPayload, flags) {
9434
+ return _regeneratorRuntime.wrap(function _callee15$(_context15) {
9221
9435
  while (1) {
9222
- switch (_context14.prev = _context14.next) {
9436
+ switch (_context15.prev = _context15.next) {
9223
9437
  case 0:
9224
- _context14.next = 2;
9438
+ _context15.next = 2;
9225
9439
  return this.client.post(this.client.baseURL + "/api/v2/moderation/custom_check", {
9226
9440
  entity_type: entityType,
9227
9441
  entity_id: entityID,
@@ -9231,17 +9445,17 @@ var Moderation = /*#__PURE__*/function () {
9231
9445
  });
9232
9446
 
9233
9447
  case 2:
9234
- return _context14.abrupt("return", _context14.sent);
9448
+ return _context15.abrupt("return", _context15.sent);
9235
9449
 
9236
9450
  case 3:
9237
9451
  case "end":
9238
- return _context14.stop();
9452
+ return _context15.stop();
9239
9453
  }
9240
9454
  }
9241
- }, _callee14, this);
9455
+ }, _callee15, this);
9242
9456
  }));
9243
9457
 
9244
- function addCustomFlags(_x28, _x29, _x30, _x31, _x32) {
9458
+ function addCustomFlags(_x30, _x31, _x32, _x33, _x34) {
9245
9459
  return _addCustomFlags.apply(this, arguments);
9246
9460
  }
9247
9461
 
@@ -9257,26 +9471,26 @@ var Moderation = /*#__PURE__*/function () {
9257
9471
  }, {
9258
9472
  key: "addCustomMessageFlags",
9259
9473
  value: function () {
9260
- var _addCustomMessageFlags = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(messageID, flags) {
9261
- return _regeneratorRuntime.wrap(function _callee15$(_context15) {
9474
+ var _addCustomMessageFlags = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(messageID, flags) {
9475
+ return _regeneratorRuntime.wrap(function _callee16$(_context16) {
9262
9476
  while (1) {
9263
- switch (_context15.prev = _context15.next) {
9477
+ switch (_context16.prev = _context16.next) {
9264
9478
  case 0:
9265
- _context15.next = 2;
9479
+ _context16.next = 2;
9266
9480
  return this.addCustomFlags(MODERATION_ENTITY_TYPES.message, messageID, '', {}, flags);
9267
9481
 
9268
9482
  case 2:
9269
- return _context15.abrupt("return", _context15.sent);
9483
+ return _context16.abrupt("return", _context16.sent);
9270
9484
 
9271
9485
  case 3:
9272
9486
  case "end":
9273
- return _context15.stop();
9487
+ return _context16.stop();
9274
9488
  }
9275
9489
  }
9276
- }, _callee15, this);
9490
+ }, _callee16, this);
9277
9491
  }));
9278
9492
 
9279
- function addCustomMessageFlags(_x33, _x34) {
9493
+ function addCustomMessageFlags(_x35, _x36) {
9280
9494
  return _addCustomMessageFlags.apply(this, arguments);
9281
9495
  }
9282
9496
 
@@ -12333,7 +12547,8 @@ var StreamChat = /*#__PURE__*/function () {
12333
12547
  // making sure cookies are not sent
12334
12548
  warmUp: false,
12335
12549
  recoverStateOnReconnect: true,
12336
- disableCache: false
12550
+ disableCache: false,
12551
+ wsUrlParams: new URLSearchParams({})
12337
12552
  }, inputOptions);
12338
12553
 
12339
12554
  if (this.node && !this.options.httpsAgent) {
@@ -15668,7 +15883,7 @@ var StreamChat = /*#__PURE__*/function () {
15668
15883
  case 2:
15669
15884
  clonedMessage = _extends({}, message);
15670
15885
  delete clonedMessage.id;
15671
- reservedMessageFields = ['command', 'created_at', 'html', 'latest_reactions', 'own_reactions', 'quoted_message', 'reaction_counts', 'reply_count', 'type', 'updated_at', 'user', '__html'];
15886
+ reservedMessageFields = ['command', 'created_at', 'html', 'latest_reactions', 'own_reactions', 'quoted_message', 'reaction_counts', 'reply_count', 'type', 'updated_at', 'user', 'pinned_at', '__html'];
15672
15887
  reservedMessageFields.forEach(function (item) {
15673
15888
  if (clonedMessage[item] != null) {
15674
15889
  delete clonedMessage[item];
@@ -16093,7 +16308,7 @@ var StreamChat = /*#__PURE__*/function () {
16093
16308
  return this.userAgent;
16094
16309
  }
16095
16310
 
16096
- var version = "8.57.5";
16311
+ var version = "8.58.0";
16097
16312
  var clientBundle = "";
16098
16313
  var userAgentString = '';
16099
16314
 
@@ -18339,6 +18554,51 @@ var StreamChat = /*#__PURE__*/function () {
18339
18554
 
18340
18555
  return updateFlags;
18341
18556
  }()
18557
+ /**
18558
+ * queryDrafts - Queries drafts for the current user
18559
+ *
18560
+ * @param {object} [options] Query options
18561
+ * @param {object} [options.filter] Filters for the query
18562
+ * @param {number} [options.sort] Sort parameters
18563
+ * @param {number} [options.limit] Limit the number of results
18564
+ * @param {string} [options.next] Pagination parameter
18565
+ * @param {string} [options.prev] Pagination parameter
18566
+ * @param {string} [options.user_id] Has to be provided when called server-side
18567
+ *
18568
+ * @return {Promise<APIResponse & { drafts: DraftResponse<StreamChatGenerics>[]; next?: string }>} Response containing the drafts
18569
+ */
18570
+
18571
+ }, {
18572
+ key: "queryDrafts",
18573
+ value: function () {
18574
+ var _queryDrafts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee118() {
18575
+ var options,
18576
+ _args118 = arguments;
18577
+ return _regeneratorRuntime.wrap(function _callee118$(_context118) {
18578
+ while (1) {
18579
+ switch (_context118.prev = _context118.next) {
18580
+ case 0:
18581
+ options = _args118.length > 0 && _args118[0] !== undefined ? _args118[0] : {};
18582
+ _context118.next = 3;
18583
+ return this.post(this.baseURL + '/drafts/query', options);
18584
+
18585
+ case 3:
18586
+ return _context118.abrupt("return", _context118.sent);
18587
+
18588
+ case 4:
18589
+ case "end":
18590
+ return _context118.stop();
18591
+ }
18592
+ }
18593
+ }, _callee118, this);
18594
+ }));
18595
+
18596
+ function queryDrafts() {
18597
+ return _queryDrafts.apply(this, arguments);
18598
+ }
18599
+
18600
+ return queryDrafts;
18601
+ }()
18342
18602
  }], [{
18343
18603
  key: "getInstance",
18344
18604
  value: function getInstance(key, secretOrOptions, options) {