@final-commerce/common 2.8.1-preprod.1 → 2.8.1-preprod.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.mjs CHANGED
@@ -1706,6 +1706,48 @@ function compositeReservationMismatches(order) {
1706
1706
  });
1707
1707
  }
1708
1708
 
1709
+ // utils/line-stock-moves.util.ts
1710
+ function lineStockMoves(item, quantity, reservations = []) {
1711
+ const sign = Math.sign(quantity);
1712
+ const pool = (stockVariantId) => stockVariantId ? { stockVariantId: stockVariantId.toString() } : {};
1713
+ if (!item.components?.length)
1714
+ return [
1715
+ {
1716
+ productId: item.productId.toString(),
1717
+ variantId: item.variantId.toString(),
1718
+ fields: {
1719
+ quantity,
1720
+ ...item.stockQuantity != null ? { stockQuantity: sign * item.stockQuantity, unitId: item.unitId?.toString() } : {},
1721
+ ...pool(item.stockVariantId)
1722
+ }
1723
+ }
1724
+ ];
1725
+ const booked = new Set(
1726
+ reservations.filter((reservation) => reservation.lineItemInternalId && reservation.lineItemInternalId === item.internalId).map((reservation) => reservation.componentIndex)
1727
+ );
1728
+ return item.components.flatMap((component, componentIndex) => {
1729
+ if (booked.has(componentIndex)) return [];
1730
+ if (component.unitId && component.stockQuantity == null)
1731
+ throw new Error(
1732
+ `Composite ${item.productId?.toString()} component ${component.variantId.toString()} is sold in ${component.unitId.toString()} but carries no stockQuantity`
1733
+ );
1734
+ return [
1735
+ {
1736
+ productId: component.productId.toString(),
1737
+ variantId: component.variantId.toString(),
1738
+ componentIndex,
1739
+ fields: {
1740
+ quantity: component.quantity * quantity,
1741
+ ...component.stockQuantity != null ? { stockQuantity: component.stockQuantity * quantity, unitId: component.unitId?.toString() } : {},
1742
+ ...pool(component.stockVariantId),
1743
+ ...item.productId ? { compositeProductId: item.productId.toString() } : {},
1744
+ ...item.name ? { compositeName: item.name } : {}
1745
+ }
1746
+ }
1747
+ ];
1748
+ });
1749
+ }
1750
+
1709
1751
  // units/family-code.ts
1710
1752
  var MAX_SLUG_LENGTH = 32;
1711
1753
  var FALLBACK_SLUG = "family";
@@ -4198,6 +4240,7 @@ export {
4198
4240
  isSystemFamilyCode,
4199
4241
  isValidQuantity,
4200
4242
  isWhole,
4243
+ lineStockMoves,
4201
4244
  listCountries,
4202
4245
  listProvinces,
4203
4246
  mapToLegacyStatus,