@final-commerce/common 2.9.0 → 2.9.2-preprod.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +224 -2
- package/dist/index.d.ts +224 -2
- package/dist/index.js +512 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +484 -0
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +310 -229
- package/dist/pos-types/index.d.ts +310 -229
- package/dist/pos-types/index.js +1 -0
- package/dist/pos-types/index.js.map +1 -1
- package/dist/pos-types/index.mjs +1 -0
- package/dist/pos-types/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -200,6 +200,7 @@ var OrderPlatform = /* @__PURE__ */ ((OrderPlatform2) => {
|
|
|
200
200
|
OrderPlatform2["POS"] = "in-store";
|
|
201
201
|
OrderPlatform2["WOO_COMMERCE"] = "woo-commerce";
|
|
202
202
|
OrderPlatform2["PUBLIC_API"] = "public-api";
|
|
203
|
+
OrderPlatform2["ONLINE_STORE"] = "online-store";
|
|
203
204
|
return OrderPlatform2;
|
|
204
205
|
})(OrderPlatform || {});
|
|
205
206
|
var CustomerPlatform = /* @__PURE__ */ ((CustomerPlatform2) => {
|
|
@@ -496,6 +497,50 @@ var ResourceAvailabilityState = /* @__PURE__ */ ((ResourceAvailabilityState2) =>
|
|
|
496
497
|
return ResourceAvailabilityState2;
|
|
497
498
|
})(ResourceAvailabilityState || {});
|
|
498
499
|
|
|
500
|
+
// enums/shipping.enum.ts
|
|
501
|
+
var ShippingZoneKind = /* @__PURE__ */ ((ShippingZoneKind2) => {
|
|
502
|
+
ShippingZoneKind2["COUNTRY"] = "country";
|
|
503
|
+
ShippingZoneKind2["PROVINCE"] = "province";
|
|
504
|
+
ShippingZoneKind2["CITY"] = "city";
|
|
505
|
+
ShippingZoneKind2["EVERYWHERE"] = "everywhere";
|
|
506
|
+
return ShippingZoneKind2;
|
|
507
|
+
})(ShippingZoneKind || {});
|
|
508
|
+
var ShippingOptionType = /* @__PURE__ */ ((ShippingOptionType2) => {
|
|
509
|
+
ShippingOptionType2["SHIP"] = "ship";
|
|
510
|
+
ShippingOptionType2["PICKUP"] = "pickup";
|
|
511
|
+
return ShippingOptionType2;
|
|
512
|
+
})(ShippingOptionType || {});
|
|
513
|
+
var ShippingRateType = /* @__PURE__ */ ((ShippingRateType2) => {
|
|
514
|
+
ShippingRateType2["FLAT"] = "flat";
|
|
515
|
+
return ShippingRateType2;
|
|
516
|
+
})(ShippingRateType || {});
|
|
517
|
+
var ShippingChannel = /* @__PURE__ */ ((ShippingChannel2) => {
|
|
518
|
+
ShippingChannel2["WEB"] = "web";
|
|
519
|
+
ShippingChannel2["POS"] = "pos";
|
|
520
|
+
return ShippingChannel2;
|
|
521
|
+
})(ShippingChannel || {});
|
|
522
|
+
var ShippingNoOptionReason = /* @__PURE__ */ ((ShippingNoOptionReason2) => {
|
|
523
|
+
ShippingNoOptionReason2["INCOMPLETE"] = "INCOMPLETE";
|
|
524
|
+
ShippingNoOptionReason2["ADDRESS_MISMATCH"] = "ADDRESS_MISMATCH";
|
|
525
|
+
ShippingNoOptionReason2["NO_COVERAGE"] = "NO_COVERAGE";
|
|
526
|
+
ShippingNoOptionReason2["BLOCKED"] = "BLOCKED";
|
|
527
|
+
ShippingNoOptionReason2["NO_OPTION"] = "NO_OPTION";
|
|
528
|
+
return ShippingNoOptionReason2;
|
|
529
|
+
})(ShippingNoOptionReason || {});
|
|
530
|
+
var ShippingZoneError = /* @__PURE__ */ ((ShippingZoneError2) => {
|
|
531
|
+
ShippingZoneError2["NO_PLACES"] = "NO_PLACES";
|
|
532
|
+
ShippingZoneError2["INVALID_PLACE"] = "INVALID_PLACE";
|
|
533
|
+
ShippingZoneError2["DUPLICATE_PLACE"] = "DUPLICATE_PLACE";
|
|
534
|
+
ShippingZoneError2["NO_WEBSITE_OPTION"] = "NO_WEBSITE_OPTION";
|
|
535
|
+
ShippingZoneError2["INVALID_PRICE"] = "INVALID_PRICE";
|
|
536
|
+
ShippingZoneError2["INVALID_DAYS"] = "INVALID_DAYS";
|
|
537
|
+
ShippingZoneError2["INVALID_TIERS"] = "INVALID_TIERS";
|
|
538
|
+
ShippingZoneError2["NO_CHANNEL"] = "NO_CHANNEL";
|
|
539
|
+
ShippingZoneError2["PICKUP_WITHOUT_STORE"] = "PICKUP_WITHOUT_STORE";
|
|
540
|
+
ShippingZoneError2["MISSING_NAME"] = "MISSING_NAME";
|
|
541
|
+
return ShippingZoneError2;
|
|
542
|
+
})(ShippingZoneError || {});
|
|
543
|
+
|
|
499
544
|
// enums/sales-line.enum.ts
|
|
500
545
|
var SalesLineAction = /* @__PURE__ */ ((SalesLineAction2) => {
|
|
501
546
|
SalesLineAction2["SALE"] = "sale";
|
|
@@ -1694,6 +1739,48 @@ function compositeReservationMismatches(order) {
|
|
|
1694
1739
|
});
|
|
1695
1740
|
}
|
|
1696
1741
|
|
|
1742
|
+
// utils/line-stock-moves.util.ts
|
|
1743
|
+
function lineStockMoves(item, quantity, reservations = []) {
|
|
1744
|
+
const sign = Math.sign(quantity);
|
|
1745
|
+
const pool = (stockVariantId) => stockVariantId ? { stockVariantId: stockVariantId.toString() } : {};
|
|
1746
|
+
if (!item.components?.length)
|
|
1747
|
+
return [
|
|
1748
|
+
{
|
|
1749
|
+
productId: item.productId.toString(),
|
|
1750
|
+
variantId: item.variantId.toString(),
|
|
1751
|
+
fields: {
|
|
1752
|
+
quantity,
|
|
1753
|
+
...item.stockQuantity != null ? { stockQuantity: sign * item.stockQuantity, unitId: item.unitId?.toString() } : {},
|
|
1754
|
+
...pool(item.stockVariantId)
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
];
|
|
1758
|
+
const booked = new Set(
|
|
1759
|
+
reservations.filter((reservation) => reservation.lineItemInternalId && reservation.lineItemInternalId === item.internalId).map((reservation) => reservation.componentIndex)
|
|
1760
|
+
);
|
|
1761
|
+
return item.components.flatMap((component, componentIndex) => {
|
|
1762
|
+
if (booked.has(componentIndex)) return [];
|
|
1763
|
+
if (component.unitId && component.stockQuantity == null)
|
|
1764
|
+
throw new Error(
|
|
1765
|
+
`Composite ${item.productId?.toString()} component ${component.variantId.toString()} is sold in ${component.unitId.toString()} but carries no stockQuantity`
|
|
1766
|
+
);
|
|
1767
|
+
return [
|
|
1768
|
+
{
|
|
1769
|
+
productId: component.productId.toString(),
|
|
1770
|
+
variantId: component.variantId.toString(),
|
|
1771
|
+
componentIndex,
|
|
1772
|
+
fields: {
|
|
1773
|
+
quantity: component.quantity * quantity,
|
|
1774
|
+
...component.stockQuantity != null ? { stockQuantity: component.stockQuantity * quantity, unitId: component.unitId?.toString() } : {},
|
|
1775
|
+
...pool(component.stockVariantId),
|
|
1776
|
+
...item.productId ? { compositeProductId: item.productId.toString() } : {},
|
|
1777
|
+
...item.name ? { compositeName: item.name } : {}
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
];
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1697
1784
|
// units/family-code.ts
|
|
1698
1785
|
var MAX_SLUG_LENGTH = 32;
|
|
1699
1786
|
var FALLBACK_SLUG = "family";
|
|
@@ -2842,6 +2929,39 @@ function isInCart(order) {
|
|
|
2842
2929
|
return (order.status ?? "").trim().toLowerCase() === "in-cart";
|
|
2843
2930
|
}
|
|
2844
2931
|
|
|
2932
|
+
// order-state-machine/assigned-users.ts
|
|
2933
|
+
function orderAssignments(order) {
|
|
2934
|
+
const value = order?.assignedUser;
|
|
2935
|
+
if (Array.isArray(value)) return value.filter((entry) => entry?.userId);
|
|
2936
|
+
return value?.userId ? [value] : [];
|
|
2937
|
+
}
|
|
2938
|
+
var sameLabel = (entry, label) => (entry.label ?? null) === (label ?? null);
|
|
2939
|
+
function currentAssignees(order, label) {
|
|
2940
|
+
return orderAssignments(order).filter(
|
|
2941
|
+
(entry) => !entry.unassignedAt && (label === void 0 || sameLabel(entry, label))
|
|
2942
|
+
);
|
|
2943
|
+
}
|
|
2944
|
+
function applyAssignment(order, change) {
|
|
2945
|
+
const { userId, at } = change;
|
|
2946
|
+
const label = change.label?.trim() || null;
|
|
2947
|
+
const entries = orderAssignments(order);
|
|
2948
|
+
if (userId === null) {
|
|
2949
|
+
const all = change.label === void 0;
|
|
2950
|
+
return entries.map(
|
|
2951
|
+
(entry) => !entry.unassignedAt && (all || sameLabel(entry, label)) ? { ...entry, unassignedAt: at } : entry
|
|
2952
|
+
);
|
|
2953
|
+
}
|
|
2954
|
+
if (entries.some((entry) => !entry.unassignedAt && entry.userId === userId && sameLabel(entry, label))) {
|
|
2955
|
+
return entries;
|
|
2956
|
+
}
|
|
2957
|
+
return [
|
|
2958
|
+
...entries.map(
|
|
2959
|
+
(entry) => !entry.unassignedAt && sameLabel(entry, label) ? { ...entry, unassignedAt: at } : entry
|
|
2960
|
+
),
|
|
2961
|
+
{ userId, assignedAt: at, ...label ? { label } : {} }
|
|
2962
|
+
];
|
|
2963
|
+
}
|
|
2964
|
+
|
|
2845
2965
|
// order-state-machine/order-status.ts
|
|
2846
2966
|
var STATUS_KEY = /^[a-z0-9][a-z0-9_-]*$/;
|
|
2847
2967
|
function validateOrderStatuses(statuses) {
|
|
@@ -3597,6 +3717,321 @@ function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }
|
|
|
3597
3717
|
}
|
|
3598
3718
|
var holdExpiresAt = (rule, now) => new Date(now.getTime() + (rule.window.holdMinutes ?? DEFAULT_HOLD_MINUTES) * 6e4);
|
|
3599
3719
|
|
|
3720
|
+
// shipping/fold-text.ts
|
|
3721
|
+
function foldText(value) {
|
|
3722
|
+
return value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/&/g, " and ").replace(/[^a-z0-9]+/g, " ").trim();
|
|
3723
|
+
}
|
|
3724
|
+
|
|
3725
|
+
// shipping/countries.ts
|
|
3726
|
+
var NOT_COUNTRIES = /* @__PURE__ */ new Set(["AC", "CP", "CQ", "DG", "EA", "EU", "EZ", "IC", "QO", "TA", "UN", "XA", "XB", "ZZ"]);
|
|
3727
|
+
var ALIASES = {
|
|
3728
|
+
canada: "CA",
|
|
3729
|
+
"united states": "US",
|
|
3730
|
+
usa: "US",
|
|
3731
|
+
"united states of america": "US",
|
|
3732
|
+
uk: "GB",
|
|
3733
|
+
"great britain": "GB",
|
|
3734
|
+
england: "GB",
|
|
3735
|
+
uae: "AE",
|
|
3736
|
+
can: "CA",
|
|
3737
|
+
mex: "MX",
|
|
3738
|
+
aus: "AU",
|
|
3739
|
+
gbr: "GB"
|
|
3740
|
+
};
|
|
3741
|
+
var NAME_LOCALES = ["en", "fr"];
|
|
3742
|
+
function regionNames(locale) {
|
|
3743
|
+
try {
|
|
3744
|
+
return new Intl.DisplayNames([locale], { type: "region", fallback: "none" });
|
|
3745
|
+
} catch {
|
|
3746
|
+
return null;
|
|
3747
|
+
}
|
|
3748
|
+
}
|
|
3749
|
+
function canonicalCode(code) {
|
|
3750
|
+
try {
|
|
3751
|
+
return new Intl.Locale(`und-${code}`).maximize().region ?? code;
|
|
3752
|
+
} catch {
|
|
3753
|
+
return code;
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
function allCodes() {
|
|
3757
|
+
const names = regionNames("en");
|
|
3758
|
+
if (!names) return [];
|
|
3759
|
+
const codes2 = [];
|
|
3760
|
+
for (let a = 65; a <= 90; a++) {
|
|
3761
|
+
for (let b = 65; b <= 90; b++) {
|
|
3762
|
+
const code = String.fromCharCode(a, b);
|
|
3763
|
+
if (!NOT_COUNTRIES.has(code) && names.of(code) && canonicalCode(code) === code) codes2.push(code);
|
|
3764
|
+
}
|
|
3765
|
+
}
|
|
3766
|
+
return codes2;
|
|
3767
|
+
}
|
|
3768
|
+
var lookup = null;
|
|
3769
|
+
var codes = null;
|
|
3770
|
+
function countryCodes() {
|
|
3771
|
+
codes ??= allCodes();
|
|
3772
|
+
return codes;
|
|
3773
|
+
}
|
|
3774
|
+
function countryLookup() {
|
|
3775
|
+
if (lookup) return lookup;
|
|
3776
|
+
lookup = new Map(Object.entries(ALIASES));
|
|
3777
|
+
for (const locale of NAME_LOCALES) {
|
|
3778
|
+
const names = regionNames(locale);
|
|
3779
|
+
if (!names) continue;
|
|
3780
|
+
for (const code of countryCodes()) {
|
|
3781
|
+
const name = names.of(code);
|
|
3782
|
+
if (name) lookup.set(foldText(name), code);
|
|
3783
|
+
}
|
|
3784
|
+
}
|
|
3785
|
+
return lookup;
|
|
3786
|
+
}
|
|
3787
|
+
function normalizeCountry(value) {
|
|
3788
|
+
const text = (value ?? "").trim();
|
|
3789
|
+
if (!text) return void 0;
|
|
3790
|
+
const upper = text.toUpperCase();
|
|
3791
|
+
if (upper.length === 2) {
|
|
3792
|
+
if (NOT_COUNTRIES.has(upper)) return void 0;
|
|
3793
|
+
if (countryCodes().length === 0) return /^[A-Z]{2}$/.test(upper) ? upper : void 0;
|
|
3794
|
+
const code = canonicalCode(upper);
|
|
3795
|
+
if (countryCodes().includes(code)) return code;
|
|
3796
|
+
}
|
|
3797
|
+
return countryLookup().get(foldText(text));
|
|
3798
|
+
}
|
|
3799
|
+
function listCountries(locale = "en") {
|
|
3800
|
+
const names = regionNames(locale) ?? regionNames("en");
|
|
3801
|
+
return countryCodes().map((code) => ({ code, name: names?.of(code) ?? code })).sort((a, b) => a.name.localeCompare(b.name, locale));
|
|
3802
|
+
}
|
|
3803
|
+
|
|
3804
|
+
// shipping/provinces.ts
|
|
3805
|
+
var CANADA_PROVINCES = [
|
|
3806
|
+
{ code: "AB", name: "Alberta", nameFr: "Alberta", postalLetters: ["T"] },
|
|
3807
|
+
{ code: "BC", name: "British Columbia", nameFr: "Colombie-Britannique", postalLetters: ["V"] },
|
|
3808
|
+
{ code: "MB", name: "Manitoba", nameFr: "Manitoba", postalLetters: ["R"] },
|
|
3809
|
+
{ code: "NB", name: "New Brunswick", nameFr: "Nouveau-Brunswick", postalLetters: ["E"] },
|
|
3810
|
+
{
|
|
3811
|
+
code: "NL",
|
|
3812
|
+
name: "Newfoundland and Labrador",
|
|
3813
|
+
nameFr: "Terre-Neuve-et-Labrador",
|
|
3814
|
+
postalLetters: ["A"],
|
|
3815
|
+
aliases: ["NF", "LB", "Newfoundland", "Labrador"]
|
|
3816
|
+
},
|
|
3817
|
+
{ code: "NS", name: "Nova Scotia", nameFr: "Nouvelle-\xC9cosse", postalLetters: ["B"] },
|
|
3818
|
+
{ code: "NT", name: "Northwest Territories", nameFr: "Territoires du Nord-Ouest", postalLetters: ["X"] },
|
|
3819
|
+
{ code: "NU", name: "Nunavut", nameFr: "Nunavut", postalLetters: ["X"] },
|
|
3820
|
+
{ code: "ON", name: "Ontario", nameFr: "Ontario", postalLetters: ["K", "L", "M", "N", "P"] },
|
|
3821
|
+
{
|
|
3822
|
+
code: "PE",
|
|
3823
|
+
name: "Prince Edward Island",
|
|
3824
|
+
nameFr: "\xCEle-du-Prince-\xC9douard",
|
|
3825
|
+
postalLetters: ["C"],
|
|
3826
|
+
aliases: ["PEI"]
|
|
3827
|
+
},
|
|
3828
|
+
{ code: "QC", name: "Quebec", nameFr: "Qu\xE9bec", postalLetters: ["G", "H", "J"], aliases: ["PQ"] },
|
|
3829
|
+
{ code: "SK", name: "Saskatchewan", nameFr: "Saskatchewan", postalLetters: ["S"] },
|
|
3830
|
+
{ code: "YT", name: "Yukon", nameFr: "Yukon", postalLetters: ["Y"], aliases: ["YK"] }
|
|
3831
|
+
];
|
|
3832
|
+
var PROVINCES_BY_COUNTRY = { CA: CANADA_PROVINCES };
|
|
3833
|
+
var lookups = /* @__PURE__ */ new Map();
|
|
3834
|
+
function provinceLookup(country) {
|
|
3835
|
+
const provinces = PROVINCES_BY_COUNTRY[country];
|
|
3836
|
+
if (!provinces) return void 0;
|
|
3837
|
+
let lookup2 = lookups.get(country);
|
|
3838
|
+
if (!lookup2) {
|
|
3839
|
+
lookup2 = /* @__PURE__ */ new Map();
|
|
3840
|
+
for (const p of provinces) {
|
|
3841
|
+
for (const label of [p.code, p.name, p.nameFr, ...p.aliases ?? []]) lookup2.set(foldText(label), p.code);
|
|
3842
|
+
}
|
|
3843
|
+
lookups.set(country, lookup2);
|
|
3844
|
+
}
|
|
3845
|
+
return lookup2;
|
|
3846
|
+
}
|
|
3847
|
+
function normalizeProvince(country, value) {
|
|
3848
|
+
if (!country || !value?.trim()) return void 0;
|
|
3849
|
+
return provinceLookup(country)?.get(foldText(value));
|
|
3850
|
+
}
|
|
3851
|
+
function listProvinces(country) {
|
|
3852
|
+
return PROVINCES_BY_COUNTRY[country] ?? [];
|
|
3853
|
+
}
|
|
3854
|
+
function provincesForPostCode(country, postCode) {
|
|
3855
|
+
const letter = postCode?.charAt(0);
|
|
3856
|
+
if (!country || !letter) return [];
|
|
3857
|
+
return listProvinces(country).filter((p) => p.postalLetters.includes(letter)).map((p) => p.code);
|
|
3858
|
+
}
|
|
3859
|
+
|
|
3860
|
+
// shipping/normalize.ts
|
|
3861
|
+
var EVERYWHERE_KEY = "*";
|
|
3862
|
+
function normalizeCityKey(value) {
|
|
3863
|
+
const words = foldText(value ?? "").split(" ").filter(Boolean).map((word) => word === "saint" ? "st" : word === "sainte" ? "ste" : word);
|
|
3864
|
+
return words.length ? words.join("") : void 0;
|
|
3865
|
+
}
|
|
3866
|
+
function normalizePostCode(value) {
|
|
3867
|
+
const compact = (value ?? "").replace(/[^0-9a-z]/gi, "").toUpperCase();
|
|
3868
|
+
return compact || void 0;
|
|
3869
|
+
}
|
|
3870
|
+
function normalizeAddress(address) {
|
|
3871
|
+
if (!address) return {};
|
|
3872
|
+
const country = normalizeCountry(address.country);
|
|
3873
|
+
const postCode = normalizePostCode(address.postCode ?? address.postalCode ?? address.zip);
|
|
3874
|
+
const fromPostCode = provincesForPostCode(country, postCode);
|
|
3875
|
+
const province = normalizeProvince(country, address.state ?? address.province) ?? (fromPostCode.length === 1 ? fromPostCode[0] : void 0);
|
|
3876
|
+
return { country, province, cityKey: normalizeCityKey(address.city), postCode };
|
|
3877
|
+
}
|
|
3878
|
+
function postCodeMatchesProvince(address) {
|
|
3879
|
+
const candidates = provincesForPostCode(address.country, address.postCode);
|
|
3880
|
+
if (!address.province || candidates.length === 0) return true;
|
|
3881
|
+
return candidates.includes(address.province);
|
|
3882
|
+
}
|
|
3883
|
+
function placeKey(place) {
|
|
3884
|
+
const country = normalizeCountry(place.country);
|
|
3885
|
+
if (!country) return void 0;
|
|
3886
|
+
if (!place.province) return country;
|
|
3887
|
+
const province = normalizeProvince(country, place.province);
|
|
3888
|
+
if (!province) return void 0;
|
|
3889
|
+
if (!place.city) return `${country}-${province}`;
|
|
3890
|
+
const city = normalizeCityKey(place.city);
|
|
3891
|
+
return city ? `${country}-${province}/${city}` : void 0;
|
|
3892
|
+
}
|
|
3893
|
+
function addressPlaceKeys(address) {
|
|
3894
|
+
const keys = [];
|
|
3895
|
+
if (address.country && address.province && address.cityKey) {
|
|
3896
|
+
keys.push(`${address.country}-${address.province}/${address.cityKey}`);
|
|
3897
|
+
}
|
|
3898
|
+
if (address.country && address.province) keys.push(`${address.country}-${address.province}`);
|
|
3899
|
+
if (address.country) keys.push(address.country);
|
|
3900
|
+
keys.push(EVERYWHERE_KEY);
|
|
3901
|
+
return keys;
|
|
3902
|
+
}
|
|
3903
|
+
|
|
3904
|
+
// shipping/resolve.ts
|
|
3905
|
+
function resolveShipping({ zones, address, itemsTotal, channel }) {
|
|
3906
|
+
const shipsToCountries = countriesShippedTo(zones);
|
|
3907
|
+
const none = (reason, zone2) => ({
|
|
3908
|
+
zoneId: zone2?.id ?? null,
|
|
3909
|
+
options: [],
|
|
3910
|
+
reason,
|
|
3911
|
+
message: zone2?.message?.trim() || null,
|
|
3912
|
+
shipsToCountries
|
|
3913
|
+
});
|
|
3914
|
+
const normalized = normalizeAddress(address);
|
|
3915
|
+
if (!normalized.country) return none("INCOMPLETE" /* INCOMPLETE */);
|
|
3916
|
+
if (!postCodeMatchesProvince(normalized)) return none("ADDRESS_MISMATCH" /* ADDRESS_MISMATCH */);
|
|
3917
|
+
const zone = findZone(zones, addressPlaceKeys(normalized));
|
|
3918
|
+
if (!zone) return none("NO_COVERAGE" /* NO_COVERAGE */);
|
|
3919
|
+
const offered = zone.options.filter((option) => isOffered(option, zone, channel));
|
|
3920
|
+
if (offered.length === 0) {
|
|
3921
|
+
return none(zone.ships ? "NO_OPTION" /* NO_OPTION */ : "BLOCKED" /* BLOCKED */, zone);
|
|
3922
|
+
}
|
|
3923
|
+
const quotes = offered.map((option) => quote(option, zone.id, itemsTotal));
|
|
3924
|
+
const ship = quotes.filter((q) => q.type === "ship" /* SHIP */).sort((a, b) => a.amount - b.amount);
|
|
3925
|
+
const pickup = quotes.filter((q) => q.type === "pickup" /* PICKUP */).sort((a, b) => a.amount - b.amount);
|
|
3926
|
+
return {
|
|
3927
|
+
zoneId: zone.id,
|
|
3928
|
+
options: [...ship, ...pickup],
|
|
3929
|
+
reason: null,
|
|
3930
|
+
message: zone.ships ? null : zone.message?.trim() || null,
|
|
3931
|
+
shipsToCountries
|
|
3932
|
+
};
|
|
3933
|
+
}
|
|
3934
|
+
function findZone(zones, keys) {
|
|
3935
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
3936
|
+
for (const zone of zones) {
|
|
3937
|
+
for (const key of zoneKeys(zone)) if (!byKey.has(key)) byKey.set(key, zone);
|
|
3938
|
+
}
|
|
3939
|
+
for (const key of keys) {
|
|
3940
|
+
const zone = byKey.get(key);
|
|
3941
|
+
if (zone) return zone;
|
|
3942
|
+
}
|
|
3943
|
+
return void 0;
|
|
3944
|
+
}
|
|
3945
|
+
function zoneKeys(zone) {
|
|
3946
|
+
if (zone.kind === "everywhere" /* EVERYWHERE */) return [EVERYWHERE_KEY];
|
|
3947
|
+
return zone.places.map(placeKey).filter((key) => Boolean(key));
|
|
3948
|
+
}
|
|
3949
|
+
function isOffered(option, zone, channel) {
|
|
3950
|
+
if (!option.channels.some((c) => c === channel)) return false;
|
|
3951
|
+
if (option.type === "pickup" /* PICKUP */) return channel !== "pos" /* POS */;
|
|
3952
|
+
return zone.ships;
|
|
3953
|
+
}
|
|
3954
|
+
function priceForTotal(option, itemsTotal) {
|
|
3955
|
+
const tiers = [...option.priceByTotal ?? []].sort((a, b) => a.from - b.from);
|
|
3956
|
+
let price = option.price;
|
|
3957
|
+
for (const tier of tiers) if (itemsTotal >= tier.from) price = tier.price;
|
|
3958
|
+
if (option.freeOver != null && itemsTotal >= option.freeOver) return 0;
|
|
3959
|
+
return price;
|
|
3960
|
+
}
|
|
3961
|
+
function quote(option, zoneId, itemsTotal) {
|
|
3962
|
+
const amount = priceForTotal(option, itemsTotal);
|
|
3963
|
+
const freeOver = option.freeOver ?? null;
|
|
3964
|
+
return {
|
|
3965
|
+
optionId: option.id,
|
|
3966
|
+
zoneId,
|
|
3967
|
+
type: option.type,
|
|
3968
|
+
name: option.name?.trim() || null,
|
|
3969
|
+
amount,
|
|
3970
|
+
amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
|
|
3971
|
+
minDays: option.minDays ?? null,
|
|
3972
|
+
maxDays: option.maxDays ?? null,
|
|
3973
|
+
outletId: option.outletId ?? null
|
|
3974
|
+
};
|
|
3975
|
+
}
|
|
3976
|
+
function countriesShippedTo(zones) {
|
|
3977
|
+
const countries = /* @__PURE__ */ new Set();
|
|
3978
|
+
for (const zone of zones) {
|
|
3979
|
+
if (!zone.ships) continue;
|
|
3980
|
+
for (const key of zoneKeys(zone)) if (key !== EVERYWHERE_KEY) countries.add(key.slice(0, 2));
|
|
3981
|
+
}
|
|
3982
|
+
return [...countries].sort();
|
|
3983
|
+
}
|
|
3984
|
+
|
|
3985
|
+
// shipping/validate.ts
|
|
3986
|
+
function validateShippingZone(zone) {
|
|
3987
|
+
const problems = [...placeProblems(zone)];
|
|
3988
|
+
for (const option of zone.options) problems.push(...optionProblems(option));
|
|
3989
|
+
const reachesWebsite = zone.options.some((option) => option.channels.includes("web" /* WEB */));
|
|
3990
|
+
if (zone.ships && !reachesWebsite) problems.push({ code: "NO_WEBSITE_OPTION" /* NO_WEBSITE_OPTION */ });
|
|
3991
|
+
return problems;
|
|
3992
|
+
}
|
|
3993
|
+
function placeProblems(zone) {
|
|
3994
|
+
if (zone.kind === "everywhere" /* EVERYWHERE */) {
|
|
3995
|
+
return zone.places.length ? [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }] : [];
|
|
3996
|
+
}
|
|
3997
|
+
if (zone.places.length === 0) return [{ code: "NO_PLACES" /* NO_PLACES */ }];
|
|
3998
|
+
if (!zone.places.every((place) => fitsKind(place, zone.kind))) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
|
|
3999
|
+
const keys = zone.places.map(placeKey);
|
|
4000
|
+
if (keys.some((key) => !key)) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
|
|
4001
|
+
if (new Set(keys).size !== keys.length) return [{ code: "DUPLICATE_PLACE" /* DUPLICATE_PLACE */ }];
|
|
4002
|
+
return [];
|
|
4003
|
+
}
|
|
4004
|
+
function fitsKind(place, kind) {
|
|
4005
|
+
const hasProvince = Boolean(place.province?.trim());
|
|
4006
|
+
const hasCity = Boolean(place.city?.trim());
|
|
4007
|
+
if (kind === "country" /* COUNTRY */) return !hasProvince && !hasCity;
|
|
4008
|
+
if (kind === "province" /* PROVINCE */) return hasProvince && !hasCity;
|
|
4009
|
+
if (kind === "city" /* CITY */) return hasProvince && hasCity;
|
|
4010
|
+
return false;
|
|
4011
|
+
}
|
|
4012
|
+
var isAmount = (value) => Number.isInteger(value) && value >= 0;
|
|
4013
|
+
var isDays = (value) => value == null || isAmount(value);
|
|
4014
|
+
function optionProblems(option) {
|
|
4015
|
+
const problems = [];
|
|
4016
|
+
const isPickup = option.type === "pickup" /* PICKUP */;
|
|
4017
|
+
if (!isAmount(option.price) || option.freeOver != null && !isAmount(option.freeOver)) {
|
|
4018
|
+
problems.push("INVALID_PRICE" /* INVALID_PRICE */);
|
|
4019
|
+
}
|
|
4020
|
+
if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
|
|
4021
|
+
if (!isDays(option.minDays) || !isDays(option.maxDays) || (option.minDays ?? 0) > (option.maxDays ?? Infinity)) {
|
|
4022
|
+
problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4023
|
+
}
|
|
4024
|
+
if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
|
|
4025
|
+
if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
|
|
4026
|
+
if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
|
|
4027
|
+
return problems.map((code) => ({ code, optionId: option.id }));
|
|
4028
|
+
}
|
|
4029
|
+
function tiersAreValid(option) {
|
|
4030
|
+
const tiers = option.priceByTotal ?? [];
|
|
4031
|
+
const froms = tiers.map((tier) => tier.from);
|
|
4032
|
+
return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
|
|
4033
|
+
}
|
|
4034
|
+
|
|
3600
4035
|
// constants/adyen.constants.ts
|
|
3601
4036
|
var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
|
|
3602
4037
|
function isAdyenRolloutCountry(alpha2) {
|
|
@@ -3646,6 +4081,27 @@ var BNPL_SKIP_REASON = {
|
|
|
3646
4081
|
NO_BUSINESS_LINE: "no_business_line"
|
|
3647
4082
|
};
|
|
3648
4083
|
|
|
4084
|
+
// pos-types/active/ProcessorType.ts
|
|
4085
|
+
var ProcessorType = /* @__PURE__ */ ((ProcessorType2) => {
|
|
4086
|
+
ProcessorType2["FINAL_PAY"] = "Terminal";
|
|
4087
|
+
ProcessorType2["TAP_TO_PAY"] = "TapToPay";
|
|
4088
|
+
ProcessorType2["MOTO"] = "Moto";
|
|
4089
|
+
ProcessorType2["CLOUD"] = "Cloud";
|
|
4090
|
+
ProcessorType2["BLUETOOTH"] = "Bluetooth";
|
|
4091
|
+
ProcessorType2["CASH"] = "Cash";
|
|
4092
|
+
ProcessorType2["CUSTOM_PAY"] = "CustomPay";
|
|
4093
|
+
ProcessorType2["VENDARA"] = "Vendara";
|
|
4094
|
+
ProcessorType2["REDEEM"] = "Redeem";
|
|
4095
|
+
ProcessorType2["INTEGRATION"] = "Integration";
|
|
4096
|
+
ProcessorType2["PAYMENT_LINK"] = "PaymentLink";
|
|
4097
|
+
ProcessorType2["ONLINE_PAYMENT"] = "OnlinePayment";
|
|
4098
|
+
ProcessorType2["EXTERNAL"] = "External";
|
|
4099
|
+
return ProcessorType2;
|
|
4100
|
+
})(ProcessorType || {});
|
|
4101
|
+
|
|
4102
|
+
// constants/payment-channel.constants.ts
|
|
4103
|
+
var PAYMENT_CHANNELS = ["inPerson", "online"];
|
|
4104
|
+
|
|
3649
4105
|
// constants/expense.constants.ts
|
|
3650
4106
|
var EXPENSE_PAYMENT_METHOD_PRESETS = [
|
|
3651
4107
|
"Cash",
|
|
@@ -3687,6 +4143,7 @@ export {
|
|
|
3687
4143
|
BookingResourceStatus,
|
|
3688
4144
|
BookingRulesError,
|
|
3689
4145
|
BookingType,
|
|
4146
|
+
CANADA_PROVINCES,
|
|
3690
4147
|
CONDITION_OPERATORS,
|
|
3691
4148
|
COUNTRY_CURRENCIES,
|
|
3692
4149
|
CURRENCY_CONFIG,
|
|
@@ -3703,6 +4160,7 @@ export {
|
|
|
3703
4160
|
DualWriteStrategy,
|
|
3704
4161
|
EUFixedRates,
|
|
3705
4162
|
EUROPE,
|
|
4163
|
+
EVERYWHERE_KEY,
|
|
3706
4164
|
EXPENSE_DEFAULT_CATEGORIES,
|
|
3707
4165
|
EXPENSE_NAME_MAX_LENGTH,
|
|
3708
4166
|
EXPENSE_PAYMENT_METHOD_PRESETS,
|
|
@@ -3728,6 +4186,7 @@ export {
|
|
|
3728
4186
|
OtherFixedRates,
|
|
3729
4187
|
OwnerType,
|
|
3730
4188
|
PATH_MODES,
|
|
4189
|
+
PAYMENT_CHANNELS,
|
|
3731
4190
|
PAYMENT_STATES,
|
|
3732
4191
|
POS_VALID_INITIAL_STATES,
|
|
3733
4192
|
PaymentMethod,
|
|
@@ -3737,6 +4196,7 @@ export {
|
|
|
3737
4196
|
PricingLevel,
|
|
3738
4197
|
PricingPlanEnum,
|
|
3739
4198
|
PricingRegionEnum,
|
|
4199
|
+
ProcessorType,
|
|
3740
4200
|
ProductSalesChartStep,
|
|
3741
4201
|
ProductSalesReportCompare,
|
|
3742
4202
|
ProductStatus,
|
|
@@ -3759,6 +4219,12 @@ export {
|
|
|
3759
4219
|
SYSTEM_UNIT_IDS,
|
|
3760
4220
|
SalesLineAction,
|
|
3761
4221
|
SalesLineSourceArray,
|
|
4222
|
+
ShippingChannel,
|
|
4223
|
+
ShippingNoOptionReason,
|
|
4224
|
+
ShippingOptionType,
|
|
4225
|
+
ShippingRateType,
|
|
4226
|
+
ShippingZoneError,
|
|
4227
|
+
ShippingZoneKind,
|
|
3762
4228
|
StationStatus,
|
|
3763
4229
|
StripeCurrencyCode,
|
|
3764
4230
|
StripeStatus,
|
|
@@ -3766,6 +4232,7 @@ export {
|
|
|
3766
4232
|
TopMetericsSort,
|
|
3767
4233
|
UserTypes,
|
|
3768
4234
|
addAmounts,
|
|
4235
|
+
addressPlaceKeys,
|
|
3769
4236
|
adyenLegalEntityRequiresStateOrProvince,
|
|
3770
4237
|
adyenRequiresJobTitle,
|
|
3771
4238
|
adyenStoreRequiresStateOrProvince,
|
|
@@ -3773,6 +4240,7 @@ export {
|
|
|
3773
4240
|
adyenTaxNumberFormat,
|
|
3774
4241
|
amountToString,
|
|
3775
4242
|
ancestorChain,
|
|
4243
|
+
applyAssignment,
|
|
3776
4244
|
assertUnitSane,
|
|
3777
4245
|
availableIn,
|
|
3778
4246
|
baseFor,
|
|
@@ -3798,6 +4266,7 @@ export {
|
|
|
3798
4266
|
convertFixedFeeToLocalCurrency,
|
|
3799
4267
|
createAmount,
|
|
3800
4268
|
crossAxisRuleApplies,
|
|
4269
|
+
currentAssignees,
|
|
3801
4270
|
deriveDisplayState,
|
|
3802
4271
|
deriveFamilyCode,
|
|
3803
4272
|
deriveUnitId,
|
|
@@ -3844,25 +4313,39 @@ export {
|
|
|
3844
4313
|
isSystemFamilyCode,
|
|
3845
4314
|
isValidQuantity,
|
|
3846
4315
|
isWhole,
|
|
4316
|
+
lineStockMoves,
|
|
4317
|
+
listCountries,
|
|
4318
|
+
listProvinces,
|
|
3847
4319
|
mapToLegacyStatus,
|
|
3848
4320
|
maxPrecisionFor,
|
|
3849
4321
|
mergeFragment,
|
|
3850
4322
|
modifiersSellable,
|
|
3851
4323
|
multiplyAmount,
|
|
4324
|
+
normalizeAddress,
|
|
4325
|
+
normalizeCityKey,
|
|
4326
|
+
normalizeCountry,
|
|
3852
4327
|
normalizeMongoIdString,
|
|
4328
|
+
normalizePostCode,
|
|
4329
|
+
normalizeProvince,
|
|
3853
4330
|
occupancyIn,
|
|
4331
|
+
orderAssignments,
|
|
3854
4332
|
parseAmountToMinorUnits,
|
|
3855
4333
|
parseCurrencyCode,
|
|
3856
4334
|
parseStripeCurrencyCode,
|
|
4335
|
+
placeKey,
|
|
3857
4336
|
planWindow,
|
|
3858
4337
|
poolDemand,
|
|
3859
4338
|
poolOf,
|
|
3860
4339
|
poolShortfall,
|
|
3861
4340
|
poolStockAt,
|
|
4341
|
+
postCodeMatchesProvince,
|
|
3862
4342
|
presentAt,
|
|
4343
|
+
priceForTotal,
|
|
4344
|
+
provincesForPostCode,
|
|
3863
4345
|
removeFragment,
|
|
3864
4346
|
resolveFamily,
|
|
3865
4347
|
resolveModifiersForProduct,
|
|
4348
|
+
resolveShipping,
|
|
3866
4349
|
resolveTemplate,
|
|
3867
4350
|
resolveUnit,
|
|
3868
4351
|
roundToPrecision,
|
|
@@ -3879,6 +4362,7 @@ export {
|
|
|
3879
4362
|
validateConfig,
|
|
3880
4363
|
validateFragmentCompatibility,
|
|
3881
4364
|
validateOrderStatuses,
|
|
4365
|
+
validateShippingZone,
|
|
3882
4366
|
violatesFinancialInvariant,
|
|
3883
4367
|
windowEndsAt,
|
|
3884
4368
|
withinPresence
|