@moonbase.sh/storefront-api 0.4.27 → 0.4.31

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
@@ -252,7 +252,8 @@ var storefrontOfferSchema = import_zod3.z.object({
252
252
  });
253
253
  var storefrontSchema = import_zod3.z.object({
254
254
  suggestedCurrency: import_zod3.z.string(),
255
- enabledCurrencies: import_zod3.z.string().array(),
255
+ // Enabled currencies need to be optional since we may still have old, cached representations in browsers
256
+ enabledCurrencies: import_zod3.z.string().array().optional(),
256
257
  products: storefrontProductSchema.array(),
257
258
  bundles: storefrontBundleSchema.array(),
258
259
  // Offers need to be optional since we may still have old, cached representations in browsers
@@ -1363,10 +1364,16 @@ var OfferUtils = class {
1363
1364
  switch (offer.condition.type) {
1364
1365
  case "CartContainsItems":
1365
1366
  const relevantItems = order.items.filter(
1366
- (i) => i.type === "Product" && offer.condition.relevantItemVariations[`Product/${i.productId}`] && (offer.condition.relevantItemVariations[`Product/${i.productId}`].length === 0 || offer.condition.relevantItemVariations[`Product/${i.productId}`].includes(i.variationId)) || i.type === "Bundle" && offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`] && (offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`].length === 0 || offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`].includes(i.variationId))
1367
+ (i) => i.type === "Product" && offer.condition.relevantItemVariations[`Product/${i.productId}`] && offer.condition.relevantItemVariations[`Product/${i.productId}`].includes(i.variationId) || i.type === "Bundle" && offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`] && offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`].includes(i.variationId)
1367
1368
  );
1368
- console.log("Relevant items for offer:", { offer, relevantItems });
1369
- return relevantItems.length >= offer.condition.minimumItems;
1369
+ const relevantReplacedItems = order.items.flatMap((i) => {
1370
+ var _a;
1371
+ return i.type === "Bundle" && offer.target.type === "Bundle" && offer.target.id === i.bundleId && offer.id === i.offerId ? (_a = i.replaced) != null ? _a : [] : [];
1372
+ }).filter((ref) => {
1373
+ const [productId, variationId] = ref.split("/");
1374
+ return offer.condition.relevantItemVariations[`Product/${productId}`] && offer.condition.relevantItemVariations[`Product/${productId}`].includes(variationId);
1375
+ });
1376
+ return relevantItems.length + relevantReplacedItems.length >= offer.condition.minimumItems;
1370
1377
  }
1371
1378
  console.warn("Unsupported offer condition found:", offer.condition);
1372
1379
  return false;
package/dist/index.d.cts CHANGED
@@ -19187,7 +19187,6 @@ declare class StorefrontEndpoints {
19187
19187
  }[] | undefined;
19188
19188
  }[];
19189
19189
  suggestedCurrency: string;
19190
- enabledCurrencies: string[];
19191
19190
  bundles: {
19192
19191
  id: string;
19193
19192
  name: string;
@@ -19361,6 +19360,7 @@ declare class StorefrontEndpoints {
19361
19360
  }[] | null | undefined;
19362
19361
  }[] | undefined;
19363
19362
  }[];
19363
+ enabledCurrencies?: string[] | undefined;
19364
19364
  offers?: {
19365
19365
  id: string;
19366
19366
  discount: {
@@ -26737,7 +26737,7 @@ declare const storefrontOfferSchema: z.ZodObject<{
26737
26737
  }>;
26738
26738
  declare const storefrontSchema: z.ZodObject<{
26739
26739
  suggestedCurrency: z.ZodString;
26740
- enabledCurrencies: z.ZodArray<z.ZodString, "many">;
26740
+ enabledCurrencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
26741
26741
  products: z.ZodArray<z.ZodObject<{
26742
26742
  id: z.ZodString;
26743
26743
  name: z.ZodString;
@@ -30981,7 +30981,6 @@ declare const storefrontSchema: z.ZodObject<{
30981
30981
  }[] | undefined;
30982
30982
  }[];
30983
30983
  suggestedCurrency: string;
30984
- enabledCurrencies: string[];
30985
30984
  bundles: {
30986
30985
  id: string;
30987
30986
  name: string;
@@ -31155,6 +31154,7 @@ declare const storefrontSchema: z.ZodObject<{
31155
31154
  }[] | null | undefined;
31156
31155
  }[] | undefined;
31157
31156
  }[];
31157
+ enabledCurrencies?: string[] | undefined;
31158
31158
  offers?: {
31159
31159
  id: string;
31160
31160
  discount: {
@@ -31540,7 +31540,6 @@ declare const storefrontSchema: z.ZodObject<{
31540
31540
  }[] | undefined;
31541
31541
  }[];
31542
31542
  suggestedCurrency: string;
31543
- enabledCurrencies: string[];
31544
31543
  bundles: {
31545
31544
  id: string;
31546
31545
  name: string;
@@ -31714,6 +31713,7 @@ declare const storefrontSchema: z.ZodObject<{
31714
31713
  }[] | null | undefined;
31715
31714
  }[] | undefined;
31716
31715
  }[];
31716
+ enabledCurrencies?: string[] | undefined;
31717
31717
  offers?: {
31718
31718
  id: string;
31719
31719
  discount: {
package/dist/index.d.ts CHANGED
@@ -19187,7 +19187,6 @@ declare class StorefrontEndpoints {
19187
19187
  }[] | undefined;
19188
19188
  }[];
19189
19189
  suggestedCurrency: string;
19190
- enabledCurrencies: string[];
19191
19190
  bundles: {
19192
19191
  id: string;
19193
19192
  name: string;
@@ -19361,6 +19360,7 @@ declare class StorefrontEndpoints {
19361
19360
  }[] | null | undefined;
19362
19361
  }[] | undefined;
19363
19362
  }[];
19363
+ enabledCurrencies?: string[] | undefined;
19364
19364
  offers?: {
19365
19365
  id: string;
19366
19366
  discount: {
@@ -26737,7 +26737,7 @@ declare const storefrontOfferSchema: z.ZodObject<{
26737
26737
  }>;
26738
26738
  declare const storefrontSchema: z.ZodObject<{
26739
26739
  suggestedCurrency: z.ZodString;
26740
- enabledCurrencies: z.ZodArray<z.ZodString, "many">;
26740
+ enabledCurrencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
26741
26741
  products: z.ZodArray<z.ZodObject<{
26742
26742
  id: z.ZodString;
26743
26743
  name: z.ZodString;
@@ -30981,7 +30981,6 @@ declare const storefrontSchema: z.ZodObject<{
30981
30981
  }[] | undefined;
30982
30982
  }[];
30983
30983
  suggestedCurrency: string;
30984
- enabledCurrencies: string[];
30985
30984
  bundles: {
30986
30985
  id: string;
30987
30986
  name: string;
@@ -31155,6 +31154,7 @@ declare const storefrontSchema: z.ZodObject<{
31155
31154
  }[] | null | undefined;
31156
31155
  }[] | undefined;
31157
31156
  }[];
31157
+ enabledCurrencies?: string[] | undefined;
31158
31158
  offers?: {
31159
31159
  id: string;
31160
31160
  discount: {
@@ -31540,7 +31540,6 @@ declare const storefrontSchema: z.ZodObject<{
31540
31540
  }[] | undefined;
31541
31541
  }[];
31542
31542
  suggestedCurrency: string;
31543
- enabledCurrencies: string[];
31544
31543
  bundles: {
31545
31544
  id: string;
31546
31545
  name: string;
@@ -31714,6 +31713,7 @@ declare const storefrontSchema: z.ZodObject<{
31714
31713
  }[] | null | undefined;
31715
31714
  }[] | undefined;
31716
31715
  }[];
31716
+ enabledCurrencies?: string[] | undefined;
31717
31717
  offers?: {
31718
31718
  id: string;
31719
31719
  discount: {
package/dist/index.js CHANGED
@@ -196,7 +196,8 @@ var storefrontOfferSchema = z3.object({
196
196
  });
197
197
  var storefrontSchema = z3.object({
198
198
  suggestedCurrency: z3.string(),
199
- enabledCurrencies: z3.string().array(),
199
+ // Enabled currencies need to be optional since we may still have old, cached representations in browsers
200
+ enabledCurrencies: z3.string().array().optional(),
200
201
  products: storefrontProductSchema.array(),
201
202
  bundles: storefrontBundleSchema.array(),
202
203
  // Offers need to be optional since we may still have old, cached representations in browsers
@@ -1307,10 +1308,16 @@ var OfferUtils = class {
1307
1308
  switch (offer.condition.type) {
1308
1309
  case "CartContainsItems":
1309
1310
  const relevantItems = order.items.filter(
1310
- (i) => i.type === "Product" && offer.condition.relevantItemVariations[`Product/${i.productId}`] && (offer.condition.relevantItemVariations[`Product/${i.productId}`].length === 0 || offer.condition.relevantItemVariations[`Product/${i.productId}`].includes(i.variationId)) || i.type === "Bundle" && offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`] && (offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`].length === 0 || offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`].includes(i.variationId))
1311
+ (i) => i.type === "Product" && offer.condition.relevantItemVariations[`Product/${i.productId}`] && offer.condition.relevantItemVariations[`Product/${i.productId}`].includes(i.variationId) || i.type === "Bundle" && offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`] && offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`].includes(i.variationId)
1311
1312
  );
1312
- console.log("Relevant items for offer:", { offer, relevantItems });
1313
- return relevantItems.length >= offer.condition.minimumItems;
1313
+ const relevantReplacedItems = order.items.flatMap((i) => {
1314
+ var _a;
1315
+ return i.type === "Bundle" && offer.target.type === "Bundle" && offer.target.id === i.bundleId && offer.id === i.offerId ? (_a = i.replaced) != null ? _a : [] : [];
1316
+ }).filter((ref) => {
1317
+ const [productId, variationId] = ref.split("/");
1318
+ return offer.condition.relevantItemVariations[`Product/${productId}`] && offer.condition.relevantItemVariations[`Product/${productId}`].includes(variationId);
1319
+ });
1320
+ return relevantItems.length + relevantReplacedItems.length >= offer.condition.minimumItems;
1314
1321
  }
1315
1322
  console.warn("Unsupported offer condition found:", offer.condition);
1316
1323
  return false;
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.27",
4
+ "version": "0.4.31",
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",