@veloceapps/sdk 8.0.0-116 → 8.0.0-118
Sign up to get free protection for your applications and to get access to all the features.
- package/cms/vendor-map.d.ts +2 -1
- package/core/services/flow-state-configuration.service.d.ts +20 -0
- package/core/services/flow-state.service.d.ts +5 -2
- package/core/services/index.d.ts +1 -0
- package/esm2020/cms/vendor-map.mjs +3 -2
- package/esm2020/core/services/flow-state-configuration.service.mjs +53 -0
- package/esm2020/core/services/flow-state.service.mjs +51 -36
- package/esm2020/core/services/index.mjs +2 -1
- package/fesm2015/veloceapps-sdk-cms.mjs +2 -1
- package/fesm2015/veloceapps-sdk-cms.mjs.map +1 -1
- package/fesm2015/veloceapps-sdk-core.mjs +149 -92
- package/fesm2015/veloceapps-sdk-core.mjs.map +1 -1
- package/fesm2020/veloceapps-sdk-cms.mjs +2 -1
- package/fesm2020/veloceapps-sdk-cms.mjs.map +1 -1
- package/fesm2020/veloceapps-sdk-core.mjs +104 -49
- package/fesm2020/veloceapps-sdk-core.mjs.map +1 -1
- package/package.json +1 -1
@@ -723,7 +723,7 @@ class FlowStateService {
|
|
723
723
|
.pipe(filter$1(Boolean), filter$1(() => !this.getFlowSafe().properties.stateful), switchMap(() => this.quoteDraftService.quoteDraft$), skip$1(1), switchMap(() => this.executeRequest$({}, true)))
|
724
724
|
.subscribe();
|
725
725
|
this.charges$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
|
726
|
-
if (!
|
726
|
+
if (!flow.properties.stateful) {
|
727
727
|
return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.charges));
|
728
728
|
}
|
729
729
|
else {
|
@@ -731,7 +731,7 @@ class FlowStateService {
|
|
731
731
|
cold: true,
|
732
732
|
}).pipe(map$1(response => (response.success ? response.result : {})));
|
733
733
|
}
|
734
|
-
}), shareReplay$1());
|
734
|
+
}), filter$1(isDefined), shareReplay$1());
|
735
735
|
this.charges$.subscribe();
|
736
736
|
this.pricePlans$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
|
737
737
|
if (!flow.properties.stateful) {
|
@@ -742,10 +742,10 @@ class FlowStateService {
|
|
742
742
|
cold: true,
|
743
743
|
}).pipe(map$1(response => (response.success ? response.result : {})));
|
744
744
|
}
|
745
|
-
}), shareReplay$1());
|
745
|
+
}), filter$1(isDefined), shareReplay$1());
|
746
746
|
this.pricePlans$.subscribe();
|
747
747
|
this.activeMetrics$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
|
748
|
-
if (!
|
748
|
+
if (!flow.properties.stateful) {
|
749
749
|
return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.activeMetrics));
|
750
750
|
}
|
751
751
|
else {
|
@@ -753,7 +753,7 @@ class FlowStateService {
|
|
753
753
|
cold: true,
|
754
754
|
}).pipe(map$1(response => (response.success ? response.result : [])));
|
755
755
|
}
|
756
|
-
}), shareReplay$1());
|
756
|
+
}), filter$1(isDefined), shareReplay$1());
|
757
757
|
this.activeMetrics$.subscribe();
|
758
758
|
}
|
759
759
|
init$() {
|
@@ -781,6 +781,9 @@ class FlowStateService {
|
|
781
781
|
? this._hasStatefulUnsavedChanges
|
782
782
|
: this.quoteDraftService.hasUnsavedChanges;
|
783
783
|
}
|
784
|
+
get stateId() {
|
785
|
+
return this.stateId$.value;
|
786
|
+
}
|
784
787
|
isInitialized$() {
|
785
788
|
return combineLatest([this.stateId$, this.quoteDraftService.isInitialized$]).pipe(map$1(values => values.some(Boolean)));
|
786
789
|
}
|
@@ -963,7 +966,7 @@ class FlowStateService {
|
|
963
966
|
if (!this.stateId$.value) {
|
964
967
|
throw 'Stateful session is not initialized';
|
965
968
|
}
|
966
|
-
return this.flowStateApiService.execute(this.stateId$.value, request).pipe(tap$1(
|
969
|
+
return this.flowStateApiService.execute(this.stateId$.value, request).pipe(tap$1(() => {
|
967
970
|
var _a;
|
968
971
|
if ((_a = request.actions) === null || _a === void 0 ? void 0 : _a.length) {
|
969
972
|
this._hasStatefulUnsavedChanges = true;
|
@@ -993,41 +996,54 @@ class FlowStateService {
|
|
993
996
|
return this.flowConfiguration.calculate$(flowState);
|
994
997
|
}
|
995
998
|
executeStateless$(request) {
|
996
|
-
return of(undefined).pipe(switchMap(() => {
|
999
|
+
return of(undefined).pipe(tap$1(() => this.executeStatelessActions(request)), switchMap(() => {
|
997
1000
|
var _a;
|
998
|
-
|
1001
|
+
/*
|
1002
|
+
Skip price calculation in case
|
1003
|
+
1. No actions in the request
|
1004
|
+
2. Initialization process execution (state not initialized yet)
|
1005
|
+
*/
|
1006
|
+
if (!((_a = request.actions) === null || _a === void 0 ? void 0 : _a.length) || !this.isInitialized()) {
|
999
1007
|
return of(undefined);
|
1000
1008
|
}
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
+
else {
|
1010
|
+
return this.calculate$();
|
1011
|
+
}
|
1012
|
+
}), map$1(() => this.executeStatelessSelectors(request)));
|
1013
|
+
}
|
1014
|
+
executeStatelessActions(request) {
|
1015
|
+
var _a;
|
1016
|
+
if (!this.quoteDraftService.quoteDraft || !((_a = request.actions) === null || _a === void 0 ? void 0 : _a.length)) {
|
1017
|
+
return;
|
1018
|
+
}
|
1019
|
+
let flowState = this.quoteDraftService.quoteDraft;
|
1020
|
+
request.actions.forEach(action => {
|
1009
1021
|
var _a;
|
1010
|
-
|
1011
|
-
|
1022
|
+
flowState = (_a = this.executeActionScript(flowState, action)) !== null && _a !== void 0 ? _a : flowState;
|
1023
|
+
});
|
1024
|
+
this.quoteDraftService.updateQuoteDraft(flowState);
|
1025
|
+
}
|
1026
|
+
executeStatelessSelectors(request) {
|
1027
|
+
var _a;
|
1028
|
+
if (!this.quoteDraftService.quoteDraft) {
|
1029
|
+
throw 'QuoteDraft is not initialized';
|
1030
|
+
}
|
1031
|
+
const flowState = this.quoteDraftService.quoteDraft;
|
1032
|
+
return EntityUtil.entries((_a = request.selectors) !== null && _a !== void 0 ? _a : {}).reduce((result, [key, selector]) => {
|
1033
|
+
try {
|
1034
|
+
result.selectors[key] = {
|
1035
|
+
success: true,
|
1036
|
+
result: this.executeSelectorScript(flowState, selector),
|
1037
|
+
};
|
1012
1038
|
}
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
catch (e) {
|
1022
|
-
result.selectors[key] = {
|
1023
|
-
success: false,
|
1024
|
-
errorMessage: String(e),
|
1025
|
-
};
|
1026
|
-
}
|
1027
|
-
return result;
|
1028
|
-
}, { stateId: '', selectors: {} });
|
1029
|
-
return executionResult;
|
1030
|
-
}));
|
1039
|
+
catch (e) {
|
1040
|
+
result.selectors[key] = {
|
1041
|
+
success: false,
|
1042
|
+
errorMessage: String(e),
|
1043
|
+
};
|
1044
|
+
}
|
1045
|
+
return result;
|
1046
|
+
}, { stateId: '', selectors: {} });
|
1031
1047
|
}
|
1032
1048
|
getFlowSafe() {
|
1033
1049
|
if (!this.flowInfoService.flow) {
|
@@ -1120,48 +1136,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
1120
1136
|
}] }];
|
1121
1137
|
} });
|
1122
1138
|
|
1123
|
-
function calculateMetricByMethod(lineItems, metric, method) {
|
1124
|
-
const items = getLineItemsByMethod(lineItems, method);
|
1125
|
-
return items.reduce((acc, li) => {
|
1126
|
-
let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
|
1127
|
-
if (method === 'avg' && li.length > 0) {
|
1128
|
-
value /= li.length;
|
1129
|
-
}
|
1130
|
-
return acc + value;
|
1131
|
-
}, 0);
|
1132
|
-
}
|
1133
|
-
function getLineItemsByMethod(lineItems, method) {
|
1134
|
-
switch (method) {
|
1135
|
-
case 'first': {
|
1136
|
-
return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
|
1137
|
-
}
|
1138
|
-
case 'last': {
|
1139
|
-
const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
|
1140
|
-
const products = rootTermItems.map(lineItem => [
|
1141
|
-
lineItem,
|
1142
|
-
...lineItems.filter(li => li.rampInstanceId === lineItem.id),
|
1143
|
-
]);
|
1144
|
-
return products
|
1145
|
-
.map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
|
1146
|
-
.filter((li) => Boolean(li))
|
1147
|
-
.map(item => [item]);
|
1148
|
-
}
|
1149
|
-
case 'avg': {
|
1150
|
-
const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
|
1151
|
-
return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
|
1152
|
-
}
|
1153
|
-
case 'sum': {
|
1154
|
-
return lineItems.map(item => [item]);
|
1155
|
-
}
|
1156
|
-
default: {
|
1157
|
-
return lineItems.map(item => [item]);
|
1158
|
-
}
|
1159
|
-
}
|
1160
|
-
}
|
1161
|
-
function getDateValue(date) {
|
1162
|
-
return date ? new Date(date).getTime() : 0;
|
1163
|
-
}
|
1164
|
-
|
1165
1139
|
class FlowUpdateService {
|
1166
1140
|
update(rootLineItems, updates, charges) {
|
1167
1141
|
let remainingUpdates = [...updates];
|
@@ -1757,6 +1731,102 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
1757
1731
|
type: Injectable
|
1758
1732
|
}], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
|
1759
1733
|
|
1734
|
+
class FlowConfigurationModule {
|
1735
|
+
}
|
1736
|
+
FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
1737
|
+
FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule });
|
1738
|
+
FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService] });
|
1739
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, decorators: [{
|
1740
|
+
type: NgModule,
|
1741
|
+
args: [{
|
1742
|
+
imports: [],
|
1743
|
+
providers: [FlowConfigurationService, FlowUpdateService, PriceApiService],
|
1744
|
+
}]
|
1745
|
+
}] });
|
1746
|
+
|
1747
|
+
class FlowStateConfigurationService {
|
1748
|
+
constructor(flowStateService, flowInfoService, configurationService, flowConfigurationService, flowStateApiService) {
|
1749
|
+
this.flowStateService = flowStateService;
|
1750
|
+
this.flowInfoService = flowInfoService;
|
1751
|
+
this.configurationService = configurationService;
|
1752
|
+
this.flowConfigurationService = flowConfigurationService;
|
1753
|
+
this.flowStateApiService = flowStateApiService;
|
1754
|
+
this.configurationStateId$ = new BehaviorSubject(null);
|
1755
|
+
}
|
1756
|
+
get configurationStateId() {
|
1757
|
+
return this.configurationStateId$.value;
|
1758
|
+
}
|
1759
|
+
addToCart$(props) {
|
1760
|
+
var _a;
|
1761
|
+
const stateful = (_a = this.flowInfoService.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful;
|
1762
|
+
if (stateful) {
|
1763
|
+
const stateId = this.flowStateService.stateId;
|
1764
|
+
if (!stateId) {
|
1765
|
+
return of();
|
1766
|
+
}
|
1767
|
+
return this.configurationService.configureExternal$(props).pipe(switchMap(lineItem => this.flowStateApiService
|
1768
|
+
.newConfiguration(stateId, { lineItem })
|
1769
|
+
.pipe(tap$1(r => this.configurationStateId$.next(r.stateId)))), switchMap(() => {
|
1770
|
+
if (!this.configurationStateId) {
|
1771
|
+
return of();
|
1772
|
+
}
|
1773
|
+
return this.flowStateApiService.saveConfiguration(stateId, this.configurationStateId).pipe(switchMap(() => this.flowStateService.executeRequest$({}, true)), map$1(noop));
|
1774
|
+
}));
|
1775
|
+
}
|
1776
|
+
else {
|
1777
|
+
return this.flowConfigurationService.addToCart$(props).pipe(map$1(noop));
|
1778
|
+
}
|
1779
|
+
}
|
1780
|
+
}
|
1781
|
+
FlowStateConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, deps: [{ token: FlowStateService }, { token: FlowInfoService }, { token: ConfigurationService }, { token: FlowConfigurationService }, { token: i1.FlowStateApiService }], target: i0.ɵɵFactoryTarget.Injectable });
|
1782
|
+
FlowStateConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, providedIn: 'root' });
|
1783
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, decorators: [{
|
1784
|
+
type: Injectable,
|
1785
|
+
args: [{ providedIn: 'root' }]
|
1786
|
+
}], ctorParameters: function () { return [{ type: FlowStateService }, { type: FlowInfoService }, { type: ConfigurationService }, { type: FlowConfigurationService }, { type: i1.FlowStateApiService }]; } });
|
1787
|
+
|
1788
|
+
function calculateMetricByMethod(lineItems, metric, method) {
|
1789
|
+
const items = getLineItemsByMethod(lineItems, method);
|
1790
|
+
return items.reduce((acc, li) => {
|
1791
|
+
let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
|
1792
|
+
if (method === 'avg' && li.length > 0) {
|
1793
|
+
value /= li.length;
|
1794
|
+
}
|
1795
|
+
return acc + value;
|
1796
|
+
}, 0);
|
1797
|
+
}
|
1798
|
+
function getLineItemsByMethod(lineItems, method) {
|
1799
|
+
switch (method) {
|
1800
|
+
case 'first': {
|
1801
|
+
return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
|
1802
|
+
}
|
1803
|
+
case 'last': {
|
1804
|
+
const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
|
1805
|
+
const products = rootTermItems.map(lineItem => [
|
1806
|
+
lineItem,
|
1807
|
+
...lineItems.filter(li => li.rampInstanceId === lineItem.id),
|
1808
|
+
]);
|
1809
|
+
return products
|
1810
|
+
.map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
|
1811
|
+
.filter((li) => Boolean(li))
|
1812
|
+
.map(item => [item]);
|
1813
|
+
}
|
1814
|
+
case 'avg': {
|
1815
|
+
const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
|
1816
|
+
return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
|
1817
|
+
}
|
1818
|
+
case 'sum': {
|
1819
|
+
return lineItems.map(item => [item]);
|
1820
|
+
}
|
1821
|
+
default: {
|
1822
|
+
return lineItems.map(item => [item]);
|
1823
|
+
}
|
1824
|
+
}
|
1825
|
+
}
|
1826
|
+
function getDateValue(date) {
|
1827
|
+
return date ? new Date(date).getTime() : 0;
|
1828
|
+
}
|
1829
|
+
|
1760
1830
|
class MetricsCalculationService {
|
1761
1831
|
get onMetricsUpdate$() {
|
1762
1832
|
return this.metricsUpdated$.asObservable();
|
@@ -2115,19 +2185,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
2115
2185
|
type: Injectable
|
2116
2186
|
}], ctorParameters: function () { return [{ type: i1.StatefulConfigurationApiService }, { type: ConfigurationRuntimeService }, { type: ConfigurationService }, { type: i6.ToastService }]; } });
|
2117
2187
|
|
2118
|
-
class FlowConfigurationModule {
|
2119
|
-
}
|
2120
|
-
FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
2121
|
-
FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule });
|
2122
|
-
FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService] });
|
2123
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, decorators: [{
|
2124
|
-
type: NgModule,
|
2125
|
-
args: [{
|
2126
|
-
imports: [],
|
2127
|
-
providers: [FlowConfigurationService, FlowUpdateService, PriceApiService],
|
2128
|
-
}]
|
2129
|
-
}] });
|
2130
|
-
|
2131
2188
|
class ConfigurationModule {
|
2132
2189
|
}
|
2133
2190
|
ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
@@ -2366,5 +2423,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
2366
2423
|
* Generated bundle index. Do not edit.
|
2367
2424
|
*/
|
2368
2425
|
|
2369
|
-
export { ActionCodePipe, CalendarDirective, ConfigurationRuntimeService, ConfigurationService, ConfigurationState, ContextService, DEFAULT_FORMATTING_SETTINGS, DatePipe, FLOW_CUSTOMIZATION, FORMATTING_SETTINGS_TOKEN, FlowConfigurationModule, FlowConfigurationService, FlowInfoService, FlowStateService, FlowUpdateService, IntegrationState, LineItemWorker, MetricsCalculationService, NumberPipe, PricePipe, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeSettingsService, RuntimeStep, SdkCoreModule, SdkDirectivesModule, SdkPipesModule, UI_DEFINITION_VERSION, calculateCardinalityVariables, extractMetadata, filterOutTechnicalAttributes, findLineItem, findLineItemWithComparator, generateLineItem, generateModifiedAssetsMap, getAttributeValue, getAttributes, getDefaultLineItem, getGuidedSellingConfigurationRequest, getOriginParent, getRecommendedPrices, insertLineItem, isLineItemModified, isTechnicalAttribute, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, recalculateCardinalityVariables, removeLineItem, replaceLineItem, upsertAttributes };
|
2426
|
+
export { ActionCodePipe, CalendarDirective, ConfigurationRuntimeService, ConfigurationService, ConfigurationState, ContextService, DEFAULT_FORMATTING_SETTINGS, DatePipe, FLOW_CUSTOMIZATION, FORMATTING_SETTINGS_TOKEN, FlowConfigurationModule, FlowConfigurationService, FlowInfoService, FlowStateConfigurationService, FlowStateService, FlowUpdateService, IntegrationState, LineItemWorker, MetricsCalculationService, NumberPipe, PricePipe, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeSettingsService, RuntimeStep, SdkCoreModule, SdkDirectivesModule, SdkPipesModule, UI_DEFINITION_VERSION, calculateCardinalityVariables, extractMetadata, filterOutTechnicalAttributes, findLineItem, findLineItemWithComparator, generateLineItem, generateModifiedAssetsMap, getAttributeValue, getAttributes, getDefaultLineItem, getGuidedSellingConfigurationRequest, getOriginParent, getRecommendedPrices, insertLineItem, isLineItemModified, isTechnicalAttribute, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, recalculateCardinalityVariables, removeLineItem, replaceLineItem, upsertAttributes };
|
2370
2427
|
//# sourceMappingURL=veloceapps-sdk-core.mjs.map
|