@moonbase.sh/vue 0.3.3 → 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
@@ -41,8 +41,6 @@ var import_vue13 = require("vue");
41
41
 
42
42
  // src/context.ts
43
43
  var import_storefront_api2 = require("@moonbase.sh/storefront-api");
44
- var import_schemas = require("@moonbase.sh/storefront-api/src/identity/schemas");
45
- var import_tokenStore = require("@moonbase.sh/storefront-api/src/utils/tokenStore");
46
44
  var import_uuid = require("uuid");
47
45
  var import_vue = require("vue");
48
46
 
@@ -67,7 +65,8 @@ var import_zod = require("zod");
67
65
  var closeEventSchema = import_zod.z.object({
68
66
  source: import_zod.z.literal("moonbase-checkout"),
69
67
  event: import_zod.z.literal("close"),
70
- intent: import_zod.z.string().optional()
68
+ intent: import_zod.z.string().optional(),
69
+ completed: import_zod.z.boolean()
71
70
  });
72
71
  var completedEventSchema = import_zod.z.object({
73
72
  source: import_zod.z.literal("moonbase-checkout"),
@@ -210,7 +209,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
210
209
  this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
211
210
  }
212
211
  if (this.client.tokenStore.hasAccessToken) {
213
- this.currentUser.value = import_schemas.userSchema.parse(this.client.tokenStore.user);
212
+ this.currentUser.value = import_storefront_api2.schemas.identity.userSchema.parse(this.client.tokenStore.user);
214
213
  }
215
214
  this.updateStorefront();
216
215
  this.updateUser();
@@ -320,7 +319,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
320
319
  case _StorefrontContextImpl.utmKey:
321
320
  this.utm.value = JSON.parse(event.newValue);
322
321
  break;
323
- case import_tokenStore.TokenStore.storageKey:
322
+ case import_storefront_api2.TokenStore.storageKey:
324
323
  if (!event.newValue) {
325
324
  this.currentUser.value = null;
326
325
  console.warn("User was removed");
@@ -698,12 +697,13 @@ function useCart(context) {
698
697
  return new Promise((resolve) => {
699
698
  mountCheckout(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
700
699
  window.addEventListener("moonbase-checkout-closed", (e) => {
701
- resolve({ next: e.detail.next });
702
- });
700
+ const evnt = e;
701
+ resolve({ next: evnt.detail.intent, completed: evnt.detail.completed });
702
+ }, { once: true });
703
703
  });
704
704
  } else if (options.redirect && updatedOrder.checkoutUrl && typeof window !== "undefined") {
705
705
  window.location.href = updatedOrder.checkoutUrl;
706
- return { next: void 0 };
706
+ return { next: void 0, completed: false };
707
707
  } else {
708
708
  throw new Error("No checkout URL found");
709
709
  }
@@ -772,12 +772,13 @@ async function useCheckout(items, options, context) {
772
772
  return new Promise((resolve) => {
773
773
  mountCheckout(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
774
774
  window.addEventListener("moonbase-checkout-closed", (e) => {
775
- resolve({ next: e.detail.next });
776
- });
775
+ const evnt = e;
776
+ resolve({ next: evnt.detail.intent, completed: evnt.detail.completed });
777
+ }, { once: true });
777
778
  });
778
779
  } else if (options.redirect && updatedOrder.checkoutUrl && typeof window !== "undefined") {
779
780
  window.location.href = updatedOrder.checkoutUrl;
780
- return Promise.resolve({ next: void 0 });
781
+ return Promise.resolve({ next: void 0, completed: false });
781
782
  } else {
782
783
  throw new Error("No checkout URL found");
783
784
  }
@@ -818,6 +819,33 @@ function useInventory(context) {
818
819
  if (!download.path)
819
820
  throw new Error("Product is not downloadable");
820
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
+ }
821
849
  }
822
850
  };
823
851
  }