@veloceapps/sdk 8.0.0-111 → 8.0.0-112

Sign up to get free protection for your applications and to get access to all the features.
@@ -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, 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';
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, distinctUntilChanged } 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';
@@ -181,7 +181,7 @@ class FlowInfoService {
181
181
  }
182
182
  init$(flowId, params) {
183
183
  this.params = params;
184
- return this.flowsApiService.getFlow(flowId).pipe(tap$1(flow => this.flowSubj$.next(flow)), switchMap(flow => this.initFlowTemplates$(flow)), map$1(noop), catchError(e => {
184
+ 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 => {
185
185
  this.flowSubj$.next(null);
186
186
  return throwError(() => e);
187
187
  }));
@@ -782,6 +782,39 @@ class FlowStateService {
782
782
  this.isInitialized$()
783
783
  .pipe(filter$1(Boolean), filter$1(() => !this.getFlowSafe().properties.stateful), switchMap(() => this.quoteDraftService.quoteDraft$), skip$1(1), switchMap(() => this.executeRequest$({})))
784
784
  .subscribe();
785
+ this.charges$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
786
+ if (!flow?.properties.stateful) {
787
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.charges));
788
+ }
789
+ else {
790
+ return this.subscribe$(UITemplateType.FLOW_ENGINE, 'CHARGES', null, {
791
+ cold: true,
792
+ }).pipe(map$1(response => (response.success ? response.result : {})));
793
+ }
794
+ }), shareReplay$1());
795
+ this.charges$.subscribe();
796
+ this.pricePlans$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
797
+ if (!flow.properties.stateful) {
798
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.pricePlans));
799
+ }
800
+ else {
801
+ return this.subscribe$(UITemplateType.FLOW_ENGINE, 'PRICE_PLANS', null, {
802
+ cold: true,
803
+ }).pipe(map$1(response => (response.success ? response.result : {})));
804
+ }
805
+ }), shareReplay$1());
806
+ this.pricePlans$.subscribe();
807
+ this.activeMetrics$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
808
+ if (!flow?.properties.stateful) {
809
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.activeMetrics));
810
+ }
811
+ else {
812
+ return this.subscribe$(UITemplateType.FLOW_ENGINE, 'ACTIVE_METRICS', null, {
813
+ cold: true,
814
+ }).pipe(map$1(response => (response.success ? response.result : [])));
815
+ }
816
+ }), shareReplay$1());
817
+ this.activeMetrics$.subscribe();
785
818
  }
786
819
  init$() {
787
820
  return this.initProcessors$().pipe(switchMap(() => {
@@ -830,7 +863,7 @@ class FlowStateService {
830
863
  return this.executeRequest$(request).pipe(map$1(noop));
831
864
  }
832
865
  select$(scope, selectorName, inputData) {
833
- const requestId = UUID.UUID();
866
+ const requestId = this.generateRequestId(scope, selectorName, inputData);
834
867
  const request = this.execToRequest(scope, {
835
868
  selectors: {
836
869
  [requestId]: {
@@ -842,8 +875,7 @@ class FlowStateService {
842
875
  return this.executeRequest$(request).pipe(map$1(response => response.selectors[requestId]));
843
876
  }
844
877
  subscribe$(scope, selectorName, inputData, options) {
845
- const inputDataHash = UUID.hex(JSON.stringify(inputData)).slice(0, 8);
846
- const requestId = `${scope}/${selectorName}/${inputDataHash}`;
878
+ const requestId = this.generateRequestId(scope, selectorName, inputData);
847
879
  if (!this.subscriptions[requestId]) {
848
880
  const request = this.execToRequest(scope, {
849
881
  selectors: {
@@ -946,7 +978,7 @@ class FlowStateService {
946
978
  }
947
979
  initStateful$() {
948
980
  // Subscriptions
949
- this.subscribe$(UITemplateType.FLOW_ENGINE, 'GET_CONTEXT', null, { cold: true })
981
+ this.subscribe$(UITemplateType.FLOW_ENGINE, 'CONTEXT', null, { cold: true })
950
982
  .pipe(tap$1(response => {
951
983
  if (response.success) {
952
984
  this.contextService.update(response.result);
@@ -985,7 +1017,7 @@ class FlowStateService {
985
1017
  const stateInit$ = this.quoteDraftService
986
1018
  .init(headerId, this.flowInfoService.params ?? {})
987
1019
  .pipe(switchMap(() => this.calculate$()));
988
- return forkJoin([this.initProcessors$(), stateInit$]).pipe(tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
1020
+ return stateInit$.pipe(tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
989
1021
  }
990
1022
  calculate$() {
991
1023
  const flowState = this.quoteDraftService.quoteDraft;
@@ -1046,6 +1078,10 @@ class FlowStateService {
1046
1078
  initProcessors$() {
1047
1079
  const hasOverrides = Boolean(this.customizationService?.getTemplateConfigurationProcessors);
1048
1080
  const flow = this.getFlowSafe();
1081
+ if (flow.properties.stateful == null) {
1082
+ // Skip initialization for Stateless flow (legacy)
1083
+ return of(undefined);
1084
+ }
1049
1085
  if (flow.properties.stateful && !hasOverrides) {
1050
1086
  // Skip initialization as backend will take processors from SF
1051
1087
  return of(undefined);
@@ -1091,6 +1127,10 @@ class FlowStateService {
1091
1127
  inputData: inputData,
1092
1128
  });
1093
1129
  }
1130
+ generateRequestId(scope, selectorName, inputData) {
1131
+ const inputDataHash = UUID.hex(JSON.stringify(inputData) || '').slice(0, 8);
1132
+ return `${scope}/${selectorName}/${inputDataHash}`;
1133
+ }
1094
1134
  }
1095
1135
  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 });
1096
1136
  FlowStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, providedIn: 'root' });