@veloceapps/sdk 9.0.0-1 → 9.0.0-10

Sign up to get free protection for your applications and to get access to all the features.
@@ -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, 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';
3
+ import { UUID, ConfigurationContextMode, ConfigurationContext, UITemplateType, QuoteDraft, 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 { ApiModule } from '@veloceapps/api';
6
- import { BehaviorSubject, switchMap, map as map$1, tap as tap$1, noop, catchError, throwError, of, forkJoin, zip, combineLatest, Subject, filter as filter$1, shareReplay as shareReplay$1, finalize, takeUntil, buffer, debounceTime, share, take as take$1, distinctUntilChanged } from 'rxjs';
6
+ import { BehaviorSubject, switchMap, map as map$1, tap as tap$1, noop, catchError, throwError, forkJoin, of, zip, combineLatest, Subject, filter as filter$1, shareReplay as shareReplay$1, finalize, takeUntil, buffer, debounceTime, share, 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
- import { merge, isEmpty, isEqual, cloneDeep, assign, flatten, entries, sortBy, map as map$2, uniqBy, omit, transform } from 'lodash';
8
+ import { merge, isEqual, cloneDeep, assign, flatten, entries, sortBy, map as map$2, uniqBy, omit, transform } 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';
@@ -230,9 +230,6 @@ class FlowInfoService {
230
230
  this.templates = {};
231
231
  }
232
232
  initFlowTemplates$(flow) {
233
- if (isEmpty(flow.properties.templates)) {
234
- return of(undefined);
235
- }
236
233
  return forkJoin([
237
234
  this.templatesApiService.fetchTemplates$(),
238
235
  this.customizationService?.getTemplates?.() ?? of([]),
@@ -344,13 +341,19 @@ class QuoteDraftService {
344
341
  }
345
342
  init(headerId, params) {
346
343
  const ctx = this.context.resolve();
347
- const accountId = this.context.mode === ConfigurationContextMode.ACCOUNT ? headerId : ctx.properties.AccountId;
348
- return zip(accountId ? this.accountApiService.getAssetsState(accountId, params) : of(null), this.quoteApiService.getQuoteState(headerId, params)).pipe(tap(([assets, quote]) => {
344
+ const isAccountMode = this.context.mode === ConfigurationContextMode.ACCOUNT;
345
+ const accountId = isAccountMode ? headerId : ctx.properties.AccountId;
346
+ return zip(accountId ? this.accountApiService.getAssetsState(accountId, params) : of(null), isAccountMode ? of(QuoteDraft.emptyQuote(ConfigurationContextMode.ACCOUNT)) : this.quoteApiService.getQuoteState(headerId, params)).pipe(tap(([assets, quote]) => {
349
347
  if (assets) {
350
348
  this.assetsSubj$.next(assets);
351
349
  }
352
350
  this.quoteSubj$.next(quote);
353
- this.context.update(quote.context);
351
+ if (assets && isAccountMode) {
352
+ this.context.update(assets.context);
353
+ }
354
+ else {
355
+ this.context.update(quote.context);
356
+ }
354
357
  }), map(() => noop()), take(1));
355
358
  }
356
359
  finalizeInit() {
@@ -474,7 +477,7 @@ class FlowStateService {
474
477
  this.processors = {};
475
478
  this.subscriptions = {};
476
479
  this.flowStore = {};
477
- this.statefulExecutionInProgress$ = new BehaviorSubject(false);
480
+ this.executionInProgress$ = new BehaviorSubject(false);
478
481
  this.statefulRequestStream$ = new Subject();
479
482
  this.cleanup$ = new Subject();
480
483
  this.statefulExecutionRequest$ = this.initBufferedRequest$();
@@ -560,7 +563,7 @@ class FlowStateService {
560
563
  return this.stateId$.value;
561
564
  }
562
565
  get isExecutionInProgress$() {
563
- return this.statefulExecutionInProgress$.asObservable();
566
+ return this.executionInProgress$.asObservable();
564
567
  }
565
568
  isInitialized$() {
566
569
  return combineLatest([this.stateId$, this.quoteDraftService.isInitialized$]).pipe(map$1(values => values.some(Boolean)));
@@ -754,15 +757,15 @@ class FlowStateService {
754
757
  .filter(isDefined)
755
758
  .reduce((acc, selectorsMap) => Object.assign(acc, selectorsMap), {}),
756
759
  };
757
- this.statefulExecutionInProgress$.next(true);
760
+ this.executionInProgress$.next(true);
758
761
  return this.flowStateApiService.execute(this.stateId$.value, request);
759
- }), tap$1(({ stateId }) => this.stateId$.next(stateId)), share(), tap$1(() => this.statefulExecutionInProgress$.next(false)), catchError(e => {
760
- this.statefulExecutionInProgress$.next(false);
762
+ }), tap$1(({ stateId }) => this.stateId$.next(stateId)), share(), tap$1(() => this.executionInProgress$.next(false)), catchError(e => {
763
+ this.executionInProgress$.next(false);
761
764
  return throwError(() => e);
762
765
  }));
763
766
  }
764
767
  executeStateful$(request) {
765
- return this.statefulExecutionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap(() =>
768
+ return this.executionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap(() =>
766
769
  // make sure stream switches to statefulExecutionRequest$ before pushing an execution request
767
770
  combineLatest([
768
771
  this.statefulExecutionRequest$,
@@ -776,7 +779,12 @@ class FlowStateService {
776
779
  if (assets) {
777
780
  this.flowStore = { ...this.flowStore, assets };
778
781
  }
779
- }), switchMap(() => this.executeRequest$(this.getDefaultExecutionRequestDTO())), switchMap(() => this.calculate$()), tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
782
+ }), switchMap(() => {
783
+ if (this.flowInfoService.isLegacy) {
784
+ return of(null);
785
+ }
786
+ return this.executeRequest$(this.getDefaultExecutionRequestDTO());
787
+ }), switchMap(() => this.calculate$()), tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
780
788
  }
781
789
  calculate$() {
782
790
  const flowState = this.quoteDraftService.quoteDraft;
@@ -798,6 +806,7 @@ class FlowStateService {
798
806
  return this.flowConfiguration.calculate$(flowState);
799
807
  }
800
808
  executeStateless$(request) {
809
+ this.executionInProgress$.next(true);
801
810
  return of(undefined).pipe(tap$1(() => this.executeStatelessActions(request)), switchMap(() => {
802
811
  /*
803
812
  Skip price calculation in case
@@ -810,7 +819,10 @@ class FlowStateService {
810
819
  else {
811
820
  return this.calculate$();
812
821
  }
813
- }), map$1(() => this.executeStatelessSelectors(request)));
822
+ }), map$1(() => this.executeStatelessSelectors(request)), tap$1(() => this.executionInProgress$.next(false)), catchError(e => {
823
+ this.executionInProgress$.next(false);
824
+ return throwError(() => e);
825
+ }));
814
826
  }
815
827
  executeStatelessActions(request) {
816
828
  if (!this.quoteDraftService.quoteDraft || !request.actions?.length) {
@@ -2047,10 +2059,13 @@ class ConfigurationStateService {
2047
2059
  this.ownerId = '';
2048
2060
  this.subscriptions = {};
2049
2061
  this.configurationStore = {};
2050
- this.statefulExecutionInProgress$ = new BehaviorSubject(false);
2062
+ this.executionInProgress$ = new BehaviorSubject(false);
2051
2063
  this.statefulRequestStream$ = new Subject();
2052
2064
  this.statefulExecutionRequest$ = this.initBufferedRequest$();
2053
2065
  }
2066
+ get isExecutionInProgress$() {
2067
+ return this.executionInProgress$.asObservable();
2068
+ }
2054
2069
  init$() {
2055
2070
  let request$;
2056
2071
  if (this.flowStateService.stateId && this.isStatefulConfiguration) {
@@ -2144,7 +2159,8 @@ class ConfigurationStateService {
2144
2159
  }
2145
2160
  }), takeUntil(this.canceledConfiguration$));
2146
2161
  }
2147
- saveConfiguration(quoteId, flow) {
2162
+ saveConfiguration(first, second) {
2163
+ const flow = typeof first === 'boolean' ? first : second;
2148
2164
  if (this.isStatefulConfiguration) {
2149
2165
  return this.flowStateApiService
2150
2166
  .saveConfiguration(this.flowStateService.stateId ?? '', this.stateId ?? '')
@@ -2152,16 +2168,15 @@ class ConfigurationStateService {
2152
2168
  }
2153
2169
  else {
2154
2170
  if (!flow) {
2155
- if (!quoteId) {
2171
+ const quoteDraft = this.quoteDraftService.quoteDraft;
2172
+ if (!quoteDraft) {
2156
2173
  return of({ quoteId: '' });
2157
2174
  }
2158
2175
  const rootLineItem = this.configurationService.getSnapshot();
2159
2176
  const asset = this.configurationService.getAsset();
2160
2177
  const currentState = rootLineItem ? [rootLineItem] : [];
2161
2178
  const initialState = asset ? [asset] : [];
2162
- return this.quoteApiService
2163
- .getQuoteState(quoteId)
2164
- .pipe(switchMap(quoteDraft => this.quoteApiService.upsertQuote({ ...quoteDraft, currentState, initialState })));
2179
+ return this.quoteApiService.upsertQuote({ ...quoteDraft, currentState, initialState });
2165
2180
  }
2166
2181
  else {
2167
2182
  const quoteDraft = this.quoteDraftService.quoteDraft;
@@ -2238,6 +2253,7 @@ class ConfigurationStateService {
2238
2253
  return this.configurationService.configure().pipe(map$1(() => undefined));
2239
2254
  }
2240
2255
  executeStateless$(request) {
2256
+ this.executionInProgress$.next(true);
2241
2257
  return of(undefined).pipe(switchMap(() => {
2242
2258
  // Apply actions and execute configuration/price call
2243
2259
  // No need to run configuration if no actions in the request
@@ -2248,6 +2264,7 @@ class ConfigurationStateService {
2248
2264
  request.actions.forEach(action => {
2249
2265
  configurationRequest = this.executeActionScript(configurationRequest, action) ?? configurationRequest;
2250
2266
  });
2267
+ configurationRequest = ConfigurationTranslatorUtils.lightenConfigurationRequest(configurationRequest);
2251
2268
  return this.configurationService.configureRequest$(configurationRequest);
2252
2269
  }), map$1(() => {
2253
2270
  // Run selectors and apply them to the state
@@ -2272,7 +2289,8 @@ class ConfigurationStateService {
2272
2289
  return result;
2273
2290
  }, { stateId: '', selectors: {} });
2274
2291
  return selectorsResult;
2275
- }), catchError(error => {
2292
+ }), tap$1(() => this.executionInProgress$.next(false)), catchError(error => {
2293
+ this.executionInProgress$.next(false);
2276
2294
  if (!this.configurationRuntimeService.uiDefinitionProperties.suppressToastMessages) {
2277
2295
  this.toastService.add({ severity: ToastType.error, summary: String(error) });
2278
2296
  }
@@ -2292,15 +2310,15 @@ class ConfigurationStateService {
2292
2310
  .filter(isDefined)
2293
2311
  .reduce((acc, selectorsMap) => Object.assign(acc, selectorsMap), {}),
2294
2312
  };
2295
- this.statefulExecutionInProgress$.next(true);
2313
+ this.executionInProgress$.next(true);
2296
2314
  return this.flowStateApiService.executeConfiguration(this.flowStateService.stateId, this.stateId, request);
2297
- }), tap$1(({ stateId }) => (this.stateId = stateId)), share(), tap$1(() => this.statefulExecutionInProgress$.next(false)), catchError(e => {
2298
- this.statefulExecutionInProgress$.next(false);
2315
+ }), tap$1(({ stateId }) => (this.stateId = stateId)), share(), tap$1(() => this.executionInProgress$.next(false)), catchError(e => {
2316
+ this.executionInProgress$.next(false);
2299
2317
  return throwError(() => e);
2300
2318
  }));
2301
2319
  }
2302
2320
  executeStateful$(request) {
2303
- return this.statefulExecutionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap(() =>
2321
+ return this.executionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap(() =>
2304
2322
  // make sure stream switches to statefulExecutionRequest$ before pushing an execution request
2305
2323
  combineLatest([
2306
2324
  this.statefulExecutionRequest$,