@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.js CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  NotAuthenticatedError,
8
8
  NotAuthorizedError,
9
9
  NotFoundError,
10
+ OfferUtils,
10
11
  OrderStatus,
11
12
  schemas as schemas2,
12
13
  TokenStore
@@ -103,6 +104,65 @@ function mountCheckout(endpoint) {
103
104
  };
104
105
  }
105
106
 
107
+ // src/utils/iframe-subscription.ts
108
+ import { z as z2 } from "zod";
109
+ var closeEventSchema2 = z2.object({
110
+ source: z2.literal("moonbase-subscription"),
111
+ event: z2.literal("close"),
112
+ completed: z2.boolean()
113
+ });
114
+ var updatedPaymentMethodSchema = z2.object({
115
+ source: z2.literal("moonbase-subscription"),
116
+ event: z2.literal("updated-payment-method")
117
+ });
118
+ var eventSchema2 = z2.discriminatedUnion("event", [closeEventSchema2, updatedPaymentMethodSchema]);
119
+ function mountSubscription(endpoint) {
120
+ if (typeof window === "undefined") {
121
+ console.warn("Can not mount subscription server side");
122
+ return;
123
+ }
124
+ if (document.getElementById("moonbase-subscription"))
125
+ return;
126
+ const iframe = document.createElement("iframe");
127
+ iframe.id = "moonbase-subscription";
128
+ iframe.src = endpoint;
129
+ iframe.style.position = "fixed";
130
+ iframe.style.top = "0px";
131
+ iframe.style.left = "0px";
132
+ iframe.style.right = "0px";
133
+ iframe.style.border = "none";
134
+ iframe.style.colorScheme = "normal";
135
+ iframe.style.backgroundColor = "transparent";
136
+ iframe.style.zIndex = Number.MAX_SAFE_INTEGER.toString();
137
+ iframe.setAttribute("background", "transparent");
138
+ iframe.setAttribute("frameborder", "0");
139
+ iframe.setAttribute("allowtransparency", "true");
140
+ iframe.setAttribute("allow", "payment");
141
+ iframe.height = "100%";
142
+ iframe.width = "100%";
143
+ document.body.append(iframe);
144
+ document.documentElement.style.overflow = "hidden";
145
+ window.onmessage = function(e) {
146
+ var _a;
147
+ try {
148
+ const evnt = eventSchema2.parse(e.data);
149
+ if (evnt.event === "close") {
150
+ if (document.body.contains(iframe)) {
151
+ document.documentElement.style.removeProperty("overflow");
152
+ document.body.removeChild(iframe);
153
+ }
154
+ window.dispatchEvent(new CustomEvent("moonbase-subscription-closed", {
155
+ detail: evnt
156
+ }));
157
+ }
158
+ } catch (err) {
159
+ if (((_a = e.data) == null ? void 0 : _a.source) === "moonbase-subscription") {
160
+ console.error("Could not parse event:", e.data, err);
161
+ }
162
+ }
163
+ };
164
+ }
165
+
106
166
  // src/context.ts
107
167
  var _StorefrontContextImpl = class _StorefrontContextImpl {
108
168
  constructor(configuration, client, stateFactory) {
@@ -124,8 +184,10 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
124
184
  });
125
185
  this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, {
126
186
  suggestedCurrency: "",
187
+ enabledCurrencies: [],
127
188
  bundles: [],
128
- products: []
189
+ products: [],
190
+ offers: []
129
191
  });
130
192
  this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
131
193
  this.utm = stateFactory(_StorefrontContextImpl.utmKey, void 0);
@@ -177,8 +239,10 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
177
239
  } else {
178
240
  this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, {
179
241
  suggestedCurrency: "",
242
+ enabledCurrencies: [],
180
243
  bundles: [],
181
- products: []
244
+ products: [],
245
+ offers: []
182
246
  });
183
247
  this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
184
248
  }
@@ -200,6 +264,15 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
200
264
  mountCheckout(finalEndpoint.toString());
201
265
  window.history.replaceState(null, "", window.location.href.split("?")[0]);
202
266
  }
267
+ if (intent === "update_subscription" && urlParams2.get("mb_complete") && endpoint) {
268
+ const parameters = Object.fromEntries([...urlParams2.entries()].filter(([key]) => !key.startsWith("mb_")));
269
+ const finalEndpoint = new URL(decodeURIComponent(endpoint));
270
+ for (const prop of Object.keys(parameters)) {
271
+ finalEndpoint.searchParams.append(prop, parameters[prop]);
272
+ }
273
+ mountSubscription(finalEndpoint.toString());
274
+ window.history.replaceState(null, "", window.location.href.split("?")[0]);
275
+ }
203
276
  }
204
277
  window.addEventListener("moonbase-checkout-completed", (e) => {
205
278
  const order = e.detail.order;
@@ -266,7 +339,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
266
339
  localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
267
340
  this.storefront.value = latestStorefront;
268
341
  this.loadedStorefront.value = true;
269
- if (!this.currentOrder.value.currency) {
342
+ if (!this.currentOrder.value.currency || !latestStorefront.enabledCurrencies.includes(this.currentOrder.value.currency)) {
270
343
  this.currentOrder.value.currency = latestStorefront.suggestedCurrency;
271
344
  }
272
345
  this.currentOrder.value.items = this.enrichLineItems(this.currentOrder.value.items);
@@ -317,6 +390,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
317
390
  latestOrder.items = this.enrichLineItems(latestOrder.items);
318
391
  if (typeof window !== "undefined")
319
392
  localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
393
+ if (this.storefront.value && !this.storefront.value.enabledCurrencies.includes(latestOrder.currency)) {
394
+ latestOrder.currency = this.storefront.value.suggestedCurrency;
395
+ }
320
396
  this.currentOrder.value = latestOrder;
321
397
  }
322
398
  }
@@ -350,28 +426,35 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
350
426
  enrichLineItems(lineItems) {
351
427
  if (this.storefront) {
352
428
  return lineItems.map((item) => {
353
- var _a, _b;
429
+ var _a, _b, _c;
430
+ const offer = (_a = this.storefront.value.offers) == null ? void 0 : _a.find((o) => o.id === item.offerId);
354
431
  if (item.type === "Product") {
355
432
  const product = this.storefront.value.products.find((p) => p.id === item.productId);
356
433
  const variations = (product == null ? void 0 : product.variations) || [];
357
- const variation = variations.find((v) => v.id === item.variationId);
434
+ let variation = variations.find((v) => v.id === item.variationId);
435
+ if (offer && variation && OfferUtils.eligible(offer, this.currentOrder.value)) {
436
+ variation = OfferUtils.applyToVariation(offer, variation);
437
+ }
358
438
  return {
359
439
  ...item,
360
440
  product,
361
441
  variation,
362
442
  price: variation == null ? void 0 : variation.price,
363
- appliedDiscount: (_a = variation == null ? void 0 : variation.discount) != null ? _a : item.appliedDiscount
443
+ appliedDiscount: (_b = variation == null ? void 0 : variation.discount) != null ? _b : item.appliedDiscount
364
444
  };
365
445
  } else {
366
446
  const bundle = this.storefront.value.bundles.find((b) => b.id === item.bundleId);
367
447
  const variations = (bundle == null ? void 0 : bundle.variations) || [];
368
- const variation = variations.find((v) => v.id === item.variationId);
448
+ let variation = variations.find((v) => v.id === item.variationId);
449
+ if (offer && variation && OfferUtils.eligible(offer, this.currentOrder.value)) {
450
+ variation = OfferUtils.applyToVariation(offer, variation);
451
+ }
369
452
  return {
370
453
  ...item,
371
454
  bundle,
372
455
  variation,
373
456
  price: variation == null ? void 0 : variation.price,
374
- appliedDiscount: (_b = variation == null ? void 0 : variation.discount) != null ? _b : item.appliedDiscount
457
+ appliedDiscount: (_c = variation == null ? void 0 : variation.discount) != null ? _c : item.appliedDiscount
375
458
  };
376
459
  }
377
460
  });
@@ -572,7 +655,7 @@ function useBundles(context) {
572
655
  }
573
656
 
574
657
  // src/composables/useCart.ts
575
- import { MoonbaseError } from "@moonbase.sh/storefront-api";
658
+ import { DiscountUtils, MoonbaseError, OfferUtils as OfferUtils2 } from "@moonbase.sh/storefront-api";
576
659
  import { computed as computed4, inject as inject5, unref } from "vue";
577
660
  function useCart(context) {
578
661
  const storefront = context != null ? context : inject5(storefrontKey);
@@ -581,7 +664,7 @@ function useCart(context) {
581
664
  const total = computed4(() => {
582
665
  const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
583
666
  const total2 = storefront.currentOrder.value.items.reduce((agg, item) => {
584
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
667
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
585
668
  let price;
586
669
  if (item.type === "Product") {
587
670
  const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
@@ -596,70 +679,113 @@ function useCart(context) {
596
679
  const pickedVariation = variations.find((v) => v.id === item.variationId);
597
680
  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;
598
681
  }
682
+ const offer = (_j = storefront.storefront.value.offers) == null ? void 0 : _j.find((o) => o.id === item.offerId);
683
+ if (offer && OfferUtils2.eligible(offer, storefront.currentOrder.value)) {
684
+ const offerDiscount = DiscountUtils.apply(offer.discount, { [currency]: price });
685
+ price -= offerDiscount[currency];
686
+ }
599
687
  return agg + price * item.quantity;
600
688
  }, 0);
601
689
  return { amount: total2, currency };
602
690
  });
603
- return {
604
- items: computed4(() => storefront.enrichLineItems(storefront.currentOrder.value.items)),
605
- currency: computed4(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
606
- total,
607
- addToCart: (item, variation) => {
608
- var _a, _b;
609
- item = unref(item);
610
- variation != null ? variation : variation = item.defaultVariation;
611
- if (!variation)
612
- throw new Error("Added item does not have a default variation, and none have been specified");
613
- const id = `${item.type === "bundle" ? "b" : "p"}/${item.id}/${variation.id}`;
614
- let lineItem = storefront.currentOrder.value.items.find((i) => i.id === id);
615
- if (!lineItem) {
616
- if (item.type === "bundle") {
617
- lineItem = {
618
- id,
619
- type: "Bundle",
620
- bundleId: item.id,
621
- bundle: item,
622
- quantity: 1,
623
- variation,
624
- variationId: variation.id,
625
- price: variation.price,
626
- appliedDiscount: variation.discount,
627
- isDefaultVariation: variation.id === ((_a = item.defaultVariation) == null ? void 0 : _a.id)
628
- };
629
- storefront.currentOrder.value.items.push(lineItem);
630
- } else if (item.type === "product") {
631
- lineItem = {
691
+ function addToCart(item, variation, offer, options) {
692
+ var _a, _b, _c;
693
+ item = unref(item);
694
+ variation != null ? variation : variation = item.defaultVariation;
695
+ if (!variation)
696
+ throw new Error("Added item does not have a default variation, and none have been specified");
697
+ const id = `${item.type === "Bundle" ? "b" : "p"}/${item.id}/${variation.id}`;
698
+ let lineItem = storefront == null ? void 0 : storefront.currentOrder.value.items.find((i) => i.id === id);
699
+ if (!lineItem) {
700
+ if (item.type === "Bundle") {
701
+ lineItem = {
702
+ id,
703
+ type: "Bundle",
704
+ bundleId: item.id,
705
+ bundle: item,
706
+ quantity: 1,
707
+ variation,
708
+ variationId: variation.id,
709
+ offerId: offer == null ? void 0 : offer.id,
710
+ price: variation.price,
711
+ appliedDiscount: variation.discount,
712
+ isDefaultVariation: variation.id === ((_a = item.defaultVariation) == null ? void 0 : _a.id)
713
+ };
714
+ if ((options == null ? void 0 : options.bundleBehaviour) === "replace") {
715
+ 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));
716
+ for (const productLineItem of lineItemsToReplace != null ? lineItemsToReplace : []) {
717
+ const index = storefront == null ? void 0 : storefront.currentOrder.value.items.findIndex((i) => i.id === productLineItem.id);
718
+ if (index !== void 0)
719
+ storefront == null ? void 0 : storefront.currentOrder.value.items.splice(index, 1);
720
+ }
721
+ lineItem.replaced = lineItemsToReplace == null ? void 0 : lineItemsToReplace.filter((i) => i.type === "Product").map((i) => `${i.productId}/${i.variationId}`);
722
+ }
723
+ storefront == null ? void 0 : storefront.currentOrder.value.items.push(lineItem);
724
+ } else if (item.type === "Product") {
725
+ lineItem = {
726
+ id,
727
+ type: "Product",
728
+ productId: item.id,
729
+ product: item,
730
+ quantity: 1,
731
+ variation,
732
+ variationId: variation.id,
733
+ offerId: offer == null ? void 0 : offer.id,
734
+ price: variation.price,
735
+ appliedDiscount: variation.discount,
736
+ isDefaultVariation: variation.id === ((_b = item.defaultVariation) == null ? void 0 : _b.id)
737
+ };
738
+ storefront == null ? void 0 : storefront.currentOrder.value.items.push(lineItem);
739
+ } else {
740
+ throw new MoonbaseError("Invalid input", `Could not handle item of type '${item.type}'`);
741
+ }
742
+ } else {
743
+ lineItem.quantity += 1;
744
+ (_c = lineItem.offerId) != null ? _c : lineItem.offerId = offer == null ? void 0 : offer.id;
745
+ if (!lineItem.variation && variation)
746
+ lineItem.variation = variation;
747
+ if (!lineItem.price && variation)
748
+ lineItem.price = variation.price;
749
+ if (!lineItem.appliedDiscount && variation.discount)
750
+ lineItem.appliedDiscount = variation.discount;
751
+ if (lineItem.type === "Product" && item.type === "Product" && !lineItem.product)
752
+ lineItem.product = item;
753
+ if (lineItem.type === "Bundle" && item.type === "Bundle" && !lineItem.bundle)
754
+ lineItem.bundle = item;
755
+ }
756
+ const _ = storefront == null ? void 0 : storefront.pushOrderContent();
757
+ return lineItem;
758
+ }
759
+ function addReplacedBundleProducts(cartItem) {
760
+ var _a, _b;
761
+ if (cartItem.type === "Bundle" && cartItem.replaced && cartItem.replaced.length > 0) {
762
+ for (const { productId, variationId } of cartItem.replaced.map((composite) => ({ productId: composite.split("/")[0], variationId: composite.split("/")[1] }))) {
763
+ const product = storefront == null ? void 0 : storefront.storefront.value.products.find((p) => p.id === productId);
764
+ const variation = (_a = product == null ? void 0 : product.variations) == null ? void 0 : _a.find((v) => v.id === variationId);
765
+ if (product && variation && !(storefront == null ? void 0 : storefront.currentOrder.value.items.some((i) => i.type === "Product" && i.productId === productId))) {
766
+ const id = `p/${product.id}/${variationId}`;
767
+ storefront == null ? void 0 : storefront.currentOrder.value.items.push({
632
768
  id,
633
769
  type: "Product",
634
- productId: item.id,
635
- product: item,
770
+ productId: product.id,
771
+ product,
636
772
  quantity: 1,
637
773
  variation,
638
- variationId: variation.id,
774
+ variationId,
775
+ // offerId: offer?.id, // TODO: Should we handle this?
639
776
  price: variation.price,
640
777
  appliedDiscount: variation.discount,
641
- isDefaultVariation: variation.id === ((_b = item.defaultVariation) == null ? void 0 : _b.id)
642
- };
643
- storefront.currentOrder.value.items.push(lineItem);
644
- } else {
645
- throw new MoonbaseError("Invalid input", `Could not handle item of type '${item.type}'`);
778
+ isDefaultVariation: variation.id === ((_b = product.defaultVariation) == null ? void 0 : _b.id)
779
+ });
646
780
  }
647
- } else {
648
- lineItem.quantity += 1;
649
- if (!lineItem.variation && variation)
650
- lineItem.variation = variation;
651
- if (!lineItem.price && variation)
652
- lineItem.price = variation.price;
653
- if (!lineItem.appliedDiscount && variation.discount)
654
- lineItem.appliedDiscount = variation.discount;
655
- if (lineItem.type === "Product" && item.type === "product" && !lineItem.product)
656
- lineItem.product = item;
657
- if (lineItem.type === "Bundle" && item.type === "bundle" && !lineItem.bundle)
658
- lineItem.bundle = item;
659
781
  }
660
- const _ = storefront.pushOrderContent();
661
- return lineItem;
662
- },
782
+ }
783
+ }
784
+ return {
785
+ items: computed4(() => storefront.enrichLineItems(storefront.currentOrder.value.items)),
786
+ currency: computed4(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
787
+ total,
788
+ addToCart,
663
789
  setQuantity: (cartItem, quantity) => {
664
790
  const cartItemRef = storefront.currentOrder.value.items.find((i) => i.id === cartItem.id);
665
791
  if (!cartItemRef)
@@ -668,6 +794,7 @@ function useCart(context) {
668
794
  if (cartItemRef.quantity <= 0) {
669
795
  const index = storefront.currentOrder.value.items.findIndex((i) => i.id === cartItemRef.id);
670
796
  storefront.currentOrder.value.items.splice(index, 1);
797
+ addReplacedBundleProducts(cartItem);
671
798
  }
672
799
  const _ = storefront.pushOrderContent();
673
800
  return cartItem;
@@ -675,6 +802,7 @@ function useCart(context) {
675
802
  removeFromCart: (cartItem) => {
676
803
  const index = storefront.currentOrder.value.items.findIndex((i) => i.id === cartItem.id);
677
804
  storefront.currentOrder.value.items.splice(index, 1);
805
+ addReplacedBundleProducts(cartItem);
678
806
  const _ = storefront.pushOrderContent();
679
807
  },
680
808
  checkout: async (options) => {
@@ -722,8 +850,8 @@ async function useCheckout(items, options, context) {
722
850
  const variation = (_a = item.variation) != null ? _a : target.defaultVariation;
723
851
  if (!variation)
724
852
  throw new Error("Added item does not have a default variation, and none have been specified");
725
- const id = `${target.type === "bundle" ? "b" : "p"}/${target.id}/${variation.id}`;
726
- if (target.type === "bundle") {
853
+ const id = `${target.type === "Bundle" ? "b" : "p"}/${target.id}/${variation.id}`;
854
+ if (target.type === "Bundle") {
727
855
  checkoutSession.push({
728
856
  id,
729
857
  type: "Bundle",
@@ -735,7 +863,7 @@ async function useCheckout(items, options, context) {
735
863
  price: variation.price,
736
864
  appliedDiscount: variation.discount
737
865
  });
738
- } else if (target.type === "product") {
866
+ } else if (target.type === "Product") {
739
867
  checkoutSession.push({
740
868
  id,
741
869
  type: "Product",
@@ -785,7 +913,7 @@ async function useCheckout(items, options, context) {
785
913
  }
786
914
 
787
915
  // src/composables/useInventory.ts
788
- import { inject as inject7 } from "vue";
916
+ import { inject as inject7, toRaw } from "vue";
789
917
  function useInventory(context) {
790
918
  const storefront = context != null ? context : inject7(storefrontKey);
791
919
  if (!storefront)
@@ -846,32 +974,98 @@ function useInventory(context) {
846
974
  }, { once: true });
847
975
  });
848
976
  }
977
+ },
978
+ updateSubscriptionPaymentMethod: async (subscription, options) => {
979
+ var _a;
980
+ const fallbackPath = typeof window !== "undefined" ? window.location.pathname : "";
981
+ const absoluteReturnUrl = new URL((_a = options.returnUrl) != null ? _a : fallbackPath, document.baseURI).href;
982
+ const response = await storefront.client.inventory.subscriptions.getById(subscription.id, {
983
+ toUpdatePaymentMethod: true,
984
+ returnUrl: absoluteReturnUrl
985
+ });
986
+ window.dispatchEvent(new CustomEvent("moonbase-subscription-payment-method-update-initiated", {
987
+ detail: { subscription: toRaw(subscription) }
988
+ }));
989
+ if (response.embeddedUpdatePaymentUrl && typeof window !== "undefined") {
990
+ const embeddedUrl = response.embeddedUpdatePaymentUrl;
991
+ return new Promise((resolve) => {
992
+ mountSubscription(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
993
+ window.addEventListener("moonbase-subscription-closed", (e) => {
994
+ const evnt = e;
995
+ resolve({ completed: evnt.detail.completed });
996
+ }, { once: true });
997
+ });
998
+ } else {
999
+ throw new Error("No update URL found");
1000
+ }
849
1001
  }
850
1002
  };
851
1003
  }
852
1004
 
853
- // src/composables/useProduct.ts
1005
+ // src/composables/useOffer.ts
854
1006
  import { computed as computed5, inject as inject8 } from "vue";
855
- function useProduct(productId, context) {
1007
+ function useOffer(offerId, context) {
856
1008
  const storefront = context != null ? context : inject8(storefrontKey);
857
1009
  if (!storefront)
858
1010
  throw new Error("No storefront configured");
859
- return computed5(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
1011
+ return computed5(() => {
1012
+ var _a;
1013
+ return ((_a = storefront.storefront.value.offers) == null ? void 0 : _a.find((o) => o.id === offerId)) || null;
1014
+ });
860
1015
  }
861
1016
 
862
- // src/composables/useProducts.ts
1017
+ // src/composables/useOffers.ts
1018
+ import { OfferUtils as OfferUtils3 } from "@moonbase.sh/storefront-api";
863
1019
  import { computed as computed6, inject as inject9 } from "vue";
864
- function useProducts(context) {
1020
+ function useOffers(context) {
1021
+ const storefront = context != null ? context : inject9(storefrontKey);
1022
+ if (!storefront)
1023
+ throw new Error("No storefront configured");
1024
+ return computed6(() => {
1025
+ var _a;
1026
+ return (_a = storefront.storefront.value.offers) != null ? _a : [];
1027
+ });
1028
+ }
1029
+ function useEligibleOffers(context) {
865
1030
  const storefront = context != null ? context : inject9(storefrontKey);
866
1031
  if (!storefront)
867
1032
  throw new Error("No storefront configured");
868
- return computed6(() => storefront.storefront.value.products);
1033
+ return computed6(() => {
1034
+ var _a;
1035
+ return ((_a = storefront.storefront.value.offers) != null ? _a : []).filter((o) => OfferUtils3.eligible(o, storefront.currentOrder.value) && !offerTargetIsInCart(o, storefront.currentOrder.value));
1036
+ });
1037
+ }
1038
+ function offerTargetIsInCart(offer, order) {
1039
+ if (order.items.some(
1040
+ (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
1041
+ )) {
1042
+ return true;
1043
+ }
1044
+ return false;
1045
+ }
1046
+
1047
+ // src/composables/useProduct.ts
1048
+ import { computed as computed7, inject as inject10 } from "vue";
1049
+ function useProduct(productId, context) {
1050
+ const storefront = context != null ? context : inject10(storefrontKey);
1051
+ if (!storefront)
1052
+ throw new Error("No storefront configured");
1053
+ return computed7(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
1054
+ }
1055
+
1056
+ // src/composables/useProducts.ts
1057
+ import { computed as computed8, inject as inject11 } from "vue";
1058
+ function useProducts(context) {
1059
+ const storefront = context != null ? context : inject11(storefrontKey);
1060
+ if (!storefront)
1061
+ throw new Error("No storefront configured");
1062
+ return computed8(() => storefront.storefront.value.products);
869
1063
  }
870
1064
 
871
1065
  // src/composables/useVendor.ts
872
- import { inject as inject10, ref as ref2 } from "vue";
1066
+ import { inject as inject12, ref as ref2 } from "vue";
873
1067
  function useVendor(context) {
874
- const storefront = context != null ? context : inject10(storefrontKey);
1068
+ const storefront = context != null ? context : inject12(storefrontKey);
875
1069
  if (!storefront)
876
1070
  throw new Error("No storefront configured");
877
1071
  const vendor = ref2(null);
@@ -888,9 +1082,9 @@ function useVendor(context) {
888
1082
 
889
1083
  // src/composables/useVoucher.ts
890
1084
  import { NotFoundError as NotFoundError2 } from "@moonbase.sh/storefront-api";
891
- import { inject as inject11 } from "vue";
1085
+ import { inject as inject13 } from "vue";
892
1086
  function useVoucher(context) {
893
- const storefront = context != null ? context : inject11(storefrontKey);
1087
+ const storefront = context != null ? context : inject13(storefrontKey);
894
1088
  if (!storefront)
895
1089
  throw new Error("No storefront configured");
896
1090
  return {
@@ -938,7 +1132,10 @@ export {
938
1132
  useBundles,
939
1133
  useCart,
940
1134
  useCheckout,
1135
+ useEligibleOffers,
941
1136
  useInventory,
1137
+ useOffer,
1138
+ useOffers,
942
1139
  useProduct,
943
1140
  useProducts,
944
1141
  useVendor,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/vue",
3
3
  "type": "module",
4
- "version": "0.4.25",
4
+ "version": "0.4.27",
5
5
  "description": "Package to let you build vue.js storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",
@@ -19,14 +19,14 @@
19
19
  "@vue/devtools-api": "^6.6.3",
20
20
  "uuid": "^9.0.1",
21
21
  "zod": "^3.23.8",
22
- "@moonbase.sh/storefront-api": "0.4.25"
22
+ "@moonbase.sh/storefront-api": "0.4.27"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/uuid": "^9.0.8",
26
26
  "rimraf": "^5.0.10",
27
- "tsup": "^7.2.0",
28
- "typescript": "~5.1.6",
29
- "vue": "^3.5.3"
27
+ "tsup": "^8.5.0",
28
+ "typescript": "~5.8.3",
29
+ "vue": "^3.5.17"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "tsup src/index.ts --format esm,cjs --dts",