@pisell/pisellos 2.1.172 → 2.1.174
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/apis/picoding.d.ts +0 -0
- package/dist/apis/picoding.js +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/model/strategy/adapter/promotion/evaluator.js +26 -99
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -2
- package/dist/model/strategy/adapter/walletPass/evaluator.js +12 -63
- package/dist/model/strategy/adapter/walletPass/locales.js +3 -12
- package/dist/model/strategy/engine.d.ts +5 -18
- package/dist/model/strategy/engine.js +45 -145
- package/dist/model/strategy/type.d.ts +0 -17
- package/dist/model/strategy/type.js +0 -4
- package/dist/modules/Cart/types.d.ts +0 -2
- package/dist/modules/Cart/utils/cartProduct.js +25 -56
- package/dist/modules/Cart/utils/changePrice.js +16 -9
- package/dist/modules/Discount/availability.d.ts +7 -0
- package/dist/modules/Discount/availability.js +52 -0
- package/dist/modules/Discount/entitlementPass.d.ts +34 -0
- package/dist/modules/Discount/entitlementPass.js +147 -0
- package/dist/modules/Discount/entitlementState.d.ts +8 -0
- package/dist/modules/Discount/entitlementState.js +205 -0
- package/dist/modules/Discount/index.d.ts +12 -3
- package/dist/modules/Discount/index.js +211 -17
- package/dist/modules/Discount/types.d.ts +42 -22
- package/dist/modules/Holder/index.d.ts +48 -0
- package/dist/modules/Holder/index.js +640 -0
- package/dist/modules/Holder/types.d.ts +123 -0
- package/dist/modules/Holder/types.js +1 -0
- package/dist/modules/Holder/utils.d.ts +13 -0
- package/dist/modules/Holder/utils.js +34 -0
- package/dist/modules/OpenData/index.d.ts +24 -0
- package/dist/modules/OpenData/index.js +173 -0
- package/dist/modules/OpenData/types.d.ts +73 -0
- package/dist/modules/OpenData/types.js +1 -0
- package/dist/modules/OpenData/utils.d.ts +2 -0
- package/dist/modules/OpenData/utils.js +75 -0
- package/dist/modules/Order/index.d.ts +67 -1
- package/dist/modules/Order/index.js +923 -30
- package/dist/modules/Order/types.d.ts +176 -12
- package/dist/modules/Order/types.js +2 -0
- package/dist/modules/Order/utils.d.ts +128 -0
- package/dist/modules/Order/utils.js +621 -5
- package/dist/modules/Payment/index.d.ts +1 -2
- package/dist/modules/Payment/index.js +7 -10
- package/dist/modules/Payment/utils.js +0 -3
- package/dist/modules/Payment/walletpass.d.ts +0 -23
- package/dist/modules/Payment/walletpass.js +95 -191
- package/dist/modules/Product/types.d.ts +7 -0
- package/dist/modules/Product/utils.js +2 -2
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +4 -3
- package/dist/modules/Quotation/index.d.ts +48 -0
- package/dist/modules/Quotation/index.js +248 -0
- package/dist/modules/Quotation/types.d.ts +42 -0
- package/dist/modules/Quotation/types.js +1 -0
- package/dist/modules/Rules/entitlementLines.d.ts +8 -0
- package/dist/modules/Rules/entitlementLines.js +157 -0
- package/dist/modules/Rules/index.d.ts +17 -11
- package/dist/modules/Rules/index.js +495 -726
- package/dist/modules/Rules/types.d.ts +2 -4
- package/dist/modules/SalesSummary/index.d.ts +63 -0
- package/dist/modules/SalesSummary/index.js +174 -0
- package/dist/modules/SalesSummary/types.d.ts +60 -0
- package/dist/modules/SalesSummary/types.js +1 -0
- package/dist/modules/SalesSummary/utils.d.ts +30 -0
- package/dist/modules/SalesSummary/utils.js +480 -0
- package/dist/modules/ScanOrderLogger/index.d.ts +23 -0
- package/dist/modules/ScanOrderLogger/index.js +174 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.js +221 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
- package/dist/modules/ScanOrderLogger/types.d.ts +53 -0
- package/dist/modules/ScanOrderLogger/types.js +1 -0
- package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
- package/dist/modules/Schedule/utils.d.ts +1 -1
- package/dist/modules/Summary/types.d.ts +0 -2
- package/dist/modules/Summary/utils.d.ts +3 -9
- package/dist/modules/Summary/utils.js +67 -57
- package/dist/modules/index.d.ts +5 -0
- package/dist/modules/index.js +6 -1
- package/dist/plugins/window.d.ts +3 -2
- package/dist/solution/BookingByStep/index.d.ts +17 -3
- package/dist/solution/BookingByStep/index.js +322 -247
- package/dist/solution/BookingByStep/types.d.ts +4 -1
- package/dist/solution/BookingByStep/types.js +7 -1
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
- package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
- package/dist/solution/Checkout/index.js +0 -2
- package/dist/solution/ScanOrder/index.d.ts +158 -0
- package/dist/solution/ScanOrder/index.js +3474 -0
- package/dist/solution/ScanOrder/types.d.ts +307 -0
- package/dist/solution/ScanOrder/types.js +35 -0
- package/dist/solution/ScanOrder/utils.d.ts +172 -0
- package/dist/solution/ScanOrder/utils.js +796 -0
- package/dist/solution/ShopDiscount/index.d.ts +6 -2
- package/dist/solution/ShopDiscount/index.js +194 -110
- package/dist/solution/ShopDiscount/types.d.ts +1 -1
- package/dist/solution/ShopDiscount/types.js +1 -2
- package/dist/solution/ShopDiscount/utils.d.ts +1 -0
- package/dist/solution/ShopDiscount/utils.js +52 -27
- package/dist/solution/VenueBooking/index.d.ts +225 -0
- package/dist/solution/VenueBooking/index.js +3749 -0
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/dist/solution/VenueBooking/types.d.ts +156 -0
- package/dist/solution/VenueBooking/types.js +21 -0
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
- package/dist/solution/VenueBooking/utils/dateSummary.js +104 -0
- package/dist/solution/VenueBooking/utils/resource.d.ts +14 -0
- package/dist/solution/VenueBooking/utils/resource.js +131 -0
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +239 -0
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/dist/solution/VenueBooking/utils/timeSlot.js +453 -0
- package/dist/solution/VenueBooking/utils.d.ts +1 -0
- package/dist/solution/VenueBooking/utils.js +1 -0
- package/dist/solution/index.d.ts +2 -0
- package/dist/solution/index.js +3 -1
- package/dist/types/index.d.ts +1 -0
- package/lib/apis/picoding.d.ts +0 -0
- package/lib/apis/picoding.js +0 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -3
- package/lib/model/strategy/adapter/promotion/evaluator.js +8 -57
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -2
- package/lib/model/strategy/adapter/walletPass/evaluator.js +7 -36
- package/lib/model/strategy/adapter/walletPass/locales.js +3 -12
- package/lib/model/strategy/engine.d.ts +5 -18
- package/lib/model/strategy/engine.js +21 -85
- package/lib/model/strategy/type.d.ts +0 -17
- package/lib/modules/Cart/types.d.ts +0 -2
- package/lib/modules/Cart/utils/cartProduct.js +12 -39
- package/lib/modules/Cart/utils/changePrice.js +13 -9
- package/lib/modules/Discount/availability.d.ts +7 -0
- package/lib/modules/Discount/availability.js +91 -0
- package/lib/modules/Discount/entitlementPass.d.ts +34 -0
- package/lib/modules/Discount/entitlementPass.js +184 -0
- package/lib/modules/Discount/entitlementState.d.ts +8 -0
- package/lib/modules/Discount/entitlementState.js +206 -0
- package/lib/modules/Discount/index.d.ts +12 -3
- package/lib/modules/Discount/index.js +123 -12
- package/lib/modules/Discount/types.d.ts +42 -22
- package/lib/modules/Holder/index.d.ts +48 -0
- package/lib/modules/Holder/index.js +402 -0
- package/lib/modules/Holder/types.d.ts +123 -0
- package/lib/modules/Holder/types.js +17 -0
- package/lib/modules/Holder/utils.d.ts +13 -0
- package/lib/modules/Holder/utils.js +71 -0
- package/lib/modules/OpenData/index.d.ts +24 -0
- package/lib/modules/OpenData/index.js +119 -0
- package/lib/modules/OpenData/types.d.ts +73 -0
- package/lib/modules/OpenData/types.js +17 -0
- package/lib/modules/OpenData/utils.d.ts +2 -0
- package/lib/modules/OpenData/utils.js +111 -0
- package/lib/modules/Order/index.d.ts +67 -1
- package/lib/modules/Order/index.js +529 -1
- package/lib/modules/Order/types.d.ts +176 -12
- package/lib/modules/Order/utils.d.ts +128 -0
- package/lib/modules/Order/utils.js +514 -2
- package/lib/modules/Payment/index.d.ts +1 -2
- package/lib/modules/Payment/index.js +0 -1
- package/lib/modules/Payment/utils.js +0 -3
- package/lib/modules/Payment/walletpass.d.ts +0 -23
- package/lib/modules/Payment/walletpass.js +17 -94
- package/lib/modules/Product/types.d.ts +7 -0
- package/lib/modules/Product/utils.js +2 -2
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +5 -4
- package/lib/modules/Quotation/index.d.ts +48 -0
- package/lib/modules/Quotation/index.js +152 -0
- package/lib/modules/Quotation/types.d.ts +42 -0
- package/lib/modules/Quotation/types.js +17 -0
- package/lib/modules/Rules/entitlementLines.d.ts +8 -0
- package/lib/modules/Rules/entitlementLines.js +158 -0
- package/lib/modules/Rules/index.d.ts +17 -11
- package/lib/modules/Rules/index.js +548 -798
- package/lib/modules/Rules/types.d.ts +2 -4
- package/lib/modules/SalesSummary/index.d.ts +63 -0
- package/lib/modules/SalesSummary/index.js +105 -0
- package/lib/modules/SalesSummary/types.d.ts +60 -0
- package/lib/modules/SalesSummary/types.js +17 -0
- package/lib/modules/SalesSummary/utils.d.ts +30 -0
- package/lib/modules/SalesSummary/utils.js +420 -0
- package/lib/modules/ScanOrderLogger/index.d.ts +23 -0
- package/lib/modules/ScanOrderLogger/index.js +147 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.js +157 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
- package/lib/modules/ScanOrderLogger/types.d.ts +53 -0
- package/lib/modules/ScanOrderLogger/types.js +17 -0
- package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
- package/lib/modules/Schedule/utils.d.ts +1 -1
- package/lib/modules/Summary/types.d.ts +0 -2
- package/lib/modules/Summary/utils.d.ts +3 -9
- package/lib/modules/Summary/utils.js +45 -34
- package/lib/modules/index.d.ts +5 -0
- package/lib/modules/index.js +11 -1
- package/lib/plugins/window.d.ts +3 -2
- package/lib/solution/BookingByStep/index.d.ts +17 -3
- package/lib/solution/BookingByStep/index.js +45 -4
- package/lib/solution/BookingByStep/types.d.ts +4 -1
- package/lib/solution/BookingByStep/types.js +15 -0
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
- package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
- package/lib/solution/Checkout/index.js +0 -2
- package/lib/solution/ScanOrder/index.d.ts +158 -0
- package/lib/solution/ScanOrder/index.js +2135 -0
- package/lib/solution/ScanOrder/types.d.ts +307 -0
- package/lib/solution/ScanOrder/types.js +36 -0
- package/lib/solution/ScanOrder/utils.d.ts +172 -0
- package/lib/solution/ScanOrder/utils.js +658 -0
- package/lib/solution/ShopDiscount/index.d.ts +6 -2
- package/lib/solution/ShopDiscount/index.js +94 -50
- package/lib/solution/ShopDiscount/types.d.ts +1 -1
- package/lib/solution/ShopDiscount/utils.d.ts +1 -0
- package/lib/solution/ShopDiscount/utils.js +48 -11
- package/lib/solution/VenueBooking/index.d.ts +225 -0
- package/lib/solution/VenueBooking/index.js +2073 -0
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/lib/solution/VenueBooking/types.d.ts +156 -0
- package/lib/solution/VenueBooking/types.js +44 -0
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
- package/lib/solution/VenueBooking/utils/dateSummary.js +110 -0
- package/lib/solution/VenueBooking/utils/resource.d.ts +14 -0
- package/lib/solution/VenueBooking/utils/resource.js +92 -0
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +237 -0
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/lib/solution/VenueBooking/utils/timeSlot.js +339 -0
- package/lib/solution/VenueBooking/utils.d.ts +1 -0
- package/lib/solution/VenueBooking/utils.js +69 -0
- package/lib/solution/index.d.ts +2 -0
- package/lib/solution/index.js +5 -1
- package/lib/types/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,91 @@
|
|
|
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/availability.ts
|
|
30
|
+
var availability_exports = {};
|
|
31
|
+
__export(availability_exports, {
|
|
32
|
+
getDiscountLifecycleReason: () => getDiscountLifecycleReason,
|
|
33
|
+
getDiscountUsageBlockReason: () => getDiscountUsageBlockReason,
|
|
34
|
+
getDiscountUsageLimitFailKey: () => getDiscountUsageLimitFailKey,
|
|
35
|
+
hasAvailableDiscountBalance: () => hasAvailableDiscountBalance
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(availability_exports);
|
|
38
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
39
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
40
|
+
var import_entitlementPass = require("./entitlementPass");
|
|
41
|
+
function getDiscountUsageLimitFailKey(discount) {
|
|
42
|
+
var _a, _b, _c;
|
|
43
|
+
const value = (_b = (_a = discount.extension_data) == null ? void 0 : _a.find(
|
|
44
|
+
(field) => field.field_key === "usage_credits"
|
|
45
|
+
)) == null ? void 0 : _b.value;
|
|
46
|
+
if (!value)
|
|
47
|
+
return null;
|
|
48
|
+
const limits = [
|
|
49
|
+
["total_credits", discount.total_order_behavior_count],
|
|
50
|
+
["per_user_limit", discount.customer_order_behavior_count],
|
|
51
|
+
["max_per_day", discount.today_order_behavior_count],
|
|
52
|
+
["max_per_week", discount.week_order_behavior_count],
|
|
53
|
+
["max_per_month", discount.month_order_behavior_count]
|
|
54
|
+
];
|
|
55
|
+
return ((_c = limits.find(
|
|
56
|
+
([key, count]) => Number(value[key]) > 0 && Number(count || 0) >= Number(value[key])
|
|
57
|
+
)) == null ? void 0 : _c[0]) || null;
|
|
58
|
+
}
|
|
59
|
+
function hasAvailableDiscountBalance(discount) {
|
|
60
|
+
if ((0, import_entitlementPass.isEntitlementPass)(discount))
|
|
61
|
+
return (0, import_entitlementPass.hasAvailableEntitlementUses)(discount);
|
|
62
|
+
return new import_decimal.default(discount.par_value || 0).minus(discount.used_par_value || 0).greaterThan(0);
|
|
63
|
+
}
|
|
64
|
+
function getDiscountLifecycleReason(discount) {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
if (discount.is_franchisor_pass === 1 && ((_a = discount.franchisee_wallet_pass) == null ? void 0 : _a.use) !== "enabled") {
|
|
67
|
+
return "not_shared_at_store";
|
|
68
|
+
}
|
|
69
|
+
if (discount.limit_status && discount.limit_status !== "enable") {
|
|
70
|
+
return "disabled";
|
|
71
|
+
}
|
|
72
|
+
if (((0, import_entitlementPass.isEntitlementPass)(discount) || discount.par_value != null) && !hasAvailableDiscountBalance(discount) || getDiscountUsageLimitFailKey(discount) === "total_credits") {
|
|
73
|
+
return "exhausted";
|
|
74
|
+
}
|
|
75
|
+
if (((_b = discount.metadata) == null ? void 0 : _b.validity_type) !== "custom_schedule_validity" && discount.expire_time) {
|
|
76
|
+
const expiry = (0, import_dayjs.default)(discount.expire_time);
|
|
77
|
+
if (expiry.isValid() && !(0, import_dayjs.default)().isBefore(expiry))
|
|
78
|
+
return "expired";
|
|
79
|
+
}
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
function getDiscountUsageBlockReason(discount) {
|
|
83
|
+
return getDiscountLifecycleReason(discount) || getDiscountUsageLimitFailKey(discount) || (discount.unified_available_status != null && String(discount.unified_available_status) !== "" && Number(discount.unified_available_status) === 0 ? "server_unavailable" : void 0);
|
|
84
|
+
}
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
getDiscountLifecycleReason,
|
|
88
|
+
getDiscountUsageBlockReason,
|
|
89
|
+
getDiscountUsageLimitFailKey,
|
|
90
|
+
hasAvailableDiscountBalance
|
|
91
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const ENTITLEMENT_PASS_TYPE = "entitlement_pass";
|
|
2
|
+
export declare const GOOD_PASS_TYPE = "good_pass";
|
|
3
|
+
type DiscountLike = {
|
|
4
|
+
id?: number | string | null;
|
|
5
|
+
tag?: unknown;
|
|
6
|
+
type?: unknown;
|
|
7
|
+
discount?: object | null;
|
|
8
|
+
metadata?: object | null;
|
|
9
|
+
extension_data?: unknown;
|
|
10
|
+
balance?: unknown;
|
|
11
|
+
expire_time?: unknown;
|
|
12
|
+
};
|
|
13
|
+
export type EntitlementQuota = {
|
|
14
|
+
type: 'limited';
|
|
15
|
+
value: number;
|
|
16
|
+
balance: number;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'unlimited';
|
|
19
|
+
value: null;
|
|
20
|
+
balance: null;
|
|
21
|
+
};
|
|
22
|
+
export declare function isEntitlementPass(discount: DiscountLike | null | undefined): boolean;
|
|
23
|
+
export declare function isFullCoveragePass(discount: DiscountLike | null | undefined): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the authoritative total-use contract for an Entitlement Pass.
|
|
26
|
+
* Invalid or missing configuration fails closed. Legacy mode/total_uses fields
|
|
27
|
+
* are intentionally unsupported.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveEntitlementQuota(discount: DiscountLike | null | undefined): EntitlementQuota | null;
|
|
30
|
+
export declare function getRemainingEntitlementUses(discount: DiscountLike | null | undefined, usedCount: number, requestedCount: number): number;
|
|
31
|
+
export declare function hasAvailableEntitlementUses(discount: DiscountLike | null | undefined): boolean;
|
|
32
|
+
/** Sort Entitlement Passes by expiry, finite balance, then card instance id. */
|
|
33
|
+
export declare function compareEntitlementPassPriority(left: DiscountLike, right: DiscountLike): number;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
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[];
|
|
@@ -0,0 +1,206 @@
|
|
|
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,6 +1,6 @@
|
|
|
1
1
|
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
|
-
import { Discount, DiscountModuleAPI } from './types';
|
|
3
|
+
import { Discount, DiscountModuleAPI, DiscountWithReason } from './types';
|
|
4
4
|
export declare class DiscountModule extends BaseModule implements Module, DiscountModuleAPI {
|
|
5
5
|
protected defaultName: string;
|
|
6
6
|
protected defaultVersion: string;
|
|
@@ -17,17 +17,26 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
17
17
|
setOriginalDiscountList(originalDiscountList: Discount[]): Promise<void>;
|
|
18
18
|
getOriginalDiscountList(): Discount[];
|
|
19
19
|
loadPrepareConfig(params: {
|
|
20
|
-
action?: 'create';
|
|
20
|
+
action?: 'create' | 'edit';
|
|
21
21
|
with_good_pass: 0 | 1;
|
|
22
22
|
with_discount_card: 0 | 1;
|
|
23
23
|
customer_id: number;
|
|
24
24
|
with_wallet_pass_holder: 0 | 1;
|
|
25
25
|
request_timezone: string;
|
|
26
|
+
order_id?: number | string;
|
|
27
|
+
with_entitlement_pass?: 0 | 1;
|
|
28
|
+
filter_order_wallet_pass_usage?: 0 | 1;
|
|
26
29
|
}): Promise<Discount[]>;
|
|
27
|
-
batchSearch(code: string,
|
|
30
|
+
batchSearch(code: string, customerIdOrOptions?: number | {
|
|
31
|
+
customerId?: number;
|
|
32
|
+
orderId?: number | string;
|
|
33
|
+
withEntitlementPass?: boolean;
|
|
34
|
+
}): Promise<DiscountWithReason>;
|
|
28
35
|
batchSearchByProductIds(productIds: number[]): Promise<any>;
|
|
29
36
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
30
37
|
private checkUsageCreditsLimit;
|
|
38
|
+
filterEnabledDiscountListWithReason(discountList: Discount[]): DiscountWithReason;
|
|
39
|
+
private checkUsageCreditsLimitWithFailKey;
|
|
31
40
|
uniqueByProductId(discountList: Discount[]): Discount[];
|
|
32
41
|
filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
|
|
33
42
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|