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