@veloceapps/sdk 3.0.13 → 3.0.15

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.
@@ -1287,9 +1287,7 @@
1287
1287
  .configureLineItem({ configurationRequest: configurationRequest, runtimeModel: runtimeModel, pricingEnabled: pricingEnabled })
1288
1288
  .pipe(rxjsOperators.map(function (_f) {
1289
1289
  var lineItem = _f.lineItem, context = _f.context, charges = _f.charges, deletedLineItems = _f.deletedLineItems;
1290
- if (context) {
1291
- _this.contextService.update({ properties: context.properties });
1292
- }
1290
+ _this.contextService.update(context !== null && context !== void 0 ? context : {});
1293
1291
  _this.charges.next(charges !== null && charges !== void 0 ? charges : {});
1294
1292
  if (deletedLineItems === null || deletedLineItems === void 0 ? void 0 : deletedLineItems.length) {
1295
1293
  _this.showInactiveProductsConfirmation();
@@ -1794,18 +1792,36 @@
1794
1792
  var FlowUpdateService = /** @class */ (function () {
1795
1793
  function FlowUpdateService() {
1796
1794
  }
1797
- FlowUpdateService.prototype.update = function (rootLineItem, params) {
1798
- switch (params.attributeType) {
1799
- case 'QTY':
1800
- return this.updateQty(rootLineItem, params);
1801
- case 'EFFECTIVE_START_DATE':
1802
- return this.updateEffectiveStartDate(rootLineItem, params);
1803
- case 'END_DATE':
1804
- return this.updateEndDate(rootLineItem, params);
1805
- case 'PRICE_ADJUSTMENT':
1806
- return this.updatePriceAdjustment(rootLineItem, params);
1807
- default:
1808
- return rootLineItem;
1795
+ FlowUpdateService.prototype.update = function (rootLineItems, updates) {
1796
+ var _this = this;
1797
+ var remainingUpdates = __spreadArray([], __read(updates));
1798
+ var currentLevel = rootLineItems;
1799
+ while (currentLevel.length && remainingUpdates.length) {
1800
+ currentLevel.forEach(function (li) {
1801
+ var unhandledUpdates = [];
1802
+ remainingUpdates.forEach(function (update) {
1803
+ var updated = false;
1804
+ switch (update.dataType) {
1805
+ case 'LINEITEM':
1806
+ updated = _this.applyLineItemUpdate(li, update);
1807
+ break;
1808
+ case 'CHARGE':
1809
+ updated = _this.applyChargeUpdate(li, update);
1810
+ break;
1811
+ case 'GROUP_CHARGE':
1812
+ updated = _this.applyChargeGroupUpdate(li, update);
1813
+ break;
1814
+ default:
1815
+ // Unknown dataType. Do not try to handle it anymore
1816
+ updated = true;
1817
+ }
1818
+ if (!updated) {
1819
+ unhandledUpdates.push(update);
1820
+ }
1821
+ });
1822
+ remainingUpdates = unhandledUpdates;
1823
+ });
1824
+ currentLevel = lodash.flatten(currentLevel.map(function (parent) { return parent.lineItems; }));
1809
1825
  }
1810
1826
  };
1811
1827
  FlowUpdateService.prototype.delete = function (lineItems, id) {
@@ -1825,77 +1841,64 @@
1825
1841
  var filtered = lineItems.filter(function (lineItem) { return !idsToRemove.includes(lineItem.id); });
1826
1842
  return filtered.map(function (lineItem) { return new LineItemWorker(lineItem).remove(id).li; });
1827
1843
  };
1828
- FlowUpdateService.prototype.updateQty = function (rootLineItem, params) {
1829
- // change quantity allowed only for lineItem
1830
- if (params.dataType !== 'LINEITEM') {
1831
- return rootLineItem;
1832
- }
1833
- var lineItem = findLineItem(params.id, [rootLineItem]);
1834
- if (!lineItem) {
1835
- return rootLineItem;
1836
- }
1837
- if (lineItem.id !== rootLineItem.id) {
1838
- throw new Error('Quantity can be changed only for root product');
1839
- }
1840
- var updated = new LineItemWorker(rootLineItem).replace(Object.assign(Object.assign({}, lineItem), { qty: params.newValue }));
1841
- return updated.li;
1842
- };
1843
- FlowUpdateService.prototype.updateEffectiveStartDate = function (rootLineItem, params) {
1844
- var lineItem = findLineItem(params.id, [rootLineItem]);
1845
- if (!lineItem) {
1846
- return rootLineItem;
1847
- }
1848
- var updated = new LineItemWorker(rootLineItem).replace(Object.assign(Object.assign({}, lineItem), { effectiveStartDate: moment__default["default"](params.newValue).format('YYYY-MM-DD') }));
1849
- return updated.li;
1850
- };
1851
- FlowUpdateService.prototype.updateEndDate = function (rootLineItem, params) {
1852
- var lineItem = findLineItem(params.id, [rootLineItem]);
1853
- if (!lineItem) {
1854
- return rootLineItem;
1855
- }
1856
- var updated = new LineItemWorker(rootLineItem).replace(Object.assign(Object.assign({}, lineItem), { endDate: moment__default["default"](params.newValue).format('YYYY-MM-DD') }));
1857
- return updated.li;
1858
- };
1859
- FlowUpdateService.prototype.updatePriceAdjustment = function (rootLineItem, params) {
1860
- var comparator = params.dataType === 'LINEITEM'
1861
- ? function (li) { return li.id === params.id; }
1862
- : params.dataType === 'CHARGE'
1863
- ? function (li) { return li.chargeItems.some(function (_a) {
1864
- var id = _a.id;
1865
- return id === params.id;
1866
- }); }
1867
- : params.dataType === 'GROUP_CHARGE'
1868
- ? function (li) { return li.chargeGroupItems.some(function (_a) {
1869
- var id = _a.id;
1870
- return id === params.id;
1871
- }); }
1872
- : undefined;
1873
- if (!comparator) {
1874
- return rootLineItem;
1875
- }
1876
- var lineItem = findLineItemWithComparator([rootLineItem], comparator);
1877
- if (!lineItem) {
1878
- return rootLineItem;
1879
- }
1880
- var updated;
1881
- if (params.dataType === 'LINEITEM') {
1882
- updated = Object.assign(Object.assign({}, lineItem), { chargeItems: lineItem.chargeItems.map(function (chargeItem, index) {
1883
- return index === 0 ? Object.assign(Object.assign({}, chargeItem), { priceAdjustment: params.newValue }) : chargeItem;
1884
- }) });
1885
- }
1886
- else if (params.dataType === 'CHARGE') {
1887
- updated = Object.assign(Object.assign({}, lineItem), { chargeItems: lineItem.chargeItems.map(function (chargeItem) {
1888
- return chargeItem.id === params.id ? Object.assign(Object.assign({}, chargeItem), { priceAdjustment: params.newValue }) : chargeItem;
1889
- }) });
1890
- }
1891
- else if (params.dataType === 'GROUP_CHARGE') {
1892
- updated = Object.assign(Object.assign({}, lineItem), { chargeGroupItems: lineItem.chargeGroupItems.map(function (chargeGroupItem) {
1893
- return chargeGroupItem.id === params.id
1894
- ? Object.assign(Object.assign({}, chargeGroupItem), { priceAdjustment: params.newValue }) : chargeGroupItem;
1895
- }) });
1896
- }
1897
- var updatedRootLineItem = updated ? new LineItemWorker(rootLineItem).replace(updated).li : rootLineItem;
1898
- return updatedRootLineItem;
1844
+ FlowUpdateService.prototype.applyLineItemUpdate = function (lineItem, update) {
1845
+ if (lineItem.id !== update.id) {
1846
+ return false;
1847
+ }
1848
+ switch (update.attributeType) {
1849
+ case 'QTY':
1850
+ lineItem.qty = update.newValue;
1851
+ break;
1852
+ case 'EFFECTIVE_START_DATE':
1853
+ lineItem.effectiveStartDate = moment__default["default"](update.newValue).format('YYYY-MM-DD');
1854
+ break;
1855
+ case 'END_DATE':
1856
+ lineItem.endDate = moment__default["default"](update.newValue).format('YYYY-MM-DD');
1857
+ break;
1858
+ case 'PRICE_ADJUSTMENT':
1859
+ {
1860
+ var _a = __read(lineItem.chargeItems, 1), charge = _a[0];
1861
+ if (charge) {
1862
+ charge.priceAdjustment = update.newValue;
1863
+ }
1864
+ }
1865
+ break;
1866
+ default:
1867
+ throw new Error("Not suppored AttributeType for LineItem update: " + update.attributeType);
1868
+ }
1869
+ return true;
1870
+ };
1871
+ FlowUpdateService.prototype.applyChargeUpdate = function (lineItem, update) {
1872
+ var foundCharge = lineItem.chargeItems.find(function (_a) {
1873
+ var id = _a.id;
1874
+ return id === update.id;
1875
+ });
1876
+ if (!foundCharge) {
1877
+ return false;
1878
+ }
1879
+ if (update.attributeType === 'PRICE_ADJUSTMENT') {
1880
+ foundCharge.priceAdjustment = update.newValue;
1881
+ }
1882
+ else {
1883
+ throw new Error("Not suppored AttributeType for Charge Item update: " + update.attributeType);
1884
+ }
1885
+ return true;
1886
+ };
1887
+ FlowUpdateService.prototype.applyChargeGroupUpdate = function (lineItem, update) {
1888
+ var foundChargeGroup = lineItem.chargeGroupItems.find(function (_a) {
1889
+ var id = _a.id;
1890
+ return id === update.id;
1891
+ });
1892
+ if (!foundChargeGroup) {
1893
+ return false;
1894
+ }
1895
+ if (update.attributeType === 'PRICE_ADJUSTMENT') {
1896
+ foundChargeGroup.priceAdjustment = update.newValue;
1897
+ }
1898
+ else {
1899
+ throw new Error("Not suppored AttributeType for Charge Group Item update: " + update.attributeType);
1900
+ }
1901
+ return true;
1899
1902
  };
1900
1903
  return FlowUpdateService;
1901
1904
  }());
@@ -1932,12 +1935,13 @@
1932
1935
  FlowConfigurationService.prototype.calculate = function (currentState) {
1933
1936
  this.calculate$(currentState).subscribe();
1934
1937
  };
1935
- FlowConfigurationService.prototype.update$ = function (params) {
1938
+ FlowConfigurationService.prototype.update$ = function (updates) {
1936
1939
  var _this = this;
1937
- return rxjs.of([]).pipe(rxjs.map(function () { return _this.lineItems.value.map(function (li) { return _this.updateService.update(li, params); }); }), this.handleError(), rxjs.switchMap(function (currentState) { return _this.calculate$(currentState); }));
1940
+ var lineItems = lodash.cloneDeep(this.lineItems.value);
1941
+ return rxjs.of([]).pipe(rxjs.tap(function () { return _this.updateService.update(lineItems, updates); }), this.handleError(), rxjs.switchMap(function () { return _this.calculate$(lineItems); }));
1938
1942
  };
1939
- FlowConfigurationService.prototype.update = function (params) {
1940
- this.update$(params).subscribe();
1943
+ FlowConfigurationService.prototype.update = function (updates) {
1944
+ this.update$(updates).subscribe();
1941
1945
  };
1942
1946
  FlowConfigurationService.prototype.delete$ = function (ids) {
1943
1947
  var _this = this;