@bentonow/bento-node-sdk 0.1.9 → 0.1.12

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.
@@ -1107,15 +1107,6 @@ var NotAuthorizedError = /*#__PURE__*/function (_Error) {
1107
1107
 
1108
1108
  return NotAuthorizedError;
1109
1109
  }( /*#__PURE__*/_wrapNativeSuper(Error));
1110
- var InternalServerError = /*#__PURE__*/function (_Error2) {
1111
- _inheritsLoose(InternalServerError, _Error2);
1112
-
1113
- function InternalServerError() {
1114
- return _Error2.apply(this, arguments) || this;
1115
- }
1116
-
1117
- return InternalServerError;
1118
- }( /*#__PURE__*/_wrapNativeSuper(Error));
1119
1110
 
1120
1111
  var BentoClient = /*#__PURE__*/function () {
1121
1112
  function BentoClient(options) {
@@ -1153,13 +1144,38 @@ var BentoClient = /*#__PURE__*/function () {
1153
1144
  fetch("" + _this._baseUrl + endpoint + "?" + queryParameters, {
1154
1145
  method: 'GET',
1155
1146
  headers: _this._headers
1156
- }).then(function (result) {
1157
- if (_this._isSuccessfulStatus(result.status)) {
1158
- return result.json();
1159
- }
1147
+ }).then( /*#__PURE__*/function () {
1148
+ var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(result) {
1149
+ return runtime_1.wrap(function _callee$(_context) {
1150
+ while (1) {
1151
+ switch (_context.prev = _context.next) {
1152
+ case 0:
1153
+ if (!_this._isSuccessfulStatus(result.status)) {
1154
+ _context.next = 2;
1155
+ break;
1156
+ }
1157
+
1158
+ return _context.abrupt("return", result.json());
1159
+
1160
+ case 2:
1161
+ _context.next = 4;
1162
+ return _this._getErrorForResponse(result);
1163
+
1164
+ case 4:
1165
+ throw _context.sent;
1166
+
1167
+ case 5:
1168
+ case "end":
1169
+ return _context.stop();
1170
+ }
1171
+ }
1172
+ }, _callee);
1173
+ }));
1160
1174
 
1161
- throw _this._getErrorForResponse(result);
1162
- }).then(function (data) {
1175
+ return function (_x) {
1176
+ return _ref.apply(this, arguments);
1177
+ };
1178
+ }()).then(function (data) {
1163
1179
  return resolve(data);
1164
1180
  })["catch"](function (error) {
1165
1181
  return reject(error);
@@ -1192,13 +1208,38 @@ var BentoClient = /*#__PURE__*/function () {
1192
1208
  'Content-Type': 'application/json'
1193
1209
  }),
1194
1210
  body: body
1195
- }).then(function (result) {
1196
- if (_this2._isSuccessfulStatus(result.status)) {
1197
- return result.json();
1198
- }
1211
+ }).then( /*#__PURE__*/function () {
1212
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(result) {
1213
+ return runtime_1.wrap(function _callee2$(_context2) {
1214
+ while (1) {
1215
+ switch (_context2.prev = _context2.next) {
1216
+ case 0:
1217
+ if (!_this2._isSuccessfulStatus(result.status)) {
1218
+ _context2.next = 2;
1219
+ break;
1220
+ }
1221
+
1222
+ return _context2.abrupt("return", result.json());
1223
+
1224
+ case 2:
1225
+ _context2.next = 4;
1226
+ return _this2._getErrorForResponse(result);
1227
+
1228
+ case 4:
1229
+ throw _context2.sent;
1230
+
1231
+ case 5:
1232
+ case "end":
1233
+ return _context2.stop();
1234
+ }
1235
+ }
1236
+ }, _callee2);
1237
+ }));
1199
1238
 
1200
- throw _this2._getErrorForResponse(result);
1201
- }).then(function (data) {
1239
+ return function (_x2) {
1240
+ return _ref2.apply(this, arguments);
1241
+ };
1242
+ }()).then(function (data) {
1202
1243
  return resolve(data);
1203
1244
  })["catch"](function (error) {
1204
1245
  return reject(error);
@@ -1279,10 +1320,68 @@ var BentoClient = /*#__PURE__*/function () {
1279
1320
  */
1280
1321
  ;
1281
1322
 
1282
- _proto._getErrorForResponse = function _getErrorForResponse(response) {
1283
- if (response.status === 401) return new NotAuthorizedError();
1284
- return new InternalServerError();
1285
- };
1323
+ _proto._getErrorForResponse =
1324
+ /*#__PURE__*/
1325
+ function () {
1326
+ var _getErrorForResponse2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(response) {
1327
+ var contentType, responseMessage;
1328
+ return runtime_1.wrap(function _callee3$(_context3) {
1329
+ while (1) {
1330
+ switch (_context3.prev = _context3.next) {
1331
+ case 0:
1332
+ if (!(response.status === 401)) {
1333
+ _context3.next = 2;
1334
+ break;
1335
+ }
1336
+
1337
+ return _context3.abrupt("return", new NotAuthorizedError());
1338
+
1339
+ case 2:
1340
+ contentType = response.headers.get('Content-Type');
1341
+ responseMessage = '';
1342
+ _context3.t0 = contentType == null ? void 0 : contentType.toLocaleLowerCase();
1343
+ _context3.next = _context3.t0 === 'text/plain' ? 7 : _context3.t0 === 'application/json' ? 11 : 17;
1344
+ break;
1345
+
1346
+ case 7:
1347
+ _context3.next = 9;
1348
+ return response.text();
1349
+
1350
+ case 9:
1351
+ responseMessage = _context3.sent;
1352
+ return _context3.abrupt("break", 19);
1353
+
1354
+ case 11:
1355
+ _context3.t1 = JSON;
1356
+ _context3.next = 14;
1357
+ return response.json();
1358
+
1359
+ case 14:
1360
+ _context3.t2 = _context3.sent;
1361
+ responseMessage = _context3.t1.stringify.call(_context3.t1, _context3.t2);
1362
+ return _context3.abrupt("break", 19);
1363
+
1364
+ case 17:
1365
+ responseMessage = 'Unknown response from the Bento API.';
1366
+ return _context3.abrupt("break", 19);
1367
+
1368
+ case 19:
1369
+ return _context3.abrupt("return", new Error("[" + response.status + "] - " + responseMessage));
1370
+
1371
+ case 20:
1372
+ case "end":
1373
+ return _context3.stop();
1374
+ }
1375
+ }
1376
+ }, _callee3);
1377
+ }));
1378
+
1379
+ function _getErrorForResponse(_x3) {
1380
+ return _getErrorForResponse2.apply(this, arguments);
1381
+ }
1382
+
1383
+ return _getErrorForResponse;
1384
+ }();
1286
1385
 
1287
1386
  return BentoClient;
1288
1387
  }();
@@ -1295,6 +1394,7 @@ var CommandTypes;
1295
1394
  (function (CommandTypes) {
1296
1395
  CommandTypes["ADD_FIELD"] = "add_field";
1297
1396
  CommandTypes["ADD_TAG"] = "add_tag";
1397
+ CommandTypes["CHANGE_EMAIL"] = "change_email";
1298
1398
  CommandTypes["REMOVE_FIELD"] = "remove_field";
1299
1399
  CommandTypes["REMOVE_TAG"] = "remove_tag";
1300
1400
  CommandTypes["SUBSCRIBE"] = "subscribe";
@@ -1682,6 +1782,65 @@ var BentoCommands = /*#__PURE__*/function () {
1682
1782
  }
1683
1783
 
1684
1784
  return unsubscribe;
1785
+ }()
1786
+ /**
1787
+ * Updates the email of a user in Bento.
1788
+ *
1789
+ * @param parameters \{ oldEmail: string, newEmail: string \}
1790
+ * @returns Promise\<Subscriber | null\>
1791
+ */
1792
+ ;
1793
+
1794
+ _proto.changeEmail =
1795
+ /*#__PURE__*/
1796
+ function () {
1797
+ var _changeEmail = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(parameters) {
1798
+ var result;
1799
+ return runtime_1.wrap(function _callee7$(_context7) {
1800
+ while (1) {
1801
+ switch (_context7.prev = _context7.next) {
1802
+ case 0:
1803
+ _context7.prev = 0;
1804
+ _context7.next = 3;
1805
+ return this._client.post(this._url, {
1806
+ command: {
1807
+ command: CommandTypes.CHANGE_EMAIL,
1808
+ email: parameters.oldEmail,
1809
+ query: parameters.newEmail
1810
+ }
1811
+ });
1812
+
1813
+ case 3:
1814
+ result = _context7.sent;
1815
+
1816
+ if (!(Object.keys(result).length === 0 || !result.data)) {
1817
+ _context7.next = 6;
1818
+ break;
1819
+ }
1820
+
1821
+ return _context7.abrupt("return", null);
1822
+
1823
+ case 6:
1824
+ return _context7.abrupt("return", result.data);
1825
+
1826
+ case 9:
1827
+ _context7.prev = 9;
1828
+ _context7.t0 = _context7["catch"](0);
1829
+ throw _context7.t0;
1830
+
1831
+ case 12:
1832
+ case "end":
1833
+ return _context7.stop();
1834
+ }
1835
+ }
1836
+ }, _callee7, this, [[0, 9]]);
1837
+ }));
1838
+
1839
+ function changeEmail(_x7) {
1840
+ return _changeEmail.apply(this, arguments);
1841
+ }
1842
+
1843
+ return changeEmail;
1685
1844
  }();
1686
1845
 
1687
1846
  return BentoCommands;
@@ -2349,6 +2508,7 @@ var BentoEvents;
2349
2508
  BentoEvents["PURCHASE"] = "$purchase";
2350
2509
  BentoEvents["SUBSCRIBE"] = "$subscribe";
2351
2510
  BentoEvents["TAG"] = "$tag";
2511
+ BentoEvents["REMOVE_TAG"] = "$remove_tag";
2352
2512
  BentoEvents["UNSUBSCRIBE"] = "$unsubscribe";
2353
2513
  BentoEvents["UPDATE_FIELDS"] = "$update_fields";
2354
2514
  })(BentoEvents || (BentoEvents = {}));
@@ -2759,5 +2919,5 @@ var Analytics = function Analytics(options) {
2759
2919
  this.V1 = new BentoAPIV1(options);
2760
2920
  };
2761
2921
 
2762
- export { Analytics, InternalServerError, NotAuthorizedError };
2922
+ export { Analytics, NotAuthorizedError };
2763
2923
  //# sourceMappingURL=bento-node-sdk.esm.js.map