@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.
@@ -1,7 +1,7 @@
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
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, 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, distinctUntilChanged } from 'rxjs';
4
+ 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';
5
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';
@@ -710,6 +710,7 @@ class FlowStateService {
710
710
  this.toastService = toastService;
711
711
  this.customizationService = customizationService;
712
712
  this.NOT_INITIALIZED = Symbol();
713
+ this._hasStatefulUnsavedChanges = false;
713
714
  this.stateId$ = new BehaviorSubject(null);
714
715
  this.processors = {};
715
716
  this.subscriptions = {};
@@ -719,7 +720,7 @@ class FlowStateService {
719
720
  all subscriptions get their updates according to updated QuoteDraft
720
721
  */
721
722
  this.isInitialized$()
722
- .pipe(filter$1(Boolean), filter$1(() => !this.getFlowSafe().properties.stateful), switchMap(() => this.quoteDraftService.quoteDraft$), skip$1(1), switchMap(() => this.executeRequest$({})))
723
+ .pipe(filter$1(Boolean), filter$1(() => !this.getFlowSafe().properties.stateful), switchMap(() => this.quoteDraftService.quoteDraft$), skip$1(1), switchMap(() => this.executeRequest$({}, true)))
723
724
  .subscribe();
724
725
  this.charges$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
725
726
  if (!(flow === null || flow === void 0 ? void 0 : flow.properties.stateful)) {
@@ -775,6 +776,11 @@ class FlowStateService {
775
776
  this.processors = {};
776
777
  this.cleanup$.next();
777
778
  }
779
+ get hasUnsavedChanges() {
780
+ return this.getFlowSafe().properties.stateful
781
+ ? this._hasStatefulUnsavedChanges
782
+ : this.quoteDraftService.hasUnsavedChanges;
783
+ }
778
784
  isInitialized$() {
779
785
  return combineLatest([this.stateId$, this.quoteDraftService.isInitialized$]).pipe(map$1(values => values.some(Boolean)));
780
786
  }
@@ -833,7 +839,9 @@ class FlowStateService {
833
839
  this.executeRequest$(request).subscribe();
834
840
  }
835
841
  }
836
- return this.subscriptions[requestId].data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), finalize(() => {
842
+ return this.subscriptions[requestId].data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), distinctUntilChanged((p, c) => {
843
+ return isEqual(p, c);
844
+ }), map$1(data => data), finalize(() => {
837
845
  if (!this.subscriptions[requestId].data$.observed) {
838
846
  delete this.subscriptions[requestId];
839
847
  }
@@ -848,10 +856,10 @@ class FlowStateService {
848
856
  else {
849
857
  const quoteDraft = this.quoteDraftService.quoteDraftForActivePriceList;
850
858
  if (quoteDraft) {
851
- return this.quoteApiService.upsertQuote(quoteDraft).pipe(map$1(noop));
859
+ return this.quoteApiService.upsertQuote(quoteDraft);
852
860
  }
853
861
  }
854
- return of(undefined);
862
+ return of({ quoteId: '' });
855
863
  }
856
864
  submit$() {
857
865
  if (this.getFlowSafe().properties.stateful) {
@@ -862,10 +870,10 @@ class FlowStateService {
862
870
  else {
863
871
  const quoteDraft = this.quoteDraftService.quoteDraftForActivePriceList;
864
872
  if (quoteDraft) {
865
- return this.quoteApiService.submitQuote(quoteDraft).pipe(map$1(noop));
873
+ return this.quoteApiService.submitQuote(quoteDraft);
866
874
  }
867
875
  }
868
- return of(undefined);
876
+ return of({ quoteId: '' });
869
877
  }
870
878
  getOwnerIdByScope(scope) {
871
879
  var _a;
@@ -895,10 +903,10 @@ class FlowStateService {
895
903
  }, {}),
896
904
  };
897
905
  }
898
- executeRequest$(request) {
906
+ executeRequest$(request, forceSubscriptions = false) {
899
907
  var _a;
900
908
  const fullRequest = cloneDeep(request);
901
- if ((_a = fullRequest.actions) === null || _a === void 0 ? void 0 : _a.length) {
909
+ if (((_a = fullRequest.actions) === null || _a === void 0 ? void 0 : _a.length) || forceSubscriptions) {
902
910
  for (const subscription of Object.values(this.subscriptions)) {
903
911
  fullRequest.selectors = assign(fullRequest.selectors, subscription.request.selectors);
904
912
  }
@@ -936,13 +944,15 @@ class FlowStateService {
936
944
  .map(({ request }) => request.selectors)
937
945
  .filter(isDefined)
938
946
  .reduce((trunk, selectors) => (Object.assign(Object.assign({}, trunk), selectors)), {});
947
+ const request = this.getDefaultExecutionRequestDTO();
939
948
  return this.flowStateApiService
940
949
  .init({
941
950
  quoteId: this.contextService.resolve().headerId,
942
951
  params: (_a = this.flowInfoService.params) !== null && _a !== void 0 ? _a : {},
943
952
  actionsOverride: processors === null || processors === void 0 ? void 0 : processors.filter(processor => processor.type === ConfigurationProcessorTypes.ACTION),
944
953
  selectorsOverride: processors === null || processors === void 0 ? void 0 : processors.filter(processor => processor.type === ConfigurationProcessorTypes.SELECTOR),
945
- selectors,
954
+ selectors: Object.assign(Object.assign({}, selectors), request.selectors),
955
+ actions: request.actions,
946
956
  })
947
957
  .pipe(map$1(({ stateId, selectors }) => {
948
958
  this.handleSelectorsResponse(selectors);
@@ -953,16 +963,17 @@ class FlowStateService {
953
963
  if (!this.stateId$.value) {
954
964
  throw 'Stateful session is not initialized';
955
965
  }
956
- return this.flowStateApiService
957
- .execute(this.stateId$.value, request)
958
- .pipe(tap$1(response => this.stateId$.next(response.stateId)));
966
+ return this.flowStateApiService.execute(this.stateId$.value, request).pipe(tap$1(response => {
967
+ var _a;
968
+ if ((_a = request.actions) === null || _a === void 0 ? void 0 : _a.length) {
969
+ this._hasStatefulUnsavedChanges = true;
970
+ }
971
+ }), tap$1(response => this.stateId$.next(response.stateId)));
959
972
  }
960
973
  initStateless$() {
961
974
  var _a;
962
975
  const { headerId } = this.contextService.resolve();
963
- const stateInit$ = this.quoteDraftService
964
- .init(headerId, (_a = this.flowInfoService.params) !== null && _a !== void 0 ? _a : {})
965
- .pipe(switchMap(() => this.calculate$()));
976
+ const stateInit$ = this.quoteDraftService.init(headerId, (_a = this.flowInfoService.params) !== null && _a !== void 0 ? _a : {}).pipe(switchMap(() => this.executeRequest$(this.getDefaultExecutionRequestDTO())), switchMap(() => this.calculate$()));
966
977
  return stateInit$.pipe(tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
967
978
  }
968
979
  calculate$() {
@@ -1084,6 +1095,20 @@ class FlowStateService {
1084
1095
  const inputDataHash = UUID.hex(JSON.stringify(inputData) || '').slice(0, 8);
1085
1096
  return `${scope}/${selectorName}/${inputDataHash}`;
1086
1097
  }
1098
+ getDefaultExecutionRequestDTO() {
1099
+ var _a;
1100
+ const request = {
1101
+ actions: [],
1102
+ selectors: {},
1103
+ };
1104
+ const ownerId = this.getOwnerIdByScope(UITemplateType.FLOW_ENGINE);
1105
+ (_a = request.actions) === null || _a === void 0 ? void 0 : _a.push({
1106
+ apiName: 'INITIALIZE_STATE',
1107
+ ownerId,
1108
+ inputData: {},
1109
+ });
1110
+ return request;
1111
+ }
1087
1112
  }
1088
1113
  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 });
1089
1114
  FlowStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, providedIn: 'root' });