@veloceapps/sdk 8.0.0-170 → 8.0.0-172

Sign up to get free protection for your applications and to get access to all the features.
@@ -1404,10 +1404,7 @@ class ConfigurationService {
1404
1404
  this.dialogService = dialogService;
1405
1405
  this.runtimeSettings = runtimeSettings;
1406
1406
  this.mode = ConfigurationMode.SEARCH;
1407
- this.lineItem = new BehaviorSubject(undefined);
1408
- this.charges = new BehaviorSubject({});
1409
- this.pricePlans = new BehaviorSubject({});
1410
- this.procedureContext = new BehaviorSubject({});
1407
+ this.configurationState = new BehaviorSubject(null);
1411
1408
  this.isLoadingSubj$ = new BehaviorSubject(false);
1412
1409
  this.isLoading$ = this.isLoadingSubj$.asObservable();
1413
1410
  this.hasUnsavedChanges = false;
@@ -1416,23 +1413,23 @@ class ConfigurationService {
1416
1413
  this.hasUnsavedChanges = false;
1417
1414
  this.runtimeService.reset();
1418
1415
  this.configurableRamp = undefined;
1419
- this.lineItem.next(undefined);
1420
- this.charges.next({});
1421
- this.pricePlans.next({});
1416
+ this.configurationState.next(null);
1422
1417
  }
1423
1418
  patch$(lineItem, options) {
1424
- if (!this.lineItem.value) {
1419
+ const source = this.getSnapshot();
1420
+ if (!source) {
1425
1421
  return throwError(() => new Error(`Source LineItem not found`));
1426
1422
  }
1427
1423
  const skipCardinalityCalculation = options?.skipCardinalityCalculation || this.contextSnapshot.properties['#skipCardinalityCalculation'] === 'true';
1428
- this.configurableRamp = new LineItemWorker(this.lineItem.value).replace(lineItem, skipCardinalityCalculation).li;
1424
+ this.configurableRamp = new LineItemWorker(source).replace(lineItem, skipCardinalityCalculation).li;
1429
1425
  return this.configure().pipe(catchError$1(error => {
1430
1426
  console.error(error);
1431
1427
  if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
1432
1428
  this.messageService.add({ severity: 'error', summary: error });
1433
1429
  }
1434
1430
  // bounce back if configuration call has failed
1435
- this.lineItem.next(this.lineItem.value ? { ...this.lineItem.value } : undefined);
1431
+ const prevState = this.configurationState.value;
1432
+ this.configurationState.next(prevState ? { ...prevState } : null);
1436
1433
  return throwError(() => error);
1437
1434
  }), tap(() => {
1438
1435
  if (!this.hasUnsavedChanges) {
@@ -1447,10 +1444,10 @@ class ConfigurationService {
1447
1444
  this.configurableRamp = lineItem;
1448
1445
  }
1449
1446
  get() {
1450
- return this.lineItem.asObservable().pipe(shareReplay$1());
1447
+ return this.configurationState.pipe(map(state => state?.lineItem), shareReplay$1());
1451
1448
  }
1452
1449
  getSnapshot() {
1453
- return this.lineItem.value ? { ...this.lineItem.value } : undefined;
1450
+ return this.configurationState.value?.lineItem ? { ...this.configurationState.value?.lineItem } : undefined;
1454
1451
  }
1455
1452
  getRuntimeModel() {
1456
1453
  const runtimeModel = this.runtimeService.runtimeModel;
@@ -1466,6 +1463,12 @@ class ConfigurationService {
1466
1463
  }
1467
1464
  return runtimeContext;
1468
1465
  }
1466
+ get state$() {
1467
+ return this.configurationState.asObservable();
1468
+ }
1469
+ get stateSnapshot() {
1470
+ return this.configurationState.value;
1471
+ }
1469
1472
  get contextSnapshot() {
1470
1473
  return this.contextService.resolve();
1471
1474
  }
@@ -1473,22 +1476,22 @@ class ConfigurationService {
1473
1476
  return this.contextService.resolve$();
1474
1477
  }
1475
1478
  get charges$() {
1476
- return this.charges.asObservable();
1479
+ return this.configurationState.pipe(map(state => state?.charges ?? {}));
1477
1480
  }
1478
1481
  get chargesSnapshot() {
1479
- return this.charges.value;
1482
+ return this.configurationState.value?.charges ?? {};
1480
1483
  }
1481
1484
  get pricePlans$() {
1482
- return this.pricePlans.asObservable();
1485
+ return this.configurationState.pipe(map(state => state?.pricePlans ?? {}));
1483
1486
  }
1484
1487
  get pricePlansSnapshot() {
1485
- return this.pricePlans.value;
1488
+ return this.configurationState.value?.pricePlans ?? {};
1486
1489
  }
1487
1490
  get procedureContext$() {
1488
- return this.procedureContext.asObservable();
1491
+ return this.configurationState.pipe(map(state => state?.procedureContext ?? {}));
1489
1492
  }
1490
1493
  get procedureContextSnapshot() {
1491
- return this.procedureContext.value;
1494
+ return this.configurationState.value?.procedureContext ?? {};
1492
1495
  }
1493
1496
  configure() {
1494
1497
  return this.configureRequest$(this.generateRequest());
@@ -1508,18 +1511,13 @@ class ConfigurationService {
1508
1511
  runtimeModel,
1509
1512
  pricingEnabled,
1510
1513
  });
1511
- return configure$.pipe(tap(({ lineItem, context, charges, pricePlans, deletedLineItems, procedureContext }) => {
1512
- this.contextService.update(context ?? {});
1513
- this.charges.next(charges ?? {});
1514
- this.pricePlans.next(pricePlans ?? {});
1515
- this.procedureContext.next(procedureContext ?? {});
1516
- if (lineItem) {
1517
- this.lineItem.next(lineItem);
1518
- }
1519
- if (deletedLineItems?.length) {
1514
+ return configure$.pipe(tap(result => {
1515
+ this.contextService.update(result.context);
1516
+ this.configurationState.next(result);
1517
+ if (result.deletedLineItems?.length) {
1520
1518
  this.showInactiveProductsConfirmation();
1521
1519
  }
1522
- this.configurableRamp = lineItem;
1520
+ this.configurableRamp = result.lineItem;
1523
1521
  }), map(({ lineItem }) => lineItem), catchError$1(error => throwError(() => new Error(error.error?.message || error.message || JSON.stringify(error)))), finalize$1(() => this.isLoadingSubj$.next(false)));
1524
1522
  }
1525
1523
  configureExternal$(props) {
@@ -1547,7 +1545,7 @@ class ConfigurationService {
1547
1545
  let request = {
1548
1546
  lineItem,
1549
1547
  mode: this.mode,
1550
- step: !this.lineItem.value ? RuntimeStep.START : RuntimeStep.UPDATE,
1548
+ step: !this.configurationState.value?.lineItem ? RuntimeStep.START : RuntimeStep.UPDATE,
1551
1549
  attributeDomainMode: 'ALL',
1552
1550
  context: this.contextService.resolve(),
1553
1551
  lineItems: this.quoteDraftService.quoteDraft?.currentState || [],
@@ -2204,7 +2202,7 @@ class ConfigurationStateService {
2204
2202
  this.execute$(request).subscribe();
2205
2203
  }
2206
2204
  }
2207
- return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), finalize(() => {
2205
+ return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), distinctUntilChanged(), finalize(() => {
2208
2206
  if (!this.subscriptions[requestId]?.data$.observed) {
2209
2207
  delete this.subscriptions[requestId];
2210
2208
  }
@@ -2315,12 +2313,15 @@ class ConfigurationStateService {
2315
2313
  return this.configurationService.configureRequest$(configurationRequest);
2316
2314
  }), map$1(() => {
2317
2315
  // Run selectors and apply them to the state
2318
- const finalConfigurationRequest = this.configurationService.generateRequest(false);
2316
+ const configurationState = cloneDeep(this.configurationService.stateSnapshot);
2317
+ if (!configurationState) {
2318
+ return { stateId: '', selectors: {} };
2319
+ }
2319
2320
  const selectorsResult = EntityUtil.entries(request.selectors ?? {}).reduce((result, [key, selector]) => {
2320
2321
  try {
2321
2322
  result.selectors[key] = {
2322
2323
  success: true,
2323
- result: this.executeSelectorScript(finalConfigurationRequest, selector),
2324
+ result: this.executeSelectorScript(configurationState, selector),
2324
2325
  };
2325
2326
  }
2326
2327
  catch (e) {