stream-chat 8.57.6 → 8.59.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.
@@ -110,7 +110,7 @@ var Campaign = /*#__PURE__*/function () {
110
110
  key: "create",
111
111
  value: function () {
112
112
  var _create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
113
- var _this$data, _this$data2, _this$data3, _this$data4, _this$data5, _this$data6, _this$data7, _this$data8, _this$data9;
113
+ var _this$data, _this$data2, _this$data3, _this$data4, _this$data5, _this$data6, _this$data7, _this$data8, _this$data9, _this$data10, _this$data11, _this$data12;
114
114
 
115
115
  var body, result;
116
116
  return _regeneratorRuntime.wrap(function _callee$(_context) {
@@ -125,9 +125,12 @@ var Campaign = /*#__PURE__*/function () {
125
125
  sender_mode: (_this$data4 = this.data) === null || _this$data4 === void 0 ? void 0 : _this$data4.sender_mode,
126
126
  channel_template: (_this$data5 = this.data) === null || _this$data5 === void 0 ? void 0 : _this$data5.channel_template,
127
127
  create_channels: (_this$data6 = this.data) === null || _this$data6 === void 0 ? void 0 : _this$data6.create_channels,
128
- description: (_this$data7 = this.data) === null || _this$data7 === void 0 ? void 0 : _this$data7.description,
129
- name: (_this$data8 = this.data) === null || _this$data8 === void 0 ? void 0 : _this$data8.name,
130
- user_ids: (_this$data9 = this.data) === null || _this$data9 === void 0 ? void 0 : _this$data9.user_ids
128
+ show_channels: (_this$data7 = this.data) === null || _this$data7 === void 0 ? void 0 : _this$data7.show_channels,
129
+ description: (_this$data8 = this.data) === null || _this$data8 === void 0 ? void 0 : _this$data8.description,
130
+ name: (_this$data9 = this.data) === null || _this$data9 === void 0 ? void 0 : _this$data9.name,
131
+ skip_push: (_this$data10 = this.data) === null || _this$data10 === void 0 ? void 0 : _this$data10.skip_push,
132
+ skip_webhook: (_this$data11 = this.data) === null || _this$data11 === void 0 ? void 0 : _this$data11.skip_webhook,
133
+ user_ids: (_this$data12 = this.data) === null || _this$data12 === void 0 ? void 0 : _this$data12.user_ids
131
134
  };
132
135
  _context.next = 3;
133
136
  return this.client.createCampaign(body);
@@ -5007,6 +5010,134 @@ var Channel = /*#__PURE__*/function () {
5007
5010
 
5008
5011
  return removeVote;
5009
5012
  }()
5013
+ /**
5014
+ * createDraft - Creates or updates a draft message in a channel
5015
+ *
5016
+ * @param {string} channelType The channel type
5017
+ * @param {string} channelID The channel ID
5018
+ * @param {DraftMessagePayload<StreamChatGenerics>} message The draft message to create or update
5019
+ *
5020
+ * @return {Promise<CreateDraftResponse<StreamChatGenerics>>} Response containing the created draft
5021
+ */
5022
+
5023
+ }, {
5024
+ key: "createDraft",
5025
+ value: function () {
5026
+ var _createDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee50(message) {
5027
+ return _regeneratorRuntime.wrap(function _callee50$(_context50) {
5028
+ while (1) {
5029
+ switch (_context50.prev = _context50.next) {
5030
+ case 0:
5031
+ _context50.next = 2;
5032
+ return this.getClient().post(this._channelURL() + '/draft', {
5033
+ message: message
5034
+ });
5035
+
5036
+ case 2:
5037
+ return _context50.abrupt("return", _context50.sent);
5038
+
5039
+ case 3:
5040
+ case "end":
5041
+ return _context50.stop();
5042
+ }
5043
+ }
5044
+ }, _callee50, this);
5045
+ }));
5046
+
5047
+ function createDraft(_x53) {
5048
+ return _createDraft.apply(this, arguments);
5049
+ }
5050
+
5051
+ return createDraft;
5052
+ }()
5053
+ /**
5054
+ * deleteDraft - Deletes a draft message from a channel
5055
+ *
5056
+ * @param {Object} options
5057
+ * @param {string} options.parent_id Optional parent message ID for drafts in threads
5058
+ *
5059
+ * @return {Promise<APIResponse>} API response
5060
+ */
5061
+
5062
+ }, {
5063
+ key: "deleteDraft",
5064
+ value: function () {
5065
+ var _deleteDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee51() {
5066
+ var _ref2,
5067
+ parent_id,
5068
+ _args51 = arguments;
5069
+
5070
+ return _regeneratorRuntime.wrap(function _callee51$(_context51) {
5071
+ while (1) {
5072
+ switch (_context51.prev = _context51.next) {
5073
+ case 0:
5074
+ _ref2 = _args51.length > 0 && _args51[0] !== undefined ? _args51[0] : {}, parent_id = _ref2.parent_id;
5075
+ _context51.next = 3;
5076
+ return this.getClient().delete(this._channelURL() + '/draft', {
5077
+ parent_id: parent_id
5078
+ });
5079
+
5080
+ case 3:
5081
+ return _context51.abrupt("return", _context51.sent);
5082
+
5083
+ case 4:
5084
+ case "end":
5085
+ return _context51.stop();
5086
+ }
5087
+ }
5088
+ }, _callee51, this);
5089
+ }));
5090
+
5091
+ function deleteDraft() {
5092
+ return _deleteDraft.apply(this, arguments);
5093
+ }
5094
+
5095
+ return deleteDraft;
5096
+ }()
5097
+ /**
5098
+ * getDraft - Retrieves a draft message from a channel
5099
+ *
5100
+ * @param {Object} options
5101
+ * @param {string} options.parent_id Optional parent message ID for drafts in threads
5102
+ *
5103
+ * @return {Promise<GetDraftResponse<StreamChatGenerics>>} Response containing the draft
5104
+ */
5105
+
5106
+ }, {
5107
+ key: "getDraft",
5108
+ value: function () {
5109
+ var _getDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee52() {
5110
+ var _ref3,
5111
+ parent_id,
5112
+ _args52 = arguments;
5113
+
5114
+ return _regeneratorRuntime.wrap(function _callee52$(_context52) {
5115
+ while (1) {
5116
+ switch (_context52.prev = _context52.next) {
5117
+ case 0:
5118
+ _ref3 = _args52.length > 0 && _args52[0] !== undefined ? _args52[0] : {}, parent_id = _ref3.parent_id;
5119
+ _context52.next = 3;
5120
+ return this.getClient().get(this._channelURL() + '/draft', {
5121
+ parent_id: parent_id
5122
+ });
5123
+
5124
+ case 3:
5125
+ return _context52.abrupt("return", _context52.sent);
5126
+
5127
+ case 4:
5128
+ case "end":
5129
+ return _context52.stop();
5130
+ }
5131
+ }
5132
+ }, _callee52, this);
5133
+ }));
5134
+
5135
+ function getDraft() {
5136
+ return _getDraft.apply(this, arguments);
5137
+ }
5138
+
5139
+ return getDraft;
5140
+ }()
5010
5141
  /**
5011
5142
  * on - Listen to events on this channel.
5012
5143
  *
@@ -5217,18 +5348,18 @@ var Channel = /*#__PURE__*/function () {
5217
5348
  if ((_event$channel = event.channel) !== null && _event$channel !== void 0 && _event$channel.truncated_at) {
5218
5349
  var truncatedAt = +new Date(event.channel.truncated_at);
5219
5350
  channelState.messageSets.forEach(function (messageSet, messageSetIndex) {
5220
- messageSet.messages.forEach(function (_ref2) {
5221
- var createdAt = _ref2.created_at,
5222
- id = _ref2.id;
5351
+ messageSet.messages.forEach(function (_ref4) {
5352
+ var createdAt = _ref4.created_at,
5353
+ id = _ref4.id;
5223
5354
  if (truncatedAt > +createdAt) channelState.removeMessage({
5224
5355
  id: id,
5225
5356
  messageSetIndex: messageSetIndex
5226
5357
  });
5227
5358
  });
5228
5359
  });
5229
- channelState.pinnedMessages.forEach(function (_ref3) {
5230
- var id = _ref3.id,
5231
- createdAt = _ref3.created_at;
5360
+ channelState.pinnedMessages.forEach(function (_ref5) {
5361
+ var id = _ref5.id,
5362
+ createdAt = _ref5.created_at;
5232
5363
  if (truncatedAt > +createdAt) channelState.removePinnedMessage({
5233
5364
  id: id
5234
5365
  });
@@ -5528,10 +5659,10 @@ var Channel = /*#__PURE__*/function () {
5528
5659
  }
5529
5660
  }, {
5530
5661
  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;
5662
+ value: function _hydrateMembers(_ref6) {
5663
+ var members = _ref6.members,
5664
+ _ref6$overrideCurrent = _ref6.overrideCurrentState,
5665
+ overrideCurrentState = _ref6$overrideCurrent === void 0 ? true : _ref6$overrideCurrent;
5535
5666
  var newMembersById = members.reduce(function (membersById, member) {
5536
5667
  if (member.user) {
5537
5668
  membersById[member.user.id] = member;
@@ -5836,11 +5967,20 @@ var StableWSConnection = /*#__PURE__*/function () {
5836
5967
  _defineProperty(this, "wsID", void 0);
5837
5968
 
5838
5969
  _defineProperty(this, "_buildUrl", function () {
5839
- var qs = encodeURIComponent(_this.client._buildWSPayload(_this.requestID));
5970
+ var qs = _this.client._buildWSPayload(_this.requestID);
5840
5971
 
5841
5972
  var token = _this.client.tokenManager.getToken();
5842
5973
 
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()));
5974
+ var wsUrlParams = _this.client.options.wsUrlParams;
5975
+ var params = new URLSearchParams(wsUrlParams);
5976
+ params.set('json', qs);
5977
+ params.set('api_key', _this.client.key); // it is expected that the autorization parameter exists even if
5978
+ // the token is undefined, so we interpolate it to be safe
5979
+
5980
+ params.set('authorization', "".concat(token));
5981
+ params.set('stream-auth-type', _this.client.getAuthType());
5982
+ params.set('X-Stream-Client', _this.client.getUserAgent());
5983
+ return "".concat(_this.client.wsBaseURL, "/connect?").concat(params.toString());
5844
5984
  });
5845
5985
 
5846
5986
  _defineProperty(this, "onlineStatusChanged", function (event) {
@@ -8677,7 +8817,8 @@ function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if
8677
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; }
8678
8818
  var MODERATION_ENTITY_TYPES = {
8679
8819
  user: 'stream:user',
8680
- message: 'stream:chat:v1:message'
8820
+ message: 'stream:chat:v1:message',
8821
+ userprofile: 'stream:v1:user_profile'
8681
8822
  }; // Moderation class provides all the endpoints related to moderation v2.
8682
8823
 
8683
8824
  var Moderation = /*#__PURE__*/function () {
@@ -9200,6 +9341,82 @@ var Moderation = /*#__PURE__*/function () {
9200
9341
 
9201
9342
  return check;
9202
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
+ }()
9203
9420
  /**
9204
9421
  *
9205
9422
  * @param {string} entityType string Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string
@@ -9216,12 +9433,12 @@ var Moderation = /*#__PURE__*/function () {
9216
9433
  }, {
9217
9434
  key: "addCustomFlags",
9218
9435
  value: function () {
9219
- var _addCustomFlags = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(entityType, entityID, entityCreatorID, moderationPayload, flags) {
9220
- 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) {
9221
9438
  while (1) {
9222
- switch (_context14.prev = _context14.next) {
9439
+ switch (_context15.prev = _context15.next) {
9223
9440
  case 0:
9224
- _context14.next = 2;
9441
+ _context15.next = 2;
9225
9442
  return this.client.post(this.client.baseURL + "/api/v2/moderation/custom_check", {
9226
9443
  entity_type: entityType,
9227
9444
  entity_id: entityID,
@@ -9231,17 +9448,17 @@ var Moderation = /*#__PURE__*/function () {
9231
9448
  });
9232
9449
 
9233
9450
  case 2:
9234
- return _context14.abrupt("return", _context14.sent);
9451
+ return _context15.abrupt("return", _context15.sent);
9235
9452
 
9236
9453
  case 3:
9237
9454
  case "end":
9238
- return _context14.stop();
9455
+ return _context15.stop();
9239
9456
  }
9240
9457
  }
9241
- }, _callee14, this);
9458
+ }, _callee15, this);
9242
9459
  }));
9243
9460
 
9244
- function addCustomFlags(_x28, _x29, _x30, _x31, _x32) {
9461
+ function addCustomFlags(_x30, _x31, _x32, _x33, _x34) {
9245
9462
  return _addCustomFlags.apply(this, arguments);
9246
9463
  }
9247
9464
 
@@ -9257,26 +9474,26 @@ var Moderation = /*#__PURE__*/function () {
9257
9474
  }, {
9258
9475
  key: "addCustomMessageFlags",
9259
9476
  value: function () {
9260
- var _addCustomMessageFlags = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(messageID, flags) {
9261
- return _regeneratorRuntime.wrap(function _callee15$(_context15) {
9477
+ var _addCustomMessageFlags = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(messageID, flags) {
9478
+ return _regeneratorRuntime.wrap(function _callee16$(_context16) {
9262
9479
  while (1) {
9263
- switch (_context15.prev = _context15.next) {
9480
+ switch (_context16.prev = _context16.next) {
9264
9481
  case 0:
9265
- _context15.next = 2;
9482
+ _context16.next = 2;
9266
9483
  return this.addCustomFlags(MODERATION_ENTITY_TYPES.message, messageID, '', {}, flags);
9267
9484
 
9268
9485
  case 2:
9269
- return _context15.abrupt("return", _context15.sent);
9486
+ return _context16.abrupt("return", _context16.sent);
9270
9487
 
9271
9488
  case 3:
9272
9489
  case "end":
9273
- return _context15.stop();
9490
+ return _context16.stop();
9274
9491
  }
9275
9492
  }
9276
- }, _callee15, this);
9493
+ }, _callee16, this);
9277
9494
  }));
9278
9495
 
9279
- function addCustomMessageFlags(_x33, _x34) {
9496
+ function addCustomMessageFlags(_x35, _x36) {
9280
9497
  return _addCustomMessageFlags.apply(this, arguments);
9281
9498
  }
9282
9499
 
@@ -12333,7 +12550,8 @@ var StreamChat = /*#__PURE__*/function () {
12333
12550
  // making sure cookies are not sent
12334
12551
  warmUp: false,
12335
12552
  recoverStateOnReconnect: true,
12336
- disableCache: false
12553
+ disableCache: false,
12554
+ wsUrlParams: new URLSearchParams({})
12337
12555
  }, inputOptions);
12338
12556
 
12339
12557
  if (this.node && !this.options.httpsAgent) {
@@ -16093,7 +16311,7 @@ var StreamChat = /*#__PURE__*/function () {
16093
16311
  return this.userAgent;
16094
16312
  }
16095
16313
 
16096
- var version = "8.57.6";
16314
+ var version = "8.59.0";
16097
16315
  var clientBundle = "";
16098
16316
  var userAgentString = '';
16099
16317
 
@@ -18339,6 +18557,55 @@ var StreamChat = /*#__PURE__*/function () {
18339
18557
 
18340
18558
  return updateFlags;
18341
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
+ payload,
18580
+ _args118 = arguments;
18581
+ return _regeneratorRuntime.wrap(function _callee118$(_context118) {
18582
+ while (1) {
18583
+ switch (_context118.prev = _context118.next) {
18584
+ case 0:
18585
+ options = _args118.length > 0 && _args118[0] !== undefined ? _args118[0] : {};
18586
+ payload = _objectSpread$1(_objectSpread$1({}, options), {}, {
18587
+ sort: options.sort ? normalizeQuerySort(options.sort) : undefined
18588
+ });
18589
+ _context118.next = 4;
18590
+ return this.post(this.baseURL + '/drafts/query', payload);
18591
+
18592
+ case 4:
18593
+ return _context118.abrupt("return", _context118.sent);
18594
+
18595
+ case 5:
18596
+ case "end":
18597
+ return _context118.stop();
18598
+ }
18599
+ }
18600
+ }, _callee118, this);
18601
+ }));
18602
+
18603
+ function queryDrafts() {
18604
+ return _queryDrafts.apply(this, arguments);
18605
+ }
18606
+
18607
+ return queryDrafts;
18608
+ }()
18342
18609
  }], [{
18343
18610
  key: "getInstance",
18344
18611
  value: function getInstance(key, secretOrOptions, options) {