@final-commerce/common 2.8.0 → 2.8.1-online.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 +165 -2
- package/dist/index.d.ts +165 -2
- package/dist/index.js +429 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +405 -0
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +305 -226
- package/dist/pos-types/index.d.ts +305 -226
- 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) => {
|
|
@@ -486,6 +487,50 @@ var ResourceAvailabilityState = /* @__PURE__ */ ((ResourceAvailabilityState2) =>
|
|
|
486
487
|
return ResourceAvailabilityState2;
|
|
487
488
|
})(ResourceAvailabilityState || {});
|
|
488
489
|
|
|
490
|
+
// enums/shipping.enum.ts
|
|
491
|
+
var ShippingZoneKind = /* @__PURE__ */ ((ShippingZoneKind2) => {
|
|
492
|
+
ShippingZoneKind2["COUNTRY"] = "country";
|
|
493
|
+
ShippingZoneKind2["PROVINCE"] = "province";
|
|
494
|
+
ShippingZoneKind2["CITY"] = "city";
|
|
495
|
+
ShippingZoneKind2["EVERYWHERE"] = "everywhere";
|
|
496
|
+
return ShippingZoneKind2;
|
|
497
|
+
})(ShippingZoneKind || {});
|
|
498
|
+
var ShippingOptionType = /* @__PURE__ */ ((ShippingOptionType2) => {
|
|
499
|
+
ShippingOptionType2["SHIP"] = "ship";
|
|
500
|
+
ShippingOptionType2["PICKUP"] = "pickup";
|
|
501
|
+
return ShippingOptionType2;
|
|
502
|
+
})(ShippingOptionType || {});
|
|
503
|
+
var ShippingRateType = /* @__PURE__ */ ((ShippingRateType2) => {
|
|
504
|
+
ShippingRateType2["FLAT"] = "flat";
|
|
505
|
+
return ShippingRateType2;
|
|
506
|
+
})(ShippingRateType || {});
|
|
507
|
+
var ShippingChannel = /* @__PURE__ */ ((ShippingChannel2) => {
|
|
508
|
+
ShippingChannel2["WEB"] = "web";
|
|
509
|
+
ShippingChannel2["POS"] = "pos";
|
|
510
|
+
return ShippingChannel2;
|
|
511
|
+
})(ShippingChannel || {});
|
|
512
|
+
var ShippingNoOptionReason = /* @__PURE__ */ ((ShippingNoOptionReason2) => {
|
|
513
|
+
ShippingNoOptionReason2["INCOMPLETE"] = "INCOMPLETE";
|
|
514
|
+
ShippingNoOptionReason2["ADDRESS_MISMATCH"] = "ADDRESS_MISMATCH";
|
|
515
|
+
ShippingNoOptionReason2["NO_COVERAGE"] = "NO_COVERAGE";
|
|
516
|
+
ShippingNoOptionReason2["BLOCKED"] = "BLOCKED";
|
|
517
|
+
ShippingNoOptionReason2["NO_OPTION"] = "NO_OPTION";
|
|
518
|
+
return ShippingNoOptionReason2;
|
|
519
|
+
})(ShippingNoOptionReason || {});
|
|
520
|
+
var ShippingZoneError = /* @__PURE__ */ ((ShippingZoneError2) => {
|
|
521
|
+
ShippingZoneError2["NO_PLACES"] = "NO_PLACES";
|
|
522
|
+
ShippingZoneError2["INVALID_PLACE"] = "INVALID_PLACE";
|
|
523
|
+
ShippingZoneError2["DUPLICATE_PLACE"] = "DUPLICATE_PLACE";
|
|
524
|
+
ShippingZoneError2["NO_WEBSITE_OPTION"] = "NO_WEBSITE_OPTION";
|
|
525
|
+
ShippingZoneError2["INVALID_PRICE"] = "INVALID_PRICE";
|
|
526
|
+
ShippingZoneError2["INVALID_DAYS"] = "INVALID_DAYS";
|
|
527
|
+
ShippingZoneError2["INVALID_TIERS"] = "INVALID_TIERS";
|
|
528
|
+
ShippingZoneError2["NO_CHANNEL"] = "NO_CHANNEL";
|
|
529
|
+
ShippingZoneError2["PICKUP_WITHOUT_STORE"] = "PICKUP_WITHOUT_STORE";
|
|
530
|
+
ShippingZoneError2["MISSING_NAME"] = "MISSING_NAME";
|
|
531
|
+
return ShippingZoneError2;
|
|
532
|
+
})(ShippingZoneError || {});
|
|
533
|
+
|
|
489
534
|
// utils/currency.util.ts
|
|
490
535
|
var CURRENCY_CONFIG = {
|
|
491
536
|
// Major currencies with 2 decimal places
|
|
@@ -3564,6 +3609,321 @@ function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }
|
|
|
3564
3609
|
}
|
|
3565
3610
|
var holdExpiresAt = (rule, now) => new Date(now.getTime() + (rule.window.holdMinutes ?? DEFAULT_HOLD_MINUTES) * 6e4);
|
|
3566
3611
|
|
|
3612
|
+
// shipping/fold-text.ts
|
|
3613
|
+
function foldText(value) {
|
|
3614
|
+
return value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/&/g, " and ").replace(/[^a-z0-9]+/g, " ").trim();
|
|
3615
|
+
}
|
|
3616
|
+
|
|
3617
|
+
// shipping/countries.ts
|
|
3618
|
+
var NOT_COUNTRIES = /* @__PURE__ */ new Set(["AC", "CP", "CQ", "DG", "EA", "EU", "EZ", "IC", "QO", "TA", "UN", "XA", "XB", "ZZ"]);
|
|
3619
|
+
var ALIASES = {
|
|
3620
|
+
canada: "CA",
|
|
3621
|
+
"united states": "US",
|
|
3622
|
+
usa: "US",
|
|
3623
|
+
"united states of america": "US",
|
|
3624
|
+
uk: "GB",
|
|
3625
|
+
"great britain": "GB",
|
|
3626
|
+
england: "GB",
|
|
3627
|
+
uae: "AE",
|
|
3628
|
+
can: "CA",
|
|
3629
|
+
mex: "MX",
|
|
3630
|
+
aus: "AU",
|
|
3631
|
+
gbr: "GB"
|
|
3632
|
+
};
|
|
3633
|
+
var NAME_LOCALES = ["en", "fr"];
|
|
3634
|
+
function regionNames(locale) {
|
|
3635
|
+
try {
|
|
3636
|
+
return new Intl.DisplayNames([locale], { type: "region", fallback: "none" });
|
|
3637
|
+
} catch {
|
|
3638
|
+
return null;
|
|
3639
|
+
}
|
|
3640
|
+
}
|
|
3641
|
+
function canonicalCode(code) {
|
|
3642
|
+
try {
|
|
3643
|
+
return new Intl.Locale(`und-${code}`).maximize().region ?? code;
|
|
3644
|
+
} catch {
|
|
3645
|
+
return code;
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
function allCodes() {
|
|
3649
|
+
const names = regionNames("en");
|
|
3650
|
+
if (!names) return [];
|
|
3651
|
+
const codes2 = [];
|
|
3652
|
+
for (let a = 65; a <= 90; a++) {
|
|
3653
|
+
for (let b = 65; b <= 90; b++) {
|
|
3654
|
+
const code = String.fromCharCode(a, b);
|
|
3655
|
+
if (!NOT_COUNTRIES.has(code) && names.of(code) && canonicalCode(code) === code) codes2.push(code);
|
|
3656
|
+
}
|
|
3657
|
+
}
|
|
3658
|
+
return codes2;
|
|
3659
|
+
}
|
|
3660
|
+
var lookup = null;
|
|
3661
|
+
var codes = null;
|
|
3662
|
+
function countryCodes() {
|
|
3663
|
+
codes ??= allCodes();
|
|
3664
|
+
return codes;
|
|
3665
|
+
}
|
|
3666
|
+
function countryLookup() {
|
|
3667
|
+
if (lookup) return lookup;
|
|
3668
|
+
lookup = new Map(Object.entries(ALIASES));
|
|
3669
|
+
for (const locale of NAME_LOCALES) {
|
|
3670
|
+
const names = regionNames(locale);
|
|
3671
|
+
if (!names) continue;
|
|
3672
|
+
for (const code of countryCodes()) {
|
|
3673
|
+
const name = names.of(code);
|
|
3674
|
+
if (name) lookup.set(foldText(name), code);
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
return lookup;
|
|
3678
|
+
}
|
|
3679
|
+
function normalizeCountry(value) {
|
|
3680
|
+
const text = (value ?? "").trim();
|
|
3681
|
+
if (!text) return void 0;
|
|
3682
|
+
const upper = text.toUpperCase();
|
|
3683
|
+
if (upper.length === 2) {
|
|
3684
|
+
if (NOT_COUNTRIES.has(upper)) return void 0;
|
|
3685
|
+
if (countryCodes().length === 0) return /^[A-Z]{2}$/.test(upper) ? upper : void 0;
|
|
3686
|
+
const code = canonicalCode(upper);
|
|
3687
|
+
if (countryCodes().includes(code)) return code;
|
|
3688
|
+
}
|
|
3689
|
+
return countryLookup().get(foldText(text));
|
|
3690
|
+
}
|
|
3691
|
+
function listCountries(locale = "en") {
|
|
3692
|
+
const names = regionNames(locale) ?? regionNames("en");
|
|
3693
|
+
return countryCodes().map((code) => ({ code, name: names?.of(code) ?? code })).sort((a, b) => a.name.localeCompare(b.name, locale));
|
|
3694
|
+
}
|
|
3695
|
+
|
|
3696
|
+
// shipping/provinces.ts
|
|
3697
|
+
var CANADA_PROVINCES = [
|
|
3698
|
+
{ code: "AB", name: "Alberta", nameFr: "Alberta", postalLetters: ["T"] },
|
|
3699
|
+
{ code: "BC", name: "British Columbia", nameFr: "Colombie-Britannique", postalLetters: ["V"] },
|
|
3700
|
+
{ code: "MB", name: "Manitoba", nameFr: "Manitoba", postalLetters: ["R"] },
|
|
3701
|
+
{ code: "NB", name: "New Brunswick", nameFr: "Nouveau-Brunswick", postalLetters: ["E"] },
|
|
3702
|
+
{
|
|
3703
|
+
code: "NL",
|
|
3704
|
+
name: "Newfoundland and Labrador",
|
|
3705
|
+
nameFr: "Terre-Neuve-et-Labrador",
|
|
3706
|
+
postalLetters: ["A"],
|
|
3707
|
+
aliases: ["NF", "LB", "Newfoundland", "Labrador"]
|
|
3708
|
+
},
|
|
3709
|
+
{ code: "NS", name: "Nova Scotia", nameFr: "Nouvelle-\xC9cosse", postalLetters: ["B"] },
|
|
3710
|
+
{ code: "NT", name: "Northwest Territories", nameFr: "Territoires du Nord-Ouest", postalLetters: ["X"] },
|
|
3711
|
+
{ code: "NU", name: "Nunavut", nameFr: "Nunavut", postalLetters: ["X"] },
|
|
3712
|
+
{ code: "ON", name: "Ontario", nameFr: "Ontario", postalLetters: ["K", "L", "M", "N", "P"] },
|
|
3713
|
+
{
|
|
3714
|
+
code: "PE",
|
|
3715
|
+
name: "Prince Edward Island",
|
|
3716
|
+
nameFr: "\xCEle-du-Prince-\xC9douard",
|
|
3717
|
+
postalLetters: ["C"],
|
|
3718
|
+
aliases: ["PEI"]
|
|
3719
|
+
},
|
|
3720
|
+
{ code: "QC", name: "Quebec", nameFr: "Qu\xE9bec", postalLetters: ["G", "H", "J"], aliases: ["PQ"] },
|
|
3721
|
+
{ code: "SK", name: "Saskatchewan", nameFr: "Saskatchewan", postalLetters: ["S"] },
|
|
3722
|
+
{ code: "YT", name: "Yukon", nameFr: "Yukon", postalLetters: ["Y"], aliases: ["YK"] }
|
|
3723
|
+
];
|
|
3724
|
+
var PROVINCES_BY_COUNTRY = { CA: CANADA_PROVINCES };
|
|
3725
|
+
var lookups = /* @__PURE__ */ new Map();
|
|
3726
|
+
function provinceLookup(country) {
|
|
3727
|
+
const provinces = PROVINCES_BY_COUNTRY[country];
|
|
3728
|
+
if (!provinces) return void 0;
|
|
3729
|
+
let lookup2 = lookups.get(country);
|
|
3730
|
+
if (!lookup2) {
|
|
3731
|
+
lookup2 = /* @__PURE__ */ new Map();
|
|
3732
|
+
for (const p of provinces) {
|
|
3733
|
+
for (const label of [p.code, p.name, p.nameFr, ...p.aliases ?? []]) lookup2.set(foldText(label), p.code);
|
|
3734
|
+
}
|
|
3735
|
+
lookups.set(country, lookup2);
|
|
3736
|
+
}
|
|
3737
|
+
return lookup2;
|
|
3738
|
+
}
|
|
3739
|
+
function normalizeProvince(country, value) {
|
|
3740
|
+
if (!country || !value?.trim()) return void 0;
|
|
3741
|
+
return provinceLookup(country)?.get(foldText(value));
|
|
3742
|
+
}
|
|
3743
|
+
function listProvinces(country) {
|
|
3744
|
+
return PROVINCES_BY_COUNTRY[country] ?? [];
|
|
3745
|
+
}
|
|
3746
|
+
function provincesForPostCode(country, postCode) {
|
|
3747
|
+
const letter = postCode?.charAt(0);
|
|
3748
|
+
if (!country || !letter) return [];
|
|
3749
|
+
return listProvinces(country).filter((p) => p.postalLetters.includes(letter)).map((p) => p.code);
|
|
3750
|
+
}
|
|
3751
|
+
|
|
3752
|
+
// shipping/normalize.ts
|
|
3753
|
+
var EVERYWHERE_KEY = "*";
|
|
3754
|
+
function normalizeCityKey(value) {
|
|
3755
|
+
const words = foldText(value ?? "").split(" ").filter(Boolean).map((word) => word === "saint" ? "st" : word === "sainte" ? "ste" : word);
|
|
3756
|
+
return words.length ? words.join("") : void 0;
|
|
3757
|
+
}
|
|
3758
|
+
function normalizePostCode(value) {
|
|
3759
|
+
const compact = (value ?? "").replace(/[^0-9a-z]/gi, "").toUpperCase();
|
|
3760
|
+
return compact || void 0;
|
|
3761
|
+
}
|
|
3762
|
+
function normalizeAddress(address) {
|
|
3763
|
+
if (!address) return {};
|
|
3764
|
+
const country = normalizeCountry(address.country);
|
|
3765
|
+
const postCode = normalizePostCode(address.postCode ?? address.postalCode ?? address.zip);
|
|
3766
|
+
const fromPostCode = provincesForPostCode(country, postCode);
|
|
3767
|
+
const province = normalizeProvince(country, address.state ?? address.province) ?? (fromPostCode.length === 1 ? fromPostCode[0] : void 0);
|
|
3768
|
+
return { country, province, cityKey: normalizeCityKey(address.city), postCode };
|
|
3769
|
+
}
|
|
3770
|
+
function postCodeMatchesProvince(address) {
|
|
3771
|
+
const candidates = provincesForPostCode(address.country, address.postCode);
|
|
3772
|
+
if (!address.province || candidates.length === 0) return true;
|
|
3773
|
+
return candidates.includes(address.province);
|
|
3774
|
+
}
|
|
3775
|
+
function placeKey(place) {
|
|
3776
|
+
const country = normalizeCountry(place.country);
|
|
3777
|
+
if (!country) return void 0;
|
|
3778
|
+
if (!place.province) return country;
|
|
3779
|
+
const province = normalizeProvince(country, place.province);
|
|
3780
|
+
if (!province) return void 0;
|
|
3781
|
+
if (!place.city) return `${country}-${province}`;
|
|
3782
|
+
const city = normalizeCityKey(place.city);
|
|
3783
|
+
return city ? `${country}-${province}/${city}` : void 0;
|
|
3784
|
+
}
|
|
3785
|
+
function addressPlaceKeys(address) {
|
|
3786
|
+
const keys = [];
|
|
3787
|
+
if (address.country && address.province && address.cityKey) {
|
|
3788
|
+
keys.push(`${address.country}-${address.province}/${address.cityKey}`);
|
|
3789
|
+
}
|
|
3790
|
+
if (address.country && address.province) keys.push(`${address.country}-${address.province}`);
|
|
3791
|
+
if (address.country) keys.push(address.country);
|
|
3792
|
+
keys.push(EVERYWHERE_KEY);
|
|
3793
|
+
return keys;
|
|
3794
|
+
}
|
|
3795
|
+
|
|
3796
|
+
// shipping/resolve.ts
|
|
3797
|
+
function resolveShipping({ zones, address, itemsTotal, channel }) {
|
|
3798
|
+
const shipsToCountries = countriesShippedTo(zones);
|
|
3799
|
+
const none = (reason, zone2) => ({
|
|
3800
|
+
zoneId: zone2?.id ?? null,
|
|
3801
|
+
options: [],
|
|
3802
|
+
reason,
|
|
3803
|
+
message: zone2?.message?.trim() || null,
|
|
3804
|
+
shipsToCountries
|
|
3805
|
+
});
|
|
3806
|
+
const normalized = normalizeAddress(address);
|
|
3807
|
+
if (!normalized.country) return none("INCOMPLETE" /* INCOMPLETE */);
|
|
3808
|
+
if (!postCodeMatchesProvince(normalized)) return none("ADDRESS_MISMATCH" /* ADDRESS_MISMATCH */);
|
|
3809
|
+
const zone = findZone(zones, addressPlaceKeys(normalized));
|
|
3810
|
+
if (!zone) return none("NO_COVERAGE" /* NO_COVERAGE */);
|
|
3811
|
+
const offered = zone.options.filter((option) => isOffered(option, zone, channel));
|
|
3812
|
+
if (offered.length === 0) {
|
|
3813
|
+
return none(zone.ships ? "NO_OPTION" /* NO_OPTION */ : "BLOCKED" /* BLOCKED */, zone);
|
|
3814
|
+
}
|
|
3815
|
+
const quotes = offered.map((option) => quote(option, zone.id, itemsTotal));
|
|
3816
|
+
const ship = quotes.filter((q) => q.type === "ship" /* SHIP */).sort((a, b) => a.amount - b.amount);
|
|
3817
|
+
const pickup = quotes.filter((q) => q.type === "pickup" /* PICKUP */).sort((a, b) => a.amount - b.amount);
|
|
3818
|
+
return {
|
|
3819
|
+
zoneId: zone.id,
|
|
3820
|
+
options: [...ship, ...pickup],
|
|
3821
|
+
reason: null,
|
|
3822
|
+
message: zone.ships ? null : zone.message?.trim() || null,
|
|
3823
|
+
shipsToCountries
|
|
3824
|
+
};
|
|
3825
|
+
}
|
|
3826
|
+
function findZone(zones, keys) {
|
|
3827
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
3828
|
+
for (const zone of zones) {
|
|
3829
|
+
for (const key of zoneKeys(zone)) if (!byKey.has(key)) byKey.set(key, zone);
|
|
3830
|
+
}
|
|
3831
|
+
for (const key of keys) {
|
|
3832
|
+
const zone = byKey.get(key);
|
|
3833
|
+
if (zone) return zone;
|
|
3834
|
+
}
|
|
3835
|
+
return void 0;
|
|
3836
|
+
}
|
|
3837
|
+
function zoneKeys(zone) {
|
|
3838
|
+
if (zone.kind === "everywhere" /* EVERYWHERE */) return [EVERYWHERE_KEY];
|
|
3839
|
+
return zone.places.map(placeKey).filter((key) => Boolean(key));
|
|
3840
|
+
}
|
|
3841
|
+
function isOffered(option, zone, channel) {
|
|
3842
|
+
if (!option.channels.some((c) => c === channel)) return false;
|
|
3843
|
+
if (option.type === "pickup" /* PICKUP */) return channel !== "pos" /* POS */;
|
|
3844
|
+
return zone.ships;
|
|
3845
|
+
}
|
|
3846
|
+
function priceForTotal(option, itemsTotal) {
|
|
3847
|
+
const tiers = [...option.priceByTotal ?? []].sort((a, b) => a.from - b.from);
|
|
3848
|
+
let price = option.price;
|
|
3849
|
+
for (const tier of tiers) if (itemsTotal >= tier.from) price = tier.price;
|
|
3850
|
+
if (option.freeOver != null && itemsTotal >= option.freeOver) return 0;
|
|
3851
|
+
return price;
|
|
3852
|
+
}
|
|
3853
|
+
function quote(option, zoneId, itemsTotal) {
|
|
3854
|
+
const amount = priceForTotal(option, itemsTotal);
|
|
3855
|
+
const freeOver = option.freeOver ?? null;
|
|
3856
|
+
return {
|
|
3857
|
+
optionId: option.id,
|
|
3858
|
+
zoneId,
|
|
3859
|
+
type: option.type,
|
|
3860
|
+
name: option.name?.trim() || null,
|
|
3861
|
+
amount,
|
|
3862
|
+
amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
|
|
3863
|
+
minDays: option.minDays ?? null,
|
|
3864
|
+
maxDays: option.maxDays ?? null,
|
|
3865
|
+
outletId: option.outletId ?? null
|
|
3866
|
+
};
|
|
3867
|
+
}
|
|
3868
|
+
function countriesShippedTo(zones) {
|
|
3869
|
+
const countries = /* @__PURE__ */ new Set();
|
|
3870
|
+
for (const zone of zones) {
|
|
3871
|
+
if (!zone.ships) continue;
|
|
3872
|
+
for (const key of zoneKeys(zone)) if (key !== EVERYWHERE_KEY) countries.add(key.slice(0, 2));
|
|
3873
|
+
}
|
|
3874
|
+
return [...countries].sort();
|
|
3875
|
+
}
|
|
3876
|
+
|
|
3877
|
+
// shipping/validate.ts
|
|
3878
|
+
function validateShippingZone(zone) {
|
|
3879
|
+
const problems = [...placeProblems(zone)];
|
|
3880
|
+
for (const option of zone.options) problems.push(...optionProblems(option));
|
|
3881
|
+
const reachesWebsite = zone.options.some((option) => option.channels.includes("web" /* WEB */));
|
|
3882
|
+
if (zone.ships && !reachesWebsite) problems.push({ code: "NO_WEBSITE_OPTION" /* NO_WEBSITE_OPTION */ });
|
|
3883
|
+
return problems;
|
|
3884
|
+
}
|
|
3885
|
+
function placeProblems(zone) {
|
|
3886
|
+
if (zone.kind === "everywhere" /* EVERYWHERE */) {
|
|
3887
|
+
return zone.places.length ? [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }] : [];
|
|
3888
|
+
}
|
|
3889
|
+
if (zone.places.length === 0) return [{ code: "NO_PLACES" /* NO_PLACES */ }];
|
|
3890
|
+
if (!zone.places.every((place) => fitsKind(place, zone.kind))) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
|
|
3891
|
+
const keys = zone.places.map(placeKey);
|
|
3892
|
+
if (keys.some((key) => !key)) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
|
|
3893
|
+
if (new Set(keys).size !== keys.length) return [{ code: "DUPLICATE_PLACE" /* DUPLICATE_PLACE */ }];
|
|
3894
|
+
return [];
|
|
3895
|
+
}
|
|
3896
|
+
function fitsKind(place, kind) {
|
|
3897
|
+
const hasProvince = Boolean(place.province?.trim());
|
|
3898
|
+
const hasCity = Boolean(place.city?.trim());
|
|
3899
|
+
if (kind === "country" /* COUNTRY */) return !hasProvince && !hasCity;
|
|
3900
|
+
if (kind === "province" /* PROVINCE */) return hasProvince && !hasCity;
|
|
3901
|
+
if (kind === "city" /* CITY */) return hasProvince && hasCity;
|
|
3902
|
+
return false;
|
|
3903
|
+
}
|
|
3904
|
+
var isAmount = (value) => Number.isInteger(value) && value >= 0;
|
|
3905
|
+
var isDays = (value) => value == null || isAmount(value);
|
|
3906
|
+
function optionProblems(option) {
|
|
3907
|
+
const problems = [];
|
|
3908
|
+
const isPickup = option.type === "pickup" /* PICKUP */;
|
|
3909
|
+
if (!isAmount(option.price) || option.freeOver != null && !isAmount(option.freeOver)) {
|
|
3910
|
+
problems.push("INVALID_PRICE" /* INVALID_PRICE */);
|
|
3911
|
+
}
|
|
3912
|
+
if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
|
|
3913
|
+
if (!isDays(option.minDays) || !isDays(option.maxDays) || (option.minDays ?? 0) > (option.maxDays ?? Infinity)) {
|
|
3914
|
+
problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
3915
|
+
}
|
|
3916
|
+
if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
|
|
3917
|
+
if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
|
|
3918
|
+
if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
|
|
3919
|
+
return problems.map((code) => ({ code, optionId: option.id }));
|
|
3920
|
+
}
|
|
3921
|
+
function tiersAreValid(option) {
|
|
3922
|
+
const tiers = option.priceByTotal ?? [];
|
|
3923
|
+
const froms = tiers.map((tier) => tier.from);
|
|
3924
|
+
return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
|
|
3925
|
+
}
|
|
3926
|
+
|
|
3567
3927
|
// constants/adyen.constants.ts
|
|
3568
3928
|
var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
|
|
3569
3929
|
function isAdyenRolloutCountry(alpha2) {
|
|
@@ -3613,6 +3973,27 @@ var BNPL_SKIP_REASON = {
|
|
|
3613
3973
|
NO_BUSINESS_LINE: "no_business_line"
|
|
3614
3974
|
};
|
|
3615
3975
|
|
|
3976
|
+
// pos-types/active/ProcessorType.ts
|
|
3977
|
+
var ProcessorType = /* @__PURE__ */ ((ProcessorType2) => {
|
|
3978
|
+
ProcessorType2["FINAL_PAY"] = "Terminal";
|
|
3979
|
+
ProcessorType2["TAP_TO_PAY"] = "TapToPay";
|
|
3980
|
+
ProcessorType2["MOTO"] = "Moto";
|
|
3981
|
+
ProcessorType2["CLOUD"] = "Cloud";
|
|
3982
|
+
ProcessorType2["BLUETOOTH"] = "Bluetooth";
|
|
3983
|
+
ProcessorType2["CASH"] = "Cash";
|
|
3984
|
+
ProcessorType2["CUSTOM_PAY"] = "CustomPay";
|
|
3985
|
+
ProcessorType2["VENDARA"] = "Vendara";
|
|
3986
|
+
ProcessorType2["REDEEM"] = "Redeem";
|
|
3987
|
+
ProcessorType2["INTEGRATION"] = "Integration";
|
|
3988
|
+
ProcessorType2["PAYMENT_LINK"] = "PaymentLink";
|
|
3989
|
+
ProcessorType2["ONLINE_PAYMENT"] = "OnlinePayment";
|
|
3990
|
+
ProcessorType2["EXTERNAL"] = "External";
|
|
3991
|
+
return ProcessorType2;
|
|
3992
|
+
})(ProcessorType || {});
|
|
3993
|
+
|
|
3994
|
+
// constants/payment-channel.constants.ts
|
|
3995
|
+
var PAYMENT_CHANNELS = ["inPerson", "online"];
|
|
3996
|
+
|
|
3616
3997
|
// constants/expense.constants.ts
|
|
3617
3998
|
var EXPENSE_PAYMENT_METHOD_PRESETS = [
|
|
3618
3999
|
"Cash",
|
|
@@ -3654,6 +4035,7 @@ export {
|
|
|
3654
4035
|
BookingResourceStatus,
|
|
3655
4036
|
BookingRulesError,
|
|
3656
4037
|
BookingType,
|
|
4038
|
+
CANADA_PROVINCES,
|
|
3657
4039
|
CONDITION_OPERATORS,
|
|
3658
4040
|
COUNTRY_CURRENCIES,
|
|
3659
4041
|
CURRENCY_CONFIG,
|
|
@@ -3670,6 +4052,7 @@ export {
|
|
|
3670
4052
|
DualWriteStrategy,
|
|
3671
4053
|
EUFixedRates,
|
|
3672
4054
|
EUROPE,
|
|
4055
|
+
EVERYWHERE_KEY,
|
|
3673
4056
|
EXPENSE_DEFAULT_CATEGORIES,
|
|
3674
4057
|
EXPENSE_NAME_MAX_LENGTH,
|
|
3675
4058
|
EXPENSE_PAYMENT_METHOD_PRESETS,
|
|
@@ -3694,6 +4077,7 @@ export {
|
|
|
3694
4077
|
OtherFixedRates,
|
|
3695
4078
|
OwnerType,
|
|
3696
4079
|
PATH_MODES,
|
|
4080
|
+
PAYMENT_CHANNELS,
|
|
3697
4081
|
PAYMENT_STATES,
|
|
3698
4082
|
POS_VALID_INITIAL_STATES,
|
|
3699
4083
|
PaymentMethod,
|
|
@@ -3703,6 +4087,7 @@ export {
|
|
|
3703
4087
|
PricingLevel,
|
|
3704
4088
|
PricingPlanEnum,
|
|
3705
4089
|
PricingRegionEnum,
|
|
4090
|
+
ProcessorType,
|
|
3706
4091
|
ProductStatus,
|
|
3707
4092
|
ProductType,
|
|
3708
4093
|
PublicationAvailability,
|
|
@@ -3721,6 +4106,12 @@ export {
|
|
|
3721
4106
|
SYSTEM_FAMILY_IDS,
|
|
3722
4107
|
SYSTEM_UNITS,
|
|
3723
4108
|
SYSTEM_UNIT_IDS,
|
|
4109
|
+
ShippingChannel,
|
|
4110
|
+
ShippingNoOptionReason,
|
|
4111
|
+
ShippingOptionType,
|
|
4112
|
+
ShippingRateType,
|
|
4113
|
+
ShippingZoneError,
|
|
4114
|
+
ShippingZoneKind,
|
|
3724
4115
|
StationStatus,
|
|
3725
4116
|
StripeCurrencyCode,
|
|
3726
4117
|
StripeStatus,
|
|
@@ -3728,6 +4119,7 @@ export {
|
|
|
3728
4119
|
TopMetericsSort,
|
|
3729
4120
|
UserTypes,
|
|
3730
4121
|
addAmounts,
|
|
4122
|
+
addressPlaceKeys,
|
|
3731
4123
|
adyenLegalEntityRequiresStateOrProvince,
|
|
3732
4124
|
adyenRequiresJobTitle,
|
|
3733
4125
|
adyenStoreRequiresStateOrProvince,
|
|
@@ -3806,25 +4198,37 @@ export {
|
|
|
3806
4198
|
isSystemFamilyCode,
|
|
3807
4199
|
isValidQuantity,
|
|
3808
4200
|
isWhole,
|
|
4201
|
+
listCountries,
|
|
4202
|
+
listProvinces,
|
|
3809
4203
|
mapToLegacyStatus,
|
|
3810
4204
|
maxPrecisionFor,
|
|
3811
4205
|
mergeFragment,
|
|
3812
4206
|
modifiersSellable,
|
|
3813
4207
|
multiplyAmount,
|
|
4208
|
+
normalizeAddress,
|
|
4209
|
+
normalizeCityKey,
|
|
4210
|
+
normalizeCountry,
|
|
3814
4211
|
normalizeMongoIdString,
|
|
4212
|
+
normalizePostCode,
|
|
4213
|
+
normalizeProvince,
|
|
3815
4214
|
occupancyIn,
|
|
3816
4215
|
parseAmountToMinorUnits,
|
|
3817
4216
|
parseCurrencyCode,
|
|
3818
4217
|
parseStripeCurrencyCode,
|
|
4218
|
+
placeKey,
|
|
3819
4219
|
planWindow,
|
|
3820
4220
|
poolDemand,
|
|
3821
4221
|
poolOf,
|
|
3822
4222
|
poolShortfall,
|
|
3823
4223
|
poolStockAt,
|
|
4224
|
+
postCodeMatchesProvince,
|
|
3824
4225
|
presentAt,
|
|
4226
|
+
priceForTotal,
|
|
4227
|
+
provincesForPostCode,
|
|
3825
4228
|
removeFragment,
|
|
3826
4229
|
resolveFamily,
|
|
3827
4230
|
resolveModifiersForProduct,
|
|
4231
|
+
resolveShipping,
|
|
3828
4232
|
resolveTemplate,
|
|
3829
4233
|
resolveUnit,
|
|
3830
4234
|
roundToPrecision,
|
|
@@ -3841,6 +4245,7 @@ export {
|
|
|
3841
4245
|
validateConfig,
|
|
3842
4246
|
validateFragmentCompatibility,
|
|
3843
4247
|
validateOrderStatuses,
|
|
4248
|
+
validateShippingZone,
|
|
3844
4249
|
violatesFinancialInvariant,
|
|
3845
4250
|
windowEndsAt,
|
|
3846
4251
|
withinPresence
|