@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.
@@ -1502,10 +1502,7 @@ class ConfigurationService {
1502
1502
  this.dialogService = dialogService;
1503
1503
  this.runtimeSettings = runtimeSettings;
1504
1504
  this.mode = ConfigurationMode.SEARCH;
1505
- this.lineItem = new BehaviorSubject(undefined);
1506
- this.charges = new BehaviorSubject({});
1507
- this.pricePlans = new BehaviorSubject({});
1508
- this.procedureContext = new BehaviorSubject({});
1505
+ this.configurationState = new BehaviorSubject(null);
1509
1506
  this.isLoadingSubj$ = new BehaviorSubject(false);
1510
1507
  this.isLoading$ = this.isLoadingSubj$.asObservable();
1511
1508
  this.hasUnsavedChanges = false;
@@ -1514,23 +1511,23 @@ class ConfigurationService {
1514
1511
  this.hasUnsavedChanges = false;
1515
1512
  this.runtimeService.reset();
1516
1513
  this.configurableRamp = undefined;
1517
- this.lineItem.next(undefined);
1518
- this.charges.next({});
1519
- this.pricePlans.next({});
1514
+ this.configurationState.next(null);
1520
1515
  }
1521
1516
  patch$(lineItem, options) {
1522
- if (!this.lineItem.value) {
1517
+ const source = this.getSnapshot();
1518
+ if (!source) {
1523
1519
  return throwError(() => new Error(`Source LineItem not found`));
1524
1520
  }
1525
1521
  const skipCardinalityCalculation = (options === null || options === void 0 ? void 0 : options.skipCardinalityCalculation) || this.contextSnapshot.properties['#skipCardinalityCalculation'] === 'true';
1526
- this.configurableRamp = new LineItemWorker(this.lineItem.value).replace(lineItem, skipCardinalityCalculation).li;
1522
+ this.configurableRamp = new LineItemWorker(source).replace(lineItem, skipCardinalityCalculation).li;
1527
1523
  return this.configure().pipe(catchError$1(error => {
1528
1524
  console.error(error);
1529
1525
  if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
1530
1526
  this.messageService.add({ severity: 'error', summary: error });
1531
1527
  }
1532
1528
  // bounce back if configuration call has failed
1533
- this.lineItem.next(this.lineItem.value ? Object.assign({}, this.lineItem.value) : undefined);
1529
+ const prevState = this.configurationState.value;
1530
+ this.configurationState.next(prevState ? Object.assign({}, prevState) : null);
1534
1531
  return throwError(() => error);
1535
1532
  }), tap(() => {
1536
1533
  if (!this.hasUnsavedChanges) {
@@ -1545,10 +1542,11 @@ class ConfigurationService {
1545
1542
  this.configurableRamp = lineItem;
1546
1543
  }
1547
1544
  get() {
1548
- return this.lineItem.asObservable().pipe(shareReplay$1());
1545
+ return this.configurationState.pipe(map(state => state === null || state === void 0 ? void 0 : state.lineItem), shareReplay$1());
1549
1546
  }
1550
1547
  getSnapshot() {
1551
- return this.lineItem.value ? Object.assign({}, this.lineItem.value) : undefined;
1548
+ var _a, _b;
1549
+ return ((_a = this.configurationState.value) === null || _a === void 0 ? void 0 : _a.lineItem) ? Object.assign({}, (_b = this.configurationState.value) === null || _b === void 0 ? void 0 : _b.lineItem) : undefined;
1552
1550
  }
1553
1551
  getRuntimeModel() {
1554
1552
  const runtimeModel = this.runtimeService.runtimeModel;
@@ -1564,6 +1562,12 @@ class ConfigurationService {
1564
1562
  }
1565
1563
  return runtimeContext;
1566
1564
  }
1565
+ get state$() {
1566
+ return this.configurationState.asObservable();
1567
+ }
1568
+ get stateSnapshot() {
1569
+ return this.configurationState.value;
1570
+ }
1567
1571
  get contextSnapshot() {
1568
1572
  return this.contextService.resolve();
1569
1573
  }
@@ -1571,22 +1575,25 @@ class ConfigurationService {
1571
1575
  return this.contextService.resolve$();
1572
1576
  }
1573
1577
  get charges$() {
1574
- return this.charges.asObservable();
1578
+ return this.configurationState.pipe(map(state => { var _a; return (_a = state === null || state === void 0 ? void 0 : state.charges) !== null && _a !== void 0 ? _a : {}; }));
1575
1579
  }
1576
1580
  get chargesSnapshot() {
1577
- return this.charges.value;
1581
+ var _a, _b;
1582
+ return (_b = (_a = this.configurationState.value) === null || _a === void 0 ? void 0 : _a.charges) !== null && _b !== void 0 ? _b : {};
1578
1583
  }
1579
1584
  get pricePlans$() {
1580
- return this.pricePlans.asObservable();
1585
+ return this.configurationState.pipe(map(state => { var _a; return (_a = state === null || state === void 0 ? void 0 : state.pricePlans) !== null && _a !== void 0 ? _a : {}; }));
1581
1586
  }
1582
1587
  get pricePlansSnapshot() {
1583
- return this.pricePlans.value;
1588
+ var _a, _b;
1589
+ return (_b = (_a = this.configurationState.value) === null || _a === void 0 ? void 0 : _a.pricePlans) !== null && _b !== void 0 ? _b : {};
1584
1590
  }
1585
1591
  get procedureContext$() {
1586
- return this.procedureContext.asObservable();
1592
+ return this.configurationState.pipe(map(state => { var _a; return (_a = state === null || state === void 0 ? void 0 : state.procedureContext) !== null && _a !== void 0 ? _a : {}; }));
1587
1593
  }
1588
1594
  get procedureContextSnapshot() {
1589
- return this.procedureContext.value;
1595
+ var _a, _b;
1596
+ return (_b = (_a = this.configurationState.value) === null || _a === void 0 ? void 0 : _a.procedureContext) !== null && _b !== void 0 ? _b : {};
1590
1597
  }
1591
1598
  configure() {
1592
1599
  return this.configureRequest$(this.generateRequest());
@@ -1607,18 +1614,14 @@ class ConfigurationService {
1607
1614
  runtimeModel,
1608
1615
  pricingEnabled,
1609
1616
  });
1610
- return configure$.pipe(tap(({ lineItem, context, charges, pricePlans, deletedLineItems, procedureContext }) => {
1611
- this.contextService.update(context !== null && context !== void 0 ? context : {});
1612
- this.charges.next(charges !== null && charges !== void 0 ? charges : {});
1613
- this.pricePlans.next(pricePlans !== null && pricePlans !== void 0 ? pricePlans : {});
1614
- this.procedureContext.next(procedureContext !== null && procedureContext !== void 0 ? procedureContext : {});
1615
- if (lineItem) {
1616
- this.lineItem.next(lineItem);
1617
- }
1618
- if (deletedLineItems === null || deletedLineItems === void 0 ? void 0 : deletedLineItems.length) {
1617
+ return configure$.pipe(tap(result => {
1618
+ var _a;
1619
+ this.contextService.update(result.context);
1620
+ this.configurationState.next(result);
1621
+ if ((_a = result.deletedLineItems) === null || _a === void 0 ? void 0 : _a.length) {
1619
1622
  this.showInactiveProductsConfirmation();
1620
1623
  }
1621
- this.configurableRamp = lineItem;
1624
+ this.configurableRamp = result.lineItem;
1622
1625
  }), map(({ lineItem }) => lineItem), catchError$1(error => throwError(() => { var _a; return new Error(((_a = error.error) === null || _a === void 0 ? void 0 : _a.message) || error.message || JSON.stringify(error)); })), finalize$1(() => this.isLoadingSubj$.next(false)));
1623
1626
  }
1624
1627
  configureExternal$(props) {
@@ -1642,15 +1645,15 @@ class ConfigurationService {
1642
1645
  }));
1643
1646
  }
1644
1647
  generateRequest(lightMode = true) {
1645
- var _a;
1648
+ var _a, _b;
1646
1649
  const lineItem = this.generateLineItem();
1647
1650
  let request = {
1648
1651
  lineItem,
1649
1652
  mode: this.mode,
1650
- step: !this.lineItem.value ? RuntimeStep.START : RuntimeStep.UPDATE,
1653
+ step: !((_a = this.configurationState.value) === null || _a === void 0 ? void 0 : _a.lineItem) ? RuntimeStep.START : RuntimeStep.UPDATE,
1651
1654
  attributeDomainMode: 'ALL',
1652
1655
  context: this.contextService.resolve(),
1653
- lineItems: ((_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) || [],
1656
+ lineItems: ((_b = this.quoteDraftService.quoteDraft) === null || _b === void 0 ? void 0 : _b.currentState) || [],
1654
1657
  asset: this.getAsset(),
1655
1658
  };
1656
1659
  if (lightMode) {
@@ -2169,7 +2172,7 @@ class ConfigurationStateService {
2169
2172
  this.execute$(request).subscribe();
2170
2173
  }
2171
2174
  }
2172
- return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), finalize(() => {
2175
+ return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), distinctUntilChanged(), finalize(() => {
2173
2176
  var _a;
2174
2177
  if (!((_a = this.subscriptions[requestId]) === null || _a === void 0 ? void 0 : _a.data$.observed)) {
2175
2178
  delete this.subscriptions[requestId];
@@ -2288,12 +2291,15 @@ class ConfigurationStateService {
2288
2291
  }), map$1(() => {
2289
2292
  var _a;
2290
2293
  // Run selectors and apply them to the state
2291
- const finalConfigurationRequest = this.configurationService.generateRequest(false);
2294
+ const configurationState = cloneDeep(this.configurationService.stateSnapshot);
2295
+ if (!configurationState) {
2296
+ return { stateId: '', selectors: {} };
2297
+ }
2292
2298
  const selectorsResult = EntityUtil.entries((_a = request.selectors) !== null && _a !== void 0 ? _a : {}).reduce((result, [key, selector]) => {
2293
2299
  try {
2294
2300
  result.selectors[key] = {
2295
2301
  success: true,
2296
- result: this.executeSelectorScript(finalConfigurationRequest, selector),
2302
+ result: this.executeSelectorScript(configurationState, selector),
2297
2303
  };
2298
2304
  }
2299
2305
  catch (e) {