@pisell/pisellos 0.10.88 → 0.10.91

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 (227) hide show
  1. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  2. package/dist/model/strategy/adapter/itemRule/adapter.js +74 -7
  3. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  4. package/dist/model/strategy/adapter/itemRule/evaluator.js +13 -0
  5. package/dist/model/strategy/adapter/itemRule/type.d.ts +40 -1
  6. package/dist/model/strategy/adapter/itemRule/type.js +10 -0
  7. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  8. package/dist/model/strategy/adapter/promotion/evaluator.js +103 -112
  9. package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  10. package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
  11. package/dist/modules/BookingContext/utils/index.d.ts +1 -0
  12. package/dist/modules/BookingContext/utils/index.js +1 -0
  13. package/dist/modules/BookingContext/utils/productExtend.d.ts +21 -0
  14. package/dist/modules/BookingContext/utils/productExtend.js +132 -33
  15. package/dist/modules/BookingContext/utils/resources.js +1 -1
  16. package/dist/modules/Cart/index.js +4 -3
  17. package/dist/modules/Cart/types.d.ts +2 -0
  18. package/dist/modules/Cart/utils/cartProduct.d.ts +3 -1
  19. package/dist/modules/Cart/utils/cartProduct.js +59 -32
  20. package/dist/modules/Date/index.d.ts +1 -1
  21. package/dist/modules/Date/index.js +60 -14
  22. package/dist/modules/Date/types.d.ts +5 -0
  23. package/dist/modules/OpenData/salesSettings.js +1 -1
  24. package/dist/modules/OpenData/types.d.ts +9 -0
  25. package/dist/modules/OpenData/utils.d.ts +1 -1
  26. package/dist/modules/OpenData/utils.js +3 -2
  27. package/dist/modules/Order/index.d.ts +22 -7
  28. package/dist/modules/Order/index.js +1565 -1161
  29. package/dist/modules/Order/localEftposState.d.ts +13 -0
  30. package/dist/modules/Order/localEftposState.js +39 -0
  31. package/dist/modules/Order/types.d.ts +33 -11
  32. package/dist/modules/Order/types.js +2 -2
  33. package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
  34. package/dist/modules/Order/unpaidAmountGap.js +72 -0
  35. package/dist/modules/Order/utils.d.ts +4 -1
  36. package/dist/modules/Order/utils.js +185 -129
  37. package/dist/modules/Payment/walletpass.js +32 -6
  38. package/dist/modules/Product/types.d.ts +16 -0
  39. package/dist/modules/ProductList/index.js +1 -1
  40. package/dist/modules/ResourcePlanner/planner.d.ts +2 -0
  41. package/dist/modules/ResourcePlanner/planner.js +383 -24
  42. package/dist/modules/ResourcePlanner/types.d.ts +42 -0
  43. package/dist/modules/Rules/index.js +86 -54
  44. package/dist/modules/Schedule/index.d.ts +7 -1
  45. package/dist/modules/Schedule/index.js +155 -39
  46. package/dist/modules/Schedule/types.d.ts +2 -0
  47. package/dist/modules/bookingReadValidation.d.ts +6 -0
  48. package/dist/modules/bookingReadValidation.js +72 -0
  49. package/dist/plugins/request.d.ts +2 -0
  50. package/dist/server/index.d.ts +9 -0
  51. package/dist/server/index.js +1928 -1462
  52. package/dist/server/modules/form/index.d.ts +19 -0
  53. package/dist/server/modules/form/index.js +205 -0
  54. package/dist/server/modules/form/types.d.ts +13 -0
  55. package/dist/server/modules/form/types.js +3 -0
  56. package/dist/server/modules/index.d.ts +3 -0
  57. package/dist/server/modules/index.js +4 -0
  58. package/dist/server/modules/order/index.d.ts +21 -0
  59. package/dist/server/modules/order/index.js +1399 -831
  60. package/dist/server/modules/order/types.d.ts +3 -0
  61. package/dist/server/modules/order/utils/filterOrders.js +20 -0
  62. package/dist/server/modules/products/index.d.ts +28 -7
  63. package/dist/server/modules/products/index.js +1295 -769
  64. package/dist/server/modules/products/replication.d.ts +8 -0
  65. package/dist/server/modules/products/replication.js +69 -0
  66. package/dist/server/modules/products/types.d.ts +12 -1
  67. package/dist/server/modules/products/types.js +4 -0
  68. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  69. package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
  70. package/dist/shared/receipt/small-ticket.d.ts +1 -0
  71. package/dist/shared/receipt/small-ticket.js +58 -26
  72. package/dist/shared/receipt/templateVisibility.d.ts +3 -0
  73. package/dist/shared/receipt/templateVisibility.js +6 -2
  74. package/dist/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  75. package/dist/solution/BaseSales/fulfillmentItemRules.js +750 -0
  76. package/dist/solution/BaseSales/index.d.ts +22 -6
  77. package/dist/solution/BaseSales/index.js +1881 -1347
  78. package/dist/solution/BaseSales/pickupTiming.d.ts +4 -0
  79. package/dist/solution/BaseSales/pickupTiming.js +35 -8
  80. package/dist/solution/BaseSales/types.d.ts +4 -0
  81. package/dist/solution/BaseSales/types.js +1 -0
  82. package/dist/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  83. package/dist/solution/BaseSales/utils/posDurationPricing.js +174 -0
  84. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  85. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -8
  86. package/dist/solution/BookingByStep/index.d.ts +19 -3
  87. package/dist/solution/BookingByStep/index.js +681 -361
  88. package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
  89. package/dist/solution/BookingByStep/utils/resources.js +117 -76
  90. package/dist/solution/BookingTicket/index.d.ts +6 -0
  91. package/dist/solution/BookingTicket/index.js +666 -593
  92. package/dist/solution/BookingTicket/types.d.ts +1 -1
  93. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  94. package/dist/solution/BookingTicket/utils/addProductDecision.js +35 -8
  95. package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +7 -7
  96. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  97. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
  98. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +58 -94
  99. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
  100. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +33 -62
  101. package/dist/solution/OrderInvoicePreview/index.js +4 -3
  102. package/dist/solution/Sales/index.js +1 -1
  103. package/dist/solution/ScanOrder/index.d.ts +2 -0
  104. package/dist/solution/ScanOrder/index.js +230 -97
  105. package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
  106. package/dist/solution/ScanOrder/menuAvailability.js +363 -0
  107. package/dist/solution/ScanOrder/types.d.ts +3 -0
  108. package/dist/solution/UnifiedBookingSales/index.d.ts +42 -10
  109. package/dist/solution/UnifiedBookingSales/index.js +2493 -1496
  110. package/dist/solution/UnifiedBookingSales/salesSettings.js +1 -1
  111. package/dist/solution/UnifiedBookingSales/types.d.ts +20 -5
  112. package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
  113. package/dist/utils/pos-receipt-auto-print.js +14 -0
  114. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  115. package/lib/model/strategy/adapter/itemRule/adapter.js +54 -4
  116. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  117. package/lib/model/strategy/adapter/itemRule/evaluator.js +9 -0
  118. package/lib/model/strategy/adapter/itemRule/type.d.ts +40 -1
  119. package/lib/model/strategy/adapter/itemRule/type.js +10 -0
  120. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  121. package/lib/model/strategy/adapter/promotion/evaluator.js +22 -21
  122. package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  123. package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
  124. package/lib/modules/BookingContext/utils/index.d.ts +1 -0
  125. package/lib/modules/BookingContext/utils/index.js +11 -0
  126. package/lib/modules/BookingContext/utils/productExtend.d.ts +21 -0
  127. package/lib/modules/BookingContext/utils/productExtend.js +104 -5
  128. package/lib/modules/BookingContext/utils/resources.js +1 -1
  129. package/lib/modules/Cart/index.js +4 -2
  130. package/lib/modules/Cart/types.d.ts +2 -0
  131. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -1
  132. package/lib/modules/Cart/utils/cartProduct.js +39 -20
  133. package/lib/modules/Date/index.d.ts +1 -1
  134. package/lib/modules/Date/index.js +28 -5
  135. package/lib/modules/Date/types.d.ts +5 -0
  136. package/lib/modules/OpenData/salesSettings.js +1 -1
  137. package/lib/modules/OpenData/types.d.ts +9 -0
  138. package/lib/modules/OpenData/utils.d.ts +1 -1
  139. package/lib/modules/OpenData/utils.js +3 -2
  140. package/lib/modules/Order/index.d.ts +22 -7
  141. package/lib/modules/Order/index.js +457 -174
  142. package/lib/modules/Order/localEftposState.d.ts +13 -0
  143. package/lib/modules/Order/localEftposState.js +44 -0
  144. package/lib/modules/Order/types.d.ts +33 -11
  145. package/lib/modules/Order/types.js +2 -2
  146. package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
  147. package/lib/modules/Order/unpaidAmountGap.js +60 -0
  148. package/lib/modules/Order/utils.d.ts +4 -1
  149. package/lib/modules/Order/utils.js +51 -3
  150. package/lib/modules/Payment/walletpass.js +23 -1
  151. package/lib/modules/Product/types.d.ts +16 -0
  152. package/lib/modules/ProductList/index.js +1 -1
  153. package/lib/modules/ResourcePlanner/planner.d.ts +2 -0
  154. package/lib/modules/ResourcePlanner/planner.js +299 -9
  155. package/lib/modules/ResourcePlanner/types.d.ts +42 -0
  156. package/lib/modules/Rules/index.js +32 -3
  157. package/lib/modules/Schedule/index.d.ts +7 -1
  158. package/lib/modules/Schedule/index.js +68 -4
  159. package/lib/modules/Schedule/types.d.ts +2 -0
  160. package/lib/modules/bookingReadValidation.d.ts +6 -0
  161. package/lib/modules/bookingReadValidation.js +56 -0
  162. package/lib/plugins/request.d.ts +2 -0
  163. package/lib/server/index.d.ts +9 -0
  164. package/lib/server/index.js +279 -30
  165. package/lib/server/modules/form/index.d.ts +19 -0
  166. package/lib/server/modules/form/index.js +73 -0
  167. package/lib/server/modules/form/types.d.ts +13 -0
  168. package/lib/server/modules/form/types.js +9 -0
  169. package/lib/server/modules/index.d.ts +3 -0
  170. package/lib/server/modules/index.js +15 -1
  171. package/lib/server/modules/order/index.d.ts +21 -0
  172. package/lib/server/modules/order/index.js +344 -35
  173. package/lib/server/modules/order/types.d.ts +3 -0
  174. package/lib/server/modules/order/utils/filterOrders.js +18 -0
  175. package/lib/server/modules/products/index.d.ts +28 -7
  176. package/lib/server/modules/products/index.js +224 -62
  177. package/lib/server/modules/products/replication.d.ts +8 -0
  178. package/lib/server/modules/products/replication.js +30 -0
  179. package/lib/server/modules/products/types.d.ts +12 -1
  180. package/lib/server/modules/products/types.js +3 -0
  181. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  182. package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
  183. package/lib/shared/receipt/small-ticket.d.ts +1 -0
  184. package/lib/shared/receipt/small-ticket.js +53 -25
  185. package/lib/shared/receipt/templateVisibility.d.ts +3 -0
  186. package/lib/shared/receipt/templateVisibility.js +6 -2
  187. package/lib/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  188. package/lib/solution/BaseSales/fulfillmentItemRules.js +259 -0
  189. package/lib/solution/BaseSales/index.d.ts +22 -6
  190. package/lib/solution/BaseSales/index.js +347 -59
  191. package/lib/solution/BaseSales/pickupTiming.d.ts +4 -0
  192. package/lib/solution/BaseSales/pickupTiming.js +24 -3
  193. package/lib/solution/BaseSales/types.d.ts +4 -0
  194. package/lib/solution/BaseSales/types.js +1 -0
  195. package/lib/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  196. package/lib/solution/BaseSales/utils/posDurationPricing.js +133 -0
  197. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  198. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
  199. package/lib/solution/BookingByStep/index.d.ts +19 -3
  200. package/lib/solution/BookingByStep/index.js +229 -17
  201. package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
  202. package/lib/solution/BookingByStep/utils/resources.js +25 -15
  203. package/lib/solution/BookingTicket/index.d.ts +6 -0
  204. package/lib/solution/BookingTicket/index.js +40 -5
  205. package/lib/solution/BookingTicket/types.d.ts +1 -1
  206. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  207. package/lib/solution/BookingTicket/utils/addProductDecision.js +34 -4
  208. package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +7 -7
  209. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  210. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
  211. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +2 -14
  212. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
  213. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +17 -34
  214. package/lib/solution/OrderInvoicePreview/index.js +1 -0
  215. package/lib/solution/Sales/index.js +1 -1
  216. package/lib/solution/ScanOrder/index.d.ts +2 -0
  217. package/lib/solution/ScanOrder/index.js +131 -22
  218. package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
  219. package/lib/solution/ScanOrder/menuAvailability.js +203 -0
  220. package/lib/solution/ScanOrder/types.d.ts +3 -0
  221. package/lib/solution/UnifiedBookingSales/index.d.ts +42 -10
  222. package/lib/solution/UnifiedBookingSales/index.js +717 -144
  223. package/lib/solution/UnifiedBookingSales/salesSettings.js +1 -1
  224. package/lib/solution/UnifiedBookingSales/types.d.ts +20 -5
  225. package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
  226. package/lib/utils/pos-receipt-auto-print.js +13 -0
  227. package/package.json +1 -1
@@ -1,4 +1,8 @@
1
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
5
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
2
6
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
7
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
8
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -171,8 +175,11 @@ function resolveCutOffPolicyIssue(policy) {
171
175
  return null;
172
176
  }
173
177
  function addLeadWindow(base, unit, unitType, _timezoneName) {
174
- // Calendar-day lead times retain the current local hour, minute and second.
175
- if (unitType === 'days') return addLocalCalendarDays(base, unit);
178
+ if (unitType === 'days') {
179
+ var leadDate = addLocalCalendarDays(base, unit);
180
+ // Positive day lead times start at midnight; zero days keeps the current-time boundary.
181
+ return Math.trunc(unit) > 0 ? localDateToScalarStart(formatLocalDate(leadDate)) : leadDate;
182
+ }
176
183
  if (unitType === 'hours') return addLocalHours(base, unit);
177
184
  return addLocalMinutes(base, unit);
178
185
  }
@@ -236,6 +243,16 @@ function isCandidateFromExcludedScheduleDate(params) {
236
243
  return getProductTimeRangeIdentity(range) === candidateIdentity;
237
244
  });
238
245
  }
246
+ function resolveRememberedDurationRange(product, value, timezoneName) {
247
+ if (value === undefined) return null;
248
+ var range = normalizeAbsoluteRange(value, timezoneName);
249
+ if (!range || range.end <= range.start) {
250
+ throw availabilityError('INVALID_TARGET_FILTER', '记忆时间必须包含有效且递增的开始和结束时间');
251
+ }
252
+ if (product.kind !== 'duration') return null;
253
+ if (!product.isFlexibleDuration && (!Number.isFinite(product.durationMinutes) || range.end - range.start !== Number(product.durationMinutes) * 60000)) return null;
254
+ return range;
255
+ }
239
256
  function evaluateCandidateTimeGate(params) {
240
257
  var projection = params.projection,
241
258
  product = params.product,
@@ -264,6 +281,18 @@ function evaluateCandidateTimeGate(params) {
264
281
  };
265
282
  }
266
283
  var policy = product.cutOffPolicy;
284
+ // Current duration items can be shown outside business hours. Their real
285
+ // interval must remain unavailable, including products with no resource groups.
286
+ if (evaluationContext.useDurationTimeGrid && product.kind === 'duration' && !projection.meta.defaults.operatingHours.windows.some(function (window) {
287
+ var range = normalizeAbsoluteRange(window);
288
+ return range && contains(range, candidateRange);
289
+ })) {
290
+ return {
291
+ status: 'unavailable',
292
+ reasonCodes: ['outside_operating_hours'],
293
+ conflictCode: 'booking_cutoff'
294
+ };
295
+ }
267
296
  if (!policy) return null;
268
297
  if (resolveCutOffPolicyIssue(policy)) {
269
298
  return {
@@ -295,13 +324,18 @@ function evaluateCandidateTimeGate(params) {
295
324
  };
296
325
  }
297
326
  if (policy.type === 'before_start') {
327
+ var _evaluationContext$re;
328
+ var rememberedRange = resolveRememberedDurationRange(product, (_evaluationContext$re = evaluationContext.rememberedTimeByProductId) === null || _evaluationContext$re === void 0 ? void 0 : _evaluationContext$re[String(product.id)], timezoneName);
329
+ // Only the exact order-scoped interval may retain its start after this
330
+ // cutoff. The end/past and operating-window gates above still apply.
331
+ if ((rememberedRange === null || rememberedRange === void 0 ? void 0 : rememberedRange.start) === candidateRange.start && rememberedRange.end === candidateRange.end) return null;
298
332
  // POS fixed-duration candidates use the context's stable opening-minute
299
333
  // anchor. Keep that anchored range selectable while it is still active;
300
334
  // otherwise a minute refresh turns it into 0 capacity and incorrectly
301
335
  // advances a create flow to the next slot. The earlier `past` gate still
302
336
  // rejects the anchor once its booking range has ended.
303
- var isActivePosDurationAnchor = evaluationContext.useExactDurationCandidateMinute && product.kind === 'duration' && !product.isFlexibleDuration && evaluationContext.durationCandidateAnchorAtMs === candidateRange.start;
304
- var usesMinutePrecision = product.isFlexibleDuration || evaluationContext.useExactDurationCandidateMinute && product.kind === 'duration';
337
+ var isActivePosDurationAnchor = evaluationContext.useExactDurationCandidateMinute && !evaluationContext.enforceSaleCutoff && product.kind === 'duration' && !product.isFlexibleDuration && evaluationContext.durationCandidateAnchorAtMs === candidateRange.start;
338
+ var usesMinutePrecision = product.isFlexibleDuration || evaluationContext.useDurationTimeGrid || evaluationContext.useExactDurationCandidateMinute && product.kind === 'duration';
305
339
  var hasNotReachedStart = isActivePosDurationAnchor || (usesMinutePrecision ? floorToMinute(now) <= candidateRange.start : now < candidateRange.start);
306
340
  if (hasNotReachedStart) return null;
307
341
  return {
@@ -495,7 +529,7 @@ function normalizeResources(resources) {
495
529
  });
496
530
  }
497
531
  function normalizeOperatingHours(params) {
498
- var _params$input, _params$input2, _params$input3, _params$input4;
532
+ var _params$input, _params$input2, _params$input3, _params$input4, _params$input5, _params$input6;
499
533
  var fallbackWindows = enumerateDates(params.dateRange.startDate, params.dateRange.endDate).map(function (date) {
500
534
  var start = toDateTimeInDate(date, params.businessHours.startTime, params.timezoneName);
501
535
  var end = toDateTimeInDate(date, params.businessHours.endTime, params.timezoneName);
@@ -531,11 +565,43 @@ function normalizeOperatingHours(params) {
531
565
  };
532
566
  var windows = normalizeWindows(sourceWindows);
533
567
  var excludedWindows = normalizeWindows(((_params$input = params.input) === null || _params$input === void 0 ? void 0 : _params$input.excludedWindows) || []);
568
+ // Keep original dates and opening anchors separately: the availability
569
+ // windows below may be clipped at midnight or merged without segment identity.
570
+ var periodMap = new Map();
571
+ var originalPeriods = ((_params$input2 = params.input) === null || _params$input2 === void 0 ? void 0 : _params$input2.businessPeriods) || [].concat(_toConsumableArray(sourceWindows), _toConsumableArray(((_params$input3 = params.input) === null || _params$input3 === void 0 ? void 0 : _params$input3.excludedWindows) || [])).map(function (window) {
572
+ return {
573
+ businessDate: window.businessDate || window.startAt.slice(0, 10),
574
+ startAt: window.openingAnchorAt || window.startAt,
575
+ endAt: window.endAt
576
+ };
577
+ });
578
+ originalPeriods.forEach(function (period) {
579
+ var range = normalizeAbsoluteRange(period);
580
+ if (!range) return;
581
+ var previous = periodMap.get(period.businessDate);
582
+ periodMap.set(period.businessDate, {
583
+ start: previous ? Math.min(previous.start, range.start) : range.start,
584
+ end: previous ? Math.max(previous.end, range.end) : range.end
585
+ });
586
+ });
587
+ var businessPeriods = Array.from(periodMap, function (_ref) {
588
+ var _ref2 = _slicedToArray(_ref, 2),
589
+ businessDate = _ref2[0],
590
+ range = _ref2[1];
591
+ return {
592
+ businessDate: businessDate,
593
+ startAt: formatDateTime(range.start, params.timezoneName, params.fixedOffsetMinutes),
594
+ endAt: formatDateTime(range.end, params.timezoneName, params.fixedOffsetMinutes)
595
+ };
596
+ }).sort(function (left, right) {
597
+ return left.startAt.localeCompare(right.startAt);
598
+ });
534
599
  return _objectSpread({
535
- source: ((_params$input2 = params.input) === null || _params$input2 === void 0 ? void 0 : _params$input2.source) || params.fallbackSource,
536
- scheduleIds: uniqById(((_params$input3 = params.input) === null || _params$input3 === void 0 ? void 0 : _params$input3.scheduleIds) || []),
537
- missingScheduleIds: uniqById(((_params$input4 = params.input) === null || _params$input4 === void 0 ? void 0 : _params$input4.missingScheduleIds) || []),
538
- windows: windows
600
+ source: ((_params$input4 = params.input) === null || _params$input4 === void 0 ? void 0 : _params$input4.source) || params.fallbackSource,
601
+ scheduleIds: uniqById(((_params$input5 = params.input) === null || _params$input5 === void 0 ? void 0 : _params$input5.scheduleIds) || []),
602
+ missingScheduleIds: uniqById(((_params$input6 = params.input) === null || _params$input6 === void 0 ? void 0 : _params$input6.missingScheduleIds) || []),
603
+ windows: windows,
604
+ businessPeriods: businessPeriods
539
605
  }, excludedWindows.length > 0 ? {
540
606
  excludedWindows: excludedWindows
541
607
  } : {});
@@ -554,8 +620,8 @@ function matchesRequirementGroup(requirementGroup, resource, product) {
554
620
  return resource.capacity >= resolveRequiredCapacity(requirementGroup, product, partySize);
555
621
  }
556
622
  function resolveRequiredCapacity(requirementGroup, product, partySize) {
557
- var _ref, _ref2;
558
- return Math.max(1, Number((_ref = (_ref2 = partySize !== null && partySize !== void 0 ? partySize : requirementGroup.capacityRequired) !== null && _ref2 !== void 0 ? _ref2 : product.capacityRequired) !== null && _ref !== void 0 ? _ref : 1) || 1);
623
+ var _ref3, _ref4;
624
+ return Math.max(1, Number((_ref3 = (_ref4 = partySize !== null && partySize !== void 0 ? partySize : requirementGroup.capacityRequired) !== null && _ref4 !== void 0 ? _ref4 : product.capacityRequired) !== null && _ref3 !== void 0 ? _ref3 : 1) || 1);
559
625
  }
560
626
  function buildCellKey(params) {
561
627
  return [String(params.productId), params.groupId, String(params.resourceId), params.start, params.end].join(':');
@@ -614,8 +680,8 @@ function buildCells(projection) {
614
680
  boundaries.add(window.start);
615
681
  boundaries.add(window.end);
616
682
  });
617
- occupancies.forEach(function (_ref3) {
618
- var range = _ref3.range;
683
+ occupancies.forEach(function (_ref5) {
684
+ var range = _ref5.range;
619
685
  boundaries.add(range.start);
620
686
  boundaries.add(range.end);
621
687
  });
@@ -633,11 +699,11 @@ function buildCells(projection) {
633
699
  var isInsideWorkingWindow = windows.some(function (window) {
634
700
  return contains(window, segment);
635
701
  });
636
- var segmentOccupancies = isInsideWorkingWindow ? occupancies.filter(function (_ref4) {
637
- var range = _ref4.range;
702
+ var segmentOccupancies = isInsideWorkingWindow ? occupancies.filter(function (_ref6) {
703
+ var range = _ref6.range;
638
704
  return overlaps(range, segment);
639
- }).map(function (_ref5) {
640
- var occupancy = _ref5.occupancy;
705
+ }).map(function (_ref7) {
706
+ var occupancy = _ref7.occupancy;
641
707
  return occupancy;
642
708
  }) : [];
643
709
  var usedCapacity = segmentOccupancies.reduce(function (sum, occupancy) {
@@ -1114,6 +1180,233 @@ function createDurationTimeRangeWithEnd(product, start, bookingEnd, projection,
1114
1180
  scheduleRefs: []
1115
1181
  };
1116
1182
  }
1183
+
1184
+ /** Resolve the label without changing the real calendar timestamp. */
1185
+ export function getDurationBusinessDate(projection, startAt) {
1186
+ var start = toDateTime(startAt);
1187
+ var periods = projection.meta.defaults.operatingHours.businessPeriods || [];
1188
+ var period = _toConsumableArray(periods).reverse().find(function (item) {
1189
+ var range = normalizeAbsoluteRange(item);
1190
+ return range && range.start <= start && start < range.end;
1191
+ });
1192
+ return (period === null || period === void 0 ? void 0 : period.businessDate) || startAt.slice(0, 10);
1193
+ }
1194
+ function getRequestedProductRange(projection, product, request, runtimeOptions, fixedOffsetMinutes) {
1195
+ var _request$requestedRan;
1196
+ var range = (_request$requestedRan = request.requestedRangesByProductId) === null || _request$requestedRan === void 0 ? void 0 : _request$requestedRan[String(product.id)];
1197
+ if (!runtimeOptions.allowRequestedRanges || !range || product.kind !== 'duration' && product.kind !== 'session') return [];
1198
+ var start = toDateTime(range.startAt);
1199
+ var end = toDateTime(range.endAt);
1200
+ if (!Number.isFinite(start) || !Number.isFinite(end) || !Number.isInteger((end - start) / 60000) || end <= start) {
1201
+ throw availabilityError('INVALID_TARGET_FILTER', '手工预约范围必须包含有效起止时间和正整数分钟时长');
1202
+ }
1203
+ var candidate = createDurationTimeRangeWithEnd(product, start, end, projection, fixedOffsetMinutes);
1204
+ candidate.businessDate = getDurationBusinessDate(projection, candidate.startAt);
1205
+ assertRangesWithinProjection(projection, [candidate]);
1206
+ return [candidate];
1207
+ }
1208
+ function getAlignedDurationRanges(params) {
1209
+ var _request$rememberedSt, _request$rememberedTi, _request$editingStart;
1210
+ var projection = params.projection,
1211
+ product = params.product,
1212
+ request = params.request,
1213
+ runtimeOptions = params.runtimeOptions,
1214
+ dateRange = params.dateRange,
1215
+ operatingRanges = params.operatingRanges,
1216
+ baseRanges = params.baseRanges,
1217
+ resourceWindowIndex = params.resourceWindowIndex,
1218
+ fixedOffsetMinutes = params.fixedOffsetMinutes;
1219
+ var step = projection.meta.defaults.slotStepMinutes;
1220
+ var now = floorToMinute(toDateTime(runtimeOptions.evaluatedAt || projection.meta.durationCandidateAnchorAt));
1221
+ if (!Number.isFinite(now)) throw availabilityError('INVALID_TARGET_FILTER', 'evaluatedAt 必须是有效时间');
1222
+ var nowAt = formatDateTime(now, projection.meta.timezone, fixedOffsetMinutes);
1223
+ var currentBusinessDate = getDurationBusinessDate(projection, nowAt);
1224
+ var inRequestedDays = function inRequestedDays(date) {
1225
+ return date >= dateRange.startDate && date <= dateRange.endDate;
1226
+ };
1227
+ var periods = (projection.meta.defaults.operatingHours.businessPeriods || []).filter(function (period) {
1228
+ return inRequestedDays(period.businessDate);
1229
+ });
1230
+ // A prepared month includes tomorrow's windows too; the single-day UI must
1231
+ // receive the selected business cycle's end, not tomorrow's closing time.
1232
+ var operatingEndAt = dateRange.startDate === dateRange.endDate && periods.length ? periods.reduce(function (latest, period) {
1233
+ return period.endAt > latest ? period.endAt : latest;
1234
+ }, periods[0].endAt) : undefined;
1235
+ var ranges = [];
1236
+ var duration = resolveRequestedDurationMinutes(product, request);
1237
+ var addRange = function addRange(start, end, businessDate) {
1238
+ if (end <= start) return;
1239
+ var candidate = createDurationTimeRangeWithEnd(product, start, end, projection, fixedOffsetMinutes);
1240
+ candidate.businessDate = businessDate || getDurationBusinessDate(projection, candidate.startAt);
1241
+ if (inRequestedDays(candidate.businessDate)) ranges.push(candidate);
1242
+ };
1243
+ // A flexible end comes from resources that actually cover this exact start,
1244
+ // never from the next future window. Keep alternative real ends separate.
1245
+ var flexibleEnds = function flexibleEnds(start) {
1246
+ var _projection$meta$defa;
1247
+ var operating = operatingRanges.find(function (range) {
1248
+ return range.start <= start && start < range.end;
1249
+ });
1250
+ if (!operating) return [];
1251
+ var businessDate = getDurationBusinessDate(projection, formatDateTime(start, projection.meta.timezone, fixedOffsetMinutes));
1252
+ var period = (_projection$meta$defa = projection.meta.defaults.operatingHours.businessPeriods) === null || _projection$meta$defa === void 0 ? void 0 : _projection$meta$defa.find(function (item) {
1253
+ return item.businessDate === businessDate;
1254
+ });
1255
+ var operatingEnd = Math.min(operating.end, period ? toDateTime(period.endAt) : operating.end);
1256
+ var requiredGroups = (product.requirementGroups || []).filter(function (group) {
1257
+ return group.required !== false;
1258
+ });
1259
+ var groups = requiredGroups.map(function (group) {
1260
+ return projection.resources.filter(function (resource) {
1261
+ return matchesRequirementGroup(group, resource, product, request.partySize);
1262
+ }).filter(function (resource) {
1263
+ var _request$resourceIds;
1264
+ return !((_request$resourceIds = request.resourceIds) !== null && _request$resourceIds !== void 0 && _request$resourceIds.length) || request.resourceIds.some(function (id) {
1265
+ return sameId(id, resource.id);
1266
+ });
1267
+ }).flatMap(function (resource) {
1268
+ return (resourceWindowIndex.get(String(resource.id)) || []).filter(function (range) {
1269
+ return range.start <= start && start < range.end;
1270
+ }).map(function (range) {
1271
+ return Math.min(range.end, operatingEnd);
1272
+ });
1273
+ });
1274
+ });
1275
+ if (groups.some(function (ends) {
1276
+ return ends.length === 0;
1277
+ })) return [];
1278
+ if (!groups.length) return [operatingEnd];
1279
+ return Array.from(new Set(groups.flat())).filter(function (end) {
1280
+ return groups.every(function (ends) {
1281
+ return ends.some(function (availableEnd) {
1282
+ return availableEnd >= end;
1283
+ });
1284
+ });
1285
+ }).sort(function (left, right) {
1286
+ return left - right;
1287
+ });
1288
+ };
1289
+ if (product.isFlexibleDuration) {
1290
+ // Preserve the existing continuous-window UI, with the business-day label.
1291
+ periods.forEach(function (period) {
1292
+ var periodRange = normalizeAbsoluteRange(period);
1293
+ baseRanges.forEach(function (range) {
1294
+ var start = Math.max(range.start, periodRange.start, now);
1295
+ var end = Math.min(range.end, periodRange.end);
1296
+ if (start < end) addRange(start, end, period.businessDate);
1297
+ });
1298
+ });
1299
+ } else {
1300
+ periods.forEach(function (period) {
1301
+ var periodRange = normalizeAbsoluteRange(period);
1302
+ var anchor = 60 % step === 0 ? toDateStart(period.businessDate) : periodRange.start;
1303
+ baseRanges.forEach(function (range) {
1304
+ var lower = Math.max(range.start, periodRange.start, now);
1305
+ var upper = Math.min(range.end, periodRange.end);
1306
+ var cursor = anchor + Math.ceil((lower - anchor) / (step * 60000)) * step * 60000;
1307
+ for (; cursor + duration * 60000 <= upper; cursor += step * 60000) {
1308
+ addRange(cursor, cursor + duration * 60000, period.businessDate);
1309
+ }
1310
+ });
1311
+ });
1312
+ }
1313
+ var unavailableCurrentTime;
1314
+ if (inRequestedDays(currentBusinessDate)) {
1315
+ if (product.isFlexibleDuration) {
1316
+ var ends = flexibleEnds(now);
1317
+ ends.forEach(function (end) {
1318
+ return addRange(now, end, currentBusinessDate);
1319
+ });
1320
+ if (!ends.length) {
1321
+ unavailableCurrentTime = {
1322
+ productId: product.id,
1323
+ startAt: nowAt,
1324
+ date: formatDate(now),
1325
+ businessDate: currentBusinessDate,
1326
+ startTime: formatTime(now),
1327
+ status: 'unavailable',
1328
+ reasonCodes: [operatingRanges.some(function (range) {
1329
+ return range.start <= now && now < range.end;
1330
+ }) ? 'outside_resource_window' : 'outside_operating_hours']
1331
+ };
1332
+ }
1333
+ } else {
1334
+ // Even outside a working window the fixed product has a real end. Query
1335
+ // reports unavailable; POS manual capabilities remain a separate policy.
1336
+ addRange(now, now + duration * 60000, currentBusinessDate);
1337
+ }
1338
+ }
1339
+ var rememberedAt = (_request$rememberedSt = request.rememberedStartAtByProductId) === null || _request$rememberedSt === void 0 ? void 0 : _request$rememberedSt[String(product.id)];
1340
+ if (rememberedAt !== undefined) {
1341
+ var start = toDateTime(rememberedAt);
1342
+ if (!Number.isFinite(start)) throw availabilityError('INVALID_TARGET_FILTER', '记忆开始时间必须是完整日期时间');
1343
+ if (product.isFlexibleDuration) {
1344
+ flexibleEnds(start).forEach(function (end) {
1345
+ return addRange(start, end);
1346
+ });
1347
+ } else {
1348
+ addRange(start, start + duration * 60000);
1349
+ }
1350
+ }
1351
+ var rememberedRange = resolveRememberedDurationRange(product, (_request$rememberedTi = request.rememberedTimeByProductId) === null || _request$rememberedTi === void 0 ? void 0 : _request$rememberedTi[String(product.id)], projection.meta.timezone);
1352
+ if (rememberedRange && baseRanges.some(function (range) {
1353
+ return contains(range, rememberedRange);
1354
+ })) {
1355
+ // Never extend a remembered flexible interval when the resource now has a
1356
+ // later closing time, or rebuild a fixed interval after its duration changed.
1357
+ addRange(rememberedRange.start, rememberedRange.end);
1358
+ }
1359
+ var editingAt = (_request$editingStart = request.editingStartAtByProductId) === null || _request$editingStart === void 0 ? void 0 : _request$editingStart[String(product.id)];
1360
+ if (editingAt !== undefined) {
1361
+ var _request$durationMinu3;
1362
+ var _start = toDateTime(editingAt);
1363
+ var editingDuration = Number((_request$durationMinu3 = request.durationMinutesByProductId) === null || _request$durationMinu3 === void 0 ? void 0 : _request$durationMinu3[String(product.id)]);
1364
+ if (!Number.isFinite(_start) || !Number.isInteger(editingDuration) || editingDuration <= 0) {
1365
+ throw availabilityError('INVALID_TARGET_FILTER', '编辑时间必须包含完整开始日期时间和明确的正整数时长');
1366
+ }
1367
+ // Editing restores the original interval, including its actual overnight
1368
+ // date. It neither adopts the current grid nor recomputes a flexible end.
1369
+ if (request.allowOutsideOperatingHoursForRequestedStartTimes || operatingRanges.some(function (range) {
1370
+ return range.start <= _start && _start < range.end;
1371
+ })) {
1372
+ addRange(_start, addMinutesZoned(_start, editingDuration, projection.meta.timezone));
1373
+ }
1374
+ }
1375
+
1376
+ // Explicit custom input keeps its existing start + requested duration
1377
+ // semantics. Remembered input above must never use this default-30 path.
1378
+ if (dateRange.startDate === dateRange.endDate) {
1379
+ resolveRequestedDurationStartTimes(product, request).forEach(function (startTime) {
1380
+ var sameDayStart = toDateTimeInDate(dateRange.startDate, startTime);
1381
+ var period = periods.find(function (item) {
1382
+ return item.businessDate === dateRange.startDate;
1383
+ });
1384
+ var periodRange = period ? normalizeAbsoluteRange(period) : null;
1385
+ var nextDayStart = addLocalCalendarDays(sameDayStart, 1);
1386
+ // HH:mm is entered within a selected business day, whose early hours
1387
+ // may belong to the next calendar day. Do not move other out-of-hours
1388
+ // manual input to tomorrow merely because the business closes overnight.
1389
+ var start = periodRange && !(periodRange.start <= sameDayStart && sameDayStart < periodRange.end) && periodRange.start <= nextDayStart && nextDayStart < periodRange.end ? nextDayStart : sameDayStart;
1390
+ if (request.allowOutsideOperatingHoursForRequestedStartTimes || operatingRanges.some(function (range) {
1391
+ return range.start <= start && start < range.end;
1392
+ })) {
1393
+ addRange(start, start + duration * 60000);
1394
+ }
1395
+ });
1396
+ }
1397
+ return _objectSpread(_objectSpread({
1398
+ productId: product.id,
1399
+ title: product.title,
1400
+ kind: product.kind,
1401
+ slotStepMinutes: step
1402
+ }, operatingEndAt ? {
1403
+ operatingEndAt: operatingEndAt
1404
+ } : {}), {}, {
1405
+ ranges: dedupeProductRanges(ranges)
1406
+ }, unavailableCurrentTime ? {
1407
+ unavailableCurrentTime: unavailableCurrentTime
1408
+ } : {});
1409
+ }
1117
1410
  export function getProductTimeRanges(projection) {
1118
1411
  var _extractFixedOffsetMi3, _request$productIds;
1119
1412
  var request = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -1128,6 +1421,16 @@ export function getProductTimeRanges(projection) {
1128
1421
  return projection.products.filter(function (product) {
1129
1422
  return !filteredProductIdSet || filteredProductIdSet.has(String(product.id));
1130
1423
  }).map(function (product) {
1424
+ var requestedRanges = getRequestedProductRange(projection, product, request, runtimeOptions, fixedOffsetMinutes);
1425
+ if (requestedRanges.length > 0) {
1426
+ return {
1427
+ productId: product.id,
1428
+ title: product.title,
1429
+ kind: product.kind,
1430
+ slotStepMinutes: slotStepMinutes,
1431
+ ranges: dedupeProductRanges(requestedRanges)
1432
+ };
1433
+ }
1131
1434
  if (product.kind === 'normal') {
1132
1435
  return {
1133
1436
  productId: product.id,
@@ -1179,6 +1482,19 @@ export function getProductTimeRanges(projection) {
1179
1482
  return current === null ? ranges : intersectRangeLists(current, ranges);
1180
1483
  }, null) || [] : null;
1181
1484
  var baseRanges = resourceRanges === null ? operatingRanges : intersectRangeLists(resourceRanges, operatingRanges);
1485
+ if (runtimeOptions.useDurationTimeGrid) {
1486
+ return getAlignedDurationRanges({
1487
+ projection: projection,
1488
+ product: product,
1489
+ request: request,
1490
+ runtimeOptions: runtimeOptions,
1491
+ dateRange: dateRange,
1492
+ operatingRanges: operatingRanges,
1493
+ baseRanges: baseRanges,
1494
+ resourceWindowIndex: resourceWindowIndex,
1495
+ fixedOffsetMinutes: fixedOffsetMinutes
1496
+ });
1497
+ }
1182
1498
  var durationMinutes = resolveRequestedDurationMinutes(product, request);
1183
1499
  var flexibleStartAt = function () {
1184
1500
  if (!product.isFlexibleDuration) return undefined;
@@ -1460,7 +1776,10 @@ function buildEvaluationContext(params) {
1460
1776
  selectionsByGroupKey: selectionsByGroupKey,
1461
1777
  useExactDurationCandidateMinute: params.useExactDurationCandidateMinute === true,
1462
1778
  durationCandidateAnchorAtMs: Number.isFinite(durationCandidateAnchorAt) ? floorToMinute(durationCandidateAnchorAt) : null,
1463
- allowExcludedScheduleDateOverride: params.allowExcludedScheduleDateOverride === true
1779
+ allowExcludedScheduleDateOverride: params.allowExcludedScheduleDateOverride === true,
1780
+ useDurationTimeGrid: params.useDurationTimeGrid === true,
1781
+ enforceSaleCutoff: params.enforceSaleCutoff === true,
1782
+ rememberedTimeByProductId: params.rememberedTimeByProductId
1464
1783
  };
1465
1784
  }
1466
1785
  function summarizeStatuses(statuses) {
@@ -1510,7 +1829,7 @@ function summarizeStatusAggregate(aggregate) {
1510
1829
  return 'unavailable';
1511
1830
  }
1512
1831
  function evaluateMatchedResourceSummary(params) {
1513
- var _ref6, _params$matchedCell$m;
1832
+ var _ref8, _params$matchedCell$m;
1514
1833
  var isPast = params.candidateRange.endMs <= params.evaluationContext.evaluatedAtMs;
1515
1834
  if (!params.matchedCell) {
1516
1835
  return {
@@ -1522,7 +1841,7 @@ function evaluateMatchedResourceSummary(params) {
1522
1841
  };
1523
1842
  }
1524
1843
  var remainingCapacity = Math.max(0, params.matchedCell.remainingCapacity || 0);
1525
- var maxCapacity = Math.max(0, (_ref6 = (_params$matchedCell$m = params.matchedCell.maxCapacity) !== null && _params$matchedCell$m !== void 0 ? _params$matchedCell$m : params.resourceCapacity) !== null && _ref6 !== void 0 ? _ref6 : 0);
1844
+ var maxCapacity = Math.max(0, (_ref8 = (_params$matchedCell$m = params.matchedCell.maxCapacity) !== null && _params$matchedCell$m !== void 0 ? _params$matchedCell$m : params.resourceCapacity) !== null && _ref8 !== void 0 ? _ref8 : 0);
1526
1845
  var maxPartySize = isPast ? 0 : remainingCapacity;
1527
1846
  var status = function () {
1528
1847
  if (isPast) return 'past';
@@ -1948,6 +2267,9 @@ export function queryAvailabilityProjection(projection, request) {
1948
2267
  projection: projection,
1949
2268
  evaluatedAt: evaluatedAt,
1950
2269
  resourceIds: request.resourceIds,
2270
+ useDurationTimeGrid: runtimeOptions.useDurationTimeGrid,
2271
+ enforceSaleCutoff: runtimeOptions.enforceSaleCutoff,
2272
+ rememberedTimeByProductId: runtimeOptions.rememberedTimeByProductId,
1951
2273
  useExactDurationCandidateMinute: runtimeOptions.useExactDurationCandidateMinute,
1952
2274
  allowExcludedScheduleDateOverride: runtimeOptions.allowExcludedScheduleDateOverride
1953
2275
  });
@@ -2038,6 +2360,9 @@ export function queryAvailabilityProjection(projection, request) {
2038
2360
  partySize: normalizedPartySize
2039
2361
  }, {
2040
2362
  evaluatedAt: evaluatedAt,
2363
+ useDurationTimeGrid: runtimeOptions.useDurationTimeGrid,
2364
+ enforceSaleCutoff: runtimeOptions.enforceSaleCutoff,
2365
+ rememberedTimeByProductId: runtimeOptions.rememberedTimeByProductId,
2041
2366
  useExactDurationCandidateMinute: runtimeOptions.useExactDurationCandidateMinute,
2042
2367
  allowExcludedScheduleDateOverride: runtimeOptions.allowExcludedScheduleDateOverride
2043
2368
  });
@@ -2066,7 +2391,8 @@ export function queryAvailabilityProjection(projection, request) {
2066
2391
  candidateRangeCache: candidateRangeCache,
2067
2392
  evaluationContext: evaluationContext
2068
2393
  });
2069
- var aggregate = byDate.get(candidate.date) || {
2394
+ var candidateDate = runtimeOptions.useDurationTimeGrid ? candidate.businessDate || candidate.date : candidate.date;
2395
+ var aggregate = byDate.get(candidateDate) || {
2070
2396
  availableCount: 0,
2071
2397
  totalCount: 0,
2072
2398
  maxPartySize: 0,
@@ -2086,8 +2412,26 @@ export function queryAvailabilityProjection(projection, request) {
2086
2412
  evaluated.reasonCodes.forEach(function (reasonCode) {
2087
2413
  return aggregate.reasonCodeSet.add(reasonCode);
2088
2414
  });
2089
- byDate.set(candidate.date, aggregate);
2415
+ byDate.set(candidateDate, aggregate);
2090
2416
  });
2417
+ if (group.unavailableCurrentTime) {
2418
+ var current = group.unavailableCurrentTime;
2419
+ var aggregate = byDate.get(current.businessDate) || {
2420
+ availableCount: 0,
2421
+ totalCount: 0,
2422
+ maxPartySize: 0,
2423
+ remainingCapacity: 0,
2424
+ maxCapacity: 0,
2425
+ reasonCodeSet: new Set(),
2426
+ statusAggregate: createStatusAggregate()
2427
+ };
2428
+ aggregate.totalCount += 1;
2429
+ pushStatusAggregate(aggregate.statusAggregate, 'unavailable');
2430
+ current.reasonCodes.forEach(function (reason) {
2431
+ return aggregate.reasonCodeSet.add(reason);
2432
+ });
2433
+ byDate.set(current.businessDate, aggregate);
2434
+ }
2091
2435
  var dates = enumerateDates(dateRange.startDate, dateRange.endDate).map(function (date) {
2092
2436
  var aggregate = byDate.get(date);
2093
2437
  return {
@@ -2149,10 +2493,22 @@ export function queryAvailabilityProjection(projection, request) {
2149
2493
  evaluated.reasonCodes.forEach(function (reasonCode) {
2150
2494
  return productReasonCodeSet.add(reasonCode);
2151
2495
  });
2152
- var dateAggregate = dateStatusMap.get(candidate.date) || createStatusAggregate();
2496
+ var candidateDate = runtimeOptions.useDurationTimeGrid ? candidate.businessDate || candidate.date : candidate.date;
2497
+ var dateAggregate = dateStatusMap.get(candidateDate) || createStatusAggregate();
2153
2498
  pushStatusAggregate(dateAggregate, evaluated.status);
2154
- dateStatusMap.set(candidate.date, dateAggregate);
2499
+ dateStatusMap.set(candidateDate, dateAggregate);
2155
2500
  });
2501
+ if (group.unavailableCurrentTime) {
2502
+ var current = group.unavailableCurrentTime;
2503
+ totalTimeCount += 1;
2504
+ pushStatusAggregate(productStatusAggregate, 'unavailable');
2505
+ current.reasonCodes.forEach(function (reason) {
2506
+ return productReasonCodeSet.add(reason);
2507
+ });
2508
+ var dateAggregate = dateStatusMap.get(current.businessDate) || createStatusAggregate();
2509
+ pushStatusAggregate(dateAggregate, 'unavailable');
2510
+ dateStatusMap.set(current.businessDate, dateAggregate);
2511
+ }
2156
2512
  var availableDateCount = Array.from(dateStatusMap.values()).filter(function (aggregate) {
2157
2513
  var status = summarizeStatusAggregate(aggregate);
2158
2514
  return status === 'available' || status === 'limited';
@@ -2239,6 +2595,9 @@ export function validateAvailabilitySelection(projection, params) {
2239
2595
  projection: projection,
2240
2596
  evaluatedAt: evaluatedAt,
2241
2597
  requirementSelections: params.requirementSelections,
2598
+ useDurationTimeGrid: runtimeOptions.useDurationTimeGrid,
2599
+ enforceSaleCutoff: runtimeOptions.enforceSaleCutoff,
2600
+ rememberedTimeByProductId: runtimeOptions.rememberedTimeByProductId,
2242
2601
  useExactDurationCandidateMinute: runtimeOptions.useExactDurationCandidateMinute,
2243
2602
  allowExcludedScheduleDateOverride: runtimeOptions.allowExcludedScheduleDateOverride
2244
2603
  })
@@ -92,6 +92,9 @@ export interface AvailabilityProduct {
92
92
  raw?: Record<string, any>;
93
93
  }
94
94
  export interface AvailabilityResourceWindow extends AvailabilityAbsoluteRange {
95
+ /** Original business day and opening anchor, before coverage clipping. */
96
+ businessDate?: string;
97
+ openingAnchorAt?: string;
95
98
  source?: string;
96
99
  raw?: Record<string, any>;
97
100
  }
@@ -101,10 +104,15 @@ export interface AvailabilityOperatingHoursSnapshot {
101
104
  scheduleIds: AvailabilityId[];
102
105
  missingScheduleIds: AvailabilityId[];
103
106
  windows: AvailabilityResourceWindow[];
107
+ /** Complete business cycles; lunch gaps remain in windows, not in this envelope. */
108
+ businessPeriods?: AvailabilityBusinessPeriod[];
104
109
  /** Schedule windows omitted only because their date is excluded. POS may use
105
110
  * these to surface an unavailable, manually selectable candidate. */
106
111
  excludedWindows?: AvailabilityResourceWindow[];
107
112
  }
113
+ export interface AvailabilityBusinessPeriod extends AvailabilityAbsoluteRange {
114
+ businessDate: string;
115
+ }
108
116
  export interface AvailabilityResource {
109
117
  id: AvailabilityId;
110
118
  formId?: AvailabilityId;
@@ -212,6 +220,17 @@ export interface ProductTimeRange extends AvailabilityDisplayRange {
212
220
  bookingEndAt: string;
213
221
  scheduleRefs: AvailabilityScheduleRef[];
214
222
  primaryScheduleRef?: AvailabilityScheduleRef;
223
+ /** Business-day label. date/startAt keep the actual calendar date. */
224
+ businessDate?: string;
225
+ }
226
+ export interface UnavailableCurrentTime {
227
+ productId: AvailabilityId;
228
+ startAt: string;
229
+ date: string;
230
+ businessDate: string;
231
+ startTime: string;
232
+ status: 'unavailable';
233
+ reasonCodes: string[];
215
234
  }
216
235
  export interface ProductTimeRangeGroup {
217
236
  productId: AvailabilityId;
@@ -221,6 +240,8 @@ export interface ProductTimeRangeGroup {
221
240
  /** 单日查询对应营业窗口的最终结束时刻,不受资源排班是否为空影响。 */
222
241
  operatingEndAt?: string;
223
242
  ranges: ProductTimeRange[];
243
+ /** A display-only current item when flexible duration has no valid end. Never submit it. */
244
+ unavailableCurrentTime?: UnavailableCurrentTime;
224
245
  }
225
246
  export interface AvailabilityAssignment extends AvailabilityAbsoluteRange {
226
247
  productId: AvailabilityId;
@@ -242,6 +263,19 @@ export interface GetProductTimeRangesRequest {
242
263
  partySize?: number;
243
264
  durationMinutesByProductId?: Record<string, number>;
244
265
  durationStartTimesByProductId?: Record<string, string[]>;
266
+ /** Explicit POS manual interval. Endpoints are absolute datetimes, not business-day HH:mm. */
267
+ requestedRangesByProductId?: Record<string, {
268
+ startAt: string;
269
+ endAt: string;
270
+ }>;
271
+ /** Restore only the exact remembered start; recompute the end from current product/windows. */
272
+ rememberedStartAtByProductId?: Record<string, string>;
273
+ /** Order-scoped v2 memory preserves the complete actual booking interval. */
274
+ rememberedTimeByProductId?: Record<string, AvailabilityAbsoluteRange>;
275
+ /** Required by the POS facade before accepting v2 remembered intervals. */
276
+ orderSessionId?: string;
277
+ /** Edit only: preserve the full actual start plus an explicit durationMinutesByProductId. */
278
+ editingStartAtByProductId?: Record<string, string>;
245
279
  /**
246
280
  * POS 手工输入时间的兼容开关:只为明确请求的 start time 补候选,
247
281
  * 不改变常规候选列表仍按营业时间生成的规则。
@@ -250,6 +284,12 @@ export interface GetProductTimeRangesRequest {
250
284
  }
251
285
  export interface GetProductTimeRangesRuntimeOptions {
252
286
  evaluatedAt?: string;
287
+ /** Enabled by the POS/Kiosk facade only; other consumers retain their existing grid. */
288
+ useDurationTimeGrid?: boolean;
289
+ /** Automatic remembered selection must not use POS opening-minute cutoff exceptions. */
290
+ enforceSaleCutoff?: boolean;
291
+ /** Internal POS capability, validated against the current order session by the facade. */
292
+ rememberedTimeByProductId?: Record<string, AvailabilityAbsoluteRange>;
253
293
  /**
254
294
  * Internal POS capability: fixed-duration candidates start from the stable
255
295
  * context anchor's current minute instead of rounding up to ten minutes, and
@@ -265,6 +305,8 @@ export interface GetProductTimeRangesRuntimeOptions {
265
305
  * disabled.
266
306
  */
267
307
  allowSessionCustomRanges?: boolean;
308
+ /** Internal POS manual capability; automatic/remembered selections must leave this disabled. */
309
+ allowRequestedRanges?: boolean;
268
310
  /**
269
311
  * Internal POS capability: materialize candidates whose schedule date was
270
312
  * explicitly excluded, while availability evaluation keeps them unavailable.