@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
@@ -1,11 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, NgModule } from '@angular/core';
3
3
  import { UUID, ConfigurationContext, ConfigurationContextMode, RuntimeModel, SalesforceIdUtils, ConfigurationMode, ChargeGroupUtils } from '@veloceapps/core';
4
- import { BehaviorSubject, map as map$1, distinctUntilChanged, catchError, of, tap as tap$1, zip, noop, combineLatest, throwError, shareReplay as shareReplay$1, switchMap as switchMap$1 } from 'rxjs';
4
+ import { BehaviorSubject, zip, noop, combineLatest, Subject, take as take$1, map as map$1, distinctUntilChanged, catchError, of, tap as tap$1, throwError, shareReplay as shareReplay$1, switchMap as switchMap$1 } from 'rxjs';
5
5
  import { filter, tap, map, switchMap, skip, take, shareReplay, first, catchError as catchError$1, finalize } from 'rxjs/operators';
6
6
  import * as i1 from '@veloceapps/api';
7
7
  import { PriceApiService, ContextApiService, ProductModelApiService, ConfigurationApiService } from '@veloceapps/api';
8
- import { merge, flatten, sortBy, cloneDeep } from 'lodash';
8
+ import { merge, isEqual, uniq, flatten, sortBy, map as map$2, cloneDeep } from 'lodash';
9
9
  import { ToastType, ConfirmationComponent, ConfirmationDialogModule } from '@veloceapps/components';
10
10
  import * as i4 from 'primeng/api';
11
11
  import * as i5 from 'primeng/dynamicdialog';
@@ -79,31 +79,47 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
79
79
  args: [{ providedIn: 'root' }]
80
80
  }], ctorParameters: function () { return [{ type: i1.ContextApiService }]; } });
81
81
 
82
- class ProductImagesService {
83
- constructor(productApiService) {
84
- this.productApiService = productApiService;
85
- this.imagesMap$ = new BehaviorSubject({});
86
- }
87
- getImageUrl$(productId) {
88
- if (this.imagesMap$.value[productId] == null) {
89
- this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: '' }));
90
- this.fetchProductImage(productId);
82
+ function calculateMetricByMethod(lineItems, metric, method) {
83
+ const items = getLineItemsByMethod(lineItems, method);
84
+ return items.reduce((acc, li) => {
85
+ let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
86
+ if (method === 'avg' && li.length > 0) {
87
+ value /= li.length;
88
+ }
89
+ return acc + value;
90
+ }, 0);
91
+ }
92
+ function getLineItemsByMethod(lineItems, method) {
93
+ switch (method) {
94
+ case 'first': {
95
+ return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
96
+ }
97
+ case 'last': {
98
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
99
+ const products = rootTermItems.map(lineItem => [
100
+ lineItem,
101
+ ...lineItems.filter(li => li.rampInstanceId === lineItem.id),
102
+ ]);
103
+ return products
104
+ .map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
105
+ .filter((li) => Boolean(li))
106
+ .map(item => [item]);
107
+ }
108
+ case 'avg': {
109
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
110
+ return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
111
+ }
112
+ case 'sum': {
113
+ return lineItems.map(item => [item]);
114
+ }
115
+ default: {
116
+ return lineItems.map(item => [item]);
91
117
  }
92
- return this.imagesMap$.pipe(map$1(imagesMap => imagesMap[productId]), distinctUntilChanged());
93
- }
94
- fetchProductImage(productId) {
95
- this.productApiService
96
- .fetchImage$(productId)
97
- .pipe(map$1(file => URL.createObjectURL(file)), catchError(() => of('')), tap$1(url => this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: url }))))
98
- .subscribe();
99
118
  }
100
119
  }
101
- ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
102
- ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, providedIn: 'root' });
103
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, decorators: [{
104
- type: Injectable,
105
- args: [{ providedIn: 'root' }]
106
- }], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
120
+ function getDateValue(date) {
121
+ return date ? new Date(date).getTime() : 0;
122
+ }
107
123
 
108
124
  class QuoteDraftService {
109
125
  constructor(context, quoteApiService, priceApiService) {
@@ -114,9 +130,9 @@ class QuoteDraftService {
114
130
  this.resetSubj$ = new BehaviorSubject(true);
115
131
  this.isInitializedSubj$ = new BehaviorSubject(false);
116
132
  this.initialCurrentState = [];
133
+ this._hasUnsavedChanges = false;
117
134
  this.allPriceLists = [];
118
135
  this.assetPriceLists = [];
119
- this.hasUnsavedChanges = false;
120
136
  this.reset$ = this.resetSubj$.asObservable();
121
137
  this.activePriceList$ = this.context.resolve$().pipe(map(ctx => this.allPriceLists.find(priceList => priceList.id === ctx.properties.PriceListId)), map(priceList => priceList !== null && priceList !== void 0 ? priceList : null));
122
138
  this.isInitializedSubj$
@@ -131,6 +147,16 @@ class QuoteDraftService {
131
147
  this.isInitializedSubj$.next(value);
132
148
  }
133
149
  }
150
+ get hasUnsavedChanges() {
151
+ return this._hasUnsavedChanges;
152
+ }
153
+ set hasUnsavedChanges(value) {
154
+ var _a, _b;
155
+ this._hasUnsavedChanges = value;
156
+ if (!this._hasUnsavedChanges) {
157
+ this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
158
+ }
159
+ }
134
160
  get hasAssets$() {
135
161
  return this.quoteSubj$.pipe(map(() => this.hasAssets));
136
162
  }
@@ -141,13 +167,12 @@ class QuoteDraftService {
141
167
  reset() {
142
168
  this.resetSubj$.next(true);
143
169
  this.quoteSubj$.next(null);
144
- this.initialCurrentState = [];
170
+ this.hasUnsavedChanges = false;
145
171
  }
146
172
  init(quoteId, params) {
147
173
  return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([quote, allPriceLists]) => {
148
174
  this.allPriceLists = allPriceLists;
149
175
  this.quoteSubj$.next(quote);
150
- this.initialCurrentState = quote.currentState;
151
176
  this.context.update(quote.context);
152
177
  this.populateActivePriceLists$();
153
178
  }), map(() => noop()), take(1));
@@ -294,7 +319,7 @@ class QuoteDraftService {
294
319
  this.hasUnsavedChanges = !!quote && !quote.currentState.every(li => li.actionCode === 'EXIST');
295
320
  }
296
321
  else {
297
- this.hasUnsavedChanges = true;
322
+ this.hasUnsavedChanges = !isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
298
323
  }
299
324
  }
300
325
  }
@@ -305,6 +330,99 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
305
330
  args: [{ providedIn: 'root' }]
306
331
  }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
307
332
 
333
+ class MetricsCalculationService {
334
+ constructor(quoteDraftService, settingsService) {
335
+ this.quoteDraftService = quoteDraftService;
336
+ this.settingsService = settingsService;
337
+ this.metricsUpdated$ = new Subject();
338
+ this.quoteMetricsSettings = {};
339
+ this.metricsCalculationMethodMap = {};
340
+ this.metricsData = {};
341
+ combineLatest([
342
+ this.quoteDraftService.currentState$,
343
+ this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(take$1(1)),
344
+ ]).subscribe(([lineItems, setting]) => {
345
+ let settingsData = {};
346
+ try {
347
+ settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
348
+ }
349
+ catch (error) {
350
+ settingsData = {};
351
+ }
352
+ this.quoteMetricsSettings = settingsData;
353
+ this.updateMetrics(lineItems);
354
+ });
355
+ }
356
+ get onMetricsUpdate$() {
357
+ return this.metricsUpdated$.asObservable();
358
+ }
359
+ getMetricValue(metric) {
360
+ return this.metricsData[metric] || 0;
361
+ }
362
+ updateMetrics(lineItems) {
363
+ const metricKeys = this.collectMetricKeys(lineItems).filter(key => !key.includes('Effective_'));
364
+ this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
365
+ this.metricsData = metricKeys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: this.calculateMetric(lineItems, key) })), {});
366
+ this.metricsUpdated$.next();
367
+ }
368
+ calculateMetric(lineItems, metric) {
369
+ return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
370
+ }
371
+ buildMetricsCalculationMethods(metricKeys, initial) {
372
+ return metricKeys.reduce((acc, name) => {
373
+ if (acc[name]) {
374
+ return acc;
375
+ }
376
+ acc = Object.assign(Object.assign({}, acc), { [name]: 'sum' });
377
+ const settingKey = name.replace(/VDM_|Total_/g, '');
378
+ if (this.quoteMetricsSettings[settingKey]) {
379
+ acc = Object.assign(Object.assign({}, acc), { [name]: this.quoteMetricsSettings[settingKey] });
380
+ }
381
+ return acc;
382
+ }, initial);
383
+ }
384
+ collectMetricKeys(lineItems) {
385
+ const keys = [];
386
+ lineItems.forEach(lineItem => {
387
+ keys.push(...Object.keys(lineItem.totalMetrics || {}));
388
+ keys.push(...this.collectMetricKeys(lineItem.lineItems));
389
+ });
390
+ return uniq(keys);
391
+ }
392
+ }
393
+ MetricsCalculationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
394
+ MetricsCalculationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: MetricsCalculationService, providedIn: 'root' });
395
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: MetricsCalculationService, decorators: [{
396
+ type: Injectable,
397
+ args: [{ providedIn: 'root' }]
398
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: i1.ConfigurationSettingsApiService }]; } });
399
+
400
+ class ProductImagesService {
401
+ constructor(productApiService) {
402
+ this.productApiService = productApiService;
403
+ this.imagesMap$ = new BehaviorSubject({});
404
+ }
405
+ getImageUrl$(productId) {
406
+ if (this.imagesMap$.value[productId] == null) {
407
+ this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: '' }));
408
+ this.fetchProductImage(productId);
409
+ }
410
+ return this.imagesMap$.pipe(map$1(imagesMap => imagesMap[productId]), distinctUntilChanged());
411
+ }
412
+ fetchProductImage(productId) {
413
+ this.productApiService
414
+ .fetchImage$(productId)
415
+ .pipe(map$1(file => URL.createObjectURL(file)), catchError(() => of('')), tap$1(url => this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: url }))))
416
+ .subscribe();
417
+ }
418
+ }
419
+ ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
420
+ ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, providedIn: 'root' });
421
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, decorators: [{
422
+ type: Injectable,
423
+ args: [{ providedIn: 'root' }]
424
+ }], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
425
+
308
426
  class RuntimeContextService {
309
427
  constructor(configurationApiService) {
310
428
  this.configurationApiService = configurationApiService;
@@ -530,6 +648,17 @@ const getRecommendedPrices = (portDomain, type) => {
530
648
  }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0];
531
649
  return { net, list };
532
650
  };
651
+ const multiplyLineItems = (lineItem, qty, split) => {
652
+ if (split) {
653
+ const unifyIds = (lineItem) => (Object.assign(Object.assign({}, lineItem), { id: UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds) }));
654
+ return map$2(new Array(qty), () => unifyIds(lineItem));
655
+ }
656
+ else {
657
+ return [
658
+ Object.assign(Object.assign({}, lineItem), { qty: qty }),
659
+ ];
660
+ }
661
+ };
533
662
 
534
663
  var lineItem_utils = /*#__PURE__*/Object.freeze({
535
664
  __proto__: null,
@@ -544,7 +673,8 @@ var lineItem_utils = /*#__PURE__*/Object.freeze({
544
673
  patchAttributes: patchAttributes,
545
674
  getAttributeValue: getAttributeValue,
546
675
  generateLineItem: generateLineItem,
547
- getRecommendedPrices: getRecommendedPrices
676
+ getRecommendedPrices: getRecommendedPrices,
677
+ multiplyLineItems: multiplyLineItems
548
678
  });
549
679
 
550
680
  class LineItemWorker {
@@ -925,7 +1055,13 @@ class FlowConfigurationService {
925
1055
  if (!quoteDraft) {
926
1056
  return of(null);
927
1057
  }
928
- return this.configurationService.configureExternal$(productId, qty).pipe(map$1(lineItem => [...quoteDraft.currentState, lineItem]), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1058
+ return this.configurationService.configureExternal$(productId, qty).pipe(map$1(lineItem => {
1059
+ var _a, _b;
1060
+ const model = this.configurationService.getRuntimeModel();
1061
+ const split = (_b = (_a = model === null || model === void 0 ? void 0 : model.types.find(type => type.name === lineItem.type)) === null || _a === void 0 ? void 0 : _a.split) !== null && _b !== void 0 ? _b : false;
1062
+ const lineItems = multiplyLineItems(lineItem, qty !== null && qty !== void 0 ? qty : 1, split);
1063
+ return [...quoteDraft.currentState, ...lineItems];
1064
+ }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
929
1065
  }
930
1066
  get() {
931
1067
  return this.quoteDraftService.quoteDraft$.pipe(map$1(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
@@ -1018,12 +1154,12 @@ class SdkCoreModule {
1018
1154
  }
1019
1155
  SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1020
1156
  SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1021
- SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
1157
+ SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
1022
1158
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, decorators: [{
1023
1159
  type: NgModule,
1024
1160
  args: [{
1025
1161
  imports: [ConfigurationModule, FlowConfigurationModule],
1026
- providers: [ContextService, QuoteDraftService, ProductImagesService],
1162
+ providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService],
1027
1163
  }]
1028
1164
  }] });
1029
1165
 
@@ -1031,5 +1167,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
1031
1167
  * Generated bundle index. Do not edit.
1032
1168
  */
1033
1169
 
1034
- export { ConfigurationRuntimeService, ConfigurationService, ContextService, FlowConfigurationModule, FlowConfigurationService, FlowUpdateService, LineItemWorker, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeStep, SdkCoreModule, findLineItem, findLineItemWithComparator, generateLineItem, getAttributeValue, getAttributes, getDefaultLineItem, getRecommendedPrices, insertLineItem, lineItem_utils as lineItemUtils, mapAttributes, patchAttributes, removeLineItem, replaceLineItem, upsertAttributes };
1170
+ export { ConfigurationRuntimeService, ConfigurationService, ContextService, FlowConfigurationModule, FlowConfigurationService, FlowUpdateService, LineItemWorker, MetricsCalculationService, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeStep, SdkCoreModule, findLineItem, findLineItemWithComparator, generateLineItem, getAttributeValue, getAttributes, getDefaultLineItem, getRecommendedPrices, insertLineItem, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, removeLineItem, replaceLineItem, upsertAttributes };
1035
1171
  //# sourceMappingURL=veloceapps-sdk-core.js.map