@pisell/pisellos 2.2.323 → 2.2.324

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 (195) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/inventory/index.d.ts +92 -0
  4. package/dist/inventory/index.js +509 -0
  5. package/dist/modules/BookingContext/index.d.ts +2 -2
  6. package/dist/modules/BookingContext/index.js +55 -25
  7. package/dist/modules/BookingContext/types.d.ts +2 -0
  8. package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  9. package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
  10. package/dist/modules/BookingContext/utils/index.d.ts +1 -0
  11. package/dist/modules/BookingContext/utils/index.js +1 -0
  12. package/dist/modules/BookingContext/utils/productExtend.d.ts +20 -1
  13. package/dist/modules/BookingContext/utils/productExtend.js +122 -29
  14. package/dist/modules/Date/index.d.ts +1 -1
  15. package/dist/modules/Date/index.js +60 -14
  16. package/dist/modules/Date/types.d.ts +5 -0
  17. package/dist/modules/Discount/index.js +1 -0
  18. package/dist/modules/OpenData/index.d.ts +1 -0
  19. package/dist/modules/OpenData/index.js +1 -0
  20. package/dist/modules/OpenData/salesSettings.d.ts +32 -0
  21. package/dist/modules/OpenData/salesSettings.js +80 -0
  22. package/dist/modules/OpenData/types.d.ts +16 -0
  23. package/dist/modules/OpenData/utils.d.ts +1 -1
  24. package/dist/modules/OpenData/utils.js +3 -2
  25. package/dist/modules/Order/index.d.ts +54 -11
  26. package/dist/modules/Order/index.js +2699 -1411
  27. package/dist/modules/Order/types.d.ts +43 -5
  28. package/dist/modules/Order/types.js +4 -0
  29. package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
  30. package/dist/modules/Order/unpaidAmountGap.js +72 -0
  31. package/dist/modules/Order/utils/discountProductLineIdentity.js +2 -2
  32. package/dist/modules/Order/utils/productVoucherGroups.d.ts +15 -0
  33. package/dist/modules/Order/utils/productVoucherGroups.js +115 -0
  34. package/dist/modules/Order/utils.d.ts +3 -1
  35. package/dist/modules/Order/utils.js +6 -2
  36. package/dist/modules/ProductList/clientDataVariants.js +6 -2
  37. package/dist/modules/ProductList/index.d.ts +2 -0
  38. package/dist/modules/ProductList/index.js +161 -51
  39. package/dist/modules/ResourcePlanner/planner.js +58 -2
  40. package/dist/modules/ResourcePlanner/types.d.ts +13 -0
  41. package/dist/modules/Rules/index.d.ts +2 -0
  42. package/dist/modules/Rules/index.js +58 -39
  43. package/dist/modules/Schedule/index.d.ts +7 -1
  44. package/dist/modules/Schedule/index.js +155 -39
  45. package/dist/modules/Schedule/types.d.ts +2 -0
  46. package/dist/modules/bookingReadValidation.d.ts +6 -0
  47. package/dist/modules/bookingReadValidation.js +72 -0
  48. package/dist/plugins/request.d.ts +2 -0
  49. package/dist/server/index.d.ts +5 -0
  50. package/dist/server/index.js +1312 -1154
  51. package/dist/server/modules/order/index.js +2 -1
  52. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  53. package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
  54. package/dist/shared/receipt/small-ticket.d.ts +4 -0
  55. package/dist/shared/receipt/small-ticket.js +70 -12
  56. package/dist/solution/BaseSales/index.d.ts +39 -5
  57. package/dist/solution/BaseSales/index.js +1828 -1462
  58. package/dist/solution/BaseSales/types.d.ts +1 -0
  59. package/dist/solution/BaseSales/types.js +1 -0
  60. package/dist/solution/BookingByStep/index.d.ts +17 -3
  61. package/dist/solution/BookingByStep/index.js +676 -361
  62. package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
  63. package/dist/solution/BookingByStep/utils/resources.js +117 -76
  64. package/dist/solution/BookingTicket/index.d.ts +15 -3
  65. package/dist/solution/BookingTicket/index.js +249 -135
  66. package/dist/solution/BookingTicket/types.d.ts +14 -2
  67. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +3 -1
  68. package/dist/solution/BookingTicket/utils/addProductDecision.js +39 -11
  69. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  70. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
  71. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
  72. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +88 -0
  73. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
  74. package/dist/solution/BookingTicket/utils/scan/handleScan.js +2 -1
  75. package/dist/solution/OrderInvoicePreview/index.js +14 -8
  76. package/dist/solution/ScanOrder/index.d.ts +2 -0
  77. package/dist/solution/ScanOrder/index.js +166 -67
  78. package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
  79. package/dist/solution/ScanOrder/menuAvailability.js +363 -0
  80. package/dist/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
  81. package/dist/solution/UnifiedBookingSales/catalogQueryBatch.js +202 -0
  82. package/dist/solution/UnifiedBookingSales/index.d.ts +96 -4
  83. package/dist/solution/UnifiedBookingSales/index.js +3374 -1177
  84. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
  85. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.js +4 -0
  86. package/dist/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
  87. package/dist/solution/UnifiedBookingSales/salesSettings.js +81 -0
  88. package/dist/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
  89. package/dist/solution/UnifiedBookingSales/sessionResourceCache.js +271 -0
  90. package/dist/solution/UnifiedBookingSales/types.d.ts +71 -2
  91. package/dist/solution/UnifiedBookingSales/types.js +7 -1
  92. package/dist/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
  93. package/dist/solution/UnifiedBookingSales/venueCatalogSession.js +283 -0
  94. package/dist/utils/platform.d.ts +2 -0
  95. package/dist/utils/platform.js +6 -0
  96. package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
  97. package/dist/utils/pos-receipt-auto-print.js +14 -0
  98. package/lib/index.d.ts +1 -0
  99. package/lib/index.js +12 -0
  100. package/lib/inventory/index.d.ts +92 -0
  101. package/lib/inventory/index.js +287 -0
  102. package/lib/modules/BookingContext/index.d.ts +2 -2
  103. package/lib/modules/BookingContext/index.js +42 -10
  104. package/lib/modules/BookingContext/types.d.ts +2 -0
  105. package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  106. package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
  107. package/lib/modules/BookingContext/utils/index.d.ts +1 -0
  108. package/lib/modules/BookingContext/utils/index.js +11 -0
  109. package/lib/modules/BookingContext/utils/productExtend.d.ts +20 -1
  110. package/lib/modules/BookingContext/utils/productExtend.js +96 -7
  111. package/lib/modules/Date/index.d.ts +1 -1
  112. package/lib/modules/Date/index.js +28 -5
  113. package/lib/modules/Date/types.d.ts +5 -0
  114. package/lib/modules/Discount/index.js +1 -0
  115. package/lib/modules/OpenData/index.d.ts +1 -0
  116. package/lib/modules/OpenData/index.js +12 -0
  117. package/lib/modules/OpenData/salesSettings.d.ts +32 -0
  118. package/lib/modules/OpenData/salesSettings.js +70 -0
  119. package/lib/modules/OpenData/types.d.ts +16 -0
  120. package/lib/modules/OpenData/utils.d.ts +1 -1
  121. package/lib/modules/OpenData/utils.js +3 -2
  122. package/lib/modules/Order/index.d.ts +54 -11
  123. package/lib/modules/Order/index.js +659 -80
  124. package/lib/modules/Order/types.d.ts +43 -5
  125. package/lib/modules/Order/types.js +2 -0
  126. package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
  127. package/lib/modules/Order/unpaidAmountGap.js +60 -0
  128. package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
  129. package/lib/modules/Order/utils/productVoucherGroups.d.ts +15 -0
  130. package/lib/modules/Order/utils/productVoucherGroups.js +64 -0
  131. package/lib/modules/Order/utils.d.ts +3 -1
  132. package/lib/modules/Order/utils.js +6 -2
  133. package/lib/modules/ProductList/clientDataVariants.js +6 -2
  134. package/lib/modules/ProductList/index.d.ts +2 -0
  135. package/lib/modules/ProductList/index.js +74 -0
  136. package/lib/modules/ResourcePlanner/planner.js +52 -1
  137. package/lib/modules/ResourcePlanner/types.d.ts +13 -0
  138. package/lib/modules/Rules/index.d.ts +2 -0
  139. package/lib/modules/Rules/index.js +25 -9
  140. package/lib/modules/Schedule/index.d.ts +7 -1
  141. package/lib/modules/Schedule/index.js +68 -4
  142. package/lib/modules/Schedule/types.d.ts +2 -0
  143. package/lib/modules/bookingReadValidation.d.ts +6 -0
  144. package/lib/modules/bookingReadValidation.js +56 -0
  145. package/lib/plugins/request.d.ts +2 -0
  146. package/lib/server/index.d.ts +5 -0
  147. package/lib/server/index.js +124 -16
  148. package/lib/server/modules/order/index.js +2 -1
  149. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  150. package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
  151. package/lib/shared/receipt/small-ticket.d.ts +4 -0
  152. package/lib/shared/receipt/small-ticket.js +63 -8
  153. package/lib/solution/BaseSales/index.d.ts +39 -5
  154. package/lib/solution/BaseSales/index.js +212 -18
  155. package/lib/solution/BaseSales/types.d.ts +1 -0
  156. package/lib/solution/BaseSales/types.js +1 -0
  157. package/lib/solution/BookingByStep/index.d.ts +17 -3
  158. package/lib/solution/BookingByStep/index.js +222 -14
  159. package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
  160. package/lib/solution/BookingByStep/utils/resources.js +25 -15
  161. package/lib/solution/BookingTicket/index.d.ts +15 -3
  162. package/lib/solution/BookingTicket/index.js +47 -4
  163. package/lib/solution/BookingTicket/types.d.ts +14 -2
  164. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +3 -1
  165. package/lib/solution/BookingTicket/utils/addProductDecision.js +37 -6
  166. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  167. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
  168. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
  169. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +54 -0
  170. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
  171. package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -1
  172. package/lib/solution/OrderInvoicePreview/index.js +7 -1
  173. package/lib/solution/ScanOrder/index.d.ts +2 -0
  174. package/lib/solution/ScanOrder/index.js +72 -2
  175. package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
  176. package/lib/solution/ScanOrder/menuAvailability.js +203 -0
  177. package/lib/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
  178. package/lib/solution/UnifiedBookingSales/catalogQueryBatch.js +109 -0
  179. package/lib/solution/UnifiedBookingSales/index.d.ts +96 -4
  180. package/lib/solution/UnifiedBookingSales/index.js +1316 -73
  181. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
  182. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +2 -0
  183. package/lib/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
  184. package/lib/solution/UnifiedBookingSales/salesSettings.js +72 -0
  185. package/lib/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
  186. package/lib/solution/UnifiedBookingSales/sessionResourceCache.js +199 -0
  187. package/lib/solution/UnifiedBookingSales/types.d.ts +71 -2
  188. package/lib/solution/UnifiedBookingSales/types.js +4 -1
  189. package/lib/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
  190. package/lib/solution/UnifiedBookingSales/venueCatalogSession.js +155 -0
  191. package/lib/utils/platform.d.ts +2 -0
  192. package/lib/utils/platform.js +7 -0
  193. package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
  194. package/lib/utils/pos-receipt-auto-print.js +13 -0
  195. package/package.json +1 -1
@@ -11,6 +11,8 @@ export declare class AvailabilityRemoteOccupancyCache {
11
11
  scopeKey: string;
12
12
  resourceIds: AvailabilityId[];
13
13
  dateRange: AvailabilityDateRange;
14
+ /** Only opt-in preview reads expire cells; legacy reads retain their SWR semantics. */
15
+ maxAgeMs?: number;
14
16
  }): Record<string, any>[] | null;
15
17
  hasCompleteCoverage(params: {
16
18
  scopeKey: string;
@@ -146,6 +146,7 @@ export var AvailabilityRemoteOccupancyCache = /*#__PURE__*/function () {
146
146
  var requestedResourceIds = uniqueIds(params.resourceIds);
147
147
  var requestedDates = buildDateList(params.dateRange);
148
148
  if (requestedResourceIds.length === 0 || requestedDates.length === 0) return [];
149
+ var now = Date.now();
149
150
  var resources = [];
150
151
  var _iterator = _createForOfIteratorHelper(requestedResourceIds),
151
152
  _step;
@@ -164,6 +165,9 @@ export var AvailabilityRemoteOccupancyCache = /*#__PURE__*/function () {
164
165
  if (!cell) return {
165
166
  v: null
166
167
  };
168
+ if (params.maxAgeMs !== undefined && (now < cell.fetchedAt || now - cell.fetchedAt >= params.maxAgeMs)) return {
169
+ v: null
170
+ };
167
171
  cell.eventList.forEach(function (rawEvent) {
168
172
  eventList.set(buildEventIdentity(resourceId, rawEvent), cloneDeep(rawEvent));
169
173
  });
@@ -0,0 +1,16 @@
1
+ import type { MultipleBookingScheduling } from '../../modules/OpenData';
2
+ export interface ResolveDefaultBookingStartParams {
3
+ /** Product bookings in cart insertion order; unrelated order-level bookings are excluded by the facade. */
4
+ bookings: readonly Record<string, any>[];
5
+ holderIds?: unknown;
6
+ mode?: MultipleBookingScheduling;
7
+ fallback?: string;
8
+ }
9
+ /** Normalize scalar/array holder identities without merging the no-holder group with real holders. */
10
+ export declare function normalizeBookingHolderIds(value: unknown): string[];
11
+ export declare function getBookingHolderIds(booking: Record<string, any>): string[];
12
+ /** Validate input and convert absolute ISO values to the runtime-local date/time used by booking fields. */
13
+ export declare function normalizeBookingDateTime(value: unknown): string | undefined;
14
+ export declare function getBookingBoundary(booking: Record<string, any>, edge: 'start' | 'end'): string | undefined;
15
+ /** Select a default only; availability and resource occupancy remain the commit path's authority. */
16
+ export declare function resolveDefaultBookingStart({ bookings, holderIds, mode, fallback, }: ResolveDefaultBookingStartParams): string | undefined;
@@ -0,0 +1,81 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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."); }
3
+ 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); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ 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; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import dayjs from 'dayjs';
8
+ import { isFulfillmentTimingBooking } from "../../modules/Order/pickupTiming";
9
+ /** Normalize scalar/array holder identities without merging the no-holder group with real holders. */
10
+ export function normalizeBookingHolderIds(value) {
11
+ var values = Array.isArray(value) ? value : value == null ? [] : [value];
12
+ return Array.from(new Set(values.flatMap(function (id) {
13
+ if (typeof id !== 'string' && typeof id !== 'number') return [];
14
+ var text = String(id).trim();
15
+ return text && text !== '0' ? [text] : [];
16
+ })));
17
+ }
18
+ export function getBookingHolderIds(booking) {
19
+ var _ref, _ref2, _ref3, _ref4, _booking$holder_id, _booking$metadata, _booking$holder, _booking$metadata2, _booking$_extend, _booking$_extend2;
20
+ return normalizeBookingHolderIds((_ref = (_ref2 = (_ref3 = (_ref4 = (_booking$holder_id = booking.holder_id) !== null && _booking$holder_id !== void 0 ? _booking$holder_id : (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.holder_id) !== null && _ref4 !== void 0 ? _ref4 : (_booking$holder = booking.holder) === null || _booking$holder === void 0 ? void 0 : _booking$holder.form_record) !== null && _ref3 !== void 0 ? _ref3 : (_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 || (_booking$metadata2 = _booking$metadata2.holder) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.form_record) !== null && _ref2 !== void 0 ? _ref2 : (_booking$_extend = booking._extend) === null || _booking$_extend === void 0 ? void 0 : _booking$_extend.holder_id) !== null && _ref !== void 0 ? _ref : (_booking$_extend2 = booking._extend) === null || _booking$_extend2 === void 0 || (_booking$_extend2 = _booking$_extend2.holder) === null || _booking$_extend2 === void 0 ? void 0 : _booking$_extend2.form_record);
21
+ }
22
+
23
+ /** Validate input and convert absolute ISO values to the runtime-local date/time used by booking fields. */
24
+ export function normalizeBookingDateTime(value) {
25
+ if (typeof value !== 'string') return undefined;
26
+ var text = value.trim().replace(' ', 'T');
27
+ var match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,3})?)?(Z|[+-]\d{2}:\d{2})?$/.exec(text);
28
+ if (!match) return undefined;
29
+ var _match = _slicedToArray(match, 8),
30
+ y = _match[1],
31
+ m = _match[2],
32
+ d = _match[3],
33
+ h = _match[4],
34
+ minute = _match[5],
35
+ _match$ = _match[6],
36
+ second = _match$ === void 0 ? '0' : _match$,
37
+ zone = _match[7];
38
+ var calendar = new Date("".concat(y, "-").concat(m, "-").concat(d, "T00:00:00.000Z"));
39
+ if (!Number.isFinite(calendar.getTime()) || calendar.toISOString().slice(0, 10) !== "".concat(y, "-").concat(m, "-").concat(d) || Number(h) > 23 || Number(minute) > 59 || Number(second) > 59 || !dayjs(text).isValid()) return undefined;
40
+ return zone ? dayjs(text).format('YYYY-MM-DDTHH:mm:ss') : text;
41
+ }
42
+ export function getBookingBoundary(booking, edge) {
43
+ var _booking;
44
+ var direct = (_booking = booking["".concat(edge, "At")]) !== null && _booking !== void 0 ? _booking : booking["".concat(edge, "_at")];
45
+ var directTime = normalizeBookingDateTime(direct);
46
+ if (directTime) return directTime;
47
+ var date = booking["".concat(edge, "_date")];
48
+ var time = booking["".concat(edge, "_time")];
49
+ if (typeof date !== 'string') return undefined;
50
+ return typeof time === 'string' ? normalizeBookingDateTime("".concat(date.slice(0, 10), "T").concat(time)) : normalizeBookingDateTime(date);
51
+ }
52
+
53
+ /** Select a default only; availability and resource occupancy remain the commit path's authority. */
54
+ export function resolveDefaultBookingStart(_ref5) {
55
+ var bookings = _ref5.bookings,
56
+ holderIds = _ref5.holderIds,
57
+ _ref5$mode = _ref5.mode,
58
+ mode = _ref5$mode === void 0 ? 'same_start_time' : _ref5$mode,
59
+ fallback = _ref5.fallback;
60
+ var holders = new Set(normalizeBookingHolderIds(holderIds));
61
+ var related = bookings.flatMap(function (booking) {
62
+ if (!booking || isFulfillmentTimingBooking(booking) || booking.deleted_at) return [];
63
+ var previousHolders = getBookingHolderIds(booking);
64
+ var matches = holders.size === 0 ? previousHolders.length === 0 : previousHolders.some(function (holder) {
65
+ return holders.has(holder);
66
+ });
67
+ if (!matches) return [];
68
+ var start = getBookingBoundary(booking, 'start');
69
+ var end = getBookingBoundary(booking, 'end');
70
+ if (!start || !end || !dayjs(end).isAfter(dayjs(start))) return [];
71
+ return [{
72
+ start: start,
73
+ end: end
74
+ }];
75
+ });
76
+ if (!related.length) return normalizeBookingDateTime(fallback);
77
+ if (mode === 'same_start_time') return related[related.length - 1].start;
78
+ return related.reduce(function (latest, booking) {
79
+ return dayjs(booking.end).isAfter(dayjs(latest)) ? booking.end : latest;
80
+ }, related[0].end);
81
+ }
@@ -0,0 +1,27 @@
1
+ import type { AvailabilityDateRange } from '../../modules/ResourcePlanner';
2
+ type ResourceId = number | string;
3
+ type RawResource = Record<string, any>;
4
+ export interface AvailabilitySessionResourceQuery {
5
+ resourceIds: ResourceId[];
6
+ dateRange: AvailabilityDateRange;
7
+ }
8
+ export interface AvailabilitySessionResourceLoadParams extends AvailabilitySessionResourceQuery {
9
+ /** The owner supplies shop/tenant, order cache, business and channel identity. */
10
+ scopeKey: string;
11
+ timezoneName: string;
12
+ /** Must reject transport/business errors; only a successful empty array is negative coverage. */
13
+ fetch: (query: AvailabilitySessionResourceQuery) => Promise<RawResource[]>;
14
+ }
15
+ /**
16
+ * Opt-in venue-session snapshots. Unlike the legacy SWR cache, a covered resource/day is never
17
+ * refreshed or evicted during this session. Only missing cells are fetched, including when a new
18
+ * resource set partly overlaps an earlier one. The final backend submission remains authoritative.
19
+ */
20
+ export declare class AvailabilitySessionResourceCache {
21
+ private readonly cells;
22
+ private readonly pending;
23
+ private generation;
24
+ clear(): void;
25
+ load(params: AvailabilitySessionResourceLoadParams): Promise<RawResource[]>;
26
+ }
27
+ export {};
@@ -0,0 +1,271 @@
1
+ var _excluded = ["event_list"];
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
5
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
6
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
7
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
8
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
9
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
11
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
12
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
14
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
+ 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); }
16
+ import { cloneDeep } from 'lodash-es';
17
+ import { dateOrdinalFromLocalDate, formatLocalDate, localDateTimeToScalar, localDateToScalarStart, nextDate, parseLocalDateTime } from "../../modules/ResourcePlanner/localClock";
18
+ function datesInRange(range) {
19
+ var count = dateOrdinalFromLocalDate(range.endDate) - dateOrdinalFromLocalDate(range.startDate) + 1;
20
+ // A legal 90-business-day projection may include its preceding opening and overnight tail.
21
+ if (count < 1 || count > 92) throw new Error('Resource coverage requires a valid range of at most 92 days.');
22
+ var dates = [];
23
+ var date = formatLocalDate(range.startDate);
24
+ for (var index = 0; index < count; index += 1) {
25
+ dates.push(date);
26
+ date = nextDate(date);
27
+ }
28
+ return dates;
29
+ }
30
+ function resourceIdOf(resource) {
31
+ var _ref, _resource$resourceId;
32
+ return (_ref = (_resource$resourceId = resource.resourceId) !== null && _resource$resourceId !== void 0 ? _resource$resourceId : resource.resource_id) !== null && _ref !== void 0 ? _ref : resource.id;
33
+ }
34
+ function eventTime(event, edge) {
35
+ var _ref2, _ref3, _ref4, _event;
36
+ return String((_ref2 = (_ref3 = (_ref4 = (_event = event["".concat(edge, "_at")]) !== null && _event !== void 0 ? _event : event["".concat(edge, "At")]) !== null && _ref4 !== void 0 ? _ref4 : event["".concat(edge, "_time")]) !== null && _ref3 !== void 0 ? _ref3 : event["".concat(edge, "Time")]) !== null && _ref2 !== void 0 ? _ref2 : '');
37
+ }
38
+ function stableValue(value) {
39
+ if (Array.isArray(value)) return value.map(stableValue);
40
+ if (value && _typeof(value) === 'object') {
41
+ return Object.keys(value).sort().reduce(function (result, key) {
42
+ result[key] = stableValue(value[key]);
43
+ return result;
44
+ }, {});
45
+ }
46
+ return value;
47
+ }
48
+ function eventIdentity(event) {
49
+ var _ref5, _ref6, _event$schedule_event;
50
+ var id = (_ref5 = (_ref6 = (_event$schedule_event = event.schedule_event_id) !== null && _event$schedule_event !== void 0 ? _event$schedule_event : event.scheduleEventId) !== null && _ref6 !== void 0 ? _ref6 : event.server_event_id) !== null && _ref5 !== void 0 ? _ref5 : event.id;
51
+ var isUniqueEvent = id !== undefined && id !== null && id !== '';
52
+ return {
53
+ // A booking/product UID can own several allocations. Only an actual event ID plus its
54
+ // interval identifies one event; otherwise retain the complete payload and its multiplicity.
55
+ key: isUniqueEvent ? "event:".concat(JSON.stringify([String(id), eventTime(event, 'start'), eventTime(event, 'end')])) : "raw:".concat(JSON.stringify(stableValue(event))),
56
+ isUniqueEvent: isUniqueEvent
57
+ };
58
+ }
59
+ function eventsOnDate(events, date) {
60
+ var start = localDateToScalarStart(date);
61
+ var end = localDateToScalarStart(nextDate(date));
62
+ return events.filter(function (event) {
63
+ try {
64
+ var eventStart = localDateTimeToScalar(parseLocalDateTime(eventTime(event, 'start')));
65
+ var eventEnd = localDateTimeToScalar(parseLocalDateTime(eventTime(event, 'end')));
66
+ return eventStart < eventEnd && eventStart < end && eventEnd > start;
67
+ } catch (_unused) {
68
+ return false;
69
+ }
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Opt-in venue-session snapshots. Unlike the legacy SWR cache, a covered resource/day is never
75
+ * refreshed or evicted during this session. Only missing cells are fetched, including when a new
76
+ * resource set partly overlaps an earlier one. The final backend submission remains authoritative.
77
+ */
78
+ export var AvailabilitySessionResourceCache = /*#__PURE__*/function () {
79
+ function AvailabilitySessionResourceCache() {
80
+ _classCallCheck(this, AvailabilitySessionResourceCache);
81
+ _defineProperty(this, "cells", new Map());
82
+ _defineProperty(this, "pending", new Map());
83
+ _defineProperty(this, "generation", 0);
84
+ }
85
+ _createClass(AvailabilitySessionResourceCache, [{
86
+ key: "clear",
87
+ value: function clear() {
88
+ this.generation += 1;
89
+ this.cells.clear();
90
+ this.pending.clear();
91
+ }
92
+ }, {
93
+ key: "load",
94
+ value: function () {
95
+ var _load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
96
+ var _this = this;
97
+ var generation, assertCurrent, resources, dates, key, waits, gaps, previousIds, result;
98
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
99
+ while (1) switch (_context2.prev = _context2.next) {
100
+ case 0:
101
+ generation = this.generation;
102
+ assertCurrent = function assertCurrent() {
103
+ if (generation !== _this.generation) {
104
+ throw Object.assign(new Error('Resource session changed while loading. Please prepare again.'), {
105
+ code: 'AVAILABILITY_CONTEXT_NOT_FOUND'
106
+ });
107
+ }
108
+ };
109
+ resources = Array.from(new Map(params.resourceIds.filter(function (id) {
110
+ return id !== undefined && id !== null && id !== '';
111
+ }).map(function (id) {
112
+ return [String(id), id];
113
+ })).values());
114
+ dates = datesInRange(params.dateRange);
115
+ key = function key(resourceId, date) {
116
+ return JSON.stringify([params.scopeKey, params.timezoneName, String(resourceId), date]);
117
+ };
118
+ waits = new Set();
119
+ gaps = [];
120
+ previousIds = '';
121
+ dates.forEach(function (date) {
122
+ var missing = resources.filter(function (resourceId) {
123
+ var cellKey = key(resourceId, date);
124
+ if (_this.cells.has(cellKey)) return false;
125
+ var pending = _this.pending.get(cellKey);
126
+ if (pending) {
127
+ waits.add(pending);
128
+ return false;
129
+ }
130
+ return true;
131
+ }).sort(function (left, right) {
132
+ return String(left).localeCompare(String(right));
133
+ });
134
+ var ids = JSON.stringify(missing.map(String));
135
+ var previous = gaps[gaps.length - 1];
136
+ if (missing.length && ids === previousIds && previous && nextDate(previous.dateRange.endDate) === date) {
137
+ previous.dateRange.endDate = date;
138
+ } else if (missing.length) {
139
+ gaps.push({
140
+ resourceIds: missing,
141
+ dateRange: {
142
+ startDate: date,
143
+ endDate: date
144
+ }
145
+ });
146
+ }
147
+ previousIds = ids;
148
+ });
149
+
150
+ // Reserve every missing cell synchronously before dispatching any request. This also deduplicates
151
+ // partial overlapping in-flight queries, rather than only identical or fully covering requests.
152
+ gaps.forEach(function (query) {
153
+ var queryDates = datesInRange(query.dateRange);
154
+ var cellKeys = query.resourceIds.flatMap(function (id) {
155
+ return queryDates.map(function (date) {
156
+ return key(id, date);
157
+ });
158
+ });
159
+ var promise = Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
160
+ var response, byId, updates;
161
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
162
+ while (1) switch (_context.prev = _context.next) {
163
+ case 0:
164
+ assertCurrent();
165
+ _context.next = 3;
166
+ return params.fetch(cloneDeep(query));
167
+ case 3:
168
+ response = _context.sent;
169
+ assertCurrent();
170
+ if (Array.isArray(response)) {
171
+ _context.next = 7;
172
+ break;
173
+ }
174
+ throw new Error('Booking resources returned an invalid response.');
175
+ case 7:
176
+ byId = new Map();
177
+ response.forEach(function (resource) {
178
+ if (!resource || _typeof(resource) !== 'object' || Array.isArray(resource)) {
179
+ throw new Error('Booking resources returned an invalid resource.');
180
+ }
181
+ var id = resourceIdOf(resource);
182
+ if (typeof id !== 'string' && typeof id !== 'number' || id === '' || typeof id === 'number' && !Number.isFinite(id) || resource.event_list != null && !Array.isArray(resource.event_list)) {
183
+ throw new Error('Booking resources returned invalid identity or occupancy data.');
184
+ }
185
+ byId.set(String(id), cloneDeep(resource));
186
+ });
187
+ // Assemble the response before publishing any cells, so malformed data cannot mark a
188
+ // partially successful range as covered. Missing resources in a valid response are cached too.
189
+ updates = new Map();
190
+ query.resourceIds.forEach(function (id) {
191
+ var raw = byId.get(String(id));
192
+ var events = Array.isArray(raw === null || raw === void 0 ? void 0 : raw.event_list) ? raw.event_list : [];
193
+ var metadata = raw ? function (_ref8) {
194
+ var _events = _ref8.event_list,
195
+ rest = _objectWithoutProperties(_ref8, _excluded);
196
+ return rest;
197
+ }(raw) : null;
198
+ queryDates.forEach(function (date) {
199
+ return updates.set(key(id, date), {
200
+ resource: metadata,
201
+ events: eventsOnDate(events, date)
202
+ });
203
+ });
204
+ });
205
+ assertCurrent();
206
+ updates.forEach(function (cell, cellKey) {
207
+ if (!_this.cells.has(cellKey)) _this.cells.set(cellKey, cell);
208
+ });
209
+ case 13:
210
+ case "end":
211
+ return _context.stop();
212
+ }
213
+ }, _callee);
214
+ }))).finally(function () {
215
+ cellKeys.forEach(function (cellKey) {
216
+ if (_this.pending.get(cellKey) === promise) _this.pending.delete(cellKey);
217
+ });
218
+ });
219
+ cellKeys.forEach(function (cellKey) {
220
+ return _this.pending.set(cellKey, promise);
221
+ });
222
+ waits.add(promise);
223
+ });
224
+ _context2.next = 12;
225
+ return Promise.all(Array.from(waits));
226
+ case 12:
227
+ assertCurrent();
228
+ result = [];
229
+ resources.forEach(function (id) {
230
+ var metadata = null;
231
+ var events = new Map();
232
+ dates.forEach(function (date) {
233
+ var cell = _this.cells.get(key(id, date));
234
+ if (!cell) throw new Error('Resource session coverage was lost. Please prepare again.');
235
+ if (!metadata && cell.resource) metadata = cell.resource;
236
+ var occurrences = new Map();
237
+ cell.events.forEach(function (event) {
238
+ var identity = eventIdentity(event);
239
+ var occurrence = identity.isUniqueEvent ? 0 : occurrences.get(identity.key) || 0;
240
+ occurrences.set(identity.key, occurrence + 1);
241
+ var occupancyKey = JSON.stringify([identity.key, occurrence]);
242
+ // Merge the maximum count seen in a day, not a set of booking UIDs: anonymous duplicate
243
+ // allocations must still count twice, while one cross-midnight event counts only once.
244
+ if (!events.has(occupancyKey)) events.set(occupancyKey, _objectSpread(_objectSpread({}, event), {}, {
245
+ __availabilitySessionOccupancyKey: occupancyKey
246
+ }));
247
+ });
248
+ });
249
+ if (metadata) {
250
+ result.push(cloneDeep(_objectSpread(_objectSpread({}, metadata), {}, {
251
+ event_list: Array.from(events.values()).sort(function (left, right) {
252
+ return eventTime(left, 'start').localeCompare(eventTime(right, 'start')) || eventTime(left, 'end').localeCompare(eventTime(right, 'end'));
253
+ })
254
+ })));
255
+ }
256
+ });
257
+ return _context2.abrupt("return", result);
258
+ case 16:
259
+ case "end":
260
+ return _context2.stop();
261
+ }
262
+ }, _callee2, this);
263
+ }));
264
+ function load(_x) {
265
+ return _load.apply(this, arguments);
266
+ }
267
+ return load;
268
+ }()
269
+ }]);
270
+ return AvailabilitySessionResourceCache;
271
+ }();
@@ -6,10 +6,42 @@ import type { AvailabilityDateRange, AvailabilityErrorCode, AvailabilityId, Avai
6
6
  import type { BookingTicketState } from '../BookingTicket/types';
7
7
  import type { AllergyRequirement } from '../../model/strategy/adapter/itemRule';
8
8
  import type { SalesNoteDraftInput } from '../../modules/Order/types';
9
+ import type { BaseSalesCalculateProductBookingPriceParams, BaseSalesProductBookingPriceResult } from '../BaseSales/types';
9
10
  export type { ProductListStoreQueryParams } from '../../modules/ProductList';
10
11
  export type { AvailabilityAbsoluteRange, AvailabilityAssignment, AvailabilityCell, AvailabilityDateRange, AvailabilityDisplayRange, AvailabilityErrorCode, AvailabilityId, AvailabilityMode, AvailabilityOccupancy, AvailabilityProduct, AvailabilityProductKind, AvailabilityProjection, AvailabilityProjectionInput, AvailabilityProjectionMeta, AvailabilityQuery, AvailabilityQueryResult, AvailabilityRequirementGroup, AvailabilityRequirementGroupResult, AvailabilityRequirementSelection, AvailabilityResource, AvailabilityResourceOption, AvailabilityResourceType, AvailabilityResourceWindow, AvailabilityScheduleMode, AvailabilityScheduleRef, AvailabilityScheduleRule, AvailabilitySelectionValidationParams, AvailabilitySelectionValidationResult, AvailabilitySessionRange, AvailabilityStatus, DateAvailabilityGroup, DateAvailabilityItem, DateAvailabilityQuery, DateAvailabilityQueryResult, GetProductTimeRangesRequest, ProductAvailabilityGroup, ProductAvailabilityItem, ProductAvailabilityQuery, ProductAvailabilityQueryResult, ProductTimeRange, ProductTimeRangeGroup, QueryAvailabilityBaseRequest, ResourceAvailabilityGroup, ResourceAvailabilityQuery, ResourceAvailabilityQueryResult, ResourceAvailabilityRangeGroup, TimeAvailabilityGroup, TimeAvailabilityItem, TimeAvailabilityQuery, TimeAvailabilityQueryResult, } from '../../modules/ResourcePlanner';
11
12
  export interface UnifiedBookingSalesState extends BookingTicketState {
12
13
  }
14
+ /** Read-only preview scope; existing solution queries remain fresh for selection and submission. */
15
+ export interface UnifiedBookingSalesCatalogQueryBatch {
16
+ queryCatalogSnapshot(params: ProductListLoadProductsParams): Promise<ProductData[]>;
17
+ queryCatalogProductDetail(params: ProductListLoadProductsParams & {
18
+ product_id: number;
19
+ }): Promise<ProductData | undefined>;
20
+ /** Releases retained results. A disposed batch cannot be reused. */
21
+ dispose(): void;
22
+ }
23
+ /** Venue page lifetime pool. Reads/quotes stay local; explicit opening may hydrate a variant once. */
24
+ export interface UnifiedBookingSalesVenueCatalogSession {
25
+ queryCatalogSnapshot(params?: ProductListLoadProductsParams): Promise<ProductData[]>;
26
+ queryCatalogProductDetail(params: ProductListLoadProductsParams & {
27
+ product_id: number;
28
+ }): Promise<ProductData | undefined>;
29
+ /** User-initiated opening only. Non-variant products never load a detail endpoint. */
30
+ prepareProductDetail(params: ProductListLoadProductsParams & {
31
+ product_id: number;
32
+ retry?: boolean;
33
+ }): Promise<ProductData | undefined>;
34
+ calculateProductBookingPrice(params: BaseSalesCalculateProductBookingPriceParams): Promise<BaseSalesProductBookingPriceResult>;
35
+ /** Retries failed pool/detail loads; successfully loaded records remain cached. */
36
+ retry(): void;
37
+ dispose(): void;
38
+ }
39
+ export type UnifiedBookingSalesVenueCatalogSessionParams = ProductListLoadProductsParams & {
40
+ /** Stable page/order session identity shared by main and extras pools. */
41
+ sessionKey?: string;
42
+ /** Lets implicit order repricing select the originating pool without guessing by product ID. */
43
+ poolRole?: 'main' | 'extras';
44
+ };
13
45
  export interface UnifiedBookingSalesPolicy {
14
46
  id?: AvailabilityId;
15
47
  title?: unknown;
@@ -39,6 +71,19 @@ export interface UnifiedBookingSalesLoadOpenDataParams {
39
71
  channel: string;
40
72
  force?: boolean;
41
73
  }
74
+ export interface UnifiedBookingSalesQueryBookingResourceDetailsParams {
75
+ /** Explicit booking date, YYYY-MM-DD. No implicit current-date fallback. */
76
+ date: string;
77
+ resourceIds: AvailabilityId[];
78
+ }
79
+ /** Original resource metadata. form_id is its resource type, not an associated customer form. */
80
+ export interface UnifiedBookingSalesResourceDetail extends Record<string, any> {
81
+ id: AvailabilityId;
82
+ resource_form_id?: number | string | null;
83
+ policy_id?: number | string | null;
84
+ form_id?: AvailabilityId;
85
+ main_field?: unknown;
86
+ }
42
87
  export interface UnifiedBookingSalesLoadProductsByScheduleDateParams extends Omit<ProductListLoadProductsParams, 'schedule_date' | 'product_ids'> {
43
88
  date: string;
44
89
  product_ids?: number[];
@@ -59,6 +104,14 @@ export interface UnifiedBookingSalesPrepareAvailabilityProjectionParams {
59
104
  dateRange?: Partial<AvailabilityDateRange>;
60
105
  catalogScope?: UnifiedBookingSalesCatalogScope;
61
106
  rawProducts?: Record<string, any>[];
107
+ /** Keep an independent catalog/projection without replacing the public sales catalog. Defaults to true. */
108
+ publishCatalog?: boolean;
109
+ /** Await remote occupancy refresh instead of stale-while-revalidate. Ignores rawResources; does not lock resources. */
110
+ refreshOccupancies?: boolean;
111
+ /** cache_first: 30-second preview. session: retain resource/date coverage for this venue page, including commit; overrides refreshOccupancies. Omit for legacy SWR. */
112
+ occupancyCachePolicy?: 'cache_first' | 'session';
113
+ /** Enforce configured sale cutoffs and disable manual POS availability overrides for this context. Defaults to false. */
114
+ strictAvailability?: boolean;
62
115
  rawResources?: Record<string, any>[];
63
116
  rawOccupancies?: AvailabilityOccupancy[];
64
117
  editingProductLineUids?: string[];
@@ -74,8 +127,9 @@ export interface AvailabilityContextRef {
74
127
  contextId: string;
75
128
  /** POS/Kiosk duration protocol capability and business-day default. */
76
129
  durationTimeSelection?: {
77
- version: 1;
130
+ version: 2;
78
131
  currentBusinessDate: string;
132
+ orderSessionId: string | null;
79
133
  };
80
134
  }
81
135
  export interface ContextualProductTimeRange extends ProductTimeRange {
@@ -100,6 +154,8 @@ export type ContextualAvailabilityQuery = (Omit<Extract<AvailabilityQuery, {
100
154
  })) & {
101
155
  /** Automatic remembered selection must not inherit POS manual exceptions. */
102
156
  selectionIntent?: 'remembered' | 'manual';
157
+ rememberedTimeByProductId?: GetProductTimeRangesRequest['rememberedTimeByProductId'];
158
+ orderSessionId?: string;
103
159
  };
104
160
  export type ContextualTimeAvailabilityItem = Omit<TimeAvailabilityItem, keyof ProductTimeRange> & ContextualProductTimeRange;
105
161
  export interface ContextualTimeAvailabilityGroup extends Omit<TimeAvailabilityGroup, 'times'> {
@@ -160,14 +216,26 @@ export interface UnifiedBookingSalesAddRetailProductParams {
160
216
  productId?: number | string;
161
217
  quantity?: number;
162
218
  productLoadParams?: ProductListLoadProductsParams;
219
+ salesNotes?: SalesNoteDraftInput[];
220
+ availabilityCommitGuard?: () => void;
163
221
  }
164
222
  export interface ContextualCommitAvailabilitySelectionParams {
165
- mode: 'add' | 'edit';
223
+ mode: 'add' | 'edit' | 'replace';
166
224
  /** Only POS duration add supports automatic remembered-time commits. */
167
225
  selectionIntent?: 'remembered' | 'manual';
226
+ /** v2 remembered commits must still belong to the order that saved the interval. */
227
+ orderSessionId?: string;
168
228
  /** Local UI intent guard, checked again immediately before the Order mutation. */
169
229
  availabilityCommitGuard?: () => void;
170
230
  productLineUid?: string;
231
+ /**
232
+ * Confirmed complete Party extras set (configured, purchase-time-repriced retail source products).
233
+ * Their legacy venue_booking_service_datetime metadata stores the venue-local quote time,
234
+ * independently of the main product's appointment time.
235
+ * Required for replace; edit opts into the same atomic path. Existing extras keep their own
236
+ * metadata.unique_identification_number; new extras omit it. [] explicitly removes all owned extras.
237
+ */
238
+ relatedRetailProducts?: Record<string, any>[];
171
239
  orderProduct: Record<string, any>;
172
240
  candidate: ContextualProductTimeRange;
173
241
  requirementSelections: AvailabilityRequirementSelection[];
@@ -242,6 +310,7 @@ export interface UnifiedBookingSalesApi {
242
310
  loadProductsByScheduleDate: (params: UnifiedBookingSalesLoadProductsByScheduleDateParams) => Promise<unknown[]>;
243
311
  queryProducts: (params?: ProductListStoreQueryParams) => Promise<ProductData[]>;
244
312
  stageRetailProducts: (params: UnifiedBookingSalesStageRetailProductsParams) => Promise<Record<string, any> | null>;
313
+ supportsVenueExtraHolders: () => boolean;
245
314
  addRetailProduct: (params: UnifiedBookingSalesAddRetailProductParams) => Promise<Record<string, any>[]>;
246
315
  prepareAvailabilityProjection: (params: UnifiedBookingSalesPrepareAvailabilityProjectionParams) => Promise<AvailabilityContextRef>;
247
316
  getProductTimeRanges: (contextId: string, request?: GetProductTimeRangesRequest) => Promise<ContextualProductTimeRangeGroup[]>;
@@ -1,6 +1,12 @@
1
+ /** Read-only preview scope; existing solution queries remain fresh for selection and submission. */
2
+
3
+ /** Venue page lifetime pool. Reads/quotes stay local; explicit opening may hydrate a variant once. */
4
+
1
5
  export var UnifiedBookingSalesHooks = /*#__PURE__*/function (UnifiedBookingSalesHooks) {
2
6
  UnifiedBookingSalesHooks["onAvailabilityProjectionPrepared"] = "unifiedBookingSales:onAvailabilityProjectionPrepared";
3
7
  UnifiedBookingSalesHooks["onAvailabilitySelectionCommitted"] = "unifiedBookingSales:onAvailabilitySelectionCommitted";
4
8
  UnifiedBookingSalesHooks["onAvailabilityProjectionDiagnostic"] = "unifiedBookingSales:onAvailabilityProjectionDiagnostic";
5
9
  return UnifiedBookingSalesHooks;
6
- }({});
10
+ }({});
11
+
12
+ /** Original resource metadata. form_id is its resource type, not an associated customer form. */
@@ -0,0 +1,32 @@
1
+ import type { ProductData } from '../../modules/Product/types';
2
+ import type { ProductListLoadProductsParams } from '../../modules/ProductList';
3
+ import type { BaseSalesCalculateProductBookingPriceParams, BaseSalesProductBookingPriceResult } from '../BaseSales/types';
4
+ import type { UnifiedBookingSalesVenueCatalogSession } from './types';
5
+ export type VenueCatalogRecord = Record<string, any>;
6
+ export interface VenueCatalogPool {
7
+ products: ProductData[];
8
+ menus: VenueCatalogRecord[];
9
+ /** Pricing menu_match follows the OS evaluator's full menu-definition contract. */
10
+ pricingMenus: VenueCatalogRecord[];
11
+ }
12
+ export declare function venueCatalogError(code: string, message: string): Error & {
13
+ code: string;
14
+ };
15
+ export declare function readVenueCatalogList(response: any, description: string): VenueCatalogRecord[];
16
+ export declare function validateVenueMenus(records: VenueCatalogRecord[], ids: number[]): VenueCatalogRecord[];
17
+ /** Same ID/collection union as the local OS product query; variant selection stays with SKU validation. */
18
+ export declare function productMatchesVenueMenu(product: VenueCatalogRecord, menu: VenueCatalogRecord): boolean;
19
+ export declare function activeVenueMenus(menus: VenueCatalogRecord[], schedules: VenueCatalogRecord[], datetime: string, dateOnly?: boolean): VenueCatalogRecord[];
20
+ /** Internal loader injection is not exposed to material callers. Rejected loads remain rejected until explicit retry. */
21
+ export declare function createVenueCatalogSessionAdapter(options: {
22
+ assertCurrent(): void;
23
+ load(): Promise<VenueCatalogPool>;
24
+ snapshot(pool: VenueCatalogPool, params: ProductListLoadProductsParams): ProductData[];
25
+ prepareDetail(pool: VenueCatalogPool, params: ProductListLoadProductsParams & {
26
+ product_id: number;
27
+ retry?: boolean;
28
+ }): Promise<void>;
29
+ quote(pool: VenueCatalogPool, params: BaseSalesCalculateProductBookingPriceParams): Promise<BaseSalesProductBookingPriceResult>;
30
+ onDispose?(): void;
31
+ onRetry?(): void;
32
+ }): UnifiedBookingSalesVenueCatalogSession;