@pisell/pisellos 2.3.129 → 2.3.130

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 (87) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +3 -1
  3. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  4. package/dist/modules/FulfillmentTiming/index.js +407 -0
  5. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  6. package/dist/modules/FulfillmentTiming/types.js +1 -0
  7. package/dist/modules/OpenData/types.d.ts +6 -0
  8. package/dist/modules/Order/index.d.ts +6 -0
  9. package/dist/modules/Order/index.js +55 -12
  10. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  11. package/dist/modules/Order/pickupTiming.js +53 -0
  12. package/dist/modules/Order/types.d.ts +5 -1
  13. package/dist/modules/Order/utils.js +16 -6
  14. package/dist/modules/Payment/index.js +9 -10
  15. package/dist/modules/Schedule/index.d.ts +8 -0
  16. package/dist/modules/Schedule/index.js +141 -39
  17. package/dist/modules/index.d.ts +1 -0
  18. package/dist/modules/index.js +1 -0
  19. package/dist/plugins/request.d.ts +7 -0
  20. package/dist/server/utils/small-ticket.d.ts +1 -85
  21. package/dist/server/utils/small-ticket.js +2 -2542
  22. package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
  23. package/dist/shared/payment/loadPaymentMethods.js +66 -0
  24. package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  25. package/dist/shared/receipt/loadCustomerInvoiceLayout.js +142 -0
  26. package/dist/shared/receipt/small-ticket.d.ts +85 -0
  27. package/dist/shared/receipt/small-ticket.js +2576 -0
  28. package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  29. package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
  30. package/dist/solution/BaseSales/index.d.ts +24 -0
  31. package/dist/solution/BaseSales/index.js +1221 -1038
  32. package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
  33. package/dist/solution/BaseSales/pickupTiming.js +589 -0
  34. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  35. package/dist/solution/BookingByStep/index.d.ts +1 -1
  36. package/dist/solution/BookingTicket/index.d.ts +3 -3
  37. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  38. package/dist/solution/OrderInvoicePreview/index.d.ts +56 -0
  39. package/dist/solution/OrderInvoicePreview/index.js +269 -0
  40. package/dist/solution/UnifiedBookingSales/index.d.ts +13 -4
  41. package/dist/solution/UnifiedBookingSales/index.js +872 -707
  42. package/dist/solution/index.d.ts +1 -0
  43. package/dist/solution/index.js +2 -1
  44. package/lib/index.d.ts +2 -0
  45. package/lib/index.js +21 -1
  46. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  47. package/lib/modules/FulfillmentTiming/index.js +359 -0
  48. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  49. package/lib/modules/FulfillmentTiming/types.js +5 -0
  50. package/lib/modules/OpenData/types.d.ts +6 -0
  51. package/lib/modules/Order/index.d.ts +6 -0
  52. package/lib/modules/Order/index.js +39 -8
  53. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  54. package/lib/modules/Order/pickupTiming.js +61 -0
  55. package/lib/modules/Order/types.d.ts +5 -1
  56. package/lib/modules/Order/utils.js +12 -4
  57. package/lib/modules/Payment/index.js +3 -4
  58. package/lib/modules/Schedule/index.d.ts +8 -0
  59. package/lib/modules/Schedule/index.js +68 -12
  60. package/lib/modules/index.d.ts +1 -0
  61. package/lib/modules/index.js +11 -0
  62. package/lib/plugins/request.d.ts +7 -0
  63. package/lib/server/utils/small-ticket.d.ts +1 -85
  64. package/lib/server/utils/small-ticket.js +9 -2305
  65. package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
  66. package/lib/shared/payment/loadPaymentMethods.js +40 -0
  67. package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  68. package/lib/shared/receipt/loadCustomerInvoiceLayout.js +86 -0
  69. package/lib/shared/receipt/small-ticket.d.ts +85 -0
  70. package/lib/shared/receipt/small-ticket.js +2342 -0
  71. package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  72. package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
  73. package/lib/solution/BaseSales/index.d.ts +24 -0
  74. package/lib/solution/BaseSales/index.js +97 -1
  75. package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
  76. package/lib/solution/BaseSales/pickupTiming.js +269 -0
  77. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  78. package/lib/solution/BookingByStep/index.d.ts +1 -1
  79. package/lib/solution/BookingTicket/index.d.ts +3 -3
  80. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  81. package/lib/solution/OrderInvoicePreview/index.d.ts +56 -0
  82. package/lib/solution/OrderInvoicePreview/index.js +192 -0
  83. package/lib/solution/UnifiedBookingSales/index.d.ts +13 -4
  84. package/lib/solution/UnifiedBookingSales/index.js +130 -46
  85. package/lib/solution/index.d.ts +1 -0
  86. package/lib/solution/index.js +11 -0
  87. package/package.json +1 -1
@@ -9,3 +9,4 @@ export * from './ScanOrder';
9
9
  export * from './BaseSales';
10
10
  export * from './VenueBooking';
11
11
  export * from './UnifiedBookingSales';
12
+ export * from './OrderInvoicePreview';
@@ -8,4 +8,5 @@ export * from "./Sales";
8
8
  export * from "./ScanOrder";
9
9
  export * from "./BaseSales";
10
10
  export * from "./VenueBooking";
11
- export * from "./UnifiedBookingSales";
11
+ export * from "./UnifiedBookingSales";
12
+ export * from "./OrderInvoicePreview";
package/lib/index.d.ts CHANGED
@@ -10,3 +10,5 @@ export * from './model';
10
10
  export { PisellOSCore } from './core';
11
11
  import PisellOSCore from './core';
12
12
  export default PisellOSCore;
13
+ export * from './shared/receipt/small-ticket';
14
+ export { loadSalesOrderSnapshot } from './shared/sales/loadSalesOrderSnapshot';
package/lib/index.js CHANGED
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
- PisellOSCore: true
7
+ PisellOSCore: true,
8
+ loadSalesOrderSnapshot: true
8
9
  };
9
10
  Object.defineProperty(exports, "PisellOSCore", {
10
11
  enumerable: true,
@@ -13,6 +14,12 @@ Object.defineProperty(exports, "PisellOSCore", {
13
14
  }
14
15
  });
15
16
  exports.default = void 0;
17
+ Object.defineProperty(exports, "loadSalesOrderSnapshot", {
18
+ enumerable: true,
19
+ get: function () {
20
+ return _loadSalesOrderSnapshot.loadSalesOrderSnapshot;
21
+ }
22
+ });
16
23
  var _types = require("./types");
17
24
  Object.keys(_types).forEach(function (key) {
18
25
  if (key === "default" || key === "__esModule") return;
@@ -74,6 +81,19 @@ Object.keys(_model).forEach(function (key) {
74
81
  });
75
82
  });
76
83
  var _core = _interopRequireWildcard(require("./core"));
84
+ var _smallTicket = require("./shared/receipt/small-ticket");
85
+ Object.keys(_smallTicket).forEach(function (key) {
86
+ if (key === "default" || key === "__esModule") return;
87
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
88
+ if (key in exports && exports[key] === _smallTicket[key]) return;
89
+ Object.defineProperty(exports, key, {
90
+ enumerable: true,
91
+ get: function () {
92
+ return _smallTicket[key];
93
+ }
94
+ });
95
+ });
96
+ var _loadSalesOrderSnapshot = require("./shared/sales/loadSalesOrderSnapshot");
77
97
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
78
98
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
79
99
  /**
@@ -0,0 +1,11 @@
1
+ import type { PickupTimingAvailability, PickupTimingBookingTimes, PickupTimingClockInput, PickupTimingComputeInput, PickupTimingConfig, PickupTimingSelection, PickupTimingSlot, PickupTimingValidationResult } from './types';
2
+ export * from './types';
3
+ /** Consume effective OpenData values only; legacy switches never enable Pickup. */
4
+ export declare function normalizePickupTimingConfig(openData: Record<string, unknown>): PickupTimingConfig;
5
+ export declare function resolvePickupTimingDateTime(date: string, time: string, timezone: string, instant?: string): PickupTimingSlot | undefined;
6
+ export declare function getAsapPickupTiming({ config, timezone, now }: PickupTimingClockInput): PickupTimingSlot;
7
+ export declare function pickupTimingSlotToBookingTimes(slot: PickupTimingSlot): PickupTimingBookingTimes;
8
+ export declare function computePickupTimingAvailability(input: PickupTimingComputeInput): PickupTimingAvailability;
9
+ export declare function validatePickupTimingSelection(selection: PickupTimingSelection, input: PickupTimingComputeInput & {
10
+ allowManualOverride?: boolean;
11
+ }): PickupTimingValidationResult;
@@ -0,0 +1,359 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ normalizePickupTimingConfig: true,
8
+ resolvePickupTimingDateTime: true,
9
+ getAsapPickupTiming: true,
10
+ pickupTimingSlotToBookingTimes: true,
11
+ computePickupTimingAvailability: true,
12
+ validatePickupTimingSelection: true
13
+ };
14
+ exports.computePickupTimingAvailability = computePickupTimingAvailability;
15
+ exports.getAsapPickupTiming = getAsapPickupTiming;
16
+ exports.normalizePickupTimingConfig = normalizePickupTimingConfig;
17
+ exports.pickupTimingSlotToBookingTimes = pickupTimingSlotToBookingTimes;
18
+ exports.resolvePickupTimingDateTime = resolvePickupTimingDateTime;
19
+ exports.validatePickupTimingSelection = validatePickupTimingSelection;
20
+ var _dayjs = _interopRequireDefault(require("dayjs"));
21
+ var _isSameOrAfter = _interopRequireDefault(require("dayjs/plugin/isSameOrAfter"));
22
+ var _isSameOrBefore = _interopRequireDefault(require("dayjs/plugin/isSameOrBefore"));
23
+ var _getDateIsInSchedule = require("../Schedule/getDateIsInSchedule");
24
+ var _types = require("./types");
25
+ Object.keys(_types).forEach(function (key) {
26
+ if (key === "default" || key === "__esModule") return;
27
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
28
+ if (key in exports && exports[key] === _types[key]) return;
29
+ Object.defineProperty(exports, key, {
30
+ enumerable: true,
31
+ get: function () {
32
+ return _types[key];
33
+ }
34
+ });
35
+ });
36
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
+ // The shared Schedule resolver uses these comparisons without registering them.
38
+ _dayjs.default.extend(_isSameOrAfter.default);
39
+ _dayjs.default.extend(_isSameOrBefore.default);
40
+ const MINUTE = 60_000;
41
+ const DAY = 24 * 60 * MINUTE;
42
+ const integerSetting = (value, min, max, fallback) => typeof value === 'number' && Number.isInteger(value) && value >= min && value <= max ? value : fallback;
43
+
44
+ /** Consume effective OpenData values only; legacy switches never enable Pickup. */
45
+ function normalizePickupTimingConfig(openData) {
46
+ const handovers = openData['fulfillment.handover_mode'];
47
+ const scheduleIds = openData['fulfillment.pickup.schedule'];
48
+ const operatingHoursScheduleIds = openData['availability.operating_hours'];
49
+ const mode = openData['fulfillment.pickup.timing_mode'];
50
+ return {
51
+ handoverModes: Array.isArray(handovers) ? [...new Set(handovers.filter(value => typeof value === 'string' && value.length > 0))] : [],
52
+ timingMode: mode === 'scheduled_only' || mode === 'asap_and_scheduled' ? mode : 'asap_only',
53
+ scheduleIds: Array.isArray(scheduleIds) ? [...new Set(scheduleIds.filter(value => typeof value === 'number' && Number.isInteger(value) && value > 0))] : [],
54
+ operatingHoursScheduleIds: Array.isArray(operatingHoursScheduleIds) ? [...new Set(operatingHoursScheduleIds.map(value => typeof value === 'number' || typeof value === 'string' ? Number(value) : NaN).filter(value => Number.isInteger(value) && value > 0))] : [],
55
+ slotIntervalMinutes: integerSetting(openData['fulfillment.pickup.slot_interval_minutes'], 1, 1440, 15),
56
+ preparationTimeMinutes: integerSetting(openData['fulfillment.pickup.preparation_time_minutes'], 0, 1440, 0),
57
+ advanceDays: integerSetting(openData['fulfillment.pickup.advance_days'], 0, 365, 7),
58
+ fulfillmentRefMode: typeof openData['fulfillment.fulfillment_ref_mode'] === 'string' ? openData['fulfillment.fulfillment_ref_mode'] : undefined,
59
+ manualInputType: typeof openData['fulfillment.manual_input_type'] === 'string' ? openData['fulfillment.manual_input_type'] : undefined
60
+ };
61
+ }
62
+ function dateStamp(date) {
63
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) return NaN;
64
+ const value = Date.parse(`${date}T00:00:00Z`);
65
+ return Number.isFinite(value) && new Date(value).toISOString().slice(0, 10) === date ? value : NaN;
66
+ }
67
+ function addDays(date, days) {
68
+ return new Date(dateStamp(date) + days * DAY).toISOString().slice(0, 10);
69
+ }
70
+ function timeMinutes(time, allowDayEnd = false) {
71
+ if (!/^\d{2}:\d{2}(?::00)?$/.test(time)) return NaN;
72
+ const [hours, minutes] = time.split(':').map(Number);
73
+ if (allowDayEnd && hours === 24 && minutes === 0) return 1440;
74
+ return hours < 24 && minutes < 60 ? hours * 60 + minutes : NaN;
75
+ }
76
+ function instantStamp(value) {
77
+ // A local string would silently use the device timezone instead of the store.
78
+ if (typeof value === 'string' && !/(Z|[+-]\d{2}:?\d{2})$/i.test(value)) return NaN;
79
+ return value instanceof Date ? value.getTime() : new Date(value).getTime();
80
+ }
81
+
82
+ /** Per-query timezone adapter; no device-offset arithmetic or global time cache. */
83
+ function createClock(timezone) {
84
+ if (!timezone || typeof timezone !== 'string') throw new Error('Store timezone is unavailable.');
85
+ let formatter;
86
+ try {
87
+ formatter = new Intl.DateTimeFormat('en-GB', {
88
+ timeZone: timezone,
89
+ year: 'numeric',
90
+ month: '2-digit',
91
+ day: '2-digit',
92
+ hour: '2-digit',
93
+ minute: '2-digit',
94
+ second: '2-digit',
95
+ hourCycle: 'h23'
96
+ });
97
+ } catch {
98
+ throw new Error('Store timezone is invalid.');
99
+ }
100
+ const offsetsByDate = new Map();
101
+ const local = timestamp => {
102
+ const parts = {};
103
+ formatter.formatToParts(timestamp).forEach(part => {
104
+ parts[part.type] = part.value;
105
+ });
106
+ return {
107
+ date: `${parts.year}-${parts.month}-${parts.day}`,
108
+ time: `${parts.hour}:${parts.minute}`,
109
+ second: parts.second
110
+ };
111
+ };
112
+ const offsets = date => {
113
+ const cached = offsetsByDate.get(date);
114
+ if (cached) return cached;
115
+ const result = new Set();
116
+ const nominal = dateStamp(date);
117
+ // Sampling both sides of the target day discovers pre/post-transition offsets.
118
+ for (let hours = -36; hours <= 36; hours += 6) {
119
+ const sample = nominal + hours * 60 * MINUTE;
120
+ const wall = local(sample);
121
+ result.add(Date.parse(`${wall.date}T${wall.time}:${wall.second}Z`) - sample);
122
+ }
123
+ const values = [...result];
124
+ offsetsByDate.set(date, values);
125
+ return values;
126
+ };
127
+ const resolve = (date, time) => {
128
+ const day = dateStamp(date);
129
+ const minutes = timeMinutes(time);
130
+ if (!Number.isFinite(day) || !Number.isFinite(minutes)) return [];
131
+ const label = time.slice(0, 5);
132
+ const nominal = day + minutes * MINUTE;
133
+ return offsets(date).map(offset => nominal - offset).filter(timestamp => {
134
+ const wall = local(timestamp);
135
+ return wall.date === date && wall.time === label;
136
+ }).sort((a, b) => a - b);
137
+ };
138
+ const slot = timestamp => {
139
+ const {
140
+ date,
141
+ time
142
+ } = local(timestamp);
143
+ const instant = new Date(timestamp).toISOString();
144
+ return {
145
+ id: instant,
146
+ date,
147
+ time,
148
+ instant
149
+ };
150
+ };
151
+ return {
152
+ local,
153
+ resolve,
154
+ slot,
155
+ hasOffsetTransition: date => offsets(date).length > 1
156
+ };
157
+ }
158
+ function resolvePickupTimingDateTime(date, time, timezone, instant) {
159
+ const clock = createClock(timezone);
160
+ const matches = clock.resolve(date, time);
161
+ const selected = instant ? instantStamp(instant) : matches.length === 1 ? matches[0] : NaN;
162
+ return matches.includes(selected) ? clock.slot(selected) : undefined;
163
+ }
164
+ function getAsapPickupTiming({
165
+ config,
166
+ timezone,
167
+ now
168
+ }) {
169
+ const timestamp = instantStamp(now);
170
+ if (!Number.isFinite(timestamp)) throw new Error('Current time is invalid.');
171
+ return createClock(timezone).slot(timestamp + config.preparationTimeMinutes * MINUTE);
172
+ }
173
+ function pickupTimingSlotToBookingTimes(slot) {
174
+ return {
175
+ start_date: slot.date,
176
+ start_time: slot.time,
177
+ end_date: slot.date,
178
+ end_time: slot.time
179
+ };
180
+ }
181
+ function createEvaluation(input) {
182
+ const {
183
+ config,
184
+ timezone
185
+ } = input;
186
+ const clock = createClock(timezone);
187
+ const now = instantStamp(input.now);
188
+ if (!Number.isFinite(now)) throw new Error('Current time is invalid.');
189
+ const today = clock.local(now).date;
190
+ const maxDate = addDays(today, config.advanceDays);
191
+ const earliest = now + config.preparationTimeMinutes * MINUTE;
192
+ const schedules = input.schedules.filter(schedule => config.scheduleIds.includes(schedule.id));
193
+ const windowCache = new Map();
194
+ const windows = date => {
195
+ if (!windowCache.has(date)) {
196
+ windowCache.set(date, (0, _getDateIsInSchedule.getScheduleStartEndTimePoints)(date, schedules));
197
+ }
198
+ return windowCache.get(date);
199
+ };
200
+ const operatingIds = config.operatingHoursScheduleIds || [];
201
+ const operatingSchedules = input.schedules.filter(schedule => operatingIds.includes(schedule.id));
202
+ const operatingWindowCache = new Map();
203
+ const operatingWindows = date => {
204
+ if (!operatingWindowCache.has(date)) {
205
+ const ranges = [];
206
+ for (const offset of [-1, 0]) {
207
+ for (const window of (0, _getDateIsInSchedule.getScheduleStartEndTimePoints)(addDays(date, offset), operatingSchedules)) {
208
+ const start = timeMinutes(window.start_time);
209
+ let end = timeMinutes(window.end_time, true);
210
+ if (!Number.isFinite(start) || !Number.isFinite(end)) continue;
211
+ // Store hours use equal endpoints for a full operating day, while
212
+ // the Pickup Schedule may deliberately contain a single time point.
213
+ if (end <= start) end += 1440;
214
+ ranges.push({
215
+ start: start + offset * 1440,
216
+ end: end + offset * 1440
217
+ });
218
+ }
219
+ }
220
+ operatingWindowCache.set(date, ranges);
221
+ }
222
+ return operatingWindowCache.get(date);
223
+ };
224
+ const slotsForDate = (date, firstOnly = false) => {
225
+ if (!Number.isFinite(dateStamp(date)) || date < today || date > maxDate || !config.handoverModes.includes('pick_up') || config.timingMode === 'asap_only') return [];
226
+ const found = new Map();
227
+ // Missing hours configuration preserves the existing all-day convention.
228
+ // Referenced but missing schedules yield no windows, never an all-day fallback.
229
+ const businessWindows = operatingIds.length ? operatingWindows(date) : undefined;
230
+ // Include the prior day's windows so overnight tails belong to their actual date.
231
+ for (const windowDate of [addDays(date, -1), date]) {
232
+ for (const window of windows(windowDate)) {
233
+ const start = timeMinutes(window.start_time);
234
+ let end = timeMinutes(window.end_time, true);
235
+ if (!Number.isFinite(start) || !Number.isFinite(end)) continue;
236
+ if (end < start) end += 1440;
237
+ let firstFoundInWindow = false;
238
+ for (let minute = start; minute <= end; minute += config.slotIntervalMinutes) {
239
+ const targetDate = minute >= 1440 ? addDays(windowDate, 1) : windowDate;
240
+ if (targetDate !== date) continue;
241
+ const localMinute = minute % 1440;
242
+ // Filter the original Pickup grid rather than moving its anchor to
243
+ // the store opening time. A zero-duration pickup may be at closing.
244
+ if (businessWindows && !businessWindows.some(({
245
+ start,
246
+ end
247
+ }) => localMinute >= start && localMinute <= end)) continue;
248
+ const time = `${String(Math.floor(localMinute / 60)).padStart(2, '0')}:${String(localMinute % 60).padStart(2, '0')}`;
249
+ for (const timestamp of clock.resolve(date, time)) {
250
+ if (timestamp < earliest) continue;
251
+ found.set(timestamp, clock.slot(timestamp));
252
+ firstFoundInWindow = true;
253
+ }
254
+ // Summary needs only an available candidate, not a full year's slots.
255
+ // During a repeated hour, an earlier wall label's second occurrence can
256
+ // be later than a subsequent label's first occurrence. Sort them all.
257
+ if (firstOnly && firstFoundInWindow && !clock.hasOffsetTransition(date)) break;
258
+ }
259
+ }
260
+ }
261
+ const result = [...found.entries()].sort(([a], [b]) => a - b).map(([, slot]) => slot);
262
+ return firstOnly ? result.slice(0, 1) : result;
263
+ };
264
+ return {
265
+ clock,
266
+ now,
267
+ today,
268
+ maxDate,
269
+ slotsForDate
270
+ };
271
+ }
272
+ function computePickupTimingAvailability(input) {
273
+ if (!input.config.handoverModes.includes('pick_up')) {
274
+ const now = instantStamp(input.now);
275
+ if (!Number.isFinite(now)) throw new Error('Current time is invalid.');
276
+ return {
277
+ config: input.config,
278
+ timezone: input.timezone,
279
+ now: new Date(now).toISOString(),
280
+ today: '',
281
+ maxDate: '',
282
+ date: input.date || '',
283
+ dates: [],
284
+ slots: []
285
+ };
286
+ }
287
+ const evaluation = createEvaluation(input);
288
+ const {
289
+ today,
290
+ maxDate,
291
+ slotsForDate
292
+ } = evaluation;
293
+ const date = input.date || today;
294
+ if (!Number.isFinite(dateStamp(date))) throw new Error('Pickup date is invalid.');
295
+ const slots = slotsForDate(date);
296
+ const dates = [];
297
+ let firstSlot;
298
+ for (let day = today; day <= maxDate; day = addDays(day, 1)) {
299
+ const first = day === date ? slots[0] : slotsForDate(day, true)[0];
300
+ dates.push({
301
+ date: day,
302
+ status: first ? 'available' : 'unavailable'
303
+ });
304
+ if (!firstSlot && first) firstSlot = first;
305
+ }
306
+ return {
307
+ config: input.config,
308
+ timezone: input.timezone,
309
+ now: new Date(evaluation.now).toISOString(),
310
+ today,
311
+ maxDate,
312
+ date,
313
+ dates,
314
+ slots,
315
+ firstSlot
316
+ };
317
+ }
318
+ function validatePickupTimingSelection(selection, input) {
319
+ const fail = (code, message) => ({
320
+ valid: false,
321
+ code,
322
+ message
323
+ });
324
+ const {
325
+ config
326
+ } = input;
327
+ if (config.handoverModes.length === 0) return {
328
+ valid: true
329
+ };
330
+ if (!config.handoverModes.includes(selection.serviceType)) {
331
+ return fail('handover_unavailable', 'Choose an available handover method.');
332
+ }
333
+ if (selection.serviceType !== 'pick_up') return {
334
+ valid: true
335
+ };
336
+ if (selection.mode === 'asap') {
337
+ return config.timingMode === 'scheduled_only' ? fail('scheduled_required', 'Choose a pickup date and time.') : {
338
+ valid: true,
339
+ slot: getAsapPickupTiming(input)
340
+ };
341
+ }
342
+ if (selection.mode !== 'scheduled' || config.timingMode === 'asap_only') {
343
+ return fail('mode_unavailable', 'The selected pickup timing mode is unavailable.');
344
+ }
345
+ const slot = resolvePickupTimingDateTime(selection.date || '', selection.time || '', input.timezone, selection.instant);
346
+ if (!slot) return fail('invalid_time', 'Choose a valid pickup date and time.');
347
+ const now = instantStamp(input.now);
348
+ if (!Number.isFinite(now)) throw new Error('Current time is invalid.');
349
+ if (instantStamp(slot.instant) < now) return fail('time_in_past', 'Pickup time cannot be in the past.');
350
+ if (selection.source === 'pos_manual' && input.allowManualOverride) return {
351
+ valid: true,
352
+ slot
353
+ };
354
+ const legal = createEvaluation(input).slotsForDate(slot.date).some(candidate => candidate.instant === slot.instant);
355
+ return legal ? {
356
+ valid: true,
357
+ slot
358
+ } : fail('time_unavailable', 'This pickup time is no longer available. Choose another time.');
359
+ }
@@ -0,0 +1,67 @@
1
+ import type { ScheduleItem } from '../Schedule/types';
2
+ export type PickupTimingMode = 'asap_only' | 'scheduled_only' | 'asap_and_scheduled';
3
+ export interface PickupTimingConfig {
4
+ handoverModes: string[];
5
+ timingMode: PickupTimingMode;
6
+ scheduleIds: number[];
7
+ /** Empty or absent means no additional store-hours restriction. */
8
+ operatingHoursScheduleIds?: number[];
9
+ slotIntervalMinutes: number;
10
+ preparationTimeMinutes: number;
11
+ advanceDays: number;
12
+ fulfillmentRefMode?: string;
13
+ manualInputType?: string;
14
+ }
15
+ export interface PickupTimingSelection {
16
+ serviceType: string;
17
+ mode: 'asap' | 'scheduled';
18
+ date?: string;
19
+ time?: string;
20
+ /** The absolute instant disambiguates a repeated local minute during DST. */
21
+ instant?: string;
22
+ source?: 'schedule' | 'pos_manual' | 'asap';
23
+ }
24
+ export interface PickupTimingSlot {
25
+ id: string;
26
+ date: string;
27
+ time: string;
28
+ instant: string;
29
+ }
30
+ export interface PickupTimingAvailability {
31
+ /** Config remains available when Schedule or store timezone cannot be loaded. */
32
+ error?: string;
33
+ config: PickupTimingConfig;
34
+ timezone: string;
35
+ now: string;
36
+ today: string;
37
+ maxDate: string;
38
+ date: string;
39
+ dates: Array<{
40
+ date: string;
41
+ status: 'available' | 'unavailable';
42
+ }>;
43
+ slots: PickupTimingSlot[];
44
+ /** Earliest legal candidate across all permitted dates, for POS prefill. */
45
+ firstSlot?: PickupTimingSlot;
46
+ }
47
+ export interface PickupTimingClockInput {
48
+ config: PickupTimingConfig;
49
+ timezone: string;
50
+ now: Date | string | number;
51
+ }
52
+ export interface PickupTimingComputeInput extends PickupTimingClockInput {
53
+ schedules: ScheduleItem[];
54
+ date?: string;
55
+ }
56
+ export interface PickupTimingValidationResult {
57
+ valid: boolean;
58
+ code?: string;
59
+ message?: string;
60
+ slot?: PickupTimingSlot;
61
+ }
62
+ export interface PickupTimingBookingTimes {
63
+ start_date: string;
64
+ start_time: string;
65
+ end_date: string;
66
+ end_time: string;
67
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -77,6 +77,12 @@ export interface OpenDataConfig {
77
77
  'sale.sale_number_prefix'?: string | null;
78
78
  'sale.enabled_item_rules'?: number[];
79
79
  'fulfillment.enable_pickup'?: boolean;
80
+ 'fulfillment.handover_mode'?: string[];
81
+ 'fulfillment.pickup.timing_mode'?: 'asap_only' | 'scheduled_only' | 'asap_and_scheduled';
82
+ 'fulfillment.pickup.schedule'?: number[];
83
+ 'fulfillment.pickup.advance_days'?: number;
84
+ 'fulfillment.pickup.slot_interval_minutes'?: number;
85
+ 'fulfillment.pickup.preparation_time_minutes'?: number;
80
86
  'fulfillment.overdue_reminder'?: boolean;
81
87
  'fulfillment.manual_input_type'?: string;
82
88
  'fulfillment.enable_auto_complete'?: boolean;
@@ -3,6 +3,7 @@ import { BaseModule } from '../BaseModule';
3
3
  import { OrderModuleAPI, CommitOrderParams, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, CancelOrderParams, ChangeBookingStatusParams, CheckoutOrderParams } from './types';
4
4
  import { CartItem } from '../Cart/types';
5
5
  import { type SubmitPayloadEnhancer } from './utils';
6
+ import { type PickupTimingBooking, type PickupTimingBookingInput } from './pickupTiming';
6
7
  import type { OrderAmountSnapshot, AddProductBookingInput, AddProductToOrderOptions, OrderIdentitySnapshot, OrderPaymentSource, OrderSnapshot, OrderSyncState, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, SubmitSalesOrderParams, OrderProduct, OrderProductIdentity, OrderSummary, OrderTempOrder, OrderPaymentData, OrderPaymentUpdateOptions, OrderPaymentUpdateResult, SendCustomerPayLinkParams, UpdateTempOrderCustomerInput, OrderCustomerPatch, OrderCustomerView, ReplaceTempOrderOptions, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions, RemoveProductsFromOrderOptions, SalesNote, SalesNotesMutationSnapshot, SetSalesNoteInput, PickupReferenceMode, PointCardSnapshotMergeContext, PointCardSnapshotItem, ShopServiceData, ShopServiceType } from './types';
7
8
  import type { ICustomer } from '../AccountList/types';
8
9
  import type { Discount } from '../Discount/types';
@@ -354,6 +355,9 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
354
355
  private updateTempOrderShopServiceData;
355
356
  updateTempOrderPickupReferenceMode(mode: PickupReferenceMode): ShopServiceData;
356
357
  updateTempOrderServiceType(serviceType: ShopServiceType): ShopServiceData;
358
+ getPickupTimingBooking(): PickupTimingBooking | null;
359
+ setPickupTimingBooking(input: PickupTimingBookingInput): PickupTimingBooking;
360
+ clearPickupTimingBooking(): void;
357
361
  updateTempOrderContactsInfo(contactsInfo: Record<string, any> | null): Record<string, any> | null;
358
362
  private buildTempOrderCustomer;
359
363
  private isCustomerBoundDiscount;
@@ -664,3 +668,5 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
664
668
  getVouchers(): any[];
665
669
  }
666
670
  export type { AddProductToOrderOptions, OrderMetaList, PointCardSnapshotItem, VirtualCurrencySnapshotItem, RemoveProductsFromOrderOptions, SalesNote, SalesNoteDraftInput, SalesNoteLocalizedSelection, SalesNoteLocalizedText, SalesNoteRelation, SalesNoteTextInput, SetSalesNoteInput, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, } from './types';
671
+ export { isFulfillmentTimingBooking } from './pickupTiming';
672
+ export type { PickupTimingBooking, PickupTimingBookingInput, PickupTimingBookingMetadata, PickupTimingSelectionMode, PickupTimingSource, } from './pickupTiming';
@@ -4,11 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.OrderModule = void 0;
7
+ Object.defineProperty(exports, "isFulfillmentTimingBooking", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _pickupTiming.isFulfillmentTimingBooking;
11
+ }
12
+ });
13
+ var _loadSalesOrderSnapshot = require("../../shared/sales/loadSalesOrderSnapshot");
7
14
  var _BaseModule = require("../BaseModule");
8
15
  var _types = require("./types");
9
16
  var _utils = require("./utils");
10
17
  var _utils2 = require("../Product/utils");
11
18
  var _weighedProduct = require("./utils/weighedProduct");
19
+ var _pickupTiming = require("./pickupTiming");
12
20
  var _dayjs = _interopRequireDefault(require("dayjs"));
13
21
  var _availability = require("../Discount/availability");
14
22
  var _osPrivatePayload = require("../../utils/os-private-payload");
@@ -2275,6 +2283,7 @@ class OrderModule extends _BaseModule.BaseModule {
2275
2283
  const bookingByBookingUid = new Map();
2276
2284
  bookings.forEach(booking => {
2277
2285
  if (!booking || typeof booking !== 'object') return;
2286
+ if ((0, _pickupTiming.isFulfillmentTimingBooking)(booking)) return;
2278
2287
  const productUid = booking.product_uid || booking.metadata?.product_uid;
2279
2288
  if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
2280
2289
  bookingByProductUid.set(String(productUid), booking);
@@ -2325,6 +2334,7 @@ class OrderModule extends _BaseModule.BaseModule {
2325
2334
  let baseHolder = null;
2326
2335
  const seen = new Set();
2327
2336
  for (const booking of tempOrder.bookings || []) {
2337
+ if ((0, _pickupTiming.isFulfillmentTimingBooking)(booking)) continue;
2328
2338
  const holder = booking?.holder && typeof booking.holder === 'object' ? booking.holder : null;
2329
2339
  if (!baseHolder && holder) {
2330
2340
  baseHolder = holder;
@@ -2365,7 +2375,7 @@ class OrderModule extends _BaseModule.BaseModule {
2365
2375
  * this.syncTempOrderHolderFromBookings(tempOrder);
2366
2376
  */
2367
2377
  syncTempOrderHolderFromBookings(tempOrder) {
2368
- const bookings = tempOrder.bookings || [];
2378
+ const bookings = (tempOrder.bookings || []).filter(booking => !(0, _pickupTiming.isFulfillmentTimingBooking)(booking));
2369
2379
  const hasHolderSource = bookings.some(booking => {
2370
2380
  return booking?.holder !== undefined || booking?.metadata?.holder_id !== undefined;
2371
2381
  });
@@ -2390,6 +2400,7 @@ class OrderModule extends _BaseModule.BaseModule {
2390
2400
  const bookingUid = product?.booking_uid || product?.metadata?.booking_uid;
2391
2401
  if (!productUid && !bookingUid) return;
2392
2402
  tempOrder.bookings = (tempOrder.bookings || []).filter(booking => {
2403
+ if ((0, _pickupTiming.isFulfillmentTimingBooking)(booking)) return true;
2393
2404
  const currentBookingUid = this.getBookingUniqueIdentificationNumber(booking);
2394
2405
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
2395
2406
  if (productUid && String(booking?.product_uid || '') === String(productUid)) return false;
@@ -2803,10 +2814,33 @@ class OrderModule extends _BaseModule.BaseModule {
2803
2814
  });
2804
2815
  }
2805
2816
  updateTempOrderServiceType(serviceType) {
2817
+ if (serviceType !== 'pick_up') {
2818
+ const tempOrder = this.ensureTempOrder();
2819
+ tempOrder.bookings = (tempOrder.bookings || []).filter(booking => !(0, _pickupTiming.isFulfillmentTimingBooking)(booking));
2820
+ }
2806
2821
  return this.updateTempOrderShopServiceData({
2807
2822
  service_type: serviceType
2808
2823
  });
2809
2824
  }
2825
+ getPickupTimingBooking() {
2826
+ return (this.store.tempOrder?.bookings || []).find(_pickupTiming.isFulfillmentTimingBooking) || null;
2827
+ }
2828
+ setPickupTimingBooking(input) {
2829
+ const tempOrder = this.ensureTempOrder();
2830
+ const bookings = tempOrder.bookings || [];
2831
+ const firstIndex = bookings.findIndex(_pickupTiming.isFulfillmentTimingBooking);
2832
+ const nextBooking = (0, _pickupTiming.buildPickupTimingBooking)(input, bookings[firstIndex]);
2833
+ // Keep the first row's identity and position; repair duplicate marked rows only.
2834
+ tempOrder.bookings = firstIndex === -1 ? [...bookings, nextBooking] : bookings.flatMap((booking, index) => index === firstIndex ? [nextBooking] : (0, _pickupTiming.isFulfillmentTimingBooking)(booking) ? [] : [booking]);
2835
+ this.notifyTempOrderChanged();
2836
+ return nextBooking;
2837
+ }
2838
+ clearPickupTimingBooking() {
2839
+ const tempOrder = this.store.tempOrder;
2840
+ if (!tempOrder?.bookings?.some(_pickupTiming.isFulfillmentTimingBooking)) return;
2841
+ tempOrder.bookings = tempOrder.bookings.filter(booking => !(0, _pickupTiming.isFulfillmentTimingBooking)(booking));
2842
+ this.notifyTempOrderChanged();
2843
+ }
2810
2844
  updateTempOrderContactsInfo(contactsInfo) {
2811
2845
  const tempOrder = this.ensureTempOrder();
2812
2846
  tempOrder.contacts_info = contactsInfo && typeof contactsInfo === 'object' && !Array.isArray(contactsInfo) ? contactsInfo : null;
@@ -5044,13 +5078,10 @@ class OrderModule extends _BaseModule.BaseModule {
5044
5078
  if (lookup.startsWith('LOCAL_')) {
5045
5079
  params.forceRemote = false;
5046
5080
  }
5047
- const res = await this.request.get(`/order/sales/${encodeURIComponent(lookup)}`, {
5048
- with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'order_meta_list', 'refunds', 'notes'],
5049
- ...(params.forceRemote ? {
5050
- forceRemote: true
5051
- } : {})
5052
- }, {
5053
- osServer: true
5081
+ const res = await (0, _loadSalesOrderSnapshot.loadSalesOrderSnapshot)(this.request, {
5082
+ lookup,
5083
+ transport: 'os-server',
5084
+ forceRemote: params.forceRemote
5054
5085
  });
5055
5086
  if (res.code === 200) {
5056
5087
  this.store.lastOrderInfo = res.data;