@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.js CHANGED
@@ -35,7 +35,8 @@ import { z } from "zod";
35
35
  var closeEventSchema = z.object({
36
36
  source: z.literal("moonbase-checkout"),
37
37
  event: z.literal("close"),
38
- intent: z.string().optional()
38
+ intent: z.string().optional(),
39
+ completed: z.boolean()
39
40
  });
40
41
  var completedEventSchema = z.object({
41
42
  source: z.literal("moonbase-checkout"),
@@ -666,12 +667,13 @@ function useCart(context) {
666
667
  return new Promise((resolve) => {
667
668
  mountCheckout(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
668
669
  window.addEventListener("moonbase-checkout-closed", (e) => {
669
- resolve({ next: e.detail.next });
670
- });
670
+ const evnt = e;
671
+ resolve({ next: evnt.detail.intent, completed: evnt.detail.completed });
672
+ }, { once: true });
671
673
  });
672
674
  } else if (options.redirect && updatedOrder.checkoutUrl && typeof window !== "undefined") {
673
675
  window.location.href = updatedOrder.checkoutUrl;
674
- return { next: void 0 };
676
+ return { next: void 0, completed: false };
675
677
  } else {
676
678
  throw new Error("No checkout URL found");
677
679
  }
@@ -740,12 +742,13 @@ async function useCheckout(items, options, context) {
740
742
  return new Promise((resolve) => {
741
743
  mountCheckout(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
742
744
  window.addEventListener("moonbase-checkout-closed", (e) => {
743
- resolve({ next: e.detail.next });
744
- });
745
+ const evnt = e;
746
+ resolve({ next: evnt.detail.intent, completed: evnt.detail.completed });
747
+ }, { once: true });
745
748
  });
746
749
  } else if (options.redirect && updatedOrder.checkoutUrl && typeof window !== "undefined") {
747
750
  window.location.href = updatedOrder.checkoutUrl;
748
- return Promise.resolve({ next: void 0 });
751
+ return Promise.resolve({ next: void 0, completed: false });
749
752
  } else {
750
753
  throw new Error("No checkout URL found");
751
754
  }
@@ -786,6 +789,33 @@ function useInventory(context) {
786
789
  if (!download.path)
787
790
  throw new Error("Product is not downloadable");
788
791
  window.location.href = await storefront.client.inventory.products.getDownloadUrl(download.path);
792
+ },
793
+ getSubscriptions: async (nextUrl) => {
794
+ return storefront.client.inventory.subscriptions.get(nextUrl);
795
+ },
796
+ getSubscription: async (subscriptionId) => {
797
+ return storefront.client.inventory.subscriptions.getById(subscriptionId);
798
+ },
799
+ cancelSubscription: async (subscriptionId) => {
800
+ return storefront.client.inventory.subscriptions.cancel(subscriptionId);
801
+ },
802
+ renewSubscription: async (subscriptionId, options) => {
803
+ var _a;
804
+ const fallbackPath = typeof window !== "undefined" ? window.location.pathname : "";
805
+ const absoluteReturnUrl = new URL((_a = options.returnUrl) != null ? _a : fallbackPath, document.baseURI).href;
806
+ const { location: url } = await storefront.client.inventory.subscriptions.renew(subscriptionId, absoluteReturnUrl, !options.redirect);
807
+ if (options.redirect) {
808
+ window.location.href = url;
809
+ return Promise.resolve({ next: void 0, completed: false });
810
+ } else {
811
+ return new Promise((resolve) => {
812
+ mountCheckout(url.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
813
+ window.addEventListener("moonbase-checkout-closed", (e) => {
814
+ const evnt = e;
815
+ resolve({ next: evnt.detail.intent, completed: evnt.detail.completed });
816
+ }, { once: true });
817
+ });
818
+ }
789
819
  }
790
820
  };
791
821
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/vue",
3
3
  "type": "module",
4
- "version": "0.3.4",
4
+ "version": "0.3.5",
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,7 +19,7 @@
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.3.4"
22
+ "@moonbase.sh/storefront-api": "0.3.5"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/uuid": "^9.0.8",