@veloceapps/sdk 4.0.0 → 4.0.2

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