@veloceapps/sdk 4.0.0 → 4.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.
@@ -1285,31 +1285,31 @@
1285
1285
  this.updateService = updateService;
1286
1286
  this.configurationService = configurationService;
1287
1287
  }
1288
- FlowConfigurationService.prototype.calculate$ = function () {
1288
+ FlowConfigurationService.prototype.calculate$ = function (quoteDraft) {
1289
1289
  var _this = this;
1290
- var quoteDraft = this.quoteDraftService.quoteDraft;
1291
- if (!quoteDraft || !quoteDraft.currentState.length) {
1292
- return rxjs.of(undefined);
1293
- }
1294
1290
  return this.proceduresApiService.apply$(quoteDraft).pipe(rxjs.tap(function (result) { return _this.quoteDraftService.updateQuoteDraft(result); }), rxjs.map(rxjs.noop));
1295
1291
  };
1296
- FlowConfigurationService.prototype.calculate = function () {
1297
- this.calculate$().subscribe();
1292
+ FlowConfigurationService.prototype.calculate = function (quoteDraft) {
1293
+ this.calculate$(quoteDraft).subscribe();
1298
1294
  };
1299
1295
  FlowConfigurationService.prototype.update$ = function (updates) {
1300
1296
  var _this = this;
1301
- var currentState = this.quoteDraftService.currentState;
1302
- return rxjs.of([]).pipe(rxjs.tap(function () {
1303
- var updatedState = lodash.cloneDeep(currentState);
1297
+ var quoteDraft = this.quoteDraftService.quoteDraft;
1298
+ if (!quoteDraft) {
1299
+ return rxjs.of(null);
1300
+ }
1301
+ return rxjs.of([]).pipe(rxjs.map(function () {
1302
+ var updatedState = lodash.cloneDeep(quoteDraft.currentState);
1304
1303
  _this.updateService.update(updatedState, updates);
1305
- _this.quoteDraftService.setCurrentLineItemState(updatedState);
1306
- }), rxjs.switchMap(function () { return _this.calculate$(); }), rxjs.map(function () { return _this.quoteDraftService.quoteDraft; }), this.handleErrorAndBounceBack(currentState));
1304
+ return updatedState;
1305
+ }), rxjs.switchMap(function (updatedState) { return _this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState })); }), rxjs.map(function () { return _this.quoteDraftService.quoteDraft; }), this.handleErrorAndBounceBack());
1307
1306
  };
1308
1307
  FlowConfigurationService.prototype.update = function (updates) {
1309
1308
  this.update$(updates).subscribe();
1310
1309
  };
1311
1310
  FlowConfigurationService.prototype.revert$ = function (lineItemId) {
1312
1311
  var _this = this;
1312
+ var quoteDraft = this.quoteDraftService.quoteDraft;
1313
1313
  var initialState = this.quoteDraftService.activeInitialState;
1314
1314
  var currentState = this.quoteDraftService.activeCurrentState;
1315
1315
  var currentLineItemIndex = currentState.findIndex(function (_c) {
@@ -1321,50 +1321,51 @@
1321
1321
  var integrationId = _c.integrationId;
1322
1322
  return integrationId === (currentLineItem === null || currentLineItem === void 0 ? void 0 : currentLineItem.integrationId);
1323
1323
  });
1324
- if (!currentLineItem || !initialLineItem) {
1324
+ if (!quoteDraft || !currentLineItem || !initialLineItem) {
1325
1325
  return rxjs.of(null);
1326
1326
  }
1327
1327
  var updatedState = lodash.cloneDeep(currentState);
1328
1328
  updatedState.splice(currentLineItemIndex, 1, initialLineItem);
1329
1329
  return rxjs.of([]).pipe(rxjs.tap(function () {
1330
1330
  _this.quoteDraftService.setCurrentLineItemState(updatedState);
1331
- }), rxjs.switchMap(function () { return _this.calculate$(); }), rxjs.map(function () { return _this.quoteDraftService.quoteDraft; }), this.handleErrorAndBounceBack(currentState));
1331
+ }), rxjs.switchMap(function () { return _this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState })); }), rxjs.map(function () { return _this.quoteDraftService.quoteDraft; }), this.handleErrorAndBounceBack());
1332
1332
  };
1333
1333
  FlowConfigurationService.prototype.revert = function (lineItemId) {
1334
1334
  this.revert$(lineItemId).subscribe();
1335
1335
  };
1336
1336
  FlowConfigurationService.prototype.delete$ = function (ids) {
1337
1337
  var _this = this;
1338
+ var quoteDraft = this.quoteDraftService.quoteDraft;
1338
1339
  var currentState = this.quoteDraftService.currentState;
1339
- return rxjs.of([]).pipe(rxjs.tap(function () {
1340
- var updatedState = ids.reduce(function (result, id) { return _this.updateService.delete(result, id); }, currentState);
1341
- _this.quoteDraftService.setCurrentLineItemState(updatedState);
1342
- }), rxjs.switchMap(function () { return _this.calculate$(); }), rxjs.map(function () { return _this.quoteDraftService.quoteDraft; }), this.handleErrorAndBounceBack(currentState));
1340
+ if (!quoteDraft) {
1341
+ return rxjs.of(null);
1342
+ }
1343
+ return rxjs.of([]).pipe(rxjs.map(function () { return ids.reduce(function (result, id) { return _this.updateService.delete(result, id); }, currentState); }), rxjs.switchMap(function (updatedState) { return _this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState })); }), rxjs.map(function () { return _this.quoteDraftService.quoteDraft; }), this.handleErrorAndBounceBack());
1343
1344
  };
1344
1345
  FlowConfigurationService.prototype.delete = function (ids) {
1345
1346
  this.delete$(ids).subscribe();
1346
1347
  };
1347
1348
  FlowConfigurationService.prototype.addTerm$ = function (term) {
1348
1349
  var _this = this;
1349
- var currentState = this.quoteDraftService.currentState;
1350
- return rxjs.of([]).pipe(rxjs.tap(function () { return _this.quoteDraftService.setCurrentLineItemState(__spreadArray(__spreadArray([], __read(currentState)), [term])); }), rxjs.switchMap(function () { return _this.calculate$(); }), rxjs.map(function () { return _this.quoteDraftService.quoteDraft; }), this.handleErrorAndBounceBack(currentState));
1350
+ var quoteDraft = this.quoteDraftService.quoteDraft;
1351
+ if (!quoteDraft) {
1352
+ return rxjs.of(null);
1353
+ }
1354
+ var updatedState = __spreadArray(__spreadArray([], __read(quoteDraft.currentState)), [term]);
1355
+ return rxjs.of([]).pipe(rxjs.switchMap(function () { return _this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState })); }), rxjs.map(function () { return _this.quoteDraftService.quoteDraft; }), this.handleErrorAndBounceBack());
1351
1356
  };
1352
1357
  FlowConfigurationService.prototype.addToCart$ = function (productId, qty) {
1353
1358
  var _this = this;
1354
- var currentState = this.quoteDraftService.currentState;
1355
- return this.configurationService.configureExternal$(productId, qty).pipe(rxjs.tap(function (lineItem) { return _this.quoteDraftService.setCurrentLineItemState(__spreadArray(__spreadArray([], __read(currentState)), [lineItem])); }), rxjs.switchMap(function () { return _this.calculate$(); }), rxjs.map(function () { return _this.quoteDraftService.quoteDraft; }), this.handleErrorAndBounceBack(currentState));
1359
+ var quoteDraft = this.quoteDraftService.quoteDraft;
1360
+ if (!quoteDraft) {
1361
+ return rxjs.of(null);
1362
+ }
1363
+ return this.configurationService.configureExternal$(productId, qty).pipe(rxjs.map(function (lineItem) { return __spreadArray(__spreadArray([], __read(quoteDraft.currentState)), [lineItem]); }), rxjs.switchMap(function (updatedState) { return _this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState })); }), rxjs.map(function () { return _this.quoteDraftService.quoteDraft; }), this.handleErrorAndBounceBack());
1356
1364
  };
1357
1365
  FlowConfigurationService.prototype.get = function () {
1358
1366
  var _this = this;
1359
1367
  return this.quoteDraftService.quoteDraft$.pipe(rxjs.map(function () { return _this.quoteDraftService.activeCurrentState; }), rxjs.shareReplay());
1360
1368
  };
1361
- /**
1362
- * Returns only active lineItems with `actionCode !== 'DELETE'`.
1363
- */
1364
- FlowConfigurationService.prototype.getActive = function () {
1365
- var _this = this;
1366
- return this.quoteDraftService.quoteDraft$.pipe(rxjs.map(function () { return _this.quoteDraftService.activeCurrentState.filter(function (li) { return li.actionCode !== 'DELETE'; }); }), rxjs.shareReplay());
1367
- };
1368
1369
  FlowConfigurationService.prototype.getSnapshot = function () {
1369
1370
  var _a, _b;
1370
1371
  return (_b = (_a = this.quoteDraftService) === null || _a === void 0 ? void 0 : _a.currentState.slice()) !== null && _b !== void 0 ? _b : [];
@@ -1401,13 +1402,16 @@
1401
1402
  enumerable: false,
1402
1403
  configurable: true
1403
1404
  });
1404
- FlowConfigurationService.prototype.handleErrorAndBounceBack = function (stateToRestore) {
1405
+ FlowConfigurationService.prototype.handleErrorAndBounceBack = function () {
1405
1406
  var _this = this;
1406
1407
  return function (source$) {
1407
1408
  return source$.pipe(rxjs.catchError(function (error) {
1408
1409
  console.error(error);
1409
1410
  // bounce back if configuration call has failed
1410
- _this.quoteDraftService.setCurrentLineItemState(stateToRestore);
1411
+ var quoteDraft = _this.quoteDraftService.quoteDraft;
1412
+ if (quoteDraft) {
1413
+ _this.quoteDraftService.updateQuoteDraft(quoteDraft);
1414
+ }
1411
1415
  return rxjs.throwError(function () { return error; });
1412
1416
  }));
1413
1417
  };