@veloceapps/sdk 8.0.0-106 → 8.0.0-108
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/core/services/flow-info.service.d.ts +1 -0
- package/core/services/flow-state.service.d.ts +4 -2
- package/core/types/flow-state.types.d.ts +6 -0
- package/esm2020/core/services/flow-info.service.mjs +13 -3
- package/esm2020/core/services/flow-state.service.mjs +67 -50
- package/esm2020/core/types/flow-state.types.mjs +2 -0
- package/fesm2015/veloceapps-sdk-core.mjs +89 -53
- package/fesm2015/veloceapps-sdk-core.mjs.map +1 -1
- package/fesm2020/veloceapps-sdk-core.mjs +81 -54
- package/fesm2020/veloceapps-sdk-core.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken, Injectable, Optional, Inject, NgModule, inject, Directive, Input, LOCALE_ID, Pipe } from '@angular/core';
|
|
3
|
-
import { UUID, ConfigurationContextMode, ConfigurationContext, UITemplateType, ConfigurationProcessorTypes, EntityUtil,
|
|
4
|
-
import { BehaviorSubject, tap as tap$1, switchMap, map as map$1, noop, catchError, throwError, of, forkJoin, Subject, filter as filter$1, zip, combineLatest, skip as skip$1, shareReplay as shareReplay$1, take as take$1, distinctUntilChanged } from 'rxjs';
|
|
5
|
-
import { map, filter, tap, switchMap as switchMap$1, skip, take, shareReplay, catchError as catchError$1, finalize, first } from 'rxjs/operators';
|
|
3
|
+
import { UUID, ConfigurationContextMode, ConfigurationContext, UITemplateType, isDefined, ConfigurationProcessorTypes, EntityUtil, ChargeGroupUtils, DEFAULT_CURRENCY_ISO_CODE, DEFAULT_CURRENCY_SYMBOL, validateDateFormat, DEFAULT_DATE_FORMAT, DEFAULT_DECIMALS_COUNT, getSupportedDateFormats, DEFAULT_DECIMAL_SEPARATOR, DEFAULT_THOUSANDS_SEPARATOR, DEFAULT_ACTION_CODE_LABELS, parseJsonSafely, ConfigurationMode, ConfigurationTranslatorUtils, RuntimeModel, isNotLegacyUIDefinition, SalesforceIdUtils, DEFAULT_TIME_FORMAT, formatNumber } from '@veloceapps/core';
|
|
4
|
+
import { BehaviorSubject, tap as tap$1, switchMap, map as map$1, noop, catchError, throwError, of, forkJoin, Subject, filter as filter$1, zip, combineLatest, skip as skip$1, finalize, takeUntil, shareReplay as shareReplay$1, take as take$1, distinctUntilChanged } from 'rxjs';
|
|
5
|
+
import { map, filter, tap, switchMap as switchMap$1, skip, take, shareReplay, catchError as catchError$1, finalize as finalize$1, first } from 'rxjs/operators';
|
|
6
6
|
import * as i1 from '@veloceapps/api';
|
|
7
7
|
import { PriceApiService, ContextApiService, ProductModelApiService, ConfigurationApiService } from '@veloceapps/api';
|
|
8
|
-
import { merge, isEmpty, flatten, sortBy, map as map$2, omit, isEqual, uniqBy, transform,
|
|
8
|
+
import { merge, isEmpty, flatten, sortBy, map as map$2, omit, isEqual, cloneDeep, assign, uniqBy, transform, uniq } from 'lodash';
|
|
9
9
|
import * as i6 from '@veloceapps/components';
|
|
10
10
|
import { ToastType, ConfirmationComponent, ConfirmationDialogModule } from '@veloceapps/components';
|
|
11
11
|
import moment from 'moment';
|
|
@@ -139,6 +139,9 @@ class FlowInfoService {
|
|
|
139
139
|
this.templatesApiService = templatesApiService;
|
|
140
140
|
this.customizationService = customizationService;
|
|
141
141
|
this.templates = {};
|
|
142
|
+
this.defaultTemplates = {
|
|
143
|
+
flowEngine: 'Flow Engine',
|
|
144
|
+
};
|
|
142
145
|
this.flowSubj$ = new BehaviorSubject(null);
|
|
143
146
|
this.flow$ = this.flowSubj$.asObservable();
|
|
144
147
|
}
|
|
@@ -163,7 +166,7 @@ class FlowInfoService {
|
|
|
163
166
|
this.templatesApiService.fetchTemplates$(),
|
|
164
167
|
(_c = (_b = (_a = this.customizationService) === null || _a === void 0 ? void 0 : _a.getTemplates) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : of([]),
|
|
165
168
|
]).pipe(map$1(([templates, localTemplates]) => {
|
|
166
|
-
Object.entries(flow.properties.templates).forEach(([key, name]) => {
|
|
169
|
+
Object.entries(Object.assign(Object.assign({}, this.defaultTemplates), flow.properties.templates)).forEach(([key, name]) => {
|
|
167
170
|
var _a;
|
|
168
171
|
const type = this.remapTemplateName(key);
|
|
169
172
|
if (type) {
|
|
@@ -174,6 +177,12 @@ class FlowInfoService {
|
|
|
174
177
|
}));
|
|
175
178
|
}
|
|
176
179
|
remapTemplateName(templateType) {
|
|
180
|
+
switch (templateType) {
|
|
181
|
+
case 'flowEngine':
|
|
182
|
+
return UITemplateType.FLOW_ENGINE;
|
|
183
|
+
default:
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
177
186
|
switch (templateType) {
|
|
178
187
|
case 'assets':
|
|
179
188
|
case 'shoppingCart':
|
|
@@ -188,8 +197,9 @@ class FlowInfoService {
|
|
|
188
197
|
case 'flowHeader':
|
|
189
198
|
return UITemplateType.FLOW_HEADER;
|
|
190
199
|
default:
|
|
191
|
-
|
|
200
|
+
break;
|
|
192
201
|
}
|
|
202
|
+
return undefined;
|
|
193
203
|
}
|
|
194
204
|
}
|
|
195
205
|
FlowInfoService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowInfoService, deps: [{ token: i1.FlowsApiService }, { token: i1.UITemplatesApiService }, { token: FLOW_CUSTOMIZATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
@@ -703,6 +713,7 @@ class FlowStateService {
|
|
|
703
713
|
this.stateId$ = new BehaviorSubject(null);
|
|
704
714
|
this.processors = {};
|
|
705
715
|
this.subscriptions = {};
|
|
716
|
+
this.cleanup$ = new Subject();
|
|
706
717
|
/*
|
|
707
718
|
In stateless mode watch QuoteDraft changes and call executeRequest so that
|
|
708
719
|
all subscriptions get their updates according to updated QuoteDraft
|
|
@@ -712,12 +723,14 @@ class FlowStateService {
|
|
|
712
723
|
.subscribe();
|
|
713
724
|
}
|
|
714
725
|
init$() {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
726
|
+
return this.initProcessors$().pipe(switchMap(() => {
|
|
727
|
+
if (this.getFlowSafe().properties.stateful) {
|
|
728
|
+
return this.initStateful$();
|
|
729
|
+
}
|
|
730
|
+
else {
|
|
731
|
+
return this.initStateless$();
|
|
732
|
+
}
|
|
733
|
+
}));
|
|
721
734
|
}
|
|
722
735
|
cleanup() {
|
|
723
736
|
Object.values(this.subscriptions).forEach(({ data$ }) => data$.complete());
|
|
@@ -727,6 +740,7 @@ class FlowStateService {
|
|
|
727
740
|
this.stateId$.next(null);
|
|
728
741
|
}
|
|
729
742
|
this.processors = {};
|
|
743
|
+
this.cleanup$.next();
|
|
730
744
|
}
|
|
731
745
|
isInitialized$() {
|
|
732
746
|
return combineLatest([this.stateId$, this.quoteDraftService.isInitialized$]).pipe(map$1(values => values.some(Boolean)));
|
|
@@ -767,7 +781,7 @@ class FlowStateService {
|
|
|
767
781
|
});
|
|
768
782
|
return this.executeRequest$(request).pipe(map$1(response => response.selectors[requestId]));
|
|
769
783
|
}
|
|
770
|
-
subscribe$(scope, selectorName, inputData) {
|
|
784
|
+
subscribe$(scope, selectorName, inputData, options) {
|
|
771
785
|
const inputDataHash = UUID.hex(JSON.stringify(inputData)).slice(0, 8);
|
|
772
786
|
const requestId = `${scope}/${selectorName}/${inputDataHash}`;
|
|
773
787
|
if (!this.subscriptions[requestId]) {
|
|
@@ -783,9 +797,15 @@ class FlowStateService {
|
|
|
783
797
|
request,
|
|
784
798
|
data$: new BehaviorSubject(this.NOT_INITIALIZED),
|
|
785
799
|
};
|
|
786
|
-
|
|
800
|
+
if (!(options === null || options === void 0 ? void 0 : options.cold)) {
|
|
801
|
+
this.executeRequest$(request).subscribe();
|
|
802
|
+
}
|
|
787
803
|
}
|
|
788
|
-
return this.subscriptions[requestId].data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data))
|
|
804
|
+
return this.subscriptions[requestId].data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), finalize(() => {
|
|
805
|
+
if (!this.subscriptions[requestId].data$.observed) {
|
|
806
|
+
delete this.subscriptions[requestId];
|
|
807
|
+
}
|
|
808
|
+
}));
|
|
789
809
|
}
|
|
790
810
|
save$() {
|
|
791
811
|
if (this.getFlowSafe().properties.stateful) {
|
|
@@ -844,35 +864,56 @@ class FlowStateService {
|
|
|
844
864
|
};
|
|
845
865
|
}
|
|
846
866
|
executeRequest$(request) {
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
867
|
+
var _a;
|
|
868
|
+
const fullRequest = cloneDeep(request);
|
|
869
|
+
if ((_a = fullRequest.actions) === null || _a === void 0 ? void 0 : _a.length) {
|
|
870
|
+
for (const subscription of Object.values(this.subscriptions)) {
|
|
871
|
+
fullRequest.selectors = assign(fullRequest.selectors, subscription.request.selectors);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
850
874
|
const execution$ = this.getFlowSafe().properties.stateful
|
|
851
875
|
? this.executeStateful$(fullRequest)
|
|
852
876
|
: this.executeStateless$(fullRequest);
|
|
853
|
-
return execution$.pipe(tap$1(result =>
|
|
854
|
-
Object.entries(result.selectors).forEach(([requestId, selectorResult]) => {
|
|
855
|
-
var _a;
|
|
856
|
-
if (!selectorResult.success) {
|
|
857
|
-
this.toastService.add({ severity: ToastType.error, summary: selectorResult.errorMessage });
|
|
858
|
-
}
|
|
859
|
-
const subscription$ = (_a = this.subscriptions[requestId]) === null || _a === void 0 ? void 0 : _a.data$;
|
|
860
|
-
if (subscription$) {
|
|
861
|
-
subscription$.next(selectorResult);
|
|
862
|
-
}
|
|
863
|
-
});
|
|
864
|
-
}));
|
|
877
|
+
return execution$.pipe(tap$1(result => this.handleSelectorsResponse(result.selectors)));
|
|
865
878
|
}
|
|
866
|
-
|
|
867
|
-
|
|
879
|
+
handleSelectorsResponse(selectors) {
|
|
880
|
+
Object.entries(selectors).forEach(([requestId, selectorResult]) => {
|
|
868
881
|
var _a;
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
882
|
+
if (!selectorResult.success) {
|
|
883
|
+
this.toastService.add({ severity: ToastType.error, summary: selectorResult.errorMessage });
|
|
884
|
+
}
|
|
885
|
+
const subscription$ = (_a = this.subscriptions[requestId]) === null || _a === void 0 ? void 0 : _a.data$;
|
|
886
|
+
if (subscription$) {
|
|
887
|
+
subscription$.next(selectorResult);
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
initStateful$() {
|
|
892
|
+
var _a;
|
|
893
|
+
// Subscriptions
|
|
894
|
+
this.subscribe$(UITemplateType.FLOW_ENGINE, 'GET_CONTEXT', null, { cold: true })
|
|
895
|
+
.pipe(tap$1(response => {
|
|
896
|
+
if (response.success) {
|
|
897
|
+
this.contextService.update(response.result);
|
|
898
|
+
}
|
|
899
|
+
}), takeUntil(this.cleanup$))
|
|
900
|
+
.subscribe();
|
|
901
|
+
const processorsList = flatten(Object.values(this.processors).map(ownerMap => Object.values(ownerMap !== null && ownerMap !== void 0 ? ownerMap : {})));
|
|
902
|
+
const processors = processorsList.length ? processorsList : undefined;
|
|
903
|
+
const selectors = Object.values(this.subscriptions)
|
|
904
|
+
.map(({ request }) => request.selectors)
|
|
905
|
+
.filter(isDefined)
|
|
906
|
+
.reduce((trunk, selectors) => (Object.assign(Object.assign({}, trunk), selectors)), {});
|
|
907
|
+
return this.flowStateApiService
|
|
908
|
+
.init({
|
|
909
|
+
quoteId: this.contextService.resolve().headerId,
|
|
910
|
+
params: (_a = this.flowInfoService.params) !== null && _a !== void 0 ? _a : {},
|
|
911
|
+
actionsOverride: processors === null || processors === void 0 ? void 0 : processors.filter(processor => processor.type === ConfigurationProcessorTypes.ACTION),
|
|
912
|
+
selectorsOverride: processors === null || processors === void 0 ? void 0 : processors.filter(processor => processor.type === ConfigurationProcessorTypes.SELECTOR),
|
|
913
|
+
selectors,
|
|
914
|
+
})
|
|
915
|
+
.pipe(map$1(({ stateId, selectors }) => {
|
|
916
|
+
this.handleSelectorsResponse(selectors);
|
|
876
917
|
this.stateId$.next(stateId);
|
|
877
918
|
}));
|
|
878
919
|
}
|
|
@@ -952,6 +993,13 @@ class FlowStateService {
|
|
|
952
993
|
return this.flowInfoService.flow;
|
|
953
994
|
}
|
|
954
995
|
initProcessors$() {
|
|
996
|
+
var _a;
|
|
997
|
+
const hasOverrides = Boolean((_a = this.customizationService) === null || _a === void 0 ? void 0 : _a.getTemplateConfigurationProcessors);
|
|
998
|
+
const flow = this.getFlowSafe();
|
|
999
|
+
if (flow.properties.stateful && !hasOverrides) {
|
|
1000
|
+
// Skip initialization as backend will take processors from SF
|
|
1001
|
+
return of(undefined);
|
|
1002
|
+
}
|
|
955
1003
|
const owners$ = Object.values(this.flowInfoService.templates)
|
|
956
1004
|
.map(template => {
|
|
957
1005
|
var _a, _b, _c;
|
|
@@ -970,18 +1018,6 @@ class FlowStateService {
|
|
|
970
1018
|
.filter(isDefined);
|
|
971
1019
|
return forkJoin(owners$).pipe(map$1(noop));
|
|
972
1020
|
}
|
|
973
|
-
getLocalProcessors$() {
|
|
974
|
-
const processorsPerTemplate$ = Object.values(this.flowInfoService.templates).map(template => { var _a, _b, _c; return (_c = (_b = (_a = this.customizationService) === null || _a === void 0 ? void 0 : _a.getTemplateConfigurationProcessors) === null || _b === void 0 ? void 0 : _b.call(_a, template.name)) !== null && _c !== void 0 ? _c : of(null); });
|
|
975
|
-
return forkJoin(processorsPerTemplate$).pipe(map$1(processors => {
|
|
976
|
-
const definedProcessors = processors.filter(isDefined);
|
|
977
|
-
if (definedProcessors.length) {
|
|
978
|
-
return flatten(definedProcessors);
|
|
979
|
-
}
|
|
980
|
-
else {
|
|
981
|
-
return null;
|
|
982
|
-
}
|
|
983
|
-
}));
|
|
984
|
-
}
|
|
985
1021
|
executeActionScript(request, executable) {
|
|
986
1022
|
var _a, _b;
|
|
987
1023
|
const script = (_b = (_a = this.processors[executable.ownerId]) === null || _a === void 0 ? void 0 : _a[executable.apiName]) === null || _b === void 0 ? void 0 : _b.script;
|
|
@@ -1429,7 +1465,7 @@ class ConfigurationService {
|
|
|
1429
1465
|
this.showInactiveProductsConfirmation();
|
|
1430
1466
|
}
|
|
1431
1467
|
this.configurableRamp = lineItem;
|
|
1432
|
-
}), map(({ lineItem }) => lineItem), catchError$1(error => throwError(() => { var _a; return new Error(((_a = error.error) === null || _a === void 0 ? void 0 : _a.message) || error.message || JSON.stringify(error)); })), finalize(() => this.isLoadingSubj$.next(false)));
|
|
1468
|
+
}), map(({ lineItem }) => lineItem), catchError$1(error => throwError(() => { var _a; return new Error(((_a = error.error) === null || _a === void 0 ? void 0 : _a.message) || error.message || JSON.stringify(error)); })), finalize$1(() => this.isLoadingSubj$.next(false)));
|
|
1433
1469
|
}
|
|
1434
1470
|
configureExternal$(props) {
|
|
1435
1471
|
return this.runtimeService
|
|
@@ -1437,7 +1473,7 @@ class ConfigurationService {
|
|
|
1437
1473
|
.pipe(switchMap$1(() => this.configure()), first(), catchError$1(error => {
|
|
1438
1474
|
this.messageService.add({ severity: ToastType.error, summary: error });
|
|
1439
1475
|
throw error;
|
|
1440
|
-
}), finalize(() => this.reset()));
|
|
1476
|
+
}), finalize$1(() => this.reset()));
|
|
1441
1477
|
}
|
|
1442
1478
|
configureGuidedSelling$(data) {
|
|
1443
1479
|
return this.configurationApiService
|