@final-commerce/common 2.7.0-preprod.1 → 2.7.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 +298 -225
- package/dist/pos-types/index.d.ts +298 -225
- 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) {
|
|
@@ -3612,6 +3972,27 @@ var BNPL_SKIP_REASON = {
|
|
|
3612
3972
|
NO_CURRENCY: "no_currency",
|
|
3613
3973
|
NO_BUSINESS_LINE: "no_business_line"
|
|
3614
3974
|
};
|
|
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"];
|
|
3615
3996
|
export {
|
|
3616
3997
|
ADYEN_JOB_TITLE_ASSOCIATION_TYPES,
|
|
3617
3998
|
ADYEN_LEGAL_ENTITY_STATE_PROVINCE_COUNTRIES,
|
|
@@ -3630,6 +4011,7 @@ export {
|
|
|
3630
4011
|
BookingResourceStatus,
|
|
3631
4012
|
BookingRulesError,
|
|
3632
4013
|
BookingType,
|
|
4014
|
+
CANADA_PROVINCES,
|
|
3633
4015
|
CONDITION_OPERATORS,
|
|
3634
4016
|
COUNTRY_CURRENCIES,
|
|
3635
4017
|
CURRENCY_CONFIG,
|
|
@@ -3646,6 +4028,7 @@ export {
|
|
|
3646
4028
|
DualWriteStrategy,
|
|
3647
4029
|
EUFixedRates,
|
|
3648
4030
|
EUROPE,
|
|
4031
|
+
EVERYWHERE_KEY,
|
|
3649
4032
|
ExtensionCategory,
|
|
3650
4033
|
FINANCIAL_INVARIANTS,
|
|
3651
4034
|
FULFILLMENT_STATES,
|
|
@@ -3667,6 +4050,7 @@ export {
|
|
|
3667
4050
|
OtherFixedRates,
|
|
3668
4051
|
OwnerType,
|
|
3669
4052
|
PATH_MODES,
|
|
4053
|
+
PAYMENT_CHANNELS,
|
|
3670
4054
|
PAYMENT_STATES,
|
|
3671
4055
|
POS_VALID_INITIAL_STATES,
|
|
3672
4056
|
PaymentMethod,
|
|
@@ -3676,6 +4060,7 @@ export {
|
|
|
3676
4060
|
PricingLevel,
|
|
3677
4061
|
PricingPlanEnum,
|
|
3678
4062
|
PricingRegionEnum,
|
|
4063
|
+
ProcessorType,
|
|
3679
4064
|
ProductStatus,
|
|
3680
4065
|
ProductType,
|
|
3681
4066
|
PublicationAvailability,
|
|
@@ -3694,6 +4079,12 @@ export {
|
|
|
3694
4079
|
SYSTEM_FAMILY_IDS,
|
|
3695
4080
|
SYSTEM_UNITS,
|
|
3696
4081
|
SYSTEM_UNIT_IDS,
|
|
4082
|
+
ShippingChannel,
|
|
4083
|
+
ShippingNoOptionReason,
|
|
4084
|
+
ShippingOptionType,
|
|
4085
|
+
ShippingRateType,
|
|
4086
|
+
ShippingZoneError,
|
|
4087
|
+
ShippingZoneKind,
|
|
3697
4088
|
StationStatus,
|
|
3698
4089
|
StripeCurrencyCode,
|
|
3699
4090
|
StripeStatus,
|
|
@@ -3701,6 +4092,7 @@ export {
|
|
|
3701
4092
|
TopMetericsSort,
|
|
3702
4093
|
UserTypes,
|
|
3703
4094
|
addAmounts,
|
|
4095
|
+
addressPlaceKeys,
|
|
3704
4096
|
adyenLegalEntityRequiresStateOrProvince,
|
|
3705
4097
|
adyenRequiresJobTitle,
|
|
3706
4098
|
adyenStoreRequiresStateOrProvince,
|
|
@@ -3779,25 +4171,37 @@ export {
|
|
|
3779
4171
|
isSystemFamilyCode,
|
|
3780
4172
|
isValidQuantity,
|
|
3781
4173
|
isWhole,
|
|
4174
|
+
listCountries,
|
|
4175
|
+
listProvinces,
|
|
3782
4176
|
mapToLegacyStatus,
|
|
3783
4177
|
maxPrecisionFor,
|
|
3784
4178
|
mergeFragment,
|
|
3785
4179
|
modifiersSellable,
|
|
3786
4180
|
multiplyAmount,
|
|
4181
|
+
normalizeAddress,
|
|
4182
|
+
normalizeCityKey,
|
|
4183
|
+
normalizeCountry,
|
|
3787
4184
|
normalizeMongoIdString,
|
|
4185
|
+
normalizePostCode,
|
|
4186
|
+
normalizeProvince,
|
|
3788
4187
|
occupancyIn,
|
|
3789
4188
|
parseAmountToMinorUnits,
|
|
3790
4189
|
parseCurrencyCode,
|
|
3791
4190
|
parseStripeCurrencyCode,
|
|
4191
|
+
placeKey,
|
|
3792
4192
|
planWindow,
|
|
3793
4193
|
poolDemand,
|
|
3794
4194
|
poolOf,
|
|
3795
4195
|
poolShortfall,
|
|
3796
4196
|
poolStockAt,
|
|
4197
|
+
postCodeMatchesProvince,
|
|
3797
4198
|
presentAt,
|
|
4199
|
+
priceForTotal,
|
|
4200
|
+
provincesForPostCode,
|
|
3798
4201
|
removeFragment,
|
|
3799
4202
|
resolveFamily,
|
|
3800
4203
|
resolveModifiersForProduct,
|
|
4204
|
+
resolveShipping,
|
|
3801
4205
|
resolveTemplate,
|
|
3802
4206
|
resolveUnit,
|
|
3803
4207
|
roundToPrecision,
|
|
@@ -3814,6 +4218,7 @@ export {
|
|
|
3814
4218
|
validateConfig,
|
|
3815
4219
|
validateFragmentCompatibility,
|
|
3816
4220
|
validateOrderStatuses,
|
|
4221
|
+
validateShippingZone,
|
|
3817
4222
|
violatesFinancialInvariant,
|
|
3818
4223
|
windowEndsAt,
|
|
3819
4224
|
withinPresence
|