@veloceapps/sdk 8.0.0-113 → 8.0.0-115
Sign up to get free protection for your applications and to get access to all the features.
- package/cms/vendor-map.d.ts +4 -0
- package/core/services/flow-state.service.d.ts +9 -2
- package/esm2020/cms/vendor-map.mjs +5 -1
- package/esm2020/core/services/flow-state.service.mjs +41 -18
- package/fesm2015/veloceapps-sdk-cms.mjs +4 -1
- package/fesm2015/veloceapps-sdk-cms.mjs.map +1 -1
- package/fesm2015/veloceapps-sdk-core.mjs +41 -16
- package/fesm2015/veloceapps-sdk-core.mjs.map +1 -1
- package/fesm2020/veloceapps-sdk-cms.mjs +4 -0
- package/fesm2020/veloceapps-sdk-cms.mjs.map +1 -1
- package/fesm2020/veloceapps-sdk-core.mjs +39 -16
- package/fesm2020/veloceapps-sdk-core.mjs.map +1 -1
- package/package.json +1 -1
@@ -3,7 +3,7 @@ import { Injectable, InjectionToken, Optional, Inject, NgModule, inject, Directi
|
|
3
3
|
import { UUID, ConfigurationContextMode, ConfigurationContext, UITemplateType, isDefined, ConfigurationProcessorTypes, EntityUtil, 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, ChargeGroupUtils, RuntimeModel, isNotLegacyUIDefinition, SalesforceIdUtils, DEFAULT_TIME_FORMAT, formatNumber } from '@veloceapps/core';
|
4
4
|
import * as i1 from '@veloceapps/api';
|
5
5
|
import { PriceApiService, ContextApiService, ProductModelApiService, ConfigurationApiService } from '@veloceapps/api';
|
6
|
-
import { BehaviorSubject, switchMap, map as map$1, tap as tap$1, noop, catchError, throwError, of, forkJoin, Subject, filter as filter$1, zip, combineLatest, skip as skip$1, shareReplay as shareReplay$1, finalize, takeUntil, take as take$1
|
6
|
+
import { BehaviorSubject, switchMap, map as map$1, tap as tap$1, noop, catchError, throwError, of, forkJoin, Subject, filter as filter$1, zip, combineLatest, skip as skip$1, shareReplay as shareReplay$1, distinctUntilChanged, finalize, takeUntil, take as take$1 } from 'rxjs';
|
7
7
|
import { map, filter, tap, switchMap as switchMap$1, skip, take, shareReplay, catchError as catchError$1, finalize as finalize$1, first } from 'rxjs/operators';
|
8
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';
|
@@ -771,6 +771,7 @@ class FlowStateService {
|
|
771
771
|
this.toastService = toastService;
|
772
772
|
this.customizationService = customizationService;
|
773
773
|
this.NOT_INITIALIZED = Symbol();
|
774
|
+
this._hasStatefulUnsavedChanges = false;
|
774
775
|
this.stateId$ = new BehaviorSubject(null);
|
775
776
|
this.processors = {};
|
776
777
|
this.subscriptions = {};
|
@@ -780,7 +781,7 @@ class FlowStateService {
|
|
780
781
|
all subscriptions get their updates according to updated QuoteDraft
|
781
782
|
*/
|
782
783
|
this.isInitialized$()
|
783
|
-
.pipe(filter$1(Boolean), filter$1(() => !this.getFlowSafe().properties.stateful), switchMap(() => this.quoteDraftService.quoteDraft$), skip$1(1), switchMap(() => this.executeRequest$({})))
|
784
|
+
.pipe(filter$1(Boolean), filter$1(() => !this.getFlowSafe().properties.stateful), switchMap(() => this.quoteDraftService.quoteDraft$), skip$1(1), switchMap(() => this.executeRequest$({}, true)))
|
784
785
|
.subscribe();
|
785
786
|
this.charges$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
|
786
787
|
if (!flow?.properties.stateful) {
|
@@ -836,6 +837,11 @@ class FlowStateService {
|
|
836
837
|
this.processors = {};
|
837
838
|
this.cleanup$.next();
|
838
839
|
}
|
840
|
+
get hasUnsavedChanges() {
|
841
|
+
return this.getFlowSafe().properties.stateful
|
842
|
+
? this._hasStatefulUnsavedChanges
|
843
|
+
: this.quoteDraftService.hasUnsavedChanges;
|
844
|
+
}
|
839
845
|
isInitialized$() {
|
840
846
|
return combineLatest([this.stateId$, this.quoteDraftService.isInitialized$]).pipe(map$1(values => values.some(Boolean)));
|
841
847
|
}
|
@@ -893,7 +899,9 @@ class FlowStateService {
|
|
893
899
|
this.executeRequest$(request).subscribe();
|
894
900
|
}
|
895
901
|
}
|
896
|
-
return this.subscriptions[requestId].data$.pipe(filter$1(data => data != this.NOT_INITIALIZED),
|
902
|
+
return this.subscriptions[requestId].data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), distinctUntilChanged((p, c) => {
|
903
|
+
return isEqual(p, c);
|
904
|
+
}), map$1(data => data), finalize(() => {
|
897
905
|
if (!this.subscriptions[requestId].data$.observed) {
|
898
906
|
delete this.subscriptions[requestId];
|
899
907
|
}
|
@@ -908,10 +916,10 @@ class FlowStateService {
|
|
908
916
|
else {
|
909
917
|
const quoteDraft = this.quoteDraftService.quoteDraftForActivePriceList;
|
910
918
|
if (quoteDraft) {
|
911
|
-
return this.quoteApiService.upsertQuote(quoteDraft)
|
919
|
+
return this.quoteApiService.upsertQuote(quoteDraft);
|
912
920
|
}
|
913
921
|
}
|
914
|
-
return of(
|
922
|
+
return of({ quoteId: '' });
|
915
923
|
}
|
916
924
|
submit$() {
|
917
925
|
if (this.getFlowSafe().properties.stateful) {
|
@@ -922,10 +930,10 @@ class FlowStateService {
|
|
922
930
|
else {
|
923
931
|
const quoteDraft = this.quoteDraftService.quoteDraftForActivePriceList;
|
924
932
|
if (quoteDraft) {
|
925
|
-
return this.quoteApiService.submitQuote(quoteDraft)
|
933
|
+
return this.quoteApiService.submitQuote(quoteDraft);
|
926
934
|
}
|
927
935
|
}
|
928
|
-
return of(
|
936
|
+
return of({ quoteId: '' });
|
929
937
|
}
|
930
938
|
getOwnerIdByScope(scope) {
|
931
939
|
const ownerId = this.flowInfoService.templates[scope]?.id;
|
@@ -953,9 +961,9 @@ class FlowStateService {
|
|
953
961
|
}), {}),
|
954
962
|
};
|
955
963
|
}
|
956
|
-
executeRequest$(request) {
|
964
|
+
executeRequest$(request, forceSubscriptions = false) {
|
957
965
|
const fullRequest = cloneDeep(request);
|
958
|
-
if (fullRequest.actions?.length) {
|
966
|
+
if (fullRequest.actions?.length || forceSubscriptions) {
|
959
967
|
for (const subscription of Object.values(this.subscriptions)) {
|
960
968
|
fullRequest.selectors = assign(fullRequest.selectors, subscription.request.selectors);
|
961
969
|
}
|
@@ -991,13 +999,15 @@ class FlowStateService {
|
|
991
999
|
.map(({ request }) => request.selectors)
|
992
1000
|
.filter(isDefined)
|
993
1001
|
.reduce((trunk, selectors) => ({ ...trunk, ...selectors }), {});
|
1002
|
+
const request = this.getDefaultExecutionRequestDTO();
|
994
1003
|
return this.flowStateApiService
|
995
1004
|
.init({
|
996
1005
|
quoteId: this.contextService.resolve().headerId,
|
997
1006
|
params: this.flowInfoService.params ?? {},
|
998
1007
|
actionsOverride: processors?.filter(processor => processor.type === ConfigurationProcessorTypes.ACTION),
|
999
1008
|
selectorsOverride: processors?.filter(processor => processor.type === ConfigurationProcessorTypes.SELECTOR),
|
1000
|
-
selectors,
|
1009
|
+
selectors: { ...selectors, ...request.selectors },
|
1010
|
+
actions: request.actions,
|
1001
1011
|
})
|
1002
1012
|
.pipe(map$1(({ stateId, selectors }) => {
|
1003
1013
|
this.handleSelectorsResponse(selectors);
|
@@ -1008,15 +1018,15 @@ class FlowStateService {
|
|
1008
1018
|
if (!this.stateId$.value) {
|
1009
1019
|
throw 'Stateful session is not initialized';
|
1010
1020
|
}
|
1011
|
-
return this.flowStateApiService
|
1012
|
-
|
1013
|
-
|
1021
|
+
return this.flowStateApiService.execute(this.stateId$.value, request).pipe(tap$1(response => {
|
1022
|
+
if (request.actions?.length) {
|
1023
|
+
this._hasStatefulUnsavedChanges = true;
|
1024
|
+
}
|
1025
|
+
}), tap$1(response => this.stateId$.next(response.stateId)));
|
1014
1026
|
}
|
1015
1027
|
initStateless$() {
|
1016
1028
|
const { headerId } = this.contextService.resolve();
|
1017
|
-
const stateInit$ = this.quoteDraftService
|
1018
|
-
.init(headerId, this.flowInfoService.params ?? {})
|
1019
|
-
.pipe(switchMap(() => this.calculate$()));
|
1029
|
+
const stateInit$ = this.quoteDraftService.init(headerId, this.flowInfoService.params ?? {}).pipe(switchMap(() => this.executeRequest$(this.getDefaultExecutionRequestDTO())), switchMap(() => this.calculate$()));
|
1020
1030
|
return stateInit$.pipe(tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
|
1021
1031
|
}
|
1022
1032
|
calculate$() {
|
@@ -1131,6 +1141,19 @@ class FlowStateService {
|
|
1131
1141
|
const inputDataHash = UUID.hex(JSON.stringify(inputData) || '').slice(0, 8);
|
1132
1142
|
return `${scope}/${selectorName}/${inputDataHash}`;
|
1133
1143
|
}
|
1144
|
+
getDefaultExecutionRequestDTO() {
|
1145
|
+
const request = {
|
1146
|
+
actions: [],
|
1147
|
+
selectors: {},
|
1148
|
+
};
|
1149
|
+
const ownerId = this.getOwnerIdByScope(UITemplateType.FLOW_ENGINE);
|
1150
|
+
request.actions?.push({
|
1151
|
+
apiName: 'INITIALIZE_STATE',
|
1152
|
+
ownerId,
|
1153
|
+
inputData: {},
|
1154
|
+
});
|
1155
|
+
return request;
|
1156
|
+
}
|
1134
1157
|
}
|
1135
1158
|
FlowStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, deps: [{ token: ContextService }, { token: QuoteDraftService }, { token: FlowInfoService }, { token: FlowConfigurationService }, { token: i1.ConfigurationProcessorsApiService }, { token: i1.FlowStateApiService }, { token: i1.QuoteApiService }, { token: i6.ToastService }, { token: FLOW_CUSTOMIZATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
1136
1159
|
FlowStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, providedIn: 'root' });
|