@veloceapps/sdk 5.0.13-8 → 6.0.0-0
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.
- package/bundles/veloceapps-sdk-core.umd.js +155 -32
- package/bundles/veloceapps-sdk-core.umd.js.map +1 -1
- package/bundles/veloceapps-sdk.umd.js +13 -9
- package/bundles/veloceapps-sdk.umd.js.map +1 -1
- package/core/services/index.d.ts +1 -0
- package/core/services/metric-calculation/metric-calculation.service.d.ts +21 -0
- package/core/services/metric-calculation/metric-calculation.types.d.ts +1 -0
- package/core/services/metric-calculation/metric-calculation.utils.d.ts +5 -0
- package/esm2015/core/core.module.js +4 -4
- package/esm2015/core/services/index.js +2 -1
- package/esm2015/core/services/metric-calculation/metric-calculation.service.js +74 -0
- package/esm2015/core/services/metric-calculation/metric-calculation.types.js +2 -0
- package/esm2015/core/services/metric-calculation/metric-calculation.utils.js +42 -0
- package/esm2015/src/components/header/metrics/metrics.component.js +11 -7
- package/esm2015/src/components/header/metrics/metrics.definitions.js +6 -6
- package/fesm2015/veloceapps-sdk-core.js +136 -27
- package/fesm2015/veloceapps-sdk-core.js.map +1 -1
- package/fesm2015/veloceapps-sdk.js +13 -9
- package/fesm2015/veloceapps-sdk.js.map +1 -1
- package/package.json +5 -5
- 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,
|
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, isEqual, flatten, sortBy, map as map$2, 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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
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) {
|
@@ -314,6 +330,99 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
|
|
314
330
|
args: [{ providedIn: 'root' }]
|
315
331
|
}], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
|
316
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
|
+
|
317
426
|
class RuntimeContextService {
|
318
427
|
constructor(configurationApiService) {
|
319
428
|
this.configurationApiService = configurationApiService;
|
@@ -1045,12 +1154,12 @@ class SdkCoreModule {
|
|
1045
1154
|
}
|
1046
1155
|
SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
1047
1156
|
SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
|
1048
|
-
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]] });
|
1049
1158
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, decorators: [{
|
1050
1159
|
type: NgModule,
|
1051
1160
|
args: [{
|
1052
1161
|
imports: [ConfigurationModule, FlowConfigurationModule],
|
1053
|
-
providers: [ContextService, QuoteDraftService, ProductImagesService],
|
1162
|
+
providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService],
|
1054
1163
|
}]
|
1055
1164
|
}] });
|
1056
1165
|
|
@@ -1058,5 +1167,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
|
|
1058
1167
|
* Generated bundle index. Do not edit.
|
1059
1168
|
*/
|
1060
1169
|
|
1061
|
-
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, multiplyLineItems, 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 };
|
1062
1171
|
//# sourceMappingURL=veloceapps-sdk-core.js.map
|