@pisell/pisellos 2.1.174 → 2.1.176
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/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -4
- package/dist/modules/Discount/index.d.ts +3 -6
- package/dist/modules/Discount/index.js +23 -125
- package/dist/modules/Discount/types.d.ts +5 -34
- package/dist/modules/OpenData/types.d.ts +1 -0
- package/dist/modules/ProductList/index.js +13 -6
- package/dist/modules/Rules/index.d.ts +2 -12
- package/dist/modules/Rules/index.js +113 -377
- package/dist/modules/Rules/types.d.ts +2 -2
- package/dist/plugins/window.d.ts +0 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/ScanOrder/index.d.ts +7 -5
- package/dist/solution/ScanOrder/index.js +123 -31
- package/dist/solution/ScanOrder/resourceSchedule.d.ts +12 -0
- package/dist/solution/ScanOrder/resourceSchedule.js +300 -0
- package/dist/solution/ScanOrder/types.d.ts +9 -1
- package/dist/solution/ShopDiscount/index.d.ts +0 -3
- package/dist/solution/ShopDiscount/index.js +78 -161
- package/dist/solution/ShopDiscount/utils.d.ts +0 -1
- package/dist/solution/ShopDiscount/utils.js +1 -40
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -4
- package/lib/modules/Discount/index.d.ts +3 -6
- package/lib/modules/Discount/index.js +16 -66
- package/lib/modules/Discount/types.d.ts +5 -34
- package/lib/modules/OpenData/types.d.ts +1 -0
- package/lib/modules/ProductList/index.js +8 -1
- package/lib/modules/Rules/index.d.ts +2 -12
- package/lib/modules/Rules/index.js +69 -303
- package/lib/modules/Rules/types.d.ts +2 -2
- package/lib/plugins/window.d.ts +0 -2
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/ScanOrder/index.d.ts +7 -5
- package/lib/solution/ScanOrder/index.js +90 -12
- package/lib/solution/ScanOrder/resourceSchedule.d.ts +12 -0
- package/lib/solution/ScanOrder/resourceSchedule.js +272 -0
- package/lib/solution/ScanOrder/types.d.ts +9 -1
- package/lib/solution/ShopDiscount/index.d.ts +0 -3
- package/lib/solution/ShopDiscount/index.js +28 -78
- package/lib/solution/ShopDiscount/utils.d.ts +0 -1
- package/lib/solution/ShopDiscount/utils.js +1 -42
- package/package.json +1 -1
- package/dist/modules/Discount/availability.d.ts +0 -7
- package/dist/modules/Discount/availability.js +0 -52
- package/dist/modules/Discount/entitlementPass.d.ts +0 -34
- package/dist/modules/Discount/entitlementPass.js +0 -147
- package/dist/modules/Discount/entitlementState.d.ts +0 -8
- package/dist/modules/Discount/entitlementState.js +0 -205
- package/dist/modules/Rules/entitlementLines.d.ts +0 -8
- package/dist/modules/Rules/entitlementLines.js +0 -157
- package/lib/modules/Discount/availability.d.ts +0 -7
- package/lib/modules/Discount/availability.js +0 -91
- package/lib/modules/Discount/entitlementPass.d.ts +0 -34
- package/lib/modules/Discount/entitlementPass.js +0 -184
- package/lib/modules/Discount/entitlementState.d.ts +0 -8
- package/lib/modules/Discount/entitlementState.js +0 -206
- package/lib/modules/Rules/entitlementLines.d.ts +0 -8
- package/lib/modules/Rules/entitlementLines.js +0 -158
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/modules/Discount/entitlementPass.ts
|
|
30
|
-
var entitlementPass_exports = {};
|
|
31
|
-
__export(entitlementPass_exports, {
|
|
32
|
-
ENTITLEMENT_PASS_TYPE: () => ENTITLEMENT_PASS_TYPE,
|
|
33
|
-
GOOD_PASS_TYPE: () => GOOD_PASS_TYPE,
|
|
34
|
-
compareEntitlementPassPriority: () => compareEntitlementPassPriority,
|
|
35
|
-
getRemainingEntitlementUses: () => getRemainingEntitlementUses,
|
|
36
|
-
hasAvailableEntitlementUses: () => hasAvailableEntitlementUses,
|
|
37
|
-
isEntitlementPass: () => isEntitlementPass,
|
|
38
|
-
isFullCoveragePass: () => isFullCoveragePass,
|
|
39
|
-
resolveEntitlementQuota: () => resolveEntitlementQuota
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(entitlementPass_exports);
|
|
42
|
-
var import_dayjs = __toESM(require("dayjs"));
|
|
43
|
-
var ENTITLEMENT_PASS_TYPE = "entitlement_pass";
|
|
44
|
-
var GOOD_PASS_TYPE = "good_pass";
|
|
45
|
-
function getDiscountType(discount) {
|
|
46
|
-
const nestedDiscount = discount == null ? void 0 : discount.discount;
|
|
47
|
-
return String(
|
|
48
|
-
(discount == null ? void 0 : discount.tag) || (discount == null ? void 0 : discount.type) || (nestedDiscount == null ? void 0 : nestedDiscount.tag) || (nestedDiscount == null ? void 0 : nestedDiscount.type) || ""
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
function isEntitlementPass(discount) {
|
|
52
|
-
return getDiscountType(discount) === ENTITLEMENT_PASS_TYPE;
|
|
53
|
-
}
|
|
54
|
-
function isFullCoveragePass(discount) {
|
|
55
|
-
const type = getDiscountType(discount);
|
|
56
|
-
return type === GOOD_PASS_TYPE || type === ENTITLEMENT_PASS_TYPE;
|
|
57
|
-
}
|
|
58
|
-
function resolveIncludedUses(discount) {
|
|
59
|
-
var _a;
|
|
60
|
-
const metadata = discount.metadata;
|
|
61
|
-
const hasMetadataIncludedUses = !!metadata && typeof metadata === "object" && Object.prototype.hasOwnProperty.call(metadata, "included_uses");
|
|
62
|
-
const rawValue = hasMetadataIncludedUses ? metadata == null ? void 0 : metadata.included_uses : Array.isArray(discount.extension_data) ? (_a = discount.extension_data.find(
|
|
63
|
-
(item) => (item == null ? void 0 : item.field_key) === "included_uses"
|
|
64
|
-
)) == null ? void 0 : _a.value : void 0;
|
|
65
|
-
if (!rawValue || typeof rawValue !== "object" || Array.isArray(rawValue)) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
const includedUses = rawValue;
|
|
69
|
-
if (includedUses.type === "unlimited" && includedUses.value === null) {
|
|
70
|
-
return { type: "unlimited", value: null };
|
|
71
|
-
}
|
|
72
|
-
if (includedUses.type === "limited" && typeof includedUses.value === "number" && Number.isInteger(includedUses.value) && includedUses.value >= 1 && includedUses.value <= 9999) {
|
|
73
|
-
return { type: "limited", value: includedUses.value };
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
function resolveNonNegativeInteger(value) {
|
|
78
|
-
if (typeof value !== "number" && typeof value !== "string" || typeof value === "string" && value.trim() === "") {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
const normalizedValue = Number(value);
|
|
82
|
-
if (!Number.isInteger(normalizedValue) || normalizedValue < 0)
|
|
83
|
-
return null;
|
|
84
|
-
return normalizedValue;
|
|
85
|
-
}
|
|
86
|
-
function resolveEntitlementQuota(discount) {
|
|
87
|
-
if (!isEntitlementPass(discount))
|
|
88
|
-
return null;
|
|
89
|
-
const includedUses = resolveIncludedUses(discount);
|
|
90
|
-
if (!includedUses)
|
|
91
|
-
return null;
|
|
92
|
-
if (includedUses.type === "unlimited") {
|
|
93
|
-
return { type: "unlimited", value: null, balance: null };
|
|
94
|
-
}
|
|
95
|
-
const balance = resolveNonNegativeInteger(discount == null ? void 0 : discount.balance);
|
|
96
|
-
if (balance === null)
|
|
97
|
-
return null;
|
|
98
|
-
return {
|
|
99
|
-
type: "limited",
|
|
100
|
-
value: includedUses.value,
|
|
101
|
-
balance
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function getRemainingEntitlementUses(discount, usedCount, requestedCount) {
|
|
105
|
-
const quota = resolveEntitlementQuota(discount);
|
|
106
|
-
const normalizedRequestedCount = Math.max(
|
|
107
|
-
Math.floor(Number(requestedCount) || 0),
|
|
108
|
-
0
|
|
109
|
-
);
|
|
110
|
-
if (!quota || normalizedRequestedCount <= 0)
|
|
111
|
-
return 0;
|
|
112
|
-
if (quota.type === "unlimited")
|
|
113
|
-
return normalizedRequestedCount;
|
|
114
|
-
const normalizedUsedCount = Math.max(Math.floor(Number(usedCount) || 0), 0);
|
|
115
|
-
return Math.min(
|
|
116
|
-
Math.max(quota.balance - normalizedUsedCount, 0),
|
|
117
|
-
normalizedRequestedCount
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
function hasAvailableEntitlementUses(discount) {
|
|
121
|
-
const quota = resolveEntitlementQuota(discount);
|
|
122
|
-
return !!quota && (quota.type === "unlimited" || quota.balance > 0);
|
|
123
|
-
}
|
|
124
|
-
function resolveExpireTimestamp(value) {
|
|
125
|
-
if (typeof value !== "string" || !value.trim())
|
|
126
|
-
return Number.POSITIVE_INFINITY;
|
|
127
|
-
const normalizedValue = value.trim();
|
|
128
|
-
const calendarParts = normalizedValue.match(
|
|
129
|
-
/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/
|
|
130
|
-
);
|
|
131
|
-
if (calendarParts) {
|
|
132
|
-
const [, year, month, day, hour = "0", minute = "0", second = "0"] = calendarParts;
|
|
133
|
-
const yearNumber = Number(year);
|
|
134
|
-
const monthNumber = Number(month);
|
|
135
|
-
const dayNumber = Number(day);
|
|
136
|
-
const hourNumber = Number(hour);
|
|
137
|
-
const minuteNumber = Number(minute);
|
|
138
|
-
const secondNumber = Number(second);
|
|
139
|
-
const daysInMonth = new Date(
|
|
140
|
-
Date.UTC(yearNumber, monthNumber, 0)
|
|
141
|
-
).getUTCDate();
|
|
142
|
-
if (yearNumber <= 0 || monthNumber < 1 || monthNumber > 12 || dayNumber < 1 || dayNumber > daysInMonth || hourNumber < 0 || hourNumber > 23 || minuteNumber < 0 || minuteNumber > 59 || secondNumber < 0 || secondNumber > 59) {
|
|
143
|
-
return Number.POSITIVE_INFINITY;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const date = (0, import_dayjs.default)(normalizedValue);
|
|
147
|
-
return date.isValid() ? date.valueOf() : Number.POSITIVE_INFINITY;
|
|
148
|
-
}
|
|
149
|
-
function compareIds(left, right) {
|
|
150
|
-
const leftNumber = Number(left);
|
|
151
|
-
const rightNumber = Number(right);
|
|
152
|
-
if (Number.isFinite(leftNumber) && Number.isFinite(rightNumber)) {
|
|
153
|
-
return leftNumber - rightNumber;
|
|
154
|
-
}
|
|
155
|
-
return String(left ?? "").localeCompare(String(right ?? ""), void 0, {
|
|
156
|
-
numeric: true
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
function compareEntitlementPassPriority(left, right) {
|
|
160
|
-
const expireDifference = resolveExpireTimestamp(left.expire_time) - resolveExpireTimestamp(right.expire_time);
|
|
161
|
-
if (!Number.isNaN(expireDifference) && expireDifference !== 0) {
|
|
162
|
-
return expireDifference;
|
|
163
|
-
}
|
|
164
|
-
const leftQuota = resolveEntitlementQuota(left);
|
|
165
|
-
const rightQuota = resolveEntitlementQuota(right);
|
|
166
|
-
const leftBalance = (leftQuota == null ? void 0 : leftQuota.type) === "limited" ? leftQuota.balance : Number.POSITIVE_INFINITY;
|
|
167
|
-
const rightBalance = (rightQuota == null ? void 0 : rightQuota.type) === "limited" ? rightQuota.balance : Number.POSITIVE_INFINITY;
|
|
168
|
-
const balanceDifference = leftBalance - rightBalance;
|
|
169
|
-
if (!Number.isNaN(balanceDifference) && balanceDifference !== 0) {
|
|
170
|
-
return balanceDifference;
|
|
171
|
-
}
|
|
172
|
-
return compareIds(left.id, right.id);
|
|
173
|
-
}
|
|
174
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
175
|
-
0 && (module.exports = {
|
|
176
|
-
ENTITLEMENT_PASS_TYPE,
|
|
177
|
-
GOOD_PASS_TYPE,
|
|
178
|
-
compareEntitlementPassPriority,
|
|
179
|
-
getRemainingEntitlementUses,
|
|
180
|
-
hasAvailableEntitlementUses,
|
|
181
|
-
isEntitlementPass,
|
|
182
|
-
isFullCoveragePass,
|
|
183
|
-
resolveEntitlementQuota
|
|
184
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Discount } from './types';
|
|
2
|
-
export declare function hasEntitlementDiscount(product: any): boolean;
|
|
3
|
-
export declare function isPersistedEntitlementLine(product: any, mappedProduct?: any): boolean;
|
|
4
|
-
/** Refresh authoritative balances while retaining the user's scan/selection state. */
|
|
5
|
-
export declare function mergeEntitlementDiscountLists(current: Discount[], incoming: Discount[], observed?: Discount[]): Discount[];
|
|
6
|
-
export declare function retainScannedEntitlements(current: Discount[], scanned: Discount[]): Discount[];
|
|
7
|
-
/** Historical uses are display records; backend balance already excludes them. */
|
|
8
|
-
export declare function withCommittedEntitlementDetails(discounts: Discount[], products: any[], getProduct: (item: any) => any): Discount[];
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/modules/Discount/entitlementState.ts
|
|
30
|
-
var entitlementState_exports = {};
|
|
31
|
-
__export(entitlementState_exports, {
|
|
32
|
-
hasEntitlementDiscount: () => hasEntitlementDiscount,
|
|
33
|
-
isPersistedEntitlementLine: () => isPersistedEntitlementLine,
|
|
34
|
-
mergeEntitlementDiscountLists: () => mergeEntitlementDiscountLists,
|
|
35
|
-
retainScannedEntitlements: () => retainScannedEntitlements,
|
|
36
|
-
withCommittedEntitlementDetails: () => withCommittedEntitlementDetails
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(entitlementState_exports);
|
|
39
|
-
var import_lodash_es = require("lodash-es");
|
|
40
|
-
var import_decimal = __toESM(require("decimal.js"));
|
|
41
|
-
var import_availability = require("./availability");
|
|
42
|
-
var import_entitlementPass = require("./entitlementPass");
|
|
43
|
-
function getEntitlementDiscountLines(product) {
|
|
44
|
-
var _a, _b, _c, _d;
|
|
45
|
-
const nested = ((_a = product == null ? void 0 : product._origin) == null ? void 0 : _a.product) ?? ((_b = product == null ? void 0 : product._originData) == null ? void 0 : _b.product);
|
|
46
|
-
return [
|
|
47
|
-
{ discount_list: (product == null ? void 0 : product.discount_list) ?? (nested == null ? void 0 : nested.discount_list) ?? [] },
|
|
48
|
-
...(product == null ? void 0 : product.product_bundle) ?? (product == null ? void 0 : product.bundle) ?? ((_d = (_c = product == null ? void 0 : product._extend) == null ? void 0 : _c.other) == null ? void 0 : _d.bundle) ?? (nested == null ? void 0 : nested.product_bundle) ?? []
|
|
49
|
-
];
|
|
50
|
-
}
|
|
51
|
-
function hasEntitlementDiscount(product) {
|
|
52
|
-
return getEntitlementDiscountLines(product).some((line) => (line.discount_list || []).some(import_entitlementPass.isEntitlementPass));
|
|
53
|
-
}
|
|
54
|
-
function isPersistedEntitlementLine(product, mappedProduct) {
|
|
55
|
-
var _a, _b, _c, _d, _e, _f;
|
|
56
|
-
const nested = ((_a = product == null ? void 0 : product._origin) == null ? void 0 : _a.product) ?? ((_b = product == null ? void 0 : product._originData) == null ? void 0 : _b.product);
|
|
57
|
-
const persisted = [
|
|
58
|
-
product == null ? void 0 : product.order_detail_id,
|
|
59
|
-
product == null ? void 0 : product.booking_id,
|
|
60
|
-
(_c = product == null ? void 0 : product._origin) == null ? void 0 : _c.booking_id,
|
|
61
|
-
(_d = product == null ? void 0 : product._originData) == null ? void 0 : _d.booking_id,
|
|
62
|
-
(_e = product == null ? void 0 : product._extend) == null ? void 0 : _e.order_detail_id,
|
|
63
|
-
nested == null ? void 0 : nested.order_detail_id,
|
|
64
|
-
nested == null ? void 0 : nested.booking_id,
|
|
65
|
-
mappedProduct == null ? void 0 : mappedProduct.order_detail_id,
|
|
66
|
-
mappedProduct == null ? void 0 : mappedProduct.booking_id
|
|
67
|
-
].some((value) => value !== void 0 && value !== null && value !== "" && value !== 0 && value !== "0");
|
|
68
|
-
const lines = getEntitlementDiscountLines(mappedProduct ?? product);
|
|
69
|
-
return lines.some((line) => (line.discount_list || []).some(import_entitlementPass.isEntitlementPass)) && (persisted && ((_f = product == null ? void 0 : product.metadata) == null ? void 0 : _f.entitlement_source_identity) == null || lines.some(
|
|
70
|
-
(line) => (line.discount_list || []).some((item) => (0, import_entitlementPass.isEntitlementPass)(item) && item.id)
|
|
71
|
-
));
|
|
72
|
-
}
|
|
73
|
-
function mergeEntitlementDiscountLists(current, incoming, observed = incoming) {
|
|
74
|
-
const previous = new Map(current.map((item) => [String(item.id), item]));
|
|
75
|
-
const observedById = new Map(observed.map((item) => [String(item.id), item]));
|
|
76
|
-
const next = /* @__PURE__ */ new Map();
|
|
77
|
-
current.filter((item) => item.isScan).forEach((item) => {
|
|
78
|
-
const fresh = observedById.get(String(item.id));
|
|
79
|
-
if ((0, import_entitlementPass.isEntitlementPass)(item) && (0, import_availability.getDiscountLifecycleReason)(fresh || item))
|
|
80
|
-
return;
|
|
81
|
-
next.set(String(item.id), item);
|
|
82
|
-
});
|
|
83
|
-
incoming.forEach((item) => {
|
|
84
|
-
const old = previous.get(String(item.id));
|
|
85
|
-
if ((old == null ? void 0 : old.isScan) && !(0, import_entitlementPass.isEntitlementPass)(item))
|
|
86
|
-
return;
|
|
87
|
-
next.set(String(item.id), old && (0, import_entitlementPass.isEntitlementPass)(item) ? {
|
|
88
|
-
...item,
|
|
89
|
-
isScan: old.isScan,
|
|
90
|
-
isSelected: old.isSelected,
|
|
91
|
-
isManualSelect: old.isManualSelect
|
|
92
|
-
} : item);
|
|
93
|
-
});
|
|
94
|
-
return [...next.values()];
|
|
95
|
-
}
|
|
96
|
-
function retainScannedEntitlements(current, scanned) {
|
|
97
|
-
const result = new Map(current.map((item) => [String(item.id), item]));
|
|
98
|
-
scanned.filter((item) => (0, import_entitlementPass.isEntitlementPass)(item) && !(0, import_availability.getDiscountLifecycleReason)(item)).forEach((item) => {
|
|
99
|
-
const previous = result.get(String(item.id));
|
|
100
|
-
const committed = item.committedAppliedProductDetails || (previous == null ? void 0 : previous.committedAppliedProductDetails) || [];
|
|
101
|
-
const isAvailable = !!item.isAvailable;
|
|
102
|
-
result.set(String(item.id), {
|
|
103
|
-
...item,
|
|
104
|
-
isScan: true,
|
|
105
|
-
isAvailable,
|
|
106
|
-
isSelected: committed.length > 0,
|
|
107
|
-
reasonCode: isAvailable ? void 0 : item.reasonCode || "product_not_applicable",
|
|
108
|
-
committedAppliedProductDetails: committed,
|
|
109
|
-
appliedProductDetails: committed,
|
|
110
|
-
savedAmount: committed.length ? previous == null ? void 0 : previous.savedAmount : 0
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
return [...result.values()];
|
|
114
|
-
}
|
|
115
|
-
function withCommittedEntitlementDetails(discounts, products, getProduct) {
|
|
116
|
-
var _a, _b, _c, _d, _e;
|
|
117
|
-
const savedAmount = (details) => details.reduce((sum, detail) => {
|
|
118
|
-
var _a2;
|
|
119
|
-
return sum.plus(new import_decimal.default(((_a2 = detail.discount) == null ? void 0 : _a2.fixed_amount) || 0).times(detail._num));
|
|
120
|
-
}, new import_decimal.default(0)).toNumber();
|
|
121
|
-
const committed = /* @__PURE__ */ new Map();
|
|
122
|
-
for (const origin of products) {
|
|
123
|
-
const product = getProduct(origin);
|
|
124
|
-
const persisted = isPersistedEntitlementLine(origin, product);
|
|
125
|
-
const lines = [product, ...product.bundle || []];
|
|
126
|
-
const bundleKeys = new Set((product.bundle || []).flatMap(
|
|
127
|
-
(line) => (line.discount_list || []).map((detail) => {
|
|
128
|
-
var _a2, _b2;
|
|
129
|
-
return `${((_a2 = detail.discount) == null ? void 0 : _a2.resource_id) ?? detail.id}:${(_b2 = detail.metadata) == null ? void 0 : _b2.custom_product_bundle_map_id}`;
|
|
130
|
-
})
|
|
131
|
-
));
|
|
132
|
-
for (const line of lines) {
|
|
133
|
-
for (const detail of line.discount_list || []) {
|
|
134
|
-
const bundleId = (_a = detail.metadata) == null ? void 0 : _a.custom_product_bundle_map_id;
|
|
135
|
-
if (!(0, import_entitlementPass.isEntitlementPass)(detail) || !persisted && !detail.id || line === product && bundleId && bundleKeys.has(`${((_b = detail.discount) == null ? void 0 : _b.resource_id) ?? detail.id}:${bundleId}`))
|
|
136
|
-
continue;
|
|
137
|
-
const id = ((_c = detail.discount) == null ? void 0 : _c.resource_id) ?? detail.resource_id ?? detail.id;
|
|
138
|
-
if (id == null)
|
|
139
|
-
continue;
|
|
140
|
-
const lineUses = Number(((_d = detail.metadata) == null ? void 0 : _d.num) ?? line.num ?? line.quantity ?? 1);
|
|
141
|
-
if (!Number.isFinite(lineUses) || lineUses <= 0)
|
|
142
|
-
continue;
|
|
143
|
-
const count = lineUses * (line === product && !bundleId ? 1 : Number(product.quantity ?? product.num ?? 1));
|
|
144
|
-
const list = committed.get(String(id)) || [];
|
|
145
|
-
list.push({
|
|
146
|
-
...(0, import_lodash_es.cloneDeep)(detail),
|
|
147
|
-
_num: count,
|
|
148
|
-
metadata: { ...detail.metadata, num: count },
|
|
149
|
-
discount: {
|
|
150
|
-
...detail.discount,
|
|
151
|
-
fixed_amount: ((_e = detail.discount) == null ? void 0 : _e.fixed_amount) ?? new import_decimal.default(detail.amount || 0).div(bundleId ? lineUses : 1).toNumber()
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
committed.set(String(id), list);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const next = discounts.map((item) => {
|
|
159
|
-
if (!(0, import_entitlementPass.isEntitlementPass)(item))
|
|
160
|
-
return item;
|
|
161
|
-
const details = committed.get(String(item.id)) || [];
|
|
162
|
-
committed.delete(String(item.id));
|
|
163
|
-
return {
|
|
164
|
-
...item,
|
|
165
|
-
committedAppliedProductDetails: details,
|
|
166
|
-
isEditMode: details.length > 0 && !(0, import_entitlementPass.resolveEntitlementQuota)(item),
|
|
167
|
-
...item.isEditMode && (0, import_entitlementPass.resolveEntitlementQuota)(item) ? { isDisabled: false } : {},
|
|
168
|
-
...details.length && !(0, import_entitlementPass.resolveEntitlementQuota)(item) ? {
|
|
169
|
-
isSelected: true,
|
|
170
|
-
isDisabled: true,
|
|
171
|
-
isUsed: true,
|
|
172
|
-
appliedProductDetails: details,
|
|
173
|
-
savedAmount: savedAmount(details)
|
|
174
|
-
} : {}
|
|
175
|
-
};
|
|
176
|
-
});
|
|
177
|
-
committed.forEach((details, id) => {
|
|
178
|
-
var _a2;
|
|
179
|
-
const first = details[0];
|
|
180
|
-
next.push({
|
|
181
|
-
...first,
|
|
182
|
-
id: Number(id),
|
|
183
|
-
tag: "entitlement_pass",
|
|
184
|
-
type: "entitlement_pass",
|
|
185
|
-
format_title: (_a2 = first.discount) == null ? void 0 : _a2.title,
|
|
186
|
-
isEditMode: true,
|
|
187
|
-
isSelected: true,
|
|
188
|
-
isDisabled: true,
|
|
189
|
-
isUsed: true,
|
|
190
|
-
isAvailable: true,
|
|
191
|
-
committedAppliedProductDetails: details,
|
|
192
|
-
appliedProductDetails: details,
|
|
193
|
-
applicableProductDetails: [],
|
|
194
|
-
savedAmount: savedAmount(details)
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
return next;
|
|
198
|
-
}
|
|
199
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
200
|
-
0 && (module.exports = {
|
|
201
|
-
hasEntitlementDiscount,
|
|
202
|
-
isPersistedEntitlementLine,
|
|
203
|
-
mergeEntitlementDiscountLists,
|
|
204
|
-
retainScannedEntitlements,
|
|
205
|
-
withCommittedEntitlementDetails
|
|
206
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { RulesParamsHooks } from './types';
|
|
2
|
-
export declare function isEntitlementRuntimeLine(product: any, mappedProduct?: any): boolean;
|
|
3
|
-
/** 仅同步本次多次卡行的数量与价格,沿用 Rules 的主商品、套餐计算结果。 */
|
|
4
|
-
export declare function rebuildEntitlementLine(origin: any, bundle: any[], hooks: RulesParamsHooks, count?: number): any;
|
|
5
|
-
/** 重算只还原本次多次卡;套餐和多 Holder 按父商品份数计算,不再合并商品行。 */
|
|
6
|
-
export declare function prepareEntitlementLines(products: any[], hooks: RulesParamsHooks, canUseEntitlement: (product: any) => boolean): any[];
|
|
7
|
-
/** 客户端钩子可能保留原 _id,只给新增的重复行补标识,保留拆分结果。 */
|
|
8
|
-
export declare function finalizeEntitlementLines(products: any[], hooks: RulesParamsHooks): any[];
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/modules/Rules/entitlementLines.ts
|
|
30
|
-
var entitlementLines_exports = {};
|
|
31
|
-
__export(entitlementLines_exports, {
|
|
32
|
-
finalizeEntitlementLines: () => finalizeEntitlementLines,
|
|
33
|
-
isEntitlementRuntimeLine: () => isEntitlementRuntimeLine,
|
|
34
|
-
prepareEntitlementLines: () => prepareEntitlementLines,
|
|
35
|
-
rebuildEntitlementLine: () => rebuildEntitlementLine
|
|
36
|
-
});
|
|
37
|
-
module.exports = __toCommonJS(entitlementLines_exports);
|
|
38
|
-
var import_lodash_es = require("lodash-es");
|
|
39
|
-
var import_decimal = __toESM(require("decimal.js"));
|
|
40
|
-
var import_entitlementPass = require("../Discount/entitlementPass");
|
|
41
|
-
var import_entitlementState = require("../Discount/entitlementState");
|
|
42
|
-
var SOURCE = "entitlement_source_identity";
|
|
43
|
-
function isManualDiscount(data) {
|
|
44
|
-
var _a;
|
|
45
|
-
return data.isManualDiscount ?? (data.total != data.origin_total && (data.bundle || []).every((item) => {
|
|
46
|
-
var _a2;
|
|
47
|
-
return !((_a2 = item.discount_list) == null ? void 0 : _a2.length);
|
|
48
|
-
}) && (!((_a = data.discount_list) == null ? void 0 : _a.length) || data.discount_list.every((item) => item.type === "product")));
|
|
49
|
-
}
|
|
50
|
-
function isEntitlementRuntimeLine(product, mappedProduct) {
|
|
51
|
-
var _a;
|
|
52
|
-
return ((_a = product.metadata) == null ? void 0 : _a[SOURCE]) != null && !(0, import_entitlementState.isPersistedEntitlementLine)(product, mappedProduct) && !isManualDiscount(mappedProduct ?? product);
|
|
53
|
-
}
|
|
54
|
-
function rebuildEntitlementLine(origin, bundle, hooks, count) {
|
|
55
|
-
const data = hooks.getProduct(origin);
|
|
56
|
-
const quantity = count ?? data.quantity ?? data.num ?? 1;
|
|
57
|
-
const discounts = (data.discount_list || []).map(
|
|
58
|
-
(item) => {
|
|
59
|
-
var _a;
|
|
60
|
-
return (0, import_entitlementPass.isEntitlementPass)(item) && !((_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) ? { ...item, _num: quantity, metadata: { ...item.metadata, num: quantity } } : item;
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
const mainDiscount = discounts.filter((item) => {
|
|
64
|
-
var _a;
|
|
65
|
-
return !((_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
|
|
66
|
-
}).reduce((sum, item) => sum.plus(item.amount || 0), new import_decimal.default(0));
|
|
67
|
-
const originalPrice = new import_decimal.default(data.original_price ?? data.price ?? 0);
|
|
68
|
-
const sourceSellingPrice = originalPrice.minus(mainDiscount).toNumber();
|
|
69
|
-
const optionPrice = (data.options || []).reduce((sum, item) => sum.plus(new import_decimal.default(item.price || 0).times(item.num || 0)), new import_decimal.default(0));
|
|
70
|
-
const bundleTotal = bundle.reduce((sum, item) => sum.plus(new import_decimal.default(item.price || 0).times(item.num || 1)), new import_decimal.default(0));
|
|
71
|
-
const bundleOriginalTotal = bundle.reduce((sum, item) => sum.plus(new import_decimal.default(item.original_price ?? item.price ?? 0).times(item.num || 1)), new import_decimal.default(0));
|
|
72
|
-
return hooks.setProduct(origin, {
|
|
73
|
-
quantity,
|
|
74
|
-
discount_list: discounts,
|
|
75
|
-
bundle,
|
|
76
|
-
price: sourceSellingPrice,
|
|
77
|
-
main_product_selling_price: sourceSellingPrice,
|
|
78
|
-
total: new import_decimal.default(sourceSellingPrice).plus(optionPrice).plus(bundleTotal).toNumber(),
|
|
79
|
-
origin_total: originalPrice.plus(optionPrice).plus(bundleOriginalTotal).toNumber()
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function setLineIdentity(row, id) {
|
|
83
|
-
row._id = id;
|
|
84
|
-
row.metadata = { ...row.metadata, unique_identification_number: id };
|
|
85
|
-
if (row._extend)
|
|
86
|
-
row._extend.unique_identification_number = id;
|
|
87
|
-
return row;
|
|
88
|
-
}
|
|
89
|
-
function prepareEntitlementLines(products, hooks, canUseEntitlement) {
|
|
90
|
-
return products.flatMap((original) => {
|
|
91
|
-
var _a, _b, _c, _d;
|
|
92
|
-
const data = hooks.getProduct(original);
|
|
93
|
-
if ((0, import_entitlementState.isPersistedEntitlementLine)(original, data) || isManualDiscount(data))
|
|
94
|
-
return [original];
|
|
95
|
-
const applicable = canUseEntitlement(original);
|
|
96
|
-
if (!((_a = original.metadata) == null ? void 0 : _a[SOURCE]) && !(0, import_entitlementState.hasEntitlementDiscount)(data) && !applicable)
|
|
97
|
-
return [original];
|
|
98
|
-
const origin = (0, import_lodash_es.cloneDeep)(original);
|
|
99
|
-
origin.metadata = { ...origin.metadata, [SOURCE]: ((_b = origin.metadata) == null ? void 0 : _b[SOURCE]) ?? data._id };
|
|
100
|
-
const bundle = (data.bundle || []).map((item) => {
|
|
101
|
-
var _a2;
|
|
102
|
-
const entitlement = (item.discount_list || []).find(import_entitlementPass.isEntitlementPass);
|
|
103
|
-
if (!entitlement)
|
|
104
|
-
return item;
|
|
105
|
-
const discounts = (item.discount_list || []).filter((discount) => !(0, import_entitlementPass.isEntitlementPass)(discount));
|
|
106
|
-
const originalPrice = item.original_price ?? ((_a2 = entitlement.discount) == null ? void 0 : _a2.original_amount) ?? item.product_price ?? item.price ?? 0;
|
|
107
|
-
const amount = discounts.reduce((sum, discount) => sum.plus(discount.amount || 0), new import_decimal.default(0));
|
|
108
|
-
const price = new import_decimal.default(originalPrice).minus(amount.div(item.num || 1)).toNumber();
|
|
109
|
-
return { ...item, original_price: originalPrice, price, bundle_selling_price: price, discount_list: discounts };
|
|
110
|
-
});
|
|
111
|
-
const mainEntitlement = (_c = data.discount_list) == null ? void 0 : _c.find(import_entitlementPass.isEntitlementPass);
|
|
112
|
-
const restored = hooks.setProduct(origin, {
|
|
113
|
-
original_price: data.original_price ?? ((_d = mainEntitlement == null ? void 0 : mainEntitlement.discount) == null ? void 0 : _d.original_amount) ?? data.price,
|
|
114
|
-
discount_list: (data.discount_list || []).filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item)),
|
|
115
|
-
bundle
|
|
116
|
-
});
|
|
117
|
-
const row = rebuildEntitlementLine(restored, bundle, hooks);
|
|
118
|
-
const count = Math.max(1, Math.floor(Number(data.quantity || data.num || 1)));
|
|
119
|
-
if (!applicable || count <= 1 || !bundle.length && !Array.isArray(data.holder_id))
|
|
120
|
-
return [row];
|
|
121
|
-
return Array.from({ length: count }, (_, index) => {
|
|
122
|
-
var _a2, _b2;
|
|
123
|
-
const unit = (0, import_lodash_es.cloneDeep)(row);
|
|
124
|
-
for (const source of [unit, unit._extend]) {
|
|
125
|
-
if (Array.isArray(source == null ? void 0 : source.holder_id))
|
|
126
|
-
source.holder_id = source.holder_id.slice(index, index + 1);
|
|
127
|
-
}
|
|
128
|
-
if (Array.isArray((_b2 = (_a2 = unit._origin) == null ? void 0 : _a2.holder) == null ? void 0 : _b2.form_record)) {
|
|
129
|
-
const records = unit._origin.holder.form_record;
|
|
130
|
-
if (records.length > 1)
|
|
131
|
-
unit._origin.holder.form_record = records.slice(index, index + 1);
|
|
132
|
-
}
|
|
133
|
-
return setLineIdentity(rebuildEntitlementLine(unit, hooks.getProduct(unit).bundle || [], hooks, 1), `${data._id}:entitlement-unit:${index}`);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
function finalizeEntitlementLines(products, hooks) {
|
|
138
|
-
const runtime = (item) => isEntitlementRuntimeLine(item, hooks.getProduct(item));
|
|
139
|
-
const seen = new Set(products.filter((item) => !runtime(item)).map((item) => String(item._id)));
|
|
140
|
-
return products.map((origin, index) => {
|
|
141
|
-
if (!runtime(origin))
|
|
142
|
-
return origin;
|
|
143
|
-
const base = String(origin._id ?? hooks.getProduct(origin)._id);
|
|
144
|
-
let id = base;
|
|
145
|
-
let ordinal = index;
|
|
146
|
-
while (seen.has(id))
|
|
147
|
-
id = `${base}:entitlement-split:${ordinal++}`;
|
|
148
|
-
seen.add(id);
|
|
149
|
-
return id === String(origin._id) ? origin : setLineIdentity((0, import_lodash_es.cloneDeep)(origin), id);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
153
|
-
0 && (module.exports = {
|
|
154
|
-
finalizeEntitlementLines,
|
|
155
|
-
isEntitlementRuntimeLine,
|
|
156
|
-
prepareEntitlementLines,
|
|
157
|
-
rebuildEntitlementLine
|
|
158
|
-
});
|