@pisell/pisellos 2.1.171 → 2.1.172

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 (230) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -3
  3. package/dist/model/strategy/adapter/index.d.ts +0 -4
  4. package/dist/model/strategy/adapter/index.js +1 -5
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  6. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  7. package/dist/model/strategy/adapter/walletPass/evaluator.js +61 -8
  8. package/dist/model/strategy/adapter/walletPass/locales.js +12 -3
  9. package/dist/model/strategy/engine.d.ts +18 -5
  10. package/dist/model/strategy/engine.js +145 -45
  11. package/dist/model/strategy/type.d.ts +17 -0
  12. package/dist/model/strategy/type.js +4 -0
  13. package/dist/modules/Cart/types.d.ts +2 -0
  14. package/dist/modules/Cart/utils/cartProduct.js +56 -25
  15. package/dist/modules/Cart/utils/changePrice.js +9 -16
  16. package/dist/modules/Discount/index.d.ts +4 -13
  17. package/dist/modules/Discount/index.js +12 -124
  18. package/dist/modules/Discount/types.d.ts +18 -13
  19. package/dist/modules/Order/index.d.ts +1 -67
  20. package/dist/modules/Order/index.js +30 -918
  21. package/dist/modules/Order/types.d.ts +12 -176
  22. package/dist/modules/Order/types.js +0 -2
  23. package/dist/modules/Order/utils.d.ts +0 -118
  24. package/dist/modules/Order/utils.js +2 -586
  25. package/dist/modules/Payment/index.d.ts +2 -1
  26. package/dist/modules/Payment/index.js +10 -7
  27. package/dist/modules/Payment/utils.js +3 -0
  28. package/dist/modules/Payment/walletpass.d.ts +23 -0
  29. package/dist/modules/Payment/walletpass.js +191 -95
  30. package/dist/modules/Product/utils.js +2 -2
  31. package/dist/modules/ProductList/index.d.ts +2 -4
  32. package/dist/modules/ProductList/index.js +12 -24
  33. package/dist/modules/Rules/index.d.ts +9 -5
  34. package/dist/modules/Rules/index.js +669 -173
  35. package/dist/modules/Rules/types.d.ts +2 -0
  36. package/dist/modules/Schedule/getDateIsInSchedule.js +18 -16
  37. package/dist/modules/Schedule/utils.d.ts +1 -1
  38. package/dist/modules/Summary/types.d.ts +2 -0
  39. package/dist/modules/Summary/utils.d.ts +9 -3
  40. package/dist/modules/Summary/utils.js +57 -67
  41. package/dist/modules/index.d.ts +0 -4
  42. package/dist/modules/index.js +1 -5
  43. package/dist/plugins/window.d.ts +2 -0
  44. package/dist/solution/BookingByStep/index.d.ts +3 -2
  45. package/dist/solution/BookingByStep/index.js +43 -46
  46. package/dist/solution/BookingByStep/types.d.ts +1 -3
  47. package/dist/solution/BookingByStep/types.js +1 -5
  48. package/dist/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  49. package/dist/solution/BookingByStep/utils/timeslots.js +12 -19
  50. package/dist/solution/Checkout/index.js +2 -0
  51. package/dist/solution/ShopDiscount/index.d.ts +2 -3
  52. package/dist/solution/ShopDiscount/index.js +60 -62
  53. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  54. package/dist/solution/ShopDiscount/types.js +2 -1
  55. package/dist/solution/ShopDiscount/utils.js +26 -12
  56. package/dist/solution/index.d.ts +0 -2
  57. package/dist/solution/index.js +1 -3
  58. package/lib/index.d.ts +1 -1
  59. package/lib/index.js +3 -4
  60. package/lib/model/strategy/adapter/index.d.ts +0 -4
  61. package/lib/model/strategy/adapter/index.js +2 -13
  62. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  63. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  64. package/lib/model/strategy/adapter/walletPass/evaluator.js +34 -3
  65. package/lib/model/strategy/adapter/walletPass/locales.js +12 -3
  66. package/lib/model/strategy/engine.d.ts +18 -5
  67. package/lib/model/strategy/engine.js +85 -21
  68. package/lib/model/strategy/type.d.ts +17 -0
  69. package/lib/modules/Cart/types.d.ts +2 -0
  70. package/lib/modules/Cart/utils/cartProduct.js +39 -12
  71. package/lib/modules/Cart/utils/changePrice.js +9 -13
  72. package/lib/modules/Discount/index.d.ts +4 -13
  73. package/lib/modules/Discount/index.js +5 -76
  74. package/lib/modules/Discount/types.d.ts +18 -13
  75. package/lib/modules/Order/index.d.ts +1 -67
  76. package/lib/modules/Order/index.js +1 -525
  77. package/lib/modules/Order/types.d.ts +12 -176
  78. package/lib/modules/Order/utils.d.ts +0 -118
  79. package/lib/modules/Order/utils.js +2 -483
  80. package/lib/modules/Payment/index.d.ts +2 -1
  81. package/lib/modules/Payment/index.js +1 -0
  82. package/lib/modules/Payment/utils.js +3 -0
  83. package/lib/modules/Payment/walletpass.d.ts +23 -0
  84. package/lib/modules/Payment/walletpass.js +94 -17
  85. package/lib/modules/Product/utils.js +2 -2
  86. package/lib/modules/ProductList/index.d.ts +2 -4
  87. package/lib/modules/ProductList/index.js +39 -46
  88. package/lib/modules/Rules/index.d.ts +9 -5
  89. package/lib/modules/Rules/index.js +776 -292
  90. package/lib/modules/Rules/types.d.ts +2 -0
  91. package/lib/modules/Schedule/getDateIsInSchedule.js +11 -13
  92. package/lib/modules/Schedule/utils.d.ts +1 -1
  93. package/lib/modules/Summary/types.d.ts +2 -0
  94. package/lib/modules/Summary/utils.d.ts +9 -3
  95. package/lib/modules/Summary/utils.js +34 -45
  96. package/lib/modules/index.d.ts +0 -4
  97. package/lib/modules/index.js +1 -9
  98. package/lib/plugins/window.d.ts +2 -0
  99. package/lib/solution/BookingByStep/index.d.ts +3 -2
  100. package/lib/solution/BookingByStep/index.js +4 -6
  101. package/lib/solution/BookingByStep/types.d.ts +1 -3
  102. package/lib/solution/BookingByStep/types.js +0 -10
  103. package/lib/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  104. package/lib/solution/BookingByStep/utils/timeslots.js +11 -19
  105. package/lib/solution/Checkout/index.js +2 -0
  106. package/lib/solution/ShopDiscount/index.d.ts +2 -3
  107. package/lib/solution/ShopDiscount/index.js +27 -22
  108. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  109. package/lib/solution/ShopDiscount/utils.js +10 -6
  110. package/lib/solution/index.d.ts +0 -2
  111. package/lib/solution/index.js +1 -5
  112. package/package.json +2 -2
  113. package/dist/apis/picoding.d.ts +0 -0
  114. package/dist/apis/picoding.js +0 -1
  115. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
  116. package/dist/model/strategy/adapter/dataVariant/adapter.js +0 -167
  117. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
  118. package/dist/model/strategy/adapter/dataVariant/evaluator.js +0 -780
  119. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  120. package/dist/model/strategy/adapter/dataVariant/examples.js +0 -277
  121. package/dist/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  122. package/dist/model/strategy/adapter/dataVariant/index.js +0 -4
  123. package/dist/model/strategy/adapter/dataVariant/type.d.ts +0 -148
  124. package/dist/model/strategy/adapter/dataVariant/type.js +0 -54
  125. package/dist/modules/OpenData/index.d.ts +0 -24
  126. package/dist/modules/OpenData/index.js +0 -173
  127. package/dist/modules/OpenData/types.d.ts +0 -73
  128. package/dist/modules/OpenData/types.js +0 -1
  129. package/dist/modules/OpenData/utils.d.ts +0 -2
  130. package/dist/modules/OpenData/utils.js +0 -75
  131. package/dist/modules/Quotation/index.d.ts +0 -48
  132. package/dist/modules/Quotation/index.js +0 -248
  133. package/dist/modules/Quotation/types.d.ts +0 -42
  134. package/dist/modules/Quotation/types.js +0 -1
  135. package/dist/modules/SalesSummary/index.d.ts +0 -63
  136. package/dist/modules/SalesSummary/index.js +0 -174
  137. package/dist/modules/SalesSummary/types.d.ts +0 -60
  138. package/dist/modules/SalesSummary/types.js +0 -1
  139. package/dist/modules/SalesSummary/utils.d.ts +0 -30
  140. package/dist/modules/SalesSummary/utils.js +0 -480
  141. package/dist/modules/ScanOrderLogger/index.d.ts +0 -23
  142. package/dist/modules/ScanOrderLogger/index.js +0 -174
  143. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  144. package/dist/modules/ScanOrderLogger/providers/feishu.js +0 -221
  145. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  146. package/dist/modules/ScanOrderLogger/providers/grafana.js +0 -50
  147. package/dist/modules/ScanOrderLogger/types.d.ts +0 -53
  148. package/dist/modules/ScanOrderLogger/types.js +0 -1
  149. package/dist/solution/ScanOrder/index.d.ts +0 -158
  150. package/dist/solution/ScanOrder/index.js +0 -3474
  151. package/dist/solution/ScanOrder/types.d.ts +0 -306
  152. package/dist/solution/ScanOrder/types.js +0 -35
  153. package/dist/solution/ScanOrder/utils.d.ts +0 -172
  154. package/dist/solution/ScanOrder/utils.js +0 -796
  155. package/dist/solution/VenueBooking/index.d.ts +0 -262
  156. package/dist/solution/VenueBooking/index.js +0 -3991
  157. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  158. package/dist/solution/VenueBooking/types.d.ts +0 -156
  159. package/dist/solution/VenueBooking/types.js +0 -22
  160. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  161. package/dist/solution/VenueBooking/utils/dateSummary.js +0 -91
  162. package/dist/solution/VenueBooking/utils/resource.d.ts +0 -14
  163. package/dist/solution/VenueBooking/utils/resource.js +0 -131
  164. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -32
  165. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -233
  166. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  167. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
  168. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -34
  169. package/dist/solution/VenueBooking/utils/timeSlot.js +0 -458
  170. package/dist/solution/VenueBooking/utils.d.ts +0 -1
  171. package/dist/solution/VenueBooking/utils.js +0 -1
  172. package/lib/apis/picoding.d.ts +0 -0
  173. package/lib/apis/picoding.js +0 -0
  174. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
  175. package/lib/model/strategy/adapter/dataVariant/adapter.js +0 -149
  176. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
  177. package/lib/model/strategy/adapter/dataVariant/evaluator.js +0 -583
  178. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  179. package/lib/model/strategy/adapter/dataVariant/examples.js +0 -293
  180. package/lib/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  181. package/lib/model/strategy/adapter/dataVariant/index.js +0 -38
  182. package/lib/model/strategy/adapter/dataVariant/type.d.ts +0 -148
  183. package/lib/model/strategy/adapter/dataVariant/type.js +0 -31
  184. package/lib/modules/OpenData/index.d.ts +0 -24
  185. package/lib/modules/OpenData/index.js +0 -119
  186. package/lib/modules/OpenData/types.d.ts +0 -73
  187. package/lib/modules/OpenData/types.js +0 -17
  188. package/lib/modules/OpenData/utils.d.ts +0 -2
  189. package/lib/modules/OpenData/utils.js +0 -111
  190. package/lib/modules/Quotation/index.d.ts +0 -48
  191. package/lib/modules/Quotation/index.js +0 -152
  192. package/lib/modules/Quotation/types.d.ts +0 -42
  193. package/lib/modules/Quotation/types.js +0 -17
  194. package/lib/modules/SalesSummary/index.d.ts +0 -63
  195. package/lib/modules/SalesSummary/index.js +0 -105
  196. package/lib/modules/SalesSummary/types.d.ts +0 -60
  197. package/lib/modules/SalesSummary/types.js +0 -17
  198. package/lib/modules/SalesSummary/utils.d.ts +0 -30
  199. package/lib/modules/SalesSummary/utils.js +0 -420
  200. package/lib/modules/ScanOrderLogger/index.d.ts +0 -23
  201. package/lib/modules/ScanOrderLogger/index.js +0 -147
  202. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  203. package/lib/modules/ScanOrderLogger/providers/feishu.js +0 -157
  204. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  205. package/lib/modules/ScanOrderLogger/providers/grafana.js +0 -52
  206. package/lib/modules/ScanOrderLogger/types.d.ts +0 -53
  207. package/lib/modules/ScanOrderLogger/types.js +0 -17
  208. package/lib/solution/ScanOrder/index.d.ts +0 -158
  209. package/lib/solution/ScanOrder/index.js +0 -2135
  210. package/lib/solution/ScanOrder/types.d.ts +0 -306
  211. package/lib/solution/ScanOrder/types.js +0 -36
  212. package/lib/solution/ScanOrder/utils.d.ts +0 -172
  213. package/lib/solution/ScanOrder/utils.js +0 -658
  214. package/lib/solution/VenueBooking/index.d.ts +0 -262
  215. package/lib/solution/VenueBooking/index.js +0 -2394
  216. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  217. package/lib/solution/VenueBooking/types.d.ts +0 -156
  218. package/lib/solution/VenueBooking/types.js +0 -45
  219. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  220. package/lib/solution/VenueBooking/utils/dateSummary.js +0 -105
  221. package/lib/solution/VenueBooking/utils/resource.d.ts +0 -14
  222. package/lib/solution/VenueBooking/utils/resource.js +0 -92
  223. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -32
  224. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -236
  225. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  226. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -180
  227. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -34
  228. package/lib/solution/VenueBooking/utils/timeSlot.js +0 -343
  229. package/lib/solution/VenueBooking/utils.d.ts +0 -1
  230. package/lib/solution/VenueBooking/utils.js +0 -69
@@ -1,658 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/solution/ScanOrder/utils.ts
30
- var utils_exports = {};
31
- __export(utils_exports, {
32
- aggregateItemRuleLimit: () => aggregateItemRuleLimit,
33
- attachItemRuleLimitsToTopLevelProducts: () => attachItemRuleLimitsToTopLevelProducts,
34
- buildItemRuleBusinessData: () => buildItemRuleBusinessData,
35
- buildProductKey: () => buildProductKey,
36
- buildProductLineFingerprint: () => buildProductLineFingerprint,
37
- buildQuantityLimitIndex: () => buildQuantityLimitIndex,
38
- collectLinkProductIdsFromReservationRules: () => collectLinkProductIdsFromReservationRules,
39
- computeResourceIsFull: () => computeResourceIsFull,
40
- createEmptySummary: () => createEmptySummary,
41
- extractStrategyModelIdsFromTableConfig: () => extractStrategyModelIdsFromTableConfig,
42
- findReservationRuleProductByResourceId: () => findReservationRuleProductByResourceId,
43
- getProductIdentityIndex: () => getProductIdentityIndex,
44
- getSafeProductNum: () => getSafeProductNum,
45
- getTopLevelProductId: () => getTopLevelProductId,
46
- getTopLevelVariantId: () => getTopLevelVariantId,
47
- hasCustomCapacityProduct: () => hasCustomCapacityProduct,
48
- isIdentityMatch: () => isIdentityMatch,
49
- isSkuOnlyDeleteIdentity: () => isSkuOnlyDeleteIdentity,
50
- normalizeEnabledItemRuleIds: () => normalizeEnabledItemRuleIds,
51
- normalizeItemRuleStrategies: () => normalizeItemRuleStrategies,
52
- normalizeOrderProduct: () => normalizeOrderProduct,
53
- pickFirstCustomCapacityDimensionId: () => pickFirstCustomCapacityDimensionId,
54
- pickFirstCustomCapacityPaxBounds: () => pickFirstCustomCapacityPaxBounds,
55
- pickFirstDurationMinutesFromProducts: () => pickFirstDurationMinutesFromProducts,
56
- resolveSkuMatchedQuantityLimits: () => resolveSkuMatchedQuantityLimits,
57
- toBoolean: () => toBoolean,
58
- toNonNegativeInt: () => toNonNegativeInt,
59
- toNonNegativeNumber: () => toNonNegativeNumber,
60
- toPositiveString: () => toPositiveString,
61
- toPriceString: () => toPriceString
62
- });
63
- module.exports = __toCommonJS(utils_exports);
64
- var import_dayjs = __toESM(require("dayjs"));
65
- var import_decimal = __toESM(require("decimal.js"));
66
- var import_utils = require("../../modules/Order/utils");
67
- function createEmptySummary() {
68
- return {
69
- product_quantity: 0,
70
- product_original_amount: "0.00",
71
- product_amount: "0.00",
72
- product_expect_amount: "0.00",
73
- product_tax_fee: "0.00",
74
- shipping_fee: "0.00",
75
- shipping_tax_fee: "0.00",
76
- tax_fee: "0.00",
77
- surcharge_fee: "0.00",
78
- discount_amount: "0.00",
79
- deposit_amount: "0.00",
80
- expect_amount: "0.00",
81
- total_amount: "0.00",
82
- amount_gap: "0.00",
83
- rounding_amount: "0.00",
84
- pay_service_charge_amount: "0.00"
85
- };
86
- }
87
- function getSafeProductNum(num) {
88
- if (!num || Number.isNaN(num))
89
- return 1;
90
- if (num < 1)
91
- return 1;
92
- return Math.floor(num);
93
- }
94
- function toBoolean(value) {
95
- if (typeof value === "boolean")
96
- return value;
97
- if (typeof value === "number")
98
- return value !== 0;
99
- if (typeof value === "string") {
100
- const normalized = value.trim().toLowerCase();
101
- return ["1", "true", "yes", "y", "on"].includes(normalized);
102
- }
103
- return false;
104
- }
105
- function toPositiveString(value) {
106
- if (value === null || value === void 0 || value === "")
107
- return void 0;
108
- const normalized = String(value).trim();
109
- if (!normalized || normalized === "0" || normalized.toLowerCase() === "null") {
110
- return void 0;
111
- }
112
- return normalized;
113
- }
114
- function normalizeEnabledItemRuleIds(rawIds) {
115
- if (!Array.isArray(rawIds))
116
- return [];
117
- const uniqueIds = /* @__PURE__ */ new Set();
118
- for (const item of rawIds) {
119
- const strategyId = Number(item);
120
- if (Number.isFinite(strategyId) && strategyId > 0) {
121
- uniqueIds.add(strategyId);
122
- }
123
- }
124
- return Array.from(uniqueIds);
125
- }
126
- function extractStrategyModelIdsFromTableConfig(tableConfig) {
127
- const rawIds = Array.isArray(tableConfig == null ? void 0 : tableConfig.strategy_model_ids) ? tableConfig.strategy_model_ids : [];
128
- return rawIds.map((id) => Number(id)).filter((id) => Number.isFinite(id) && id > 0);
129
- }
130
- function normalizeItemRuleStrategies(configs) {
131
- if (!Array.isArray(configs))
132
- return [];
133
- return configs.filter(
134
- (config) => {
135
- var _a;
136
- return Boolean(
137
- config && typeof config === "object" && ((_a = config == null ? void 0 : config.metadata) == null ? void 0 : _a.type) === "item_rule"
138
- );
139
- }
140
- );
141
- }
142
- function toNonNegativeNumber(value) {
143
- if (typeof value === "number") {
144
- return Number.isFinite(value) && value >= 0 ? value : 0;
145
- }
146
- if (typeof value === "string") {
147
- const parsed = Number(value);
148
- return Number.isFinite(parsed) && parsed >= 0 ? parsed : 0;
149
- }
150
- return 0;
151
- }
152
- function toNonNegativeInt(value) {
153
- return Math.floor(toNonNegativeNumber(value));
154
- }
155
- function toPriceString(value, fallback = "0.00") {
156
- const parsedValue = Number(value);
157
- if (Number.isNaN(parsedValue))
158
- return fallback;
159
- return parsedValue.toFixed(2);
160
- }
161
- function buildProductKey(productId, productVariantId) {
162
- return `${productId}_${productVariantId}`;
163
- }
164
- function getTopLevelProductId(product) {
165
- const rawProductId = product.product_id ?? product.id;
166
- const productId = Number(rawProductId);
167
- if (!Number.isFinite(productId) || productId <= 0)
168
- return null;
169
- return productId;
170
- }
171
- function getTopLevelVariantId(product) {
172
- const rawVariantId = product.product_variant_id ?? product.variant_id;
173
- if (rawVariantId === void 0 || rawVariantId === null || rawVariantId === "") {
174
- return null;
175
- }
176
- const variantId = Number(rawVariantId);
177
- if (!Number.isFinite(variantId) || variantId <= 0)
178
- return null;
179
- return variantId;
180
- }
181
- function buildQuantityLimitIndex(limits) {
182
- const exactLimitMap = /* @__PURE__ */ new Map();
183
- const productLimitMap = /* @__PURE__ */ new Map();
184
- for (const limit of limits) {
185
- const targets = limit.targets || [];
186
- if (targets.length !== 1)
187
- continue;
188
- const target = targets[0];
189
- const productId = Number(target.product_id);
190
- if (!Number.isFinite(productId) || productId <= 0)
191
- continue;
192
- const variantId = Number(target.product_variant_id);
193
- const hasVariant = Number.isFinite(variantId) && variantId > 0;
194
- if (hasVariant) {
195
- const exactKey = buildProductKey(productId, variantId);
196
- const existed = exactLimitMap.get(exactKey) || [];
197
- exactLimitMap.set(exactKey, [...existed, limit]);
198
- } else {
199
- const existed = productLimitMap.get(productId) || [];
200
- productLimitMap.set(productId, [...existed, limit]);
201
- }
202
- }
203
- return {
204
- exactLimitMap,
205
- productLimitMap
206
- };
207
- }
208
- function resolveSkuMatchedQuantityLimits(params) {
209
- const { productId, variantId, limitIndex } = params;
210
- const exactMatched = variantId && variantId > 0 ? limitIndex.exactLimitMap.get(buildProductKey(productId, variantId)) || [] : [];
211
- const productMatched = limitIndex.productLimitMap.get(productId) || [];
212
- return [...exactMatched, ...productMatched];
213
- }
214
- function aggregateItemRuleLimit(matchedLimits) {
215
- if (!matchedLimits.length)
216
- return null;
217
- let min;
218
- let max;
219
- let remainingMax;
220
- let exact;
221
- let mustInclude = false;
222
- let maxSourceLimit;
223
- let remainingMaxSourceLimit;
224
- let exactSourceLimit;
225
- let minSourceLimit;
226
- let firstMessagedLimit;
227
- for (const limit of matchedLimits) {
228
- if (typeof limit.requiredMin === "number" && Number.isFinite(limit.requiredMin)) {
229
- if (min === void 0 || limit.requiredMin > min) {
230
- min = limit.requiredMin;
231
- minSourceLimit = limit;
232
- }
233
- }
234
- if (typeof limit.requiredMax === "number" && Number.isFinite(limit.requiredMax)) {
235
- if (max === void 0 || limit.requiredMax < max) {
236
- max = limit.requiredMax;
237
- maxSourceLimit = limit;
238
- }
239
- }
240
- if (typeof limit.remainingMax === "number" && Number.isFinite(limit.remainingMax)) {
241
- if (remainingMax === void 0 || limit.remainingMax < remainingMax) {
242
- remainingMax = limit.remainingMax;
243
- remainingMaxSourceLimit = limit;
244
- }
245
- }
246
- if (typeof limit.requiredExact === "number" && Number.isFinite(limit.requiredExact)) {
247
- exact = limit.requiredExact;
248
- exactSourceLimit = limit;
249
- }
250
- mustInclude = mustInclude || Boolean(limit.mustInclude);
251
- if (!firstMessagedLimit && limit.validationMessage) {
252
- firstMessagedLimit = limit;
253
- }
254
- }
255
- if (typeof exact === "number" && Number.isFinite(exact)) {
256
- min = exact;
257
- max = exact;
258
- }
259
- const maxMessageSource = maxSourceLimit || remainingMaxSourceLimit || exactSourceLimit || firstMessagedLimit;
260
- const minMessageSource = minSourceLimit || exactSourceLimit || firstMessagedLimit;
261
- const maxValidationMessage = maxMessageSource == null ? void 0 : maxMessageSource.validationMessage;
262
- const rawMaxValidationMessage = maxMessageSource == null ? void 0 : maxMessageSource.rawValidationMessage;
263
- const minValidationMessage = minMessageSource == null ? void 0 : minMessageSource.validationMessage;
264
- const rawMinValidationMessage = minMessageSource == null ? void 0 : minMessageSource.rawValidationMessage;
265
- const validationMessage = maxValidationMessage ?? minValidationMessage;
266
- const rawValidationMessage = rawMaxValidationMessage ?? rawMinValidationMessage;
267
- return {
268
- min,
269
- max,
270
- remainingMax,
271
- exact,
272
- mustInclude,
273
- validationMessage,
274
- rawValidationMessage,
275
- maxValidationMessage,
276
- rawMaxValidationMessage,
277
- minValidationMessage,
278
- rawMinValidationMessage
279
- };
280
- }
281
- function buildItemRuleBusinessData(params) {
282
- const { tempOrder, runtimeConfig, itemRuleConfigs } = params;
283
- const rawPax = runtimeConfig.pax || {};
284
- const adultPax = toNonNegativeInt(rawPax.adult);
285
- const childPax = toNonNegativeInt(rawPax.child);
286
- const totalPax = toNonNegativeInt(rawPax.total) || adultPax + childPax || 1;
287
- const cartItems = tempOrder.products.reduce((result, product) => {
288
- if (typeof product.product_id !== "number")
289
- return result;
290
- result.push({
291
- product_id: product.product_id,
292
- quantity: toNonNegativeInt(product.num),
293
- ...typeof product.product_variant_id === "number" ? { product_variant_id: product.product_variant_id } : {}
294
- });
295
- return result;
296
- }, []);
297
- const historicalItems = Array.isArray(runtimeConfig.historicalItems) ? runtimeConfig.historicalItems.reduce((result, item) => {
298
- if (typeof (item == null ? void 0 : item.product_id) !== "number")
299
- return result;
300
- result.push({
301
- product_id: item.product_id,
302
- quantity: toNonNegativeInt(item.quantity),
303
- ...typeof item.product_variant_id === "number" ? { product_variant_id: item.product_variant_id } : {}
304
- });
305
- return result;
306
- }, []) : [];
307
- return {
308
- pax: {
309
- total: totalPax,
310
- adult: adultPax,
311
- child: childPax
312
- },
313
- cartItems,
314
- historicalItems,
315
- serviceType: runtimeConfig.serviceType || "dine-in",
316
- submissionIndex: typeof runtimeConfig.submissionIndex === "number" ? toNonNegativeInt(runtimeConfig.submissionIndex) : tempOrder.order_id ? 1 : 0,
317
- custom: runtimeConfig.custom || {},
318
- strategyConfigs: itemRuleConfigs
319
- };
320
- }
321
- function attachItemRuleLimitsToTopLevelProducts(productList, limits) {
322
- if (!Array.isArray(productList))
323
- return productList;
324
- const limitIndex = buildQuantityLimitIndex(limits || []);
325
- for (const item of productList) {
326
- if (!item || typeof item !== "object")
327
- continue;
328
- const productItem = item;
329
- const productId = getTopLevelProductId(productItem);
330
- if (productId === null)
331
- continue;
332
- const variantId = getTopLevelVariantId(productItem);
333
- const matchedLimits = limits.length ? resolveSkuMatchedQuantityLimits({
334
- productId,
335
- variantId,
336
- limitIndex
337
- }) : [];
338
- const aggregatedLimit = aggregateItemRuleLimit(matchedLimits);
339
- if (aggregatedLimit) {
340
- productItem.item_rule_limit = aggregatedLimit;
341
- } else if ("item_rule_limit" in productItem) {
342
- delete productItem.item_rule_limit;
343
- }
344
- }
345
- return productList;
346
- }
347
- function buildProductLineFingerprint(productOptionItem, productBundle) {
348
- const optArr = Array.isArray(productOptionItem) ? productOptionItem : [];
349
- const normalizedOpts = optArr.map((item) => ({
350
- product_option_item_id: Number(item == null ? void 0 : item.product_option_item_id) || 0,
351
- option_group_id: Number(item == null ? void 0 : item.option_group_id) || 0,
352
- num: typeof (item == null ? void 0 : item.num) === "number" && !Number.isNaN(item.num) ? Math.max(1, Math.floor(item.num)) : 1,
353
- price: String((item == null ? void 0 : item.price) ?? "")
354
- })).sort((p, q) => {
355
- if (p.product_option_item_id !== q.product_option_item_id) {
356
- return p.product_option_item_id - q.product_option_item_id;
357
- }
358
- if (p.option_group_id !== q.option_group_id)
359
- return p.option_group_id - q.option_group_id;
360
- if (p.num !== q.num)
361
- return p.num - q.num;
362
- return p.price.localeCompare(q.price);
363
- });
364
- const bundleArr = Array.isArray(productBundle) ? productBundle : [];
365
- const normalizedBundles = bundleArr.map((item) => ({
366
- bundle_id: Number((item == null ? void 0 : item.bundle_id) ?? (item == null ? void 0 : item.id) ?? 0) || 0,
367
- product_id: Number(item == null ? void 0 : item.product_id) || 0,
368
- num: typeof (item == null ? void 0 : item.num) === "number" && !Number.isNaN(item.num) ? Math.max(1, Math.floor(item.num)) : 1
369
- })).sort((p, q) => {
370
- if (p.bundle_id !== q.bundle_id)
371
- return p.bundle_id - q.bundle_id;
372
- if (p.product_id !== q.product_id)
373
- return p.product_id - q.product_id;
374
- return p.num - q.num;
375
- });
376
- return JSON.stringify([normalizedOpts, normalizedBundles]);
377
- }
378
- function isSkuOnlyDeleteIdentity(x) {
379
- if (x.identity_key)
380
- return false;
381
- return !("product_option_item" in x) && !("product_bundle" in x);
382
- }
383
- function fingerprintForIdentityWithOptionKeys(x) {
384
- const row = x;
385
- const opts = "product_option_item" in row ? Array.isArray(row.product_option_item) ? row.product_option_item : [] : [];
386
- const buds = "product_bundle" in row ? Array.isArray(row.product_bundle) ? row.product_bundle : [] : [];
387
- return buildProductLineFingerprint(opts, buds);
388
- }
389
- function isIdentityMatch(a, b) {
390
- if (a.product_id !== b.product_id || a.product_variant_id !== b.product_variant_id)
391
- return false;
392
- const aHasKey = typeof a.identity_key === "string" && a.identity_key.length > 0;
393
- const bHasKey = typeof b.identity_key === "string" && b.identity_key.length > 0;
394
- if (aHasKey && bHasKey)
395
- return a.identity_key === b.identity_key;
396
- if (isSkuOnlyDeleteIdentity(a) || isSkuOnlyDeleteIdentity(b))
397
- return true;
398
- return fingerprintForIdentityWithOptionKeys(a) === fingerprintForIdentityWithOptionKeys(b);
399
- }
400
- function getProductIdentityIndex(products, identity) {
401
- return products.findIndex((item) => isIdentityMatch(item, identity));
402
- }
403
- function normalizeOrderProduct(product) {
404
- var _a, _b;
405
- const metadata = { ...product.metadata || {} };
406
- const resolvedIdentityKey = product.identity_key && String(product.identity_key).length > 0 ? String(product.identity_key) : (0, import_utils.createUuidV4)();
407
- if (!metadata.unique_identification_number) {
408
- metadata.unique_identification_number = resolvedIdentityKey;
409
- }
410
- const normalizedBundle = (product.product_bundle || []).map((item) => ({
411
- ...item,
412
- bundle_selling_price: item.bundle_selling_price ?? item.price ?? "0.00"
413
- // custom_price: item.custom_price ?? item.bundle_selling_price ?? item.price ?? '0.00',
414
- }));
415
- const normalizedOptions = product.product_option_item || [];
416
- const optionSum = (0, import_utils.sumOptionUnitPrice)(normalizedOptions);
417
- const isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === "2";
418
- const variantId = Number(product.product_variant_id || 0);
419
- const variantList = variantId ? (_a = metadata == null ? void 0 : metadata.origin) == null ? void 0 : _a.variant : null;
420
- const variantPrice = Array.isArray(variantList) ? (_b = variantList.find((v) => Number(v == null ? void 0 : v.id) === variantId)) == null ? void 0 : _b.price : void 0;
421
- const resolvedSource = (() => {
422
- var _a2, _b2;
423
- if (metadata.source_product_price !== void 0) {
424
- return String(metadata.source_product_price);
425
- }
426
- if (variantPrice !== void 0 && variantPrice !== null) {
427
- return String(variantPrice);
428
- }
429
- const originPrice = (_a2 = product._origin) == null ? void 0 : _a2.price;
430
- if (originPrice !== void 0 && originPrice !== null) {
431
- return String(originPrice);
432
- }
433
- const originBasePrice = (_b2 = product._origin) == null ? void 0 : _b2.base_price;
434
- if (originBasePrice !== void 0 && originBasePrice !== null) {
435
- return String(originBasePrice);
436
- }
437
- if (!isV2 && metadata.main_product_original_price !== void 0) {
438
- return String(metadata.main_product_original_price);
439
- }
440
- return product.original_price ?? product.selling_price ?? "0.00";
441
- })();
442
- const mainOriginalDec = new import_decimal.default(Number(resolvedSource) || 0).plus(optionSum);
443
- const mainOriginalStr = mainOriginalDec.toDecimalPlaces(2).toFixed(2);
444
- let mainSellingDec;
445
- if (isV2 && metadata.main_product_selling_price != null) {
446
- mainSellingDec = new import_decimal.default(Number(metadata.main_product_selling_price) || 0);
447
- } else if (metadata.main_product_selling_price != null && metadata.main_product_original_price != null) {
448
- const legacyOriginal = new import_decimal.default(Number(metadata.main_product_original_price) || 0);
449
- const legacySelling = new import_decimal.default(Number(metadata.main_product_selling_price) || 0);
450
- const legacyDiscount = legacyOriginal.minus(legacySelling);
451
- mainSellingDec = mainOriginalDec.minus(legacyDiscount);
452
- } else if (product.original_price != null && product.selling_price != null && new import_decimal.default(Number(product.original_price) || 0).greaterThan(
453
- new import_decimal.default(Number(product.selling_price) || 0)
454
- )) {
455
- const topOriginal = new import_decimal.default(Number(product.original_price) || 0);
456
- const topSelling = new import_decimal.default(Number(product.selling_price) || 0);
457
- const legacyDiscount = topOriginal.minus(topSelling);
458
- mainSellingDec = mainOriginalDec.minus(legacyDiscount);
459
- } else {
460
- mainSellingDec = mainOriginalDec;
461
- }
462
- const mainSellingStr = mainSellingDec.toDecimalPlaces(2).toFixed(2);
463
- metadata.source_product_price = resolvedSource;
464
- metadata.main_product_original_price = mainOriginalStr;
465
- metadata.main_product_selling_price = mainSellingStr;
466
- metadata.price_schema_version = 2;
467
- const composedSellingPrice = (0, import_utils.composeLinePrice)({
468
- mainPrice: mainSellingStr,
469
- bundle: normalizedBundle
470
- });
471
- const composedOriginalPrice = (0, import_utils.composeLinePrice)({
472
- mainPrice: mainOriginalStr,
473
- bundle: normalizedBundle,
474
- useOriginalBundle: true
475
- });
476
- return {
477
- order_detail_id: product.order_detail_id || null,
478
- product_id: product.product_id,
479
- num: getSafeProductNum(product.num),
480
- product_variant_id: product.product_variant_id,
481
- identity_key: resolvedIdentityKey,
482
- product_option_item: normalizedOptions,
483
- selling_price: composedSellingPrice,
484
- original_price: composedOriginalPrice,
485
- tax_fee: product.tax_fee || "0.00",
486
- is_charge_tax: product.is_charge_tax ?? 0,
487
- discount_list: product.discount_list || [],
488
- product_bundle: normalizedBundle,
489
- metadata,
490
- note: product.note != null ? String(product.note) : "",
491
- _origin: product._origin
492
- };
493
- }
494
- function collectLinkProductIdsFromReservationRules(rules) {
495
- if (!Array.isArray(rules))
496
- return [];
497
- const ids = [];
498
- for (const entry of rules) {
499
- if (!entry || typeof entry !== "object")
500
- continue;
501
- const rec = entry;
502
- if (rec.type !== "link")
503
- continue;
504
- if (!Array.isArray(rec.value))
505
- continue;
506
- for (const v of rec.value) {
507
- const n = Number(v);
508
- if (Number.isFinite(n) && n > 0)
509
- ids.push(Math.floor(n));
510
- }
511
- }
512
- return [...new Set(ids)];
513
- }
514
- function findReservationRuleProductByResourceId(products, resourceId) {
515
- var _a;
516
- const numericResourceId = Number(resourceId);
517
- if (!Number.isFinite(numericResourceId) || numericResourceId <= 0)
518
- return void 0;
519
- for (const product of products) {
520
- const resources = (_a = product == null ? void 0 : product.product_resource) == null ? void 0 : _a.resources;
521
- if (!Array.isArray(resources))
522
- continue;
523
- const hasMatchedResource = resources.some((resource) => {
524
- const defaultResources = Array.isArray(resource == null ? void 0 : resource.default_resource) ? resource.default_resource : [];
525
- const optionalResources = Array.isArray(resource == null ? void 0 : resource.optional_resource) ? resource.optional_resource : [];
526
- return [...defaultResources, ...optionalResources].some(
527
- (id) => Number(id) === numericResourceId
528
- );
529
- });
530
- if (hasMatchedResource)
531
- return product;
532
- }
533
- return void 0;
534
- }
535
- function pickFirstDurationMinutesFromProducts(products) {
536
- var _a;
537
- for (const product of products) {
538
- const value = (_a = product == null ? void 0 : product.duration) == null ? void 0 : _a.value;
539
- const n = Number(value);
540
- if (Number.isFinite(n) && n > 0)
541
- return Math.floor(n);
542
- }
543
- return void 0;
544
- }
545
- function hasCustomCapacityProduct(products) {
546
- return products.some((p) => {
547
- var _a;
548
- return ((_a = p == null ? void 0 : p.capacity) == null ? void 0 : _a.type) === "custom";
549
- });
550
- }
551
- function computeResourceIsFull(params) {
552
- const { resourceSelectType, lastOrderId, capacityList, capacity } = params;
553
- if (resourceSelectType === "single")
554
- return Boolean(lastOrderId);
555
- if (resourceSelectType !== "multiple")
556
- return false;
557
- const totalCapacity = Number(capacity);
558
- if (!Number.isFinite(totalCapacity) || totalCapacity <= 0)
559
- return false;
560
- const now = (0, import_dayjs.default)();
561
- let occupied = 0;
562
- for (const slot of capacityList || []) {
563
- const start = (0, import_dayjs.default)(slot == null ? void 0 : slot.start_at);
564
- const end = (0, import_dayjs.default)(slot == null ? void 0 : slot.end_at);
565
- if (!start.isValid() || !end.isValid())
566
- continue;
567
- if ((now.isAfter(start) || now.isSame(start)) && (now.isBefore(end) || now.isSame(end))) {
568
- const pax = Number(slot == null ? void 0 : slot.pax);
569
- if (Number.isFinite(pax) && pax > 0)
570
- occupied += pax;
571
- }
572
- }
573
- return occupied >= totalCapacity;
574
- }
575
- function pickFirstCustomCapacityPaxBounds(products) {
576
- for (const p of products) {
577
- const cap = p == null ? void 0 : p.capacity;
578
- if (!cap || cap.type !== "custom")
579
- continue;
580
- if (!Array.isArray(cap.custom) || cap.custom.length === 0)
581
- continue;
582
- const row = cap.custom[0];
583
- if (!row || typeof row !== "object")
584
- continue;
585
- const raw = row;
586
- const out = {};
587
- if (raw.min !== null && raw.min !== void 0 && raw.min !== "") {
588
- const min = Number(raw.min);
589
- if (Number.isFinite(min))
590
- out.min = min;
591
- }
592
- if (raw.max !== null && raw.max !== void 0 && raw.max !== "") {
593
- const max = Number(raw.max);
594
- if (Number.isFinite(max))
595
- out.max = max;
596
- }
597
- if (out.min !== void 0 || out.max !== void 0)
598
- return out;
599
- }
600
- return void 0;
601
- }
602
- function pickFirstCustomCapacityDimensionId(products) {
603
- for (const p of products) {
604
- const cap = p == null ? void 0 : p.capacity;
605
- if (!cap || cap.type !== "custom")
606
- continue;
607
- if (!Array.isArray(cap.custom) || cap.custom.length === 0)
608
- continue;
609
- const row = cap.custom[0];
610
- if (!row || typeof row !== "object")
611
- continue;
612
- const id = row.id;
613
- if (id === null || id === void 0 || id === "")
614
- continue;
615
- if (typeof id === "number" && Number.isFinite(id))
616
- return id;
617
- if (typeof id === "string") {
618
- const trimmed = id.trim();
619
- if (!trimmed)
620
- continue;
621
- return trimmed;
622
- }
623
- }
624
- return void 0;
625
- }
626
- // Annotate the CommonJS export names for ESM import in node:
627
- 0 && (module.exports = {
628
- aggregateItemRuleLimit,
629
- attachItemRuleLimitsToTopLevelProducts,
630
- buildItemRuleBusinessData,
631
- buildProductKey,
632
- buildProductLineFingerprint,
633
- buildQuantityLimitIndex,
634
- collectLinkProductIdsFromReservationRules,
635
- computeResourceIsFull,
636
- createEmptySummary,
637
- extractStrategyModelIdsFromTableConfig,
638
- findReservationRuleProductByResourceId,
639
- getProductIdentityIndex,
640
- getSafeProductNum,
641
- getTopLevelProductId,
642
- getTopLevelVariantId,
643
- hasCustomCapacityProduct,
644
- isIdentityMatch,
645
- isSkuOnlyDeleteIdentity,
646
- normalizeEnabledItemRuleIds,
647
- normalizeItemRuleStrategies,
648
- normalizeOrderProduct,
649
- pickFirstCustomCapacityDimensionId,
650
- pickFirstCustomCapacityPaxBounds,
651
- pickFirstDurationMinutesFromProducts,
652
- resolveSkuMatchedQuantityLimits,
653
- toBoolean,
654
- toNonNegativeInt,
655
- toNonNegativeNumber,
656
- toPositiveString,
657
- toPriceString
658
- });