@pisell/pisellos 2.2.323 → 2.2.325

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 (199) 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/model/strategy/adapter/promotion/index.js +9 -0
  6. package/dist/modules/BookingContext/index.d.ts +2 -2
  7. package/dist/modules/BookingContext/index.js +55 -25
  8. package/dist/modules/BookingContext/types.d.ts +2 -0
  9. package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  10. package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
  11. package/dist/modules/BookingContext/utils/index.d.ts +1 -0
  12. package/dist/modules/BookingContext/utils/index.js +1 -0
  13. package/dist/modules/BookingContext/utils/productExtend.d.ts +20 -1
  14. package/dist/modules/BookingContext/utils/productExtend.js +122 -29
  15. package/dist/modules/Date/index.d.ts +1 -1
  16. package/dist/modules/Date/index.js +60 -14
  17. package/dist/modules/Date/types.d.ts +5 -0
  18. package/dist/modules/Discount/index.js +1 -0
  19. package/dist/modules/OpenData/index.d.ts +1 -0
  20. package/dist/modules/OpenData/index.js +1 -0
  21. package/dist/modules/OpenData/salesSettings.d.ts +32 -0
  22. package/dist/modules/OpenData/salesSettings.js +80 -0
  23. package/dist/modules/OpenData/types.d.ts +16 -0
  24. package/dist/modules/OpenData/utils.d.ts +1 -1
  25. package/dist/modules/OpenData/utils.js +3 -2
  26. package/dist/modules/Order/index.d.ts +55 -12
  27. package/dist/modules/Order/index.js +2699 -1411
  28. package/dist/modules/Order/types.d.ts +43 -5
  29. package/dist/modules/Order/types.js +4 -0
  30. package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
  31. package/dist/modules/Order/unpaidAmountGap.js +72 -0
  32. package/dist/modules/Order/utils/discountProductLineIdentity.js +2 -2
  33. package/dist/modules/Order/utils/productVoucherGroups.d.ts +15 -0
  34. package/dist/modules/Order/utils/productVoucherGroups.js +115 -0
  35. package/dist/modules/Order/utils.d.ts +3 -1
  36. package/dist/modules/Order/utils.js +6 -2
  37. package/dist/modules/Product/index.d.ts +1 -1
  38. package/dist/modules/ProductList/clientDataVariants.js +6 -2
  39. package/dist/modules/ProductList/index.d.ts +2 -0
  40. package/dist/modules/ProductList/index.js +161 -51
  41. package/dist/modules/ResourcePlanner/planner.js +58 -2
  42. package/dist/modules/ResourcePlanner/types.d.ts +13 -0
  43. package/dist/modules/Rules/index.d.ts +2 -0
  44. package/dist/modules/Rules/index.js +58 -39
  45. package/dist/modules/Schedule/index.d.ts +7 -1
  46. package/dist/modules/Schedule/index.js +155 -39
  47. package/dist/modules/Schedule/types.d.ts +2 -0
  48. package/dist/modules/bookingReadValidation.d.ts +6 -0
  49. package/dist/modules/bookingReadValidation.js +72 -0
  50. package/dist/plugins/request.d.ts +2 -0
  51. package/dist/server/index.d.ts +8 -0
  52. package/dist/server/index.js +1458 -1166
  53. package/dist/server/modules/order/index.js +2 -1
  54. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  55. package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
  56. package/dist/shared/receipt/small-ticket.d.ts +4 -0
  57. package/dist/shared/receipt/small-ticket.js +70 -12
  58. package/dist/solution/BaseSales/index.d.ts +39 -5
  59. package/dist/solution/BaseSales/index.js +1828 -1462
  60. package/dist/solution/BaseSales/types.d.ts +1 -0
  61. package/dist/solution/BaseSales/types.js +1 -0
  62. package/dist/solution/BookingByStep/index.d.ts +16 -2
  63. package/dist/solution/BookingByStep/index.js +676 -361
  64. package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
  65. package/dist/solution/BookingByStep/utils/resources.js +117 -76
  66. package/dist/solution/BookingTicket/index.d.ts +15 -3
  67. package/dist/solution/BookingTicket/index.js +249 -135
  68. package/dist/solution/BookingTicket/types.d.ts +14 -2
  69. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +3 -1
  70. package/dist/solution/BookingTicket/utils/addProductDecision.js +39 -11
  71. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  72. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
  73. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
  74. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +88 -0
  75. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
  76. package/dist/solution/BookingTicket/utils/scan/handleScan.js +2 -1
  77. package/dist/solution/OrderInvoicePreview/index.js +14 -8
  78. package/dist/solution/ScanOrder/index.d.ts +2 -0
  79. package/dist/solution/ScanOrder/index.js +166 -67
  80. package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
  81. package/dist/solution/ScanOrder/menuAvailability.js +363 -0
  82. package/dist/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
  83. package/dist/solution/UnifiedBookingSales/catalogQueryBatch.js +202 -0
  84. package/dist/solution/UnifiedBookingSales/index.d.ts +96 -4
  85. package/dist/solution/UnifiedBookingSales/index.js +3374 -1177
  86. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
  87. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.js +4 -0
  88. package/dist/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
  89. package/dist/solution/UnifiedBookingSales/salesSettings.js +81 -0
  90. package/dist/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
  91. package/dist/solution/UnifiedBookingSales/sessionResourceCache.js +271 -0
  92. package/dist/solution/UnifiedBookingSales/types.d.ts +71 -2
  93. package/dist/solution/UnifiedBookingSales/types.js +7 -1
  94. package/dist/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
  95. package/dist/solution/UnifiedBookingSales/venueCatalogSession.js +283 -0
  96. package/dist/utils/platform.d.ts +2 -0
  97. package/dist/utils/platform.js +6 -0
  98. package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
  99. package/dist/utils/pos-receipt-auto-print.js +14 -0
  100. package/lib/index.d.ts +1 -0
  101. package/lib/index.js +12 -0
  102. package/lib/inventory/index.d.ts +92 -0
  103. package/lib/inventory/index.js +287 -0
  104. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  105. package/lib/modules/BookingContext/index.d.ts +2 -2
  106. package/lib/modules/BookingContext/index.js +42 -10
  107. package/lib/modules/BookingContext/types.d.ts +2 -0
  108. package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  109. package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
  110. package/lib/modules/BookingContext/utils/index.d.ts +1 -0
  111. package/lib/modules/BookingContext/utils/index.js +11 -0
  112. package/lib/modules/BookingContext/utils/productExtend.d.ts +20 -1
  113. package/lib/modules/BookingContext/utils/productExtend.js +96 -7
  114. package/lib/modules/Date/index.d.ts +1 -1
  115. package/lib/modules/Date/index.js +28 -5
  116. package/lib/modules/Date/types.d.ts +5 -0
  117. package/lib/modules/Discount/index.js +1 -0
  118. package/lib/modules/OpenData/index.d.ts +1 -0
  119. package/lib/modules/OpenData/index.js +12 -0
  120. package/lib/modules/OpenData/salesSettings.d.ts +32 -0
  121. package/lib/modules/OpenData/salesSettings.js +70 -0
  122. package/lib/modules/OpenData/types.d.ts +16 -0
  123. package/lib/modules/OpenData/utils.d.ts +1 -1
  124. package/lib/modules/OpenData/utils.js +3 -2
  125. package/lib/modules/Order/index.d.ts +55 -12
  126. package/lib/modules/Order/index.js +659 -80
  127. package/lib/modules/Order/types.d.ts +43 -5
  128. package/lib/modules/Order/types.js +2 -0
  129. package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
  130. package/lib/modules/Order/unpaidAmountGap.js +60 -0
  131. package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
  132. package/lib/modules/Order/utils/productVoucherGroups.d.ts +15 -0
  133. package/lib/modules/Order/utils/productVoucherGroups.js +64 -0
  134. package/lib/modules/Order/utils.d.ts +3 -1
  135. package/lib/modules/Order/utils.js +6 -2
  136. package/lib/modules/Product/index.d.ts +1 -1
  137. package/lib/modules/ProductList/clientDataVariants.js +6 -2
  138. package/lib/modules/ProductList/index.d.ts +2 -0
  139. package/lib/modules/ProductList/index.js +74 -0
  140. package/lib/modules/ResourcePlanner/planner.js +52 -1
  141. package/lib/modules/ResourcePlanner/types.d.ts +13 -0
  142. package/lib/modules/Rules/index.d.ts +2 -0
  143. package/lib/modules/Rules/index.js +25 -9
  144. package/lib/modules/Schedule/index.d.ts +7 -1
  145. package/lib/modules/Schedule/index.js +68 -4
  146. package/lib/modules/Schedule/types.d.ts +2 -0
  147. package/lib/modules/bookingReadValidation.d.ts +6 -0
  148. package/lib/modules/bookingReadValidation.js +56 -0
  149. package/lib/plugins/request.d.ts +2 -0
  150. package/lib/server/index.d.ts +8 -0
  151. package/lib/server/index.js +194 -19
  152. package/lib/server/modules/order/index.js +2 -1
  153. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  154. package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
  155. package/lib/shared/receipt/small-ticket.d.ts +4 -0
  156. package/lib/shared/receipt/small-ticket.js +63 -8
  157. package/lib/solution/BaseSales/index.d.ts +39 -5
  158. package/lib/solution/BaseSales/index.js +212 -18
  159. package/lib/solution/BaseSales/types.d.ts +1 -0
  160. package/lib/solution/BaseSales/types.js +1 -0
  161. package/lib/solution/BookingByStep/index.d.ts +16 -2
  162. package/lib/solution/BookingByStep/index.js +222 -14
  163. package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
  164. package/lib/solution/BookingByStep/utils/resources.js +25 -15
  165. package/lib/solution/BookingTicket/index.d.ts +15 -3
  166. package/lib/solution/BookingTicket/index.js +47 -4
  167. package/lib/solution/BookingTicket/types.d.ts +14 -2
  168. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +3 -1
  169. package/lib/solution/BookingTicket/utils/addProductDecision.js +37 -6
  170. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  171. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
  172. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
  173. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +54 -0
  174. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
  175. package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -1
  176. package/lib/solution/OrderInvoicePreview/index.js +7 -1
  177. package/lib/solution/ScanOrder/index.d.ts +2 -0
  178. package/lib/solution/ScanOrder/index.js +72 -2
  179. package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
  180. package/lib/solution/ScanOrder/menuAvailability.js +203 -0
  181. package/lib/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
  182. package/lib/solution/UnifiedBookingSales/catalogQueryBatch.js +109 -0
  183. package/lib/solution/UnifiedBookingSales/index.d.ts +96 -4
  184. package/lib/solution/UnifiedBookingSales/index.js +1316 -73
  185. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
  186. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +2 -0
  187. package/lib/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
  188. package/lib/solution/UnifiedBookingSales/salesSettings.js +72 -0
  189. package/lib/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
  190. package/lib/solution/UnifiedBookingSales/sessionResourceCache.js +199 -0
  191. package/lib/solution/UnifiedBookingSales/types.d.ts +71 -2
  192. package/lib/solution/UnifiedBookingSales/types.js +4 -1
  193. package/lib/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
  194. package/lib/solution/UnifiedBookingSales/venueCatalogSession.js +155 -0
  195. package/lib/utils/platform.d.ts +2 -0
  196. package/lib/utils/platform.js +7 -0
  197. package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
  198. package/lib/utils/pos-receipt-auto-print.js +13 -0
  199. package/package.json +1 -1
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ScanOrderMenuAvailabilityError = void 0;
7
+ exports.prepareScanOrderMenuAvailability = prepareScanOrderMenuAvailability;
8
+ var _utils = require("../ShopDiscount/utils");
9
+ var _dayjs = _interopRequireDefault(require("dayjs"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ class ScanOrderMenuAvailabilityError extends Error {
12
+ code;
13
+ productIds;
14
+ constructor(code, productIds = []) {
15
+ super(code);
16
+ this.name = 'ScanOrderMenuAvailabilityError';
17
+ this.code = code;
18
+ this.productIds = [...new Set(productIds)];
19
+ }
20
+ }
21
+ exports.ScanOrderMenuAvailabilityError = ScanOrderMenuAvailabilityError;
22
+ const positiveId = value => {
23
+ const id = Number(value);
24
+ return Number.isInteger(id) && id > 0 ? id : undefined;
25
+ };
26
+ const productId = product => positiveId(product?.product_id ?? product?.id);
27
+ const fail = (ids = []) => {
28
+ throw new ScanOrderMenuAvailabilityError('SCAN_ORDER_MENU_VALIDATION_FAILED', ids);
29
+ };
30
+ function readList(response) {
31
+ if (!response || response.code !== undefined && Number(response.code) !== 200 || response.status === false || typeof response.status === 'number' && response.status >= 400 || response.success === false || !Array.isArray(response.data?.list)) fail();
32
+ return response.data.list;
33
+ }
34
+ function readIds(values) {
35
+ if (!Array.isArray(values)) return fail();
36
+ const ids = values.map(positiveId);
37
+ if (ids.some(id => id === undefined)) return fail();
38
+ return [...new Set(ids)];
39
+ }
40
+ function readMenu(record) {
41
+ const scope = record.partyroom_package?.type;
42
+ if (!['product_all', 'products', 'product_collection'].includes(scope)) return fail();
43
+ const items = record.partyroom_package?.products;
44
+ if (scope !== 'product_all' && !Array.isArray(items)) return fail();
45
+ return {
46
+ id: positiveId(record.form_record_id),
47
+ scheduleIds: readIds(record.schedule),
48
+ scope,
49
+ productIds: scope === 'products' ? readIds(items.map(item => item.product_id)) : [],
50
+ collectionIds: scope === 'product_collection' ? readIds(items.map(item => item.product_collection_id)) : []
51
+ };
52
+ }
53
+ function validateSchedule(schedule) {
54
+ const validDate = value => typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value) && (0, _dayjs.default)(value).isValid() && (0, _dayjs.default)(value).format('YYYY-MM-DD') === value;
55
+ const validDateTime = value => typeof value === 'string' && /^\d{4}-\d{2}-\d{2}(?:[ T](?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?)?$/.test(value) && validDate(value.slice(0, 10)) && (0, _dayjs.default)(value).isValid();
56
+ const validTime = value => typeof value === 'string' && /^(?:(?:[01]\d|2[0-3]):[0-5]\d|24:00)$/.test(value);
57
+ if (!schedule || !['standard', 'time-slots', 'designation'].includes(schedule.type)) return fail();
58
+ if (schedule.type === 'designation') {
59
+ if (!Array.isArray(schedule.designation) || schedule.designation.some(item => !validDate(item?.start_date) || !validDate(item?.end_date) || !validTime(item?.start_time) || !validTime(item?.end_time))) return fail();
60
+ return;
61
+ }
62
+ if (!validDateTime(schedule.start_time)) return fail();
63
+ if (schedule.type === 'standard' && !validDateTime(schedule.end_time)) return fail();
64
+ if (schedule.type === 'time-slots' && (!Array.isArray(schedule.time_slot) || schedule.time_slot.some(slot => !validTime(slot?.start_time) || !validTime(slot?.end_time)))) return fail();
65
+ if (schedule.repeat_type === 'none') return;
66
+ if (!['daily', 'weekly'].includes(schedule.repeat_type)) return fail();
67
+ const rule = schedule.repeat_rule;
68
+ if (!rule || !positiveId(rule.frequency) || !['never', 'date', 'occurrence'].includes(rule.end?.type) || rule.end.type === 'date' && !validDateTime(rule.end.end_date)) return fail();
69
+ for (const ranges of [rule.excluded_date, rule.included_date ?? []]) {
70
+ if (!Array.isArray(ranges) || ranges.some(range => !validDateTime(range?.start) || !validDateTime(range?.end))) return fail();
71
+ }
72
+ if (schedule.repeat_type === 'weekly' && (!Array.isArray(rule.frequency_date) || rule.frequency_date.some(day => typeof day !== 'number' || !Number.isInteger(day) || day < 0 || day > 6))) return fail();
73
+ }
74
+ function createShopClock(timezone) {
75
+ if (typeof timezone !== 'string' || !timezone.trim()) return fail();
76
+ const formatter = new Intl.DateTimeFormat('en-GB', {
77
+ timeZone: timezone.trim(),
78
+ year: 'numeric',
79
+ month: '2-digit',
80
+ day: '2-digit',
81
+ hour: '2-digit',
82
+ minute: '2-digit',
83
+ second: '2-digit',
84
+ hourCycle: 'h23'
85
+ });
86
+ return () => {
87
+ const parts = formatter.formatToParts(new Date());
88
+ const value = type => parts.find(part => part.type === type)?.value;
89
+ return `${value('year')}-${value('month')}-${value('day')} ${value('hour')}:${value('minute')}:${value('second')}`;
90
+ };
91
+ }
92
+ function collectSources(target, sources) {
93
+ for (const source of sources) {
94
+ const id = productId(source);
95
+ if (!id || !Array.isArray(source?.collection)) continue;
96
+ const ids = source.collection.map(item => positiveId(item?.id));
97
+ if (ids.every(value => value !== undefined)) {
98
+ target.set(id, [...new Set(ids)]);
99
+ }
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Prepare fresh menu definitions without changing ProductList or the cart. The
105
+ * returned validator reads the shop's current time again at the submission boundary.
106
+ */
107
+ async function prepareScanOrderMenuAvailability({
108
+ request,
109
+ menuIds,
110
+ timezone,
111
+ products,
112
+ productSources = []
113
+ }) {
114
+ const initialIds = products.map(productId).filter(id => id !== undefined);
115
+ try {
116
+ const now = createShopClock(timezone);
117
+ const configuredIds = readIds(menuIds);
118
+ const [menuResponse, scheduleResponse] = await Promise.all([request.get('/form/data/v1', {
119
+ skip: 1,
120
+ num: 999,
121
+ code: 'menu_list'
122
+ }, {
123
+ useCache: false
124
+ }), request.get('/schedule', {
125
+ num: 999
126
+ }, {
127
+ useCache: false
128
+ })]);
129
+ const menuRecords = readList(menuResponse);
130
+ const scheduleRecords = readList(scheduleResponse);
131
+ const menuById = new Map(menuRecords.map(menu => [positiveId(menu.form_record_id), menu]));
132
+ const menus = configuredIds.map(id => {
133
+ const record = menuById.get(id);
134
+ return record ? readMenu(record) : fail();
135
+ });
136
+ const scheduleById = new Map(scheduleRecords.map(schedule => [positiveId(schedule.id), schedule]));
137
+ // Only configured menus and their schedules are required. Other pages in a
138
+ // larger catalog cannot affect this business's menu availability.
139
+ const referencedScheduleIds = menus.reduce((ids, menu) => ids.concat(menu.scheduleIds), []);
140
+ for (const id of new Set(referencedScheduleIds)) {
141
+ validateSchedule(scheduleById.get(id));
142
+ }
143
+ const hasCollectionMenu = menus.some(menu => menu.scope === 'product_collection');
144
+ const collectionsByProduct = new Map();
145
+ collectSources(collectionsByProduct, [...products, ...productSources]);
146
+ if (hasCollectionMenu) {
147
+ const missingIds = [...new Set(initialIds.filter(id => !collectionsByProduct.has(id)))];
148
+ if (missingIds.length) {
149
+ const response = await request.post('/product/query', {
150
+ ids: missingIds,
151
+ with: ['collection'],
152
+ open_quotation: 0,
153
+ open_bundle: 0,
154
+ skip: 1,
155
+ num: missingIds.length
156
+ }, {
157
+ useCache: false
158
+ });
159
+ collectSources(collectionsByProduct, readList(response));
160
+ const unresolved = missingIds.filter(id => !collectionsByProduct.has(id));
161
+ if (unresolved.length) fail(unresolved);
162
+ }
163
+ }
164
+ return (currentProducts, currentSources = []) => {
165
+ try {
166
+ const currentTime = now();
167
+ const collections = new Map(collectionsByProduct);
168
+ collectSources(collections, [...currentProducts, ...currentSources]);
169
+ const unavailable = [];
170
+ const insufficient = [];
171
+ for (const product of currentProducts) {
172
+ const id = productId(product);
173
+ if (!id) return fail();
174
+ const matchesDirectly = menu => menu.scope === 'product_all' || menu.scope === 'products' && menu.productIds.includes(id);
175
+ const isAvailable = menu => (0, _utils.getDateIsInSchedule)(currentTime, menu.scheduleIds.map(scheduleId => scheduleById.get(scheduleId)));
176
+ // A known valid direct relation is sufficient regardless of missing
177
+ // collection data on a rule product appended after preparation.
178
+ if (menus.some(menu => matchesDirectly(menu) && isAvailable(menu))) continue;
179
+ if (hasCollectionMenu && !collections.has(id)) {
180
+ insufficient.push(id);
181
+ continue;
182
+ }
183
+ const productCollections = collections.get(id) || [];
184
+ const associated = menus.filter(menu => matchesDirectly(menu) || menu.scope === 'product_collection' && menu.collectionIds.some(collectionId => productCollections.includes(collectionId)));
185
+ if (associated.some(isAvailable)) continue;
186
+ const systemItem = product.metadata?.item_rule_prefill === true || product.metadata?.is_rule === true;
187
+ if (associated.length === 0 && systemItem) continue;
188
+ unavailable.push(id);
189
+ }
190
+ if (insufficient.length) fail(insufficient);
191
+ if (unavailable.length) {
192
+ throw new ScanOrderMenuAvailabilityError('SCAN_ORDER_MENU_UNAVAILABLE', unavailable);
193
+ }
194
+ } catch (error) {
195
+ if (error instanceof ScanOrderMenuAvailabilityError) throw error;
196
+ return fail(currentProducts.map(productId).filter(id => id !== undefined));
197
+ }
198
+ };
199
+ } catch (error) {
200
+ if (error instanceof ScanOrderMenuAvailabilityError) throw error;
201
+ return fail(initialIds);
202
+ }
203
+ }
@@ -0,0 +1,21 @@
1
+ import type { ProductListLoadProductsParams } from '../../modules/ProductList';
2
+ import type { ProductData } from '../../modules/Product/types';
3
+ import type { UnifiedBookingSalesCatalogQueryBatch } from './types';
4
+ type DetailParams = ProductListLoadProductsParams & {
5
+ product_id: number;
6
+ };
7
+ export interface CatalogQueryRuntime {
8
+ references: unknown[];
9
+ values: unknown;
10
+ /** Late-loaded pricing/schedule data may refresh within the same owner. */
11
+ refreshValues?: unknown;
12
+ }
13
+ /** Internal adapter: membership loaders are never accepted from public callers. */
14
+ export declare function createCatalogQueryBatchAdapter(options: {
15
+ runtime(): CatalogQueryRuntime;
16
+ normalize(params: ProductListLoadProductsParams, now: number): ProductListLoadProductsParams;
17
+ key(params: ProductListLoadProductsParams): string;
18
+ snapshot(params: ProductListLoadProductsParams): Promise<ProductData[]>;
19
+ detail(params: DetailParams, snapshot: UnifiedBookingSalesCatalogQueryBatch['queryCatalogSnapshot']): Promise<ProductData | undefined>;
20
+ }): UnifiedBookingSalesCatalogQueryBatch;
21
+ export {};
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createCatalogQueryBatchAdapter = createCatalogQueryBatchAdapter;
7
+ var _lodashEs = require("lodash-es");
8
+ const BATCH_MAX_AGE_MS = 60 * 1000;
9
+ // Enough for a 42-day calendar with several product details per day, but bounded.
10
+ const BATCH_MAX_ENTRIES = 512;
11
+
12
+ /** Internal adapter: membership loaders are never accepted from public callers. */
13
+ function createCatalogQueryBatchAdapter(options) {
14
+ let disposed = false;
15
+ let epoch;
16
+ const sameOwner = (left, right) => left.references.length === right.references.length && left.references.every((ref, index) => ref === right.references[index]) && (0, _lodashEs.isEqual)(left.values, right.values);
17
+ const fail = code => Object.assign(new Error(code === 'CATALOG_QUERY_BATCH_DISPOSED' ? 'The catalog query batch is closed. Create a new batch before querying.' : 'The catalog context changed while loading. Please retry.'), {
18
+ code
19
+ });
20
+ const current = () => {
21
+ if (disposed) throw fail('CATALOG_QUERY_BATCH_DISPOSED');
22
+ const now = Date.now();
23
+ const runtime = options.runtime();
24
+ if (!epoch || now < epoch.startedAt || now - epoch.startedAt >= BATCH_MAX_AGE_MS || !sameOwner(runtime, epoch.runtime) || !(0, _lodashEs.isEqual)(runtime.refreshValues, epoch.runtime.refreshValues)) {
25
+ epoch?.entries.clear();
26
+ epoch = {
27
+ runtime: {
28
+ references: [...runtime.references],
29
+ values: (0, _lodashEs.cloneDeep)(runtime.values),
30
+ refreshValues: (0, _lodashEs.cloneDeep)(runtime.refreshValues)
31
+ },
32
+ startedAt: now,
33
+ entries: new Map()
34
+ };
35
+ }
36
+ return epoch;
37
+ };
38
+ const assertEpoch = owner => {
39
+ const next = current();
40
+ if (next !== owner) throw Object.assign(fail('CATALOG_QUERY_BATCH_STALE'), {
41
+ retryable: sameOwner(owner.runtime, next.runtime)
42
+ });
43
+ };
44
+ const run = async load => {
45
+ for (let attempt = 0;; attempt++) {
46
+ try {
47
+ return await load(current());
48
+ } catch (error) {
49
+ const failure = error;
50
+ // Drop the old result and reread under the new configuration. Never replay
51
+ // a network error, disposed batch or a request belonging to a different user/store.
52
+ if (attempt >= 2 || failure?.code !== 'CATALOG_QUERY_BATCH_STALE' || !failure.retryable) throw error;
53
+ }
54
+ }
55
+ };
56
+ const read = async (owner, key, load) => {
57
+ assertEpoch(owner);
58
+ let promise = owner.entries.get(key);
59
+ if (promise) {
60
+ owner.entries.delete(key);
61
+ owner.entries.set(key, promise);
62
+ } else {
63
+ promise = Promise.resolve().then(() => {
64
+ assertEpoch(owner);
65
+ return load();
66
+ }).then(value => (0, _lodashEs.cloneDeep)(value));
67
+ owner.entries.set(key, promise);
68
+ while (owner.entries.size > BATCH_MAX_ENTRIES) owner.entries.delete(owner.entries.keys().next().value);
69
+ }
70
+ try {
71
+ const result = await promise;
72
+ assertEpoch(owner);
73
+ return (0, _lodashEs.cloneDeep)(result);
74
+ } catch (error) {
75
+ if (owner.entries.get(key) === promise) owner.entries.delete(key);
76
+ throw error;
77
+ }
78
+ };
79
+ const snapshotFor = async (owner, input) => {
80
+ assertEpoch(owner);
81
+ const {
82
+ product_ids,
83
+ ...scope
84
+ } = options.normalize((0, _lodashEs.cloneDeep)(input), owner.startedAt);
85
+ // The membership scope is always the whole menu; ID filtering is only a detached view.
86
+ const products = await read(owner, `list:${options.key(scope)}`, () => options.snapshot(scope));
87
+ return product_ids?.length ? products.filter(product => product_ids.some(id => Number(id) === Number(product.id))) : products;
88
+ };
89
+ return {
90
+ queryCatalogSnapshot: params => run(owner => snapshotFor(owner, params)),
91
+ queryCatalogProductDetail: input => run(owner => {
92
+ const {
93
+ product_id,
94
+ product_ids: _ignored,
95
+ ...scope
96
+ } = (0, _lodashEs.cloneDeep)(input);
97
+ const params = {
98
+ ...options.normalize(scope, owner.startedAt),
99
+ product_id
100
+ };
101
+ return read(owner, `detail:${options.key(params)}`, () => options.detail(params, query => snapshotFor(owner, query)));
102
+ }),
103
+ dispose: () => {
104
+ disposed = true;
105
+ epoch?.entries.clear();
106
+ epoch = undefined;
107
+ }
108
+ };
109
+ }
@@ -1,14 +1,19 @@
1
1
  import type { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import type { ProductData } from '../../modules';
3
- import { type InvoiceLayoutConfig, type InvoiceTemplateSettings, type OpenDataConfig } from '../../modules/OpenData';
3
+ import type { BookingCalcContext } from '../../modules/BookingContext';
4
+ import type { AddProductDecideContext } from '../BookingTicket/utils/addProductDecision';
5
+ import { type InvoiceLayoutConfig, type InvoiceTemplateSettings, type OpenDataConfig, type ResolvedSalesSettings } from '../../modules/OpenData';
4
6
  import type { LoadScheduleAvailableDateParams, ScheduleItem } from '../../modules/Schedule/types';
5
7
  import type { ProductListLoadProductsParams, ProductListStoreQueryParams } from '../../modules/ProductList';
6
- import type { AvailabilityDateRange, AvailabilityOccupancy, AvailabilityProduct, AvailabilityResource, GetProductTimeRangesRequest } from '../../modules/ResourcePlanner';
7
- import type { AvailabilityContextRef, ContextualAvailabilityQuery, ContextualAvailabilityQueryResult, ContextualCommitAvailabilitySelectionParams, ContextualProductTimeRangeGroup, UnifiedBookingSalesAddRetailProductParams, UnifiedBookingSalesApplyPlannerDiscountsParams, UnifiedBookingSalesCommitAvailabilitySelectionResult, UnifiedBookingSalesDiscountResult, UnifiedBookingSalesLoadProductsByScheduleDateParams, UnifiedBookingSalesLoadOpenDataParams, UnifiedBookingSalesPrepareAvailabilityProjectionParams, UnifiedBookingSalesPolicyResponse, UnifiedBookingSalesResolveProductAllergyRequirementParams, UnifiedBookingSalesStageRetailProductsParams, UnifiedBookingSalesState } from './types';
8
+ import type { AvailabilityDateRange, AvailabilityOccupancy, AvailabilityProduct, AvailabilityRequirementSelection, AvailabilityResource, GetProductTimeRangesRequest } from '../../modules/ResourcePlanner';
9
+ import type { AvailabilityContextRef, ContextualAvailabilityQuery, ContextualAvailabilityQueryResult, ContextualCommitAvailabilitySelectionParams, ContextualProductTimeRange, ContextualProductTimeRangeGroup, UnifiedBookingSalesAddRetailProductParams, UnifiedBookingSalesCatalogQueryBatch, UnifiedBookingSalesVenueCatalogSession, UnifiedBookingSalesVenueCatalogSessionParams, UnifiedBookingSalesApplyPlannerDiscountsParams, UnifiedBookingSalesCommitAvailabilitySelectionResult, UnifiedBookingSalesDiscountResult, UnifiedBookingSalesLoadProductsByScheduleDateParams, UnifiedBookingSalesLoadOpenDataParams, UnifiedBookingSalesPrepareAvailabilityProjectionParams, UnifiedBookingSalesPolicyResponse, UnifiedBookingSalesQueryBookingResourceDetailsParams, UnifiedBookingSalesResourceDetail, UnifiedBookingSalesResolveProductAllergyRequirementParams, UnifiedBookingSalesStageRetailProductsParams, UnifiedBookingSalesState } from './types';
8
10
  import type { BusinessAvailability } from '../../modules/BusinessAvailability';
9
11
  import { BookingTicket } from '../BookingTicket';
12
+ import type { BaseSalesSubmitSalesOrderParams } from '../BaseSales/types';
13
+ import { type PosReceiptAutoPrintPaymentStatus } from '../../utils/pos-receipt-auto-print';
10
14
  import type { AllergyRequirement } from '../../model/strategy/adapter/itemRule';
11
15
  export * from './types';
16
+ export * from './salesSettings';
12
17
  export type { BusinessAvailability, BusinessClosedBehavior } from '../../modules/BusinessAvailability';
13
18
  export { AvailabilityError } from '../../modules/ResourcePlanner';
14
19
  /**
@@ -68,8 +73,13 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
68
73
  private runtimeOpenDataModule;
69
74
  private runtimeOpenDataCore;
70
75
  private runtimeOpenDataGeneration;
76
+ private runtimeInitializationGeneration;
71
77
  private runtimeOpenDataDestroyed;
72
78
  private unifiedProductCatalog;
79
+ private venueCatalogSessions;
80
+ private venueCatalogSessionKey?;
81
+ private venueCatalogMenus?;
82
+ private venueVariantDetails;
73
83
  private availabilityRuntimeOffsetMinutes;
74
84
  private availabilityScheduleCatalog;
75
85
  private availabilityProjectionSequence;
@@ -80,6 +90,7 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
80
90
  private availabilityPrepareInFlight;
81
91
  private availabilityProjectionRefreshInFlight;
82
92
  private availabilityRemoteOccupancyCache;
93
+ private availabilitySessionResourceCache;
83
94
  private availabilityRemoteResourceQueryInFlight;
84
95
  private availabilityRemoteResourceQuerySequence;
85
96
  private availabilityRemoteResourceEpoch;
@@ -111,6 +122,18 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
111
122
  * 仅供直加调用;手动时间选择和 availability candidate 不经过此方法。
112
123
  */
113
124
  prepareDirectAddFlexibleBooking(cacheItem: any): Promise<any>;
125
+ /** Reuse an approved calendar cache; only the final commit may mutate the order. */
126
+ prepareDirectAddCalendarBooking(cacheItem: any, options?: {
127
+ bookingCount?: number;
128
+ availabilityCommitGuard?: () => void;
129
+ }): Promise<{
130
+ cacheItem: any;
131
+ contextId: string;
132
+ candidate: ContextualProductTimeRange;
133
+ requirementSelections: AvailabilityRequirementSelection[];
134
+ partySize: number;
135
+ bookingCount: number;
136
+ } | null>;
114
137
  private resolveAvailabilityPrepareDefaults;
115
138
  private buildAvailabilityPrepareKey;
116
139
  private clearAvailabilityRemoteResourceState;
@@ -127,6 +150,9 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
127
150
  private cloneAvailabilityPrepareParams;
128
151
  private getAvailabilityDurationCandidateAnchorAt;
129
152
  private createAvailabilityContextRef;
153
+ /** Accept the v2 interval only within the POS order that recorded it. */
154
+ private resolveOrderRememberedTimes;
155
+ private assertRememberedOrderSession;
130
156
  private emitAvailabilityDiagnostic;
131
157
  private touchAvailabilityContext;
132
158
  private touchAvailabilityProjection;
@@ -156,7 +182,7 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
156
182
  /** 在 Kiosk 拉起支付设备前补齐订单号,同一订单重试复用已分配的号码。 */
157
183
  ensureLocalOrderNumbersForCheckout(): Promise<void>;
158
184
  /**
159
- * PC/H5/Kiosk 结账默认直接等待云端 checkout;POS/WebPOS 仍保持本地待同步。
185
+ * PC/H5 及自助终端结账默认直接等待云端 checkout;POS/WebPOS 仍保持本地待同步。
160
186
  * 显式传 checkoutSyncTaskEnabled: true 时仍可回退到本地同步模式。
161
187
  */
162
188
  protected shouldUseCheckoutSyncTask(): boolean;
@@ -178,9 +204,30 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
178
204
  /** A successful configuration belongs to this business runtime until an explicit refresh. */
179
205
  loadOpenData(params: UnifiedBookingSalesLoadOpenDataParams): Promise<OpenDataConfig>;
180
206
  getOpenData(): Promise<OpenDataConfig | null>;
207
+ /** One policy snapshot for all Sales 2.0 consumers. Network errors must reach the caller. */
208
+ getSalesSettings(): Promise<ResolvedSalesSettings>;
209
+ private getLoadedSalesSettings;
210
+ private getProductBookingsForScheduling;
211
+ private shouldApplyMultipleBookingScheduling;
212
+ private resolveLoadedDefaultBookingStart;
213
+ /** Used by the SKU flow after Holder changes, without changing an explicit user-selected time. */
214
+ resolveDefaultBookingStart(params: {
215
+ holderIds?: unknown;
216
+ fallback?: string;
217
+ }): Promise<string | undefined>;
218
+ protected buildBookingCalcContext(extra?: Partial<BookingCalcContext>): BookingCalcContext;
219
+ protected buildAddProductCtx(extra?: Partial<AddProductDecideContext>): AddProductDecideContext;
220
+ /** Re-evaluate an automatic default after Holder enrichment, or restore a known explicit TimeBar start. */
221
+ applyDefaultBookingStart(cacheItem: any, options?: {
222
+ holderIds?: unknown;
223
+ explicitStart?: string;
224
+ }): Promise<any>;
181
225
  protected loadPickupTimingOpenData(_force: boolean): Promise<Record<string, unknown>>;
182
226
  private resetAllergyItemRuleState;
183
227
  private fetchAllergyItemRuleConfigs;
228
+ /** Required products currently apply only to the online venue-ticket entry. */
229
+ validateRequiredProducts(): Promise<void>;
230
+ submitSalesOrder<T = any>(params?: BaseSalesSubmitSalesOrderParams): Promise<T>;
184
231
  private ensureAllergyItemRuleConfigsLoaded;
185
232
  /**
186
233
  * 评估当前渠道与商品是否命中 ALLERGY_CHECK。
@@ -190,6 +237,7 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
190
237
  clearOpenDataCache(): void;
191
238
  getInvoiceLayoutConfig(): Promise<InvoiceLayoutConfig>;
192
239
  getInvoiceTemplateSettings(): Promise<InvoiceTemplateSettings>;
240
+ protected getPosReceiptAutoPrintPaymentStatuses(): PosReceiptAutoPrintPaymentStatus[] | undefined;
193
241
  protected isInvoiceOpenDataCacheCurrent(): boolean;
194
242
  /**
195
243
  * Load a resource policy without depending on the legacy appointmentBooking solution.
@@ -203,6 +251,42 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
203
251
  callback?: (result: any) => void;
204
252
  subscriberId?: string;
205
253
  }): Promise<ProductData[]>;
254
+ /**
255
+ * Queries one explicitly configured menu scope without publishing the sales catalog.
256
+ * The returned graph is detached from ProductList's shared ID cache. Callers own its
257
+ * membership and must requery/reprice with the service datetime after a context change.
258
+ * Missing/invalid menu configuration fails closed instead of querying every product.
259
+ */
260
+ queryCatalogSnapshot(params: ProductListLoadProductsParams): Promise<ProductData[]>;
261
+ /** Full SKU/bundle detail, after verifying membership in the explicit day/menu scope. */
262
+ queryCatalogProductDetail(params: ProductListLoadProductsParams & {
263
+ product_id: number;
264
+ }): Promise<ProductData | undefined>;
265
+ protected isVenueCatalogLocalPricingActive(): boolean;
266
+ protected getVenueCatalogLocalPriceSource(productId: number, selectedProduct?: Record<string, any>): {
267
+ product: Record<string, any>;
268
+ menuList: Record<string, any>[];
269
+ } | undefined;
270
+ getProductByIds(ids: number[], options?: {
271
+ loadMissing?: boolean;
272
+ }): Promise<ProductData[]>;
273
+ private getVenueCatalogHydratedProduct;
274
+ /** Explicit user opening for legacy promotion/gift SKU hosts. Pure readers never call this. */
275
+ prepareVenueCatalogProductDetail(params: {
276
+ product_id: number;
277
+ retry?: boolean;
278
+ }): Promise<ProductData | undefined>;
279
+ private hydrateVenueVariantDetail;
280
+ /** One complete raw product query per explicitly configured pool for this page lifetime. */
281
+ createVenueCatalogSession(params: UnifiedBookingSalesVenueCatalogSessionParams): UnifiedBookingSalesVenueCatalogSession;
282
+ /**
283
+ * Opt-in calendar/card preview batching. Results expire after sixty seconds or a
284
+ * runtime change; the next read starts a fresh clock/cache. Selection and submit
285
+ * must keep using the ordinary fresh query methods. Call dispose on owner cleanup.
286
+ */
287
+ createCatalogQueryBatch(): UnifiedBookingSalesCatalogQueryBatch;
288
+ private loadCatalogProductDetail;
289
+ private loadCatalogProducts;
206
290
  queryProducts(params?: ProductListStoreQueryParams): Promise<ProductData[]>;
207
291
  /** Date-first entry point. It delegates protocol details and cache ownership to ScheduleModule. */
208
292
  loadScheduleAvailableDate(params: LoadScheduleAvailableDateParams): Promise<import("../../modules/Date/types").ITime[]>;
@@ -235,6 +319,10 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
235
319
  * Its staged lines have separate ownership so planner and retail skins can coexist safely.
236
320
  */
237
321
  stageRetailProducts(params: UnifiedBookingSalesStageRetailProductsParams): Promise<Record<string, any> | null>;
322
+ /** Explicit capability: order-scoped Tickets extras use guarded writes without implicit SKU merging. */
323
+ supportsVenueTicketExtras(): boolean;
324
+ /** The venue retail write path accepts per-line Holder relations for both templates. */
325
+ supportsVenueExtraHolders(): boolean;
238
326
  /**
239
327
  * Adds one retail line without replacing the cart's existing retail selection.
240
328
  * This is intentionally separate from stageRetailProducts(), whose contract is
@@ -254,6 +342,8 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
254
342
  * resource dates endpoint.
255
343
  */
256
344
  private fetchAvailabilityResourcesV2;
345
+ /** Fresh read-only metadata for confirmation forms/policies; does not create a projection or mutate BookingContext. */
346
+ queryBookingResourceDetails(params: UnifiedBookingSalesQueryBookingResourceDetailsParams): Promise<UnifiedBookingSalesResourceDetail[]>;
257
347
  private fetchAndPublishAvailabilityResourcesV2;
258
348
  private refreshAvailabilityRemoteResourceQuery;
259
349
  private loadAvailabilityResources;
@@ -280,6 +370,8 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
280
370
  getProductTimeRanges(contextId: string, request?: GetProductTimeRangesRequest): Promise<ContextualProductTimeRangeGroup[]>;
281
371
  /** Thin facade: auto-refresh on cart drift, then delegate to the pure projection query. */
282
372
  queryBookingAvailability(contextId: string, request: ContextualAvailabilityQuery): Promise<ContextualAvailabilityQueryResult>;
373
+ /** Reads detached resource metadata from the current context; never refreshes or performs I/O. */
374
+ getAvailabilityResources(contextId: string, expectedVersion?: number): AvailabilityResource[];
283
375
  releaseAvailabilityContext(contextId: string): void;
284
376
  private assertAvailabilityCommitWriteCAS;
285
377
  private findProductLineByUid;