@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.
@@ -1,11 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, InjectionToken, Optional, Inject, NgModule, inject, Directive, Input, LOCALE_ID, Pipe } from '@angular/core';
3
- import { UUID, ConfigurationContextMode, ConfigurationContext, UITemplateType, ConfigurationProcessorTypes, EntityUtil, isDefined, 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';
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, shareReplay as shareReplay$1, take as take$1, distinctUntilChanged } from 'rxjs';
7
- import { map, filter, tap, switchMap as switchMap$1, skip, take, shareReplay, catchError as catchError$1, finalize, first } from 'rxjs/operators';
8
- import { merge, isEmpty, flatten, sortBy, map as map$2, omit, isEqual, uniqBy, transform, cloneDeep, uniq } from 'lodash';
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';
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
+ 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 { HttpErrorResponse } from '@angular/common/http';
@@ -173,6 +173,9 @@ class FlowInfoService {
173
173
  this.templatesApiService = templatesApiService;
174
174
  this.customizationService = customizationService;
175
175
  this.templates = {};
176
+ this.defaultTemplates = {
177
+ flowEngine: 'Flow Engine',
178
+ };
176
179
  this.flowSubj$ = new BehaviorSubject(null);
177
180
  this.flow$ = this.flowSubj$.asObservable();
178
181
  }
@@ -196,7 +199,7 @@ class FlowInfoService {
196
199
  this.templatesApiService.fetchTemplates$(),
197
200
  this.customizationService?.getTemplates?.() ?? of([]),
198
201
  ]).pipe(map$1(([templates, localTemplates]) => {
199
- Object.entries(flow.properties.templates).forEach(([key, name]) => {
202
+ Object.entries({ ...this.defaultTemplates, ...flow.properties.templates }).forEach(([key, name]) => {
200
203
  const type = this.remapTemplateName(key);
201
204
  if (type) {
202
205
  this.templates[type] =
@@ -207,6 +210,12 @@ class FlowInfoService {
207
210
  }));
208
211
  }
209
212
  remapTemplateName(templateType) {
213
+ switch (templateType) {
214
+ case 'flowEngine':
215
+ return UITemplateType.FLOW_ENGINE;
216
+ default:
217
+ break;
218
+ }
210
219
  switch (templateType) {
211
220
  case 'assets':
212
221
  case 'shoppingCart':
@@ -221,8 +230,9 @@ class FlowInfoService {
221
230
  case 'flowHeader':
222
231
  return UITemplateType.FLOW_HEADER;
223
232
  default:
224
- return;
233
+ break;
225
234
  }
235
+ return undefined;
226
236
  }
227
237
  }
228
238
  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 });
@@ -764,6 +774,7 @@ class FlowStateService {
764
774
  this.stateId$ = new BehaviorSubject(null);
765
775
  this.processors = {};
766
776
  this.subscriptions = {};
777
+ this.cleanup$ = new Subject();
767
778
  /*
768
779
  In stateless mode watch QuoteDraft changes and call executeRequest so that
769
780
  all subscriptions get their updates according to updated QuoteDraft
@@ -773,12 +784,14 @@ class FlowStateService {
773
784
  .subscribe();
774
785
  }
775
786
  init$() {
776
- if (this.getFlowSafe().properties.stateful) {
777
- return this.initStateful$();
778
- }
779
- else {
780
- return this.initStateless$();
781
- }
787
+ return this.initProcessors$().pipe(switchMap(() => {
788
+ if (this.getFlowSafe().properties.stateful) {
789
+ return this.initStateful$();
790
+ }
791
+ else {
792
+ return this.initStateless$();
793
+ }
794
+ }));
782
795
  }
783
796
  cleanup() {
784
797
  Object.values(this.subscriptions).forEach(({ data$ }) => data$.complete());
@@ -788,6 +801,7 @@ class FlowStateService {
788
801
  this.stateId$.next(null);
789
802
  }
790
803
  this.processors = {};
804
+ this.cleanup$.next();
791
805
  }
792
806
  isInitialized$() {
793
807
  return combineLatest([this.stateId$, this.quoteDraftService.isInitialized$]).pipe(map$1(values => values.some(Boolean)));
@@ -827,7 +841,7 @@ class FlowStateService {
827
841
  });
828
842
  return this.executeRequest$(request).pipe(map$1(response => response.selectors[requestId]));
829
843
  }
830
- subscribe$(scope, selectorName, inputData) {
844
+ subscribe$(scope, selectorName, inputData, options) {
831
845
  const inputDataHash = UUID.hex(JSON.stringify(inputData)).slice(0, 8);
832
846
  const requestId = `${scope}/${selectorName}/${inputDataHash}`;
833
847
  if (!this.subscriptions[requestId]) {
@@ -843,9 +857,15 @@ class FlowStateService {
843
857
  request,
844
858
  data$: new BehaviorSubject(this.NOT_INITIALIZED),
845
859
  };
846
- this.executeRequest$({}).subscribe();
860
+ if (!options?.cold) {
861
+ this.executeRequest$(request).subscribe();
862
+ }
847
863
  }
848
- return this.subscriptions[requestId].data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data));
864
+ return this.subscriptions[requestId].data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), finalize(() => {
865
+ if (!this.subscriptions[requestId].data$.observed) {
866
+ delete this.subscriptions[requestId];
867
+ }
868
+ }));
849
869
  }
850
870
  save$() {
851
871
  if (this.getFlowSafe().properties.stateful) {
@@ -902,40 +922,53 @@ class FlowStateService {
902
922
  };
903
923
  }
904
924
  executeRequest$(request) {
905
- const fullRequest = {
906
- ...request,
907
- selectors: {
908
- ...request.selectors,
909
- ...Object.values(this.subscriptions).reduce((trunk, subscription) => {
910
- return {
911
- ...trunk,
912
- ...subscription.request.selectors,
913
- };
914
- }, {}),
915
- },
916
- };
925
+ const fullRequest = cloneDeep(request);
926
+ if (fullRequest.actions?.length) {
927
+ for (const subscription of Object.values(this.subscriptions)) {
928
+ fullRequest.selectors = assign(fullRequest.selectors, subscription.request.selectors);
929
+ }
930
+ }
917
931
  const execution$ = this.getFlowSafe().properties.stateful
918
932
  ? this.executeStateful$(fullRequest)
919
933
  : this.executeStateless$(fullRequest);
920
- return execution$.pipe(tap$1(result => {
921
- Object.entries(result.selectors).forEach(([requestId, selectorResult]) => {
922
- if (!selectorResult.success) {
923
- this.toastService.add({ severity: ToastType.error, summary: selectorResult.errorMessage });
924
- }
925
- const subscription$ = this.subscriptions[requestId]?.data$;
926
- if (subscription$) {
927
- subscription$.next(selectorResult);
928
- }
929
- });
930
- }));
934
+ return execution$.pipe(tap$1(result => this.handleSelectorsResponse(result.selectors)));
935
+ }
936
+ handleSelectorsResponse(selectors) {
937
+ Object.entries(selectors).forEach(([requestId, selectorResult]) => {
938
+ if (!selectorResult.success) {
939
+ this.toastService.add({ severity: ToastType.error, summary: selectorResult.errorMessage });
940
+ }
941
+ const subscription$ = this.subscriptions[requestId]?.data$;
942
+ if (subscription$) {
943
+ subscription$.next(selectorResult);
944
+ }
945
+ });
931
946
  }
932
947
  initStateful$() {
933
- return this.getLocalProcessors$().pipe(switchMap(processors => this.flowStateApiService.init({
948
+ // Subscriptions
949
+ this.subscribe$(UITemplateType.FLOW_ENGINE, 'GET_CONTEXT', null, { cold: true })
950
+ .pipe(tap$1(response => {
951
+ if (response.success) {
952
+ this.contextService.update(response.result);
953
+ }
954
+ }), takeUntil(this.cleanup$))
955
+ .subscribe();
956
+ const processorsList = flatten(Object.values(this.processors).map(ownerMap => Object.values(ownerMap ?? {})));
957
+ const processors = processorsList.length ? processorsList : undefined;
958
+ const selectors = Object.values(this.subscriptions)
959
+ .map(({ request }) => request.selectors)
960
+ .filter(isDefined)
961
+ .reduce((trunk, selectors) => ({ ...trunk, ...selectors }), {});
962
+ return this.flowStateApiService
963
+ .init({
934
964
  quoteId: this.contextService.resolve().headerId,
935
965
  params: this.flowInfoService.params ?? {},
936
966
  actionsOverride: processors?.filter(processor => processor.type === ConfigurationProcessorTypes.ACTION),
937
967
  selectorsOverride: processors?.filter(processor => processor.type === ConfigurationProcessorTypes.SELECTOR),
938
- })), map$1(({ stateId }) => {
968
+ selectors,
969
+ })
970
+ .pipe(map$1(({ stateId, selectors }) => {
971
+ this.handleSelectorsResponse(selectors);
939
972
  this.stateId$.next(stateId);
940
973
  }));
941
974
  }
@@ -1011,6 +1044,12 @@ class FlowStateService {
1011
1044
  return this.flowInfoService.flow;
1012
1045
  }
1013
1046
  initProcessors$() {
1047
+ const hasOverrides = Boolean(this.customizationService?.getTemplateConfigurationProcessors);
1048
+ const flow = this.getFlowSafe();
1049
+ if (flow.properties.stateful && !hasOverrides) {
1050
+ // Skip initialization as backend will take processors from SF
1051
+ return of(undefined);
1052
+ }
1014
1053
  const owners$ = Object.values(this.flowInfoService.templates)
1015
1054
  .map(template => {
1016
1055
  if (!template) {
@@ -1028,18 +1067,6 @@ class FlowStateService {
1028
1067
  .filter(isDefined);
1029
1068
  return forkJoin(owners$).pipe(map$1(noop));
1030
1069
  }
1031
- getLocalProcessors$() {
1032
- const processorsPerTemplate$ = Object.values(this.flowInfoService.templates).map(template => this.customizationService?.getTemplateConfigurationProcessors?.(template.name) ?? of(null));
1033
- return forkJoin(processorsPerTemplate$).pipe(map$1(processors => {
1034
- const definedProcessors = processors.filter(isDefined);
1035
- if (definedProcessors.length) {
1036
- return flatten(definedProcessors);
1037
- }
1038
- else {
1039
- return null;
1040
- }
1041
- }));
1042
- }
1043
1070
  executeActionScript(request, executable) {
1044
1071
  const script = this.processors[executable.ownerId]?.[executable.apiName]?.script;
1045
1072
  if (!script) {
@@ -1306,7 +1333,7 @@ class ConfigurationService {
1306
1333
  this.showInactiveProductsConfirmation();
1307
1334
  }
1308
1335
  this.configurableRamp = lineItem;
1309
- }), map(({ lineItem }) => lineItem), catchError$1(error => throwError(() => new Error(error.error?.message || error.message || JSON.stringify(error)))), finalize(() => this.isLoadingSubj$.next(false)));
1336
+ }), map(({ lineItem }) => lineItem), catchError$1(error => throwError(() => new Error(error.error?.message || error.message || JSON.stringify(error)))), finalize$1(() => this.isLoadingSubj$.next(false)));
1310
1337
  }
1311
1338
  configureExternal$(props) {
1312
1339
  return this.runtimeService
@@ -1314,7 +1341,7 @@ class ConfigurationService {
1314
1341
  .pipe(switchMap$1(() => this.configure()), first(), catchError$1(error => {
1315
1342
  this.messageService.add({ severity: ToastType.error, summary: error });
1316
1343
  throw error;
1317
- }), finalize(() => this.reset()));
1344
+ }), finalize$1(() => this.reset()));
1318
1345
  }
1319
1346
  configureGuidedSelling$(data) {
1320
1347
  return this.configurationApiService