@final-commerce/common 2.9.2-preprod.2 → 2.10.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/index.d.mts +20 -208
- package/dist/index.d.ts +20 -208
- package/dist/index.js +20 -488
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -462
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +230 -309
- package/dist/pos-types/index.d.ts +230 -309
- package/dist/pos-types/index.js +0 -1
- package/dist/pos-types/index.js.map +1 -1
- package/dist/pos-types/index.mjs +0 -1
- package/dist/pos-types/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -200,7 +200,6 @@ 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";
|
|
204
203
|
return OrderPlatform2;
|
|
205
204
|
})(OrderPlatform || {});
|
|
206
205
|
var CustomerPlatform = /* @__PURE__ */ ((CustomerPlatform2) => {
|
|
@@ -497,50 +496,6 @@ var ResourceAvailabilityState = /* @__PURE__ */ ((ResourceAvailabilityState2) =>
|
|
|
497
496
|
return ResourceAvailabilityState2;
|
|
498
497
|
})(ResourceAvailabilityState || {});
|
|
499
498
|
|
|
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
|
-
|
|
544
499
|
// enums/sales-line.enum.ts
|
|
545
500
|
var SalesLineAction = /* @__PURE__ */ ((SalesLineAction2) => {
|
|
546
501
|
SalesLineAction2["SALE"] = "sale";
|
|
@@ -1739,48 +1694,6 @@ function compositeReservationMismatches(order) {
|
|
|
1739
1694
|
});
|
|
1740
1695
|
}
|
|
1741
1696
|
|
|
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
|
-
|
|
1784
1697
|
// units/family-code.ts
|
|
1785
1698
|
var MAX_SLUG_LENGTH = 32;
|
|
1786
1699
|
var FALLBACK_SLUG = "family";
|
|
@@ -3717,334 +3630,6 @@ function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }
|
|
|
3717
3630
|
}
|
|
3718
3631
|
var holdExpiresAt = (rule, now) => new Date(now.getTime() + (rule.window.holdMinutes ?? DEFAULT_HOLD_MINUTES) * 6e4);
|
|
3719
3632
|
|
|
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
|
-
var SHIPPING_COUNTRIES = ["CA"];
|
|
3804
|
-
function shipsToCountry(code) {
|
|
3805
|
-
return !!code && SHIPPING_COUNTRIES.includes(code);
|
|
3806
|
-
}
|
|
3807
|
-
function listShippingCountries(locale = "en") {
|
|
3808
|
-
const names = regionNames(locale) ?? regionNames("en");
|
|
3809
|
-
return SHIPPING_COUNTRIES.map((code) => ({ code, name: names?.of(code) ?? code })).sort(
|
|
3810
|
-
(a, b) => a.name.localeCompare(b.name, locale)
|
|
3811
|
-
);
|
|
3812
|
-
}
|
|
3813
|
-
|
|
3814
|
-
// shipping/provinces.ts
|
|
3815
|
-
var CANADA_PROVINCES = [
|
|
3816
|
-
{ code: "AB", name: "Alberta", nameFr: "Alberta", postalLetters: ["T"] },
|
|
3817
|
-
{ code: "BC", name: "British Columbia", nameFr: "Colombie-Britannique", postalLetters: ["V"] },
|
|
3818
|
-
{ code: "MB", name: "Manitoba", nameFr: "Manitoba", postalLetters: ["R"] },
|
|
3819
|
-
{ code: "NB", name: "New Brunswick", nameFr: "Nouveau-Brunswick", postalLetters: ["E"] },
|
|
3820
|
-
{
|
|
3821
|
-
code: "NL",
|
|
3822
|
-
name: "Newfoundland and Labrador",
|
|
3823
|
-
nameFr: "Terre-Neuve-et-Labrador",
|
|
3824
|
-
postalLetters: ["A"],
|
|
3825
|
-
aliases: ["NF", "LB", "Newfoundland", "Labrador"]
|
|
3826
|
-
},
|
|
3827
|
-
{ code: "NS", name: "Nova Scotia", nameFr: "Nouvelle-\xC9cosse", postalLetters: ["B"] },
|
|
3828
|
-
{ code: "NT", name: "Northwest Territories", nameFr: "Territoires du Nord-Ouest", postalLetters: ["X"] },
|
|
3829
|
-
{ code: "NU", name: "Nunavut", nameFr: "Nunavut", postalLetters: ["X"] },
|
|
3830
|
-
{ code: "ON", name: "Ontario", nameFr: "Ontario", postalLetters: ["K", "L", "M", "N", "P"] },
|
|
3831
|
-
{
|
|
3832
|
-
code: "PE",
|
|
3833
|
-
name: "Prince Edward Island",
|
|
3834
|
-
nameFr: "\xCEle-du-Prince-\xC9douard",
|
|
3835
|
-
postalLetters: ["C"],
|
|
3836
|
-
aliases: ["PEI"]
|
|
3837
|
-
},
|
|
3838
|
-
{ code: "QC", name: "Quebec", nameFr: "Qu\xE9bec", postalLetters: ["G", "H", "J"], aliases: ["PQ"] },
|
|
3839
|
-
{ code: "SK", name: "Saskatchewan", nameFr: "Saskatchewan", postalLetters: ["S"] },
|
|
3840
|
-
{ code: "YT", name: "Yukon", nameFr: "Yukon", postalLetters: ["Y"], aliases: ["YK"] }
|
|
3841
|
-
];
|
|
3842
|
-
var PROVINCES_BY_COUNTRY = { CA: CANADA_PROVINCES };
|
|
3843
|
-
var lookups = /* @__PURE__ */ new Map();
|
|
3844
|
-
function provinceLookup(country) {
|
|
3845
|
-
const provinces = PROVINCES_BY_COUNTRY[country];
|
|
3846
|
-
if (!provinces) return void 0;
|
|
3847
|
-
let lookup2 = lookups.get(country);
|
|
3848
|
-
if (!lookup2) {
|
|
3849
|
-
lookup2 = /* @__PURE__ */ new Map();
|
|
3850
|
-
for (const p of provinces) {
|
|
3851
|
-
for (const label of [p.code, p.name, p.nameFr, ...p.aliases ?? []]) lookup2.set(foldText(label), p.code);
|
|
3852
|
-
}
|
|
3853
|
-
lookups.set(country, lookup2);
|
|
3854
|
-
}
|
|
3855
|
-
return lookup2;
|
|
3856
|
-
}
|
|
3857
|
-
function normalizeProvince(country, value) {
|
|
3858
|
-
if (!country || !value?.trim()) return void 0;
|
|
3859
|
-
return provinceLookup(country)?.get(foldText(value));
|
|
3860
|
-
}
|
|
3861
|
-
function listProvinces(country) {
|
|
3862
|
-
return PROVINCES_BY_COUNTRY[country] ?? [];
|
|
3863
|
-
}
|
|
3864
|
-
function provincesForPostCode(country, postCode) {
|
|
3865
|
-
const letter = postCode?.charAt(0);
|
|
3866
|
-
if (!country || !letter) return [];
|
|
3867
|
-
return listProvinces(country).filter((p) => p.postalLetters.includes(letter)).map((p) => p.code);
|
|
3868
|
-
}
|
|
3869
|
-
|
|
3870
|
-
// shipping/normalize.ts
|
|
3871
|
-
var EVERYWHERE_KEY = "*";
|
|
3872
|
-
function normalizeCityKey(value) {
|
|
3873
|
-
const words = foldText(value ?? "").split(" ").filter(Boolean).map((word) => word === "saint" ? "st" : word === "sainte" ? "ste" : word);
|
|
3874
|
-
return words.length ? words.join("") : void 0;
|
|
3875
|
-
}
|
|
3876
|
-
function normalizePostCode(value) {
|
|
3877
|
-
const compact = (value ?? "").replace(/[^0-9a-z]/gi, "").toUpperCase();
|
|
3878
|
-
return compact || void 0;
|
|
3879
|
-
}
|
|
3880
|
-
function normalizeAddress(address) {
|
|
3881
|
-
if (!address) return {};
|
|
3882
|
-
const country = normalizeCountry(address.country);
|
|
3883
|
-
const postCode = normalizePostCode(address.postCode ?? address.postalCode ?? address.zip);
|
|
3884
|
-
const fromPostCode = provincesForPostCode(country, postCode);
|
|
3885
|
-
const province = normalizeProvince(country, address.state ?? address.province) ?? (fromPostCode.length === 1 ? fromPostCode[0] : void 0);
|
|
3886
|
-
return { country, province, cityKey: normalizeCityKey(address.city), postCode };
|
|
3887
|
-
}
|
|
3888
|
-
function postCodeMatchesProvince(address) {
|
|
3889
|
-
const candidates = provincesForPostCode(address.country, address.postCode);
|
|
3890
|
-
if (!address.province || candidates.length === 0) return true;
|
|
3891
|
-
return candidates.includes(address.province);
|
|
3892
|
-
}
|
|
3893
|
-
function placeKey(place) {
|
|
3894
|
-
const country = normalizeCountry(place.country);
|
|
3895
|
-
if (!country) return void 0;
|
|
3896
|
-
if (!place.province) return country;
|
|
3897
|
-
const province = normalizeProvince(country, place.province);
|
|
3898
|
-
if (!province) return void 0;
|
|
3899
|
-
if (!place.city) return `${country}-${province}`;
|
|
3900
|
-
const city = normalizeCityKey(place.city);
|
|
3901
|
-
return city ? `${country}-${province}/${city}` : void 0;
|
|
3902
|
-
}
|
|
3903
|
-
function addressPlaceKeys(address) {
|
|
3904
|
-
const keys = [];
|
|
3905
|
-
if (address.country && address.province && address.cityKey) {
|
|
3906
|
-
keys.push(`${address.country}-${address.province}/${address.cityKey}`);
|
|
3907
|
-
}
|
|
3908
|
-
if (address.country && address.province) keys.push(`${address.country}-${address.province}`);
|
|
3909
|
-
if (address.country) keys.push(address.country);
|
|
3910
|
-
keys.push(EVERYWHERE_KEY);
|
|
3911
|
-
return keys;
|
|
3912
|
-
}
|
|
3913
|
-
|
|
3914
|
-
// shipping/resolve.ts
|
|
3915
|
-
function resolveShipping({ zones, address, itemsTotal, channel }) {
|
|
3916
|
-
const shipsToCountries = countriesShippedTo(zones);
|
|
3917
|
-
const none = (reason, zone2) => ({
|
|
3918
|
-
zoneId: zone2?.id ?? null,
|
|
3919
|
-
options: [],
|
|
3920
|
-
reason,
|
|
3921
|
-
message: zone2?.message?.trim() || null,
|
|
3922
|
-
shipsToCountries
|
|
3923
|
-
});
|
|
3924
|
-
const normalized = normalizeAddress(address);
|
|
3925
|
-
if (!normalized.country) return none("INCOMPLETE" /* INCOMPLETE */);
|
|
3926
|
-
if (!shipsToCountry(normalized.country)) return none("NO_COVERAGE" /* NO_COVERAGE */);
|
|
3927
|
-
if (!postCodeMatchesProvince(normalized)) return none("ADDRESS_MISMATCH" /* ADDRESS_MISMATCH */);
|
|
3928
|
-
const zone = findZone(zones, addressPlaceKeys(normalized));
|
|
3929
|
-
if (!zone) return none("NO_COVERAGE" /* NO_COVERAGE */);
|
|
3930
|
-
const offered = zone.options.filter((option) => isOffered(option, zone, channel));
|
|
3931
|
-
if (offered.length === 0) {
|
|
3932
|
-
return none(zone.ships ? "NO_OPTION" /* NO_OPTION */ : "BLOCKED" /* BLOCKED */, zone);
|
|
3933
|
-
}
|
|
3934
|
-
const quotes = offered.map((option) => quote(option, zone.id, itemsTotal));
|
|
3935
|
-
const ship = quotes.filter((q) => q.type === "ship" /* SHIP */).sort((a, b) => a.amount - b.amount);
|
|
3936
|
-
const pickup = quotes.filter((q) => q.type === "pickup" /* PICKUP */).sort((a, b) => a.amount - b.amount);
|
|
3937
|
-
return {
|
|
3938
|
-
zoneId: zone.id,
|
|
3939
|
-
options: [...ship, ...pickup],
|
|
3940
|
-
reason: null,
|
|
3941
|
-
message: zone.ships ? null : zone.message?.trim() || null,
|
|
3942
|
-
shipsToCountries
|
|
3943
|
-
};
|
|
3944
|
-
}
|
|
3945
|
-
function findZone(zones, keys) {
|
|
3946
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
3947
|
-
for (const zone of zones) {
|
|
3948
|
-
for (const key of zoneKeys(zone)) if (!byKey.has(key)) byKey.set(key, zone);
|
|
3949
|
-
}
|
|
3950
|
-
for (const key of keys) {
|
|
3951
|
-
const zone = byKey.get(key);
|
|
3952
|
-
if (zone) return zone;
|
|
3953
|
-
}
|
|
3954
|
-
return void 0;
|
|
3955
|
-
}
|
|
3956
|
-
function zoneKeys(zone) {
|
|
3957
|
-
if (zone.kind === "everywhere" /* EVERYWHERE */) return [EVERYWHERE_KEY];
|
|
3958
|
-
return zone.places.map(placeKey).filter((key) => Boolean(key));
|
|
3959
|
-
}
|
|
3960
|
-
function isOffered(option, zone, channel) {
|
|
3961
|
-
if (!option.channels.some((c) => c === channel)) return false;
|
|
3962
|
-
if (option.type === "pickup" /* PICKUP */) return channel !== "pos" /* POS */;
|
|
3963
|
-
return zone.ships;
|
|
3964
|
-
}
|
|
3965
|
-
function priceForTotal(option, itemsTotal) {
|
|
3966
|
-
const tiers = [...option.priceByTotal ?? []].sort((a, b) => a.from - b.from);
|
|
3967
|
-
let price = option.price;
|
|
3968
|
-
for (const tier of tiers) if (itemsTotal >= tier.from) price = tier.price;
|
|
3969
|
-
if (option.freeOver != null && itemsTotal >= option.freeOver) return 0;
|
|
3970
|
-
return price;
|
|
3971
|
-
}
|
|
3972
|
-
function quote(option, zoneId, itemsTotal) {
|
|
3973
|
-
const amount = priceForTotal(option, itemsTotal);
|
|
3974
|
-
const freeOver = option.freeOver ?? null;
|
|
3975
|
-
return {
|
|
3976
|
-
optionId: option.id,
|
|
3977
|
-
zoneId,
|
|
3978
|
-
type: option.type,
|
|
3979
|
-
name: option.name?.trim() || null,
|
|
3980
|
-
amount,
|
|
3981
|
-
amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
|
|
3982
|
-
minDays: option.minDays ?? null,
|
|
3983
|
-
maxDays: option.maxDays ?? null,
|
|
3984
|
-
outletId: option.outletId ?? null
|
|
3985
|
-
};
|
|
3986
|
-
}
|
|
3987
|
-
function countriesShippedTo(zones) {
|
|
3988
|
-
const countries = /* @__PURE__ */ new Set();
|
|
3989
|
-
for (const zone of zones) {
|
|
3990
|
-
if (!zone.ships) continue;
|
|
3991
|
-
for (const key of zoneKeys(zone)) {
|
|
3992
|
-
if (key !== EVERYWHERE_KEY && shipsToCountry(key.slice(0, 2))) countries.add(key.slice(0, 2));
|
|
3993
|
-
}
|
|
3994
|
-
}
|
|
3995
|
-
return [...countries].sort();
|
|
3996
|
-
}
|
|
3997
|
-
|
|
3998
|
-
// shipping/validate.ts
|
|
3999
|
-
function validateShippingZone(zone) {
|
|
4000
|
-
const problems = [...placeProblems(zone)];
|
|
4001
|
-
for (const option of zone.options) problems.push(...optionProblems(option));
|
|
4002
|
-
const reachesWebsite = zone.options.some((option) => option.channels.includes("web" /* WEB */));
|
|
4003
|
-
if (zone.ships && !reachesWebsite) problems.push({ code: "NO_WEBSITE_OPTION" /* NO_WEBSITE_OPTION */ });
|
|
4004
|
-
return problems;
|
|
4005
|
-
}
|
|
4006
|
-
function placeProblems(zone) {
|
|
4007
|
-
if (zone.kind === "everywhere" /* EVERYWHERE */) {
|
|
4008
|
-
return zone.places.length ? [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }] : [];
|
|
4009
|
-
}
|
|
4010
|
-
if (zone.places.length === 0) return [{ code: "NO_PLACES" /* NO_PLACES */ }];
|
|
4011
|
-
if (!zone.places.every((place) => fitsKind(place, zone.kind))) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
|
|
4012
|
-
const keys = zone.places.map(placeKey);
|
|
4013
|
-
if (keys.some((key) => !key || !shipsToCountry(key.slice(0, 2)))) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
|
|
4014
|
-
if (new Set(keys).size !== keys.length) return [{ code: "DUPLICATE_PLACE" /* DUPLICATE_PLACE */ }];
|
|
4015
|
-
return [];
|
|
4016
|
-
}
|
|
4017
|
-
function fitsKind(place, kind) {
|
|
4018
|
-
const hasProvince = Boolean(place.province?.trim());
|
|
4019
|
-
const hasCity = Boolean(place.city?.trim());
|
|
4020
|
-
if (kind === "country" /* COUNTRY */) return !hasProvince && !hasCity;
|
|
4021
|
-
if (kind === "province" /* PROVINCE */) return hasProvince && !hasCity;
|
|
4022
|
-
if (kind === "city" /* CITY */) return hasProvince && hasCity;
|
|
4023
|
-
return false;
|
|
4024
|
-
}
|
|
4025
|
-
var isAmount = (value) => Number.isInteger(value) && value >= 0;
|
|
4026
|
-
var isDays = (value) => value == null || isAmount(value);
|
|
4027
|
-
function optionProblems(option) {
|
|
4028
|
-
const problems = [];
|
|
4029
|
-
const isPickup = option.type === "pickup" /* PICKUP */;
|
|
4030
|
-
if (!isAmount(option.price) || option.freeOver != null && !isAmount(option.freeOver)) {
|
|
4031
|
-
problems.push("INVALID_PRICE" /* INVALID_PRICE */);
|
|
4032
|
-
}
|
|
4033
|
-
if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
|
|
4034
|
-
if (!isDays(option.minDays) || !isDays(option.maxDays) || (option.minDays ?? 0) > (option.maxDays ?? Infinity)) {
|
|
4035
|
-
problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4036
|
-
}
|
|
4037
|
-
if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
|
|
4038
|
-
if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
|
|
4039
|
-
if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
|
|
4040
|
-
return problems.map((code) => ({ code, optionId: option.id }));
|
|
4041
|
-
}
|
|
4042
|
-
function tiersAreValid(option) {
|
|
4043
|
-
const tiers = option.priceByTotal ?? [];
|
|
4044
|
-
const froms = tiers.map((tier) => tier.from);
|
|
4045
|
-
return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
|
|
4046
|
-
}
|
|
4047
|
-
|
|
4048
3633
|
// constants/adyen.constants.ts
|
|
4049
3634
|
var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
|
|
4050
3635
|
function isAdyenRolloutCountry(alpha2) {
|
|
@@ -4094,27 +3679,6 @@ var BNPL_SKIP_REASON = {
|
|
|
4094
3679
|
NO_BUSINESS_LINE: "no_business_line"
|
|
4095
3680
|
};
|
|
4096
3681
|
|
|
4097
|
-
// pos-types/active/ProcessorType.ts
|
|
4098
|
-
var ProcessorType = /* @__PURE__ */ ((ProcessorType2) => {
|
|
4099
|
-
ProcessorType2["FINAL_PAY"] = "Terminal";
|
|
4100
|
-
ProcessorType2["TAP_TO_PAY"] = "TapToPay";
|
|
4101
|
-
ProcessorType2["MOTO"] = "Moto";
|
|
4102
|
-
ProcessorType2["CLOUD"] = "Cloud";
|
|
4103
|
-
ProcessorType2["BLUETOOTH"] = "Bluetooth";
|
|
4104
|
-
ProcessorType2["CASH"] = "Cash";
|
|
4105
|
-
ProcessorType2["CUSTOM_PAY"] = "CustomPay";
|
|
4106
|
-
ProcessorType2["VENDARA"] = "Vendara";
|
|
4107
|
-
ProcessorType2["REDEEM"] = "Redeem";
|
|
4108
|
-
ProcessorType2["INTEGRATION"] = "Integration";
|
|
4109
|
-
ProcessorType2["PAYMENT_LINK"] = "PaymentLink";
|
|
4110
|
-
ProcessorType2["ONLINE_PAYMENT"] = "OnlinePayment";
|
|
4111
|
-
ProcessorType2["EXTERNAL"] = "External";
|
|
4112
|
-
return ProcessorType2;
|
|
4113
|
-
})(ProcessorType || {});
|
|
4114
|
-
|
|
4115
|
-
// constants/payment-channel.constants.ts
|
|
4116
|
-
var PAYMENT_CHANNELS = ["inPerson", "online"];
|
|
4117
|
-
|
|
4118
3682
|
// constants/expense.constants.ts
|
|
4119
3683
|
var EXPENSE_PAYMENT_METHOD_PRESETS = [
|
|
4120
3684
|
"Cash",
|
|
@@ -4138,6 +3702,26 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4138
3702
|
{ key: "vehicle-fuel", name: "Vehicle & fuel" },
|
|
4139
3703
|
{ key: "other", name: "Other" }
|
|
4140
3704
|
];
|
|
3705
|
+
|
|
3706
|
+
// pos-types/active/ProcessorType.ts
|
|
3707
|
+
var ProcessorType = /* @__PURE__ */ ((ProcessorType2) => {
|
|
3708
|
+
ProcessorType2["FINAL_PAY"] = "Terminal";
|
|
3709
|
+
ProcessorType2["TAP_TO_PAY"] = "TapToPay";
|
|
3710
|
+
ProcessorType2["MOTO"] = "Moto";
|
|
3711
|
+
ProcessorType2["CLOUD"] = "Cloud";
|
|
3712
|
+
ProcessorType2["BLUETOOTH"] = "Bluetooth";
|
|
3713
|
+
ProcessorType2["CASH"] = "Cash";
|
|
3714
|
+
ProcessorType2["CUSTOM_PAY"] = "CustomPay";
|
|
3715
|
+
ProcessorType2["VENDARA"] = "Vendara";
|
|
3716
|
+
ProcessorType2["REDEEM"] = "Redeem";
|
|
3717
|
+
ProcessorType2["INTEGRATION"] = "Integration";
|
|
3718
|
+
ProcessorType2["PAYMENT_LINK"] = "PaymentLink";
|
|
3719
|
+
ProcessorType2["EXTERNAL"] = "External";
|
|
3720
|
+
return ProcessorType2;
|
|
3721
|
+
})(ProcessorType || {});
|
|
3722
|
+
|
|
3723
|
+
// constants/payment-channel.constants.ts
|
|
3724
|
+
var PAYMENT_CHANNELS = ["inPerson", "online"];
|
|
4141
3725
|
export {
|
|
4142
3726
|
ADYEN_JOB_TITLE_ASSOCIATION_TYPES,
|
|
4143
3727
|
ADYEN_LEGAL_ENTITY_STATE_PROVINCE_COUNTRIES,
|
|
@@ -4156,7 +3740,6 @@ export {
|
|
|
4156
3740
|
BookingResourceStatus,
|
|
4157
3741
|
BookingRulesError,
|
|
4158
3742
|
BookingType,
|
|
4159
|
-
CANADA_PROVINCES,
|
|
4160
3743
|
CONDITION_OPERATORS,
|
|
4161
3744
|
COUNTRY_CURRENCIES,
|
|
4162
3745
|
CURRENCY_CONFIG,
|
|
@@ -4173,7 +3756,6 @@ export {
|
|
|
4173
3756
|
DualWriteStrategy,
|
|
4174
3757
|
EUFixedRates,
|
|
4175
3758
|
EUROPE,
|
|
4176
|
-
EVERYWHERE_KEY,
|
|
4177
3759
|
EXPENSE_DEFAULT_CATEGORIES,
|
|
4178
3760
|
EXPENSE_NAME_MAX_LENGTH,
|
|
4179
3761
|
EXPENSE_PAYMENT_METHOD_PRESETS,
|
|
@@ -4224,7 +3806,6 @@ export {
|
|
|
4224
3806
|
ResidualPaymentMethod,
|
|
4225
3807
|
ResidualStatus,
|
|
4226
3808
|
ResourceAvailabilityState,
|
|
4227
|
-
SHIPPING_COUNTRIES,
|
|
4228
3809
|
STATE_SCHEMA,
|
|
4229
3810
|
STRIPE_SUPPORTED_COUNTRIES,
|
|
4230
3811
|
SYSTEM_FAMILIES,
|
|
@@ -4233,12 +3814,6 @@ export {
|
|
|
4233
3814
|
SYSTEM_UNIT_IDS,
|
|
4234
3815
|
SalesLineAction,
|
|
4235
3816
|
SalesLineSourceArray,
|
|
4236
|
-
ShippingChannel,
|
|
4237
|
-
ShippingNoOptionReason,
|
|
4238
|
-
ShippingOptionType,
|
|
4239
|
-
ShippingRateType,
|
|
4240
|
-
ShippingZoneError,
|
|
4241
|
-
ShippingZoneKind,
|
|
4242
3817
|
StationStatus,
|
|
4243
3818
|
StripeCurrencyCode,
|
|
4244
3819
|
StripeStatus,
|
|
@@ -4246,7 +3821,6 @@ export {
|
|
|
4246
3821
|
TopMetericsSort,
|
|
4247
3822
|
UserTypes,
|
|
4248
3823
|
addAmounts,
|
|
4249
|
-
addressPlaceKeys,
|
|
4250
3824
|
adyenLegalEntityRequiresStateOrProvince,
|
|
4251
3825
|
adyenRequiresJobTitle,
|
|
4252
3826
|
adyenStoreRequiresStateOrProvince,
|
|
@@ -4327,46 +3901,31 @@ export {
|
|
|
4327
3901
|
isSystemFamilyCode,
|
|
4328
3902
|
isValidQuantity,
|
|
4329
3903
|
isWhole,
|
|
4330
|
-
lineStockMoves,
|
|
4331
|
-
listCountries,
|
|
4332
|
-
listProvinces,
|
|
4333
|
-
listShippingCountries,
|
|
4334
3904
|
mapToLegacyStatus,
|
|
4335
3905
|
maxPrecisionFor,
|
|
4336
3906
|
mergeFragment,
|
|
4337
3907
|
modifiersSellable,
|
|
4338
3908
|
multiplyAmount,
|
|
4339
|
-
normalizeAddress,
|
|
4340
|
-
normalizeCityKey,
|
|
4341
|
-
normalizeCountry,
|
|
4342
3909
|
normalizeMongoIdString,
|
|
4343
|
-
normalizePostCode,
|
|
4344
|
-
normalizeProvince,
|
|
4345
3910
|
occupancyIn,
|
|
4346
3911
|
orderAssignments,
|
|
4347
3912
|
parseAmountToMinorUnits,
|
|
4348
3913
|
parseCurrencyCode,
|
|
4349
3914
|
parseStripeCurrencyCode,
|
|
4350
|
-
placeKey,
|
|
4351
3915
|
planWindow,
|
|
4352
3916
|
poolDemand,
|
|
4353
3917
|
poolOf,
|
|
4354
3918
|
poolShortfall,
|
|
4355
3919
|
poolStockAt,
|
|
4356
|
-
postCodeMatchesProvince,
|
|
4357
3920
|
presentAt,
|
|
4358
|
-
priceForTotal,
|
|
4359
|
-
provincesForPostCode,
|
|
4360
3921
|
removeFragment,
|
|
4361
3922
|
resolveFamily,
|
|
4362
3923
|
resolveModifiersForProduct,
|
|
4363
|
-
resolveShipping,
|
|
4364
3924
|
resolveTemplate,
|
|
4365
3925
|
resolveUnit,
|
|
4366
3926
|
roundToPrecision,
|
|
4367
3927
|
sameFamily,
|
|
4368
3928
|
setOrderState,
|
|
4369
|
-
shipsToCountry,
|
|
4370
3929
|
shopDayKey,
|
|
4371
3930
|
shopDayRange,
|
|
4372
3931
|
signReportForDisplay,
|
|
@@ -4378,7 +3937,6 @@ export {
|
|
|
4378
3937
|
validateConfig,
|
|
4379
3938
|
validateFragmentCompatibility,
|
|
4380
3939
|
validateOrderStatuses,
|
|
4381
|
-
validateShippingZone,
|
|
4382
3940
|
violatesFinancialInvariant,
|
|
4383
3941
|
windowEndsAt,
|
|
4384
3942
|
withinPresence
|