@pisell/pisellos 2.1.149 → 2.1.151

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