@veloceapps/sdk 11.0.0-124 → 11.0.0-126

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.
@@ -80,11 +80,57 @@ const replaceTransactionItem = (item, replaceTo) => {
80
80
  }
81
81
  return Object.assign(Object.assign({}, item), { children: item.children.map(ti => replaceTransactionItem(ti, replaceTo)) });
82
82
  };
83
- const generateTransactionItem = (productId) => {
84
- return {
83
+ const generateTransactionItem = (pcm, salesTransactionId) => {
84
+ const defaultSTI = {
85
85
  id: UUID.UUID(),
86
- productId,
86
+ productId: pcm.id,
87
87
  };
88
+ const defaultChildren = pcm.productComponentGroups.reduce((acc, group) => {
89
+ group.components.forEach(component => {
90
+ var _a;
91
+ const { isComponentRequired, isDefaultComponent } = (_a = component.productRelatedComponent) !== null && _a !== void 0 ? _a : {};
92
+ if (isComponentRequired || isDefaultComponent) {
93
+ acc.push(generateTransactionItemFromPCM(component, defaultSTI, salesTransactionId));
94
+ }
95
+ });
96
+ return acc;
97
+ }, []);
98
+ if (!defaultChildren.length) {
99
+ return defaultSTI;
100
+ }
101
+ return Object.assign(Object.assign({}, defaultSTI), { children: defaultChildren });
102
+ };
103
+ const generateTransactionItemFromPCM = (option, parentTi, salesTransactionId) => {
104
+ var _a, _b, _c, _d, _e;
105
+ const childId = UUID.UUID();
106
+ const newItem = {
107
+ id: childId,
108
+ productId: option.id,
109
+ productName: option.name,
110
+ productCode: option.productCode,
111
+ productRelatedComponentId: (_a = option.productRelatedComponent) === null || _a === void 0 ? void 0 : _a.id,
112
+ stiAttributes: [],
113
+ attributes: {
114
+ ParentReference: salesTransactionId,
115
+ ItemPath: option.id,
116
+ SalesTransactionItemSource: childId,
117
+ SalesTransactionItemParent: salesTransactionId,
118
+ ProductSellingModel: (_c = (_b = option.productSellingModelOptions) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.productSellingModel.id,
119
+ },
120
+ parentId: parentTi.id,
121
+ qty: (_e = (_d = option.productRelatedComponent) === null || _d === void 0 ? void 0 : _d.quantity) !== null && _e !== void 0 ? _e : 1,
122
+ };
123
+ newItem.children = option.productComponentGroups.reduce((acc, group) => {
124
+ group.components.forEach(component => {
125
+ var _a, _b;
126
+ if (((_a = component.productRelatedComponent) === null || _a === void 0 ? void 0 : _a.isComponentRequired) ||
127
+ ((_b = component.productRelatedComponent) === null || _b === void 0 ? void 0 : _b.isDefaultComponent)) {
128
+ acc.push(generateTransactionItemFromPCM(component, newItem, salesTransactionId));
129
+ }
130
+ });
131
+ return acc;
132
+ }, []);
133
+ return newItem;
88
134
  };
89
135
 
90
136
  class TransactionItemWorker {
@@ -1045,15 +1091,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1045
1091
  } });
1046
1092
 
1047
1093
  class FlowStateConfigurationService {
1048
- constructor(flowInfoService, flowStateService, configurationService, salesTransactionService, flowConfigurationService) {
1094
+ constructor(flowInfoService, flowStateService, configurationService, salesTransactionService, flowConfigurationService, pcmApiService) {
1049
1095
  this.flowInfoService = flowInfoService;
1050
1096
  this.flowStateService = flowStateService;
1051
1097
  this.configurationService = configurationService;
1052
1098
  this.salesTransactionService = salesTransactionService;
1053
1099
  this.flowConfigurationService = flowConfigurationService;
1100
+ this.pcmApiService = pcmApiService;
1054
1101
  }
1055
1102
  addToCart$(props) {
1056
1103
  var _a;
1104
+ console.log(props);
1057
1105
  let request$;
1058
1106
  const stateful = (_a = this.flowInfoService.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful;
1059
1107
  if (stateful) {
@@ -1072,32 +1120,34 @@ class FlowStateConfigurationService {
1072
1120
  return request$.pipe(switchMap(() => this.flowStateService.executeRequest$({}, true)), map(noop));
1073
1121
  }
1074
1122
  configureExternal$(props) {
1075
- var _a, _b;
1076
- const { state } = this.salesTransactionService;
1077
- if (!state) {
1078
- return of();
1079
- }
1080
- const stateToConfigure = Object.assign(Object.assign({}, state), { salesTransaction: Object.assign(Object.assign({}, state.salesTransaction), { salesTransactionItems: [
1081
- Object.assign(Object.assign({}, generateTransactionItem(props.productId)), { qty: (_a = props.qty) !== null && _a !== void 0 ? _a : 1, stiAttributes: Object.entries((_b = props.attributesMap) !== null && _b !== void 0 ? _b : {}).map(([attributeName, value]) => ({
1082
- attributeName,
1083
- value,
1084
- })) }),
1085
- ] }) });
1086
- return this.configurationService.justConfigureRequest$(stateToConfigure).pipe(switchMap(configurationResult => {
1087
- const state = this.salesTransactionService.state;
1088
- const addedProduct = configurationResult.salesTransaction.salesTransactionItems[0];
1089
- if (!state || !addedProduct) {
1123
+ return this.pcmApiService.fetchPCMByProductId(props.productId).pipe(switchMap(pcm => {
1124
+ var _a, _b, _c;
1125
+ const { state } = this.salesTransactionService;
1126
+ if (!state) {
1090
1127
  return of();
1091
1128
  }
1092
- return this.flowConfigurationService.calculate$(Object.assign(Object.assign({}, state), { salesTransaction: Object.assign(Object.assign({}, state.salesTransaction), { salesTransactionItems: [...state.salesTransaction.salesTransactionItems, addedProduct] }) }));
1129
+ const stateToConfigure = Object.assign(Object.assign({}, state), { salesTransaction: Object.assign(Object.assign({}, state.salesTransaction), { salesTransactionItems: [
1130
+ Object.assign(Object.assign({}, generateTransactionItem(pcm, (_a = this.configurationService.state) === null || _a === void 0 ? void 0 : _a.salesTransaction.id)), { qty: (_b = props.qty) !== null && _b !== void 0 ? _b : 1, stiAttributes: Object.entries((_c = props.attributesMap) !== null && _c !== void 0 ? _c : {}).map(([attributeName, value]) => ({
1131
+ attributeName,
1132
+ value,
1133
+ })) }),
1134
+ ] }) });
1135
+ return this.configurationService.justConfigureRequest$(stateToConfigure).pipe(switchMap(configurationResult => {
1136
+ const state = this.salesTransactionService.state;
1137
+ const addedProduct = configurationResult.salesTransaction.salesTransactionItems[0];
1138
+ if (!state || !addedProduct) {
1139
+ return of();
1140
+ }
1141
+ return this.flowConfigurationService.calculate$(Object.assign(Object.assign({}, state), { salesTransaction: Object.assign(Object.assign({}, state.salesTransaction), { salesTransactionItems: [...state.salesTransaction.salesTransactionItems, addedProduct] }) }));
1142
+ }));
1093
1143
  }));
1094
1144
  }
1095
1145
  }
1096
- FlowStateConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, deps: [{ token: FlowInfoService }, { token: FlowStateService }, { token: ConfigurationService }, { token: SalesTransactionService }, { token: FlowConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable });
1146
+ FlowStateConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, deps: [{ token: FlowInfoService }, { token: FlowStateService }, { token: ConfigurationService }, { token: SalesTransactionService }, { token: FlowConfigurationService }, { token: i1.PCMApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1097
1147
  FlowStateConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService });
1098
1148
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, decorators: [{
1099
1149
  type: Injectable
1100
- }], ctorParameters: function () { return [{ type: FlowInfoService }, { type: FlowStateService }, { type: ConfigurationService }, { type: SalesTransactionService }, { type: FlowConfigurationService }]; } });
1150
+ }], ctorParameters: function () { return [{ type: FlowInfoService }, { type: FlowStateService }, { type: ConfigurationService }, { type: SalesTransactionService }, { type: FlowConfigurationService }, { type: i1.PCMApiService }]; } });
1101
1151
 
1102
1152
  class IntegrationState {
1103
1153
  constructor() {
@@ -1214,7 +1264,7 @@ class ConfigurationService {
1214
1264
  this.previousConfigurationStateSubj$.next(null);
1215
1265
  }
1216
1266
  init$() {
1217
- var _a;
1267
+ var _a, _b;
1218
1268
  const { state } = this.salesTransactionService;
1219
1269
  const { standalone } = this.flowInfoService.flow.properties;
1220
1270
  const { productId, transactionItemId, newProductQty } = this.flowInfoService.context;
@@ -1228,7 +1278,7 @@ class ConfigurationService {
1228
1278
  transactionItem = salesTransactionItems.find(item => item.productId === productId);
1229
1279
  }
1230
1280
  if (!transactionItem) {
1231
- transactionItem = generateTransactionItem(productId);
1281
+ transactionItem = generateTransactionItem(this.getPCMModel(), (_b = this.state) === null || _b === void 0 ? void 0 : _b.salesTransaction.id);
1232
1282
  if (typeof newProductQty === 'number' && newProductQty > 0) {
1233
1283
  transactionItem.qty = newProductQty;
1234
1284
  }
@@ -1299,6 +1349,7 @@ class ConfigurationService {
1299
1349
  })));
1300
1350
  }
1301
1351
  getPCMModel() {
1352
+ console.log('GET PCM');
1302
1353
  const pcmModel = this.configurationRuntimeService.pcmModel;
1303
1354
  if (!pcmModel) {
1304
1355
  throw new Error('PCM model not initialized');
@@ -1313,7 +1364,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1313
1364
  }], ctorParameters: function () { return [{ type: FlowInfoService }, { type: i2.MessageService }, { type: ConfigurationRuntimeService }, { type: SalesTransactionService }, { type: i1.OrchestrationsApiService }, { type: GuidedSellingService }]; } });
1314
1365
 
1315
1366
  class ConfigurationStateService {
1316
- constructor(configurationRuntimeService, configurationService, flowStateService, flowInfoService, flowConfigurationService, flowStateApiService, salesTransactionService, salesTransactionApiService, toastService) {
1367
+ constructor(configurationRuntimeService, configurationService, flowStateService, flowInfoService, flowConfigurationService, flowStateApiService, salesTransactionService, salesTransactionApiService, toastService, pcmApiService) {
1317
1368
  this.configurationRuntimeService = configurationRuntimeService;
1318
1369
  this.configurationService = configurationService;
1319
1370
  this.flowStateService = flowStateService;
@@ -1323,6 +1374,7 @@ class ConfigurationStateService {
1323
1374
  this.salesTransactionService = salesTransactionService;
1324
1375
  this.salesTransactionApiService = salesTransactionApiService;
1325
1376
  this.toastService = toastService;
1377
+ this.pcmApiService = pcmApiService;
1326
1378
  this.isInitialized$ = new BehaviorSubject(false);
1327
1379
  this.canceledConfiguration$ = new Subject();
1328
1380
  this.NOT_INITIALIZED = Symbol();
@@ -1486,7 +1538,7 @@ class ConfigurationStateService {
1486
1538
  return (_b = (_a = this.flowInfoService.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful) !== null && _b !== void 0 ? _b : false;
1487
1539
  }
1488
1540
  initStateful$() {
1489
- var _a, _b, _c, _d, _e, _f;
1541
+ var _a, _b, _c, _d;
1490
1542
  this.ownerId = (_b = (_a = this.configurationRuntimeService.uiDefinitionContainer) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '';
1491
1543
  const { productId, transactionItemId } = this.flowInfoService.context;
1492
1544
  if (!productId || !this.flowStateService.stateId) {
@@ -1495,17 +1547,20 @@ class ConfigurationStateService {
1495
1547
  const container = this.configurationRuntimeService.uiDefinitionContainer;
1496
1548
  let request$;
1497
1549
  if (!transactionItemId) {
1498
- request$ = this.flowStateApiService.newConfiguration(this.flowStateService.stateId, {
1499
- transactionItem: generateTransactionItem(productId),
1500
- actionsOverride: (_c = container === null || container === void 0 ? void 0 : container.actions) === null || _c === void 0 ? void 0 : _c.map(processor => (Object.assign(Object.assign({}, processor), { ownerId: this.ownerId }))),
1501
- selectorsOverride: (_d = container === null || container === void 0 ? void 0 : container.selectors) === null || _d === void 0 ? void 0 : _d.map(processor => (Object.assign(Object.assign({}, processor), { ownerId: this.ownerId }))),
1502
- });
1550
+ request$ = this.pcmApiService.fetchPCMByProductId(productId).pipe(switchMap(pcm => {
1551
+ var _a, _b, _c;
1552
+ return this.flowStateApiService.newConfiguration(this.flowStateService.stateId || '', {
1553
+ transactionItem: generateTransactionItem(pcm, (_a = this.configurationService.state) === null || _a === void 0 ? void 0 : _a.salesTransaction.id),
1554
+ actionsOverride: (_b = container === null || container === void 0 ? void 0 : container.actions) === null || _b === void 0 ? void 0 : _b.map(processor => (Object.assign(Object.assign({}, processor), { ownerId: this.ownerId }))),
1555
+ selectorsOverride: (_c = container === null || container === void 0 ? void 0 : container.selectors) === null || _c === void 0 ? void 0 : _c.map(processor => (Object.assign(Object.assign({}, processor), { ownerId: this.ownerId }))),
1556
+ });
1557
+ }));
1503
1558
  }
1504
1559
  else {
1505
1560
  request$ = this.flowStateApiService.startConfiguration(this.flowStateService.stateId, {
1506
1561
  transactionItemId,
1507
- actionsOverride: (_e = container === null || container === void 0 ? void 0 : container.actions) === null || _e === void 0 ? void 0 : _e.map(processor => (Object.assign(Object.assign({}, processor), { ownerId: this.ownerId }))),
1508
- selectorsOverride: (_f = container === null || container === void 0 ? void 0 : container.selectors) === null || _f === void 0 ? void 0 : _f.map(processor => (Object.assign(Object.assign({}, processor), { ownerId: this.ownerId }))),
1562
+ actionsOverride: (_c = container === null || container === void 0 ? void 0 : container.actions) === null || _c === void 0 ? void 0 : _c.map(processor => (Object.assign(Object.assign({}, processor), { ownerId: this.ownerId }))),
1563
+ selectorsOverride: (_d = container === null || container === void 0 ? void 0 : container.selectors) === null || _d === void 0 ? void 0 : _d.map(processor => (Object.assign(Object.assign({}, processor), { ownerId: this.ownerId }))),
1509
1564
  });
1510
1565
  }
1511
1566
  return request$.pipe(map(r => {
@@ -1675,11 +1730,11 @@ class ConfigurationStateService {
1675
1730
  }, { stateId: '', selectors: {} });
1676
1731
  }
1677
1732
  }
1678
- ConfigurationStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService, deps: [{ token: ConfigurationRuntimeService }, { token: ConfigurationService }, { token: FlowStateService }, { token: FlowInfoService }, { token: FlowConfigurationService }, { token: i3.FlowStateApiService }, { token: SalesTransactionService }, { token: i1.SalesTransactionApiService }, { token: i6.ToastService }], target: i0.ɵɵFactoryTarget.Injectable });
1733
+ ConfigurationStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService, deps: [{ token: ConfigurationRuntimeService }, { token: ConfigurationService }, { token: FlowStateService }, { token: FlowInfoService }, { token: FlowConfigurationService }, { token: i3.FlowStateApiService }, { token: SalesTransactionService }, { token: i1.SalesTransactionApiService }, { token: i6.ToastService }, { token: i1.PCMApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1679
1734
  ConfigurationStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService });
1680
1735
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService, decorators: [{
1681
1736
  type: Injectable
1682
- }], ctorParameters: function () { return [{ type: ConfigurationRuntimeService }, { type: ConfigurationService }, { type: FlowStateService }, { type: FlowInfoService }, { type: FlowConfigurationService }, { type: i3.FlowStateApiService }, { type: SalesTransactionService }, { type: i1.SalesTransactionApiService }, { type: i6.ToastService }]; } });
1737
+ }], ctorParameters: function () { return [{ type: ConfigurationRuntimeService }, { type: ConfigurationService }, { type: FlowStateService }, { type: FlowInfoService }, { type: FlowConfigurationService }, { type: i3.FlowStateApiService }, { type: SalesTransactionService }, { type: i1.SalesTransactionApiService }, { type: i6.ToastService }, { type: i1.PCMApiService }]; } });
1683
1738
 
1684
1739
  class ConfigurationModule {
1685
1740
  }
@@ -1950,5 +2005,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1950
2005
  * Generated bundle index. Do not edit.
1951
2006
  */
1952
2007
 
1953
- export { ActionCodePipe, CalendarDirective, CatalogProductsService, ConfigurationRuntimeService, ConfigurationService, ConfigurationStateService, DEFAULT_FORMATTING_SETTINGS, DatePipe, FLOW_CUSTOMIZATION, FORMATTING_SETTINGS_TOKEN, FlowConfigurationService, FlowInfoService, FlowStateConfigurationService, FlowStateService, GuidedSellingService, IntegrationState, NumberPipe, PricePipe, ProductImagesService, RuntimeSettingsService, SalesTransactionService, SdkCoreModule, SdkDirectivesModule, SdkPipesModule, TestModeConfigurationService, TransactionItemWorker, UI_DEFINITION_VERSION, extractMetadata, filterSuccessfulExecute, findTransactionItem, findTransactionItemWithComparator, generateTransactionItem, insertTransactionItem, removeTransactionItem, replaceTransactionItem };
2008
+ export { ActionCodePipe, CalendarDirective, CatalogProductsService, ConfigurationRuntimeService, ConfigurationService, ConfigurationStateService, DEFAULT_FORMATTING_SETTINGS, DatePipe, FLOW_CUSTOMIZATION, FORMATTING_SETTINGS_TOKEN, FlowConfigurationService, FlowInfoService, FlowStateConfigurationService, FlowStateService, GuidedSellingService, IntegrationState, NumberPipe, PricePipe, ProductImagesService, RuntimeSettingsService, SalesTransactionService, SdkCoreModule, SdkDirectivesModule, SdkPipesModule, TestModeConfigurationService, TransactionItemWorker, UI_DEFINITION_VERSION, extractMetadata, filterSuccessfulExecute, findTransactionItem, findTransactionItemWithComparator, generateTransactionItem, generateTransactionItemFromPCM, insertTransactionItem, removeTransactionItem, replaceTransactionItem };
1954
2009
  //# sourceMappingURL=veloceapps-sdk-core.mjs.map