@final-commerce/common 2.12.0-staging.5 → 2.12.0-staging.6

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
@@ -3779,7 +3779,7 @@ function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }
3779
3779
  const grid = buildGrid(rule, timeZone, startAt, endAt, now, busy).filter(
3780
3780
  (slot) => withinPresence(slot, timeZone, presence)
3781
3781
  );
3782
- const slots = slotsForWindow(grid, startAt, endAt);
3782
+ const slots = slotsForWindow(grid, startAt, endAt, cellChainOf(rule, timeZone));
3783
3783
  const last = slots[slots.length - 1];
3784
3784
  const parts = bookingRuleParts(rule);
3785
3785
  const wholePeriods = parts.method === "date-ranges" && parts.wholePeriods;
@@ -3846,7 +3846,7 @@ function windowForPeriods({ rule, timeZone, startAt, periods, now }) {
3846
3846
  const endAt = monthsEnd ?? grid[startIndex + cells - 1]?.endAt;
3847
3847
  if (!endAt)
3848
3848
  throw new BookingRulesError(`${periods} period(s) from ${startAt.toISOString()} run past the bookable grid`);
3849
- slotsForWindow(grid, startAt, endAt);
3849
+ slotsForWindow(grid, startAt, endAt, cellChainOf(rule, timeZone));
3850
3850
  return { startAt, endAt };
3851
3851
  }
3852
3852
  function rentalEnds(input) {
@@ -3878,7 +3878,7 @@ function walkRentalEnds(grid, { rule, timeZone, startAt, untilDay }, parts, hori
3878
3878
  refusal ??= new BookingRulesError(`No stay from ${startAt.toISOString()} ends on or before ${untilDay}`);
3879
3879
  return { ends, refusal, ranOut: false };
3880
3880
  }
3881
- const slots = refusalOr(() => slotsForWindow(grid, startAt, cell.endAt));
3881
+ const slots = refusalOr(() => slotsForWindow(grid, startAt, cell.endAt, cellChainOf(rule, timeZone)));
3882
3882
  if (slots instanceof BookingRulesError) return { ends, refusal, ranOut: false };
3883
3883
  const periods = refusalOr(
3884
3884
  () => parts.wholePeriods ? wholePeriodsIn(rule.ratePeriod, timeZone, startAt, cell.endAt, slots.length) : slots.length
@@ -4490,7 +4490,13 @@ function pastMaxAdvance(cell, rule) {
4490
4490
  if (soldAsCourse(rule)) return [cell];
4491
4491
  return bookingMethodOf(rule) === "date-ranges" ? [{ ...cell, canStart: false }] : [];
4492
4492
  }
4493
- function slotsForWindow(grid, startAt, endAt) {
4493
+ var endToStart = (previous, next) => next.startAt.getTime() === previous.bufferEndAt.getTime();
4494
+ function cellChainOf(rule, timeZone) {
4495
+ if (rule.ratePeriod !== "day" /* DAY */) return endToStart;
4496
+ const dayOf = (slot) => startOfZonedDay(slot.startAt, timeZone);
4497
+ return (previous, next) => +dayOf(next) === +nextZonedDay(dayOf(previous), timeZone);
4498
+ }
4499
+ function slotsForWindow(grid, startAt, endAt, chain = endToStart) {
4494
4500
  const startIndex = grid.findIndex((entry) => entry.startAt.getTime() === startAt.getTime());
4495
4501
  if (startIndex < 0) {
4496
4502
  throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
@@ -4502,7 +4508,7 @@ function slotsForWindow(grid, startAt, endAt) {
4502
4508
  for (let index = startIndex; index < grid.length; index++) {
4503
4509
  const entry = grid[index];
4504
4510
  const previous = covered[covered.length - 1];
4505
- if (previous && entry.startAt.getTime() !== previous.bufferEndAt.getTime()) break;
4511
+ if (previous && !chain(previous, entry)) break;
4506
4512
  covered.push(entry);
4507
4513
  if (entry.endAt.getTime() === endAt.getTime()) return covered;
4508
4514
  if (entry.endAt.getTime() > endAt.getTime()) break;
@@ -5072,6 +5078,7 @@ export {
5072
5078
  calendarDate,
5073
5079
  canTransition,
5074
5080
  capacityOf,
5081
+ cellChainOf,
5075
5082
  cheapestCompositeItem,
5076
5083
  cheapestCompositePrice,
5077
5084
  checkPartySize,