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