@veloceapps/sdk 8.0.0-185 → 8.0.0-187

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. package/cms/vendor-map.d.ts +3 -4
  2. package/core/modules/configuration/services/configuration-state.service.d.ts +2 -4
  3. package/core/modules/configuration/services/configuration.service.d.ts +1 -1
  4. package/core/services/flow-state.service.d.ts +1 -0
  5. package/core/services/quote-draft.service.d.ts +8 -31
  6. package/core/types/flow-state.types.d.ts +5 -0
  7. package/core/types/integration.types.d.ts +0 -1
  8. package/core/utils/line-item.utils.d.ts +1 -2
  9. package/esm2020/core/modules/configuration/services/configuration-state.service.mjs +16 -7
  10. package/esm2020/core/modules/configuration/services/configuration.service.mjs +10 -8
  11. package/esm2020/core/modules/flow-configuration/services/flow-configuration.service.mjs +3 -3
  12. package/esm2020/core/services/flow-state.service.mjs +31 -25
  13. package/esm2020/core/services/quote-draft.service.mjs +27 -100
  14. package/esm2020/core/types/flow-state.types.mjs +1 -1
  15. package/esm2020/core/types/integration.types.mjs +1 -1
  16. package/esm2020/core/utils/line-item.utils.mjs +4 -18
  17. package/esm2020/src/pages/product/product.component.mjs +15 -12
  18. package/esm2020/src/services/flow.service.mjs +38 -18
  19. package/fesm2015/veloceapps-sdk-core.mjs +455 -522
  20. package/fesm2015/veloceapps-sdk-core.mjs.map +1 -1
  21. package/fesm2015/veloceapps-sdk.mjs +47 -28
  22. package/fesm2015/veloceapps-sdk.mjs.map +1 -1
  23. package/fesm2020/veloceapps-sdk-core.mjs +418 -487
  24. package/fesm2020/veloceapps-sdk-core.mjs.map +1 -1
  25. package/fesm2020/veloceapps-sdk.mjs +50 -27
  26. package/fesm2020/veloceapps-sdk.mjs.map +1 -1
  27. package/package.json +1 -1
  28. package/src/pages/product/product.component.d.ts +1 -1
  29. package/src/services/flow.service.d.ts +1 -0
@@ -755,11 +755,16 @@ class FlowService {
755
755
  initSubscriptions() {
756
756
  this.integrationState
757
757
  .listen$(FlowAction.FLOW_CONFIGURE_PRODUCT)
758
- .pipe(tap(payload => {
759
- const productId = payload.productId ??
760
- this.quoteDraftService.currentState.find(li => li.id === payload.lineItemId)?.productId;
761
- if (productId) {
762
- this.flowRouterService.navigateToProductConfiguration(productId, payload.lineItemId);
758
+ .pipe(switchMap(payload => {
759
+ if (this.flowInfoService.isLegacy) {
760
+ const productId = payload.productId ??
761
+ this.quoteDraftService.currentState.find(li => li.id === payload.lineItemId)?.productId;
762
+ return of({ ...payload, productId });
763
+ }
764
+ return this.prepareConfiguration$(payload);
765
+ }), tap(payload => {
766
+ if (payload.productId) {
767
+ this.flowRouterService.navigateToProductConfiguration(payload.productId, payload.lineItemId);
763
768
  }
764
769
  else {
765
770
  console.warn("Parameter 'productId' is needed to start configuration");
@@ -808,9 +813,9 @@ class FlowService {
808
813
  return this.legacyApplyConfiguration();
809
814
  }
810
815
  else {
811
- return this.configurationStateService.saveConfiguration('', true).pipe(switchMap(() => this.configurationStateService.cancelConfiguration()), switchMap(() => this.flowStateService.dispatch$(UITemplateType.FLOW_ENGINE, 'UPDATE_ASSET_IDS', {
812
- addConfiguringAssetId: true,
813
- })));
816
+ return this.configurationStateService
817
+ .saveConfiguration('', true)
818
+ .pipe(switchMap(() => this.configurationStateService.cancelConfiguration()));
814
819
  }
815
820
  }), tap(() => {
816
821
  this.configurationService.hasUnsavedChanges = false;
@@ -828,6 +833,29 @@ class FlowService {
828
833
  .pipe(map(path => path.queryParams['productId']), takeUntil(this.cleanup$))
829
834
  .subscribe(productId => this.integrationState.patchState({ productId }));
830
835
  }
836
+ prepareConfiguration$(payload) {
837
+ if (!payload.productId && !payload.lineItemId) {
838
+ return of(payload);
839
+ }
840
+ // When reconfiguring asset, PriceList should be updated with priceListId of an asset
841
+ const actions = [
842
+ { name: 'UPDATE_PRICE_LIST', inputData: { lineItemId: payload.lineItemId } },
843
+ ];
844
+ const selectors = {};
845
+ if (!payload.productId) {
846
+ selectors['productIdResult'] = { name: 'FIND_PRODUCT_ID', inputData: { lineItemId: payload.lineItemId } };
847
+ }
848
+ return this.flowStateService.execute$(UITemplateType.FLOW_ENGINE, { actions, selectors }).pipe(map(({ productIdResult }) => {
849
+ if (!productIdResult) {
850
+ return payload;
851
+ }
852
+ const productId = productIdResult.success && typeof productIdResult.result === 'string' ? productIdResult.result : undefined;
853
+ return {
854
+ ...payload,
855
+ productId,
856
+ };
857
+ }));
858
+ }
831
859
  legacyApplyConfiguration() {
832
860
  const quoteDraft = this.quoteDraftService.quoteDraft;
833
861
  const lineItem = this.configurationService.getSnapshot();
@@ -835,7 +863,6 @@ class FlowService {
835
863
  return of(undefined);
836
864
  }
837
865
  const isNewLineItem = quoteDraft.currentState.every(li => li.id !== lineItem.id);
838
- const assetId = lineItem.assetId || lineItem.openOrderLineItemId;
839
866
  let updatedState;
840
867
  if (isNewLineItem) {
841
868
  updatedState = [...quoteDraft.currentState, lineItem];
@@ -843,14 +870,7 @@ class FlowService {
843
870
  else {
844
871
  updatedState = quoteDraft.currentState.map(li => (li.id === lineItem.id ? lineItem : li));
845
872
  }
846
- return this.flowConfigurationService.calculate$({ ...quoteDraft, currentState: updatedState }).pipe(tap(() => {
847
- if (assetId) {
848
- const modifiedAssets = this.integrationState.state.modifiedAssets ?? {};
849
- this.integrationState.patchState({
850
- modifiedAssets: { ...modifiedAssets, [assetId]: true },
851
- });
852
- }
853
- }));
873
+ return this.flowConfigurationService.calculate$({ ...quoteDraft, currentState: updatedState });
854
874
  }
855
875
  }
856
876
  FlowService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowService, deps: [{ token: i5.IntegrationState }, { token: FlowRouterService }, { token: i2.QuoteDraftService }, { token: i2.ConfigurationService }, { token: i2.ConfigurationStateService }, { token: FlowDialogService }, { token: i2.FlowConfigurationService }, { token: i2.FlowInfoService }, { token: i2.FlowStateService }], target: i0.ɵɵFactoryTarget.Injectable });
@@ -1483,12 +1503,11 @@ class ProductComponent {
1483
1503
  const offeringId = contextProperties.offeringId;
1484
1504
  return this.configurationRuntimeService.init({ productId, offeringId });
1485
1505
  }
1486
- const lineItemId = this.getLineItemId(quote, productId, contextProperties.lineItemId);
1487
- const currentStateItem = quote.currentState.find(({ id }) => id === lineItemId);
1488
- if (currentStateItem) {
1489
- this.configurationService.setConfigurableRamp(currentStateItem);
1506
+ const lineItem = this.getLineItem(quote, productId, contextProperties.lineItemId);
1507
+ if (lineItem) {
1508
+ this.configurationService.setConfigurableRamp(lineItem);
1490
1509
  }
1491
- const { offeringId } = currentStateItem ?? {};
1510
+ const { offeringId } = lineItem ?? {};
1492
1511
  return this.configurationRuntimeService.init({ productId, offeringId });
1493
1512
  }), switchMap(() => this.customizeUI$()), tap(() => {
1494
1513
  const uiDefinition = this.configurationRuntimeService.runtimeContext?.uiDefinitionContainer?.source;
@@ -1505,13 +1524,17 @@ class ProductComponent {
1505
1524
  }
1506
1525
  }), switchMap(() => this.configurationStateService.init$()));
1507
1526
  }
1508
- getLineItemId(quote, productId, lineItemId) {
1527
+ getLineItem(quote, productId, lineItemId) {
1509
1528
  // search by lineItemId first
1510
- let id = quote.currentState.find(li => li.id === lineItemId)?.id;
1511
- if (!id && this.quoteDraftService.isStandalone) {
1512
- id = quote.currentState.find(li => li.productId === productId)?.id;
1529
+ let li = quote.currentState.find(li => li.id === lineItemId);
1530
+ if (!li && this.quoteDraftService.isStandalone) {
1531
+ li = quote.currentState.find(li => li.productId === productId);
1532
+ }
1533
+ // If still not found, is could be an asset
1534
+ if (!li) {
1535
+ li = this.quoteDraftService.assetsState?.currentState.find(li => li.id === lineItemId);
1513
1536
  }
1514
- return id;
1537
+ return li;
1515
1538
  }
1516
1539
  }
1517
1540
  ProductComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductComponent, deps: [{ token: i2.ContextService }, { token: i2.ConfigurationRuntimeService }, { token: i2.ConfigurationService }, { token: i2.ConfigurationStateService }, { token: i2.QuoteDraftService }, { token: i2.FlowInfoService }, { token: i2.FlowStateService }, { token: i2.IntegrationState }, { token: FLOW_CUSTOMIZATION, optional: true }], target: i0.ɵɵFactoryTarget.Component });