@final-commerce/common 2.11.1-online.4 → 2.11.1-online.6
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 +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +31 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -4
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +6 -0
- package/dist/pos-types/index.d.ts +6 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4005,6 +4005,8 @@ function quote(option, zoneId, itemsTotal) {
|
|
|
4005
4005
|
amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
|
|
4006
4006
|
minDays: option.minDays ?? null,
|
|
4007
4007
|
maxDays: option.maxDays ?? null,
|
|
4008
|
+
minMinutes: option.minMinutes ?? null,
|
|
4009
|
+
maxMinutes: option.maxMinutes ?? null,
|
|
4008
4010
|
outletId: option.outletId ?? null
|
|
4009
4011
|
};
|
|
4010
4012
|
}
|
|
@@ -4019,6 +4021,21 @@ function countriesShippedTo(zones) {
|
|
|
4019
4021
|
return [...countries].sort();
|
|
4020
4022
|
}
|
|
4021
4023
|
|
|
4024
|
+
// shipping/time.ts
|
|
4025
|
+
function shippingDuration(minMinutes, maxMinutes) {
|
|
4026
|
+
const min = minMinutes ?? maxMinutes;
|
|
4027
|
+
const max = maxMinutes ?? minMinutes;
|
|
4028
|
+
if (min == null || max == null) return null;
|
|
4029
|
+
const wholeHours = max > 0 && min % 60 === 0 && max % 60 === 0;
|
|
4030
|
+
return wholeHours ? { unit: "hour", min: min / 60, max: max / 60 } : { unit: "minute", min, max };
|
|
4031
|
+
}
|
|
4032
|
+
function formatShippingDuration(minMinutes, maxMinutes, locale, display = "long") {
|
|
4033
|
+
const duration = shippingDuration(minMinutes, maxMinutes);
|
|
4034
|
+
if (!duration) return null;
|
|
4035
|
+
const unit2 = new Intl.NumberFormat(locale ?? "en", { style: "unit", unit: duration.unit, unitDisplay: display });
|
|
4036
|
+
return duration.min === duration.max ? unit2.format(duration.max) : `${duration.min}\u2013${unit2.format(duration.max)}`;
|
|
4037
|
+
}
|
|
4038
|
+
|
|
4022
4039
|
// shipping/validate.ts
|
|
4023
4040
|
function validateShippingZone(zone) {
|
|
4024
4041
|
const problems = [...placeProblems(zone)];
|
|
@@ -4047,7 +4064,15 @@ function fitsKind(place, kind) {
|
|
|
4047
4064
|
return false;
|
|
4048
4065
|
}
|
|
4049
4066
|
var isAmount = (value) => Number.isInteger(value) && value >= 0;
|
|
4050
|
-
var
|
|
4067
|
+
var isTime = (value) => value == null || isAmount(value);
|
|
4068
|
+
var inOrder = (min, max) => (min ?? 0) <= (max ?? Infinity);
|
|
4069
|
+
function timeIsValid(option) {
|
|
4070
|
+
const { minDays, maxDays, minMinutes, maxMinutes } = option;
|
|
4071
|
+
if (![minDays, maxDays, minMinutes, maxMinutes].every(isTime)) return false;
|
|
4072
|
+
const hasDays = minDays != null || maxDays != null;
|
|
4073
|
+
const hasMinutes = minMinutes != null || maxMinutes != null;
|
|
4074
|
+
return !(hasDays && hasMinutes) && inOrder(minDays, maxDays) && inOrder(minMinutes, maxMinutes);
|
|
4075
|
+
}
|
|
4051
4076
|
function optionProblems(option) {
|
|
4052
4077
|
const problems = [];
|
|
4053
4078
|
const isPickup = option.type === "pickup" /* PICKUP */;
|
|
@@ -4055,9 +4080,7 @@ function optionProblems(option) {
|
|
|
4055
4080
|
problems.push("INVALID_PRICE" /* INVALID_PRICE */);
|
|
4056
4081
|
}
|
|
4057
4082
|
if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
|
|
4058
|
-
if (!
|
|
4059
|
-
problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4060
|
-
}
|
|
4083
|
+
if (!timeIsValid(option)) problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4061
4084
|
if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
|
|
4062
4085
|
if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
|
|
4063
4086
|
if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
|
|
@@ -4525,6 +4548,7 @@ export {
|
|
|
4525
4548
|
formatInUnit,
|
|
4526
4549
|
formatMinorUnitsToString,
|
|
4527
4550
|
formatQuantity,
|
|
4551
|
+
formatShippingDuration,
|
|
4528
4552
|
fromBase,
|
|
4529
4553
|
fromMinorUnits,
|
|
4530
4554
|
generateMongoID,
|
|
@@ -4600,6 +4624,7 @@ export {
|
|
|
4600
4624
|
sameFamily,
|
|
4601
4625
|
setOrderState,
|
|
4602
4626
|
sha1Hex,
|
|
4627
|
+
shippingDuration,
|
|
4603
4628
|
shipsToCountry,
|
|
4604
4629
|
shopDayKey,
|
|
4605
4630
|
shopDayRange,
|