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/index.js CHANGED
@@ -5036,6 +5036,134 @@ var Channel = /*#__PURE__*/function () {
5036
5036
 
5037
5037
  return removeVote;
5038
5038
  }()
5039
+ /**
5040
+ * createDraft - Creates or updates a draft message in a channel
5041
+ *
5042
+ * @param {string} channelType The channel type
5043
+ * @param {string} channelID The channel ID
5044
+ * @param {DraftMessagePayload<StreamChatGenerics>} message The draft message to create or update
5045
+ *
5046
+ * @return {Promise<CreateDraftResponse<StreamChatGenerics>>} Response containing the created draft
5047
+ */
5048
+
5049
+ }, {
5050
+ key: "createDraft",
5051
+ value: function () {
5052
+ var _createDraft = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee50(message) {
5053
+ return _regeneratorRuntime__default['default'].wrap(function _callee50$(_context50) {
5054
+ while (1) {
5055
+ switch (_context50.prev = _context50.next) {
5056
+ case 0:
5057
+ _context50.next = 2;
5058
+ return this.getClient().post(this._channelURL() + '/draft', {
5059
+ message: message
5060
+ });
5061
+
5062
+ case 2:
5063
+ return _context50.abrupt("return", _context50.sent);
5064
+
5065
+ case 3:
5066
+ case "end":
5067
+ return _context50.stop();
5068
+ }
5069
+ }
5070
+ }, _callee50, this);
5071
+ }));
5072
+
5073
+ function createDraft(_x53) {
5074
+ return _createDraft.apply(this, arguments);
5075
+ }
5076
+
5077
+ return createDraft;
5078
+ }()
5079
+ /**
5080
+ * deleteDraft - Deletes a draft message from a channel
5081
+ *
5082
+ * @param {Object} options
5083
+ * @param {string} options.parent_id Optional parent message ID for drafts in threads
5084
+ *
5085
+ * @return {Promise<APIResponse>} API response
5086
+ */
5087
+
5088
+ }, {
5089
+ key: "deleteDraft",
5090
+ value: function () {
5091
+ var _deleteDraft = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee51() {
5092
+ var _ref2,
5093
+ parent_id,
5094
+ _args51 = arguments;
5095
+
5096
+ return _regeneratorRuntime__default['default'].wrap(function _callee51$(_context51) {
5097
+ while (1) {
5098
+ switch (_context51.prev = _context51.next) {
5099
+ case 0:
5100
+ _ref2 = _args51.length > 0 && _args51[0] !== undefined ? _args51[0] : {}, parent_id = _ref2.parent_id;
5101
+ _context51.next = 3;
5102
+ return this.getClient().delete(this._channelURL() + '/draft', {
5103
+ parent_id: parent_id
5104
+ });
5105
+
5106
+ case 3:
5107
+ return _context51.abrupt("return", _context51.sent);
5108
+
5109
+ case 4:
5110
+ case "end":
5111
+ return _context51.stop();
5112
+ }
5113
+ }
5114
+ }, _callee51, this);
5115
+ }));
5116
+
5117
+ function deleteDraft() {
5118
+ return _deleteDraft.apply(this, arguments);
5119
+ }
5120
+
5121
+ return deleteDraft;
5122
+ }()
5123
+ /**
5124
+ * getDraft - Retrieves a draft message from a channel
5125
+ *
5126
+ * @param {Object} options
5127
+ * @param {string} options.parent_id Optional parent message ID for drafts in threads
5128
+ *
5129
+ * @return {Promise<GetDraftResponse<StreamChatGenerics>>} Response containing the draft
5130
+ */
5131
+
5132
+ }, {
5133
+ key: "getDraft",
5134
+ value: function () {
5135
+ var _getDraft = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee52() {
5136
+ var _ref3,
5137
+ parent_id,
5138
+ _args52 = arguments;
5139
+
5140
+ return _regeneratorRuntime__default['default'].wrap(function _callee52$(_context52) {
5141
+ while (1) {
5142
+ switch (_context52.prev = _context52.next) {
5143
+ case 0:
5144
+ _ref3 = _args52.length > 0 && _args52[0] !== undefined ? _args52[0] : {}, parent_id = _ref3.parent_id;
5145
+ _context52.next = 3;
5146
+ return this.getClient().get(this._channelURL() + '/draft', {
5147
+ parent_id: parent_id
5148
+ });
5149
+
5150
+ case 3:
5151
+ return _context52.abrupt("return", _context52.sent);
5152
+
5153
+ case 4:
5154
+ case "end":
5155
+ return _context52.stop();
5156
+ }
5157
+ }
5158
+ }, _callee52, this);
5159
+ }));
5160
+
5161
+ function getDraft() {
5162
+ return _getDraft.apply(this, arguments);
5163
+ }
5164
+
5165
+ return getDraft;
5166
+ }()
5039
5167
  /**
5040
5168
  * on - Listen to events on this channel.
5041
5169
  *
@@ -5246,18 +5374,18 @@ var Channel = /*#__PURE__*/function () {
5246
5374
  if ((_event$channel = event.channel) !== null && _event$channel !== void 0 && _event$channel.truncated_at) {
5247
5375
  var truncatedAt = +new Date(event.channel.truncated_at);
5248
5376
  channelState.messageSets.forEach(function (messageSet, messageSetIndex) {
5249
- messageSet.messages.forEach(function (_ref2) {
5250
- var createdAt = _ref2.created_at,
5251
- id = _ref2.id;
5377
+ messageSet.messages.forEach(function (_ref4) {
5378
+ var createdAt = _ref4.created_at,
5379
+ id = _ref4.id;
5252
5380
  if (truncatedAt > +createdAt) channelState.removeMessage({
5253
5381
  id: id,
5254
5382
  messageSetIndex: messageSetIndex
5255
5383
  });
5256
5384
  });
5257
5385
  });
5258
- channelState.pinnedMessages.forEach(function (_ref3) {
5259
- var id = _ref3.id,
5260
- createdAt = _ref3.created_at;
5386
+ channelState.pinnedMessages.forEach(function (_ref5) {
5387
+ var id = _ref5.id,
5388
+ createdAt = _ref5.created_at;
5261
5389
  if (truncatedAt > +createdAt) channelState.removePinnedMessage({
5262
5390
  id: id
5263
5391
  });
@@ -5557,10 +5685,10 @@ var Channel = /*#__PURE__*/function () {
5557
5685
  }
5558
5686
  }, {
5559
5687
  key: "_hydrateMembers",
5560
- value: function _hydrateMembers(_ref4) {
5561
- var members = _ref4.members,
5562
- _ref4$overrideCurrent = _ref4.overrideCurrentState,
5563
- overrideCurrentState = _ref4$overrideCurrent === void 0 ? true : _ref4$overrideCurrent;
5688
+ value: function _hydrateMembers(_ref6) {
5689
+ var members = _ref6.members,
5690
+ _ref6$overrideCurrent = _ref6.overrideCurrentState,
5691
+ overrideCurrentState = _ref6$overrideCurrent === void 0 ? true : _ref6$overrideCurrent;
5564
5692
  var newMembersById = members.reduce(function (membersById, member) {
5565
5693
  if (member.user) {
5566
5694
  membersById[member.user.id] = member;
@@ -5865,11 +5993,20 @@ var StableWSConnection = /*#__PURE__*/function () {
5865
5993
  _defineProperty__default['default'](this, "wsID", void 0);
5866
5994
 
5867
5995
  _defineProperty__default['default'](this, "_buildUrl", function () {
5868
- var qs = encodeURIComponent(_this.client._buildWSPayload(_this.requestID));
5996
+ var qs = _this.client._buildWSPayload(_this.requestID);
5869
5997
 
5870
5998
  var token = _this.client.tokenManager.getToken();
5871
5999
 
5872
- 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()));
6000
+ var wsUrlParams = _this.client.options.wsUrlParams;
6001
+ var params = new URLSearchParams(wsUrlParams);
6002
+ params.set('json', qs);
6003
+ params.set('api_key', _this.client.key); // it is expected that the autorization parameter exists even if
6004
+ // the token is undefined, so we interpolate it to be safe
6005
+
6006
+ params.set('authorization', "".concat(token));
6007
+ params.set('stream-auth-type', _this.client.getAuthType());
6008
+ params.set('X-Stream-Client', _this.client.getUserAgent());
6009
+ return "".concat(_this.client.wsBaseURL, "/connect?").concat(params.toString());
5873
6010
  });
5874
6011
 
5875
6012
  _defineProperty__default['default'](this, "onlineStatusChanged", function (event) {
@@ -8708,7 +8845,8 @@ function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if
8708
8845
  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; }
8709
8846
  var MODERATION_ENTITY_TYPES = {
8710
8847
  user: 'stream:user',
8711
- message: 'stream:chat:v1:message'
8848
+ message: 'stream:chat:v1:message',
8849
+ userprofile: 'stream:v1:user_profile'
8712
8850
  }; // Moderation class provides all the endpoints related to moderation v2.
8713
8851
 
8714
8852
  var Moderation = /*#__PURE__*/function () {
@@ -9231,6 +9369,82 @@ var Moderation = /*#__PURE__*/function () {
9231
9369
 
9232
9370
  return check;
9233
9371
  }()
9372
+ /**
9373
+ * Experimental: Check user profile
9374
+ *
9375
+ * Warning: This is an experimental feature and the API is subject to change.
9376
+ *
9377
+ * This function is used to check a user profile for moderation.
9378
+ * This will not create any review queue items for the user profile.
9379
+ * You can just use this to check whether to allow a certain user profile to be created or not.
9380
+ *
9381
+ * Example:
9382
+ *
9383
+ * ```ts
9384
+ * const res = await client.moderation.checkUserProfile(userId, { username: "fuck_boy_001", image: "https://example.com/profile.jpg" });
9385
+ * if (res.recommended_action === "remove") {
9386
+ * // Block the user profile from being created
9387
+ * } else {
9388
+ * // Allow the user profile to be created
9389
+ * }
9390
+ * ```
9391
+ *
9392
+ * @param userId
9393
+ * @param profile.username
9394
+ * @param profile.image
9395
+ * @returns
9396
+ */
9397
+
9398
+ }, {
9399
+ key: "checkUserProfile",
9400
+ value: function () {
9401
+ var _checkUserProfile = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee14(userId, profile) {
9402
+ var moderationPayload;
9403
+ return _regeneratorRuntime__default['default'].wrap(function _callee14$(_context14) {
9404
+ while (1) {
9405
+ switch (_context14.prev = _context14.next) {
9406
+ case 0:
9407
+ if (!(!profile.username && !profile.image)) {
9408
+ _context14.next = 2;
9409
+ break;
9410
+ }
9411
+
9412
+ throw new Error('Either username or image must be provided');
9413
+
9414
+ case 2:
9415
+ moderationPayload = {};
9416
+
9417
+ if (profile.username) {
9418
+ moderationPayload.texts = [profile.username];
9419
+ }
9420
+
9421
+ if (profile.image) {
9422
+ moderationPayload.images = [profile.image];
9423
+ }
9424
+
9425
+ _context14.next = 7;
9426
+ return this.check(MODERATION_ENTITY_TYPES.userprofile, userId, userId, moderationPayload, 'user_profile:default', {
9427
+ force_sync: true,
9428
+ test_mode: true
9429
+ });
9430
+
9431
+ case 7:
9432
+ return _context14.abrupt("return", _context14.sent);
9433
+
9434
+ case 8:
9435
+ case "end":
9436
+ return _context14.stop();
9437
+ }
9438
+ }
9439
+ }, _callee14, this);
9440
+ }));
9441
+
9442
+ function checkUserProfile(_x28, _x29) {
9443
+ return _checkUserProfile.apply(this, arguments);
9444
+ }
9445
+
9446
+ return checkUserProfile;
9447
+ }()
9234
9448
  /**
9235
9449
  *
9236
9450
  * @param {string} entityType string Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string
@@ -9247,12 +9461,12 @@ var Moderation = /*#__PURE__*/function () {
9247
9461
  }, {
9248
9462
  key: "addCustomFlags",
9249
9463
  value: function () {
9250
- var _addCustomFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee14(entityType, entityID, entityCreatorID, moderationPayload, flags) {
9251
- return _regeneratorRuntime__default['default'].wrap(function _callee14$(_context14) {
9464
+ var _addCustomFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee15(entityType, entityID, entityCreatorID, moderationPayload, flags) {
9465
+ return _regeneratorRuntime__default['default'].wrap(function _callee15$(_context15) {
9252
9466
  while (1) {
9253
- switch (_context14.prev = _context14.next) {
9467
+ switch (_context15.prev = _context15.next) {
9254
9468
  case 0:
9255
- _context14.next = 2;
9469
+ _context15.next = 2;
9256
9470
  return this.client.post(this.client.baseURL + "/api/v2/moderation/custom_check", {
9257
9471
  entity_type: entityType,
9258
9472
  entity_id: entityID,
@@ -9262,17 +9476,17 @@ var Moderation = /*#__PURE__*/function () {
9262
9476
  });
9263
9477
 
9264
9478
  case 2:
9265
- return _context14.abrupt("return", _context14.sent);
9479
+ return _context15.abrupt("return", _context15.sent);
9266
9480
 
9267
9481
  case 3:
9268
9482
  case "end":
9269
- return _context14.stop();
9483
+ return _context15.stop();
9270
9484
  }
9271
9485
  }
9272
- }, _callee14, this);
9486
+ }, _callee15, this);
9273
9487
  }));
9274
9488
 
9275
- function addCustomFlags(_x28, _x29, _x30, _x31, _x32) {
9489
+ function addCustomFlags(_x30, _x31, _x32, _x33, _x34) {
9276
9490
  return _addCustomFlags.apply(this, arguments);
9277
9491
  }
9278
9492
 
@@ -9288,26 +9502,26 @@ var Moderation = /*#__PURE__*/function () {
9288
9502
  }, {
9289
9503
  key: "addCustomMessageFlags",
9290
9504
  value: function () {
9291
- var _addCustomMessageFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee15(messageID, flags) {
9292
- return _regeneratorRuntime__default['default'].wrap(function _callee15$(_context15) {
9505
+ var _addCustomMessageFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee16(messageID, flags) {
9506
+ return _regeneratorRuntime__default['default'].wrap(function _callee16$(_context16) {
9293
9507
  while (1) {
9294
- switch (_context15.prev = _context15.next) {
9508
+ switch (_context16.prev = _context16.next) {
9295
9509
  case 0:
9296
- _context15.next = 2;
9510
+ _context16.next = 2;
9297
9511
  return this.addCustomFlags(MODERATION_ENTITY_TYPES.message, messageID, '', {}, flags);
9298
9512
 
9299
9513
  case 2:
9300
- return _context15.abrupt("return", _context15.sent);
9514
+ return _context16.abrupt("return", _context16.sent);
9301
9515
 
9302
9516
  case 3:
9303
9517
  case "end":
9304
- return _context15.stop();
9518
+ return _context16.stop();
9305
9519
  }
9306
9520
  }
9307
- }, _callee15, this);
9521
+ }, _callee16, this);
9308
9522
  }));
9309
9523
 
9310
- function addCustomMessageFlags(_x33, _x34) {
9524
+ function addCustomMessageFlags(_x35, _x36) {
9311
9525
  return _addCustomMessageFlags.apply(this, arguments);
9312
9526
  }
9313
9527
 
@@ -12364,7 +12578,8 @@ var StreamChat = /*#__PURE__*/function () {
12364
12578
  // making sure cookies are not sent
12365
12579
  warmUp: false,
12366
12580
  recoverStateOnReconnect: true,
12367
- disableCache: false
12581
+ disableCache: false,
12582
+ wsUrlParams: new URLSearchParams({})
12368
12583
  }, inputOptions);
12369
12584
 
12370
12585
  if (this.node && !this.options.httpsAgent) {
@@ -16124,7 +16339,7 @@ var StreamChat = /*#__PURE__*/function () {
16124
16339
  return this.userAgent;
16125
16340
  }
16126
16341
 
16127
- var version = "8.57.6";
16342
+ var version = "8.58.0";
16128
16343
  var clientBundle = "";
16129
16344
  var userAgentString = '';
16130
16345
 
@@ -18370,6 +18585,51 @@ var StreamChat = /*#__PURE__*/function () {
18370
18585
 
18371
18586
  return updateFlags;
18372
18587
  }()
18588
+ /**
18589
+ * queryDrafts - Queries drafts for the current user
18590
+ *
18591
+ * @param {object} [options] Query options
18592
+ * @param {object} [options.filter] Filters for the query
18593
+ * @param {number} [options.sort] Sort parameters
18594
+ * @param {number} [options.limit] Limit the number of results
18595
+ * @param {string} [options.next] Pagination parameter
18596
+ * @param {string} [options.prev] Pagination parameter
18597
+ * @param {string} [options.user_id] Has to be provided when called server-side
18598
+ *
18599
+ * @return {Promise<APIResponse & { drafts: DraftResponse<StreamChatGenerics>[]; next?: string }>} Response containing the drafts
18600
+ */
18601
+
18602
+ }, {
18603
+ key: "queryDrafts",
18604
+ value: function () {
18605
+ var _queryDrafts = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee118() {
18606
+ var options,
18607
+ _args118 = arguments;
18608
+ return _regeneratorRuntime__default['default'].wrap(function _callee118$(_context118) {
18609
+ while (1) {
18610
+ switch (_context118.prev = _context118.next) {
18611
+ case 0:
18612
+ options = _args118.length > 0 && _args118[0] !== undefined ? _args118[0] : {};
18613
+ _context118.next = 3;
18614
+ return this.post(this.baseURL + '/drafts/query', options);
18615
+
18616
+ case 3:
18617
+ return _context118.abrupt("return", _context118.sent);
18618
+
18619
+ case 4:
18620
+ case "end":
18621
+ return _context118.stop();
18622
+ }
18623
+ }
18624
+ }, _callee118, this);
18625
+ }));
18626
+
18627
+ function queryDrafts() {
18628
+ return _queryDrafts.apply(this, arguments);
18629
+ }
18630
+
18631
+ return queryDrafts;
18632
+ }()
18373
18633
  }], [{
18374
18634
  key: "getInstance",
18375
18635
  value: function getInstance(key, secretOrOptions, options) {