@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.js CHANGED
@@ -110,6 +110,9 @@ function quantifiable(itemSchema) {
110
110
  quantity: z.number()
111
111
  });
112
112
  }
113
+ function singleOrMultiple(schema) {
114
+ return z.union([schema, z.array(schema)]);
115
+ }
113
116
 
114
117
  // src/inventory/products/schemas.ts
115
118
  var schemas_exports = {};
@@ -207,7 +210,7 @@ var cartContainsItemsConditionSchema = z3.object({
207
210
  var offerConditionSchema = z3.discriminatedUnion("type", [cartContainsItemsConditionSchema]);
208
211
  var storefrontOfferSchema = z3.object({
209
212
  id: z3.string(),
210
- target: z3.union([storefrontProductSchema, storefrontBundleSchema]),
213
+ target: singleOrMultiple(z3.union([storefrontProductSchema, storefrontBundleSchema])),
211
214
  targetVariations: z3.string().array(),
212
215
  condition: offerConditionSchema,
213
216
  discount: discountSchema
@@ -1405,7 +1408,7 @@ var MoneyCollectionUtils = class {
1405
1408
  };
1406
1409
 
1407
1410
  // src/utils/offer.ts
1408
- var OfferUtils = class {
1411
+ var OfferUtils = class _OfferUtils {
1409
1412
  static eligible(offer, order) {
1410
1413
  switch (offer.condition.type) {
1411
1414
  case "CartContainsItems":
@@ -1414,7 +1417,7 @@ var OfferUtils = class {
1414
1417
  );
1415
1418
  const relevantReplacedItems = order.items.flatMap((i) => {
1416
1419
  var _a;
1417
- return i.type === "Bundle" && offer.target.type === "Bundle" && offer.target.id === i.bundleId && offer.id === i.offerId ? (_a = i.replaced) != null ? _a : [] : [];
1420
+ return offer.id === i.offerId && i.type === "Bundle" && _OfferUtils.targetContainsBundle(offer, i.id) ? (_a = i.replaced) != null ? _a : [] : [];
1418
1421
  }).filter((ref) => {
1419
1422
  const [productId, variationId] = ref.split("/");
1420
1423
  return offer.condition.relevantItemVariations[`Product/${productId}`] && offer.condition.relevantItemVariations[`Product/${productId}`].includes(variationId);
@@ -1432,6 +1435,9 @@ var OfferUtils = class {
1432
1435
  hasDiscount: Object.values(discount).some((v) => v > 0) || variation.hasDiscount
1433
1436
  };
1434
1437
  }
1438
+ static targetContainsBundle(offer, bundleId) {
1439
+ if (Array.isArray(offer.target)) return offer.target.some((i) => i.type === "Bundle" && i.id === bundleId);
1440
+ }
1435
1441
  };
1436
1442
 
1437
1443
  // src/index.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "0.4.57",
4
+ "version": "0.4.58",
5
5
  "description": "Package to let you build storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",