@pisell/pisellos 0.0.569 → 0.10.1

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 (329) hide show
  1. package/dist/core/index.js +10 -6
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -3
  4. package/dist/model/strategy/adapter/walletPass/evaluator.js +7 -5
  5. package/dist/model/strategy/adapter/walletPass/example.js +26 -3
  6. package/dist/model/strategy/adapter/walletPass/index.js +5 -5
  7. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -3
  8. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  9. package/dist/model/strategy/adapter/walletPass/utils.js +17 -92
  10. package/dist/model/strategy/strategy-example.js +19 -5
  11. package/dist/modules/BaseModule.d.ts +1 -1
  12. package/dist/modules/BaseModule.js +8 -10
  13. package/dist/modules/Cart/index.js +3 -0
  14. package/dist/modules/Cart/utils/cartProduct.js +1 -0
  15. package/dist/modules/Cart/utils/cartResource.js +0 -2
  16. package/dist/modules/Cart/utils/changePrice.js +9 -16
  17. package/dist/modules/Date/index.js +5 -1
  18. package/dist/modules/Discount/index.d.ts +0 -1
  19. package/dist/modules/Discount/index.js +7 -22
  20. package/dist/modules/Discount/types.d.ts +0 -1
  21. package/dist/modules/OpenData/index.js +2 -0
  22. package/dist/modules/Order/index.d.ts +1 -1
  23. package/dist/modules/Order/index.js +70 -40
  24. package/dist/modules/Payment/index.js +162 -97
  25. package/dist/modules/Payment/types.d.ts +4 -8
  26. package/dist/modules/Payment/walletpass.d.ts +0 -2
  27. package/dist/modules/Payment/walletpass.js +5 -4
  28. package/dist/modules/ProductList/index.d.ts +1 -1
  29. package/dist/modules/ProductList/index.js +3 -12
  30. package/dist/modules/ProductList/types.d.ts +0 -1
  31. package/dist/modules/Rules/index.js +126 -427
  32. package/dist/modules/SalesSummary/utils.js +1 -2
  33. package/dist/modules/Schedule/getDateIsInSchedule.js +0 -5
  34. package/dist/modules/Schedule/index.js +1 -0
  35. package/dist/modules/Schedule/utils.js +1 -0
  36. package/dist/modules/Step/index.js +1 -0
  37. package/dist/modules/Summary/utils.js +22 -43
  38. package/dist/plugins/request.js +4 -1
  39. package/dist/plugins/window.js +6 -2
  40. package/dist/server/index.js +129 -97
  41. package/dist/server/modules/menu/index.js +41 -32
  42. package/dist/server/modules/order/index.js +4 -2
  43. package/dist/server/modules/products/index.js +42 -24
  44. package/dist/server/modules/quotation/index.js +38 -29
  45. package/dist/server/modules/resource/index.js +4 -3
  46. package/dist/server/modules/schedule/index.js +35 -27
  47. package/dist/server/utils/product.js +1 -0
  48. package/dist/solution/BaseSales/index.js +41 -38
  49. package/dist/solution/BookingByStep/index.d.ts +1 -1
  50. package/dist/solution/BookingByStep/index.js +60 -11
  51. package/dist/solution/BookingByStep/utils/capacity.js +11 -1
  52. package/dist/solution/BookingByStep/utils/resources.js +3 -1
  53. package/dist/solution/BookingByStep/utils/timeslots.js +43 -2
  54. package/dist/solution/BookingTicket/index.d.ts +1 -1
  55. package/dist/solution/BookingTicket/index.js +2 -0
  56. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +7 -6
  57. package/dist/solution/BookingTicket/utils/scan/handleScan.js +31 -25
  58. package/dist/solution/BookingTicket/utils/scan/index.js +10 -6
  59. package/dist/solution/BuyTickets/index.js +12 -9
  60. package/dist/solution/Checkout/index.js +252 -177
  61. package/dist/solution/Checkout/utils/index.js +16 -4
  62. package/dist/solution/RegisterAndLogin/index.js +76 -30
  63. package/dist/solution/ScanOrder/index.js +60 -50
  64. package/dist/solution/ShopDiscount/index.js +14 -15
  65. package/dist/solution/ShopDiscount/types.d.ts +4 -5
  66. package/dist/solution/ShopDiscount/utils.d.ts +0 -9
  67. package/dist/solution/ShopDiscount/utils.js +0 -9
  68. package/dist/solution/VenueBooking/index.d.ts +3 -31
  69. package/dist/solution/VenueBooking/index.js +496 -651
  70. package/dist/solution/VenueBooking/types.d.ts +1 -3
  71. package/dist/solution/VenueBooking/types.js +0 -1
  72. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  73. package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
  74. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  75. package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
  76. package/dist/types/index.d.ts +1 -1
  77. package/dist/utils/task.js +18 -15
  78. package/dist/utils/watch.js +1 -0
  79. package/lib/apis/picoding.js +0 -2
  80. package/lib/core/index.js +132 -130
  81. package/lib/effects/index.js +57 -46
  82. package/lib/index.d.ts +0 -1
  83. package/lib/index.js +50 -92
  84. package/lib/model/index.js +21 -14
  85. package/lib/model/strategy/adapter/dataVariant/adapter.js +50 -38
  86. package/lib/model/strategy/adapter/dataVariant/evaluator.js +236 -162
  87. package/lib/model/strategy/adapter/dataVariant/examples.js +237 -229
  88. package/lib/model/strategy/adapter/dataVariant/index.js +34 -39
  89. package/lib/model/strategy/adapter/dataVariant/type.js +28 -57
  90. package/lib/model/strategy/adapter/index.js +64 -100
  91. package/lib/model/strategy/adapter/itemRule/adapter.js +144 -156
  92. package/lib/model/strategy/adapter/itemRule/evaluator.js +48 -36
  93. package/lib/model/strategy/adapter/itemRule/examples.js +225 -295
  94. package/lib/model/strategy/adapter/itemRule/index.js +57 -83
  95. package/lib/model/strategy/adapter/itemRule/type.js +36 -97
  96. package/lib/model/strategy/adapter/promotion/adapter.js +63 -84
  97. package/lib/model/strategy/adapter/promotion/evaluator.js +231 -381
  98. package/lib/model/strategy/adapter/promotion/examples.js +159 -139
  99. package/lib/model/strategy/adapter/promotion/index.js +0 -1
  100. package/lib/model/strategy/adapter/promotion/type.js +35 -199
  101. package/lib/model/strategy/adapter/type.js +16 -4
  102. package/lib/model/strategy/adapter/walletPass/evaluator.js +152 -180
  103. package/lib/model/strategy/adapter/walletPass/example.js +190 -217
  104. package/lib/model/strategy/adapter/walletPass/index.js +51 -75
  105. package/lib/model/strategy/adapter/walletPass/locales.js +58 -36
  106. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -3
  107. package/lib/model/strategy/adapter/walletPass/type.js +16 -4
  108. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  109. package/lib/model/strategy/adapter/walletPass/utils.js +383 -678
  110. package/lib/model/strategy/engine.js +168 -270
  111. package/lib/model/strategy/index.js +34 -49
  112. package/lib/model/strategy/strategy-example.js +239 -243
  113. package/lib/model/strategy/type.js +40 -100
  114. package/lib/modules/Account/index.js +53 -39
  115. package/lib/modules/Account/types.js +33 -20
  116. package/lib/modules/AccountList/index.js +154 -116
  117. package/lib/modules/AccountList/types.js +31 -30
  118. package/lib/modules/AccountList/utils.js +30 -18
  119. package/lib/modules/BaseModule.d.ts +1 -1
  120. package/lib/modules/BaseModule.js +46 -25
  121. package/lib/modules/BookingContext/index.js +136 -158
  122. package/lib/modules/BookingContext/types.js +32 -46
  123. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +143 -131
  124. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +82 -75
  125. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +150 -170
  126. package/lib/modules/BookingContext/utils/flexible.js +55 -38
  127. package/lib/modules/BookingContext/utils/formatResourceList.js +34 -19
  128. package/lib/modules/BookingContext/utils/index.js +41 -124
  129. package/lib/modules/BookingContext/utils/noResource.js +70 -58
  130. package/lib/modules/BookingContext/utils/orderLineDisplay.js +41 -14
  131. package/lib/modules/BookingContext/utils/productExtend.js +155 -202
  132. package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
  133. package/lib/modules/BookingContext/utils/resourceSelection.js +41 -19
  134. package/lib/modules/BookingContext/utils/resources.js +167 -209
  135. package/lib/modules/BookingContext/utils/serviceTimes.js +116 -115
  136. package/lib/modules/BookingContext/utils/timeSlices.js +80 -70
  137. package/lib/modules/Cart/index.js +124 -170
  138. package/lib/modules/Cart/types.js +51 -46
  139. package/lib/modules/Cart/utils/cartAccount.js +39 -40
  140. package/lib/modules/Cart/utils/cartDate.js +61 -56
  141. package/lib/modules/Cart/utils/cartDiscount.js +33 -28
  142. package/lib/modules/Cart/utils/cartNote.js +32 -27
  143. package/lib/modules/Cart/utils/cartProduct.js +251 -321
  144. package/lib/modules/Cart/utils/cartRelationForms.js +35 -29
  145. package/lib/modules/Cart/utils/cartResource.js +78 -72
  146. package/lib/modules/Cart/utils/changePrice.js +50 -28
  147. package/lib/modules/Cart/utils/index.js +48 -106
  148. package/lib/modules/Customer/constants.js +34 -13
  149. package/lib/modules/Customer/index.js +169 -232
  150. package/lib/modules/Customer/types.js +35 -38
  151. package/lib/modules/Date/index.js +115 -116
  152. package/lib/modules/Date/types.js +28 -16
  153. package/lib/modules/Date/utils.js +123 -174
  154. package/lib/modules/Discount/index.d.ts +0 -1
  155. package/lib/modules/Discount/index.js +128 -130
  156. package/lib/modules/Discount/types.d.ts +0 -1
  157. package/lib/modules/Discount/types.js +31 -9
  158. package/lib/modules/Guests/index.js +56 -30
  159. package/lib/modules/Guests/types.js +33 -23
  160. package/lib/modules/Holder/index.js +189 -209
  161. package/lib/modules/Holder/types.js +16 -4
  162. package/lib/modules/Holder/utils.js +49 -20
  163. package/lib/modules/OpenData/index.js +76 -69
  164. package/lib/modules/OpenData/types.js +16 -4
  165. package/lib/modules/OpenData/utils.js +78 -44
  166. package/lib/modules/Order/index.d.ts +1 -1
  167. package/lib/modules/Order/index.js +1909 -1572
  168. package/lib/modules/Order/types.js +35 -78
  169. package/lib/modules/Order/utils/bundleDiscountHydration.js +74 -41
  170. package/lib/modules/Order/utils/manualProductDiscount.js +123 -124
  171. package/lib/modules/Order/utils/orderCollectionIdentity.js +210 -148
  172. package/lib/modules/Order/utils.js +634 -799
  173. package/lib/modules/Payment/cash.js +33 -20
  174. package/lib/modules/Payment/cashRecommendationAlgorithm.js +76 -145
  175. package/lib/modules/Payment/eftpos.js +30 -16
  176. package/lib/modules/Payment/index.js +378 -518
  177. package/lib/modules/Payment/mx51.js +0 -1
  178. package/lib/modules/Payment/types.d.ts +4 -8
  179. package/lib/modules/Payment/types.js +107 -216
  180. package/lib/modules/Payment/utils.js +48 -51
  181. package/lib/modules/Payment/walletpass.d.ts +0 -2
  182. package/lib/modules/Payment/walletpass.js +211 -226
  183. package/lib/modules/Product/index.js +46 -51
  184. package/lib/modules/Product/types.js +16 -4
  185. package/lib/modules/Product/utils.js +33 -32
  186. package/lib/modules/ProductList/index.d.ts +1 -1
  187. package/lib/modules/ProductList/index.js +117 -117
  188. package/lib/modules/ProductList/types.d.ts +0 -1
  189. package/lib/modules/ProductList/types.js +31 -9
  190. package/lib/modules/Quotation/index.js +100 -66
  191. package/lib/modules/Quotation/types.js +16 -4
  192. package/lib/modules/Resource/index.js +59 -27
  193. package/lib/modules/Resource/types.js +32 -22
  194. package/lib/modules/Resource/utils.js +38 -30
  195. package/lib/modules/ResourcePlanner/index.js +61 -60
  196. package/lib/modules/ResourcePlanner/planner.js +384 -346
  197. package/lib/modules/ResourcePlanner/types.js +16 -4
  198. package/lib/modules/Rules/index.js +903 -1475
  199. package/lib/modules/Rules/types.js +40 -17
  200. package/lib/modules/SalesSummary/index.js +90 -85
  201. package/lib/modules/SalesSummary/types.js +16 -4
  202. package/lib/modules/SalesSummary/utils.js +427 -351
  203. package/lib/modules/ScanOrderLogger/index.js +79 -59
  204. package/lib/modules/ScanOrderLogger/providers/feishu.js +78 -54
  205. package/lib/modules/ScanOrderLogger/providers/grafana.js +36 -13
  206. package/lib/modules/ScanOrderLogger/types.js +16 -4
  207. package/lib/modules/Schedule/getDateIsInSchedule.js +163 -339
  208. package/lib/modules/Schedule/index.js +114 -100
  209. package/lib/modules/Schedule/type.js +16 -4
  210. package/lib/modules/Schedule/types.js +16 -4
  211. package/lib/modules/Schedule/utils.js +291 -433
  212. package/lib/modules/Step/index.js +52 -40
  213. package/lib/modules/Step/tyeps.js +16 -4
  214. package/lib/modules/Summary/index.js +71 -66
  215. package/lib/modules/Summary/types.js +16 -4
  216. package/lib/modules/Summary/utils.js +418 -791
  217. package/lib/modules/SurchargeList/index.js +60 -46
  218. package/lib/modules/SurchargeList/types.js +16 -4
  219. package/lib/modules/index.js +63 -245
  220. package/lib/plugins/app.js +16 -4
  221. package/lib/plugins/index.js +25 -36
  222. package/lib/plugins/request.js +126 -137
  223. package/lib/plugins/shopStore.js +16 -4
  224. package/lib/plugins/user.js +16 -4
  225. package/lib/plugins/window.js +179 -171
  226. package/lib/server/index.js +2337 -2675
  227. package/lib/server/modules/floor-plan/index.js +123 -102
  228. package/lib/server/modules/floor-plan/types.js +30 -15
  229. package/lib/server/modules/index.js +68 -106
  230. package/lib/server/modules/menu/index.js +122 -146
  231. package/lib/server/modules/menu/types.js +31 -18
  232. package/lib/server/modules/order/index.js +642 -567
  233. package/lib/server/modules/order/types.js +32 -117
  234. package/lib/server/modules/order/utils/filterBookings.js +194 -219
  235. package/lib/server/modules/order/utils/filterOrders.js +92 -118
  236. package/lib/server/modules/payment/index.js +83 -59
  237. package/lib/server/modules/payment/types.js +16 -4
  238. package/lib/server/modules/products/index.js +459 -575
  239. package/lib/server/modules/products/types.js +34 -44
  240. package/lib/server/modules/quotation/index.js +172 -137
  241. package/lib/server/modules/quotation/types.js +31 -21
  242. package/lib/server/modules/resource/index.js +184 -213
  243. package/lib/server/modules/resource/types.js +33 -42
  244. package/lib/server/modules/schedule/index.js +123 -135
  245. package/lib/server/modules/schedule/types.js +21 -14
  246. package/lib/server/modules/schedule/utils.js +163 -334
  247. package/lib/server/types.js +16 -4
  248. package/lib/server/utils/index.js +23 -25
  249. package/lib/server/utils/product.js +139 -196
  250. package/lib/server/utils/schedule.js +41 -34
  251. package/lib/server/utils/small-ticket.js +456 -478
  252. package/lib/server/utils/time.js +49 -40
  253. package/lib/solution/BaseSales/index.js +1016 -850
  254. package/lib/solution/BaseSales/types.js +37 -41
  255. package/lib/solution/BaseSales/utils/cartPromotion.js +460 -611
  256. package/lib/solution/BaseSales/utils/parseSalesResponse.js +105 -85
  257. package/lib/solution/BaseSales/utils/quotationPrice.js +114 -56
  258. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +143 -102
  259. package/lib/solution/BaseSales/utils.js +140 -155
  260. package/lib/solution/BookingByStep/index.d.ts +1 -1
  261. package/lib/solution/BookingByStep/index.js +1340 -1530
  262. package/lib/solution/BookingByStep/types.js +99 -40
  263. package/lib/solution/BookingByStep/utils/capacity.js +160 -192
  264. package/lib/solution/BookingByStep/utils/products.js +52 -42
  265. package/lib/solution/BookingByStep/utils/resources.js +330 -527
  266. package/lib/solution/BookingByStep/utils/stock.js +44 -65
  267. package/lib/solution/BookingByStep/utils/timeslots.js +131 -129
  268. package/lib/solution/BookingTicket/index.d.ts +1 -1
  269. package/lib/solution/BookingTicket/index.js +459 -543
  270. package/lib/solution/BookingTicket/types.js +77 -99
  271. package/lib/solution/BookingTicket/utils/addProductDecision.js +184 -219
  272. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +89 -58
  273. package/lib/solution/BookingTicket/utils/bookingStatus.js +78 -107
  274. package/lib/solution/BookingTicket/utils/cartView.js +94 -110
  275. package/lib/solution/BookingTicket/utils/exampleData.js +0 -185
  276. package/lib/solution/BookingTicket/utils/orderCustomer.js +41 -18
  277. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +86 -219
  278. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +93 -144
  279. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +91 -79
  280. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +41 -54
  281. package/lib/solution/BookingTicket/utils/scan/handleScan.js +81 -84
  282. package/lib/solution/BookingTicket/utils/scan/index.js +104 -98
  283. package/lib/solution/BookingTicket/utils/scan/scanCache.js +43 -90
  284. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +64 -52
  285. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +58 -56
  286. package/lib/solution/BuyTickets/index.js +70 -67
  287. package/lib/solution/BuyTickets/types.js +38 -22
  288. package/lib/solution/Checkout/index.js +1158 -1451
  289. package/lib/solution/Checkout/types.js +61 -91
  290. package/lib/solution/Checkout/utils/index.js +156 -228
  291. package/lib/solution/PlaceOrder/index.js +0 -55
  292. package/lib/solution/RegisterAndLogin/config.js +460 -493
  293. package/lib/solution/RegisterAndLogin/index.js +630 -633
  294. package/lib/solution/RegisterAndLogin/types.js +76 -189
  295. package/lib/solution/RegisterAndLogin/utils.js +125 -183
  296. package/lib/solution/Sales/index.js +320 -317
  297. package/lib/solution/Sales/types.js +33 -27
  298. package/lib/solution/ScanOrder/index.js +862 -831
  299. package/lib/solution/ScanOrder/types.js +34 -33
  300. package/lib/solution/ScanOrder/utils.js +371 -406
  301. package/lib/solution/ShopDiscount/index.js +233 -235
  302. package/lib/solution/ShopDiscount/types.d.ts +4 -5
  303. package/lib/solution/ShopDiscount/types.js +37 -15
  304. package/lib/solution/ShopDiscount/utils.d.ts +0 -9
  305. package/lib/solution/ShopDiscount/utils.js +172 -309
  306. package/lib/solution/UnifiedBookingSales/index.js +405 -379
  307. package/lib/solution/UnifiedBookingSales/types.js +31 -12
  308. package/lib/solution/VenueBooking/index.d.ts +3 -31
  309. package/lib/solution/VenueBooking/index.js +916 -967
  310. package/lib/solution/VenueBooking/types.d.ts +1 -3
  311. package/lib/solution/VenueBooking/types.js +39 -20
  312. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  313. package/lib/solution/VenueBooking/utils/dateSummary.js +62 -25
  314. package/lib/solution/VenueBooking/utils/resource.js +54 -31
  315. package/lib/solution/VenueBooking/utils/slotMerge.js +107 -94
  316. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  317. package/lib/solution/VenueBooking/utils/timeSlot.js +133 -138
  318. package/lib/solution/VenueBooking/utils.js +67 -130
  319. package/lib/solution/index.js +41 -124
  320. package/lib/store/createStore.js +29 -32
  321. package/lib/types/index.d.ts +1 -1
  322. package/lib/types/index.js +16 -4
  323. package/lib/utils/task.js +36 -36
  324. package/lib/utils/watch.js +47 -81
  325. package/package.json +2 -4
  326. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  327. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
  328. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  329. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -192
@@ -1,27 +1,36 @@
1
- "use strict";
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
18
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
19
+ // src/model/strategy/adapter/itemRule/adapter.ts
20
+ var adapter_exports = {};
21
+ __export(adapter_exports, {
22
+ ItemRuleAdapter: () => ItemRuleAdapter,
23
+ default: () => adapter_default
5
24
  });
6
- exports.default = exports.ItemRuleAdapter = void 0;
7
- var _type = require("./type");
8
- /**
9
- * ItemRule 适配器
10
- *
11
- * 将堂食扫码点餐的商品规则业务数据转换为策略引擎格式,
12
- * 并将引擎结果转换为数量校验和预填购物车的业务结果。
13
- */
14
- class ItemRuleAdapter {
15
- name = 'ItemRuleAdapter';
16
- version = '1.0.0';
25
+ module.exports = __toCommonJS(adapter_exports);
26
+ var import_type = require("./type");
27
+ var ItemRuleAdapter = class {
28
+ constructor() {
29
+ this.name = "ItemRuleAdapter";
30
+ this.version = "1.0.0";
31
+ }
17
32
  prepareContext(businessData) {
18
- const {
19
- pax,
20
- cartItems,
21
- serviceType,
22
- submissionIndex,
23
- custom
24
- } = businessData;
33
+ const { pax, cartItems, serviceType, submissionIndex, custom } = businessData;
25
34
  return {
26
35
  entities: {
27
36
  cartItems,
@@ -29,7 +38,7 @@ class ItemRuleAdapter {
29
38
  pax
30
39
  },
31
40
  attributes: {
32
- serviceType: serviceType || '',
41
+ serviceType: serviceType || "",
33
42
  totalPax: pax.total,
34
43
  adultPax: pax.adult,
35
44
  childPax: pax.child,
@@ -47,61 +56,47 @@ class ItemRuleAdapter {
47
56
  const quantityChecks = [];
48
57
  const prefillItems = [];
49
58
  if (!result.applicable || !businessData) {
50
- return {
51
- quantityChecks,
52
- prefillItems
53
- };
59
+ return { quantityChecks, prefillItems };
54
60
  }
55
61
  for (const action of result.matchedActions) {
56
- if (action.type === _type.ITEM_RULE_ACTION_TYPES.QUANTITY_CHECK) {
62
+ if (action.type === import_type.ITEM_RULE_ACTION_TYPES.QUANTITY_CHECK) {
57
63
  const checkResult = this.processQuantityCheck(action, businessData);
58
64
  if (checkResult) {
59
65
  quantityChecks.push(checkResult);
60
66
  }
61
- } else if (action.type === _type.ITEM_RULE_ACTION_TYPES.PREFILL_CART) {
67
+ } else if (action.type === import_type.ITEM_RULE_ACTION_TYPES.PREFILL_CART) {
62
68
  const items = this.processPrefillCart(action, businessData);
63
69
  prefillItems.push(...items);
64
70
  }
65
71
  }
66
- return {
67
- quantityChecks,
68
- prefillItems
69
- };
72
+ return { quantityChecks, prefillItems };
70
73
  }
71
74
  formatConfig(result, businessData) {
72
- return {
73
- result,
74
- businessData
75
- };
75
+ return { result, businessData };
76
76
  }
77
-
78
77
  // ============================================
79
78
  // Quantity Check 处理
80
79
  // ============================================
81
-
82
80
  processQuantityCheck(action, businessData) {
83
81
  const config = action.config;
84
- if (!config) return null;
85
- const {
86
- scope,
87
- quantityRules,
88
- targetType,
89
- targets,
90
- validationMessage
91
- } = config;
82
+ if (!config)
83
+ return null;
84
+ const { scope, quantityRules, targetType, targets, validationMessage } = config;
92
85
  if (!this.shouldEvaluateForScope(scope, businessData.submissionIndex ?? 0)) {
93
86
  return null;
94
87
  }
95
- const actualQuantity = this.calculateActualQuantity(targets, scope, businessData);
96
- const {
97
- passed,
98
- failedRules,
88
+ const actualQuantity = this.calculateActualQuantity(
89
+ targets,
90
+ scope,
91
+ businessData
92
+ );
93
+ const { passed, failedRules, requiredMin, requiredMax, requiredExact, mustInclude } = this.evaluateQuantityRules(quantityRules, actualQuantity, businessData);
94
+ const message = this.formatValidationMessage(
95
+ validationMessage,
99
96
  requiredMin,
100
97
  requiredMax,
101
- requiredExact,
102
- mustInclude
103
- } = this.evaluateQuantityRules(quantityRules, actualQuantity, businessData);
104
- const message = this.formatValidationMessage(validationMessage, requiredMin, requiredMax, requiredExact);
98
+ requiredExact
99
+ );
105
100
  return {
106
101
  ruleId: action.id,
107
102
  passed,
@@ -114,44 +109,42 @@ class ItemRuleAdapter {
114
109
  mustInclude,
115
110
  validationMessage: message,
116
111
  scope,
117
- failedRules: passed ? undefined : failedRules
112
+ failedRules: passed ? void 0 : failedRules
118
113
  };
119
114
  }
120
-
121
115
  /**
122
116
  * 根据 scope 判断当前提交是否需要评估此规则
123
117
  */
124
118
  shouldEvaluateForScope(scope, submissionIndex) {
125
119
  switch (scope) {
126
- case 'each_submission':
120
+ case "each_submission":
127
121
  return true;
128
- case 'first_submission_only':
122
+ case "first_submission_only":
129
123
  return submissionIndex === 0;
130
- case 'subsequent_only':
124
+ case "subsequent_only":
131
125
  return submissionIndex > 0;
132
- case 'cumulative':
126
+ case "cumulative":
133
127
  return true;
134
128
  default:
135
129
  return true;
136
130
  }
137
131
  }
138
-
139
132
  /**
140
133
  * 计算目标商品在购物车中的实际数量
141
134
  *
142
135
  * cumulative scope 时还会加上历史订单数量。
143
136
  */
144
137
  calculateActualQuantity(targets, scope, businessData) {
145
- const targetIds = new Set(targets.map(t => t.product_id));
138
+ const targetIds = new Set(targets.map((t) => t.product_id));
146
139
  let quantity = 0;
147
- const countFromItems = items => {
140
+ const countFromItems = (items) => {
148
141
  for (const item of items) {
149
142
  if (targetIds.has(item.product_id)) {
150
143
  quantity += item.quantity;
151
144
  }
152
145
  }
153
146
  };
154
- if (scope === 'cumulative') {
147
+ if (scope === "cumulative") {
155
148
  if (businessData.historicalItems) {
156
149
  countFromItems(businessData.historicalItems);
157
150
  }
@@ -173,42 +166,38 @@ class ItemRuleAdapter {
173
166
  for (const rule of rules) {
174
167
  const resolvedValue = this.resolveQuantityValue(rule, businessData);
175
168
  switch (rule.comparison) {
176
- case 'minimum':
177
- {
178
- if (requiredMin === undefined || resolvedValue > requiredMin) {
179
- requiredMin = resolvedValue;
180
- }
181
- if (actualQuantity < resolvedValue) {
182
- failedRules.push(rule);
183
- }
184
- break;
169
+ case "minimum": {
170
+ if (requiredMin === void 0 || resolvedValue > requiredMin) {
171
+ requiredMin = resolvedValue;
172
+ }
173
+ if (actualQuantity < resolvedValue) {
174
+ failedRules.push(rule);
175
+ }
176
+ break;
177
+ }
178
+ case "maximum": {
179
+ if (requiredMax === void 0 || resolvedValue < requiredMax) {
180
+ requiredMax = resolvedValue;
185
181
  }
186
- case 'maximum':
187
- {
188
- if (requiredMax === undefined || resolvedValue < requiredMax) {
189
- requiredMax = resolvedValue;
190
- }
191
- if (actualQuantity > resolvedValue) {
192
- failedRules.push(rule);
193
- }
194
- break;
182
+ if (actualQuantity > resolvedValue) {
183
+ failedRules.push(rule);
195
184
  }
196
- case 'exact':
197
- {
198
- requiredExact = resolvedValue;
199
- if (actualQuantity !== resolvedValue) {
200
- failedRules.push(rule);
201
- }
202
- break;
185
+ break;
186
+ }
187
+ case "exact": {
188
+ requiredExact = resolvedValue;
189
+ if (actualQuantity !== resolvedValue) {
190
+ failedRules.push(rule);
203
191
  }
204
- case 'must_include':
205
- {
206
- mustInclude = true;
207
- if (actualQuantity < 1) {
208
- failedRules.push(rule);
209
- }
210
- break;
192
+ break;
193
+ }
194
+ case "must_include": {
195
+ mustInclude = true;
196
+ if (actualQuantity < 1) {
197
+ failedRules.push(rule);
211
198
  }
199
+ break;
200
+ }
212
201
  }
213
202
  }
214
203
  return {
@@ -220,39 +209,36 @@ class ItemRuleAdapter {
220
209
  mustInclude
221
210
  };
222
211
  }
223
-
224
212
  /**
225
213
  * 根据 source 解析出数量规则的实际数值
226
214
  */
227
215
  resolveQuantityValue(rule, businessData) {
228
216
  switch (rule.source) {
229
- case 'total_pax':
217
+ case "total_pax":
230
218
  return businessData.pax.total;
231
- case 'adult_pax':
219
+ case "adult_pax":
232
220
  return businessData.pax.adult;
233
- case 'fixed':
221
+ case "fixed":
234
222
  return rule.value ?? 0;
235
223
  default:
236
224
  return rule.value ?? 0;
237
225
  }
238
226
  }
239
-
240
227
  /**
241
228
  * 格式化校验提示语,替换 {min} {max} 占位符
242
229
  */
243
230
  formatValidationMessage(template, min, max, exact, locale) {
244
- if (!template) return undefined;
245
- let text = typeof template === 'string' ? template : template[locale || 'en'] || Object.values(template)[0] || '';
246
- text = text.replace(/\{min\}/g, String(min ?? ''));
247
- text = text.replace(/\{max\}/g, String(max ?? ''));
248
- text = text.replace(/\{exact\}/g, String(exact ?? ''));
231
+ if (!template)
232
+ return void 0;
233
+ let text = typeof template === "string" ? template : template[locale || "en"] || Object.values(template)[0] || "";
234
+ text = text.replace(/\{min\}/g, String(min ?? ""));
235
+ text = text.replace(/\{max\}/g, String(max ?? ""));
236
+ text = text.replace(/\{exact\}/g, String(exact ?? ""));
249
237
  return text;
250
238
  }
251
-
252
239
  // ============================================
253
240
  // Quantity Limit 提取(仅读取配置,不做校验)
254
241
  // ============================================
255
-
256
242
  /**
257
243
  * 从单个 QUANTITY_CHECK action 中提取数量限制配置。
258
244
  *
@@ -262,14 +248,9 @@ class ItemRuleAdapter {
262
248
  */
263
249
  extractQuantityLimits(action, businessData) {
264
250
  const config = action.config;
265
- if (!config) return null;
266
- const {
267
- scope,
268
- quantityRules,
269
- targetType,
270
- targets,
271
- validationMessage
272
- } = config;
251
+ if (!config)
252
+ return null;
253
+ const { scope, quantityRules, targetType, targets, validationMessage } = config;
273
254
  if (!this.shouldEvaluateForScope(scope, businessData.submissionIndex ?? 0)) {
274
255
  return null;
275
256
  }
@@ -280,34 +261,40 @@ class ItemRuleAdapter {
280
261
  for (const rule of quantityRules) {
281
262
  const resolvedValue = this.resolveQuantityValue(rule, businessData);
282
263
  switch (rule.comparison) {
283
- case 'minimum':
284
- {
285
- if (requiredMin === undefined || resolvedValue > requiredMin) {
286
- requiredMin = resolvedValue;
287
- }
288
- break;
289
- }
290
- case 'maximum':
291
- {
292
- if (requiredMax === undefined || resolvedValue < requiredMax) {
293
- requiredMax = resolvedValue;
294
- }
295
- break;
264
+ case "minimum": {
265
+ if (requiredMin === void 0 || resolvedValue > requiredMin) {
266
+ requiredMin = resolvedValue;
296
267
  }
297
- case 'exact':
298
- {
299
- requiredExact = resolvedValue;
300
- break;
301
- }
302
- case 'must_include':
303
- {
304
- mustInclude = true;
305
- break;
268
+ break;
269
+ }
270
+ case "maximum": {
271
+ if (requiredMax === void 0 || resolvedValue < requiredMax) {
272
+ requiredMax = resolvedValue;
306
273
  }
274
+ break;
275
+ }
276
+ case "exact": {
277
+ requiredExact = resolvedValue;
278
+ break;
279
+ }
280
+ case "must_include": {
281
+ mustInclude = true;
282
+ break;
283
+ }
307
284
  }
308
285
  }
309
- const remainingMax = this.calculateRemainingMax(scope, requiredMax, targets, businessData);
310
- const formattedValidationMessage = this.formatValidationMessage(validationMessage, requiredMin, requiredMax, requiredExact);
286
+ const remainingMax = this.calculateRemainingMax(
287
+ scope,
288
+ requiredMax,
289
+ targets,
290
+ businessData
291
+ );
292
+ const formattedValidationMessage = this.formatValidationMessage(
293
+ validationMessage,
294
+ requiredMin,
295
+ requiredMax,
296
+ requiredExact
297
+ );
311
298
  return {
312
299
  ruleId: action.id,
313
300
  targetType,
@@ -322,7 +309,6 @@ class ItemRuleAdapter {
322
309
  rawValidationMessage: validationMessage
323
310
  };
324
311
  }
325
-
326
312
  /**
327
313
  * 计算当前提交剩余可选的最大数量。
328
314
  *
@@ -331,14 +317,14 @@ class ItemRuleAdapter {
331
317
  * 其余场景返回 undefined,保持向后兼容。
332
318
  */
333
319
  calculateRemainingMax(scope, requiredMax, targets, businessData) {
334
- if (scope !== 'cumulative' || typeof requiredMax !== 'number') {
335
- return undefined;
320
+ if (scope !== "cumulative" || typeof requiredMax !== "number") {
321
+ return void 0;
336
322
  }
337
323
  const historicalItems = businessData.historicalItems;
338
- if (!historicalItems?.length) {
324
+ if (!(historicalItems == null ? void 0 : historicalItems.length)) {
339
325
  return Math.max(0, requiredMax);
340
326
  }
341
- const targetIds = new Set(targets.map(t => t.product_id));
327
+ const targetIds = new Set(targets.map((t) => t.product_id));
342
328
  let historicalQty = 0;
343
329
  for (const item of historicalItems) {
344
330
  if (targetIds.has(item.product_id)) {
@@ -347,18 +333,18 @@ class ItemRuleAdapter {
347
333
  }
348
334
  return Math.max(0, requiredMax - historicalQty);
349
335
  }
350
-
351
336
  // ============================================
352
337
  // Prefill Cart 处理
353
338
  // ============================================
354
-
355
339
  processPrefillCart(action, businessData) {
356
340
  const config = action.config;
357
- if (!config?.products) return [];
341
+ if (!(config == null ? void 0 : config.products))
342
+ return [];
358
343
  const results = [];
359
344
  for (const prefillProduct of config.products) {
360
345
  const quantity = this.resolvePrefillQuantity(prefillProduct.quantityFrom, prefillProduct.quantity, businessData);
361
- if (quantity <= 0) continue;
346
+ if (quantity <= 0)
347
+ continue;
362
348
  results.push({
363
349
  ruleId: action.id,
364
350
  product_id: prefillProduct.product_id,
@@ -368,22 +354,24 @@ class ItemRuleAdapter {
368
354
  }
369
355
  return results;
370
356
  }
371
-
372
357
  /**
373
358
  * 根据 quantityFrom 计算预填数量
374
359
  */
375
360
  resolvePrefillQuantity(quantityFrom, fixedValue, businessData) {
376
361
  switch (quantityFrom) {
377
- case 'total_pax':
362
+ case "total_pax":
378
363
  return businessData.pax.total;
379
- case 'adult_pax':
364
+ case "adult_pax":
380
365
  return businessData.pax.adult;
381
- case 'fixed':
366
+ case "fixed":
382
367
  return fixedValue ?? 0;
383
368
  default:
384
369
  return fixedValue ?? 0;
385
370
  }
386
371
  }
387
- }
388
- exports.ItemRuleAdapter = ItemRuleAdapter;
389
- var _default = exports.default = ItemRuleAdapter;
372
+ };
373
+ var adapter_default = ItemRuleAdapter;
374
+ // Annotate the CommonJS export names for ESM import in node:
375
+ 0 && (module.exports = {
376
+ ItemRuleAdapter
377
+ });
@@ -1,46 +1,56 @@
1
- "use strict";
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
18
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
19
+ // src/model/strategy/adapter/itemRule/evaluator.ts
20
+ var evaluator_exports = {};
21
+ __export(evaluator_exports, {
22
+ ItemRuleEvaluator: () => ItemRuleEvaluator
5
23
  });
6
- exports.ItemRuleEvaluator = void 0;
7
- var _engine = require("../../engine");
8
- var _adapter = require("./adapter");
9
- var _type = require("./type");
10
- /**
11
- * ItemRule 评估器
12
- *
13
- * 组合 StrategyEngine + ItemRuleAdapter,提供面向业务的高层 API。
14
- * 支持批量评估多条 item_rule 策略配置,聚合数量校验和预填购物车结果。
15
- */
16
- class ItemRuleEvaluator {
17
- engine;
18
- adapter;
19
- strategyConfigs = [];
24
+ module.exports = __toCommonJS(evaluator_exports);
25
+ var import_engine = require("../../engine");
26
+ var import_adapter = require("./adapter");
27
+ var import_type = require("./type");
28
+ var ItemRuleEvaluator = class {
20
29
  constructor() {
21
- this.engine = new _engine.StrategyEngine({
30
+ this.strategyConfigs = [];
31
+ this.engine = new import_engine.StrategyEngine({
22
32
  debug: false,
23
33
  enableTrace: false
24
34
  });
25
- this.adapter = new _adapter.ItemRuleAdapter();
35
+ this.adapter = new import_adapter.ItemRuleAdapter();
26
36
  }
27
-
28
37
  /**
29
38
  * 设置策略配置列表
30
39
  * 自动过滤 metadata.type === 'item_rule' 的配置
31
40
  */
32
41
  setStrategyConfigs(configs) {
33
- this.strategyConfigs = configs.filter(c => c.metadata.type === 'item_rule');
42
+ this.strategyConfigs = configs.filter(
43
+ (c) => c.metadata.type === "item_rule"
44
+ );
34
45
  }
35
46
  getStrategyConfigs() {
36
47
  return this.strategyConfigs;
37
48
  }
38
-
39
49
  /**
40
50
  * 完整评估:数量校验 + 预填购物车
41
51
  */
42
52
  evaluate(businessData) {
43
- const configs = businessData.strategyConfigs ? businessData.strategyConfigs.filter(c => c.metadata.type === 'item_rule') : this.strategyConfigs;
53
+ const configs = businessData.strategyConfigs ? businessData.strategyConfigs.filter((c) => c.metadata.type === "item_rule") : this.strategyConfigs;
44
54
  const allQuantityChecks = [];
45
55
  const allPrefillItems = [];
46
56
  const rawResults = [];
@@ -48,14 +58,14 @@ class ItemRuleEvaluator {
48
58
  for (const config of configs) {
49
59
  const evalResult = this.engine.evaluate(config, context);
50
60
  rawResults.push(evalResult);
51
- const {
52
- quantityChecks,
53
- prefillItems
54
- } = this.adapter.transformResult(evalResult, businessData);
61
+ const { quantityChecks, prefillItems } = this.adapter.transformResult(
62
+ evalResult,
63
+ businessData
64
+ );
55
65
  allQuantityChecks.push(...quantityChecks);
56
66
  allPrefillItems.push(...prefillItems);
57
67
  }
58
- const failedChecks = allQuantityChecks.filter(c => !c.passed);
68
+ const failedChecks = allQuantityChecks.filter((c) => !c.passed);
59
69
  return {
60
70
  quantityChecks: allQuantityChecks,
61
71
  prefillItems: allPrefillItems,
@@ -64,7 +74,6 @@ class ItemRuleEvaluator {
64
74
  rawResults
65
75
  };
66
76
  }
67
-
68
77
  /**
69
78
  * 获取当前配置中各商品的数量限制
70
79
  *
@@ -73,14 +82,16 @@ class ItemRuleEvaluator {
73
82
  * 会评估条件是否满足、根据 scope + submissionIndex 过滤。
74
83
  */
75
84
  getQuantityLimits(businessData) {
76
- const configs = businessData.strategyConfigs ? businessData.strategyConfigs.filter(c => c.metadata.type === 'item_rule') : this.strategyConfigs;
85
+ const configs = businessData.strategyConfigs ? businessData.strategyConfigs.filter((c) => c.metadata.type === "item_rule") : this.strategyConfigs;
77
86
  const results = [];
78
87
  const context = this.adapter.prepareContext(businessData);
79
88
  for (const config of configs) {
80
89
  const evalResult = this.engine.evaluate(config, context);
81
- if (!evalResult.applicable) continue;
90
+ if (!evalResult.applicable)
91
+ continue;
82
92
  for (const action of evalResult.matchedActions) {
83
- if (action.type !== _type.ITEM_RULE_ACTION_TYPES.QUANTITY_CHECK) continue;
93
+ if (action.type !== import_type.ITEM_RULE_ACTION_TYPES.QUANTITY_CHECK)
94
+ continue;
84
95
  const limit = this.adapter.extractQuantityLimits(action, businessData);
85
96
  if (limit) {
86
97
  results.push(limit);
@@ -89,7 +100,6 @@ class ItemRuleEvaluator {
89
100
  }
90
101
  return results;
91
102
  }
92
-
93
103
  /**
94
104
  * 便捷方法:仅做数量校验,返回是否全部通过及失败详情
95
105
  */
@@ -100,7 +110,6 @@ class ItemRuleEvaluator {
100
110
  failures: result.failedChecks
101
111
  };
102
112
  }
103
-
104
113
  /**
105
114
  * 便捷方法:仅获取需要预填到购物车的商品
106
115
  */
@@ -108,5 +117,8 @@ class ItemRuleEvaluator {
108
117
  const result = this.evaluate(businessData);
109
118
  return result.prefillItems;
110
119
  }
111
- }
112
- exports.ItemRuleEvaluator = ItemRuleEvaluator;
120
+ };
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ ItemRuleEvaluator
124
+ });