@final-commerce/common 2.12.0-staging.4 → 2.12.0-staging.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +56 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -10
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.js.map +1 -1
- package/dist/pos-types/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -485,6 +485,11 @@ var BookingSessionSale = /* @__PURE__ */ ((BookingSessionSale2) => {
|
|
|
485
485
|
BookingSessionSale2["COURSE"] = "course";
|
|
486
486
|
return BookingSessionSale2;
|
|
487
487
|
})(BookingSessionSale || {});
|
|
488
|
+
var BookingArriveLeave = /* @__PURE__ */ ((BookingArriveLeave2) => {
|
|
489
|
+
BookingArriveLeave2["SET_TIMES"] = "set-times";
|
|
490
|
+
BookingArriveLeave2["OPENING_HOURS"] = "opening-hours";
|
|
491
|
+
return BookingArriveLeave2;
|
|
492
|
+
})(BookingArriveLeave || {});
|
|
488
493
|
var BookingResourceKind = /* @__PURE__ */ ((BookingResourceKind2) => {
|
|
489
494
|
BookingResourceKind2["ASSET"] = "asset";
|
|
490
495
|
BookingResourceKind2["ROOM"] = "room";
|
|
@@ -3527,7 +3532,7 @@ function buildAvailability({
|
|
|
3527
3532
|
// The per-booking limits, so a stepper is bounded by the rules (G7) instead of a number in the flow.
|
|
3528
3533
|
maxQtyPerBooking: rule.slot.maxQtyPerBooking,
|
|
3529
3534
|
maxPartySize: rule.slot.maxPartySize,
|
|
3530
|
-
// Why a day can come back empty. Past this instant the rule refuses
|
|
3535
|
+
// Why a day can come back empty. Past this instant the rule refuses every start, so the UI
|
|
3531
3536
|
// can say "beyond the booking window" where it would otherwise claim "nothing free".
|
|
3532
3537
|
bookableUntil,
|
|
3533
3538
|
// The comparison itself, not just the boundary: deciding whether a day lies past the
|
|
@@ -3610,6 +3615,7 @@ function courseAvailability(rule, resources, byResource, productId, shared, now)
|
|
|
3610
3615
|
if (resources.length === 0) return void 0;
|
|
3611
3616
|
const sessions = courseSessions(rule, resources[0].timeZone);
|
|
3612
3617
|
const alreadyStarted = courseStartedInZone(rule, sessions, now, resources[0].timeZone);
|
|
3618
|
+
const beyondWindow = startsPastMaxAdvance(rule, sessions[0].startAt, now, resources[0].timeZone);
|
|
3613
3619
|
const free = resources.map((resource) => {
|
|
3614
3620
|
const mine = byResource.get(resource.id) ?? [];
|
|
3615
3621
|
const everySession = sessions.every((session) => withinPresence(session, resource.timeZone, resource.presence));
|
|
@@ -3617,13 +3623,14 @@ function courseAvailability(rule, resources, byResource, productId, shared, now)
|
|
|
3617
3623
|
const { taken, foreignProductId } = occupancyIn(mine, productId, session.startAt, session.bufferEndAt, shared);
|
|
3618
3624
|
return foreignProductId ? 0 : Math.max(capacityOf(rule, resource) - taken, 0);
|
|
3619
3625
|
});
|
|
3620
|
-
const fewest = everySession && !alreadyStarted ? Math.min(...freePerSession) : 0;
|
|
3626
|
+
const fewest = everySession && !alreadyStarted && !beyondWindow ? Math.min(...freePerSession) : 0;
|
|
3621
3627
|
return Number.isFinite(fewest) ? { resourceId: resource.id, free: fewest } : { resourceId: resource.id, free: UNLIMITED_PLACES, unlimited: true };
|
|
3622
3628
|
});
|
|
3623
3629
|
return withMaxQtyNow(
|
|
3624
3630
|
{
|
|
3625
3631
|
sessions: sessions.length,
|
|
3626
3632
|
alreadyStarted,
|
|
3633
|
+
beyondWindow,
|
|
3627
3634
|
sessionTimes: sessions.map(({ startAt, endAt }) => ({ startAt, endAt })),
|
|
3628
3635
|
startAt: sessions[0].startAt,
|
|
3629
3636
|
endAt: sessions[sessions.length - 1].endAt,
|
|
@@ -3768,6 +3775,7 @@ function noticeAboveAdvance({
|
|
|
3768
3775
|
// booking/plan.ts
|
|
3769
3776
|
var DEFAULT_HOLD_MINUTES = 10;
|
|
3770
3777
|
function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }) {
|
|
3778
|
+
if (!soldAsCourse(rule)) checkStartWithinMaxAdvance(rule, timeZone, startAt, now);
|
|
3771
3779
|
const grid = buildGrid(rule, timeZone, startAt, endAt, now, busy).filter(
|
|
3772
3780
|
(slot) => withinPresence(slot, timeZone, presence)
|
|
3773
3781
|
);
|
|
@@ -3781,6 +3789,11 @@ function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }
|
|
|
3781
3789
|
const bufferEndAt = rule.ratePeriod === "hour" /* HOUR */ || wholePeriods ? buffer ? addDuration(last.endAt, buffer, timeZone) : new Date(last.endAt.getTime()) : last.bufferEndAt;
|
|
3782
3790
|
return { slots, periods, endAt: last.endAt, bufferEndAt };
|
|
3783
3791
|
}
|
|
3792
|
+
function checkStartWithinMaxAdvance(rule, timeZone, startAt, now) {
|
|
3793
|
+
if (startsPastMaxAdvance(rule, startAt, now, timeZone)) {
|
|
3794
|
+
throw new BookingRulesError(`${startAt.toISOString()} is past the booking window of these rules`);
|
|
3795
|
+
}
|
|
3796
|
+
}
|
|
3784
3797
|
function checkStay(parts, timeZone, startAt, periods) {
|
|
3785
3798
|
if (parts.method !== "date-ranges") return;
|
|
3786
3799
|
const stay = { count: periods, unit: periodUnitOf(parts) };
|
|
@@ -3813,6 +3826,7 @@ function windowForPeriods({ rule, timeZone, startAt, periods, now }) {
|
|
|
3813
3826
|
if (!Number.isInteger(periods) || periods < 1) {
|
|
3814
3827
|
throw new BookingRulesError(`periods must be a whole number of at least 1, got ${String(periods)}`);
|
|
3815
3828
|
}
|
|
3829
|
+
checkStartWithinMaxAdvance(rule, timeZone, startAt, now);
|
|
3816
3830
|
const parts = bookingRuleParts(rule);
|
|
3817
3831
|
checkStay(parts, timeZone, startAt, periods);
|
|
3818
3832
|
const wholePeriods = parts.method === "date-ranges" && parts.wholePeriods;
|
|
@@ -3839,6 +3853,7 @@ function rentalEnds(input) {
|
|
|
3839
3853
|
const { rule, timeZone, startAt, now, untilDay } = input;
|
|
3840
3854
|
const parts = bookingRuleParts(rule);
|
|
3841
3855
|
if (parts.method !== "date-ranges") throw new BookingRulesError("Only date-range rules book a stay");
|
|
3856
|
+
checkStartWithinMaxAdvance(rule, timeZone, startAt, now);
|
|
3842
3857
|
const horizon = shopDayRange(untilDay, 1, timeZone).to;
|
|
3843
3858
|
if (horizon <= startAt) throw new BookingRulesError(`untilDay ${untilDay} is before the stay starts`);
|
|
3844
3859
|
const gridUntil = (end) => buildGrid(rule, timeZone, startAt, new Date(Math.min(end, startAt.getTime() + 366 * 1440 * 6e4)), now);
|
|
@@ -3957,6 +3972,9 @@ function planCourse({ rule, timeZone, presence, now }) {
|
|
|
3957
3972
|
}
|
|
3958
3973
|
if (courseStartedInZone(rule, sessions, now, timeZone))
|
|
3959
3974
|
throw new BookingRulesError("This course has already started");
|
|
3975
|
+
if (startsPastMaxAdvance(rule, sessions[0].startAt, now, timeZone)) {
|
|
3976
|
+
throw new BookingRulesError("This course starts past the booking window of these rules");
|
|
3977
|
+
}
|
|
3960
3978
|
return sessions;
|
|
3961
3979
|
}
|
|
3962
3980
|
function holdExpiresAt(rule, now) {
|
|
@@ -4114,12 +4132,21 @@ var OLD_FIELDS = [
|
|
|
4114
4132
|
"date-ranges": "dateRanges.weeklyHours"
|
|
4115
4133
|
}
|
|
4116
4134
|
},
|
|
4117
|
-
|
|
4135
|
+
{
|
|
4136
|
+
path: "availability.arrivalDays",
|
|
4137
|
+
home: {
|
|
4138
|
+
"time-slots": { unread: "date ranges only" },
|
|
4139
|
+
sessions: { unread: "date ranges only" },
|
|
4140
|
+
"date-ranges": "dateRanges.arrivalDays"
|
|
4141
|
+
}
|
|
4142
|
+
},
|
|
4143
|
+
// An `opening-hours` night has no check times (FC-1503): switching to it drops the old ones, said in a note.
|
|
4144
|
+
...["checkInTime", "checkOutTime", "checkTimesByWeekday"].map((path) => ({
|
|
4118
4145
|
path,
|
|
4119
4146
|
home: {
|
|
4120
4147
|
"time-slots": { unread: "date ranges only" },
|
|
4121
4148
|
sessions: { unread: "date ranges only" },
|
|
4122
|
-
"date-ranges":
|
|
4149
|
+
"date-ranges": ({ dateRanges }) => dateRanges?.arriveLeave === "opening-hours" /* OPENING_HOURS */ ? { dropped: "opening-hours nights have no check times" } : `dateRanges.${path}`
|
|
4123
4150
|
}
|
|
4124
4151
|
}))
|
|
4125
4152
|
];
|
|
@@ -4232,13 +4259,23 @@ function windowEndsAt(rule, now) {
|
|
|
4232
4259
|
return Number.isFinite(ends) ? new Date(ends) : null;
|
|
4233
4260
|
}
|
|
4234
4261
|
function windowEndsAtInZone(rule, now, timeZone) {
|
|
4235
|
-
const { maxAdvance } = ruleDurationsOf(rule);
|
|
4236
4262
|
const ends = Math.min(
|
|
4237
|
-
|
|
4263
|
+
lastStartOf(rule, now, timeZone),
|
|
4238
4264
|
asTime(rule.window.bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY
|
|
4239
4265
|
);
|
|
4240
4266
|
return Number.isFinite(ends) ? new Date(ends) : null;
|
|
4241
4267
|
}
|
|
4268
|
+
function lastStartOf(rule, now, timeZone) {
|
|
4269
|
+
const { maxAdvance } = ruleDurationsOf(rule);
|
|
4270
|
+
if (!maxAdvance) return Number.POSITIVE_INFINITY;
|
|
4271
|
+
const reached = addInZone(now, maxAdvance, timeZone, "window.maxAdvance");
|
|
4272
|
+
if (maxAdvance.unit === "minute" /* MINUTE */ || maxAdvance.unit === "hour" /* HOUR */) {
|
|
4273
|
+
return reached.getTime();
|
|
4274
|
+
}
|
|
4275
|
+
const zone = timeZone;
|
|
4276
|
+
return nextZonedDay(startOfZonedDay(reached, zone), zone).getTime() - 1;
|
|
4277
|
+
}
|
|
4278
|
+
var startsPastMaxAdvance = (rule, startAt, now, timeZone) => startAt.getTime() > lastStartOf(rule, now, timeZone);
|
|
4242
4279
|
function addInZone(from, duration, timeZone, field) {
|
|
4243
4280
|
if (timeZone) return addDuration(from, duration, timeZone);
|
|
4244
4281
|
if (duration.unit === "minute" /* MINUTE */ || duration.unit === "hour" /* HOUR */) {
|
|
@@ -4286,7 +4323,7 @@ function oldMaxAdvanceOf({
|
|
|
4286
4323
|
function periodSlot(dayStart, timeZone, parts, buffer, openMinute, closeMinute) {
|
|
4287
4324
|
const { ratePeriod } = parts;
|
|
4288
4325
|
const at = (minutes) => atZonedMinute(dayStart, minutes, timeZone);
|
|
4289
|
-
if (ratePeriod === "night" /* NIGHT */) {
|
|
4326
|
+
if (ratePeriod === "night" /* NIGHT */ && parts.arriveLeave !== "opening-hours" /* OPENING_HOURS */) {
|
|
4290
4327
|
const arrival = zonedParts(dayStart, timeZone).weekday;
|
|
4291
4328
|
const departure = (arrival + 1) % 7;
|
|
4292
4329
|
return {
|
|
@@ -4299,7 +4336,7 @@ function periodSlot(dayStart, timeZone, parts, buffer, openMinute, closeMinute)
|
|
|
4299
4336
|
}
|
|
4300
4337
|
const from = ratePeriod === "day" /* DAY */ ? openMinute ?? 0 : 0;
|
|
4301
4338
|
const to = ratePeriod === "day" /* DAY */ ? closeMinute ?? 1440 : 1440;
|
|
4302
|
-
const turnaround = parts.wholePeriods ? void 0 : buffer;
|
|
4339
|
+
const turnaround = parts.wholePeriods || ratePeriod === "night" /* NIGHT */ ? void 0 : buffer;
|
|
4303
4340
|
return {
|
|
4304
4341
|
startAt: at(from),
|
|
4305
4342
|
endAt: at(to),
|
|
@@ -4436,7 +4473,8 @@ function buildGrid(rule, timeZone, from, to, now, busy = []) {
|
|
|
4436
4473
|
asTime(window.bookableFrom, "window.bookableFrom") ?? 0,
|
|
4437
4474
|
asTime(availability.availableFrom, "availability.availableFrom") ?? 0
|
|
4438
4475
|
);
|
|
4439
|
-
const notAfter =
|
|
4476
|
+
const notAfter = asTime(window.bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY;
|
|
4477
|
+
const lastStart = lastStartOf(rule, now, timeZone);
|
|
4440
4478
|
const blocked = offMarketOf(rule);
|
|
4441
4479
|
const slots = cellsOf(rule, bookingRuleParts(rule), timeZone, from, to, busy);
|
|
4442
4480
|
const askedFrom = from.getTime();
|
|
@@ -4446,7 +4484,11 @@ function buildGrid(rule, timeZone, from, to, now, busy = []) {
|
|
|
4446
4484
|
if (start < askedFrom || start >= askedTo) return false;
|
|
4447
4485
|
if (start < notBefore || start > notAfter) return false;
|
|
4448
4486
|
return !isBlocked(blocked, start, bufferEndAt.getTime());
|
|
4449
|
-
}).sort((first, second) => +first.startAt - +second.startAt);
|
|
4487
|
+
}).flatMap((cell) => cell.startAt.getTime() > lastStart ? pastMaxAdvance(cell, rule) : [cell]).sort((first, second) => +first.startAt - +second.startAt);
|
|
4488
|
+
}
|
|
4489
|
+
function pastMaxAdvance(cell, rule) {
|
|
4490
|
+
if (soldAsCourse(rule)) return [cell];
|
|
4491
|
+
return bookingMethodOf(rule) === "date-ranges" ? [{ ...cell, canStart: false }] : [];
|
|
4450
4492
|
}
|
|
4451
4493
|
function slotsForWindow(grid, startAt, endAt) {
|
|
4452
4494
|
const startIndex = grid.findIndex((entry) => entry.startAt.getTime() === startAt.getTime());
|
|
@@ -4904,6 +4946,7 @@ export {
|
|
|
4904
4946
|
AttributeType,
|
|
4905
4947
|
BNPL_METHOD_STATUS,
|
|
4906
4948
|
BNPL_SKIP_REASON,
|
|
4949
|
+
BookingArriveLeave,
|
|
4907
4950
|
BookingDurationUnit,
|
|
4908
4951
|
BookingRatePeriod,
|
|
4909
4952
|
BookingResourceKind,
|
|
@@ -5153,6 +5196,7 @@ export {
|
|
|
5153
5196
|
signReportForDisplay,
|
|
5154
5197
|
slotsForWindow,
|
|
5155
5198
|
soldAsCourse,
|
|
5199
|
+
startsPastMaxAdvance,
|
|
5156
5200
|
stringifyMinorUnits,
|
|
5157
5201
|
subtractAmounts,
|
|
5158
5202
|
toBase,
|