@moonbase.sh/vue 0.3.4 → 0.3.5

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
@@ -65,7 +65,8 @@ var import_zod = require("zod");
65
65
  var closeEventSchema = import_zod.z.object({
66
66
  source: import_zod.z.literal("moonbase-checkout"),
67
67
  event: import_zod.z.literal("close"),
68
- intent: import_zod.z.string().optional()
68
+ intent: import_zod.z.string().optional(),
69
+ completed: import_zod.z.boolean()
69
70
  });
70
71
  var completedEventSchema = import_zod.z.object({
71
72
  source: import_zod.z.literal("moonbase-checkout"),
@@ -696,12 +697,13 @@ function useCart(context) {
696
697
  return new Promise((resolve) => {
697
698
  mountCheckout(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
698
699
  window.addEventListener("moonbase-checkout-closed", (e) => {
699
- resolve({ next: e.detail.next });
700
- });
700
+ const evnt = e;
701
+ resolve({ next: evnt.detail.intent, completed: evnt.detail.completed });
702
+ }, { once: true });
701
703
  });
702
704
  } else if (options.redirect && updatedOrder.checkoutUrl && typeof window !== "undefined") {
703
705
  window.location.href = updatedOrder.checkoutUrl;
704
- return { next: void 0 };
706
+ return { next: void 0, completed: false };
705
707
  } else {
706
708
  throw new Error("No checkout URL found");
707
709
  }
@@ -770,12 +772,13 @@ async function useCheckout(items, options, context) {
770
772
  return new Promise((resolve) => {
771
773
  mountCheckout(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
772
774
  window.addEventListener("moonbase-checkout-closed", (e) => {
773
- resolve({ next: e.detail.next });
774
- });
775
+ const evnt = e;
776
+ resolve({ next: evnt.detail.intent, completed: evnt.detail.completed });
777
+ }, { once: true });
775
778
  });
776
779
  } else if (options.redirect && updatedOrder.checkoutUrl && typeof window !== "undefined") {
777
780
  window.location.href = updatedOrder.checkoutUrl;
778
- return Promise.resolve({ next: void 0 });
781
+ return Promise.resolve({ next: void 0, completed: false });
779
782
  } else {
780
783
  throw new Error("No checkout URL found");
781
784
  }
@@ -816,6 +819,33 @@ function useInventory(context) {
816
819
  if (!download.path)
817
820
  throw new Error("Product is not downloadable");
818
821
  window.location.href = await storefront.client.inventory.products.getDownloadUrl(download.path);
822
+ },
823
+ getSubscriptions: async (nextUrl) => {
824
+ return storefront.client.inventory.subscriptions.get(nextUrl);
825
+ },
826
+ getSubscription: async (subscriptionId) => {
827
+ return storefront.client.inventory.subscriptions.getById(subscriptionId);
828
+ },
829
+ cancelSubscription: async (subscriptionId) => {
830
+ return storefront.client.inventory.subscriptions.cancel(subscriptionId);
831
+ },
832
+ renewSubscription: async (subscriptionId, options) => {
833
+ var _a;
834
+ const fallbackPath = typeof window !== "undefined" ? window.location.pathname : "";
835
+ const absoluteReturnUrl = new URL((_a = options.returnUrl) != null ? _a : fallbackPath, document.baseURI).href;
836
+ const { location: url } = await storefront.client.inventory.subscriptions.renew(subscriptionId, absoluteReturnUrl, !options.redirect);
837
+ if (options.redirect) {
838
+ window.location.href = url;
839
+ return Promise.resolve({ next: void 0, completed: false });
840
+ } else {
841
+ return new Promise((resolve) => {
842
+ mountCheckout(url.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
843
+ window.addEventListener("moonbase-checkout-closed", (e) => {
844
+ const evnt = e;
845
+ resolve({ next: evnt.detail.intent, completed: evnt.detail.completed });
846
+ }, { once: true });
847
+ });
848
+ }
819
849
  }
820
850
  };
821
851
  }