@moonbase.sh/vue 0.4.25 → 0.4.27

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
@@ -19,8 +19,8 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
 
21
21
  // src/index.ts
22
- var src_exports = {};
23
- __export(src_exports, {
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
24
  createStorefront: () => createStorefront,
25
25
  storefrontKey: () => storefrontKey,
26
26
  useActivationRequest: () => useActivationRequest,
@@ -29,15 +29,18 @@ __export(src_exports, {
29
29
  useBundles: () => useBundles,
30
30
  useCart: () => useCart,
31
31
  useCheckout: () => useCheckout,
32
+ useEligibleOffers: () => useEligibleOffers,
32
33
  useInventory: () => useInventory,
34
+ useOffer: () => useOffer,
35
+ useOffers: () => useOffers,
33
36
  useProduct: () => useProduct,
34
37
  useProducts: () => useProducts,
35
38
  useVendor: () => useVendor,
36
39
  useVoucher: () => useVoucher
37
40
  });
38
- module.exports = __toCommonJS(src_exports);
39
- var import_storefront_api7 = require("@moonbase.sh/storefront-api");
40
- var import_vue13 = require("vue");
41
+ module.exports = __toCommonJS(index_exports);
42
+ var import_storefront_api8 = require("@moonbase.sh/storefront-api");
43
+ var import_vue15 = require("vue");
41
44
 
42
45
  // src/context.ts
43
46
  var import_storefront_api2 = require("@moonbase.sh/storefront-api");
@@ -133,6 +136,65 @@ function mountCheckout(endpoint) {
133
136
  };
134
137
  }
135
138
 
139
+ // src/utils/iframe-subscription.ts
140
+ var import_zod2 = require("zod");
141
+ var closeEventSchema2 = import_zod2.z.object({
142
+ source: import_zod2.z.literal("moonbase-subscription"),
143
+ event: import_zod2.z.literal("close"),
144
+ completed: import_zod2.z.boolean()
145
+ });
146
+ var updatedPaymentMethodSchema = import_zod2.z.object({
147
+ source: import_zod2.z.literal("moonbase-subscription"),
148
+ event: import_zod2.z.literal("updated-payment-method")
149
+ });
150
+ var eventSchema2 = import_zod2.z.discriminatedUnion("event", [closeEventSchema2, updatedPaymentMethodSchema]);
151
+ function mountSubscription(endpoint) {
152
+ if (typeof window === "undefined") {
153
+ console.warn("Can not mount subscription server side");
154
+ return;
155
+ }
156
+ if (document.getElementById("moonbase-subscription"))
157
+ return;
158
+ const iframe = document.createElement("iframe");
159
+ iframe.id = "moonbase-subscription";
160
+ iframe.src = endpoint;
161
+ iframe.style.position = "fixed";
162
+ iframe.style.top = "0px";
163
+ iframe.style.left = "0px";
164
+ iframe.style.right = "0px";
165
+ iframe.style.border = "none";
166
+ iframe.style.colorScheme = "normal";
167
+ iframe.style.backgroundColor = "transparent";
168
+ iframe.style.zIndex = Number.MAX_SAFE_INTEGER.toString();
169
+ iframe.setAttribute("background", "transparent");
170
+ iframe.setAttribute("frameborder", "0");
171
+ iframe.setAttribute("allowtransparency", "true");
172
+ iframe.setAttribute("allow", "payment");
173
+ iframe.height = "100%";
174
+ iframe.width = "100%";
175
+ document.body.append(iframe);
176
+ document.documentElement.style.overflow = "hidden";
177
+ window.onmessage = function(e) {
178
+ var _a;
179
+ try {
180
+ const evnt = eventSchema2.parse(e.data);
181
+ if (evnt.event === "close") {
182
+ if (document.body.contains(iframe)) {
183
+ document.documentElement.style.removeProperty("overflow");
184
+ document.body.removeChild(iframe);
185
+ }
186
+ window.dispatchEvent(new CustomEvent("moonbase-subscription-closed", {
187
+ detail: evnt
188
+ }));
189
+ }
190
+ } catch (err) {
191
+ if (((_a = e.data) == null ? void 0 : _a.source) === "moonbase-subscription") {
192
+ console.error("Could not parse event:", e.data, err);
193
+ }
194
+ }
195
+ };
196
+ }
197
+
136
198
  // src/context.ts
137
199
  var _StorefrontContextImpl = class _StorefrontContextImpl {
138
200
  constructor(configuration, client, stateFactory) {
@@ -154,8 +216,10 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
154
216
  });
155
217
  this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, {
156
218
  suggestedCurrency: "",
219
+ enabledCurrencies: [],
157
220
  bundles: [],
158
- products: []
221
+ products: [],
222
+ offers: []
159
223
  });
160
224
  this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
161
225
  this.utm = stateFactory(_StorefrontContextImpl.utmKey, void 0);
@@ -207,8 +271,10 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
207
271
  } else {
208
272
  this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, {
209
273
  suggestedCurrency: "",
274
+ enabledCurrencies: [],
210
275
  bundles: [],
211
- products: []
276
+ products: [],
277
+ offers: []
212
278
  });
213
279
  this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
214
280
  }
@@ -230,6 +296,15 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
230
296
  mountCheckout(finalEndpoint.toString());
231
297
  window.history.replaceState(null, "", window.location.href.split("?")[0]);
232
298
  }
299
+ if (intent === "update_subscription" && urlParams2.get("mb_complete") && endpoint) {
300
+ const parameters = Object.fromEntries([...urlParams2.entries()].filter(([key]) => !key.startsWith("mb_")));
301
+ const finalEndpoint = new URL(decodeURIComponent(endpoint));
302
+ for (const prop of Object.keys(parameters)) {
303
+ finalEndpoint.searchParams.append(prop, parameters[prop]);
304
+ }
305
+ mountSubscription(finalEndpoint.toString());
306
+ window.history.replaceState(null, "", window.location.href.split("?")[0]);
307
+ }
233
308
  }
234
309
  window.addEventListener("moonbase-checkout-completed", (e) => {
235
310
  const order = e.detail.order;
@@ -296,7 +371,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
296
371
  localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
297
372
  this.storefront.value = latestStorefront;
298
373
  this.loadedStorefront.value = true;
299
- if (!this.currentOrder.value.currency) {
374
+ if (!this.currentOrder.value.currency || !latestStorefront.enabledCurrencies.includes(this.currentOrder.value.currency)) {
300
375
  this.currentOrder.value.currency = latestStorefront.suggestedCurrency;
301
376
  }
302
377
  this.currentOrder.value.items = this.enrichLineItems(this.currentOrder.value.items);
@@ -347,6 +422,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
347
422
  latestOrder.items = this.enrichLineItems(latestOrder.items);
348
423
  if (typeof window !== "undefined")
349
424
  localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
425
+ if (this.storefront.value && !this.storefront.value.enabledCurrencies.includes(latestOrder.currency)) {
426
+ latestOrder.currency = this.storefront.value.suggestedCurrency;
427
+ }
350
428
  this.currentOrder.value = latestOrder;
351
429
  }
352
430
  }
@@ -380,28 +458,35 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
380
458
  enrichLineItems(lineItems) {
381
459
  if (this.storefront) {
382
460
  return lineItems.map((item) => {
383
- var _a, _b;
461
+ var _a, _b, _c;
462
+ const offer = (_a = this.storefront.value.offers) == null ? void 0 : _a.find((o) => o.id === item.offerId);
384
463
  if (item.type === "Product") {
385
464
  const product = this.storefront.value.products.find((p) => p.id === item.productId);
386
465
  const variations = (product == null ? void 0 : product.variations) || [];
387
- const variation = variations.find((v) => v.id === item.variationId);
466
+ let variation = variations.find((v) => v.id === item.variationId);
467
+ if (offer && variation && import_storefront_api2.OfferUtils.eligible(offer, this.currentOrder.value)) {
468
+ variation = import_storefront_api2.OfferUtils.applyToVariation(offer, variation);
469
+ }
388
470
  return {
389
471
  ...item,
390
472
  product,
391
473
  variation,
392
474
  price: variation == null ? void 0 : variation.price,
393
- appliedDiscount: (_a = variation == null ? void 0 : variation.discount) != null ? _a : item.appliedDiscount
475
+ appliedDiscount: (_b = variation == null ? void 0 : variation.discount) != null ? _b : item.appliedDiscount
394
476
  };
395
477
  } else {
396
478
  const bundle = this.storefront.value.bundles.find((b) => b.id === item.bundleId);
397
479
  const variations = (bundle == null ? void 0 : bundle.variations) || [];
398
- const variation = variations.find((v) => v.id === item.variationId);
480
+ let variation = variations.find((v) => v.id === item.variationId);
481
+ if (offer && variation && import_storefront_api2.OfferUtils.eligible(offer, this.currentOrder.value)) {
482
+ variation = import_storefront_api2.OfferUtils.applyToVariation(offer, variation);
483
+ }
399
484
  return {
400
485
  ...item,
401
486
  bundle,
402
487
  variation,
403
488
  price: variation == null ? void 0 : variation.price,
404
- appliedDiscount: (_b = variation == null ? void 0 : variation.discount) != null ? _b : item.appliedDiscount
489
+ appliedDiscount: (_c = variation == null ? void 0 : variation.discount) != null ? _c : item.appliedDiscount
405
490
  };
406
491
  }
407
492
  });
@@ -611,7 +696,7 @@ function useCart(context) {
611
696
  const total = (0, import_vue6.computed)(() => {
612
697
  const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
613
698
  const total2 = storefront.currentOrder.value.items.reduce((agg, item) => {
614
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
699
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
615
700
  let price;
616
701
  if (item.type === "Product") {
617
702
  const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
@@ -626,70 +711,113 @@ function useCart(context) {
626
711
  const pickedVariation = variations.find((v) => v.id === item.variationId);
627
712
  price = (_i = (_h = pickedVariation == null ? void 0 : pickedVariation.price[currency]) != null ? _h : (_g = bundle == null ? void 0 : bundle.defaultVariation) == null ? void 0 : _g.price[currency]) != null ? _i : 0;
628
713
  }
714
+ const offer = (_j = storefront.storefront.value.offers) == null ? void 0 : _j.find((o) => o.id === item.offerId);
715
+ if (offer && import_storefront_api4.OfferUtils.eligible(offer, storefront.currentOrder.value)) {
716
+ const offerDiscount = import_storefront_api4.DiscountUtils.apply(offer.discount, { [currency]: price });
717
+ price -= offerDiscount[currency];
718
+ }
629
719
  return agg + price * item.quantity;
630
720
  }, 0);
631
721
  return { amount: total2, currency };
632
722
  });
633
- return {
634
- items: (0, import_vue6.computed)(() => storefront.enrichLineItems(storefront.currentOrder.value.items)),
635
- currency: (0, import_vue6.computed)(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
636
- total,
637
- addToCart: (item, variation) => {
638
- var _a, _b;
639
- item = (0, import_vue6.unref)(item);
640
- variation != null ? variation : variation = item.defaultVariation;
641
- if (!variation)
642
- throw new Error("Added item does not have a default variation, and none have been specified");
643
- const id = `${item.type === "bundle" ? "b" : "p"}/${item.id}/${variation.id}`;
644
- let lineItem = storefront.currentOrder.value.items.find((i) => i.id === id);
645
- if (!lineItem) {
646
- if (item.type === "bundle") {
647
- lineItem = {
648
- id,
649
- type: "Bundle",
650
- bundleId: item.id,
651
- bundle: item,
652
- quantity: 1,
653
- variation,
654
- variationId: variation.id,
655
- price: variation.price,
656
- appliedDiscount: variation.discount,
657
- isDefaultVariation: variation.id === ((_a = item.defaultVariation) == null ? void 0 : _a.id)
658
- };
659
- storefront.currentOrder.value.items.push(lineItem);
660
- } else if (item.type === "product") {
661
- lineItem = {
723
+ function addToCart(item, variation, offer, options) {
724
+ var _a, _b, _c;
725
+ item = (0, import_vue6.unref)(item);
726
+ variation != null ? variation : variation = item.defaultVariation;
727
+ if (!variation)
728
+ throw new Error("Added item does not have a default variation, and none have been specified");
729
+ const id = `${item.type === "Bundle" ? "b" : "p"}/${item.id}/${variation.id}`;
730
+ let lineItem = storefront == null ? void 0 : storefront.currentOrder.value.items.find((i) => i.id === id);
731
+ if (!lineItem) {
732
+ if (item.type === "Bundle") {
733
+ lineItem = {
734
+ id,
735
+ type: "Bundle",
736
+ bundleId: item.id,
737
+ bundle: item,
738
+ quantity: 1,
739
+ variation,
740
+ variationId: variation.id,
741
+ offerId: offer == null ? void 0 : offer.id,
742
+ price: variation.price,
743
+ appliedDiscount: variation.discount,
744
+ isDefaultVariation: variation.id === ((_a = item.defaultVariation) == null ? void 0 : _a.id)
745
+ };
746
+ if ((options == null ? void 0 : options.bundleBehaviour) === "replace") {
747
+ const lineItemsToReplace = storefront == null ? void 0 : storefront.currentOrder.value.items.filter((i) => i.type === "Product" && item.products.some((p) => p.included && p.id === i.productId));
748
+ for (const productLineItem of lineItemsToReplace != null ? lineItemsToReplace : []) {
749
+ const index = storefront == null ? void 0 : storefront.currentOrder.value.items.findIndex((i) => i.id === productLineItem.id);
750
+ if (index !== void 0)
751
+ storefront == null ? void 0 : storefront.currentOrder.value.items.splice(index, 1);
752
+ }
753
+ lineItem.replaced = lineItemsToReplace == null ? void 0 : lineItemsToReplace.filter((i) => i.type === "Product").map((i) => `${i.productId}/${i.variationId}`);
754
+ }
755
+ storefront == null ? void 0 : storefront.currentOrder.value.items.push(lineItem);
756
+ } else if (item.type === "Product") {
757
+ lineItem = {
758
+ id,
759
+ type: "Product",
760
+ productId: item.id,
761
+ product: item,
762
+ quantity: 1,
763
+ variation,
764
+ variationId: variation.id,
765
+ offerId: offer == null ? void 0 : offer.id,
766
+ price: variation.price,
767
+ appliedDiscount: variation.discount,
768
+ isDefaultVariation: variation.id === ((_b = item.defaultVariation) == null ? void 0 : _b.id)
769
+ };
770
+ storefront == null ? void 0 : storefront.currentOrder.value.items.push(lineItem);
771
+ } else {
772
+ throw new import_storefront_api4.MoonbaseError("Invalid input", `Could not handle item of type '${item.type}'`);
773
+ }
774
+ } else {
775
+ lineItem.quantity += 1;
776
+ (_c = lineItem.offerId) != null ? _c : lineItem.offerId = offer == null ? void 0 : offer.id;
777
+ if (!lineItem.variation && variation)
778
+ lineItem.variation = variation;
779
+ if (!lineItem.price && variation)
780
+ lineItem.price = variation.price;
781
+ if (!lineItem.appliedDiscount && variation.discount)
782
+ lineItem.appliedDiscount = variation.discount;
783
+ if (lineItem.type === "Product" && item.type === "Product" && !lineItem.product)
784
+ lineItem.product = item;
785
+ if (lineItem.type === "Bundle" && item.type === "Bundle" && !lineItem.bundle)
786
+ lineItem.bundle = item;
787
+ }
788
+ const _ = storefront == null ? void 0 : storefront.pushOrderContent();
789
+ return lineItem;
790
+ }
791
+ function addReplacedBundleProducts(cartItem) {
792
+ var _a, _b;
793
+ if (cartItem.type === "Bundle" && cartItem.replaced && cartItem.replaced.length > 0) {
794
+ for (const { productId, variationId } of cartItem.replaced.map((composite) => ({ productId: composite.split("/")[0], variationId: composite.split("/")[1] }))) {
795
+ const product = storefront == null ? void 0 : storefront.storefront.value.products.find((p) => p.id === productId);
796
+ const variation = (_a = product == null ? void 0 : product.variations) == null ? void 0 : _a.find((v) => v.id === variationId);
797
+ if (product && variation && !(storefront == null ? void 0 : storefront.currentOrder.value.items.some((i) => i.type === "Product" && i.productId === productId))) {
798
+ const id = `p/${product.id}/${variationId}`;
799
+ storefront == null ? void 0 : storefront.currentOrder.value.items.push({
662
800
  id,
663
801
  type: "Product",
664
- productId: item.id,
665
- product: item,
802
+ productId: product.id,
803
+ product,
666
804
  quantity: 1,
667
805
  variation,
668
- variationId: variation.id,
806
+ variationId,
807
+ // offerId: offer?.id, // TODO: Should we handle this?
669
808
  price: variation.price,
670
809
  appliedDiscount: variation.discount,
671
- isDefaultVariation: variation.id === ((_b = item.defaultVariation) == null ? void 0 : _b.id)
672
- };
673
- storefront.currentOrder.value.items.push(lineItem);
674
- } else {
675
- throw new import_storefront_api4.MoonbaseError("Invalid input", `Could not handle item of type '${item.type}'`);
810
+ isDefaultVariation: variation.id === ((_b = product.defaultVariation) == null ? void 0 : _b.id)
811
+ });
676
812
  }
677
- } else {
678
- lineItem.quantity += 1;
679
- if (!lineItem.variation && variation)
680
- lineItem.variation = variation;
681
- if (!lineItem.price && variation)
682
- lineItem.price = variation.price;
683
- if (!lineItem.appliedDiscount && variation.discount)
684
- lineItem.appliedDiscount = variation.discount;
685
- if (lineItem.type === "Product" && item.type === "product" && !lineItem.product)
686
- lineItem.product = item;
687
- if (lineItem.type === "Bundle" && item.type === "bundle" && !lineItem.bundle)
688
- lineItem.bundle = item;
689
813
  }
690
- const _ = storefront.pushOrderContent();
691
- return lineItem;
692
- },
814
+ }
815
+ }
816
+ return {
817
+ items: (0, import_vue6.computed)(() => storefront.enrichLineItems(storefront.currentOrder.value.items)),
818
+ currency: (0, import_vue6.computed)(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
819
+ total,
820
+ addToCart,
693
821
  setQuantity: (cartItem, quantity) => {
694
822
  const cartItemRef = storefront.currentOrder.value.items.find((i) => i.id === cartItem.id);
695
823
  if (!cartItemRef)
@@ -698,6 +826,7 @@ function useCart(context) {
698
826
  if (cartItemRef.quantity <= 0) {
699
827
  const index = storefront.currentOrder.value.items.findIndex((i) => i.id === cartItemRef.id);
700
828
  storefront.currentOrder.value.items.splice(index, 1);
829
+ addReplacedBundleProducts(cartItem);
701
830
  }
702
831
  const _ = storefront.pushOrderContent();
703
832
  return cartItem;
@@ -705,6 +834,7 @@ function useCart(context) {
705
834
  removeFromCart: (cartItem) => {
706
835
  const index = storefront.currentOrder.value.items.findIndex((i) => i.id === cartItem.id);
707
836
  storefront.currentOrder.value.items.splice(index, 1);
837
+ addReplacedBundleProducts(cartItem);
708
838
  const _ = storefront.pushOrderContent();
709
839
  },
710
840
  checkout: async (options) => {
@@ -752,8 +882,8 @@ async function useCheckout(items, options, context) {
752
882
  const variation = (_a = item.variation) != null ? _a : target.defaultVariation;
753
883
  if (!variation)
754
884
  throw new Error("Added item does not have a default variation, and none have been specified");
755
- const id = `${target.type === "bundle" ? "b" : "p"}/${target.id}/${variation.id}`;
756
- if (target.type === "bundle") {
885
+ const id = `${target.type === "Bundle" ? "b" : "p"}/${target.id}/${variation.id}`;
886
+ if (target.type === "Bundle") {
757
887
  checkoutSession.push({
758
888
  id,
759
889
  type: "Bundle",
@@ -765,7 +895,7 @@ async function useCheckout(items, options, context) {
765
895
  price: variation.price,
766
896
  appliedDiscount: variation.discount
767
897
  });
768
- } else if (target.type === "product") {
898
+ } else if (target.type === "Product") {
769
899
  checkoutSession.push({
770
900
  id,
771
901
  type: "Product",
@@ -876,36 +1006,102 @@ function useInventory(context) {
876
1006
  }, { once: true });
877
1007
  });
878
1008
  }
1009
+ },
1010
+ updateSubscriptionPaymentMethod: async (subscription, options) => {
1011
+ var _a;
1012
+ const fallbackPath = typeof window !== "undefined" ? window.location.pathname : "";
1013
+ const absoluteReturnUrl = new URL((_a = options.returnUrl) != null ? _a : fallbackPath, document.baseURI).href;
1014
+ const response = await storefront.client.inventory.subscriptions.getById(subscription.id, {
1015
+ toUpdatePaymentMethod: true,
1016
+ returnUrl: absoluteReturnUrl
1017
+ });
1018
+ window.dispatchEvent(new CustomEvent("moonbase-subscription-payment-method-update-initiated", {
1019
+ detail: { subscription: (0, import_vue8.toRaw)(subscription) }
1020
+ }));
1021
+ if (response.embeddedUpdatePaymentUrl && typeof window !== "undefined") {
1022
+ const embeddedUrl = response.embeddedUpdatePaymentUrl;
1023
+ return new Promise((resolve) => {
1024
+ mountSubscription(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
1025
+ window.addEventListener("moonbase-subscription-closed", (e) => {
1026
+ const evnt = e;
1027
+ resolve({ completed: evnt.detail.completed });
1028
+ }, { once: true });
1029
+ });
1030
+ } else {
1031
+ throw new Error("No update URL found");
1032
+ }
879
1033
  }
880
1034
  };
881
1035
  }
882
1036
 
883
- // src/composables/useProduct.ts
1037
+ // src/composables/useOffer.ts
884
1038
  var import_vue9 = require("vue");
885
- function useProduct(productId, context) {
1039
+ function useOffer(offerId, context) {
886
1040
  const storefront = context != null ? context : (0, import_vue9.inject)(storefrontKey);
887
1041
  if (!storefront)
888
1042
  throw new Error("No storefront configured");
889
- return (0, import_vue9.computed)(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
1043
+ return (0, import_vue9.computed)(() => {
1044
+ var _a;
1045
+ return ((_a = storefront.storefront.value.offers) == null ? void 0 : _a.find((o) => o.id === offerId)) || null;
1046
+ });
890
1047
  }
891
1048
 
892
- // src/composables/useProducts.ts
1049
+ // src/composables/useOffers.ts
1050
+ var import_storefront_api6 = require("@moonbase.sh/storefront-api");
893
1051
  var import_vue10 = require("vue");
894
- function useProducts(context) {
1052
+ function useOffers(context) {
895
1053
  const storefront = context != null ? context : (0, import_vue10.inject)(storefrontKey);
896
1054
  if (!storefront)
897
1055
  throw new Error("No storefront configured");
898
- return (0, import_vue10.computed)(() => storefront.storefront.value.products);
1056
+ return (0, import_vue10.computed)(() => {
1057
+ var _a;
1058
+ return (_a = storefront.storefront.value.offers) != null ? _a : [];
1059
+ });
1060
+ }
1061
+ function useEligibleOffers(context) {
1062
+ const storefront = context != null ? context : (0, import_vue10.inject)(storefrontKey);
1063
+ if (!storefront)
1064
+ throw new Error("No storefront configured");
1065
+ return (0, import_vue10.computed)(() => {
1066
+ var _a;
1067
+ return ((_a = storefront.storefront.value.offers) != null ? _a : []).filter((o) => import_storefront_api6.OfferUtils.eligible(o, storefront.currentOrder.value) && !offerTargetIsInCart(o, storefront.currentOrder.value));
1068
+ });
1069
+ }
1070
+ function offerTargetIsInCart(offer, order) {
1071
+ if (order.items.some(
1072
+ (i) => i.type === "Product" && offer.target.type === "Product" && i.productId === offer.target.id || i.type === "Bundle" && offer.target.type === "Bundle" && i.bundleId === offer.target.id
1073
+ )) {
1074
+ return true;
1075
+ }
1076
+ return false;
899
1077
  }
900
1078
 
901
- // src/composables/useVendor.ts
1079
+ // src/composables/useProduct.ts
902
1080
  var import_vue11 = require("vue");
903
- function useVendor(context) {
1081
+ function useProduct(productId, context) {
904
1082
  const storefront = context != null ? context : (0, import_vue11.inject)(storefrontKey);
905
1083
  if (!storefront)
906
1084
  throw new Error("No storefront configured");
907
- const vendor = (0, import_vue11.ref)(null);
908
- const loading = (0, import_vue11.ref)(true);
1085
+ return (0, import_vue11.computed)(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
1086
+ }
1087
+
1088
+ // src/composables/useProducts.ts
1089
+ var import_vue12 = require("vue");
1090
+ function useProducts(context) {
1091
+ const storefront = context != null ? context : (0, import_vue12.inject)(storefrontKey);
1092
+ if (!storefront)
1093
+ throw new Error("No storefront configured");
1094
+ return (0, import_vue12.computed)(() => storefront.storefront.value.products);
1095
+ }
1096
+
1097
+ // src/composables/useVendor.ts
1098
+ var import_vue13 = require("vue");
1099
+ function useVendor(context) {
1100
+ const storefront = context != null ? context : (0, import_vue13.inject)(storefrontKey);
1101
+ if (!storefront)
1102
+ throw new Error("No storefront configured");
1103
+ const vendor = (0, import_vue13.ref)(null);
1104
+ const loading = (0, import_vue13.ref)(true);
909
1105
  storefront.client.vendor.get().then((v) => {
910
1106
  vendor.value = v;
911
1107
  loading.value = false;
@@ -917,10 +1113,10 @@ function useVendor(context) {
917
1113
  }
918
1114
 
919
1115
  // src/composables/useVoucher.ts
920
- var import_storefront_api6 = require("@moonbase.sh/storefront-api");
921
- var import_vue12 = require("vue");
1116
+ var import_storefront_api7 = require("@moonbase.sh/storefront-api");
1117
+ var import_vue14 = require("vue");
922
1118
  function useVoucher(context) {
923
- const storefront = context != null ? context : (0, import_vue12.inject)(storefrontKey);
1119
+ const storefront = context != null ? context : (0, import_vue14.inject)(storefrontKey);
924
1120
  if (!storefront)
925
1121
  throw new Error("No storefront configured");
926
1122
  return {
@@ -928,7 +1124,7 @@ function useVoucher(context) {
928
1124
  try {
929
1125
  return await storefront.client.vouchers.peek(code);
930
1126
  } catch (e) {
931
- if (e instanceof import_storefront_api6.NotFoundError)
1127
+ if (e instanceof import_storefront_api7.NotFoundError)
932
1128
  throw new Error("Voucher code invalid");
933
1129
  throw e;
934
1130
  }
@@ -937,7 +1133,7 @@ function useVoucher(context) {
937
1133
  try {
938
1134
  return await storefront.client.vouchers.redeem(code);
939
1135
  } catch (e) {
940
- if (e instanceof import_storefront_api6.NotFoundError)
1136
+ if (e instanceof import_storefront_api7.NotFoundError)
941
1137
  throw new Error("Voucher code invalid");
942
1138
  throw e;
943
1139
  }
@@ -946,7 +1142,7 @@ function useVoucher(context) {
946
1142
  }
947
1143
 
948
1144
  // src/index.ts
949
- __reExport(src_exports, require("@moonbase.sh/storefront-api"), module.exports);
1145
+ __reExport(index_exports, require("@moonbase.sh/storefront-api"), module.exports);
950
1146
  function createStorefront(endpoint, stateFactory, config) {
951
1147
  const configuration = {
952
1148
  ...config != null ? config : {},
@@ -954,9 +1150,9 @@ function createStorefront(endpoint, stateFactory, config) {
954
1150
  };
955
1151
  return new StorefrontContextImpl(
956
1152
  configuration,
957
- new import_storefront_api7.MoonbaseClient(configuration),
1153
+ new import_storefront_api8.MoonbaseClient(configuration),
958
1154
  // Default to vue refs but allow stuff like Nuxt useState wrappers
959
- stateFactory || ((_, state) => (0, import_vue13.ref)(state))
1155
+ stateFactory || ((_, state) => (0, import_vue15.ref)(state))
960
1156
  );
961
1157
  }
962
1158
  // Annotate the CommonJS export names for ESM import in node:
@@ -969,7 +1165,10 @@ function createStorefront(endpoint, stateFactory, config) {
969
1165
  useBundles,
970
1166
  useCart,
971
1167
  useCheckout,
1168
+ useEligibleOffers,
972
1169
  useInventory,
1170
+ useOffer,
1171
+ useOffers,
973
1172
  useProduct,
974
1173
  useProducts,
975
1174
  useVendor,