@veloceapps/sdk 10.0.0-5 → 10.0.0-51

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.
Files changed (42) hide show
  1. package/cms/modules/runtime/services/runtime.service.d.ts +3 -1
  2. package/cms/utils/index.d.ts +1 -0
  3. package/cms/utils/inject.d.ts +1 -0
  4. package/cms/utils/ui-definition.utils.d.ts +1 -0
  5. package/cms/vendor-map.d.ts +4 -2
  6. package/core/modules/configuration/services/configuration-state.service.d.ts +2 -0
  7. package/core/modules/configuration/services/configuration.service.d.ts +2 -0
  8. package/core/modules/flow-configuration/services/flow-configuration.service.d.ts +4 -1
  9. package/core/services/context.service.d.ts +3 -1
  10. package/core/services/flow-info.service.d.ts +4 -2
  11. package/core/services/quote-draft.service.d.ts +3 -1
  12. package/core/services/runtime-settings.service.d.ts +1 -1
  13. package/esm2020/cms/components/element-renderer/element-renderer.component.mjs +3 -2
  14. package/esm2020/cms/components/element-tools-panel/element-tools-panel.component.mjs +3 -3
  15. package/esm2020/cms/modules/runtime/services/runtime.service.mjs +3 -1
  16. package/esm2020/cms/utils/index.mjs +2 -1
  17. package/esm2020/cms/utils/inject.mjs +27 -0
  18. package/esm2020/cms/utils/ui-definition.utils.mjs +13 -1
  19. package/esm2020/cms/vendor-map.mjs +7 -4
  20. package/esm2020/core/modules/configuration/services/configuration-state.service.mjs +38 -22
  21. package/esm2020/core/modules/configuration/services/configuration.service.mjs +14 -3
  22. package/esm2020/core/modules/flow-configuration/services/flow-configuration.service.mjs +16 -5
  23. package/esm2020/core/services/context.service.mjs +15 -6
  24. package/esm2020/core/services/flow-info.service.mjs +19 -6
  25. package/esm2020/core/services/flow-state.service.mjs +19 -6
  26. package/esm2020/core/services/quote-draft.service.mjs +21 -9
  27. package/esm2020/core/services/runtime-settings.service.mjs +3 -3
  28. package/esm2020/src/guards/context.guard.mjs +4 -6
  29. package/esm2020/src/guards/flow.guard.mjs +5 -4
  30. package/fesm2015/veloceapps-sdk-cms.mjs +45 -5
  31. package/fesm2015/veloceapps-sdk-cms.mjs.map +1 -1
  32. package/fesm2015/veloceapps-sdk-core.mjs +333 -254
  33. package/fesm2015/veloceapps-sdk-core.mjs.map +1 -1
  34. package/fesm2015/veloceapps-sdk.mjs +6 -7
  35. package/fesm2015/veloceapps-sdk.mjs.map +1 -1
  36. package/fesm2020/veloceapps-sdk-cms.mjs +44 -4
  37. package/fesm2020/veloceapps-sdk-cms.mjs.map +1 -1
  38. package/fesm2020/veloceapps-sdk-core.mjs +328 -251
  39. package/fesm2020/veloceapps-sdk-core.mjs.map +1 -1
  40. package/fesm2020/veloceapps-sdk.mjs +6 -7
  41. package/fesm2020/veloceapps-sdk.mjs.map +1 -1
  42. package/package.json +1 -1
@@ -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, 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, extractErrorDetails, ConfigurationTranslatorUtils, ChargeGroupUtils, RuntimeModel, isNotLegacyUIDefinition, SalesforceIdUtils, DEFAULT_TIME_FORMAT, formatNumber } from '@veloceapps/core';
3
+ import { UUID, ConfigurationContextMode, 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, ConfigurationContext, UITemplateType, QuoteDraft, isDefined, ConfigurationProcessorTypes, EntityUtil, ConfigurationMode, extractErrorDetails, 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, 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
- 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, isEqual, cloneDeep, assign, flatten, entries, sortBy, map as map$2, uniqBy, omit, transform } from 'lodash';
6
+ import { BehaviorSubject, map, tap, of, noop, catchError, throwError, forkJoin, zip, combineLatest, Subject, filter as filter$1, switchMap as switchMap$1, shareReplay as shareReplay$1, finalize, takeUntil, buffer, debounceTime, share, take as take$1, distinctUntilChanged } from 'rxjs';
7
+ import { map as map$1, filter, tap as tap$1, switchMap, skip, take, shareReplay, catchError as catchError$1, finalize as finalize$1, first } from 'rxjs/operators';
8
+ import { uniqBy, merge, isEqual, cloneDeep, assign, flatten, entries, sortBy, map as map$2, 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';
@@ -88,22 +88,128 @@ const generateConfigurationLineItem = (props, qty = 1) => {
88
88
  };
89
89
  };
90
90
 
91
+ class RuntimeSettingsService {
92
+ constructor(configurationSettingsApiService) {
93
+ this.configurationSettingsApiService = configurationSettingsApiService;
94
+ this.configurationSettings$ = new BehaviorSubject({});
95
+ this.currencySettings$ = new BehaviorSubject({
96
+ iso: DEFAULT_CURRENCY_ISO_CODE,
97
+ symbol: DEFAULT_CURRENCY_SYMBOL,
98
+ });
99
+ this.shoppingCartSettings$ = new BehaviorSubject([]);
100
+ this.getCurrencySymbol = (locale, currency) => {
101
+ return (0)
102
+ .toLocaleString(locale, { style: 'currency', currency, minimumFractionDigits: 0, maximumFractionDigits: 0 })
103
+ .replace(/\d/g, '')
104
+ .trim();
105
+ };
106
+ }
107
+ create() {
108
+ return this.configurationSettingsApiService.fetchSettings().pipe(map(settings => this.parseConfigurationSettings(settings)), tap(configurationSettings => {
109
+ this.configurationSettings$.next(configurationSettings);
110
+ this.addShoppingCartSettings(configurationSettings['shopping-cart'] ?? []);
111
+ this.formattingSettings = this.getFormattingSettings();
112
+ }), map(() => undefined));
113
+ }
114
+ initCurrency(iso) {
115
+ if (iso) {
116
+ const symbol = this.getCurrencySymbol('en-US', iso);
117
+ this.currencySettings$.next({ iso, symbol });
118
+ if (this.formattingSettings) {
119
+ this.formattingSettings.currencySymbol = symbol;
120
+ }
121
+ }
122
+ }
123
+ getFormattingSettings() {
124
+ if (this.formattingSettings) {
125
+ return this.formattingSettings;
126
+ }
127
+ const shoppingCartSettings = this.configurationSettings['shopping-cart']?.reduce((acc, setting) => {
128
+ return { ...acc, [setting.id]: setting.properties };
129
+ }, {});
130
+ const currencySettings = this.getCurrencySettings();
131
+ const dateFormat = (validateDateFormat(shoppingCartSettings?.DATE_FORMAT ?? '') && shoppingCartSettings?.DATE_FORMAT) ||
132
+ DEFAULT_DATE_FORMAT;
133
+ const decimalSeparator = shoppingCartSettings?.DECIMAL_SEPARATOR;
134
+ const thousandsSeparator = shoppingCartSettings?.THOUSANDS_SEPARATOR;
135
+ // the number of decimal places can be 0
136
+ const priceScale = shoppingCartSettings?.PRICE_SCALE;
137
+ const decimalsCount = priceScale !== null && priceScale !== '' && !isNaN(Number(priceScale)) && Number(priceScale) >= 0
138
+ ? Number(priceScale)
139
+ : DEFAULT_DECIMALS_COUNT;
140
+ const actionCodeSettings = shoppingCartSettings?.STATUS_LABEL;
141
+ return {
142
+ currencySymbol: currencySettings.symbol,
143
+ dateFormats: getSupportedDateFormats(dateFormat),
144
+ decimalsCount,
145
+ decimalSeparator: decimalSeparator !== undefined && ['.', ','].includes(decimalSeparator)
146
+ ? decimalSeparator
147
+ : DEFAULT_DECIMAL_SEPARATOR,
148
+ // thousands separator can be a blank value, so it can also be null
149
+ thousandsSeparator: thousandsSeparator !== undefined && ['.', ',', '', null].includes(thousandsSeparator)
150
+ ? thousandsSeparator || ''
151
+ : DEFAULT_THOUSANDS_SEPARATOR,
152
+ actionCodeLabels: actionCodeSettings?.length
153
+ ? actionCodeSettings.reduce((result, setting) => ({ ...result, [setting.status_label]: setting.custom_label }), {})
154
+ : DEFAULT_ACTION_CODE_LABELS,
155
+ };
156
+ }
157
+ get configurationSettings() {
158
+ return this.configurationSettings$.value;
159
+ }
160
+ getShoppingCartSettings() {
161
+ return this.shoppingCartSettings$.value;
162
+ }
163
+ getCurrencySettings() {
164
+ return this.currencySettings$.value;
165
+ }
166
+ parseConfigurationSettings(settings) {
167
+ return settings.reduce((acc, setting) => {
168
+ switch (setting.key) {
169
+ case 'shopping-cart':
170
+ acc['shopping-cart'] = parseJsonSafely(setting.value, []);
171
+ break;
172
+ case 'navigation':
173
+ acc.navigation = parseJsonSafely(setting.value, {});
174
+ break;
175
+ case 'flows':
176
+ acc.flows = parseJsonSafely(setting.value, []);
177
+ break;
178
+ default:
179
+ acc[setting.key] = setting.value;
180
+ }
181
+ return acc;
182
+ }, {});
183
+ }
184
+ addShoppingCartSettings(settings) {
185
+ // uniqBy removes items with the biggest index
186
+ const newSettings = uniqBy([...settings, ...this.shoppingCartSettings$.value], 'id');
187
+ this.shoppingCartSettings$.next(newSettings);
188
+ }
189
+ }
190
+ RuntimeSettingsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService, deps: [{ token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
191
+ RuntimeSettingsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService });
192
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService, decorators: [{
193
+ type: Injectable
194
+ }], ctorParameters: function () { return [{ type: i1.ConfigurationSettingsApiService }]; } });
195
+
91
196
  class ContextService {
92
- constructor(contextApiService) {
197
+ constructor(contextApiService, runtimeSettingsService) {
93
198
  this.contextApiService = contextApiService;
199
+ this.runtimeSettingsService = runtimeSettingsService;
94
200
  this.context = new BehaviorSubject(null);
95
201
  }
96
202
  get isInitialized() {
97
203
  return Boolean(this.context.value);
98
204
  }
99
205
  get isInitialized$() {
100
- return this.context.pipe(map(Boolean));
206
+ return this.context.pipe(map$1(Boolean));
101
207
  }
102
208
  get mode() {
103
209
  return this.resolve().properties['#mode'];
104
210
  }
105
211
  get isEditMode$() {
106
- return this.resolve$().pipe(map(() => this.isEditMode));
212
+ return this.resolve$().pipe(map$1(() => this.isEditMode));
107
213
  }
108
214
  get isEditMode() {
109
215
  const context = this.resolve();
@@ -125,10 +231,16 @@ class ContextService {
125
231
  return this.context.pipe(filter((ctx) => Boolean(ctx)));
126
232
  }
127
233
  create(headerId, mode) {
128
- return this.contextApiService.getContext(headerId, mode).pipe(tap(context => this.context.next(merge(new ConfigurationContext(headerId, mode), context))), map(() => this.resolve()));
234
+ const configurationSettings = this.runtimeSettingsService.configurationSettings;
235
+ const skipContextRequest = configurationSettings['SKIP_CONTEXT_REQUEST'] === 'true';
236
+ let contextRequest$ = this.contextApiService.getContext(headerId, mode);
237
+ if (skipContextRequest) {
238
+ contextRequest$ = of({});
239
+ }
240
+ return contextRequest$.pipe(tap$1(context => this.context.next(merge(new ConfigurationContext(headerId, mode), context))), map$1(() => this.resolve()));
129
241
  }
130
242
  initTestMode() {
131
- return this.create('TestId', ConfigurationContextMode.TEST).pipe(map(context => {
243
+ return this.create('TestId', ConfigurationContextMode.TEST).pipe(map$1(context => {
132
244
  return this.update({
133
245
  properties: {
134
246
  ...context.properties,
@@ -165,11 +277,11 @@ class ContextService {
165
277
  this.context.next(null);
166
278
  }
167
279
  }
168
- ContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextService, deps: [{ token: i1.ContextApiService }], target: i0.ɵɵFactoryTarget.Injectable });
280
+ ContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextService, deps: [{ token: i1.ContextApiService }, { token: RuntimeSettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
169
281
  ContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextService });
170
282
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextService, decorators: [{
171
283
  type: Injectable
172
- }], ctorParameters: function () { return [{ type: i1.ContextApiService }]; } });
284
+ }], ctorParameters: function () { return [{ type: i1.ContextApiService }, { type: RuntimeSettingsService }]; } });
173
285
 
174
286
  const FLOW_CUSTOMIZATION = new InjectionToken('FLOW_CUSTOMIZATION');
175
287
 
@@ -206,9 +318,10 @@ class FlowInfoService {
206
318
  get isStateful() {
207
319
  return !!this.flow?.properties.stateful;
208
320
  }
209
- constructor(flowsApiService, templatesApiService, customizationService) {
321
+ constructor(flowsApiService, templatesApiService, runtimeSettingsService, customizationService) {
210
322
  this.flowsApiService = flowsApiService;
211
323
  this.templatesApiService = templatesApiService;
324
+ this.runtimeSettingsService = runtimeSettingsService;
212
325
  this.customizationService = customizationService;
213
326
  this.templates = {};
214
327
  this.defaultTemplates = {
@@ -218,10 +331,20 @@ class FlowInfoService {
218
331
  this.flow$ = this.flowSubj$.asObservable();
219
332
  }
220
333
  init$(flowId, routeQueryParams) {
221
- return this.flowsApiService.getFlow(flowId).pipe(switchMap(flow => this.initFlowTemplates$(flow).pipe(map$1(() => flow))), tap$1(flow => {
334
+ const flows = this.runtimeSettingsService.configurationSettings['flows'];
335
+ const flow = flows?.find(({ id }) => id === flowId);
336
+ if (!flow) {
337
+ return of(undefined);
338
+ }
339
+ const isLegacy = !!flow && flow?.properties.stateful == null;
340
+ let flowTemplates$ = of(undefined);
341
+ if (!isLegacy) {
342
+ flowTemplates$ = this.initFlowTemplates$(flow).pipe(map(() => undefined));
343
+ }
344
+ return flowTemplates$.pipe(tap(() => {
222
345
  this.params = { ...routeQueryParams, ...flow.properties.queryParams };
223
346
  this.flowSubj$.next(flow);
224
- }), map$1(noop), catchError(e => {
347
+ }), map(noop), catchError(e => {
225
348
  this.flowSubj$.next(null);
226
349
  return throwError(() => e);
227
350
  }));
@@ -235,7 +358,7 @@ class FlowInfoService {
235
358
  return forkJoin([
236
359
  this.templatesApiService.fetchTemplates$(),
237
360
  this.customizationService?.getTemplates?.() ?? of([]),
238
- ]).pipe(map$1(([templates, localTemplates]) => {
361
+ ]).pipe(map(([templates, localTemplates]) => {
239
362
  Object.entries({ ...this.defaultTemplates, ...flow.properties.templates }).forEach(([key, name]) => {
240
363
  const type = this.remapTemplateName(key);
241
364
  if (type) {
@@ -272,11 +395,11 @@ class FlowInfoService {
272
395
  return undefined;
273
396
  }
274
397
  }
275
- 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 });
398
+ FlowInfoService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowInfoService, deps: [{ token: i1.FlowsApiService }, { token: i1.UITemplatesApiService }, { token: RuntimeSettingsService }, { token: FLOW_CUSTOMIZATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
276
399
  FlowInfoService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowInfoService });
277
400
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowInfoService, decorators: [{
278
401
  type: Injectable
279
- }], ctorParameters: function () { return [{ type: i1.FlowsApiService }, { type: i1.UITemplatesApiService }, { type: undefined, decorators: [{
402
+ }], ctorParameters: function () { return [{ type: i1.FlowsApiService }, { type: i1.UITemplatesApiService }, { type: RuntimeSettingsService }, { type: undefined, decorators: [{
280
403
  type: Optional
281
404
  }, {
282
405
  type: Inject,
@@ -305,13 +428,13 @@ class QuoteDraftService {
305
428
  }
306
429
  }
307
430
  get hasProducts$() {
308
- return this.quoteSubj$.pipe(map(() => this.hasProducts));
431
+ return this.quoteSubj$.pipe(map$1(() => this.hasProducts));
309
432
  }
310
433
  get hasProducts() {
311
434
  return Boolean(this.quoteSubj$.value?.currentState.length);
312
435
  }
313
436
  get hasAssets$() {
314
- return this.assetsSubj$.pipe(map(() => this.hasAssets));
437
+ return this.assetsSubj$.pipe(map$1(() => this.hasAssets));
315
438
  }
316
439
  get hasAssets() {
317
440
  return Boolean(this.assetsSubj$.value?.currentState.length);
@@ -319,11 +442,12 @@ class QuoteDraftService {
319
442
  get assetsState() {
320
443
  return this.assetsSubj$.value;
321
444
  }
322
- constructor(context, flowInfoService, accountApiService, quoteApiService) {
445
+ constructor(context, flowInfoService, accountApiService, quoteApiService, runtimeSettingsService) {
323
446
  this.context = context;
324
447
  this.flowInfoService = flowInfoService;
325
448
  this.accountApiService = accountApiService;
326
449
  this.quoteApiService = quoteApiService;
450
+ this.runtimeSettingsService = runtimeSettingsService;
327
451
  this.quoteSubj$ = new BehaviorSubject(null);
328
452
  this.assetsSubj$ = new BehaviorSubject(null);
329
453
  this.resetSubj$ = new BehaviorSubject(true);
@@ -332,7 +456,7 @@ class QuoteDraftService {
332
456
  this._hasUnsavedChanges = false;
333
457
  this.reset$ = this.resetSubj$.asObservable();
334
458
  this.isInitializedSubj$
335
- .pipe(filter(isInitialized => isInitialized), switchMap$1(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
459
+ .pipe(filter(isInitialized => isInitialized), switchMap(() => this.quoteSubj$.asObservable()), skip(1), tap$1(quote => this.markAsUpdated(quote)))
336
460
  .subscribe();
337
461
  }
338
462
  reset() {
@@ -345,21 +469,30 @@ class QuoteDraftService {
345
469
  init(headerId, params) {
346
470
  const ctx = this.context.resolve();
347
471
  const isAccountMode = this.context.mode === ConfigurationContextMode.ACCOUNT;
348
- const accountId = isAccountMode ? headerId : ctx.properties.AccountId;
349
- return zip(accountId ? this.accountApiService.getAssetsState(accountId, params) : of(null), isAccountMode
472
+ const accountId = isAccountMode ? headerId : ctx.properties?.AccountId;
473
+ const configurationSettings = this.runtimeSettingsService.configurationSettings;
474
+ const skipAssetsQuery = configurationSettings['SKIP_ASSETS_QUERY'] === 'true';
475
+ let assetRequest$ = of(null);
476
+ if (accountId && !skipAssetsQuery) {
477
+ assetRequest$ = this.accountApiService.getAssetsState(accountId, params);
478
+ }
479
+ return zip(assetRequest$, isAccountMode
350
480
  ? of(QuoteDraft.emptyQuote(ConfigurationContextMode.ACCOUNT))
351
- : this.quoteApiService.getQuoteState(headerId, params)).pipe(tap(([assets, quote]) => {
481
+ : this.quoteApiService.getQuoteState(headerId, params)).pipe(tap$1(([assets, quote]) => {
352
482
  if (assets) {
353
483
  this.assetsSubj$.next(assets);
354
484
  }
485
+ let context;
355
486
  this.quoteSubj$.next(quote);
356
487
  if (assets && isAccountMode) {
357
- this.context.update(assets.context);
488
+ context = assets.context;
358
489
  }
359
490
  else {
360
- this.context.update(quote.context);
491
+ context = quote.context;
361
492
  }
362
- }), map(() => noop()), take(1));
493
+ this.context.update(context);
494
+ this.runtimeSettingsService.initCurrency(context.properties['CurrencyIsoCode']);
495
+ }), map$1(() => noop()), take(1));
363
496
  }
364
497
  finalizeInit() {
365
498
  this.isInitialized = true;
@@ -408,7 +541,7 @@ class QuoteDraftService {
408
541
  this.assetsSubj$.next(assetsState);
409
542
  }
410
543
  get quoteDraft$() {
411
- return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
544
+ return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map$1(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
412
545
  }
413
546
  get quoteDraft() {
414
547
  const quote = this.quoteSubj$.value;
@@ -421,7 +554,7 @@ class QuoteDraftService {
421
554
  };
422
555
  }
423
556
  get currentState$() {
424
- return this.quoteDraft$.pipe(map(quote => quote.currentState));
557
+ return this.quoteDraft$.pipe(map$1(quote => quote.currentState));
425
558
  }
426
559
  get currentState() {
427
560
  return this.quoteDraft?.currentState ?? [];
@@ -430,13 +563,13 @@ class QuoteDraftService {
430
563
  return this.flowInfoService.flow?.properties.standalone ?? false;
431
564
  }
432
565
  get isStandalone$() {
433
- return this.flowInfoService.flow$.pipe(map(() => this.isStandalone));
566
+ return this.flowInfoService.flow$.pipe(map$1(() => this.isStandalone));
434
567
  }
435
568
  getInitialCurrentState() {
436
569
  return this.initialCurrentState;
437
570
  }
438
571
  isEditMode$() {
439
- return this.context.resolve$().pipe(map(() => this.isEditMode()));
572
+ return this.context.resolve$().pipe(map$1(() => this.isEditMode()));
440
573
  }
441
574
  isEditMode() {
442
575
  const context = this.context.resolve();
@@ -457,11 +590,11 @@ class QuoteDraftService {
457
590
  }
458
591
  }
459
592
  }
460
- QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: FlowInfoService }, { token: i1.AccountApiService }, { token: i1.QuoteApiService }], target: i0.ɵɵFactoryTarget.Injectable });
593
+ QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: FlowInfoService }, { token: i1.AccountApiService }, { token: i1.QuoteApiService }, { token: RuntimeSettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
461
594
  QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService });
462
595
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, decorators: [{
463
596
  type: Injectable
464
- }], ctorParameters: function () { return [{ type: ContextService }, { type: FlowInfoService }, { type: i1.AccountApiService }, { type: i1.QuoteApiService }]; } });
597
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: FlowInfoService }, { type: i1.AccountApiService }, { type: i1.QuoteApiService }, { type: RuntimeSettingsService }]; } });
465
598
 
466
599
  class FlowStateService {
467
600
  constructor(contextService, quoteDraftService, flowInfoService, flowConfiguration, processorsApiService, flowStateApiService, quoteApiService, toastService, customizationService) {
@@ -492,55 +625,59 @@ class FlowStateService {
492
625
  all subscriptions get their updates according to updated QuoteDraft
493
626
  */
494
627
  this.isInitialized$()
495
- .pipe(filter$1(Boolean), filter$1(() => !this.getFlowSafe().properties.stateful), switchMap(() => this.flowConfiguration.updated$), switchMap(() => this.executeRequest$({}, true)))
628
+ .pipe(filter$1(Boolean), filter$1(() => !this.getFlowSafe().properties.stateful), switchMap$1(() => this.flowConfiguration.updated$), switchMap$1(() => this.executeRequest$({}, true)))
496
629
  .subscribe();
497
- this.charges$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(() => {
630
+ this.charges$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap$1(() => {
498
631
  if (this.flowInfoService.isLegacy) {
499
- return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.charges));
632
+ return this.quoteDraftService.quoteDraft$.pipe(map(quoteDraft => quoteDraft.charges));
500
633
  }
501
634
  else {
502
635
  return this.subscribe$(UITemplateType.FLOW_ENGINE, 'CHARGES', null, {
503
636
  cold: true,
504
- }).pipe(map$1(response => (response.success ? response.result : {})));
637
+ }).pipe(map(response => (response.success ? response.result : {})));
505
638
  }
506
639
  }), shareReplay$1(1));
507
640
  this.charges$.subscribe();
508
- this.pricePlans$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(() => {
641
+ this.pricePlans$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap$1(() => {
509
642
  if (this.flowInfoService.isLegacy) {
510
- return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.pricePlans));
643
+ return this.quoteDraftService.quoteDraft$.pipe(map(quoteDraft => quoteDraft.pricePlans));
511
644
  }
512
645
  else {
513
646
  return this.subscribe$(UITemplateType.FLOW_ENGINE, 'PRICE_PLANS', null, {
514
647
  cold: true,
515
- }).pipe(map$1(response => (response.success ? response.result : {})));
648
+ }).pipe(map(response => (response.success ? response.result : {})));
516
649
  }
517
650
  }), shareReplay$1(1));
518
651
  this.pricePlans$.subscribe();
519
- this.activeMetrics$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(() => {
652
+ this.activeMetrics$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap$1(() => {
520
653
  if (this.flowInfoService.isLegacy) {
521
- return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.activeMetrics));
654
+ return this.quoteDraftService.quoteDraft$.pipe(map(quoteDraft => quoteDraft.activeMetrics));
522
655
  }
523
656
  else {
524
657
  return this.subscribe$(UITemplateType.FLOW_ENGINE, 'ACTIVE_METRICS', null, {
525
658
  cold: true,
526
- }).pipe(map$1(response => (response.success ? response.result : [])));
659
+ }).pipe(map(response => (response.success ? response.result : [])));
527
660
  }
528
661
  }), shareReplay$1(1));
529
662
  this.activeMetrics$.subscribe();
530
- this.isPriceListLocked$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(() => {
663
+ this.isPriceListLocked$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap$1(() => {
531
664
  if (this.flowInfoService.isLegacy) {
532
665
  return of(false);
533
666
  }
534
667
  else {
535
668
  return this.subscribe$(UITemplateType.FLOW_ENGINE, 'IS_PRICE_LIST_LOCKED', null, {
536
669
  cold: true,
537
- }).pipe(map$1(response => (response.success ? response.result : false)));
670
+ }).pipe(map(response => (response.success ? response.result : false)));
538
671
  }
539
672
  }), shareReplay$1(1));
540
673
  this.isPriceListLocked$.subscribe();
541
674
  }
542
675
  init$() {
543
- return this.initProcessors$().pipe(switchMap(() => {
676
+ let processors$ = this.initProcessors$();
677
+ if (this.flowInfoService.isLegacy) {
678
+ processors$ = of(undefined);
679
+ }
680
+ return processors$.pipe(switchMap$1(() => {
544
681
  if (this.getFlowSafe().properties.stateful) {
545
682
  return this.initStateful$();
546
683
  }
@@ -572,14 +709,14 @@ class FlowStateService {
572
709
  return this.executionInProgress$.asObservable();
573
710
  }
574
711
  isInitialized$() {
575
- return combineLatest([this.stateId$, this.quoteDraftService.isInitialized$]).pipe(map$1(values => values.some(Boolean)));
712
+ return combineLatest([this.stateId$, this.quoteDraftService.isInitialized$]).pipe(map(values => values.some(Boolean)));
576
713
  }
577
714
  isInitialized() {
578
715
  return Boolean(this.stateId$.value) || this.quoteDraftService.isInitialized;
579
716
  }
580
717
  execute$(scope, exec) {
581
718
  const request = this.execToRequest(scope, exec);
582
- return this.executeRequest$(request).pipe(map$1(result => {
719
+ return this.executeRequest$(request).pipe(map(result => {
583
720
  // Keep only requested results
584
721
  const actualSelectors = Object.entries(result.selectors).reduce((trunk, [requestId, result]) => {
585
722
  if (exec.selectors?.[requestId]) {
@@ -591,11 +728,14 @@ class FlowStateService {
591
728
  }));
592
729
  }
593
730
  dispatch$(scope, action, inputData) {
731
+ if (this.flowInfoService.isLegacy) {
732
+ return of(undefined);
733
+ }
594
734
  const exec = {
595
735
  actions: [{ name: action, inputData }],
596
736
  };
597
737
  const request = this.execToRequest(scope, exec);
598
- return this.executeRequest$(request).pipe(map$1(noop));
738
+ return this.executeRequest$(request).pipe(map(noop));
599
739
  }
600
740
  select$(scope, selectorName, inputData) {
601
741
  const requestId = this.generateRequestId(scope, selectorName, inputData);
@@ -607,9 +747,15 @@ class FlowStateService {
607
747
  },
608
748
  },
609
749
  });
610
- return this.executeRequest$(request).pipe(map$1(response => response.selectors[requestId]));
750
+ return this.executeRequest$(request).pipe(map(response => response.selectors[requestId]));
611
751
  }
612
752
  subscribe$(scope, selectorName, inputData, options) {
753
+ if (this.flowInfoService.isLegacy) {
754
+ return of({
755
+ success: false,
756
+ errorMessage: '',
757
+ });
758
+ }
613
759
  const requestId = this.generateRequestId(scope, selectorName, inputData);
614
760
  let subscription = this.subscriptions[requestId];
615
761
  if (!subscription) {
@@ -633,7 +779,7 @@ class FlowStateService {
633
779
  this.executeRequest$(request).subscribe();
634
780
  }
635
781
  }
636
- return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), finalize(() => {
782
+ return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map(data => data), finalize(() => {
637
783
  if (!this.subscriptions[requestId]?.data$.observed) {
638
784
  delete this.subscriptions[requestId];
639
785
  }
@@ -642,7 +788,7 @@ class FlowStateService {
642
788
  save$() {
643
789
  if (this.getFlowSafe().properties.stateful) {
644
790
  if (this.stateId$.value) {
645
- return this.flowStateApiService.save(this.stateId$.value).pipe(tap$1(() => {
791
+ return this.flowStateApiService.save(this.stateId$.value).pipe(tap(() => {
646
792
  Array.from(this.trackedStatefulChangesMap.keys()).forEach(key => {
647
793
  this.trackedStatefulChangesMap.set(key, false);
648
794
  });
@@ -652,8 +798,8 @@ class FlowStateService {
652
798
  else {
653
799
  const quoteDraft = this.quoteDraftService.quoteDraft;
654
800
  if (quoteDraft) {
655
- return this.quoteApiService.upsertQuote(quoteDraft).pipe(tap$1(({ configurationId }) => {
656
- this.contextService.update({ properties: { ConfigurationId: configurationId } });
801
+ return this.quoteApiService.upsertQuote(quoteDraft).pipe(tap(({ versionId }) => {
802
+ this.contextService.update({ properties: { VELOCPQ__VersionId__c: versionId } });
657
803
  }));
658
804
  }
659
805
  }
@@ -668,8 +814,8 @@ class FlowStateService {
668
814
  else {
669
815
  const quoteDraft = this.quoteDraftService.quoteDraft;
670
816
  if (quoteDraft) {
671
- return this.quoteApiService.submitQuote(quoteDraft).pipe(tap$1(({ configurationId }) => {
672
- this.contextService.update({ properties: { ConfigurationId: configurationId } });
817
+ return this.quoteApiService.submitQuote(quoteDraft).pipe(tap(({ versionId }) => {
818
+ this.contextService.update({ properties: { VELOCPQ__VersionId__c: versionId } });
673
819
  }));
674
820
  }
675
821
  }
@@ -714,7 +860,7 @@ class FlowStateService {
714
860
  const execution$ = this.getFlowSafe().properties.stateful
715
861
  ? this.executeStateful$(fullRequest)
716
862
  : this.executeStateless$(fullRequest);
717
- return execution$.pipe(tap$1(result => this.handleSelectorsResponse(result.selectors)));
863
+ return execution$.pipe(tap(result => this.handleSelectorsResponse(result.selectors)));
718
864
  }
719
865
  handleSelectorsResponse(selectors) {
720
866
  Object.entries(selectors).forEach(([requestId, selectorResult]) => {
@@ -731,7 +877,7 @@ class FlowStateService {
731
877
  initStateful$() {
732
878
  // Subscriptions
733
879
  this.subscribe$(UITemplateType.FLOW_ENGINE, 'CONTEXT', null, { cold: true })
734
- .pipe(tap$1(response => {
880
+ .pipe(tap(response => {
735
881
  if (response.success) {
736
882
  this.contextService.update(response.result);
737
883
  }
@@ -753,13 +899,13 @@ class FlowStateService {
753
899
  selectors: { ...selectors, ...request.selectors },
754
900
  actions: request.actions,
755
901
  })
756
- .pipe(map$1(({ stateId, selectors }) => {
902
+ .pipe(map(({ stateId, selectors }) => {
757
903
  this.handleSelectorsResponse(selectors);
758
904
  this.stateId$.next(stateId);
759
905
  }));
760
906
  }
761
907
  initBufferedRequest$() {
762
- return this.statefulRequestStream$.pipe(buffer(this.statefulRequestStream$.pipe(debounceTime(this.EXECUTION_BUFFER_TIME))), switchMap(requests => {
908
+ return this.statefulRequestStream$.pipe(buffer(this.statefulRequestStream$.pipe(debounceTime(this.EXECUTION_BUFFER_TIME))), switchMap$1(requests => {
763
909
  if (!this.stateId$.value) {
764
910
  throw 'Stateful session is not initialized';
765
911
  }
@@ -773,32 +919,32 @@ class FlowStateService {
773
919
  };
774
920
  this.executionInProgress$.next(true);
775
921
  return this.flowStateApiService.execute(this.stateId$.value, request);
776
- }), tap$1(({ stateId }) => this.stateId$.next(stateId)), share(), tap$1(() => this.executionInProgress$.next(false)), catchError(e => {
922
+ }), tap(({ stateId }) => this.stateId$.next(stateId)), share(), tap(() => this.executionInProgress$.next(false)), catchError(e => {
777
923
  this.executionInProgress$.next(false);
778
924
  return throwError(() => e);
779
925
  }));
780
926
  }
781
927
  executeStateful$(request) {
782
- return this.executionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap(() =>
928
+ return this.executionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap$1(() =>
783
929
  // make sure stream switches to statefulExecutionRequest$ before pushing an execution request
784
930
  combineLatest([
785
931
  this.statefulExecutionRequest$,
786
- of(undefined).pipe(tap$1(() => this.statefulRequestStream$.next(request))),
787
- ])), map$1(([response]) => response), take$1(1));
932
+ of(undefined).pipe(tap(() => this.statefulRequestStream$.next(request))),
933
+ ])), map(([response]) => response), take$1(1));
788
934
  }
789
935
  initStateless$() {
790
936
  const { headerId } = this.contextService.resolve();
791
- return this.quoteDraftService.init(headerId, this.flowInfoService.params ?? {}).pipe(tap$1(() => {
937
+ return this.quoteDraftService.init(headerId, this.flowInfoService.params ?? {}).pipe(tap(() => {
792
938
  const assets = this.quoteDraftService.assetsState;
793
939
  if (assets) {
794
940
  this.flowStore = { ...this.flowStore, assets };
795
941
  }
796
- }), switchMap(() => {
942
+ }), switchMap$1(() => {
797
943
  if (this.flowInfoService.isLegacy) {
798
944
  return of(null);
799
945
  }
800
946
  return this.executeRequest$(this.getDefaultExecutionRequestDTO());
801
- }), switchMap(() => this.calculate$()), tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
947
+ }), switchMap$1(() => this.calculate$()), tap(() => this.quoteDraftService.finalizeInit()), map(noop));
802
948
  }
803
949
  calculate$() {
804
950
  const flowState = this.quoteDraftService.quoteDraft;
@@ -821,7 +967,7 @@ class FlowStateService {
821
967
  }
822
968
  executeStateless$(request) {
823
969
  this.executionInProgress$.next(true);
824
- return of(undefined).pipe(tap$1(() => this.executeStatelessActions(request)), switchMap(() => {
970
+ return of(undefined).pipe(tap(() => this.executeStatelessActions(request)), switchMap$1(() => {
825
971
  /*
826
972
  Skip price calculation in case
827
973
  1. No actions in the request
@@ -833,7 +979,7 @@ class FlowStateService {
833
979
  else {
834
980
  return this.calculate$();
835
981
  }
836
- }), map$1(() => this.executeStatelessSelectors(request)), tap$1(() => this.executionInProgress$.next(false)), catchError(e => {
982
+ }), map(() => this.executeStatelessSelectors(request)), tap(() => this.executionInProgress$.next(false)), catchError(e => {
837
983
  this.executionInProgress$.next(false);
838
984
  return throwError(() => e);
839
985
  }));
@@ -896,7 +1042,7 @@ class FlowStateService {
896
1042
  return;
897
1043
  }
898
1044
  const localProcessors$ = this.customizationService?.getTemplateConfigurationProcessors?.(template.name) ?? of(null);
899
- return localProcessors$.pipe(switchMap(processors => processors ? of(processors) : this.processorsApiService.fetchConfigurationProcessors$(template.id)), tap$1(processors => {
1045
+ return localProcessors$.pipe(switchMap$1(processors => processors ? of(processors) : this.processorsApiService.fetchConfigurationProcessors$(template.id)), tap(processors => {
900
1046
  const processorsMap = processors.reduce((acc, p) => {
901
1047
  acc[p.apiName] = p;
902
1048
  return acc;
@@ -908,7 +1054,7 @@ class FlowStateService {
908
1054
  if (!owners$.length) {
909
1055
  return of(undefined);
910
1056
  }
911
- return forkJoin(owners$).pipe(map$1(noop));
1057
+ return forkJoin(owners$).pipe(map(noop));
912
1058
  }
913
1059
  executeActionScript(request, executable) {
914
1060
  const configurationProcessor = this.processors[executable.ownerId]?.[executable.apiName];
@@ -1191,111 +1337,6 @@ var lineItem_utils = /*#__PURE__*/Object.freeze({
1191
1337
  upsertAttributes: upsertAttributes
1192
1338
  });
1193
1339
 
1194
- class RuntimeSettingsService {
1195
- constructor(configurationSettingsApiService) {
1196
- this.configurationSettingsApiService = configurationSettingsApiService;
1197
- this.configurationSettings$ = new BehaviorSubject({});
1198
- this.currencySettings$ = new BehaviorSubject({
1199
- iso: DEFAULT_CURRENCY_ISO_CODE,
1200
- symbol: DEFAULT_CURRENCY_SYMBOL,
1201
- });
1202
- this.shoppingCartSettings$ = new BehaviorSubject([]);
1203
- this.getCurrencySymbol = (locale, currency) => {
1204
- return (0)
1205
- .toLocaleString(locale, { style: 'currency', currency, minimumFractionDigits: 0, maximumFractionDigits: 0 })
1206
- .replace(/\d/g, '')
1207
- .trim();
1208
- };
1209
- }
1210
- create() {
1211
- return this.configurationSettingsApiService.fetchSettings().pipe(map$1(settings => this.parseConfigurationSettings(settings)), tap$1(configurationSettings => {
1212
- this.configurationSettings$.next(configurationSettings);
1213
- this.addShoppingCartSettings(configurationSettings['shopping-cart'] ?? []);
1214
- this.formattingSettings = this.getFormattingSettings();
1215
- }), map$1(() => undefined));
1216
- }
1217
- initCurrency(iso) {
1218
- if (iso) {
1219
- const symbol = this.getCurrencySymbol('en-US', iso);
1220
- this.currencySettings$.next({ iso, symbol });
1221
- if (this.formattingSettings) {
1222
- this.formattingSettings.currencySymbol = symbol;
1223
- }
1224
- }
1225
- }
1226
- getFormattingSettings() {
1227
- if (this.formattingSettings) {
1228
- return this.formattingSettings;
1229
- }
1230
- const shoppingCartSettings = this.getConfigurationSettings()['shopping-cart']?.reduce((acc, setting) => {
1231
- return { ...acc, [setting.id]: setting.properties };
1232
- }, {});
1233
- const currencySettings = this.getCurrencySettings();
1234
- const dateFormat = (validateDateFormat(shoppingCartSettings?.DATE_FORMAT ?? '') && shoppingCartSettings?.DATE_FORMAT) ||
1235
- DEFAULT_DATE_FORMAT;
1236
- const decimalSeparator = shoppingCartSettings?.DECIMAL_SEPARATOR;
1237
- const thousandsSeparator = shoppingCartSettings?.THOUSANDS_SEPARATOR;
1238
- // the number of decimal places can be 0
1239
- const priceScale = shoppingCartSettings?.PRICE_SCALE;
1240
- const decimalsCount = priceScale !== null && priceScale !== '' && !isNaN(Number(priceScale)) && Number(priceScale) >= 0
1241
- ? Number(priceScale)
1242
- : DEFAULT_DECIMALS_COUNT;
1243
- const actionCodeSettings = shoppingCartSettings?.STATUS_LABEL;
1244
- return {
1245
- currencySymbol: currencySettings.symbol,
1246
- dateFormats: getSupportedDateFormats(dateFormat),
1247
- decimalsCount,
1248
- decimalSeparator: decimalSeparator !== undefined && ['.', ','].includes(decimalSeparator)
1249
- ? decimalSeparator
1250
- : DEFAULT_DECIMAL_SEPARATOR,
1251
- // thousands separator can be a blank value, so it can also be null
1252
- thousandsSeparator: thousandsSeparator !== undefined && ['.', ',', '', null].includes(thousandsSeparator)
1253
- ? thousandsSeparator || ''
1254
- : DEFAULT_THOUSANDS_SEPARATOR,
1255
- actionCodeLabels: actionCodeSettings?.length
1256
- ? actionCodeSettings.reduce((result, setting) => ({ ...result, [setting.status_label]: setting.custom_label }), {})
1257
- : DEFAULT_ACTION_CODE_LABELS,
1258
- };
1259
- }
1260
- getConfigurationSettings() {
1261
- return this.configurationSettings$.value;
1262
- }
1263
- getShoppingCartSettings() {
1264
- return this.shoppingCartSettings$.value;
1265
- }
1266
- getCurrencySettings() {
1267
- return this.currencySettings$.value;
1268
- }
1269
- parseConfigurationSettings(settings) {
1270
- return settings.reduce((acc, setting) => {
1271
- switch (setting.key) {
1272
- case 'shopping-cart':
1273
- acc['shopping-cart'] = parseJsonSafely(setting.value, []);
1274
- break;
1275
- case 'navigation':
1276
- acc.navigation = parseJsonSafely(setting.value, {});
1277
- break;
1278
- case 'flows':
1279
- acc.flows = parseJsonSafely(setting.value, []);
1280
- break;
1281
- default:
1282
- acc[setting.key] = setting.value;
1283
- }
1284
- return acc;
1285
- }, {});
1286
- }
1287
- addShoppingCartSettings(settings) {
1288
- // uniqBy removes items with the biggest index
1289
- const newSettings = uniqBy([...settings, ...this.shoppingCartSettings$.value], 'id');
1290
- this.shoppingCartSettings$.next(newSettings);
1291
- }
1292
- }
1293
- RuntimeSettingsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService, deps: [{ token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1294
- RuntimeSettingsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService });
1295
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService, decorators: [{
1296
- type: Injectable
1297
- }], ctorParameters: function () { return [{ type: i1.ConfigurationSettingsApiService }]; } });
1298
-
1299
1340
  class LineItemWorker {
1300
1341
  constructor(src) {
1301
1342
  this.li = { ...src };
@@ -1333,6 +1374,7 @@ class ConfigurationService {
1333
1374
  this.runtimeSettings = runtimeSettings;
1334
1375
  this.mode = ConfigurationMode.SEARCH;
1335
1376
  this.configurationState = new BehaviorSubject(null);
1377
+ this.previousConfigurationState = new BehaviorSubject(null);
1336
1378
  this.isLoadingSubj$ = new BehaviorSubject(false);
1337
1379
  this.isLoading$ = this.isLoadingSubj$.asObservable();
1338
1380
  this.hasUnsavedChanges = false;
@@ -1342,6 +1384,7 @@ class ConfigurationService {
1342
1384
  this.runtimeService.reset();
1343
1385
  this.configurableRamp = undefined;
1344
1386
  this.configurationState.next(null);
1387
+ this.previousConfigurationState.next(null);
1345
1388
  }
1346
1389
  patch$(lineItem, options) {
1347
1390
  const source = this.getSnapshot();
@@ -1359,7 +1402,7 @@ class ConfigurationService {
1359
1402
  const prevState = this.configurationState.value;
1360
1403
  this.configurationState.next(prevState ? { ...prevState } : null);
1361
1404
  return throwError(() => error);
1362
- }), tap(() => {
1405
+ }), tap$1(() => {
1363
1406
  if (!this.hasUnsavedChanges) {
1364
1407
  this.hasUnsavedChanges = true;
1365
1408
  }
@@ -1372,7 +1415,7 @@ class ConfigurationService {
1372
1415
  this.configurableRamp = lineItem;
1373
1416
  }
1374
1417
  get() {
1375
- return this.configurationState.pipe(map(state => state?.lineItem), shareReplay$1());
1418
+ return this.configurationState.pipe(map$1(state => state?.lineItem), shareReplay$1());
1376
1419
  }
1377
1420
  getSnapshot() {
1378
1421
  return this.configurationState.value?.lineItem ? { ...this.configurationState.value?.lineItem } : undefined;
@@ -1397,6 +1440,9 @@ class ConfigurationService {
1397
1440
  get stateSnapshot() {
1398
1441
  return this.configurationState.value;
1399
1442
  }
1443
+ get previousStateSnapshot() {
1444
+ return this.previousConfigurationState.value;
1445
+ }
1400
1446
  get contextSnapshot() {
1401
1447
  return this.contextService.resolve();
1402
1448
  }
@@ -1404,19 +1450,19 @@ class ConfigurationService {
1404
1450
  return this.contextService.resolve$();
1405
1451
  }
1406
1452
  get charges$() {
1407
- return this.configurationState.pipe(map(state => state?.charges ?? {}));
1453
+ return this.configurationState.pipe(map$1(state => state?.charges ?? {}));
1408
1454
  }
1409
1455
  get chargesSnapshot() {
1410
1456
  return this.configurationState.value?.charges ?? {};
1411
1457
  }
1412
1458
  get pricePlans$() {
1413
- return this.configurationState.pipe(map(state => state?.pricePlans ?? {}));
1459
+ return this.configurationState.pipe(map$1(state => state?.pricePlans ?? {}));
1414
1460
  }
1415
1461
  get pricePlansSnapshot() {
1416
1462
  return this.configurationState.value?.pricePlans ?? {};
1417
1463
  }
1418
1464
  get procedureContext$() {
1419
- return this.configurationState.pipe(map(state => state?.procedureContext ?? {}));
1465
+ return this.configurationState.pipe(map$1(state => state?.procedureContext ?? {}));
1420
1466
  }
1421
1467
  get procedureContextSnapshot() {
1422
1468
  return this.configurationState.value?.procedureContext ?? {};
@@ -1430,7 +1476,7 @@ class ConfigurationService {
1430
1476
  const uiDefinitionProperties = this.getUIDefinitionProperties();
1431
1477
  const mainPricingEnabled = runtimeContext.properties?.PricingEnabled;
1432
1478
  const pricingEnabled = mainPricingEnabled ? mainPricingEnabled === 'true' : uiDefinitionProperties.pricingEnabled;
1433
- const customPriceApi = this.runtimeSettings.getConfigurationSettings()['CUSTOM_PRICE_API'];
1479
+ const customPriceApi = this.runtimeSettings.configurationSettings['CUSTOM_PRICE_API'];
1434
1480
  this.isLoadingSubj$.next(true);
1435
1481
  const configure$ = pricingEnabled && customPriceApi
1436
1482
  ? this.configurationApiService.customConfigurePrice({ url: customPriceApi, configurationRequest, runtimeModel })
@@ -1439,14 +1485,20 @@ class ConfigurationService {
1439
1485
  runtimeModel,
1440
1486
  pricingEnabled,
1441
1487
  });
1442
- return configure$.pipe(tap(result => {
1488
+ return configure$.pipe(tap$1(result => {
1443
1489
  this.contextService.update(result.context);
1444
1490
  this.configurationState.next(result);
1491
+ this.previousConfigurationState.next(cloneDeep(result));
1445
1492
  if (result.deletedLineItems?.length) {
1446
1493
  this.showInactiveProductsConfirmation();
1447
1494
  }
1448
1495
  this.configurableRamp = result.lineItem;
1449
- }), map(({ lineItem }) => lineItem), catchError$1(error => throwError(() => {
1496
+ }), map$1(({ lineItem }) => lineItem), catchError$1(error => throwError(() => {
1497
+ const resetState = this.previousConfigurationState.value;
1498
+ if (resetState) {
1499
+ this.previousConfigurationState.next(cloneDeep(resetState));
1500
+ this.configurationState.next(resetState);
1501
+ }
1450
1502
  if (error.error) {
1451
1503
  return extractErrorDetails(error.error).join('. ');
1452
1504
  }
@@ -1456,7 +1508,7 @@ class ConfigurationService {
1456
1508
  configureExternal$(props) {
1457
1509
  return this.runtimeService
1458
1510
  .init({ productId: props.productId, defaultQty: props.qty, attributesMap: props.attributesMap })
1459
- .pipe(switchMap$1(() => this.configure()), first(), catchError$1(error => {
1511
+ .pipe(switchMap(() => this.configure()), first(), catchError$1(error => {
1460
1512
  this.messageService.add({ severity: ToastType.error, summary: error });
1461
1513
  throw error;
1462
1514
  }), finalize$1(() => this.reset()));
@@ -1492,7 +1544,7 @@ class ConfigurationService {
1492
1544
  generateLineItem() {
1493
1545
  const runtimeContext = this.getRuntimeContext();
1494
1546
  const uiDefinitionProperties = this.getUIDefinitionProperties();
1495
- let lineItem = cloneDeep(this.configurableRamp);
1547
+ let lineItem = this.configurableRamp;
1496
1548
  if (!lineItem) {
1497
1549
  const { initializationProps } = this.runtimeService ?? {};
1498
1550
  lineItem = getDefaultLineItem(runtimeContext, uiDefinitionProperties, initializationProps?.defaultQty);
@@ -1682,24 +1734,25 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1682
1734
  }] });
1683
1735
 
1684
1736
  class FlowConfigurationService {
1685
- constructor(proceduresApiService, contextService, quoteDraftService, updateService, configurationService) {
1737
+ constructor(proceduresApiService, contextService, quoteDraftService, updateService, configurationService, flowInfoService) {
1686
1738
  this.proceduresApiService = proceduresApiService;
1687
1739
  this.contextService = contextService;
1688
1740
  this.quoteDraftService = quoteDraftService;
1689
1741
  this.updateService = updateService;
1690
1742
  this.configurationService = configurationService;
1743
+ this.flowInfoService = flowInfoService;
1691
1744
  this.updatedSubj$ = new Subject();
1692
1745
  this.updated$ = this.updatedSubj$.asObservable();
1693
1746
  }
1694
1747
  calculate$(quoteDraft) {
1695
- return this.proceduresApiService.apply$(quoteDraft).pipe(tap$1(result => {
1748
+ return this.extendedApply$(quoteDraft).pipe(tap(result => {
1696
1749
  // sort the result current state based on the quote draft initial state
1697
1750
  const initialStateIds = quoteDraft.initialState.map(lineItem => lineItem.integrationId);
1698
1751
  result.currentState = result.currentState
1699
1752
  .slice()
1700
1753
  .sort((a, b) => initialStateIds.indexOf(a.integrationId) - initialStateIds.indexOf(b.integrationId));
1701
1754
  this.quoteDraftService.updateQuoteDraft(result);
1702
- }), map$1(noop));
1755
+ }), map(noop));
1703
1756
  }
1704
1757
  calculate(quoteDraft) {
1705
1758
  this.calculate$(quoteDraft).subscribe();
@@ -1709,11 +1762,11 @@ class FlowConfigurationService {
1709
1762
  if (!quoteDraft) {
1710
1763
  return of(null);
1711
1764
  }
1712
- return of([]).pipe(map$1(() => {
1765
+ return of([]).pipe(map(() => {
1713
1766
  const updatedState = cloneDeep(quoteDraft.currentState);
1714
1767
  this.updateService.update(updatedState, updates, quoteDraft.charges);
1715
1768
  return updatedState;
1716
- }), switchMap(updatedState => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1769
+ }), switchMap$1(updatedState => this.calculate$({ ...quoteDraft, currentState: updatedState })), map(() => this.quoteDraftService.quoteDraft), tap(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1717
1770
  }
1718
1771
  update(updates) {
1719
1772
  this.update$(updates).subscribe();
@@ -1730,9 +1783,9 @@ class FlowConfigurationService {
1730
1783
  }
1731
1784
  const updatedState = cloneDeep(currentState);
1732
1785
  updatedState.splice(currentLineItemIndex, 1, initialLineItem);
1733
- return of([]).pipe(tap$1(() => {
1786
+ return of([]).pipe(tap(() => {
1734
1787
  this.quoteDraftService.setCurrentLineItemState(updatedState);
1735
- }), switchMap(() => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1788
+ }), switchMap$1(() => this.calculate$({ ...quoteDraft, currentState: updatedState })), map(() => this.quoteDraftService.quoteDraft), tap(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1736
1789
  }
1737
1790
  revert(lineItemId) {
1738
1791
  this.revert$(lineItemId).subscribe();
@@ -1743,7 +1796,7 @@ class FlowConfigurationService {
1743
1796
  if (!quoteDraft) {
1744
1797
  return of(null);
1745
1798
  }
1746
- return of([]).pipe(map$1(() => ids.reduce((result, id) => this.updateService.delete(result, id), currentState)), switchMap(updatedState => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1799
+ return of([]).pipe(map(() => ids.reduce((result, id) => this.updateService.delete(result, id), currentState)), switchMap$1(updatedState => this.calculate$({ ...quoteDraft, currentState: updatedState })), map(() => this.quoteDraftService.quoteDraft), tap(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1747
1800
  }
1748
1801
  delete(ids) {
1749
1802
  this.delete$(ids).subscribe();
@@ -1754,34 +1807,34 @@ class FlowConfigurationService {
1754
1807
  return of(null);
1755
1808
  }
1756
1809
  const updatedState = [...quoteDraft.currentState, term];
1757
- return of([]).pipe(switchMap(() => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1810
+ return of([]).pipe(switchMap$1(() => this.calculate$({ ...quoteDraft, currentState: updatedState })), map(() => this.quoteDraftService.quoteDraft), tap(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1758
1811
  }
1759
1812
  addToCart$(props) {
1760
1813
  const quoteDraft = this.quoteDraftService.quoteDraft;
1761
1814
  if (!quoteDraft) {
1762
1815
  return of(null);
1763
1816
  }
1764
- return this.configurationService.configureExternal$(props).pipe(map$1(lineItem => {
1817
+ return this.configurationService.configureExternal$(props).pipe(map(lineItem => {
1765
1818
  const model = this.configurationService.getRuntimeModel();
1766
1819
  const split = model?.types.find(type => type.name === lineItem.type)?.split ?? false;
1767
1820
  const lineItems = multiplyLineItems(lineItem, props.qty ?? 1, split);
1768
1821
  return [...quoteDraft.currentState, ...lineItems];
1769
- }), switchMap(updatedState => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1822
+ }), switchMap$1(updatedState => this.calculate$({ ...quoteDraft, currentState: updatedState })), map(() => this.quoteDraftService.quoteDraft), tap(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1770
1823
  }
1771
1824
  get() {
1772
- return this.quoteDraftService.quoteDraft$.pipe(map$1(() => this.quoteDraftService.currentState), shareReplay$1());
1825
+ return this.quoteDraftService.quoteDraft$.pipe(map(() => this.quoteDraftService.currentState), shareReplay$1());
1773
1826
  }
1774
1827
  getSnapshot() {
1775
1828
  return this.quoteDraftService?.currentState.slice() ?? [];
1776
1829
  }
1777
1830
  get charges$() {
1778
- return this.quoteDraftService.quoteDraft$.pipe(map$1(({ charges }) => charges));
1831
+ return this.quoteDraftService.quoteDraft$.pipe(map(({ charges }) => charges));
1779
1832
  }
1780
1833
  get pricePlans$() {
1781
- return this.quoteDraftService.quoteDraft$.pipe(map$1(({ pricePlans }) => pricePlans));
1834
+ return this.quoteDraftService.quoteDraft$.pipe(map(({ pricePlans }) => pricePlans));
1782
1835
  }
1783
1836
  get activeMetrics$() {
1784
- return this.quoteDraftService.quoteDraft$.pipe(map$1(({ activeMetrics }) => activeMetrics));
1837
+ return this.quoteDraftService.quoteDraft$.pipe(map(({ activeMetrics }) => activeMetrics));
1785
1838
  }
1786
1839
  get chargesSnapshot() {
1787
1840
  return this.quoteDraftService.quoteDraft?.charges ?? {};
@@ -1812,12 +1865,20 @@ class FlowConfigurationService {
1812
1865
  }));
1813
1866
  };
1814
1867
  }
1868
+ extendedApply$(quoteDraft) {
1869
+ const request = { ...quoteDraft };
1870
+ const procedureName = this.flowInfoService.flow?.properties.procedureName;
1871
+ if (procedureName) {
1872
+ request.procedureName = procedureName;
1873
+ }
1874
+ return this.proceduresApiService.apply$(request);
1875
+ }
1815
1876
  }
1816
- FlowConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationService, deps: [{ token: i1.ProceduresApiService }, { token: ContextService }, { token: QuoteDraftService }, { token: FlowUpdateService }, { token: ConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable });
1877
+ FlowConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationService, deps: [{ token: i1.ProceduresApiService }, { token: ContextService }, { token: QuoteDraftService }, { token: FlowUpdateService }, { token: ConfigurationService }, { token: FlowInfoService }], target: i0.ɵɵFactoryTarget.Injectable });
1817
1878
  FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationService });
1818
1879
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationService, decorators: [{
1819
1880
  type: Injectable
1820
- }], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1881
+ }], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }, { type: FlowInfoService }]; } });
1821
1882
 
1822
1883
  class FlowConfigurationModule {
1823
1884
  }
@@ -1853,18 +1914,18 @@ class FlowStateConfigurationService {
1853
1914
  }
1854
1915
  else {
1855
1916
  const lineItem = generateConfigurationLineItem(props, props.qty);
1856
- request$ = this.flowStateApiService.newConfiguration(stateId, { lineItem }).pipe(tap$1(r => this.configurationStateId$.next(r.stateId)), switchMap(() => {
1917
+ request$ = this.flowStateApiService.newConfiguration(stateId, { lineItem }).pipe(tap(r => this.configurationStateId$.next(r.stateId)), switchMap$1(() => {
1857
1918
  if (!this.configurationStateId) {
1858
1919
  return of();
1859
1920
  }
1860
- return this.flowStateApiService.saveConfiguration(stateId, this.configurationStateId).pipe(tap$1(() => this.configurationStateId$.next(null)), map$1(noop));
1921
+ return this.flowStateApiService.saveConfiguration(stateId, this.configurationStateId).pipe(tap(() => this.configurationStateId$.next(null)), map(noop));
1861
1922
  }));
1862
1923
  }
1863
1924
  }
1864
1925
  else {
1865
- request$ = this.flowConfigurationService.addToCart$(props).pipe(map$1(noop));
1926
+ request$ = this.flowConfigurationService.addToCart$(props).pipe(map(noop));
1866
1927
  }
1867
- return request$.pipe(switchMap(() => this.flowStateService.executeRequest$({}, true)), map$1(noop));
1928
+ return request$.pipe(switchMap$1(() => this.flowStateService.executeRequest$({}, true)), map(noop));
1868
1929
  }
1869
1930
  }
1870
1931
  FlowStateConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, deps: [{ token: FlowInfoService }, { token: FlowConfigurationService }, { token: i1.FlowStateApiService }, { token: FlowStateService }], target: i0.ɵɵFactoryTarget.Injectable });
@@ -1891,7 +1952,7 @@ class IntegrationState {
1891
1952
  this.action$.next(action);
1892
1953
  }
1893
1954
  listen$(actionType) {
1894
- return this.action$.pipe(filter$1(action => action.type === actionType), map$1(action => action.payload));
1955
+ return this.action$.pipe(filter$1(action => action.type === actionType), map(action => action.payload));
1895
1956
  }
1896
1957
  listenAll$() {
1897
1958
  return this.action$.asObservable();
@@ -1916,12 +1977,12 @@ class ProductImagesService {
1916
1977
  this.imagesMap$.next({ ...this.imagesMap$.value, [productId]: '' });
1917
1978
  this.fetchProductImage(productId);
1918
1979
  }
1919
- return this.imagesMap$.pipe(map$1(imagesMap => imagesMap[productId] ?? null), distinctUntilChanged());
1980
+ return this.imagesMap$.pipe(map(imagesMap => imagesMap[productId] ?? null), distinctUntilChanged());
1920
1981
  }
1921
1982
  fetchProductImage(productId) {
1922
1983
  this.productApiService
1923
1984
  .fetchImage$(productId)
1924
- .pipe(map$1(file => URL.createObjectURL(file)), catchError(() => of('')), tap$1(url => this.imagesMap$.next({ ...this.imagesMap$.value, [productId]: url })))
1985
+ .pipe(map(file => URL.createObjectURL(file)), catchError(() => of('')), tap(url => this.imagesMap$.next({ ...this.imagesMap$.value, [productId]: url })))
1925
1986
  .subscribe();
1926
1987
  }
1927
1988
  }
@@ -1936,7 +1997,7 @@ class RuntimeContextService {
1936
1997
  this.configurationApiService = configurationApiService;
1937
1998
  }
1938
1999
  getRuntimeContext(productId, offeringId) {
1939
- return this.configurationApiService.getRuntimeDataByProductId(productId, offeringId).pipe(map(runtimeData => {
2000
+ return this.configurationApiService.getRuntimeDataByProductId(productId, offeringId).pipe(map$1(runtimeData => {
1940
2001
  const uiDefinitionContainer = this.getUIDefinitionContainer(runtimeData);
1941
2002
  const runtimeModel = RuntimeModel.create(runtimeData.types, runtimeData.products);
1942
2003
  const { productName, properties } = Array.from(runtimeModel.components.values()).find(c => c.productId === productId) ?? {};
@@ -1987,7 +2048,7 @@ class ConfigurationRuntimeService {
1987
2048
  return combineLatest([
1988
2049
  this.apiService.getRuntimeDataByModelId(uiDefinitionContainer.modelId),
1989
2050
  this.contextService.initTestMode(),
1990
- ]).pipe(first(), map(([runtimeData, context]) => {
2051
+ ]).pipe(first(), map$1(([runtimeData, context]) => {
1991
2052
  this.contextService.update({
1992
2053
  properties: {
1993
2054
  ...this.runtimeContext?.properties,
@@ -2006,12 +2067,12 @@ class ConfigurationRuntimeService {
2006
2067
  uiDefinitionContainer,
2007
2068
  };
2008
2069
  return this._runtimeContext;
2009
- }), tap(() => (this._isInitialized = true)));
2070
+ }), tap$1(() => (this._isInitialized = true)));
2010
2071
  }
2011
2072
  init(props) {
2012
2073
  this.initializationProps = props;
2013
2074
  const context = this.contextService.resolve();
2014
- return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(tap(runtimeContext => {
2075
+ return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(tap$1(runtimeContext => {
2015
2076
  this.uiDefinitionProperties = runtimeContext.uiDefinitionContainer?.source.properties ?? {};
2016
2077
  const { PriceListId } = context.properties ?? {};
2017
2078
  const mergeContext = {
@@ -2033,7 +2094,7 @@ class ConfigurationRuntimeService {
2033
2094
  });
2034
2095
  }
2035
2096
  return this._runtimeContext;
2036
- }), tap(() => (this._isInitialized = true)));
2097
+ }), tap$1(() => (this._isInitialized = true)));
2037
2098
  }
2038
2099
  overrideUIDefinition(uiDefinitionContainer) {
2039
2100
  if (!this._runtimeContext) {
@@ -2089,6 +2150,7 @@ class ConfigurationStateService {
2089
2150
  this.configurationStore = {};
2090
2151
  this.executionInProgress$ = new BehaviorSubject(false);
2091
2152
  this.statefulRequestStream$ = new Subject();
2153
+ this.statelessExecutionRequest$ = null;
2092
2154
  this.statefulExecutionRequest$ = this.initBufferedRequest$();
2093
2155
  }
2094
2156
  get isExecutionInProgress$() {
@@ -2119,7 +2181,7 @@ class ConfigurationStateService {
2119
2181
  }
2120
2182
  execute$(exec) {
2121
2183
  const request = this.execToRequest(exec);
2122
- return this.executeRequest$(request).pipe(map$1(result => {
2184
+ return this.executeRequest$(request).pipe(map(result => {
2123
2185
  // Keep only requested results
2124
2186
  const actualSelectors = Object.entries(result.selectors).reduce((trunk, [requestId, result]) => {
2125
2187
  if (exec.selectors?.[requestId]) {
@@ -2135,7 +2197,15 @@ class ConfigurationStateService {
2135
2197
  actions: [{ name: actionName, inputData }],
2136
2198
  };
2137
2199
  const request = this.execToRequest(exec);
2138
- return this.executeRequest$(request);
2200
+ const executionRequest$ = this.executeRequest$(request);
2201
+ if (this.isStatefulConfiguration) {
2202
+ return executionRequest$;
2203
+ }
2204
+ // prevent parallel configuration requests in stateless mode
2205
+ if (!this.statelessExecutionRequest$) {
2206
+ this.statelessExecutionRequest$ = executionRequest$.pipe(shareReplay$1(), take$1(1), finalize(() => (this.statelessExecutionRequest$ = null)));
2207
+ }
2208
+ return this.statelessExecutionRequest$;
2139
2209
  }
2140
2210
  select$(selectorName, inputData = {}) {
2141
2211
  const requestId = UUID.UUID();
@@ -2147,7 +2217,7 @@ class ConfigurationStateService {
2147
2217
  },
2148
2218
  },
2149
2219
  });
2150
- return this.executeRequest$(request).pipe(map$1(response => response.selectors[requestId]));
2220
+ return this.executeRequest$(request).pipe(map(response => response.selectors[requestId]));
2151
2221
  }
2152
2222
  subscribe$(selectorName, inputData = {}, options) {
2153
2223
  const requestId = UUID.UUID();
@@ -2170,7 +2240,7 @@ class ConfigurationStateService {
2170
2240
  this.executeRequest$(request).subscribe();
2171
2241
  }
2172
2242
  }
2173
- return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), distinctUntilChanged(), finalize(() => {
2243
+ return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map(data => data), distinctUntilChanged(), finalize(() => {
2174
2244
  if (!this.subscriptions[requestId]?.data$.observed) {
2175
2245
  delete this.subscriptions[requestId];
2176
2246
  }
@@ -2181,7 +2251,7 @@ class ConfigurationStateService {
2181
2251
  if (this.isStatefulConfiguration) {
2182
2252
  return this.flowStateApiService
2183
2253
  .saveConfiguration(this.flowStateService.stateId ?? '', this.stateId ?? '')
2184
- .pipe(switchMap(r => this.flowStateService.executeRequest$({}, true).pipe(map$1(() => r))));
2254
+ .pipe(switchMap$1(r => this.flowStateService.executeRequest$({}, true).pipe(map(() => r))));
2185
2255
  }
2186
2256
  else {
2187
2257
  if (!flow) {
@@ -2218,7 +2288,7 @@ class ConfigurationStateService {
2218
2288
  }
2219
2289
  return this.flowConfigurationService
2220
2290
  .calculate$({ ...quoteDraft, currentState, initialState })
2221
- .pipe(map$1(() => ({ quoteId: '' })));
2291
+ .pipe(map(() => ({ quoteId: '' })));
2222
2292
  }
2223
2293
  }
2224
2294
  }
@@ -2261,13 +2331,13 @@ class ConfigurationStateService {
2261
2331
  selectorsOverride: container?.selectors?.map(processor => ({ ...processor, ownerId: this.ownerId })),
2262
2332
  });
2263
2333
  }
2264
- return request$.pipe(map$1(r => {
2334
+ return request$.pipe(map(r => {
2265
2335
  this.stateId = r.stateId;
2266
2336
  return undefined;
2267
2337
  }));
2268
2338
  }
2269
2339
  initStateless$() {
2270
- return this.configurationService.configure().pipe(map$1(() => undefined));
2340
+ return this.configurationService.configure().pipe(map(() => undefined));
2271
2341
  }
2272
2342
  execToRequest(exec) {
2273
2343
  return {
@@ -2308,46 +2378,35 @@ class ConfigurationStateService {
2308
2378
  else {
2309
2379
  execution$ = this.executeStateless$(fullRequest);
2310
2380
  }
2311
- return execution$.pipe(tap$1(result => this.handleSelectorsResponse(result.selectors)));
2381
+ return execution$.pipe(tap(result => this.handleSelectorsResponse(result.selectors)));
2312
2382
  }
2313
2383
  executeStateless$(request) {
2314
2384
  this.executionInProgress$.next(true);
2315
- return of(undefined).pipe(switchMap(() => {
2385
+ return of(undefined).pipe(switchMap$1(() => {
2316
2386
  // Apply actions and execute configuration/price call
2317
2387
  // No need to run configuration if no actions in the request
2318
2388
  if (!request.actions?.length) {
2319
2389
  return of(undefined);
2320
2390
  }
2321
- let configurationRequest = this.configurationService.generateRequest();
2391
+ let configurationRequest = this.configurationService.generateRequest(false);
2322
2392
  request.actions.forEach(action => {
2323
2393
  configurationRequest = this.executeActionScript(configurationRequest, action) ?? configurationRequest;
2324
2394
  });
2325
2395
  configurationRequest = ConfigurationTranslatorUtils.lightenConfigurationRequest(configurationRequest);
2326
2396
  return this.configurationService.configureRequest$(configurationRequest);
2327
- }), map$1(() => {
2397
+ }), map(() => {
2328
2398
  // Run selectors and apply them to the state
2329
- const configurationState = cloneDeep(this.configurationService.stateSnapshot);
2399
+ const configurationState = this.configurationService.stateSnapshot;
2330
2400
  if (!configurationState) {
2331
2401
  return { stateId: '', selectors: {} };
2332
2402
  }
2333
- const selectorsResult = EntityUtil.entries(request.selectors ?? {}).reduce((result, [key, selector]) => {
2334
- try {
2335
- result.selectors[key] = {
2336
- success: true,
2337
- result: this.executeSelectorScript(configurationState, selector),
2338
- };
2339
- }
2340
- catch (e) {
2341
- console.error(e);
2342
- result.selectors[key] = {
2343
- success: false,
2344
- errorMessage: String(e),
2345
- };
2346
- }
2347
- return result;
2348
- }, { stateId: '', selectors: {} });
2349
- return selectorsResult;
2350
- }), tap$1(() => this.executionInProgress$.next(false)), catchError(error => {
2403
+ return this.runStatelessSelectors(request, configurationState);
2404
+ }), tap(() => this.executionInProgress$.next(false)), catchError(error => {
2405
+ const configurationState = this.configurationService.previousStateSnapshot;
2406
+ if (configurationState) {
2407
+ const selectorsResult = this.runStatelessSelectors(request, configurationState);
2408
+ this.handleSelectorsResponse(selectorsResult.selectors);
2409
+ }
2351
2410
  this.executionInProgress$.next(false);
2352
2411
  if (!this.configurationRuntimeService.uiDefinitionProperties.suppressToastMessages) {
2353
2412
  this.toastService.add({ severity: ToastType.error, summary: String(error) });
@@ -2356,7 +2415,7 @@ class ConfigurationStateService {
2356
2415
  }));
2357
2416
  }
2358
2417
  initBufferedRequest$() {
2359
- return this.statefulRequestStream$.pipe(buffer(this.statefulRequestStream$.pipe(debounceTime(this.EXECUTION_BUFFER_TIME))), switchMap(requests => {
2418
+ return this.statefulRequestStream$.pipe(buffer(this.statefulRequestStream$.pipe(debounceTime(this.EXECUTION_BUFFER_TIME))), switchMap$1(requests => {
2360
2419
  if (!this.flowStateService.stateId || !this.stateId) {
2361
2420
  throw 'Stateful session is not initialized';
2362
2421
  }
@@ -2370,18 +2429,18 @@ class ConfigurationStateService {
2370
2429
  };
2371
2430
  this.executionInProgress$.next(true);
2372
2431
  return this.flowStateApiService.executeConfiguration(this.flowStateService.stateId, this.stateId, request);
2373
- }), tap$1(({ stateId }) => (this.stateId = stateId)), share(), tap$1(() => this.executionInProgress$.next(false)), catchError(e => {
2432
+ }), tap(({ stateId }) => (this.stateId = stateId)), share(), tap(() => this.executionInProgress$.next(false)), catchError(e => {
2374
2433
  this.executionInProgress$.next(false);
2375
2434
  return throwError(() => e);
2376
2435
  }));
2377
2436
  }
2378
2437
  executeStateful$(request) {
2379
- return this.executionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap(() =>
2438
+ return this.executionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap$1(() =>
2380
2439
  // make sure stream switches to statefulExecutionRequest$ before pushing an execution request
2381
2440
  combineLatest([
2382
2441
  this.statefulExecutionRequest$,
2383
- of(undefined).pipe(tap$1(() => this.statefulRequestStream$.next(request))),
2384
- ])), map$1(([response]) => response), take$1(1));
2442
+ of(undefined).pipe(tap(() => this.statefulRequestStream$.next(request))),
2443
+ ])), map(([response]) => response), take$1(1));
2385
2444
  }
2386
2445
  executeActionScript(request, processor) {
2387
2446
  const { actions } = this.configurationRuntimeService.runtimeContext?.uiDefinitionContainer ?? {};
@@ -2414,6 +2473,24 @@ class ConfigurationStateService {
2414
2473
  configurationStore: this.configurationStore,
2415
2474
  });
2416
2475
  }
2476
+ runStatelessSelectors(request, configurationState) {
2477
+ return EntityUtil.entries(request.selectors ?? {}).reduce((result, [key, selector]) => {
2478
+ try {
2479
+ result.selectors[key] = {
2480
+ success: true,
2481
+ result: this.executeSelectorScript(configurationState, selector),
2482
+ };
2483
+ }
2484
+ catch (e) {
2485
+ console.error(e);
2486
+ result.selectors[key] = {
2487
+ success: false,
2488
+ errorMessage: String(e),
2489
+ };
2490
+ }
2491
+ return result;
2492
+ }, { stateId: '', selectors: {} });
2493
+ }
2417
2494
  }
2418
2495
  ConfigurationStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService, deps: [{ token: ConfigurationRuntimeService }, { token: ConfigurationService }, { token: QuoteDraftService }, { token: i6.ToastService }, { token: FlowStateService }, { token: FlowInfoService }, { token: FlowConfigurationService }, { token: i1.FlowStateApiService }, { token: i1.QuoteApiService }], target: i0.ɵɵFactoryTarget.Injectable });
2419
2496
  ConfigurationStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService });