@veloceapps/sdk 7.0.2-19 → 7.0.2-20
Sign up to get free protection for your applications and to get access to all the features.
- package/cms/vendor-map.d.ts +2 -2
- package/core/modules/configuration/services/configuration.service.d.ts +3 -3
- package/core/utils/line-item.utils.d.ts +2 -2
- package/core/utils/line-item.worker.d.ts +2 -2
- package/esm2020/core/modules/configuration/services/configuration.service.mjs +6 -5
- package/esm2020/core/utils/line-item.utils.mjs +14 -7
- package/esm2020/core/utils/line-item.worker.mjs +5 -5
- package/fesm2015/veloceapps-sdk-core.mjs +22 -14
- package/fesm2015/veloceapps-sdk-core.mjs.map +1 -1
- package/fesm2020/veloceapps-sdk-core.mjs +22 -14
- package/fesm2020/veloceapps-sdk-core.mjs.map +1 -1
- package/package.json +1 -1
@@ -503,18 +503,25 @@ const removeLineItem = (lineItem, idToRemove) => {
|
|
503
503
|
.filter(r => !!r),
|
504
504
|
};
|
505
505
|
};
|
506
|
-
const replaceLineItem = (lineItem, replaceTo) => {
|
506
|
+
const replaceLineItem = (lineItem, replaceTo, skipCardinalityCalculation = false) => {
|
507
507
|
if (lineItem.id === replaceTo.id) {
|
508
|
-
|
508
|
+
if (!skipCardinalityCalculation) {
|
509
|
+
return { ...recalculateCardinalityVariables(lineItem, replaceTo) };
|
510
|
+
}
|
511
|
+
else {
|
512
|
+
return { ...replaceTo };
|
513
|
+
}
|
509
514
|
}
|
510
515
|
return {
|
511
516
|
...lineItem,
|
512
|
-
lineItems: lineItem.lineItems.map(li => replaceLineItem(li, replaceTo)),
|
517
|
+
lineItems: lineItem.lineItems.map(li => replaceLineItem(li, replaceTo, skipCardinalityCalculation)),
|
513
518
|
};
|
514
519
|
};
|
515
520
|
const calculateCardinalityVariables = (lineItems) => {
|
516
521
|
const cardVars = new Map();
|
517
|
-
lineItems
|
522
|
+
lineItems
|
523
|
+
.filter(({ port, type }) => !!port && !!type)
|
524
|
+
.forEach(li => {
|
518
525
|
const cardinalityVariableName = `#CV-${li.type}@${li.port}`;
|
519
526
|
cardVars.set(cardinalityVariableName, (cardVars.get(cardinalityVariableName) ?? 0) + li.qty);
|
520
527
|
});
|
@@ -554,13 +561,13 @@ const upsertAttributes = (originalAttributes, attributesToUpsert) => {
|
|
554
561
|
];
|
555
562
|
}, originalAttributes);
|
556
563
|
};
|
557
|
-
const patchAttributes = (rootLineItem, id, attrs) => {
|
564
|
+
const patchAttributes = (rootLineItem, id, attrs, skipCardinalityCalculation = false) => {
|
558
565
|
const lineItem = findLineItem(id, [rootLineItem]);
|
559
566
|
if (!lineItem) {
|
560
567
|
return rootLineItem;
|
561
568
|
}
|
562
569
|
const attributes = upsertAttributes(lineItem.attributes, attrs);
|
563
|
-
return replaceLineItem(rootLineItem, { ...lineItem, attributes });
|
570
|
+
return replaceLineItem(rootLineItem, { ...lineItem, attributes }, skipCardinalityCalculation);
|
564
571
|
};
|
565
572
|
const getAttributeValue = (attributes, name) => attributes.find(attr => attr.name === name)?.value;
|
566
573
|
const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
|
@@ -664,11 +671,11 @@ class LineItemWorker {
|
|
664
671
|
remove(id) {
|
665
672
|
return new LineItemWorker(removeLineItem(this.li, id));
|
666
673
|
}
|
667
|
-
replace(toReplace) {
|
668
|
-
return new LineItemWorker(replaceLineItem(this.li, toReplace));
|
674
|
+
replace(toReplace, skipCardinalityCalculation = false) {
|
675
|
+
return new LineItemWorker(replaceLineItem(this.li, toReplace, skipCardinalityCalculation));
|
669
676
|
}
|
670
|
-
patchAttribute(attrs, id) {
|
671
|
-
return new LineItemWorker(patchAttributes(this.li, id ?? this.li.id, attrs));
|
677
|
+
patchAttribute(attrs, id, skipCardinalityCalculation = false) {
|
678
|
+
return new LineItemWorker(patchAttributes(this.li, id ?? this.li.id, attrs, skipCardinalityCalculation));
|
672
679
|
}
|
673
680
|
}
|
674
681
|
|
@@ -694,11 +701,12 @@ class ConfigurationService {
|
|
694
701
|
this.charges.next({});
|
695
702
|
this.pricePlans.next({});
|
696
703
|
}
|
697
|
-
patch$(lineItem) {
|
704
|
+
patch$(lineItem, options) {
|
698
705
|
if (!this.lineItem.value) {
|
699
706
|
return throwError(() => new Error(`Source LineItem not found`));
|
700
707
|
}
|
701
|
-
|
708
|
+
const skipCardinalityCalculation = options?.skipCardinalityCalculation || this.contextSnapshot.properties['#skipCardinalityCalculation'] === 'true';
|
709
|
+
this.configurableRamp = new LineItemWorker(this.lineItem.value).replace(lineItem, skipCardinalityCalculation).li;
|
702
710
|
return this.configure().pipe(catchError(error => {
|
703
711
|
console.error(error);
|
704
712
|
if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
|
@@ -713,8 +721,8 @@ class ConfigurationService {
|
|
713
721
|
}
|
714
722
|
}));
|
715
723
|
}
|
716
|
-
patch(lineItem) {
|
717
|
-
this.patch$(lineItem).subscribe();
|
724
|
+
patch(lineItem, options) {
|
725
|
+
this.patch$(lineItem, options).subscribe();
|
718
726
|
}
|
719
727
|
setConfigurableRamp(lineItem) {
|
720
728
|
this.configurableRamp = lineItem;
|