@final-commerce/common 2.12.0-staging.5 → 2.12.2-staging2.1
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/README.md +20 -0
- package/bin/gate-done.mjs +71 -36
- package/bin/lib/budget.mjs +71 -0
- package/dist/index.d.mts +24 -248
- package/dist/index.d.ts +24 -248
- package/dist/index.js +164 -1025
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +164 -992
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +8 -58
- package/dist/pos-types/index.d.ts +8 -58
- package/dist/pos-types/index.js +2 -7
- package/dist/pos-types/index.js.map +1 -1
- package/dist/pos-types/index.mjs +1 -5
- package/dist/pos-types/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31,13 +31,10 @@ __export(index_exports, {
|
|
|
31
31
|
AttributeType: () => AttributeType,
|
|
32
32
|
BNPL_METHOD_STATUS: () => BNPL_METHOD_STATUS,
|
|
33
33
|
BNPL_SKIP_REASON: () => BNPL_SKIP_REASON,
|
|
34
|
-
BookingArriveLeave: () => BookingArriveLeave,
|
|
35
|
-
BookingDurationUnit: () => BookingDurationUnit,
|
|
36
34
|
BookingRatePeriod: () => BookingRatePeriod,
|
|
37
35
|
BookingResourceKind: () => BookingResourceKind,
|
|
38
36
|
BookingResourceStatus: () => BookingResourceStatus,
|
|
39
37
|
BookingRulesError: () => BookingRulesError,
|
|
40
|
-
BookingSessionSale: () => BookingSessionSale,
|
|
41
38
|
BookingType: () => BookingType,
|
|
42
39
|
CANADA_PROVINCES: () => CANADA_PROVINCES,
|
|
43
40
|
CONDITION_OPERATORS: () => CONDITION_OPERATORS,
|
|
@@ -127,7 +124,6 @@ __export(index_exports, {
|
|
|
127
124
|
StripeStatus: () => StripeStatus,
|
|
128
125
|
TimePeriod: () => TimePeriod,
|
|
129
126
|
TopMetericsSort: () => TopMetericsSort,
|
|
130
|
-
UNLIMITED_PLACES: () => UNLIMITED_PLACES,
|
|
131
127
|
UserTypes: () => UserTypes,
|
|
132
128
|
addAmounts: () => addAmounts,
|
|
133
129
|
addressPlaceKeys: () => addressPlaceKeys,
|
|
@@ -136,7 +132,6 @@ __export(index_exports, {
|
|
|
136
132
|
adyenStoreRequiresStateOrProvince: () => adyenStoreRequiresStateOrProvince,
|
|
137
133
|
adyenSupportsTaxNumberAbsent: () => adyenSupportsTaxNumberAbsent,
|
|
138
134
|
adyenTaxNumberFormat: () => adyenTaxNumberFormat,
|
|
139
|
-
allowedDurationUnits: () => allowedDurationUnits,
|
|
140
135
|
amountToString: () => amountToString,
|
|
141
136
|
ancestorChain: () => ancestorChain,
|
|
142
137
|
applyAssignment: () => applyAssignment,
|
|
@@ -146,21 +141,15 @@ __export(index_exports, {
|
|
|
146
141
|
baseFulfillmentDefinitions: () => baseFulfillmentDefinitions,
|
|
147
142
|
baseOf: () => baseOf,
|
|
148
143
|
basePaymentDefinitions: () => basePaymentDefinitions,
|
|
149
|
-
bookingMethodOf: () => bookingMethodOf,
|
|
150
|
-
bookingRuleParts: () => bookingRuleParts,
|
|
151
144
|
buildAvailability: () => buildAvailability,
|
|
152
145
|
buildGrid: () => buildGrid,
|
|
153
146
|
buildOrderContext: () => buildOrderContext,
|
|
154
147
|
buildPosPresetConfig: () => buildPosPresetConfig,
|
|
155
148
|
buildResolvedConfig: () => buildResolvedConfig,
|
|
156
149
|
calculatePercentage: () => calculatePercentage,
|
|
157
|
-
calendarDate: () => calendarDate,
|
|
158
150
|
canTransition: () => canTransition,
|
|
159
|
-
capacityOf: () => capacityOf,
|
|
160
151
|
cheapestCompositeItem: () => cheapestCompositeItem,
|
|
161
152
|
cheapestCompositePrice: () => cheapestCompositePrice,
|
|
162
|
-
checkPartySize: () => checkPartySize,
|
|
163
|
-
checkQtyPerBooking: () => checkQtyPerBooking,
|
|
164
153
|
compositeItemCost: () => compositeItemCost,
|
|
165
154
|
compositeItemUnavailable: () => compositeItemUnavailable,
|
|
166
155
|
compositeMakeable: () => compositeMakeable,
|
|
@@ -169,10 +158,6 @@ __export(index_exports, {
|
|
|
169
158
|
compositeVariantInStock: () => compositeVariantInStock,
|
|
170
159
|
conditionSummary: () => conditionSummary,
|
|
171
160
|
convertFixedFeeToLocalCurrency: () => convertFixedFeeToLocalCurrency,
|
|
172
|
-
courseSessions: () => courseSessions,
|
|
173
|
-
courseSpan: () => courseSpan,
|
|
174
|
-
courseStarted: () => courseStarted,
|
|
175
|
-
courseStartedInZone: () => courseStartedInZone,
|
|
176
161
|
createAmount: () => createAmount,
|
|
177
162
|
crossAxisRuleApplies: () => crossAxisRuleApplies,
|
|
178
163
|
currentAssignees: () => currentAssignees,
|
|
@@ -181,13 +166,10 @@ __export(index_exports, {
|
|
|
181
166
|
deriveUnitId: () => deriveUnitId,
|
|
182
167
|
displayRuleMatchesPair: () => displayRuleMatchesPair,
|
|
183
168
|
divideAmount: () => divideAmount,
|
|
184
|
-
durationProblems: () => durationProblems,
|
|
185
|
-
durationText: () => durationText,
|
|
186
169
|
evaluateCondition: () => evaluateCondition,
|
|
187
170
|
evaluateConditionSet: () => evaluateConditionSet,
|
|
188
171
|
extendPrice: () => extendPrice,
|
|
189
172
|
extendPriceFor: () => extendPriceFor,
|
|
190
|
-
fewestFreeOver: () => fewestFreeOver,
|
|
191
173
|
formatCurrency: () => formatCurrency,
|
|
192
174
|
formatInUnit: () => formatInUnit,
|
|
193
175
|
formatMinorUnitsToString: () => formatMinorUnitsToString,
|
|
@@ -229,9 +211,7 @@ __export(index_exports, {
|
|
|
229
211
|
listCountries: () => listCountries,
|
|
230
212
|
listProvinces: () => listProvinces,
|
|
231
213
|
listShippingCountries: () => listShippingCountries,
|
|
232
|
-
longestMinutesOf: () => longestMinutesOf,
|
|
233
214
|
mapToLegacyStatus: () => mapToLegacyStatus,
|
|
234
|
-
maxAdvanceMinutesOf: () => maxAdvanceMinutesOf,
|
|
235
215
|
maxPrecisionFor: () => maxPrecisionFor,
|
|
236
216
|
mergeFragment: () => mergeFragment,
|
|
237
217
|
modifiersSellable: () => modifiersSellable,
|
|
@@ -243,15 +223,11 @@ __export(index_exports, {
|
|
|
243
223
|
normalizePostCode: () => normalizePostCode,
|
|
244
224
|
normalizeProvince: () => normalizeProvince,
|
|
245
225
|
occupancyIn: () => occupancyIn,
|
|
246
|
-
occupiedAtOutlet: () => occupiedAtOutlet,
|
|
247
|
-
oldMaxAdvanceOf: () => oldMaxAdvanceOf,
|
|
248
226
|
orderAssignments: () => orderAssignments,
|
|
249
227
|
parseAmountToMinorUnits: () => parseAmountToMinorUnits,
|
|
250
228
|
parseCurrencyCode: () => parseCurrencyCode,
|
|
251
229
|
parseStripeCurrencyCode: () => parseStripeCurrencyCode,
|
|
252
|
-
pickFreeResource: () => pickFreeResource,
|
|
253
230
|
placeKey: () => placeKey,
|
|
254
|
-
planCourse: () => planCourse,
|
|
255
231
|
planWindow: () => planWindow,
|
|
256
232
|
poolDemand: () => poolDemand,
|
|
257
233
|
poolOf: () => poolOf,
|
|
@@ -262,26 +238,19 @@ __export(index_exports, {
|
|
|
262
238
|
priceForTotal: () => priceForTotal,
|
|
263
239
|
provincesForPostCode: () => provincesForPostCode,
|
|
264
240
|
removeFragment: () => removeFragment,
|
|
265
|
-
rentalEnds: () => rentalEnds,
|
|
266
241
|
resolveFamily: () => resolveFamily,
|
|
267
242
|
resolveModifiersForProduct: () => resolveModifiersForProduct,
|
|
268
243
|
resolveShipping: () => resolveShipping,
|
|
269
244
|
resolveTemplate: () => resolveTemplate,
|
|
270
245
|
resolveUnit: () => resolveUnit,
|
|
271
246
|
roundToPrecision: () => roundToPrecision,
|
|
272
|
-
ruleDurationsOf: () => ruleDurationsOf,
|
|
273
|
-
ruleInNewShape: () => ruleInNewShape,
|
|
274
247
|
sameFamily: () => sameFamily,
|
|
275
|
-
sessionCells: () => sessionCells,
|
|
276
248
|
setOrderState: () => setOrderState,
|
|
277
249
|
shipsToCountry: () => shipsToCountry,
|
|
278
250
|
shopDayKey: () => shopDayKey,
|
|
279
251
|
shopDayRange: () => shopDayRange,
|
|
280
|
-
shortestMinutesOf: () => shortestMinutesOf,
|
|
281
252
|
signReportForDisplay: () => signReportForDisplay,
|
|
282
253
|
slotsForWindow: () => slotsForWindow,
|
|
283
|
-
soldAsCourse: () => soldAsCourse,
|
|
284
|
-
startsPastMaxAdvance: () => startsPastMaxAdvance,
|
|
285
254
|
stringifyMinorUnits: () => stringifyMinorUnits,
|
|
286
255
|
subtractAmounts: () => subtractAmounts,
|
|
287
256
|
toBase: () => toBase,
|
|
@@ -292,8 +261,6 @@ __export(index_exports, {
|
|
|
292
261
|
validateShippingZone: () => validateShippingZone,
|
|
293
262
|
violatesFinancialInvariant: () => violatesFinancialInvariant,
|
|
294
263
|
windowEndsAt: () => windowEndsAt,
|
|
295
|
-
windowEndsAtInZone: () => windowEndsAtInZone,
|
|
296
|
-
windowForPeriods: () => windowForPeriods,
|
|
297
264
|
withinPresence: () => withinPresence
|
|
298
265
|
});
|
|
299
266
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -754,42 +721,21 @@ var PaymentProcessor = /* @__PURE__ */ ((PaymentProcessor2) => {
|
|
|
754
721
|
})(PaymentProcessor || {});
|
|
755
722
|
|
|
756
723
|
// enums/booking.enum.ts
|
|
757
|
-
var BookingType = /* @__PURE__ */ ((
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
return
|
|
724
|
+
var BookingType = /* @__PURE__ */ ((BookingType3) => {
|
|
725
|
+
BookingType3["RENTAL"] = "rental";
|
|
726
|
+
BookingType3["APPOINTMENT"] = "appointment";
|
|
727
|
+
BookingType3["OVERNIGHT"] = "overnight";
|
|
728
|
+
BookingType3["GROUP"] = "group";
|
|
729
|
+
return BookingType3;
|
|
763
730
|
})(BookingType || {});
|
|
764
731
|
var BookingRatePeriod = /* @__PURE__ */ ((BookingRatePeriod2) => {
|
|
765
732
|
BookingRatePeriod2["SLOT"] = "slot";
|
|
766
|
-
BookingRatePeriod2["HOUR"] = "hour";
|
|
767
|
-
BookingRatePeriod2["SESSION"] = "session";
|
|
768
733
|
BookingRatePeriod2["DAY"] = "day";
|
|
769
734
|
BookingRatePeriod2["NIGHT"] = "night";
|
|
770
735
|
BookingRatePeriod2["WEEK"] = "week";
|
|
771
736
|
BookingRatePeriod2["MONTH"] = "month";
|
|
772
737
|
return BookingRatePeriod2;
|
|
773
738
|
})(BookingRatePeriod || {});
|
|
774
|
-
var BookingDurationUnit = /* @__PURE__ */ ((BookingDurationUnit2) => {
|
|
775
|
-
BookingDurationUnit2["MINUTE"] = "minute";
|
|
776
|
-
BookingDurationUnit2["HOUR"] = "hour";
|
|
777
|
-
BookingDurationUnit2["DAY"] = "day";
|
|
778
|
-
BookingDurationUnit2["NIGHT"] = "night";
|
|
779
|
-
BookingDurationUnit2["WEEK"] = "week";
|
|
780
|
-
BookingDurationUnit2["MONTH"] = "month";
|
|
781
|
-
return BookingDurationUnit2;
|
|
782
|
-
})(BookingDurationUnit || {});
|
|
783
|
-
var BookingSessionSale = /* @__PURE__ */ ((BookingSessionSale2) => {
|
|
784
|
-
BookingSessionSale2["SESSION"] = "session";
|
|
785
|
-
BookingSessionSale2["COURSE"] = "course";
|
|
786
|
-
return BookingSessionSale2;
|
|
787
|
-
})(BookingSessionSale || {});
|
|
788
|
-
var BookingArriveLeave = /* @__PURE__ */ ((BookingArriveLeave2) => {
|
|
789
|
-
BookingArriveLeave2["SET_TIMES"] = "set-times";
|
|
790
|
-
BookingArriveLeave2["OPENING_HOURS"] = "opening-hours";
|
|
791
|
-
return BookingArriveLeave2;
|
|
792
|
-
})(BookingArriveLeave || {});
|
|
793
739
|
var BookingResourceKind = /* @__PURE__ */ ((BookingResourceKind2) => {
|
|
794
740
|
BookingResourceKind2["ASSET"] = "asset";
|
|
795
741
|
BookingResourceKind2["ROOM"] = "room";
|
|
@@ -3650,7 +3596,6 @@ var ORDER_STATE_EVENTS = {
|
|
|
3650
3596
|
};
|
|
3651
3597
|
|
|
3652
3598
|
// booking/types.ts
|
|
3653
|
-
var UNLIMITED_PLACES = Number.MAX_SAFE_INTEGER;
|
|
3654
3599
|
var BookingRulesError = class extends Error {
|
|
3655
3600
|
constructor(message) {
|
|
3656
3601
|
super(message);
|
|
@@ -3719,39 +3664,153 @@ function atZonedMinute(dayStart, minutes, timeZone) {
|
|
|
3719
3664
|
const { year, month, day } = zonedParts(dayStart, timeZone);
|
|
3720
3665
|
return instantFromLocal(year, month, day, minutes, timeZone);
|
|
3721
3666
|
}
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3667
|
+
|
|
3668
|
+
// booking/grid.ts
|
|
3669
|
+
var MINUTE2 = 6e4;
|
|
3670
|
+
var MAX_RANGE_DAYS = 366;
|
|
3671
|
+
var asTime = (value, field) => {
|
|
3672
|
+
if (value == null) return void 0;
|
|
3673
|
+
const time = new Date(value).getTime();
|
|
3674
|
+
if (Number.isNaN(time)) throw new BookingRulesError(`Booking rules: ${field} is not a date, got "${String(value)}"`);
|
|
3675
|
+
return time;
|
|
3676
|
+
};
|
|
3677
|
+
function parseHhMm(value, field) {
|
|
3678
|
+
const [hours, minutes] = value.split(":").map(Number);
|
|
3679
|
+
if (!Number.isInteger(hours) || !Number.isInteger(minutes)) {
|
|
3680
|
+
throw new BookingRulesError(`Booking rules: ${field} must be "HH:mm", got "${value}"`);
|
|
3681
|
+
}
|
|
3682
|
+
return hours * 60 + minutes;
|
|
3726
3683
|
}
|
|
3727
|
-
function
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3684
|
+
function windowEndsAt(rule, now) {
|
|
3685
|
+
const { maxAdvanceDays, bookableTo } = rule.window;
|
|
3686
|
+
const ends = Math.min(
|
|
3687
|
+
maxAdvanceDays ? now.getTime() + maxAdvanceDays * 1440 * MINUTE2 : Number.POSITIVE_INFINITY,
|
|
3688
|
+
asTime(bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY
|
|
3732
3689
|
);
|
|
3690
|
+
return Number.isFinite(ends) ? new Date(ends) : null;
|
|
3733
3691
|
}
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3692
|
+
function periodSlot(dayStart, timeZone, rule, openMinute, closeMinute) {
|
|
3693
|
+
const { ratePeriod, slot, checkInTime, checkOutTime } = rule;
|
|
3694
|
+
const at = (minutes) => atZonedMinute(dayStart, minutes, timeZone);
|
|
3695
|
+
if (ratePeriod === "night" /* NIGHT */) {
|
|
3696
|
+
if (!checkInTime || !checkOutTime) {
|
|
3697
|
+
throw new BookingRulesError("Overnight booking rules need both checkInTime and checkOutTime");
|
|
3698
|
+
}
|
|
3699
|
+
const checkIn = parseHhMm(checkInTime, "checkInTime");
|
|
3700
|
+
const checkOut = parseHhMm(checkOutTime, "checkOutTime");
|
|
3701
|
+
return {
|
|
3702
|
+
startAt: at(checkIn),
|
|
3703
|
+
endAt: at(1440 + checkOut),
|
|
3704
|
+
// Housekeeping sits between check-out and the next check-in: it costs no night.
|
|
3705
|
+
bufferEndAt: at(1440 + checkIn),
|
|
3706
|
+
canStart: true
|
|
3707
|
+
};
|
|
3708
|
+
}
|
|
3709
|
+
const from = ratePeriod === "day" /* DAY */ ? openMinute ?? 0 : 0;
|
|
3710
|
+
const to = ratePeriod === "day" /* DAY */ ? closeMinute ?? 1440 : 1440;
|
|
3711
|
+
return {
|
|
3712
|
+
startAt: at(from),
|
|
3713
|
+
endAt: at(to),
|
|
3714
|
+
bufferEndAt: at(to + (slot.bufferMinutes ?? 0)),
|
|
3715
|
+
canStart: true
|
|
3716
|
+
};
|
|
3717
|
+
}
|
|
3718
|
+
function freeGaps(openAt, closeAt, busy) {
|
|
3719
|
+
const inside = busy.map(({ startAt, bufferEndAt }) => ({ from: +startAt, to: +bufferEndAt })).filter(({ from, to }) => to > openAt && from < closeAt).sort((first, second) => first.from - second.from);
|
|
3720
|
+
const gaps = [];
|
|
3721
|
+
let cursor = openAt;
|
|
3722
|
+
for (const { from, to } of inside) {
|
|
3723
|
+
if (from > cursor) gaps.push({ from: cursor, to: from, endsAtBooking: true });
|
|
3724
|
+
cursor = Math.max(cursor, to);
|
|
3725
|
+
if (cursor >= closeAt) break;
|
|
3726
|
+
}
|
|
3727
|
+
if (cursor < closeAt) gaps.push({ from: cursor, to: closeAt, endsAtBooking: false });
|
|
3728
|
+
return gaps;
|
|
3729
|
+
}
|
|
3730
|
+
function buildGrid(rule, timeZone, from, to, now, busy = []) {
|
|
3731
|
+
if (to.getTime() - from.getTime() > MAX_RANGE_DAYS * 1440 * MINUTE2) {
|
|
3732
|
+
throw new BookingRulesError(`A booking range may span at most ${MAX_RANGE_DAYS} days`);
|
|
3733
|
+
}
|
|
3734
|
+
const { availability, slot, window, ratePeriod } = rule;
|
|
3735
|
+
const periodMode = ratePeriod !== "slot" /* SLOT */;
|
|
3736
|
+
const weeklyHours = availability.weeklyHours ?? [];
|
|
3737
|
+
const notBefore = Math.max(
|
|
3738
|
+
now.getTime() + (window.minNoticeMinutes ?? 0) * MINUTE2,
|
|
3739
|
+
asTime(window.bookableFrom, "window.bookableFrom") ?? 0,
|
|
3740
|
+
asTime(availability.availableFrom, "availability.availableFrom") ?? 0
|
|
3741
|
+
);
|
|
3742
|
+
const notAfter = windowEndsAt(rule, now)?.getTime() ?? Number.POSITIVE_INFINITY;
|
|
3743
|
+
const blocked = (availability.offMarket ?? []).map(({ from: blockFrom, to: blockTo }) => ({
|
|
3744
|
+
from: asTime(blockFrom, "availability.offMarket.from"),
|
|
3745
|
+
to: asTime(blockTo, "availability.offMarket.to")
|
|
3746
|
+
}));
|
|
3747
|
+
const arrivalDays = availability.arrivalDays;
|
|
3748
|
+
const step = slot.lengthMinutes + (slot.bufferMinutes ?? 0);
|
|
3749
|
+
const slots = [];
|
|
3750
|
+
const lastDay = startOfZonedDay(to, timeZone).getTime();
|
|
3751
|
+
let dayStart = startOfZonedDay(from, timeZone);
|
|
3752
|
+
while (dayStart.getTime() <= lastDay) {
|
|
3753
|
+
const weekday = zonedParts(dayStart, timeZone).weekday;
|
|
3754
|
+
const rows = weeklyHours.filter((entry) => entry.weekday === weekday);
|
|
3755
|
+
if (periodMode) {
|
|
3756
|
+
const openToday = weeklyHours.length === 0 || rows.length > 0;
|
|
3757
|
+
if (openToday) {
|
|
3758
|
+
const built = periodSlot(dayStart, timeZone, rule, rows[0]?.openMinute, rows[0]?.closeMinute);
|
|
3759
|
+
slots.push({ ...built, canStart: !arrivalDays?.length || arrivalDays.includes(weekday) });
|
|
3760
|
+
}
|
|
3761
|
+
} else {
|
|
3762
|
+
for (const row of rows) {
|
|
3763
|
+
const openAt = +atZonedMinute(dayStart, row.openMinute, timeZone);
|
|
3764
|
+
const closeAt = +atZonedMinute(dayStart, row.closeMinute, timeZone);
|
|
3765
|
+
for (const gap of freeGaps(openAt, closeAt, busy)) {
|
|
3766
|
+
const mustFit = (gap.endsAtBooking ? step : slot.lengthMinutes) * MINUTE2;
|
|
3767
|
+
for (let start = gap.from; start + mustFit <= gap.to; start += step * MINUTE2) {
|
|
3768
|
+
slots.push({
|
|
3769
|
+
startAt: new Date(start),
|
|
3770
|
+
endAt: new Date(start + slot.lengthMinutes * MINUTE2),
|
|
3771
|
+
bufferEndAt: new Date(start + step * MINUTE2),
|
|
3772
|
+
canStart: true
|
|
3773
|
+
});
|
|
3774
|
+
}
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3778
|
+
dayStart = nextZonedDay(dayStart, timeZone);
|
|
3779
|
+
}
|
|
3780
|
+
const askedFrom = from.getTime();
|
|
3781
|
+
const askedTo = to.getTime();
|
|
3782
|
+
return slots.filter(({ startAt, bufferEndAt }) => {
|
|
3783
|
+
const start = startAt.getTime();
|
|
3784
|
+
if (start < askedFrom || start >= askedTo) return false;
|
|
3785
|
+
if (start < notBefore || start > notAfter) return false;
|
|
3786
|
+
return !blocked.some(
|
|
3787
|
+
({ from: blockFrom, to: blockTo }) => start < blockTo && bufferEndAt.getTime() > blockFrom
|
|
3788
|
+
);
|
|
3789
|
+
}).sort((first, second) => +first.startAt - +second.startAt);
|
|
3790
|
+
}
|
|
3791
|
+
function slotsForWindow(grid, startAt, endAt) {
|
|
3792
|
+
const startIndex = grid.findIndex((entry) => entry.startAt.getTime() === startAt.getTime());
|
|
3793
|
+
if (startIndex < 0) {
|
|
3794
|
+
throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
|
|
3795
|
+
}
|
|
3796
|
+
if (!grid[startIndex].canStart) {
|
|
3797
|
+
throw new BookingRulesError(`${startAt.toISOString()} is not an arrival day for these rules`);
|
|
3798
|
+
}
|
|
3799
|
+
const covered = [];
|
|
3800
|
+
for (let index = startIndex; index < grid.length; index++) {
|
|
3801
|
+
const entry = grid[index];
|
|
3802
|
+
const previous = covered[covered.length - 1];
|
|
3803
|
+
if (previous && entry.startAt.getTime() !== previous.bufferEndAt.getTime()) break;
|
|
3804
|
+
covered.push(entry);
|
|
3805
|
+
if (entry.endAt.getTime() === endAt.getTime()) return covered;
|
|
3806
|
+
if (entry.endAt.getTime() > endAt.getTime()) break;
|
|
3807
|
+
}
|
|
3808
|
+
throw new BookingRulesError(
|
|
3809
|
+
`${startAt.toISOString()} \u2192 ${endAt.toISOString()} does not line up with the bookable grid`
|
|
3810
|
+
);
|
|
3751
3811
|
}
|
|
3752
3812
|
|
|
3753
3813
|
// booking/availability.ts
|
|
3754
|
-
var placesOnTheWire = (entry) => Number.isFinite(entry.capacity) ? entry : { ...entry, capacity: UNLIMITED_PLACES, free: UNLIMITED_PLACES, unlimited: true };
|
|
3755
3814
|
var withinPresence = (slot, timeZone, presence) => {
|
|
3756
3815
|
if (!presence?.length) return true;
|
|
3757
3816
|
const dayStart = startOfZonedDay(slot.startAt, timeZone);
|
|
@@ -3769,11 +3828,6 @@ function occupancyIn(occupied, productId, startAt, bufferEndAt, shared) {
|
|
|
3769
3828
|
foreignProductId: foreign?.productId
|
|
3770
3829
|
};
|
|
3771
3830
|
}
|
|
3772
|
-
var inEveryOutletPool = (entry) => !entry.outletId;
|
|
3773
|
-
function occupiedAtOutlet(occupied, rule, outletId) {
|
|
3774
|
-
if (bookingMethodOf(rule) !== "sessions" || !outletId) return occupied;
|
|
3775
|
-
return occupied.filter((entry) => inEveryOutletPool(entry) || entry.outletId === outletId);
|
|
3776
|
-
}
|
|
3777
3831
|
var stateFor = (hasShift, offerable, free) => {
|
|
3778
3832
|
if (offerable === 0) {
|
|
3779
3833
|
return hasShift() ? "fullyBooked" /* FULLY_BOOKED */ : "noHoursInRange" /* NO_HOURS_IN_RANGE */;
|
|
@@ -3803,36 +3857,26 @@ function shopDayRange(fromDayKey, count, timeZone) {
|
|
|
3803
3857
|
function buildAvailability({
|
|
3804
3858
|
productId,
|
|
3805
3859
|
bookingRulesId,
|
|
3860
|
+
bookingType,
|
|
3806
3861
|
rule,
|
|
3807
3862
|
resources,
|
|
3808
|
-
occupied
|
|
3809
|
-
outletId,
|
|
3863
|
+
occupied,
|
|
3810
3864
|
from,
|
|
3811
3865
|
to,
|
|
3812
|
-
now
|
|
3813
|
-
timeZone
|
|
3866
|
+
now
|
|
3814
3867
|
}) {
|
|
3815
|
-
const occupied = occupiedAtOutlet(everyOutlet, rule, outletId);
|
|
3816
3868
|
const shared = rule.slot.sharedAcrossProducts ?? false;
|
|
3817
|
-
const bookableUntil =
|
|
3818
|
-
const parts = bookingRuleParts(rule);
|
|
3869
|
+
const bookableUntil = windowEndsAt(rule, now);
|
|
3819
3870
|
const header = {
|
|
3820
3871
|
productId,
|
|
3821
3872
|
bookingRulesId,
|
|
3873
|
+
bookingType,
|
|
3822
3874
|
ratePeriod: rule.ratePeriod,
|
|
3823
|
-
// Time slots / sessions / date ranges — so a reader never re-classifies `ratePeriod` itself.
|
|
3824
|
-
bookingMethod: bookingMethodOf(rule),
|
|
3825
3875
|
// Passed through for the UI to label: a group slot under minimumToRun may not run.
|
|
3826
3876
|
minimumToRun: rule.slot.minimumToRun,
|
|
3827
3877
|
minStay: rule.slot.minStay,
|
|
3828
3878
|
maxStay: rule.slot.maxStay,
|
|
3829
|
-
//
|
|
3830
|
-
minStayLength: parts.method === "date-ranges" ? parts.minStay : void 0,
|
|
3831
|
-
maxStayLength: parts.method === "date-ranges" ? parts.maxStay : void 0,
|
|
3832
|
-
// The per-booking limits, so a stepper is bounded by the rules (G7) instead of a number in the flow.
|
|
3833
|
-
maxQtyPerBooking: rule.slot.maxQtyPerBooking,
|
|
3834
|
-
maxPartySize: rule.slot.maxPartySize,
|
|
3835
|
-
// Why a day can come back empty. Past this instant the rule refuses every start, so the UI
|
|
3879
|
+
// Why a day can come back empty. Past this instant the rule refuses everything, so the UI
|
|
3836
3880
|
// can say "beyond the booking window" where it would otherwise claim "nothing free".
|
|
3837
3881
|
bookableUntil,
|
|
3838
3882
|
// The comparison itself, not just the boundary: deciding whether a day lies past the
|
|
@@ -3855,7 +3899,7 @@ function buildAvailability({
|
|
|
3855
3899
|
const byInstant = /* @__PURE__ */ new Map();
|
|
3856
3900
|
const freeSlotsPerResource = /* @__PURE__ */ new Map();
|
|
3857
3901
|
for (const { resource, slots: slots2 } of grids) {
|
|
3858
|
-
const capacity =
|
|
3902
|
+
const capacity = resource.seats ?? 1;
|
|
3859
3903
|
const mine = byResource.get(resource.id) ?? [];
|
|
3860
3904
|
for (const slot of slots2) {
|
|
3861
3905
|
const { taken, foreignProductId } = occupancyIn(mine, productId, slot.startAt, slot.bufferEndAt, shared);
|
|
@@ -3872,9 +3916,7 @@ function buildAvailability({
|
|
|
3872
3916
|
entry.booked += foreignProductId ? capacity : taken;
|
|
3873
3917
|
entry.free += free;
|
|
3874
3918
|
entry.canStart = entry.canStart || slot.canStart;
|
|
3875
|
-
entry.resources.push(
|
|
3876
|
-
placesOnTheWire({ resourceId: resource.id, name: resource.name, capacity, booked: taken, free })
|
|
3877
|
-
);
|
|
3919
|
+
entry.resources.push({ resourceId: resource.id, name: resource.name, capacity, booked: taken, free });
|
|
3878
3920
|
if (free > 0) freeSlotsPerResource.set(resource.id, (freeSlotsPerResource.get(resource.id) ?? 0) + 1);
|
|
3879
3921
|
byInstant.set(+slot.startAt, entry);
|
|
3880
3922
|
}
|
|
@@ -3896,10 +3938,9 @@ function buildAvailability({
|
|
|
3896
3938
|
)
|
|
3897
3939
|
};
|
|
3898
3940
|
});
|
|
3899
|
-
const slots = [...byInstant.values()].
|
|
3941
|
+
const slots = [...byInstant.values()].sort((first, second) => +first.startAt - +second.startAt);
|
|
3900
3942
|
return {
|
|
3901
3943
|
...header,
|
|
3902
|
-
course: soldAsCourse(rule) ? courseAvailability(rule, resources, byResource, productId, shared, now) : void 0,
|
|
3903
3944
|
resources: inWindow,
|
|
3904
3945
|
slots,
|
|
3905
3946
|
/**
|
|
@@ -3911,53 +3952,6 @@ function buildAvailability({
|
|
|
3911
3952
|
days: [...new Set(slots.map((slot) => slot.dayKey))]
|
|
3912
3953
|
};
|
|
3913
3954
|
}
|
|
3914
|
-
function courseAvailability(rule, resources, byResource, productId, shared, now) {
|
|
3915
|
-
if (resources.length === 0) return void 0;
|
|
3916
|
-
const sessions = courseSessions(rule, resources[0].timeZone);
|
|
3917
|
-
const alreadyStarted = courseStartedInZone(rule, sessions, now, resources[0].timeZone);
|
|
3918
|
-
const beyondWindow = startsPastMaxAdvance(rule, sessions[0].startAt, now, resources[0].timeZone);
|
|
3919
|
-
const free = resources.map((resource) => {
|
|
3920
|
-
const mine = byResource.get(resource.id) ?? [];
|
|
3921
|
-
const everySession = sessions.every((session) => withinPresence(session, resource.timeZone, resource.presence));
|
|
3922
|
-
const freePerSession = sessions.map((session) => {
|
|
3923
|
-
const { taken, foreignProductId } = occupancyIn(mine, productId, session.startAt, session.bufferEndAt, shared);
|
|
3924
|
-
return foreignProductId ? 0 : Math.max(capacityOf(rule, resource) - taken, 0);
|
|
3925
|
-
});
|
|
3926
|
-
const fewest = everySession && !alreadyStarted && !beyondWindow ? Math.min(...freePerSession) : 0;
|
|
3927
|
-
return Number.isFinite(fewest) ? { resourceId: resource.id, free: fewest } : { resourceId: resource.id, free: UNLIMITED_PLACES, unlimited: true };
|
|
3928
|
-
});
|
|
3929
|
-
return withMaxQtyNow(
|
|
3930
|
-
{
|
|
3931
|
-
sessions: sessions.length,
|
|
3932
|
-
alreadyStarted,
|
|
3933
|
-
beyondWindow,
|
|
3934
|
-
sessionTimes: sessions.map(({ startAt, endAt }) => ({ startAt, endAt })),
|
|
3935
|
-
startAt: sessions[0].startAt,
|
|
3936
|
-
endAt: sessions[sessions.length - 1].endAt,
|
|
3937
|
-
resources: free
|
|
3938
|
-
},
|
|
3939
|
-
free,
|
|
3940
|
-
rule.slot.maxQtyPerBooking
|
|
3941
|
-
);
|
|
3942
|
-
}
|
|
3943
|
-
function pickFreeResource(slot, qty = 1) {
|
|
3944
|
-
return slot.resources.find((entry) => entry.free >= qty);
|
|
3945
|
-
}
|
|
3946
|
-
function withMaxQtyNow(entry, resources, maxQtyPerBooking) {
|
|
3947
|
-
const largest = resources.some((resource) => resource.unlimited) ? Number.POSITIVE_INFINITY : Math.max(0, ...resources.map((resource) => resource.free));
|
|
3948
|
-
const maxQtyNow = Math.min(largest, maxQtyPerBooking ?? Number.POSITIVE_INFINITY);
|
|
3949
|
-
return Number.isFinite(maxQtyNow) ? { ...entry, maxQtyNow } : entry;
|
|
3950
|
-
}
|
|
3951
|
-
function fewestFreeOver(slots, from, to) {
|
|
3952
|
-
const cells = slots.filter(({ startAt, endAt }) => +startAt >= +from && +endAt <= +to);
|
|
3953
|
-
if (cells.length === 0) return [];
|
|
3954
|
-
return cells[0].resources.map((resource) => ({
|
|
3955
|
-
...resource,
|
|
3956
|
-
free: Math.min(
|
|
3957
|
-
...cells.map((cell) => cell.resources.find(({ resourceId }) => resourceId === resource.resourceId)?.free ?? 0)
|
|
3958
|
-
)
|
|
3959
|
-
}));
|
|
3960
|
-
}
|
|
3961
3955
|
function presentAt(resources, rows, outletId) {
|
|
3962
3956
|
const byResource = /* @__PURE__ */ new Map();
|
|
3963
3957
|
for (const row of rows) {
|
|
@@ -3971,846 +3965,24 @@ function presentAt(resources, rows, outletId) {
|
|
|
3971
3965
|
});
|
|
3972
3966
|
}
|
|
3973
3967
|
|
|
3974
|
-
// booking/durations.ts
|
|
3975
|
-
var { MINUTE: MINUTE2, HOUR, DAY, NIGHT, WEEK, MONTH } = BookingDurationUnit;
|
|
3976
|
-
var NONE = [];
|
|
3977
|
-
var CLOCK = [MINUTE2, HOUR];
|
|
3978
|
-
var everyType = (units) => Object.fromEntries(Object.values(BookingRatePeriod).map((ratePeriod) => [ratePeriod, units]));
|
|
3979
|
-
var STAY = {
|
|
3980
|
-
slot: NONE,
|
|
3981
|
-
session: NONE,
|
|
3982
|
-
hour: [HOUR, DAY, WEEK],
|
|
3983
|
-
night: [NIGHT, WEEK, MONTH],
|
|
3984
|
-
day: [DAY, WEEK, MONTH],
|
|
3985
|
-
week: [WEEK],
|
|
3986
|
-
month: [MONTH]
|
|
3987
|
-
};
|
|
3988
|
-
var ALLOWED_UNITS = {
|
|
3989
|
-
"timeSlots.length": { ...everyType(NONE), slot: CLOCK },
|
|
3990
|
-
"slot.buffer": { ...everyType(CLOCK), night: NONE },
|
|
3991
|
-
"window.hold": everyType(CLOCK),
|
|
3992
|
-
"window.minNotice": everyType([MINUTE2, HOUR, DAY, WEEK]),
|
|
3993
|
-
"window.maxAdvance": everyType([MINUTE2, HOUR, DAY, WEEK, MONTH]),
|
|
3994
|
-
"dateRanges.minStay": STAY,
|
|
3995
|
-
"dateRanges.maxStay": STAY
|
|
3996
|
-
};
|
|
3997
|
-
function allowedDurationUnits(rule, field) {
|
|
3998
|
-
const units = ALLOWED_UNITS[field]?.[rule.ratePeriod];
|
|
3999
|
-
if (!units) throw new BookingRulesError(`Booking rules: no duration "${field}" for rate period "${rule.ratePeriod}"`);
|
|
4000
|
-
return units;
|
|
4001
|
-
}
|
|
4002
|
-
var DURATION_AT = {
|
|
4003
|
-
"timeSlots.length": (rule) => rule.timeSlots?.length,
|
|
4004
|
-
"slot.buffer": (rule) => rule.slot.buffer,
|
|
4005
|
-
"window.hold": (rule) => rule.window.hold,
|
|
4006
|
-
"window.minNotice": (rule) => rule.window.minNotice,
|
|
4007
|
-
"window.maxAdvance": (rule) => rule.window.maxAdvance,
|
|
4008
|
-
"dateRanges.minStay": (rule) => rule.dateRanges?.minStay,
|
|
4009
|
-
"dateRanges.maxStay": (rule) => rule.dateRanges?.maxStay
|
|
4010
|
-
};
|
|
4011
|
-
function durationProblems(rule) {
|
|
4012
|
-
const problems = Object.keys(DURATION_AT).flatMap((field) => {
|
|
4013
|
-
const duration = DURATION_AT[field](rule);
|
|
4014
|
-
const problem = duration && problemOf(field, duration, allowedDurationUnits(rule, field), rule.ratePeriod);
|
|
4015
|
-
return problem ? [problem] : [];
|
|
4016
|
-
});
|
|
4017
|
-
if (problems.length > 0) return problems;
|
|
4018
|
-
return [stayAboveMax(rule.dateRanges?.minStay, rule.dateRanges?.maxStay), noticeAboveAdvance(rule.window)].filter(
|
|
4019
|
-
(problem) => !!problem
|
|
4020
|
-
);
|
|
4021
|
-
}
|
|
4022
|
-
function problemOf(field, duration, allowed, ratePeriod) {
|
|
4023
|
-
if (!Number.isInteger(duration.count) || duration.count < 1) {
|
|
4024
|
-
const message = `${field}: count must be a whole number of at least 1, got ${String(duration.count)}`;
|
|
4025
|
-
return { field, kind: "count", message };
|
|
4026
|
-
}
|
|
4027
|
-
if (allowed.length === 0) {
|
|
4028
|
-
return { field, kind: "not-for-type", message: `${field}: does not apply to ${ratePeriod} rules` };
|
|
4029
|
-
}
|
|
4030
|
-
if (!allowed.includes(duration.unit)) {
|
|
4031
|
-
return { field, kind: "unit", allowed, message: `${field}: takes ${allowed.join(", ")}, got ${duration.unit}` };
|
|
4032
|
-
}
|
|
4033
|
-
return void 0;
|
|
4034
|
-
}
|
|
4035
|
-
var MINUTES_RANGE = {
|
|
4036
|
-
minute: [1, 1],
|
|
4037
|
-
hour: [60, 60],
|
|
4038
|
-
day: [1440, 1440],
|
|
4039
|
-
night: [1440, 1440],
|
|
4040
|
-
week: [7 * 1440, 7 * 1440],
|
|
4041
|
-
month: [28 * 1440, 31 * 1440]
|
|
4042
|
-
};
|
|
4043
|
-
var clockShiftOf = (unit2) => unit2 === MINUTE2 || unit2 === HOUR ? 0 : 60;
|
|
4044
|
-
var shortestMinutesOf = ({ count, unit: unit2 }) => count * MINUTES_RANGE[unit2][0] - clockShiftOf(unit2);
|
|
4045
|
-
var longestMinutesOf = ({ count, unit: unit2 }) => count * MINUTES_RANGE[unit2][1] + clockShiftOf(unit2);
|
|
4046
|
-
var durationText = ({ count, unit: unit2 }) => `${count} ${unit2}${count === 1 ? "" : "s"}`;
|
|
4047
|
-
var DAYS_IN_UNIT = { day: 1, night: 1, week: 7 };
|
|
4048
|
-
var MINUTES_IN_UNIT = { minute: 1, hour: 60 };
|
|
4049
|
-
function exactly(min, max) {
|
|
4050
|
-
if (min.unit === max.unit) return [min.count, max.count];
|
|
4051
|
-
for (const table of [DAYS_IN_UNIT, MINUTES_IN_UNIT]) {
|
|
4052
|
-
const [minSize, maxSize] = [table[min.unit], table[max.unit]];
|
|
4053
|
-
if (minSize && maxSize) return [min.count * minSize, max.count * maxSize];
|
|
4054
|
-
}
|
|
4055
|
-
return void 0;
|
|
4056
|
-
}
|
|
4057
|
-
function minLongerThanMax(min, max) {
|
|
4058
|
-
const exact = exactly(min, max);
|
|
4059
|
-
return exact ? exact[0] > exact[1] : longestMinutesOf(min) > shortestMinutesOf(max);
|
|
4060
|
-
}
|
|
4061
|
-
function stayAboveMax(min, max) {
|
|
4062
|
-
if (!min || !max || !minLongerThanMax(min, max)) return void 0;
|
|
4063
|
-
const message = `dateRanges.maxStay: Max ${durationText(max)} can be shorter than Min ${durationText(min)}`;
|
|
4064
|
-
return { field: "dateRanges.maxStay", kind: "min-above-max", min, max, message };
|
|
4065
|
-
}
|
|
4066
|
-
function noticeAboveAdvance({
|
|
4067
|
-
minNotice,
|
|
4068
|
-
maxAdvance
|
|
4069
|
-
}) {
|
|
4070
|
-
if (!minNotice || !maxAdvance || !minLongerThanMax(minNotice, maxAdvance)) return void 0;
|
|
4071
|
-
const message = `window.maxAdvance: ${durationText(maxAdvance)} ahead can be shorter than the notice of ${durationText(minNotice)}`;
|
|
4072
|
-
return { field: "window.maxAdvance", kind: "min-above-max", min: minNotice, max: maxAdvance, message };
|
|
4073
|
-
}
|
|
4074
|
-
|
|
4075
3968
|
// booking/plan.ts
|
|
4076
3969
|
var DEFAULT_HOLD_MINUTES = 10;
|
|
4077
3970
|
function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }) {
|
|
4078
|
-
if (!soldAsCourse(rule)) checkStartWithinMaxAdvance(rule, timeZone, startAt, now);
|
|
4079
3971
|
const grid = buildGrid(rule, timeZone, startAt, endAt, now, busy).filter(
|
|
4080
3972
|
(slot) => withinPresence(slot, timeZone, presence)
|
|
4081
3973
|
);
|
|
4082
3974
|
const slots = slotsForWindow(grid, startAt, endAt);
|
|
4083
|
-
const
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
const periods = wholePeriods ? wholePeriodsIn(rule.ratePeriod, timeZone, startAt, last.endAt, slots.length) : slots.length;
|
|
4087
|
-
checkStay(parts, timeZone, startAt, periods);
|
|
4088
|
-
const { buffer } = ruleDurationsOf(rule);
|
|
4089
|
-
const bufferEndAt = rule.ratePeriod === "hour" /* HOUR */ || wholePeriods ? buffer ? addDuration(last.endAt, buffer, timeZone) : new Date(last.endAt.getTime()) : last.bufferEndAt;
|
|
4090
|
-
return { slots, periods, endAt: last.endAt, bufferEndAt };
|
|
4091
|
-
}
|
|
4092
|
-
function checkStartWithinMaxAdvance(rule, timeZone, startAt, now) {
|
|
4093
|
-
if (startsPastMaxAdvance(rule, startAt, now, timeZone)) {
|
|
4094
|
-
throw new BookingRulesError(`${startAt.toISOString()} is past the booking window of these rules`);
|
|
4095
|
-
}
|
|
4096
|
-
}
|
|
4097
|
-
function checkStay(parts, timeZone, startAt, periods) {
|
|
4098
|
-
if (parts.method !== "date-ranges") return;
|
|
4099
|
-
const stay = { count: periods, unit: periodUnitOf(parts) };
|
|
4100
|
-
const length = (duration) => stayLength(parts.ratePeriod, duration, startAt, timeZone);
|
|
4101
|
-
const { minStay, maxStay } = parts;
|
|
4102
|
-
if (minStay && length(stay) < length(minStay)) {
|
|
4103
|
-
throw new BookingRulesError(
|
|
4104
|
-
`These rules ask for a stay of at least ${durationText(minStay)}, got ${durationText(stay)}`
|
|
4105
|
-
);
|
|
4106
|
-
}
|
|
4107
|
-
if (maxStay && length(stay) > length(maxStay)) {
|
|
4108
|
-
throw new BookingRulesError(
|
|
4109
|
-
`These rules allow a stay of at most ${durationText(maxStay)}, got ${durationText(stay)}`
|
|
4110
|
-
);
|
|
4111
|
-
}
|
|
4112
|
-
}
|
|
4113
|
-
function stayLength(ratePeriod, duration, startAt, timeZone) {
|
|
4114
|
-
if (ratePeriod === "hour" /* HOUR */) return addDuration(startAt, duration, timeZone).getTime();
|
|
4115
|
-
const { count, unit: unit2 } = duration;
|
|
4116
|
-
if (unit2 === "day" /* DAY */ || unit2 === "night" /* NIGHT */) return count;
|
|
4117
|
-
if (unit2 === "week" /* WEEK */) return 7 * count;
|
|
4118
|
-
if (unit2 !== "month" /* MONTH */) {
|
|
4119
|
-
throw new BookingRulesError(`Booking rules: a ${ratePeriod} stay cannot be counted in ${unit2}s`);
|
|
4120
|
-
}
|
|
4121
|
-
const { year, month, day } = zonedParts(startAt, timeZone);
|
|
4122
|
-
const [toYear, toMonth, toDay] = sameDayMonthsLaterDate(year, month, day, count);
|
|
4123
|
-
return (Date.UTC(toYear, toMonth - 1, toDay) - Date.UTC(year, month - 1, day)) / 864e5;
|
|
4124
|
-
}
|
|
4125
|
-
function windowForPeriods({ rule, timeZone, startAt, periods, now }) {
|
|
4126
|
-
if (!Number.isInteger(periods) || periods < 1) {
|
|
4127
|
-
throw new BookingRulesError(`periods must be a whole number of at least 1, got ${String(periods)}`);
|
|
4128
|
-
}
|
|
4129
|
-
checkStartWithinMaxAdvance(rule, timeZone, startAt, now);
|
|
4130
|
-
const parts = bookingRuleParts(rule);
|
|
4131
|
-
checkStay(parts, timeZone, startAt, periods);
|
|
4132
|
-
const wholePeriods = parts.method === "date-ranges" && parts.wholePeriods;
|
|
4133
|
-
const monthsEnd = wholePeriods && rule.ratePeriod === "month" /* MONTH */ ? sameDayMonthsLater(startAt, periods, timeZone) : null;
|
|
4134
|
-
const cells = wholePeriods && rule.ratePeriod === "week" /* WEEK */ ? periods * 7 : periods;
|
|
4135
|
-
const lastDay = monthsEnd ?? new Date(startAt.getTime() + (cells + 2) * 1440 * 6e4);
|
|
4136
|
-
const grid = buildGrid(
|
|
4137
|
-
rule,
|
|
4138
|
-
timeZone,
|
|
4139
|
-
startAt,
|
|
4140
|
-
new Date(Math.min(lastDay.getTime() + 1440 * 6e4, startAt.getTime() + 366 * 1440 * 6e4)),
|
|
4141
|
-
now
|
|
4142
|
-
);
|
|
4143
|
-
const startIndex = grid.findIndex((cell) => cell.startAt.getTime() === startAt.getTime());
|
|
4144
|
-
if (startIndex < 0)
|
|
4145
|
-
throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
|
|
4146
|
-
const endAt = monthsEnd ?? grid[startIndex + cells - 1]?.endAt;
|
|
4147
|
-
if (!endAt)
|
|
4148
|
-
throw new BookingRulesError(`${periods} period(s) from ${startAt.toISOString()} run past the bookable grid`);
|
|
4149
|
-
slotsForWindow(grid, startAt, endAt);
|
|
4150
|
-
return { startAt, endAt };
|
|
4151
|
-
}
|
|
4152
|
-
function rentalEnds(input) {
|
|
4153
|
-
const { rule, timeZone, startAt, now, untilDay } = input;
|
|
4154
|
-
const parts = bookingRuleParts(rule);
|
|
4155
|
-
if (parts.method !== "date-ranges") throw new BookingRulesError("Only date-range rules book a stay");
|
|
4156
|
-
checkStartWithinMaxAdvance(rule, timeZone, startAt, now);
|
|
4157
|
-
const horizon = shopDayRange(untilDay, 1, timeZone).to;
|
|
4158
|
-
if (horizon <= startAt) throw new BookingRulesError(`untilDay ${untilDay} is before the stay starts`);
|
|
4159
|
-
const gridUntil = (end) => buildGrid(rule, timeZone, startAt, new Date(Math.min(end, startAt.getTime() + 366 * 1440 * 6e4)), now);
|
|
4160
|
-
let walk = walkRentalEnds(gridUntil(horizon.getTime() + 1440 * 6e4), input, parts, horizon);
|
|
4161
|
-
if (!walk.ends.length && walk.refusal && walk.ranOut)
|
|
4162
|
-
walk = walkRentalEnds(gridUntil(Infinity), input, parts, horizon);
|
|
4163
|
-
if (walk.ends.length) return walk.ends;
|
|
4164
|
-
throw walk.refusal ?? new BookingRulesError(
|
|
4165
|
-
`No stay from ${startAt.toISOString()} fits these rules: the bookable days run out before the shortest allowed stay`
|
|
4166
|
-
);
|
|
4167
|
-
}
|
|
4168
|
-
function walkRentalEnds(grid, { rule, timeZone, startAt, untilDay }, parts, horizon) {
|
|
4169
|
-
const startIndex = grid.findIndex((cell) => cell.startAt.getTime() === startAt.getTime());
|
|
4170
|
-
if (startIndex < 0) {
|
|
4171
|
-
throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
|
|
4172
|
-
}
|
|
4173
|
-
slotsForWindow(grid, startAt, grid[startIndex].endAt);
|
|
4174
|
-
const ends = [];
|
|
4175
|
-
let refusal;
|
|
4176
|
-
for (const cell of grid.slice(startIndex)) {
|
|
4177
|
-
if (cell.endAt > horizon && (ends.length || !refusal)) {
|
|
4178
|
-
refusal ??= new BookingRulesError(`No stay from ${startAt.toISOString()} ends on or before ${untilDay}`);
|
|
4179
|
-
return { ends, refusal, ranOut: false };
|
|
4180
|
-
}
|
|
4181
|
-
const slots = refusalOr(() => slotsForWindow(grid, startAt, cell.endAt));
|
|
4182
|
-
if (slots instanceof BookingRulesError) return { ends, refusal, ranOut: false };
|
|
4183
|
-
const periods = refusalOr(
|
|
4184
|
-
() => parts.wholePeriods ? wholePeriodsIn(rule.ratePeriod, timeZone, startAt, cell.endAt, slots.length) : slots.length
|
|
4185
|
-
);
|
|
4186
|
-
if (periods instanceof BookingRulesError) continue;
|
|
4187
|
-
const stay = refusalOr(() => checkStay(parts, timeZone, startAt, periods));
|
|
4188
|
-
if (stay instanceof BookingRulesError) {
|
|
4189
|
-
if (ends.length) return { ends, refusal, ranOut: false };
|
|
4190
|
-
refusal = stay;
|
|
4191
|
-
continue;
|
|
4192
|
-
}
|
|
4193
|
-
ends.push(rentalEndOf(slots, periods, timeZone));
|
|
4194
|
-
}
|
|
4195
|
-
return { ends, refusal, ranOut: true };
|
|
4196
|
-
}
|
|
4197
|
-
function rentalEndOf(slots, periods, timeZone) {
|
|
4198
|
-
const endAt = slots[slots.length - 1].endAt;
|
|
4199
|
-
return {
|
|
4200
|
-
periods,
|
|
4201
|
-
endAt: endAt.toISOString(),
|
|
4202
|
-
lastDayKey: shopDayKey(new Date(endAt.getTime() - 1), timeZone),
|
|
4203
|
-
coveredSlots: slots.map((slot) => ({
|
|
4204
|
-
startAt: slot.startAt.toISOString(),
|
|
4205
|
-
dayKey: shopDayKey(slot.startAt, timeZone)
|
|
4206
|
-
}))
|
|
4207
|
-
};
|
|
4208
|
-
}
|
|
4209
|
-
function refusalOr(run) {
|
|
4210
|
-
try {
|
|
4211
|
-
return run();
|
|
4212
|
-
} catch (error) {
|
|
4213
|
-
if (error instanceof BookingRulesError) return error;
|
|
4214
|
-
throw error;
|
|
4215
|
-
}
|
|
4216
|
-
}
|
|
4217
|
-
function sameDayMonthsLater(startAt, months, timeZone) {
|
|
4218
|
-
const { year, month, day } = zonedParts(startAt, timeZone);
|
|
4219
|
-
return instantFromLocal(...sameDayMonthsLaterDate(year, month, day, months), 0, timeZone);
|
|
4220
|
-
}
|
|
4221
|
-
function wholePeriodsIn(ratePeriod, timeZone, startAt, endAt, days) {
|
|
4222
|
-
if (ratePeriod === "week" /* WEEK */) {
|
|
4223
|
-
if (days % 7 !== 0) throw new BookingRulesError(`Book whole weeks: ${days} day(s) is not a number of weeks`);
|
|
4224
|
-
return days / 7;
|
|
4225
|
-
}
|
|
4226
|
-
if (ratePeriod !== "month" /* MONTH */) {
|
|
4227
|
-
throw new BookingRulesError("Whole periods are for week and month rules only");
|
|
4228
|
-
}
|
|
4229
|
-
const start = zonedParts(startAt, timeZone);
|
|
4230
|
-
const end = zonedParts(endAt, timeZone);
|
|
4231
|
-
const months = (end.year - start.year) * 12 + (end.month - start.month);
|
|
4232
|
-
const lastDayOfEndMonth = new Date(Date.UTC(end.year, end.month, 0)).getUTCDate();
|
|
4233
|
-
if (months < 1 || end.day !== Math.min(start.day, lastDayOfEndMonth)) {
|
|
4234
|
-
throw new BookingRulesError("Book whole months: the stay must end on the same day of a later month");
|
|
4235
|
-
}
|
|
4236
|
-
return months;
|
|
4237
|
-
}
|
|
4238
|
-
function courseSessions(rule, timeZone) {
|
|
4239
|
-
const [from, to] = rule.sessions?.weekly?.length ? weeklyCourseRange(rule) : datesCourseRange(rule.sessions?.dates ?? [], timeZone);
|
|
4240
|
-
const sessions = sessionCells(rule, timeZone, from, to).sort((first, second) => +first.startAt - +second.startAt);
|
|
4241
|
-
if (sessions.length === 0) throw new BookingRulesError("These course dates hold no session");
|
|
4242
|
-
return sessions;
|
|
4243
|
-
}
|
|
4244
|
-
function courseSpan(rule, timeZone) {
|
|
4245
|
-
const sessions = courseSessions(rule, timeZone);
|
|
4246
|
-
return { from: sessions[0].startAt, to: sessions[sessions.length - 1].bufferEndAt };
|
|
4247
|
-
}
|
|
4248
|
-
function weeklyCourseRange(rule) {
|
|
4249
|
-
const { bookableFrom, bookableTo } = rule.window;
|
|
4250
|
-
if (!bookableFrom || !bookableTo) throw new BookingRulesError("A course needs both course dates");
|
|
4251
|
-
return [new Date(bookableFrom), new Date(bookableTo)];
|
|
4252
|
-
}
|
|
4253
|
-
function datesCourseRange(dates, timeZone) {
|
|
4254
|
-
if (dates.length === 0) throw new BookingRulesError("A course needs its sessions");
|
|
4255
|
-
const days = dates.map(({ date }) => date).sort();
|
|
4256
|
-
const [firstYear, firstMonth, firstDay] = calendarDate(days[0]);
|
|
4257
|
-
const [lastYear, lastMonth, lastDay] = calendarDate(days[days.length - 1]);
|
|
4258
|
-
return [
|
|
4259
|
-
instantFromLocal(firstYear, firstMonth, firstDay, 0, timeZone),
|
|
4260
|
-
instantFromLocal(lastYear, lastMonth, lastDay + 1, 0, timeZone)
|
|
4261
|
-
];
|
|
4262
|
-
}
|
|
4263
|
-
var courseStarted = (rule, sessions, now) => sessions[0].startAt.getTime() < now.getTime() + (rule.window.minNoticeMinutes ?? 0) * 6e4;
|
|
4264
|
-
function courseStartedInZone(rule, sessions, now, timeZone) {
|
|
4265
|
-
const { minNotice } = ruleDurationsOf(rule);
|
|
4266
|
-
return sessions[0].startAt.getTime() < (minNotice ? addDuration(now, minNotice, timeZone) : now).getTime();
|
|
4267
|
-
}
|
|
4268
|
-
function planCourse({ rule, timeZone, presence, now }) {
|
|
4269
|
-
const sessions = courseSessions(rule, timeZone);
|
|
4270
|
-
if (!sessions.every((session) => withinPresence(session, timeZone, presence))) {
|
|
4271
|
-
throw new BookingRulesError("This resource is not there for every session of the course");
|
|
4272
|
-
}
|
|
4273
|
-
if (courseStartedInZone(rule, sessions, now, timeZone))
|
|
4274
|
-
throw new BookingRulesError("This course has already started");
|
|
4275
|
-
if (startsPastMaxAdvance(rule, sessions[0].startAt, now, timeZone)) {
|
|
4276
|
-
throw new BookingRulesError("This course starts past the booking window of these rules");
|
|
4277
|
-
}
|
|
4278
|
-
return sessions;
|
|
4279
|
-
}
|
|
4280
|
-
function holdExpiresAt(rule, now) {
|
|
4281
|
-
return addClockDuration(now, holdOf(rule) ?? DEFAULT_HOLD);
|
|
4282
|
-
}
|
|
4283
|
-
var DEFAULT_HOLD = { count: DEFAULT_HOLD_MINUTES, unit: "minute" /* MINUTE */ };
|
|
4284
|
-
function holdOf(rule) {
|
|
4285
|
-
const { hold } = ruleDurationsOf(rule);
|
|
4286
|
-
if (!hold) return void 0;
|
|
4287
|
-
const field = rule.window.hold ? "window.hold" : "window.holdMinutes";
|
|
4288
|
-
if (!Number.isInteger(hold.count)) {
|
|
4289
|
-
throw new BookingRulesError(`${field} must be a whole number of ${hold.unit}s, got ${hold.count}`);
|
|
4290
|
-
}
|
|
4291
|
-
if (hold.count < 1) throw new BookingRulesError(`${field} must be at least 1 ${hold.unit}, got ${hold.count}`);
|
|
4292
|
-
return hold;
|
|
4293
|
-
}
|
|
4294
|
-
function checkQtyPerBooking(rule, qty) {
|
|
4295
|
-
const max = rule.slot.maxQtyPerBooking;
|
|
4296
|
-
if (max !== void 0 && qty > max) {
|
|
4297
|
-
throw new BookingRulesError(`These rules allow at most ${max} per booking, got ${qty}`);
|
|
4298
|
-
}
|
|
4299
|
-
}
|
|
4300
|
-
function checkPartySize(rule, partySize) {
|
|
4301
|
-
const max = rule.slot.maxPartySize;
|
|
4302
|
-
if (max !== void 0 && partySize > max) {
|
|
4303
|
-
throw new BookingRulesError(`These rules allow at most ${max} people per booking, got ${partySize}`);
|
|
4304
|
-
}
|
|
4305
|
-
}
|
|
4306
|
-
function bookingMethodOf(rule) {
|
|
4307
|
-
if (rule.ratePeriod === "slot" /* SLOT */) return "time-slots";
|
|
4308
|
-
if (rule.ratePeriod === "session" /* SESSION */) return "sessions";
|
|
4309
|
-
return "date-ranges";
|
|
4310
|
-
}
|
|
4311
|
-
var soldAsCourse = (rule) => rule.ratePeriod === "session" /* SESSION */ && rule.sessions?.sold === "course" /* COURSE */;
|
|
4312
|
-
function capacityOf(rule, resource) {
|
|
4313
|
-
if (rule.ratePeriod !== "session" /* SESSION */) return resource.seats ?? 1;
|
|
4314
|
-
if (!rule.sessions) throw new BookingRulesError("Scheduled-session rules need their sessions");
|
|
4315
|
-
return rule.sessions.spots ?? Number.POSITIVE_INFINITY;
|
|
4316
|
-
}
|
|
4317
|
-
function bookingRuleParts(rule) {
|
|
4318
|
-
const method = bookingMethodOf(rule);
|
|
4319
|
-
if (method === "sessions") {
|
|
4320
|
-
if (!rule.sessions) throw new BookingRulesError("Scheduled-session rules need their sessions");
|
|
4321
|
-
return { method, sessions: rule.sessions };
|
|
4322
|
-
}
|
|
4323
|
-
if (method === "time-slots") {
|
|
4324
|
-
const timeSlots = rule.timeSlots ? newTimeSlotsOf(rule.timeSlots) : oldTimeSlotsOf(rule);
|
|
4325
|
-
const { count } = timeSlots.length;
|
|
4326
|
-
if (!Number.isInteger(count) || count < 1) {
|
|
4327
|
-
const field = rule.timeSlots ? "timeSlots.length" : "slot.lengthMinutes";
|
|
4328
|
-
throw new BookingRulesError(`Booking rules: ${field} must be a whole number of at least 1, got ${count}`);
|
|
4329
|
-
}
|
|
4330
|
-
return { method, ...timeSlots };
|
|
3975
|
+
const { minStay, maxStay } = rule.slot;
|
|
3976
|
+
if (minStay && slots.length < minStay) {
|
|
3977
|
+
throw new BookingRulesError(`These rules ask for at least ${minStay} period(s), got ${slots.length}`);
|
|
4331
3978
|
}
|
|
4332
|
-
if (
|
|
4333
|
-
|
|
4334
|
-
return { method, ratePeriod: rule.ratePeriod, wholePeriods, ...rule.dateRanges };
|
|
4335
|
-
}
|
|
4336
|
-
function newTimeSlotsOf({ length, weeklyHours }) {
|
|
4337
|
-
if (!weeklyHours?.length) throw new BookingRulesError("Booking rules: timeSlots.weeklyHours needs at least one day");
|
|
4338
|
-
return { length, weeklyHours };
|
|
4339
|
-
}
|
|
4340
|
-
function oldTimeSlotsOf({ slot, availability }) {
|
|
4341
|
-
if (slot.lengthMinutes == null) throw new BookingRulesError("Time-slot rules need their slot length");
|
|
4342
|
-
return {
|
|
4343
|
-
length: { count: slot.lengthMinutes, unit: "minute" /* MINUTE */ },
|
|
4344
|
-
weeklyHours: availability.weeklyHours ?? []
|
|
4345
|
-
};
|
|
4346
|
-
}
|
|
4347
|
-
function oldDateRangesOf(rule) {
|
|
4348
|
-
const { slot, availability } = rule;
|
|
4349
|
-
const wholePeriods = slot.wholePeriods ?? false;
|
|
4350
|
-
const stay = (count) => count ? { count, unit: periodUnitOf({ ratePeriod: rule.ratePeriod, wholePeriods }) } : void 0;
|
|
4351
|
-
return {
|
|
4352
|
-
// Old `[]` meant "open every day" — the new form says that by having no rows.
|
|
4353
|
-
weeklyHours: availability.weeklyHours?.length ? availability.weeklyHours : void 0,
|
|
4354
|
-
arrivalDays: availability.arrivalDays,
|
|
4355
|
-
checkInTime: rule.checkInTime,
|
|
4356
|
-
checkOutTime: rule.checkOutTime,
|
|
4357
|
-
checkTimesByWeekday: rule.checkTimesByWeekday,
|
|
4358
|
-
minStay: stay(slot.minStay),
|
|
4359
|
-
maxStay: stay(slot.maxStay),
|
|
4360
|
-
wholePeriods
|
|
4361
|
-
};
|
|
4362
|
-
}
|
|
4363
|
-
function periodUnitOf({
|
|
4364
|
-
ratePeriod,
|
|
4365
|
-
wholePeriods
|
|
4366
|
-
}) {
|
|
4367
|
-
const units = {
|
|
4368
|
-
["hour" /* HOUR */]: "hour" /* HOUR */,
|
|
4369
|
-
["night" /* NIGHT */]: "night" /* NIGHT */,
|
|
4370
|
-
["day" /* DAY */]: "day" /* DAY */,
|
|
4371
|
-
["week" /* WEEK */]: wholePeriods ? "week" /* WEEK */ : "day" /* DAY */,
|
|
4372
|
-
["month" /* MONTH */]: wholePeriods ? "month" /* MONTH */ : "day" /* DAY */
|
|
4373
|
-
};
|
|
4374
|
-
const unit2 = units[ratePeriod];
|
|
4375
|
-
if (!unit2) throw new BookingRulesError(`Booking rules: "${ratePeriod}" is not a date-range rate period`);
|
|
4376
|
-
return unit2;
|
|
4377
|
-
}
|
|
4378
|
-
var OLD_BUFFER = {
|
|
4379
|
-
path: "slot.bufferMinutes",
|
|
4380
|
-
home: {
|
|
4381
|
-
"time-slots": "slot.buffer",
|
|
4382
|
-
sessions: "slot.buffer",
|
|
4383
|
-
// The old night grid never read it: housekeeping is the gap between check-out and check-in (O-1).
|
|
4384
|
-
"date-ranges": ({ ratePeriod }) => ratePeriod === "night" /* NIGHT */ ? { unread: "nights clean between check-out and check-in" } : "slot.buffer"
|
|
3979
|
+
if (maxStay && slots.length > maxStay) {
|
|
3980
|
+
throw new BookingRulesError(`These rules allow at most ${maxStay} period(s), got ${slots.length}`);
|
|
4385
3981
|
}
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
{
|
|
4389
|
-
path: "slot.lengthMinutes",
|
|
4390
|
-
home: {
|
|
4391
|
-
"time-slots": "timeSlots.length",
|
|
4392
|
-
sessions: { unread: "placeholder" },
|
|
4393
|
-
"date-ranges": { unread: "placeholder" }
|
|
4394
|
-
}
|
|
4395
|
-
},
|
|
4396
|
-
OLD_BUFFER,
|
|
4397
|
-
{
|
|
4398
|
-
path: "slot.minStay",
|
|
4399
|
-
home: {
|
|
4400
|
-
"time-slots": { dropped: "time-slots rules have no stay limits" },
|
|
4401
|
-
sessions: { dropped: "sessions rules have no stay limits" },
|
|
4402
|
-
"date-ranges": "dateRanges.minStay"
|
|
4403
|
-
}
|
|
4404
|
-
},
|
|
4405
|
-
{
|
|
4406
|
-
path: "slot.maxStay",
|
|
4407
|
-
home: {
|
|
4408
|
-
"time-slots": { dropped: "time-slots rules have no stay limits" },
|
|
4409
|
-
sessions: { dropped: "sessions rules have no stay limits" },
|
|
4410
|
-
"date-ranges": "dateRanges.maxStay"
|
|
4411
|
-
}
|
|
4412
|
-
},
|
|
4413
|
-
{
|
|
4414
|
-
path: "window.holdMinutes",
|
|
4415
|
-
home: { "time-slots": "window.hold", sessions: "window.hold", "date-ranges": "window.hold" }
|
|
4416
|
-
},
|
|
4417
|
-
{
|
|
4418
|
-
path: "window.minNoticeMinutes",
|
|
4419
|
-
home: { "time-slots": "window.minNotice", sessions: "window.minNotice", "date-ranges": "window.minNotice" }
|
|
4420
|
-
},
|
|
4421
|
-
// The two old max-advance fields are one fact, as the old readers took it: minutes, else days × 1440.
|
|
4422
|
-
...["window.maxAdvanceMinutes", "window.maxAdvanceDays"].map((path) => ({
|
|
4423
|
-
path,
|
|
4424
|
-
carried: maxAdvanceMinutesOf,
|
|
4425
|
-
home: { "time-slots": "window.maxAdvance", sessions: "window.maxAdvance", "date-ranges": "window.maxAdvance" }
|
|
4426
|
-
})),
|
|
4427
|
-
{
|
|
4428
|
-
path: "availability.weeklyHours",
|
|
4429
|
-
home: {
|
|
4430
|
-
"time-slots": "timeSlots.weeklyHours",
|
|
4431
|
-
sessions: { unread: "sessions read their timetable" },
|
|
4432
|
-
"date-ranges": "dateRanges.weeklyHours"
|
|
4433
|
-
}
|
|
4434
|
-
},
|
|
4435
|
-
{
|
|
4436
|
-
path: "availability.arrivalDays",
|
|
4437
|
-
home: {
|
|
4438
|
-
"time-slots": { unread: "date ranges only" },
|
|
4439
|
-
sessions: { unread: "date ranges only" },
|
|
4440
|
-
"date-ranges": "dateRanges.arrivalDays"
|
|
4441
|
-
}
|
|
4442
|
-
},
|
|
4443
|
-
// An `opening-hours` night has no check times (FC-1503): switching to it drops the old ones, said in a note.
|
|
4444
|
-
...["checkInTime", "checkOutTime", "checkTimesByWeekday"].map((path) => ({
|
|
4445
|
-
path,
|
|
4446
|
-
home: {
|
|
4447
|
-
"time-slots": { unread: "date ranges only" },
|
|
4448
|
-
sessions: { unread: "date ranges only" },
|
|
4449
|
-
"date-ranges": ({ dateRanges }) => dateRanges?.arriveLeave === "opening-hours" /* OPENING_HOURS */ ? { dropped: "opening-hours nights have no check times" } : `dateRanges.${path}`
|
|
4450
|
-
}
|
|
4451
|
-
}))
|
|
4452
|
-
];
|
|
4453
|
-
var homeOf = (field, rule) => {
|
|
4454
|
-
const home = field.home[bookingMethodOf(rule)];
|
|
4455
|
-
return typeof home === "function" ? home(rule) : home;
|
|
4456
|
-
};
|
|
4457
|
-
var carriedValueOf = (rule, field) => field.carried ? field.carried(rule) : valueAt(rule, field.path);
|
|
4458
|
-
var carries = (value) => value != null && value !== 0 && !(Array.isArray(value) && value.length === 0);
|
|
4459
|
-
function ruleInNewShape(rule) {
|
|
4460
|
-
const set = { ...typePartInNewShape(rule), ...durationsInNewShape(rule) };
|
|
4461
|
-
const unset = [...OLD_FIELDS.map(({ path }) => path), "slot.wholePeriods"].filter(
|
|
4462
|
-
(path) => valueAt(rule, path) !== void 0
|
|
4463
|
-
);
|
|
4464
|
-
const written = writtenRule(rule, set, unset);
|
|
4465
|
-
bookingRuleParts(written);
|
|
4466
|
-
refuseLostValues(rule, written);
|
|
4467
|
-
const changesBehaviour = sellsOneDayOfWeekOrMonth(rule) ? "whole-periods" : void 0;
|
|
4468
|
-
const notes = [
|
|
4469
|
-
...droppedFieldNotes(rule, written),
|
|
4470
|
-
...changesBehaviour ? [`${rule.ratePeriod} rule now sells whole ${rule.ratePeriod}s, was one day per booking`] : []
|
|
4471
|
-
];
|
|
4472
|
-
return { set, unset, problems: durationProblems(written), notes, ...changesBehaviour && { changesBehaviour } };
|
|
4473
|
-
}
|
|
4474
|
-
function typePartInNewShape(rule) {
|
|
4475
|
-
const method = bookingMethodOf(rule);
|
|
4476
|
-
if (method === "sessions") return {};
|
|
4477
|
-
if (method === "time-slots") return { timeSlots: newTimeSlotsOf(rule.timeSlots ?? oldTimeSlotsOf(rule)) };
|
|
4478
|
-
if (rule.dateRanges) return { dateRanges: rule.dateRanges };
|
|
4479
|
-
const dateRanges = oldDateRangesOf(rule);
|
|
4480
|
-
delete dateRanges.wholePeriods;
|
|
4481
|
-
return { dateRanges: definedOnly(dateRanges) };
|
|
4482
|
-
}
|
|
4483
|
-
function durationsInNewShape(rule) {
|
|
4484
|
-
const { buffer, minNotice } = ruleDurationsOf(rule);
|
|
4485
|
-
return definedOnly({
|
|
4486
|
-
"slot.buffer": rule.slot.buffer ?? (typeof homeOf(OLD_BUFFER, rule) === "string" ? buffer : void 0),
|
|
4487
|
-
"window.hold": holdOf(rule) ?? DEFAULT_HOLD,
|
|
4488
|
-
"window.minNotice": minNotice,
|
|
4489
|
-
"window.maxAdvance": ruleDurationsOf(rule).maxAdvance
|
|
4490
|
-
});
|
|
4491
|
-
}
|
|
4492
|
-
var sellsOneDayOfWeekOrMonth = ({ ratePeriod, slot, dateRanges }) => !dateRanges && (ratePeriod === "week" /* WEEK */ || ratePeriod === "month" /* MONTH */) && !slot.wholePeriods;
|
|
4493
|
-
function droppedFieldNotes(rule, written) {
|
|
4494
|
-
const weekOrMonth = rule.ratePeriod === "week" /* WEEK */ || rule.ratePeriod === "month" /* MONTH */;
|
|
4495
|
-
return [
|
|
4496
|
-
...OLD_FIELDS.flatMap((field) => {
|
|
4497
|
-
const home = homeOf(field, rule);
|
|
4498
|
-
const dropped = typeof home === "object" && "dropped" in home && carries(carriedValueOf(rule, field));
|
|
4499
|
-
return dropped ? [`${field.path} is dropped: ${home.dropped}`] : [];
|
|
4500
|
-
}),
|
|
4501
|
-
...rule.slot.wholePeriods && !weekOrMonth ? ["slot.wholePeriods is dropped: only week and month rules have it"] : [],
|
|
4502
|
-
...rule.ratePeriod === "hour" /* HOUR */ && !written.dateRanges?.weeklyHours?.length ? ["hour rule has no opening hours: nothing can be booked"] : [],
|
|
4503
|
-
...rule.window.holdMinutes == null && !rule.window.hold ? [`window.hold is set to the default ${DEFAULT_HOLD_MINUTES} minutes`] : []
|
|
4504
|
-
];
|
|
4505
|
-
}
|
|
4506
|
-
function writtenRule(rule, set, unset) {
|
|
4507
|
-
const written = {
|
|
4508
|
-
...rule,
|
|
4509
|
-
slot: { ...rule.slot },
|
|
4510
|
-
window: { ...rule.window },
|
|
4511
|
-
availability: { ...rule.availability }
|
|
4512
|
-
};
|
|
4513
|
-
for (const path of unset) {
|
|
4514
|
-
const [head, leaf] = path.split(".");
|
|
4515
|
-
if (leaf) delete written[head][leaf];
|
|
4516
|
-
else delete written[head];
|
|
4517
|
-
}
|
|
4518
|
-
for (const [path, value] of Object.entries(set)) {
|
|
4519
|
-
const [head, leaf] = path.split(".");
|
|
4520
|
-
if (leaf) written[head][leaf] = value;
|
|
4521
|
-
else written[head] = value;
|
|
4522
|
-
}
|
|
4523
|
-
return written;
|
|
4524
|
-
}
|
|
4525
|
-
function refuseLostValues(rule, written) {
|
|
4526
|
-
for (const field of OLD_FIELDS) {
|
|
4527
|
-
const home = homeOf(field, rule);
|
|
4528
|
-
if (typeof home === "string" && carries(carriedValueOf(rule, field)) && valueAt(written, home) == null) {
|
|
4529
|
-
throw new BookingRulesError(`Booking rules: ${home} is missing \u2014 the rule's old value would be lost`);
|
|
4530
|
-
}
|
|
4531
|
-
}
|
|
4532
|
-
}
|
|
4533
|
-
var definedOnly = (value) => Object.fromEntries(Object.entries(value).filter(([, entry]) => entry != null));
|
|
4534
|
-
var valueAt = (rule, path) => path.split(".").reduce((node, key) => node?.[key], rule);
|
|
4535
|
-
|
|
4536
|
-
// booking/grid.ts
|
|
4537
|
-
var MINUTE3 = 6e4;
|
|
4538
|
-
var HOUR_MINUTES = 60;
|
|
4539
|
-
var MAX_RANGE_DAYS = 366;
|
|
4540
|
-
var asTime = (value, field) => {
|
|
4541
|
-
if (value == null) return void 0;
|
|
4542
|
-
const time = new Date(value).getTime();
|
|
4543
|
-
if (Number.isNaN(time)) throw new BookingRulesError(`Booking rules: ${field} is not a date, got "${String(value)}"`);
|
|
4544
|
-
return time;
|
|
4545
|
-
};
|
|
4546
|
-
function parseHhMm(value, field) {
|
|
4547
|
-
const [hours, minutes] = value.split(":").map(Number);
|
|
4548
|
-
if (!Number.isInteger(hours) || !Number.isInteger(minutes)) {
|
|
4549
|
-
throw new BookingRulesError(`Booking rules: ${field} must be "HH:mm", got "${value}"`);
|
|
4550
|
-
}
|
|
4551
|
-
return hours * 60 + minutes;
|
|
4552
|
-
}
|
|
4553
|
-
function windowEndsAt(rule, now) {
|
|
4554
|
-
const maxAdvanceMinutes = maxAdvanceMinutesOf(rule);
|
|
4555
|
-
const ends = Math.min(
|
|
4556
|
-
maxAdvanceMinutes ? now.getTime() + maxAdvanceMinutes * MINUTE3 : Number.POSITIVE_INFINITY,
|
|
4557
|
-
asTime(rule.window.bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY
|
|
4558
|
-
);
|
|
4559
|
-
return Number.isFinite(ends) ? new Date(ends) : null;
|
|
4560
|
-
}
|
|
4561
|
-
function windowEndsAtInZone(rule, now, timeZone) {
|
|
4562
|
-
const ends = Math.min(
|
|
4563
|
-
lastStartOf(rule, now, timeZone),
|
|
4564
|
-
asTime(rule.window.bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY
|
|
4565
|
-
);
|
|
4566
|
-
return Number.isFinite(ends) ? new Date(ends) : null;
|
|
4567
|
-
}
|
|
4568
|
-
function lastStartOf(rule, now, timeZone) {
|
|
4569
|
-
const { maxAdvance } = ruleDurationsOf(rule);
|
|
4570
|
-
if (!maxAdvance) return Number.POSITIVE_INFINITY;
|
|
4571
|
-
const reached = addInZone(now, maxAdvance, timeZone, "window.maxAdvance");
|
|
4572
|
-
if (maxAdvance.unit === "minute" /* MINUTE */ || maxAdvance.unit === "hour" /* HOUR */) {
|
|
4573
|
-
return reached.getTime();
|
|
4574
|
-
}
|
|
4575
|
-
const zone = timeZone;
|
|
4576
|
-
return nextZonedDay(startOfZonedDay(reached, zone), zone).getTime() - 1;
|
|
4577
|
-
}
|
|
4578
|
-
var startsPastMaxAdvance = (rule, startAt, now, timeZone) => startAt.getTime() > lastStartOf(rule, now, timeZone);
|
|
4579
|
-
function addInZone(from, duration, timeZone, field) {
|
|
4580
|
-
if (timeZone) return addDuration(from, duration, timeZone);
|
|
4581
|
-
if (duration.unit === "minute" /* MINUTE */ || duration.unit === "hour" /* HOUR */) {
|
|
4582
|
-
return addClockDuration(from, duration);
|
|
4583
|
-
}
|
|
4584
|
-
throw new BookingRulesError(`Booking rules: ${field} in ${duration.unit}s needs the shop's time zone`);
|
|
4585
|
-
}
|
|
4586
|
-
function maxAdvanceMinutesOf(rule) {
|
|
4587
|
-
const { maxAdvanceMinutes, maxAdvanceDays } = rule.window;
|
|
4588
|
-
return maxAdvanceMinutes ?? (maxAdvanceDays ?? 0) * 1440;
|
|
4589
|
-
}
|
|
4590
|
-
var asMinutes = (minutes) => minutes == null ? void 0 : { count: minutes, unit: "minute" /* MINUTE */ };
|
|
4591
|
-
var inMinutes = (minutes) => minutes === 0 ? void 0 : asMinutes(minutes);
|
|
4592
|
-
function notNegative(duration, field) {
|
|
4593
|
-
if (duration && !(Number.isFinite(duration.count) && duration.count >= 0)) {
|
|
4594
|
-
throw new BookingRulesError(`Booking rules: ${field} must be a number of at least 0, got ${duration.count}`);
|
|
4595
|
-
}
|
|
4596
|
-
return duration;
|
|
4597
|
-
}
|
|
4598
|
-
function ruleDurationsOf(rule) {
|
|
4599
|
-
const { slot, window } = rule;
|
|
4600
|
-
return {
|
|
4601
|
-
buffer: notNegative(
|
|
4602
|
-
slot.buffer ?? inMinutes(slot.bufferMinutes),
|
|
4603
|
-
slot.buffer ? "slot.buffer" : "slot.bufferMinutes"
|
|
4604
|
-
),
|
|
4605
|
-
hold: window.hold ?? asMinutes(window.holdMinutes),
|
|
4606
|
-
minNotice: notNegative(
|
|
4607
|
-
window.minNotice ?? inMinutes(window.minNoticeMinutes),
|
|
4608
|
-
window.minNotice ? "window.minNotice" : "window.minNoticeMinutes"
|
|
4609
|
-
),
|
|
4610
|
-
maxAdvance: window.maxAdvance ?? oldMaxAdvanceOf(window)
|
|
4611
|
-
};
|
|
4612
|
-
}
|
|
4613
|
-
function oldMaxAdvanceOf({
|
|
4614
|
-
maxAdvanceMinutes,
|
|
4615
|
-
maxAdvanceDays
|
|
4616
|
-
}) {
|
|
4617
|
-
const days = maxAdvanceDays ?? 0;
|
|
4618
|
-
if (maxAdvanceMinutes == null || days > 0 && maxAdvanceMinutes === days * 1440) {
|
|
4619
|
-
return days > 0 ? { count: days, unit: "day" /* DAY */ } : void 0;
|
|
4620
|
-
}
|
|
4621
|
-
return maxAdvanceMinutes ? { count: maxAdvanceMinutes, unit: "minute" /* MINUTE */ } : void 0;
|
|
4622
|
-
}
|
|
4623
|
-
function periodSlot(dayStart, timeZone, parts, buffer, openMinute, closeMinute) {
|
|
4624
|
-
const { ratePeriod } = parts;
|
|
4625
|
-
const at = (minutes) => atZonedMinute(dayStart, minutes, timeZone);
|
|
4626
|
-
if (ratePeriod === "night" /* NIGHT */ && parts.arriveLeave !== "opening-hours" /* OPENING_HOURS */) {
|
|
4627
|
-
const arrival = zonedParts(dayStart, timeZone).weekday;
|
|
4628
|
-
const departure = (arrival + 1) % 7;
|
|
4629
|
-
return {
|
|
4630
|
-
startAt: at(checkTimesOf(parts, arrival).checkIn),
|
|
4631
|
-
endAt: at(1440 + checkTimesOf(parts, departure).checkOut),
|
|
4632
|
-
// Housekeeping sits between check-out and the next check-in: it costs no night.
|
|
4633
|
-
bufferEndAt: at(1440 + checkTimesOf(parts, departure).checkIn),
|
|
4634
|
-
canStart: true
|
|
4635
|
-
};
|
|
4636
|
-
}
|
|
4637
|
-
const from = ratePeriod === "day" /* DAY */ ? openMinute ?? 0 : 0;
|
|
4638
|
-
const to = ratePeriod === "day" /* DAY */ ? closeMinute ?? 1440 : 1440;
|
|
4639
|
-
const turnaround = parts.wholePeriods || ratePeriod === "night" /* NIGHT */ ? void 0 : buffer;
|
|
4640
|
-
return {
|
|
4641
|
-
startAt: at(from),
|
|
4642
|
-
endAt: at(to),
|
|
4643
|
-
bufferEndAt: turnaround ? addDuration(at(to), turnaround, timeZone) : at(to),
|
|
4644
|
-
canStart: true
|
|
4645
|
-
};
|
|
4646
|
-
}
|
|
4647
|
-
function checkTimesOf(rule, weekday) {
|
|
4648
|
-
const row = rule.checkTimesByWeekday?.find((entry) => entry.weekday === weekday);
|
|
4649
|
-
const checkInTime = row?.checkInTime ?? rule.checkInTime;
|
|
4650
|
-
const checkOutTime = row?.checkOutTime ?? rule.checkOutTime;
|
|
4651
|
-
if (!checkInTime || !checkOutTime) {
|
|
4652
|
-
throw new BookingRulesError("Overnight booking rules need both checkInTime and checkOutTime");
|
|
4653
|
-
}
|
|
4654
|
-
return { checkIn: parseHhMm(checkInTime, "checkInTime"), checkOut: parseHhMm(checkOutTime, "checkOutTime") };
|
|
4655
|
-
}
|
|
4656
|
-
function freeGaps(openAt, closeAt, busy) {
|
|
4657
|
-
const inside = busy.map(({ startAt, bufferEndAt }) => ({ from: +startAt, to: +bufferEndAt })).filter(({ from, to }) => to > openAt && from < closeAt).sort((first, second) => first.from - second.from);
|
|
4658
|
-
const gaps = [];
|
|
4659
|
-
let cursor = openAt;
|
|
4660
|
-
for (const { from, to } of inside) {
|
|
4661
|
-
if (from > cursor) gaps.push({ from: cursor, to: from, endsAtBooking: true });
|
|
4662
|
-
cursor = Math.max(cursor, to);
|
|
4663
|
-
if (cursor >= closeAt) break;
|
|
4664
|
-
}
|
|
4665
|
-
if (cursor < closeAt) gaps.push({ from: cursor, to: closeAt, endsAtBooking: false });
|
|
4666
|
-
return gaps;
|
|
4667
|
-
}
|
|
4668
|
-
function sessionCells(rule, timeZone, from, to) {
|
|
4669
|
-
if (!rule.sessions) throw new BookingRulesError("Scheduled-session rules need their sessions");
|
|
4670
|
-
const { weekly = [], dates = [] } = rule.sessions;
|
|
4671
|
-
const { buffer } = ruleDurationsOf(rule);
|
|
4672
|
-
const cell = (startAt, endAt) => ({
|
|
4673
|
-
startAt: new Date(startAt),
|
|
4674
|
-
endAt: new Date(endAt),
|
|
4675
|
-
bufferEndAt: buffer ? addDuration(new Date(endAt), buffer, timeZone) : new Date(endAt),
|
|
4676
|
-
canStart: true
|
|
4677
|
-
});
|
|
4678
|
-
const cells = dates.map(({ date, startMinute, endMinute }) => {
|
|
4679
|
-
const [year, month, day] = calendarDate(date);
|
|
4680
|
-
return cell(
|
|
4681
|
-
+instantFromLocal(year, month, day, startMinute, timeZone),
|
|
4682
|
-
+instantFromLocal(year, month, day, endMinute, timeZone)
|
|
4683
|
-
);
|
|
4684
|
-
});
|
|
4685
|
-
const lastDay = startOfZonedDay(to, timeZone).getTime();
|
|
4686
|
-
for (let day = startOfZonedDay(from, timeZone); day.getTime() <= lastDay; day = nextZonedDay(day, timeZone)) {
|
|
4687
|
-
const weekday = zonedParts(day, timeZone).weekday;
|
|
4688
|
-
for (const row of weekly.filter((entry) => entry.weekday === weekday)) {
|
|
4689
|
-
cells.push(cell(+atZonedMinute(day, row.startMinute, timeZone), +atZonedMinute(day, row.endMinute, timeZone)));
|
|
4690
|
-
}
|
|
4691
|
-
}
|
|
4692
|
-
const blocked = offMarketOf(rule);
|
|
4693
|
-
return cells.filter(({ startAt, bufferEndAt }) => {
|
|
4694
|
-
const start = startAt.getTime();
|
|
4695
|
-
return start >= from.getTime() && start <= to.getTime() && !isBlocked(blocked, start, bufferEndAt.getTime());
|
|
4696
|
-
});
|
|
4697
|
-
}
|
|
4698
|
-
function calendarDate(value) {
|
|
4699
|
-
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value ?? "");
|
|
4700
|
-
const [year, month, day] = match ? match.slice(1).map(Number) : [];
|
|
4701
|
-
const real = match && new Date(Date.UTC(year, month - 1, day)).toISOString().slice(0, 10) === value;
|
|
4702
|
-
if (!real) throw new BookingRulesError(`Booking rules: "${value}" is not a date (YYYY-MM-DD)`);
|
|
4703
|
-
return [year, month, day];
|
|
4704
|
-
}
|
|
4705
|
-
var offMarketOf = (rule) => (rule.availability.offMarket ?? []).map(({ from: blockFrom, to: blockTo }) => ({
|
|
4706
|
-
from: asTime(blockFrom, "availability.offMarket.from"),
|
|
4707
|
-
to: asTime(blockTo, "availability.offMarket.to")
|
|
4708
|
-
}));
|
|
4709
|
-
var isBlocked = (blocked, start, bufferEnd) => blocked.some(({ from, to }) => start < to && bufferEnd > from);
|
|
4710
|
-
function hourCells(openAt, closeAt) {
|
|
4711
|
-
const cells = [];
|
|
4712
|
-
for (let start = openAt; start + HOUR_MINUTES * MINUTE3 <= closeAt; start += HOUR_MINUTES * MINUTE3) {
|
|
4713
|
-
const endAt = new Date(start + HOUR_MINUTES * MINUTE3);
|
|
4714
|
-
cells.push({ startAt: new Date(start), endAt, bufferEndAt: endAt, canStart: true });
|
|
4715
|
-
}
|
|
4716
|
-
return cells;
|
|
4717
|
-
}
|
|
4718
|
-
function cellsOf(rule, parts, timeZone, from, to, busy) {
|
|
4719
|
-
if (parts.method === "sessions") return sessionCells(rule, timeZone, from, to);
|
|
4720
|
-
const { buffer } = ruleDurationsOf(rule);
|
|
4721
|
-
const cells = [];
|
|
4722
|
-
const lastDay = startOfZonedDay(to, timeZone).getTime();
|
|
4723
|
-
for (let day = startOfZonedDay(from, timeZone); day.getTime() <= lastDay; day = nextZonedDay(day, timeZone)) {
|
|
4724
|
-
cells.push(
|
|
4725
|
-
...parts.method === "time-slots" ? timeSlotCells(parts, buffer, day, timeZone, busy) : periodCells(parts, buffer, day, timeZone)
|
|
4726
|
-
);
|
|
4727
|
-
}
|
|
4728
|
-
return cells;
|
|
4729
|
-
}
|
|
4730
|
-
function timeSlotCells(parts, buffer, dayStart, timeZone, busy) {
|
|
4731
|
-
const weekday = zonedParts(dayStart, timeZone).weekday;
|
|
4732
|
-
return parts.weeklyHours.filter((entry) => entry.weekday === weekday).flatMap(
|
|
4733
|
-
(row) => freeGaps(
|
|
4734
|
-
+atZonedMinute(dayStart, row.openMinute, timeZone),
|
|
4735
|
-
+atZonedMinute(dayStart, row.closeMinute, timeZone),
|
|
4736
|
-
busy
|
|
4737
|
-
).flatMap((gap) => cellsInGap(gap, parts.length, buffer, timeZone))
|
|
4738
|
-
);
|
|
4739
|
-
}
|
|
4740
|
-
function cellsInGap(gap, length, buffer, timeZone) {
|
|
4741
|
-
const cells = [];
|
|
4742
|
-
for (let start = gap.from; ; ) {
|
|
4743
|
-
const endAt = addDuration(new Date(start), length, timeZone);
|
|
4744
|
-
const bufferEndAt = buffer ? addDuration(endAt, buffer, timeZone) : new Date(endAt.getTime());
|
|
4745
|
-
if ((gap.endsAtBooking ? bufferEndAt : endAt).getTime() > gap.to) return cells;
|
|
4746
|
-
cells.push({ startAt: new Date(start), endAt, bufferEndAt, canStart: true });
|
|
4747
|
-
start = bufferEndAt.getTime();
|
|
4748
|
-
}
|
|
4749
|
-
}
|
|
4750
|
-
function periodCells(parts, buffer, dayStart, timeZone) {
|
|
4751
|
-
const weekday = zonedParts(dayStart, timeZone).weekday;
|
|
4752
|
-
const rows = (parts.weeklyHours ?? []).filter((entry) => entry.weekday === weekday);
|
|
4753
|
-
if (parts.ratePeriod === "hour" /* HOUR */) {
|
|
4754
|
-
return rows.flatMap(
|
|
4755
|
-
(row) => hourCells(
|
|
4756
|
-
+atZonedMinute(dayStart, row.openMinute, timeZone),
|
|
4757
|
-
+atZonedMinute(dayStart, row.closeMinute, timeZone)
|
|
4758
|
-
)
|
|
4759
|
-
);
|
|
4760
|
-
}
|
|
4761
|
-
if (parts.weeklyHours?.length && rows.length === 0) return [];
|
|
4762
|
-
const built = periodSlot(dayStart, timeZone, parts, buffer, rows[0]?.openMinute, rows[0]?.closeMinute);
|
|
4763
|
-
return [{ ...built, canStart: !parts.arrivalDays?.length || parts.arrivalDays.includes(weekday) }];
|
|
4764
|
-
}
|
|
4765
|
-
function buildGrid(rule, timeZone, from, to, now, busy = []) {
|
|
4766
|
-
if (to.getTime() - from.getTime() > MAX_RANGE_DAYS * 1440 * MINUTE3) {
|
|
4767
|
-
throw new BookingRulesError(`A booking range may span at most ${MAX_RANGE_DAYS} days`);
|
|
4768
|
-
}
|
|
4769
|
-
const { availability, window } = rule;
|
|
4770
|
-
const { minNotice } = ruleDurationsOf(rule);
|
|
4771
|
-
const notBefore = Math.max(
|
|
4772
|
-
(minNotice ? addDuration(now, minNotice, timeZone) : now).getTime(),
|
|
4773
|
-
asTime(window.bookableFrom, "window.bookableFrom") ?? 0,
|
|
4774
|
-
asTime(availability.availableFrom, "availability.availableFrom") ?? 0
|
|
4775
|
-
);
|
|
4776
|
-
const notAfter = asTime(window.bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY;
|
|
4777
|
-
const lastStart = lastStartOf(rule, now, timeZone);
|
|
4778
|
-
const blocked = offMarketOf(rule);
|
|
4779
|
-
const slots = cellsOf(rule, bookingRuleParts(rule), timeZone, from, to, busy);
|
|
4780
|
-
const askedFrom = from.getTime();
|
|
4781
|
-
const askedTo = to.getTime();
|
|
4782
|
-
return slots.filter(({ startAt, bufferEndAt }) => {
|
|
4783
|
-
const start = startAt.getTime();
|
|
4784
|
-
if (start < askedFrom || start >= askedTo) return false;
|
|
4785
|
-
if (start < notBefore || start > notAfter) return false;
|
|
4786
|
-
return !isBlocked(blocked, start, bufferEndAt.getTime());
|
|
4787
|
-
}).flatMap((cell) => cell.startAt.getTime() > lastStart ? pastMaxAdvance(cell, rule) : [cell]).sort((first, second) => +first.startAt - +second.startAt);
|
|
4788
|
-
}
|
|
4789
|
-
function pastMaxAdvance(cell, rule) {
|
|
4790
|
-
if (soldAsCourse(rule)) return [cell];
|
|
4791
|
-
return bookingMethodOf(rule) === "date-ranges" ? [{ ...cell, canStart: false }] : [];
|
|
4792
|
-
}
|
|
4793
|
-
function slotsForWindow(grid, startAt, endAt) {
|
|
4794
|
-
const startIndex = grid.findIndex((entry) => entry.startAt.getTime() === startAt.getTime());
|
|
4795
|
-
if (startIndex < 0) {
|
|
4796
|
-
throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
|
|
4797
|
-
}
|
|
4798
|
-
if (!grid[startIndex].canStart) {
|
|
4799
|
-
throw new BookingRulesError(`${startAt.toISOString()} is not an arrival day for these rules`);
|
|
4800
|
-
}
|
|
4801
|
-
const covered = [];
|
|
4802
|
-
for (let index = startIndex; index < grid.length; index++) {
|
|
4803
|
-
const entry = grid[index];
|
|
4804
|
-
const previous = covered[covered.length - 1];
|
|
4805
|
-
if (previous && entry.startAt.getTime() !== previous.bufferEndAt.getTime()) break;
|
|
4806
|
-
covered.push(entry);
|
|
4807
|
-
if (entry.endAt.getTime() === endAt.getTime()) return covered;
|
|
4808
|
-
if (entry.endAt.getTime() > endAt.getTime()) break;
|
|
4809
|
-
}
|
|
4810
|
-
throw new BookingRulesError(
|
|
4811
|
-
`${startAt.toISOString()} \u2192 ${endAt.toISOString()} does not line up with the bookable grid`
|
|
4812
|
-
);
|
|
3982
|
+
const last = slots[slots.length - 1];
|
|
3983
|
+
return { slots, endAt: last.endAt, bufferEndAt: last.bufferEndAt };
|
|
4813
3984
|
}
|
|
3985
|
+
var holdExpiresAt = (rule, now) => new Date(now.getTime() + (rule.window.holdMinutes ?? DEFAULT_HOLD_MINUTES) * 6e4);
|
|
4814
3986
|
|
|
4815
3987
|
// shipping/fold-text.ts
|
|
4816
3988
|
function foldText(value) {
|
|
@@ -5247,13 +4419,10 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
5247
4419
|
AttributeType,
|
|
5248
4420
|
BNPL_METHOD_STATUS,
|
|
5249
4421
|
BNPL_SKIP_REASON,
|
|
5250
|
-
BookingArriveLeave,
|
|
5251
|
-
BookingDurationUnit,
|
|
5252
4422
|
BookingRatePeriod,
|
|
5253
4423
|
BookingResourceKind,
|
|
5254
4424
|
BookingResourceStatus,
|
|
5255
4425
|
BookingRulesError,
|
|
5256
|
-
BookingSessionSale,
|
|
5257
4426
|
BookingType,
|
|
5258
4427
|
CANADA_PROVINCES,
|
|
5259
4428
|
CONDITION_OPERATORS,
|
|
@@ -5343,7 +4512,6 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
5343
4512
|
StripeStatus,
|
|
5344
4513
|
TimePeriod,
|
|
5345
4514
|
TopMetericsSort,
|
|
5346
|
-
UNLIMITED_PLACES,
|
|
5347
4515
|
UserTypes,
|
|
5348
4516
|
addAmounts,
|
|
5349
4517
|
addressPlaceKeys,
|
|
@@ -5352,7 +4520,6 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
5352
4520
|
adyenStoreRequiresStateOrProvince,
|
|
5353
4521
|
adyenSupportsTaxNumberAbsent,
|
|
5354
4522
|
adyenTaxNumberFormat,
|
|
5355
|
-
allowedDurationUnits,
|
|
5356
4523
|
amountToString,
|
|
5357
4524
|
ancestorChain,
|
|
5358
4525
|
applyAssignment,
|
|
@@ -5362,21 +4529,15 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
5362
4529
|
baseFulfillmentDefinitions,
|
|
5363
4530
|
baseOf,
|
|
5364
4531
|
basePaymentDefinitions,
|
|
5365
|
-
bookingMethodOf,
|
|
5366
|
-
bookingRuleParts,
|
|
5367
4532
|
buildAvailability,
|
|
5368
4533
|
buildGrid,
|
|
5369
4534
|
buildOrderContext,
|
|
5370
4535
|
buildPosPresetConfig,
|
|
5371
4536
|
buildResolvedConfig,
|
|
5372
4537
|
calculatePercentage,
|
|
5373
|
-
calendarDate,
|
|
5374
4538
|
canTransition,
|
|
5375
|
-
capacityOf,
|
|
5376
4539
|
cheapestCompositeItem,
|
|
5377
4540
|
cheapestCompositePrice,
|
|
5378
|
-
checkPartySize,
|
|
5379
|
-
checkQtyPerBooking,
|
|
5380
4541
|
compositeItemCost,
|
|
5381
4542
|
compositeItemUnavailable,
|
|
5382
4543
|
compositeMakeable,
|
|
@@ -5385,10 +4546,6 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
5385
4546
|
compositeVariantInStock,
|
|
5386
4547
|
conditionSummary,
|
|
5387
4548
|
convertFixedFeeToLocalCurrency,
|
|
5388
|
-
courseSessions,
|
|
5389
|
-
courseSpan,
|
|
5390
|
-
courseStarted,
|
|
5391
|
-
courseStartedInZone,
|
|
5392
4549
|
createAmount,
|
|
5393
4550
|
crossAxisRuleApplies,
|
|
5394
4551
|
currentAssignees,
|
|
@@ -5397,13 +4554,10 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
5397
4554
|
deriveUnitId,
|
|
5398
4555
|
displayRuleMatchesPair,
|
|
5399
4556
|
divideAmount,
|
|
5400
|
-
durationProblems,
|
|
5401
|
-
durationText,
|
|
5402
4557
|
evaluateCondition,
|
|
5403
4558
|
evaluateConditionSet,
|
|
5404
4559
|
extendPrice,
|
|
5405
4560
|
extendPriceFor,
|
|
5406
|
-
fewestFreeOver,
|
|
5407
4561
|
formatCurrency,
|
|
5408
4562
|
formatInUnit,
|
|
5409
4563
|
formatMinorUnitsToString,
|
|
@@ -5445,9 +4599,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
5445
4599
|
listCountries,
|
|
5446
4600
|
listProvinces,
|
|
5447
4601
|
listShippingCountries,
|
|
5448
|
-
longestMinutesOf,
|
|
5449
4602
|
mapToLegacyStatus,
|
|
5450
|
-
maxAdvanceMinutesOf,
|
|
5451
4603
|
maxPrecisionFor,
|
|
5452
4604
|
mergeFragment,
|
|
5453
4605
|
modifiersSellable,
|
|
@@ -5459,15 +4611,11 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
5459
4611
|
normalizePostCode,
|
|
5460
4612
|
normalizeProvince,
|
|
5461
4613
|
occupancyIn,
|
|
5462
|
-
occupiedAtOutlet,
|
|
5463
|
-
oldMaxAdvanceOf,
|
|
5464
4614
|
orderAssignments,
|
|
5465
4615
|
parseAmountToMinorUnits,
|
|
5466
4616
|
parseCurrencyCode,
|
|
5467
4617
|
parseStripeCurrencyCode,
|
|
5468
|
-
pickFreeResource,
|
|
5469
4618
|
placeKey,
|
|
5470
|
-
planCourse,
|
|
5471
4619
|
planWindow,
|
|
5472
4620
|
poolDemand,
|
|
5473
4621
|
poolOf,
|
|
@@ -5478,26 +4626,19 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
5478
4626
|
priceForTotal,
|
|
5479
4627
|
provincesForPostCode,
|
|
5480
4628
|
removeFragment,
|
|
5481
|
-
rentalEnds,
|
|
5482
4629
|
resolveFamily,
|
|
5483
4630
|
resolveModifiersForProduct,
|
|
5484
4631
|
resolveShipping,
|
|
5485
4632
|
resolveTemplate,
|
|
5486
4633
|
resolveUnit,
|
|
5487
4634
|
roundToPrecision,
|
|
5488
|
-
ruleDurationsOf,
|
|
5489
|
-
ruleInNewShape,
|
|
5490
4635
|
sameFamily,
|
|
5491
|
-
sessionCells,
|
|
5492
4636
|
setOrderState,
|
|
5493
4637
|
shipsToCountry,
|
|
5494
4638
|
shopDayKey,
|
|
5495
4639
|
shopDayRange,
|
|
5496
|
-
shortestMinutesOf,
|
|
5497
4640
|
signReportForDisplay,
|
|
5498
4641
|
slotsForWindow,
|
|
5499
|
-
soldAsCourse,
|
|
5500
|
-
startsPastMaxAdvance,
|
|
5501
4642
|
stringifyMinorUnits,
|
|
5502
4643
|
subtractAmounts,
|
|
5503
4644
|
toBase,
|
|
@@ -5508,8 +4649,6 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
5508
4649
|
validateShippingZone,
|
|
5509
4650
|
violatesFinancialInvariant,
|
|
5510
4651
|
windowEndsAt,
|
|
5511
|
-
windowEndsAtInZone,
|
|
5512
|
-
windowForPeriods,
|
|
5513
4652
|
withinPresence
|
|
5514
4653
|
});
|
|
5515
4654
|
//# sourceMappingURL=index.js.map
|