@moonbase.sh/vue 0.2.127 → 0.2.129
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 +106 -22
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +94 -11
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,7 @@ __export(src_exports, {
|
|
|
28
28
|
useBundle: () => useBundle,
|
|
29
29
|
useBundles: () => useBundles,
|
|
30
30
|
useCart: () => useCart,
|
|
31
|
+
useCheckout: () => useCheckout,
|
|
31
32
|
useInventory: () => useInventory,
|
|
32
33
|
useProduct: () => useProduct,
|
|
33
34
|
useProducts: () => useProducts,
|
|
@@ -35,8 +36,8 @@ __export(src_exports, {
|
|
|
35
36
|
useVoucher: () => useVoucher
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(src_exports);
|
|
38
|
-
var
|
|
39
|
-
var
|
|
39
|
+
var import_storefront_api7 = require("@moonbase.sh/storefront-api");
|
|
40
|
+
var import_vue13 = require("vue");
|
|
40
41
|
|
|
41
42
|
// src/context.ts
|
|
42
43
|
var import_storefront_api2 = require("@moonbase.sh/storefront-api");
|
|
@@ -227,7 +228,11 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
227
228
|
window.history.replaceState(null, "", window.location.href.split("?")[0]);
|
|
228
229
|
}
|
|
229
230
|
}
|
|
230
|
-
window.addEventListener("moonbase-checkout-completed", () =>
|
|
231
|
+
window.addEventListener("moonbase-checkout-completed", (e) => {
|
|
232
|
+
const order = e.detail.order;
|
|
233
|
+
if (order.id === this.currentOrder.value.id)
|
|
234
|
+
this.resetOrder();
|
|
235
|
+
});
|
|
231
236
|
}
|
|
232
237
|
get loadedStorefrontPromise() {
|
|
233
238
|
return new Promise((resolve) => {
|
|
@@ -251,6 +256,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
251
256
|
closeCheckout() {
|
|
252
257
|
closeCheckout();
|
|
253
258
|
}
|
|
259
|
+
onCheckoutInitiated(callback) {
|
|
260
|
+
window.addEventListener("moonbase-checkout-initiated", (e) => callback(e.detail.order));
|
|
261
|
+
}
|
|
254
262
|
onCheckoutCompleted(callback) {
|
|
255
263
|
window.addEventListener("moonbase-checkout-completed", (e) => callback(e.detail.order));
|
|
256
264
|
}
|
|
@@ -662,6 +670,9 @@ function useCart(context) {
|
|
|
662
670
|
const updatedOrder = await storefront.client.orders.pushContent(storefront.currentOrder.value, {
|
|
663
671
|
returnUrl: absoluteReturnUrl
|
|
664
672
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
673
|
+
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
674
|
+
detail: { order: updatedOrder }
|
|
675
|
+
}));
|
|
665
676
|
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
666
677
|
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
|
667
678
|
return new Promise((resolve) => {
|
|
@@ -680,10 +691,82 @@ function useCart(context) {
|
|
|
680
691
|
};
|
|
681
692
|
}
|
|
682
693
|
|
|
683
|
-
// src/composables/
|
|
694
|
+
// src/composables/useCheckout.ts
|
|
695
|
+
var import_storefront_api5 = require("@moonbase.sh/storefront-api");
|
|
696
|
+
var import_uuid2 = require("uuid");
|
|
684
697
|
var import_vue7 = require("vue");
|
|
685
|
-
function
|
|
698
|
+
async function useCheckout(items, options, context) {
|
|
699
|
+
var _a, _b;
|
|
686
700
|
const storefront = context != null ? context : (0, import_vue7.inject)(storefrontKey);
|
|
701
|
+
if (!storefront)
|
|
702
|
+
throw new Error("No storefront configured");
|
|
703
|
+
const checkoutSession = [];
|
|
704
|
+
for (const item of items) {
|
|
705
|
+
const target = (0, import_vue7.unref)(item.item);
|
|
706
|
+
const variation = (_a = item.variation) != null ? _a : target.defaultVariation;
|
|
707
|
+
if (!variation)
|
|
708
|
+
throw new Error("Added item does not have a default variation, and none have been specified");
|
|
709
|
+
const id = `${target.type === "bundle" ? "b" : "p"}/${target.id}/${variation.id}`;
|
|
710
|
+
if (target.type === "bundle") {
|
|
711
|
+
checkoutSession.push({
|
|
712
|
+
id,
|
|
713
|
+
type: "Bundle",
|
|
714
|
+
bundleId: target.id,
|
|
715
|
+
bundle: target,
|
|
716
|
+
quantity: 1,
|
|
717
|
+
variation,
|
|
718
|
+
variationId: variation.id,
|
|
719
|
+
price: variation.price,
|
|
720
|
+
appliedDiscount: variation.discount
|
|
721
|
+
});
|
|
722
|
+
} else if (target.type === "product") {
|
|
723
|
+
checkoutSession.push({
|
|
724
|
+
id,
|
|
725
|
+
type: "Product",
|
|
726
|
+
productId: target.id,
|
|
727
|
+
product: target,
|
|
728
|
+
quantity: 1,
|
|
729
|
+
variation,
|
|
730
|
+
variationId: variation.id,
|
|
731
|
+
price: variation.price,
|
|
732
|
+
appliedDiscount: variation.discount
|
|
733
|
+
});
|
|
734
|
+
} else {
|
|
735
|
+
throw new import_storefront_api5.MoonbaseError("Invalid input", `Could not handle item of type '${item.type}'`);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
const fallbackPath = typeof window !== "undefined" ? window.location.pathname : "";
|
|
739
|
+
const absoluteReturnUrl = new URL((_b = options.returnUrl) != null ? _b : fallbackPath, document.baseURI).href;
|
|
740
|
+
const updatedOrder = await storefront.client.orders.pushContent({
|
|
741
|
+
id: (0, import_uuid2.v4)(),
|
|
742
|
+
currency: storefront.storefront.value.suggestedCurrency,
|
|
743
|
+
items: checkoutSession
|
|
744
|
+
}, {
|
|
745
|
+
returnUrl: absoluteReturnUrl
|
|
746
|
+
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
747
|
+
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
748
|
+
detail: { order: updatedOrder }
|
|
749
|
+
}));
|
|
750
|
+
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
751
|
+
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
|
752
|
+
return new Promise((resolve) => {
|
|
753
|
+
mountCheckout(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
|
|
754
|
+
window.addEventListener("moonbase-checkout-closed", (e) => {
|
|
755
|
+
resolve({ next: e.detail.next });
|
|
756
|
+
});
|
|
757
|
+
});
|
|
758
|
+
} else if (options.redirect && updatedOrder.checkoutUrl && typeof window !== "undefined") {
|
|
759
|
+
window.location.href = updatedOrder.checkoutUrl;
|
|
760
|
+
return Promise.resolve({ next: void 0 });
|
|
761
|
+
} else {
|
|
762
|
+
throw new Error("No checkout URL found");
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// src/composables/useInventory.ts
|
|
767
|
+
var import_vue8 = require("vue");
|
|
768
|
+
function useInventory(context) {
|
|
769
|
+
const storefront = context != null ? context : (0, import_vue8.inject)(storefrontKey);
|
|
687
770
|
if (!storefront)
|
|
688
771
|
throw new Error("No storefront configured");
|
|
689
772
|
return {
|
|
@@ -720,31 +803,31 @@ function useInventory(context) {
|
|
|
720
803
|
}
|
|
721
804
|
|
|
722
805
|
// src/composables/useProduct.ts
|
|
723
|
-
var
|
|
806
|
+
var import_vue9 = require("vue");
|
|
724
807
|
function useProduct(productId, context) {
|
|
725
|
-
const storefront = context != null ? context : (0,
|
|
808
|
+
const storefront = context != null ? context : (0, import_vue9.inject)(storefrontKey);
|
|
726
809
|
if (!storefront)
|
|
727
810
|
throw new Error("No storefront configured");
|
|
728
|
-
return (0,
|
|
811
|
+
return (0, import_vue9.computed)(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
|
|
729
812
|
}
|
|
730
813
|
|
|
731
814
|
// src/composables/useProducts.ts
|
|
732
|
-
var
|
|
815
|
+
var import_vue10 = require("vue");
|
|
733
816
|
function useProducts(context) {
|
|
734
|
-
const storefront = context != null ? context : (0,
|
|
817
|
+
const storefront = context != null ? context : (0, import_vue10.inject)(storefrontKey);
|
|
735
818
|
if (!storefront)
|
|
736
819
|
throw new Error("No storefront configured");
|
|
737
|
-
return (0,
|
|
820
|
+
return (0, import_vue10.computed)(() => storefront.storefront.value.products);
|
|
738
821
|
}
|
|
739
822
|
|
|
740
823
|
// src/composables/useVendor.ts
|
|
741
|
-
var
|
|
824
|
+
var import_vue11 = require("vue");
|
|
742
825
|
function useVendor(context) {
|
|
743
|
-
const storefront = context != null ? context : (0,
|
|
826
|
+
const storefront = context != null ? context : (0, import_vue11.inject)(storefrontKey);
|
|
744
827
|
if (!storefront)
|
|
745
828
|
throw new Error("No storefront configured");
|
|
746
|
-
const vendor = (0,
|
|
747
|
-
const loading = (0,
|
|
829
|
+
const vendor = (0, import_vue11.ref)(null);
|
|
830
|
+
const loading = (0, import_vue11.ref)(true);
|
|
748
831
|
storefront.client.vendor.get().then((v) => {
|
|
749
832
|
vendor.value = v;
|
|
750
833
|
loading.value = false;
|
|
@@ -756,10 +839,10 @@ function useVendor(context) {
|
|
|
756
839
|
}
|
|
757
840
|
|
|
758
841
|
// src/composables/useVoucher.ts
|
|
759
|
-
var
|
|
760
|
-
var
|
|
842
|
+
var import_storefront_api6 = require("@moonbase.sh/storefront-api");
|
|
843
|
+
var import_vue12 = require("vue");
|
|
761
844
|
function useVoucher(context) {
|
|
762
|
-
const storefront = context != null ? context : (0,
|
|
845
|
+
const storefront = context != null ? context : (0, import_vue12.inject)(storefrontKey);
|
|
763
846
|
if (!storefront)
|
|
764
847
|
throw new Error("No storefront configured");
|
|
765
848
|
return {
|
|
@@ -767,7 +850,7 @@ function useVoucher(context) {
|
|
|
767
850
|
try {
|
|
768
851
|
return await storefront.client.vouchers.peek(code);
|
|
769
852
|
} catch (e) {
|
|
770
|
-
if (e instanceof
|
|
853
|
+
if (e instanceof import_storefront_api6.NotFoundError)
|
|
771
854
|
throw new Error("Voucher code invalid");
|
|
772
855
|
throw e;
|
|
773
856
|
}
|
|
@@ -776,7 +859,7 @@ function useVoucher(context) {
|
|
|
776
859
|
try {
|
|
777
860
|
return await storefront.client.vouchers.redeem(code);
|
|
778
861
|
} catch (e) {
|
|
779
|
-
if (e instanceof
|
|
862
|
+
if (e instanceof import_storefront_api6.NotFoundError)
|
|
780
863
|
throw new Error("Voucher code invalid");
|
|
781
864
|
throw e;
|
|
782
865
|
}
|
|
@@ -793,9 +876,9 @@ function createStorefront(endpoint, stateFactory, config) {
|
|
|
793
876
|
};
|
|
794
877
|
return new StorefrontContextImpl(
|
|
795
878
|
configuration,
|
|
796
|
-
new
|
|
879
|
+
new import_storefront_api7.MoonbaseClient(configuration),
|
|
797
880
|
// Default to vue refs but allow stuff like Nuxt useState wrappers
|
|
798
|
-
stateFactory || ((_, state) => (0,
|
|
881
|
+
stateFactory || ((_, state) => (0, import_vue13.ref)(state))
|
|
799
882
|
);
|
|
800
883
|
}
|
|
801
884
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -807,6 +890,7 @@ function createStorefront(endpoint, stateFactory, config) {
|
|
|
807
890
|
useBundle,
|
|
808
891
|
useBundles,
|
|
809
892
|
useCart,
|
|
893
|
+
useCheckout,
|
|
810
894
|
useInventory,
|
|
811
895
|
useProduct,
|
|
812
896
|
useProducts,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _moonbase_sh_storefront_api from '@moonbase.sh/storefront-api';
|
|
2
|
-
import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, CompletedOrder, ActivationRequest, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor, LineItem } from '@moonbase.sh/storefront-api';
|
|
2
|
+
import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, OpenOrder, CompletedOrder, ActivationRequest, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor, LineItem } from '@moonbase.sh/storefront-api';
|
|
3
3
|
export * from '@moonbase.sh/storefront-api';
|
|
4
4
|
import * as vue from 'vue';
|
|
5
5
|
import { Plugin, Ref, App, UnwrapRef, InjectionKey } from 'vue';
|
|
@@ -24,6 +24,7 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
|
24
24
|
resetOrder: () => void;
|
|
25
25
|
surrenderOrder: () => Promise<void>;
|
|
26
26
|
closeCheckout: () => void;
|
|
27
|
+
onCheckoutInitiated: (callback: (order: OpenOrder) => void) => void;
|
|
27
28
|
onCheckoutCompleted: (callback: (order: CompletedOrder) => void) => void;
|
|
28
29
|
onCheckoutClosed: (callback: (intent: string | undefined) => void) => void;
|
|
29
30
|
/**
|
|
@@ -285,6 +286,18 @@ declare function useCart(context?: StorefrontContext): {
|
|
|
285
286
|
} | undefined>;
|
|
286
287
|
};
|
|
287
288
|
|
|
289
|
+
interface CheckoutItem {
|
|
290
|
+
item: StorefrontProduct | StorefrontBundle | Ref<StorefrontProduct> | Ref<StorefrontBundle>;
|
|
291
|
+
variation?: PricingVariation;
|
|
292
|
+
quantity?: number;
|
|
293
|
+
}
|
|
294
|
+
declare function useCheckout(items: CheckoutItem[], options: {
|
|
295
|
+
redirect: boolean;
|
|
296
|
+
returnUrl?: string;
|
|
297
|
+
}, context?: StorefrontContext): Promise<{
|
|
298
|
+
next: string | undefined;
|
|
299
|
+
}>;
|
|
300
|
+
|
|
288
301
|
declare function useInventory(context?: StorefrontContext): {
|
|
289
302
|
getLicenses: (nextUrl?: string) => Promise<_moonbase_sh_storefront_api.Page<{
|
|
290
303
|
status: _moonbase_sh_storefront_api.LicenseStatus;
|
|
@@ -921,4 +934,4 @@ interface Cart {
|
|
|
921
934
|
type CartItem = LineItem;
|
|
922
935
|
declare function createStorefront(endpoint: string, stateFactory?: StateFactory, config?: Omit<MoonbaseConfiguration, 'endpoint'>): StorefrontContext;
|
|
923
936
|
|
|
924
|
-
export { type ActivationRequestComposable, type Cart, type CartItem, type VendorComposable, createStorefront, storefrontKey, useActivationRequest, useAuth, useBundle, useBundles, useCart, useInventory, useProduct, useProducts, useVendor, useVoucher };
|
|
937
|
+
export { type ActivationRequestComposable, type Cart, type CartItem, type CheckoutItem, type VendorComposable, createStorefront, storefrontKey, useActivationRequest, useAuth, useBundle, useBundles, useCart, useCheckout, useInventory, useProduct, useProducts, useVendor, useVoucher };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _moonbase_sh_storefront_api from '@moonbase.sh/storefront-api';
|
|
2
|
-
import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, CompletedOrder, ActivationRequest, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor, LineItem } from '@moonbase.sh/storefront-api';
|
|
2
|
+
import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, OpenOrder, CompletedOrder, ActivationRequest, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor, LineItem } from '@moonbase.sh/storefront-api';
|
|
3
3
|
export * from '@moonbase.sh/storefront-api';
|
|
4
4
|
import * as vue from 'vue';
|
|
5
5
|
import { Plugin, Ref, App, UnwrapRef, InjectionKey } from 'vue';
|
|
@@ -24,6 +24,7 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
|
24
24
|
resetOrder: () => void;
|
|
25
25
|
surrenderOrder: () => Promise<void>;
|
|
26
26
|
closeCheckout: () => void;
|
|
27
|
+
onCheckoutInitiated: (callback: (order: OpenOrder) => void) => void;
|
|
27
28
|
onCheckoutCompleted: (callback: (order: CompletedOrder) => void) => void;
|
|
28
29
|
onCheckoutClosed: (callback: (intent: string | undefined) => void) => void;
|
|
29
30
|
/**
|
|
@@ -285,6 +286,18 @@ declare function useCart(context?: StorefrontContext): {
|
|
|
285
286
|
} | undefined>;
|
|
286
287
|
};
|
|
287
288
|
|
|
289
|
+
interface CheckoutItem {
|
|
290
|
+
item: StorefrontProduct | StorefrontBundle | Ref<StorefrontProduct> | Ref<StorefrontBundle>;
|
|
291
|
+
variation?: PricingVariation;
|
|
292
|
+
quantity?: number;
|
|
293
|
+
}
|
|
294
|
+
declare function useCheckout(items: CheckoutItem[], options: {
|
|
295
|
+
redirect: boolean;
|
|
296
|
+
returnUrl?: string;
|
|
297
|
+
}, context?: StorefrontContext): Promise<{
|
|
298
|
+
next: string | undefined;
|
|
299
|
+
}>;
|
|
300
|
+
|
|
288
301
|
declare function useInventory(context?: StorefrontContext): {
|
|
289
302
|
getLicenses: (nextUrl?: string) => Promise<_moonbase_sh_storefront_api.Page<{
|
|
290
303
|
status: _moonbase_sh_storefront_api.LicenseStatus;
|
|
@@ -921,4 +934,4 @@ interface Cart {
|
|
|
921
934
|
type CartItem = LineItem;
|
|
922
935
|
declare function createStorefront(endpoint: string, stateFactory?: StateFactory, config?: Omit<MoonbaseConfiguration, 'endpoint'>): StorefrontContext;
|
|
923
936
|
|
|
924
|
-
export { type ActivationRequestComposable, type Cart, type CartItem, type VendorComposable, createStorefront, storefrontKey, useActivationRequest, useAuth, useBundle, useBundles, useCart, useInventory, useProduct, useProducts, useVendor, useVoucher };
|
|
937
|
+
export { type ActivationRequestComposable, type Cart, type CartItem, type CheckoutItem, type VendorComposable, createStorefront, storefrontKey, useActivationRequest, useAuth, useBundle, useBundles, useCart, useCheckout, useInventory, useProduct, useProducts, useVendor, useVoucher };
|
package/dist/index.js
CHANGED
|
@@ -196,7 +196,11 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
196
196
|
window.history.replaceState(null, "", window.location.href.split("?")[0]);
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
|
-
window.addEventListener("moonbase-checkout-completed", () =>
|
|
199
|
+
window.addEventListener("moonbase-checkout-completed", (e) => {
|
|
200
|
+
const order = e.detail.order;
|
|
201
|
+
if (order.id === this.currentOrder.value.id)
|
|
202
|
+
this.resetOrder();
|
|
203
|
+
});
|
|
200
204
|
}
|
|
201
205
|
get loadedStorefrontPromise() {
|
|
202
206
|
return new Promise((resolve) => {
|
|
@@ -220,6 +224,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
220
224
|
closeCheckout() {
|
|
221
225
|
closeCheckout();
|
|
222
226
|
}
|
|
227
|
+
onCheckoutInitiated(callback) {
|
|
228
|
+
window.addEventListener("moonbase-checkout-initiated", (e) => callback(e.detail.order));
|
|
229
|
+
}
|
|
223
230
|
onCheckoutCompleted(callback) {
|
|
224
231
|
window.addEventListener("moonbase-checkout-completed", (e) => callback(e.detail.order));
|
|
225
232
|
}
|
|
@@ -631,6 +638,9 @@ function useCart(context) {
|
|
|
631
638
|
const updatedOrder = await storefront.client.orders.pushContent(storefront.currentOrder.value, {
|
|
632
639
|
returnUrl: absoluteReturnUrl
|
|
633
640
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
641
|
+
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
642
|
+
detail: { order: updatedOrder }
|
|
643
|
+
}));
|
|
634
644
|
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
635
645
|
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
|
636
646
|
return new Promise((resolve) => {
|
|
@@ -649,10 +659,82 @@ function useCart(context) {
|
|
|
649
659
|
};
|
|
650
660
|
}
|
|
651
661
|
|
|
662
|
+
// src/composables/useCheckout.ts
|
|
663
|
+
import { MoonbaseError as MoonbaseError2 } from "@moonbase.sh/storefront-api";
|
|
664
|
+
import { v4 as uuidv42 } from "uuid";
|
|
665
|
+
import { inject as inject6, unref as unref2 } from "vue";
|
|
666
|
+
async function useCheckout(items, options, context) {
|
|
667
|
+
var _a, _b;
|
|
668
|
+
const storefront = context != null ? context : inject6(storefrontKey);
|
|
669
|
+
if (!storefront)
|
|
670
|
+
throw new Error("No storefront configured");
|
|
671
|
+
const checkoutSession = [];
|
|
672
|
+
for (const item of items) {
|
|
673
|
+
const target = unref2(item.item);
|
|
674
|
+
const variation = (_a = item.variation) != null ? _a : target.defaultVariation;
|
|
675
|
+
if (!variation)
|
|
676
|
+
throw new Error("Added item does not have a default variation, and none have been specified");
|
|
677
|
+
const id = `${target.type === "bundle" ? "b" : "p"}/${target.id}/${variation.id}`;
|
|
678
|
+
if (target.type === "bundle") {
|
|
679
|
+
checkoutSession.push({
|
|
680
|
+
id,
|
|
681
|
+
type: "Bundle",
|
|
682
|
+
bundleId: target.id,
|
|
683
|
+
bundle: target,
|
|
684
|
+
quantity: 1,
|
|
685
|
+
variation,
|
|
686
|
+
variationId: variation.id,
|
|
687
|
+
price: variation.price,
|
|
688
|
+
appliedDiscount: variation.discount
|
|
689
|
+
});
|
|
690
|
+
} else if (target.type === "product") {
|
|
691
|
+
checkoutSession.push({
|
|
692
|
+
id,
|
|
693
|
+
type: "Product",
|
|
694
|
+
productId: target.id,
|
|
695
|
+
product: target,
|
|
696
|
+
quantity: 1,
|
|
697
|
+
variation,
|
|
698
|
+
variationId: variation.id,
|
|
699
|
+
price: variation.price,
|
|
700
|
+
appliedDiscount: variation.discount
|
|
701
|
+
});
|
|
702
|
+
} else {
|
|
703
|
+
throw new MoonbaseError2("Invalid input", `Could not handle item of type '${item.type}'`);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
const fallbackPath = typeof window !== "undefined" ? window.location.pathname : "";
|
|
707
|
+
const absoluteReturnUrl = new URL((_b = options.returnUrl) != null ? _b : fallbackPath, document.baseURI).href;
|
|
708
|
+
const updatedOrder = await storefront.client.orders.pushContent({
|
|
709
|
+
id: uuidv42(),
|
|
710
|
+
currency: storefront.storefront.value.suggestedCurrency,
|
|
711
|
+
items: checkoutSession
|
|
712
|
+
}, {
|
|
713
|
+
returnUrl: absoluteReturnUrl
|
|
714
|
+
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
715
|
+
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
716
|
+
detail: { order: updatedOrder }
|
|
717
|
+
}));
|
|
718
|
+
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
719
|
+
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
|
720
|
+
return new Promise((resolve) => {
|
|
721
|
+
mountCheckout(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
|
|
722
|
+
window.addEventListener("moonbase-checkout-closed", (e) => {
|
|
723
|
+
resolve({ next: e.detail.next });
|
|
724
|
+
});
|
|
725
|
+
});
|
|
726
|
+
} else if (options.redirect && updatedOrder.checkoutUrl && typeof window !== "undefined") {
|
|
727
|
+
window.location.href = updatedOrder.checkoutUrl;
|
|
728
|
+
return Promise.resolve({ next: void 0 });
|
|
729
|
+
} else {
|
|
730
|
+
throw new Error("No checkout URL found");
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
652
734
|
// src/composables/useInventory.ts
|
|
653
|
-
import { inject as
|
|
735
|
+
import { inject as inject7 } from "vue";
|
|
654
736
|
function useInventory(context) {
|
|
655
|
-
const storefront = context != null ? context :
|
|
737
|
+
const storefront = context != null ? context : inject7(storefrontKey);
|
|
656
738
|
if (!storefront)
|
|
657
739
|
throw new Error("No storefront configured");
|
|
658
740
|
return {
|
|
@@ -689,27 +771,27 @@ function useInventory(context) {
|
|
|
689
771
|
}
|
|
690
772
|
|
|
691
773
|
// src/composables/useProduct.ts
|
|
692
|
-
import { computed as computed5, inject as
|
|
774
|
+
import { computed as computed5, inject as inject8 } from "vue";
|
|
693
775
|
function useProduct(productId, context) {
|
|
694
|
-
const storefront = context != null ? context :
|
|
776
|
+
const storefront = context != null ? context : inject8(storefrontKey);
|
|
695
777
|
if (!storefront)
|
|
696
778
|
throw new Error("No storefront configured");
|
|
697
779
|
return computed5(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
|
|
698
780
|
}
|
|
699
781
|
|
|
700
782
|
// src/composables/useProducts.ts
|
|
701
|
-
import { computed as computed6, inject as
|
|
783
|
+
import { computed as computed6, inject as inject9 } from "vue";
|
|
702
784
|
function useProducts(context) {
|
|
703
|
-
const storefront = context != null ? context :
|
|
785
|
+
const storefront = context != null ? context : inject9(storefrontKey);
|
|
704
786
|
if (!storefront)
|
|
705
787
|
throw new Error("No storefront configured");
|
|
706
788
|
return computed6(() => storefront.storefront.value.products);
|
|
707
789
|
}
|
|
708
790
|
|
|
709
791
|
// src/composables/useVendor.ts
|
|
710
|
-
import { inject as
|
|
792
|
+
import { inject as inject10, ref as ref2 } from "vue";
|
|
711
793
|
function useVendor(context) {
|
|
712
|
-
const storefront = context != null ? context :
|
|
794
|
+
const storefront = context != null ? context : inject10(storefrontKey);
|
|
713
795
|
if (!storefront)
|
|
714
796
|
throw new Error("No storefront configured");
|
|
715
797
|
const vendor = ref2(null);
|
|
@@ -726,9 +808,9 @@ function useVendor(context) {
|
|
|
726
808
|
|
|
727
809
|
// src/composables/useVoucher.ts
|
|
728
810
|
import { NotFoundError as NotFoundError2 } from "@moonbase.sh/storefront-api";
|
|
729
|
-
import { inject as
|
|
811
|
+
import { inject as inject11 } from "vue";
|
|
730
812
|
function useVoucher(context) {
|
|
731
|
-
const storefront = context != null ? context :
|
|
813
|
+
const storefront = context != null ? context : inject11(storefrontKey);
|
|
732
814
|
if (!storefront)
|
|
733
815
|
throw new Error("No storefront configured");
|
|
734
816
|
return {
|
|
@@ -775,6 +857,7 @@ export {
|
|
|
775
857
|
useBundle,
|
|
776
858
|
useBundles,
|
|
777
859
|
useCart,
|
|
860
|
+
useCheckout,
|
|
778
861
|
useInventory,
|
|
779
862
|
useProduct,
|
|
780
863
|
useProducts,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.129",
|
|
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.2.
|
|
22
|
+
"@moonbase.sh/storefront-api": "0.2.129"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/uuid": "^9.0.8",
|