riverbankcms 0.34.0 → 0.35.0
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/acceptance/matrix.mjs +3 -3
- package/dist/cli/index.mjs +419 -247
- package/dist/cli/init-docs/content/getting-started.md +4 -4
- package/dist/{entryCommands-DoJE41hf.mjs → entryCommands-D-1ldejM.mjs} +64 -4
- package/dist/{eventUpsertInputSchema-o-ntZyOs.mjs → eventUpsertInputSchema-D1CXYu1M.mjs} +3 -2
- package/dist/{load-config-FQqihBPt.mjs → load-config-DB_S_gdr.mjs} +2 -2
- package/dist/load-config-DSGN-x3K.mjs +4 -0
- package/dist/{plan-DQbhrxOI.mjs → plan-CMMvs6Nr.mjs} +2 -1
- package/dist/scaffold/index.mjs +2 -2
- package/dist/{sdk-event-upsert-DNjdjBVm.mjs → sdk-event-upsert-DoazwQVt.mjs} +3 -1
- package/dist/{src-B3ufN6kf.mjs → src-CysOxz1U.mjs} +864 -769
- package/dist/testing.mjs +4 -4
- package/package.json +1 -1
- package/dist/load-config-CwqwHzX8.mjs +0 -4
|
@@ -1660,543 +1660,213 @@ function toPageSurfaceSubjectWire(subject) {
|
|
|
1660
1660
|
}
|
|
1661
1661
|
|
|
1662
1662
|
//#endregion
|
|
1663
|
-
//#region ../core/src/
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1663
|
+
//#region ../core/src/date-time-formatter.ts
|
|
1664
|
+
/** Shared Intl engine, internal to core's date presentation owners. */
|
|
1665
|
+
const FORMATTER_CACHE_LIMIT$1 = 100;
|
|
1666
|
+
const dateTimeFormatterCache = new Map();
|
|
1667
|
+
/** Intl's boolean clock option can select h11/h24 on other ICU builds. */
|
|
1668
|
+
function resolveClockCycle(format) {
|
|
1669
|
+
const { hour12, ...explicitFormat } = format;
|
|
1670
|
+
return hour12 === undefined ? explicitFormat : {
|
|
1671
|
+
...explicitFormat,
|
|
1672
|
+
hourCycle: hour12 ? "h12" : "h23"
|
|
1673
|
+
};
|
|
1674
|
+
}
|
|
1675
|
+
function getDateTimeFormatter(locale, timeZone, format) {
|
|
1676
|
+
const explicitFormat = resolveClockCycle(format);
|
|
1677
|
+
const formatKey = JSON.stringify(Object.entries(explicitFormat).sort(([left], [right]) => left.localeCompare(right)));
|
|
1678
|
+
const key = `${locale}\u0000${timeZone}\u0000${formatKey}`;
|
|
1679
|
+
const cached = dateTimeFormatterCache.get(key);
|
|
1680
|
+
if (cached !== undefined) {
|
|
1681
|
+
return cached;
|
|
1667
1682
|
}
|
|
1668
|
-
|
|
1683
|
+
if (typeof locale !== "string" || Intl.DateTimeFormat.supportedLocalesOf([locale]).length === 0) {
|
|
1684
|
+
throw new RangeError("An explicit supported locale is required");
|
|
1685
|
+
}
|
|
1686
|
+
if (typeof timeZone !== "string" || timeZone.length === 0) {
|
|
1687
|
+
throw new RangeError("An explicit time zone is required");
|
|
1688
|
+
}
|
|
1689
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
1690
|
+
...explicitFormat,
|
|
1691
|
+
timeZone
|
|
1692
|
+
});
|
|
1693
|
+
if (dateTimeFormatterCache.size >= FORMATTER_CACHE_LIMIT$1) {
|
|
1694
|
+
dateTimeFormatterCache.clear();
|
|
1695
|
+
}
|
|
1696
|
+
dateTimeFormatterCache.set(key, formatter);
|
|
1697
|
+
return formatter;
|
|
1669
1698
|
}
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
const total = lines.reduce((sum, line$1) => sum + line$1.quantity, 0);
|
|
1677
|
-
const parsed = toPositiveTicketQuantity(total);
|
|
1678
|
-
return parsed.ok ? parsed.value : null;
|
|
1699
|
+
function formatIntlRange(formatter, start, end) {
|
|
1700
|
+
const nativeFormatRange = Reflect.get(formatter, "formatRange");
|
|
1701
|
+
if (typeof nativeFormatRange !== "function") throw new Error("Intl.DateTimeFormat.formatRange is required");
|
|
1702
|
+
const output = Reflect.apply(nativeFormatRange, formatter, [start, end]);
|
|
1703
|
+
if (typeof output !== "string") throw new Error("Intl.DateTimeFormat.formatRange returned a non-string value");
|
|
1704
|
+
return output;
|
|
1679
1705
|
}
|
|
1680
1706
|
|
|
1681
1707
|
//#endregion
|
|
1682
|
-
//#region ../core/src/booking-
|
|
1683
|
-
function
|
|
1684
|
-
return
|
|
1685
|
-
}
|
|
1686
|
-
function resolveFlexibleBalanceInitialPaymentCents(input) {
|
|
1687
|
-
return clampFlexibleBalanceConfiguredAmount(input.config.upfrontAmountCents, input.totalAmountCents);
|
|
1688
|
-
}
|
|
1689
|
-
function calculateFlexibleBalanceRemainingBalanceCents(input) {
|
|
1690
|
-
return Math.max(0, input.totalAmountCents - input.paidAmountCents);
|
|
1708
|
+
//#region ../core/src/booking-date-time/parts.ts
|
|
1709
|
+
function formatToPartsLookup(date, locale, timeZone, format) {
|
|
1710
|
+
return new Map(getDateTimeFormatter(locale, timeZone, format).formatToParts(date).map((part) => [part.type, part.value]));
|
|
1691
1711
|
}
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1712
|
+
|
|
1713
|
+
//#endregion
|
|
1714
|
+
//#region ../core/src/booking-time-zone.ts
|
|
1715
|
+
const TIME_ZONE_VALIDITY_CACHE_LIMIT = 100;
|
|
1716
|
+
const timeZoneValidityCache = new Map();
|
|
1717
|
+
const NUMERIC_OFFSET_TIME_ZONE_PATTERN = /^(?:[+-]\d{2}(?::?\d{2})?|(?:UTC|GMT)[+-]\d{1,2}(?::?\d{2})?)$/iu;
|
|
1718
|
+
function isValidBookingTimeZone(timeZone) {
|
|
1719
|
+
const normalized = timeZone.trim();
|
|
1720
|
+
if (NUMERIC_OFFSET_TIME_ZONE_PATTERN.test(normalized)) return false;
|
|
1721
|
+
const cached = timeZoneValidityCache.get(normalized);
|
|
1722
|
+
if (cached !== undefined) return cached;
|
|
1723
|
+
let isValid;
|
|
1724
|
+
try {
|
|
1725
|
+
new Intl.DateTimeFormat("en-US", { timeZone: normalized }).format(new Date());
|
|
1726
|
+
isValid = true;
|
|
1727
|
+
} catch {
|
|
1728
|
+
isValid = false;
|
|
1697
1729
|
}
|
|
1730
|
+
if (timeZoneValidityCache.size >= TIME_ZONE_VALIDITY_CACHE_LIMIT) {
|
|
1731
|
+
timeZoneValidityCache.clear();
|
|
1732
|
+
}
|
|
1733
|
+
timeZoneValidityCache.set(normalized, isValid);
|
|
1734
|
+
return isValid;
|
|
1698
1735
|
}
|
|
1699
|
-
function
|
|
1700
|
-
if (
|
|
1701
|
-
|
|
1736
|
+
function parseBookingTimeZone(timeZone) {
|
|
1737
|
+
if (typeof timeZone !== "string") return err("invalid-time-zone");
|
|
1738
|
+
const normalized = timeZone.trim();
|
|
1739
|
+
if (normalized.length === 0 || NUMERIC_OFFSET_TIME_ZONE_PATTERN.test(normalized) || !isValidBookingTimeZone(normalized)) {
|
|
1740
|
+
return err("invalid-time-zone");
|
|
1702
1741
|
}
|
|
1703
|
-
|
|
1704
|
-
const percentageFloor = Math.ceil(input.remainingBalanceCents * minimumPercentageBps / 1e4);
|
|
1705
|
-
return Math.min(input.remainingBalanceCents, Math.max(input.stripeMinimumChargeCents, percentageFloor));
|
|
1742
|
+
return ok(normalized);
|
|
1706
1743
|
}
|
|
1707
|
-
|
|
1708
|
-
|
|
1744
|
+
|
|
1745
|
+
//#endregion
|
|
1746
|
+
//#region ../core/src/booking-date-time/time-zone.ts
|
|
1747
|
+
const FALLBACK_TIMEZONE = "UTC";
|
|
1748
|
+
function getSafeTimeZone(timeZone) {
|
|
1749
|
+
const normalized = typeof timeZone === "string" ? timeZone.trim() : "";
|
|
1750
|
+
return normalized.length > 0 && isValidBookingTimeZone(normalized) ? normalized : FALLBACK_TIMEZONE;
|
|
1751
|
+
}
|
|
1752
|
+
function toBookingTimeZone(timeZone) {
|
|
1753
|
+
return getSafeTimeZone(timeZone);
|
|
1754
|
+
}
|
|
1755
|
+
const DEFAULT_BOOKING_TIME_ZONE = FALLBACK_TIMEZONE;
|
|
1756
|
+
function resolveBookingTimezone(venueTimezone, siteDefaultTimezone) {
|
|
1757
|
+
return venueTimezone ?? siteDefaultTimezone;
|
|
1758
|
+
}
|
|
1759
|
+
function resolveBookingTimeZoneId(...candidates) {
|
|
1760
|
+
const normalized = candidates.map((candidate$1) => typeof candidate$1 === "string" ? candidate$1.trim() : "");
|
|
1761
|
+
return normalized.find((candidate$1) => candidate$1.length > 0 && isValidBookingTimeZone(candidate$1)) ?? FALLBACK_TIMEZONE;
|
|
1762
|
+
}
|
|
1763
|
+
/** Canonical business-zone admission, shared by server and public wire boundaries. */
|
|
1764
|
+
const DEFAULT_BOOKING_BUSINESS_TIME_ZONE = "Europe/London";
|
|
1765
|
+
/** Stored site zones must be valid; a broken read must not silently choose another zone. */
|
|
1766
|
+
function requireBookingTimeZone(value) {
|
|
1767
|
+
const parsed = parseBookingTimeZone(value);
|
|
1768
|
+
if (!parsed.ok) throw new Error("Expected a valid canonical site time zone");
|
|
1769
|
+
return parsed.value;
|
|
1770
|
+
}
|
|
1771
|
+
/** Effect boundary for browser-authored local inputs; formats no displayed date. */
|
|
1772
|
+
function getRuntimeBookingTimeZone() {
|
|
1773
|
+
return resolveBookingTimeZoneId(new Intl.DateTimeFormat("en-GB").resolvedOptions().timeZone);
|
|
1774
|
+
}
|
|
1775
|
+
function resolveBookingBusinessTimeZone(value) {
|
|
1776
|
+
return resolveBookingTimeZoneId(value, DEFAULT_BOOKING_BUSINESS_TIME_ZONE);
|
|
1709
1777
|
}
|
|
1710
1778
|
|
|
1711
1779
|
//#endregion
|
|
1712
|
-
//#region ../core/src/booking-
|
|
1713
|
-
function
|
|
1714
|
-
|
|
1780
|
+
//#region ../core/src/booking-date-time/instant.ts
|
|
1781
|
+
function parseUtcIsoDateTimeString(value) {
|
|
1782
|
+
const normalized = value.trim();
|
|
1783
|
+
const hasUtcSuffix = normalized.endsWith("Z");
|
|
1784
|
+
const hasExplicitOffset = /[+-]\d{2}:\d{2}$/u.test(normalized);
|
|
1785
|
+
if (!hasUtcSuffix && !hasExplicitOffset) {
|
|
1786
|
+
return err("missing-timezone-offset");
|
|
1787
|
+
}
|
|
1788
|
+
const date = new Date(normalized);
|
|
1789
|
+
if (Number.isNaN(date.getTime())) {
|
|
1790
|
+
return err("invalid-date-time");
|
|
1791
|
+
}
|
|
1792
|
+
return ok(date.toISOString());
|
|
1715
1793
|
}
|
|
1716
|
-
function
|
|
1717
|
-
|
|
1794
|
+
function toUtcIsoDateTimeString(value) {
|
|
1795
|
+
const parsed = parseUtcIsoDateTimeString(value);
|
|
1796
|
+
if (!parsed.ok) {
|
|
1797
|
+
const message = parsed.error === "missing-timezone-offset" ? `Expected an offset-aware ISO datetime, received "${value}"` : `Expected a valid ISO datetime, received "${value}"`;
|
|
1798
|
+
throw new Error(message);
|
|
1799
|
+
}
|
|
1800
|
+
return parsed.value;
|
|
1718
1801
|
}
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1802
|
+
|
|
1803
|
+
//#endregion
|
|
1804
|
+
//#region ../core/src/booking-date-time/local.ts
|
|
1805
|
+
const LOCAL_DATE_PATTERN = /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/u;
|
|
1806
|
+
function getZonedDateTimeParts(date, timeZone) {
|
|
1807
|
+
const parts = formatToPartsLookup(date, "en-GB", timeZone, {
|
|
1808
|
+
year: "numeric",
|
|
1809
|
+
month: "2-digit",
|
|
1810
|
+
day: "2-digit",
|
|
1811
|
+
hour: "2-digit",
|
|
1812
|
+
minute: "2-digit",
|
|
1813
|
+
second: "2-digit",
|
|
1814
|
+
hourCycle: "h23"
|
|
1815
|
+
});
|
|
1816
|
+
const read = (type) => Number(parts.get(type) ?? "");
|
|
1817
|
+
return {
|
|
1818
|
+
year: read("year"),
|
|
1819
|
+
month: read("month"),
|
|
1820
|
+
day: read("day"),
|
|
1821
|
+
hour: read("hour"),
|
|
1822
|
+
minute: read("minute"),
|
|
1823
|
+
second: read("second")
|
|
1723
1824
|
};
|
|
1724
1825
|
}
|
|
1725
|
-
function
|
|
1726
|
-
const
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
requestedRefundMethod: "original_payment",
|
|
1731
|
-
protectedDepositOverride
|
|
1732
|
-
} : {
|
|
1733
|
-
kind: "refund_only",
|
|
1734
|
-
amount: options.amount ?? { kind: "full_remaining" },
|
|
1735
|
-
requestedRefundMethod: "original_payment",
|
|
1736
|
-
protectedDepositOverride
|
|
1737
|
-
};
|
|
1826
|
+
function formatDateKey(date) {
|
|
1827
|
+
const year = String(date.year).padStart(4, "0");
|
|
1828
|
+
const month = String(date.month).padStart(2, "0");
|
|
1829
|
+
const day = String(date.day).padStart(2, "0");
|
|
1830
|
+
return `${year}-${month}-${day}`;
|
|
1738
1831
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
return "kind" in response && response.kind === "accepted_unavailable";
|
|
1832
|
+
function getBookingLocalDateKey(input) {
|
|
1833
|
+
return formatDateKey(getLocalScheduleDate(new Date(input.startsAt), input.timeZone));
|
|
1742
1834
|
}
|
|
1743
|
-
function
|
|
1835
|
+
function compareLocalScheduleDates(left, right) {
|
|
1836
|
+
return Date.UTC(left.year, left.month - 1, left.day) - Date.UTC(right.year, right.month - 1, right.day);
|
|
1837
|
+
}
|
|
1838
|
+
function parseBookingLocalDate(value) {
|
|
1839
|
+
const match = LOCAL_DATE_PATTERN.exec(value.trim());
|
|
1840
|
+
if (match === null || match.groups === undefined) {
|
|
1841
|
+
throw new Error(`Invalid booking date format: "${value}" (expected YYYY-MM-DD)`);
|
|
1842
|
+
}
|
|
1843
|
+
const year = Number(match.groups.year);
|
|
1844
|
+
const month = Number(match.groups.month);
|
|
1845
|
+
const day = Number(match.groups.day);
|
|
1846
|
+
const candidate$1 = new Date(Date.UTC(year, month - 1, day, 12, 0, 0));
|
|
1847
|
+
if (Number.isNaN(candidate$1.getTime()) || candidate$1.getUTCFullYear() !== year || candidate$1.getUTCMonth() + 1 !== month || candidate$1.getUTCDate() !== day) {
|
|
1848
|
+
throw new Error(`Invalid booking date format: "${value}" (expected YYYY-MM-DD)`);
|
|
1849
|
+
}
|
|
1744
1850
|
return {
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1851
|
+
year,
|
|
1852
|
+
month,
|
|
1853
|
+
day
|
|
1748
1854
|
};
|
|
1749
1855
|
}
|
|
1750
|
-
|
|
1856
|
+
/** Canonical schedule text at command and SDK boundaries: HH:MM or HH:MM:SS. */
|
|
1857
|
+
const localScheduleTimePattern = /^([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/u;
|
|
1858
|
+
function parseLocalScheduleTime(value) {
|
|
1859
|
+
const match = /^(?<hour>[01]?\d|2[0-3]):(?<minute>[0-5]\d)(?::(?<second>[0-5]\d))?$/u.exec(value.trim());
|
|
1860
|
+
if (match === null || match.groups === undefined) {
|
|
1861
|
+
throw new Error(`Invalid start time format: "${value}" (expected HH:MM or HH:MM:SS)`);
|
|
1862
|
+
}
|
|
1863
|
+
const hour = Number(match.groups.hour);
|
|
1864
|
+
const minute = Number(match.groups.minute);
|
|
1865
|
+
const second = Number(match.groups.second ?? "0");
|
|
1751
1866
|
return {
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
};
|
|
1756
|
-
}
|
|
1757
|
-
function hasDirectRefundFunding(funding) {
|
|
1758
|
-
return funding?.some((line$1) => line$1.destination === "direct" && line$1.remainingCents > 0) ?? false;
|
|
1759
|
-
}
|
|
1760
|
-
/** A refund cut-off as a span of time: "24 hours", "2 days", "1 hour". */
|
|
1761
|
-
function formatCancellationCutoffSpan(cutoffHours) {
|
|
1762
|
-
if (cutoffHours > 24 && cutoffHours % 24 === 0) return `${cutoffHours / 24} days`;
|
|
1763
|
-
return cutoffHours === 1 ? "1 hour" : `${cutoffHours} hours`;
|
|
1764
|
-
}
|
|
1765
|
-
/** Closed refusal and reconciliation reasons shared by stored reviews and receipts. */
|
|
1766
|
-
const scheduleBookingReasonCodes = [
|
|
1767
|
-
"closed",
|
|
1768
|
-
"switched_off",
|
|
1769
|
-
"course_booking",
|
|
1770
|
-
"checked_in",
|
|
1771
|
-
"cancelled",
|
|
1772
|
-
"waitlisted",
|
|
1773
|
-
"past",
|
|
1774
|
-
"date_missing",
|
|
1775
|
-
"payment_pending",
|
|
1776
|
-
"not_owner",
|
|
1777
|
-
"full",
|
|
1778
|
-
"not_enough_room",
|
|
1779
|
-
"needs_ticket_choice",
|
|
1780
|
-
"ticket_not_usable",
|
|
1781
|
-
"tickets_collide",
|
|
1782
|
-
"pass_not_accepted",
|
|
1783
|
-
"already_booked",
|
|
1784
|
-
"not_bookable",
|
|
1785
|
-
"not_found",
|
|
1786
|
-
"source_changed",
|
|
1787
|
-
"source_unavailable",
|
|
1788
|
-
"target_full",
|
|
1789
|
-
"target_not_bookable",
|
|
1790
|
-
"target_changed",
|
|
1791
|
-
"already_booked_on_target",
|
|
1792
|
-
"no_replacement_in_week",
|
|
1793
|
-
"changed_after_review",
|
|
1794
|
-
"added_after_review",
|
|
1795
|
-
"cancellation_chosen",
|
|
1796
|
-
"move_refused"
|
|
1797
|
-
];
|
|
1798
|
-
const businessCancellationRefusalCodes = [
|
|
1799
|
-
"review_changed",
|
|
1800
|
-
"not_found",
|
|
1801
|
-
"payment_in_progress",
|
|
1802
|
-
"payment_check_unavailable",
|
|
1803
|
-
"partial_payment_terms",
|
|
1804
|
-
"settlement_not_allowed"
|
|
1805
|
-
];
|
|
1806
|
-
const businessCancellationRefusalCopy = {
|
|
1807
|
-
review_changed: "Bookings have changed since you reviewed this schedule. Review the changes again before saving.",
|
|
1808
|
-
not_found: "One of these dates could not be found. Refresh the dates and review your changes again.",
|
|
1809
|
-
payment_in_progress: "A payment is still being processed for one of these bookings. Wait for it to finish, then review the cancellation again.",
|
|
1810
|
-
payment_check_unavailable: "We could not check a payment for one of these bookings. Review the cancellation again later, or contact us for help.",
|
|
1811
|
-
partial_payment_terms: "One of these bookings shares a payment arrangement with another booking. Cancel the bookings together or contact us for help.",
|
|
1812
|
-
settlement_not_allowed: "A refund choice can't be used any more: account credit may have been turned off, or how a booking was paid has changed. Review the cancellation again and choose again."
|
|
1813
|
-
};
|
|
1814
|
-
|
|
1815
|
-
//#endregion
|
|
1816
|
-
//#region ../core/src/booking-instalments.ts
|
|
1817
|
-
function isDepositBearingBookingInstalmentPlan(plan) {
|
|
1818
|
-
switch (plan.kind) {
|
|
1819
|
-
case "deposit_plus_one_remainder":
|
|
1820
|
-
case "deposit_plus_scheduled_instalments": return true;
|
|
1821
|
-
case "equal_scheduled_instalments": return false;
|
|
1822
|
-
default: return assertNever$4(plan);
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
function getBookingInstalmentDepositRefundability(plan) {
|
|
1826
|
-
return isDepositBearingBookingInstalmentPlan(plan) ? plan.depositRefundability : null;
|
|
1827
|
-
}
|
|
1828
|
-
function getBookingInstalmentProtectedDepositAmountCents(plan) {
|
|
1829
|
-
return isDepositBearingBookingInstalmentPlan(plan) ? plan.depositAmountCents : null;
|
|
1830
|
-
}
|
|
1831
|
-
function clampConfiguredAmount(amountCents, totalAmountCents) {
|
|
1832
|
-
return Math.max(0, Math.min(amountCents, totalAmountCents));
|
|
1833
|
-
}
|
|
1834
|
-
function splitAmountWithRemainderInFirst(totalAmountCents, partCount) {
|
|
1835
|
-
if (partCount <= 0) {
|
|
1836
|
-
return [];
|
|
1837
|
-
}
|
|
1838
|
-
const baseAmountCents = Math.floor(totalAmountCents / partCount);
|
|
1839
|
-
const remainderCents = totalAmountCents - baseAmountCents * partCount;
|
|
1840
|
-
return Array.from({ length: partCount }, (_, index) => index === 0 ? baseAmountCents + remainderCents : baseAmountCents);
|
|
1841
|
-
}
|
|
1842
|
-
function addIntervalPreservingMonthAnchor(isoString, intervalCount, intervalUnit) {
|
|
1843
|
-
const date = new Date(isoString);
|
|
1844
|
-
if (!Number.isFinite(date.getTime())) {
|
|
1845
|
-
return isoString;
|
|
1846
|
-
}
|
|
1847
|
-
switch (intervalUnit) {
|
|
1848
|
-
case "day":
|
|
1849
|
-
date.setUTCDate(date.getUTCDate() + intervalCount);
|
|
1850
|
-
return date.toISOString();
|
|
1851
|
-
case "week":
|
|
1852
|
-
date.setUTCDate(date.getUTCDate() + intervalCount * 7);
|
|
1853
|
-
return date.toISOString();
|
|
1854
|
-
case "month": return addMonthsPreservingAnchorDay(date, intervalCount).toISOString();
|
|
1855
|
-
default: return assertNever$4(intervalUnit);
|
|
1856
|
-
}
|
|
1857
|
-
}
|
|
1858
|
-
function getBookingInstalmentPlanIntervalCount(plan) {
|
|
1859
|
-
switch (plan.kind) {
|
|
1860
|
-
case "deposit_plus_one_remainder": return plan.remainderDueCount;
|
|
1861
|
-
case "deposit_plus_scheduled_instalments":
|
|
1862
|
-
case "equal_scheduled_instalments": return plan.intervalCount;
|
|
1863
|
-
default: return assertNever$4(plan);
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
function omitZeroAmountFutureRows(rows) {
|
|
1867
|
-
if (rows.length <= 1) {
|
|
1868
|
-
return rows;
|
|
1869
|
-
}
|
|
1870
|
-
const firstRow = rows[0];
|
|
1871
|
-
if (firstRow === undefined) {
|
|
1872
|
-
return [];
|
|
1873
|
-
}
|
|
1874
|
-
const futureRows = rows.slice(1);
|
|
1875
|
-
return [firstRow, ...futureRows.filter((row) => row.amountCents > 0)];
|
|
1876
|
-
}
|
|
1877
|
-
function formatOrderInstalmentStatusLabel(input) {
|
|
1878
|
-
switch (input.status) {
|
|
1879
|
-
case "pending_initial_payment": return input.phaseKind === "initial" ? "Due today" : "Scheduled";
|
|
1880
|
-
case "scheduled": return "Scheduled";
|
|
1881
|
-
case "paid": return input.phaseKind === "initial" ? "Paid today" : "Paid";
|
|
1882
|
-
case "failed": return "Payment failed";
|
|
1883
|
-
case "waived": return "Waived";
|
|
1884
|
-
case "cancelled": return "Cancelled";
|
|
1885
|
-
case "cancelled_as_paid_early": return "Paid early";
|
|
1886
|
-
case "refunded": return "Refunded";
|
|
1887
|
-
default: return assertNever$4(input.status);
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
const NEXT_DUE_STATUSES = new Set(["scheduled", "failed"]);
|
|
1891
|
-
function buildOrderInstalmentSummary(input) {
|
|
1892
|
-
const nextDue = input.instalments.find((instalment) => NEXT_DUE_STATUSES.has(instalment.status)) ?? null;
|
|
1893
|
-
return {
|
|
1894
|
-
status: input.paymentPlan.status,
|
|
1895
|
-
remainingBalanceCents: input.paymentPlan.remainingBalanceCents,
|
|
1896
|
-
nextDueAt: nextDue?.dueAt ?? null,
|
|
1897
|
-
nextDueAmountCents: nextDue?.amountCents ?? null,
|
|
1898
|
-
rows: [...input.instalments]
|
|
1899
|
-
};
|
|
1900
|
-
}
|
|
1901
|
-
function addMonthsPreservingAnchorDay(date, intervalCount) {
|
|
1902
|
-
const anchorDay = date.getUTCDate();
|
|
1903
|
-
const nextMonth = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + intervalCount, 1, date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds()));
|
|
1904
|
-
const lastDayOfTargetMonth = new Date(Date.UTC(nextMonth.getUTCFullYear(), nextMonth.getUTCMonth() + 1, 0)).getUTCDate();
|
|
1905
|
-
nextMonth.setUTCDate(Math.min(anchorDay, lastDayOfTargetMonth));
|
|
1906
|
-
return nextMonth;
|
|
1907
|
-
}
|
|
1908
|
-
function assertNever$4(value) {
|
|
1909
|
-
throw new Error(`Unexpected value: ${String(value)}`);
|
|
1910
|
-
}
|
|
1911
|
-
|
|
1912
|
-
//#endregion
|
|
1913
|
-
//#region ../core/src/booking-instalment-deposit.ts
|
|
1914
|
-
/**
|
|
1915
|
-
* A plan that starts with a deposit takes it by card when the customer books
|
|
1916
|
-
* and saves the card for the later payments, so the deposit must be at least
|
|
1917
|
-
* the card minimum for the site's currency. Plans without a deposit step
|
|
1918
|
-
* (equal instalments) charge their first instalment instead and are not
|
|
1919
|
-
* checked here.
|
|
1920
|
-
*/
|
|
1921
|
-
function checkInstalmentPlanDeposit(plan, minimumCents) {
|
|
1922
|
-
if (!isDepositBearingBookingInstalmentPlan(plan)) return ok(undefined);
|
|
1923
|
-
return plan.depositAmountCents >= minimumCents ? ok(undefined) : err({
|
|
1924
|
-
kind: "instalment_deposit_below_minimum",
|
|
1925
|
-
minimumCents,
|
|
1926
|
-
option: "instalment_plan"
|
|
1927
|
-
});
|
|
1928
|
-
}
|
|
1929
|
-
/** The deposit check for whichever instalment option a set of payment options offers. */
|
|
1930
|
-
function checkPaymentOptionsInstalmentDeposit(allowedOptions, minimumCents) {
|
|
1931
|
-
const failure = allowedOptions.map((option) => option.kind === "instalment_plan" ? checkInstalmentPlanDeposit(option.plan, minimumCents) : option.kind === "flexible_balance" && option.config.upfrontAmountCents < minimumCents ? err({
|
|
1932
|
-
kind: "instalment_deposit_below_minimum",
|
|
1933
|
-
minimumCents,
|
|
1934
|
-
option: "flexible_balance"
|
|
1935
|
-
}) : ok(undefined)).find((checked) => !checked.ok);
|
|
1936
|
-
return failure ?? ok(undefined);
|
|
1937
|
-
}
|
|
1938
|
-
/** The one message for a deposit below the minimum, shown in the editor and returned by the server. */
|
|
1939
|
-
function describeInstalmentDepositBelowMinimum(failure, currency) {
|
|
1940
|
-
const minimum = formatCurrencyAmount(failure.minimumCents, currency);
|
|
1941
|
-
switch (failure.option) {
|
|
1942
|
-
case "instalment_plan": return `Enter a deposit of at least ${minimum}. We take it when the customer books and save their card for the later payments.`;
|
|
1943
|
-
case "flexible_balance": return `The deposit needs to be at least ${minimum}.`;
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
|
-
|
|
1947
|
-
//#endregion
|
|
1948
|
-
//#region ../core/src/booking-live-payment-terms.ts
|
|
1949
|
-
/**
|
|
1950
|
-
* Stored instalment-provider outcomes used by schedule coordination.
|
|
1951
|
-
* Order money admissions and flexible-balance liveness come from the position.
|
|
1952
|
-
* The table is total over the plan status union.
|
|
1953
|
-
*/
|
|
1954
|
-
const LIVE_PLAN_STATUSES = {
|
|
1955
|
-
pending_initial_payment: true,
|
|
1956
|
-
active: true,
|
|
1957
|
-
payment_failed: true,
|
|
1958
|
-
reconciliation_required: true,
|
|
1959
|
-
completed: false,
|
|
1960
|
-
cancelled: false,
|
|
1961
|
-
cancelled_as_paid_early: false,
|
|
1962
|
-
refunded: false
|
|
1963
|
-
};
|
|
1964
|
-
function isLiveOrderInstalmentPlanStatus(status) {
|
|
1965
|
-
return LIVE_PLAN_STATUSES[status];
|
|
1966
|
-
}
|
|
1967
|
-
/** The live plan statuses as a list, for queries that select plans to collect. */
|
|
1968
|
-
const LIVE_ORDER_INSTALMENT_PLAN_STATUSES = Object.keys(LIVE_PLAN_STATUSES).filter(isLiveOrderInstalmentPlanStatus);
|
|
1969
|
-
/** Shared reason for closing either form of booking payment terms. */
|
|
1970
|
-
const PAYMENT_TERMS_CLOSURE_REASONS = ["cancelled", "refunded"];
|
|
1971
|
-
|
|
1972
|
-
//#endregion
|
|
1973
|
-
//#region ../core/src/booking-payment-options.ts
|
|
1974
|
-
/**
|
|
1975
|
-
* One way a customer may pay for a booking. This is the single definition of
|
|
1976
|
-
* the option type; `booking-payment-schemas.typetest.ts` keeps it equal to the
|
|
1977
|
-
* schema's output in both directions.
|
|
1978
|
-
*/
|
|
1979
|
-
/** When a course's instalments must all be paid by: before its first or its last live session. */
|
|
1980
|
-
const BOOKING_COURSE_INSTALMENT_DEADLINES = ["first_session", "last_session"];
|
|
1981
|
-
/** Automatic instalments and a flexible balance cannot share one booking offer. */
|
|
1982
|
-
function validateBookingPaymentOptionKinds(kinds) {
|
|
1983
|
-
if (kinds.length === 0) return err("no_options");
|
|
1984
|
-
const uniqueKinds = new Set(kinds);
|
|
1985
|
-
if (uniqueKinds.size !== kinds.length) return err("duplicate_kind");
|
|
1986
|
-
if (uniqueKinds.has("instalment_plan") && uniqueKinds.has("flexible_balance")) {
|
|
1987
|
-
return err("incompatible_collection_options");
|
|
1988
|
-
}
|
|
1989
|
-
return ok(undefined);
|
|
1990
|
-
}
|
|
1991
|
-
|
|
1992
|
-
//#endregion
|
|
1993
|
-
//#region ../core/src/booking-date-time/instant.ts
|
|
1994
|
-
function parseUtcIsoDateTimeString(value) {
|
|
1995
|
-
const normalized = value.trim();
|
|
1996
|
-
const hasUtcSuffix = normalized.endsWith("Z");
|
|
1997
|
-
const hasExplicitOffset = /[+-]\d{2}:\d{2}$/u.test(normalized);
|
|
1998
|
-
if (!hasUtcSuffix && !hasExplicitOffset) {
|
|
1999
|
-
return err("missing-timezone-offset");
|
|
2000
|
-
}
|
|
2001
|
-
const date = new Date(normalized);
|
|
2002
|
-
if (Number.isNaN(date.getTime())) {
|
|
2003
|
-
return err("invalid-date-time");
|
|
2004
|
-
}
|
|
2005
|
-
return ok(date.toISOString());
|
|
2006
|
-
}
|
|
2007
|
-
function toUtcIsoDateTimeString(value) {
|
|
2008
|
-
const parsed = parseUtcIsoDateTimeString(value);
|
|
2009
|
-
if (!parsed.ok) {
|
|
2010
|
-
const message = parsed.error === "missing-timezone-offset" ? `Expected an offset-aware ISO datetime, received "${value}"` : `Expected a valid ISO datetime, received "${value}"`;
|
|
2011
|
-
throw new Error(message);
|
|
2012
|
-
}
|
|
2013
|
-
return parsed.value;
|
|
2014
|
-
}
|
|
2015
|
-
|
|
2016
|
-
//#endregion
|
|
2017
|
-
//#region ../core/src/date-time-formatter.ts
|
|
2018
|
-
/** Shared Intl engine, internal to core's date presentation owners. */
|
|
2019
|
-
const FORMATTER_CACHE_LIMIT$1 = 100;
|
|
2020
|
-
const dateTimeFormatterCache = new Map();
|
|
2021
|
-
/** Intl's boolean clock option can select h11/h24 on other ICU builds. */
|
|
2022
|
-
function resolveClockCycle(format) {
|
|
2023
|
-
const { hour12, ...explicitFormat } = format;
|
|
2024
|
-
return hour12 === undefined ? explicitFormat : {
|
|
2025
|
-
...explicitFormat,
|
|
2026
|
-
hourCycle: hour12 ? "h12" : "h23"
|
|
2027
|
-
};
|
|
2028
|
-
}
|
|
2029
|
-
function getDateTimeFormatter(locale, timeZone, format) {
|
|
2030
|
-
const explicitFormat = resolveClockCycle(format);
|
|
2031
|
-
const formatKey = JSON.stringify(Object.entries(explicitFormat).sort(([left], [right]) => left.localeCompare(right)));
|
|
2032
|
-
const key = `${locale}\u0000${timeZone}\u0000${formatKey}`;
|
|
2033
|
-
const cached = dateTimeFormatterCache.get(key);
|
|
2034
|
-
if (cached !== undefined) {
|
|
2035
|
-
return cached;
|
|
2036
|
-
}
|
|
2037
|
-
if (typeof locale !== "string" || Intl.DateTimeFormat.supportedLocalesOf([locale]).length === 0) {
|
|
2038
|
-
throw new RangeError("An explicit supported locale is required");
|
|
2039
|
-
}
|
|
2040
|
-
if (typeof timeZone !== "string" || timeZone.length === 0) {
|
|
2041
|
-
throw new RangeError("An explicit time zone is required");
|
|
2042
|
-
}
|
|
2043
|
-
const formatter = new Intl.DateTimeFormat(locale, {
|
|
2044
|
-
...explicitFormat,
|
|
2045
|
-
timeZone
|
|
2046
|
-
});
|
|
2047
|
-
if (dateTimeFormatterCache.size >= FORMATTER_CACHE_LIMIT$1) {
|
|
2048
|
-
dateTimeFormatterCache.clear();
|
|
2049
|
-
}
|
|
2050
|
-
dateTimeFormatterCache.set(key, formatter);
|
|
2051
|
-
return formatter;
|
|
2052
|
-
}
|
|
2053
|
-
function formatIntlRange(formatter, start, end) {
|
|
2054
|
-
const nativeFormatRange = Reflect.get(formatter, "formatRange");
|
|
2055
|
-
if (typeof nativeFormatRange !== "function") throw new Error("Intl.DateTimeFormat.formatRange is required");
|
|
2056
|
-
const output = Reflect.apply(nativeFormatRange, formatter, [start, end]);
|
|
2057
|
-
if (typeof output !== "string") throw new Error("Intl.DateTimeFormat.formatRange returned a non-string value");
|
|
2058
|
-
return output;
|
|
2059
|
-
}
|
|
2060
|
-
|
|
2061
|
-
//#endregion
|
|
2062
|
-
//#region ../core/src/booking-date-time/parts.ts
|
|
2063
|
-
function formatToPartsLookup(date, locale, timeZone, format) {
|
|
2064
|
-
return new Map(getDateTimeFormatter(locale, timeZone, format).formatToParts(date).map((part) => [part.type, part.value]));
|
|
2065
|
-
}
|
|
2066
|
-
|
|
2067
|
-
//#endregion
|
|
2068
|
-
//#region ../core/src/booking-time-zone.ts
|
|
2069
|
-
const TIME_ZONE_VALIDITY_CACHE_LIMIT = 100;
|
|
2070
|
-
const timeZoneValidityCache = new Map();
|
|
2071
|
-
const NUMERIC_OFFSET_TIME_ZONE_PATTERN = /^(?:[+-]\d{2}(?::?\d{2})?|(?:UTC|GMT)[+-]\d{1,2}(?::?\d{2})?)$/iu;
|
|
2072
|
-
function isValidBookingTimeZone(timeZone) {
|
|
2073
|
-
const normalized = timeZone.trim();
|
|
2074
|
-
if (NUMERIC_OFFSET_TIME_ZONE_PATTERN.test(normalized)) return false;
|
|
2075
|
-
const cached = timeZoneValidityCache.get(normalized);
|
|
2076
|
-
if (cached !== undefined) return cached;
|
|
2077
|
-
let isValid;
|
|
2078
|
-
try {
|
|
2079
|
-
new Intl.DateTimeFormat("en-US", { timeZone: normalized }).format(new Date());
|
|
2080
|
-
isValid = true;
|
|
2081
|
-
} catch {
|
|
2082
|
-
isValid = false;
|
|
2083
|
-
}
|
|
2084
|
-
if (timeZoneValidityCache.size >= TIME_ZONE_VALIDITY_CACHE_LIMIT) {
|
|
2085
|
-
timeZoneValidityCache.clear();
|
|
2086
|
-
}
|
|
2087
|
-
timeZoneValidityCache.set(normalized, isValid);
|
|
2088
|
-
return isValid;
|
|
2089
|
-
}
|
|
2090
|
-
function parseBookingTimeZone(timeZone) {
|
|
2091
|
-
if (typeof timeZone !== "string") return err("invalid-time-zone");
|
|
2092
|
-
const normalized = timeZone.trim();
|
|
2093
|
-
if (normalized.length === 0 || NUMERIC_OFFSET_TIME_ZONE_PATTERN.test(normalized) || !isValidBookingTimeZone(normalized)) {
|
|
2094
|
-
return err("invalid-time-zone");
|
|
2095
|
-
}
|
|
2096
|
-
return ok(normalized);
|
|
2097
|
-
}
|
|
2098
|
-
|
|
2099
|
-
//#endregion
|
|
2100
|
-
//#region ../core/src/booking-date-time/time-zone.ts
|
|
2101
|
-
const FALLBACK_TIMEZONE = "UTC";
|
|
2102
|
-
function getSafeTimeZone(timeZone) {
|
|
2103
|
-
const normalized = typeof timeZone === "string" ? timeZone.trim() : "";
|
|
2104
|
-
return normalized.length > 0 && isValidBookingTimeZone(normalized) ? normalized : FALLBACK_TIMEZONE;
|
|
2105
|
-
}
|
|
2106
|
-
function toBookingTimeZone(timeZone) {
|
|
2107
|
-
return getSafeTimeZone(timeZone);
|
|
2108
|
-
}
|
|
2109
|
-
const DEFAULT_BOOKING_TIME_ZONE = FALLBACK_TIMEZONE;
|
|
2110
|
-
function resolveBookingTimezone(venueTimezone, siteDefaultTimezone) {
|
|
2111
|
-
return venueTimezone ?? siteDefaultTimezone;
|
|
2112
|
-
}
|
|
2113
|
-
function resolveBookingTimeZoneId(...candidates) {
|
|
2114
|
-
const normalized = candidates.map((candidate$1) => typeof candidate$1 === "string" ? candidate$1.trim() : "");
|
|
2115
|
-
return normalized.find((candidate$1) => candidate$1.length > 0 && isValidBookingTimeZone(candidate$1)) ?? FALLBACK_TIMEZONE;
|
|
2116
|
-
}
|
|
2117
|
-
/** Canonical business-zone admission, shared by server and public wire boundaries. */
|
|
2118
|
-
const DEFAULT_BOOKING_BUSINESS_TIME_ZONE = "Europe/London";
|
|
2119
|
-
/** Stored site zones must be valid; a broken read must not silently choose another zone. */
|
|
2120
|
-
function requireBookingTimeZone(value) {
|
|
2121
|
-
const parsed = parseBookingTimeZone(value);
|
|
2122
|
-
if (!parsed.ok) throw new Error("Expected a valid canonical site time zone");
|
|
2123
|
-
return parsed.value;
|
|
2124
|
-
}
|
|
2125
|
-
/** Effect boundary for browser-authored local inputs; formats no displayed date. */
|
|
2126
|
-
function getRuntimeBookingTimeZone() {
|
|
2127
|
-
return resolveBookingTimeZoneId(new Intl.DateTimeFormat("en-GB").resolvedOptions().timeZone);
|
|
2128
|
-
}
|
|
2129
|
-
function resolveBookingBusinessTimeZone(value) {
|
|
2130
|
-
return resolveBookingTimeZoneId(value, DEFAULT_BOOKING_BUSINESS_TIME_ZONE);
|
|
2131
|
-
}
|
|
2132
|
-
|
|
2133
|
-
//#endregion
|
|
2134
|
-
//#region ../core/src/booking-date-time/local.ts
|
|
2135
|
-
const LOCAL_DATE_PATTERN = /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/u;
|
|
2136
|
-
function getZonedDateTimeParts(date, timeZone) {
|
|
2137
|
-
const parts = formatToPartsLookup(date, "en-GB", timeZone, {
|
|
2138
|
-
year: "numeric",
|
|
2139
|
-
month: "2-digit",
|
|
2140
|
-
day: "2-digit",
|
|
2141
|
-
hour: "2-digit",
|
|
2142
|
-
minute: "2-digit",
|
|
2143
|
-
second: "2-digit",
|
|
2144
|
-
hourCycle: "h23"
|
|
2145
|
-
});
|
|
2146
|
-
const read = (type) => Number(parts.get(type) ?? "");
|
|
2147
|
-
return {
|
|
2148
|
-
year: read("year"),
|
|
2149
|
-
month: read("month"),
|
|
2150
|
-
day: read("day"),
|
|
2151
|
-
hour: read("hour"),
|
|
2152
|
-
minute: read("minute"),
|
|
2153
|
-
second: read("second")
|
|
2154
|
-
};
|
|
2155
|
-
}
|
|
2156
|
-
function formatDateKey(date) {
|
|
2157
|
-
const year = String(date.year).padStart(4, "0");
|
|
2158
|
-
const month = String(date.month).padStart(2, "0");
|
|
2159
|
-
const day = String(date.day).padStart(2, "0");
|
|
2160
|
-
return `${year}-${month}-${day}`;
|
|
2161
|
-
}
|
|
2162
|
-
function getBookingLocalDateKey(input) {
|
|
2163
|
-
return formatDateKey(getLocalScheduleDate(new Date(input.startsAt), input.timeZone));
|
|
2164
|
-
}
|
|
2165
|
-
function compareLocalScheduleDates(left, right) {
|
|
2166
|
-
return Date.UTC(left.year, left.month - 1, left.day) - Date.UTC(right.year, right.month - 1, right.day);
|
|
2167
|
-
}
|
|
2168
|
-
function parseBookingLocalDate(value) {
|
|
2169
|
-
const match = LOCAL_DATE_PATTERN.exec(value.trim());
|
|
2170
|
-
if (match === null || match.groups === undefined) {
|
|
2171
|
-
throw new Error(`Invalid booking date format: "${value}" (expected YYYY-MM-DD)`);
|
|
2172
|
-
}
|
|
2173
|
-
const year = Number(match.groups.year);
|
|
2174
|
-
const month = Number(match.groups.month);
|
|
2175
|
-
const day = Number(match.groups.day);
|
|
2176
|
-
const candidate$1 = new Date(Date.UTC(year, month - 1, day, 12, 0, 0));
|
|
2177
|
-
if (Number.isNaN(candidate$1.getTime()) || candidate$1.getUTCFullYear() !== year || candidate$1.getUTCMonth() + 1 !== month || candidate$1.getUTCDate() !== day) {
|
|
2178
|
-
throw new Error(`Invalid booking date format: "${value}" (expected YYYY-MM-DD)`);
|
|
2179
|
-
}
|
|
2180
|
-
return {
|
|
2181
|
-
year,
|
|
2182
|
-
month,
|
|
2183
|
-
day
|
|
2184
|
-
};
|
|
2185
|
-
}
|
|
2186
|
-
/** Canonical schedule text at command and SDK boundaries: HH:MM or HH:MM:SS. */
|
|
2187
|
-
const localScheduleTimePattern = /^([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/u;
|
|
2188
|
-
function parseLocalScheduleTime(value) {
|
|
2189
|
-
const match = /^(?<hour>[01]?\d|2[0-3]):(?<minute>[0-5]\d)(?::(?<second>[0-5]\d))?$/u.exec(value.trim());
|
|
2190
|
-
if (match === null || match.groups === undefined) {
|
|
2191
|
-
throw new Error(`Invalid start time format: "${value}" (expected HH:MM or HH:MM:SS)`);
|
|
2192
|
-
}
|
|
2193
|
-
const hour = Number(match.groups.hour);
|
|
2194
|
-
const minute = Number(match.groups.minute);
|
|
2195
|
-
const second = Number(match.groups.second ?? "0");
|
|
2196
|
-
return {
|
|
2197
|
-
hour,
|
|
2198
|
-
minute,
|
|
2199
|
-
second
|
|
1867
|
+
hour,
|
|
1868
|
+
minute,
|
|
1869
|
+
second
|
|
2200
1870
|
};
|
|
2201
1871
|
}
|
|
2202
1872
|
function getLocalScheduleDate(date, timeZone) {
|
|
@@ -2278,84 +1948,24 @@ function zonedDateTimeLocalToUtcIso(localValue, timeZone) {
|
|
|
2278
1948
|
if (match === null) return null;
|
|
2279
1949
|
try {
|
|
2280
1950
|
return localScheduleDateTimeToUtcDate(parseBookingLocalDate(match[1] ?? ""), parseLocalScheduleTime(match[2] ?? ""), timeZone).toISOString();
|
|
2281
|
-
} catch {
|
|
2282
|
-
return null;
|
|
2283
|
-
}
|
|
2284
|
-
}
|
|
2285
|
-
/** A date is valid through its whole local day; storage ends at the next midnight. */
|
|
2286
|
-
function localDateToExclusiveDeadlineIso(value, timeZone) {
|
|
2287
|
-
return localScheduleDateTimeToUtcDate(addLocalScheduleDays(parseBookingLocalDate(value), 1), {
|
|
2288
|
-
hour: 0,
|
|
2289
|
-
minute: 0,
|
|
2290
|
-
second: 0
|
|
2291
|
-
}, timeZone).toISOString();
|
|
2292
|
-
}
|
|
2293
|
-
/** Subtract before projecting into the zone, just as an exclusive deadline is displayed. */
|
|
2294
|
-
function exclusiveDeadlineToLocalDateInput(iso, timeZone) {
|
|
2295
|
-
if (iso === null || iso === "") return "";
|
|
2296
|
-
const instant = Date.parse(iso);
|
|
2297
|
-
if (Number.isNaN(instant)) return "";
|
|
2298
|
-
return formatLocalScheduleDate(getLocalScheduleDate(new Date(instant - 1), timeZone));
|
|
2299
|
-
}
|
|
2300
|
-
|
|
2301
|
-
//#endregion
|
|
2302
|
-
//#region ../core/src/booking-date-time/window.ts
|
|
2303
|
-
const START_OF_DAY = {
|
|
2304
|
-
hour: 0,
|
|
2305
|
-
minute: 0,
|
|
2306
|
-
second: 0
|
|
2307
|
-
};
|
|
2308
|
-
function parseWindowDate(value, field) {
|
|
2309
|
-
try {
|
|
2310
|
-
return {
|
|
2311
|
-
ok: true,
|
|
2312
|
-
value: parseBookingLocalDate(value)
|
|
2313
|
-
};
|
|
2314
|
-
} catch {
|
|
2315
|
-
return {
|
|
2316
|
-
ok: false,
|
|
2317
|
-
field,
|
|
2318
|
-
reason: "invalid_date_format",
|
|
2319
|
-
value
|
|
2320
|
-
};
|
|
2321
|
-
}
|
|
2322
|
-
}
|
|
2323
|
-
function parseBookingUtcDateWindow(input) {
|
|
2324
|
-
const timeZone = resolveBookingTimeZoneId(input.timeZone);
|
|
2325
|
-
const start = parseWindowDate(input.startDate, "startDate");
|
|
2326
|
-
if (!start.ok) return start;
|
|
2327
|
-
const end = parseWindowDate(input.endDate, "endDate");
|
|
2328
|
-
if (!end.ok) return end;
|
|
2329
|
-
const startLocalDate = start.value;
|
|
2330
|
-
const endLocalDate = end.value;
|
|
2331
|
-
if (compareLocalScheduleDates(startLocalDate, endLocalDate) > 0) {
|
|
2332
|
-
return {
|
|
2333
|
-
ok: false,
|
|
2334
|
-
field: "endDate",
|
|
2335
|
-
reason: "invalid_date_range",
|
|
2336
|
-
value: input.endDate
|
|
2337
|
-
};
|
|
2338
|
-
}
|
|
2339
|
-
return {
|
|
2340
|
-
ok: true,
|
|
2341
|
-
value: {
|
|
2342
|
-
timeZone,
|
|
2343
|
-
startLocalDate,
|
|
2344
|
-
endLocalDate,
|
|
2345
|
-
startAt: localScheduleDateTimeToUtcDate(startLocalDate, START_OF_DAY, timeZone),
|
|
2346
|
-
endExclusive: localScheduleDateTimeToUtcDate(addLocalScheduleDays(endLocalDate, 1), START_OF_DAY, timeZone)
|
|
2347
|
-
}
|
|
2348
|
-
};
|
|
2349
|
-
}
|
|
2350
|
-
function buildBookingUtcDateWindow(input) {
|
|
2351
|
-
const result = parseBookingUtcDateWindow(input);
|
|
2352
|
-
if (result.ok) {
|
|
2353
|
-
return result.value;
|
|
2354
|
-
}
|
|
2355
|
-
if (result.reason === "invalid_date_range") {
|
|
2356
|
-
throw new Error(`Invalid booking date range: startDate "${input.startDate}" must be on or before endDate "${input.endDate}"`);
|
|
1951
|
+
} catch {
|
|
1952
|
+
return null;
|
|
2357
1953
|
}
|
|
2358
|
-
|
|
1954
|
+
}
|
|
1955
|
+
/** A date is valid through its whole local day; storage ends at the next midnight. */
|
|
1956
|
+
function localDateToExclusiveDeadlineIso(value, timeZone) {
|
|
1957
|
+
return localScheduleDateTimeToUtcDate(addLocalScheduleDays(parseBookingLocalDate(value), 1), {
|
|
1958
|
+
hour: 0,
|
|
1959
|
+
minute: 0,
|
|
1960
|
+
second: 0
|
|
1961
|
+
}, timeZone).toISOString();
|
|
1962
|
+
}
|
|
1963
|
+
/** Subtract before projecting into the zone, just as an exclusive deadline is displayed. */
|
|
1964
|
+
function exclusiveDeadlineToLocalDateInput(iso, timeZone) {
|
|
1965
|
+
if (iso === null || iso === "") return "";
|
|
1966
|
+
const instant = Date.parse(iso);
|
|
1967
|
+
if (Number.isNaN(instant)) return "";
|
|
1968
|
+
return formatLocalScheduleDate(getLocalScheduleDate(new Date(instant - 1), timeZone));
|
|
2359
1969
|
}
|
|
2360
1970
|
|
|
2361
1971
|
//#endregion
|
|
@@ -2691,208 +2301,676 @@ function presentDate(value, context, profile) {
|
|
|
2691
2301
|
const normalized = normalizeDisplay(output);
|
|
2692
2302
|
return profile.dateFormat.weekday && new Intl.Locale(context.locale).language === "en" ? normalized.replace(/^([^,]+), /u, "$1 ") : normalized;
|
|
2693
2303
|
}
|
|
2694
|
-
function presentDateRange(start, end, context, profile) {
|
|
2695
|
-
if (dateCarrier(end).getTime() < dateCarrier(start).getTime()) throw new RangeError("Date range end must be on or after its start");
|
|
2696
|
-
if (profile.kind === "display" && compareLocalScheduleDates(projectDate(start, context), projectDate(end, context)) === 0) {
|
|
2697
|
-
return presentDate(start, context, profile);
|
|
2698
|
-
}
|
|
2699
|
-
const output = formatIntlRange(getDateTimeFormatter(context.locale, start.kind === "civil" ? "UTC" : context.timeZone, profile.dateFormat), dateCarrier(start), dateCarrier(end));
|
|
2700
|
-
if (profile.kind === "sdk") return output;
|
|
2701
|
-
const startDate = projectDate(start, context);
|
|
2702
|
-
const endDate = projectDate(end, context);
|
|
2703
|
-
const separator = startDate.month === endDate.month && startDate.year === endDate.year ? "–" : " – ";
|
|
2704
|
-
return normalizeDisplay(output).replace(/\s*–\s*/gu, separator);
|
|
2304
|
+
function presentDateRange(start, end, context, profile) {
|
|
2305
|
+
if (dateCarrier(end).getTime() < dateCarrier(start).getTime()) throw new RangeError("Date range end must be on or after its start");
|
|
2306
|
+
if (profile.kind === "display" && compareLocalScheduleDates(projectDate(start, context), projectDate(end, context)) === 0) {
|
|
2307
|
+
return presentDate(start, context, profile);
|
|
2308
|
+
}
|
|
2309
|
+
const output = formatIntlRange(getDateTimeFormatter(context.locale, start.kind === "civil" ? "UTC" : context.timeZone, profile.dateFormat), dateCarrier(start), dateCarrier(end));
|
|
2310
|
+
if (profile.kind === "sdk") return output;
|
|
2311
|
+
const startDate = projectDate(start, context);
|
|
2312
|
+
const endDate = projectDate(end, context);
|
|
2313
|
+
const separator = startDate.month === endDate.month && startDate.year === endDate.year ? "–" : " – ";
|
|
2314
|
+
return normalizeDisplay(output).replace(/\s*–\s*/gu, separator);
|
|
2315
|
+
}
|
|
2316
|
+
function presentTime(value, context, profile) {
|
|
2317
|
+
const clock = presentClock(value, context, profile.clock);
|
|
2318
|
+
return profile.zone === "always" ? `${clock} ${zoneLabel(value, context)}` : clock;
|
|
2319
|
+
}
|
|
2320
|
+
function presentDateTime(value, context, profile) {
|
|
2321
|
+
if (profile.clock.kind === "intl") {
|
|
2322
|
+
return getDateTimeFormatter(context.locale, context.timeZone, combinedFormat(profile.dateFormat, profile.clock)).format(new Date(value));
|
|
2323
|
+
}
|
|
2324
|
+
return `${presentDate({
|
|
2325
|
+
kind: "instant",
|
|
2326
|
+
value
|
|
2327
|
+
}, context, profile)}, ${presentTime(value, context, profile)}`;
|
|
2328
|
+
}
|
|
2329
|
+
function presentTimeRange(span, context, profile) {
|
|
2330
|
+
assertOrdered(span.start, span.end);
|
|
2331
|
+
if (profile.clock.kind === "intl") return presentNativeRange(span, context, profile.clock.format);
|
|
2332
|
+
const startClock = presentClock(span.start, context, profile.clock);
|
|
2333
|
+
const endClock = presentClock(span.end, context, profile.clock);
|
|
2334
|
+
const equal = profile.kind === "sdk" ? startClock === endClock : span.start === span.end;
|
|
2335
|
+
const clocks = equal ? startClock : `${startClock}–${endClock}`;
|
|
2336
|
+
const labels = decideRangeLabels(span, context, profile);
|
|
2337
|
+
switch (labels.kind) {
|
|
2338
|
+
case "omit": return clocks;
|
|
2339
|
+
case "shared": return `${clocks} ${labels.label}`;
|
|
2340
|
+
case "endpoints": return `${startClock} ${labels.start} – ${endClock} ${labels.end}`;
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
function presentDateTimeRange(span, context, profile) {
|
|
2344
|
+
assertOrdered(span.start, span.end);
|
|
2345
|
+
if (profile.clock.kind === "intl") return presentNativeRange(span, context, combinedFormat(profile.dateFormat, profile.clock));
|
|
2346
|
+
const startDate = getLocalScheduleDate(new Date(span.start), context.timeZone);
|
|
2347
|
+
const endDate = getLocalScheduleDate(new Date(span.end), context.timeZone);
|
|
2348
|
+
if (compareLocalScheduleDates(startDate, endDate) === 0) {
|
|
2349
|
+
return `${presentDate({
|
|
2350
|
+
kind: "instant",
|
|
2351
|
+
value: span.start
|
|
2352
|
+
}, context, profile)}, ${presentTimeRange(span, context, profile)}`;
|
|
2353
|
+
}
|
|
2354
|
+
const labels = decideRangeLabels(span, context, profile);
|
|
2355
|
+
const startProfile = profile.kind === "display" && startDate.year === endDate.year ? {
|
|
2356
|
+
...profile,
|
|
2357
|
+
dateFormat: {
|
|
2358
|
+
...profile.dateFormat,
|
|
2359
|
+
year: undefined
|
|
2360
|
+
}
|
|
2361
|
+
} : profile;
|
|
2362
|
+
const start = presentRangeEndpoint(span.start, context, startProfile, labels.kind === "endpoints" ? labels.start : undefined);
|
|
2363
|
+
const end = presentRangeEndpoint(span.end, context, profile, labels.kind === "endpoints" ? labels.end : undefined);
|
|
2364
|
+
const separator = profile.kind === "sdk" ? "–" : " – ";
|
|
2365
|
+
return profile.kind === "sdk" && start === end ? start : `${start}${separator}${end}`;
|
|
2366
|
+
}
|
|
2367
|
+
/** Offset changes override ordinary venue omission for the approved display profile. */
|
|
2368
|
+
function decideRangeLabels(span, context, profile) {
|
|
2369
|
+
if (profile.kind === "sdk") return { kind: "omit" };
|
|
2370
|
+
const offsetsDiffer = offsetToken(span.start, context) !== offsetToken(span.end, context);
|
|
2371
|
+
if (!offsetsDiffer && profile.zone === "omit") return { kind: "omit" };
|
|
2372
|
+
const start = zoneLabel(span.start, context);
|
|
2373
|
+
const end = zoneLabel(span.end, context);
|
|
2374
|
+
return offsetsDiffer || start !== end ? {
|
|
2375
|
+
kind: "endpoints",
|
|
2376
|
+
start,
|
|
2377
|
+
end
|
|
2378
|
+
} : {
|
|
2379
|
+
kind: "shared",
|
|
2380
|
+
label: start
|
|
2381
|
+
};
|
|
2382
|
+
}
|
|
2383
|
+
function presentRangeEndpoint(value, context, profile, label$1) {
|
|
2384
|
+
const date = presentDate({
|
|
2385
|
+
kind: "instant",
|
|
2386
|
+
value
|
|
2387
|
+
}, context, profile);
|
|
2388
|
+
const time = label$1 === undefined ? presentTime(value, context, profile) : `${presentClock(value, context, profile.clock)} ${label$1}`;
|
|
2389
|
+
return `${date}, ${time}`;
|
|
2390
|
+
}
|
|
2391
|
+
function presentNativeRange(span, context, format) {
|
|
2392
|
+
return formatIntlRange(getDateTimeFormatter(context.locale, context.timeZone, format), new Date(span.start), new Date(span.end));
|
|
2393
|
+
}
|
|
2394
|
+
function combinedFormat(date, clock) {
|
|
2395
|
+
return {
|
|
2396
|
+
...date,
|
|
2397
|
+
...clock.format
|
|
2398
|
+
};
|
|
2399
|
+
}
|
|
2400
|
+
function displayProfile(options, zone, seconds) {
|
|
2401
|
+
return {
|
|
2402
|
+
kind: "display",
|
|
2403
|
+
dateFormat: dateFormat(options),
|
|
2404
|
+
clock: {
|
|
2405
|
+
kind: "compact",
|
|
2406
|
+
localeSource: "product",
|
|
2407
|
+
seconds
|
|
2408
|
+
},
|
|
2409
|
+
zone
|
|
2410
|
+
};
|
|
2411
|
+
}
|
|
2412
|
+
function dateCarrier(value) {
|
|
2413
|
+
return value.kind === "civil" ? civilCarrier(value.value) : new Date(value.value);
|
|
2414
|
+
}
|
|
2415
|
+
function presentClock(value, context, clock) {
|
|
2416
|
+
return clock.kind === "compact" ? formatBookingCompactEnglishTime({
|
|
2417
|
+
startsAt: value,
|
|
2418
|
+
timeZone: context.timeZone,
|
|
2419
|
+
locale: clock.localeSource === "product" ? "en-GB" : context.locale
|
|
2420
|
+
}, { seconds: clock.seconds }) : getDateTimeFormatter(context.locale, context.timeZone, clock.format).format(new Date(value));
|
|
2421
|
+
}
|
|
2422
|
+
function offsetToken(value, context) {
|
|
2423
|
+
return getDateTimeFormatter("en-GB", context.timeZone, { timeZoneName: "longOffset" }).formatToParts(new Date(value)).find((part) => part.type === "timeZoneName")?.value ?? "";
|
|
2424
|
+
}
|
|
2425
|
+
function formatTimeAgo(value, now, context) {
|
|
2426
|
+
return formatRelative(value, now, context, "past");
|
|
2427
|
+
}
|
|
2428
|
+
function formatTimeUntil(value, now, context) {
|
|
2429
|
+
return formatRelative(value, now, context, "future");
|
|
2430
|
+
}
|
|
2431
|
+
const DATE_STYLE_PARTS = {
|
|
2432
|
+
numeric: {
|
|
2433
|
+
day: "2-digit",
|
|
2434
|
+
month: "2-digit"
|
|
2435
|
+
},
|
|
2436
|
+
short: {
|
|
2437
|
+
day: "numeric",
|
|
2438
|
+
month: "short"
|
|
2439
|
+
},
|
|
2440
|
+
long: {
|
|
2441
|
+
day: "numeric",
|
|
2442
|
+
month: "long"
|
|
2443
|
+
},
|
|
2444
|
+
omit: {
|
|
2445
|
+
day: undefined,
|
|
2446
|
+
month: undefined
|
|
2447
|
+
}
|
|
2448
|
+
};
|
|
2449
|
+
function dateFormat(options) {
|
|
2450
|
+
return {
|
|
2451
|
+
...DATE_STYLE_PARTS[options.date ?? "long"],
|
|
2452
|
+
...options.day ? { day: options.day === "omit" ? undefined : options.day } : {},
|
|
2453
|
+
...options.month === "omit" ? { month: undefined } : {},
|
|
2454
|
+
...options.year === "omit" ? {} : { year: "numeric" },
|
|
2455
|
+
...options.weekday ? { weekday: options.weekday } : {}
|
|
2456
|
+
};
|
|
2457
|
+
}
|
|
2458
|
+
function civilCarrier(value) {
|
|
2459
|
+
return new Date(Date.UTC(value.year, value.month - 1, value.day, 12));
|
|
2460
|
+
}
|
|
2461
|
+
function projectDate(value, context) {
|
|
2462
|
+
return value.kind === "civil" ? value.value : getLocalScheduleDate(new Date(value.value), context.timeZone);
|
|
2463
|
+
}
|
|
2464
|
+
function normalizeDisplay(value) {
|
|
2465
|
+
return value.replace(/[\u00a0\u202f]/gu, " ");
|
|
2466
|
+
}
|
|
2467
|
+
function zoneToken(value, context, locale) {
|
|
2468
|
+
return getDateTimeFormatter(locale, context.timeZone, { timeZoneName: "short" }).formatToParts(new Date(value)).find((part) => part.type === "timeZoneName")?.value ?? "";
|
|
2469
|
+
}
|
|
2470
|
+
function zoneLabel(value, context) {
|
|
2471
|
+
const tokens = [zoneToken(value, context, "en-GB"), zoneToken(value, context, "en-US")];
|
|
2472
|
+
const abbreviation = tokens.find((token) => /^[A-Z]{2,6}$/u.test(token));
|
|
2473
|
+
return abbreviation ?? formatTimeZoneCityLabel(context.timeZone);
|
|
2474
|
+
}
|
|
2475
|
+
function assertOrdered(start, end) {
|
|
2476
|
+
if (new Date(end).getTime() < new Date(start).getTime()) {
|
|
2477
|
+
throw new RangeError("Date/time range end must be on or after its start");
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
function calendarDayDifference(value, now, context) {
|
|
2481
|
+
return compareLocalScheduleDates(getLocalScheduleDate(new Date(value), context.timeZone), getLocalScheduleDate(new Date(now), context.timeZone)) / 864e5;
|
|
2482
|
+
}
|
|
2483
|
+
function formatRelative(value, now, context, direction) {
|
|
2484
|
+
const seconds = (new Date(value).getTime() - new Date(now).getTime()) / 1e3;
|
|
2485
|
+
const magnitude = Math.abs(seconds);
|
|
2486
|
+
if (direction === "past" && seconds > 0 && seconds <= 120) return relativeNearNow(context.locale, "past");
|
|
2487
|
+
if (magnitude < 60) return relativeNearNow(context.locale, direction);
|
|
2488
|
+
const days = calendarDayDifference(value, now, context);
|
|
2489
|
+
if (Math.abs(days) > 7) return formatDate({
|
|
2490
|
+
kind: "instant",
|
|
2491
|
+
value
|
|
2492
|
+
}, context, { date: "short" });
|
|
2493
|
+
const formatter = new Intl.RelativeTimeFormat(context.locale, { numeric: "auto" });
|
|
2494
|
+
if (days !== 0) return formatter.format(days, "day");
|
|
2495
|
+
const unit = magnitude < 3600 ? "minute" : "hour";
|
|
2496
|
+
const signedCount = Math.sign(seconds) * Math.floor(magnitude / (unit === "minute" ? 60 : 3600));
|
|
2497
|
+
return formatter.format(signedCount, unit);
|
|
2498
|
+
}
|
|
2499
|
+
function relativeNearNow(locale, direction) {
|
|
2500
|
+
if (new Intl.Locale(locale).language === "en") return direction === "past" ? "just now" : "in a moment";
|
|
2501
|
+
return new Intl.RelativeTimeFormat(locale, { numeric: "auto" }).format(0, "second");
|
|
2502
|
+
}
|
|
2503
|
+
/** Same city vocabulary as clock-label fallback, for explanatory timezone copy. */
|
|
2504
|
+
function formatTimeZoneCityLabel(timeZone) {
|
|
2505
|
+
return timeZone.startsWith("Etc/") ? "local time" : `${timeZone.split("/").slice(-1)[0]?.replace(/_/gu, " ") ?? timeZone} time`;
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
//#endregion
|
|
2509
|
+
//#region ../core/src/event-booking-cut-off.ts
|
|
2510
|
+
/**
|
|
2511
|
+
* How long before an event starts online bookings stop.
|
|
2512
|
+
*
|
|
2513
|
+
* This file is the one owner of the arithmetic. The SQL admission gates apply
|
|
2514
|
+
* the same sum in `public.event_booking_closes_at_v1`, so the page and the gate
|
|
2515
|
+
* agree on the same instant: whole hours counted back from the start, never
|
|
2516
|
+
* calendar hours, so a clock change can't move it.
|
|
2517
|
+
*/
|
|
2518
|
+
/** The largest cut-off anyone can choose: 30 days. The database enforces it too. */
|
|
2519
|
+
const MAX_BOOKING_CUT_OFF_HOURS = 720;
|
|
2520
|
+
/** Zero is "when it starts": today's behaviour, and what a site that never chose gets. */
|
|
2521
|
+
const BOOKING_CUT_OFF_AT_START = 0;
|
|
2522
|
+
/**
|
|
2523
|
+
* What a form holds while "A different number of hours" has nothing usable in it.
|
|
2524
|
+
* The form's number stays the only value there is, and this one is out of range
|
|
2525
|
+
* on purpose: the save checks and the server's schemas all refuse it, so a blank
|
|
2526
|
+
* field can't quietly save as something else.
|
|
2527
|
+
*/
|
|
2528
|
+
const BOOKING_CUT_OFF_HOURS_BLANK = -1;
|
|
2529
|
+
const BOOKING_CUT_OFF_HOURS_MESSAGE = `Enter a whole number of hours, from 1 to ${MAX_BOOKING_CUT_OFF_HOURS}.`;
|
|
2530
|
+
/** Whether a form's value can be saved. Null follows the site, zero is "when it starts". */
|
|
2531
|
+
function isValidBookingCutOffHours(hours) {
|
|
2532
|
+
return hours === null || Number.isInteger(hours) && hours >= BOOKING_CUT_OFF_AT_START && hours <= MAX_BOOKING_CUT_OFF_HOURS;
|
|
2533
|
+
}
|
|
2534
|
+
const MS_PER_HOUR = 36e5;
|
|
2535
|
+
const MS_PER_WEEK = 7 * 24 * MS_PER_HOUR;
|
|
2536
|
+
/** An event's own choice wins. Null on the event means it follows the site. */
|
|
2537
|
+
function resolveBookingCutOffHours(input) {
|
|
2538
|
+
return input.eventHours ?? input.siteHours;
|
|
2539
|
+
}
|
|
2540
|
+
/** The instant bookings stop for something starting at `startsAt`. */
|
|
2541
|
+
function bookingClosesAt(startsAt, cutOffHours) {
|
|
2542
|
+
return new Date(Date.parse(startsAt) - cutOffHours * MS_PER_HOUR).toISOString();
|
|
2543
|
+
}
|
|
2544
|
+
/** Closing is inclusive, matching the gate: at the exact instant it has closed. */
|
|
2545
|
+
function hasBookingClosed(closesAt, now) {
|
|
2546
|
+
return Date.parse(closesAt) <= now.getTime();
|
|
2547
|
+
}
|
|
2548
|
+
/**
|
|
2549
|
+
* What the public wire says: an instant only when it's earlier than the start.
|
|
2550
|
+
* Absent means "when it starts", so events with no cut-off read exactly as they
|
|
2551
|
+
* did before the field existed.
|
|
2552
|
+
*/
|
|
2553
|
+
function publicBookingClosesAt(startsAt, cutOffHours) {
|
|
2554
|
+
return cutOffHours > 0 ? { bookingClosesAt: bookingClosesAt(startsAt, cutOffHours) } : {};
|
|
2555
|
+
}
|
|
2556
|
+
/** The whole hours between closing and the start, for "2 hours before the start". */
|
|
2557
|
+
function bookingCutOffHoursBetween(startsAt, closesAt) {
|
|
2558
|
+
return Math.round((Date.parse(startsAt) - Date.parse(closesAt)) / MS_PER_HOUR);
|
|
2559
|
+
}
|
|
2560
|
+
/**
|
|
2561
|
+
* When bookings closed, in the event's own time zone: "5pm" on the day it starts,
|
|
2562
|
+
* "7pm on Tuesday" earlier in the week, and with the date if it's further back
|
|
2563
|
+
* than that, when a weekday alone could mean the wrong one.
|
|
2564
|
+
*/
|
|
2565
|
+
function formatBookingClosedTime(closesAt, startsAt, timeZone) {
|
|
2566
|
+
const time = formatSiteInstantTime(closesAt, timeZone);
|
|
2567
|
+
const dayOf = (iso) => formatSiteInstantDate(iso, timeZone);
|
|
2568
|
+
if (dayOf(closesAt) === dayOf(startsAt)) return time;
|
|
2569
|
+
const further = Date.parse(startsAt) - Date.parse(closesAt) >= MS_PER_WEEK;
|
|
2570
|
+
const day = formatSiteInstantDate(closesAt, timeZone, further ? {
|
|
2571
|
+
date: "long",
|
|
2572
|
+
weekday: "long",
|
|
2573
|
+
year: "omit"
|
|
2574
|
+
} : {
|
|
2575
|
+
date: "omit",
|
|
2576
|
+
weekday: "long",
|
|
2577
|
+
year: "omit"
|
|
2578
|
+
});
|
|
2579
|
+
return `${time} on ${day}`;
|
|
2580
|
+
}
|
|
2581
|
+
/** "1 hour" or "24 hours". */
|
|
2582
|
+
function formatBookingCutOffHours(hours) {
|
|
2583
|
+
return hours === 1 ? "1 hour" : `${hours} hours`;
|
|
2584
|
+
}
|
|
2585
|
+
|
|
2586
|
+
//#endregion
|
|
2587
|
+
//#region ../core/src/ticket-quantity.ts
|
|
2588
|
+
function toPositiveTicketQuantity(value) {
|
|
2589
|
+
if (!Number.isFinite(value) || !Number.isInteger(value) || value <= 0) {
|
|
2590
|
+
return err("invalid_quantity");
|
|
2591
|
+
}
|
|
2592
|
+
return ok(value);
|
|
2593
|
+
}
|
|
2594
|
+
/**
|
|
2595
|
+
* The places a booking holds: the sum of its ticket lines' quantities. The one
|
|
2596
|
+
* derivation for selections, persisted lines and a booking outcome's lines;
|
|
2597
|
+
* null when the total is not a positive whole number.
|
|
2598
|
+
*/
|
|
2599
|
+
function deriveTotalTicketQuantity(lines) {
|
|
2600
|
+
const total = lines.reduce((sum, line$1) => sum + line$1.quantity, 0);
|
|
2601
|
+
const parsed = toPositiveTicketQuantity(total);
|
|
2602
|
+
return parsed.ok ? parsed.value : null;
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2605
|
+
//#endregion
|
|
2606
|
+
//#region ../core/src/booking-flexible-balance.ts
|
|
2607
|
+
function clampFlexibleBalanceConfiguredAmount(amountCents, totalAmountCents) {
|
|
2608
|
+
return Math.max(0, Math.min(amountCents, totalAmountCents));
|
|
2705
2609
|
}
|
|
2706
|
-
function
|
|
2707
|
-
|
|
2708
|
-
return profile.zone === "always" ? `${clock} ${zoneLabel(value, context)}` : clock;
|
|
2610
|
+
function resolveFlexibleBalanceInitialPaymentCents(input) {
|
|
2611
|
+
return clampFlexibleBalanceConfiguredAmount(input.config.upfrontAmountCents, input.totalAmountCents);
|
|
2709
2612
|
}
|
|
2710
|
-
function
|
|
2711
|
-
|
|
2712
|
-
return getDateTimeFormatter(context.locale, context.timeZone, combinedFormat(profile.dateFormat, profile.clock)).format(new Date(value));
|
|
2713
|
-
}
|
|
2714
|
-
return `${presentDate({
|
|
2715
|
-
kind: "instant",
|
|
2716
|
-
value
|
|
2717
|
-
}, context, profile)}, ${presentTime(value, context, profile)}`;
|
|
2613
|
+
function calculateFlexibleBalanceRemainingBalanceCents(input) {
|
|
2614
|
+
return Math.max(0, input.totalAmountCents - input.paidAmountCents);
|
|
2718
2615
|
}
|
|
2719
|
-
function
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
const equal = profile.kind === "sdk" ? startClock === endClock : span.start === span.end;
|
|
2725
|
-
const clocks = equal ? startClock : `${startClock}–${endClock}`;
|
|
2726
|
-
const labels = decideRangeLabels(span, context, profile);
|
|
2727
|
-
switch (labels.kind) {
|
|
2728
|
-
case "omit": return clocks;
|
|
2729
|
-
case "shared": return `${clocks} ${labels.label}`;
|
|
2730
|
-
case "endpoints": return `${startClock} ${labels.start} – ${endClock} ${labels.end}`;
|
|
2616
|
+
function resolveFlexibleBalanceDueAt(input) {
|
|
2617
|
+
switch (input.dueDateRule.kind) {
|
|
2618
|
+
case "relative_to_start_date": return subtractDaysFromIso(input.bookingStartAt, input.dueDateRule.daysBeforeStart);
|
|
2619
|
+
case "fixed_calendar_date": return input.dueDateRule.dueAt;
|
|
2620
|
+
default: return assertNever$5(input.dueDateRule);
|
|
2731
2621
|
}
|
|
2732
2622
|
}
|
|
2733
|
-
function
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
const startDate = getLocalScheduleDate(new Date(span.start), context.timeZone);
|
|
2737
|
-
const endDate = getLocalScheduleDate(new Date(span.end), context.timeZone);
|
|
2738
|
-
if (compareLocalScheduleDates(startDate, endDate) === 0) {
|
|
2739
|
-
return `${presentDate({
|
|
2740
|
-
kind: "instant",
|
|
2741
|
-
value: span.start
|
|
2742
|
-
}, context, profile)}, ${presentTimeRange(span, context, profile)}`;
|
|
2623
|
+
function calculateFlexibleBalanceMinimumPaymentCents(input) {
|
|
2624
|
+
if (input.remainingBalanceCents <= 0) {
|
|
2625
|
+
return 0;
|
|
2743
2626
|
}
|
|
2744
|
-
const
|
|
2745
|
-
const
|
|
2746
|
-
|
|
2747
|
-
dateFormat: {
|
|
2748
|
-
...profile.dateFormat,
|
|
2749
|
-
year: undefined
|
|
2750
|
-
}
|
|
2751
|
-
} : profile;
|
|
2752
|
-
const start = presentRangeEndpoint(span.start, context, startProfile, labels.kind === "endpoints" ? labels.start : undefined);
|
|
2753
|
-
const end = presentRangeEndpoint(span.end, context, profile, labels.kind === "endpoints" ? labels.end : undefined);
|
|
2754
|
-
const separator = profile.kind === "sdk" ? "–" : " – ";
|
|
2755
|
-
return profile.kind === "sdk" && start === end ? start : `${start}${separator}${end}`;
|
|
2627
|
+
const minimumPercentageBps = input.minimumPercentageBps ?? 1e3;
|
|
2628
|
+
const percentageFloor = Math.ceil(input.remainingBalanceCents * minimumPercentageBps / 1e4);
|
|
2629
|
+
return Math.min(input.remainingBalanceCents, Math.max(input.stripeMinimumChargeCents, percentageFloor));
|
|
2756
2630
|
}
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
return
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2631
|
+
function assertNever$5(value) {
|
|
2632
|
+
throw new Error(`Unexpected value: ${String(value)}`);
|
|
2633
|
+
}
|
|
2634
|
+
|
|
2635
|
+
//#endregion
|
|
2636
|
+
//#region ../core/src/booking-refunds.ts
|
|
2637
|
+
function normalizeBookingProtectedDepositPolicyState(value) {
|
|
2638
|
+
return value === "not_applicable" || value === "refundable" || value === "non_refundable" ? value : "not_applicable";
|
|
2639
|
+
}
|
|
2640
|
+
function shouldAllowProtectedDepositOverride(command) {
|
|
2641
|
+
return command.protectedDepositOverride === "allow_protected_deposit_override";
|
|
2642
|
+
}
|
|
2643
|
+
function createBookingRefundAmountRequest(amountCents) {
|
|
2644
|
+
return amountCents == null ? { kind: "full_remaining" } : {
|
|
2645
|
+
kind: "partial_amount",
|
|
2646
|
+
amountCents
|
|
2771
2647
|
};
|
|
2772
2648
|
}
|
|
2773
|
-
function
|
|
2774
|
-
const
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2649
|
+
function createOriginalPaymentRefundCommand(options) {
|
|
2650
|
+
const protectedDepositOverride = options.protectedDepositOverride ?? "respect_policy";
|
|
2651
|
+
return options.kind === "refund_and_revoke" ? {
|
|
2652
|
+
kind: "refund_and_revoke",
|
|
2653
|
+
amount: { kind: "full_remaining" },
|
|
2654
|
+
requestedRefundMethod: "original_payment",
|
|
2655
|
+
protectedDepositOverride
|
|
2656
|
+
} : {
|
|
2657
|
+
kind: "refund_only",
|
|
2658
|
+
amount: options.amount ?? { kind: "full_remaining" },
|
|
2659
|
+
requestedRefundMethod: "original_payment",
|
|
2660
|
+
protectedDepositOverride
|
|
2661
|
+
};
|
|
2780
2662
|
}
|
|
2781
|
-
|
|
2782
|
-
|
|
2663
|
+
/** Narrow an already typed run or schedule write response to its accepted receipt. */
|
|
2664
|
+
function isAcceptedEventScheduleUpdate(response) {
|
|
2665
|
+
return "kind" in response && response.kind === "accepted_unavailable";
|
|
2783
2666
|
}
|
|
2784
|
-
function
|
|
2667
|
+
function refundDestinationAmounts(destination, amountCents) {
|
|
2785
2668
|
return {
|
|
2786
|
-
|
|
2787
|
-
|
|
2669
|
+
cardCents: destination === "card" ? amountCents : 0,
|
|
2670
|
+
directCents: destination === "direct" ? amountCents : 0,
|
|
2671
|
+
creditCents: destination === "credit" ? amountCents : 0
|
|
2788
2672
|
};
|
|
2789
2673
|
}
|
|
2790
|
-
function
|
|
2674
|
+
function addRefundDestinationAmounts(a, b) {
|
|
2791
2675
|
return {
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
kind: "compact",
|
|
2796
|
-
localeSource: "product",
|
|
2797
|
-
seconds
|
|
2798
|
-
},
|
|
2799
|
-
zone
|
|
2676
|
+
cardCents: a.cardCents + b.cardCents,
|
|
2677
|
+
directCents: a.directCents + b.directCents,
|
|
2678
|
+
creditCents: a.creditCents + b.creditCents
|
|
2800
2679
|
};
|
|
2801
2680
|
}
|
|
2802
|
-
function
|
|
2803
|
-
return
|
|
2681
|
+
function hasDirectRefundFunding(funding) {
|
|
2682
|
+
return funding?.some((line$1) => line$1.destination === "direct" && line$1.remainingCents > 0) ?? false;
|
|
2804
2683
|
}
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
locale: clock.localeSource === "product" ? "en-GB" : context.locale
|
|
2810
|
-
}, { seconds: clock.seconds }) : getDateTimeFormatter(context.locale, context.timeZone, clock.format).format(new Date(value));
|
|
2684
|
+
/** A refund cut-off as a span of time: "24 hours", "2 days", "1 hour". */
|
|
2685
|
+
function formatCancellationCutoffSpan(cutoffHours) {
|
|
2686
|
+
if (cutoffHours > 24 && cutoffHours % 24 === 0) return `${cutoffHours / 24} days`;
|
|
2687
|
+
return cutoffHours === 1 ? "1 hour" : `${cutoffHours} hours`;
|
|
2811
2688
|
}
|
|
2812
|
-
|
|
2813
|
-
|
|
2689
|
+
/** Closed refusal and reconciliation reasons shared by stored reviews and receipts. */
|
|
2690
|
+
const scheduleBookingReasonCodes = [
|
|
2691
|
+
"closed",
|
|
2692
|
+
"switched_off",
|
|
2693
|
+
"course_booking",
|
|
2694
|
+
"checked_in",
|
|
2695
|
+
"cancelled",
|
|
2696
|
+
"waitlisted",
|
|
2697
|
+
"past",
|
|
2698
|
+
"date_missing",
|
|
2699
|
+
"payment_pending",
|
|
2700
|
+
"not_owner",
|
|
2701
|
+
"full",
|
|
2702
|
+
"not_enough_room",
|
|
2703
|
+
"needs_ticket_choice",
|
|
2704
|
+
"ticket_not_usable",
|
|
2705
|
+
"tickets_collide",
|
|
2706
|
+
"pass_not_accepted",
|
|
2707
|
+
"already_booked",
|
|
2708
|
+
"not_bookable",
|
|
2709
|
+
"not_found",
|
|
2710
|
+
"source_changed",
|
|
2711
|
+
"source_unavailable",
|
|
2712
|
+
"target_full",
|
|
2713
|
+
"target_not_bookable",
|
|
2714
|
+
"target_changed",
|
|
2715
|
+
"already_booked_on_target",
|
|
2716
|
+
"no_replacement_in_week",
|
|
2717
|
+
"changed_after_review",
|
|
2718
|
+
"added_after_review",
|
|
2719
|
+
"cancellation_chosen",
|
|
2720
|
+
"move_refused"
|
|
2721
|
+
];
|
|
2722
|
+
const businessCancellationRefusalCodes = [
|
|
2723
|
+
"review_changed",
|
|
2724
|
+
"not_found",
|
|
2725
|
+
"payment_in_progress",
|
|
2726
|
+
"payment_check_unavailable",
|
|
2727
|
+
"partial_payment_terms",
|
|
2728
|
+
"settlement_not_allowed"
|
|
2729
|
+
];
|
|
2730
|
+
const businessCancellationRefusalCopy = {
|
|
2731
|
+
review_changed: "Bookings have changed since you reviewed this schedule. Review the changes again before saving.",
|
|
2732
|
+
not_found: "One of these dates could not be found. Refresh the dates and review your changes again.",
|
|
2733
|
+
payment_in_progress: "A payment is still being processed for one of these bookings. Wait for it to finish, then review the cancellation again.",
|
|
2734
|
+
payment_check_unavailable: "We could not check a payment for one of these bookings. Review the cancellation again later, or contact us for help.",
|
|
2735
|
+
partial_payment_terms: "One of these bookings shares a payment arrangement with another booking. Cancel the bookings together or contact us for help.",
|
|
2736
|
+
settlement_not_allowed: "A refund choice can't be used any more: account credit may have been turned off, or how a booking was paid has changed. Review the cancellation again and choose again."
|
|
2737
|
+
};
|
|
2738
|
+
|
|
2739
|
+
//#endregion
|
|
2740
|
+
//#region ../core/src/booking-instalments.ts
|
|
2741
|
+
function isDepositBearingBookingInstalmentPlan(plan) {
|
|
2742
|
+
switch (plan.kind) {
|
|
2743
|
+
case "deposit_plus_one_remainder":
|
|
2744
|
+
case "deposit_plus_scheduled_instalments": return true;
|
|
2745
|
+
case "equal_scheduled_instalments": return false;
|
|
2746
|
+
default: return assertNever$4(plan);
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
function getBookingInstalmentDepositRefundability(plan) {
|
|
2750
|
+
return isDepositBearingBookingInstalmentPlan(plan) ? plan.depositRefundability : null;
|
|
2751
|
+
}
|
|
2752
|
+
function getBookingInstalmentProtectedDepositAmountCents(plan) {
|
|
2753
|
+
return isDepositBearingBookingInstalmentPlan(plan) ? plan.depositAmountCents : null;
|
|
2754
|
+
}
|
|
2755
|
+
function clampConfiguredAmount(amountCents, totalAmountCents) {
|
|
2756
|
+
return Math.max(0, Math.min(amountCents, totalAmountCents));
|
|
2757
|
+
}
|
|
2758
|
+
function splitAmountWithRemainderInFirst(totalAmountCents, partCount) {
|
|
2759
|
+
if (partCount <= 0) {
|
|
2760
|
+
return [];
|
|
2761
|
+
}
|
|
2762
|
+
const baseAmountCents = Math.floor(totalAmountCents / partCount);
|
|
2763
|
+
const remainderCents = totalAmountCents - baseAmountCents * partCount;
|
|
2764
|
+
return Array.from({ length: partCount }, (_, index) => index === 0 ? baseAmountCents + remainderCents : baseAmountCents);
|
|
2765
|
+
}
|
|
2766
|
+
function addIntervalPreservingMonthAnchor(isoString, intervalCount, intervalUnit) {
|
|
2767
|
+
const date = new Date(isoString);
|
|
2768
|
+
if (!Number.isFinite(date.getTime())) {
|
|
2769
|
+
return isoString;
|
|
2770
|
+
}
|
|
2771
|
+
switch (intervalUnit) {
|
|
2772
|
+
case "day":
|
|
2773
|
+
date.setUTCDate(date.getUTCDate() + intervalCount);
|
|
2774
|
+
return date.toISOString();
|
|
2775
|
+
case "week":
|
|
2776
|
+
date.setUTCDate(date.getUTCDate() + intervalCount * 7);
|
|
2777
|
+
return date.toISOString();
|
|
2778
|
+
case "month": return addMonthsPreservingAnchorDay(date, intervalCount).toISOString();
|
|
2779
|
+
default: return assertNever$4(intervalUnit);
|
|
2780
|
+
}
|
|
2814
2781
|
}
|
|
2815
|
-
function
|
|
2816
|
-
|
|
2782
|
+
function getBookingInstalmentPlanIntervalCount(plan) {
|
|
2783
|
+
switch (plan.kind) {
|
|
2784
|
+
case "deposit_plus_one_remainder": return plan.remainderDueCount;
|
|
2785
|
+
case "deposit_plus_scheduled_instalments":
|
|
2786
|
+
case "equal_scheduled_instalments": return plan.intervalCount;
|
|
2787
|
+
default: return assertNever$4(plan);
|
|
2788
|
+
}
|
|
2817
2789
|
}
|
|
2818
|
-
function
|
|
2819
|
-
|
|
2790
|
+
function omitZeroAmountFutureRows(rows) {
|
|
2791
|
+
if (rows.length <= 1) {
|
|
2792
|
+
return rows;
|
|
2793
|
+
}
|
|
2794
|
+
const firstRow = rows[0];
|
|
2795
|
+
if (firstRow === undefined) {
|
|
2796
|
+
return [];
|
|
2797
|
+
}
|
|
2798
|
+
const futureRows = rows.slice(1);
|
|
2799
|
+
return [firstRow, ...futureRows.filter((row) => row.amountCents > 0)];
|
|
2820
2800
|
}
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
month: "long"
|
|
2833
|
-
},
|
|
2834
|
-
omit: {
|
|
2835
|
-
day: undefined,
|
|
2836
|
-
month: undefined
|
|
2801
|
+
function formatOrderInstalmentStatusLabel(input) {
|
|
2802
|
+
switch (input.status) {
|
|
2803
|
+
case "pending_initial_payment": return input.phaseKind === "initial" ? "Due today" : "Scheduled";
|
|
2804
|
+
case "scheduled": return "Scheduled";
|
|
2805
|
+
case "paid": return input.phaseKind === "initial" ? "Paid today" : "Paid";
|
|
2806
|
+
case "failed": return "Payment failed";
|
|
2807
|
+
case "waived": return "Waived";
|
|
2808
|
+
case "cancelled": return "Cancelled";
|
|
2809
|
+
case "cancelled_as_paid_early": return "Paid early";
|
|
2810
|
+
case "refunded": return "Refunded";
|
|
2811
|
+
default: return assertNever$4(input.status);
|
|
2837
2812
|
}
|
|
2838
|
-
}
|
|
2839
|
-
|
|
2813
|
+
}
|
|
2814
|
+
const NEXT_DUE_STATUSES = new Set(["scheduled", "failed"]);
|
|
2815
|
+
function buildOrderInstalmentSummary(input) {
|
|
2816
|
+
const nextDue = input.instalments.find((instalment) => NEXT_DUE_STATUSES.has(instalment.status)) ?? null;
|
|
2840
2817
|
return {
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2818
|
+
status: input.paymentPlan.status,
|
|
2819
|
+
remainingBalanceCents: input.paymentPlan.remainingBalanceCents,
|
|
2820
|
+
nextDueAt: nextDue?.dueAt ?? null,
|
|
2821
|
+
nextDueAmountCents: nextDue?.amountCents ?? null,
|
|
2822
|
+
rows: [...input.instalments]
|
|
2846
2823
|
};
|
|
2847
2824
|
}
|
|
2848
|
-
function
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2825
|
+
function addMonthsPreservingAnchorDay(date, intervalCount) {
|
|
2826
|
+
const anchorDay = date.getUTCDate();
|
|
2827
|
+
const nextMonth = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + intervalCount, 1, date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds()));
|
|
2828
|
+
const lastDayOfTargetMonth = new Date(Date.UTC(nextMonth.getUTCFullYear(), nextMonth.getUTCMonth() + 1, 0)).getUTCDate();
|
|
2829
|
+
nextMonth.setUTCDate(Math.min(anchorDay, lastDayOfTargetMonth));
|
|
2830
|
+
return nextMonth;
|
|
2853
2831
|
}
|
|
2854
|
-
function
|
|
2855
|
-
|
|
2832
|
+
function assertNever$4(value) {
|
|
2833
|
+
throw new Error(`Unexpected value: ${String(value)}`);
|
|
2856
2834
|
}
|
|
2857
|
-
|
|
2858
|
-
|
|
2835
|
+
|
|
2836
|
+
//#endregion
|
|
2837
|
+
//#region ../core/src/booking-instalment-deposit.ts
|
|
2838
|
+
/**
|
|
2839
|
+
* A plan that starts with a deposit takes it by card when the customer books
|
|
2840
|
+
* and saves the card for the later payments, so the deposit must be at least
|
|
2841
|
+
* the card minimum for the site's currency. Plans without a deposit step
|
|
2842
|
+
* (equal instalments) charge their first instalment instead and are not
|
|
2843
|
+
* checked here.
|
|
2844
|
+
*/
|
|
2845
|
+
function checkInstalmentPlanDeposit(plan, minimumCents) {
|
|
2846
|
+
if (!isDepositBearingBookingInstalmentPlan(plan)) return ok(undefined);
|
|
2847
|
+
return plan.depositAmountCents >= minimumCents ? ok(undefined) : err({
|
|
2848
|
+
kind: "instalment_deposit_below_minimum",
|
|
2849
|
+
minimumCents,
|
|
2850
|
+
option: "instalment_plan"
|
|
2851
|
+
});
|
|
2859
2852
|
}
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
const
|
|
2863
|
-
|
|
2853
|
+
/** The deposit check for whichever instalment option a set of payment options offers. */
|
|
2854
|
+
function checkPaymentOptionsInstalmentDeposit(allowedOptions, minimumCents) {
|
|
2855
|
+
const failure = allowedOptions.map((option) => option.kind === "instalment_plan" ? checkInstalmentPlanDeposit(option.plan, minimumCents) : option.kind === "flexible_balance" && option.config.upfrontAmountCents < minimumCents ? err({
|
|
2856
|
+
kind: "instalment_deposit_below_minimum",
|
|
2857
|
+
minimumCents,
|
|
2858
|
+
option: "flexible_balance"
|
|
2859
|
+
}) : ok(undefined)).find((checked) => !checked.ok);
|
|
2860
|
+
return failure ?? ok(undefined);
|
|
2864
2861
|
}
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2862
|
+
/** The one message for a deposit below the minimum, shown in the editor and returned by the server. */
|
|
2863
|
+
function describeInstalmentDepositBelowMinimum(failure, currency) {
|
|
2864
|
+
const minimum = formatCurrencyAmount(failure.minimumCents, currency);
|
|
2865
|
+
switch (failure.option) {
|
|
2866
|
+
case "instalment_plan": return `Enter a deposit of at least ${minimum}. We take it when the customer books and save their card for the later payments.`;
|
|
2867
|
+
case "flexible_balance": return `The deposit needs to be at least ${minimum}.`;
|
|
2868
2868
|
}
|
|
2869
2869
|
}
|
|
2870
|
-
|
|
2871
|
-
|
|
2870
|
+
|
|
2871
|
+
//#endregion
|
|
2872
|
+
//#region ../core/src/booking-live-payment-terms.ts
|
|
2873
|
+
/**
|
|
2874
|
+
* Stored instalment-provider outcomes used by schedule coordination.
|
|
2875
|
+
* Order money admissions and flexible-balance liveness come from the position.
|
|
2876
|
+
* The table is total over the plan status union.
|
|
2877
|
+
*/
|
|
2878
|
+
const LIVE_PLAN_STATUSES = {
|
|
2879
|
+
pending_initial_payment: true,
|
|
2880
|
+
active: true,
|
|
2881
|
+
payment_failed: true,
|
|
2882
|
+
reconciliation_required: true,
|
|
2883
|
+
completed: false,
|
|
2884
|
+
cancelled: false,
|
|
2885
|
+
cancelled_as_paid_early: false,
|
|
2886
|
+
refunded: false
|
|
2887
|
+
};
|
|
2888
|
+
function isLiveOrderInstalmentPlanStatus(status) {
|
|
2889
|
+
return LIVE_PLAN_STATUSES[status];
|
|
2872
2890
|
}
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2891
|
+
/** The live plan statuses as a list, for queries that select plans to collect. */
|
|
2892
|
+
const LIVE_ORDER_INSTALMENT_PLAN_STATUSES = Object.keys(LIVE_PLAN_STATUSES).filter(isLiveOrderInstalmentPlanStatus);
|
|
2893
|
+
/** Shared reason for closing either form of booking payment terms. */
|
|
2894
|
+
const PAYMENT_TERMS_CLOSURE_REASONS = ["cancelled", "refunded"];
|
|
2895
|
+
|
|
2896
|
+
//#endregion
|
|
2897
|
+
//#region ../core/src/booking-payment-options.ts
|
|
2898
|
+
/**
|
|
2899
|
+
* One way a customer may pay for a booking. This is the single definition of
|
|
2900
|
+
* the option type; `booking-payment-schemas.typetest.ts` keeps it equal to the
|
|
2901
|
+
* schema's output in both directions.
|
|
2902
|
+
*/
|
|
2903
|
+
/** When a course's instalments must all be paid by: before its first or its last live session. */
|
|
2904
|
+
const BOOKING_COURSE_INSTALMENT_DEADLINES = ["first_session", "last_session"];
|
|
2905
|
+
/** Automatic instalments and a flexible balance cannot share one booking offer. */
|
|
2906
|
+
function validateBookingPaymentOptionKinds(kinds) {
|
|
2907
|
+
if (kinds.length === 0) return err("no_options");
|
|
2908
|
+
const uniqueKinds = new Set(kinds);
|
|
2909
|
+
if (uniqueKinds.size !== kinds.length) return err("duplicate_kind");
|
|
2910
|
+
if (uniqueKinds.has("instalment_plan") && uniqueKinds.has("flexible_balance")) {
|
|
2911
|
+
return err("incompatible_collection_options");
|
|
2912
|
+
}
|
|
2913
|
+
return ok(undefined);
|
|
2888
2914
|
}
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2915
|
+
|
|
2916
|
+
//#endregion
|
|
2917
|
+
//#region ../core/src/booking-date-time/window.ts
|
|
2918
|
+
const START_OF_DAY = {
|
|
2919
|
+
hour: 0,
|
|
2920
|
+
minute: 0,
|
|
2921
|
+
second: 0
|
|
2922
|
+
};
|
|
2923
|
+
function parseWindowDate(value, field) {
|
|
2924
|
+
try {
|
|
2925
|
+
return {
|
|
2926
|
+
ok: true,
|
|
2927
|
+
value: parseBookingLocalDate(value)
|
|
2928
|
+
};
|
|
2929
|
+
} catch {
|
|
2930
|
+
return {
|
|
2931
|
+
ok: false,
|
|
2932
|
+
field,
|
|
2933
|
+
reason: "invalid_date_format",
|
|
2934
|
+
value
|
|
2935
|
+
};
|
|
2936
|
+
}
|
|
2892
2937
|
}
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2938
|
+
function parseBookingUtcDateWindow(input) {
|
|
2939
|
+
const timeZone = resolveBookingTimeZoneId(input.timeZone);
|
|
2940
|
+
const start = parseWindowDate(input.startDate, "startDate");
|
|
2941
|
+
if (!start.ok) return start;
|
|
2942
|
+
const end = parseWindowDate(input.endDate, "endDate");
|
|
2943
|
+
if (!end.ok) return end;
|
|
2944
|
+
const startLocalDate = start.value;
|
|
2945
|
+
const endLocalDate = end.value;
|
|
2946
|
+
if (compareLocalScheduleDates(startLocalDate, endLocalDate) > 0) {
|
|
2947
|
+
return {
|
|
2948
|
+
ok: false,
|
|
2949
|
+
field: "endDate",
|
|
2950
|
+
reason: "invalid_date_range",
|
|
2951
|
+
value: input.endDate
|
|
2952
|
+
};
|
|
2953
|
+
}
|
|
2954
|
+
return {
|
|
2955
|
+
ok: true,
|
|
2956
|
+
value: {
|
|
2957
|
+
timeZone,
|
|
2958
|
+
startLocalDate,
|
|
2959
|
+
endLocalDate,
|
|
2960
|
+
startAt: localScheduleDateTimeToUtcDate(startLocalDate, START_OF_DAY, timeZone),
|
|
2961
|
+
endExclusive: localScheduleDateTimeToUtcDate(addLocalScheduleDays(endLocalDate, 1), START_OF_DAY, timeZone)
|
|
2962
|
+
}
|
|
2963
|
+
};
|
|
2964
|
+
}
|
|
2965
|
+
function buildBookingUtcDateWindow(input) {
|
|
2966
|
+
const result = parseBookingUtcDateWindow(input);
|
|
2967
|
+
if (result.ok) {
|
|
2968
|
+
return result.value;
|
|
2969
|
+
}
|
|
2970
|
+
if (result.reason === "invalid_date_range") {
|
|
2971
|
+
throw new Error(`Invalid booking date range: startDate "${input.startDate}" must be on or before endDate "${input.endDate}"`);
|
|
2972
|
+
}
|
|
2973
|
+
throw new Error(`Invalid booking date format: "${result.value}" (expected YYYY-MM-DD)`);
|
|
2896
2974
|
}
|
|
2897
2975
|
|
|
2898
2976
|
//#endregion
|
|
@@ -8389,16 +8467,17 @@ function nextLiveRunSessionStartMs(sessions, now) {
|
|
|
8389
8467
|
return next === undefined ? null : sessionStartMs(next);
|
|
8390
8468
|
}
|
|
8391
8469
|
/**
|
|
8392
|
-
* Booking stays open until the run's
|
|
8470
|
+
* Booking stays open until the run's cut-off, counted from its first surviving
|
|
8471
|
+
* session. A cut-off of zero closes it as that session starts.
|
|
8393
8472
|
*
|
|
8394
8473
|
* There has to be something left to sell: a run with no schedule at all, or one
|
|
8395
8474
|
* whose every session has been cancelled, is closed rather than open. Adding a
|
|
8396
8475
|
* future session opens it again, subject to the usual status, visibility and
|
|
8397
8476
|
* admission rules.
|
|
8398
8477
|
*/
|
|
8399
|
-
function isWholeSeriesRegistrationOpen(sessions, now) {
|
|
8400
|
-
const
|
|
8401
|
-
return
|
|
8478
|
+
function isWholeSeriesRegistrationOpen(sessions, now, cutOffHours) {
|
|
8479
|
+
const first = orderedLiveRunSessions(sessions)[0];
|
|
8480
|
+
return first !== undefined && !hasBookingClosed(bookingClosesAt(first.startsAt, cutOffHours), now);
|
|
8402
8481
|
}
|
|
8403
8482
|
/**
|
|
8404
8483
|
* Where the run sits in its own life, independent of any one session.
|
|
@@ -8423,8 +8502,8 @@ function resolveWholeSeriesRunLifecycle(input, now) {
|
|
|
8423
8502
|
* Whether a prepared run is still inviting bookings at render time.
|
|
8424
8503
|
*
|
|
8425
8504
|
* `lifecycle` and `enrollmentOpen` come from the projection; the first session
|
|
8426
|
-
* start
|
|
8427
|
-
* cached page can cross while it sits in front of a visitor.
|
|
8505
|
+
* start and the cut-off are the facts re-read against `now`, because those are
|
|
8506
|
+
* the boundaries a cached page can cross while it sits in front of a visitor.
|
|
8428
8507
|
*/
|
|
8429
8508
|
function resolveWholeSeriesBookingPhase(run, now) {
|
|
8430
8509
|
switch (run.lifecycle) {
|
|
@@ -8447,12 +8526,18 @@ function resolveWholeSeriesBookingPhase(run, now) {
|
|
|
8447
8526
|
reason: "no-sessions"
|
|
8448
8527
|
};
|
|
8449
8528
|
}
|
|
8450
|
-
if (!isWholeSeriesRegistrationOpen(run.sessions, now)) {
|
|
8529
|
+
if (!isWholeSeriesRegistrationOpen(run.sessions, now, BOOKING_CUT_OFF_AT_START)) {
|
|
8451
8530
|
return {
|
|
8452
8531
|
kind: "closed",
|
|
8453
8532
|
reason: "in-progress"
|
|
8454
8533
|
};
|
|
8455
8534
|
}
|
|
8535
|
+
if (run.bookingClosesAt !== undefined && hasBookingClosed(run.bookingClosesAt, now)) {
|
|
8536
|
+
return {
|
|
8537
|
+
kind: "closed",
|
|
8538
|
+
reason: "bookings-closed"
|
|
8539
|
+
};
|
|
8540
|
+
}
|
|
8456
8541
|
return run.enrollmentOpen ? { kind: "open" } : {
|
|
8457
8542
|
kind: "closed",
|
|
8458
8543
|
reason: "enrolment-closed"
|
|
@@ -11265,6 +11350,12 @@ function decideBookingEmbedChange(current, change) {
|
|
|
11265
11350
|
|
|
11266
11351
|
//#endregion
|
|
11267
11352
|
//#region ../core/src/ownerAppointmentTime.ts
|
|
11353
|
+
function googleBusy(check) {
|
|
11354
|
+
return check.kind === "checked" ? check.busy : [];
|
|
11355
|
+
}
|
|
11356
|
+
function googleCalendarWarning(check) {
|
|
11357
|
+
return check.kind === "unchecked" ? check.warning : null;
|
|
11358
|
+
}
|
|
11268
11359
|
/** Owners may waive public rules, but cannot waive real clashes or book into the past. */
|
|
11269
11360
|
function decideOwnerAppointmentTime(proposed, rules, nowMs) {
|
|
11270
11361
|
const start = Date.parse(proposed.startAt);
|
|
@@ -11296,11 +11387,12 @@ function decideOwnerAppointmentTime(proposed, rules, nowMs) {
|
|
|
11296
11387
|
booking_window: rules.bookingNotice.maxBookingNoticeMinutes !== null && start > nowMs + rules.bookingNotice.maxBookingNoticeMinutes * 6e4,
|
|
11297
11388
|
buffer: rules.occupiedWindows.some((window) => overlaps$1(window, occupiedStart, occupiedEnd)),
|
|
11298
11389
|
closure: rules.closures.some((window) => overlaps$1(window, occupiedStart, occupiedEnd)),
|
|
11299
|
-
google_busy: rules.
|
|
11390
|
+
google_busy: googleBusy(rules.googleCalendar).some((window) => overlaps$1(window, occupiedStart, occupiedEnd))
|
|
11300
11391
|
};
|
|
11301
11392
|
return {
|
|
11302
11393
|
kind: "allowed",
|
|
11303
|
-
ruleBreaks: Object.keys(breaks).filter((key) => breaks[key])
|
|
11394
|
+
ruleBreaks: Object.keys(breaks).filter((key) => breaks[key]),
|
|
11395
|
+
googleCalendarWarning: googleCalendarWarning(rules.googleCalendar)
|
|
11304
11396
|
};
|
|
11305
11397
|
}
|
|
11306
11398
|
function regularRefusalFromBreaks(breaks) {
|
|
@@ -11339,7 +11431,10 @@ const OWNER_APPOINTMENT_RULE_COPY = {
|
|
|
11339
11431
|
closure: "During a closure or time off",
|
|
11340
11432
|
google_busy: "Busy in Google Calendar"
|
|
11341
11433
|
};
|
|
11342
|
-
const
|
|
11434
|
+
const OWNER_APPOINTMENT_GOOGLE_WARNING_COPY = {
|
|
11435
|
+
read_failed: "We couldn’t check Google Calendar just now, so this time might clash with something there.",
|
|
11436
|
+
needs_reconnecting: "Google Calendar needs reconnecting, so this time hasn’t been checked against it."
|
|
11437
|
+
};
|
|
11343
11438
|
const OWNER_APPOINTMENT_REFUSAL_COPY = {
|
|
11344
11439
|
nonexistent_time: "The clocks go forward on this date, so that time is skipped. Choose another time.",
|
|
11345
11440
|
invalid_time: "Choose a valid time for this service.",
|
|
@@ -11389,4 +11484,4 @@ function isEventOccurrenceRouteSegment(segment) {
|
|
|
11389
11484
|
}
|
|
11390
11485
|
|
|
11391
11486
|
//#endregion
|
|
11392
|
-
export { footerLayoutForLookId as $,
|
|
11487
|
+
export { footerLayoutForLookId as $, parseDatedOfferingCapacityHoldId as $n, resolveBookingDisplayContext as $t, publicReadBatchFreshnessSeconds as A, mapNonEmptyArray as An, unsafeAsEventSeriesId as Ar, clampConfiguredAmount as At, parseManagementKey as B, parseCurrencyCode as Bn, deriveTotalTicketQuantity as Bt, ORDINARY_EVENT_PRESET_VALUES as C, publicEventPricingDisplay as Cn, unsafeAsSiteId as Cr, mapDrawingSchema as Ct, PUBLIC_CONTENT_FRESHNESS_SECONDS as D, resolveExactOrFreePriceDisplay as Dn, unsafeAsEventCategoryId as Dr, validateBookingPaymentOptionKinds as Dt, PUBLIC_AVAILABILITY_FRESHNESS_SECONDS as E, publicEventPricingType as En, parseRetiredCourseId as Er, BOOKING_COURSE_INSTALMENT_DEADLINES as Et, orderedLiveRunSessions as F, toCents as Fn, blockInteractionContextSchema as Fr, splitAmountWithRemainderInFirst as Ft, parseMailingListRuntimeContext as G, unsafeAsAppointmentResourceId as Gn, hasBookingClosed as Gt, parseMailingListBlockId as H, formatDurationUnitLabel as Hn, bookingCutOffHoursBetween as Ht, resolveWholeSeriesBookingPhase as I, toNonNegativeCents as In, businessCancellationRefusalCodes as It, parseMailingListGlobalForm as J, parseSiteTermsVersionId as Jn, formatDateTime as Jt, assessMailingListTargeting as K, unsafeAsStaffMemberId as Kn, formatDate as Kt, resolveWholeSeriesRunLifecycle as L, unsafeAsNonNegativeCents as Ln, scheduleBookingReasonCodes as Lt, CANCELLED_SESSION_STATUS as M, isNonNegativeWholeCents as Mn, unsafeAsPricingOptionId as Mr, getBookingInstalmentPlanIntervalCount as Mt, firstLiveRunSessionStartMs as N, parseNonNegativeCents as Nn, err as Nr, getBookingInstalmentProtectedDepositAmountCents as Nt, getPublicReadCachePolicy as O, resolvePricingOptionsPriceDisplay as On, unsafeAsEventInstanceId as Or, isLiveOrderInstalmentPlanStatus as Ot, nextLiveRunSessionStartMs as P, parsePositiveCents as Pn, ok as Pr, omitZeroAmountFutureRows as Pt, parseFooterCompositionV1 as Q, parseDatedOfferingCapacityHoldAuditRef as Qn, inferSiteDateLocale as Qt, createSecret as R, unsafeAsPositiveCents as Rn, resolveFlexibleBalanceDueAt as Rt, EVENT_PRESET_VALUES as S, publicEventPricingCurrency as Sn, parseUserId as Sr, trimmedStringOrNull as St, WHOLE_SERIES_EVENT_PRESET_VALUES as T, publicEventPricingStrategy as Tn, parseEventSeriesId as Tr, buildBookingUtcDateWindow as Tt, parseMailingListContentVersionId as U, unsafeAsBookingRequirementId as Un, formatBookingClosedTime as Ut, slugify as V, assertNever as Vn, MAX_BOOKING_CUT_OFF_HOURS as Vt, parseMailingListSignedSourceToken as W, unsafeAsDemoCapability as Wn, formatBookingCutOffHours as Wt, DEFAULT_MAILING_LIST_SUCCESS_MESSAGE as X, unsafeAsEntitlementId as Xn, formatTime as Xt, DEFAULT_MAILING_LIST_PRIVACY_NOTE as Y, parseMembershipId as Yn, formatDateTimeRange as Yt, parseMailingListProviderScope as Z, unsafeAsPassId as Zn, formatTimeRange as Zt, canonicalizeConfiguredBookingVerticalConfig as _, parsePageSurfaceSubject as _n, unsafeAsOrderPaymentPlanId as _r, parseLocationValue as _t, authoredValuesEqual as a, getBookingLocalDateKey as an, unsafeAsMediaAssetId as ar, formatOpeningHoursRows as at, resolveSiteVerticalBookingConfig as b, formatEventPricing as bn, parseApiKeyId as br, toLocationCoordinates as bt, STAFF_OPERATIONAL_CAPABILITIES as c, localScheduleTimePattern as cn, unsafeAsPositiveSeconds as cr, assertAllowedPublicUrl as ct, formatCreditProductUnits as d, parseUtcIsoDateTimeString as dn, unsafeAsStorageBucketName as dr, decideLocationSave as dt, toScheduledBookingDateTime as en, unsafeAsBookingSessionId as er, parseMailingListPlacementTargeting as et, planTurningOnCourses as f, toUtcIsoDateTimeString as fn, unsafeAsStoragePath as fr, stableJsonStringify as ft, areConfiguredBookingVerticalConfigsEqual as g, parseBookingTimeZone as gn, unsafeAsOrderFlexibleBalanceContractId as gr, normalizeLocationAddressText as gt, NAVIGATION_LOCATIONS as h, toBookingTimeZone as hn, unsafeAsCheckoutLineId as hr, locationValueSchema as ht, isRecord as i, formatLocalScheduleTime as in, unsafeAsFileChecksumSha256 as ir, richTextHasText as it, publicReadFreshnessSeconds as j, mapReadonlyNonEmptyArray as jn, unsafeAsOccurrenceId as jr, getBookingInstalmentDepositRefundability as jt, isPublicReadEndpoint as k, fromArray as kn, unsafeAsEventOfferingId as kr, addIntervalPreservingMonthAnchor as kt, creditProductUnitNoun as l, parseBookingLocalDate as ln, unsafeAsSafeDownloadFilename as lr, SENSITIVE_COLLECTION_CONFIRMATION_VERSION as lt, withBookingModulesForSelectionChange as m, resolveBookingTimeZoneId as mn, unsafeAsProductId as mr, EVENT_ADDRESS_AFTER_BOOKING_LABEL as mt, OFFLINE_PAYMENT_METHODS as n, compareLocalScheduleDates as nn, unsafeAsDeclaredMimeType as nr, planMailingListChoicePresentation as nt, applyClearable as o, getLocalScheduleDate as on, unsafeAsOriginalFilename as or, parsePublicContactDetails as ot, resolveEventCatalogue as p, resolveBookingBusinessTimeZone as pn, unsafeAsUploadSessionId as pr, locationMapLinks as pt, parseConfiguredMailingListProvider as q, parseCustomerId as qn, formatDateRange as qt, committedWriteProofSchema as r, formatLocalScheduleDate as rn, unsafeAsDetectedMimeType as rr, isCanonicalRichTextDoc as rt, clearableFrom as s, getLocalScheduleTime as sn, unsafeAsPositiveByteCount as sr, parseWeeklyOpeningHours as st, isEventOccurrenceRouteSegment as t, addLocalScheduleDays as tn, parseMediaAssetId as tr, DEFAULT_MAILING_LIST_TARGETING as tt, formatCreditProductPayment as u, parseLocalScheduleTime as un, unsafeAsSiteScopedStoragePath as ur, SENSITIVE_COLLECTION_MODES as ut, parseVerticalId as v, EVENT_PRESET_VOCABULARY as vn, parseEditorSessionGeneration as vr, projectPublicLocation as vt, SURFACE_EVENT_PRESET_VALUES as w, publicEventPricingOptions as wn, unsafeAsUserId as wr, selectCategoryView as wt, DEFAULT_EVENT_TYPE_PRESETS as x, isPublicEventPricingOptionDisplayable as xn, parseSiteId as xr, isPresent as xt, parseVerticalPresetId as y, formatBookingPriceDisplay as yn, unsafeAsSiteFontId as yr, publicLocationSchema as yt, exposeSecret as z, formatCurrencyAmount as zn, resolveFlexibleBalanceInitialPaymentCents as zt };
|