@twilio/conversations 3.0.1-rc.103 → 3.0.1

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.
Files changed (124) hide show
  1. package/README.md +2 -2
  2. package/builds/browser.esm.js +10846 -0
  3. package/builds/browser.esm.js.map +1 -0
  4. package/builds/browser.js +579 -218
  5. package/builds/browser.js.map +1 -1
  6. package/builds/lib.d.ts +40 -27
  7. package/builds/lib.esm.d.ts +3178 -0
  8. package/builds/lib.esm.js +10845 -0
  9. package/builds/lib.js +588 -218
  10. package/builds/lib.js.map +1 -1
  11. package/builds/twilio-conversations.js +9111 -10398
  12. package/builds/twilio-conversations.js.map +1 -0
  13. package/builds/twilio-conversations.min.js +2 -1
  14. package/builds/twilio-conversations.min.js.map +1 -0
  15. package/dist/aggregated-delivery-receipt.js +1 -5
  16. package/dist/aggregated-delivery-receipt.js.map +1 -1
  17. package/dist/channel-metadata-client.js +5 -10
  18. package/dist/channel-metadata-client.js.map +1 -1
  19. package/dist/client.js +218 -206
  20. package/dist/client.js.map +1 -1
  21. package/dist/command-executor.js +6 -10
  22. package/dist/command-executor.js.map +1 -1
  23. package/dist/configuration.js +6 -10
  24. package/dist/configuration.js.map +1 -1
  25. package/dist/content-client.js +5 -9
  26. package/dist/content-client.js.map +1 -1
  27. package/dist/content-template.js +1 -7
  28. package/dist/content-template.js.map +1 -1
  29. package/dist/conversation.js +166 -136
  30. package/dist/conversation.js.map +1 -1
  31. package/dist/data/conversations.js +44 -46
  32. package/dist/data/conversations.js.map +1 -1
  33. package/dist/data/messages.js +18 -22
  34. package/dist/data/messages.js.map +1 -1
  35. package/dist/data/participants.js +22 -25
  36. package/dist/data/participants.js.map +1 -1
  37. package/dist/data/users.js +10 -14
  38. package/dist/data/users.js.map +1 -1
  39. package/dist/detailed-delivery-receipt.js +1 -5
  40. package/dist/detailed-delivery-receipt.js.map +1 -1
  41. package/dist/index.js +17 -49
  42. package/dist/index.js.map +1 -1
  43. package/dist/interfaces/notification-types.js +1 -5
  44. package/dist/interfaces/notification-types.js.map +1 -1
  45. package/dist/interfaces/rules.js +7 -13
  46. package/dist/interfaces/rules.js.map +1 -1
  47. package/dist/logger.js +9 -29
  48. package/dist/logger.js.map +1 -1
  49. package/dist/media.js +32 -25
  50. package/dist/media.js.map +1 -1
  51. package/dist/message-builder.js +43 -47
  52. package/dist/message-builder.js.map +1 -1
  53. package/dist/message-recipients-client.js +10 -16
  54. package/dist/message-recipients-client.js.map +1 -1
  55. package/dist/message.js +114 -98
  56. package/dist/message.js.map +1 -1
  57. package/dist/node_modules/quick-lru/index.js +1 -5
  58. package/dist/node_modules/quick-lru/index.js.map +1 -1
  59. package/dist/node_modules/tslib/tslib.es6.js +7 -6
  60. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  61. package/dist/packages/conversations/package.json.js +2 -6
  62. package/dist/packages/conversations/package.json.js.map +1 -1
  63. package/dist/participant.js +32 -37
  64. package/dist/participant.js.map +1 -1
  65. package/dist/push-notification.js +1 -5
  66. package/dist/push-notification.js.map +1 -1
  67. package/dist/rest-paginator.js +1 -5
  68. package/dist/rest-paginator.js.map +1 -1
  69. package/dist/services/network.js +3 -7
  70. package/dist/services/network.js.map +1 -1
  71. package/dist/services/typing-indicator.js +7 -10
  72. package/dist/services/typing-indicator.js.map +1 -1
  73. package/dist/unsent-message.js +5 -9
  74. package/dist/unsent-message.js.map +1 -1
  75. package/dist/user.js +21 -30
  76. package/dist/user.js.map +1 -1
  77. package/dist/util/deferred.js +1 -5
  78. package/dist/util/deferred.js.map +1 -1
  79. package/dist/util/index.js +36 -9
  80. package/dist/util/index.js.map +1 -1
  81. package/dist/utils/uuid.js +145 -0
  82. package/dist/utils/uuid.js.map +1 -0
  83. package/package.json +14 -17
  84. package/docs/assets/css/main.css +0 -2660
  85. package/docs/assets/images/icons.png +0 -0
  86. package/docs/assets/images/icons@2x.png +0 -0
  87. package/docs/assets/images/widgets.png +0 -0
  88. package/docs/assets/images/widgets@2x.png +0 -0
  89. package/docs/assets/js/main.js +0 -248
  90. package/docs/assets/js/search.js +0 -1
  91. package/docs/classes/AggregatedDeliveryReceipt.html +0 -3184
  92. package/docs/classes/CancellablePromise.html +0 -3213
  93. package/docs/classes/ChannelMetadata.html +0 -3050
  94. package/docs/classes/Client.html +0 -4278
  95. package/docs/classes/ContentTemplate.html +0 -3116
  96. package/docs/classes/ContentTemplateVariable.html +0 -3116
  97. package/docs/classes/Conversation.html +0 -4382
  98. package/docs/classes/DetailedDeliveryReceipt.html +0 -3163
  99. package/docs/classes/EmailRecipientDescriptor.html +0 -3098
  100. package/docs/classes/Media.html +0 -3167
  101. package/docs/classes/Message.html +0 -3826
  102. package/docs/classes/MessageBuilder.html +0 -3318
  103. package/docs/classes/Participant.html +0 -3444
  104. package/docs/classes/PushNotification.html +0 -3130
  105. package/docs/classes/RestPaginator.html +0 -3160
  106. package/docs/classes/UnknownRecipientDescriptor.html +0 -3067
  107. package/docs/classes/UnsentMessage.html +0 -3042
  108. package/docs/classes/User.html +0 -3349
  109. package/docs/index.html +0 -4373
  110. package/docs/interfaces/ClientOptions.html +0 -3066
  111. package/docs/interfaces/ConversationBindings.html +0 -3001
  112. package/docs/interfaces/ConversationEmailBinding.html +0 -3001
  113. package/docs/interfaces/ConversationLimits.html +0 -3098
  114. package/docs/interfaces/ConversationState.html +0 -3050
  115. package/docs/interfaces/ConversationUpdatedEventArgs.html +0 -3001
  116. package/docs/interfaces/CreateConversationOptions.html +0 -3066
  117. package/docs/interfaces/LastMessage.html +0 -3050
  118. package/docs/interfaces/Paginator.html +0 -3141
  119. package/docs/interfaces/ParticipantBindings.html +0 -3001
  120. package/docs/interfaces/ParticipantEmailBinding.html +0 -3001
  121. package/docs/interfaces/PushNotificationData.html +0 -3114
  122. package/docs/interfaces/SendEmailOptions.html +0 -3034
  123. package/docs/interfaces/SendMediaOptions.html +0 -3068
  124. package/docs/modules.html +0 -4374
package/builds/lib.js CHANGED
@@ -128,6 +128,15 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  require('core-js/modules/es.reflect.to-string-tag.js');
@@ -145,10 +154,10 @@ var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
145
154
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
146
155
  var _createClass = require('@babel/runtime/helpers/createClass');
147
156
  var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
148
- require('core-js/modules/es.object.to-string.js');
149
- require('core-js/modules/es.promise.js');
150
157
  require('core-js/modules/es.array.map.js');
158
+ require('core-js/modules/es.object.to-string.js');
151
159
  require('core-js/modules/web.dom-collections.for-each.js');
160
+ require('core-js/modules/es.promise.js');
152
161
  var _regeneratorRuntime = require('@babel/runtime/regenerator');
153
162
  var _typeof = require('@babel/runtime/helpers/typeof');
154
163
  require('core-js/modules/es.array.concat.js');
@@ -167,7 +176,6 @@ var declarativeTypeValidator = require('@twilio/declarative-type-validator');
167
176
  var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
168
177
  require('core-js/modules/es.array.includes.js');
169
178
  var replayEventEmitter = require('@twilio/replay-event-emitter');
170
- var isEqual = require('lodash.isequal');
171
179
  require('core-js/modules/es.array.slice.js');
172
180
  require('core-js/modules/es.function.name.js');
173
181
  require('core-js/modules/es.regexp.test.js');
@@ -208,16 +216,15 @@ require('core-js/modules/es.typed-array.subarray.js');
208
216
  require('core-js/modules/es.typed-array.to-locale-string.js');
209
217
  require('core-js/modules/es.typed-array.to-string.js');
210
218
  require('core-js/modules/es.array-buffer.constructor.js');
211
- require('isomorphic-form-data');
212
219
  require('core-js/modules/es.array.sort.js');
213
220
  require('core-js/modules/es.string.includes.js');
214
221
  require('core-js/modules/es.string.starts-with.js');
222
+ require('core-js/modules/es.weak-set.js');
215
223
  var deprecationDecorator = require('@twilio/deprecation-decorator');
216
224
  require('core-js/modules/es.object.entries.js');
217
225
  require('core-js/modules/es.array.find.js');
218
226
  require('core-js/modules/es.array.splice.js');
219
227
  var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
220
- var uuid = require('uuid');
221
228
  require('core-js/modules/es.object.freeze.js');
222
229
 
223
230
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -252,7 +259,6 @@ var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regenerat
252
259
  var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
253
260
  var loglevelLog__namespace = /*#__PURE__*/_interopNamespace(loglevelLog);
254
261
  var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
255
- var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
256
262
  var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
257
263
  var _wrapNativeSuper__default = /*#__PURE__*/_interopDefaultLegacy(_wrapNativeSuper);
258
264
 
@@ -292,11 +298,13 @@ var Logger = /*#__PURE__*/function () {
292
298
  }, {
293
299
  key: "trace",
294
300
  value: function trace() {
295
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
296
- args[_key] = arguments[_key];
297
- }
301
+ if (log$7.getLevel() == log$7.levels.TRACE) {
302
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
303
+ args[_key] = arguments[_key];
304
+ }
298
305
 
299
- log$7.trace.apply(null, prepareLine(this.prefix + "T", args));
306
+ log$7.debug.apply(null, prepareLine(this.prefix + "T", args));
307
+ }
300
308
  }
301
309
  }, {
302
310
  key: "debug",
@@ -347,11 +355,13 @@ var Logger = /*#__PURE__*/function () {
347
355
  }, {
348
356
  key: "trace",
349
357
  value: function trace() {
350
- for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
351
- args[_key6] = arguments[_key6];
352
- }
358
+ if (log$7.getLevel() == log$7.levels.TRACE) {
359
+ for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
360
+ args[_key6] = arguments[_key6];
361
+ }
353
362
 
354
- log$7.trace.apply(null, prepareLine("T", args));
363
+ log$7.debug.apply(null, prepareLine("T", args));
364
+ }
355
365
  }
356
366
  }, {
357
367
  key: "debug",
@@ -561,6 +571,56 @@ var UriBuilder = /*#__PURE__*/function () {
561
571
 
562
572
  return UriBuilder;
563
573
  }();
574
+ /**
575
+ * Deep equality check for objects
576
+ * @param a - first value to compare
577
+ * @param b - second value to compare
578
+ * @returns true if values are deeply equal
579
+ */
580
+
581
+
582
+ function isEqual(a, b) {
583
+ if (a === b) {
584
+ return true;
585
+ }
586
+
587
+ if (a === null || b === null || a === undefined || b === undefined) {
588
+ return a === b;
589
+ }
590
+
591
+ if (_typeof__default["default"](a) !== _typeof__default["default"](b)) {
592
+ return false;
593
+ }
594
+
595
+ if (_typeof__default["default"](a) !== "object") {
596
+ return a === b;
597
+ }
598
+
599
+ if (Array.isArray(a) && Array.isArray(b)) {
600
+ if (a.length !== b.length) {
601
+ return false;
602
+ }
603
+
604
+ return a.every(function (item, index) {
605
+ return isEqual(item, b[index]);
606
+ });
607
+ }
608
+
609
+ if (Array.isArray(a) || Array.isArray(b)) {
610
+ return false;
611
+ }
612
+
613
+ var aKeys = Object.keys(a);
614
+ var bKeys = Object.keys(b);
615
+
616
+ if (aKeys.length !== bKeys.length) {
617
+ return false;
618
+ }
619
+
620
+ return aKeys.every(function (key) {
621
+ return isEqual(a[key], b[key]);
622
+ });
623
+ }
564
624
 
565
625
  var json = declarativeTypeValidator.custom(function (value) {
566
626
  return [["string", "number", "boolean", "object"].includes(_typeof__default["default"](value)), "a JSON type"];
@@ -641,6 +701,22 @@ var User = /*#__PURE__*/function (_ReplayEventEmitter) {
641
701
  * @event
642
702
  */
643
703
 
704
+ /**
705
+ * Fired when the client has subscribed to the user.
706
+ *
707
+ * Parameters:
708
+ * 1. {@link User} `user` - the user in question
709
+ * @event
710
+ */
711
+
712
+ /**
713
+ * Fired when the client has unsubscribed from the user.
714
+ *
715
+ * Parameters:
716
+ * 1. {@link User} `user` - the user in question
717
+ * @event
718
+ */
719
+
644
720
 
645
721
  _createClass__default["default"](User, [{
646
722
  key: "identity",
@@ -735,7 +811,7 @@ var User = /*#__PURE__*/function (_ReplayEventEmitter) {
735
811
  case 9:
736
812
  updateAttributes = parseAttributes(value.value, "Retrieved malformed attributes from the server for user: ".concat(this.state.identity), log$6);
737
813
 
738
- if (!isEqual__default["default"](this.state.attributes, updateAttributes)) {
814
+ if (!isEqual(this.state.attributes, updateAttributes)) {
739
815
  this.state.attributes = updateAttributes;
740
816
  updateReasons.push("attributes");
741
817
  }
@@ -1313,6 +1389,24 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
1313
1389
  * @event
1314
1390
  */
1315
1391
 
1392
+ /**
1393
+ * Fired when the participant has stopped typing.
1394
+ *
1395
+ * Parameters:
1396
+ * 1. {@link Participant} `participant` - the participant in question
1397
+ * @event
1398
+ */
1399
+
1400
+ /**
1401
+ * Fired when the fields of the participant have been updated.
1402
+ *
1403
+ * Parameters:
1404
+ * 1. object `data` - info object provided with the event. It has the following properties:
1405
+ * * {@link Participant} participant - the participant in question
1406
+ * * {@link ParticipantUpdateReason}[] updateReasons - array of reasons for the update
1407
+ * @event
1408
+ */
1409
+
1316
1410
 
1317
1411
  _createClass__default["default"](Participant, [{
1318
1412
  key: "sid",
@@ -1439,8 +1533,9 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
1439
1533
  }
1440
1534
 
1441
1535
  this.state.isTyping = true;
1442
- this.emit("typingStarted", this);
1443
- this.conversation.emit("typingStarted", this);
1536
+ this.emit(Participant.typingStarted, this);
1537
+ this.conversation.emit(Conversation.typingStarted, this); // @fixme layering violation
1538
+
1444
1539
  this.state.typingTimeout = Number(setTimeout(function () {
1445
1540
  return _this2._endTyping();
1446
1541
  }, timeout));
@@ -1459,8 +1554,8 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
1459
1554
  }
1460
1555
 
1461
1556
  this.state.isTyping = false;
1462
- this.emit("typingEnded", this);
1463
- this.conversation.emit("typingEnded", this);
1557
+ this.emit(Participant.typingEnded, this);
1558
+ this.conversation.emit(Conversation.typingEnded, this);
1464
1559
  clearInterval(this.state.typingTimeout);
1465
1560
  this.state.typingTimeout = null;
1466
1561
  }
@@ -1475,7 +1570,7 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
1475
1570
  var updateReasons = [];
1476
1571
  var updateAttributes = parseAttributes(data.attributes, "Retrieved malformed attributes from the server for participant: " + this.state.sid, log$5);
1477
1572
 
1478
- if (data.attributes && !isEqual__default["default"](this.state.attributes, updateAttributes)) {
1573
+ if (data.attributes && !isEqual(this.state.attributes, updateAttributes)) {
1479
1574
  this.state.attributes = updateAttributes;
1480
1575
  updateReasons.push("attributes");
1481
1576
  }
@@ -1513,13 +1608,13 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
1513
1608
  }
1514
1609
  }
1515
1610
 
1516
- if (data.bindings && !isEqual__default["default"](this.state.bindings, data.bindings)) {
1611
+ if (data.bindings && !isEqual(this.state.bindings, data.bindings)) {
1517
1612
  this.state.bindings = data.bindings;
1518
1613
  updateReasons.push("bindings");
1519
1614
  }
1520
1615
 
1521
1616
  if (updateReasons.length > 0) {
1522
- this.emit("updated", {
1617
+ this.emit(Participant.updated, {
1523
1618
  participant: this,
1524
1619
  updateReasons: updateReasons
1525
1620
  });
@@ -1655,7 +1750,8 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
1655
1750
 
1656
1751
  var _super = _createSuper$7(Participants);
1657
1752
 
1658
- function Participants(conversation, participants, links, configuration, services) {
1753
+ // passed in from Conversation
1754
+ function Participants(conversation, participants, links, services) {
1659
1755
  var _this;
1660
1756
 
1661
1757
  _classCallCheck__default["default"](this, Participants);
@@ -1667,7 +1763,6 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
1667
1763
  _this.conversation = conversation;
1668
1764
  _this.participants = participants;
1669
1765
  _this.links = links;
1670
- _this.configuration = configuration;
1671
1766
  _this.services = services;
1672
1767
  return _this;
1673
1768
  }
@@ -1718,14 +1813,14 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
1718
1813
  mode: "open_existing"
1719
1814
  }) : Promise.resolve(arg);
1720
1815
  return this.rosterEntityPromise = this.rosterEntityPromise || participantsMapPromise.then(function (rosterMap) {
1721
- rosterMap.on("itemAdded", function (args) {
1816
+ rosterMap.on(twilioSync.SyncMap.itemAdded, function (args) {
1722
1817
  log$4.debug(_this2.conversation.sid + " itemAdded: " + args.item.key);
1723
1818
 
1724
1819
  _this2.upsertParticipant(args.item.key, args.item.data).then(function (participant) {
1725
- _this2.emit("participantJoined", participant);
1820
+ _this2.emit(Conversation.participantJoined, participant);
1726
1821
  });
1727
1822
  });
1728
- rosterMap.on("itemRemoved", function (args) {
1823
+ rosterMap.on(twilioSync.SyncMap.itemRemoved, function (args) {
1729
1824
  log$4.debug(_this2.conversation.sid + " itemRemoved: " + args.key);
1730
1825
  var participantSid = args.key;
1731
1826
 
@@ -1741,12 +1836,14 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
1741
1836
  return;
1742
1837
  }
1743
1838
 
1744
- _this2.emit("participantLeft", leftParticipant);
1839
+ _this2.emit(Conversation.participantLeft, leftParticipant);
1745
1840
  });
1746
- rosterMap.on("itemUpdated", function (args) {
1841
+ rosterMap.on(twilioSync.SyncMap.itemUpdated, function (args) {
1747
1842
  log$4.debug(_this2.conversation.sid + " itemUpdated: " + args.item.key);
1748
1843
 
1749
- _this2.upsertParticipant(args.item.key, args.item.data);
1844
+ _this2.upsertParticipant(args.item.key, args.item.data).catch(function (e) {
1845
+ return log$4.error(e);
1846
+ });
1750
1847
  });
1751
1848
  var participantsPromises = [];
1752
1849
 
@@ -1840,8 +1937,8 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
1840
1937
  };
1841
1938
  participant = new Participant(data, participantSid, this.conversation, links, this.services);
1842
1939
  this.participants.set(participantSid, participant);
1843
- participant.on("updated", function (args) {
1844
- return _this3.emit("participantUpdated", args);
1940
+ participant.on(Participant.updated, function (args) {
1941
+ return _this3.emit(Conversation.participantUpdated, args);
1845
1942
  });
1846
1943
  return _context3.abrupt("return", participant);
1847
1944
 
@@ -2105,6 +2202,8 @@ var Media = /*#__PURE__*/function () {
2105
2202
  * @internal
2106
2203
  */
2107
2204
  function Media(data, services) {
2205
+ var _data$filename;
2206
+
2108
2207
  _classCallCheck__default["default"](this, Media);
2109
2208
 
2110
2209
  _defineProperty__default["default"](this, "mcsMedia", null);
@@ -2118,7 +2217,7 @@ var Media = /*#__PURE__*/function () {
2118
2217
  this.state = {
2119
2218
  sid: data.sid,
2120
2219
  category: data.category,
2121
- filename: data.filename,
2220
+ filename: (_data$filename = data.filename) !== null && _data$filename !== void 0 ? _data$filename : null,
2122
2221
  contentType: data.contentType,
2123
2222
  size: data.size
2124
2223
  };
@@ -2191,10 +2290,12 @@ var Media = /*#__PURE__*/function () {
2191
2290
  while (1) {
2192
2291
  switch (_context.prev = _context.next) {
2193
2292
  case 0:
2194
- fetchMediaRequest = _this._fetchMcsMedia();
2293
+ fetchMediaRequest = _this.mcsMedia ? undefined : _this._fetchMcsMedia();
2195
2294
  contentUrlRequest = (_this$mcsMedia = _this.mcsMedia) === null || _this$mcsMedia === void 0 ? void 0 : _this$mcsMedia.getContentUrl();
2196
2295
  onCancel(function () {
2197
- fetchMediaRequest.cancel();
2296
+ if (fetchMediaRequest) {
2297
+ fetchMediaRequest.cancel();
2298
+ }
2198
2299
 
2199
2300
  if (contentUrlRequest) {
2200
2301
  contentUrlRequest.cancel();
@@ -2202,7 +2303,7 @@ var Media = /*#__PURE__*/function () {
2202
2303
  });
2203
2304
  _context.prev = 3;
2204
2305
 
2205
- if (_this.mcsMedia) {
2306
+ if (contentUrlRequest) {
2206
2307
  _context.next = 9;
2207
2308
  break;
2208
2309
  }
@@ -2212,7 +2313,7 @@ var Media = /*#__PURE__*/function () {
2212
2313
 
2213
2314
  case 7:
2214
2315
  mcsMedia = _context.sent;
2215
- contentUrlRequest = mcsMedia.getContentUrl();
2316
+ contentUrlRequest = mcsMedia === null || mcsMedia === void 0 ? void 0 : mcsMedia.getContentUrl();
2216
2317
 
2217
2318
  case 9:
2218
2319
  _context.t0 = resolve;
@@ -2269,13 +2370,11 @@ var Media = /*#__PURE__*/function () {
2269
2370
  while (1) {
2270
2371
  switch (_context2.prev = _context2.next) {
2271
2372
  case 0:
2272
- request = _this2.services.mcsClient.get(_this2.state.sid);
2273
-
2274
- if (!_this2.services.mcsClient) {
2275
- _context2.next = 14;
2276
- break;
2373
+ if (_this2.services.mcsClient === null) {
2374
+ reject(new Error("Media Content Service is unavailable"));
2277
2375
  }
2278
2376
 
2377
+ request = _this2.services.mcsClient.get(_this2.state.sid);
2279
2378
  onCancel(function () {
2280
2379
  return request.cancel();
2281
2380
  });
@@ -2285,27 +2384,22 @@ var Media = /*#__PURE__*/function () {
2285
2384
 
2286
2385
  case 6:
2287
2386
  _this2.mcsMedia = _context2.sent;
2387
+ _this2.state = _this2.mcsMedia._state();
2288
2388
  resolve(_this2.mcsMedia);
2289
- _context2.next = 13;
2389
+ _context2.next = 14;
2290
2390
  break;
2291
2391
 
2292
- case 10:
2293
- _context2.prev = 10;
2392
+ case 11:
2393
+ _context2.prev = 11;
2294
2394
  _context2.t0 = _context2["catch"](3);
2295
2395
  reject(_context2.t0);
2296
2396
 
2297
- case 13:
2298
- return _context2.abrupt("return");
2299
-
2300
2397
  case 14:
2301
- reject(new Error("Media Content Service is unavailable"));
2302
-
2303
- case 15:
2304
2398
  case "end":
2305
2399
  return _context2.stop();
2306
2400
  }
2307
2401
  }
2308
- }, _callee2, null, [[3, 10]]);
2402
+ }, _callee2, null, [[3, 11]]);
2309
2403
  }));
2310
2404
 
2311
2405
  return function (_x4, _x5, _x6) {
@@ -2313,6 +2407,15 @@ var Media = /*#__PURE__*/function () {
2313
2407
  };
2314
2408
  }());
2315
2409
  }
2410
+ /**
2411
+ * @internal
2412
+ */
2413
+
2414
+ }, {
2415
+ key: "_state",
2416
+ value: function _state() {
2417
+ return this.state;
2418
+ }
2316
2419
  }]);
2317
2420
 
2318
2421
  return Media;
@@ -2810,6 +2913,12 @@ function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) {
2810
2913
  function _createSuper$6(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$6(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
2811
2914
 
2812
2915
  function _isNativeReflectConstruct$6() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2916
+
2917
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
2918
+
2919
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
2920
+
2921
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
2813
2922
  var log$3 = Logger.scope("Message");
2814
2923
 
2815
2924
  var XHR = // eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -2819,6 +2928,10 @@ global["XMLHttpRequest"] || require("xmlhttprequest").XMLHttpRequest;
2819
2928
  */
2820
2929
 
2821
2930
 
2931
+ var _wrapMedia = /*#__PURE__*/new WeakSet();
2932
+
2933
+ var _assignMedias = /*#__PURE__*/new WeakSet();
2934
+
2822
2935
  var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2823
2936
  _inherits__default["default"](Message, _ReplayEventEmitter);
2824
2937
 
@@ -2832,13 +2945,18 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2832
2945
  * @internal
2833
2946
  */
2834
2947
  function Message(index, data, conversation, links, configuration, services) {
2835
- var _data$text, _data$lastUpdatedBy, _data$type, _data$memberSid, _data$channelMetadata;
2948
+ var _data$text, _data$lastUpdatedBy, _data$type, _data$memberSid, _data$channelMetadata, _data$medias, _data$media;
2836
2949
 
2837
2950
  var _this;
2838
2951
 
2839
2952
  _classCallCheck__default["default"](this, Message);
2840
2953
 
2841
2954
  _this = _super.call(this);
2955
+
2956
+ _classPrivateMethodInitSpec(_assertThisInitialized__default["default"](_this), _assignMedias);
2957
+
2958
+ _classPrivateMethodInitSpec(_assertThisInitialized__default["default"](_this), _wrapMedia);
2959
+
2842
2960
  _this.conversation = conversation;
2843
2961
  _this.links = links;
2844
2962
  _this.configuration = configuration;
@@ -2855,16 +2973,15 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2855
2973
  lastUpdatedBy: (_data$lastUpdatedBy = data.lastUpdatedBy) !== null && _data$lastUpdatedBy !== void 0 ? _data$lastUpdatedBy : null,
2856
2974
  attributes: parseAttributes(data.attributes, "Got malformed attributes for the message ".concat(data.sid), log$3),
2857
2975
  type: (_data$type = data.type) !== null && _data$type !== void 0 ? _data$type : "text",
2858
- media: data.type === "media" && data.media ? new Media(data.media, _this.services) : null,
2859
- medias: data.type === "media" && data.medias ? data.medias.map(function (m) {
2860
- return new Media(m, _this.services);
2861
- }) : data.type === "media" && data.media && !data.medias ? [new Media(_objectSpread$4(_objectSpread$4({}, data.media), {}, {
2862
- category: "media"
2863
- }), _this.services)] : null,
2976
+ media: null,
2977
+ medias: null,
2864
2978
  participantSid: (_data$memberSid = data.memberSid) !== null && _data$memberSid !== void 0 ? _data$memberSid : null,
2865
2979
  aggregatedDeliveryReceipt: data.delivery ? new AggregatedDeliveryReceipt(data.delivery) : null,
2866
2980
  hasChannelMetadata: (_data$channelMetadata = data.channelMetadata) !== null && _data$channelMetadata !== void 0 ? _data$channelMetadata : false
2867
2981
  };
2982
+
2983
+ _classPrivateMethodGet(_assertThisInitialized__default["default"](_this), _assignMedias, _assignMedias2).call(_assertThisInitialized__default["default"](_this), (_data$medias = data.medias) !== null && _data$medias !== void 0 ? _data$medias : null, (_data$media = data.media) !== null && _data$media !== void 0 ? _data$media : null);
2984
+
2868
2985
  return _this;
2869
2986
  }
2870
2987
  /**
@@ -3086,6 +3203,12 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3086
3203
  }, {
3087
3204
  key: "_update",
3088
3205
  value: function _update(data) {
3206
+ var _data$medias2,
3207
+ _this2 = this,
3208
+ _this$state$medias2,
3209
+ _classPrivateMethodGe2,
3210
+ _this$state$media;
3211
+
3089
3212
  var updateReasons = [];
3090
3213
 
3091
3214
  if ((data.text || typeof data.text === "string") && data.text !== this.state.body) {
@@ -3120,7 +3243,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3120
3243
 
3121
3244
  var updatedAttributes = parseAttributes(data.attributes, "Got malformed attributes for the message ".concat(this.sid), log$3);
3122
3245
 
3123
- if (!isEqual__default["default"](this.state.attributes, updatedAttributes)) {
3246
+ if (!isEqual(this.state.attributes, updatedAttributes)) {
3124
3247
  this.state.attributes = updatedAttributes;
3125
3248
  updateReasons.push("attributes");
3126
3249
  }
@@ -3138,6 +3261,29 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3138
3261
 
3139
3262
  updateReasons.push("deliveryReceipt");
3140
3263
  }
3264
+ } // @fixme: This is a fairly heavy check.
3265
+ // Map data back and forth to perform a necessary field massage.
3266
+
3267
+
3268
+ var input = ((_data$medias2 = data.medias) !== null && _data$medias2 !== void 0 ? _data$medias2 : []).map(function (value) {
3269
+ var _classPrivateMethodGe;
3270
+
3271
+ return (_classPrivateMethodGe = _classPrivateMethodGet(_this2, _wrapMedia, _wrapMedia2).call(_this2, value)) === null || _classPrivateMethodGe === void 0 ? void 0 : _classPrivateMethodGe._state();
3272
+ }).filter(function (el) {
3273
+ return !(el === null);
3274
+ });
3275
+ var current = ((_this$state$medias2 = this.state.medias) !== null && _this$state$medias2 !== void 0 ? _this$state$medias2 : []).map(function (value) {
3276
+ return value._state();
3277
+ }).filter(function (el) {
3278
+ return !(el === null);
3279
+ });
3280
+
3281
+ if (!isEqual(input, current) || !isEqual((_classPrivateMethodGe2 = _classPrivateMethodGet(this, _wrapMedia, _wrapMedia2).call(this, data.media)) === null || _classPrivateMethodGe2 === void 0 ? void 0 : _classPrivateMethodGe2._state(), (_this$state$media = this.state.media) === null || _this$state$media === void 0 ? void 0 : _this$state$media._state())) {
3282
+ var _data$medias3, _data$media2;
3283
+
3284
+ _classPrivateMethodGet(this, _assignMedias, _assignMedias2).call(this, (_data$medias3 = data.medias) !== null && _data$medias3 !== void 0 ? _data$medias3 : null, (_data$media2 = data.media) !== null && _data$media2 !== void 0 ? _data$media2 : null);
3285
+
3286
+ updateReasons.push("media");
3141
3287
  }
3142
3288
 
3143
3289
  if (updateReasons.length > 0) {
@@ -3155,9 +3301,9 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3155
3301
  key: "getParticipant",
3156
3302
  value: function () {
3157
3303
  var _getParticipant = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
3158
- var _this2 = this;
3304
+ var _this3 = this;
3159
3305
 
3160
- var participant, errorMesage;
3306
+ var participant, errorMessage;
3161
3307
  return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
3162
3308
  while (1) {
3163
3309
  switch (_context.prev = _context.next) {
@@ -3171,7 +3317,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3171
3317
 
3172
3318
  _context.next = 4;
3173
3319
  return this.conversation.getParticipantBySid(this.state.participantSid).catch(function () {
3174
- log$3.debug("Participant with sid \"".concat(_this2.participantSid, "\" not found for message ").concat(_this2.sid));
3320
+ log$3.debug("Participant with sid \"".concat(_this3.participantSid, "\" not found for message ").concat(_this3.sid));
3175
3321
  return null;
3176
3322
  });
3177
3323
 
@@ -3186,7 +3332,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3186
3332
 
3187
3333
  _context.next = 8;
3188
3334
  return this.conversation.getParticipantByIdentity(this.state.author).catch(function () {
3189
- log$3.debug("Participant with identity \"".concat(_this2.author, "\" not found for message ").concat(_this2.sid));
3335
+ log$3.debug("Participant with identity \"".concat(_this3.author, "\" not found for message ").concat(_this3.sid));
3190
3336
  return null;
3191
3337
  });
3192
3338
 
@@ -3202,26 +3348,26 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3202
3348
  return _context.abrupt("return", participant);
3203
3349
 
3204
3350
  case 11:
3205
- errorMesage = "Participant with ";
3351
+ errorMessage = "Participant with ";
3206
3352
 
3207
3353
  if (this.state.participantSid) {
3208
- errorMesage += "SID '" + this.state.participantSid + "' ";
3354
+ errorMessage += "SID '" + this.state.participantSid + "' ";
3209
3355
  }
3210
3356
 
3211
3357
  if (this.state.author) {
3212
3358
  if (this.state.participantSid) {
3213
- errorMesage += "or ";
3359
+ errorMessage += "or ";
3214
3360
  }
3215
3361
 
3216
- errorMesage += "identity '" + this.state.author + "' ";
3362
+ errorMessage += "identity '" + this.state.author + "' ";
3217
3363
  }
3218
3364
 
3219
- if (errorMesage === "Participant with ") {
3220
- errorMesage = "Participant ";
3365
+ if (errorMessage === "Participant with ") {
3366
+ errorMessage = "Participant ";
3221
3367
  }
3222
3368
 
3223
- errorMesage += "was not found";
3224
- throw new Error(errorMesage);
3369
+ errorMessage += "was not found";
3370
+ throw new Error(errorMessage);
3225
3371
 
3226
3372
  case 17:
3227
3373
  case "end":
@@ -3401,7 +3547,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3401
3547
  key: "attachTemporaryUrlsFor",
3402
3548
  value: function () {
3403
3549
  var _attachTemporaryUrlsFor = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(contentSet) {
3404
- var _this3 = this;
3550
+ var _this4 = this;
3405
3551
 
3406
3552
  var sids;
3407
3553
  return _regeneratorRuntime__default["default"].wrap(function _callee6$(_context6) {
@@ -3424,7 +3570,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3424
3570
 
3425
3571
  case 4:
3426
3572
  return _context6.abrupt("return", _context6.sent.map(function (item) {
3427
- return new Media(item, _this3.services);
3573
+ return new Media(item, _this4.services);
3428
3574
  }));
3429
3575
 
3430
3576
  case 7:
@@ -3467,7 +3613,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3467
3613
  }, {
3468
3614
  key: "getTemporaryContentUrlsForMediaSids",
3469
3615
  value: function getTemporaryContentUrlsForMediaSids(mediaSids) {
3470
- var _this4 = this;
3616
+ var _this5 = this;
3471
3617
 
3472
3618
  return new mcsClient.CancellablePromise( /*#__PURE__*/function () {
3473
3619
  var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee7(resolve, reject, onCancel) {
@@ -3476,9 +3622,9 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3476
3622
  while (1) {
3477
3623
  switch (_context7.prev = _context7.next) {
3478
3624
  case 0:
3479
- mediaGetRequest = _this4.services.mcsClient.mediaSetGetContentUrls(mediaSids !== null && mediaSids !== void 0 ? mediaSids : []);
3625
+ mediaGetRequest = _this5.services.mcsClient.mediaSetGetContentUrls(mediaSids !== null && mediaSids !== void 0 ? mediaSids : []);
3480
3626
 
3481
- if (!(!_this4.services.mcsClient || !mediaSids)) {
3627
+ if (!(!_this5.services.mcsClient || !mediaSids)) {
3482
3628
  _context7.next = 4;
3483
3629
  break;
3484
3630
  }
@@ -3537,7 +3683,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3537
3683
  key: "_getDetailedDeliveryReceiptsPaginator",
3538
3684
  value: function () {
3539
3685
  var _getDetailedDeliveryReceiptsPaginator2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee8(options) {
3540
- var _this5 = this;
3686
+ var _this6 = this;
3541
3687
 
3542
3688
  var messagesReceiptsUrl, url, response;
3543
3689
  return _regeneratorRuntime__default["default"].wrap(function _callee8$(_context8) {
@@ -3554,7 +3700,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3554
3700
  return _context8.abrupt("return", new RestPaginator(response.body.delivery_receipts.map(function (x) {
3555
3701
  return new DetailedDeliveryReceipt(x);
3556
3702
  }), function (pageToken, pageSize) {
3557
- return _this5._getDetailedDeliveryReceiptsPaginator({
3703
+ return _this6._getDetailedDeliveryReceiptsPaginator({
3558
3704
  pageToken: pageToken,
3559
3705
  pageSize: pageSize
3560
3706
  });
@@ -3582,7 +3728,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3582
3728
  }, {
3583
3729
  key: "getContentData",
3584
3730
  value: function getContentData() {
3585
- var _this6 = this;
3731
+ var _this7 = this;
3586
3732
 
3587
3733
  return new mcsClient.CancellablePromise( /*#__PURE__*/function () {
3588
3734
  var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee9(resolve, reject, onCancel) {
@@ -3591,7 +3737,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3591
3737
  while (1) {
3592
3738
  switch (_context9.prev = _context9.next) {
3593
3739
  case 0:
3594
- if (!(_this6.state.contentSid === null)) {
3740
+ if (!(_this7.state.contentSid === null)) {
3595
3741
  _context9.next = 3;
3596
3742
  break;
3597
3743
  }
@@ -3600,7 +3746,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3600
3746
  return _context9.abrupt("return");
3601
3747
 
3602
3748
  case 3:
3603
- bodies = _this6.getMediaByCategories(["body"]);
3749
+ bodies = _this7.getMediaByCategories(["body"]);
3604
3750
 
3605
3751
  if (!(bodies === null)) {
3606
3752
  _context9.next = 7;
@@ -3793,6 +3939,28 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3793
3939
  return Message;
3794
3940
  }(replayEventEmitter.ReplayEventEmitter);
3795
3941
 
3942
+ function _wrapMedia2(media) {
3943
+ var category = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
3944
+ return media ? category ? new Media(_objectSpread$4(_objectSpread$4({}, media), {}, {
3945
+ category: category
3946
+ }), this.services) : new Media(media, this.services) : null;
3947
+ }
3948
+
3949
+ function _assignMedias2(medias, media) {
3950
+ var _this8 = this;
3951
+
3952
+ this.state.media = _classPrivateMethodGet(this, _wrapMedia, _wrapMedia2).call(this, media); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3953
+ // @ts-ignore
3954
+
3955
+ this.state.medias = medias ? medias.map(function (m) {
3956
+ return _classPrivateMethodGet(_this8, _wrapMedia, _wrapMedia2).call(_this8, m);
3957
+ }).filter(function (el) {
3958
+ return el !== null;
3959
+ }) : media && !medias ? [_classPrivateMethodGet(this, _wrapMedia, _wrapMedia2).call(this, media, "media")].filter(function (el) {
3960
+ return el !== null;
3961
+ }) : null;
3962
+ }
3963
+
3796
3964
  _defineProperty__default["default"](Message, "updated", "updated");
3797
3965
 
3798
3966
  __decorate([deprecationDecorator.deprecated("getMediaByCategory", "getMediaByCategories"), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", Array)], Message.prototype, "getMediaByCategory", null);
@@ -4821,6 +4989,68 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4821
4989
  * Logger instance.
4822
4990
  */
4823
4991
 
4992
+ /**
4993
+ * Unique system identifier of the conversation.
4994
+ */
4995
+
4996
+ /**
4997
+ * Conversation links for REST requests.
4998
+ * @internal
4999
+ */
5000
+
5001
+ /**
5002
+ * Configuration of the client that the conversation belongs to.
5003
+ */
5004
+
5005
+ /**
5006
+ * Conversation service objects.
5007
+ */
5008
+
5009
+ /**
5010
+ * Internal state of the conversation.
5011
+ */
5012
+
5013
+ /**
5014
+ * Name of the conversation entity document.
5015
+ */
5016
+
5017
+ /**
5018
+ * Messages entity.
5019
+ */
5020
+
5021
+ /**
5022
+ * Sync list containing messages.
5023
+ */
5024
+
5025
+ /**
5026
+ * Map of participants.
5027
+ * @internal
5028
+ */
5029
+
5030
+ /**
5031
+ * Participants entity.
5032
+ */
5033
+
5034
+ /**
5035
+ * Sync map containing participants.
5036
+ */
5037
+
5038
+ /**
5039
+ * Source of the most recent update.
5040
+ */
5041
+
5042
+ /**
5043
+ * Promise for the conversation entity document.
5044
+ */
5045
+
5046
+ /**
5047
+ * Promise for the messages list.
5048
+ */
5049
+
5050
+ /**
5051
+ * Conversation entity document.
5052
+ */
5053
+
4824
5054
  /**
4825
5055
  * @param descriptor Conversation descriptor.
4826
5056
  * @param sid Conversation SID.
@@ -4862,32 +5092,39 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4862
5092
  participants: _this._links.participants
4863
5093
  };
4864
5094
  _this._participants = new Map();
4865
- _this._participantsEntity = new Participants(_assertThisInitialized__default["default"](_this), _this._participants, participantsLinks, _this._configuration, _this._services);
5095
+ _this._participantsEntity = new Participants(_assertThisInitialized__default["default"](_this), _this._participants, // state leak
5096
+ participantsLinks, _this._services);
4866
5097
 
4867
- _this._participantsEntity.on("participantJoined", function (participant) {
4868
- return _this.emit("participantJoined", participant);
5098
+ _this._participantsEntity.on(Conversation.participantJoined, function (participant) {
5099
+ return (// @todo update participants map here??
5100
+ _this.emit(Conversation.participantJoined, participant)
5101
+ );
4869
5102
  });
4870
5103
 
4871
- _this._participantsEntity.on("participantLeft", function (participant) {
4872
- return _this.emit("participantLeft", participant);
5104
+ _this._participantsEntity.on(Conversation.participantLeft, function (participant) {
5105
+ return (// @todo update participants map here??
5106
+ _this.emit(Conversation.participantLeft, participant)
5107
+ );
4873
5108
  });
4874
5109
 
4875
- _this._participantsEntity.on("participantUpdated", function (args) {
4876
- return _this.emit("participantUpdated", args);
5110
+ _this._participantsEntity.on(Conversation.participantUpdated, function (args) {
5111
+ return (// @todo update participants map here??
5112
+ _this.emit(Conversation.participantUpdated, args)
5113
+ );
4877
5114
  });
4878
5115
 
4879
5116
  _this._messagesEntity = new Messages(_assertThisInitialized__default["default"](_this), configuration, services);
4880
5117
 
4881
- _this._messagesEntity.on("messageAdded", function (message) {
5118
+ _this._messagesEntity.on(Conversation.messageAdded, function (message) {
4882
5119
  return _this._onMessageAdded(message);
4883
5120
  });
4884
5121
 
4885
- _this._messagesEntity.on("messageUpdated", function (args) {
4886
- return _this.emit("messageUpdated", args);
5122
+ _this._messagesEntity.on(Conversation.messageUpdated, function (args) {
5123
+ return _this.emit(Conversation.messageUpdated, args);
4887
5124
  });
4888
5125
 
4889
- _this._messagesEntity.on("messageRemoved", function (message) {
4890
- return _this.emit("messageRemoved", message);
5126
+ _this._messagesEntity.on(Conversation.messageRemoved, function (message) {
5127
+ return _this.emit(Conversation.messageRemoved, message);
4891
5128
  });
4892
5129
 
4893
5130
  return _this;
@@ -4990,7 +5227,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4990
5227
  return (_this$_internalState$3 = this._internalState.notificationLevel) !== null && _this$_internalState$3 !== void 0 ? _this$_internalState$3 : "default";
4991
5228
  }
4992
5229
  /**
4993
- * Conversation bindings. Undocumented feature (for now).
5230
+ * Conversation bindings. An undocumented feature (for now).
4994
5231
  * @internal
4995
5232
  */
4996
5233
 
@@ -5972,18 +6209,19 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
5972
6209
  }()
5973
6210
  /**
5974
6211
  * Get recipients of all messages in the conversation.
6212
+ * @param options Optional configuration, set pageSize to request a specific pagination page size. Page size specifies a number of messages to include in a single batch. Each message may include multiple recipients.
5975
6213
  */
5976
6214
 
5977
6215
  }, {
5978
6216
  key: "getMessageRecipients",
5979
6217
  value: function () {
5980
- var _getMessageRecipients = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee24() {
6218
+ var _getMessageRecipients = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee24(options) {
5981
6219
  return _regeneratorRuntime__default["default"].wrap(function _callee24$(_context24) {
5982
6220
  while (1) {
5983
6221
  switch (_context24.prev = _context24.next) {
5984
6222
  case 0:
5985
6223
  _context24.next = 2;
5986
- return this._services.messageRecipientsClient.getRecipientsFromConversation(this.sid);
6224
+ return this._services.messageRecipientsClient.getRecipientsFromConversation(this.sid, options);
5987
6225
 
5988
6226
  case 2:
5989
6227
  return _context24.abrupt("return", _context24.sent);
@@ -5996,7 +6234,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
5996
6234
  }, _callee24, this);
5997
6235
  }));
5998
6236
 
5999
- function getMessageRecipients() {
6237
+ function getMessageRecipients(_x19) {
6000
6238
  return _getMessageRecipients.apply(this, arguments);
6001
6239
  }
6002
6240
 
@@ -6005,7 +6243,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6005
6243
  /**
6006
6244
  * Load and subscribe to this conversation and do not subscribe to its
6007
6245
  * participants and messages. This or _subscribeStreams will need to be called
6008
- * before any events on conversation will fire.
6246
+ * before any events in the conversation will fire.
6009
6247
  * @internal
6010
6248
  */
6011
6249
 
@@ -6038,12 +6276,12 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6038
6276
  case 6:
6039
6277
  this._entity = _context25.sent;
6040
6278
 
6041
- this._entity.on("updated", function (args) {
6279
+ this._entity.on(twilioSync.SyncDocument.updated, function (args) {
6042
6280
  return _this2._update(args.data);
6043
6281
  });
6044
6282
 
6045
- this._entity.on("removed", function () {
6046
- return _this2.emit("removed", _this2);
6283
+ this._entity.on(twilioSync.SyncDocument.removed, function () {
6284
+ return _this2.emit(Conversation.removed, _this2);
6047
6285
  });
6048
6286
 
6049
6287
  this._update(this._entity.data);
@@ -6091,44 +6329,95 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6091
6329
  }, {
6092
6330
  key: "_fetchStreams",
6093
6331
  value: function () {
6094
- var _fetchStreams2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee26() {
6095
- var _this$_entity, _this$_entity2;
6332
+ var _fetchStreams2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee27() {
6333
+ var _this3 = this;
6096
6334
 
6097
- var data;
6098
- return _regeneratorRuntime__default["default"].wrap(function _callee26$(_context26) {
6335
+ return _regeneratorRuntime__default["default"].wrap(function _callee27$(_context27) {
6099
6336
  while (1) {
6100
- switch (_context26.prev = _context26.next) {
6337
+ switch (_context27.prev = _context27.next) {
6101
6338
  case 0:
6102
- _context26.next = 2;
6103
- return this._subscribe();
6339
+ if (!this._streamsPromise) {
6340
+ _context27.next = 2;
6341
+ break;
6342
+ }
6104
6343
 
6105
- case 2:
6106
- Conversation._logger.trace("_streamsAvailable, this.entity.data=", (_this$_entity = this._entity) === null || _this$_entity === void 0 ? void 0 : _this$_entity.data);
6344
+ return _context27.abrupt("return", this._streamsPromise);
6107
6345
 
6108
- data = (_this$_entity2 = this._entity) === null || _this$_entity2 === void 0 ? void 0 : _this$_entity2.data;
6109
- _context26.next = 6;
6110
- return this._services.syncClient.list({
6111
- id: data.messages,
6112
- mode: "open_existing"
6113
- });
6346
+ case 2:
6347
+ this._streamsPromise = new Promise( /*#__PURE__*/function () {
6348
+ var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee26(resolve, reject) {
6349
+ var _this3$_entity, _this3$_entity2;
6350
+
6351
+ var data, messagesPromise, participantsPromise;
6352
+ return _regeneratorRuntime__default["default"].wrap(function _callee26$(_context26) {
6353
+ while (1) {
6354
+ switch (_context26.prev = _context26.next) {
6355
+ case 0:
6356
+ _context26.prev = 0;
6357
+ _context26.next = 3;
6358
+ return _this3._subscribe();
6359
+
6360
+ case 3:
6361
+ _context26.next = 9;
6362
+ break;
6114
6363
 
6115
- case 6:
6116
- this._messagesList = _context26.sent;
6117
- _context26.next = 9;
6118
- return this._services.syncClient.map({
6119
- id: data.roster,
6120
- mode: "open_existing"
6121
- });
6364
+ case 5:
6365
+ _context26.prev = 5;
6366
+ _context26.t0 = _context26["catch"](0);
6367
+
6368
+ Conversation._logger.trace("Failed to subscribe to conversation", _context26.t0);
6369
+
6370
+ return _context26.abrupt("return", reject(_context26.t0));
6371
+
6372
+ case 9:
6373
+ Conversation._logger.trace("_streamsAvailable, this.entity.data=", (_this3$_entity = _this3._entity) === null || _this3$_entity === void 0 ? void 0 : _this3$_entity.data);
6374
+
6375
+ data = (_this3$_entity2 = _this3._entity) === null || _this3$_entity2 === void 0 ? void 0 : _this3$_entity2.data;
6376
+ messagesPromise = _this3._services.syncClient.list({
6377
+ id: data.messages,
6378
+ mode: "open_existing"
6379
+ }).then(function (list) {
6380
+ _this3._messagesList = list;
6381
+ return list;
6382
+ });
6383
+ participantsPromise = _this3._services.syncClient.map({
6384
+ id: data.roster,
6385
+ mode: "open_existing"
6386
+ }).then(function (map) {
6387
+ _this3._participantsMap = map;
6388
+ return map;
6389
+ });
6390
+ Promise.all([messagesPromise, participantsPromise]).then(function () {
6391
+ return resolve(true);
6392
+ }).catch(function (err) {
6393
+ Conversation._logger.trace("Failed to fetch conversation streams for conversation", _this3.sid, err);
6394
+
6395
+ reject(err);
6396
+ });
6397
+
6398
+ case 14:
6399
+ case "end":
6400
+ return _context26.stop();
6401
+ }
6402
+ }
6403
+ }, _callee26, null, [[0, 5]]);
6404
+ }));
6122
6405
 
6123
- case 9:
6124
- this._participantsMap = _context26.sent;
6406
+ return function (_x20, _x21) {
6407
+ return _ref.apply(this, arguments);
6408
+ };
6409
+ }());
6410
+ return _context27.abrupt("return", this._streamsPromise.catch(function (err) {
6411
+ _this3._streamsPromise = null;
6412
+ throw err;
6413
+ }));
6125
6414
 
6126
- case 10:
6415
+ case 4:
6127
6416
  case "end":
6128
- return _context26.stop();
6417
+ return _context27.stop();
6129
6418
  }
6130
6419
  }
6131
- }, _callee26, this);
6420
+ }, _callee27, this);
6132
6421
  }));
6133
6422
 
6134
6423
  function _fetchStreams() {
@@ -6148,48 +6437,48 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6148
6437
  }, {
6149
6438
  key: "_subscribeStreams",
6150
6439
  value: function () {
6151
- var _subscribeStreams2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee27() {
6152
- var _this$_entity3, _this$_entity4, _this$_messagesList, _this$_participantsMa, data, messagesObjectName, rosterObjectName;
6440
+ var _subscribeStreams2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee28() {
6441
+ var _this$_entity, _this$_entity2, _this$_messagesList, _this$_participantsMa, data, messagesObjectName, rosterObjectName;
6153
6442
 
6154
- return _regeneratorRuntime__default["default"].wrap(function _callee27$(_context27) {
6443
+ return _regeneratorRuntime__default["default"].wrap(function _callee28$(_context28) {
6155
6444
  while (1) {
6156
- switch (_context27.prev = _context27.next) {
6445
+ switch (_context28.prev = _context28.next) {
6157
6446
  case 0:
6158
- _context27.prev = 0;
6159
- _context27.next = 3;
6160
- return this._subscribe();
6447
+ _context28.prev = 0;
6448
+ _context28.next = 3;
6449
+ return this._fetchStreams();
6161
6450
 
6162
6451
  case 3:
6163
- Conversation._logger.trace("_subscribeStreams, this.entity.data=", (_this$_entity3 = this._entity) === null || _this$_entity3 === void 0 ? void 0 : _this$_entity3.data);
6452
+ Conversation._logger.trace("_subscribeStreams, this.entity.data=", (_this$_entity = this._entity) === null || _this$_entity === void 0 ? void 0 : _this$_entity.data);
6164
6453
 
6165
- data = (_this$_entity4 = this._entity) === null || _this$_entity4 === void 0 ? void 0 : _this$_entity4.data;
6454
+ data = (_this$_entity2 = this._entity) === null || _this$_entity2 === void 0 ? void 0 : _this$_entity2.data;
6166
6455
  messagesObjectName = data.messages;
6167
6456
  rosterObjectName = data.roster;
6168
- _context27.next = 9;
6457
+ _context28.next = 9;
6169
6458
  return Promise.all([this._messagesEntity.subscribe((_this$_messagesList = this._messagesList) !== null && _this$_messagesList !== void 0 ? _this$_messagesList : messagesObjectName), this._participantsEntity.subscribe((_this$_participantsMa = this._participantsMap) !== null && _this$_participantsMa !== void 0 ? _this$_participantsMa : rosterObjectName)]);
6170
6459
 
6171
6460
  case 9:
6172
- _context27.next = 16;
6461
+ _context28.next = 16;
6173
6462
  break;
6174
6463
 
6175
6464
  case 11:
6176
- _context27.prev = 11;
6177
- _context27.t0 = _context27["catch"](0);
6465
+ _context28.prev = 11;
6466
+ _context28.t0 = _context28["catch"](0);
6178
6467
 
6179
6468
  if (this._services.syncClient.connectionState !== "disconnected") {
6180
- Conversation._logger.error("Failed to subscribe on conversation objects", this.sid, _context27.t0);
6469
+ Conversation._logger.error("Failed to subscribe on conversation objects", this.sid, _context28.t0);
6181
6470
  }
6182
6471
 
6183
- Conversation._logger.debug("ERROR: Failed to subscribe on conversation objects", this.sid, _context27.t0);
6472
+ Conversation._logger.debug("ERROR: Failed to subscribe on conversation objects", this.sid, _context28.t0);
6184
6473
 
6185
- throw _context27.t0;
6474
+ throw _context28.t0;
6186
6475
 
6187
6476
  case 16:
6188
6477
  case "end":
6189
- return _context27.stop();
6478
+ return _context28.stop();
6190
6479
  }
6191
6480
  }
6192
- }, _callee27, this, [[0, 11]]);
6481
+ }, _callee28, this, [[0, 11]]);
6193
6482
  }));
6194
6483
 
6195
6484
  function _subscribeStreams() {
@@ -6206,32 +6495,26 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6206
6495
  }, {
6207
6496
  key: "_unsubscribe",
6208
6497
  value: function () {
6209
- var _unsubscribe2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee28() {
6210
- return _regeneratorRuntime__default["default"].wrap(function _callee28$(_context28) {
6498
+ var _unsubscribe2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee29() {
6499
+ return _regeneratorRuntime__default["default"].wrap(function _callee29$(_context29) {
6211
6500
  while (1) {
6212
- switch (_context28.prev = _context28.next) {
6501
+ switch (_context29.prev = _context29.next) {
6213
6502
  case 0:
6214
- if (!this._entity) {
6215
- _context28.next = 5;
6216
- break;
6217
- }
6503
+ if (this._entity) {
6504
+ this._entity.close();
6218
6505
 
6219
- _context28.next = 3;
6220
- return this._entity.close();
6221
-
6222
- case 3:
6223
- this._entity = null;
6224
- this._entityPromise = null;
6506
+ this._entity = null;
6507
+ this._entityPromise = null;
6508
+ }
6225
6509
 
6226
- case 5:
6227
- return _context28.abrupt("return", Promise.all([this._participantsEntity.unsubscribe(), this._messagesEntity.unsubscribe()]));
6510
+ return _context29.abrupt("return", Promise.all([this._participantsEntity.unsubscribe(), this._messagesEntity.unsubscribe()]));
6228
6511
 
6229
- case 6:
6512
+ case 2:
6230
6513
  case "end":
6231
- return _context28.stop();
6514
+ return _context29.stop();
6232
6515
  }
6233
6516
  }
6234
- }, _callee28, this);
6517
+ }, _callee29, this);
6235
6518
  }));
6236
6519
 
6237
6520
  function _unsubscribe() {
@@ -6248,7 +6531,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6248
6531
  }, {
6249
6532
  key: "_setStatus",
6250
6533
  value: function _setStatus(status, source) {
6251
- var _this3 = this;
6534
+ var _this4 = this;
6252
6535
 
6253
6536
  this._dataSource = source;
6254
6537
 
@@ -6262,7 +6545,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6262
6545
  this._subscribeStreams().catch(function (err) {
6263
6546
  Conversation._logger.debug("ERROR while setting conversation status " + status, err);
6264
6547
 
6265
- if (_this3._services.syncClient.connectionState !== "disconnected") {
6548
+ if (_this4._services.syncClient.connectionState !== "disconnected") {
6266
6549
  throw err;
6267
6550
  }
6268
6551
  });
@@ -6274,7 +6557,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6274
6557
  this._unsubscribe().catch(function (err) {
6275
6558
  Conversation._logger.debug("ERROR while setting conversation status " + status, err);
6276
6559
 
6277
- if (_this3._services.syncClient.connectionState !== "disconnected") {
6560
+ if (_this4._services.syncClient.connectionState !== "disconnected") {
6278
6561
  throw err;
6279
6562
  }
6280
6563
  });
@@ -6314,7 +6597,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6314
6597
  break;
6315
6598
 
6316
6599
  case fieldMappings.attributes:
6317
- if (isEqual__default["default"](this._internalState.attributes, update.attributes)) {
6600
+ if (isEqual(this._internalState.attributes, update.attributes)) {
6318
6601
  break;
6319
6602
  }
6320
6603
 
@@ -6350,7 +6633,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6350
6633
  updateReasons.add(localKey);
6351
6634
  }
6352
6635
 
6353
- if (isEqual__default["default"](this._internalState.lastMessage, {})) {
6636
+ if (isEqual(this._internalState.lastMessage, {})) {
6354
6637
  delete this._internalState.lastMessage;
6355
6638
  }
6356
6639
 
@@ -6363,7 +6646,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6363
6646
  state.dateUpdated = new Date(state.dateUpdated);
6364
6647
  }
6365
6648
 
6366
- if (isEqual__default["default"](this._internalState.state, state)) {
6649
+ if (isEqual(this._internalState.state, state)) {
6367
6650
  break;
6368
6651
  }
6369
6652
 
@@ -6372,7 +6655,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6372
6655
  break;
6373
6656
 
6374
6657
  case fieldMappings.bindings:
6375
- if (isEqual__default["default"](this._internalState.bindings, update.bindings)) {
6658
+ if (isEqual(this._internalState.bindings, update.bindings)) {
6376
6659
  break;
6377
6660
  }
6378
6661
 
@@ -6395,7 +6678,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6395
6678
  }
6396
6679
 
6397
6680
  if (updateReasons.size > 0) {
6398
- this.emit("updated", {
6681
+ this.emit(Conversation.updated, {
6399
6682
  conversation: this,
6400
6683
  updateReasons: _toConsumableArray__default["default"](updateReasons)
6401
6684
  });
@@ -6427,7 +6710,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6427
6710
  _iterator.f();
6428
6711
  }
6429
6712
 
6430
- this.emit("messageAdded", message);
6713
+ this.emit(Conversation.messageAdded, message);
6431
6714
  }
6432
6715
  /**
6433
6716
  * Set last read message index.
@@ -6437,30 +6720,30 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
6437
6720
  }, {
6438
6721
  key: "_setLastReadMessageIndex",
6439
6722
  value: function () {
6440
- var _setLastReadMessageIndex2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee29(index) {
6723
+ var _setLastReadMessageIndex2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee30(index) {
6441
6724
  var result;
6442
- return _regeneratorRuntime__default["default"].wrap(function _callee29$(_context29) {
6725
+ return _regeneratorRuntime__default["default"].wrap(function _callee30$(_context30) {
6443
6726
  while (1) {
6444
- switch (_context29.prev = _context29.next) {
6727
+ switch (_context30.prev = _context30.next) {
6445
6728
  case 0:
6446
- _context29.next = 2;
6729
+ _context30.next = 2;
6447
6730
  return this._services.commandExecutor.mutateResource("post", "".concat(this._configuration.links.myConversations, "/").concat(this.sid), {
6448
6731
  last_read_message_index: index
6449
6732
  });
6450
6733
 
6451
6734
  case 2:
6452
- result = _context29.sent;
6453
- return _context29.abrupt("return", result.unread_messages_count);
6735
+ result = _context30.sent;
6736
+ return _context30.abrupt("return", result.unread_messages_count);
6454
6737
 
6455
6738
  case 4:
6456
6739
  case "end":
6457
- return _context29.stop();
6740
+ return _context30.stop();
6458
6741
  }
6459
6742
  }
6460
- }, _callee29, this);
6743
+ }, _callee30, this);
6461
6744
  }));
6462
6745
 
6463
- function _setLastReadMessageIndex(_x19) {
6746
+ function _setLastReadMessageIndex(_x22) {
6464
6747
  return _setLastReadMessageIndex2.apply(this, arguments);
6465
6748
  }
6466
6749
 
@@ -6540,7 +6823,7 @@ _defineProperty__default["default"](Conversation, "_logger", Logger.scope("Conve
6540
6823
 
6541
6824
  __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, optionalJson), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "add", null);
6542
6825
 
6543
- __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, declarativeTypeValidator.nonEmptyString, optionalJson), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, Object, Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "addNonChatParticipant", null);
6826
+ __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, declarativeTypeValidator.nonEmptyString, optionalJson, optionalJson), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, Object, Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "addNonChatParticipant", null);
6544
6827
 
6545
6828
  __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonNegativeInteger), __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", Promise)], Conversation.prototype, "advanceLastReadMessageIndex", null);
6546
6829
 
@@ -6676,6 +6959,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
6676
6959
  return this.services.commandExecutor.mutateResource("post", this.configuration.links.conversations, {
6677
6960
  friendly_name: options.friendlyName,
6678
6961
  unique_name: options.uniqueName,
6962
+ access: options.access,
6679
6963
  attributes: typeof attributes !== "undefined" ? JSON.stringify(attributes) : undefined
6680
6964
  });
6681
6965
 
@@ -6737,7 +7021,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
6737
7021
  return addConversation;
6738
7022
  }()
6739
7023
  /**
6740
- * Fetch conversations list and instantiate all necessary objects
7024
+ * Fetch conversations' list and instantiate all necessary objects
6741
7025
  */
6742
7026
 
6743
7027
  }, {
@@ -6758,12 +7042,12 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
6758
7042
 
6759
7043
  case 3:
6760
7044
  map = _context2.sent;
6761
- map.on("itemAdded", function (args) {
7045
+ map.on(twilioSync.SyncMap.itemAdded, function (args) {
6762
7046
  log$1.debug("itemAdded: ".concat(args.item.key));
6763
7047
 
6764
7048
  _this2._upsertConversation("sync", args.item.key, args.item.data);
6765
7049
  });
6766
- map.on("itemRemoved", function (args) {
7050
+ map.on(twilioSync.SyncMap.itemRemoved, function (args) {
6767
7051
  log$1.debug("itemRemoved: ".concat(args.key));
6768
7052
  var sid = args.key;
6769
7053
 
@@ -6789,7 +7073,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
6789
7073
 
6790
7074
  conversation.emit("removed", conversation);
6791
7075
  });
6792
- map.on("itemUpdated", function (args) {
7076
+ map.on(twilioSync.SyncMap.itemUpdated, function (args) {
6793
7077
  log$1.debug("itemUpdated: ".concat(args.item.key));
6794
7078
 
6795
7079
  _this2._upsertConversation("sync", args.item.key, args.item.data);
@@ -6960,6 +7244,8 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
6960
7244
  createdBy: body.created_by,
6961
7245
  attributes: body.attributes,
6962
7246
  channel: body.sync_objects.conversation,
7247
+ roster: body.sync_objects.participants,
7248
+ messages: body.sync_objects.messages,
6963
7249
  notificationLevel: body === null || body === void 0 ? void 0 : body.notification_level,
6964
7250
  sid: sid
6965
7251
  };
@@ -7005,8 +7291,10 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
7005
7291
  uniqueName: body.unique_name,
7006
7292
  createdBy: body.created_by,
7007
7293
  attributes: body.attributes,
7008
- channel: "".concat(sid, ".channel"),
7009
- // notificationLevel: body?.notification_level,
7294
+ channel: body.sync_objects.conversation || "".concat(sid, ".channel"),
7295
+ roster: body.sync_objects.participants,
7296
+ messages: body.sync_objects.messages,
7297
+ notificationLevel: body === null || body === void 0 ? void 0 : body.notification_level,
7010
7298
  sid: sid
7011
7299
  };
7012
7300
  return _context6.abrupt("return", this._upsertConversation("sync", sid, data));
@@ -7146,7 +7434,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
7146
7434
  updateData.lastConsumedMessageIndex = data.lastConsumedMessageIndex;
7147
7435
  }
7148
7436
 
7149
- if (!isEqual__default["default"](updateData, {})) {
7437
+ if (!isEqual(updateData, {})) {
7150
7438
  conversation._update(updateData);
7151
7439
  }
7152
7440
 
@@ -7343,7 +7631,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
7343
7631
  status: conversationDescriptor.status,
7344
7632
  channel: conversationDescriptor.sync_objects.conversation,
7345
7633
  messages: conversationDescriptor.sync_objects.messages,
7346
- roster: "".concat(conversationDescriptor.conversation_sid, ".roster"),
7634
+ roster: conversationDescriptor.sync_objects.participants || "".concat(conversationDescriptor.conversation_sid, ".roster"),
7347
7635
  lastConsumedMessageIndex: conversationDescriptor.last_read_message_index,
7348
7636
  notificationLevel: conversationDescriptor.notification_level
7349
7637
  };
@@ -7766,7 +8054,7 @@ var TypingIndicator = /*#__PURE__*/function () {
7766
8054
  }
7767
8055
 
7768
8056
  conversation._participants.forEach(function (participant) {
7769
- if (participant.identity !== message.identity) {
8057
+ if (participant.identity !== message.identity && participant.type !== "apple") {
7770
8058
  return;
7771
8059
  }
7772
8060
 
@@ -7882,7 +8170,15 @@ function PushNotification(data) {
7882
8170
  this.data = data.data || {};
7883
8171
  });
7884
8172
 
7885
- var version = "3.0.1-rc.103";
8173
+ var version = "3.0.1";
8174
+
8175
+ /**
8176
+ * Generate a random UUID using the Web Crypto API.
8177
+ * Available in Node.js 14.17+, modern browsers, and React Native.
8178
+ */
8179
+ var randomUUID = function randomUUID() {
8180
+ return crypto.randomUUID();
8181
+ };
7886
8182
 
7887
8183
  function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
7888
8184
 
@@ -7891,6 +8187,7 @@ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) {
7891
8187
  function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
7892
8188
 
7893
8189
  function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
8190
+ var uuidv4 = randomUUID;
7894
8191
 
7895
8192
  var trimSlashes = function trimSlashes(url) {
7896
8193
  return url.replace(/(^\/+|\/+$)/g, "");
@@ -8115,7 +8412,7 @@ var CommandExecutor = /*#__PURE__*/function () {
8115
8412
  case 0:
8116
8413
  _context4.next = 2;
8117
8414
  return this._makeRequest(method, url, requestBody, {
8118
- "X-Twilio-Mutation-Id": uuid.v4()
8415
+ "X-Twilio-Mutation-Id": uuidv4()
8119
8416
  });
8120
8417
 
8121
8418
  case 2:
@@ -8755,6 +9052,22 @@ var EmailRecipientDescriptor = /*#__PURE__*/_createClass__default["default"](
8755
9052
  * Type of recipient.
8756
9053
  */
8757
9054
 
9055
+ /**
9056
+ * Sid of the message that this recipient belongs to.
9057
+ */
9058
+
9059
+ /**
9060
+ * Email recipient level.
9061
+ */
9062
+
9063
+ /**
9064
+ * Name of the recipient.
9065
+ */
9066
+
9067
+ /**
9068
+ * Address of the recipient.
9069
+ */
9070
+
8758
9071
  /**
8759
9072
  * @internal
8760
9073
  */
@@ -8877,7 +9190,7 @@ var MessageRecipientsClient = /*#__PURE__*/function () {
8877
9190
  while (1) {
8878
9191
  switch (_context2.prev = _context2.next) {
8879
9192
  case 0:
8880
- url = new UriBuilder(this._configuration.links.conversations).path(conversationSid).path("MessageRecipients").arg("PageToken", (_paginatorOptions$pag = paginatorOptions === null || paginatorOptions === void 0 ? void 0 : paginatorOptions.pageToken) !== null && _paginatorOptions$pag !== void 0 ? _paginatorOptions$pag : "").arg("PageSize", (_paginatorOptions$pag2 = paginatorOptions === null || paginatorOptions === void 0 ? void 0 : paginatorOptions.pageSize) !== null && _paginatorOptions$pag2 !== void 0 ? _paginatorOptions$pag2 : "").build();
9193
+ url = new UriBuilder(this._configuration.links.conversations).path(conversationSid).path("MessageRecipients").arg("PageToken", (_paginatorOptions$pag = paginatorOptions === null || paginatorOptions === void 0 ? void 0 : paginatorOptions.pageToken) !== null && _paginatorOptions$pag !== void 0 ? _paginatorOptions$pag : undefined).arg("PageSize", (_paginatorOptions$pag2 = paginatorOptions === null || paginatorOptions === void 0 ? void 0 : paginatorOptions.pageSize) !== null && _paginatorOptions$pag2 !== void 0 ? _paginatorOptions$pag2 : undefined).build();
8881
9194
  _context2.next = 3;
8882
9195
  return this._services.commandExecutor.fetchResource(url);
8883
9196
 
@@ -9209,7 +9522,47 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
9209
9522
  */
9210
9523
 
9211
9524
  /**
9212
- * Returned Conversations instance is not yet fully initialized. Calling any
9525
+ * Promise that resolves on successful initialization.
9526
+ */
9527
+
9528
+ /**
9529
+ * Options passed to the client.
9530
+ */
9531
+
9532
+ /**
9533
+ * Client service objects.
9534
+ */
9535
+
9536
+ /**
9537
+ * The user of the client.
9538
+ */
9539
+
9540
+ /**
9541
+ * Resolves the {@link Client._ensureReady} promise.
9542
+ */
9543
+
9544
+ /**
9545
+ * Rejects the {@link Client._ensureReady} promise.
9546
+ */
9547
+
9548
+ /**
9549
+ * The current token of the client.
9550
+ */
9551
+
9552
+ /**
9553
+ * The constructed configuration object.
9554
+ */
9555
+
9556
+ /**
9557
+ * The Conversations entity.
9558
+ */
9559
+
9560
+ /**
9561
+ * Promise that resolves when initial conversations are fetched.
9562
+ */
9563
+
9564
+ /**
9565
+ * Returned Conversations Client instance is not yet fully initialized. Calling any
9213
9566
  * operations will block until it is. Use connection events to monitor when
9214
9567
  * client becomes fully available (connectionStateChanged with state
9215
9568
  * 'connected') or not available (connectionStateChange with state 'denied',
@@ -9299,16 +9652,16 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
9299
9652
 
9300
9653
  _this._services.twilsockClient = _this._options.twilsockClient = (_this$_options$twilso = _this._options.twilsockClient) !== null && _this$_options$twilso !== void 0 ? _this$_options$twilso : new twilsock.TwilsockClient(fpaToken, productId, _this._options);
9301
9654
 
9302
- _this._services.twilsockClient.on("tokenAboutToExpire", function () {
9303
- return _this.emit("tokenAboutToExpire");
9655
+ _this._services.twilsockClient.on(Client_1.tokenAboutToExpire, function () {
9656
+ return _this.emit(Client_1.tokenAboutToExpire);
9304
9657
  });
9305
9658
 
9306
- _this._services.twilsockClient.on("tokenExpired", function () {
9307
- return _this.emit("tokenExpired");
9659
+ _this._services.twilsockClient.on(Client_1.tokenExpired, function () {
9660
+ return _this.emit(Client_1.tokenExpired);
9308
9661
  });
9309
9662
 
9310
- _this._services.twilsockClient.on("connectionError", function (error) {
9311
- return _this.emit("connectionError", error);
9663
+ _this._services.twilsockClient.on(Client_1.connectionError, function (error) {
9664
+ return _this.emit(Client_1.connectionError, error);
9312
9665
  });
9313
9666
 
9314
9667
  _this._services.twilsockClient.on("stateChanged", function (state) {
@@ -9317,7 +9670,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
9317
9670
  if (state !== _this.connectionState) {
9318
9671
  _this.connectionState = state;
9319
9672
 
9320
- _this.emit("connectionStateChanged", _this.connectionState);
9673
+ _this.emit(Client_1.connectionStateChanged, _this.connectionState);
9321
9674
  }
9322
9675
  });
9323
9676
 
@@ -9335,9 +9688,9 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
9335
9688
  var emitFailed = function emitFailed(error) {
9336
9689
  _this._rejectEnsureReady(error);
9337
9690
 
9338
- _this.emit("stateChanged", "failed");
9691
+ _this.emit(Client_1.stateChanged, "failed");
9339
9692
 
9340
- _this.emit("initFailed", {
9693
+ _this.emit(Client_1.initFailed, {
9341
9694
  error: error
9342
9695
  });
9343
9696
  };
@@ -9347,6 +9700,8 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
9347
9700
  terminal: true,
9348
9701
  message: "Twilsock has disconnected."
9349
9702
  });
9703
+
9704
+ _this._initializeEnsureReady((options === null || options === void 0 ? void 0 : options.throwErrorsAlways) || false);
9350
9705
  };
9351
9706
 
9352
9707
  _this._services.twilsockClient.once("connectionError", emitFailed);
@@ -9390,9 +9745,9 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
9390
9745
 
9391
9746
  _this._rejectEnsureReady(connectionError);
9392
9747
 
9393
- _this.emit("stateChanged", "failed");
9748
+ _this.emit(Client_1.stateChanged, "failed");
9394
9749
 
9395
- _this.emit("initFailed", {
9750
+ _this.emit(Client_1.initFailed, {
9396
9751
  error: connectionError
9397
9752
  });
9398
9753
 
@@ -9404,12 +9759,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
9404
9759
  }, _callee, null, [[3, 11]]);
9405
9760
  })));
9406
9761
 
9407
- _this._ensureReady = new Promise(function (resolve, reject) {
9408
- _this._resolveEnsureReady = resolve;
9409
- _this._rejectEnsureReady = reject;
9410
- }).catch(function () {
9411
- return void 0;
9412
- }); // @todo How to process unhandled rejection here?
9762
+ _this._initializeEnsureReady((options === null || options === void 0 ? void 0 : options.throwErrorsAlways) || false);
9413
9763
 
9414
9764
  if (startTwilsock) {
9415
9765
  _this._services.twilsockClient.connect();
@@ -9634,7 +9984,6 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
9634
9984
  /**
9635
9985
  * Peek a conversation by its SID.
9636
9986
  * @param conversationSid Conversation sid
9637
- * @internal
9638
9987
  */
9639
9988
 
9640
9989
  }, {
@@ -9920,7 +10269,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
9920
10269
  return removePushRegistrations;
9921
10270
  }()
9922
10271
  /**
9923
- * Current version of the Conversations client.
10272
+ * Parse a push notification payload.
9924
10273
  */
9925
10274
 
9926
10275
  }, {
@@ -10239,6 +10588,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
10239
10588
  this._conversationsPromise = this._conversationsEntity.fetchConversations().then(function () {
10240
10589
  return _this3._conversationsEntity;
10241
10590
  }).catch(function (error) {
10591
+ console.error("Failed to fetch conversations _conversationsPromise -> client.ts", error);
10242
10592
  throw error;
10243
10593
  });
10244
10594
  _context17.next = 30;
@@ -10257,8 +10607,8 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
10257
10607
 
10258
10608
  this._resolveEnsureReady();
10259
10609
 
10260
- this.emit("stateChanged", "initialized");
10261
- this.emit("initialized");
10610
+ this.emit(Client_1.stateChanged, "initialized");
10611
+ this.emit(Client_1.initialized);
10262
10612
 
10263
10613
  case 36:
10264
10614
  case "end":
@@ -10302,6 +10652,26 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
10302
10652
  _this5._services.notificationClient.unsubscribe(channelType, messageType);
10303
10653
  });
10304
10654
  }
10655
+ /**
10656
+ * Initialize the ensureReady promise.
10657
+ */
10658
+
10659
+ }, {
10660
+ key: "_initializeEnsureReady",
10661
+ value: function _initializeEnsureReady(throwErrorsAlways) {
10662
+ var _this6 = this;
10663
+
10664
+ this._ensureReady = new Promise(function (resolve, reject) {
10665
+ _this6._resolveEnsureReady = resolve;
10666
+ _this6._rejectEnsureReady = reject;
10667
+ }).catch(function (error) {
10668
+ if (throwErrorsAlways) {
10669
+ throw error;
10670
+ } else {
10671
+ return void 0;
10672
+ }
10673
+ });
10674
+ }
10305
10675
  }], [{
10306
10676
  key: "create",
10307
10677
  value: function () {