@final-commerce/common 2.12.0-staging.3 → 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 +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +79 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +76 -15
- 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);
|
|
@@ -3921,14 +3936,30 @@ function wholePeriodsIn(ratePeriod, timeZone, startAt, endAt, days) {
|
|
|
3921
3936
|
return months;
|
|
3922
3937
|
}
|
|
3923
3938
|
function courseSessions(rule, timeZone) {
|
|
3924
|
-
const
|
|
3925
|
-
|
|
3926
|
-
const sessions = sessionCells(rule, timeZone, new Date(bookableFrom), new Date(bookableTo)).sort(
|
|
3927
|
-
(first, second) => +first.startAt - +second.startAt
|
|
3928
|
-
);
|
|
3939
|
+
const [from, to] = rule.sessions?.weekly?.length ? weeklyCourseRange(rule) : datesCourseRange(rule.sessions?.dates ?? [], timeZone);
|
|
3940
|
+
const sessions = sessionCells(rule, timeZone, from, to).sort((first, second) => +first.startAt - +second.startAt);
|
|
3929
3941
|
if (sessions.length === 0) throw new BookingRulesError("These course dates hold no session");
|
|
3930
3942
|
return sessions;
|
|
3931
3943
|
}
|
|
3944
|
+
function courseSpan(rule, timeZone) {
|
|
3945
|
+
const sessions = courseSessions(rule, timeZone);
|
|
3946
|
+
return { from: sessions[0].startAt, to: sessions[sessions.length - 1].bufferEndAt };
|
|
3947
|
+
}
|
|
3948
|
+
function weeklyCourseRange(rule) {
|
|
3949
|
+
const { bookableFrom, bookableTo } = rule.window;
|
|
3950
|
+
if (!bookableFrom || !bookableTo) throw new BookingRulesError("A course needs both course dates");
|
|
3951
|
+
return [new Date(bookableFrom), new Date(bookableTo)];
|
|
3952
|
+
}
|
|
3953
|
+
function datesCourseRange(dates, timeZone) {
|
|
3954
|
+
if (dates.length === 0) throw new BookingRulesError("A course needs its sessions");
|
|
3955
|
+
const days = dates.map(({ date }) => date).sort();
|
|
3956
|
+
const [firstYear, firstMonth, firstDay] = calendarDate(days[0]);
|
|
3957
|
+
const [lastYear, lastMonth, lastDay] = calendarDate(days[days.length - 1]);
|
|
3958
|
+
return [
|
|
3959
|
+
instantFromLocal(firstYear, firstMonth, firstDay, 0, timeZone),
|
|
3960
|
+
instantFromLocal(lastYear, lastMonth, lastDay + 1, 0, timeZone)
|
|
3961
|
+
];
|
|
3962
|
+
}
|
|
3932
3963
|
var courseStarted = (rule, sessions, now) => sessions[0].startAt.getTime() < now.getTime() + (rule.window.minNoticeMinutes ?? 0) * 6e4;
|
|
3933
3964
|
function courseStartedInZone(rule, sessions, now, timeZone) {
|
|
3934
3965
|
const { minNotice } = ruleDurationsOf(rule);
|
|
@@ -3941,6 +3972,9 @@ function planCourse({ rule, timeZone, presence, now }) {
|
|
|
3941
3972
|
}
|
|
3942
3973
|
if (courseStartedInZone(rule, sessions, now, timeZone))
|
|
3943
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
|
+
}
|
|
3944
3978
|
return sessions;
|
|
3945
3979
|
}
|
|
3946
3980
|
function holdExpiresAt(rule, now) {
|
|
@@ -4098,12 +4132,21 @@ var OLD_FIELDS = [
|
|
|
4098
4132
|
"date-ranges": "dateRanges.weeklyHours"
|
|
4099
4133
|
}
|
|
4100
4134
|
},
|
|
4101
|
-
|
|
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) => ({
|
|
4102
4145
|
path,
|
|
4103
4146
|
home: {
|
|
4104
4147
|
"time-slots": { unread: "date ranges only" },
|
|
4105
4148
|
sessions: { unread: "date ranges only" },
|
|
4106
|
-
"date-ranges":
|
|
4149
|
+
"date-ranges": ({ dateRanges }) => dateRanges?.arriveLeave === "opening-hours" /* OPENING_HOURS */ ? { dropped: "opening-hours nights have no check times" } : `dateRanges.${path}`
|
|
4107
4150
|
}
|
|
4108
4151
|
}))
|
|
4109
4152
|
];
|
|
@@ -4216,13 +4259,23 @@ function windowEndsAt(rule, now) {
|
|
|
4216
4259
|
return Number.isFinite(ends) ? new Date(ends) : null;
|
|
4217
4260
|
}
|
|
4218
4261
|
function windowEndsAtInZone(rule, now, timeZone) {
|
|
4219
|
-
const { maxAdvance } = ruleDurationsOf(rule);
|
|
4220
4262
|
const ends = Math.min(
|
|
4221
|
-
|
|
4263
|
+
lastStartOf(rule, now, timeZone),
|
|
4222
4264
|
asTime(rule.window.bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY
|
|
4223
4265
|
);
|
|
4224
4266
|
return Number.isFinite(ends) ? new Date(ends) : null;
|
|
4225
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);
|
|
4226
4279
|
function addInZone(from, duration, timeZone, field) {
|
|
4227
4280
|
if (timeZone) return addDuration(from, duration, timeZone);
|
|
4228
4281
|
if (duration.unit === "minute" /* MINUTE */ || duration.unit === "hour" /* HOUR */) {
|
|
@@ -4270,7 +4323,7 @@ function oldMaxAdvanceOf({
|
|
|
4270
4323
|
function periodSlot(dayStart, timeZone, parts, buffer, openMinute, closeMinute) {
|
|
4271
4324
|
const { ratePeriod } = parts;
|
|
4272
4325
|
const at = (minutes) => atZonedMinute(dayStart, minutes, timeZone);
|
|
4273
|
-
if (ratePeriod === "night" /* NIGHT */) {
|
|
4326
|
+
if (ratePeriod === "night" /* NIGHT */ && parts.arriveLeave !== "opening-hours" /* OPENING_HOURS */) {
|
|
4274
4327
|
const arrival = zonedParts(dayStart, timeZone).weekday;
|
|
4275
4328
|
const departure = (arrival + 1) % 7;
|
|
4276
4329
|
return {
|
|
@@ -4283,7 +4336,7 @@ function periodSlot(dayStart, timeZone, parts, buffer, openMinute, closeMinute)
|
|
|
4283
4336
|
}
|
|
4284
4337
|
const from = ratePeriod === "day" /* DAY */ ? openMinute ?? 0 : 0;
|
|
4285
4338
|
const to = ratePeriod === "day" /* DAY */ ? closeMinute ?? 1440 : 1440;
|
|
4286
|
-
const turnaround = parts.wholePeriods ? void 0 : buffer;
|
|
4339
|
+
const turnaround = parts.wholePeriods || ratePeriod === "night" /* NIGHT */ ? void 0 : buffer;
|
|
4287
4340
|
return {
|
|
4288
4341
|
startAt: at(from),
|
|
4289
4342
|
endAt: at(to),
|
|
@@ -4420,7 +4473,8 @@ function buildGrid(rule, timeZone, from, to, now, busy = []) {
|
|
|
4420
4473
|
asTime(window.bookableFrom, "window.bookableFrom") ?? 0,
|
|
4421
4474
|
asTime(availability.availableFrom, "availability.availableFrom") ?? 0
|
|
4422
4475
|
);
|
|
4423
|
-
const notAfter =
|
|
4476
|
+
const notAfter = asTime(window.bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY;
|
|
4477
|
+
const lastStart = lastStartOf(rule, now, timeZone);
|
|
4424
4478
|
const blocked = offMarketOf(rule);
|
|
4425
4479
|
const slots = cellsOf(rule, bookingRuleParts(rule), timeZone, from, to, busy);
|
|
4426
4480
|
const askedFrom = from.getTime();
|
|
@@ -4430,7 +4484,11 @@ function buildGrid(rule, timeZone, from, to, now, busy = []) {
|
|
|
4430
4484
|
if (start < askedFrom || start >= askedTo) return false;
|
|
4431
4485
|
if (start < notBefore || start > notAfter) return false;
|
|
4432
4486
|
return !isBlocked(blocked, start, bufferEndAt.getTime());
|
|
4433
|
-
}).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 }] : [];
|
|
4434
4492
|
}
|
|
4435
4493
|
function slotsForWindow(grid, startAt, endAt) {
|
|
4436
4494
|
const startIndex = grid.findIndex((entry) => entry.startAt.getTime() === startAt.getTime());
|
|
@@ -4888,6 +4946,7 @@ export {
|
|
|
4888
4946
|
AttributeType,
|
|
4889
4947
|
BNPL_METHOD_STATUS,
|
|
4890
4948
|
BNPL_SKIP_REASON,
|
|
4949
|
+
BookingArriveLeave,
|
|
4891
4950
|
BookingDurationUnit,
|
|
4892
4951
|
BookingRatePeriod,
|
|
4893
4952
|
BookingResourceKind,
|
|
@@ -5026,6 +5085,7 @@ export {
|
|
|
5026
5085
|
conditionSummary,
|
|
5027
5086
|
convertFixedFeeToLocalCurrency,
|
|
5028
5087
|
courseSessions,
|
|
5088
|
+
courseSpan,
|
|
5029
5089
|
courseStarted,
|
|
5030
5090
|
courseStartedInZone,
|
|
5031
5091
|
createAmount,
|
|
@@ -5136,6 +5196,7 @@ export {
|
|
|
5136
5196
|
signReportForDisplay,
|
|
5137
5197
|
slotsForWindow,
|
|
5138
5198
|
soldAsCourse,
|
|
5199
|
+
startsPastMaxAdvance,
|
|
5139
5200
|
stringifyMinorUnits,
|
|
5140
5201
|
subtractAmounts,
|
|
5141
5202
|
toBase,
|