@twilio/conversations 2.0.1-rc.7 → 2.1.0-rc.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 (57) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/builds/browser.js +249 -65
  3. package/builds/browser.js.map +1 -1
  4. package/builds/lib.d.ts +86 -9
  5. package/builds/lib.js +249 -65
  6. package/builds/lib.js.map +1 -1
  7. package/builds/twilio-conversations.js +254 -251
  8. package/builds/twilio-conversations.min.js +3 -3
  9. package/dist/conversation.js +24 -10
  10. package/dist/conversation.js.map +1 -1
  11. package/dist/data/conversations.js +1 -1
  12. package/dist/data/conversations.js.map +1 -1
  13. package/dist/data/messages.js +1 -1
  14. package/dist/data/messages.js.map +1 -1
  15. package/dist/data/participants.js +7 -3
  16. package/dist/data/participants.js.map +1 -1
  17. package/dist/index.js +1 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/interfaces/attributes.js +147 -0
  20. package/dist/interfaces/attributes.js.map +1 -0
  21. package/dist/message-builder.js +52 -0
  22. package/dist/message-builder.js.map +1 -1
  23. package/dist/message.js +35 -4
  24. package/dist/message.js.map +1 -1
  25. package/dist/packages/conversations/package.json.js +1 -1
  26. package/dist/participant.js +20 -3
  27. package/dist/participant.js.map +1 -1
  28. package/dist/user.js +2 -1
  29. package/dist/user.js.map +1 -1
  30. package/docs/assets/js/search.js +1 -1
  31. package/docs/classes/AggregatedDeliveryReceipt.html +15 -0
  32. package/docs/classes/Client.html +15 -0
  33. package/docs/classes/Conversation.html +24 -2
  34. package/docs/classes/DetailedDeliveryReceipt.html +15 -0
  35. package/docs/classes/Media.html +15 -0
  36. package/docs/classes/Message.html +83 -2
  37. package/docs/classes/MessageBuilder.html +91 -0
  38. package/docs/classes/Participant.html +45 -1
  39. package/docs/classes/PushNotification.html +15 -0
  40. package/docs/classes/RestPaginator.html +15 -0
  41. package/docs/classes/UnsentMessage.html +15 -0
  42. package/docs/classes/User.html +15 -0
  43. package/docs/index.html +37 -3
  44. package/docs/interfaces/ClientOptions.html +15 -0
  45. package/docs/interfaces/ConversationBindings.html +3118 -0
  46. package/docs/interfaces/ConversationEmailBinding.html +3118 -0
  47. package/docs/interfaces/ConversationState.html +15 -0
  48. package/docs/interfaces/CreateConversationOptions.html +15 -0
  49. package/docs/interfaces/LastMessage.html +15 -0
  50. package/docs/interfaces/Paginator.html +15 -0
  51. package/docs/interfaces/ParticipantBindings.html +3118 -0
  52. package/docs/interfaces/ParticipantEmailBinding.html +3118 -0
  53. package/docs/interfaces/PushNotificationData.html +15 -0
  54. package/docs/interfaces/SendEmailOptions.html +15 -0
  55. package/docs/interfaces/SendMediaOptions.html +15 -0
  56. package/docs/modules.html +37 -3
  57. package/package.json +9 -9
package/builds/lib.js CHANGED
@@ -130,6 +130,7 @@ This software includes platform.js under the following license.
130
130
 
131
131
  Object.defineProperty(exports, '__esModule', { value: true });
132
132
 
133
+ require('isomorphic-form-data');
133
134
  require('core-js/modules/es.reflect.construct.js');
134
135
  require('core-js/modules/es.object.keys.js');
135
136
  require('core-js/modules/es.symbol.js');
@@ -162,6 +163,7 @@ require('core-js/modules/es.regexp.exec.js');
162
163
  require('core-js/modules/es.string.replace.js');
163
164
  require('core-js/modules/es.array.join.js');
164
165
  var declarativeTypeValidator = require('@twilio/declarative-type-validator');
166
+ require('core-js/modules/es.array.includes.js');
165
167
  var replayEventEmitter = require('@twilio/replay-event-emitter');
166
168
  var isEqual = require('lodash.isequal');
167
169
  require('core-js/modules/es.array.slice.js');
@@ -177,7 +179,6 @@ var twilioSync = require('twilio-sync');
177
179
  var mcsClient = require('@twilio/mcs-client');
178
180
  var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
179
181
  require('core-js/modules/es.set.js');
180
- require('core-js/modules/es.array.includes.js');
181
182
  require('core-js/modules/es.number.is-integer.js');
182
183
  require('core-js/modules/es.typed-array.uint8-array.js');
183
184
  require('core-js/modules/es.typed-array.copy-within.js');
@@ -549,6 +550,13 @@ var UriBuilder = /*#__PURE__*/function () {
549
550
  return UriBuilder;
550
551
  }();
551
552
 
553
+ var attributesValidator = declarativeTypeValidator.custom(function (value) {
554
+ return [['string', 'number', 'boolean', 'object'].includes(_typeof__default['default'](value)), 'a JSON type'];
555
+ });
556
+ var optionalAttributesValidator = declarativeTypeValidator.custom(function (value) {
557
+ return [['undefined', 'string', 'number', 'boolean', 'object'].includes(_typeof__default['default'](value)), 'an optional JSON type'];
558
+ });
559
+
552
560
  function _createSuper$8(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$8(); 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); }; }
553
561
 
554
562
  function _isNativeReflectConstruct$8() { 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; } }
@@ -1054,7 +1062,7 @@ var User = /*#__PURE__*/function (_ReplayEventEmitter) {
1054
1062
  return User;
1055
1063
  }(replayEventEmitter.ReplayEventEmitter);
1056
1064
 
1057
- __decorate([declarativeTypeValidator.validateTypesAsync(['string', 'number', 'boolean', 'object', declarativeTypeValidator.literal(null)]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], User.prototype, "updateAttributes", null);
1065
+ __decorate([declarativeTypeValidator.validateTypesAsync(attributesValidator), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], User.prototype, "updateAttributes", null);
1058
1066
 
1059
1067
  __decorate([declarativeTypeValidator.validateTypesAsync(['string']), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise)], User.prototype, "updateFriendlyName", null);
1060
1068
 
@@ -1244,6 +1252,8 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
1244
1252
  * @internal
1245
1253
  */
1246
1254
  function Participant(data, sid, conversation, links, services) {
1255
+ var _data$bindings;
1256
+
1247
1257
  var _this;
1248
1258
 
1249
1259
  _classCallCheck__default['default'](this, Participant);
@@ -1264,7 +1274,8 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
1264
1274
  lastReadMessageIndex: Number.isInteger(data.lastConsumedMessageIndex) ? data.lastConsumedMessageIndex : null,
1265
1275
  lastReadTimestamp: data.lastConsumptionTimestamp ? parseTime$1(data.lastConsumptionTimestamp) : null,
1266
1276
  type: data.type || 'chat',
1267
- userInfo: data.userInfo
1277
+ userInfo: data.userInfo,
1278
+ bindings: (_data$bindings = data.bindings) !== null && _data$bindings !== void 0 ? _data$bindings : {}
1268
1279
  };
1269
1280
 
1270
1281
  if (!data.identity && !data.type) {
@@ -1367,7 +1378,7 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
1367
1378
  return this.state.roleSid;
1368
1379
  }
1369
1380
  /**
1370
- * Message type of the participant.
1381
+ * Type of the participant.
1371
1382
  */
1372
1383
 
1373
1384
  }, {
@@ -1375,6 +1386,21 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
1375
1386
  get: function get() {
1376
1387
  return this.state.type;
1377
1388
  }
1389
+ /**
1390
+ * Get the bindings mapping for the current participant.
1391
+ * Available binding depends on the participant type.
1392
+ * You could access it as `participant.bindings.sms?.address` or
1393
+ * using the type dynamically `participant.bindings[participant.type]`
1394
+ * just be aware that the binding information has different structure for
1395
+ * each participant type.
1396
+ * See also {ParticipantEmailBinding}, the only available currently binding descriptor.
1397
+ */
1398
+
1399
+ }, {
1400
+ key: "bindings",
1401
+ get: function get() {
1402
+ return this.state.bindings;
1403
+ }
1378
1404
  }, {
1379
1405
  key: "_startTyping",
1380
1406
  value:
@@ -1461,6 +1487,11 @@ var Participant = /*#__PURE__*/function (_ReplayEventEmitter) {
1461
1487
  }
1462
1488
  }
1463
1489
 
1490
+ if (data.bindings && !isEqual__default['default'](this.state.bindings, data.bindings)) {
1491
+ this.state.bindings = data.bindings;
1492
+ updateReasons.push('bindings');
1493
+ }
1494
+
1464
1495
  if (updateReasons.length > 0) {
1465
1496
  this.emit('updated', {
1466
1497
  participant: this,
@@ -1580,7 +1611,7 @@ _defineProperty__default['default'](Participant, "typingEnded", 'typingEnded');
1580
1611
 
1581
1612
  _defineProperty__default['default'](Participant, "updated", 'updated');
1582
1613
 
1583
- __decorate([declarativeTypeValidator.validateTypesAsync(['string', 'number', 'boolean', 'object', declarativeTypeValidator.literal(null)]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], Participant.prototype, "updateAttributes", null);
1614
+ __decorate([declarativeTypeValidator.validateTypesAsync(attributesValidator), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], Participant.prototype, "updateAttributes", null);
1584
1615
 
1585
1616
  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); }; }
1586
1617
 
@@ -1760,19 +1791,38 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
1760
1791
 
1761
1792
  }, {
1762
1793
  key: "getParticipants",
1763
- value: function getParticipants() {
1764
- var _this4 = this;
1794
+ value: function () {
1795
+ var _getParticipants = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3() {
1796
+ var _this4 = this;
1765
1797
 
1766
- return this.rosterEntityPromise.then(function () {
1767
- var participants = [];
1798
+ return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
1799
+ while (1) {
1800
+ switch (_context3.prev = _context3.next) {
1801
+ case 0:
1802
+ return _context3.abrupt("return", this.rosterEntityPromise.then(function () {
1803
+ var participants = [];
1768
1804
 
1769
- _this4.participants.forEach(function (participant) {
1770
- return participants.push(participant);
1771
- });
1805
+ _this4.participants.forEach(function (participant) {
1806
+ return participants.push(participant);
1807
+ });
1772
1808
 
1773
- return participants;
1774
- });
1775
- }
1809
+ return participants;
1810
+ }));
1811
+
1812
+ case 1:
1813
+ case "end":
1814
+ return _context3.stop();
1815
+ }
1816
+ }
1817
+ }, _callee3, this);
1818
+ }));
1819
+
1820
+ function getParticipants() {
1821
+ return _getParticipants.apply(this, arguments);
1822
+ }
1823
+
1824
+ return getParticipants;
1825
+ }()
1776
1826
  /**
1777
1827
  * Get participant by SID from conversation
1778
1828
  * @returns {Promise<Participant>}
@@ -1781,14 +1831,14 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
1781
1831
  }, {
1782
1832
  key: "getParticipantBySid",
1783
1833
  value: function () {
1784
- var _getParticipantBySid = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(participantSid) {
1834
+ var _getParticipantBySid = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4(participantSid) {
1785
1835
  var _this5 = this;
1786
1836
 
1787
- return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
1837
+ return _regeneratorRuntime__default['default'].wrap(function _callee4$(_context4) {
1788
1838
  while (1) {
1789
- switch (_context3.prev = _context3.next) {
1839
+ switch (_context4.prev = _context4.next) {
1790
1840
  case 0:
1791
- return _context3.abrupt("return", this.rosterEntityPromise.then(function () {
1841
+ return _context4.abrupt("return", this.rosterEntityPromise.then(function () {
1792
1842
  var participant = _this5.participants.get(participantSid);
1793
1843
 
1794
1844
  if (!participant) {
@@ -1800,10 +1850,10 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
1800
1850
 
1801
1851
  case 1:
1802
1852
  case "end":
1803
- return _context3.stop();
1853
+ return _context4.stop();
1804
1854
  }
1805
1855
  }
1806
- }, _callee3, this);
1856
+ }, _callee4, this);
1807
1857
  }));
1808
1858
 
1809
1859
  function getParticipantBySid(_x3) {
@@ -1820,16 +1870,16 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
1820
1870
  }, {
1821
1871
  key: "getParticipantByIdentity",
1822
1872
  value: function () {
1823
- var _getParticipantByIdentity = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4(identity) {
1873
+ var _getParticipantByIdentity = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5(identity) {
1824
1874
  var _this6 = this;
1825
1875
 
1826
1876
  var foundParticipant;
1827
- return _regeneratorRuntime__default['default'].wrap(function _callee4$(_context4) {
1877
+ return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
1828
1878
  while (1) {
1829
- switch (_context4.prev = _context4.next) {
1879
+ switch (_context5.prev = _context5.next) {
1830
1880
  case 0:
1831
1881
  foundParticipant = null;
1832
- return _context4.abrupt("return", this.rosterEntityPromise.then(function () {
1882
+ return _context5.abrupt("return", this.rosterEntityPromise.then(function () {
1833
1883
  _this6.participants.forEach(function (participant) {
1834
1884
  if (participant.identity === identity) {
1835
1885
  foundParticipant = participant;
@@ -1845,10 +1895,10 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
1845
1895
 
1846
1896
  case 2:
1847
1897
  case "end":
1848
- return _context4.stop();
1898
+ return _context5.stop();
1849
1899
  }
1850
1900
  }
1851
- }, _callee4, this);
1901
+ }, _callee5, this);
1852
1902
  }));
1853
1903
 
1854
1904
  function getParticipantByIdentity(_x4) {
@@ -1865,26 +1915,26 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
1865
1915
  }, {
1866
1916
  key: "add",
1867
1917
  value: function () {
1868
- var _add = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5(identity, attributes) {
1869
- return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
1918
+ var _add = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee6(identity, attributes) {
1919
+ return _regeneratorRuntime__default['default'].wrap(function _callee6$(_context6) {
1870
1920
  while (1) {
1871
- switch (_context5.prev = _context5.next) {
1921
+ switch (_context6.prev = _context6.next) {
1872
1922
  case 0:
1873
- _context5.next = 2;
1923
+ _context6.next = 2;
1874
1924
  return this.services.commandExecutor.mutateResource('post', this.links.participants, {
1875
1925
  identity: identity,
1876
1926
  attributes: typeof attributes !== 'undefined' ? JSON.stringify(attributes) : undefined
1877
1927
  });
1878
1928
 
1879
1929
  case 2:
1880
- return _context5.abrupt("return", _context5.sent);
1930
+ return _context6.abrupt("return", _context6.sent);
1881
1931
 
1882
1932
  case 3:
1883
1933
  case "end":
1884
- return _context5.stop();
1934
+ return _context6.stop();
1885
1935
  }
1886
1936
  }
1887
- }, _callee5, this);
1937
+ }, _callee6, this);
1888
1938
  }));
1889
1939
 
1890
1940
  function add(_x5, _x6) {
@@ -1899,17 +1949,24 @@ var Participants = /*#__PURE__*/function (_ReplayEventEmitter) {
1899
1949
  * @param proxyAddress
1900
1950
  * @param address
1901
1951
  * @param attributes
1952
+ * @param bindingOptions
1902
1953
  * @returns {Promise<any>}
1903
1954
  */
1904
1955
 
1905
1956
  }, {
1906
1957
  key: "addNonChatParticipant",
1907
- value: function addNonChatParticipant(proxyAddress, address, attributes) {
1958
+ value: function addNonChatParticipant(proxyAddress, address) {
1959
+ var _bindingOptions$email, _bindingOptions$email2;
1960
+
1961
+ var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1962
+ var bindingOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1908
1963
  return this.services.commandExecutor.mutateResource('post', this.links.participants, {
1909
1964
  attributes: typeof attributes !== 'undefined' ? JSON.stringify(attributes) : undefined,
1910
1965
  messaging_binding: {
1911
1966
  address: address,
1912
- proxy_address: proxyAddress
1967
+ proxy_address: proxyAddress,
1968
+ name: bindingOptions === null || bindingOptions === void 0 ? void 0 : (_bindingOptions$email = bindingOptions.email) === null || _bindingOptions$email === void 0 ? void 0 : _bindingOptions$email.name,
1969
+ level: bindingOptions === null || bindingOptions === void 0 ? void 0 : (_bindingOptions$email2 = bindingOptions.email) === null || _bindingOptions$email2 === void 0 ? void 0 : _bindingOptions$email2.level
1913
1970
  }
1914
1971
  });
1915
1972
  }
@@ -2540,7 +2597,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2540
2597
  return this.state.attributes;
2541
2598
  }
2542
2599
  /**
2543
- * Push notification type of the message.
2600
+ * Type of the message.
2544
2601
  */
2545
2602
 
2546
2603
  }, {
@@ -2549,7 +2606,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2549
2606
  return this.state.type;
2550
2607
  }
2551
2608
  /**
2552
- * One of the attached media.
2609
+ * One of the attached media (if present).
2553
2610
  * @deprecated Use attachedMedia instead. Note that the latter is now an array.
2554
2611
  */
2555
2612
 
@@ -2601,6 +2658,38 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2601
2658
  return categories.includes(m.category);
2602
2659
  });
2603
2660
  }
2661
+ /**
2662
+ * Get a media descriptor for an email body attachment of a provided type.
2663
+ * Allowed body types are returned in the Conversation.limits().emailBodiesAllowedMimeTypes array.
2664
+ * @param type Type of email body to request, defaults to `text/plain`.
2665
+ */
2666
+
2667
+ }, {
2668
+ key: "getEmailBody",
2669
+ value: function getEmailBody() {
2670
+ var _this$getMediaByCateg, _this$getMediaByCateg2;
2671
+
2672
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'text/plain';
2673
+ return (_this$getMediaByCateg = (_this$getMediaByCateg2 = this.getMediaByCategory(['body'])) === null || _this$getMediaByCateg2 === void 0 ? void 0 : _this$getMediaByCateg2.filter(function (m) {
2674
+ return m.contentType == type;
2675
+ }).shift()) !== null && _this$getMediaByCateg !== void 0 ? _this$getMediaByCateg : null;
2676
+ }
2677
+ /**
2678
+ * Get a media descriptor for an email history attachment of a provided type.
2679
+ * Allowed body types are returned in the Conversation.limits().emailHistoriesAllowedMimeTypes array.
2680
+ * @param type Type of email history to request, defaults to `text/plain`.
2681
+ */
2682
+
2683
+ }, {
2684
+ key: "getEmailHistory",
2685
+ value: function getEmailHistory() {
2686
+ var _this$getMediaByCateg3, _this$getMediaByCateg4;
2687
+
2688
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'text/plain';
2689
+ return (_this$getMediaByCateg3 = (_this$getMediaByCateg4 = this.getMediaByCategory(['history'])) === null || _this$getMediaByCateg4 === void 0 ? void 0 : _this$getMediaByCateg4.filter(function (m) {
2690
+ return m.contentType == type;
2691
+ }).shift()) !== null && _this$getMediaByCateg3 !== void 0 ? _this$getMediaByCateg3 : null;
2692
+ }
2604
2693
  }, {
2605
2694
  key: "_update",
2606
2695
  value: function _update(data) {
@@ -3014,14 +3103,18 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3014
3103
 
3015
3104
  _defineProperty__default['default'](Message, "updated", 'updated');
3016
3105
 
3106
+ __decorate([declarativeTypeValidator.validateTypes(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Media)], Message.prototype, "getEmailBody", null);
3107
+
3108
+ __decorate([declarativeTypeValidator.validateTypes(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Media)], Message.prototype, "getEmailHistory", null);
3109
+
3017
3110
  __decorate([declarativeTypeValidator.validateTypesAsync('string'), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise)], Message.prototype, "updateBody", null);
3018
3111
 
3019
- __decorate([declarativeTypeValidator.validateTypesAsync(['string', 'number', 'boolean', 'object', declarativeTypeValidator.literal(null)]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], Message.prototype, "updateAttributes", null);
3112
+ __decorate([declarativeTypeValidator.validateTypesAsync(attributesValidator), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], Message.prototype, "updateAttributes", null);
3020
3113
 
3021
3114
  __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.custom(function (value) {
3022
3115
  return [value instanceof Array && value.length > 0 && value.reduce(function (a, c) {
3023
3116
  return a && c instanceof Media;
3024
- }), 'a non-empty array of Media'];
3117
+ }, true), 'a non-empty array of Media'];
3025
3118
  })), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", Promise)], Message.prototype, "attachTemporaryUrlsFor", null);
3026
3119
 
3027
3120
  function _createForOfIteratorHelper$2(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$2(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
@@ -3206,7 +3299,7 @@ var Messages = /*#__PURE__*/function (_ReplayEventEmitter) {
3206
3299
  /**
3207
3300
  * Send Message to the conversation, message could include both text and multiple media attachments.
3208
3301
  * @param message Message to post
3209
- * @returns Returns promise which can fail
3302
+ * @returns Returns a promise which can fail
3210
3303
  */
3211
3304
 
3212
3305
  }, {
@@ -3679,6 +3772,8 @@ var MessageBuilder = /*#__PURE__*/function () {
3679
3772
 
3680
3773
  this.limits = limits;
3681
3774
  this.message = new UnsentMessage(messagesEntity);
3775
+ this.emailBodies = new Map();
3776
+ this.emailHistories = new Map();
3682
3777
  }
3683
3778
  /**
3684
3779
  * Sets the message body.
@@ -3714,6 +3809,30 @@ var MessageBuilder = /*#__PURE__*/function () {
3714
3809
  this.message.attributes = attributes;
3715
3810
  return this;
3716
3811
  }
3812
+ /**
3813
+ * Set email body with given MIME-type.
3814
+ * @param mimeType Format of the body to set (text/plain or text/html).
3815
+ * @param body Body payload in selected format.
3816
+ */
3817
+
3818
+ }, {
3819
+ key: "setEmailBody",
3820
+ value: function setEmailBody(mimeType, body) {
3821
+ this.emailBodies.set(mimeType, body);
3822
+ return this;
3823
+ }
3824
+ /**
3825
+ * Set email history with given MIME-type.
3826
+ * @param mimeType Format of the history to set (text/plain or text/html).
3827
+ * @param history History payload in selected format.
3828
+ */
3829
+
3830
+ }, {
3831
+ key: "setEmailHistory",
3832
+ value: function setEmailHistory(mimeType, history) {
3833
+ this.emailHistories.set(mimeType, history);
3834
+ return this;
3835
+ }
3717
3836
  /**
3718
3837
  * Adds media to the message.
3719
3838
  * @param payload Media to add.
@@ -3722,6 +3841,18 @@ var MessageBuilder = /*#__PURE__*/function () {
3722
3841
  }, {
3723
3842
  key: "addMedia",
3724
3843
  value: function addMedia(payload) {
3844
+ if (typeof FormData === 'undefined' && payload instanceof FormData) {
3845
+ throw new Error('Could not add FormData content whilst not in a browser');
3846
+ }
3847
+
3848
+ if (!(payload instanceof FormData)) {
3849
+ var mediaOptions = payload;
3850
+
3851
+ if (!mediaOptions.contentType || !mediaOptions.media) {
3852
+ throw new Error('Media content in SendMediaOptions must contain non-empty contentType and media');
3853
+ }
3854
+ }
3855
+
3725
3856
  this.message.mediaContent.push(['media', payload]);
3726
3857
  return this;
3727
3858
  }
@@ -3732,11 +3863,39 @@ var MessageBuilder = /*#__PURE__*/function () {
3732
3863
  }, {
3733
3864
  key: "build",
3734
3865
  value: function build() {
3866
+ var _this = this;
3867
+
3868
+ this.emailBodies.forEach(function (_, key) {
3869
+ if (!_this.limits.emailBodiesAllowedMimeTypes.includes(key)) {
3870
+ throw new Error("Unsupported email body MIME type ".concat(key));
3871
+ }
3872
+ });
3873
+ this.emailHistories.forEach(function (_, key) {
3874
+ if (!_this.limits.emailHistoriesAllowedMimeTypes.includes(key)) {
3875
+ throw new Error("Unsupported email history MIME type ".concat(key));
3876
+ }
3877
+ });
3878
+
3879
+ if (this.emailBodies.size > this.limits.emailBodiesAllowedMimeTypes.length) {
3880
+ throw new Error("Too many email bodies attached to the message (".concat(this.emailBodies.size, " > ").concat(this.limits.emailBodiesAllowedMimeTypes.length, ")"));
3881
+ }
3882
+
3883
+ if (this.emailHistories.size > this.limits.emailHistoriesAllowedMimeTypes.length) {
3884
+ throw new Error("Too many email histories attached to the message (".concat(this.emailHistories.size, " > ").concat(this.limits.emailHistoriesAllowedMimeTypes.length, ")"));
3885
+ }
3886
+
3735
3887
  if (this.message.mediaContent.length > this.limits.mediaAttachmentsCountLimit) {
3736
3888
  throw new Error("Too many media attachments in the message (".concat(this.message.mediaContent.length, " > ").concat(this.limits.mediaAttachmentsCountLimit, ")"));
3737
3889
  } // @todo we don't know the sizes of the attachments in FormData
3890
+ // @todo insertion below makes build() method non-repeatable - probably move to UnsentMessage.send() or even sendV2()?
3738
3891
 
3739
3892
 
3893
+ this.emailBodies.forEach(function (body) {
3894
+ _this.message.mediaContent.push(['body', body]);
3895
+ });
3896
+ this.emailHistories.forEach(function (history) {
3897
+ _this.message.mediaContent.push(['history', history]);
3898
+ });
3740
3899
  return this.message;
3741
3900
  }
3742
3901
  }, {
@@ -3775,7 +3934,8 @@ var fieldMappings = {
3775
3934
  sid: 'sid',
3776
3935
  status: 'status',
3777
3936
  uniqueName: 'uniqueName',
3778
- state: 'state'
3937
+ state: 'state',
3938
+ bindings: 'bindings'
3779
3939
  };
3780
3940
 
3781
3941
  function parseTime(timeString) {
@@ -3803,6 +3963,8 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
3803
3963
  * @internal
3804
3964
  */
3805
3965
  function Conversation(descriptor, sid, links, configuration, services) {
3966
+ var _descriptor$bindings;
3967
+
3806
3968
  var _this;
3807
3969
 
3808
3970
  _classCallCheck__default['default'](this, Conversation);
@@ -3835,7 +3997,8 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
3835
3997
  dateCreated: dateCreated,
3836
3998
  dateUpdated: dateUpdated,
3837
3999
  friendlyName: friendlyName,
3838
- lastReadMessageIndex: lastReadMessageIndex
4000
+ lastReadMessageIndex: lastReadMessageIndex,
4001
+ bindings: (_descriptor$bindings = descriptor.bindings) !== null && _descriptor$bindings !== void 0 ? _descriptor$bindings : {}
3839
4002
  };
3840
4003
 
3841
4004
  if (descriptor.notificationLevel) {
@@ -3969,6 +4132,11 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
3969
4132
  get: function get() {
3970
4133
  return this.channelState.notificationLevel;
3971
4134
  }
4135
+ }, {
4136
+ key: "bindings",
4137
+ get: function get() {
4138
+ return this.channelState.bindings;
4139
+ }
3972
4140
  }, {
3973
4141
  key: "limits",
3974
4142
  get: function get() {
@@ -4258,6 +4426,15 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4258
4426
  updateReasons.add(localKey);
4259
4427
  break;
4260
4428
 
4429
+ case fieldMappings.bindings:
4430
+ if (isEqual__default['default'](this.channelState.bindings, update.bindings)) {
4431
+ break;
4432
+ }
4433
+
4434
+ this.channelState.bindings = update.bindings;
4435
+ updateReasons.add(localKey);
4436
+ break;
4437
+
4261
4438
  default:
4262
4439
  var isDate = update[key] instanceof Date;
4263
4440
  var keysMatchAsDates = isDate && ((_this$channelState$lo = this.channelState[localKey]) === null || _this$channelState$lo === void 0 ? void 0 : _this$channelState$lo.getTime()) === update[key].getTime();
@@ -4353,7 +4530,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4353
4530
  while (1) {
4354
4531
  switch (_context4.prev = _context4.next) {
4355
4532
  case 0:
4356
- return _context4.abrupt("return", this.participantsEntity.add(identity, attributes));
4533
+ return _context4.abrupt("return", this.participantsEntity.add(identity, attributes !== null && attributes !== void 0 ? attributes : {}));
4357
4534
 
4358
4535
  case 1:
4359
4536
  case "end":
@@ -4374,19 +4551,25 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4374
4551
  * @param proxyAddress Proxy (Twilio) address of the participant.
4375
4552
  * @param address User address of the participant.
4376
4553
  * @param attributes Attributes to be attached to the participant.
4554
+ * @param bindingOptions Options for adding email participants - name and CC/To level.
4377
4555
  */
4378
4556
 
4379
4557
  }, {
4380
4558
  key: "addNonChatParticipant",
4381
4559
  value: function () {
4382
- var _addNonChatParticipant = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5(proxyAddress, address, attributes) {
4560
+ var _addNonChatParticipant = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5(proxyAddress, address) {
4561
+ var attributes,
4562
+ bindingOptions,
4563
+ _args5 = arguments;
4383
4564
  return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
4384
4565
  while (1) {
4385
4566
  switch (_context5.prev = _context5.next) {
4386
4567
  case 0:
4387
- return _context5.abrupt("return", this.participantsEntity.addNonChatParticipant(proxyAddress, address, attributes));
4568
+ attributes = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : {};
4569
+ bindingOptions = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : {};
4570
+ return _context5.abrupt("return", this.participantsEntity.addNonChatParticipant(proxyAddress, address, attributes !== null && attributes !== void 0 ? attributes : {}, bindingOptions !== null && bindingOptions !== void 0 ? bindingOptions : {}));
4388
4571
 
4389
- case 1:
4572
+ case 3:
4390
4573
  case "end":
4391
4574
  return _context5.stop();
4392
4575
  }
@@ -4394,7 +4577,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4394
4577
  }, _callee5, this);
4395
4578
  }));
4396
4579
 
4397
- function addNonChatParticipant(_x4, _x5, _x6) {
4580
+ function addNonChatParticipant(_x4, _x5) {
4398
4581
  return _addNonChatParticipant.apply(this, arguments);
4399
4582
  }
4400
4583
 
@@ -4446,7 +4629,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4446
4629
  }, _callee6, this);
4447
4630
  }));
4448
4631
 
4449
- function advanceLastReadMessageIndex(_x7) {
4632
+ function advanceLastReadMessageIndex(_x6) {
4450
4633
  return _advanceLastReadMessageIndex.apply(this, arguments);
4451
4634
  }
4452
4635
 
@@ -4547,7 +4730,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4547
4730
  }, _callee9, this);
4548
4731
  }));
4549
4732
 
4550
- function getMessages(_x8, _x9, _x10) {
4733
+ function getMessages(_x7, _x8, _x9) {
4551
4734
  return _getMessages.apply(this, arguments);
4552
4735
  }
4553
4736
 
@@ -4650,7 +4833,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4650
4833
  }, _callee12, this);
4651
4834
  }));
4652
4835
 
4653
- function getParticipantBySid(_x11) {
4836
+ function getParticipantBySid(_x10) {
4654
4837
  return _getParticipantBySid.apply(this, arguments);
4655
4838
  }
4656
4839
 
@@ -4679,7 +4862,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4679
4862
  }, _callee13, this);
4680
4863
  }));
4681
4864
 
4682
- function getParticipantByIdentity(_x12) {
4865
+ function getParticipantByIdentity(_x11) {
4683
4866
  return _getParticipantByIdentity.apply(this, arguments);
4684
4867
  }
4685
4868
 
@@ -4889,7 +5072,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4889
5072
  }, _callee18, this);
4890
5073
  }));
4891
5074
 
4892
- function removeParticipant(_x13) {
5075
+ function removeParticipant(_x12) {
4893
5076
  return _removeParticipant.apply(this, arguments);
4894
5077
  }
4895
5078
 
@@ -4942,7 +5125,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4942
5125
  }, _callee19, this);
4943
5126
  }));
4944
5127
 
4945
- function sendMessage(_x14, _x15, _x16) {
5128
+ function sendMessage(_x13, _x14, _x15) {
4946
5129
  return _sendMessage.apply(this, arguments);
4947
5130
  }
4948
5131
 
@@ -4951,6 +5134,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
4951
5134
  /**
4952
5135
  * New interface to prepare for sending a message.
4953
5136
  * Use instead of `sendMessage`.
5137
+ * @return A MessageBuilder to help set all message sending options.
4954
5138
  */
4955
5139
 
4956
5140
  }, {
@@ -5069,7 +5253,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
5069
5253
  }, _callee22, this);
5070
5254
  }));
5071
5255
 
5072
- function setUserNotificationLevel(_x17) {
5256
+ function setUserNotificationLevel(_x16) {
5073
5257
  return _setUserNotificationLevel.apply(this, arguments);
5074
5258
  }
5075
5259
 
@@ -5114,7 +5298,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
5114
5298
  }, _callee23, this);
5115
5299
  }));
5116
5300
 
5117
- function updateAttributes(_x18) {
5301
+ function updateAttributes(_x17) {
5118
5302
  return _updateAttributes.apply(this, arguments);
5119
5303
  }
5120
5304
 
@@ -5154,7 +5338,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
5154
5338
  }, _callee24, this);
5155
5339
  }));
5156
5340
 
5157
- function updateFriendlyName(_x19) {
5341
+ function updateFriendlyName(_x18) {
5158
5342
  return _updateFriendlyName.apply(this, arguments);
5159
5343
  }
5160
5344
 
@@ -5189,7 +5373,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
5189
5373
  }, _callee25, this);
5190
5374
  }));
5191
5375
 
5192
- function updateLastReadMessageIndex(_x20) {
5376
+ function updateLastReadMessageIndex(_x19) {
5193
5377
  return _updateLastReadMessageIndex.apply(this, arguments);
5194
5378
  }
5195
5379
 
@@ -5233,7 +5417,7 @@ var Conversation = /*#__PURE__*/function (_ReplayEventEmitter) {
5233
5417
  }, _callee26, this);
5234
5418
  }));
5235
5419
 
5236
- function updateUniqueName(_x21) {
5420
+ function updateUniqueName(_x20) {
5237
5421
  return _updateUniqueName.apply(this, arguments);
5238
5422
  }
5239
5423
 
@@ -5305,9 +5489,9 @@ _defineProperty__default['default'](Conversation, "updated", 'updated');
5305
5489
 
5306
5490
  _defineProperty__default['default'](Conversation, "removed", 'removed');
5307
5491
 
5308
- __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, ['undefined', 'string', 'number', 'boolean', 'object', declarativeTypeValidator.literal(null)]), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "add", null);
5492
+ __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, optionalAttributesValidator), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "add", null);
5309
5493
 
5310
- __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, declarativeTypeValidator.nonEmptyString, ['undefined', 'string', 'number', 'boolean', 'object', declarativeTypeValidator.literal(null)]), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "addNonChatParticipant", null);
5494
+ __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, declarativeTypeValidator.nonEmptyString, optionalAttributesValidator), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, Object, Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "addNonChatParticipant", null);
5311
5495
 
5312
5496
  __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonNegativeInteger), __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", Promise)], Conversation.prototype, "advanceLastReadMessageIndex", null);
5313
5497
 
@@ -5333,13 +5517,13 @@ declarativeTypeValidator.custom(function (value) {
5333
5517
 
5334
5518
  return [isValid, 'a non-empty string, an instance of Buffer or an instance of Blob'];
5335
5519
  })
5336
- })], ['undefined', 'string', 'number', 'boolean', 'object', declarativeTypeValidator.literal(null)], ['undefined', declarativeTypeValidator.literal(null), declarativeTypeValidator.objectSchema('email attributes', {
5520
+ })], optionalAttributesValidator, ['undefined', declarativeTypeValidator.literal(null), declarativeTypeValidator.objectSchema('email attributes', {
5337
5521
  subject: [declarativeTypeValidator.nonEmptyString, 'undefined']
5338
5522
  })]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "sendMessage", null);
5339
5523
 
5340
5524
  __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal('default', 'muted')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise)], Conversation.prototype, "setUserNotificationLevel", null);
5341
5525
 
5342
- __decorate([declarativeTypeValidator.validateTypesAsync(['string', 'number', 'boolean', 'object', declarativeTypeValidator.literal(null)]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "updateAttributes", null);
5526
+ __decorate([declarativeTypeValidator.validateTypesAsync(attributesValidator), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], Conversation.prototype, "updateAttributes", null);
5343
5527
 
5344
5528
  __decorate([declarativeTypeValidator.validateTypesAsync(['string']), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise)], Conversation.prototype, "updateFriendlyName", null);
5345
5529
 
@@ -6082,7 +6266,7 @@ var Conversations = /*#__PURE__*/function (_ReplayEventEmitter) {
6082
6266
  channel: conversationDescriptor.sync_objects.conversation,
6083
6267
  messages: conversationDescriptor.sync_objects.messages,
6084
6268
  roster: "".concat(conversationDescriptor.conversation_sid, ".roster"),
6085
- lastConsumedMessageIndex: conversationDescriptor.last_consumed_message_index,
6269
+ lastConsumedMessageIndex: conversationDescriptor.last_read_message_index,
6086
6270
  notificationLevel: conversationDescriptor.notification_level
6087
6271
  };
6088
6272
  });
@@ -6599,7 +6783,7 @@ function PushNotification(data) {
6599
6783
  this.data = data.data || {};
6600
6784
  };
6601
6785
 
6602
- var version = "2.0.1-rc.7";
6786
+ var version = "2.1.0-rc.1";
6603
6787
 
6604
6788
  function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
6605
6789