@veloceapps/sdk 8.0.0-111 → 8.0.0-113

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, 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';
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';
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';
@@ -147,7 +147,7 @@ class FlowInfoService {
147
147
  }
148
148
  init$(flowId, params) {
149
149
  this.params = params;
150
- return this.flowsApiService.getFlow(flowId).pipe(tap$1(flow => this.flowSubj$.next(flow)), switchMap(flow => this.initFlowTemplates$(flow)), map$1(noop), catchError(e => {
150
+ return this.flowsApiService.getFlow(flowId).pipe(switchMap(flow => this.initFlowTemplates$(flow).pipe(map$1(() => flow))), tap$1(flow => this.flowSubj$.next(flow)), map$1(noop), catchError(e => {
151
151
  this.flowSubj$.next(null);
152
152
  return throwError(() => e);
153
153
  }));
@@ -721,6 +721,39 @@ class FlowStateService {
721
721
  this.isInitialized$()
722
722
  .pipe(filter$1(Boolean), filter$1(() => !this.getFlowSafe().properties.stateful), switchMap(() => this.quoteDraftService.quoteDraft$), skip$1(1), switchMap(() => this.executeRequest$({})))
723
723
  .subscribe();
724
+ this.charges$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
725
+ if (!(flow === null || flow === void 0 ? void 0 : flow.properties.stateful)) {
726
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.charges));
727
+ }
728
+ else {
729
+ return this.subscribe$(UITemplateType.FLOW_ENGINE, 'CHARGES', null, {
730
+ cold: true,
731
+ }).pipe(map$1(response => (response.success ? response.result : {})));
732
+ }
733
+ }), shareReplay$1());
734
+ this.charges$.subscribe();
735
+ this.pricePlans$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
736
+ if (!flow.properties.stateful) {
737
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.pricePlans));
738
+ }
739
+ else {
740
+ return this.subscribe$(UITemplateType.FLOW_ENGINE, 'PRICE_PLANS', null, {
741
+ cold: true,
742
+ }).pipe(map$1(response => (response.success ? response.result : {})));
743
+ }
744
+ }), shareReplay$1());
745
+ this.pricePlans$.subscribe();
746
+ this.activeMetrics$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
747
+ if (!(flow === null || flow === void 0 ? void 0 : flow.properties.stateful)) {
748
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.activeMetrics));
749
+ }
750
+ else {
751
+ return this.subscribe$(UITemplateType.FLOW_ENGINE, 'ACTIVE_METRICS', null, {
752
+ cold: true,
753
+ }).pipe(map$1(response => (response.success ? response.result : [])));
754
+ }
755
+ }), shareReplay$1());
756
+ this.activeMetrics$.subscribe();
724
757
  }
725
758
  init$() {
726
759
  return this.initProcessors$().pipe(switchMap(() => {
@@ -770,7 +803,7 @@ class FlowStateService {
770
803
  return this.executeRequest$(request).pipe(map$1(noop));
771
804
  }
772
805
  select$(scope, selectorName, inputData) {
773
- const requestId = UUID.UUID();
806
+ const requestId = this.generateRequestId(scope, selectorName, inputData);
774
807
  const request = this.execToRequest(scope, {
775
808
  selectors: {
776
809
  [requestId]: {
@@ -782,8 +815,7 @@ class FlowStateService {
782
815
  return this.executeRequest$(request).pipe(map$1(response => response.selectors[requestId]));
783
816
  }
784
817
  subscribe$(scope, selectorName, inputData, options) {
785
- const inputDataHash = UUID.hex(JSON.stringify(inputData)).slice(0, 8);
786
- const requestId = `${scope}/${selectorName}/${inputDataHash}`;
818
+ const requestId = this.generateRequestId(scope, selectorName, inputData);
787
819
  if (!this.subscriptions[requestId]) {
788
820
  const request = this.execToRequest(scope, {
789
821
  selectors: {
@@ -891,7 +923,7 @@ class FlowStateService {
891
923
  initStateful$() {
892
924
  var _a;
893
925
  // Subscriptions
894
- this.subscribe$(UITemplateType.FLOW_ENGINE, 'GET_CONTEXT', null, { cold: true })
926
+ this.subscribe$(UITemplateType.FLOW_ENGINE, 'CONTEXT', null, { cold: true })
895
927
  .pipe(tap$1(response => {
896
928
  if (response.success) {
897
929
  this.contextService.update(response.result);
@@ -931,7 +963,7 @@ class FlowStateService {
931
963
  const stateInit$ = this.quoteDraftService
932
964
  .init(headerId, (_a = this.flowInfoService.params) !== null && _a !== void 0 ? _a : {})
933
965
  .pipe(switchMap(() => this.calculate$()));
934
- return forkJoin([this.initProcessors$(), stateInit$]).pipe(tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
966
+ return stateInit$.pipe(tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
935
967
  }
936
968
  calculate$() {
937
969
  const flowState = this.quoteDraftService.quoteDraft;
@@ -996,6 +1028,10 @@ class FlowStateService {
996
1028
  var _a;
997
1029
  const hasOverrides = Boolean((_a = this.customizationService) === null || _a === void 0 ? void 0 : _a.getTemplateConfigurationProcessors);
998
1030
  const flow = this.getFlowSafe();
1031
+ if (flow.properties.stateful == null) {
1032
+ // Skip initialization for Stateless flow (legacy)
1033
+ return of(undefined);
1034
+ }
999
1035
  if (flow.properties.stateful && !hasOverrides) {
1000
1036
  // Skip initialization as backend will take processors from SF
1001
1037
  return of(undefined);
@@ -1044,6 +1080,10 @@ class FlowStateService {
1044
1080
  inputData: inputData,
1045
1081
  });
1046
1082
  }
1083
+ generateRequestId(scope, selectorName, inputData) {
1084
+ const inputDataHash = UUID.hex(JSON.stringify(inputData) || '').slice(0, 8);
1085
+ return `${scope}/${selectorName}/${inputDataHash}`;
1086
+ }
1047
1087
  }
1048
1088
  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 });
1049
1089
  FlowStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, providedIn: 'root' });