@final-commerce/common 2.12.0-staging.2 → 2.12.0-staging.4
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 +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +33 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3464,6 +3464,11 @@ function occupancyIn(occupied, productId, startAt, bufferEndAt, shared) {
|
|
|
3464
3464
|
foreignProductId: foreign?.productId
|
|
3465
3465
|
};
|
|
3466
3466
|
}
|
|
3467
|
+
var inEveryOutletPool = (entry) => !entry.outletId;
|
|
3468
|
+
function occupiedAtOutlet(occupied, rule, outletId) {
|
|
3469
|
+
if (bookingMethodOf(rule) !== "sessions" || !outletId) return occupied;
|
|
3470
|
+
return occupied.filter((entry) => inEveryOutletPool(entry) || entry.outletId === outletId);
|
|
3471
|
+
}
|
|
3467
3472
|
var stateFor = (hasShift, offerable, free) => {
|
|
3468
3473
|
if (offerable === 0) {
|
|
3469
3474
|
return hasShift() ? "fullyBooked" /* FULLY_BOOKED */ : "noHoursInRange" /* NO_HOURS_IN_RANGE */;
|
|
@@ -3495,12 +3500,14 @@ function buildAvailability({
|
|
|
3495
3500
|
bookingRulesId,
|
|
3496
3501
|
rule,
|
|
3497
3502
|
resources,
|
|
3498
|
-
occupied,
|
|
3503
|
+
occupied: everyOutlet,
|
|
3504
|
+
outletId,
|
|
3499
3505
|
from,
|
|
3500
3506
|
to,
|
|
3501
3507
|
now,
|
|
3502
3508
|
timeZone
|
|
3503
3509
|
}) {
|
|
3510
|
+
const occupied = occupiedAtOutlet(everyOutlet, rule, outletId);
|
|
3504
3511
|
const shared = rule.slot.sharedAcrossProducts ?? false;
|
|
3505
3512
|
const bookableUntil = windowEndsAtInZone(rule, now, timeZone ?? null);
|
|
3506
3513
|
const parts = bookingRuleParts(rule);
|
|
@@ -3914,14 +3921,30 @@ function wholePeriodsIn(ratePeriod, timeZone, startAt, endAt, days) {
|
|
|
3914
3921
|
return months;
|
|
3915
3922
|
}
|
|
3916
3923
|
function courseSessions(rule, timeZone) {
|
|
3917
|
-
const
|
|
3918
|
-
|
|
3919
|
-
const sessions = sessionCells(rule, timeZone, new Date(bookableFrom), new Date(bookableTo)).sort(
|
|
3920
|
-
(first, second) => +first.startAt - +second.startAt
|
|
3921
|
-
);
|
|
3924
|
+
const [from, to] = rule.sessions?.weekly?.length ? weeklyCourseRange(rule) : datesCourseRange(rule.sessions?.dates ?? [], timeZone);
|
|
3925
|
+
const sessions = sessionCells(rule, timeZone, from, to).sort((first, second) => +first.startAt - +second.startAt);
|
|
3922
3926
|
if (sessions.length === 0) throw new BookingRulesError("These course dates hold no session");
|
|
3923
3927
|
return sessions;
|
|
3924
3928
|
}
|
|
3929
|
+
function courseSpan(rule, timeZone) {
|
|
3930
|
+
const sessions = courseSessions(rule, timeZone);
|
|
3931
|
+
return { from: sessions[0].startAt, to: sessions[sessions.length - 1].bufferEndAt };
|
|
3932
|
+
}
|
|
3933
|
+
function weeklyCourseRange(rule) {
|
|
3934
|
+
const { bookableFrom, bookableTo } = rule.window;
|
|
3935
|
+
if (!bookableFrom || !bookableTo) throw new BookingRulesError("A course needs both course dates");
|
|
3936
|
+
return [new Date(bookableFrom), new Date(bookableTo)];
|
|
3937
|
+
}
|
|
3938
|
+
function datesCourseRange(dates, timeZone) {
|
|
3939
|
+
if (dates.length === 0) throw new BookingRulesError("A course needs its sessions");
|
|
3940
|
+
const days = dates.map(({ date }) => date).sort();
|
|
3941
|
+
const [firstYear, firstMonth, firstDay] = calendarDate(days[0]);
|
|
3942
|
+
const [lastYear, lastMonth, lastDay] = calendarDate(days[days.length - 1]);
|
|
3943
|
+
return [
|
|
3944
|
+
instantFromLocal(firstYear, firstMonth, firstDay, 0, timeZone),
|
|
3945
|
+
instantFromLocal(lastYear, lastMonth, lastDay + 1, 0, timeZone)
|
|
3946
|
+
];
|
|
3947
|
+
}
|
|
3925
3948
|
var courseStarted = (rule, sessions, now) => sessions[0].startAt.getTime() < now.getTime() + (rule.window.minNoticeMinutes ?? 0) * 6e4;
|
|
3926
3949
|
function courseStartedInZone(rule, sessions, now, timeZone) {
|
|
3927
3950
|
const { minNotice } = ruleDurationsOf(rule);
|
|
@@ -5019,6 +5042,7 @@ export {
|
|
|
5019
5042
|
conditionSummary,
|
|
5020
5043
|
convertFixedFeeToLocalCurrency,
|
|
5021
5044
|
courseSessions,
|
|
5045
|
+
courseSpan,
|
|
5022
5046
|
courseStarted,
|
|
5023
5047
|
courseStartedInZone,
|
|
5024
5048
|
createAmount,
|
|
@@ -5091,6 +5115,7 @@ export {
|
|
|
5091
5115
|
normalizePostCode,
|
|
5092
5116
|
normalizeProvince,
|
|
5093
5117
|
occupancyIn,
|
|
5118
|
+
occupiedAtOutlet,
|
|
5094
5119
|
oldMaxAdvanceOf,
|
|
5095
5120
|
orderAssignments,
|
|
5096
5121
|
parseAmountToMinorUnits,
|