@pisell/pisellos 2.2.314 → 2.2.316

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 (268) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +3 -1
  3. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  4. package/dist/model/strategy/adapter/itemRule/adapter.js +74 -7
  5. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  6. package/dist/model/strategy/adapter/itemRule/evaluator.js +13 -0
  7. package/dist/model/strategy/adapter/itemRule/type.d.ts +40 -1
  8. package/dist/model/strategy/adapter/itemRule/type.js +10 -0
  9. package/dist/model/strategy/adapter/promotion/evaluator.js +89 -104
  10. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +3 -1
  11. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +28 -4
  12. package/dist/modules/BookingContext/utils/productExtend.d.ts +7 -0
  13. package/dist/modules/BookingContext/utils/productExtend.js +62 -18
  14. package/dist/modules/BookingContext/utils/resources.js +1 -1
  15. package/dist/modules/BusinessAvailability/index.d.ts +30 -0
  16. package/dist/modules/BusinessAvailability/index.js +204 -0
  17. package/dist/modules/Cart/index.js +4 -3
  18. package/dist/modules/Cart/types.d.ts +2 -0
  19. package/dist/modules/Cart/utils/cartProduct.d.ts +3 -1
  20. package/dist/modules/Cart/utils/cartProduct.js +59 -32
  21. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  22. package/dist/modules/FulfillmentTiming/index.js +407 -0
  23. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  24. package/dist/modules/FulfillmentTiming/types.js +1 -0
  25. package/dist/modules/Holder/utils.d.ts +2 -0
  26. package/dist/modules/Holder/utils.js +32 -2
  27. package/dist/modules/OpenData/contactInfo.d.ts +20 -0
  28. package/dist/modules/OpenData/contactInfo.js +70 -0
  29. package/dist/modules/OpenData/index.d.ts +1 -0
  30. package/dist/modules/OpenData/index.js +1 -0
  31. package/dist/modules/OpenData/types.d.ts +23 -0
  32. package/dist/modules/Order/holderRelations.d.ts +14 -0
  33. package/dist/modules/Order/holderRelations.js +154 -0
  34. package/dist/modules/Order/index.d.ts +16 -4
  35. package/dist/modules/Order/index.js +926 -511
  36. package/dist/modules/Order/localEftposState.d.ts +13 -0
  37. package/dist/modules/Order/localEftposState.js +39 -0
  38. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  39. package/dist/modules/Order/pickupTiming.js +53 -0
  40. package/dist/modules/Order/types.d.ts +49 -3
  41. package/dist/modules/Order/types.js +2 -0
  42. package/dist/modules/Order/utils/discountProductLineIdentity.d.ts +1 -1
  43. package/dist/modules/Order/utils/discountProductLineIdentity.js +142 -7
  44. package/dist/modules/Order/utils/orderCollectionIdentity.js +24 -10
  45. package/dist/modules/Order/utils.d.ts +2 -1
  46. package/dist/modules/Order/utils.js +61 -17
  47. package/dist/modules/Payment/index.js +9 -10
  48. package/dist/modules/Product/types.d.ts +11 -0
  49. package/dist/modules/ProductList/index.js +1 -1
  50. package/dist/modules/ResourcePlanner/planner.d.ts +2 -0
  51. package/dist/modules/ResourcePlanner/planner.js +332 -23
  52. package/dist/modules/ResourcePlanner/types.d.ts +29 -0
  53. package/dist/modules/Rules/index.js +62 -61
  54. package/dist/modules/Schedule/index.d.ts +8 -0
  55. package/dist/modules/Schedule/index.js +141 -39
  56. package/dist/modules/index.d.ts +1 -0
  57. package/dist/modules/index.js +1 -0
  58. package/dist/plugins/request.d.ts +7 -0
  59. package/dist/server/index.d.ts +1 -0
  60. package/dist/server/index.js +1557 -1322
  61. package/dist/server/modules/form/index.d.ts +19 -0
  62. package/dist/server/modules/form/index.js +205 -0
  63. package/dist/server/modules/form/types.d.ts +13 -0
  64. package/dist/server/modules/form/types.js +3 -0
  65. package/dist/server/modules/index.d.ts +3 -0
  66. package/dist/server/modules/index.js +4 -0
  67. package/dist/server/modules/order/index.d.ts +19 -0
  68. package/dist/server/modules/order/index.js +1071 -774
  69. package/dist/server/modules/order/types.d.ts +4 -0
  70. package/dist/server/modules/products/index.d.ts +28 -7
  71. package/dist/server/modules/products/index.js +1297 -770
  72. package/dist/server/modules/products/replication.d.ts +8 -0
  73. package/dist/server/modules/products/replication.js +69 -0
  74. package/dist/server/modules/products/types.d.ts +12 -1
  75. package/dist/server/modules/products/types.js +4 -0
  76. package/dist/server/test.json +1 -1
  77. package/dist/server/utils/small-ticket.d.ts +1 -85
  78. package/dist/server/utils/small-ticket.js +2 -2542
  79. package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
  80. package/dist/shared/payment/loadPaymentMethods.js +66 -0
  81. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +8 -0
  82. package/dist/shared/receipt/customerInvoiceLanguages.js +60 -0
  83. package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +27 -0
  84. package/dist/shared/receipt/loadCustomerInvoiceLayout.js +184 -0
  85. package/dist/shared/receipt/small-ticket.d.ts +96 -0
  86. package/dist/shared/receipt/small-ticket.js +2763 -0
  87. package/dist/shared/receipt/templateVisibility.d.ts +26 -0
  88. package/dist/shared/receipt/templateVisibility.js +68 -0
  89. package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  90. package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
  91. package/dist/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  92. package/dist/solution/BaseSales/fulfillmentItemRules.js +750 -0
  93. package/dist/solution/BaseSales/index.d.ts +43 -16
  94. package/dist/solution/BaseSales/index.js +2028 -1247
  95. package/dist/solution/BaseSales/pickupTiming.d.ts +47 -0
  96. package/dist/solution/BaseSales/pickupTiming.js +616 -0
  97. package/dist/solution/BaseSales/types.d.ts +12 -0
  98. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -1
  99. package/dist/solution/BaseSales/utils/parseSalesResponse.js +10 -3
  100. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -4
  101. package/dist/solution/BookingByStep/index.d.ts +4 -2
  102. package/dist/solution/BookingByStep/index.js +8 -3
  103. package/dist/solution/BookingTicket/index.d.ts +23 -3
  104. package/dist/solution/BookingTicket/index.js +867 -507
  105. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -1
  106. package/dist/solution/BookingTicket/utils/addProductDecision.js +1 -1
  107. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  108. package/dist/solution/OrderInvoicePreview/index.d.ts +66 -0
  109. package/dist/solution/OrderInvoicePreview/index.js +340 -0
  110. package/dist/solution/RegisterAndLogin/config.js +54 -11
  111. package/dist/solution/RegisterAndLogin/index.d.ts +2 -0
  112. package/dist/solution/RegisterAndLogin/index.js +1 -1
  113. package/dist/solution/RegisterAndLogin/utils.d.ts +12 -4
  114. package/dist/solution/RegisterAndLogin/utils.js +36 -16
  115. package/dist/solution/ScanOrder/index.js +65 -31
  116. package/dist/solution/ScanOrder/types.d.ts +3 -0
  117. package/dist/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
  118. package/dist/solution/UnifiedBookingSales/businessAvailability.js +292 -0
  119. package/dist/solution/UnifiedBookingSales/index.d.ts +36 -4
  120. package/dist/solution/UnifiedBookingSales/index.js +1715 -906
  121. package/dist/solution/UnifiedBookingSales/types.d.ts +16 -2
  122. package/dist/solution/VenueBooking/index.d.ts +15 -2
  123. package/dist/solution/VenueBooking/index.js +1062 -785
  124. package/dist/solution/VenueBooking/types.d.ts +2 -1
  125. package/dist/solution/VenueBooking/types.js +1 -0
  126. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  127. package/dist/solution/VenueBooking/utils/dateSummary.js +7 -4
  128. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  129. package/dist/solution/VenueBooking/utils/smartPricing.js +273 -0
  130. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +1 -0
  131. package/dist/solution/VenueBooking/utils/timeSlot.js +6 -3
  132. package/dist/solution/index.d.ts +1 -0
  133. package/dist/solution/index.js +2 -1
  134. package/lib/index.d.ts +2 -0
  135. package/lib/index.js +21 -1
  136. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  137. package/lib/model/strategy/adapter/itemRule/adapter.js +54 -4
  138. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  139. package/lib/model/strategy/adapter/itemRule/evaluator.js +9 -0
  140. package/lib/model/strategy/adapter/itemRule/type.d.ts +40 -1
  141. package/lib/model/strategy/adapter/itemRule/type.js +10 -0
  142. package/lib/model/strategy/adapter/promotion/evaluator.js +9 -14
  143. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  144. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +3 -1
  145. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +17 -1
  146. package/lib/modules/BookingContext/utils/productExtend.d.ts +7 -0
  147. package/lib/modules/BookingContext/utils/productExtend.js +45 -2
  148. package/lib/modules/BookingContext/utils/resources.js +1 -1
  149. package/lib/modules/BusinessAvailability/index.d.ts +30 -0
  150. package/lib/modules/BusinessAvailability/index.js +146 -0
  151. package/lib/modules/Cart/index.js +4 -2
  152. package/lib/modules/Cart/types.d.ts +2 -0
  153. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -1
  154. package/lib/modules/Cart/utils/cartProduct.js +39 -20
  155. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  156. package/lib/modules/FulfillmentTiming/index.js +359 -0
  157. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  158. package/lib/modules/FulfillmentTiming/types.js +5 -0
  159. package/lib/modules/Holder/utils.d.ts +2 -0
  160. package/lib/modules/Holder/utils.js +27 -1
  161. package/lib/modules/OpenData/contactInfo.d.ts +20 -0
  162. package/lib/modules/OpenData/contactInfo.js +56 -0
  163. package/lib/modules/OpenData/index.d.ts +1 -0
  164. package/lib/modules/OpenData/index.js +12 -0
  165. package/lib/modules/OpenData/types.d.ts +23 -0
  166. package/lib/modules/Order/holderRelations.d.ts +14 -0
  167. package/lib/modules/Order/holderRelations.js +98 -0
  168. package/lib/modules/Order/index.d.ts +16 -4
  169. package/lib/modules/Order/index.js +284 -50
  170. package/lib/modules/Order/localEftposState.d.ts +13 -0
  171. package/lib/modules/Order/localEftposState.js +44 -0
  172. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  173. package/lib/modules/Order/pickupTiming.js +61 -0
  174. package/lib/modules/Order/types.d.ts +49 -3
  175. package/lib/modules/Order/types.js +1 -0
  176. package/lib/modules/Order/utils/discountProductLineIdentity.d.ts +1 -1
  177. package/lib/modules/Order/utils/discountProductLineIdentity.js +51 -2
  178. package/lib/modules/Order/utils/orderCollectionIdentity.js +5 -0
  179. package/lib/modules/Order/utils.d.ts +2 -1
  180. package/lib/modules/Order/utils.js +49 -11
  181. package/lib/modules/Payment/index.js +3 -4
  182. package/lib/modules/Product/types.d.ts +11 -0
  183. package/lib/modules/ProductList/index.js +1 -1
  184. package/lib/modules/ResourcePlanner/planner.d.ts +2 -0
  185. package/lib/modules/ResourcePlanner/planner.js +252 -8
  186. package/lib/modules/ResourcePlanner/types.d.ts +29 -0
  187. package/lib/modules/Rules/index.js +2 -1
  188. package/lib/modules/Schedule/index.d.ts +8 -0
  189. package/lib/modules/Schedule/index.js +68 -12
  190. package/lib/modules/index.d.ts +1 -0
  191. package/lib/modules/index.js +11 -0
  192. package/lib/plugins/request.d.ts +7 -0
  193. package/lib/server/index.d.ts +1 -0
  194. package/lib/server/index.js +166 -39
  195. package/lib/server/modules/form/index.d.ts +19 -0
  196. package/lib/server/modules/form/index.js +73 -0
  197. package/lib/server/modules/form/types.d.ts +13 -0
  198. package/lib/server/modules/form/types.js +9 -0
  199. package/lib/server/modules/index.d.ts +3 -0
  200. package/lib/server/modules/index.js +15 -1
  201. package/lib/server/modules/order/index.d.ts +19 -0
  202. package/lib/server/modules/order/index.js +160 -7
  203. package/lib/server/modules/order/types.d.ts +4 -0
  204. package/lib/server/modules/products/index.d.ts +28 -7
  205. package/lib/server/modules/products/index.js +226 -63
  206. package/lib/server/modules/products/replication.d.ts +8 -0
  207. package/lib/server/modules/products/replication.js +30 -0
  208. package/lib/server/modules/products/types.d.ts +12 -1
  209. package/lib/server/modules/products/types.js +3 -0
  210. package/lib/server/test.json +1 -1
  211. package/lib/server/utils/small-ticket.d.ts +1 -85
  212. package/lib/server/utils/small-ticket.js +9 -2305
  213. package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
  214. package/lib/shared/payment/loadPaymentMethods.js +40 -0
  215. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +8 -0
  216. package/lib/shared/receipt/customerInvoiceLanguages.js +58 -0
  217. package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +27 -0
  218. package/lib/shared/receipt/loadCustomerInvoiceLayout.js +124 -0
  219. package/lib/shared/receipt/small-ticket.d.ts +96 -0
  220. package/lib/shared/receipt/small-ticket.js +2555 -0
  221. package/lib/shared/receipt/templateVisibility.d.ts +26 -0
  222. package/lib/shared/receipt/templateVisibility.js +67 -0
  223. package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  224. package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
  225. package/lib/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  226. package/lib/solution/BaseSales/fulfillmentItemRules.js +259 -0
  227. package/lib/solution/BaseSales/index.d.ts +43 -16
  228. package/lib/solution/BaseSales/index.js +401 -33
  229. package/lib/solution/BaseSales/pickupTiming.d.ts +47 -0
  230. package/lib/solution/BaseSales/pickupTiming.js +290 -0
  231. package/lib/solution/BaseSales/types.d.ts +12 -0
  232. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -1
  233. package/lib/solution/BaseSales/utils/parseSalesResponse.js +7 -0
  234. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +16 -8
  235. package/lib/solution/BookingByStep/index.d.ts +4 -2
  236. package/lib/solution/BookingByStep/index.js +7 -3
  237. package/lib/solution/BookingTicket/index.d.ts +23 -3
  238. package/lib/solution/BookingTicket/index.js +197 -9
  239. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -1
  240. package/lib/solution/BookingTicket/utils/addProductDecision.js +1 -1
  241. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  242. package/lib/solution/OrderInvoicePreview/index.d.ts +66 -0
  243. package/lib/solution/OrderInvoicePreview/index.js +246 -0
  244. package/lib/solution/RegisterAndLogin/config.js +57 -11
  245. package/lib/solution/RegisterAndLogin/index.d.ts +2 -0
  246. package/lib/solution/RegisterAndLogin/index.js +9 -1
  247. package/lib/solution/RegisterAndLogin/utils.d.ts +12 -4
  248. package/lib/solution/RegisterAndLogin/utils.js +24 -17
  249. package/lib/solution/ScanOrder/index.js +59 -20
  250. package/lib/solution/ScanOrder/types.d.ts +3 -0
  251. package/lib/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
  252. package/lib/solution/UnifiedBookingSales/businessAvailability.js +138 -0
  253. package/lib/solution/UnifiedBookingSales/index.d.ts +36 -4
  254. package/lib/solution/UnifiedBookingSales/index.js +562 -75
  255. package/lib/solution/UnifiedBookingSales/types.d.ts +16 -2
  256. package/lib/solution/VenueBooking/index.d.ts +15 -2
  257. package/lib/solution/VenueBooking/index.js +243 -96
  258. package/lib/solution/VenueBooking/types.d.ts +2 -1
  259. package/lib/solution/VenueBooking/types.js +1 -0
  260. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  261. package/lib/solution/VenueBooking/utils/dateSummary.js +7 -4
  262. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  263. package/lib/solution/VenueBooking/utils/smartPricing.js +224 -0
  264. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +1 -0
  265. package/lib/solution/VenueBooking/utils/timeSlot.js +5 -2
  266. package/lib/solution/index.d.ts +1 -0
  267. package/lib/solution/index.js +11 -0
  268. package/package.json +1 -1
@@ -33,29 +33,49 @@ export function validatePhone(phone) {
33
33
  var phoneRegex = /^(\+\d{1,3}[- ]?)?\d{10,14}$/;
34
34
  return phoneRegex.test(cleanPhone);
35
35
  }
36
-
37
- /**
38
- * 验证密码强度
39
- */
36
+ /** 验证密码强度;不传 options 时保持原有规则与返回格式。 */
40
37
  export function validatePassword(password) {
38
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
41
39
  var errors = [];
42
- if (password.length < 8) {
43
- errors.push('密码长度至少为8位');
40
+ var _options$minLength = options.minLength,
41
+ minLength = _options$minLength === void 0 ? 8 : _options$minLength,
42
+ _options$maxLength = options.maxLength,
43
+ maxLength = _options$maxLength === void 0 ? 128 : _options$maxLength,
44
+ _options$requireLower = options.requireLowercase,
45
+ requireLowercase = _options$requireLower === void 0 ? true : _options$requireLower,
46
+ _options$requireUpper = options.requireUppercase,
47
+ requireUppercase = _options$requireUpper === void 0 ? true : _options$requireUpper,
48
+ _options$requireNumbe = options.requireNumber,
49
+ requireNumber = _options$requireNumbe === void 0 ? true : _options$requireNumbe,
50
+ _options$requireSpeci = options.requireSpecialCharacters,
51
+ requireSpecialCharacters = _options$requireSpeci === void 0 ? true : _options$requireSpeci,
52
+ _options$specialChara = options.specialCharactersPattern,
53
+ specialCharactersPattern = _options$specialChara === void 0 ? /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/ : _options$specialChara,
54
+ _options$messages = options.messages,
55
+ messages = _options$messages === void 0 ? {} : _options$messages;
56
+ if (password.length < minLength) {
57
+ var _messages$minLength;
58
+ errors.push((_messages$minLength = messages.minLength) !== null && _messages$minLength !== void 0 ? _messages$minLength : "\u5BC6\u7801\u957F\u5EA6\u81F3\u5C11\u4E3A".concat(minLength, "\u4F4D"));
44
59
  }
45
- if (password.length > 128) {
46
- errors.push('密码长度不能超过128位');
60
+ if (password.length > maxLength) {
61
+ var _messages$maxLength;
62
+ errors.push((_messages$maxLength = messages.maxLength) !== null && _messages$maxLength !== void 0 ? _messages$maxLength : "\u5BC6\u7801\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7".concat(maxLength, "\u4F4D"));
47
63
  }
48
- if (!/[a-z]/.test(password)) {
49
- errors.push('密码必须包含至少一个小写字母');
64
+ if (requireLowercase && !/[a-z]/.test(password)) {
65
+ var _messages$requireLowe;
66
+ errors.push((_messages$requireLowe = messages.requireLowercase) !== null && _messages$requireLowe !== void 0 ? _messages$requireLowe : '密码必须包含至少一个小写字母');
50
67
  }
51
- if (!/[A-Z]/.test(password)) {
52
- errors.push('密码必须包含至少一个大写字母');
68
+ if (requireUppercase && !/[A-Z]/.test(password)) {
69
+ var _messages$requireUppe;
70
+ errors.push((_messages$requireUppe = messages.requireUppercase) !== null && _messages$requireUppe !== void 0 ? _messages$requireUppe : '密码必须包含至少一个大写字母');
53
71
  }
54
- if (!/\d/.test(password)) {
55
- errors.push('密码必须包含至少一个数字');
72
+ if (requireNumber && !/\d/.test(password)) {
73
+ var _messages$requireNumb;
74
+ errors.push((_messages$requireNumb = messages.requireNumber) !== null && _messages$requireNumb !== void 0 ? _messages$requireNumb : '密码必须包含至少一个数字');
56
75
  }
57
- if (!/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password)) {
58
- errors.push('密码必须包含至少一个特殊字符');
76
+ if (requireSpecialCharacters && !specialCharactersPattern.test(password)) {
77
+ var _messages$requireSpec;
78
+ errors.push((_messages$requireSpec = messages.requireSpecialCharacters) !== null && _messages$requireSpec !== void 0 ? _messages$requireSpec : '密码必须包含至少一个特殊字符');
59
79
  }
60
80
  return {
61
81
  isValid: errors.length === 0,
@@ -36,7 +36,7 @@ import { attachItemRuleLimitsToTopLevelProducts, buildProductKey, buildItemRuleB
36
36
  import { createModule } from "../BookingByStep/types";
37
37
  import { ProductList } from "../../modules/ProductList";
38
38
  import { getDateIsInSchedule } from "../../modules/Schedule/getDateIsInSchedule";
39
- import { composeLinePrice, buildSubmitPayload, createUuidV4, getProductSkuOptions, normalizeSubmitCollectPaxValue, sumOptionUnitPrice } from "../../modules/Order/utils";
39
+ import { composeLinePrice, buildSubmitPayload, createUuidV4, getProductSkuOptions, normalizeSubmitBooking, normalizeSubmitCollectPaxValue, resolveTableOccupancyDuration, sumOptionUnitPrice } from "../../modules/Order/utils";
40
40
  import dayjs from 'dayjs';
41
41
  import { ItemRuleEvaluator } from "../../model/strategy/adapter/itemRule";
42
42
  export * from "./types";
@@ -1332,6 +1332,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
1332
1332
  }
1333
1333
  return prepareRetailAvailability;
1334
1334
  }() // ScanOrder 提交 payload enhancer:
1335
+ // - 新单有桌台上下文但无 booking 时,补建基础预约(通用 Order 已不再自动生成)
1335
1336
  // - 给所有 booking 注入 appointment_status: 'started'(扫码点餐语义)
1336
1337
  // - 给所有 booking 的 metadata 注入 resource_select_type(来自预约规则商品的 resource.type)
1337
1338
  // - 给第一条 booking 补 resources 与 product_uid(仅当存在 resource / rule product)
@@ -1358,7 +1359,8 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
1358
1359
  return function (payload, _ref3) {
1359
1360
  var _resourceState$relati, _tempOrder$metadata, _ref4, _pickOriginal, _resourceState$table_2, _resourceState$relati2, _pickFirstCustomCapac;
1360
1361
  var bookingUuid = _ref3.bookingUuid,
1361
- tempOrder = _ref3.tempOrder;
1362
+ tempOrder = _ref3.tempOrder,
1363
+ now = _ref3.now;
1362
1364
  var resourceId = String((_resourceState$relati = resourceState === null || resourceState === void 0 ? void 0 : resourceState.relationId) !== null && _resourceState$relati !== void 0 ? _resourceState$relati : '').trim();
1363
1365
  var hasReservationBookingContext = Boolean(ruleProduct && resourceState && resourceId && resourceState.relationId && resourceState.tableFormId);
1364
1366
  if (!hasReservationBookingContext) {
@@ -1393,7 +1395,31 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
1393
1395
  } : undefined;
1394
1396
  var ruleProductUid = ruleProduct ? createUuidV4() : undefined;
1395
1397
  var bookingCapacityDimensionId = (_pickFirstCustomCapac = pickFirstCustomCapacityDimensionId(_this5.enabledReservationRuleProducts)) !== null && _pickFirstCustomCapac !== void 0 ? _pickFirstCustomCapac : 0;
1396
- var nextBookings = (payload.bookings || []).map(function (booking, idx) {
1398
+ var bookings = payload.bookings || [];
1399
+ if (!tempOrder.order_id && bookings.length === 0) {
1400
+ var bookingStart = dayjs(now);
1401
+ var bookingDuration = resolveTableOccupancyDuration(tempOrder);
1402
+ var bookingEnd = bookingStart.add(bookingDuration, 'minute');
1403
+ bookings = [normalizeSubmitBooking({
1404
+ relation_id: 0,
1405
+ form_id: 0,
1406
+ start_time: bookingStart.format('HH:mm'),
1407
+ start_date: bookingStart.format('YYYY-MM-DD'),
1408
+ end_time: bookingEnd.format('HH:mm'),
1409
+ end_date: bookingEnd.format('YYYY-MM-DD'),
1410
+ duration: bookingDuration,
1411
+ metadata: {
1412
+ unique_identification_number: bookingUuid
1413
+ },
1414
+ select_date: bookingStart.format('YYYY-MM-DD'),
1415
+ is_all: false,
1416
+ like_status: 'common',
1417
+ schedule_id: 0,
1418
+ relation_type: '',
1419
+ number: 1
1420
+ })];
1421
+ }
1422
+ var nextBookings = bookings.map(function (booking, idx) {
1397
1423
  var metadata = _objectSpread({}, booking.metadata || {});
1398
1424
  if (hasExplicitCollectPax) {
1399
1425
  metadata.collect_pax = normalizeSubmitCollectPaxValue(rawCollectPax);
@@ -2142,7 +2168,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
2142
2168
  key: "applyPrefillByItemRule",
2143
2169
  value: function () {
2144
2170
  var _applyPrefillByItemRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2145
- var strategyConfigs, businessData, prefillItems, productSourceMap, tempOrder, hasChanges, _iterator6, _step6, _prefillItem$product_, _origin2, _origin3, _origin4, prefillItem, productId, productVariantId, targetQuantity, sourceItem, productIndex, _sourceItem$price, sellingPrice, targetProduct, existedQuantity, delta, nextProduct, hasQuantityChanged, hasOriginChanged;
2171
+ var strategyConfigs, businessData, prefillItems, productSourceMap, tempOrder, hasChanges, _iterator6, _step6, _prefillItem$product_, _origin2, _origin3, _origin4, prefillItem, productId, productVariantId, targetQuantity, sourceItem, sourceTitle, productTitle, displayFields, productIndex, _sourceItem$price, sellingPrice, targetProduct, existedQuantity, delta, nextProduct, hasQuantityChanged, hasTitleChanged, hasOriginChanged;
2146
2172
  return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2147
2173
  while (1) switch (_context30.prev = _context30.next) {
2148
2174
  case 0:
@@ -2192,7 +2218,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
2192
2218
  _iterator6.s();
2193
2219
  case 22:
2194
2220
  if ((_step6 = _iterator6.n()).done) {
2195
- _context30.next = 47;
2221
+ _context30.next = 51;
2196
2222
  break;
2197
2223
  }
2198
2224
  prefillItem = _step6.value;
@@ -2203,25 +2229,32 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
2203
2229
  _context30.next = 29;
2204
2230
  break;
2205
2231
  }
2206
- return _context30.abrupt("continue", 45);
2232
+ return _context30.abrupt("continue", 49);
2207
2233
  case 29:
2208
2234
  if (!Number.isNaN(productVariantId)) {
2209
2235
  _context30.next = 31;
2210
2236
  break;
2211
2237
  }
2212
- return _context30.abrupt("continue", 45);
2238
+ return _context30.abrupt("continue", 49);
2213
2239
  case 31:
2214
2240
  sourceItem = productSourceMap.get(buildProductKey(productId, productVariantId)) || productSourceMap.get(buildProductKey(productId, 0)) || null;
2241
+ sourceTitle = (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.product_title) || (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.title) || (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.name);
2242
+ productTitle = typeof sourceTitle === 'string' ? {
2243
+ auto: sourceTitle
2244
+ } : sourceTitle; // 标准标题在归一化后补入,供购物车展示,并由 Order 在折扣重算时保留。
2245
+ displayFields = productTitle ? {
2246
+ product_title: productTitle
2247
+ } : {};
2215
2248
  productIndex = getProductIdentityIndex(tempOrder.products, {
2216
2249
  product_id: productId,
2217
2250
  product_variant_id: productVariantId
2218
2251
  });
2219
2252
  if (!(productIndex === -1)) {
2220
- _context30.next = 38;
2253
+ _context30.next = 41;
2221
2254
  break;
2222
2255
  }
2223
2256
  sellingPrice = toPriceString((_sourceItem$price = sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.price) !== null && _sourceItem$price !== void 0 ? _sourceItem$price : sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.selling_price, '0.00');
2224
- tempOrder.products.push(normalizeOrderProduct(_objectSpread(_objectSpread({}, sourceItem), {}, {
2257
+ tempOrder.products.push(_objectSpread(_objectSpread({}, normalizeOrderProduct(_objectSpread(_objectSpread({}, sourceItem), {}, {
2225
2258
  product_id: productId,
2226
2259
  product_variant_id: productVariantId,
2227
2260
  num: targetQuantity,
@@ -2235,14 +2268,14 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
2235
2268
  item_rule_prefill: true,
2236
2269
  item_rule_id: prefillItem.ruleId
2237
2270
  })
2238
- })));
2271
+ }))), displayFields));
2239
2272
  hasChanges = true;
2240
- return _context30.abrupt("continue", 45);
2241
- case 38:
2273
+ return _context30.abrupt("continue", 49);
2274
+ case 41:
2242
2275
  targetProduct = tempOrder.products[productIndex];
2243
2276
  existedQuantity = toNonNegativeInt(targetProduct.num);
2244
2277
  delta = targetQuantity - existedQuantity;
2245
- nextProduct = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), delta > 0 ? {
2278
+ nextProduct = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, targetProduct), displayFields), delta > 0 ? {
2246
2279
  num: getSafeProductNum(existedQuantity + delta)
2247
2280
  } : {}), {}, {
2248
2281
  metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
@@ -2252,52 +2285,53 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
2252
2285
  _origin: sourceItem ? _objectSpread(_objectSpread({}, targetProduct._origin || {}), sourceItem) : targetProduct._origin
2253
2286
  });
2254
2287
  hasQuantityChanged = delta > 0;
2288
+ hasTitleChanged = Boolean(productTitle && JSON.stringify(targetProduct.product_title) !== JSON.stringify(productTitle));
2255
2289
  hasOriginChanged = Boolean(sourceItem && (!targetProduct._origin || ((_origin2 = targetProduct._origin) === null || _origin2 === void 0 ? void 0 : _origin2.name) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.name) || ((_origin3 = targetProduct._origin) === null || _origin3 === void 0 ? void 0 : _origin3.title) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.title) || ((_origin4 = targetProduct._origin) === null || _origin4 === void 0 ? void 0 : _origin4.price) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.price)));
2256
- if (hasQuantityChanged || hasOriginChanged) {
2290
+ if (hasQuantityChanged || hasTitleChanged || hasOriginChanged) {
2257
2291
  tempOrder.products[productIndex] = nextProduct;
2258
2292
  hasChanges = true;
2259
2293
  }
2260
- case 45:
2294
+ case 49:
2261
2295
  _context30.next = 22;
2262
2296
  break;
2263
- case 47:
2264
- _context30.next = 52;
2297
+ case 51:
2298
+ _context30.next = 56;
2265
2299
  break;
2266
- case 49:
2267
- _context30.prev = 49;
2300
+ case 53:
2301
+ _context30.prev = 53;
2268
2302
  _context30.t0 = _context30["catch"](20);
2269
2303
  _iterator6.e(_context30.t0);
2270
- case 52:
2271
- _context30.prev = 52;
2304
+ case 56:
2305
+ _context30.prev = 56;
2272
2306
  _iterator6.f();
2273
- return _context30.finish(52);
2274
- case 55:
2307
+ return _context30.finish(56);
2308
+ case 59:
2275
2309
  if (!hasChanges) {
2276
- _context30.next = 60;
2310
+ _context30.next = 64;
2277
2311
  break;
2278
2312
  }
2279
2313
  // Prefill 属于 products CRUD 的一种形式:新增后让 Rules 重算,以支持自动应用可用优惠券。
2280
2314
  this.store.order.applyDiscount();
2281
- _context30.next = 59;
2315
+ _context30.next = 63;
2282
2316
  return this.store.order.recalculateSummary({
2283
2317
  createIfMissing: true
2284
2318
  });
2285
- case 59:
2319
+ case 63:
2286
2320
  this.store.order.persistTempOrder();
2287
- case 60:
2288
- _context30.next = 62;
2321
+ case 64:
2322
+ _context30.next = 66;
2289
2323
  return this.refreshItemRuleQuantityLimits();
2290
- case 62:
2324
+ case 66:
2291
2325
  this.itemRulePrefillApplied = true;
2292
2326
  this.logMethodSuccess('applyPrefillByItemRule', {
2293
2327
  prefillCount: prefillItems.length,
2294
2328
  hasChanges: hasChanges
2295
2329
  });
2296
- case 64:
2330
+ case 68:
2297
2331
  case "end":
2298
2332
  return _context30.stop();
2299
2333
  }
2300
- }, _callee30, this, [[20, 49, 52, 55]]);
2334
+ }, _callee30, this, [[20, 53, 56, 59]]);
2301
2335
  }));
2302
2336
  function applyPrefillByItemRule() {
2303
2337
  return _applyPrefillByItemRule.apply(this, arguments);
@@ -1,5 +1,6 @@
1
1
  import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLogInput, ScanOrderLoggerModule, ScanOrderLoggerProviderConfig, ScanOrderLoggerProviderType, ScheduleModule } from '../../modules';
2
2
  import type { QuantityCheckResult, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
3
+ import type { OrderLocalizedText } from '../../modules/Order/types';
3
4
  /**
4
5
  * 扫码下单流程 hook
5
6
  */
@@ -43,6 +44,8 @@ export interface ScanOrderProductSku {
43
44
  }
44
45
  export interface ScanOrderOrderProduct extends ScanOrderOrderProductIdentity {
45
46
  order_detail_id: number | null;
47
+ /** 与 Order 一致的商品展示名称。 */
48
+ product_title?: OrderLocalizedText;
46
49
  num: number;
47
50
  /** Product 或当前 Variant 的生产编码 */
48
51
  production_code?: string;
@@ -0,0 +1,27 @@
1
+ import { type BusinessAvailability } from '../../modules/BusinessAvailability';
2
+ import type { ScheduleModule } from '../../modules/Schedule';
3
+ interface BusinessAvailabilityHost {
4
+ loadOpenData: () => Promise<Record<string, unknown> | null>;
5
+ getSchedule: () => ScheduleModule | undefined;
6
+ getTimezone: () => string;
7
+ getScope: () => string;
8
+ now?: () => Date;
9
+ }
10
+ /** Read successful configuration once per business runtime; evaluate the clock on demand. */
11
+ export declare class BusinessAvailabilityController {
12
+ private readonly host;
13
+ private runtime?;
14
+ constructor(host: BusinessAvailabilityHost);
15
+ invalidate(): void;
16
+ private now;
17
+ private getRuntime;
18
+ private assertCurrent;
19
+ private loadConfig;
20
+ private loadSchedules;
21
+ private error;
22
+ /** Synchronous final cart-commit check; deliberately never starts a load. */
23
+ getCachedAvailability(): BusinessAvailability;
24
+ getAvailability(): Promise<BusinessAvailability>;
25
+ assertAvailable(): void;
26
+ }
27
+ export {};
@@ -0,0 +1,292 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
10
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
11
+ import { cloneDeep } from 'lodash-es';
12
+ import { computeBusinessAvailability, normalizeBusinessAvailabilityConfig } from "../../modules/BusinessAvailability";
13
+ function withTimeout(_x) {
14
+ return _withTimeout.apply(this, arguments);
15
+ }
16
+ /** Read successful configuration once per business runtime; evaluate the clock on demand. */
17
+ function _withTimeout() {
18
+ _withTimeout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(request) {
19
+ var timer;
20
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
21
+ while (1) switch (_context6.prev = _context6.next) {
22
+ case 0:
23
+ _context6.prev = 0;
24
+ _context6.next = 3;
25
+ return Promise.race([request, new Promise(function (_, reject) {
26
+ timer = setTimeout(function () {
27
+ return reject(new Error('Unable to load business settings. Please try again.'));
28
+ }, 30000);
29
+ })]);
30
+ case 3:
31
+ return _context6.abrupt("return", _context6.sent);
32
+ case 4:
33
+ _context6.prev = 4;
34
+ if (timer !== undefined) clearTimeout(timer);
35
+ return _context6.finish(4);
36
+ case 7:
37
+ case "end":
38
+ return _context6.stop();
39
+ }
40
+ }, _callee6, null, [[0,, 4, 7]]);
41
+ }));
42
+ return _withTimeout.apply(this, arguments);
43
+ }
44
+ export var BusinessAvailabilityController = /*#__PURE__*/function () {
45
+ function BusinessAvailabilityController(host) {
46
+ _classCallCheck(this, BusinessAvailabilityController);
47
+ _defineProperty(this, "runtime", void 0);
48
+ this.host = host;
49
+ }
50
+ _createClass(BusinessAvailabilityController, [{
51
+ key: "invalidate",
52
+ value: function invalidate() {
53
+ this.runtime = undefined;
54
+ }
55
+ }, {
56
+ key: "now",
57
+ value: function now() {
58
+ var _this$host$now, _this$host$now2, _this$host;
59
+ return (_this$host$now = (_this$host$now2 = (_this$host = this.host).now) === null || _this$host$now2 === void 0 ? void 0 : _this$host$now2.call(_this$host)) !== null && _this$host$now !== void 0 ? _this$host$now : new Date();
60
+ }
61
+ }, {
62
+ key: "getRuntime",
63
+ value: function getRuntime() {
64
+ var _this$runtime;
65
+ var scope = this.host.getScope();
66
+ if (((_this$runtime = this.runtime) === null || _this$runtime === void 0 ? void 0 : _this$runtime.scope) !== scope) this.runtime = {
67
+ scope: scope
68
+ };
69
+ return this.runtime;
70
+ }
71
+ }, {
72
+ key: "assertCurrent",
73
+ value: function assertCurrent(runtime) {
74
+ if (this.runtime !== runtime || runtime.scope !== this.host.getScope()) {
75
+ throw new Error('Store settings changed. Please try again.');
76
+ }
77
+ }
78
+ }, {
79
+ key: "loadConfig",
80
+ value: function () {
81
+ var _loadConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(runtime) {
82
+ var _this = this;
83
+ var request;
84
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
85
+ while (1) switch (_context2.prev = _context2.next) {
86
+ case 0:
87
+ if (!runtime.config) {
88
+ _context2.next = 2;
89
+ break;
90
+ }
91
+ return _context2.abrupt("return", runtime.config);
92
+ case 2:
93
+ if (!runtime.configRequest) {
94
+ runtime.configRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
95
+ var data, config;
96
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
97
+ while (1) switch (_context.prev = _context.next) {
98
+ case 0:
99
+ _context.next = 2;
100
+ return withTimeout(_this.host.loadOpenData());
101
+ case 2:
102
+ data = _context.sent;
103
+ _this.assertCurrent(runtime);
104
+ if (data) {
105
+ _context.next = 6;
106
+ break;
107
+ }
108
+ throw new Error('Business settings are unavailable. Please try again.');
109
+ case 6:
110
+ config = cloneDeep(normalizeBusinessAvailabilityConfig(data));
111
+ runtime.config = config;
112
+ return _context.abrupt("return", config);
113
+ case 9:
114
+ case "end":
115
+ return _context.stop();
116
+ }
117
+ }, _callee);
118
+ }))();
119
+ }
120
+ request = runtime.configRequest;
121
+ _context2.prev = 4;
122
+ _context2.next = 7;
123
+ return request;
124
+ case 7:
125
+ return _context2.abrupt("return", _context2.sent);
126
+ case 8:
127
+ _context2.prev = 8;
128
+ if (runtime.configRequest === request) runtime.configRequest = undefined;
129
+ return _context2.finish(8);
130
+ case 11:
131
+ case "end":
132
+ return _context2.stop();
133
+ }
134
+ }, _callee2, null, [[4,, 8, 11]]);
135
+ }));
136
+ function loadConfig(_x2) {
137
+ return _loadConfig.apply(this, arguments);
138
+ }
139
+ return loadConfig;
140
+ }()
141
+ }, {
142
+ key: "loadSchedules",
143
+ value: function () {
144
+ var _loadSchedules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(runtime) {
145
+ var _this2 = this;
146
+ var request;
147
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
148
+ while (1) switch (_context4.prev = _context4.next) {
149
+ case 0:
150
+ if (!runtime.schedules) {
151
+ _context4.next = 2;
152
+ break;
153
+ }
154
+ return _context4.abrupt("return", runtime.schedules);
155
+ case 2:
156
+ if (!runtime.scheduleRequest) {
157
+ runtime.scheduleRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
158
+ var schedule, schedules;
159
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
160
+ while (1) switch (_context3.prev = _context3.next) {
161
+ case 0:
162
+ schedule = _this2.host.getSchedule();
163
+ if (schedule) {
164
+ _context3.next = 3;
165
+ break;
166
+ }
167
+ throw new Error('Business operating-hours schedule is unavailable. Please try again.');
168
+ case 3:
169
+ _context3.next = 5;
170
+ return withTimeout(schedule.loadAllSchedule({
171
+ useCache: true
172
+ }));
173
+ case 5:
174
+ _this2.assertCurrent(runtime);
175
+ schedules = cloneDeep(schedule.getScheduleListByIds(runtime.config.scheduleIds) || []);
176
+ runtime.schedules = schedules;
177
+ return _context3.abrupt("return", schedules);
178
+ case 9:
179
+ case "end":
180
+ return _context3.stop();
181
+ }
182
+ }, _callee3);
183
+ }))();
184
+ }
185
+ request = runtime.scheduleRequest;
186
+ _context4.prev = 4;
187
+ _context4.next = 7;
188
+ return request;
189
+ case 7:
190
+ return _context4.abrupt("return", _context4.sent);
191
+ case 8:
192
+ _context4.prev = 8;
193
+ if (runtime.scheduleRequest === request) runtime.scheduleRequest = undefined;
194
+ return _context4.finish(8);
195
+ case 11:
196
+ case "end":
197
+ return _context4.stop();
198
+ }
199
+ }, _callee4, null, [[4,, 8, 11]]);
200
+ }));
201
+ function loadSchedules(_x3) {
202
+ return _loadSchedules.apply(this, arguments);
203
+ }
204
+ return loadSchedules;
205
+ }()
206
+ }, {
207
+ key: "error",
208
+ value: function error(reason, runtime) {
209
+ var _runtime$config$requi, _runtime$config;
210
+ return {
211
+ status: 'error',
212
+ behavior: 'hide_all',
213
+ message: null,
214
+ nextChangeAt: this.now().getTime() + 60000,
215
+ requirePaymentOnSubmit: (_runtime$config$requi = runtime === null || runtime === void 0 || (_runtime$config = runtime.config) === null || _runtime$config === void 0 ? void 0 : _runtime$config.requirePaymentOnSubmit) !== null && _runtime$config$requi !== void 0 ? _runtime$config$requi : true,
216
+ error: reason instanceof Error ? reason.message : 'Business settings are unavailable. Please try again.'
217
+ };
218
+ }
219
+
220
+ /** Synchronous final cart-commit check; deliberately never starts a load. */
221
+ }, {
222
+ key: "getCachedAvailability",
223
+ value: function getCachedAvailability() {
224
+ var runtime = this.getRuntime();
225
+ try {
226
+ this.assertCurrent(runtime);
227
+ if (!runtime.config) throw new Error('Business settings are still loading. Please try again.');
228
+ return computeBusinessAvailability({
229
+ config: runtime.config,
230
+ schedules: runtime.schedules || [],
231
+ timezone: this.host.getTimezone(),
232
+ now: this.now()
233
+ });
234
+ } catch (reason) {
235
+ return this.error(reason, runtime);
236
+ }
237
+ }
238
+ }, {
239
+ key: "getAvailability",
240
+ value: function () {
241
+ var _getAvailability = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
242
+ var runtime, config;
243
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
244
+ while (1) switch (_context5.prev = _context5.next) {
245
+ case 0:
246
+ runtime = this.getRuntime();
247
+ _context5.prev = 1;
248
+ _context5.next = 4;
249
+ return this.loadConfig(runtime);
250
+ case 4:
251
+ config = _context5.sent;
252
+ this.assertCurrent(runtime);
253
+ if (!(!config.paused && !config.invalidScheduleIds && config.scheduleIds.length)) {
254
+ _context5.next = 9;
255
+ break;
256
+ }
257
+ _context5.next = 9;
258
+ return this.loadSchedules(runtime);
259
+ case 9:
260
+ this.assertCurrent(runtime);
261
+ return _context5.abrupt("return", this.getCachedAvailability());
262
+ case 13:
263
+ _context5.prev = 13;
264
+ _context5.t0 = _context5["catch"](1);
265
+ return _context5.abrupt("return", this.error(_context5.t0, runtime));
266
+ case 16:
267
+ case "end":
268
+ return _context5.stop();
269
+ }
270
+ }, _callee5, this, [[1, 13]]);
271
+ }));
272
+ function getAvailability() {
273
+ return _getAvailability.apply(this, arguments);
274
+ }
275
+ return getAvailability;
276
+ }()
277
+ }, {
278
+ key: "assertAvailable",
279
+ value: function assertAvailable() {
280
+ var availability = this.getCachedAvailability();
281
+ if (availability.status !== 'open') {
282
+ var error = new Error(availability.error || (availability.status === 'paused' ? 'Ordering is temporarily paused.' : 'Ordering is currently closed.'));
283
+ Object.assign(error, {
284
+ code: 'BUSINESS_UNAVAILABLE',
285
+ businessAvailability: availability
286
+ });
287
+ throw error;
288
+ }
289
+ }
290
+ }]);
291
+ return BusinessAvailabilityController;
292
+ }();