@pisell/pisellos 0.10.76 → 0.10.78

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 (212) hide show
  1. package/dist/apis/picoding.d.ts +0 -0
  2. package/dist/effects/index.d.ts +19 -0
  3. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  4. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +105 -0
  5. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  6. package/dist/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  7. package/dist/model/strategy/adapter/dataVariant/type.d.ts +173 -0
  8. package/dist/model/strategy/adapter/promotion/adapter.d.ts +70 -0
  9. package/dist/model/strategy/adapter/promotion/examples.d.ts +224 -0
  10. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +535 -0
  12. package/dist/model/strategy/adapter/type.d.ts +28 -0
  13. package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
  14. package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  15. package/dist/model/strategy/adapter/walletPass/type.d.ts +192 -0
  16. package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  17. package/dist/model/strategy/engine.d.ts +119 -0
  18. package/dist/model/strategy/type.d.ts +245 -0
  19. package/dist/modules/Account/types.d.ts +56 -0
  20. package/dist/modules/BookingContext/types.d.ts +104 -0
  21. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  22. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  23. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  24. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  25. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  26. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  27. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  29. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  30. package/dist/modules/Customer/constants.d.ts +7 -0
  31. package/dist/modules/Date/types.d.ts +84 -0
  32. package/dist/modules/Date/utils.d.ts +36 -0
  33. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  34. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  35. package/dist/modules/Order/payment-utils.d.ts +26 -0
  36. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  37. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  38. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +68 -0
  39. package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
  40. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +21 -0
  41. package/dist/modules/Payment/mx51.d.ts +0 -0
  42. package/dist/modules/Payment/types.d.ts +943 -0
  43. package/dist/modules/Payment/utils.d.ts +19 -0
  44. package/dist/modules/Product/index.d.ts +1 -1
  45. package/dist/modules/ProductList/index.d.ts +2 -0
  46. package/dist/modules/ProductList/index.js +125 -39
  47. package/dist/modules/Quotation/types.d.ts +61 -0
  48. package/dist/modules/Resource/types.d.ts +50 -0
  49. package/dist/modules/Resource/utils.d.ts +23 -0
  50. package/dist/modules/ResourcePlanner/localClock.d.ts +33 -0
  51. package/dist/modules/ResourcePlanner/planner.js +5 -0
  52. package/dist/modules/SalesSummary/types.d.ts +69 -0
  53. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  54. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  55. package/dist/modules/ScanOrderLogger/types.d.ts +53 -0
  56. package/dist/modules/Schedule/getDateIsInSchedule.d.ts +32 -0
  57. package/dist/modules/Schedule/type.d.ts +157 -0
  58. package/dist/modules/Schedule/types.d.ts +201 -0
  59. package/dist/modules/Schedule/utils.d.ts +67 -0
  60. package/dist/modules/Step/tyeps.d.ts +20 -0
  61. package/dist/modules/SurchargeList/types.d.ts +15 -0
  62. package/dist/plugins/app.d.ts +10 -0
  63. package/dist/plugins/shopStore.d.ts +4 -0
  64. package/dist/plugins/user.d.ts +7 -0
  65. package/dist/server/modules/floor-plan/types.d.ts +43 -0
  66. package/dist/server/modules/menu/types.d.ts +68 -0
  67. package/dist/server/modules/payment/types.d.ts +9 -0
  68. package/dist/server/modules/quotation/types.d.ts +50 -0
  69. package/dist/server/modules/resource/types.d.ts +121 -0
  70. package/dist/server/modules/schedule/types.d.ts +1 -0
  71. package/dist/server/modules/schedule/utils.d.ts +32 -0
  72. package/dist/server/types.d.ts +66 -0
  73. package/dist/server/utils/index.d.ts +5 -0
  74. package/dist/server/utils/schedule.d.ts +14 -0
  75. package/dist/server/utils/time.d.ts +18 -0
  76. package/dist/solution/BaseSales/index.d.ts +12 -1
  77. package/dist/solution/BaseSales/index.js +275 -185
  78. package/dist/solution/BookingByStep/index.d.ts +2 -2
  79. package/dist/solution/BookingTicket/index.d.ts +1 -13
  80. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  81. package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  82. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  83. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +38 -0
  84. package/dist/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
  85. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  86. package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  87. package/dist/solution/PlaceOrder/index.d.ts +0 -0
  88. package/dist/solution/RegisterAndLogin/config.d.ts +93 -0
  89. package/dist/solution/RegisterAndLogin/types.d.ts +445 -0
  90. package/dist/solution/RegisterAndLogin/utils.d.ts +103 -0
  91. package/dist/solution/UnifiedBookingSales/index.d.ts +23 -1
  92. package/dist/solution/UnifiedBookingSales/index.js +1367 -646
  93. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
  94. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.js +4 -0
  95. package/dist/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
  96. package/dist/solution/UnifiedBookingSales/sessionResourceCache.js +271 -0
  97. package/dist/solution/UnifiedBookingSales/types.d.ts +25 -0
  98. package/dist/solution/UnifiedBookingSales/types.js +2 -0
  99. package/dist/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
  100. package/dist/solution/UnifiedBookingSales/venueCatalogSession.js +277 -0
  101. package/dist/store/createStore.d.ts +3 -0
  102. package/dist/types/index.d.ts +132 -0
  103. package/dist/utils/os-private-payload.d.ts +5 -0
  104. package/dist/utils/payment-number.d.ts +9 -0
  105. package/dist/utils/task.d.ts +40 -0
  106. package/dist/utils/watch.d.ts +102 -0
  107. package/lib/apis/picoding.d.ts +0 -0
  108. package/lib/effects/index.d.ts +19 -0
  109. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  110. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +105 -0
  111. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  112. package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  113. package/lib/model/strategy/adapter/dataVariant/type.d.ts +173 -0
  114. package/lib/model/strategy/adapter/promotion/adapter.d.ts +70 -0
  115. package/lib/model/strategy/adapter/promotion/examples.d.ts +224 -0
  116. package/lib/model/strategy/adapter/promotion/type.d.ts +535 -0
  117. package/lib/model/strategy/adapter/type.d.ts +28 -0
  118. package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
  119. package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  120. package/lib/model/strategy/adapter/walletPass/type.d.ts +192 -0
  121. package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  122. package/lib/model/strategy/engine.d.ts +119 -0
  123. package/lib/model/strategy/type.d.ts +245 -0
  124. package/lib/modules/Account/types.d.ts +56 -0
  125. package/lib/modules/BookingContext/types.d.ts +104 -0
  126. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  127. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  128. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  129. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  130. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  131. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  132. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  133. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  134. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  135. package/lib/modules/Customer/constants.d.ts +7 -0
  136. package/lib/modules/Date/types.d.ts +84 -0
  137. package/lib/modules/Date/utils.d.ts +36 -0
  138. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  139. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  140. package/lib/modules/Order/payment-utils.d.ts +26 -0
  141. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  142. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  143. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +68 -0
  144. package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
  145. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +21 -0
  146. package/lib/modules/Payment/mx51.d.ts +0 -0
  147. package/lib/modules/Payment/types.d.ts +943 -0
  148. package/lib/modules/Payment/utils.d.ts +19 -0
  149. package/lib/modules/Product/index.d.ts +1 -1
  150. package/lib/modules/ProductList/index.d.ts +2 -0
  151. package/lib/modules/ProductList/index.js +56 -0
  152. package/lib/modules/Quotation/types.d.ts +61 -0
  153. package/lib/modules/Resource/types.d.ts +50 -0
  154. package/lib/modules/Resource/utils.d.ts +23 -0
  155. package/lib/modules/ResourcePlanner/localClock.d.ts +33 -0
  156. package/lib/modules/ResourcePlanner/planner.js +4 -0
  157. package/lib/modules/SalesSummary/types.d.ts +69 -0
  158. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  159. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  160. package/lib/modules/ScanOrderLogger/types.d.ts +53 -0
  161. package/lib/modules/Schedule/getDateIsInSchedule.d.ts +32 -0
  162. package/lib/modules/Schedule/type.d.ts +157 -0
  163. package/lib/modules/Schedule/types.d.ts +201 -0
  164. package/lib/modules/Schedule/utils.d.ts +67 -0
  165. package/lib/modules/Step/tyeps.d.ts +20 -0
  166. package/lib/modules/SurchargeList/types.d.ts +15 -0
  167. package/lib/plugins/app.d.ts +10 -0
  168. package/lib/plugins/shopStore.d.ts +4 -0
  169. package/lib/plugins/user.d.ts +7 -0
  170. package/lib/server/modules/floor-plan/types.d.ts +43 -0
  171. package/lib/server/modules/menu/types.d.ts +68 -0
  172. package/lib/server/modules/payment/types.d.ts +9 -0
  173. package/lib/server/modules/quotation/types.d.ts +50 -0
  174. package/lib/server/modules/resource/types.d.ts +121 -0
  175. package/lib/server/modules/schedule/types.d.ts +1 -0
  176. package/lib/server/modules/schedule/utils.d.ts +32 -0
  177. package/lib/server/types.d.ts +66 -0
  178. package/lib/server/utils/index.d.ts +5 -0
  179. package/lib/server/utils/schedule.d.ts +14 -0
  180. package/lib/server/utils/time.d.ts +18 -0
  181. package/lib/solution/BaseSales/index.d.ts +12 -1
  182. package/lib/solution/BaseSales/index.js +65 -0
  183. package/lib/solution/BookingByStep/index.d.ts +2 -2
  184. package/lib/solution/BookingTicket/index.d.ts +1 -13
  185. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  186. package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  187. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  188. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +38 -0
  189. package/lib/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
  190. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  191. package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  192. package/lib/solution/PlaceOrder/index.d.ts +0 -0
  193. package/lib/solution/RegisterAndLogin/config.d.ts +93 -0
  194. package/lib/solution/RegisterAndLogin/types.d.ts +445 -0
  195. package/lib/solution/RegisterAndLogin/utils.d.ts +103 -0
  196. package/lib/solution/UnifiedBookingSales/index.d.ts +23 -1
  197. package/lib/solution/UnifiedBookingSales/index.js +399 -14
  198. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
  199. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +2 -0
  200. package/lib/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
  201. package/lib/solution/UnifiedBookingSales/sessionResourceCache.js +199 -0
  202. package/lib/solution/UnifiedBookingSales/types.d.ts +25 -0
  203. package/lib/solution/UnifiedBookingSales/types.js +1 -0
  204. package/lib/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
  205. package/lib/solution/UnifiedBookingSales/venueCatalogSession.js +151 -0
  206. package/lib/store/createStore.d.ts +3 -0
  207. package/lib/types/index.d.ts +132 -0
  208. package/lib/utils/os-private-payload.d.ts +5 -0
  209. package/lib/utils/payment-number.d.ts +9 -0
  210. package/lib/utils/task.d.ts +40 -0
  211. package/lib/utils/watch.d.ts +102 -0
  212. package/package.json +1 -1
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AvailabilitySessionResourceCache = void 0;
7
+ var _lodashEs = require("lodash-es");
8
+ var _localClock = require("../../modules/ResourcePlanner/localClock");
9
+ function datesInRange(range) {
10
+ const count = (0, _localClock.dateOrdinalFromLocalDate)(range.endDate) - (0, _localClock.dateOrdinalFromLocalDate)(range.startDate) + 1;
11
+ // A legal 90-business-day projection may include its preceding opening and overnight tail.
12
+ if (count < 1 || count > 92) throw new Error('Resource coverage requires a valid range of at most 92 days.');
13
+ const dates = [];
14
+ let date = (0, _localClock.formatLocalDate)(range.startDate);
15
+ for (let index = 0; index < count; index += 1) {
16
+ dates.push(date);
17
+ date = (0, _localClock.nextDate)(date);
18
+ }
19
+ return dates;
20
+ }
21
+ function resourceIdOf(resource) {
22
+ return resource.resourceId ?? resource.resource_id ?? resource.id;
23
+ }
24
+ function eventTime(event, edge) {
25
+ return String(event[`${edge}_at`] ?? event[`${edge}At`] ?? event[`${edge}_time`] ?? event[`${edge}Time`] ?? '');
26
+ }
27
+ function stableValue(value) {
28
+ if (Array.isArray(value)) return value.map(stableValue);
29
+ if (value && typeof value === 'object') {
30
+ return Object.keys(value).sort().reduce((result, key) => {
31
+ result[key] = stableValue(value[key]);
32
+ return result;
33
+ }, {});
34
+ }
35
+ return value;
36
+ }
37
+ function eventIdentity(event) {
38
+ const id = event.schedule_event_id ?? event.scheduleEventId ?? event.server_event_id ?? event.id;
39
+ const isUniqueEvent = id !== undefined && id !== null && id !== '';
40
+ return {
41
+ // A booking/product UID can own several allocations. Only an actual event ID plus its
42
+ // interval identifies one event; otherwise retain the complete payload and its multiplicity.
43
+ key: isUniqueEvent ? `event:${JSON.stringify([String(id), eventTime(event, 'start'), eventTime(event, 'end')])}` : `raw:${JSON.stringify(stableValue(event))}`,
44
+ isUniqueEvent
45
+ };
46
+ }
47
+ function eventsOnDate(events, date) {
48
+ const start = (0, _localClock.localDateToScalarStart)(date);
49
+ const end = (0, _localClock.localDateToScalarStart)((0, _localClock.nextDate)(date));
50
+ return events.filter(event => {
51
+ try {
52
+ const eventStart = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(eventTime(event, 'start')));
53
+ const eventEnd = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(eventTime(event, 'end')));
54
+ return eventStart < eventEnd && eventStart < end && eventEnd > start;
55
+ } catch {
56
+ return false;
57
+ }
58
+ });
59
+ }
60
+
61
+ /**
62
+ * Opt-in venue-session snapshots. Unlike the legacy SWR cache, a covered resource/day is never
63
+ * refreshed or evicted during this session. Only missing cells are fetched, including when a new
64
+ * resource set partly overlaps an earlier one. The final backend submission remains authoritative.
65
+ */
66
+ class AvailabilitySessionResourceCache {
67
+ cells = new Map();
68
+ pending = new Map();
69
+ generation = 0;
70
+ clear() {
71
+ this.generation += 1;
72
+ this.cells.clear();
73
+ this.pending.clear();
74
+ }
75
+ async load(params) {
76
+ const generation = this.generation;
77
+ const assertCurrent = () => {
78
+ if (generation !== this.generation) {
79
+ throw Object.assign(new Error('Resource session changed while loading. Please prepare again.'), {
80
+ code: 'AVAILABILITY_CONTEXT_NOT_FOUND'
81
+ });
82
+ }
83
+ };
84
+ const resources = Array.from(new Map(params.resourceIds.filter(id => id !== undefined && id !== null && id !== '').map(id => [String(id), id])).values());
85
+ const dates = datesInRange(params.dateRange);
86
+ const key = (resourceId, date) => JSON.stringify([params.scopeKey, params.timezoneName, String(resourceId), date]);
87
+ const waits = new Set();
88
+ const gaps = [];
89
+ let previousIds = '';
90
+ dates.forEach(date => {
91
+ const missing = resources.filter(resourceId => {
92
+ const cellKey = key(resourceId, date);
93
+ if (this.cells.has(cellKey)) return false;
94
+ const pending = this.pending.get(cellKey);
95
+ if (pending) {
96
+ waits.add(pending);
97
+ return false;
98
+ }
99
+ return true;
100
+ }).sort((left, right) => String(left).localeCompare(String(right)));
101
+ const ids = JSON.stringify(missing.map(String));
102
+ const previous = gaps[gaps.length - 1];
103
+ if (missing.length && ids === previousIds && previous && (0, _localClock.nextDate)(previous.dateRange.endDate) === date) {
104
+ previous.dateRange.endDate = date;
105
+ } else if (missing.length) {
106
+ gaps.push({
107
+ resourceIds: missing,
108
+ dateRange: {
109
+ startDate: date,
110
+ endDate: date
111
+ }
112
+ });
113
+ }
114
+ previousIds = ids;
115
+ });
116
+
117
+ // Reserve every missing cell synchronously before dispatching any request. This also deduplicates
118
+ // partial overlapping in-flight queries, rather than only identical or fully covering requests.
119
+ gaps.forEach(query => {
120
+ const queryDates = datesInRange(query.dateRange);
121
+ const cellKeys = query.resourceIds.flatMap(id => queryDates.map(date => key(id, date)));
122
+ const promise = Promise.resolve().then(async () => {
123
+ assertCurrent();
124
+ const response = await params.fetch((0, _lodashEs.cloneDeep)(query));
125
+ assertCurrent();
126
+ if (!Array.isArray(response)) throw new Error('Booking resources returned an invalid response.');
127
+ const byId = new Map();
128
+ response.forEach(resource => {
129
+ if (!resource || typeof resource !== 'object' || Array.isArray(resource)) {
130
+ throw new Error('Booking resources returned an invalid resource.');
131
+ }
132
+ const id = resourceIdOf(resource);
133
+ if (typeof id !== 'string' && typeof id !== 'number' || id === '' || typeof id === 'number' && !Number.isFinite(id) || resource.event_list != null && !Array.isArray(resource.event_list)) {
134
+ throw new Error('Booking resources returned invalid identity or occupancy data.');
135
+ }
136
+ byId.set(String(id), (0, _lodashEs.cloneDeep)(resource));
137
+ });
138
+ // Assemble the response before publishing any cells, so malformed data cannot mark a
139
+ // partially successful range as covered. Missing resources in a valid response are cached too.
140
+ const updates = new Map();
141
+ query.resourceIds.forEach(id => {
142
+ const raw = byId.get(String(id));
143
+ const events = Array.isArray(raw?.event_list) ? raw.event_list : [];
144
+ const metadata = raw ? (({
145
+ event_list: _events,
146
+ ...rest
147
+ }) => rest)(raw) : null;
148
+ queryDates.forEach(date => updates.set(key(id, date), {
149
+ resource: metadata,
150
+ events: eventsOnDate(events, date)
151
+ }));
152
+ });
153
+ assertCurrent();
154
+ updates.forEach((cell, cellKey) => {
155
+ if (!this.cells.has(cellKey)) this.cells.set(cellKey, cell);
156
+ });
157
+ }).finally(() => {
158
+ cellKeys.forEach(cellKey => {
159
+ if (this.pending.get(cellKey) === promise) this.pending.delete(cellKey);
160
+ });
161
+ });
162
+ cellKeys.forEach(cellKey => this.pending.set(cellKey, promise));
163
+ waits.add(promise);
164
+ });
165
+ await Promise.all(Array.from(waits));
166
+ assertCurrent();
167
+ const result = [];
168
+ resources.forEach(id => {
169
+ let metadata = null;
170
+ const events = new Map();
171
+ dates.forEach(date => {
172
+ const cell = this.cells.get(key(id, date));
173
+ if (!cell) throw new Error('Resource session coverage was lost. Please prepare again.');
174
+ if (!metadata && cell.resource) metadata = cell.resource;
175
+ const occurrences = new Map();
176
+ cell.events.forEach(event => {
177
+ const identity = eventIdentity(event);
178
+ const occurrence = identity.isUniqueEvent ? 0 : occurrences.get(identity.key) || 0;
179
+ occurrences.set(identity.key, occurrence + 1);
180
+ const occupancyKey = JSON.stringify([identity.key, occurrence]);
181
+ // Merge the maximum count seen in a day, not a set of booking UIDs: anonymous duplicate
182
+ // allocations must still count twice, while one cross-midnight event counts only once.
183
+ if (!events.has(occupancyKey)) events.set(occupancyKey, {
184
+ ...event,
185
+ __availabilitySessionOccupancyKey: occupancyKey
186
+ });
187
+ });
188
+ });
189
+ if (metadata) {
190
+ result.push((0, _lodashEs.cloneDeep)({
191
+ ...metadata,
192
+ event_list: Array.from(events.values()).sort((left, right) => eventTime(left, 'start').localeCompare(eventTime(right, 'start')) || eventTime(left, 'end').localeCompare(eventTime(right, 'end')))
193
+ }));
194
+ }
195
+ });
196
+ return result;
197
+ }
198
+ }
199
+ exports.AvailabilitySessionResourceCache = AvailabilitySessionResourceCache;
@@ -6,6 +6,7 @@ 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 {
@@ -19,6 +20,28 @@ export interface UnifiedBookingSalesCatalogQueryBatch {
19
20
  /** Releases retained results. A disposed batch cannot be reused. */
20
21
  dispose(): void;
21
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
+ };
22
45
  export interface UnifiedBookingSalesPolicy {
23
46
  id?: AvailabilityId;
24
47
  title?: unknown;
@@ -85,6 +108,8 @@ export interface UnifiedBookingSalesPrepareAvailabilityProjectionParams {
85
108
  publishCatalog?: boolean;
86
109
  /** Await remote occupancy refresh instead of stale-while-revalidate. Ignores rawResources; does not lock resources. */
87
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';
88
113
  /** Enforce configured sale cutoffs and disable manual POS availability overrides for this context. Defaults to false. */
89
114
  strictAvailability?: boolean;
90
115
  rawResources?: Record<string, any>[];
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.UnifiedBookingSalesHooks = void 0;
7
7
  /** Read-only preview scope; existing solution queries remain fresh for selection and submission. */
8
+ /** Venue page lifetime pool. Reads/quotes stay local; explicit opening may hydrate a variant once. */
8
9
  let UnifiedBookingSalesHooks = exports.UnifiedBookingSalesHooks = /*#__PURE__*/function (UnifiedBookingSalesHooks) {
9
10
  UnifiedBookingSalesHooks["onAvailabilityProjectionPrepared"] = "unifiedBookingSales:onAvailabilityProjectionPrepared";
10
11
  UnifiedBookingSalesHooks["onAvailabilitySelectionCommitted"] = "unifiedBookingSales:onAvailabilitySelectionCommitted";
@@ -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;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.activeVenueMenus = activeVenueMenus;
7
+ exports.createVenueCatalogSessionAdapter = createVenueCatalogSessionAdapter;
8
+ exports.productMatchesVenueMenu = productMatchesVenueMenu;
9
+ exports.readVenueCatalogList = readVenueCatalogList;
10
+ exports.validateVenueMenus = validateVenueMenus;
11
+ exports.venueCatalogError = venueCatalogError;
12
+ var _lodashEs = require("lodash-es");
13
+ var _getDateIsInSchedule = require("../../modules/Schedule/getDateIsInSchedule");
14
+ function venueCatalogError(code, message) {
15
+ return Object.assign(new Error(message), {
16
+ code
17
+ });
18
+ }
19
+ function readVenueCatalogList(response, description) {
20
+ const list = response?.data?.list;
21
+ if (!response || response.status === false || response.success === false || response.code != null && Number(response.code) !== 200 || !Array.isArray(list)) {
22
+ throw venueCatalogError('VENUE_CATALOG_LOAD_FAILED', response?.message || `${description} could not be loaded.`);
23
+ }
24
+ const total = response.data.total ?? response.data.total_count ?? response.data.total_num;
25
+ if (total != null && Number.isFinite(Number(total)) && Number(total) > list.length) {
26
+ throw venueCatalogError('VENUE_CATALOG_INCOMPLETE', `${description} is incomplete. A complete catalog response is required.`);
27
+ }
28
+ return list;
29
+ }
30
+ function validateVenueMenus(records, ids) {
31
+ return ids.map(id => {
32
+ const menu = records.find(row => Number(row.form_record_id) === id);
33
+ const config = menu?.partyroom_package;
34
+ if (!menu || !['product_all', 'products', 'product_collection'].includes(config?.type) || !Array.isArray(menu.schedule) || menu.schedule.some(value => !Number.isSafeInteger(Number(value)) || Number(value) <= 0) || config.type !== 'product_all' && (!Array.isArray(config.products) || config.products.some(row => {
35
+ const value = Number(row?.[config.type === 'products' ? 'product_id' : 'product_collection_id']);
36
+ return !Number.isSafeInteger(value) || value <= 0;
37
+ }))) {
38
+ throw venueCatalogError('VENUE_MENU_INCOMPLETE', 'The configured menu is incomplete. Reload the booking page.');
39
+ }
40
+ return (0, _lodashEs.cloneDeep)(menu);
41
+ });
42
+ }
43
+
44
+ /** Same ID/collection union as the local OS product query; variant selection stays with SKU validation. */
45
+ function productMatchesVenueMenu(product, menu) {
46
+ if (menu.status && menu.status !== 'valid') return false;
47
+ const config = menu.partyroom_package;
48
+ if (config?.type === 'product_all') return true;
49
+ if (config?.type === 'products') return config.products.some(row => Number(row.product_id) === Number(product.id));
50
+ if (config?.type === 'product_collection') {
51
+ if (!Array.isArray(product.collection)) {
52
+ throw venueCatalogError('VENUE_CATALOG_INCOMPLETE', 'Product collection data is missing from the catalog.');
53
+ }
54
+ return config.products.some(row => product.collection.some(collection => Number(collection.id) === Number(row.product_collection_id)));
55
+ }
56
+ return false;
57
+ }
58
+ function activeVenueMenus(menus, schedules, datetime, dateOnly = false) {
59
+ const scheduleMap = new Map(schedules.map(row => [Number(row.id), row]));
60
+ return menus.filter(menu => {
61
+ if (menu.status && menu.status !== 'valid') return false;
62
+ const records = menu.schedule.map(id => scheduleMap.get(Number(id)));
63
+ if (records.some(record => !record)) {
64
+ throw venueCatalogError('VENUE_SCHEDULE_INCOMPLETE', 'Menu schedule data is not ready. Please retry.');
65
+ }
66
+ // A calendar/card read asks whether the menu opens at any point on that date.
67
+ // Only selected-time/retail quotes require membership at an exact instant.
68
+ return dateOnly ? (0, _getDateIsInSchedule.getScheduleStartEndTimePoints)(datetime.slice(0, 10), records).length > 0 : (0, _getDateIsInSchedule.getDateIsInSchedule)(datetime, records);
69
+ });
70
+ }
71
+
72
+ /** Internal loader injection is not exposed to material callers. Rejected loads remain rejected until explicit retry. */
73
+ function createVenueCatalogSessionAdapter(options) {
74
+ let disposed = false;
75
+ let failed = false;
76
+ let pending;
77
+ const assertCurrent = () => {
78
+ if (disposed) throw venueCatalogError('VENUE_CATALOG_DISPOSED', 'The venue catalog session is closed.');
79
+ options.assertCurrent();
80
+ };
81
+ const load = async () => {
82
+ assertCurrent();
83
+ if (!pending) {
84
+ pending = Promise.resolve().then(() => {
85
+ assertCurrent();
86
+ return options.load();
87
+ }).then(pool => {
88
+ assertCurrent();
89
+ return (0, _lodashEs.cloneDeep)(pool);
90
+ }).catch(error => {
91
+ failed = true;
92
+ throw error;
93
+ });
94
+ }
95
+ const pool = await pending;
96
+ assertCurrent();
97
+ return pool;
98
+ };
99
+ return {
100
+ queryCatalogSnapshot: async (params = {}) => {
101
+ const pool = await load();
102
+ const result = options.snapshot(pool, (0, _lodashEs.cloneDeep)(params));
103
+ assertCurrent();
104
+ return (0, _lodashEs.cloneDeep)(result);
105
+ },
106
+ queryCatalogProductDetail: async ({
107
+ product_id,
108
+ ...params
109
+ }) => {
110
+ const pool = await load();
111
+ const result = options.snapshot(pool, {
112
+ ...(0, _lodashEs.cloneDeep)(params),
113
+ product_ids: [product_id]
114
+ });
115
+ assertCurrent();
116
+ return (0, _lodashEs.cloneDeep)(result.find(product => Number(product.id) === Number(product_id)));
117
+ },
118
+ prepareProductDetail: async params => {
119
+ const pool = await load();
120
+ const query = {
121
+ ...(0, _lodashEs.cloneDeep)(params),
122
+ product_ids: [params.product_id]
123
+ };
124
+ if (!options.snapshot(pool, query).some(product => Number(product.id) === Number(params.product_id))) return undefined;
125
+ await options.prepareDetail(pool, (0, _lodashEs.cloneDeep)(params));
126
+ assertCurrent();
127
+ return (0, _lodashEs.cloneDeep)(options.snapshot(pool, query).find(product => Number(product.id) === Number(params.product_id)));
128
+ },
129
+ calculateProductBookingPrice: async params => {
130
+ const pool = await load();
131
+ const result = await options.quote(pool, (0, _lodashEs.cloneDeep)(params));
132
+ assertCurrent();
133
+ return (0, _lodashEs.cloneDeep)(result);
134
+ },
135
+ retry: () => {
136
+ assertCurrent();
137
+ if (failed) {
138
+ pending = undefined;
139
+ failed = false;
140
+ }
141
+ options.onRetry?.();
142
+ },
143
+ dispose: () => {
144
+ if (!disposed) {
145
+ disposed = true;
146
+ pending = undefined;
147
+ options.onDispose?.();
148
+ }
149
+ }
150
+ };
151
+ }
@@ -0,0 +1,3 @@
1
+ export declare function createStore<T extends object>(initialState: T, moduleName: string, onChange?: (path: string, value: any) => void): {
2
+ proxy: T;
3
+ };
@@ -0,0 +1,132 @@
1
+ /**
2
+ * pisell OS 核心类型定义
3
+ */
4
+ export interface Plugin {
5
+ name: string;
6
+ version: string;
7
+ initialize: () => Promise<void> | void;
8
+ destroy?: () => Promise<void> | void;
9
+ getLocalStorage?: (key: string) => string | null;
10
+ }
11
+ export interface PluginOptions {
12
+ dependencies?: string[];
13
+ }
14
+ export interface Module {
15
+ name: string;
16
+ version: string;
17
+ initialize: (core: PisellCore, options: ModuleOptions) => Promise<void> | void;
18
+ /**
19
+ * 父级解决方案运行时更新 otherParams 后,显式通知子模块刷新自己的运行态参数。
20
+ *
21
+ * @example
22
+ * await module.updateOtherParams?.({ channel: 'pos' }, { changedParams: { channel: 'pos' } });
23
+ */
24
+ updateOtherParams?: (params: Record<string, any>, meta?: {
25
+ changedParams?: Record<string, any>;
26
+ cover?: boolean;
27
+ }) => Promise<void> | void;
28
+ destroy?: () => Promise<void> | void;
29
+ exports?: Record<string, any>;
30
+ isSolution?: boolean;
31
+ [key: string]: any;
32
+ }
33
+ export interface ModuleOptions {
34
+ dependencies?: string[];
35
+ plugins?: string[];
36
+ hooks?: any;
37
+ store?: Record<string, any>;
38
+ initialState?: Record<string, any>;
39
+ otherParams?: Record<string, any>;
40
+ }
41
+ export type EventHandler = (data?: any) => void;
42
+ export interface PisellCore {
43
+ registerPlugin: (plugin: Plugin, options?: PluginOptions) => void;
44
+ getPlugin: <T extends Plugin>(name: string) => T | null;
45
+ hasPlugin: (name: string) => boolean;
46
+ registerModule: (module: Module, options?: ModuleOptions) => void;
47
+ unregisterModule: (module: Module, options?: ModuleOptions) => void;
48
+ getModule: <T extends Module>(name: string) => T | null;
49
+ getModuleExports: <T = any>(name: string) => T | null;
50
+ hasModule: (name: string) => boolean;
51
+ getModuleNames: () => string[];
52
+ effects: {
53
+ on: (event: string, callback: (payload: any) => void) => () => void;
54
+ once: (event: string, callback: (payload: any) => void) => () => void;
55
+ only: (event: string, callback: (payload: any) => void) => () => void;
56
+ off: (event: string, callback: (payload: any) => void) => void;
57
+ emit: (event: string, payload: any, value?: any) => Promise<{
58
+ status: boolean;
59
+ data: any;
60
+ }>;
61
+ offByModuleDestroy: (module: string) => void;
62
+ };
63
+ context: BusinessContext;
64
+ validateContext: (config: ModuleContextConfig) => boolean;
65
+ serverOptions?: ServerOptions;
66
+ server?: any;
67
+ setContext: (ctx: Partial<BusinessContext>) => void;
68
+ }
69
+ /**
70
+ * 业务上下文接口
71
+ */
72
+ export interface BusinessContext {
73
+ userId?: string;
74
+ companyId?: string;
75
+ locale?: string;
76
+ [key: string]: any;
77
+ }
78
+ /**
79
+ * 上下文验证规则
80
+ */
81
+ export interface ContextValidationRule {
82
+ name: string;
83
+ required: boolean;
84
+ validate?: (value: any) => boolean;
85
+ message?: string;
86
+ }
87
+ /**
88
+ * 模块上下文配置
89
+ */
90
+ export interface ModuleContextConfig {
91
+ name: string;
92
+ validations: ContextValidationRule[];
93
+ }
94
+ /**
95
+ * Server 模块配置
96
+ */
97
+ export interface ServerModuleConfig {
98
+ /** 模块名称 */
99
+ name: string;
100
+ /** 是否自动预加载数据 */
101
+ preload?: boolean;
102
+ /** 模块配置参数 */
103
+ config?: Record<string, any>;
104
+ }
105
+ /**
106
+ * Server 配置选项
107
+ */
108
+ export interface ServerOptions {
109
+ All_DATA_SOURCES: Record<string, any>;
110
+ /** 要启用的模块列表 */
111
+ modules?: string[] | ServerModuleConfig[];
112
+ /** 是否自动初始化数据 */
113
+ autoInitData?: boolean;
114
+ }
115
+ export interface PisellOSOptions {
116
+ debug?: boolean;
117
+ plugins?: Array<{
118
+ plugin: Plugin;
119
+ options?: PluginOptions;
120
+ }>;
121
+ modules?: Array<{
122
+ module: Module;
123
+ options?: ModuleOptions;
124
+ }>;
125
+ context?: BusinessContext;
126
+ /** Server 配置 */
127
+ server?: ServerOptions;
128
+ }
129
+ export interface InitializeServerOptions {
130
+ onModuleLoad?: (module: string) => void;
131
+ onModuleLoadComplete?: (module: string) => void;
132
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Remove top-level fields reserved for communication with the PisellOS proxy.
3
+ * Nested business payloads are intentionally left untouched.
4
+ */
5
+ export declare function stripOsPrivatePayloadFields<T>(data: T): T;
@@ -0,0 +1,9 @@
1
+ export type PaymentNumberAppDataGetter = (key: string) => unknown;
2
+ /**
3
+ * Resolve the synchronous fallback without caching runtime device data.
4
+ */
5
+ export declare function resolvePaymentNumberDevicePrefixFromDeviceId(getAppData: PaymentNumberAppDataGetter): string;
6
+ /**
7
+ * Resolve the latest device segment when a new payment number is generated.
8
+ */
9
+ export declare function resolvePaymentNumberDevicePrefix(getAppData: PaymentNumberAppDataGetter): Promise<string>;
@@ -0,0 +1,40 @@
1
+ type Action = (...args: any[]) => Promise<any>;
2
+ type Task = {
3
+ uuid: string;
4
+ type: string;
5
+ actionParams?: Record<string, any>;
6
+ };
7
+ declare class Tasks {
8
+ private actions;
9
+ private taskQueue;
10
+ isRunning: boolean;
11
+ constructor(actions?: Map<string, Action>);
12
+ /**
13
+ * 清空所有任务
14
+ */
15
+ clear(): void;
16
+ /**
17
+ * 清空任务执行队列
18
+ */
19
+ clearTaskQueue(): void;
20
+ /**
21
+ * 添加action
22
+ * @param name action名称
23
+ * @param action action函数
24
+ */
25
+ addAction(name: string, action: Action): void;
26
+ /**
27
+ * 添加任务
28
+ * @param task 任务
29
+ */
30
+ addTask(task: Task): void;
31
+ /**
32
+ * 执行任务
33
+ */
34
+ run(): Promise<void>;
35
+ /**
36
+ * 判定当前的任务是否依然存在
37
+ */
38
+ isTaskExist(uuid: string): boolean;
39
+ }
40
+ export default Tasks;