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