@pisell/pisellos 2.1.173 → 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.
Files changed (93) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  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/Holder/index.d.ts +48 -0
  14. package/dist/modules/Holder/index.js +640 -0
  15. package/dist/modules/Holder/types.d.ts +123 -0
  16. package/dist/modules/Holder/types.js +1 -0
  17. package/dist/modules/Holder/utils.d.ts +13 -0
  18. package/dist/modules/Holder/utils.js +34 -0
  19. package/dist/modules/Order/index.d.ts +1 -0
  20. package/dist/modules/Order/index.js +18 -1
  21. package/dist/modules/Order/types.d.ts +2 -0
  22. package/dist/modules/Order/utils.d.ts +10 -0
  23. package/dist/modules/Order/utils.js +35 -3
  24. package/dist/modules/Product/types.d.ts +7 -0
  25. package/dist/modules/Rules/entitlementLines.d.ts +8 -0
  26. package/dist/modules/Rules/entitlementLines.js +157 -0
  27. package/dist/modules/Rules/index.d.ts +12 -2
  28. package/dist/modules/Rules/index.js +377 -112
  29. package/dist/modules/Rules/types.d.ts +2 -2
  30. package/dist/modules/index.d.ts +1 -0
  31. package/dist/modules/index.js +2 -1
  32. package/dist/plugins/window.d.ts +3 -0
  33. package/dist/solution/BookingByStep/index.d.ts +17 -2
  34. package/dist/solution/BookingByStep/index.js +276 -204
  35. package/dist/solution/BookingByStep/types.d.ts +2 -1
  36. package/dist/solution/BookingByStep/types.js +3 -1
  37. package/dist/solution/ScanOrder/index.js +1 -1
  38. package/dist/solution/ScanOrder/types.d.ts +1 -0
  39. package/dist/solution/ShopDiscount/index.d.ts +3 -0
  40. package/dist/solution/ShopDiscount/index.js +161 -78
  41. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  42. package/dist/solution/ShopDiscount/utils.js +40 -1
  43. package/dist/solution/VenueBooking/index.d.ts +19 -0
  44. package/dist/solution/VenueBooking/index.js +978 -748
  45. package/dist/solution/VenueBooking/types.d.ts +2 -0
  46. package/dist/types/index.d.ts +1 -0
  47. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  48. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  49. package/lib/model/strategy/adapter/walletPass/evaluator.js +4 -2
  50. package/lib/modules/Discount/availability.d.ts +7 -0
  51. package/lib/modules/Discount/availability.js +91 -0
  52. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  53. package/lib/modules/Discount/entitlementPass.js +184 -0
  54. package/lib/modules/Discount/entitlementState.d.ts +8 -0
  55. package/lib/modules/Discount/entitlementState.js +206 -0
  56. package/lib/modules/Discount/index.d.ts +6 -3
  57. package/lib/modules/Discount/index.js +66 -16
  58. package/lib/modules/Discount/types.d.ts +34 -5
  59. package/lib/modules/Holder/index.d.ts +48 -0
  60. package/lib/modules/Holder/index.js +402 -0
  61. package/lib/modules/Holder/types.d.ts +123 -0
  62. package/lib/modules/Holder/types.js +17 -0
  63. package/lib/modules/Holder/utils.d.ts +13 -0
  64. package/lib/modules/Holder/utils.js +71 -0
  65. package/lib/modules/Order/index.d.ts +1 -0
  66. package/lib/modules/Order/index.js +14 -0
  67. package/lib/modules/Order/types.d.ts +2 -0
  68. package/lib/modules/Order/utils.d.ts +10 -0
  69. package/lib/modules/Order/utils.js +36 -5
  70. package/lib/modules/Product/types.d.ts +7 -0
  71. package/lib/modules/Rules/entitlementLines.d.ts +8 -0
  72. package/lib/modules/Rules/entitlementLines.js +158 -0
  73. package/lib/modules/Rules/index.d.ts +12 -2
  74. package/lib/modules/Rules/index.js +304 -70
  75. package/lib/modules/Rules/types.d.ts +2 -2
  76. package/lib/modules/index.d.ts +1 -0
  77. package/lib/modules/index.js +3 -1
  78. package/lib/plugins/window.d.ts +3 -0
  79. package/lib/solution/BookingByStep/index.d.ts +17 -2
  80. package/lib/solution/BookingByStep/index.js +39 -0
  81. package/lib/solution/BookingByStep/types.d.ts +2 -1
  82. package/lib/solution/BookingByStep/types.js +5 -0
  83. package/lib/solution/ScanOrder/index.js +1 -1
  84. package/lib/solution/ScanOrder/types.d.ts +1 -0
  85. package/lib/solution/ShopDiscount/index.d.ts +3 -0
  86. package/lib/solution/ShopDiscount/index.js +78 -28
  87. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  88. package/lib/solution/ShopDiscount/utils.js +42 -1
  89. package/lib/solution/VenueBooking/index.d.ts +19 -0
  90. package/lib/solution/VenueBooking/index.js +134 -16
  91. package/lib/solution/VenueBooking/types.d.ts +2 -0
  92. package/lib/types/index.d.ts +1 -0
  93. package/package.json +1 -1
@@ -1,5 +1,6 @@
1
1
  import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLogInput, ScanOrderLoggerModule, ScanOrderLoggerProviderConfig, ScanOrderLoggerProviderType, DateModule, ScheduleModule, QuotationModule, OpenDataModule } from '../../modules';
2
2
  import type { QuantityCheckResult, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
3
+ import { HolderModule } from '../../modules/Holder';
3
4
  export type { ScanOrderOrderProductIdentity, ScanOrderOrderProduct, ScanOrderSubmitProduct, ScanOrderSummary, ScanOrderTempOrder, ScanOrderSubmitPayload, } from '../ScanOrder/types';
4
5
  export declare enum VenueBookingHooks {
5
6
  onInited = "venueBooking:onInited",
@@ -145,6 +146,7 @@ export interface VenueBookingState {
145
146
  passed: boolean | null;
146
147
  failures: QuantityCheckResult[];
147
148
  };
149
+ holder?: HolderModule;
148
150
  }
149
151
  export interface VenueBookingLoggerRuntimeConfig {
150
152
  provider?: ScanOrderLoggerProviderType;
@@ -6,6 +6,7 @@ export interface Plugin {
6
6
  version: string;
7
7
  initialize: () => Promise<void> | void;
8
8
  destroy?: () => Promise<void> | void;
9
+ getLocalStorage?: (key: string) => string | null;
9
10
  }
10
11
  export interface PluginOptions {
11
12
  dependencies?: string[];
@@ -0,0 +1,49 @@
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/model/strategy/adapter/promotion/index.ts
30
+ var promotion_exports = {};
31
+ __export(promotion_exports, {
32
+ BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
+ PromotionAdapter: () => import_adapter.PromotionAdapter,
34
+ PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
+ X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
+ default: () => import_adapter2.default
37
+ });
38
+ module.exports = __toCommonJS(promotion_exports);
39
+ var import_evaluator = require("./evaluator");
40
+ var import_adapter = require("./adapter");
41
+ var import_adapter2 = __toESM(require("./adapter"));
42
+ var import_examples = require("./examples");
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ BUY_X_GET_Y_FREE_STRATEGY,
46
+ PromotionAdapter,
47
+ PromotionEvaluator,
48
+ X_ITEMS_FOR_Y_PRICE_STRATEGY
49
+ });
@@ -26,6 +26,8 @@ export declare class WalletPassEvaluator {
26
26
  /** 检查代金券/折扣卡是否可用 并返回config */
27
27
  checkVoucherAvailability(input: EvaluatorInput): {
28
28
  isAvailable: boolean;
29
+ reason: string | undefined;
30
+ reasonCode: string | undefined;
29
31
  config: {
30
32
  [x: string]: any;
31
33
  };
@@ -203,14 +203,16 @@ var WalletPassEvaluator = class {
203
203
  }
204
204
  /** 检查代金券/折扣卡是否可用 并返回config */
205
205
  checkVoucherAvailability(input) {
206
- var _a, _b, _c, _d, _e;
206
+ var _a, _b, _c, _d, _e, _f, _g;
207
207
  const { orderTotalAmount, products, vouchers } = input;
208
208
  const results = this.evaluate(input);
209
209
  const isAvailable = ((_a = results[0]) == null ? void 0 : _a.isApplicable) || false;
210
210
  return {
211
211
  isAvailable,
212
+ reason: (_b = results[0]) == null ? void 0 : _b.reason,
213
+ reasonCode: (_c = results[0]) == null ? void 0 : _c.reasonCode,
212
214
  config: {
213
- ...(_e = (_d = (_c = (_b = results[0]) == null ? void 0 : _b.strategyResult) == null ? void 0 : _c.config) == null ? void 0 : _d.metadata) == null ? void 0 : _e.custom
215
+ ...(_g = (_f = (_e = (_d = results[0]) == null ? void 0 : _d.strategyResult) == null ? void 0 : _e.config) == null ? void 0 : _f.metadata) == null ? void 0 : _g.custom
214
216
  }
215
217
  };
216
218
  }
@@ -0,0 +1,7 @@
1
+ import type { Discount, DiscountFilterRejectKey } from './types';
2
+ /** 周期限制只影响当前使用;total_credits 才代表整张卡的次数耗尽。 */
3
+ export declare function getDiscountUsageLimitFailKey(discount: Discount): DiscountFilterRejectKey | null;
4
+ export declare function hasAvailableDiscountBalance(discount: Discount): boolean;
5
+ /** 按卡本身当前生命周期判断;预约时间或一次日程不匹配不代表已失效。 */
6
+ export declare function getDiscountLifecycleReason(discount: Discount): 'disabled' | 'exhausted' | 'expired' | 'not_shared_at_store' | undefined;
7
+ export declare function getDiscountUsageBlockReason(discount: Discount): string | undefined;
@@ -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
+ });
@@ -23,11 +23,14 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
23
23
  customer_id: number;
24
24
  with_wallet_pass_holder: 0 | 1;
25
25
  request_timezone: string;
26
- order_id?: number;
26
+ order_id?: number | string;
27
+ with_entitlement_pass?: 0 | 1;
28
+ filter_order_wallet_pass_usage?: 0 | 1;
27
29
  }): Promise<Discount[]>;
28
- batchSearch(code: string, options?: {
30
+ batchSearch(code: string, customerIdOrOptions?: number | {
29
31
  customerId?: number;
30
- orderId?: number;
32
+ orderId?: number | string;
33
+ withEntitlementPass?: boolean;
31
34
  }): Promise<DiscountWithReason>;
32
35
  batchSearchByProductIds(productIds: number[]): Promise<any>;
33
36
  filterEnabledDiscountList(discountList: Discount[]): Discount[];