@pisell/pisellos 2.1.177 → 2.1.178

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 (44) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  4. package/dist/modules/Discount/availability.d.ts +7 -0
  5. package/dist/modules/Discount/availability.js +52 -0
  6. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  7. package/dist/modules/Discount/entitlementPass.js +147 -0
  8. package/dist/modules/Discount/entitlementState.d.ts +8 -0
  9. package/dist/modules/Discount/entitlementState.js +205 -0
  10. package/dist/modules/Discount/index.d.ts +6 -3
  11. package/dist/modules/Discount/index.js +125 -23
  12. package/dist/modules/Discount/types.d.ts +34 -5
  13. package/dist/modules/Rules/entitlementLines.d.ts +8 -0
  14. package/dist/modules/Rules/entitlementLines.js +157 -0
  15. package/dist/modules/Rules/index.d.ts +12 -2
  16. package/dist/modules/Rules/index.js +377 -113
  17. package/dist/modules/Rules/types.d.ts +2 -2
  18. package/dist/plugins/window.d.ts +2 -0
  19. package/dist/solution/ShopDiscount/index.d.ts +3 -0
  20. package/dist/solution/ShopDiscount/index.js +161 -78
  21. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  22. package/dist/solution/ShopDiscount/utils.js +40 -1
  23. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  24. package/lib/model/strategy/adapter/walletPass/evaluator.js +4 -2
  25. package/lib/modules/Discount/availability.d.ts +7 -0
  26. package/lib/modules/Discount/availability.js +91 -0
  27. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  28. package/lib/modules/Discount/entitlementPass.js +184 -0
  29. package/lib/modules/Discount/entitlementState.d.ts +8 -0
  30. package/lib/modules/Discount/entitlementState.js +206 -0
  31. package/lib/modules/Discount/index.d.ts +6 -3
  32. package/lib/modules/Discount/index.js +66 -16
  33. package/lib/modules/Discount/types.d.ts +34 -5
  34. package/lib/modules/Rules/entitlementLines.d.ts +8 -0
  35. package/lib/modules/Rules/entitlementLines.js +158 -0
  36. package/lib/modules/Rules/index.d.ts +12 -2
  37. package/lib/modules/Rules/index.js +303 -69
  38. package/lib/modules/Rules/types.d.ts +2 -2
  39. package/lib/plugins/window.d.ts +2 -0
  40. package/lib/solution/ShopDiscount/index.d.ts +3 -0
  41. package/lib/solution/ShopDiscount/index.js +78 -28
  42. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  43. package/lib/solution/ShopDiscount/utils.js +42 -1
  44. package/package.json +1 -1
@@ -36,6 +36,8 @@ var import_utils = require("../../solution/ShopDiscount/utils");
36
36
  var import_BaseModule = require("../BaseModule");
37
37
  var import_types = require("./types");
38
38
  var import_decimal = __toESM(require("decimal.js"));
39
+ var import_entitlementPass = require("./entitlementPass");
40
+ var import_availability = require("./availability");
39
41
  var DiscountModule = class extends import_BaseModule.BaseModule {
40
42
  constructor(name, version) {
41
43
  super(name, version);
@@ -92,23 +94,34 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
92
94
  return this.store.originalDiscountList || [];
93
95
  }
94
96
  async loadPrepareConfig(params) {
95
- var _a, _b;
97
+ var _a, _b, _c, _d, _e;
96
98
  const prepareConfig = await this.request.post(
97
99
  `/order/prepare/config`,
98
100
  params
99
101
  );
100
- const goodPassList = this.filterEnabledDiscountList(
101
- [...((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || [], ...((_b = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _b.discount_card_list) || []]
102
- ) || [];
102
+ if (!params.with_entitlement_pass) {
103
+ return this.filterEnabledDiscountList([
104
+ ...((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || [],
105
+ ...((_b = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _b.discount_card_list) || []
106
+ ].filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item)));
107
+ }
108
+ const entitlementPassList = ((_c = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _c.entitlement_pass_list) || [];
109
+ const ids = new Set(entitlementPassList.map((item) => String(item.id)));
110
+ const rawDiscountList = [
111
+ ...entitlementPassList,
112
+ ...(((_d = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _d.good_pass_list) || []).filter((item) => !ids.has(String(item.id))),
113
+ ...(((_e = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _e.discount_card_list) || []).filter((item) => !ids.has(String(item.id)))
114
+ ];
115
+ await this.setOriginalDiscountList(rawDiscountList);
116
+ const goodPassList = this.filterEnabledDiscountList(rawDiscountList);
103
117
  return goodPassList;
104
118
  }
105
- async batchSearch(code, options) {
106
- const { customerId, orderId } = options || {};
107
- const result = await this.request.get(`/machinecode/batch-search`, {
119
+ async batchSearch(code, customerIdOrOptions) {
120
+ var _a, _b;
121
+ const { customerId, orderId, withEntitlementPass } = typeof customerIdOrOptions === "number" ? { customerId: customerIdOrOptions, orderId: void 0, withEntitlementPass: false } : customerIdOrOptions || {};
122
+ const params = {
108
123
  code,
109
124
  translate_flag: 1,
110
- tags: ["good_pass", "product_discount_card"],
111
- // available: 1,
112
125
  relation_product: 1,
113
126
  with: ["extensionData", "customScheduleSnapshot", "holder.detail"],
114
127
  order_behavior_count: 1,
@@ -116,9 +129,45 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
116
129
  ...orderId ? { order_behavior_count_order_id: orderId } : {},
117
130
  unified_status_info_flag: 1,
118
131
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
119
- });
120
- const resultDiscountWithReason = this.filterEnabledDiscountListWithReason((result == null ? void 0 : result.data) || []) || [];
121
- return resultDiscountWithReason;
132
+ };
133
+ if (!withEntitlementPass) {
134
+ const result2 = await this.request.get(`/machinecode/batch-search`, {
135
+ ...params,
136
+ tags: ["good_pass", "product_discount_card"]
137
+ });
138
+ return this.filterEnabledDiscountListWithReason(((result2 == null ? void 0 : result2.data) || []).filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item)));
139
+ }
140
+ const search = (query) => this.request.get(`/machinecode/batch-search`, query).then(
141
+ (value) => ({ status: "fulfilled", value }),
142
+ (reason) => ({ status: "rejected", reason })
143
+ );
144
+ const [legacy, entitlement] = await Promise.all([
145
+ search({
146
+ ...params,
147
+ tags: ["good_pass", "product_discount_card"]
148
+ }),
149
+ search({
150
+ ...params,
151
+ tags: ["entitlement_pass"],
152
+ with_franchisor_data: 1,
153
+ unified_status_info_flag: 1,
154
+ with: [...params.with, "franchiseeWalletPass:shop_id,source_shop_id,product_id,use"]
155
+ })
156
+ ]);
157
+ const entitlementList = (entitlement.status === "fulfilled" ? ((_a = entitlement.value) == null ? void 0 : _a.data) || [] : []).filter(import_entitlementPass.isEntitlementPass);
158
+ const legacyList = legacy.status === "fulfilled" ? ((_b = legacy.value) == null ? void 0 : _b.data) || [] : [];
159
+ const ids = new Set(entitlementList.map((item) => String(item.id)));
160
+ const result = this.filterEnabledDiscountListWithReason([
161
+ ...entitlementList,
162
+ ...legacyList.filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item) && !ids.has(String(item.id)))
163
+ ]);
164
+ if (!result.discountList.length) {
165
+ if (legacy.status === "rejected")
166
+ throw legacy.reason;
167
+ if (entitlement.status === "rejected")
168
+ throw entitlement.reason;
169
+ }
170
+ return result;
122
171
  }
123
172
  async batchSearchByProductIds(productIds) {
124
173
  const result = await this.request.get(`/machinecode/batch-search`, {
@@ -131,7 +180,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
131
180
  }
132
181
  filterEnabledDiscountList(discountList) {
133
182
  return discountList.filter(
134
- (discount) => discount.limit_status === "enable" && new import_decimal.default((discount == null ? void 0 : discount.par_value) || 0).minus(new import_decimal.default((discount == null ? void 0 : discount.used_par_value) || 0)).greaterThan(0) && this.checkUsageCreditsLimit(discount)
183
+ (discount) => (0, import_entitlementPass.isEntitlementPass)(discount) ? !(0, import_availability.getDiscountLifecycleReason)(discount) : discount.limit_status === "enable" && new import_decimal.default((discount == null ? void 0 : discount.par_value) || 0).minus(new import_decimal.default((discount == null ? void 0 : discount.used_par_value) || 0)).greaterThan(0) && this.checkUsageCreditsLimit(discount)
135
184
  );
136
185
  }
137
186
  // 检查使用次数限制
@@ -175,7 +224,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
175
224
  }
176
225
  // 过滤启用且可用的优惠券,并返回校验失败原因
177
226
  filterEnabledDiscountListWithReason(discountList) {
178
- let lists = discountList.filter((discount) => discount.limit_status === "enable").filter((discount) => {
227
+ const entitlementPasses = discountList.filter((item) => (0, import_entitlementPass.isEntitlementPass)(item) && !(0, import_availability.getDiscountLifecycleReason)(item));
228
+ let lists = discountList.filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item)).filter((discount) => discount.limit_status === "enable").filter((discount) => {
179
229
  const remaining = new import_decimal.default((discount == null ? void 0 : discount.par_value) || 0).minus(new import_decimal.default((discount == null ? void 0 : discount.used_par_value) || 0)).greaterThan(0);
180
230
  return remaining;
181
231
  }).map((discount) => {
@@ -188,8 +238,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
188
238
  const availableLists = lists.filter((item) => !item.usageLimitFailKey && item.unified_available_status !== 0);
189
239
  const currentFailDiscount = lists.find((item) => item.usageLimitFailKey);
190
240
  return {
191
- discountList: availableLists,
192
- unavailableReasonKey: currentFailDiscount == null ? void 0 : currentFailDiscount.usageLimitFailKey
241
+ discountList: [...entitlementPasses.map((item) => ({ ...item, usageLimitFailKey: (0, import_availability.getDiscountUsageLimitFailKey)(item) })), ...availableLists],
242
+ unavailableReasonKey: (currentFailDiscount == null ? void 0 : currentFailDiscount.usageLimitFailKey) || discountList.filter(import_entitlementPass.isEntitlementPass).map(import_availability.getDiscountLifecycleReason).find(Boolean) || null
193
243
  };
194
244
  }
195
245
  // 检查使用次数限制,并返回校验失败原因
@@ -45,6 +45,8 @@ interface ApplicableProductDetails {
45
45
  num: number;
46
46
  metadata?: {
47
47
  product_discount_difference?: number;
48
+ num?: number;
49
+ custom_product_bundle_map_id?: string;
48
50
  };
49
51
  discount?: {
50
52
  fixed_amount?: number;
@@ -63,10 +65,17 @@ interface UsageCreditsValue {
63
65
  max_per_week: number;
64
66
  max_per_month: number;
65
67
  }
68
+ export type IncludedUses = {
69
+ type: 'limited';
70
+ value: number;
71
+ } | {
72
+ type: 'unlimited';
73
+ value: null;
74
+ };
66
75
  export type DiscountFilterRejectKey = 'total_credits' | 'per_user_limit' | 'max_per_day' | 'max_per_week' | 'max_per_month';
67
76
  export interface DiscountWithReason {
68
77
  discountList: Discount[];
69
- unavailableReasonKey: DiscountFilterRejectKey | null;
78
+ unavailableReasonKey: DiscountFilterRejectKey | string | null;
70
79
  }
71
80
  interface ExtensionData {
72
81
  id: number;
@@ -93,19 +102,39 @@ export interface Discount {
93
102
  used_par_value: string;
94
103
  limit_status: string;
95
104
  limited_relation_product_data: Limitedrelationproductdata;
96
- balance: string;
105
+ balance?: string | number | null;
97
106
  format_title: Formattitle;
98
107
  metadata?: {
99
108
  discount_card_type?: 'fixed_amount' | 'percent';
100
109
  custom_product_bundle_map_id?: string;
101
110
  validity_type?: "custom_schedule_validity" | "fixed_validity";
102
- discount_calculation_mode: 'item_level' | 'order_level';
103
- holder: {
111
+ included_uses?: IncludedUses;
112
+ discount_calculation_mode?: 'item_level' | 'order_level';
113
+ holder?: {
104
114
  type: "customer" | "custom";
105
115
  };
106
116
  };
107
117
  product: Product;
108
- type: "product" | 'good_pass';
118
+ type?: 'product' | 'good_pass' | 'entitlement_pass' | 'discount_card' | 'product_discount_card';
119
+ shop_id?: number;
120
+ customer_id?: number | string | null;
121
+ holder?: {
122
+ holder_type?: string;
123
+ holder_id?: number | string | Array<number | string>;
124
+ [key: string]: any;
125
+ };
126
+ config?: {
127
+ isAvailable?: boolean;
128
+ maxUsagePerOrder?: number;
129
+ [key: string]: any;
130
+ };
131
+ reason?: string;
132
+ reasonCode?: string;
133
+ is_franchisor_pass?: number;
134
+ franchisee_wallet_pass?: {
135
+ use?: string;
136
+ };
137
+ committedAppliedProductDetails?: ApplicableProductDetails[];
109
138
  resource_id?: number;
110
139
  savedAmount?: number;
111
140
  isEditMode?: boolean;
@@ -0,0 +1,8 @@
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[];
@@ -0,0 +1,158 @@
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
+ });
@@ -8,17 +8,26 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
8
8
  protected defaultVersion: string;
9
9
  private store;
10
10
  private hooks;
11
+ private entitlementPassEnabled;
12
+ private defaultWalletPassEvaluator?;
13
+ setEntitlementPassEnabled(enabled: boolean): void;
14
+ private getWalletPassEvaluator;
11
15
  constructor(name?: string, version?: string);
12
16
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
13
17
  setRulesList(rulesList: Rules[]): Promise<void>;
14
18
  getRulesList(): Rules[];
19
+ private normalizeHolderRecordIds;
20
+ /**
21
+ * 商品未开启 Holder 选择时跳过匹配;已开启时,特定 form Holder 卡
22
+ * 只适用于同一 Holder Record,是否必填不影响匹配规则。
23
+ */
15
24
  private checkHolderMatch;
16
25
  isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, isFormSubject, }: {
17
26
  oldDiscountList: Discount[];
18
27
  newDiscountList: Discount[];
19
28
  productList: any[];
20
29
  holders: {
21
- form_record_id: number;
30
+ form_record_id: number | string;
22
31
  }[];
23
32
  isFormSubject: boolean;
24
33
  }): {
@@ -26,6 +35,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
26
35
  discountList: Discount[];
27
36
  productList: any[];
28
37
  unavailableReason?: UnavailableReason;
38
+ evaluatedDiscountList?: Discount[];
29
39
  };
30
40
  filterDiscountListByType(discountList: Discount[], type: string): Discount[];
31
41
  private getUnavailableReason;
@@ -33,7 +43,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
33
43
  discountList: Discount[];
34
44
  productList: any[];
35
45
  holders: {
36
- form_record_id: number;
46
+ form_record_id: number | string;
37
47
  }[];
38
48
  isFormSubject: boolean;
39
49
  }, options?: {