@final-commerce/common 2.12.2-staging2.1 → 2.13.0-staging2.2
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 +79 -4
- package/dist/index.d.ts +79 -4
- package/dist/index.js +216 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +201 -58
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +12 -1
- package/dist/pos-types/index.d.ts +12 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -136,11 +136,14 @@ __export(index_exports, {
|
|
|
136
136
|
ancestorChain: () => ancestorChain,
|
|
137
137
|
applyAssignment: () => applyAssignment,
|
|
138
138
|
assertUnitSane: () => assertUnitSane,
|
|
139
|
+
attachResolvedUnits: () => attachResolvedUnits,
|
|
139
140
|
availableIn: () => availableIn,
|
|
141
|
+
bankersRoundDiv: () => bankersRoundDiv,
|
|
140
142
|
baseFor: () => baseFor,
|
|
141
143
|
baseFulfillmentDefinitions: () => baseFulfillmentDefinitions,
|
|
142
144
|
baseOf: () => baseOf,
|
|
143
145
|
basePaymentDefinitions: () => basePaymentDefinitions,
|
|
146
|
+
bookCostPerUnit: () => bookCostPerUnit,
|
|
144
147
|
buildAvailability: () => buildAvailability,
|
|
145
148
|
buildGrid: () => buildGrid,
|
|
146
149
|
buildOrderContext: () => buildOrderContext,
|
|
@@ -150,6 +153,9 @@ __export(index_exports, {
|
|
|
150
153
|
canTransition: () => canTransition,
|
|
151
154
|
cheapestCompositeItem: () => cheapestCompositeItem,
|
|
152
155
|
cheapestCompositePrice: () => cheapestCompositePrice,
|
|
156
|
+
componentUnitsPerLine: () => componentUnitsPerLine,
|
|
157
|
+
compositeCostOfKnown: () => compositeCostOfKnown,
|
|
158
|
+
compositeCostRange: () => compositeCostRange,
|
|
153
159
|
compositeItemCost: () => compositeItemCost,
|
|
154
160
|
compositeItemUnavailable: () => compositeItemUnavailable,
|
|
155
161
|
compositeMakeable: () => compositeMakeable,
|
|
@@ -158,6 +164,7 @@ __export(index_exports, {
|
|
|
158
164
|
compositeVariantInStock: () => compositeVariantInStock,
|
|
159
165
|
conditionSummary: () => conditionSummary,
|
|
160
166
|
convertFixedFeeToLocalCurrency: () => convertFixedFeeToLocalCurrency,
|
|
167
|
+
costPriceChangeStamp: () => costPriceChangeStamp,
|
|
161
168
|
createAmount: () => createAmount,
|
|
162
169
|
crossAxisRuleApplies: () => crossAxisRuleApplies,
|
|
163
170
|
currentAssignees: () => currentAssignees,
|
|
@@ -195,6 +202,7 @@ __export(index_exports, {
|
|
|
195
202
|
hasSellableChoice: () => hasSellableChoice,
|
|
196
203
|
holdExpiresAt: () => holdExpiresAt,
|
|
197
204
|
inferStatesFromLegacyStatus: () => inferStatesFromLegacyStatus,
|
|
205
|
+
innerCompositeOption: () => innerCompositeOption,
|
|
198
206
|
isAdyenRolloutCountry: () => isAdyenRolloutCountry,
|
|
199
207
|
isAffirmCountry: () => isAffirmCountry,
|
|
200
208
|
isAffirmPricePlan: () => isAffirmPricePlan,
|
|
@@ -202,16 +210,19 @@ __export(index_exports, {
|
|
|
202
210
|
isConditionOperator: () => isConditionOperator,
|
|
203
211
|
isFulfillmentState: () => isFulfillmentState,
|
|
204
212
|
isInCart: () => isInCart,
|
|
213
|
+
isInnerComposite: () => isInnerComposite,
|
|
205
214
|
isPaymentState: () => isPaymentState,
|
|
206
215
|
isSupportedCurrency: () => isSupportedCurrency,
|
|
207
216
|
isSystemFamilyCode: () => isSystemFamilyCode,
|
|
208
217
|
isValidQuantity: () => isValidQuantity,
|
|
209
218
|
isWhole: () => isWhole,
|
|
219
|
+
landedCostPerUnit: () => landedCostPerUnit,
|
|
210
220
|
lineStockMoves: () => lineStockMoves,
|
|
211
221
|
listCountries: () => listCountries,
|
|
212
222
|
listProvinces: () => listProvinces,
|
|
213
223
|
listShippingCountries: () => listShippingCountries,
|
|
214
224
|
mapToLegacyStatus: () => mapToLegacyStatus,
|
|
225
|
+
marginPercentOf: () => marginPercentOf,
|
|
215
226
|
maxPrecisionFor: () => maxPrecisionFor,
|
|
216
227
|
mergeFragment: () => mergeFragment,
|
|
217
228
|
modifiersSellable: () => modifiersSellable,
|
|
@@ -246,6 +257,7 @@ __export(index_exports, {
|
|
|
246
257
|
roundToPrecision: () => roundToPrecision,
|
|
247
258
|
sameFamily: () => sameFamily,
|
|
248
259
|
setOrderState: () => setOrderState,
|
|
260
|
+
shelfComponents: () => shelfComponents,
|
|
249
261
|
shipsToCountry: () => shipsToCountry,
|
|
250
262
|
shopDayKey: () => shopDayKey,
|
|
251
263
|
shopDayRange: () => shopDayRange,
|
|
@@ -259,6 +271,9 @@ __export(index_exports, {
|
|
|
259
271
|
validateFragmentCompatibility: () => validateFragmentCompatibility,
|
|
260
272
|
validateOrderStatuses: () => validateOrderStatuses,
|
|
261
273
|
validateShippingZone: () => validateShippingZone,
|
|
274
|
+
variantCostAtSale: () => variantCostAtSale,
|
|
275
|
+
variantDisplayName: () => variantDisplayName,
|
|
276
|
+
variantLabel: () => variantLabel,
|
|
262
277
|
violatesFinancialInvariant: () => violatesFinancialInvariant,
|
|
263
278
|
windowEndsAt: () => windowEndsAt,
|
|
264
279
|
withinPresence: () => withinPresence
|
|
@@ -1286,6 +1301,16 @@ function resolveUnit(unitId, companyUnits = []) {
|
|
|
1286
1301
|
if (!unit2) throw new Error(`Unknown measurement unit: ${unitId}`);
|
|
1287
1302
|
return unit2;
|
|
1288
1303
|
}
|
|
1304
|
+
function attachResolvedUnits(variants, companyUnits, logLabel = "attachUnits") {
|
|
1305
|
+
for (const variant of variants)
|
|
1306
|
+
if (variant.unitId)
|
|
1307
|
+
try {
|
|
1308
|
+
variant.unit = resolveUnit(variant.unitId, companyUnits);
|
|
1309
|
+
} catch (error) {
|
|
1310
|
+
console.error(`[${logLabel}] unit ${variant.unitId} does not resolve. ${error.message}`);
|
|
1311
|
+
}
|
|
1312
|
+
return variants;
|
|
1313
|
+
}
|
|
1289
1314
|
function resolveFamily(familyId, companyFamilies = []) {
|
|
1290
1315
|
const family = SYSTEM_FAMILIES.find((f) => f.familyId === familyId) ?? companyFamilies.find((f) => f.familyId === familyId);
|
|
1291
1316
|
if (!family) throw new Error(`Unknown measurement unit family: ${familyId}`);
|
|
@@ -1826,6 +1851,66 @@ function hasSellableChoice(modifier, outletId) {
|
|
|
1826
1851
|
}
|
|
1827
1852
|
var modifiersSellable = (modifiers, outletId) => modifiers.every((modifier) => !modifier.required || hasSellableChoice(modifier, outletId));
|
|
1828
1853
|
|
|
1854
|
+
// utils/line-stock-moves.util.ts
|
|
1855
|
+
function lineStockMoves(item, quantity, reservations = []) {
|
|
1856
|
+
const sign = Math.sign(quantity);
|
|
1857
|
+
const pool = (stockVariantId) => stockVariantId ? { stockVariantId: stockVariantId.toString() } : {};
|
|
1858
|
+
if (!item.components?.length)
|
|
1859
|
+
return [
|
|
1860
|
+
{
|
|
1861
|
+
productId: item.productId.toString(),
|
|
1862
|
+
variantId: item.variantId.toString(),
|
|
1863
|
+
fields: {
|
|
1864
|
+
quantity,
|
|
1865
|
+
...item.stockQuantity != null ? { stockQuantity: sign * item.stockQuantity, unitId: item.unitId?.toString() } : {},
|
|
1866
|
+
...pool(item.stockVariantId)
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
];
|
|
1870
|
+
const booked = new Set(
|
|
1871
|
+
reservations.filter((reservation) => reservation.lineItemInternalId && reservation.lineItemInternalId === item.internalId).map((reservation) => reservation.componentIndex)
|
|
1872
|
+
);
|
|
1873
|
+
return shelfComponents(item.components).flatMap(({ component, componentIndex, parentUnits }) => {
|
|
1874
|
+
if (booked.has(componentIndex)) return [];
|
|
1875
|
+
if (component.unitId && component.stockQuantity == null)
|
|
1876
|
+
throw new Error(
|
|
1877
|
+
`Composite ${item.productId?.toString()} component ${component.variantId.toString()} is sold in ${component.unitId.toString()} but carries no stockQuantity`
|
|
1878
|
+
);
|
|
1879
|
+
return [
|
|
1880
|
+
{
|
|
1881
|
+
productId: component.productId.toString(),
|
|
1882
|
+
variantId: component.variantId.toString(),
|
|
1883
|
+
componentIndex,
|
|
1884
|
+
fields: {
|
|
1885
|
+
quantity: component.quantity * parentUnits * quantity,
|
|
1886
|
+
...component.stockQuantity != null ? { stockQuantity: component.stockQuantity * parentUnits * quantity, unitId: component.unitId?.toString() } : {},
|
|
1887
|
+
...pool(component.stockVariantId),
|
|
1888
|
+
...item.productId ? { compositeProductId: item.productId.toString() } : {},
|
|
1889
|
+
...item.name ? { compositeName: item.name } : {}
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
];
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
function componentUnitsPerLine(components, index) {
|
|
1896
|
+
const component = components[index];
|
|
1897
|
+
if (!component) throw new Error(`No component ${index} on the line`);
|
|
1898
|
+
if (component.parentIndex == null) return component.quantity;
|
|
1899
|
+
if (component.parentIndex >= index)
|
|
1900
|
+
throw new Error(`Component ${index} points to parent ${component.parentIndex}, which is not before it`);
|
|
1901
|
+
return component.quantity * componentUnitsPerLine(components, component.parentIndex);
|
|
1902
|
+
}
|
|
1903
|
+
var isInnerComposite = (components, index) => components.some((child) => child.parentIndex === index);
|
|
1904
|
+
var shelfComponents = (components) => components.flatMap(
|
|
1905
|
+
(component, componentIndex) => isInnerComposite(components, componentIndex) ? [] : [
|
|
1906
|
+
{
|
|
1907
|
+
component,
|
|
1908
|
+
componentIndex,
|
|
1909
|
+
parentUnits: component.parentIndex == null ? 1 : componentUnitsPerLine(components, component.parentIndex)
|
|
1910
|
+
}
|
|
1911
|
+
]
|
|
1912
|
+
);
|
|
1913
|
+
|
|
1829
1914
|
// utils/composite-availability.util.ts
|
|
1830
1915
|
function poolStockAt(rows, outletId) {
|
|
1831
1916
|
if (!rows.some((row) => row.manageStock === true)) return null;
|
|
@@ -1866,13 +1951,14 @@ function compositeItemUnavailable(item, rows) {
|
|
|
1866
1951
|
}
|
|
1867
1952
|
return compositeVariantInStock(variantId, item.quantity, outlet) ? null : "out_of_stock";
|
|
1868
1953
|
}
|
|
1869
|
-
function compositeMakeable(parts, rows) {
|
|
1954
|
+
function compositeMakeable(parts, rows, inner = /* @__PURE__ */ new Map()) {
|
|
1870
1955
|
const { outlet } = rows;
|
|
1871
1956
|
if (!outlet) throw new Error("compositeMakeable counts at one outlet: rows.outlet is required");
|
|
1872
|
-
const
|
|
1957
|
+
const own = parts.map((part, partIndex) => ({ ...part, partIndex })).filter((part) => part.min > 0);
|
|
1873
1958
|
const isBookable = (variantId) => rows.bookableProductIds.has(rows.variantProducts.get(String(variantId)) ?? "");
|
|
1874
|
-
if (
|
|
1959
|
+
if (own.some((part) => part.items.some((item) => item.variantId && isBookable(item.variantId))))
|
|
1875
1960
|
return { byDate: true };
|
|
1961
|
+
const required = own.flatMap((part) => withInnerParts(part, inner, rows, /* @__PURE__ */ new Set()));
|
|
1876
1962
|
const optionsOf = (item) => (item.categoryId ? rows.categoryVariants.get(String(item.categoryId)) ?? [] : [String(item.variantId)]).flatMap(
|
|
1877
1963
|
(variantId) => {
|
|
1878
1964
|
const reason = compositeItemUnavailable({ variantId, quantity: item.quantity }, rows);
|
|
@@ -1881,7 +1967,7 @@ function compositeMakeable(parts, rows) {
|
|
|
1881
1967
|
const stock = outlet.poolStock.get(shelf.pool);
|
|
1882
1968
|
const onHand = shelf.unresolved || stock === void 0 ? 0 : stock === null || shelf.backorder ? null : stock;
|
|
1883
1969
|
const perPick = shelf.unit ? toBase(item.quantity, shelf.unit) : item.quantity;
|
|
1884
|
-
return [{ itemId: item.id, pool: shelf.pool, perPick, onHand }];
|
|
1970
|
+
return [{ itemId: item.id, variantId, pool: shelf.pool, perPick, onHand }];
|
|
1885
1971
|
}
|
|
1886
1972
|
);
|
|
1887
1973
|
const counted = required.map((part) => ({ ...part, options: part.items.flatMap(optionsOf) }));
|
|
@@ -1899,28 +1985,31 @@ function compositeMakeable(parts, rows) {
|
|
|
1899
1985
|
reserved.set(option.pool, (reserved.get(option.pool) ?? 0) + taken * option.perPick);
|
|
1900
1986
|
wanted -= taken;
|
|
1901
1987
|
}
|
|
1902
|
-
if (wanted > 0) return part
|
|
1988
|
+
if (wanted > 0) return part;
|
|
1903
1989
|
}
|
|
1904
1990
|
return void 0;
|
|
1905
1991
|
};
|
|
1906
1992
|
const whyRows = [];
|
|
1907
1993
|
const rowPools = /* @__PURE__ */ new Map();
|
|
1994
|
+
const rowOf = /* @__PURE__ */ new Map();
|
|
1908
1995
|
const makes = (has, uses) => has === null ? null : Math.floor(has / uses);
|
|
1909
1996
|
for (const part of counted) {
|
|
1910
1997
|
const [option] = part.options;
|
|
1911
1998
|
if (part.options.length === 1) {
|
|
1912
1999
|
const uses = option.perPick * part.min;
|
|
1913
|
-
const
|
|
1914
|
-
if (!
|
|
2000
|
+
const row2 = whyRows.find((candidate) => rowPools.get(candidate) === option.pool);
|
|
2001
|
+
if (!row2) {
|
|
1915
2002
|
const created = { itemIds: [option.itemId], uses, has: option.onHand, makes: makes(option.onHand, uses) };
|
|
1916
2003
|
rowPools.set(created, option.pool);
|
|
2004
|
+
rowOf.set(part, created);
|
|
1917
2005
|
whyRows.push(created);
|
|
1918
2006
|
continue;
|
|
1919
2007
|
}
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
2008
|
+
rowOf.set(part, row2);
|
|
2009
|
+
if (!row2.itemIds.includes(option.itemId)) row2.itemIds.push(option.itemId);
|
|
2010
|
+
row2.uses += uses;
|
|
2011
|
+
if (option.onHand === null) row2.has = null;
|
|
2012
|
+
row2.makes = makes(row2.has, row2.uses);
|
|
1924
2013
|
continue;
|
|
1925
2014
|
}
|
|
1926
2015
|
const perPool = /* @__PURE__ */ new Map();
|
|
@@ -1928,13 +2017,19 @@ function compositeMakeable(parts, rows) {
|
|
|
1928
2017
|
perPool.set(candidate.pool, Math.max(perPool.get(candidate.pool) ?? 0, picksLeft(candidate, /* @__PURE__ */ new Map())));
|
|
1929
2018
|
const total = [...perPool.values()].reduce((sum, picks) => sum + picks, 0);
|
|
1930
2019
|
const has = total === Infinity ? null : total;
|
|
1931
|
-
|
|
1932
|
-
itemIds: part.items.map((item) => item.id),
|
|
2020
|
+
const row = {
|
|
2021
|
+
itemIds: [...new Set(part.items.map((item) => item.id))],
|
|
1933
2022
|
partIndex: part.partIndex,
|
|
1934
2023
|
uses: part.min,
|
|
1935
2024
|
has,
|
|
1936
2025
|
makes: makes(has, part.min)
|
|
1937
|
-
}
|
|
2026
|
+
};
|
|
2027
|
+
rowOf.set(part, row);
|
|
2028
|
+
whyRows.push(row);
|
|
2029
|
+
}
|
|
2030
|
+
for (const row of new Set(counted.filter((part) => part.inner).map((part) => rowOf.get(part)))) {
|
|
2031
|
+
const rowParts = counted.filter((part) => rowOf.get(part) === row);
|
|
2032
|
+
row.variantIds = [...new Set(rowParts.flatMap((part) => part.options.map((option) => option.variantId)))];
|
|
1938
2033
|
}
|
|
1939
2034
|
if (counted.every((part) => part.options.some((option) => option.onHand === null)))
|
|
1940
2035
|
return { count: null, rows: whyRows };
|
|
@@ -1950,12 +2045,29 @@ function compositeMakeable(parts, rows) {
|
|
|
1950
2045
|
else high = mid - 1;
|
|
1951
2046
|
}
|
|
1952
2047
|
const short = shortAt(low + 1);
|
|
1953
|
-
const
|
|
1954
|
-
const limitedBy = whyRows.findIndex(
|
|
1955
|
-
(row) => shortPart?.options.length === 1 ? row.partIndex === void 0 && row.itemIds.includes(shortPart.options[0].itemId) : row.partIndex === short
|
|
1956
|
-
);
|
|
2048
|
+
const limitedBy = short ? whyRows.indexOf(rowOf.get(short)) : -1;
|
|
1957
2049
|
return { count: low, rows: whyRows, ...limitedBy >= 0 ? { limitedBy } : {} };
|
|
1958
2050
|
}
|
|
2051
|
+
function withInnerParts(part, inner, rows, seen) {
|
|
2052
|
+
const [item] = part.items;
|
|
2053
|
+
const variantId = String(item?.variantId);
|
|
2054
|
+
const innerParts = part.items.length === 1 && item.variantId ? inner.get(variantId) : void 0;
|
|
2055
|
+
const reason = innerParts && compositeItemUnavailable({ variantId, quantity: item.quantity }, rows);
|
|
2056
|
+
if (!innerParts || seen.has(variantId) || reason && reason !== "out_of_stock") return [part];
|
|
2057
|
+
return innerParts.filter((innerPart) => innerPart.min > 0).flatMap(
|
|
2058
|
+
(innerPart) => withInnerParts(
|
|
2059
|
+
{
|
|
2060
|
+
...part,
|
|
2061
|
+
inner: true,
|
|
2062
|
+
min: part.min * item.quantity * innerPart.min,
|
|
2063
|
+
items: innerPart.items.map((innerItem) => ({ ...innerItem, id: item.id }))
|
|
2064
|
+
},
|
|
2065
|
+
inner,
|
|
2066
|
+
rows,
|
|
2067
|
+
new Set(seen).add(variantId)
|
|
2068
|
+
)
|
|
2069
|
+
);
|
|
2070
|
+
}
|
|
1959
2071
|
var poolOf = (line) => line.stockVariantId || line.variantId;
|
|
1960
2072
|
function poolDemand(lines) {
|
|
1961
2073
|
const demand = /* @__PURE__ */ new Map();
|
|
@@ -1964,7 +2076,9 @@ function poolDemand(lines) {
|
|
|
1964
2076
|
(demand.get(poolOf(line)) ?? 0) + (line.unit ? toBase(line.quantity * times, line.unit) : line.quantity * times)
|
|
1965
2077
|
);
|
|
1966
2078
|
for (const line of lines) {
|
|
1967
|
-
if (line.components)
|
|
2079
|
+
if (line.components)
|
|
2080
|
+
for (const { component, parentUnits } of shelfComponents(line.components))
|
|
2081
|
+
add(component, line.quantity * parentUnits);
|
|
1968
2082
|
else add(line, 1);
|
|
1969
2083
|
}
|
|
1970
2084
|
return demand;
|
|
@@ -2006,47 +2120,76 @@ function compositeReservationMismatches(order) {
|
|
|
2006
2120
|
});
|
|
2007
2121
|
}
|
|
2008
2122
|
|
|
2009
|
-
// utils/
|
|
2010
|
-
function
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
);
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
];
|
|
2123
|
+
// utils/variant-cost.util.ts
|
|
2124
|
+
function variantCostAtSale({
|
|
2125
|
+
costPrice,
|
|
2126
|
+
costPriceUpdatedAt,
|
|
2127
|
+
landedCost,
|
|
2128
|
+
lastReceivedAt
|
|
2129
|
+
}) {
|
|
2130
|
+
if (landedCost == null) return costPrice ?? null;
|
|
2131
|
+
if (costPrice == null) return landedCost;
|
|
2132
|
+
if (!costPriceUpdatedAt || !lastReceivedAt) return costPrice;
|
|
2133
|
+
return new Date(lastReceivedAt).getTime() > new Date(costPriceUpdatedAt).getTime() ? landedCost : costPrice;
|
|
2134
|
+
}
|
|
2135
|
+
function compositeCostOfKnown(items) {
|
|
2136
|
+
const known = items.filter((item) => item.cost !== null);
|
|
2137
|
+
if (!known.length) return null;
|
|
2138
|
+
return known.reduce((sum, { cost, quantity }) => sum + extendPrice(cost, quantity), 0);
|
|
2139
|
+
}
|
|
2140
|
+
function compositeCostRange(parts) {
|
|
2141
|
+
const missing = new Set(parts.flatMap((part) => part.options.flatMap((option) => option.missing)));
|
|
2142
|
+
const [low, high] = [pickedEnd(parts, "low"), pickedEnd(parts, "high")];
|
|
2143
|
+
const [lowCost, highCost] = [low.length ? compositeCostOfKnown(low) : 0, compositeCostOfKnown(high)];
|
|
2144
|
+
return { range: lowCost === null || highCost === null ? null : [lowCost, highCost], missing: [...missing] };
|
|
2145
|
+
}
|
|
2146
|
+
function innerCompositeOption(name, quantity, cost) {
|
|
2147
|
+
const [low, high] = cost.range ?? [null, null];
|
|
2148
|
+
return { name, quantity, low, high, missing: cost.range === null && !cost.missing.length ? [name] : cost.missing };
|
|
2149
|
+
}
|
|
2150
|
+
function variantLabel(variant, variantCount) {
|
|
2151
|
+
if (variantCount === 1) return "";
|
|
2152
|
+
const attributes = (variant.attributes ?? []).map((attribute) => attribute.value ?? attribute.values?.[0] ?? "");
|
|
2153
|
+
return attributes.filter(Boolean).join(" / ") || variant.name || variant.sku || "";
|
|
2154
|
+
}
|
|
2155
|
+
function variantDisplayName(productName, variant, variantCount) {
|
|
2156
|
+
const label = variantLabel(variant, variantCount);
|
|
2157
|
+
return label ? `${productName} \xB7 ${label}` : productName;
|
|
2158
|
+
}
|
|
2159
|
+
function pickedEnd(parts, end) {
|
|
2160
|
+
return parts.flatMap((part) => {
|
|
2161
|
+
if (!part.options.length) return [];
|
|
2162
|
+
const byCost = part.options.flatMap(({ quantity, [end]: cost }) => cost === null ? [] : [{ cost, quantity }]).sort((a, b) => extendPrice(a.cost, a.quantity) - extendPrice(b.cost, b.quantity));
|
|
2163
|
+
const pick = (end === "low" ? byCost[0] : byCost[byCost.length - 1]) ?? { cost: null, quantity: 1 };
|
|
2164
|
+
return Array(end === "low" ? part.minPicks : part.maxPicks).fill(pick);
|
|
2048
2165
|
});
|
|
2049
2166
|
}
|
|
2167
|
+
function costPriceChangeStamp(next, stored) {
|
|
2168
|
+
if (next === void 0 || next === (stored ?? null)) return {};
|
|
2169
|
+
return { costPriceUpdatedAt: /* @__PURE__ */ new Date() };
|
|
2170
|
+
}
|
|
2171
|
+
function bankersRoundDiv(numerator, denominator) {
|
|
2172
|
+
if (denominator === 0n) return 0n;
|
|
2173
|
+
const negative = numerator < 0n !== denominator < 0n;
|
|
2174
|
+
const n = numerator < 0n ? -numerator : numerator;
|
|
2175
|
+
const d = denominator < 0n ? -denominator : denominator;
|
|
2176
|
+
const quotient = n / d;
|
|
2177
|
+
const twiceRemainder = n % d * 2n;
|
|
2178
|
+
let result;
|
|
2179
|
+
if (twiceRemainder < d) {
|
|
2180
|
+
result = quotient;
|
|
2181
|
+
} else if (twiceRemainder > d) {
|
|
2182
|
+
result = quotient + 1n;
|
|
2183
|
+
} else {
|
|
2184
|
+
result = quotient % 2n === 0n ? quotient : quotient + 1n;
|
|
2185
|
+
}
|
|
2186
|
+
return negative ? -result : result;
|
|
2187
|
+
}
|
|
2188
|
+
function landedCostPerUnit(landedValue, baseQuantity, ratioToBase = 1) {
|
|
2189
|
+
return Number(bankersRoundDiv(BigInt(Math.round(landedValue * ratioToBase)), BigInt(baseQuantity)));
|
|
2190
|
+
}
|
|
2191
|
+
var bookCostPerUnit = (book, ratioToBase) => book && book.totalQuantity > 0 && ratioToBase ? landedCostPerUnit(book.totalLandedValue, book.totalQuantity, ratioToBase) : null;
|
|
2192
|
+
var marginPercentOf = (grossProfit, costedGross) => grossProfit === null || !costedGross ? null : grossProfit * 100 / costedGross;
|
|
2050
2193
|
|
|
2051
2194
|
// units/family-code.ts
|
|
2052
2195
|
var MAX_SLUG_LENGTH = 32;
|
|
@@ -4524,11 +4667,14 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4524
4667
|
ancestorChain,
|
|
4525
4668
|
applyAssignment,
|
|
4526
4669
|
assertUnitSane,
|
|
4670
|
+
attachResolvedUnits,
|
|
4527
4671
|
availableIn,
|
|
4672
|
+
bankersRoundDiv,
|
|
4528
4673
|
baseFor,
|
|
4529
4674
|
baseFulfillmentDefinitions,
|
|
4530
4675
|
baseOf,
|
|
4531
4676
|
basePaymentDefinitions,
|
|
4677
|
+
bookCostPerUnit,
|
|
4532
4678
|
buildAvailability,
|
|
4533
4679
|
buildGrid,
|
|
4534
4680
|
buildOrderContext,
|
|
@@ -4538,6 +4684,9 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4538
4684
|
canTransition,
|
|
4539
4685
|
cheapestCompositeItem,
|
|
4540
4686
|
cheapestCompositePrice,
|
|
4687
|
+
componentUnitsPerLine,
|
|
4688
|
+
compositeCostOfKnown,
|
|
4689
|
+
compositeCostRange,
|
|
4541
4690
|
compositeItemCost,
|
|
4542
4691
|
compositeItemUnavailable,
|
|
4543
4692
|
compositeMakeable,
|
|
@@ -4546,6 +4695,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4546
4695
|
compositeVariantInStock,
|
|
4547
4696
|
conditionSummary,
|
|
4548
4697
|
convertFixedFeeToLocalCurrency,
|
|
4698
|
+
costPriceChangeStamp,
|
|
4549
4699
|
createAmount,
|
|
4550
4700
|
crossAxisRuleApplies,
|
|
4551
4701
|
currentAssignees,
|
|
@@ -4583,6 +4733,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4583
4733
|
hasSellableChoice,
|
|
4584
4734
|
holdExpiresAt,
|
|
4585
4735
|
inferStatesFromLegacyStatus,
|
|
4736
|
+
innerCompositeOption,
|
|
4586
4737
|
isAdyenRolloutCountry,
|
|
4587
4738
|
isAffirmCountry,
|
|
4588
4739
|
isAffirmPricePlan,
|
|
@@ -4590,16 +4741,19 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4590
4741
|
isConditionOperator,
|
|
4591
4742
|
isFulfillmentState,
|
|
4592
4743
|
isInCart,
|
|
4744
|
+
isInnerComposite,
|
|
4593
4745
|
isPaymentState,
|
|
4594
4746
|
isSupportedCurrency,
|
|
4595
4747
|
isSystemFamilyCode,
|
|
4596
4748
|
isValidQuantity,
|
|
4597
4749
|
isWhole,
|
|
4750
|
+
landedCostPerUnit,
|
|
4598
4751
|
lineStockMoves,
|
|
4599
4752
|
listCountries,
|
|
4600
4753
|
listProvinces,
|
|
4601
4754
|
listShippingCountries,
|
|
4602
4755
|
mapToLegacyStatus,
|
|
4756
|
+
marginPercentOf,
|
|
4603
4757
|
maxPrecisionFor,
|
|
4604
4758
|
mergeFragment,
|
|
4605
4759
|
modifiersSellable,
|
|
@@ -4634,6 +4788,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4634
4788
|
roundToPrecision,
|
|
4635
4789
|
sameFamily,
|
|
4636
4790
|
setOrderState,
|
|
4791
|
+
shelfComponents,
|
|
4637
4792
|
shipsToCountry,
|
|
4638
4793
|
shopDayKey,
|
|
4639
4794
|
shopDayRange,
|
|
@@ -4647,6 +4802,9 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4647
4802
|
validateFragmentCompatibility,
|
|
4648
4803
|
validateOrderStatuses,
|
|
4649
4804
|
validateShippingZone,
|
|
4805
|
+
variantCostAtSale,
|
|
4806
|
+
variantDisplayName,
|
|
4807
|
+
variantLabel,
|
|
4650
4808
|
violatesFinancialInvariant,
|
|
4651
4809
|
windowEndsAt,
|
|
4652
4810
|
withinPresence
|