@veloceapps/sdk 11.0.0-99 → 12.0.0-0

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 (39) hide show
  1. package/cms/vendor-map.d.ts +6 -2
  2. package/core/modules/configuration/services/configuration-state.service.d.ts +3 -2
  3. package/core/modules/configuration/services/test-mode-configuration.service.d.ts +4 -1
  4. package/core/modules/configuration/types/configuration.types.d.ts +4 -0
  5. package/core/services/flow-info.service.d.ts +5 -5
  6. package/core/services/flow-state-configuration.service.d.ts +7 -2
  7. package/core/utils/index.d.ts +1 -0
  8. package/core/utils/pcm.utils.d.ts +5 -0
  9. package/core/utils/transaction-item.utils.d.ts +5 -2
  10. package/esm2020/cms/vendor-map.mjs +7 -3
  11. package/esm2020/core/modules/configuration/services/configuration-state.service.mjs +21 -18
  12. package/esm2020/core/modules/configuration/services/configuration.service.mjs +3 -5
  13. package/esm2020/core/modules/configuration/services/test-mode-configuration.service.mjs +32 -9
  14. package/esm2020/core/modules/configuration/types/configuration.types.mjs +1 -1
  15. package/esm2020/core/services/flow-info.service.mjs +14 -14
  16. package/esm2020/core/services/flow-state-configuration.service.mjs +70 -33
  17. package/esm2020/core/utils/index.mjs +2 -1
  18. package/esm2020/core/utils/pcm.utils.mjs +15 -0
  19. package/esm2020/core/utils/transaction-item.utils.mjs +82 -6
  20. package/esm2020/src/guards/product-unload.guard.mjs +4 -2
  21. package/esm2020/src/pages/product/product.component.mjs +37 -10
  22. package/esm2020/src/resolvers/ui-definition.resolver.mjs +7 -5
  23. package/esm2020/src/services/flow-router.service.mjs +10 -10
  24. package/fesm2015/veloceapps-sdk-cms.mjs +5 -1
  25. package/fesm2015/veloceapps-sdk-cms.mjs.map +1 -1
  26. package/fesm2015/veloceapps-sdk-core.mjs +211 -67
  27. package/fesm2015/veloceapps-sdk-core.mjs.map +1 -1
  28. package/fesm2015/veloceapps-sdk.mjs +49 -19
  29. package/fesm2015/veloceapps-sdk.mjs.map +1 -1
  30. package/fesm2020/veloceapps-sdk-cms.mjs +5 -1
  31. package/fesm2020/veloceapps-sdk-cms.mjs.map +1 -1
  32. package/fesm2020/veloceapps-sdk-core.mjs +221 -74
  33. package/fesm2020/veloceapps-sdk-core.mjs.map +1 -1
  34. package/fesm2020/veloceapps-sdk.mjs +48 -19
  35. package/fesm2020/veloceapps-sdk.mjs.map +1 -1
  36. package/package.json +4 -4
  37. package/src/pages/product/product.component.d.ts +12 -3
  38. package/src/resolvers/ui-definition.resolver.d.ts +1 -1
  39. package/src/services/flow-router.service.d.ts +3 -3
@@ -38,6 +38,21 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
38
38
  type: Injectable
39
39
  }], ctorParameters: function () { return [{ type: i1.PCMApiService }]; } });
40
40
 
41
+ class PCMUtils {
42
+ static mapByPrcId(pcm) {
43
+ const map = {};
44
+ if (pcm.productRelatedComponent) {
45
+ map[pcm.productRelatedComponent.id] = pcm;
46
+ }
47
+ for (const group of pcm.productComponentGroups) {
48
+ for (const gc of group.components) {
49
+ Object.assign(map, PCMUtils.mapByPrcId(gc));
50
+ }
51
+ }
52
+ return map;
53
+ }
54
+ }
55
+
41
56
  const findTransactionItem = (id, items) => {
42
57
  return findTransactionItemWithComparator(items, (ti) => ti.id === id);
43
58
  };
@@ -80,11 +95,85 @@ const replaceTransactionItem = (item, replaceTo) => {
80
95
  }
81
96
  return Object.assign(Object.assign({}, item), { children: item.children.map(ti => replaceTransactionItem(ti, replaceTo)) });
82
97
  };
83
- const generateTransactionItem = (productId) => {
84
- return {
85
- id: UUID.UUID(),
86
- productId,
98
+ const generateTransactionItem = (option, salesTransactionId, qty, parentTi) => {
99
+ const newItem = generateTransactionItemFromPCM(option, salesTransactionId, parentTi);
100
+ // propagate Proportional quantities to children
101
+ const updatedNewItem = updateQuantity(newItem, qty !== null && qty !== void 0 ? qty : newItem.qty, option, parentTi === null || parentTi === void 0 ? void 0 : parentTi.qty);
102
+ return updatedNewItem;
103
+ };
104
+ const generateTransactionItemFromPCM = (option, salesTransactionId, parentTi) => {
105
+ var _a, _b, _c, _d, _e;
106
+ const childId = UUID.UUID();
107
+ const newItem = {
108
+ id: childId,
109
+ productId: option.id,
110
+ productName: option.name,
111
+ productCode: option.productCode,
112
+ productRelatedComponentId: (_a = option.productRelatedComponent) === null || _a === void 0 ? void 0 : _a.id,
113
+ stiAttributes: [],
114
+ attributes: {
115
+ ParentReference: salesTransactionId,
116
+ ItemPath: option.id,
117
+ SalesTransactionItemSource: childId,
118
+ SalesTransactionItemParent: salesTransactionId,
119
+ ProductSellingModel: (_c = (_b = option.productSellingModelOptions) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.productSellingModel.id,
120
+ },
121
+ qty: (_e = (_d = option.productRelatedComponent) === null || _d === void 0 ? void 0 : _d.quantity) !== null && _e !== void 0 ? _e : 1,
122
+ };
123
+ if (parentTi) {
124
+ newItem.parentId = parentTi.id;
125
+ }
126
+ newItem.children = option.productComponentGroups.reduce((acc, group) => {
127
+ group.components.forEach(component => {
128
+ var _a, _b;
129
+ if (((_a = component.productRelatedComponent) === null || _a === void 0 ? void 0 : _a.isComponentRequired) ||
130
+ ((_b = component.productRelatedComponent) === null || _b === void 0 ? void 0 : _b.isDefaultComponent)) {
131
+ acc.push(generateTransactionItemFromPCM(component, salesTransactionId, newItem));
132
+ }
133
+ });
134
+ return acc;
135
+ }, []);
136
+ return newItem;
137
+ };
138
+ const flattenTransactionItem = (ti) => {
139
+ const result = [];
140
+ const traverse = (item) => {
141
+ if (!item)
142
+ return;
143
+ result.push(item);
144
+ if (Array.isArray(item.children) && item.children.length) {
145
+ for (const child of item.children) {
146
+ traverse(child);
147
+ }
148
+ }
149
+ };
150
+ traverse(ti);
151
+ return result;
152
+ };
153
+ const updateQuantity = (ti, qty, pcm, parentQty = 1) => {
154
+ const pcmMap = PCMUtils.mapByPrcId(pcm);
155
+ const calcNewQty = (item, parentPrevQty, parentNewQty, parentPcm, inputQty, isDirectChange) => {
156
+ var _a;
157
+ const scaleMethod = (_a = parentPcm === null || parentPcm === void 0 ? void 0 : parentPcm.productRelatedComponent) === null || _a === void 0 ? void 0 : _a.quantityScaleMethod;
158
+ if (isDirectChange) {
159
+ return scaleMethod === 'Proportional' ? parentPrevQty * inputQty : inputQty;
160
+ }
161
+ else {
162
+ return scaleMethod === 'Proportional' ? (item.qty / parentPrevQty) * parentNewQty : item.qty;
163
+ }
164
+ };
165
+ const updateItem = (item, parentPrevQty, parentNewQty, isDirectChange) => {
166
+ const pcm = pcmMap[item.productRelatedComponentId];
167
+ let nextQty = item.qty;
168
+ if (item.id === ti.id || isDirectChange) {
169
+ nextQty = calcNewQty(item, parentPrevQty, parentNewQty, pcm, qty, true);
170
+ }
171
+ else if (parentPrevQty !== parentNewQty) {
172
+ nextQty = calcNewQty(item, parentPrevQty, parentNewQty, pcm, qty, false);
173
+ }
174
+ return Object.assign(Object.assign({}, item), { qty: nextQty, children: item.children.map(child => updateItem(child, item.qty, nextQty, false)) });
87
175
  };
176
+ return updateItem(ti, parentQty, parentQty, false);
88
177
  };
89
178
 
90
179
  class TransactionItemWorker {
@@ -220,6 +309,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
220
309
  }], ctorParameters: function () { return [{ type: i1.ConfigurationSettingsApiService }]; } });
221
310
 
222
311
  class FlowInfoService {
312
+ constructor(runtimeSettingsService, templatesAdminApiService, customizationService) {
313
+ this.runtimeSettingsService = runtimeSettingsService;
314
+ this.templatesAdminApiService = templatesAdminApiService;
315
+ this.customizationService = customizationService;
316
+ this.defaultTemplates = {
317
+ flowEngine: 'Flow Engine',
318
+ };
319
+ this.flowSubj$ = new BehaviorSubject(null);
320
+ this.templatesSubj$ = new BehaviorSubject({});
321
+ this.contextSubj$ = new BehaviorSubject(null);
322
+ this.flow$ = this.flowSubj$.asObservable();
323
+ this.templates$ = this.templatesSubj$.asObservable();
324
+ }
223
325
  get flow() {
224
326
  if (!this.flowSubj$.value) {
225
327
  throw new Error(`Flow not initialized yet`);
@@ -248,19 +350,6 @@ class FlowInfoService {
248
350
  var _a;
249
351
  return !!((_a = this.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful);
250
352
  }
251
- constructor(runtimeSettingsService, templatesAdminApiService, customizationService) {
252
- this.runtimeSettingsService = runtimeSettingsService;
253
- this.templatesAdminApiService = templatesAdminApiService;
254
- this.customizationService = customizationService;
255
- this.defaultTemplates = {
256
- flowEngine: 'Flow Engine',
257
- };
258
- this.flowSubj$ = new BehaviorSubject(null);
259
- this.templatesSubj$ = new BehaviorSubject({});
260
- this.contextSubj$ = new BehaviorSubject(null);
261
- this.flow$ = this.flowSubj$.asObservable();
262
- this.templates$ = this.templatesSubj$.asObservable();
263
- }
264
353
  reset() {
265
354
  this.flowSubj$.next(null);
266
355
  this.templatesSubj$.next({});
@@ -356,12 +445,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
356
445
  } });
357
446
 
358
447
  class TestModeConfigurationService {
359
- constructor(flowInfoService, configurationService, configurationRuntimeService, salesTransactionService, runtimeSettingsService) {
448
+ constructor(flowInfoService, configurationService, configurationRuntimeService, salesTransactionService, runtimeSettingsService, sfApiService) {
360
449
  this.flowInfoService = flowInfoService;
361
450
  this.configurationService = configurationService;
362
451
  this.configurationRuntimeService = configurationRuntimeService;
363
452
  this.salesTransactionService = salesTransactionService;
364
453
  this.runtimeSettingsService = runtimeSettingsService;
454
+ this.sfApiService = sfApiService;
365
455
  this.isInitialized = false;
366
456
  }
367
457
  initTestMode$(uiDefinitionContainer, options) {
@@ -382,7 +472,7 @@ class TestModeConfigurationService {
382
472
  if (!flowId) {
383
473
  return throwError(() => `Unable to start the Configuration Preview: Flow is missing.`);
384
474
  }
385
- return this.runtimeSettingsService.create().pipe(switchMap(() => this.flowInfoService.init$(flowId, { productId, headerId: quoteId })), switchMap(() => this.configurationRuntimeService.init$({ productId })), tap(pcmModel => (this.pcmModel = pcmModel)), switchMap(() => {
475
+ return this.runtimeSettingsService.create().pipe(switchMap(() => this.flowInfoService.init$(flowId, { productId, headerId: quoteId, testMode: true })), switchMap(() => this.configurationRuntimeService.init$({ productId })), tap(pcmModel => (this.pcmModel = pcmModel)), switchMap(() => {
386
476
  if (options === null || options === void 0 ? void 0 : options.customizationMode) {
387
477
  return of(undefined);
388
478
  }
@@ -390,17 +480,38 @@ class TestModeConfigurationService {
390
480
  }), tap(() => (this.isInitialized = true)), map(noop));
391
481
  }
392
482
  initConfiguration$(quoteId) {
393
- this.salesTransactionService.setState(this.getTestTransactionContext(quoteId));
394
- return this.configurationService.init$().pipe(switchMap(() => this.configurationService.state
483
+ return this.getPriceBookId(quoteId).pipe(map(priceBookId => this.getTestTransactionContext(quoteId, priceBookId)), tap(state => this.salesTransactionService.setState(state)), switchMap(() => this.configurationService.init$()), switchMap(() => this.configurationService.state
395
484
  ? this.configurationService.configure$(this.configurationService.state)
396
485
  : of(undefined)), map(noop));
397
486
  }
398
- getTestTransactionContext(quoteId) {
487
+ getPriceBookId(quoteId) {
488
+ return this.sfApiService
489
+ .query({ count: 1, fields: ['Pricebook2Id'], rawCondition: `Id = '${quoteId}'` }, 'Quote')
490
+ .pipe(map(r => { var _a, _b; return (_b = (_a = r === null || r === void 0 ? void 0 : r[0]) === null || _a === void 0 ? void 0 : _a.Pricebook2Id) !== null && _b !== void 0 ? _b : null; }));
491
+ }
492
+ getTestTransactionContext(quoteId, priceBookId) {
493
+ var _a;
494
+ const dateStr = (_a = new Date().toISOString().split('T')[0]) !== null && _a !== void 0 ? _a : '';
399
495
  const testTransaction = {
400
496
  id: quoteId,
401
497
  businessObjectType: 'Quote',
402
498
  salesTransactionItems: [],
499
+ salesTransactionName: 'Test Quote',
500
+ account: '',
501
+ quoteAccount: '',
502
+ pricebook: '',
503
+ status: 'Draft',
504
+ totalAmount: 0,
505
+ subtotal: 0,
506
+ activatedDate: dateStr,
507
+ effectiveDate: dateStr,
508
+ startDate: dateStr,
509
+ attributes: {},
510
+ nodes: {},
403
511
  };
512
+ if (priceBookId) {
513
+ testTransaction.pricebook = priceBookId;
514
+ }
404
515
  return {
405
516
  salesTransaction: testTransaction,
406
517
  transactionId: quoteId,
@@ -415,11 +526,11 @@ class TestModeConfigurationService {
415
526
  return this.isInitialized && !!((_a = uiDefinitionContainer.source.properties) === null || _a === void 0 ? void 0 : _a.persistTestState);
416
527
  }
417
528
  }
418
- TestModeConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TestModeConfigurationService, deps: [{ token: FlowInfoService }, { token: ConfigurationService }, { token: ConfigurationRuntimeService }, { token: SalesTransactionService }, { token: RuntimeSettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
529
+ TestModeConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TestModeConfigurationService, deps: [{ token: FlowInfoService }, { token: ConfigurationService }, { token: ConfigurationRuntimeService }, { token: SalesTransactionService }, { token: RuntimeSettingsService }, { token: i1.SalesforceApiService }], target: i0.ɵɵFactoryTarget.Injectable });
419
530
  TestModeConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TestModeConfigurationService });
420
531
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TestModeConfigurationService, decorators: [{
421
532
  type: Injectable
422
- }], ctorParameters: function () { return [{ type: FlowInfoService }, { type: ConfigurationService }, { type: ConfigurationRuntimeService }, { type: SalesTransactionService }, { type: RuntimeSettingsService }]; } });
533
+ }], ctorParameters: function () { return [{ type: FlowInfoService }, { type: ConfigurationService }, { type: ConfigurationRuntimeService }, { type: SalesTransactionService }, { type: RuntimeSettingsService }, { type: i1.SalesforceApiService }]; } });
423
534
 
424
535
  class GuidedSellingService {
425
536
  constructor(orchestrationsApiService) {
@@ -1023,12 +1134,32 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1023
1134
  } });
1024
1135
 
1025
1136
  class FlowStateConfigurationService {
1026
- constructor(flowInfoService, flowStateService, configurationService, salesTransactionService, flowConfigurationService) {
1137
+ constructor(flowInfoService, flowStateService, configurationService, salesTransactionService, flowConfigurationService, pcmApiService) {
1027
1138
  this.flowInfoService = flowInfoService;
1028
1139
  this.flowStateService = flowStateService;
1029
1140
  this.configurationService = configurationService;
1030
1141
  this.salesTransactionService = salesTransactionService;
1031
1142
  this.flowConfigurationService = flowConfigurationService;
1143
+ this.pcmApiService = pcmApiService;
1144
+ this.pcmCache = {};
1145
+ }
1146
+ updateQuantity$(props) {
1147
+ var _a, _b, _c;
1148
+ const allItems = (_c = (_b = (_a = this.salesTransactionService.state) === null || _a === void 0 ? void 0 : _a.salesTransaction) === null || _b === void 0 ? void 0 : _b.salesTransactionItems) !== null && _c !== void 0 ? _c : [];
1149
+ const ti = allItems.find(item => item.id === props.id);
1150
+ if (!ti) {
1151
+ return of(undefined);
1152
+ }
1153
+ return this.getPCMProduct$(ti.productId).pipe(map(pcm => updateQuantity(ti, props.qty, pcm)), switchMap(updatedTi => {
1154
+ const state = this.salesTransactionService.state;
1155
+ if (!state) {
1156
+ return of(undefined);
1157
+ }
1158
+ const updatedState = Object.assign(Object.assign({}, state), { salesTransaction: Object.assign(Object.assign({}, state.salesTransaction), { salesTransactionItems: state.salesTransaction.salesTransactionItems.map(item => {
1159
+ return updatedTi.id === item.id ? updatedTi : item;
1160
+ }) }) });
1161
+ return this.flowConfigurationService.calculate$(updatedState);
1162
+ }), switchMap(() => this.flowStateService.executeRequest$({}, true)), map(noop));
1032
1163
  }
1033
1164
  addToCart$(props) {
1034
1165
  var _a;
@@ -1050,32 +1181,43 @@ class FlowStateConfigurationService {
1050
1181
  return request$.pipe(switchMap(() => this.flowStateService.executeRequest$({}, true)), map(noop));
1051
1182
  }
1052
1183
  configureExternal$(props) {
1053
- var _a, _b;
1054
- const { state } = this.salesTransactionService;
1055
- if (!state) {
1056
- return of();
1057
- }
1058
- const stateToConfigure = Object.assign(Object.assign({}, state), { salesTransaction: Object.assign(Object.assign({}, state.salesTransaction), { salesTransactionItems: [
1059
- 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]) => ({
1060
- attributeName,
1061
- value,
1062
- })) }),
1063
- ] }) });
1064
- return this.configurationService.justConfigureRequest$(stateToConfigure).pipe(switchMap(configurationResult => {
1065
- const state = this.salesTransactionService.state;
1066
- const addedProduct = configurationResult.salesTransaction.salesTransactionItems[0];
1067
- if (!state || !addedProduct) {
1184
+ return this.getPCMProduct$(props.productId).pipe(switchMap(pcm => {
1185
+ var _a, _b, _c;
1186
+ const { state } = this.salesTransactionService;
1187
+ if (!state) {
1068
1188
  return of();
1069
1189
  }
1070
- return this.flowConfigurationService.calculate$(Object.assign(Object.assign({}, state), { salesTransaction: Object.assign(Object.assign({}, state.salesTransaction), { salesTransactionItems: [...state.salesTransaction.salesTransactionItems, addedProduct] }) }));
1190
+ const stateToConfigure = Object.assign(Object.assign({}, state), { salesTransaction: Object.assign(Object.assign({}, state.salesTransaction), { salesTransactionItems: [
1191
+ Object.assign(Object.assign({}, generateTransactionItem(pcm, (_a = this.configurationService.state) === null || _a === void 0 ? void 0 : _a.salesTransaction.id, (_b = props.qty) !== null && _b !== void 0 ? _b : 1)), { stiAttributes: Object.entries((_c = props.attributesMap) !== null && _c !== void 0 ? _c : {}).map(([attributeName, value]) => ({
1192
+ attributeName,
1193
+ value,
1194
+ })) }),
1195
+ ] }) });
1196
+ return this.configurationService.justConfigureRequest$(stateToConfigure).pipe(switchMap(configurationResult => {
1197
+ const state = this.salesTransactionService.state;
1198
+ const addedProduct = configurationResult.salesTransaction.salesTransactionItems[0];
1199
+ if (!state || !addedProduct) {
1200
+ return of();
1201
+ }
1202
+ return this.flowConfigurationService.calculate$(Object.assign(Object.assign({}, state), { salesTransaction: Object.assign(Object.assign({}, state.salesTransaction), { salesTransactionItems: [...state.salesTransaction.salesTransactionItems, addedProduct] }) }));
1203
+ }));
1071
1204
  }));
1072
1205
  }
1206
+ getPCMProduct$(productId) {
1207
+ const cached = this.pcmCache[productId];
1208
+ if (cached) {
1209
+ return of(cached);
1210
+ }
1211
+ return this.pcmApiService
1212
+ .fetchPCMByProductId(productId)
1213
+ .pipe(tap(pcmProduct => (this.pcmCache[productId] = pcmProduct)));
1214
+ }
1073
1215
  }
1074
- 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 });
1216
+ 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 });
1075
1217
  FlowStateConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService });
1076
1218
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, decorators: [{
1077
1219
  type: Injectable
1078
- }], ctorParameters: function () { return [{ type: FlowInfoService }, { type: FlowStateService }, { type: ConfigurationService }, { type: SalesTransactionService }, { type: FlowConfigurationService }]; } });
1220
+ }], ctorParameters: function () { return [{ type: FlowInfoService }, { type: FlowStateService }, { type: ConfigurationService }, { type: SalesTransactionService }, { type: FlowConfigurationService }, { type: i1.PCMApiService }]; } });
1079
1221
 
1080
1222
  class IntegrationState {
1081
1223
  constructor() {
@@ -1192,7 +1334,7 @@ class ConfigurationService {
1192
1334
  this.previousConfigurationStateSubj$.next(null);
1193
1335
  }
1194
1336
  init$() {
1195
- var _a;
1337
+ var _a, _b;
1196
1338
  const { state } = this.salesTransactionService;
1197
1339
  const { standalone } = this.flowInfoService.flow.properties;
1198
1340
  const { productId, transactionItemId, newProductQty } = this.flowInfoService.context;
@@ -1206,10 +1348,8 @@ class ConfigurationService {
1206
1348
  transactionItem = salesTransactionItems.find(item => item.productId === productId);
1207
1349
  }
1208
1350
  if (!transactionItem) {
1209
- transactionItem = generateTransactionItem(productId);
1210
- if (typeof newProductQty === 'number' && newProductQty > 0) {
1211
- transactionItem.qty = newProductQty;
1212
- }
1351
+ const quantity = typeof newProductQty === 'number' && newProductQty > 0 ? newProductQty : undefined;
1352
+ transactionItem = generateTransactionItem(this.getPCMModel(), (_b = this.state) === null || _b === void 0 ? void 0 : _b.salesTransaction.id, quantity);
1213
1353
  isRootGenerated = true;
1214
1354
  }
1215
1355
  const guidedSellingResult = this.guidedSellingService.guidedSellingResult;
@@ -1291,7 +1431,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1291
1431
  }], ctorParameters: function () { return [{ type: FlowInfoService }, { type: i2.MessageService }, { type: ConfigurationRuntimeService }, { type: SalesTransactionService }, { type: i1.OrchestrationsApiService }, { type: GuidedSellingService }]; } });
1292
1432
 
1293
1433
  class ConfigurationStateService {
1294
- constructor(configurationRuntimeService, configurationService, flowStateService, flowInfoService, flowConfigurationService, flowStateApiService, salesTransactionService, salesTransactionApiService, toastService) {
1434
+ constructor(configurationRuntimeService, configurationService, flowStateService, flowInfoService, flowConfigurationService, flowStateApiService, salesTransactionService, salesTransactionApiService, toastService, pcmApiService) {
1295
1435
  this.configurationRuntimeService = configurationRuntimeService;
1296
1436
  this.configurationService = configurationService;
1297
1437
  this.flowStateService = flowStateService;
@@ -1301,6 +1441,7 @@ class ConfigurationStateService {
1301
1441
  this.salesTransactionService = salesTransactionService;
1302
1442
  this.salesTransactionApiService = salesTransactionApiService;
1303
1443
  this.toastService = toastService;
1444
+ this.pcmApiService = pcmApiService;
1304
1445
  this.isInitialized$ = new BehaviorSubject(false);
1305
1446
  this.canceledConfiguration$ = new Subject();
1306
1447
  this.NOT_INITIALIZED = Symbol();
@@ -1421,13 +1562,6 @@ class ConfigurationStateService {
1421
1562
  return of({ id: '' });
1422
1563
  }
1423
1564
  const { standalone } = this.flowInfoService.flow.properties;
1424
- if (standalone) {
1425
- const request = {
1426
- transactionContext: state,
1427
- flowId: this.flowInfoService.flow.id,
1428
- };
1429
- return this.salesTransactionApiService.save(request).pipe(switchMap(r => this.flowStateService.executeRequest$({}, true).pipe(map(() => r))), map(id => ({ id })));
1430
- }
1431
1565
  const transactionContext = this.salesTransactionService.state;
1432
1566
  const configurationRoot = this.configurationService.root;
1433
1567
  if (!transactionContext || !configurationRoot) {
@@ -1443,6 +1577,13 @@ class ConfigurationStateService {
1443
1577
  salesTransactionItems = stateItems.map(ti => (ti.id === configurationRoot.id ? configurationRoot : ti));
1444
1578
  }
1445
1579
  const newState = Object.assign(Object.assign({}, transactionContext), { salesTransaction: Object.assign(Object.assign({}, transactionContext.salesTransaction), { salesTransactionItems }) });
1580
+ if (standalone) {
1581
+ const request = {
1582
+ transactionContext: newState,
1583
+ flowId: this.flowInfoService.flow.id,
1584
+ };
1585
+ return this.salesTransactionApiService.save(request).pipe(switchMap(r => this.flowStateService.executeRequest$({}, true).pipe(map(() => r))), map(id => ({ id })));
1586
+ }
1446
1587
  return this.flowConfigurationService.calculate$(newState).pipe(switchMap(() => this.flowStateService.executeRequest$({}, true)), map(() => ({ id: '' })));
1447
1588
  }
1448
1589
  cancelConfiguration() {
@@ -1464,7 +1605,7 @@ class ConfigurationStateService {
1464
1605
  return (_b = (_a = this.flowInfoService.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful) !== null && _b !== void 0 ? _b : false;
1465
1606
  }
1466
1607
  initStateful$() {
1467
- var _a, _b, _c, _d, _e, _f;
1608
+ var _a, _b, _c, _d;
1468
1609
  this.ownerId = (_b = (_a = this.configurationRuntimeService.uiDefinitionContainer) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '';
1469
1610
  const { productId, transactionItemId } = this.flowInfoService.context;
1470
1611
  if (!productId || !this.flowStateService.stateId) {
@@ -1473,17 +1614,20 @@ class ConfigurationStateService {
1473
1614
  const container = this.configurationRuntimeService.uiDefinitionContainer;
1474
1615
  let request$;
1475
1616
  if (!transactionItemId) {
1476
- request$ = this.flowStateApiService.newConfiguration(this.flowStateService.stateId, {
1477
- transactionItem: generateTransactionItem(productId),
1478
- 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 }))),
1479
- 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 }))),
1480
- });
1617
+ request$ = this.pcmApiService.fetchPCMByProductId(productId).pipe(switchMap(pcm => {
1618
+ var _a, _b, _c;
1619
+ return this.flowStateApiService.newConfiguration(this.flowStateService.stateId || '', {
1620
+ transactionItem: generateTransactionItem(pcm, (_a = this.configurationService.state) === null || _a === void 0 ? void 0 : _a.salesTransaction.id),
1621
+ 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 }))),
1622
+ 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 }))),
1623
+ });
1624
+ }));
1481
1625
  }
1482
1626
  else {
1483
1627
  request$ = this.flowStateApiService.startConfiguration(this.flowStateService.stateId, {
1484
1628
  transactionItemId,
1485
- 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 }))),
1486
- 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 }))),
1629
+ 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 }))),
1630
+ 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 }))),
1487
1631
  });
1488
1632
  }
1489
1633
  return request$.pipe(map(r => {
@@ -1653,11 +1797,11 @@ class ConfigurationStateService {
1653
1797
  }, { stateId: '', selectors: {} });
1654
1798
  }
1655
1799
  }
1656
- 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 });
1800
+ 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 });
1657
1801
  ConfigurationStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService });
1658
1802
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService, decorators: [{
1659
1803
  type: Injectable
1660
- }], ctorParameters: function () { return [{ type: ConfigurationRuntimeService }, { type: ConfigurationService }, { type: FlowStateService }, { type: FlowInfoService }, { type: FlowConfigurationService }, { type: i3.FlowStateApiService }, { type: SalesTransactionService }, { type: i1.SalesTransactionApiService }, { type: i6.ToastService }]; } });
1804
+ }], 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 }]; } });
1661
1805
 
1662
1806
  class ConfigurationModule {
1663
1807
  }
@@ -1928,5 +2072,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1928
2072
  * Generated bundle index. Do not edit.
1929
2073
  */
1930
2074
 
1931
- 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 };
2075
+ export { ActionCodePipe, CalendarDirective, CatalogProductsService, ConfigurationRuntimeService, ConfigurationService, ConfigurationStateService, DEFAULT_FORMATTING_SETTINGS, DatePipe, FLOW_CUSTOMIZATION, FORMATTING_SETTINGS_TOKEN, FlowConfigurationService, FlowInfoService, FlowStateConfigurationService, FlowStateService, GuidedSellingService, IntegrationState, NumberPipe, PCMUtils, PricePipe, ProductImagesService, RuntimeSettingsService, SalesTransactionService, SdkCoreModule, SdkDirectivesModule, SdkPipesModule, TestModeConfigurationService, TransactionItemWorker, UI_DEFINITION_VERSION, extractMetadata, filterSuccessfulExecute, findTransactionItem, findTransactionItemWithComparator, flattenTransactionItem, generateTransactionItem, generateTransactionItemFromPCM, insertTransactionItem, removeTransactionItem, replaceTransactionItem, updateQuantity };
1932
2076
  //# sourceMappingURL=veloceapps-sdk-core.mjs.map