@pisell/pisellos 2.3.129 → 2.3.131
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.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/modules/BusinessAvailability/index.d.ts +30 -0
- package/dist/modules/BusinessAvailability/index.js +204 -0
- package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
- package/dist/modules/FulfillmentTiming/index.js +407 -0
- package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
- package/dist/modules/FulfillmentTiming/types.js +1 -0
- package/dist/modules/OpenData/types.d.ts +8 -0
- package/dist/modules/Order/index.d.ts +11 -2
- package/dist/modules/Order/index.js +370 -253
- package/dist/modules/Order/pickupTiming.d.ts +46 -0
- package/dist/modules/Order/pickupTiming.js +53 -0
- package/dist/modules/Order/types.d.ts +13 -1
- package/dist/modules/Order/utils.js +16 -6
- package/dist/modules/Payment/index.js +9 -10
- package/dist/modules/Schedule/index.d.ts +8 -0
- package/dist/modules/Schedule/index.js +141 -39
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/plugins/request.d.ts +7 -0
- package/dist/server/utils/small-ticket.d.ts +1 -85
- package/dist/server/utils/small-ticket.js +2 -2542
- package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
- package/dist/shared/payment/loadPaymentMethods.js +66 -0
- package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
- package/dist/shared/receipt/loadCustomerInvoiceLayout.js +142 -0
- package/dist/shared/receipt/small-ticket.d.ts +85 -0
- package/dist/shared/receipt/small-ticket.js +2576 -0
- package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
- package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
- package/dist/solution/BaseSales/index.d.ts +28 -15
- package/dist/solution/BaseSales/index.js +1346 -1101
- package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
- package/dist/solution/BaseSales/pickupTiming.js +589 -0
- package/dist/solution/BaseSales/types.d.ts +11 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +2 -2
- package/dist/solution/BookingTicket/index.js +41 -13
- package/dist/solution/BookingTicket/utils/cartView.js +3 -1
- package/dist/solution/OrderInvoicePreview/index.d.ts +56 -0
- package/dist/solution/OrderInvoicePreview/index.js +269 -0
- package/dist/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
- package/dist/solution/UnifiedBookingSales/businessAvailability.js +292 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +24 -4
- package/dist/solution/UnifiedBookingSales/index.js +953 -709
- package/dist/solution/UnifiedBookingSales/types.d.ts +2 -0
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +2 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +21 -1
- package/lib/model/strategy/adapter/promotion/index.js +46 -1
- package/lib/modules/BusinessAvailability/index.d.ts +30 -0
- package/lib/modules/BusinessAvailability/index.js +146 -0
- package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
- package/lib/modules/FulfillmentTiming/index.js +359 -0
- package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
- package/lib/modules/FulfillmentTiming/types.js +5 -0
- package/lib/modules/OpenData/types.d.ts +8 -0
- package/lib/modules/Order/index.d.ts +11 -2
- package/lib/modules/Order/index.js +101 -14
- package/lib/modules/Order/pickupTiming.d.ts +46 -0
- package/lib/modules/Order/pickupTiming.js +61 -0
- package/lib/modules/Order/types.d.ts +13 -1
- package/lib/modules/Order/utils.js +12 -4
- package/lib/modules/Payment/index.js +3 -4
- package/lib/modules/Schedule/index.d.ts +8 -0
- package/lib/modules/Schedule/index.js +68 -12
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +11 -0
- package/lib/plugins/request.d.ts +7 -0
- package/lib/server/utils/small-ticket.d.ts +1 -85
- package/lib/server/utils/small-ticket.js +9 -2305
- package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
- package/lib/shared/payment/loadPaymentMethods.js +40 -0
- package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
- package/lib/shared/receipt/loadCustomerInvoiceLayout.js +86 -0
- package/lib/shared/receipt/small-ticket.d.ts +85 -0
- package/lib/shared/receipt/small-ticket.js +2342 -0
- package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
- package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
- package/lib/solution/BaseSales/index.d.ts +28 -15
- package/lib/solution/BaseSales/index.js +161 -25
- package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
- package/lib/solution/BaseSales/pickupTiming.js +269 -0
- package/lib/solution/BaseSales/types.d.ts +11 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +2 -2
- package/lib/solution/BookingTicket/index.js +37 -4
- package/lib/solution/BookingTicket/utils/cartView.js +3 -1
- package/lib/solution/OrderInvoicePreview/index.d.ts +56 -0
- package/lib/solution/OrderInvoicePreview/index.js +192 -0
- package/lib/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
- package/lib/solution/UnifiedBookingSales/businessAvailability.js +138 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +24 -4
- package/lib/solution/UnifiedBookingSales/index.js +184 -46
- package/lib/solution/UnifiedBookingSales/types.d.ts +2 -0
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +11 -0
- package/package.json +1 -1
package/dist/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/dist/index.js
CHANGED
|
@@ -15,4 +15,6 @@ export { PisellOSCore } from "./core";
|
|
|
15
15
|
|
|
16
16
|
// 导出框架主类
|
|
17
17
|
import PisellOSCore from "./core";
|
|
18
|
-
export default PisellOSCore;
|
|
18
|
+
export default PisellOSCore;
|
|
19
|
+
export * from "./shared/receipt/small-ticket";
|
|
20
|
+
export { loadSalesOrderSnapshot } from "./shared/sales/loadSalesOrderSnapshot";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MultiLangObject } from '../OpenData/types';
|
|
2
|
+
import type { ScheduleItem } from '../Schedule/types';
|
|
3
|
+
export type BusinessClosedBehavior = 'show_menu_disabled' | 'hide_all';
|
|
4
|
+
export interface BusinessAvailability {
|
|
5
|
+
status: 'open' | 'paused' | 'closed' | 'error';
|
|
6
|
+
behavior: BusinessClosedBehavior | null;
|
|
7
|
+
message: string | MultiLangObject | null;
|
|
8
|
+
/** Epoch milliseconds. Re-evaluate the cached configuration at this time. */
|
|
9
|
+
nextChangeAt: number;
|
|
10
|
+
requirePaymentOnSubmit: boolean;
|
|
11
|
+
error?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface BusinessAvailabilityConfig {
|
|
14
|
+
paused: boolean;
|
|
15
|
+
pauseBehavior: BusinessClosedBehavior;
|
|
16
|
+
closedBehavior: BusinessClosedBehavior;
|
|
17
|
+
pauseMessage: BusinessAvailability['message'];
|
|
18
|
+
closedMessage: BusinessAvailability['message'];
|
|
19
|
+
scheduleIds: number[];
|
|
20
|
+
invalidScheduleIds: boolean;
|
|
21
|
+
requirePaymentOnSubmit: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function normalizeBusinessAvailabilityConfig(data: Record<string, unknown>): BusinessAvailabilityConfig;
|
|
24
|
+
/** Business ordering is independent of reservation switches and Pickup slot availability. */
|
|
25
|
+
export declare function computeBusinessAvailability(input: {
|
|
26
|
+
config: BusinessAvailabilityConfig;
|
|
27
|
+
schedules: ScheduleItem[];
|
|
28
|
+
timezone: string;
|
|
29
|
+
now: Date;
|
|
30
|
+
}): BusinessAvailability;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
4
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
5
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
6
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
10
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
11
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
12
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
15
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
16
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
17
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
18
|
+
import dayjs from 'dayjs';
|
|
19
|
+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
20
|
+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
21
|
+
import { getScheduleStartEndTimePoints } from "../Schedule/getDateIsInSchedule";
|
|
22
|
+
dayjs.extend(isSameOrAfter);
|
|
23
|
+
dayjs.extend(isSameOrBefore);
|
|
24
|
+
var DAY = 86400000;
|
|
25
|
+
var behavior = function behavior(value) {
|
|
26
|
+
return value === 'show_menu_disabled' ? value : 'hide_all';
|
|
27
|
+
};
|
|
28
|
+
var message = function message(value) {
|
|
29
|
+
return typeof value === 'string' || value !== null && _typeof(value) === 'object' && !Array.isArray(value) ? value : null;
|
|
30
|
+
};
|
|
31
|
+
export function normalizeBusinessAvailabilityConfig(data) {
|
|
32
|
+
var rawIds = data['availability.operating_hours'];
|
|
33
|
+
var ids = Array.isArray(rawIds) ? rawIds.map(function (id) {
|
|
34
|
+
return typeof id === 'number' || typeof id === 'string' ? Number(id) : NaN;
|
|
35
|
+
}) : [];
|
|
36
|
+
var validIds = ids.filter(function (id) {
|
|
37
|
+
return Number.isInteger(id) && id > 0;
|
|
38
|
+
});
|
|
39
|
+
var paused = data['availability.paused'];
|
|
40
|
+
return {
|
|
41
|
+
paused: paused === true || paused === 1 || paused === 'true' || paused === '1',
|
|
42
|
+
pauseBehavior: behavior(data['availability.pause_behavior']),
|
|
43
|
+
closedBehavior: behavior(data['availability.closed_behavior']),
|
|
44
|
+
pauseMessage: message(data['availability.pause_message']),
|
|
45
|
+
closedMessage: message(data['availability.closed_message']),
|
|
46
|
+
scheduleIds: _toConsumableArray(new Set(validIds)),
|
|
47
|
+
invalidScheduleIds: rawIds != null && (!Array.isArray(rawIds) || validIds.length !== ids.length),
|
|
48
|
+
// Only an explicitly disabled setting changes the existing payment flow.
|
|
49
|
+
requirePaymentOnSubmit: data['sale.require_payment_on_submit'] !== false
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function createClock(timezone) {
|
|
53
|
+
if (!timezone) throw new Error('Store timezone is unavailable.');
|
|
54
|
+
var formatter = new Intl.DateTimeFormat('en-GB', {
|
|
55
|
+
timeZone: timezone,
|
|
56
|
+
year: 'numeric',
|
|
57
|
+
month: '2-digit',
|
|
58
|
+
day: '2-digit',
|
|
59
|
+
hour: '2-digit',
|
|
60
|
+
minute: '2-digit',
|
|
61
|
+
second: '2-digit',
|
|
62
|
+
hourCycle: 'h23'
|
|
63
|
+
});
|
|
64
|
+
var local = function local(timestamp) {
|
|
65
|
+
var parts = {};
|
|
66
|
+
formatter.formatToParts(timestamp).forEach(function (part) {
|
|
67
|
+
parts[part.type] = part.value;
|
|
68
|
+
});
|
|
69
|
+
var date = "".concat(parts.year, "-").concat(parts.month, "-").concat(parts.day);
|
|
70
|
+
return {
|
|
71
|
+
date: date,
|
|
72
|
+
scalar: Date.parse("".concat(date, "T").concat(parts.hour, ":").concat(parts.minute, ":").concat(parts.second, "Z"))
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
var offsets = new Set();
|
|
76
|
+
var instants = function instants(scalar) {
|
|
77
|
+
offsets.clear();
|
|
78
|
+
for (var hours = -36; hours <= 36; hours += 6) {
|
|
79
|
+
var sample = scalar + hours * 3600000;
|
|
80
|
+
offsets.add(local(sample).scalar - sample);
|
|
81
|
+
}
|
|
82
|
+
return _toConsumableArray(offsets).map(function (offset) {
|
|
83
|
+
return scalar - offset;
|
|
84
|
+
}).filter(function (instant) {
|
|
85
|
+
return local(instant).scalar === scalar;
|
|
86
|
+
}).sort(function (a, b) {
|
|
87
|
+
return a - b;
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
local: local,
|
|
92
|
+
instants: instants
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Business ordering is independent of reservation switches and Pickup slot availability. */
|
|
97
|
+
export function computeBusinessAvailability(input) {
|
|
98
|
+
var config = input.config,
|
|
99
|
+
schedules = input.schedules,
|
|
100
|
+
timezone = input.timezone,
|
|
101
|
+
now = input.now;
|
|
102
|
+
var nowAt = now.getTime();
|
|
103
|
+
var base = {
|
|
104
|
+
requirePaymentOnSubmit: config.requirePaymentOnSubmit,
|
|
105
|
+
nextChangeAt: nowAt + DAY
|
|
106
|
+
};
|
|
107
|
+
if (config.paused) {
|
|
108
|
+
return _objectSpread(_objectSpread({}, base), {}, {
|
|
109
|
+
status: 'paused',
|
|
110
|
+
behavior: config.pauseBehavior,
|
|
111
|
+
message: config.pauseMessage
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (config.invalidScheduleIds) throw new Error('Business operating-hours configuration is invalid.');
|
|
115
|
+
if (!config.scheduleIds.length) return _objectSpread(_objectSpread({}, base), {}, {
|
|
116
|
+
status: 'open',
|
|
117
|
+
behavior: null,
|
|
118
|
+
message: null
|
|
119
|
+
});
|
|
120
|
+
var selected = schedules.filter(function (schedule) {
|
|
121
|
+
return config.scheduleIds.includes(Number(schedule.id));
|
|
122
|
+
});
|
|
123
|
+
if (config.scheduleIds.some(function (id) {
|
|
124
|
+
return !selected.some(function (schedule) {
|
|
125
|
+
return Number(schedule.id) === id;
|
|
126
|
+
});
|
|
127
|
+
})) {
|
|
128
|
+
throw new Error('A configured business operating-hours schedule is unavailable.');
|
|
129
|
+
}
|
|
130
|
+
var clock = createClock(timezone);
|
|
131
|
+
var current = clock.local(nowAt);
|
|
132
|
+
var today = Date.parse("".concat(current.date, "T00:00:00Z"));
|
|
133
|
+
var nextMidnight = clock.instants(today + DAY).find(function (instant) {
|
|
134
|
+
return instant > nowAt;
|
|
135
|
+
});
|
|
136
|
+
var nextChangeAt = nextMidnight !== null && nextMidnight !== void 0 ? nextMidnight : nowAt + 60000;
|
|
137
|
+
var open = false;
|
|
138
|
+
// Yesterday contributes the tail of overnight windows; today supplies the next boundary.
|
|
139
|
+
for (var _i = 0, _arr = [today - DAY, today]; _i < _arr.length; _i++) {
|
|
140
|
+
var dateAt = _arr[_i];
|
|
141
|
+
var date = new Date(dateAt).toISOString().slice(0, 10);
|
|
142
|
+
// Schedule's resolver merges by time-of-day, so resolve each schedule independently.
|
|
143
|
+
var _iterator = _createForOfIteratorHelper(selected),
|
|
144
|
+
_step;
|
|
145
|
+
try {
|
|
146
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
147
|
+
var schedule = _step.value;
|
|
148
|
+
var _iterator2 = _createForOfIteratorHelper(getScheduleStartEndTimePoints(date, [schedule])),
|
|
149
|
+
_step2;
|
|
150
|
+
try {
|
|
151
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
152
|
+
var window = _step2.value;
|
|
153
|
+
var toMinutes = function toMinutes(value) {
|
|
154
|
+
if (!/^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value) && value !== '24:00') {
|
|
155
|
+
throw new Error('Business operating-hours schedule contains an invalid time.');
|
|
156
|
+
}
|
|
157
|
+
var _value$split$map = value.split(':').map(Number),
|
|
158
|
+
_value$split$map2 = _slicedToArray(_value$split$map, 2),
|
|
159
|
+
hours = _value$split$map2[0],
|
|
160
|
+
minutes = _value$split$map2[1];
|
|
161
|
+
return hours * 60 + minutes;
|
|
162
|
+
};
|
|
163
|
+
var start = dateAt + toMinutes(window.start_time) * 60000;
|
|
164
|
+
var end = dateAt + toMinutes(window.end_time) * 60000;
|
|
165
|
+
if (end <= start) end += DAY;
|
|
166
|
+
if (current.scalar >= start && current.scalar < end) open = true;
|
|
167
|
+
for (var _i2 = 0, _arr2 = [start, end]; _i2 < _arr2.length; _i2++) {
|
|
168
|
+
var boundary = _arr2[_i2];
|
|
169
|
+
var _iterator3 = _createForOfIteratorHelper(clock.instants(boundary)),
|
|
170
|
+
_step3;
|
|
171
|
+
try {
|
|
172
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
173
|
+
var instant = _step3.value;
|
|
174
|
+
if (instant > nowAt) nextChangeAt = Math.min(nextChangeAt, instant);
|
|
175
|
+
}
|
|
176
|
+
} catch (err) {
|
|
177
|
+
_iterator3.e(err);
|
|
178
|
+
} finally {
|
|
179
|
+
_iterator3.f();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
} catch (err) {
|
|
184
|
+
_iterator2.e(err);
|
|
185
|
+
} finally {
|
|
186
|
+
_iterator2.f();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
} catch (err) {
|
|
190
|
+
_iterator.e(err);
|
|
191
|
+
} finally {
|
|
192
|
+
_iterator.f();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// A timezone offset change can repeat/skip a wall-clock boundary. A local-only safety
|
|
196
|
+
// check also covers throttled timers; it does not fetch either configuration source.
|
|
197
|
+
nextChangeAt = Math.min(nextChangeAt, nowAt + 60000);
|
|
198
|
+
return _objectSpread(_objectSpread({}, base), {}, {
|
|
199
|
+
nextChangeAt: nextChangeAt,
|
|
200
|
+
status: open ? 'open' : 'closed',
|
|
201
|
+
behavior: open ? null : config.closedBehavior,
|
|
202
|
+
message: open ? null : config.closedMessage
|
|
203
|
+
});
|
|
204
|
+
}
|
|
@@ -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,407 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
5
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
6
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
7
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
import dayjs from 'dayjs';
|
|
13
|
+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
14
|
+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
15
|
+
import { getScheduleStartEndTimePoints } from "../Schedule/getDateIsInSchedule";
|
|
16
|
+
export * from "./types";
|
|
17
|
+
|
|
18
|
+
// The shared Schedule resolver uses these comparisons without registering them.
|
|
19
|
+
dayjs.extend(isSameOrAfter);
|
|
20
|
+
dayjs.extend(isSameOrBefore);
|
|
21
|
+
var MINUTE = 60000;
|
|
22
|
+
var DAY = 24 * 60 * MINUTE;
|
|
23
|
+
var integerSetting = function integerSetting(value, min, max, fallback) {
|
|
24
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= min && value <= max ? value : fallback;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Consume effective OpenData values only; legacy switches never enable Pickup. */
|
|
28
|
+
export function normalizePickupTimingConfig(openData) {
|
|
29
|
+
var handovers = openData['fulfillment.handover_mode'];
|
|
30
|
+
var scheduleIds = openData['fulfillment.pickup.schedule'];
|
|
31
|
+
var operatingHoursScheduleIds = openData['availability.operating_hours'];
|
|
32
|
+
var mode = openData['fulfillment.pickup.timing_mode'];
|
|
33
|
+
return {
|
|
34
|
+
handoverModes: Array.isArray(handovers) ? _toConsumableArray(new Set(handovers.filter(function (value) {
|
|
35
|
+
return typeof value === 'string' && value.length > 0;
|
|
36
|
+
}))) : [],
|
|
37
|
+
timingMode: mode === 'scheduled_only' || mode === 'asap_and_scheduled' ? mode : 'asap_only',
|
|
38
|
+
scheduleIds: Array.isArray(scheduleIds) ? _toConsumableArray(new Set(scheduleIds.filter(function (value) {
|
|
39
|
+
return typeof value === 'number' && Number.isInteger(value) && value > 0;
|
|
40
|
+
}))) : [],
|
|
41
|
+
operatingHoursScheduleIds: Array.isArray(operatingHoursScheduleIds) ? _toConsumableArray(new Set(operatingHoursScheduleIds.map(function (value) {
|
|
42
|
+
return typeof value === 'number' || typeof value === 'string' ? Number(value) : NaN;
|
|
43
|
+
}).filter(function (value) {
|
|
44
|
+
return Number.isInteger(value) && value > 0;
|
|
45
|
+
}))) : [],
|
|
46
|
+
slotIntervalMinutes: integerSetting(openData['fulfillment.pickup.slot_interval_minutes'], 1, 1440, 15),
|
|
47
|
+
preparationTimeMinutes: integerSetting(openData['fulfillment.pickup.preparation_time_minutes'], 0, 1440, 0),
|
|
48
|
+
advanceDays: integerSetting(openData['fulfillment.pickup.advance_days'], 0, 365, 7),
|
|
49
|
+
fulfillmentRefMode: typeof openData['fulfillment.fulfillment_ref_mode'] === 'string' ? openData['fulfillment.fulfillment_ref_mode'] : undefined,
|
|
50
|
+
manualInputType: typeof openData['fulfillment.manual_input_type'] === 'string' ? openData['fulfillment.manual_input_type'] : undefined
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function dateStamp(date) {
|
|
54
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) return NaN;
|
|
55
|
+
var value = Date.parse("".concat(date, "T00:00:00Z"));
|
|
56
|
+
return Number.isFinite(value) && new Date(value).toISOString().slice(0, 10) === date ? value : NaN;
|
|
57
|
+
}
|
|
58
|
+
function addDays(date, days) {
|
|
59
|
+
return new Date(dateStamp(date) + days * DAY).toISOString().slice(0, 10);
|
|
60
|
+
}
|
|
61
|
+
function timeMinutes(time) {
|
|
62
|
+
var allowDayEnd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
63
|
+
if (!/^\d{2}:\d{2}(?::00)?$/.test(time)) return NaN;
|
|
64
|
+
var _time$split$map = time.split(':').map(Number),
|
|
65
|
+
_time$split$map2 = _slicedToArray(_time$split$map, 2),
|
|
66
|
+
hours = _time$split$map2[0],
|
|
67
|
+
minutes = _time$split$map2[1];
|
|
68
|
+
if (allowDayEnd && hours === 24 && minutes === 0) return 1440;
|
|
69
|
+
return hours < 24 && minutes < 60 ? hours * 60 + minutes : NaN;
|
|
70
|
+
}
|
|
71
|
+
function instantStamp(value) {
|
|
72
|
+
// A local string would silently use the device timezone instead of the store.
|
|
73
|
+
if (typeof value === 'string' && !/(Z|[+-]\d{2}:?\d{2})$/i.test(value)) return NaN;
|
|
74
|
+
return value instanceof Date ? value.getTime() : new Date(value).getTime();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Per-query timezone adapter; no device-offset arithmetic or global time cache. */
|
|
78
|
+
function createClock(timezone) {
|
|
79
|
+
if (!timezone || typeof timezone !== 'string') throw new Error('Store timezone is unavailable.');
|
|
80
|
+
var formatter;
|
|
81
|
+
try {
|
|
82
|
+
formatter = new Intl.DateTimeFormat('en-GB', {
|
|
83
|
+
timeZone: timezone,
|
|
84
|
+
year: 'numeric',
|
|
85
|
+
month: '2-digit',
|
|
86
|
+
day: '2-digit',
|
|
87
|
+
hour: '2-digit',
|
|
88
|
+
minute: '2-digit',
|
|
89
|
+
second: '2-digit',
|
|
90
|
+
hourCycle: 'h23'
|
|
91
|
+
});
|
|
92
|
+
} catch (_unused) {
|
|
93
|
+
throw new Error('Store timezone is invalid.');
|
|
94
|
+
}
|
|
95
|
+
var offsetsByDate = new Map();
|
|
96
|
+
var local = function local(timestamp) {
|
|
97
|
+
var parts = {};
|
|
98
|
+
formatter.formatToParts(timestamp).forEach(function (part) {
|
|
99
|
+
parts[part.type] = part.value;
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
date: "".concat(parts.year, "-").concat(parts.month, "-").concat(parts.day),
|
|
103
|
+
time: "".concat(parts.hour, ":").concat(parts.minute),
|
|
104
|
+
second: parts.second
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
var offsets = function offsets(date) {
|
|
108
|
+
var cached = offsetsByDate.get(date);
|
|
109
|
+
if (cached) return cached;
|
|
110
|
+
var result = new Set();
|
|
111
|
+
var nominal = dateStamp(date);
|
|
112
|
+
// Sampling both sides of the target day discovers pre/post-transition offsets.
|
|
113
|
+
for (var hours = -36; hours <= 36; hours += 6) {
|
|
114
|
+
var sample = nominal + hours * 60 * MINUTE;
|
|
115
|
+
var wall = local(sample);
|
|
116
|
+
result.add(Date.parse("".concat(wall.date, "T").concat(wall.time, ":").concat(wall.second, "Z")) - sample);
|
|
117
|
+
}
|
|
118
|
+
var values = _toConsumableArray(result);
|
|
119
|
+
offsetsByDate.set(date, values);
|
|
120
|
+
return values;
|
|
121
|
+
};
|
|
122
|
+
var resolve = function resolve(date, time) {
|
|
123
|
+
var day = dateStamp(date);
|
|
124
|
+
var minutes = timeMinutes(time);
|
|
125
|
+
if (!Number.isFinite(day) || !Number.isFinite(minutes)) return [];
|
|
126
|
+
var label = time.slice(0, 5);
|
|
127
|
+
var nominal = day + minutes * MINUTE;
|
|
128
|
+
return offsets(date).map(function (offset) {
|
|
129
|
+
return nominal - offset;
|
|
130
|
+
}).filter(function (timestamp) {
|
|
131
|
+
var wall = local(timestamp);
|
|
132
|
+
return wall.date === date && wall.time === label;
|
|
133
|
+
}).sort(function (a, b) {
|
|
134
|
+
return a - b;
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
var slot = function slot(timestamp) {
|
|
138
|
+
var _local = local(timestamp),
|
|
139
|
+
date = _local.date,
|
|
140
|
+
time = _local.time;
|
|
141
|
+
var instant = new Date(timestamp).toISOString();
|
|
142
|
+
return {
|
|
143
|
+
id: instant,
|
|
144
|
+
date: date,
|
|
145
|
+
time: time,
|
|
146
|
+
instant: instant
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
return {
|
|
150
|
+
local: local,
|
|
151
|
+
resolve: resolve,
|
|
152
|
+
slot: slot,
|
|
153
|
+
hasOffsetTransition: function hasOffsetTransition(date) {
|
|
154
|
+
return offsets(date).length > 1;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
export function resolvePickupTimingDateTime(date, time, timezone, instant) {
|
|
159
|
+
var clock = createClock(timezone);
|
|
160
|
+
var matches = clock.resolve(date, time);
|
|
161
|
+
var selected = instant ? instantStamp(instant) : matches.length === 1 ? matches[0] : NaN;
|
|
162
|
+
return matches.includes(selected) ? clock.slot(selected) : undefined;
|
|
163
|
+
}
|
|
164
|
+
export function getAsapPickupTiming(_ref) {
|
|
165
|
+
var config = _ref.config,
|
|
166
|
+
timezone = _ref.timezone,
|
|
167
|
+
now = _ref.now;
|
|
168
|
+
var timestamp = instantStamp(now);
|
|
169
|
+
if (!Number.isFinite(timestamp)) throw new Error('Current time is invalid.');
|
|
170
|
+
return createClock(timezone).slot(timestamp + config.preparationTimeMinutes * MINUTE);
|
|
171
|
+
}
|
|
172
|
+
export function pickupTimingSlotToBookingTimes(slot) {
|
|
173
|
+
return {
|
|
174
|
+
start_date: slot.date,
|
|
175
|
+
start_time: slot.time,
|
|
176
|
+
end_date: slot.date,
|
|
177
|
+
end_time: slot.time
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function createEvaluation(input) {
|
|
181
|
+
var config = input.config,
|
|
182
|
+
timezone = input.timezone;
|
|
183
|
+
var clock = createClock(timezone);
|
|
184
|
+
var now = instantStamp(input.now);
|
|
185
|
+
if (!Number.isFinite(now)) throw new Error('Current time is invalid.');
|
|
186
|
+
var today = clock.local(now).date;
|
|
187
|
+
var maxDate = addDays(today, config.advanceDays);
|
|
188
|
+
var earliest = now + config.preparationTimeMinutes * MINUTE;
|
|
189
|
+
var schedules = input.schedules.filter(function (schedule) {
|
|
190
|
+
return config.scheduleIds.includes(schedule.id);
|
|
191
|
+
});
|
|
192
|
+
var windowCache = new Map();
|
|
193
|
+
var windows = function windows(date) {
|
|
194
|
+
if (!windowCache.has(date)) {
|
|
195
|
+
windowCache.set(date, getScheduleStartEndTimePoints(date, schedules));
|
|
196
|
+
}
|
|
197
|
+
return windowCache.get(date);
|
|
198
|
+
};
|
|
199
|
+
var operatingIds = config.operatingHoursScheduleIds || [];
|
|
200
|
+
var operatingSchedules = input.schedules.filter(function (schedule) {
|
|
201
|
+
return operatingIds.includes(schedule.id);
|
|
202
|
+
});
|
|
203
|
+
var operatingWindowCache = new Map();
|
|
204
|
+
var operatingWindows = function operatingWindows(date) {
|
|
205
|
+
if (!operatingWindowCache.has(date)) {
|
|
206
|
+
var ranges = [];
|
|
207
|
+
for (var _i = 0, _arr = [-1, 0]; _i < _arr.length; _i++) {
|
|
208
|
+
var offset = _arr[_i];
|
|
209
|
+
var _iterator = _createForOfIteratorHelper(getScheduleStartEndTimePoints(addDays(date, offset), operatingSchedules)),
|
|
210
|
+
_step;
|
|
211
|
+
try {
|
|
212
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
213
|
+
var window = _step.value;
|
|
214
|
+
var start = timeMinutes(window.start_time);
|
|
215
|
+
var end = timeMinutes(window.end_time, true);
|
|
216
|
+
if (!Number.isFinite(start) || !Number.isFinite(end)) continue;
|
|
217
|
+
// Store hours use equal endpoints for a full operating day, while
|
|
218
|
+
// the Pickup Schedule may deliberately contain a single time point.
|
|
219
|
+
if (end <= start) end += 1440;
|
|
220
|
+
ranges.push({
|
|
221
|
+
start: start + offset * 1440,
|
|
222
|
+
end: end + offset * 1440
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
} catch (err) {
|
|
226
|
+
_iterator.e(err);
|
|
227
|
+
} finally {
|
|
228
|
+
_iterator.f();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
operatingWindowCache.set(date, ranges);
|
|
232
|
+
}
|
|
233
|
+
return operatingWindowCache.get(date);
|
|
234
|
+
};
|
|
235
|
+
var slotsForDate = function slotsForDate(date) {
|
|
236
|
+
var firstOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
237
|
+
if (!Number.isFinite(dateStamp(date)) || date < today || date > maxDate || !config.handoverModes.includes('pick_up') || config.timingMode === 'asap_only') return [];
|
|
238
|
+
var found = new Map();
|
|
239
|
+
// Missing hours configuration preserves the existing all-day convention.
|
|
240
|
+
// Referenced but missing schedules yield no windows, never an all-day fallback.
|
|
241
|
+
var businessWindows = operatingIds.length ? operatingWindows(date) : undefined;
|
|
242
|
+
// Include the prior day's windows so overnight tails belong to their actual date.
|
|
243
|
+
for (var _i2 = 0, _arr2 = [addDays(date, -1), date]; _i2 < _arr2.length; _i2++) {
|
|
244
|
+
var windowDate = _arr2[_i2];
|
|
245
|
+
var _iterator2 = _createForOfIteratorHelper(windows(windowDate)),
|
|
246
|
+
_step2;
|
|
247
|
+
try {
|
|
248
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
249
|
+
var window = _step2.value;
|
|
250
|
+
var start = timeMinutes(window.start_time);
|
|
251
|
+
var end = timeMinutes(window.end_time, true);
|
|
252
|
+
if (!Number.isFinite(start) || !Number.isFinite(end)) continue;
|
|
253
|
+
if (end < start) end += 1440;
|
|
254
|
+
var firstFoundInWindow = false;
|
|
255
|
+
var _loop = function _loop() {
|
|
256
|
+
var targetDate = minute >= 1440 ? addDays(windowDate, 1) : windowDate;
|
|
257
|
+
if (targetDate !== date) return 0; // continue
|
|
258
|
+
var localMinute = minute % 1440;
|
|
259
|
+
// Filter the original Pickup grid rather than moving its anchor to
|
|
260
|
+
// the store opening time. A zero-duration pickup may be at closing.
|
|
261
|
+
if (businessWindows && !businessWindows.some(function (_ref2) {
|
|
262
|
+
var start = _ref2.start,
|
|
263
|
+
end = _ref2.end;
|
|
264
|
+
return localMinute >= start && localMinute <= end;
|
|
265
|
+
})) return 0; // continue
|
|
266
|
+
var time = "".concat(String(Math.floor(localMinute / 60)).padStart(2, '0'), ":").concat(String(localMinute % 60).padStart(2, '0'));
|
|
267
|
+
var _iterator3 = _createForOfIteratorHelper(clock.resolve(date, time)),
|
|
268
|
+
_step3;
|
|
269
|
+
try {
|
|
270
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
271
|
+
var timestamp = _step3.value;
|
|
272
|
+
if (timestamp < earliest) continue;
|
|
273
|
+
found.set(timestamp, clock.slot(timestamp));
|
|
274
|
+
firstFoundInWindow = true;
|
|
275
|
+
}
|
|
276
|
+
// Summary needs only an available candidate, not a full year's slots.
|
|
277
|
+
// During a repeated hour, an earlier wall label's second occurrence can
|
|
278
|
+
// be later than a subsequent label's first occurrence. Sort them all.
|
|
279
|
+
} catch (err) {
|
|
280
|
+
_iterator3.e(err);
|
|
281
|
+
} finally {
|
|
282
|
+
_iterator3.f();
|
|
283
|
+
}
|
|
284
|
+
if (firstOnly && firstFoundInWindow && !clock.hasOffsetTransition(date)) return 1; // break
|
|
285
|
+
},
|
|
286
|
+
_ret;
|
|
287
|
+
for (var minute = start; minute <= end; minute += config.slotIntervalMinutes) {
|
|
288
|
+
_ret = _loop();
|
|
289
|
+
if (_ret === 0) continue;
|
|
290
|
+
if (_ret === 1) break;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
} catch (err) {
|
|
294
|
+
_iterator2.e(err);
|
|
295
|
+
} finally {
|
|
296
|
+
_iterator2.f();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
var result = _toConsumableArray(found.entries()).sort(function (_ref3, _ref4) {
|
|
300
|
+
var _ref5 = _slicedToArray(_ref3, 1),
|
|
301
|
+
a = _ref5[0];
|
|
302
|
+
var _ref6 = _slicedToArray(_ref4, 1),
|
|
303
|
+
b = _ref6[0];
|
|
304
|
+
return a - b;
|
|
305
|
+
}).map(function (_ref7) {
|
|
306
|
+
var _ref8 = _slicedToArray(_ref7, 2),
|
|
307
|
+
slot = _ref8[1];
|
|
308
|
+
return slot;
|
|
309
|
+
});
|
|
310
|
+
return firstOnly ? result.slice(0, 1) : result;
|
|
311
|
+
};
|
|
312
|
+
return {
|
|
313
|
+
clock: clock,
|
|
314
|
+
now: now,
|
|
315
|
+
today: today,
|
|
316
|
+
maxDate: maxDate,
|
|
317
|
+
slotsForDate: slotsForDate
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
export function computePickupTimingAvailability(input) {
|
|
321
|
+
if (!input.config.handoverModes.includes('pick_up')) {
|
|
322
|
+
var now = instantStamp(input.now);
|
|
323
|
+
if (!Number.isFinite(now)) throw new Error('Current time is invalid.');
|
|
324
|
+
return {
|
|
325
|
+
config: input.config,
|
|
326
|
+
timezone: input.timezone,
|
|
327
|
+
now: new Date(now).toISOString(),
|
|
328
|
+
today: '',
|
|
329
|
+
maxDate: '',
|
|
330
|
+
date: input.date || '',
|
|
331
|
+
dates: [],
|
|
332
|
+
slots: []
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
var evaluation = createEvaluation(input);
|
|
336
|
+
var today = evaluation.today,
|
|
337
|
+
maxDate = evaluation.maxDate,
|
|
338
|
+
slotsForDate = evaluation.slotsForDate;
|
|
339
|
+
var date = input.date || today;
|
|
340
|
+
if (!Number.isFinite(dateStamp(date))) throw new Error('Pickup date is invalid.');
|
|
341
|
+
var slots = slotsForDate(date);
|
|
342
|
+
var dates = [];
|
|
343
|
+
var firstSlot;
|
|
344
|
+
for (var day = today; day <= maxDate; day = addDays(day, 1)) {
|
|
345
|
+
var first = day === date ? slots[0] : slotsForDate(day, true)[0];
|
|
346
|
+
dates.push({
|
|
347
|
+
date: day,
|
|
348
|
+
status: first ? 'available' : 'unavailable'
|
|
349
|
+
});
|
|
350
|
+
if (!firstSlot && first) firstSlot = first;
|
|
351
|
+
}
|
|
352
|
+
return {
|
|
353
|
+
config: input.config,
|
|
354
|
+
timezone: input.timezone,
|
|
355
|
+
now: new Date(evaluation.now).toISOString(),
|
|
356
|
+
today: today,
|
|
357
|
+
maxDate: maxDate,
|
|
358
|
+
date: date,
|
|
359
|
+
dates: dates,
|
|
360
|
+
slots: slots,
|
|
361
|
+
firstSlot: firstSlot
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
export function validatePickupTimingSelection(selection, input) {
|
|
365
|
+
var fail = function fail(code, message) {
|
|
366
|
+
return {
|
|
367
|
+
valid: false,
|
|
368
|
+
code: code,
|
|
369
|
+
message: message
|
|
370
|
+
};
|
|
371
|
+
};
|
|
372
|
+
var config = input.config;
|
|
373
|
+
if (config.handoverModes.length === 0) return {
|
|
374
|
+
valid: true
|
|
375
|
+
};
|
|
376
|
+
if (!config.handoverModes.includes(selection.serviceType)) {
|
|
377
|
+
return fail('handover_unavailable', 'Choose an available handover method.');
|
|
378
|
+
}
|
|
379
|
+
if (selection.serviceType !== 'pick_up') return {
|
|
380
|
+
valid: true
|
|
381
|
+
};
|
|
382
|
+
if (selection.mode === 'asap') {
|
|
383
|
+
return config.timingMode === 'scheduled_only' ? fail('scheduled_required', 'Choose a pickup date and time.') : {
|
|
384
|
+
valid: true,
|
|
385
|
+
slot: getAsapPickupTiming(input)
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
if (selection.mode !== 'scheduled' || config.timingMode === 'asap_only') {
|
|
389
|
+
return fail('mode_unavailable', 'The selected pickup timing mode is unavailable.');
|
|
390
|
+
}
|
|
391
|
+
var slot = resolvePickupTimingDateTime(selection.date || '', selection.time || '', input.timezone, selection.instant);
|
|
392
|
+
if (!slot) return fail('invalid_time', 'Choose a valid pickup date and time.');
|
|
393
|
+
var now = instantStamp(input.now);
|
|
394
|
+
if (!Number.isFinite(now)) throw new Error('Current time is invalid.');
|
|
395
|
+
if (instantStamp(slot.instant) < now) return fail('time_in_past', 'Pickup time cannot be in the past.');
|
|
396
|
+
if (selection.source === 'pos_manual' && input.allowManualOverride) return {
|
|
397
|
+
valid: true,
|
|
398
|
+
slot: slot
|
|
399
|
+
};
|
|
400
|
+
var legal = createEvaluation(input).slotsForDate(slot.date).some(function (candidate) {
|
|
401
|
+
return candidate.instant === slot.instant;
|
|
402
|
+
});
|
|
403
|
+
return legal ? {
|
|
404
|
+
valid: true,
|
|
405
|
+
slot: slot
|
|
406
|
+
} : fail('time_unavailable', 'This pickup time is no longer available. Choose another time.');
|
|
407
|
+
}
|