@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.js
CHANGED
|
@@ -36,6 +36,7 @@ __export(index_exports, {
|
|
|
36
36
|
BookingResourceStatus: () => BookingResourceStatus,
|
|
37
37
|
BookingRulesError: () => BookingRulesError,
|
|
38
38
|
BookingType: () => BookingType,
|
|
39
|
+
CANADA_PROVINCES: () => CANADA_PROVINCES,
|
|
39
40
|
CONDITION_OPERATORS: () => CONDITION_OPERATORS,
|
|
40
41
|
COUNTRY_CURRENCIES: () => COUNTRY_CURRENCIES,
|
|
41
42
|
CURRENCY_CONFIG: () => CURRENCY_CONFIG,
|
|
@@ -52,6 +53,7 @@ __export(index_exports, {
|
|
|
52
53
|
DualWriteStrategy: () => DualWriteStrategy,
|
|
53
54
|
EUFixedRates: () => EUFixedRates,
|
|
54
55
|
EUROPE: () => EUROPE,
|
|
56
|
+
EVERYWHERE_KEY: () => EVERYWHERE_KEY,
|
|
55
57
|
EXPENSE_DEFAULT_CATEGORIES: () => EXPENSE_DEFAULT_CATEGORIES,
|
|
56
58
|
EXPENSE_NAME_MAX_LENGTH: () => EXPENSE_NAME_MAX_LENGTH,
|
|
57
59
|
EXPENSE_PAYMENT_METHOD_PRESETS: () => EXPENSE_PAYMENT_METHOD_PRESETS,
|
|
@@ -76,6 +78,7 @@ __export(index_exports, {
|
|
|
76
78
|
OtherFixedRates: () => OtherFixedRates,
|
|
77
79
|
OwnerType: () => OwnerType,
|
|
78
80
|
PATH_MODES: () => PATH_MODES,
|
|
81
|
+
PAYMENT_CHANNELS: () => PAYMENT_CHANNELS,
|
|
79
82
|
PAYMENT_STATES: () => PAYMENT_STATES,
|
|
80
83
|
POS_VALID_INITIAL_STATES: () => POS_VALID_INITIAL_STATES,
|
|
81
84
|
PaymentMethod: () => PaymentMethod,
|
|
@@ -85,6 +88,7 @@ __export(index_exports, {
|
|
|
85
88
|
PricingLevel: () => PricingLevel,
|
|
86
89
|
PricingPlanEnum: () => PricingPlanEnum,
|
|
87
90
|
PricingRegionEnum: () => PricingRegionEnum,
|
|
91
|
+
ProcessorType: () => ProcessorType,
|
|
88
92
|
ProductStatus: () => ProductStatus,
|
|
89
93
|
ProductType: () => ProductType,
|
|
90
94
|
PublicationAvailability: () => PublicationAvailability,
|
|
@@ -103,6 +107,12 @@ __export(index_exports, {
|
|
|
103
107
|
SYSTEM_FAMILY_IDS: () => SYSTEM_FAMILY_IDS,
|
|
104
108
|
SYSTEM_UNITS: () => SYSTEM_UNITS,
|
|
105
109
|
SYSTEM_UNIT_IDS: () => SYSTEM_UNIT_IDS,
|
|
110
|
+
ShippingChannel: () => ShippingChannel,
|
|
111
|
+
ShippingNoOptionReason: () => ShippingNoOptionReason,
|
|
112
|
+
ShippingOptionType: () => ShippingOptionType,
|
|
113
|
+
ShippingRateType: () => ShippingRateType,
|
|
114
|
+
ShippingZoneError: () => ShippingZoneError,
|
|
115
|
+
ShippingZoneKind: () => ShippingZoneKind,
|
|
106
116
|
StationStatus: () => StationStatus,
|
|
107
117
|
StripeCurrencyCode: () => StripeCurrencyCode,
|
|
108
118
|
StripeStatus: () => StripeStatus,
|
|
@@ -110,6 +120,7 @@ __export(index_exports, {
|
|
|
110
120
|
TopMetericsSort: () => TopMetericsSort,
|
|
111
121
|
UserTypes: () => UserTypes,
|
|
112
122
|
addAmounts: () => addAmounts,
|
|
123
|
+
addressPlaceKeys: () => addressPlaceKeys,
|
|
113
124
|
adyenLegalEntityRequiresStateOrProvince: () => adyenLegalEntityRequiresStateOrProvince,
|
|
114
125
|
adyenRequiresJobTitle: () => adyenRequiresJobTitle,
|
|
115
126
|
adyenStoreRequiresStateOrProvince: () => adyenStoreRequiresStateOrProvince,
|
|
@@ -188,25 +199,37 @@ __export(index_exports, {
|
|
|
188
199
|
isSystemFamilyCode: () => isSystemFamilyCode,
|
|
189
200
|
isValidQuantity: () => isValidQuantity,
|
|
190
201
|
isWhole: () => isWhole,
|
|
202
|
+
listCountries: () => listCountries,
|
|
203
|
+
listProvinces: () => listProvinces,
|
|
191
204
|
mapToLegacyStatus: () => mapToLegacyStatus,
|
|
192
205
|
maxPrecisionFor: () => maxPrecisionFor,
|
|
193
206
|
mergeFragment: () => mergeFragment,
|
|
194
207
|
modifiersSellable: () => modifiersSellable,
|
|
195
208
|
multiplyAmount: () => multiplyAmount,
|
|
209
|
+
normalizeAddress: () => normalizeAddress,
|
|
210
|
+
normalizeCityKey: () => normalizeCityKey,
|
|
211
|
+
normalizeCountry: () => normalizeCountry,
|
|
196
212
|
normalizeMongoIdString: () => normalizeMongoIdString,
|
|
213
|
+
normalizePostCode: () => normalizePostCode,
|
|
214
|
+
normalizeProvince: () => normalizeProvince,
|
|
197
215
|
occupancyIn: () => occupancyIn,
|
|
198
216
|
parseAmountToMinorUnits: () => parseAmountToMinorUnits,
|
|
199
217
|
parseCurrencyCode: () => parseCurrencyCode,
|
|
200
218
|
parseStripeCurrencyCode: () => parseStripeCurrencyCode,
|
|
219
|
+
placeKey: () => placeKey,
|
|
201
220
|
planWindow: () => planWindow,
|
|
202
221
|
poolDemand: () => poolDemand,
|
|
203
222
|
poolOf: () => poolOf,
|
|
204
223
|
poolShortfall: () => poolShortfall,
|
|
205
224
|
poolStockAt: () => poolStockAt,
|
|
225
|
+
postCodeMatchesProvince: () => postCodeMatchesProvince,
|
|
206
226
|
presentAt: () => presentAt,
|
|
227
|
+
priceForTotal: () => priceForTotal,
|
|
228
|
+
provincesForPostCode: () => provincesForPostCode,
|
|
207
229
|
removeFragment: () => removeFragment,
|
|
208
230
|
resolveFamily: () => resolveFamily,
|
|
209
231
|
resolveModifiersForProduct: () => resolveModifiersForProduct,
|
|
232
|
+
resolveShipping: () => resolveShipping,
|
|
210
233
|
resolveTemplate: () => resolveTemplate,
|
|
211
234
|
resolveUnit: () => resolveUnit,
|
|
212
235
|
roundToPrecision: () => roundToPrecision,
|
|
@@ -223,6 +246,7 @@ __export(index_exports, {
|
|
|
223
246
|
validateConfig: () => validateConfig,
|
|
224
247
|
validateFragmentCompatibility: () => validateFragmentCompatibility,
|
|
225
248
|
validateOrderStatuses: () => validateOrderStatuses,
|
|
249
|
+
validateShippingZone: () => validateShippingZone,
|
|
226
250
|
violatesFinancialInvariant: () => violatesFinancialInvariant,
|
|
227
251
|
windowEndsAt: () => windowEndsAt,
|
|
228
252
|
withinPresence: () => withinPresence
|
|
@@ -431,6 +455,7 @@ var OrderPlatform = /* @__PURE__ */ ((OrderPlatform2) => {
|
|
|
431
455
|
OrderPlatform2["POS"] = "in-store";
|
|
432
456
|
OrderPlatform2["WOO_COMMERCE"] = "woo-commerce";
|
|
433
457
|
OrderPlatform2["PUBLIC_API"] = "public-api";
|
|
458
|
+
OrderPlatform2["ONLINE_STORE"] = "online-store";
|
|
434
459
|
return OrderPlatform2;
|
|
435
460
|
})(OrderPlatform || {});
|
|
436
461
|
var CustomerPlatform = /* @__PURE__ */ ((CustomerPlatform2) => {
|
|
@@ -717,6 +742,50 @@ var ResourceAvailabilityState = /* @__PURE__ */ ((ResourceAvailabilityState2) =>
|
|
|
717
742
|
return ResourceAvailabilityState2;
|
|
718
743
|
})(ResourceAvailabilityState || {});
|
|
719
744
|
|
|
745
|
+
// enums/shipping.enum.ts
|
|
746
|
+
var ShippingZoneKind = /* @__PURE__ */ ((ShippingZoneKind2) => {
|
|
747
|
+
ShippingZoneKind2["COUNTRY"] = "country";
|
|
748
|
+
ShippingZoneKind2["PROVINCE"] = "province";
|
|
749
|
+
ShippingZoneKind2["CITY"] = "city";
|
|
750
|
+
ShippingZoneKind2["EVERYWHERE"] = "everywhere";
|
|
751
|
+
return ShippingZoneKind2;
|
|
752
|
+
})(ShippingZoneKind || {});
|
|
753
|
+
var ShippingOptionType = /* @__PURE__ */ ((ShippingOptionType2) => {
|
|
754
|
+
ShippingOptionType2["SHIP"] = "ship";
|
|
755
|
+
ShippingOptionType2["PICKUP"] = "pickup";
|
|
756
|
+
return ShippingOptionType2;
|
|
757
|
+
})(ShippingOptionType || {});
|
|
758
|
+
var ShippingRateType = /* @__PURE__ */ ((ShippingRateType2) => {
|
|
759
|
+
ShippingRateType2["FLAT"] = "flat";
|
|
760
|
+
return ShippingRateType2;
|
|
761
|
+
})(ShippingRateType || {});
|
|
762
|
+
var ShippingChannel = /* @__PURE__ */ ((ShippingChannel2) => {
|
|
763
|
+
ShippingChannel2["WEB"] = "web";
|
|
764
|
+
ShippingChannel2["POS"] = "pos";
|
|
765
|
+
return ShippingChannel2;
|
|
766
|
+
})(ShippingChannel || {});
|
|
767
|
+
var ShippingNoOptionReason = /* @__PURE__ */ ((ShippingNoOptionReason2) => {
|
|
768
|
+
ShippingNoOptionReason2["INCOMPLETE"] = "INCOMPLETE";
|
|
769
|
+
ShippingNoOptionReason2["ADDRESS_MISMATCH"] = "ADDRESS_MISMATCH";
|
|
770
|
+
ShippingNoOptionReason2["NO_COVERAGE"] = "NO_COVERAGE";
|
|
771
|
+
ShippingNoOptionReason2["BLOCKED"] = "BLOCKED";
|
|
772
|
+
ShippingNoOptionReason2["NO_OPTION"] = "NO_OPTION";
|
|
773
|
+
return ShippingNoOptionReason2;
|
|
774
|
+
})(ShippingNoOptionReason || {});
|
|
775
|
+
var ShippingZoneError = /* @__PURE__ */ ((ShippingZoneError2) => {
|
|
776
|
+
ShippingZoneError2["NO_PLACES"] = "NO_PLACES";
|
|
777
|
+
ShippingZoneError2["INVALID_PLACE"] = "INVALID_PLACE";
|
|
778
|
+
ShippingZoneError2["DUPLICATE_PLACE"] = "DUPLICATE_PLACE";
|
|
779
|
+
ShippingZoneError2["NO_WEBSITE_OPTION"] = "NO_WEBSITE_OPTION";
|
|
780
|
+
ShippingZoneError2["INVALID_PRICE"] = "INVALID_PRICE";
|
|
781
|
+
ShippingZoneError2["INVALID_DAYS"] = "INVALID_DAYS";
|
|
782
|
+
ShippingZoneError2["INVALID_TIERS"] = "INVALID_TIERS";
|
|
783
|
+
ShippingZoneError2["NO_CHANNEL"] = "NO_CHANNEL";
|
|
784
|
+
ShippingZoneError2["PICKUP_WITHOUT_STORE"] = "PICKUP_WITHOUT_STORE";
|
|
785
|
+
ShippingZoneError2["MISSING_NAME"] = "MISSING_NAME";
|
|
786
|
+
return ShippingZoneError2;
|
|
787
|
+
})(ShippingZoneError || {});
|
|
788
|
+
|
|
720
789
|
// utils/currency.util.ts
|
|
721
790
|
var CURRENCY_CONFIG = {
|
|
722
791
|
// Major currencies with 2 decimal places
|
|
@@ -3795,6 +3864,321 @@ function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }
|
|
|
3795
3864
|
}
|
|
3796
3865
|
var holdExpiresAt = (rule, now) => new Date(now.getTime() + (rule.window.holdMinutes ?? DEFAULT_HOLD_MINUTES) * 6e4);
|
|
3797
3866
|
|
|
3867
|
+
// shipping/fold-text.ts
|
|
3868
|
+
function foldText(value) {
|
|
3869
|
+
return value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/&/g, " and ").replace(/[^a-z0-9]+/g, " ").trim();
|
|
3870
|
+
}
|
|
3871
|
+
|
|
3872
|
+
// shipping/countries.ts
|
|
3873
|
+
var NOT_COUNTRIES = /* @__PURE__ */ new Set(["AC", "CP", "CQ", "DG", "EA", "EU", "EZ", "IC", "QO", "TA", "UN", "XA", "XB", "ZZ"]);
|
|
3874
|
+
var ALIASES = {
|
|
3875
|
+
canada: "CA",
|
|
3876
|
+
"united states": "US",
|
|
3877
|
+
usa: "US",
|
|
3878
|
+
"united states of america": "US",
|
|
3879
|
+
uk: "GB",
|
|
3880
|
+
"great britain": "GB",
|
|
3881
|
+
england: "GB",
|
|
3882
|
+
uae: "AE",
|
|
3883
|
+
can: "CA",
|
|
3884
|
+
mex: "MX",
|
|
3885
|
+
aus: "AU",
|
|
3886
|
+
gbr: "GB"
|
|
3887
|
+
};
|
|
3888
|
+
var NAME_LOCALES = ["en", "fr"];
|
|
3889
|
+
function regionNames(locale) {
|
|
3890
|
+
try {
|
|
3891
|
+
return new Intl.DisplayNames([locale], { type: "region", fallback: "none" });
|
|
3892
|
+
} catch {
|
|
3893
|
+
return null;
|
|
3894
|
+
}
|
|
3895
|
+
}
|
|
3896
|
+
function canonicalCode(code) {
|
|
3897
|
+
try {
|
|
3898
|
+
return new Intl.Locale(`und-${code}`).maximize().region ?? code;
|
|
3899
|
+
} catch {
|
|
3900
|
+
return code;
|
|
3901
|
+
}
|
|
3902
|
+
}
|
|
3903
|
+
function allCodes() {
|
|
3904
|
+
const names = regionNames("en");
|
|
3905
|
+
if (!names) return [];
|
|
3906
|
+
const codes2 = [];
|
|
3907
|
+
for (let a = 65; a <= 90; a++) {
|
|
3908
|
+
for (let b = 65; b <= 90; b++) {
|
|
3909
|
+
const code = String.fromCharCode(a, b);
|
|
3910
|
+
if (!NOT_COUNTRIES.has(code) && names.of(code) && canonicalCode(code) === code) codes2.push(code);
|
|
3911
|
+
}
|
|
3912
|
+
}
|
|
3913
|
+
return codes2;
|
|
3914
|
+
}
|
|
3915
|
+
var lookup = null;
|
|
3916
|
+
var codes = null;
|
|
3917
|
+
function countryCodes() {
|
|
3918
|
+
codes ??= allCodes();
|
|
3919
|
+
return codes;
|
|
3920
|
+
}
|
|
3921
|
+
function countryLookup() {
|
|
3922
|
+
if (lookup) return lookup;
|
|
3923
|
+
lookup = new Map(Object.entries(ALIASES));
|
|
3924
|
+
for (const locale of NAME_LOCALES) {
|
|
3925
|
+
const names = regionNames(locale);
|
|
3926
|
+
if (!names) continue;
|
|
3927
|
+
for (const code of countryCodes()) {
|
|
3928
|
+
const name = names.of(code);
|
|
3929
|
+
if (name) lookup.set(foldText(name), code);
|
|
3930
|
+
}
|
|
3931
|
+
}
|
|
3932
|
+
return lookup;
|
|
3933
|
+
}
|
|
3934
|
+
function normalizeCountry(value) {
|
|
3935
|
+
const text = (value ?? "").trim();
|
|
3936
|
+
if (!text) return void 0;
|
|
3937
|
+
const upper = text.toUpperCase();
|
|
3938
|
+
if (upper.length === 2) {
|
|
3939
|
+
if (NOT_COUNTRIES.has(upper)) return void 0;
|
|
3940
|
+
if (countryCodes().length === 0) return /^[A-Z]{2}$/.test(upper) ? upper : void 0;
|
|
3941
|
+
const code = canonicalCode(upper);
|
|
3942
|
+
if (countryCodes().includes(code)) return code;
|
|
3943
|
+
}
|
|
3944
|
+
return countryLookup().get(foldText(text));
|
|
3945
|
+
}
|
|
3946
|
+
function listCountries(locale = "en") {
|
|
3947
|
+
const names = regionNames(locale) ?? regionNames("en");
|
|
3948
|
+
return countryCodes().map((code) => ({ code, name: names?.of(code) ?? code })).sort((a, b) => a.name.localeCompare(b.name, locale));
|
|
3949
|
+
}
|
|
3950
|
+
|
|
3951
|
+
// shipping/provinces.ts
|
|
3952
|
+
var CANADA_PROVINCES = [
|
|
3953
|
+
{ code: "AB", name: "Alberta", nameFr: "Alberta", postalLetters: ["T"] },
|
|
3954
|
+
{ code: "BC", name: "British Columbia", nameFr: "Colombie-Britannique", postalLetters: ["V"] },
|
|
3955
|
+
{ code: "MB", name: "Manitoba", nameFr: "Manitoba", postalLetters: ["R"] },
|
|
3956
|
+
{ code: "NB", name: "New Brunswick", nameFr: "Nouveau-Brunswick", postalLetters: ["E"] },
|
|
3957
|
+
{
|
|
3958
|
+
code: "NL",
|
|
3959
|
+
name: "Newfoundland and Labrador",
|
|
3960
|
+
nameFr: "Terre-Neuve-et-Labrador",
|
|
3961
|
+
postalLetters: ["A"],
|
|
3962
|
+
aliases: ["NF", "LB", "Newfoundland", "Labrador"]
|
|
3963
|
+
},
|
|
3964
|
+
{ code: "NS", name: "Nova Scotia", nameFr: "Nouvelle-\xC9cosse", postalLetters: ["B"] },
|
|
3965
|
+
{ code: "NT", name: "Northwest Territories", nameFr: "Territoires du Nord-Ouest", postalLetters: ["X"] },
|
|
3966
|
+
{ code: "NU", name: "Nunavut", nameFr: "Nunavut", postalLetters: ["X"] },
|
|
3967
|
+
{ code: "ON", name: "Ontario", nameFr: "Ontario", postalLetters: ["K", "L", "M", "N", "P"] },
|
|
3968
|
+
{
|
|
3969
|
+
code: "PE",
|
|
3970
|
+
name: "Prince Edward Island",
|
|
3971
|
+
nameFr: "\xCEle-du-Prince-\xC9douard",
|
|
3972
|
+
postalLetters: ["C"],
|
|
3973
|
+
aliases: ["PEI"]
|
|
3974
|
+
},
|
|
3975
|
+
{ code: "QC", name: "Quebec", nameFr: "Qu\xE9bec", postalLetters: ["G", "H", "J"], aliases: ["PQ"] },
|
|
3976
|
+
{ code: "SK", name: "Saskatchewan", nameFr: "Saskatchewan", postalLetters: ["S"] },
|
|
3977
|
+
{ code: "YT", name: "Yukon", nameFr: "Yukon", postalLetters: ["Y"], aliases: ["YK"] }
|
|
3978
|
+
];
|
|
3979
|
+
var PROVINCES_BY_COUNTRY = { CA: CANADA_PROVINCES };
|
|
3980
|
+
var lookups = /* @__PURE__ */ new Map();
|
|
3981
|
+
function provinceLookup(country) {
|
|
3982
|
+
const provinces = PROVINCES_BY_COUNTRY[country];
|
|
3983
|
+
if (!provinces) return void 0;
|
|
3984
|
+
let lookup2 = lookups.get(country);
|
|
3985
|
+
if (!lookup2) {
|
|
3986
|
+
lookup2 = /* @__PURE__ */ new Map();
|
|
3987
|
+
for (const p of provinces) {
|
|
3988
|
+
for (const label of [p.code, p.name, p.nameFr, ...p.aliases ?? []]) lookup2.set(foldText(label), p.code);
|
|
3989
|
+
}
|
|
3990
|
+
lookups.set(country, lookup2);
|
|
3991
|
+
}
|
|
3992
|
+
return lookup2;
|
|
3993
|
+
}
|
|
3994
|
+
function normalizeProvince(country, value) {
|
|
3995
|
+
if (!country || !value?.trim()) return void 0;
|
|
3996
|
+
return provinceLookup(country)?.get(foldText(value));
|
|
3997
|
+
}
|
|
3998
|
+
function listProvinces(country) {
|
|
3999
|
+
return PROVINCES_BY_COUNTRY[country] ?? [];
|
|
4000
|
+
}
|
|
4001
|
+
function provincesForPostCode(country, postCode) {
|
|
4002
|
+
const letter = postCode?.charAt(0);
|
|
4003
|
+
if (!country || !letter) return [];
|
|
4004
|
+
return listProvinces(country).filter((p) => p.postalLetters.includes(letter)).map((p) => p.code);
|
|
4005
|
+
}
|
|
4006
|
+
|
|
4007
|
+
// shipping/normalize.ts
|
|
4008
|
+
var EVERYWHERE_KEY = "*";
|
|
4009
|
+
function normalizeCityKey(value) {
|
|
4010
|
+
const words = foldText(value ?? "").split(" ").filter(Boolean).map((word) => word === "saint" ? "st" : word === "sainte" ? "ste" : word);
|
|
4011
|
+
return words.length ? words.join("") : void 0;
|
|
4012
|
+
}
|
|
4013
|
+
function normalizePostCode(value) {
|
|
4014
|
+
const compact = (value ?? "").replace(/[^0-9a-z]/gi, "").toUpperCase();
|
|
4015
|
+
return compact || void 0;
|
|
4016
|
+
}
|
|
4017
|
+
function normalizeAddress(address) {
|
|
4018
|
+
if (!address) return {};
|
|
4019
|
+
const country = normalizeCountry(address.country);
|
|
4020
|
+
const postCode = normalizePostCode(address.postCode ?? address.postalCode ?? address.zip);
|
|
4021
|
+
const fromPostCode = provincesForPostCode(country, postCode);
|
|
4022
|
+
const province = normalizeProvince(country, address.state ?? address.province) ?? (fromPostCode.length === 1 ? fromPostCode[0] : void 0);
|
|
4023
|
+
return { country, province, cityKey: normalizeCityKey(address.city), postCode };
|
|
4024
|
+
}
|
|
4025
|
+
function postCodeMatchesProvince(address) {
|
|
4026
|
+
const candidates = provincesForPostCode(address.country, address.postCode);
|
|
4027
|
+
if (!address.province || candidates.length === 0) return true;
|
|
4028
|
+
return candidates.includes(address.province);
|
|
4029
|
+
}
|
|
4030
|
+
function placeKey(place) {
|
|
4031
|
+
const country = normalizeCountry(place.country);
|
|
4032
|
+
if (!country) return void 0;
|
|
4033
|
+
if (!place.province) return country;
|
|
4034
|
+
const province = normalizeProvince(country, place.province);
|
|
4035
|
+
if (!province) return void 0;
|
|
4036
|
+
if (!place.city) return `${country}-${province}`;
|
|
4037
|
+
const city = normalizeCityKey(place.city);
|
|
4038
|
+
return city ? `${country}-${province}/${city}` : void 0;
|
|
4039
|
+
}
|
|
4040
|
+
function addressPlaceKeys(address) {
|
|
4041
|
+
const keys = [];
|
|
4042
|
+
if (address.country && address.province && address.cityKey) {
|
|
4043
|
+
keys.push(`${address.country}-${address.province}/${address.cityKey}`);
|
|
4044
|
+
}
|
|
4045
|
+
if (address.country && address.province) keys.push(`${address.country}-${address.province}`);
|
|
4046
|
+
if (address.country) keys.push(address.country);
|
|
4047
|
+
keys.push(EVERYWHERE_KEY);
|
|
4048
|
+
return keys;
|
|
4049
|
+
}
|
|
4050
|
+
|
|
4051
|
+
// shipping/resolve.ts
|
|
4052
|
+
function resolveShipping({ zones, address, itemsTotal, channel }) {
|
|
4053
|
+
const shipsToCountries = countriesShippedTo(zones);
|
|
4054
|
+
const none = (reason, zone2) => ({
|
|
4055
|
+
zoneId: zone2?.id ?? null,
|
|
4056
|
+
options: [],
|
|
4057
|
+
reason,
|
|
4058
|
+
message: zone2?.message?.trim() || null,
|
|
4059
|
+
shipsToCountries
|
|
4060
|
+
});
|
|
4061
|
+
const normalized = normalizeAddress(address);
|
|
4062
|
+
if (!normalized.country) return none("INCOMPLETE" /* INCOMPLETE */);
|
|
4063
|
+
if (!postCodeMatchesProvince(normalized)) return none("ADDRESS_MISMATCH" /* ADDRESS_MISMATCH */);
|
|
4064
|
+
const zone = findZone(zones, addressPlaceKeys(normalized));
|
|
4065
|
+
if (!zone) return none("NO_COVERAGE" /* NO_COVERAGE */);
|
|
4066
|
+
const offered = zone.options.filter((option) => isOffered(option, zone, channel));
|
|
4067
|
+
if (offered.length === 0) {
|
|
4068
|
+
return none(zone.ships ? "NO_OPTION" /* NO_OPTION */ : "BLOCKED" /* BLOCKED */, zone);
|
|
4069
|
+
}
|
|
4070
|
+
const quotes = offered.map((option) => quote(option, zone.id, itemsTotal));
|
|
4071
|
+
const ship = quotes.filter((q) => q.type === "ship" /* SHIP */).sort((a, b) => a.amount - b.amount);
|
|
4072
|
+
const pickup = quotes.filter((q) => q.type === "pickup" /* PICKUP */).sort((a, b) => a.amount - b.amount);
|
|
4073
|
+
return {
|
|
4074
|
+
zoneId: zone.id,
|
|
4075
|
+
options: [...ship, ...pickup],
|
|
4076
|
+
reason: null,
|
|
4077
|
+
message: zone.ships ? null : zone.message?.trim() || null,
|
|
4078
|
+
shipsToCountries
|
|
4079
|
+
};
|
|
4080
|
+
}
|
|
4081
|
+
function findZone(zones, keys) {
|
|
4082
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
4083
|
+
for (const zone of zones) {
|
|
4084
|
+
for (const key of zoneKeys(zone)) if (!byKey.has(key)) byKey.set(key, zone);
|
|
4085
|
+
}
|
|
4086
|
+
for (const key of keys) {
|
|
4087
|
+
const zone = byKey.get(key);
|
|
4088
|
+
if (zone) return zone;
|
|
4089
|
+
}
|
|
4090
|
+
return void 0;
|
|
4091
|
+
}
|
|
4092
|
+
function zoneKeys(zone) {
|
|
4093
|
+
if (zone.kind === "everywhere" /* EVERYWHERE */) return [EVERYWHERE_KEY];
|
|
4094
|
+
return zone.places.map(placeKey).filter((key) => Boolean(key));
|
|
4095
|
+
}
|
|
4096
|
+
function isOffered(option, zone, channel) {
|
|
4097
|
+
if (!option.channels.some((c) => c === channel)) return false;
|
|
4098
|
+
if (option.type === "pickup" /* PICKUP */) return channel !== "pos" /* POS */;
|
|
4099
|
+
return zone.ships;
|
|
4100
|
+
}
|
|
4101
|
+
function priceForTotal(option, itemsTotal) {
|
|
4102
|
+
const tiers = [...option.priceByTotal ?? []].sort((a, b) => a.from - b.from);
|
|
4103
|
+
let price = option.price;
|
|
4104
|
+
for (const tier of tiers) if (itemsTotal >= tier.from) price = tier.price;
|
|
4105
|
+
if (option.freeOver != null && itemsTotal >= option.freeOver) return 0;
|
|
4106
|
+
return price;
|
|
4107
|
+
}
|
|
4108
|
+
function quote(option, zoneId, itemsTotal) {
|
|
4109
|
+
const amount = priceForTotal(option, itemsTotal);
|
|
4110
|
+
const freeOver = option.freeOver ?? null;
|
|
4111
|
+
return {
|
|
4112
|
+
optionId: option.id,
|
|
4113
|
+
zoneId,
|
|
4114
|
+
type: option.type,
|
|
4115
|
+
name: option.name?.trim() || null,
|
|
4116
|
+
amount,
|
|
4117
|
+
amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
|
|
4118
|
+
minDays: option.minDays ?? null,
|
|
4119
|
+
maxDays: option.maxDays ?? null,
|
|
4120
|
+
outletId: option.outletId ?? null
|
|
4121
|
+
};
|
|
4122
|
+
}
|
|
4123
|
+
function countriesShippedTo(zones) {
|
|
4124
|
+
const countries = /* @__PURE__ */ new Set();
|
|
4125
|
+
for (const zone of zones) {
|
|
4126
|
+
if (!zone.ships) continue;
|
|
4127
|
+
for (const key of zoneKeys(zone)) if (key !== EVERYWHERE_KEY) countries.add(key.slice(0, 2));
|
|
4128
|
+
}
|
|
4129
|
+
return [...countries].sort();
|
|
4130
|
+
}
|
|
4131
|
+
|
|
4132
|
+
// shipping/validate.ts
|
|
4133
|
+
function validateShippingZone(zone) {
|
|
4134
|
+
const problems = [...placeProblems(zone)];
|
|
4135
|
+
for (const option of zone.options) problems.push(...optionProblems(option));
|
|
4136
|
+
const reachesWebsite = zone.options.some((option) => option.channels.includes("web" /* WEB */));
|
|
4137
|
+
if (zone.ships && !reachesWebsite) problems.push({ code: "NO_WEBSITE_OPTION" /* NO_WEBSITE_OPTION */ });
|
|
4138
|
+
return problems;
|
|
4139
|
+
}
|
|
4140
|
+
function placeProblems(zone) {
|
|
4141
|
+
if (zone.kind === "everywhere" /* EVERYWHERE */) {
|
|
4142
|
+
return zone.places.length ? [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }] : [];
|
|
4143
|
+
}
|
|
4144
|
+
if (zone.places.length === 0) return [{ code: "NO_PLACES" /* NO_PLACES */ }];
|
|
4145
|
+
if (!zone.places.every((place) => fitsKind(place, zone.kind))) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
|
|
4146
|
+
const keys = zone.places.map(placeKey);
|
|
4147
|
+
if (keys.some((key) => !key)) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
|
|
4148
|
+
if (new Set(keys).size !== keys.length) return [{ code: "DUPLICATE_PLACE" /* DUPLICATE_PLACE */ }];
|
|
4149
|
+
return [];
|
|
4150
|
+
}
|
|
4151
|
+
function fitsKind(place, kind) {
|
|
4152
|
+
const hasProvince = Boolean(place.province?.trim());
|
|
4153
|
+
const hasCity = Boolean(place.city?.trim());
|
|
4154
|
+
if (kind === "country" /* COUNTRY */) return !hasProvince && !hasCity;
|
|
4155
|
+
if (kind === "province" /* PROVINCE */) return hasProvince && !hasCity;
|
|
4156
|
+
if (kind === "city" /* CITY */) return hasProvince && hasCity;
|
|
4157
|
+
return false;
|
|
4158
|
+
}
|
|
4159
|
+
var isAmount = (value) => Number.isInteger(value) && value >= 0;
|
|
4160
|
+
var isDays = (value) => value == null || isAmount(value);
|
|
4161
|
+
function optionProblems(option) {
|
|
4162
|
+
const problems = [];
|
|
4163
|
+
const isPickup = option.type === "pickup" /* PICKUP */;
|
|
4164
|
+
if (!isAmount(option.price) || option.freeOver != null && !isAmount(option.freeOver)) {
|
|
4165
|
+
problems.push("INVALID_PRICE" /* INVALID_PRICE */);
|
|
4166
|
+
}
|
|
4167
|
+
if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
|
|
4168
|
+
if (!isDays(option.minDays) || !isDays(option.maxDays) || (option.minDays ?? 0) > (option.maxDays ?? Infinity)) {
|
|
4169
|
+
problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4170
|
+
}
|
|
4171
|
+
if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
|
|
4172
|
+
if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
|
|
4173
|
+
if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
|
|
4174
|
+
return problems.map((code) => ({ code, optionId: option.id }));
|
|
4175
|
+
}
|
|
4176
|
+
function tiersAreValid(option) {
|
|
4177
|
+
const tiers = option.priceByTotal ?? [];
|
|
4178
|
+
const froms = tiers.map((tier) => tier.from);
|
|
4179
|
+
return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
|
|
4180
|
+
}
|
|
4181
|
+
|
|
3798
4182
|
// constants/adyen.constants.ts
|
|
3799
4183
|
var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
|
|
3800
4184
|
function isAdyenRolloutCountry(alpha2) {
|
|
@@ -3844,6 +4228,27 @@ var BNPL_SKIP_REASON = {
|
|
|
3844
4228
|
NO_BUSINESS_LINE: "no_business_line"
|
|
3845
4229
|
};
|
|
3846
4230
|
|
|
4231
|
+
// pos-types/active/ProcessorType.ts
|
|
4232
|
+
var ProcessorType = /* @__PURE__ */ ((ProcessorType2) => {
|
|
4233
|
+
ProcessorType2["FINAL_PAY"] = "Terminal";
|
|
4234
|
+
ProcessorType2["TAP_TO_PAY"] = "TapToPay";
|
|
4235
|
+
ProcessorType2["MOTO"] = "Moto";
|
|
4236
|
+
ProcessorType2["CLOUD"] = "Cloud";
|
|
4237
|
+
ProcessorType2["BLUETOOTH"] = "Bluetooth";
|
|
4238
|
+
ProcessorType2["CASH"] = "Cash";
|
|
4239
|
+
ProcessorType2["CUSTOM_PAY"] = "CustomPay";
|
|
4240
|
+
ProcessorType2["VENDARA"] = "Vendara";
|
|
4241
|
+
ProcessorType2["REDEEM"] = "Redeem";
|
|
4242
|
+
ProcessorType2["INTEGRATION"] = "Integration";
|
|
4243
|
+
ProcessorType2["PAYMENT_LINK"] = "PaymentLink";
|
|
4244
|
+
ProcessorType2["ONLINE_PAYMENT"] = "OnlinePayment";
|
|
4245
|
+
ProcessorType2["EXTERNAL"] = "External";
|
|
4246
|
+
return ProcessorType2;
|
|
4247
|
+
})(ProcessorType || {});
|
|
4248
|
+
|
|
4249
|
+
// constants/payment-channel.constants.ts
|
|
4250
|
+
var PAYMENT_CHANNELS = ["inPerson", "online"];
|
|
4251
|
+
|
|
3847
4252
|
// constants/expense.constants.ts
|
|
3848
4253
|
var EXPENSE_PAYMENT_METHOD_PRESETS = [
|
|
3849
4254
|
"Cash",
|
|
@@ -3886,6 +4291,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
3886
4291
|
BookingResourceStatus,
|
|
3887
4292
|
BookingRulesError,
|
|
3888
4293
|
BookingType,
|
|
4294
|
+
CANADA_PROVINCES,
|
|
3889
4295
|
CONDITION_OPERATORS,
|
|
3890
4296
|
COUNTRY_CURRENCIES,
|
|
3891
4297
|
CURRENCY_CONFIG,
|
|
@@ -3902,6 +4308,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
3902
4308
|
DualWriteStrategy,
|
|
3903
4309
|
EUFixedRates,
|
|
3904
4310
|
EUROPE,
|
|
4311
|
+
EVERYWHERE_KEY,
|
|
3905
4312
|
EXPENSE_DEFAULT_CATEGORIES,
|
|
3906
4313
|
EXPENSE_NAME_MAX_LENGTH,
|
|
3907
4314
|
EXPENSE_PAYMENT_METHOD_PRESETS,
|
|
@@ -3926,6 +4333,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
3926
4333
|
OtherFixedRates,
|
|
3927
4334
|
OwnerType,
|
|
3928
4335
|
PATH_MODES,
|
|
4336
|
+
PAYMENT_CHANNELS,
|
|
3929
4337
|
PAYMENT_STATES,
|
|
3930
4338
|
POS_VALID_INITIAL_STATES,
|
|
3931
4339
|
PaymentMethod,
|
|
@@ -3935,6 +4343,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
3935
4343
|
PricingLevel,
|
|
3936
4344
|
PricingPlanEnum,
|
|
3937
4345
|
PricingRegionEnum,
|
|
4346
|
+
ProcessorType,
|
|
3938
4347
|
ProductStatus,
|
|
3939
4348
|
ProductType,
|
|
3940
4349
|
PublicationAvailability,
|
|
@@ -3953,6 +4362,12 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
3953
4362
|
SYSTEM_FAMILY_IDS,
|
|
3954
4363
|
SYSTEM_UNITS,
|
|
3955
4364
|
SYSTEM_UNIT_IDS,
|
|
4365
|
+
ShippingChannel,
|
|
4366
|
+
ShippingNoOptionReason,
|
|
4367
|
+
ShippingOptionType,
|
|
4368
|
+
ShippingRateType,
|
|
4369
|
+
ShippingZoneError,
|
|
4370
|
+
ShippingZoneKind,
|
|
3956
4371
|
StationStatus,
|
|
3957
4372
|
StripeCurrencyCode,
|
|
3958
4373
|
StripeStatus,
|
|
@@ -3960,6 +4375,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
3960
4375
|
TopMetericsSort,
|
|
3961
4376
|
UserTypes,
|
|
3962
4377
|
addAmounts,
|
|
4378
|
+
addressPlaceKeys,
|
|
3963
4379
|
adyenLegalEntityRequiresStateOrProvince,
|
|
3964
4380
|
adyenRequiresJobTitle,
|
|
3965
4381
|
adyenStoreRequiresStateOrProvince,
|
|
@@ -4038,25 +4454,37 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4038
4454
|
isSystemFamilyCode,
|
|
4039
4455
|
isValidQuantity,
|
|
4040
4456
|
isWhole,
|
|
4457
|
+
listCountries,
|
|
4458
|
+
listProvinces,
|
|
4041
4459
|
mapToLegacyStatus,
|
|
4042
4460
|
maxPrecisionFor,
|
|
4043
4461
|
mergeFragment,
|
|
4044
4462
|
modifiersSellable,
|
|
4045
4463
|
multiplyAmount,
|
|
4464
|
+
normalizeAddress,
|
|
4465
|
+
normalizeCityKey,
|
|
4466
|
+
normalizeCountry,
|
|
4046
4467
|
normalizeMongoIdString,
|
|
4468
|
+
normalizePostCode,
|
|
4469
|
+
normalizeProvince,
|
|
4047
4470
|
occupancyIn,
|
|
4048
4471
|
parseAmountToMinorUnits,
|
|
4049
4472
|
parseCurrencyCode,
|
|
4050
4473
|
parseStripeCurrencyCode,
|
|
4474
|
+
placeKey,
|
|
4051
4475
|
planWindow,
|
|
4052
4476
|
poolDemand,
|
|
4053
4477
|
poolOf,
|
|
4054
4478
|
poolShortfall,
|
|
4055
4479
|
poolStockAt,
|
|
4480
|
+
postCodeMatchesProvince,
|
|
4056
4481
|
presentAt,
|
|
4482
|
+
priceForTotal,
|
|
4483
|
+
provincesForPostCode,
|
|
4057
4484
|
removeFragment,
|
|
4058
4485
|
resolveFamily,
|
|
4059
4486
|
resolveModifiersForProduct,
|
|
4487
|
+
resolveShipping,
|
|
4060
4488
|
resolveTemplate,
|
|
4061
4489
|
resolveUnit,
|
|
4062
4490
|
roundToPrecision,
|
|
@@ -4073,6 +4501,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4073
4501
|
validateConfig,
|
|
4074
4502
|
validateFragmentCompatibility,
|
|
4075
4503
|
validateOrderStatuses,
|
|
4504
|
+
validateShippingZone,
|
|
4076
4505
|
violatesFinancialInvariant,
|
|
4077
4506
|
windowEndsAt,
|
|
4078
4507
|
withinPresence
|