@final-commerce/common 2.10.0 → 2.11.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.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,74 @@ 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
+
544
+ // enums/tax.enum.ts
545
+ var TaxRegistrationKind = /* @__PURE__ */ ((TaxRegistrationKind2) => {
546
+ TaxRegistrationKind2["GST_HST"] = "GST_HST";
547
+ TaxRegistrationKind2["PST"] = "PST";
548
+ TaxRegistrationKind2["QST"] = "QST";
549
+ return TaxRegistrationKind2;
550
+ })(TaxRegistrationKind || {});
551
+ var TaxSource = /* @__PURE__ */ ((TaxSource2) => {
552
+ TaxSource2["MERCHANT"] = "merchant";
553
+ TaxSource2["AUTOMATIC"] = "automatic";
554
+ return TaxSource2;
555
+ })(TaxSource || {});
556
+ var OutOfProvinceTaxes = /* @__PURE__ */ ((OutOfProvinceTaxes2) => {
557
+ OutOfProvinceTaxes2["AUTOMATIC"] = "automatic";
558
+ OutOfProvinceTaxes2["HOME"] = "home";
559
+ return OutOfProvinceTaxes2;
560
+ })(OutOfProvinceTaxes || {});
561
+ var TaxWarningCode = /* @__PURE__ */ ((TaxWarningCode2) => {
562
+ TaxWarningCode2["NOT_REGISTERED"] = "NOT_REGISTERED";
563
+ TaxWarningCode2["NO_RULES_FOR_PLACE"] = "NO_RULES_FOR_PLACE";
564
+ TaxWarningCode2["NO_TABLE"] = "NO_TABLE";
565
+ return TaxWarningCode2;
566
+ })(TaxWarningCode || {});
567
+
499
568
  // enums/sales-line.enum.ts
500
569
  var SalesLineAction = /* @__PURE__ */ ((SalesLineAction2) => {
501
570
  SalesLineAction2["SALE"] = "sale";
@@ -1694,6 +1763,48 @@ function compositeReservationMismatches(order) {
1694
1763
  });
1695
1764
  }
1696
1765
 
1766
+ // utils/line-stock-moves.util.ts
1767
+ function lineStockMoves(item, quantity, reservations = []) {
1768
+ const sign = Math.sign(quantity);
1769
+ const pool = (stockVariantId) => stockVariantId ? { stockVariantId: stockVariantId.toString() } : {};
1770
+ if (!item.components?.length)
1771
+ return [
1772
+ {
1773
+ productId: item.productId.toString(),
1774
+ variantId: item.variantId.toString(),
1775
+ fields: {
1776
+ quantity,
1777
+ ...item.stockQuantity != null ? { stockQuantity: sign * item.stockQuantity, unitId: item.unitId?.toString() } : {},
1778
+ ...pool(item.stockVariantId)
1779
+ }
1780
+ }
1781
+ ];
1782
+ const booked = new Set(
1783
+ reservations.filter((reservation) => reservation.lineItemInternalId && reservation.lineItemInternalId === item.internalId).map((reservation) => reservation.componentIndex)
1784
+ );
1785
+ return item.components.flatMap((component, componentIndex) => {
1786
+ if (booked.has(componentIndex)) return [];
1787
+ if (component.unitId && component.stockQuantity == null)
1788
+ throw new Error(
1789
+ `Composite ${item.productId?.toString()} component ${component.variantId.toString()} is sold in ${component.unitId.toString()} but carries no stockQuantity`
1790
+ );
1791
+ return [
1792
+ {
1793
+ productId: component.productId.toString(),
1794
+ variantId: component.variantId.toString(),
1795
+ componentIndex,
1796
+ fields: {
1797
+ quantity: component.quantity * quantity,
1798
+ ...component.stockQuantity != null ? { stockQuantity: component.stockQuantity * quantity, unitId: component.unitId?.toString() } : {},
1799
+ ...pool(component.stockVariantId),
1800
+ ...item.productId ? { compositeProductId: item.productId.toString() } : {},
1801
+ ...item.name ? { compositeName: item.name } : {}
1802
+ }
1803
+ }
1804
+ ];
1805
+ });
1806
+ }
1807
+
1697
1808
  // units/family-code.ts
1698
1809
  var MAX_SLUG_LENGTH = 32;
1699
1810
  var FALLBACK_SLUG = "family";
@@ -3630,6 +3741,475 @@ function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }
3630
3741
  }
3631
3742
  var holdExpiresAt = (rule, now) => new Date(now.getTime() + (rule.window.holdMinutes ?? DEFAULT_HOLD_MINUTES) * 6e4);
3632
3743
 
3744
+ // shipping/fold-text.ts
3745
+ function foldText(value) {
3746
+ return value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/&/g, " and ").replace(/[^a-z0-9]+/g, " ").trim();
3747
+ }
3748
+
3749
+ // shipping/countries.ts
3750
+ var NOT_COUNTRIES = /* @__PURE__ */ new Set(["AC", "CP", "CQ", "DG", "EA", "EU", "EZ", "IC", "QO", "TA", "UN", "XA", "XB", "ZZ"]);
3751
+ var ALIASES = {
3752
+ canada: "CA",
3753
+ "united states": "US",
3754
+ usa: "US",
3755
+ "united states of america": "US",
3756
+ uk: "GB",
3757
+ "great britain": "GB",
3758
+ england: "GB",
3759
+ uae: "AE",
3760
+ can: "CA",
3761
+ mex: "MX",
3762
+ aus: "AU",
3763
+ gbr: "GB"
3764
+ };
3765
+ var NAME_LOCALES = ["en", "fr"];
3766
+ function regionNames(locale) {
3767
+ try {
3768
+ return new Intl.DisplayNames([locale], { type: "region", fallback: "none" });
3769
+ } catch {
3770
+ return null;
3771
+ }
3772
+ }
3773
+ function canonicalCode(code) {
3774
+ try {
3775
+ return new Intl.Locale(`und-${code}`).maximize().region ?? code;
3776
+ } catch {
3777
+ return code;
3778
+ }
3779
+ }
3780
+ function allCodes() {
3781
+ const names = regionNames("en");
3782
+ if (!names) return [];
3783
+ const codes2 = [];
3784
+ for (let a = 65; a <= 90; a++) {
3785
+ for (let b = 65; b <= 90; b++) {
3786
+ const code = String.fromCharCode(a, b);
3787
+ if (!NOT_COUNTRIES.has(code) && names.of(code) && canonicalCode(code) === code) codes2.push(code);
3788
+ }
3789
+ }
3790
+ return codes2;
3791
+ }
3792
+ var lookup = null;
3793
+ var codes = null;
3794
+ function countryCodes() {
3795
+ codes ??= allCodes();
3796
+ return codes;
3797
+ }
3798
+ function countryLookup() {
3799
+ if (lookup) return lookup;
3800
+ lookup = new Map(Object.entries(ALIASES));
3801
+ for (const locale of NAME_LOCALES) {
3802
+ const names = regionNames(locale);
3803
+ if (!names) continue;
3804
+ for (const code of countryCodes()) {
3805
+ const name = names.of(code);
3806
+ if (name) lookup.set(foldText(name), code);
3807
+ }
3808
+ }
3809
+ return lookup;
3810
+ }
3811
+ function normalizeCountry(value) {
3812
+ const text = (value ?? "").trim();
3813
+ if (!text) return void 0;
3814
+ const upper = text.toUpperCase();
3815
+ if (upper.length === 2) {
3816
+ if (NOT_COUNTRIES.has(upper)) return void 0;
3817
+ if (countryCodes().length === 0) return /^[A-Z]{2}$/.test(upper) ? upper : void 0;
3818
+ const code = canonicalCode(upper);
3819
+ if (countryCodes().includes(code)) return code;
3820
+ }
3821
+ return countryLookup().get(foldText(text));
3822
+ }
3823
+ function listCountries(locale = "en") {
3824
+ const names = regionNames(locale) ?? regionNames("en");
3825
+ return countryCodes().map((code) => ({ code, name: names?.of(code) ?? code })).sort((a, b) => a.name.localeCompare(b.name, locale));
3826
+ }
3827
+ var SHIPPING_COUNTRIES = ["CA"];
3828
+ function shipsToCountry(code) {
3829
+ return !!code && SHIPPING_COUNTRIES.includes(code);
3830
+ }
3831
+ function listShippingCountries(locale = "en") {
3832
+ const names = regionNames(locale) ?? regionNames("en");
3833
+ return SHIPPING_COUNTRIES.map((code) => ({ code, name: names?.of(code) ?? code })).sort(
3834
+ (a, b) => a.name.localeCompare(b.name, locale)
3835
+ );
3836
+ }
3837
+
3838
+ // shipping/provinces.ts
3839
+ var CANADA_PROVINCES = [
3840
+ { code: "AB", name: "Alberta", nameFr: "Alberta", postalLetters: ["T"] },
3841
+ { code: "BC", name: "British Columbia", nameFr: "Colombie-Britannique", postalLetters: ["V"] },
3842
+ { code: "MB", name: "Manitoba", nameFr: "Manitoba", postalLetters: ["R"] },
3843
+ { code: "NB", name: "New Brunswick", nameFr: "Nouveau-Brunswick", postalLetters: ["E"] },
3844
+ {
3845
+ code: "NL",
3846
+ name: "Newfoundland and Labrador",
3847
+ nameFr: "Terre-Neuve-et-Labrador",
3848
+ postalLetters: ["A"],
3849
+ aliases: ["NF", "LB", "Newfoundland", "Labrador"]
3850
+ },
3851
+ { code: "NS", name: "Nova Scotia", nameFr: "Nouvelle-\xC9cosse", postalLetters: ["B"] },
3852
+ { code: "NT", name: "Northwest Territories", nameFr: "Territoires du Nord-Ouest", postalLetters: ["X"] },
3853
+ { code: "NU", name: "Nunavut", nameFr: "Nunavut", postalLetters: ["X"] },
3854
+ { code: "ON", name: "Ontario", nameFr: "Ontario", postalLetters: ["K", "L", "M", "N", "P"] },
3855
+ {
3856
+ code: "PE",
3857
+ name: "Prince Edward Island",
3858
+ nameFr: "\xCEle-du-Prince-\xC9douard",
3859
+ postalLetters: ["C"],
3860
+ aliases: ["PEI"]
3861
+ },
3862
+ { code: "QC", name: "Quebec", nameFr: "Qu\xE9bec", postalLetters: ["G", "H", "J"], aliases: ["PQ"] },
3863
+ { code: "SK", name: "Saskatchewan", nameFr: "Saskatchewan", postalLetters: ["S"] },
3864
+ { code: "YT", name: "Yukon", nameFr: "Yukon", postalLetters: ["Y"], aliases: ["YK"] }
3865
+ ];
3866
+ var PROVINCES_BY_COUNTRY = { CA: CANADA_PROVINCES };
3867
+ var lookups = /* @__PURE__ */ new Map();
3868
+ function provinceLookup(country) {
3869
+ const provinces = PROVINCES_BY_COUNTRY[country];
3870
+ if (!provinces) return void 0;
3871
+ let lookup2 = lookups.get(country);
3872
+ if (!lookup2) {
3873
+ lookup2 = /* @__PURE__ */ new Map();
3874
+ for (const p of provinces) {
3875
+ for (const label of [p.code, p.name, p.nameFr, ...p.aliases ?? []]) lookup2.set(foldText(label), p.code);
3876
+ }
3877
+ lookups.set(country, lookup2);
3878
+ }
3879
+ return lookup2;
3880
+ }
3881
+ function normalizeProvince(country, value) {
3882
+ if (!country || !value?.trim()) return void 0;
3883
+ return provinceLookup(country)?.get(foldText(value));
3884
+ }
3885
+ function listProvinces(country) {
3886
+ return PROVINCES_BY_COUNTRY[country] ?? [];
3887
+ }
3888
+ function provincesForPostCode(country, postCode) {
3889
+ const letter = postCode?.charAt(0);
3890
+ if (!country || !letter) return [];
3891
+ return listProvinces(country).filter((p) => p.postalLetters.includes(letter)).map((p) => p.code);
3892
+ }
3893
+
3894
+ // shipping/normalize.ts
3895
+ var EVERYWHERE_KEY = "*";
3896
+ function normalizeCityKey(value) {
3897
+ const words = foldText(value ?? "").split(" ").filter(Boolean).map((word) => word === "saint" ? "st" : word === "sainte" ? "ste" : word);
3898
+ return words.length ? words.join("") : void 0;
3899
+ }
3900
+ function normalizePostCode(value) {
3901
+ const compact = (value ?? "").replace(/[^0-9a-z]/gi, "").toUpperCase();
3902
+ return compact || void 0;
3903
+ }
3904
+ function normalizeAddress(address) {
3905
+ if (!address) return {};
3906
+ const country = normalizeCountry(address.country);
3907
+ const postCode = normalizePostCode(address.postCode ?? address.postalCode ?? address.zip);
3908
+ const fromPostCode = provincesForPostCode(country, postCode);
3909
+ const province = normalizeProvince(country, address.state ?? address.province) ?? (fromPostCode.length === 1 ? fromPostCode[0] : void 0);
3910
+ return { country, province, cityKey: normalizeCityKey(address.city), postCode };
3911
+ }
3912
+ function postCodeMatchesProvince(address) {
3913
+ const candidates = provincesForPostCode(address.country, address.postCode);
3914
+ if (!address.province || candidates.length === 0) return true;
3915
+ return candidates.includes(address.province);
3916
+ }
3917
+ function placeKey(place) {
3918
+ const country = normalizeCountry(place.country);
3919
+ if (!country) return void 0;
3920
+ if (!place.province) return country;
3921
+ const province = normalizeProvince(country, place.province);
3922
+ if (!province) return void 0;
3923
+ if (!place.city) return `${country}-${province}`;
3924
+ const city = normalizeCityKey(place.city);
3925
+ return city ? `${country}-${province}/${city}` : void 0;
3926
+ }
3927
+ function addressPlaceKeys(address) {
3928
+ const keys = [];
3929
+ if (address.country && address.province && address.cityKey) {
3930
+ keys.push(`${address.country}-${address.province}/${address.cityKey}`);
3931
+ }
3932
+ if (address.country && address.province) keys.push(`${address.country}-${address.province}`);
3933
+ if (address.country) keys.push(address.country);
3934
+ keys.push(EVERYWHERE_KEY);
3935
+ return keys;
3936
+ }
3937
+
3938
+ // shipping/resolve.ts
3939
+ function resolveShipping({ zones, address, itemsTotal, channel }) {
3940
+ const shipsToCountries = countriesShippedTo(zones);
3941
+ const none = (reason, zone2) => ({
3942
+ zoneId: zone2?.id ?? null,
3943
+ options: [],
3944
+ reason,
3945
+ message: zone2?.message?.trim() || null,
3946
+ shipsToCountries
3947
+ });
3948
+ const normalized = normalizeAddress(address);
3949
+ if (!normalized.country) return none("INCOMPLETE" /* INCOMPLETE */);
3950
+ if (!shipsToCountry(normalized.country)) return none("NO_COVERAGE" /* NO_COVERAGE */);
3951
+ if (!postCodeMatchesProvince(normalized)) return none("ADDRESS_MISMATCH" /* ADDRESS_MISMATCH */);
3952
+ const zone = findZone(zones, addressPlaceKeys(normalized));
3953
+ if (!zone) return none("NO_COVERAGE" /* NO_COVERAGE */);
3954
+ const offered = zone.options.filter((option) => isOffered(option, zone, channel));
3955
+ if (offered.length === 0) {
3956
+ return none(zone.ships ? "NO_OPTION" /* NO_OPTION */ : "BLOCKED" /* BLOCKED */, zone);
3957
+ }
3958
+ const quotes = offered.map((option) => quote(option, zone.id, itemsTotal));
3959
+ const ship = quotes.filter((q) => q.type === "ship" /* SHIP */).sort((a, b) => a.amount - b.amount);
3960
+ const pickup = quotes.filter((q) => q.type === "pickup" /* PICKUP */).sort((a, b) => a.amount - b.amount);
3961
+ return {
3962
+ zoneId: zone.id,
3963
+ options: [...ship, ...pickup],
3964
+ reason: null,
3965
+ message: zone.ships ? null : zone.message?.trim() || null,
3966
+ shipsToCountries
3967
+ };
3968
+ }
3969
+ function findZone(zones, keys) {
3970
+ const byKey = /* @__PURE__ */ new Map();
3971
+ for (const zone of zones) {
3972
+ for (const key of zoneKeys(zone)) if (!byKey.has(key)) byKey.set(key, zone);
3973
+ }
3974
+ for (const key of keys) {
3975
+ const zone = byKey.get(key);
3976
+ if (zone) return zone;
3977
+ }
3978
+ return void 0;
3979
+ }
3980
+ function zoneKeys(zone) {
3981
+ if (zone.kind === "everywhere" /* EVERYWHERE */) return [EVERYWHERE_KEY];
3982
+ return zone.places.map(placeKey).filter((key) => Boolean(key));
3983
+ }
3984
+ function isOffered(option, zone, channel) {
3985
+ if (!option.channels.some((c) => c === channel)) return false;
3986
+ if (option.type === "pickup" /* PICKUP */) return channel !== "pos" /* POS */;
3987
+ return zone.ships;
3988
+ }
3989
+ function priceForTotal(option, itemsTotal) {
3990
+ const tiers = [...option.priceByTotal ?? []].sort((a, b) => a.from - b.from);
3991
+ let price = option.price;
3992
+ for (const tier of tiers) if (itemsTotal >= tier.from) price = tier.price;
3993
+ if (option.freeOver != null && itemsTotal >= option.freeOver) return 0;
3994
+ return price;
3995
+ }
3996
+ function quote(option, zoneId, itemsTotal) {
3997
+ const amount = priceForTotal(option, itemsTotal);
3998
+ const freeOver = option.freeOver ?? null;
3999
+ return {
4000
+ optionId: option.id,
4001
+ zoneId,
4002
+ type: option.type,
4003
+ name: option.name?.trim() || null,
4004
+ amount,
4005
+ amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
4006
+ minDays: option.minDays ?? null,
4007
+ maxDays: option.maxDays ?? null,
4008
+ outletId: option.outletId ?? null
4009
+ };
4010
+ }
4011
+ function countriesShippedTo(zones) {
4012
+ const countries = /* @__PURE__ */ new Set();
4013
+ for (const zone of zones) {
4014
+ if (!zone.ships) continue;
4015
+ for (const key of zoneKeys(zone)) {
4016
+ if (key !== EVERYWHERE_KEY && shipsToCountry(key.slice(0, 2))) countries.add(key.slice(0, 2));
4017
+ }
4018
+ }
4019
+ return [...countries].sort();
4020
+ }
4021
+
4022
+ // shipping/validate.ts
4023
+ function validateShippingZone(zone) {
4024
+ const problems = [...placeProblems(zone)];
4025
+ for (const option of zone.options) problems.push(...optionProblems(option));
4026
+ const reachesWebsite = zone.options.some((option) => option.channels.includes("web" /* WEB */));
4027
+ if (zone.ships && !reachesWebsite) problems.push({ code: "NO_WEBSITE_OPTION" /* NO_WEBSITE_OPTION */ });
4028
+ return problems;
4029
+ }
4030
+ function placeProblems(zone) {
4031
+ if (zone.kind === "everywhere" /* EVERYWHERE */) {
4032
+ return zone.places.length ? [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }] : [];
4033
+ }
4034
+ if (zone.places.length === 0) return [{ code: "NO_PLACES" /* NO_PLACES */ }];
4035
+ if (!zone.places.every((place) => fitsKind(place, zone.kind))) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
4036
+ const keys = zone.places.map(placeKey);
4037
+ if (keys.some((key) => !key || !shipsToCountry(key.slice(0, 2)))) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
4038
+ if (new Set(keys).size !== keys.length) return [{ code: "DUPLICATE_PLACE" /* DUPLICATE_PLACE */ }];
4039
+ return [];
4040
+ }
4041
+ function fitsKind(place, kind) {
4042
+ const hasProvince = Boolean(place.province?.trim());
4043
+ const hasCity = Boolean(place.city?.trim());
4044
+ if (kind === "country" /* COUNTRY */) return !hasProvince && !hasCity;
4045
+ if (kind === "province" /* PROVINCE */) return hasProvince && !hasCity;
4046
+ if (kind === "city" /* CITY */) return hasProvince && hasCity;
4047
+ return false;
4048
+ }
4049
+ var isAmount = (value) => Number.isInteger(value) && value >= 0;
4050
+ var isDays = (value) => value == null || isAmount(value);
4051
+ function optionProblems(option) {
4052
+ const problems = [];
4053
+ const isPickup = option.type === "pickup" /* PICKUP */;
4054
+ if (!isAmount(option.price) || option.freeOver != null && !isAmount(option.freeOver)) {
4055
+ problems.push("INVALID_PRICE" /* INVALID_PRICE */);
4056
+ }
4057
+ if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
4058
+ if (!isDays(option.minDays) || !isDays(option.maxDays) || (option.minDays ?? 0) > (option.maxDays ?? Infinity)) {
4059
+ problems.push("INVALID_DAYS" /* INVALID_DAYS */);
4060
+ }
4061
+ if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
4062
+ if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
4063
+ if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
4064
+ return problems.map((code) => ({ code, optionId: option.id }));
4065
+ }
4066
+ function tiersAreValid(option) {
4067
+ const tiers = option.priceByTotal ?? [];
4068
+ const froms = tiers.map((tier) => tier.from);
4069
+ return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
4070
+ }
4071
+
4072
+ // tax/sha1.ts
4073
+ function utf8Bytes(text) {
4074
+ const bytes = [];
4075
+ for (const char of text) {
4076
+ const cp = char.codePointAt(0);
4077
+ if (cp < 128) bytes.push(cp);
4078
+ else if (cp < 2048) bytes.push(192 | cp >> 6, 128 | cp & 63);
4079
+ else if (cp < 65536) bytes.push(224 | cp >> 12, 128 | cp >> 6 & 63, 128 | cp & 63);
4080
+ else bytes.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
4081
+ }
4082
+ return bytes;
4083
+ }
4084
+ var rotl = (x, n) => x << n | x >>> 32 - n;
4085
+ function sha1Hex(text) {
4086
+ const bytes = utf8Bytes(text);
4087
+ const bitLength = bytes.length * 8;
4088
+ bytes.push(128);
4089
+ while (bytes.length % 64 !== 56) bytes.push(0);
4090
+ const high = Math.floor(bitLength / 4294967296);
4091
+ for (const word of [high, bitLength >>> 0])
4092
+ bytes.push(word >>> 24 & 255, word >>> 16 & 255, word >>> 8 & 255, word & 255);
4093
+ const h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
4094
+ const w = new Array(80);
4095
+ for (let offset = 0; offset < bytes.length; offset += 64) {
4096
+ for (let i = 0; i < 16; i++) {
4097
+ const j = offset + i * 4;
4098
+ w[i] = bytes[j] << 24 | bytes[j + 1] << 16 | bytes[j + 2] << 8 | bytes[j + 3];
4099
+ }
4100
+ for (let i = 16; i < 80; i++) w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
4101
+ let [a, b, c, d, e] = h;
4102
+ for (let i = 0; i < 80; i++) {
4103
+ const [f, k] = i < 20 ? [b & c | ~b & d, 1518500249] : i < 40 ? [b ^ c ^ d, 1859775393] : i < 60 ? [b & c | b & d | c & d, 2400959708] : [b ^ c ^ d, 3395469782];
4104
+ const t = rotl(a, 5) + f + e + k + w[i] | 0;
4105
+ e = d;
4106
+ d = c;
4107
+ c = rotl(b, 30);
4108
+ b = a;
4109
+ a = t;
4110
+ }
4111
+ h[0] = h[0] + a | 0;
4112
+ h[1] = h[1] + b | 0;
4113
+ h[2] = h[2] + c | 0;
4114
+ h[3] = h[3] + d | 0;
4115
+ h[4] = h[4] + e | 0;
4116
+ }
4117
+ return h.map((x) => (x >>> 0).toString(16).padStart(8, "0")).join("");
4118
+ }
4119
+
4120
+ // tax/table.ts
4121
+ var STANDARD_TAX_TYPE = "standard";
4122
+ var TYPE_FIELDS = ["key", "name", "description", "sortOrder", "active"];
4123
+ var RATE_FIELDS = [
4124
+ "code",
4125
+ "name",
4126
+ "kind",
4127
+ "places",
4128
+ "rate",
4129
+ "from",
4130
+ "to",
4131
+ "order",
4132
+ "compound",
4133
+ "registrationPlace",
4134
+ "harmonized",
4135
+ "parts",
4136
+ "sourceUrl",
4137
+ "status"
4138
+ ];
4139
+ var RULE_FIELDS = ["taxType", "codes", "rate", "from", "to", "sourceUrl", "status", "note"];
4140
+ function canonical(row, fields) {
4141
+ return JSON.stringify(fields.map((field) => row[field] ?? null));
4142
+ }
4143
+ var sortedCanonical = (rows, fields) => rows.map((row) => canonical(row, fields)).sort();
4144
+ function automaticTaxTableVersion(table) {
4145
+ return sha1Hex(
4146
+ JSON.stringify([
4147
+ sortedCanonical(table.types, TYPE_FIELDS),
4148
+ sortedCanonical(table.rates, RATE_FIELDS),
4149
+ sortedCanonical(table.rules, RULE_FIELDS)
4150
+ ])
4151
+ );
4152
+ }
4153
+ var toTypeRow = ({ key, name, description, sortOrder, active }) => ({
4154
+ key,
4155
+ name,
4156
+ description,
4157
+ sortOrder,
4158
+ active
4159
+ });
4160
+ var toRateRow = (rate) => ({
4161
+ code: rate.code,
4162
+ name: rate.name,
4163
+ kind: rate.kind,
4164
+ places: rate.places,
4165
+ rate: rate.rate,
4166
+ from: rate.from,
4167
+ to: rate.to,
4168
+ order: rate.order,
4169
+ compound: rate.compound,
4170
+ registrationPlace: rate.registrationPlace,
4171
+ harmonized: rate.harmonized,
4172
+ parts: rate.parts?.map(({ code, name, rate: partRate, level }) => ({ code, name, rate: partRate, level })),
4173
+ sourceUrl: rate.sourceUrl,
4174
+ status: rate.status
4175
+ });
4176
+ var toRuleRow = ({
4177
+ taxType,
4178
+ codes: codes2,
4179
+ rate,
4180
+ from,
4181
+ to,
4182
+ sourceUrl,
4183
+ status,
4184
+ note
4185
+ }) => ({
4186
+ taxType,
4187
+ codes: codes2,
4188
+ rate,
4189
+ from,
4190
+ to,
4191
+ sourceUrl,
4192
+ status,
4193
+ note
4194
+ });
4195
+ function buildAutomaticTaxTable(rows) {
4196
+ const table = {
4197
+ types: [...rows.types].sort((a, b) => a.sortOrder - b.sortOrder).map(toTypeRow),
4198
+ rates: rows.rates.map(toRateRow),
4199
+ rules: rows.rules.map(toRuleRow)
4200
+ };
4201
+ return { version: automaticTaxTableVersion(table), ...table };
4202
+ }
4203
+ function registrationPlacesByKind(rates) {
4204
+ const places = /* @__PURE__ */ new Map();
4205
+ for (const rate of rates) {
4206
+ const list = places.get(rate.kind) ?? [];
4207
+ if (!list.includes(rate.registrationPlace)) list.push(rate.registrationPlace);
4208
+ places.set(rate.kind, list);
4209
+ }
4210
+ return places;
4211
+ }
4212
+
3633
4213
  // constants/adyen.constants.ts
3634
4214
  var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
3635
4215
  function isAdyenRolloutCountry(alpha2) {
@@ -3679,6 +4259,27 @@ var BNPL_SKIP_REASON = {
3679
4259
  NO_BUSINESS_LINE: "no_business_line"
3680
4260
  };
3681
4261
 
4262
+ // pos-types/active/ProcessorType.ts
4263
+ var ProcessorType = /* @__PURE__ */ ((ProcessorType2) => {
4264
+ ProcessorType2["FINAL_PAY"] = "Terminal";
4265
+ ProcessorType2["TAP_TO_PAY"] = "TapToPay";
4266
+ ProcessorType2["MOTO"] = "Moto";
4267
+ ProcessorType2["CLOUD"] = "Cloud";
4268
+ ProcessorType2["BLUETOOTH"] = "Bluetooth";
4269
+ ProcessorType2["CASH"] = "Cash";
4270
+ ProcessorType2["CUSTOM_PAY"] = "CustomPay";
4271
+ ProcessorType2["VENDARA"] = "Vendara";
4272
+ ProcessorType2["REDEEM"] = "Redeem";
4273
+ ProcessorType2["INTEGRATION"] = "Integration";
4274
+ ProcessorType2["PAYMENT_LINK"] = "PaymentLink";
4275
+ ProcessorType2["ONLINE_PAYMENT"] = "OnlinePayment";
4276
+ ProcessorType2["EXTERNAL"] = "External";
4277
+ return ProcessorType2;
4278
+ })(ProcessorType || {});
4279
+
4280
+ // constants/payment-channel.constants.ts
4281
+ var PAYMENT_CHANNELS = ["inPerson", "online"];
4282
+
3682
4283
  // constants/expense.constants.ts
3683
4284
  var EXPENSE_PAYMENT_METHOD_PRESETS = [
3684
4285
  "Cash",
@@ -3702,26 +4303,6 @@ var EXPENSE_DEFAULT_CATEGORIES = [
3702
4303
  { key: "vehicle-fuel", name: "Vehicle & fuel" },
3703
4304
  { key: "other", name: "Other" }
3704
4305
  ];
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"];
3725
4306
  export {
3726
4307
  ADYEN_JOB_TITLE_ASSOCIATION_TYPES,
3727
4308
  ADYEN_LEGAL_ENTITY_STATE_PROVINCE_COUNTRIES,
@@ -3740,6 +4321,7 @@ export {
3740
4321
  BookingResourceStatus,
3741
4322
  BookingRulesError,
3742
4323
  BookingType,
4324
+ CANADA_PROVINCES,
3743
4325
  CONDITION_OPERATORS,
3744
4326
  COUNTRY_CURRENCIES,
3745
4327
  CURRENCY_CONFIG,
@@ -3756,6 +4338,7 @@ export {
3756
4338
  DualWriteStrategy,
3757
4339
  EUFixedRates,
3758
4340
  EUROPE,
4341
+ EVERYWHERE_KEY,
3759
4342
  EXPENSE_DEFAULT_CATEGORIES,
3760
4343
  EXPENSE_NAME_MAX_LENGTH,
3761
4344
  EXPENSE_PAYMENT_METHOD_PRESETS,
@@ -3779,6 +4362,7 @@ export {
3779
4362
  ORDER_STATE_TOPIC,
3780
4363
  OrderPlatform,
3781
4364
  OtherFixedRates,
4365
+ OutOfProvinceTaxes,
3782
4366
  OwnerType,
3783
4367
  PATH_MODES,
3784
4368
  PAYMENT_CHANNELS,
@@ -3806,6 +4390,8 @@ export {
3806
4390
  ResidualPaymentMethod,
3807
4391
  ResidualStatus,
3808
4392
  ResourceAvailabilityState,
4393
+ SHIPPING_COUNTRIES,
4394
+ STANDARD_TAX_TYPE,
3809
4395
  STATE_SCHEMA,
3810
4396
  STRIPE_SUPPORTED_COUNTRIES,
3811
4397
  SYSTEM_FAMILIES,
@@ -3814,13 +4400,23 @@ export {
3814
4400
  SYSTEM_UNIT_IDS,
3815
4401
  SalesLineAction,
3816
4402
  SalesLineSourceArray,
4403
+ ShippingChannel,
4404
+ ShippingNoOptionReason,
4405
+ ShippingOptionType,
4406
+ ShippingRateType,
4407
+ ShippingZoneError,
4408
+ ShippingZoneKind,
3817
4409
  StationStatus,
3818
4410
  StripeCurrencyCode,
3819
4411
  StripeStatus,
4412
+ TaxRegistrationKind,
4413
+ TaxSource,
4414
+ TaxWarningCode,
3820
4415
  TimePeriod,
3821
4416
  TopMetericsSort,
3822
4417
  UserTypes,
3823
4418
  addAmounts,
4419
+ addressPlaceKeys,
3824
4420
  adyenLegalEntityRequiresStateOrProvince,
3825
4421
  adyenRequiresJobTitle,
3826
4422
  adyenStoreRequiresStateOrProvince,
@@ -3830,11 +4426,13 @@ export {
3830
4426
  ancestorChain,
3831
4427
  applyAssignment,
3832
4428
  assertUnitSane,
4429
+ automaticTaxTableVersion,
3833
4430
  availableIn,
3834
4431
  baseFor,
3835
4432
  baseFulfillmentDefinitions,
3836
4433
  baseOf,
3837
4434
  basePaymentDefinitions,
4435
+ buildAutomaticTaxTable,
3838
4436
  buildAvailability,
3839
4437
  buildGrid,
3840
4438
  buildOrderContext,
@@ -3901,31 +4499,48 @@ export {
3901
4499
  isSystemFamilyCode,
3902
4500
  isValidQuantity,
3903
4501
  isWhole,
4502
+ lineStockMoves,
4503
+ listCountries,
4504
+ listProvinces,
4505
+ listShippingCountries,
3904
4506
  mapToLegacyStatus,
3905
4507
  maxPrecisionFor,
3906
4508
  mergeFragment,
3907
4509
  modifiersSellable,
3908
4510
  multiplyAmount,
4511
+ normalizeAddress,
4512
+ normalizeCityKey,
4513
+ normalizeCountry,
3909
4514
  normalizeMongoIdString,
4515
+ normalizePostCode,
4516
+ normalizeProvince,
3910
4517
  occupancyIn,
3911
4518
  orderAssignments,
3912
4519
  parseAmountToMinorUnits,
3913
4520
  parseCurrencyCode,
3914
4521
  parseStripeCurrencyCode,
4522
+ placeKey,
3915
4523
  planWindow,
3916
4524
  poolDemand,
3917
4525
  poolOf,
3918
4526
  poolShortfall,
3919
4527
  poolStockAt,
4528
+ postCodeMatchesProvince,
3920
4529
  presentAt,
4530
+ priceForTotal,
4531
+ provincesForPostCode,
4532
+ registrationPlacesByKind,
3921
4533
  removeFragment,
3922
4534
  resolveFamily,
3923
4535
  resolveModifiersForProduct,
4536
+ resolveShipping,
3924
4537
  resolveTemplate,
3925
4538
  resolveUnit,
3926
4539
  roundToPrecision,
3927
4540
  sameFamily,
3928
4541
  setOrderState,
4542
+ sha1Hex,
4543
+ shipsToCountry,
3929
4544
  shopDayKey,
3930
4545
  shopDayRange,
3931
4546
  signReportForDisplay,
@@ -3937,6 +4552,7 @@ export {
3937
4552
  validateConfig,
3938
4553
  validateFragmentCompatibility,
3939
4554
  validateOrderStatuses,
4555
+ validateShippingZone,
3940
4556
  violatesFinancialInvariant,
3941
4557
  windowEndsAt,
3942
4558
  withinPresence