@moonbase.sh/storefront-api 0.4.57 → 0.4.58

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.cjs CHANGED
@@ -166,6 +166,9 @@ function quantifiable(itemSchema) {
166
166
  quantity: import_zod.z.number()
167
167
  });
168
168
  }
169
+ function singleOrMultiple(schema) {
170
+ return import_zod.z.union([schema, import_zod.z.array(schema)]);
171
+ }
169
172
 
170
173
  // src/inventory/products/schemas.ts
171
174
  var schemas_exports = {};
@@ -263,7 +266,7 @@ var cartContainsItemsConditionSchema = import_zod3.z.object({
263
266
  var offerConditionSchema = import_zod3.z.discriminatedUnion("type", [cartContainsItemsConditionSchema]);
264
267
  var storefrontOfferSchema = import_zod3.z.object({
265
268
  id: import_zod3.z.string(),
266
- target: import_zod3.z.union([storefrontProductSchema, storefrontBundleSchema]),
269
+ target: singleOrMultiple(import_zod3.z.union([storefrontProductSchema, storefrontBundleSchema])),
267
270
  targetVariations: import_zod3.z.string().array(),
268
271
  condition: offerConditionSchema,
269
272
  discount: discountSchema
@@ -1461,7 +1464,7 @@ var MoneyCollectionUtils = class {
1461
1464
  };
1462
1465
 
1463
1466
  // src/utils/offer.ts
1464
- var OfferUtils = class {
1467
+ var OfferUtils = class _OfferUtils {
1465
1468
  static eligible(offer, order) {
1466
1469
  switch (offer.condition.type) {
1467
1470
  case "CartContainsItems":
@@ -1470,7 +1473,7 @@ var OfferUtils = class {
1470
1473
  );
1471
1474
  const relevantReplacedItems = order.items.flatMap((i) => {
1472
1475
  var _a;
1473
- return i.type === "Bundle" && offer.target.type === "Bundle" && offer.target.id === i.bundleId && offer.id === i.offerId ? (_a = i.replaced) != null ? _a : [] : [];
1476
+ return offer.id === i.offerId && i.type === "Bundle" && _OfferUtils.targetContainsBundle(offer, i.id) ? (_a = i.replaced) != null ? _a : [] : [];
1474
1477
  }).filter((ref) => {
1475
1478
  const [productId, variationId] = ref.split("/");
1476
1479
  return offer.condition.relevantItemVariations[`Product/${productId}`] && offer.condition.relevantItemVariations[`Product/${productId}`].includes(variationId);
@@ -1488,6 +1491,9 @@ var OfferUtils = class {
1488
1491
  hasDiscount: Object.values(discount).some((v) => v > 0) || variation.hasDiscount
1489
1492
  };
1490
1493
  }
1494
+ static targetContainsBundle(offer, bundleId) {
1495
+ if (Array.isArray(offer.target)) return offer.target.some((i) => i.type === "Bundle" && i.id === bundleId);
1496
+ }
1491
1497
  };
1492
1498
 
1493
1499
  // src/index.ts