@medipass/utils 11.88.0 → 11.88.1-fix-object-pollution.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.
- package/package.json +2 -2
- package/service-items.d.ts +1 -0
- package/service-items.js +31 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medipass/utils",
|
|
3
|
-
"version": "11.88.0",
|
|
3
|
+
"version": "11.88.1-fix-object-pollution.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"rimraf": "^2.6.2",
|
|
48
48
|
"typescript": "4.8.4"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "72269493c1e9a4bf37eeb1e2722a6d861ade316a"
|
|
51
51
|
}
|
package/service-items.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function round(value: number, step: number): number;
|
|
2
|
+
export declare function deepClone<T>(obj: T): T;
|
|
2
3
|
export declare const calculateTotalAmount: (serviceItems: Array<Record<string, any>>, opts?: {
|
|
3
4
|
includeDiscount?: boolean;
|
|
4
5
|
includeQuantity?: boolean;
|
package/service-items.js
CHANGED
|
@@ -20,6 +20,25 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
20
20
|
function round(value, step) {
|
|
21
21
|
var inv = 1.0 / step;
|
|
22
22
|
return Math.round(value * inv) / inv;
|
|
23
|
+
} // Perform a deep clone to avoid accidental shared references/aliasing
|
|
24
|
+
|
|
25
|
+
function deepClone(obj) {
|
|
26
|
+
if (obj === null || obj === undefined) return obj;
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(JSON.stringify(obj));
|
|
30
|
+
} catch (_err) {
|
|
31
|
+
// Fallback to shallow copy if JSON cloning fails (e.g., circular refs)
|
|
32
|
+
if (Array.isArray(obj)) {
|
|
33
|
+
return [].concat(obj);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof obj === 'object') {
|
|
37
|
+
return _objectSpread({}, obj);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
23
42
|
}
|
|
24
43
|
var calculateTotalAmount = function calculateTotalAmount(serviceItems, opts) {
|
|
25
44
|
if (opts === void 0) {
|
|
@@ -118,23 +137,28 @@ var getTotalAmount = function getTotalAmount(serviceItems) {
|
|
|
118
137
|
var getItemValue = function getItemValue(item, opts) {
|
|
119
138
|
var _ref2 = opts || {},
|
|
120
139
|
_ref2$useBenefitAsPri = _ref2.useBenefitAsPrice,
|
|
121
|
-
useBenefitAsPrice = _ref2$useBenefitAsPri === void 0 ? false : _ref2$useBenefitAsPri;
|
|
140
|
+
useBenefitAsPrice = _ref2$useBenefitAsPri === void 0 ? false : _ref2$useBenefitAsPri; // Clone the incoming item to prevent downstream mutations from affecting
|
|
141
|
+
// the original SDK response or other holders of the same reference
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
var clonedItem = deepClone(item || {});
|
|
122
145
|
|
|
123
|
-
var benefit = _get__default["default"](
|
|
146
|
+
var benefit = _get__default["default"](clonedItem, 'benefit', 0);
|
|
124
147
|
|
|
125
148
|
var benefitAmount = (benefit / 100).toFixed(2);
|
|
126
149
|
|
|
127
|
-
var price = _get__default["default"](
|
|
150
|
+
var price = _get__default["default"](clonedItem, 'price');
|
|
128
151
|
|
|
129
152
|
var feeAmount = (price / 100).toFixed(2);
|
|
130
153
|
var option = {
|
|
131
|
-
label:
|
|
132
|
-
value
|
|
154
|
+
label: clonedItem.displayName,
|
|
155
|
+
// Also clone here to ensure select option value is isolated
|
|
156
|
+
value: deepClone(clonedItem)
|
|
133
157
|
};
|
|
134
158
|
return _objectSpread({
|
|
135
159
|
service: option,
|
|
136
160
|
quantity: 1
|
|
137
|
-
},
|
|
161
|
+
}, clonedItem, {
|
|
138
162
|
benefitAmount: benefitAmount,
|
|
139
163
|
hasSeenPatientToday: 'no'
|
|
140
164
|
}, price ? {
|
|
@@ -227,6 +251,7 @@ exports.calculateAmounts = calculateAmounts;
|
|
|
227
251
|
exports.calculateTotalAmount = calculateTotalAmount;
|
|
228
252
|
exports.calculateTotalDiscountAmount = calculateTotalDiscountAmount;
|
|
229
253
|
exports.calculateTotalGSTAmount = calculateTotalGSTAmount;
|
|
254
|
+
exports.deepClone = deepClone;
|
|
230
255
|
exports.getChargeAmount = getChargeAmount;
|
|
231
256
|
exports.getDiscountAmount = getDiscountAmount;
|
|
232
257
|
exports.getEarliestServiceDate = getEarliestServiceDate;
|