@final-commerce/common 2.11.1 → 2.12.0-staging.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -454,21 +454,37 @@ var PaymentProcessor = /* @__PURE__ */ ((PaymentProcessor2) => {
454
454
  })(PaymentProcessor || {});
455
455
 
456
456
  // enums/booking.enum.ts
457
- var BookingType = /* @__PURE__ */ ((BookingType3) => {
458
- BookingType3["RENTAL"] = "rental";
459
- BookingType3["APPOINTMENT"] = "appointment";
460
- BookingType3["OVERNIGHT"] = "overnight";
461
- BookingType3["GROUP"] = "group";
462
- return BookingType3;
457
+ var BookingType = /* @__PURE__ */ ((BookingType2) => {
458
+ BookingType2["RENTAL"] = "rental";
459
+ BookingType2["APPOINTMENT"] = "appointment";
460
+ BookingType2["OVERNIGHT"] = "overnight";
461
+ BookingType2["GROUP"] = "group";
462
+ return BookingType2;
463
463
  })(BookingType || {});
464
464
  var BookingRatePeriod = /* @__PURE__ */ ((BookingRatePeriod2) => {
465
465
  BookingRatePeriod2["SLOT"] = "slot";
466
+ BookingRatePeriod2["HOUR"] = "hour";
467
+ BookingRatePeriod2["SESSION"] = "session";
466
468
  BookingRatePeriod2["DAY"] = "day";
467
469
  BookingRatePeriod2["NIGHT"] = "night";
468
470
  BookingRatePeriod2["WEEK"] = "week";
469
471
  BookingRatePeriod2["MONTH"] = "month";
470
472
  return BookingRatePeriod2;
471
473
  })(BookingRatePeriod || {});
474
+ var BookingDurationUnit = /* @__PURE__ */ ((BookingDurationUnit2) => {
475
+ BookingDurationUnit2["MINUTE"] = "minute";
476
+ BookingDurationUnit2["HOUR"] = "hour";
477
+ BookingDurationUnit2["DAY"] = "day";
478
+ BookingDurationUnit2["NIGHT"] = "night";
479
+ BookingDurationUnit2["WEEK"] = "week";
480
+ BookingDurationUnit2["MONTH"] = "month";
481
+ return BookingDurationUnit2;
482
+ })(BookingDurationUnit || {});
483
+ var BookingSessionSale = /* @__PURE__ */ ((BookingSessionSale2) => {
484
+ BookingSessionSale2["SESSION"] = "session";
485
+ BookingSessionSale2["COURSE"] = "course";
486
+ return BookingSessionSale2;
487
+ })(BookingSessionSale || {});
472
488
  var BookingResourceKind = /* @__PURE__ */ ((BookingResourceKind2) => {
473
489
  BookingResourceKind2["ASSET"] = "asset";
474
490
  BookingResourceKind2["ROOM"] = "room";
@@ -3329,6 +3345,7 @@ var ORDER_STATE_EVENTS = {
3329
3345
  };
3330
3346
 
3331
3347
  // booking/types.ts
3348
+ var UNLIMITED_PLACES = Number.MAX_SAFE_INTEGER;
3332
3349
  var BookingRulesError = class extends Error {
3333
3350
  constructor(message) {
3334
3351
  super(message);
@@ -3397,153 +3414,39 @@ function atZonedMinute(dayStart, minutes, timeZone) {
3397
3414
  const { year, month, day } = zonedParts(dayStart, timeZone);
3398
3415
  return instantFromLocal(year, month, day, minutes, timeZone);
3399
3416
  }
3400
-
3401
- // booking/grid.ts
3402
- var MINUTE2 = 6e4;
3403
- var MAX_RANGE_DAYS = 366;
3404
- var asTime = (value, field) => {
3405
- if (value == null) return void 0;
3406
- const time = new Date(value).getTime();
3407
- if (Number.isNaN(time)) throw new BookingRulesError(`Booking rules: ${field} is not a date, got "${String(value)}"`);
3408
- return time;
3409
- };
3410
- function parseHhMm(value, field) {
3411
- const [hours, minutes] = value.split(":").map(Number);
3412
- if (!Number.isInteger(hours) || !Number.isInteger(minutes)) {
3413
- throw new BookingRulesError(`Booking rules: ${field} must be "HH:mm", got "${value}"`);
3414
- }
3415
- return hours * 60 + minutes;
3416
- }
3417
- function windowEndsAt(rule, now) {
3418
- const { maxAdvanceDays, bookableTo } = rule.window;
3419
- const ends = Math.min(
3420
- maxAdvanceDays ? now.getTime() + maxAdvanceDays * 1440 * MINUTE2 : Number.POSITIVE_INFINITY,
3421
- asTime(bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY
3422
- );
3423
- return Number.isFinite(ends) ? new Date(ends) : null;
3424
- }
3425
- function periodSlot(dayStart, timeZone, rule, openMinute, closeMinute) {
3426
- const { ratePeriod, slot, checkInTime, checkOutTime } = rule;
3427
- const at = (minutes) => atZonedMinute(dayStart, minutes, timeZone);
3428
- if (ratePeriod === "night" /* NIGHT */) {
3429
- if (!checkInTime || !checkOutTime) {
3430
- throw new BookingRulesError("Overnight booking rules need both checkInTime and checkOutTime");
3431
- }
3432
- const checkIn = parseHhMm(checkInTime, "checkInTime");
3433
- const checkOut = parseHhMm(checkOutTime, "checkOutTime");
3434
- return {
3435
- startAt: at(checkIn),
3436
- endAt: at(1440 + checkOut),
3437
- // Housekeeping sits between check-out and the next check-in: it costs no night.
3438
- bufferEndAt: at(1440 + checkIn),
3439
- canStart: true
3440
- };
3441
- }
3442
- const from = ratePeriod === "day" /* DAY */ ? openMinute ?? 0 : 0;
3443
- const to = ratePeriod === "day" /* DAY */ ? closeMinute ?? 1440 : 1440;
3444
- return {
3445
- startAt: at(from),
3446
- endAt: at(to),
3447
- bufferEndAt: at(to + (slot.bufferMinutes ?? 0)),
3448
- canStart: true
3449
- };
3450
- }
3451
- function freeGaps(openAt, closeAt, busy) {
3452
- const inside = busy.map(({ startAt, bufferEndAt }) => ({ from: +startAt, to: +bufferEndAt })).filter(({ from, to }) => to > openAt && from < closeAt).sort((first, second) => first.from - second.from);
3453
- const gaps = [];
3454
- let cursor = openAt;
3455
- for (const { from, to } of inside) {
3456
- if (from > cursor) gaps.push({ from: cursor, to: from, endsAtBooking: true });
3457
- cursor = Math.max(cursor, to);
3458
- if (cursor >= closeAt) break;
3459
- }
3460
- if (cursor < closeAt) gaps.push({ from: cursor, to: closeAt, endsAtBooking: false });
3461
- return gaps;
3462
- }
3463
- function buildGrid(rule, timeZone, from, to, now, busy = []) {
3464
- if (to.getTime() - from.getTime() > MAX_RANGE_DAYS * 1440 * MINUTE2) {
3465
- throw new BookingRulesError(`A booking range may span at most ${MAX_RANGE_DAYS} days`);
3466
- }
3467
- const { availability, slot, window, ratePeriod } = rule;
3468
- const periodMode = ratePeriod !== "slot" /* SLOT */;
3469
- const weeklyHours = availability.weeklyHours ?? [];
3470
- const notBefore = Math.max(
3471
- now.getTime() + (window.minNoticeMinutes ?? 0) * MINUTE2,
3472
- asTime(window.bookableFrom, "window.bookableFrom") ?? 0,
3473
- asTime(availability.availableFrom, "availability.availableFrom") ?? 0
3474
- );
3475
- const notAfter = windowEndsAt(rule, now)?.getTime() ?? Number.POSITIVE_INFINITY;
3476
- const blocked = (availability.offMarket ?? []).map(({ from: blockFrom, to: blockTo }) => ({
3477
- from: asTime(blockFrom, "availability.offMarket.from"),
3478
- to: asTime(blockTo, "availability.offMarket.to")
3479
- }));
3480
- const arrivalDays = availability.arrivalDays;
3481
- const step = slot.lengthMinutes + (slot.bufferMinutes ?? 0);
3482
- const slots = [];
3483
- const lastDay = startOfZonedDay(to, timeZone).getTime();
3484
- let dayStart = startOfZonedDay(from, timeZone);
3485
- while (dayStart.getTime() <= lastDay) {
3486
- const weekday = zonedParts(dayStart, timeZone).weekday;
3487
- const rows = weeklyHours.filter((entry) => entry.weekday === weekday);
3488
- if (periodMode) {
3489
- const openToday = weeklyHours.length === 0 || rows.length > 0;
3490
- if (openToday) {
3491
- const built = periodSlot(dayStart, timeZone, rule, rows[0]?.openMinute, rows[0]?.closeMinute);
3492
- slots.push({ ...built, canStart: !arrivalDays?.length || arrivalDays.includes(weekday) });
3493
- }
3494
- } else {
3495
- for (const row of rows) {
3496
- const openAt = +atZonedMinute(dayStart, row.openMinute, timeZone);
3497
- const closeAt = +atZonedMinute(dayStart, row.closeMinute, timeZone);
3498
- for (const gap of freeGaps(openAt, closeAt, busy)) {
3499
- const mustFit = (gap.endsAtBooking ? step : slot.lengthMinutes) * MINUTE2;
3500
- for (let start = gap.from; start + mustFit <= gap.to; start += step * MINUTE2) {
3501
- slots.push({
3502
- startAt: new Date(start),
3503
- endAt: new Date(start + slot.lengthMinutes * MINUTE2),
3504
- bufferEndAt: new Date(start + step * MINUTE2),
3505
- canStart: true
3506
- });
3507
- }
3508
- }
3509
- }
3510
- }
3511
- dayStart = nextZonedDay(dayStart, timeZone);
3512
- }
3513
- const askedFrom = from.getTime();
3514
- const askedTo = to.getTime();
3515
- return slots.filter(({ startAt, bufferEndAt }) => {
3516
- const start = startAt.getTime();
3517
- if (start < askedFrom || start >= askedTo) return false;
3518
- if (start < notBefore || start > notAfter) return false;
3519
- return !blocked.some(
3520
- ({ from: blockFrom, to: blockTo }) => start < blockTo && bufferEndAt.getTime() > blockFrom
3521
- );
3522
- }).sort((first, second) => +first.startAt - +second.startAt);
3417
+ function sameDayMonthsLaterDate(year, month, day, months) {
3418
+ const target = new Date(Date.UTC(year, month - 1 + months, 1));
3419
+ const lastDay = new Date(Date.UTC(target.getUTCFullYear(), target.getUTCMonth() + 1, 0)).getUTCDate();
3420
+ return [target.getUTCFullYear(), target.getUTCMonth() + 1, Math.min(day, lastDay)];
3523
3421
  }
3524
- function slotsForWindow(grid, startAt, endAt) {
3525
- const startIndex = grid.findIndex((entry) => entry.startAt.getTime() === startAt.getTime());
3526
- if (startIndex < 0) {
3527
- throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
3528
- }
3529
- if (!grid[startIndex].canStart) {
3530
- throw new BookingRulesError(`${startAt.toISOString()} is not an arrival day for these rules`);
3531
- }
3532
- const covered = [];
3533
- for (let index = startIndex; index < grid.length; index++) {
3534
- const entry = grid[index];
3535
- const previous = covered[covered.length - 1];
3536
- if (previous && entry.startAt.getTime() !== previous.bufferEndAt.getTime()) break;
3537
- covered.push(entry);
3538
- if (entry.endAt.getTime() === endAt.getTime()) return covered;
3539
- if (entry.endAt.getTime() > endAt.getTime()) break;
3540
- }
3422
+ function addClockDuration(from, { count, unit: unit2 }) {
3423
+ if (unit2 === "minute" /* MINUTE */) return new Date(from.getTime() + count * MINUTE);
3424
+ if (unit2 === "hour" /* HOUR */) return new Date(from.getTime() + count * 60 * MINUTE);
3541
3425
  throw new BookingRulesError(
3542
- `${startAt.toISOString()} \u2192 ${endAt.toISOString()} does not line up with the bookable grid`
3426
+ `Booking rules: ${count} ${unit2} is not minutes or hours \u2014 it needs the shop's time zone`
3543
3427
  );
3544
3428
  }
3429
+ var DAYS_IN = {
3430
+ ["day" /* DAY */]: 1,
3431
+ ["night" /* NIGHT */]: 1,
3432
+ ["week" /* WEEK */]: 7
3433
+ };
3434
+ function addDuration(from, duration, timeZone) {
3435
+ const { count, unit: unit2 } = duration;
3436
+ if (unit2 === "minute" /* MINUTE */ || unit2 === "hour" /* HOUR */) return addClockDuration(from, duration);
3437
+ const days = DAYS_IN[unit2];
3438
+ if (days === void 0 && unit2 !== "month" /* MONTH */) {
3439
+ throw new BookingRulesError(`Booking rules: "${unit2}" is not a duration unit`);
3440
+ }
3441
+ if (!Number.isInteger(count)) throw new BookingRulesError(`Booking rules: ${count} ${unit2} is not a whole number`);
3442
+ const { year, month, day, hour, minute, second } = zonedParts(from, timeZone);
3443
+ const [toYear, toMonth, toDay] = days === void 0 ? sameDayMonthsLaterDate(year, month, day, count) : [year, month, day + days * count];
3444
+ const wallClock = instantFromLocal(toYear, toMonth, toDay, hour * 60 + minute, timeZone);
3445
+ return new Date(wallClock.getTime() + second * 1e3 + from.getUTCMilliseconds());
3446
+ }
3545
3447
 
3546
3448
  // booking/availability.ts
3449
+ var placesOnTheWire = (entry) => Number.isFinite(entry.capacity) ? entry : { ...entry, capacity: UNLIMITED_PLACES, free: UNLIMITED_PLACES, unlimited: true };
3547
3450
  var withinPresence = (slot, timeZone, presence) => {
3548
3451
  if (!presence?.length) return true;
3549
3452
  const dayStart = startOfZonedDay(slot.startAt, timeZone);
@@ -3590,25 +3493,33 @@ function shopDayRange(fromDayKey, count, timeZone) {
3590
3493
  function buildAvailability({
3591
3494
  productId,
3592
3495
  bookingRulesId,
3593
- bookingType,
3594
3496
  rule,
3595
3497
  resources,
3596
3498
  occupied,
3597
3499
  from,
3598
3500
  to,
3599
- now
3501
+ now,
3502
+ timeZone
3600
3503
  }) {
3601
3504
  const shared = rule.slot.sharedAcrossProducts ?? false;
3602
- const bookableUntil = windowEndsAt(rule, now);
3505
+ const bookableUntil = windowEndsAtInZone(rule, now, timeZone ?? null);
3506
+ const parts = bookingRuleParts(rule);
3603
3507
  const header = {
3604
3508
  productId,
3605
3509
  bookingRulesId,
3606
- bookingType,
3607
3510
  ratePeriod: rule.ratePeriod,
3511
+ // Time slots / sessions / date ranges — so a reader never re-classifies `ratePeriod` itself.
3512
+ bookingMethod: bookingMethodOf(rule),
3608
3513
  // Passed through for the UI to label: a group slot under minimumToRun may not run.
3609
3514
  minimumToRun: rule.slot.minimumToRun,
3610
3515
  minStay: rule.slot.minStay,
3611
3516
  maxStay: rule.slot.maxStay,
3517
+ // The same limits with their own units, both rule shapes. `minStay` / `maxStay` above go at B13 step 9.
3518
+ minStayLength: parts.method === "date-ranges" ? parts.minStay : void 0,
3519
+ maxStayLength: parts.method === "date-ranges" ? parts.maxStay : void 0,
3520
+ // The per-booking limits, so a stepper is bounded by the rules (G7) instead of a number in the flow.
3521
+ maxQtyPerBooking: rule.slot.maxQtyPerBooking,
3522
+ maxPartySize: rule.slot.maxPartySize,
3612
3523
  // Why a day can come back empty. Past this instant the rule refuses everything, so the UI
3613
3524
  // can say "beyond the booking window" where it would otherwise claim "nothing free".
3614
3525
  bookableUntil,
@@ -3632,7 +3543,7 @@ function buildAvailability({
3632
3543
  const byInstant = /* @__PURE__ */ new Map();
3633
3544
  const freeSlotsPerResource = /* @__PURE__ */ new Map();
3634
3545
  for (const { resource, slots: slots2 } of grids) {
3635
- const capacity = resource.seats ?? 1;
3546
+ const capacity = capacityOf(rule, resource);
3636
3547
  const mine = byResource.get(resource.id) ?? [];
3637
3548
  for (const slot of slots2) {
3638
3549
  const { taken, foreignProductId } = occupancyIn(mine, productId, slot.startAt, slot.bufferEndAt, shared);
@@ -3649,7 +3560,9 @@ function buildAvailability({
3649
3560
  entry.booked += foreignProductId ? capacity : taken;
3650
3561
  entry.free += free;
3651
3562
  entry.canStart = entry.canStart || slot.canStart;
3652
- entry.resources.push({ resourceId: resource.id, name: resource.name, capacity, booked: taken, free });
3563
+ entry.resources.push(
3564
+ placesOnTheWire({ resourceId: resource.id, name: resource.name, capacity, booked: taken, free })
3565
+ );
3653
3566
  if (free > 0) freeSlotsPerResource.set(resource.id, (freeSlotsPerResource.get(resource.id) ?? 0) + 1);
3654
3567
  byInstant.set(+slot.startAt, entry);
3655
3568
  }
@@ -3671,9 +3584,10 @@ function buildAvailability({
3671
3584
  )
3672
3585
  };
3673
3586
  });
3674
- const slots = [...byInstant.values()].sort((first, second) => +first.startAt - +second.startAt);
3587
+ const slots = [...byInstant.values()].map(placesOnTheWire).map((slot) => withMaxQtyNow(slot, slot.resources, rule.slot.maxQtyPerBooking)).sort((first, second) => +first.startAt - +second.startAt);
3675
3588
  return {
3676
3589
  ...header,
3590
+ course: soldAsCourse(rule) ? courseAvailability(rule, resources, byResource, productId, shared, now) : void 0,
3677
3591
  resources: inWindow,
3678
3592
  slots,
3679
3593
  /**
@@ -3685,6 +3599,51 @@ function buildAvailability({
3685
3599
  days: [...new Set(slots.map((slot) => slot.dayKey))]
3686
3600
  };
3687
3601
  }
3602
+ function courseAvailability(rule, resources, byResource, productId, shared, now) {
3603
+ if (resources.length === 0) return void 0;
3604
+ const sessions = courseSessions(rule, resources[0].timeZone);
3605
+ const alreadyStarted = courseStartedInZone(rule, sessions, now, resources[0].timeZone);
3606
+ const free = resources.map((resource) => {
3607
+ const mine = byResource.get(resource.id) ?? [];
3608
+ const everySession = sessions.every((session) => withinPresence(session, resource.timeZone, resource.presence));
3609
+ const freePerSession = sessions.map((session) => {
3610
+ const { taken, foreignProductId } = occupancyIn(mine, productId, session.startAt, session.bufferEndAt, shared);
3611
+ return foreignProductId ? 0 : Math.max(capacityOf(rule, resource) - taken, 0);
3612
+ });
3613
+ const fewest = everySession && !alreadyStarted ? Math.min(...freePerSession) : 0;
3614
+ return Number.isFinite(fewest) ? { resourceId: resource.id, free: fewest } : { resourceId: resource.id, free: UNLIMITED_PLACES, unlimited: true };
3615
+ });
3616
+ return withMaxQtyNow(
3617
+ {
3618
+ sessions: sessions.length,
3619
+ alreadyStarted,
3620
+ sessionTimes: sessions.map(({ startAt, endAt }) => ({ startAt, endAt })),
3621
+ startAt: sessions[0].startAt,
3622
+ endAt: sessions[sessions.length - 1].endAt,
3623
+ resources: free
3624
+ },
3625
+ free,
3626
+ rule.slot.maxQtyPerBooking
3627
+ );
3628
+ }
3629
+ function pickFreeResource(slot, qty = 1) {
3630
+ return slot.resources.find((entry) => entry.free >= qty);
3631
+ }
3632
+ function withMaxQtyNow(entry, resources, maxQtyPerBooking) {
3633
+ const largest = resources.some((resource) => resource.unlimited) ? Number.POSITIVE_INFINITY : Math.max(0, ...resources.map((resource) => resource.free));
3634
+ const maxQtyNow = Math.min(largest, maxQtyPerBooking ?? Number.POSITIVE_INFINITY);
3635
+ return Number.isFinite(maxQtyNow) ? { ...entry, maxQtyNow } : entry;
3636
+ }
3637
+ function fewestFreeOver(slots, from, to) {
3638
+ const cells = slots.filter(({ startAt, endAt }) => +startAt >= +from && +endAt <= +to);
3639
+ if (cells.length === 0) return [];
3640
+ return cells[0].resources.map((resource) => ({
3641
+ ...resource,
3642
+ free: Math.min(
3643
+ ...cells.map((cell) => cell.resources.find(({ resourceId }) => resourceId === resource.resourceId)?.free ?? 0)
3644
+ )
3645
+ }));
3646
+ }
3688
3647
  function presentAt(resources, rows, outletId) {
3689
3648
  const byResource = /* @__PURE__ */ new Map();
3690
3649
  for (const row of rows) {
@@ -3698,6 +3657,107 @@ function presentAt(resources, rows, outletId) {
3698
3657
  });
3699
3658
  }
3700
3659
 
3660
+ // booking/durations.ts
3661
+ var { MINUTE: MINUTE2, HOUR, DAY, NIGHT, WEEK, MONTH } = BookingDurationUnit;
3662
+ var NONE = [];
3663
+ var CLOCK = [MINUTE2, HOUR];
3664
+ var everyType = (units) => Object.fromEntries(Object.values(BookingRatePeriod).map((ratePeriod) => [ratePeriod, units]));
3665
+ var STAY = {
3666
+ slot: NONE,
3667
+ session: NONE,
3668
+ hour: [HOUR, DAY, WEEK],
3669
+ night: [NIGHT, WEEK, MONTH],
3670
+ day: [DAY, WEEK, MONTH],
3671
+ week: [WEEK],
3672
+ month: [MONTH]
3673
+ };
3674
+ var ALLOWED_UNITS = {
3675
+ "timeSlots.length": { ...everyType(NONE), slot: CLOCK },
3676
+ "slot.buffer": { ...everyType(CLOCK), night: NONE },
3677
+ "window.hold": everyType(CLOCK),
3678
+ "window.minNotice": everyType([MINUTE2, HOUR, DAY, WEEK]),
3679
+ "window.maxAdvance": everyType([MINUTE2, HOUR, DAY, WEEK, MONTH]),
3680
+ "dateRanges.minStay": STAY,
3681
+ "dateRanges.maxStay": STAY
3682
+ };
3683
+ function allowedDurationUnits(rule, field) {
3684
+ const units = ALLOWED_UNITS[field]?.[rule.ratePeriod];
3685
+ if (!units) throw new BookingRulesError(`Booking rules: no duration "${field}" for rate period "${rule.ratePeriod}"`);
3686
+ return units;
3687
+ }
3688
+ var DURATION_AT = {
3689
+ "timeSlots.length": (rule) => rule.timeSlots?.length,
3690
+ "slot.buffer": (rule) => rule.slot.buffer,
3691
+ "window.hold": (rule) => rule.window.hold,
3692
+ "window.minNotice": (rule) => rule.window.minNotice,
3693
+ "window.maxAdvance": (rule) => rule.window.maxAdvance,
3694
+ "dateRanges.minStay": (rule) => rule.dateRanges?.minStay,
3695
+ "dateRanges.maxStay": (rule) => rule.dateRanges?.maxStay
3696
+ };
3697
+ function durationProblems(rule) {
3698
+ const problems = Object.keys(DURATION_AT).flatMap((field) => {
3699
+ const duration = DURATION_AT[field](rule);
3700
+ const problem = duration && problemOf(field, duration, allowedDurationUnits(rule, field), rule.ratePeriod);
3701
+ return problem ? [problem] : [];
3702
+ });
3703
+ if (problems.length > 0) return problems;
3704
+ return [stayAboveMax(rule.dateRanges?.minStay, rule.dateRanges?.maxStay), noticeAboveAdvance(rule.window)].filter(
3705
+ (problem) => !!problem
3706
+ );
3707
+ }
3708
+ function problemOf(field, duration, allowed, ratePeriod) {
3709
+ if (!Number.isInteger(duration.count) || duration.count < 1) {
3710
+ const message = `${field}: count must be a whole number of at least 1, got ${String(duration.count)}`;
3711
+ return { field, kind: "count", message };
3712
+ }
3713
+ if (allowed.length === 0) {
3714
+ return { field, kind: "not-for-type", message: `${field}: does not apply to ${ratePeriod} rules` };
3715
+ }
3716
+ if (!allowed.includes(duration.unit)) {
3717
+ return { field, kind: "unit", allowed, message: `${field}: takes ${allowed.join(", ")}, got ${duration.unit}` };
3718
+ }
3719
+ return void 0;
3720
+ }
3721
+ var MINUTES_RANGE = {
3722
+ minute: [1, 1],
3723
+ hour: [60, 60],
3724
+ day: [1440, 1440],
3725
+ night: [1440, 1440],
3726
+ week: [7 * 1440, 7 * 1440],
3727
+ month: [28 * 1440, 31 * 1440]
3728
+ };
3729
+ var clockShiftOf = (unit2) => unit2 === MINUTE2 || unit2 === HOUR ? 0 : 60;
3730
+ var shortestMinutesOf = ({ count, unit: unit2 }) => count * MINUTES_RANGE[unit2][0] - clockShiftOf(unit2);
3731
+ var longestMinutesOf = ({ count, unit: unit2 }) => count * MINUTES_RANGE[unit2][1] + clockShiftOf(unit2);
3732
+ var durationText = ({ count, unit: unit2 }) => `${count} ${unit2}${count === 1 ? "" : "s"}`;
3733
+ var DAYS_IN_UNIT = { day: 1, night: 1, week: 7 };
3734
+ var MINUTES_IN_UNIT = { minute: 1, hour: 60 };
3735
+ function exactly(min, max) {
3736
+ if (min.unit === max.unit) return [min.count, max.count];
3737
+ for (const table of [DAYS_IN_UNIT, MINUTES_IN_UNIT]) {
3738
+ const [minSize, maxSize] = [table[min.unit], table[max.unit]];
3739
+ if (minSize && maxSize) return [min.count * minSize, max.count * maxSize];
3740
+ }
3741
+ return void 0;
3742
+ }
3743
+ function minLongerThanMax(min, max) {
3744
+ const exact = exactly(min, max);
3745
+ return exact ? exact[0] > exact[1] : longestMinutesOf(min) > shortestMinutesOf(max);
3746
+ }
3747
+ function stayAboveMax(min, max) {
3748
+ if (!min || !max || !minLongerThanMax(min, max)) return void 0;
3749
+ const message = `dateRanges.maxStay: Max ${durationText(max)} can be shorter than Min ${durationText(min)}`;
3750
+ return { field: "dateRanges.maxStay", kind: "min-above-max", min, max, message };
3751
+ }
3752
+ function noticeAboveAdvance({
3753
+ minNotice,
3754
+ maxAdvance
3755
+ }) {
3756
+ if (!minNotice || !maxAdvance || !minLongerThanMax(minNotice, maxAdvance)) return void 0;
3757
+ const message = `window.maxAdvance: ${durationText(maxAdvance)} ahead can be shorter than the notice of ${durationText(minNotice)}`;
3758
+ return { field: "window.maxAdvance", kind: "min-above-max", min: minNotice, max: maxAdvance, message };
3759
+ }
3760
+
3701
3761
  // booking/plan.ts
3702
3762
  var DEFAULT_HOLD_MINUTES = 10;
3703
3763
  function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }) {
@@ -3705,17 +3765,687 @@ function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }
3705
3765
  (slot) => withinPresence(slot, timeZone, presence)
3706
3766
  );
3707
3767
  const slots = slotsForWindow(grid, startAt, endAt);
3708
- const { minStay, maxStay } = rule.slot;
3709
- if (minStay && slots.length < minStay) {
3710
- throw new BookingRulesError(`These rules ask for at least ${minStay} period(s), got ${slots.length}`);
3768
+ const last = slots[slots.length - 1];
3769
+ const parts = bookingRuleParts(rule);
3770
+ const wholePeriods = parts.method === "date-ranges" && parts.wholePeriods;
3771
+ const periods = wholePeriods ? wholePeriodsIn(rule.ratePeriod, timeZone, startAt, last.endAt, slots.length) : slots.length;
3772
+ checkStay(parts, timeZone, startAt, periods);
3773
+ const { buffer } = ruleDurationsOf(rule);
3774
+ const bufferEndAt = rule.ratePeriod === "hour" /* HOUR */ || wholePeriods ? buffer ? addDuration(last.endAt, buffer, timeZone) : new Date(last.endAt.getTime()) : last.bufferEndAt;
3775
+ return { slots, periods, endAt: last.endAt, bufferEndAt };
3776
+ }
3777
+ function checkStay(parts, timeZone, startAt, periods) {
3778
+ if (parts.method !== "date-ranges") return;
3779
+ const stay = { count: periods, unit: periodUnitOf(parts) };
3780
+ const length = (duration) => stayLength(parts.ratePeriod, duration, startAt, timeZone);
3781
+ const { minStay, maxStay } = parts;
3782
+ if (minStay && length(stay) < length(minStay)) {
3783
+ throw new BookingRulesError(
3784
+ `These rules ask for a stay of at least ${durationText(minStay)}, got ${durationText(stay)}`
3785
+ );
3711
3786
  }
3712
- if (maxStay && slots.length > maxStay) {
3713
- throw new BookingRulesError(`These rules allow at most ${maxStay} period(s), got ${slots.length}`);
3787
+ if (maxStay && length(stay) > length(maxStay)) {
3788
+ throw new BookingRulesError(
3789
+ `These rules allow a stay of at most ${durationText(maxStay)}, got ${durationText(stay)}`
3790
+ );
3714
3791
  }
3715
- const last = slots[slots.length - 1];
3716
- return { slots, endAt: last.endAt, bufferEndAt: last.bufferEndAt };
3717
3792
  }
3718
- var holdExpiresAt = (rule, now) => new Date(now.getTime() + (rule.window.holdMinutes ?? DEFAULT_HOLD_MINUTES) * 6e4);
3793
+ function stayLength(ratePeriod, duration, startAt, timeZone) {
3794
+ if (ratePeriod === "hour" /* HOUR */) return addDuration(startAt, duration, timeZone).getTime();
3795
+ const { count, unit: unit2 } = duration;
3796
+ if (unit2 === "day" /* DAY */ || unit2 === "night" /* NIGHT */) return count;
3797
+ if (unit2 === "week" /* WEEK */) return 7 * count;
3798
+ if (unit2 !== "month" /* MONTH */) {
3799
+ throw new BookingRulesError(`Booking rules: a ${ratePeriod} stay cannot be counted in ${unit2}s`);
3800
+ }
3801
+ const { year, month, day } = zonedParts(startAt, timeZone);
3802
+ const [toYear, toMonth, toDay] = sameDayMonthsLaterDate(year, month, day, count);
3803
+ return (Date.UTC(toYear, toMonth - 1, toDay) - Date.UTC(year, month - 1, day)) / 864e5;
3804
+ }
3805
+ function windowForPeriods({ rule, timeZone, startAt, periods, now }) {
3806
+ if (!Number.isInteger(periods) || periods < 1) {
3807
+ throw new BookingRulesError(`periods must be a whole number of at least 1, got ${String(periods)}`);
3808
+ }
3809
+ const parts = bookingRuleParts(rule);
3810
+ checkStay(parts, timeZone, startAt, periods);
3811
+ const wholePeriods = parts.method === "date-ranges" && parts.wholePeriods;
3812
+ const monthsEnd = wholePeriods && rule.ratePeriod === "month" /* MONTH */ ? sameDayMonthsLater(startAt, periods, timeZone) : null;
3813
+ const cells = wholePeriods && rule.ratePeriod === "week" /* WEEK */ ? periods * 7 : periods;
3814
+ const lastDay = monthsEnd ?? new Date(startAt.getTime() + (cells + 2) * 1440 * 6e4);
3815
+ const grid = buildGrid(
3816
+ rule,
3817
+ timeZone,
3818
+ startAt,
3819
+ new Date(Math.min(lastDay.getTime() + 1440 * 6e4, startAt.getTime() + 366 * 1440 * 6e4)),
3820
+ now
3821
+ );
3822
+ const startIndex = grid.findIndex((cell) => cell.startAt.getTime() === startAt.getTime());
3823
+ if (startIndex < 0)
3824
+ throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
3825
+ const endAt = monthsEnd ?? grid[startIndex + cells - 1]?.endAt;
3826
+ if (!endAt)
3827
+ throw new BookingRulesError(`${periods} period(s) from ${startAt.toISOString()} run past the bookable grid`);
3828
+ slotsForWindow(grid, startAt, endAt);
3829
+ return { startAt, endAt };
3830
+ }
3831
+ function rentalEnds(input) {
3832
+ const { rule, timeZone, startAt, now, untilDay } = input;
3833
+ const parts = bookingRuleParts(rule);
3834
+ if (parts.method !== "date-ranges") throw new BookingRulesError("Only date-range rules book a stay");
3835
+ const horizon = shopDayRange(untilDay, 1, timeZone).to;
3836
+ if (horizon <= startAt) throw new BookingRulesError(`untilDay ${untilDay} is before the stay starts`);
3837
+ const gridUntil = (end) => buildGrid(rule, timeZone, startAt, new Date(Math.min(end, startAt.getTime() + 366 * 1440 * 6e4)), now);
3838
+ let walk = walkRentalEnds(gridUntil(horizon.getTime() + 1440 * 6e4), input, parts, horizon);
3839
+ if (!walk.ends.length && walk.refusal && walk.ranOut)
3840
+ walk = walkRentalEnds(gridUntil(Infinity), input, parts, horizon);
3841
+ if (walk.ends.length) return walk.ends;
3842
+ throw walk.refusal ?? new BookingRulesError(
3843
+ `No stay from ${startAt.toISOString()} fits these rules: the bookable days run out before the shortest allowed stay`
3844
+ );
3845
+ }
3846
+ function walkRentalEnds(grid, { rule, timeZone, startAt, untilDay }, parts, horizon) {
3847
+ const startIndex = grid.findIndex((cell) => cell.startAt.getTime() === startAt.getTime());
3848
+ if (startIndex < 0) {
3849
+ throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
3850
+ }
3851
+ slotsForWindow(grid, startAt, grid[startIndex].endAt);
3852
+ const ends = [];
3853
+ let refusal;
3854
+ for (const cell of grid.slice(startIndex)) {
3855
+ if (cell.endAt > horizon && (ends.length || !refusal)) {
3856
+ refusal ??= new BookingRulesError(`No stay from ${startAt.toISOString()} ends on or before ${untilDay}`);
3857
+ return { ends, refusal, ranOut: false };
3858
+ }
3859
+ const slots = refusalOr(() => slotsForWindow(grid, startAt, cell.endAt));
3860
+ if (slots instanceof BookingRulesError) return { ends, refusal, ranOut: false };
3861
+ const periods = refusalOr(
3862
+ () => parts.wholePeriods ? wholePeriodsIn(rule.ratePeriod, timeZone, startAt, cell.endAt, slots.length) : slots.length
3863
+ );
3864
+ if (periods instanceof BookingRulesError) continue;
3865
+ const stay = refusalOr(() => checkStay(parts, timeZone, startAt, periods));
3866
+ if (stay instanceof BookingRulesError) {
3867
+ if (ends.length) return { ends, refusal, ranOut: false };
3868
+ refusal = stay;
3869
+ continue;
3870
+ }
3871
+ ends.push(rentalEndOf(slots, periods, timeZone));
3872
+ }
3873
+ return { ends, refusal, ranOut: true };
3874
+ }
3875
+ function rentalEndOf(slots, periods, timeZone) {
3876
+ const endAt = slots[slots.length - 1].endAt;
3877
+ return {
3878
+ periods,
3879
+ endAt: endAt.toISOString(),
3880
+ lastDayKey: shopDayKey(new Date(endAt.getTime() - 1), timeZone),
3881
+ coveredSlots: slots.map((slot) => ({
3882
+ startAt: slot.startAt.toISOString(),
3883
+ dayKey: shopDayKey(slot.startAt, timeZone)
3884
+ }))
3885
+ };
3886
+ }
3887
+ function refusalOr(run) {
3888
+ try {
3889
+ return run();
3890
+ } catch (error) {
3891
+ if (error instanceof BookingRulesError) return error;
3892
+ throw error;
3893
+ }
3894
+ }
3895
+ function sameDayMonthsLater(startAt, months, timeZone) {
3896
+ const { year, month, day } = zonedParts(startAt, timeZone);
3897
+ return instantFromLocal(...sameDayMonthsLaterDate(year, month, day, months), 0, timeZone);
3898
+ }
3899
+ function wholePeriodsIn(ratePeriod, timeZone, startAt, endAt, days) {
3900
+ if (ratePeriod === "week" /* WEEK */) {
3901
+ if (days % 7 !== 0) throw new BookingRulesError(`Book whole weeks: ${days} day(s) is not a number of weeks`);
3902
+ return days / 7;
3903
+ }
3904
+ if (ratePeriod !== "month" /* MONTH */) {
3905
+ throw new BookingRulesError("Whole periods are for week and month rules only");
3906
+ }
3907
+ const start = zonedParts(startAt, timeZone);
3908
+ const end = zonedParts(endAt, timeZone);
3909
+ const months = (end.year - start.year) * 12 + (end.month - start.month);
3910
+ const lastDayOfEndMonth = new Date(Date.UTC(end.year, end.month, 0)).getUTCDate();
3911
+ if (months < 1 || end.day !== Math.min(start.day, lastDayOfEndMonth)) {
3912
+ throw new BookingRulesError("Book whole months: the stay must end on the same day of a later month");
3913
+ }
3914
+ return months;
3915
+ }
3916
+ function courseSessions(rule, timeZone) {
3917
+ const { bookableFrom, bookableTo } = rule.window;
3918
+ if (!bookableFrom || !bookableTo) throw new BookingRulesError("A course needs both course dates");
3919
+ const sessions = sessionCells(rule, timeZone, new Date(bookableFrom), new Date(bookableTo)).sort(
3920
+ (first, second) => +first.startAt - +second.startAt
3921
+ );
3922
+ if (sessions.length === 0) throw new BookingRulesError("These course dates hold no session");
3923
+ return sessions;
3924
+ }
3925
+ var courseStarted = (rule, sessions, now) => sessions[0].startAt.getTime() < now.getTime() + (rule.window.minNoticeMinutes ?? 0) * 6e4;
3926
+ function courseStartedInZone(rule, sessions, now, timeZone) {
3927
+ const { minNotice } = ruleDurationsOf(rule);
3928
+ return sessions[0].startAt.getTime() < (minNotice ? addDuration(now, minNotice, timeZone) : now).getTime();
3929
+ }
3930
+ function planCourse({ rule, timeZone, presence, now }) {
3931
+ const sessions = courseSessions(rule, timeZone);
3932
+ if (!sessions.every((session) => withinPresence(session, timeZone, presence))) {
3933
+ throw new BookingRulesError("This resource is not there for every session of the course");
3934
+ }
3935
+ if (courseStartedInZone(rule, sessions, now, timeZone))
3936
+ throw new BookingRulesError("This course has already started");
3937
+ return sessions;
3938
+ }
3939
+ function holdExpiresAt(rule, now) {
3940
+ return addClockDuration(now, holdOf(rule) ?? DEFAULT_HOLD);
3941
+ }
3942
+ var DEFAULT_HOLD = { count: DEFAULT_HOLD_MINUTES, unit: "minute" /* MINUTE */ };
3943
+ function holdOf(rule) {
3944
+ const { hold } = ruleDurationsOf(rule);
3945
+ if (!hold) return void 0;
3946
+ const field = rule.window.hold ? "window.hold" : "window.holdMinutes";
3947
+ if (!Number.isInteger(hold.count)) {
3948
+ throw new BookingRulesError(`${field} must be a whole number of ${hold.unit}s, got ${hold.count}`);
3949
+ }
3950
+ if (hold.count < 1) throw new BookingRulesError(`${field} must be at least 1 ${hold.unit}, got ${hold.count}`);
3951
+ return hold;
3952
+ }
3953
+ function checkQtyPerBooking(rule, qty) {
3954
+ const max = rule.slot.maxQtyPerBooking;
3955
+ if (max !== void 0 && qty > max) {
3956
+ throw new BookingRulesError(`These rules allow at most ${max} per booking, got ${qty}`);
3957
+ }
3958
+ }
3959
+ function checkPartySize(rule, partySize) {
3960
+ const max = rule.slot.maxPartySize;
3961
+ if (max !== void 0 && partySize > max) {
3962
+ throw new BookingRulesError(`These rules allow at most ${max} people per booking, got ${partySize}`);
3963
+ }
3964
+ }
3965
+ function bookingMethodOf(rule) {
3966
+ if (rule.ratePeriod === "slot" /* SLOT */) return "time-slots";
3967
+ if (rule.ratePeriod === "session" /* SESSION */) return "sessions";
3968
+ return "date-ranges";
3969
+ }
3970
+ var soldAsCourse = (rule) => rule.ratePeriod === "session" /* SESSION */ && rule.sessions?.sold === "course" /* COURSE */;
3971
+ function capacityOf(rule, resource) {
3972
+ if (rule.ratePeriod !== "session" /* SESSION */) return resource.seats ?? 1;
3973
+ if (!rule.sessions) throw new BookingRulesError("Scheduled-session rules need their sessions");
3974
+ return rule.sessions.spots ?? Number.POSITIVE_INFINITY;
3975
+ }
3976
+ function bookingRuleParts(rule) {
3977
+ const method = bookingMethodOf(rule);
3978
+ if (method === "sessions") {
3979
+ if (!rule.sessions) throw new BookingRulesError("Scheduled-session rules need their sessions");
3980
+ return { method, sessions: rule.sessions };
3981
+ }
3982
+ if (method === "time-slots") {
3983
+ const timeSlots = rule.timeSlots ? newTimeSlotsOf(rule.timeSlots) : oldTimeSlotsOf(rule);
3984
+ const { count } = timeSlots.length;
3985
+ if (!Number.isInteger(count) || count < 1) {
3986
+ const field = rule.timeSlots ? "timeSlots.length" : "slot.lengthMinutes";
3987
+ throw new BookingRulesError(`Booking rules: ${field} must be a whole number of at least 1, got ${count}`);
3988
+ }
3989
+ return { method, ...timeSlots };
3990
+ }
3991
+ if (!rule.dateRanges) return { method, ratePeriod: rule.ratePeriod, ...oldDateRangesOf(rule) };
3992
+ const wholePeriods = rule.ratePeriod === "week" /* WEEK */ || rule.ratePeriod === "month" /* MONTH */;
3993
+ return { method, ratePeriod: rule.ratePeriod, wholePeriods, ...rule.dateRanges };
3994
+ }
3995
+ function newTimeSlotsOf({ length, weeklyHours }) {
3996
+ if (!weeklyHours?.length) throw new BookingRulesError("Booking rules: timeSlots.weeklyHours needs at least one day");
3997
+ return { length, weeklyHours };
3998
+ }
3999
+ function oldTimeSlotsOf({ slot, availability }) {
4000
+ if (slot.lengthMinutes == null) throw new BookingRulesError("Time-slot rules need their slot length");
4001
+ return {
4002
+ length: { count: slot.lengthMinutes, unit: "minute" /* MINUTE */ },
4003
+ weeklyHours: availability.weeklyHours ?? []
4004
+ };
4005
+ }
4006
+ function oldDateRangesOf(rule) {
4007
+ const { slot, availability } = rule;
4008
+ const wholePeriods = slot.wholePeriods ?? false;
4009
+ const stay = (count) => count ? { count, unit: periodUnitOf({ ratePeriod: rule.ratePeriod, wholePeriods }) } : void 0;
4010
+ return {
4011
+ // Old `[]` meant "open every day" — the new form says that by having no rows.
4012
+ weeklyHours: availability.weeklyHours?.length ? availability.weeklyHours : void 0,
4013
+ arrivalDays: availability.arrivalDays,
4014
+ checkInTime: rule.checkInTime,
4015
+ checkOutTime: rule.checkOutTime,
4016
+ checkTimesByWeekday: rule.checkTimesByWeekday,
4017
+ minStay: stay(slot.minStay),
4018
+ maxStay: stay(slot.maxStay),
4019
+ wholePeriods
4020
+ };
4021
+ }
4022
+ function periodUnitOf({
4023
+ ratePeriod,
4024
+ wholePeriods
4025
+ }) {
4026
+ const units = {
4027
+ ["hour" /* HOUR */]: "hour" /* HOUR */,
4028
+ ["night" /* NIGHT */]: "night" /* NIGHT */,
4029
+ ["day" /* DAY */]: "day" /* DAY */,
4030
+ ["week" /* WEEK */]: wholePeriods ? "week" /* WEEK */ : "day" /* DAY */,
4031
+ ["month" /* MONTH */]: wholePeriods ? "month" /* MONTH */ : "day" /* DAY */
4032
+ };
4033
+ const unit2 = units[ratePeriod];
4034
+ if (!unit2) throw new BookingRulesError(`Booking rules: "${ratePeriod}" is not a date-range rate period`);
4035
+ return unit2;
4036
+ }
4037
+ var OLD_BUFFER = {
4038
+ path: "slot.bufferMinutes",
4039
+ home: {
4040
+ "time-slots": "slot.buffer",
4041
+ sessions: "slot.buffer",
4042
+ // The old night grid never read it: housekeeping is the gap between check-out and check-in (O-1).
4043
+ "date-ranges": ({ ratePeriod }) => ratePeriod === "night" /* NIGHT */ ? { unread: "nights clean between check-out and check-in" } : "slot.buffer"
4044
+ }
4045
+ };
4046
+ var OLD_FIELDS = [
4047
+ {
4048
+ path: "slot.lengthMinutes",
4049
+ home: {
4050
+ "time-slots": "timeSlots.length",
4051
+ sessions: { unread: "placeholder" },
4052
+ "date-ranges": { unread: "placeholder" }
4053
+ }
4054
+ },
4055
+ OLD_BUFFER,
4056
+ {
4057
+ path: "slot.minStay",
4058
+ home: {
4059
+ "time-slots": { dropped: "time-slots rules have no stay limits" },
4060
+ sessions: { dropped: "sessions rules have no stay limits" },
4061
+ "date-ranges": "dateRanges.minStay"
4062
+ }
4063
+ },
4064
+ {
4065
+ path: "slot.maxStay",
4066
+ home: {
4067
+ "time-slots": { dropped: "time-slots rules have no stay limits" },
4068
+ sessions: { dropped: "sessions rules have no stay limits" },
4069
+ "date-ranges": "dateRanges.maxStay"
4070
+ }
4071
+ },
4072
+ {
4073
+ path: "window.holdMinutes",
4074
+ home: { "time-slots": "window.hold", sessions: "window.hold", "date-ranges": "window.hold" }
4075
+ },
4076
+ {
4077
+ path: "window.minNoticeMinutes",
4078
+ home: { "time-slots": "window.minNotice", sessions: "window.minNotice", "date-ranges": "window.minNotice" }
4079
+ },
4080
+ // The two old max-advance fields are one fact, as the old readers took it: minutes, else days × 1440.
4081
+ ...["window.maxAdvanceMinutes", "window.maxAdvanceDays"].map((path) => ({
4082
+ path,
4083
+ carried: maxAdvanceMinutesOf,
4084
+ home: { "time-slots": "window.maxAdvance", sessions: "window.maxAdvance", "date-ranges": "window.maxAdvance" }
4085
+ })),
4086
+ {
4087
+ path: "availability.weeklyHours",
4088
+ home: {
4089
+ "time-slots": "timeSlots.weeklyHours",
4090
+ sessions: { unread: "sessions read their timetable" },
4091
+ "date-ranges": "dateRanges.weeklyHours"
4092
+ }
4093
+ },
4094
+ ...["availability.arrivalDays", "checkInTime", "checkOutTime", "checkTimesByWeekday"].map((path) => ({
4095
+ path,
4096
+ home: {
4097
+ "time-slots": { unread: "date ranges only" },
4098
+ sessions: { unread: "date ranges only" },
4099
+ "date-ranges": `dateRanges.${path.replace("availability.", "")}`
4100
+ }
4101
+ }))
4102
+ ];
4103
+ var homeOf = (field, rule) => {
4104
+ const home = field.home[bookingMethodOf(rule)];
4105
+ return typeof home === "function" ? home(rule) : home;
4106
+ };
4107
+ var carriedValueOf = (rule, field) => field.carried ? field.carried(rule) : valueAt(rule, field.path);
4108
+ var carries = (value) => value != null && value !== 0 && !(Array.isArray(value) && value.length === 0);
4109
+ function ruleInNewShape(rule) {
4110
+ const set = { ...typePartInNewShape(rule), ...durationsInNewShape(rule) };
4111
+ const unset = [...OLD_FIELDS.map(({ path }) => path), "slot.wholePeriods"].filter(
4112
+ (path) => valueAt(rule, path) !== void 0
4113
+ );
4114
+ const written = writtenRule(rule, set, unset);
4115
+ bookingRuleParts(written);
4116
+ refuseLostValues(rule, written);
4117
+ const changesBehaviour = sellsOneDayOfWeekOrMonth(rule) ? "whole-periods" : void 0;
4118
+ const notes = [
4119
+ ...droppedFieldNotes(rule, written),
4120
+ ...changesBehaviour ? [`${rule.ratePeriod} rule now sells whole ${rule.ratePeriod}s, was one day per booking`] : []
4121
+ ];
4122
+ return { set, unset, problems: durationProblems(written), notes, ...changesBehaviour && { changesBehaviour } };
4123
+ }
4124
+ function typePartInNewShape(rule) {
4125
+ const method = bookingMethodOf(rule);
4126
+ if (method === "sessions") return {};
4127
+ if (method === "time-slots") return { timeSlots: newTimeSlotsOf(rule.timeSlots ?? oldTimeSlotsOf(rule)) };
4128
+ if (rule.dateRanges) return { dateRanges: rule.dateRanges };
4129
+ const dateRanges = oldDateRangesOf(rule);
4130
+ delete dateRanges.wholePeriods;
4131
+ return { dateRanges: definedOnly(dateRanges) };
4132
+ }
4133
+ function durationsInNewShape(rule) {
4134
+ const { buffer, minNotice } = ruleDurationsOf(rule);
4135
+ return definedOnly({
4136
+ "slot.buffer": rule.slot.buffer ?? (typeof homeOf(OLD_BUFFER, rule) === "string" ? buffer : void 0),
4137
+ "window.hold": holdOf(rule) ?? DEFAULT_HOLD,
4138
+ "window.minNotice": minNotice,
4139
+ "window.maxAdvance": ruleDurationsOf(rule).maxAdvance
4140
+ });
4141
+ }
4142
+ var sellsOneDayOfWeekOrMonth = ({ ratePeriod, slot, dateRanges }) => !dateRanges && (ratePeriod === "week" /* WEEK */ || ratePeriod === "month" /* MONTH */) && !slot.wholePeriods;
4143
+ function droppedFieldNotes(rule, written) {
4144
+ const weekOrMonth = rule.ratePeriod === "week" /* WEEK */ || rule.ratePeriod === "month" /* MONTH */;
4145
+ return [
4146
+ ...OLD_FIELDS.flatMap((field) => {
4147
+ const home = homeOf(field, rule);
4148
+ const dropped = typeof home === "object" && "dropped" in home && carries(carriedValueOf(rule, field));
4149
+ return dropped ? [`${field.path} is dropped: ${home.dropped}`] : [];
4150
+ }),
4151
+ ...rule.slot.wholePeriods && !weekOrMonth ? ["slot.wholePeriods is dropped: only week and month rules have it"] : [],
4152
+ ...rule.ratePeriod === "hour" /* HOUR */ && !written.dateRanges?.weeklyHours?.length ? ["hour rule has no opening hours: nothing can be booked"] : [],
4153
+ ...rule.window.holdMinutes == null && !rule.window.hold ? [`window.hold is set to the default ${DEFAULT_HOLD_MINUTES} minutes`] : []
4154
+ ];
4155
+ }
4156
+ function writtenRule(rule, set, unset) {
4157
+ const written = {
4158
+ ...rule,
4159
+ slot: { ...rule.slot },
4160
+ window: { ...rule.window },
4161
+ availability: { ...rule.availability }
4162
+ };
4163
+ for (const path of unset) {
4164
+ const [head, leaf] = path.split(".");
4165
+ if (leaf) delete written[head][leaf];
4166
+ else delete written[head];
4167
+ }
4168
+ for (const [path, value] of Object.entries(set)) {
4169
+ const [head, leaf] = path.split(".");
4170
+ if (leaf) written[head][leaf] = value;
4171
+ else written[head] = value;
4172
+ }
4173
+ return written;
4174
+ }
4175
+ function refuseLostValues(rule, written) {
4176
+ for (const field of OLD_FIELDS) {
4177
+ const home = homeOf(field, rule);
4178
+ if (typeof home === "string" && carries(carriedValueOf(rule, field)) && valueAt(written, home) == null) {
4179
+ throw new BookingRulesError(`Booking rules: ${home} is missing \u2014 the rule's old value would be lost`);
4180
+ }
4181
+ }
4182
+ }
4183
+ var definedOnly = (value) => Object.fromEntries(Object.entries(value).filter(([, entry]) => entry != null));
4184
+ var valueAt = (rule, path) => path.split(".").reduce((node, key) => node?.[key], rule);
4185
+
4186
+ // booking/grid.ts
4187
+ var MINUTE3 = 6e4;
4188
+ var HOUR_MINUTES = 60;
4189
+ var MAX_RANGE_DAYS = 366;
4190
+ var asTime = (value, field) => {
4191
+ if (value == null) return void 0;
4192
+ const time = new Date(value).getTime();
4193
+ if (Number.isNaN(time)) throw new BookingRulesError(`Booking rules: ${field} is not a date, got "${String(value)}"`);
4194
+ return time;
4195
+ };
4196
+ function parseHhMm(value, field) {
4197
+ const [hours, minutes] = value.split(":").map(Number);
4198
+ if (!Number.isInteger(hours) || !Number.isInteger(minutes)) {
4199
+ throw new BookingRulesError(`Booking rules: ${field} must be "HH:mm", got "${value}"`);
4200
+ }
4201
+ return hours * 60 + minutes;
4202
+ }
4203
+ function windowEndsAt(rule, now) {
4204
+ const maxAdvanceMinutes = maxAdvanceMinutesOf(rule);
4205
+ const ends = Math.min(
4206
+ maxAdvanceMinutes ? now.getTime() + maxAdvanceMinutes * MINUTE3 : Number.POSITIVE_INFINITY,
4207
+ asTime(rule.window.bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY
4208
+ );
4209
+ return Number.isFinite(ends) ? new Date(ends) : null;
4210
+ }
4211
+ function windowEndsAtInZone(rule, now, timeZone) {
4212
+ const { maxAdvance } = ruleDurationsOf(rule);
4213
+ const ends = Math.min(
4214
+ maxAdvance ? addInZone(now, maxAdvance, timeZone, "window.maxAdvance").getTime() : Number.POSITIVE_INFINITY,
4215
+ asTime(rule.window.bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY
4216
+ );
4217
+ return Number.isFinite(ends) ? new Date(ends) : null;
4218
+ }
4219
+ function addInZone(from, duration, timeZone, field) {
4220
+ if (timeZone) return addDuration(from, duration, timeZone);
4221
+ if (duration.unit === "minute" /* MINUTE */ || duration.unit === "hour" /* HOUR */) {
4222
+ return addClockDuration(from, duration);
4223
+ }
4224
+ throw new BookingRulesError(`Booking rules: ${field} in ${duration.unit}s needs the shop's time zone`);
4225
+ }
4226
+ function maxAdvanceMinutesOf(rule) {
4227
+ const { maxAdvanceMinutes, maxAdvanceDays } = rule.window;
4228
+ return maxAdvanceMinutes ?? (maxAdvanceDays ?? 0) * 1440;
4229
+ }
4230
+ var asMinutes = (minutes) => minutes == null ? void 0 : { count: minutes, unit: "minute" /* MINUTE */ };
4231
+ var inMinutes = (minutes) => minutes === 0 ? void 0 : asMinutes(minutes);
4232
+ function notNegative(duration, field) {
4233
+ if (duration && !(Number.isFinite(duration.count) && duration.count >= 0)) {
4234
+ throw new BookingRulesError(`Booking rules: ${field} must be a number of at least 0, got ${duration.count}`);
4235
+ }
4236
+ return duration;
4237
+ }
4238
+ function ruleDurationsOf(rule) {
4239
+ const { slot, window } = rule;
4240
+ return {
4241
+ buffer: notNegative(
4242
+ slot.buffer ?? inMinutes(slot.bufferMinutes),
4243
+ slot.buffer ? "slot.buffer" : "slot.bufferMinutes"
4244
+ ),
4245
+ hold: window.hold ?? asMinutes(window.holdMinutes),
4246
+ minNotice: notNegative(
4247
+ window.minNotice ?? inMinutes(window.minNoticeMinutes),
4248
+ window.minNotice ? "window.minNotice" : "window.minNoticeMinutes"
4249
+ ),
4250
+ maxAdvance: window.maxAdvance ?? oldMaxAdvanceOf(window)
4251
+ };
4252
+ }
4253
+ function oldMaxAdvanceOf({
4254
+ maxAdvanceMinutes,
4255
+ maxAdvanceDays
4256
+ }) {
4257
+ const days = maxAdvanceDays ?? 0;
4258
+ if (maxAdvanceMinutes == null || days > 0 && maxAdvanceMinutes === days * 1440) {
4259
+ return days > 0 ? { count: days, unit: "day" /* DAY */ } : void 0;
4260
+ }
4261
+ return maxAdvanceMinutes ? { count: maxAdvanceMinutes, unit: "minute" /* MINUTE */ } : void 0;
4262
+ }
4263
+ function periodSlot(dayStart, timeZone, parts, buffer, openMinute, closeMinute) {
4264
+ const { ratePeriod } = parts;
4265
+ const at = (minutes) => atZonedMinute(dayStart, minutes, timeZone);
4266
+ if (ratePeriod === "night" /* NIGHT */) {
4267
+ const arrival = zonedParts(dayStart, timeZone).weekday;
4268
+ const departure = (arrival + 1) % 7;
4269
+ return {
4270
+ startAt: at(checkTimesOf(parts, arrival).checkIn),
4271
+ endAt: at(1440 + checkTimesOf(parts, departure).checkOut),
4272
+ // Housekeeping sits between check-out and the next check-in: it costs no night.
4273
+ bufferEndAt: at(1440 + checkTimesOf(parts, departure).checkIn),
4274
+ canStart: true
4275
+ };
4276
+ }
4277
+ const from = ratePeriod === "day" /* DAY */ ? openMinute ?? 0 : 0;
4278
+ const to = ratePeriod === "day" /* DAY */ ? closeMinute ?? 1440 : 1440;
4279
+ const turnaround = parts.wholePeriods ? void 0 : buffer;
4280
+ return {
4281
+ startAt: at(from),
4282
+ endAt: at(to),
4283
+ bufferEndAt: turnaround ? addDuration(at(to), turnaround, timeZone) : at(to),
4284
+ canStart: true
4285
+ };
4286
+ }
4287
+ function checkTimesOf(rule, weekday) {
4288
+ const row = rule.checkTimesByWeekday?.find((entry) => entry.weekday === weekday);
4289
+ const checkInTime = row?.checkInTime ?? rule.checkInTime;
4290
+ const checkOutTime = row?.checkOutTime ?? rule.checkOutTime;
4291
+ if (!checkInTime || !checkOutTime) {
4292
+ throw new BookingRulesError("Overnight booking rules need both checkInTime and checkOutTime");
4293
+ }
4294
+ return { checkIn: parseHhMm(checkInTime, "checkInTime"), checkOut: parseHhMm(checkOutTime, "checkOutTime") };
4295
+ }
4296
+ function freeGaps(openAt, closeAt, busy) {
4297
+ const inside = busy.map(({ startAt, bufferEndAt }) => ({ from: +startAt, to: +bufferEndAt })).filter(({ from, to }) => to > openAt && from < closeAt).sort((first, second) => first.from - second.from);
4298
+ const gaps = [];
4299
+ let cursor = openAt;
4300
+ for (const { from, to } of inside) {
4301
+ if (from > cursor) gaps.push({ from: cursor, to: from, endsAtBooking: true });
4302
+ cursor = Math.max(cursor, to);
4303
+ if (cursor >= closeAt) break;
4304
+ }
4305
+ if (cursor < closeAt) gaps.push({ from: cursor, to: closeAt, endsAtBooking: false });
4306
+ return gaps;
4307
+ }
4308
+ function sessionCells(rule, timeZone, from, to) {
4309
+ if (!rule.sessions) throw new BookingRulesError("Scheduled-session rules need their sessions");
4310
+ const { weekly = [], dates = [] } = rule.sessions;
4311
+ const { buffer } = ruleDurationsOf(rule);
4312
+ const cell = (startAt, endAt) => ({
4313
+ startAt: new Date(startAt),
4314
+ endAt: new Date(endAt),
4315
+ bufferEndAt: buffer ? addDuration(new Date(endAt), buffer, timeZone) : new Date(endAt),
4316
+ canStart: true
4317
+ });
4318
+ const cells = dates.map(({ date, startMinute, endMinute }) => {
4319
+ const [year, month, day] = calendarDate(date);
4320
+ return cell(
4321
+ +instantFromLocal(year, month, day, startMinute, timeZone),
4322
+ +instantFromLocal(year, month, day, endMinute, timeZone)
4323
+ );
4324
+ });
4325
+ const lastDay = startOfZonedDay(to, timeZone).getTime();
4326
+ for (let day = startOfZonedDay(from, timeZone); day.getTime() <= lastDay; day = nextZonedDay(day, timeZone)) {
4327
+ const weekday = zonedParts(day, timeZone).weekday;
4328
+ for (const row of weekly.filter((entry) => entry.weekday === weekday)) {
4329
+ cells.push(cell(+atZonedMinute(day, row.startMinute, timeZone), +atZonedMinute(day, row.endMinute, timeZone)));
4330
+ }
4331
+ }
4332
+ const blocked = offMarketOf(rule);
4333
+ return cells.filter(({ startAt, bufferEndAt }) => {
4334
+ const start = startAt.getTime();
4335
+ return start >= from.getTime() && start <= to.getTime() && !isBlocked(blocked, start, bufferEndAt.getTime());
4336
+ });
4337
+ }
4338
+ function calendarDate(value) {
4339
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value ?? "");
4340
+ const [year, month, day] = match ? match.slice(1).map(Number) : [];
4341
+ const real = match && new Date(Date.UTC(year, month - 1, day)).toISOString().slice(0, 10) === value;
4342
+ if (!real) throw new BookingRulesError(`Booking rules: "${value}" is not a date (YYYY-MM-DD)`);
4343
+ return [year, month, day];
4344
+ }
4345
+ var offMarketOf = (rule) => (rule.availability.offMarket ?? []).map(({ from: blockFrom, to: blockTo }) => ({
4346
+ from: asTime(blockFrom, "availability.offMarket.from"),
4347
+ to: asTime(blockTo, "availability.offMarket.to")
4348
+ }));
4349
+ var isBlocked = (blocked, start, bufferEnd) => blocked.some(({ from, to }) => start < to && bufferEnd > from);
4350
+ function hourCells(openAt, closeAt) {
4351
+ const cells = [];
4352
+ for (let start = openAt; start + HOUR_MINUTES * MINUTE3 <= closeAt; start += HOUR_MINUTES * MINUTE3) {
4353
+ const endAt = new Date(start + HOUR_MINUTES * MINUTE3);
4354
+ cells.push({ startAt: new Date(start), endAt, bufferEndAt: endAt, canStart: true });
4355
+ }
4356
+ return cells;
4357
+ }
4358
+ function cellsOf(rule, parts, timeZone, from, to, busy) {
4359
+ if (parts.method === "sessions") return sessionCells(rule, timeZone, from, to);
4360
+ const { buffer } = ruleDurationsOf(rule);
4361
+ const cells = [];
4362
+ const lastDay = startOfZonedDay(to, timeZone).getTime();
4363
+ for (let day = startOfZonedDay(from, timeZone); day.getTime() <= lastDay; day = nextZonedDay(day, timeZone)) {
4364
+ cells.push(
4365
+ ...parts.method === "time-slots" ? timeSlotCells(parts, buffer, day, timeZone, busy) : periodCells(parts, buffer, day, timeZone)
4366
+ );
4367
+ }
4368
+ return cells;
4369
+ }
4370
+ function timeSlotCells(parts, buffer, dayStart, timeZone, busy) {
4371
+ const weekday = zonedParts(dayStart, timeZone).weekday;
4372
+ return parts.weeklyHours.filter((entry) => entry.weekday === weekday).flatMap(
4373
+ (row) => freeGaps(
4374
+ +atZonedMinute(dayStart, row.openMinute, timeZone),
4375
+ +atZonedMinute(dayStart, row.closeMinute, timeZone),
4376
+ busy
4377
+ ).flatMap((gap) => cellsInGap(gap, parts.length, buffer, timeZone))
4378
+ );
4379
+ }
4380
+ function cellsInGap(gap, length, buffer, timeZone) {
4381
+ const cells = [];
4382
+ for (let start = gap.from; ; ) {
4383
+ const endAt = addDuration(new Date(start), length, timeZone);
4384
+ const bufferEndAt = buffer ? addDuration(endAt, buffer, timeZone) : new Date(endAt.getTime());
4385
+ if ((gap.endsAtBooking ? bufferEndAt : endAt).getTime() > gap.to) return cells;
4386
+ cells.push({ startAt: new Date(start), endAt, bufferEndAt, canStart: true });
4387
+ start = bufferEndAt.getTime();
4388
+ }
4389
+ }
4390
+ function periodCells(parts, buffer, dayStart, timeZone) {
4391
+ const weekday = zonedParts(dayStart, timeZone).weekday;
4392
+ const rows = (parts.weeklyHours ?? []).filter((entry) => entry.weekday === weekday);
4393
+ if (parts.ratePeriod === "hour" /* HOUR */) {
4394
+ return rows.flatMap(
4395
+ (row) => hourCells(
4396
+ +atZonedMinute(dayStart, row.openMinute, timeZone),
4397
+ +atZonedMinute(dayStart, row.closeMinute, timeZone)
4398
+ )
4399
+ );
4400
+ }
4401
+ if (parts.weeklyHours?.length && rows.length === 0) return [];
4402
+ const built = periodSlot(dayStart, timeZone, parts, buffer, rows[0]?.openMinute, rows[0]?.closeMinute);
4403
+ return [{ ...built, canStart: !parts.arrivalDays?.length || parts.arrivalDays.includes(weekday) }];
4404
+ }
4405
+ function buildGrid(rule, timeZone, from, to, now, busy = []) {
4406
+ if (to.getTime() - from.getTime() > MAX_RANGE_DAYS * 1440 * MINUTE3) {
4407
+ throw new BookingRulesError(`A booking range may span at most ${MAX_RANGE_DAYS} days`);
4408
+ }
4409
+ const { availability, window } = rule;
4410
+ const { minNotice } = ruleDurationsOf(rule);
4411
+ const notBefore = Math.max(
4412
+ (minNotice ? addDuration(now, minNotice, timeZone) : now).getTime(),
4413
+ asTime(window.bookableFrom, "window.bookableFrom") ?? 0,
4414
+ asTime(availability.availableFrom, "availability.availableFrom") ?? 0
4415
+ );
4416
+ const notAfter = windowEndsAtInZone(rule, now, timeZone)?.getTime() ?? Number.POSITIVE_INFINITY;
4417
+ const blocked = offMarketOf(rule);
4418
+ const slots = cellsOf(rule, bookingRuleParts(rule), timeZone, from, to, busy);
4419
+ const askedFrom = from.getTime();
4420
+ const askedTo = to.getTime();
4421
+ return slots.filter(({ startAt, bufferEndAt }) => {
4422
+ const start = startAt.getTime();
4423
+ if (start < askedFrom || start >= askedTo) return false;
4424
+ if (start < notBefore || start > notAfter) return false;
4425
+ return !isBlocked(blocked, start, bufferEndAt.getTime());
4426
+ }).sort((first, second) => +first.startAt - +second.startAt);
4427
+ }
4428
+ function slotsForWindow(grid, startAt, endAt) {
4429
+ const startIndex = grid.findIndex((entry) => entry.startAt.getTime() === startAt.getTime());
4430
+ if (startIndex < 0) {
4431
+ throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
4432
+ }
4433
+ if (!grid[startIndex].canStart) {
4434
+ throw new BookingRulesError(`${startAt.toISOString()} is not an arrival day for these rules`);
4435
+ }
4436
+ const covered = [];
4437
+ for (let index = startIndex; index < grid.length; index++) {
4438
+ const entry = grid[index];
4439
+ const previous = covered[covered.length - 1];
4440
+ if (previous && entry.startAt.getTime() !== previous.bufferEndAt.getTime()) break;
4441
+ covered.push(entry);
4442
+ if (entry.endAt.getTime() === endAt.getTime()) return covered;
4443
+ if (entry.endAt.getTime() > endAt.getTime()) break;
4444
+ }
4445
+ throw new BookingRulesError(
4446
+ `${startAt.toISOString()} \u2192 ${endAt.toISOString()} does not line up with the bookable grid`
4447
+ );
4448
+ }
3719
4449
 
3720
4450
  // shipping/fold-text.ts
3721
4451
  function foldText(value) {
@@ -4151,10 +4881,12 @@ export {
4151
4881
  AttributeType,
4152
4882
  BNPL_METHOD_STATUS,
4153
4883
  BNPL_SKIP_REASON,
4884
+ BookingDurationUnit,
4154
4885
  BookingRatePeriod,
4155
4886
  BookingResourceKind,
4156
4887
  BookingResourceStatus,
4157
4888
  BookingRulesError,
4889
+ BookingSessionSale,
4158
4890
  BookingType,
4159
4891
  CANADA_PROVINCES,
4160
4892
  CONDITION_OPERATORS,
@@ -4244,6 +4976,7 @@ export {
4244
4976
  StripeStatus,
4245
4977
  TimePeriod,
4246
4978
  TopMetericsSort,
4979
+ UNLIMITED_PLACES,
4247
4980
  UserTypes,
4248
4981
  addAmounts,
4249
4982
  addressPlaceKeys,
@@ -4252,6 +4985,7 @@ export {
4252
4985
  adyenStoreRequiresStateOrProvince,
4253
4986
  adyenSupportsTaxNumberAbsent,
4254
4987
  adyenTaxNumberFormat,
4988
+ allowedDurationUnits,
4255
4989
  amountToString,
4256
4990
  ancestorChain,
4257
4991
  applyAssignment,
@@ -4261,15 +4995,21 @@ export {
4261
4995
  baseFulfillmentDefinitions,
4262
4996
  baseOf,
4263
4997
  basePaymentDefinitions,
4998
+ bookingMethodOf,
4999
+ bookingRuleParts,
4264
5000
  buildAvailability,
4265
5001
  buildGrid,
4266
5002
  buildOrderContext,
4267
5003
  buildPosPresetConfig,
4268
5004
  buildResolvedConfig,
4269
5005
  calculatePercentage,
5006
+ calendarDate,
4270
5007
  canTransition,
5008
+ capacityOf,
4271
5009
  cheapestCompositeItem,
4272
5010
  cheapestCompositePrice,
5011
+ checkPartySize,
5012
+ checkQtyPerBooking,
4273
5013
  compositeItemCost,
4274
5014
  compositeItemUnavailable,
4275
5015
  compositeMakeable,
@@ -4278,6 +5018,9 @@ export {
4278
5018
  compositeVariantInStock,
4279
5019
  conditionSummary,
4280
5020
  convertFixedFeeToLocalCurrency,
5021
+ courseSessions,
5022
+ courseStarted,
5023
+ courseStartedInZone,
4281
5024
  createAmount,
4282
5025
  crossAxisRuleApplies,
4283
5026
  currentAssignees,
@@ -4286,10 +5029,13 @@ export {
4286
5029
  deriveUnitId,
4287
5030
  displayRuleMatchesPair,
4288
5031
  divideAmount,
5032
+ durationProblems,
5033
+ durationText,
4289
5034
  evaluateCondition,
4290
5035
  evaluateConditionSet,
4291
5036
  extendPrice,
4292
5037
  extendPriceFor,
5038
+ fewestFreeOver,
4293
5039
  formatCurrency,
4294
5040
  formatInUnit,
4295
5041
  formatMinorUnitsToString,
@@ -4331,7 +5077,9 @@ export {
4331
5077
  listCountries,
4332
5078
  listProvinces,
4333
5079
  listShippingCountries,
5080
+ longestMinutesOf,
4334
5081
  mapToLegacyStatus,
5082
+ maxAdvanceMinutesOf,
4335
5083
  maxPrecisionFor,
4336
5084
  mergeFragment,
4337
5085
  modifiersSellable,
@@ -4343,11 +5091,14 @@ export {
4343
5091
  normalizePostCode,
4344
5092
  normalizeProvince,
4345
5093
  occupancyIn,
5094
+ oldMaxAdvanceOf,
4346
5095
  orderAssignments,
4347
5096
  parseAmountToMinorUnits,
4348
5097
  parseCurrencyCode,
4349
5098
  parseStripeCurrencyCode,
5099
+ pickFreeResource,
4350
5100
  placeKey,
5101
+ planCourse,
4351
5102
  planWindow,
4352
5103
  poolDemand,
4353
5104
  poolOf,
@@ -4358,19 +5109,25 @@ export {
4358
5109
  priceForTotal,
4359
5110
  provincesForPostCode,
4360
5111
  removeFragment,
5112
+ rentalEnds,
4361
5113
  resolveFamily,
4362
5114
  resolveModifiersForProduct,
4363
5115
  resolveShipping,
4364
5116
  resolveTemplate,
4365
5117
  resolveUnit,
4366
5118
  roundToPrecision,
5119
+ ruleDurationsOf,
5120
+ ruleInNewShape,
4367
5121
  sameFamily,
5122
+ sessionCells,
4368
5123
  setOrderState,
4369
5124
  shipsToCountry,
4370
5125
  shopDayKey,
4371
5126
  shopDayRange,
5127
+ shortestMinutesOf,
4372
5128
  signReportForDisplay,
4373
5129
  slotsForWindow,
5130
+ soldAsCourse,
4374
5131
  stringifyMinorUnits,
4375
5132
  subtractAmounts,
4376
5133
  toBase,
@@ -4381,6 +5138,8 @@ export {
4381
5138
  validateShippingZone,
4382
5139
  violatesFinancialInvariant,
4383
5140
  windowEndsAt,
5141
+ windowEndsAtInZone,
5142
+ windowForPeriods,
4384
5143
  withinPresence
4385
5144
  };
4386
5145
  //# sourceMappingURL=index.mjs.map