@pisell/pisellos 0.10.90 → 0.10.93

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 (229) 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 +75 -52
  37. package/dist/modules/Payment/walletpass.js +32 -6
  38. package/dist/modules/Product/index.d.ts +1 -1
  39. package/dist/modules/Product/types.d.ts +16 -0
  40. package/dist/modules/ProductList/index.js +1 -1
  41. package/dist/modules/ResourcePlanner/planner.d.ts +2 -0
  42. package/dist/modules/ResourcePlanner/planner.js +383 -24
  43. package/dist/modules/ResourcePlanner/types.d.ts +42 -0
  44. package/dist/modules/Rules/index.js +86 -54
  45. package/dist/modules/Schedule/index.d.ts +7 -1
  46. package/dist/modules/Schedule/index.js +155 -39
  47. package/dist/modules/Schedule/types.d.ts +2 -0
  48. package/dist/modules/bookingReadValidation.d.ts +6 -0
  49. package/dist/modules/bookingReadValidation.js +72 -0
  50. package/dist/plugins/request.d.ts +2 -0
  51. package/dist/server/index.d.ts +9 -0
  52. package/dist/server/index.js +1928 -1462
  53. package/dist/server/modules/form/index.d.ts +19 -0
  54. package/dist/server/modules/form/index.js +205 -0
  55. package/dist/server/modules/form/types.d.ts +13 -0
  56. package/dist/server/modules/form/types.js +3 -0
  57. package/dist/server/modules/index.d.ts +3 -0
  58. package/dist/server/modules/index.js +4 -0
  59. package/dist/server/modules/order/index.d.ts +21 -0
  60. package/dist/server/modules/order/index.js +1399 -831
  61. package/dist/server/modules/order/types.d.ts +3 -0
  62. package/dist/server/modules/order/utils/filterOrders.js +20 -0
  63. package/dist/server/modules/products/index.d.ts +28 -7
  64. package/dist/server/modules/products/index.js +1295 -769
  65. package/dist/server/modules/products/replication.d.ts +8 -0
  66. package/dist/server/modules/products/replication.js +69 -0
  67. package/dist/server/modules/products/types.d.ts +12 -1
  68. package/dist/server/modules/products/types.js +4 -0
  69. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  70. package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
  71. package/dist/shared/receipt/small-ticket.d.ts +1 -0
  72. package/dist/shared/receipt/small-ticket.js +58 -26
  73. package/dist/shared/receipt/templateVisibility.d.ts +3 -0
  74. package/dist/shared/receipt/templateVisibility.js +6 -2
  75. package/dist/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  76. package/dist/solution/BaseSales/fulfillmentItemRules.js +750 -0
  77. package/dist/solution/BaseSales/index.d.ts +22 -6
  78. package/dist/solution/BaseSales/index.js +1881 -1347
  79. package/dist/solution/BaseSales/pickupTiming.d.ts +4 -0
  80. package/dist/solution/BaseSales/pickupTiming.js +35 -8
  81. package/dist/solution/BaseSales/types.d.ts +4 -0
  82. package/dist/solution/BaseSales/types.js +1 -0
  83. package/dist/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  84. package/dist/solution/BaseSales/utils/posDurationPricing.js +174 -0
  85. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  86. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -8
  87. package/dist/solution/BookingByStep/index.d.ts +20 -4
  88. package/dist/solution/BookingByStep/index.js +681 -361
  89. package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
  90. package/dist/solution/BookingByStep/utils/resources.js +117 -76
  91. package/dist/solution/BookingTicket/index.d.ts +10 -0
  92. package/dist/solution/BookingTicket/index.js +686 -598
  93. package/dist/solution/BookingTicket/types.d.ts +1 -1
  94. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  95. package/dist/solution/BookingTicket/utils/addProductDecision.js +35 -8
  96. package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +8 -8
  97. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  98. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
  99. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +58 -94
  100. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
  101. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +33 -62
  102. package/dist/solution/OrderInvoicePreview/index.js +4 -3
  103. package/dist/solution/Sales/index.js +1 -1
  104. package/dist/solution/ScanOrder/index.d.ts +2 -0
  105. package/dist/solution/ScanOrder/index.js +230 -97
  106. package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
  107. package/dist/solution/ScanOrder/menuAvailability.js +363 -0
  108. package/dist/solution/ScanOrder/types.d.ts +3 -0
  109. package/dist/solution/UnifiedBookingSales/index.d.ts +42 -10
  110. package/dist/solution/UnifiedBookingSales/index.js +2493 -1496
  111. package/dist/solution/UnifiedBookingSales/salesSettings.js +1 -1
  112. package/dist/solution/UnifiedBookingSales/types.d.ts +20 -5
  113. package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
  114. package/dist/utils/pos-receipt-auto-print.js +14 -0
  115. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  116. package/lib/model/strategy/adapter/itemRule/adapter.js +54 -4
  117. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  118. package/lib/model/strategy/adapter/itemRule/evaluator.js +9 -0
  119. package/lib/model/strategy/adapter/itemRule/type.d.ts +40 -1
  120. package/lib/model/strategy/adapter/itemRule/type.js +10 -0
  121. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  122. package/lib/model/strategy/adapter/promotion/evaluator.js +22 -21
  123. package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  124. package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
  125. package/lib/modules/BookingContext/utils/index.d.ts +1 -0
  126. package/lib/modules/BookingContext/utils/index.js +11 -0
  127. package/lib/modules/BookingContext/utils/productExtend.d.ts +21 -0
  128. package/lib/modules/BookingContext/utils/productExtend.js +104 -5
  129. package/lib/modules/BookingContext/utils/resources.js +1 -1
  130. package/lib/modules/Cart/index.js +4 -2
  131. package/lib/modules/Cart/types.d.ts +2 -0
  132. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -1
  133. package/lib/modules/Cart/utils/cartProduct.js +39 -20
  134. package/lib/modules/Date/index.d.ts +1 -1
  135. package/lib/modules/Date/index.js +28 -5
  136. package/lib/modules/Date/types.d.ts +5 -0
  137. package/lib/modules/OpenData/salesSettings.js +1 -1
  138. package/lib/modules/OpenData/types.d.ts +9 -0
  139. package/lib/modules/OpenData/utils.d.ts +1 -1
  140. package/lib/modules/OpenData/utils.js +3 -2
  141. package/lib/modules/Order/index.d.ts +22 -7
  142. package/lib/modules/Order/index.js +457 -174
  143. package/lib/modules/Order/localEftposState.d.ts +13 -0
  144. package/lib/modules/Order/localEftposState.js +44 -0
  145. package/lib/modules/Order/types.d.ts +33 -11
  146. package/lib/modules/Order/types.js +2 -2
  147. package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
  148. package/lib/modules/Order/unpaidAmountGap.js +60 -0
  149. package/lib/modules/Order/utils.d.ts +4 -1
  150. package/lib/modules/Order/utils.js +29 -3
  151. package/lib/modules/Payment/walletpass.js +23 -1
  152. package/lib/modules/Product/index.d.ts +1 -1
  153. package/lib/modules/Product/types.d.ts +16 -0
  154. package/lib/modules/ProductList/index.js +1 -1
  155. package/lib/modules/ResourcePlanner/planner.d.ts +2 -0
  156. package/lib/modules/ResourcePlanner/planner.js +299 -9
  157. package/lib/modules/ResourcePlanner/types.d.ts +42 -0
  158. package/lib/modules/Rules/index.js +32 -3
  159. package/lib/modules/Schedule/index.d.ts +7 -1
  160. package/lib/modules/Schedule/index.js +68 -4
  161. package/lib/modules/Schedule/types.d.ts +2 -0
  162. package/lib/modules/bookingReadValidation.d.ts +6 -0
  163. package/lib/modules/bookingReadValidation.js +56 -0
  164. package/lib/plugins/request.d.ts +2 -0
  165. package/lib/server/index.d.ts +9 -0
  166. package/lib/server/index.js +279 -30
  167. package/lib/server/modules/form/index.d.ts +19 -0
  168. package/lib/server/modules/form/index.js +73 -0
  169. package/lib/server/modules/form/types.d.ts +13 -0
  170. package/lib/server/modules/form/types.js +9 -0
  171. package/lib/server/modules/index.d.ts +3 -0
  172. package/lib/server/modules/index.js +15 -1
  173. package/lib/server/modules/order/index.d.ts +21 -0
  174. package/lib/server/modules/order/index.js +344 -35
  175. package/lib/server/modules/order/types.d.ts +3 -0
  176. package/lib/server/modules/order/utils/filterOrders.js +18 -0
  177. package/lib/server/modules/products/index.d.ts +28 -7
  178. package/lib/server/modules/products/index.js +224 -62
  179. package/lib/server/modules/products/replication.d.ts +8 -0
  180. package/lib/server/modules/products/replication.js +30 -0
  181. package/lib/server/modules/products/types.d.ts +12 -1
  182. package/lib/server/modules/products/types.js +3 -0
  183. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  184. package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
  185. package/lib/shared/receipt/small-ticket.d.ts +1 -0
  186. package/lib/shared/receipt/small-ticket.js +53 -25
  187. package/lib/shared/receipt/templateVisibility.d.ts +3 -0
  188. package/lib/shared/receipt/templateVisibility.js +6 -2
  189. package/lib/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  190. package/lib/solution/BaseSales/fulfillmentItemRules.js +259 -0
  191. package/lib/solution/BaseSales/index.d.ts +22 -6
  192. package/lib/solution/BaseSales/index.js +347 -59
  193. package/lib/solution/BaseSales/pickupTiming.d.ts +4 -0
  194. package/lib/solution/BaseSales/pickupTiming.js +24 -3
  195. package/lib/solution/BaseSales/types.d.ts +4 -0
  196. package/lib/solution/BaseSales/types.js +1 -0
  197. package/lib/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  198. package/lib/solution/BaseSales/utils/posDurationPricing.js +133 -0
  199. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  200. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
  201. package/lib/solution/BookingByStep/index.d.ts +20 -4
  202. package/lib/solution/BookingByStep/index.js +229 -17
  203. package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
  204. package/lib/solution/BookingByStep/utils/resources.js +25 -15
  205. package/lib/solution/BookingTicket/index.d.ts +10 -0
  206. package/lib/solution/BookingTicket/index.js +57 -6
  207. package/lib/solution/BookingTicket/types.d.ts +1 -1
  208. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  209. package/lib/solution/BookingTicket/utils/addProductDecision.js +34 -4
  210. package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +8 -8
  211. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  212. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
  213. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +2 -14
  214. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
  215. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +17 -34
  216. package/lib/solution/OrderInvoicePreview/index.js +1 -0
  217. package/lib/solution/Sales/index.js +1 -1
  218. package/lib/solution/ScanOrder/index.d.ts +2 -0
  219. package/lib/solution/ScanOrder/index.js +131 -22
  220. package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
  221. package/lib/solution/ScanOrder/menuAvailability.js +203 -0
  222. package/lib/solution/ScanOrder/types.d.ts +3 -0
  223. package/lib/solution/UnifiedBookingSales/index.d.ts +42 -10
  224. package/lib/solution/UnifiedBookingSales/index.js +717 -144
  225. package/lib/solution/UnifiedBookingSales/salesSettings.js +1 -1
  226. package/lib/solution/UnifiedBookingSales/types.d.ts +20 -5
  227. package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
  228. package/lib/utils/pos-receipt-auto-print.js +13 -0
  229. package/package.json +1 -1
@@ -42,6 +42,9 @@ export interface ProductSettlementOption extends Record<string, any> {
42
42
  available: boolean;
43
43
  disabled_reason?: string;
44
44
  }
45
+ export interface ProductPricingMethod {
46
+ type: 'fixed_price' | 'duration_based';
47
+ }
45
48
  /**
46
49
  * 商品基本信息接口
47
50
  */
@@ -74,6 +77,8 @@ export interface ProductData {
74
77
  sum_stock: number;
75
78
  /** 商品价格 */
76
79
  price: string;
80
+ /** POS booking pricing; missing configuration retains existing fixed pricing. */
81
+ pricing_method?: ProductPricingMethod;
77
82
  /** 当前上下文解析出的可选结算货币 */
78
83
  available_settlement_options?: ProductSettlementOption[];
79
84
  /** 商品原价 */
@@ -218,6 +223,17 @@ export interface ProductData {
218
223
  bundle?: any[];
219
224
  /** 商品选项组成 */
220
225
  options?: any[];
226
+ /** 单规格组;用于由已选 option 反查规格项名称、价格等商品快照字段。 */
227
+ option_group?: Array<{
228
+ id: number | string;
229
+ option_item?: Array<{
230
+ id: number | string;
231
+ name?: string | Record<string, any>;
232
+ title?: string | Record<string, any>;
233
+ [key: string]: any;
234
+ }>;
235
+ [key: string]: any;
236
+ }>;
221
237
  /** 商品原信息 */
222
238
  origin?: any;
223
239
  /** 容量 */
@@ -242,7 +242,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
242
242
  online_store: 'online-store',
243
243
  scan_to_order: 'online-store',
244
244
  'scan-to-order': 'online-store',
245
- scan_to_order_2: 'mobile_order',
245
+ scan_to_order_2: 'online-store',
246
246
  scan_to_order_3: 'scantoorder3'
247
247
  };
248
248
  rawApplicationCode = (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel;
@@ -1,5 +1,7 @@
1
1
  import type { AvailabilityProjection, AvailabilityProjectionInput, AvailabilityQuery, AvailabilityQueryResult, AvailabilitySelectionValidationParams, AvailabilitySelectionValidationResult, GetProductTimeRangesRequest, GetProductTimeRangesRuntimeOptions, ProductTimeRangeGroup } from './types';
2
2
  export declare function createAvailabilityProjection(input: AvailabilityProjectionInput): AvailabilityProjection;
3
+ /** Resolve the label without changing the real calendar timestamp. */
4
+ export declare function getDurationBusinessDate(projection: AvailabilityProjection, startAt: string): string;
3
5
  export declare function getProductTimeRanges(projection: AvailabilityProjection, request?: GetProductTimeRangesRequest, runtimeOptions?: GetProductTimeRangesRuntimeOptions): ProductTimeRangeGroup[];
4
6
  export declare function queryAvailabilityProjection(projection: AvailabilityProjection, request: AvailabilityQuery, runtimeOptions?: GetProductTimeRangesRuntimeOptions): AvailabilityQueryResult;
5
7
  export declare function validateAvailabilitySelection(projection: AvailabilityProjection, params: AvailabilitySelectionValidationParams, runtimeOptions?: GetProductTimeRangesRuntimeOptions): AvailabilitySelectionValidationResult;
@@ -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
  })