@bentonow/bento-node-sdk 0.1.14 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -973,10 +973,45 @@ var TooManyEventsError = /*#__PURE__*/function (_Error4) {
973
973
 
974
974
  return TooManyEventsError;
975
975
  }( /*#__PURE__*/_wrapNativeSuper(Error));
976
+ var TooFewEmailsError = /*#__PURE__*/function (_Error5) {
977
+ _inheritsLoose(TooFewEmailsError, _Error5);
978
+
979
+ function TooFewEmailsError(message) {
980
+ var _this5;
981
+
982
+ if (message === void 0) {
983
+ message = 'Too few emails';
984
+ }
985
+
986
+ _this5 = _Error5.call(this, message) || this;
987
+ _this5.name = 'TooFewEmailsError';
988
+ return _this5;
989
+ }
990
+
991
+ return TooFewEmailsError;
992
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
993
+ var TooManyEmailsError = /*#__PURE__*/function (_Error6) {
994
+ _inheritsLoose(TooManyEmailsError, _Error6);
995
+
996
+ function TooManyEmailsError(message) {
997
+ var _this6;
998
+
999
+ if (message === void 0) {
1000
+ message = 'Too many emails';
1001
+ }
1002
+
1003
+ _this6 = _Error6.call(this, message) || this;
1004
+ _this6.name = 'TooManyEmailsError';
1005
+ return _this6;
1006
+ }
1007
+
1008
+ return TooManyEmailsError;
1009
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
976
1010
 
977
1011
  var BentoBatch = /*#__PURE__*/function () {
978
1012
  function BentoBatch(_client) {
979
1013
  this._client = void 0;
1014
+ this._maxEmailBatchSize = 100;
980
1015
  this._maxBatchSize = 1000;
981
1016
  this._url = '/batch';
982
1017
  this._client = _client;
@@ -1111,6 +1146,70 @@ var BentoBatch = /*#__PURE__*/function () {
1111
1146
  }
1112
1147
 
1113
1148
  return importEvents;
1149
+ }()
1150
+ /**
1151
+ * Creates a batch job to send transactional emails from Bento's infrastructure. You can pass in
1152
+ * between 1 and 100 emails to send.
1153
+ *
1154
+ * Each email must have a `to` address, a `from` address, a `subject`, an `html_body`
1155
+ * and `transactional: true`.
1156
+ * In addition you can add a `personalizations` object to provide
1157
+ * liquid tsags that will be injected into the email.
1158
+ *
1159
+ * Returns the number of events that were imported.
1160
+ *
1161
+ * @param parameters
1162
+ * @returns Promise\<number\>
1163
+ */
1164
+ ;
1165
+
1166
+ _proto.sendTransactionalEmails =
1167
+ /*#__PURE__*/
1168
+ function () {
1169
+ var _sendTransactionalEmails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(parameters) {
1170
+ var result;
1171
+ return runtime_1.wrap(function _callee3$(_context3) {
1172
+ while (1) {
1173
+ switch (_context3.prev = _context3.next) {
1174
+ case 0:
1175
+ if (!(parameters.emails.length === 0)) {
1176
+ _context3.next = 2;
1177
+ break;
1178
+ }
1179
+
1180
+ throw new TooFewEmailsError("You must send between 1 and 100 emails.");
1181
+
1182
+ case 2:
1183
+ if (!(parameters.emails.length > this._maxEmailBatchSize)) {
1184
+ _context3.next = 4;
1185
+ break;
1186
+ }
1187
+
1188
+ throw new TooManyEmailsError("You must send between 1 and 100 emails.");
1189
+
1190
+ case 4:
1191
+ _context3.next = 6;
1192
+ return this._client.post(this._url + "/emails", {
1193
+ emails: parameters.emails
1194
+ });
1195
+
1196
+ case 6:
1197
+ result = _context3.sent;
1198
+ return _context3.abrupt("return", result.results);
1199
+
1200
+ case 8:
1201
+ case "end":
1202
+ return _context3.stop();
1203
+ }
1204
+ }
1205
+ }, _callee3, this);
1206
+ }));
1207
+
1208
+ function sendTransactionalEmails(_x3) {
1209
+ return _sendTransactionalEmails.apply(this, arguments);
1210
+ }
1211
+
1212
+ return sendTransactionalEmails;
1114
1213
  }();
1115
1214
 
1116
1215
  return BentoBatch;