@veloceapps/sdk 5.0.13-1 → 5.0.13-11

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.
Files changed (32) hide show
  1. package/bundles/veloceapps-sdk-core.umd.js +193 -38
  2. package/bundles/veloceapps-sdk-core.umd.js.map +1 -1
  3. package/bundles/veloceapps-sdk-runtime.umd.js.map +1 -1
  4. package/bundles/veloceapps-sdk.umd.js +23 -19
  5. package/bundles/veloceapps-sdk.umd.js.map +1 -1
  6. package/cms/vendor-map.d.ts +1 -0
  7. package/core/services/index.d.ts +1 -0
  8. package/core/services/metric-calculation/metric-calculation.service.d.ts +21 -0
  9. package/core/services/metric-calculation/metric-calculation.types.d.ts +1 -0
  10. package/core/services/metric-calculation/metric-calculation.utils.d.ts +5 -0
  11. package/core/services/quote-draft.service.d.ts +3 -1
  12. package/core/utils/line-item.utils.d.ts +1 -0
  13. package/esm2015/core/core.module.js +4 -4
  14. package/esm2015/core/modules/flow-configuration/services/flow-configuration.service.js +9 -2
  15. package/esm2015/core/services/index.js +2 -1
  16. package/esm2015/core/services/metric-calculation/metric-calculation.service.js +74 -0
  17. package/esm2015/core/services/metric-calculation/metric-calculation.types.js +2 -0
  18. package/esm2015/core/services/metric-calculation/metric-calculation.utils.js +42 -0
  19. package/esm2015/core/services/quote-draft.service.js +15 -5
  20. package/esm2015/core/utils/line-item.utils.js +13 -2
  21. package/esm2015/runtime/execution/components/context-provider/context-provider.component.js +1 -1
  22. package/esm2015/src/components/header/metrics/metrics.component.js +12 -8
  23. package/esm2015/src/components/header/metrics/metrics.definitions.js +6 -6
  24. package/esm2015/src/resolvers/quote.resolver.js +9 -9
  25. package/fesm2015/veloceapps-sdk-core.js +169 -33
  26. package/fesm2015/veloceapps-sdk-core.js.map +1 -1
  27. package/fesm2015/veloceapps-sdk-runtime.js.map +1 -1
  28. package/fesm2015/veloceapps-sdk.js +22 -18
  29. package/fesm2015/veloceapps-sdk.js.map +1 -1
  30. package/package.json +2 -2
  31. package/runtime/execution/components/context-provider/context-provider.component.d.ts +2 -2
  32. package/src/components/header/metrics/metrics.component.d.ts +3 -2
@@ -423,37 +423,46 @@
423
423
  args: [{ providedIn: 'root' }]
424
424
  }], ctorParameters: function () { return [{ type: i1__namespace.ContextApiService }]; } });
425
425
 
426
- var ProductImagesService = /** @class */ (function () {
427
- function ProductImagesService(productApiService) {
428
- this.productApiService = productApiService;
429
- this.imagesMap$ = new rxjs.BehaviorSubject({});
430
- }
431
- ProductImagesService.prototype.getImageUrl$ = function (productId) {
432
- var _a;
433
- if (this.imagesMap$.value[productId] == null) {
434
- this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), (_a = {}, _a[productId] = '', _a)));
435
- this.fetchProductImage(productId);
426
+ function calculateMetricByMethod(lineItems, metric, method) {
427
+ var items = getLineItemsByMethod(lineItems, method);
428
+ return items.reduce(function (acc, li) {
429
+ var value = li.reduce(function (accProduct, item) { return accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0); }, 0);
430
+ if (method === 'avg' && li.length > 0) {
431
+ value /= li.length;
436
432
  }
437
- return this.imagesMap$.pipe(rxjs.map(function (imagesMap) { return imagesMap[productId]; }), rxjs.distinctUntilChanged());
438
- };
439
- ProductImagesService.prototype.fetchProductImage = function (productId) {
440
- var _this = this;
441
- this.productApiService
442
- .fetchImage$(productId)
443
- .pipe(rxjs.map(function (file) { return URL.createObjectURL(file); }), rxjs.catchError(function () { return rxjs.of(''); }), rxjs.tap(function (url) {
444
- var _a;
445
- return _this.imagesMap$.next(Object.assign(Object.assign({}, _this.imagesMap$.value), (_a = {}, _a[productId] = url, _a)));
446
- }))
447
- .subscribe();
448
- };
449
- return ProductImagesService;
450
- }());
451
- ProductImagesService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, deps: [{ token: i1__namespace.ProductApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
452
- ProductImagesService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, providedIn: 'root' });
453
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, decorators: [{
454
- type: i0.Injectable,
455
- args: [{ providedIn: 'root' }]
456
- }], ctorParameters: function () { return [{ type: i1__namespace.ProductApiService }]; } });
433
+ return acc + value;
434
+ }, 0);
435
+ }
436
+ function getLineItemsByMethod(lineItems, method) {
437
+ switch (method) {
438
+ case 'first': {
439
+ return lineItems.filter(function (li) { return !li.rampInstanceId; }).map(function (item) { return [item]; });
440
+ }
441
+ case 'last': {
442
+ var rootTermItems = lineItems.filter(function (li) { return !li.rampInstanceId; });
443
+ var products = rootTermItems.map(function (lineItem) { return __spreadArray([
444
+ lineItem
445
+ ], __read(lineItems.filter(function (li) { return li.rampInstanceId === lineItem.id; }))); });
446
+ return products
447
+ .map(function (items) { return __spreadArray([], __read(items)).sort(function (a, b) { return getDateValue(a.endDate || '') - getDateValue(b.endDate || ''); }).pop(); })
448
+ .filter(function (li) { return Boolean(li); })
449
+ .map(function (item) { return [item]; });
450
+ }
451
+ case 'avg': {
452
+ var rootTermItems = lineItems.filter(function (li) { return !li.rampInstanceId; });
453
+ return rootTermItems.map(function (lineItem) { return __spreadArray([lineItem], __read(lineItems.filter(function (li) { return li.rampInstanceId === lineItem.id; }))); });
454
+ }
455
+ case 'sum': {
456
+ return lineItems.map(function (item) { return [item]; });
457
+ }
458
+ default: {
459
+ return lineItems.map(function (item) { return [item]; });
460
+ }
461
+ }
462
+ }
463
+ function getDateValue(date) {
464
+ return date ? new Date(date).getTime() : 0;
465
+ }
457
466
 
458
467
  var QuoteDraftService = /** @class */ (function () {
459
468
  function QuoteDraftService(context, quoteApiService, priceApiService) {
@@ -465,9 +474,9 @@
465
474
  this.resetSubj$ = new rxjs.BehaviorSubject(true);
466
475
  this.isInitializedSubj$ = new rxjs.BehaviorSubject(false);
467
476
  this.initialCurrentState = [];
477
+ this._hasUnsavedChanges = false;
468
478
  this.allPriceLists = [];
469
479
  this.assetPriceLists = [];
470
- this.hasUnsavedChanges = false;
471
480
  this.reset$ = this.resetSubj$.asObservable();
472
481
  this.activePriceList$ = this.context.resolve$().pipe(operators.map(function (ctx) { return _this.allPriceLists.find(function (priceList) { return priceList.id === ctx.properties.PriceListId; }); }), operators.map(function (priceList) { return priceList !== null && priceList !== void 0 ? priceList : null; }));
473
482
  this.isInitializedSubj$
@@ -486,6 +495,20 @@
486
495
  enumerable: false,
487
496
  configurable: true
488
497
  });
498
+ Object.defineProperty(QuoteDraftService.prototype, "hasUnsavedChanges", {
499
+ get: function () {
500
+ return this._hasUnsavedChanges;
501
+ },
502
+ set: function (value) {
503
+ var _a, _b;
504
+ this._hasUnsavedChanges = value;
505
+ if (!this._hasUnsavedChanges) {
506
+ this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
507
+ }
508
+ },
509
+ enumerable: false,
510
+ configurable: true
511
+ });
489
512
  Object.defineProperty(QuoteDraftService.prototype, "hasAssets$", {
490
513
  get: function () {
491
514
  var _this = this;
@@ -505,7 +528,7 @@
505
528
  QuoteDraftService.prototype.reset = function () {
506
529
  this.resetSubj$.next(true);
507
530
  this.quoteSubj$.next(null);
508
- this.initialCurrentState = [];
531
+ this.hasUnsavedChanges = false;
509
532
  };
510
533
  QuoteDraftService.prototype.init = function (quoteId, params) {
511
534
  var _this = this;
@@ -513,7 +536,6 @@
513
536
  var _d = __read(_c, 2), quote = _d[0], allPriceLists = _d[1];
514
537
  _this.allPriceLists = allPriceLists;
515
538
  _this.quoteSubj$.next(quote);
516
- _this.initialCurrentState = quote.currentState;
517
539
  _this.context.update(quote.context);
518
540
  _this.populateActivePriceLists$();
519
541
  }), operators.map(function () { return rxjs.noop(); }), operators.take(1));
@@ -712,7 +734,7 @@
712
734
  this.hasUnsavedChanges = !!quote && !quote.currentState.every(function (li) { return li.actionCode === 'EXIST'; });
713
735
  }
714
736
  else {
715
- this.hasUnsavedChanges = true;
737
+ this.hasUnsavedChanges = !lodash.isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
716
738
  }
717
739
  };
718
740
  return QuoteDraftService;
@@ -724,6 +746,119 @@
724
746
  args: [{ providedIn: 'root' }]
725
747
  }], ctorParameters: function () { return [{ type: ContextService }, { type: i1__namespace.QuoteApiService }, { type: i1__namespace.PriceApiService }]; } });
726
748
 
749
+ var MetricsCalculationService = /** @class */ (function () {
750
+ function MetricsCalculationService(quoteDraftService, settingsService) {
751
+ var _this = this;
752
+ this.quoteDraftService = quoteDraftService;
753
+ this.settingsService = settingsService;
754
+ this.metricsUpdated$ = new rxjs.Subject();
755
+ this.quoteMetricsSettings = {};
756
+ this.metricsCalculationMethodMap = {};
757
+ this.metricsData = {};
758
+ rxjs.combineLatest([
759
+ this.quoteDraftService.currentState$,
760
+ this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(rxjs.take(1)),
761
+ ]).subscribe(function (_a) {
762
+ var _b = __read(_a, 2), lineItems = _b[0], setting = _b[1];
763
+ var settingsData = {};
764
+ try {
765
+ settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
766
+ }
767
+ catch (error) {
768
+ settingsData = {};
769
+ }
770
+ _this.quoteMetricsSettings = settingsData;
771
+ _this.updateMetrics(lineItems);
772
+ });
773
+ }
774
+ Object.defineProperty(MetricsCalculationService.prototype, "onMetricsUpdate$", {
775
+ get: function () {
776
+ return this.metricsUpdated$.asObservable();
777
+ },
778
+ enumerable: false,
779
+ configurable: true
780
+ });
781
+ MetricsCalculationService.prototype.getMetricValue = function (metric) {
782
+ return this.metricsData[metric] || 0;
783
+ };
784
+ MetricsCalculationService.prototype.updateMetrics = function (lineItems) {
785
+ var _this = this;
786
+ var metricKeys = this.collectMetricKeys(lineItems).filter(function (key) { return !key.includes('Effective_'); });
787
+ this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
788
+ this.metricsData = metricKeys.reduce(function (acc, key) {
789
+ var _a;
790
+ return (Object.assign(Object.assign({}, acc), (_a = {}, _a[key] = _this.calculateMetric(lineItems, key), _a)));
791
+ }, {});
792
+ this.metricsUpdated$.next();
793
+ };
794
+ MetricsCalculationService.prototype.calculateMetric = function (lineItems, metric) {
795
+ return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
796
+ };
797
+ MetricsCalculationService.prototype.buildMetricsCalculationMethods = function (metricKeys, initial) {
798
+ var _this = this;
799
+ return metricKeys.reduce(function (acc, name) {
800
+ var _a, _b;
801
+ if (acc[name]) {
802
+ return acc;
803
+ }
804
+ acc = Object.assign(Object.assign({}, acc), (_a = {}, _a[name] = 'sum', _a));
805
+ var settingKey = name.replace(/VDM_|Total_/g, '');
806
+ if (_this.quoteMetricsSettings[settingKey]) {
807
+ acc = Object.assign(Object.assign({}, acc), (_b = {}, _b[name] = _this.quoteMetricsSettings[settingKey], _b));
808
+ }
809
+ return acc;
810
+ }, initial);
811
+ };
812
+ MetricsCalculationService.prototype.collectMetricKeys = function (lineItems) {
813
+ var _this = this;
814
+ var keys = [];
815
+ lineItems.forEach(function (lineItem) {
816
+ keys.push.apply(keys, __spreadArray([], __read(Object.keys(lineItem.totalMetrics || {}))));
817
+ keys.push.apply(keys, __spreadArray([], __read(_this.collectMetricKeys(lineItem.lineItems))));
818
+ });
819
+ return lodash.uniq(keys);
820
+ };
821
+ return MetricsCalculationService;
822
+ }());
823
+ MetricsCalculationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: i1__namespace.ConfigurationSettingsApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
824
+ MetricsCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: MetricsCalculationService, providedIn: 'root' });
825
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: MetricsCalculationService, decorators: [{
826
+ type: i0.Injectable,
827
+ args: [{ providedIn: 'root' }]
828
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: i1__namespace.ConfigurationSettingsApiService }]; } });
829
+
830
+ var ProductImagesService = /** @class */ (function () {
831
+ function ProductImagesService(productApiService) {
832
+ this.productApiService = productApiService;
833
+ this.imagesMap$ = new rxjs.BehaviorSubject({});
834
+ }
835
+ ProductImagesService.prototype.getImageUrl$ = function (productId) {
836
+ var _a;
837
+ if (this.imagesMap$.value[productId] == null) {
838
+ this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), (_a = {}, _a[productId] = '', _a)));
839
+ this.fetchProductImage(productId);
840
+ }
841
+ return this.imagesMap$.pipe(rxjs.map(function (imagesMap) { return imagesMap[productId]; }), rxjs.distinctUntilChanged());
842
+ };
843
+ ProductImagesService.prototype.fetchProductImage = function (productId) {
844
+ var _this = this;
845
+ this.productApiService
846
+ .fetchImage$(productId)
847
+ .pipe(rxjs.map(function (file) { return URL.createObjectURL(file); }), rxjs.catchError(function () { return rxjs.of(''); }), rxjs.tap(function (url) {
848
+ var _a;
849
+ return _this.imagesMap$.next(Object.assign(Object.assign({}, _this.imagesMap$.value), (_a = {}, _a[productId] = url, _a)));
850
+ }))
851
+ .subscribe();
852
+ };
853
+ return ProductImagesService;
854
+ }());
855
+ ProductImagesService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, deps: [{ token: i1__namespace.ProductApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
856
+ ProductImagesService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, providedIn: 'root' });
857
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, decorators: [{
858
+ type: i0.Injectable,
859
+ args: [{ providedIn: 'root' }]
860
+ }], ctorParameters: function () { return [{ type: i1__namespace.ProductApiService }]; } });
861
+
727
862
  var RuntimeContextService = /** @class */ (function () {
728
863
  function RuntimeContextService(configurationApiService) {
729
864
  this.configurationApiService = configurationApiService;
@@ -986,6 +1121,17 @@
986
1121
  }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0], 2), net = _c[0], list = _c[1];
987
1122
  return { net: net, list: list };
988
1123
  };
1124
+ var multiplyLineItems = function (lineItem, qty, split) {
1125
+ if (split) {
1126
+ var unifyIds_1 = function (lineItem) { return (Object.assign(Object.assign({}, lineItem), { id: core.UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds_1) })); };
1127
+ return lodash.map(new Array(qty), function () { return unifyIds_1(lineItem); });
1128
+ }
1129
+ else {
1130
+ return [
1131
+ Object.assign(Object.assign({}, lineItem), { qty: qty }),
1132
+ ];
1133
+ }
1134
+ };
989
1135
 
990
1136
  var lineItem_utils = /*#__PURE__*/Object.freeze({
991
1137
  __proto__: null,
@@ -1000,7 +1146,8 @@
1000
1146
  patchAttributes: patchAttributes,
1001
1147
  getAttributeValue: getAttributeValue,
1002
1148
  generateLineItem: generateLineItem,
1003
- getRecommendedPrices: getRecommendedPrices
1149
+ getRecommendedPrices: getRecommendedPrices,
1150
+ multiplyLineItems: multiplyLineItems
1004
1151
  });
1005
1152
 
1006
1153
  var LineItemWorker = /** @class */ (function () {
@@ -1431,7 +1578,13 @@
1431
1578
  if (!quoteDraft) {
1432
1579
  return rxjs.of(null);
1433
1580
  }
1434
- 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());
1581
+ return this.configurationService.configureExternal$(productId, qty).pipe(rxjs.map(function (lineItem) {
1582
+ var _a, _b;
1583
+ var model = _this.configurationService.getRuntimeModel();
1584
+ var split = (_b = (_a = model === null || model === void 0 ? void 0 : model.types.find(function (type) { return type.name === lineItem.type; })) === null || _a === void 0 ? void 0 : _a.split) !== null && _b !== void 0 ? _b : false;
1585
+ var lineItems = multiplyLineItems(lineItem, qty !== null && qty !== void 0 ? qty : 1, split);
1586
+ return __spreadArray(__spreadArray([], __read(quoteDraft.currentState)), __read(lineItems));
1587
+ }), rxjs.switchMap(function (updatedState) { return _this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState })); }), rxjs.map(function () { return _this.quoteDraftService.quoteDraft; }), this.handleErrorAndBounceBack());
1435
1588
  };
1436
1589
  FlowConfigurationService.prototype.get = function () {
1437
1590
  var _this = this;
@@ -1566,12 +1719,12 @@
1566
1719
  }());
1567
1720
  SdkCoreModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1568
1721
  SdkCoreModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1569
- SdkCoreModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
1722
+ SdkCoreModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
1570
1723
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, decorators: [{
1571
1724
  type: i0.NgModule,
1572
1725
  args: [{
1573
1726
  imports: [ConfigurationModule, FlowConfigurationModule],
1574
- providers: [ContextService, QuoteDraftService, ProductImagesService],
1727
+ providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService],
1575
1728
  }]
1576
1729
  }] });
1577
1730
 
@@ -1586,6 +1739,7 @@
1586
1739
  exports.FlowConfigurationService = FlowConfigurationService;
1587
1740
  exports.FlowUpdateService = FlowUpdateService;
1588
1741
  exports.LineItemWorker = LineItemWorker;
1742
+ exports.MetricsCalculationService = MetricsCalculationService;
1589
1743
  exports.ProductImagesService = ProductImagesService;
1590
1744
  exports.QuoteDraftService = QuoteDraftService;
1591
1745
  exports.SdkCoreModule = SdkCoreModule;
@@ -1599,6 +1753,7 @@
1599
1753
  exports.insertLineItem = insertLineItem;
1600
1754
  exports.lineItemUtils = lineItem_utils;
1601
1755
  exports.mapAttributes = mapAttributes;
1756
+ exports.multiplyLineItems = multiplyLineItems;
1602
1757
  exports.patchAttributes = patchAttributes;
1603
1758
  exports.removeLineItem = removeLineItem;
1604
1759
  exports.replaceLineItem = replaceLineItem;