@moonbase.sh/vue 0.3.5 → 0.3.7
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 +35 -25
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +35 -25
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -256,7 +256,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
256
256
|
closeCheckout();
|
|
257
257
|
}
|
|
258
258
|
onCheckoutInitiated(callback) {
|
|
259
|
-
window.addEventListener("moonbase-checkout-initiated", (e) => callback(e.detail.order));
|
|
259
|
+
window.addEventListener("moonbase-checkout-initiated", (e) => callback(e.detail.order, e.detail.total));
|
|
260
260
|
}
|
|
261
261
|
onCheckoutCompleted(callback) {
|
|
262
262
|
window.addEventListener("moonbase-checkout-completed", (e) => callback(e.detail.order));
|
|
@@ -569,6 +569,28 @@ function useCart(context) {
|
|
|
569
569
|
const storefront = context != null ? context : (0, import_vue6.inject)(storefrontKey);
|
|
570
570
|
if (!storefront)
|
|
571
571
|
throw new Error("No storefront configured");
|
|
572
|
+
const total = (0, import_vue6.computed)(() => {
|
|
573
|
+
const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
|
|
574
|
+
const total2 = storefront.currentOrder.value.items.reduce((agg, item) => {
|
|
575
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
576
|
+
let price;
|
|
577
|
+
if (item.type === "Product") {
|
|
578
|
+
const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
|
|
579
|
+
const variations = (product == null ? void 0 : product.variations) || [];
|
|
580
|
+
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
581
|
+
const eligiblePricingTiers = (_b = (_a = pickedVariation == null ? void 0 : pickedVariation.pricingTiers) == null ? void 0 : _a.filter((tier) => item.quantity >= tier.minQuantity)) != null ? _b : [];
|
|
582
|
+
const matchingPricingTier = eligiblePricingTiers.length > 0 ? eligiblePricingTiers[eligiblePricingTiers.length - 1] : null;
|
|
583
|
+
price = (_f = (_e = (_c = matchingPricingTier == null ? void 0 : matchingPricingTier.price[currency]) != null ? _c : pickedVariation == null ? void 0 : pickedVariation.price[currency]) != null ? _e : (_d = product == null ? void 0 : product.defaultVariation) == null ? void 0 : _d.price[currency]) != null ? _f : 0;
|
|
584
|
+
} else {
|
|
585
|
+
const bundle = storefront.storefront.value.bundles.find((b) => b.id === item.bundleId);
|
|
586
|
+
const variations = (bundle == null ? void 0 : bundle.variations) || [];
|
|
587
|
+
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
588
|
+
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;
|
|
589
|
+
}
|
|
590
|
+
return agg + price * item.quantity;
|
|
591
|
+
}, 0);
|
|
592
|
+
return { amount: total2, currency };
|
|
593
|
+
});
|
|
572
594
|
return {
|
|
573
595
|
items: (0, import_vue6.computed)(() => storefront.currentOrder.value.items.map((item) => {
|
|
574
596
|
var _a, _b;
|
|
@@ -597,28 +619,7 @@ function useCart(context) {
|
|
|
597
619
|
}
|
|
598
620
|
})),
|
|
599
621
|
currency: (0, import_vue6.computed)(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
|
|
600
|
-
total
|
|
601
|
-
const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
|
|
602
|
-
const total = storefront.currentOrder.value.items.reduce((agg, item) => {
|
|
603
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
604
|
-
let price;
|
|
605
|
-
if (item.type === "Product") {
|
|
606
|
-
const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
|
|
607
|
-
const variations = (product == null ? void 0 : product.variations) || [];
|
|
608
|
-
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
609
|
-
const eligiblePricingTiers = (_b = (_a = pickedVariation == null ? void 0 : pickedVariation.pricingTiers) == null ? void 0 : _a.filter((tier) => item.quantity >= tier.minQuantity)) != null ? _b : [];
|
|
610
|
-
const matchingPricingTier = eligiblePricingTiers.length > 0 ? eligiblePricingTiers[eligiblePricingTiers.length - 1] : null;
|
|
611
|
-
price = (_f = (_e = (_c = matchingPricingTier == null ? void 0 : matchingPricingTier.price[currency]) != null ? _c : pickedVariation == null ? void 0 : pickedVariation.price[currency]) != null ? _e : (_d = product == null ? void 0 : product.defaultVariation) == null ? void 0 : _d.price[currency]) != null ? _f : 0;
|
|
612
|
-
} else {
|
|
613
|
-
const bundle = storefront.storefront.value.bundles.find((b) => b.id === item.bundleId);
|
|
614
|
-
const variations = (bundle == null ? void 0 : bundle.variations) || [];
|
|
615
|
-
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
616
|
-
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;
|
|
617
|
-
}
|
|
618
|
-
return agg + price * item.quantity;
|
|
619
|
-
}, 0);
|
|
620
|
-
return { amount: total, currency };
|
|
621
|
-
}),
|
|
622
|
+
total,
|
|
622
623
|
addToCart: (item, variation) => {
|
|
623
624
|
var _a, _b;
|
|
624
625
|
item = (0, import_vue6.unref)(item);
|
|
@@ -661,6 +662,12 @@ function useCart(context) {
|
|
|
661
662
|
}
|
|
662
663
|
} else {
|
|
663
664
|
lineItem.quantity += 1;
|
|
665
|
+
if (!lineItem.variation && variation)
|
|
666
|
+
lineItem.variation = variation;
|
|
667
|
+
if (lineItem.type === "Product" && item.type === "product" && !lineItem.product)
|
|
668
|
+
lineItem.product = item;
|
|
669
|
+
if (lineItem.type === "Bundle" && item.type === "bundle" && !lineItem.bundle)
|
|
670
|
+
lineItem.bundle = item;
|
|
664
671
|
}
|
|
665
672
|
const _ = storefront.pushOrderContent();
|
|
666
673
|
return lineItem;
|
|
@@ -690,7 +697,7 @@ function useCart(context) {
|
|
|
690
697
|
returnUrl: absoluteReturnUrl
|
|
691
698
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
692
699
|
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
693
|
-
detail: { order: updatedOrder }
|
|
700
|
+
detail: { order: updatedOrder, total: total.value }
|
|
694
701
|
}));
|
|
695
702
|
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
696
703
|
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
|
@@ -765,7 +772,10 @@ async function useCheckout(items, options, context) {
|
|
|
765
772
|
returnUrl: absoluteReturnUrl
|
|
766
773
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
767
774
|
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
768
|
-
detail: { order: updatedOrder
|
|
775
|
+
detail: { order: updatedOrder, total: { amount: items.reduce((a, item) => {
|
|
776
|
+
var _a2, _b2;
|
|
777
|
+
return a + ((_b2 = (_a2 = item.variation) == null ? void 0 : _a2.price[updatedOrder.currency]) != null ? _b2 : 0);
|
|
778
|
+
}, 0), currency: updatedOrder.currency } }
|
|
769
779
|
}));
|
|
770
780
|
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
771
781
|
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
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, OpenOrder, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor, LineItem } from '@moonbase.sh/storefront-api';
|
|
2
|
+
import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, OpenOrder, Money, CompletedOrder, ActivationRequest, Address, 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';
|
|
@@ -23,7 +23,7 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
|
23
23
|
resetOrder: () => void;
|
|
24
24
|
surrenderOrder: () => Promise<void>;
|
|
25
25
|
closeCheckout: () => void;
|
|
26
|
-
onCheckoutInitiated: (callback: (order: OpenOrder) => void) => void;
|
|
26
|
+
onCheckoutInitiated: (callback: (order: OpenOrder, total: Money) => void) => void;
|
|
27
27
|
onCheckoutCompleted: (callback: (order: CompletedOrder) => void) => void;
|
|
28
28
|
onCheckoutClosed: (callback: (intent: string | undefined) => void) => void;
|
|
29
29
|
/**
|
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, OpenOrder, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor, LineItem } from '@moonbase.sh/storefront-api';
|
|
2
|
+
import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, OpenOrder, Money, CompletedOrder, ActivationRequest, Address, 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';
|
|
@@ -23,7 +23,7 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
|
23
23
|
resetOrder: () => void;
|
|
24
24
|
surrenderOrder: () => Promise<void>;
|
|
25
25
|
closeCheckout: () => void;
|
|
26
|
-
onCheckoutInitiated: (callback: (order: OpenOrder) => void) => void;
|
|
26
|
+
onCheckoutInitiated: (callback: (order: OpenOrder, total: Money) => void) => void;
|
|
27
27
|
onCheckoutCompleted: (callback: (order: CompletedOrder) => void) => void;
|
|
28
28
|
onCheckoutClosed: (callback: (intent: string | undefined) => void) => void;
|
|
29
29
|
/**
|
package/dist/index.js
CHANGED
|
@@ -226,7 +226,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
226
226
|
closeCheckout();
|
|
227
227
|
}
|
|
228
228
|
onCheckoutInitiated(callback) {
|
|
229
|
-
window.addEventListener("moonbase-checkout-initiated", (e) => callback(e.detail.order));
|
|
229
|
+
window.addEventListener("moonbase-checkout-initiated", (e) => callback(e.detail.order, e.detail.total));
|
|
230
230
|
}
|
|
231
231
|
onCheckoutCompleted(callback) {
|
|
232
232
|
window.addEventListener("moonbase-checkout-completed", (e) => callback(e.detail.order));
|
|
@@ -539,6 +539,28 @@ function useCart(context) {
|
|
|
539
539
|
const storefront = context != null ? context : inject5(storefrontKey);
|
|
540
540
|
if (!storefront)
|
|
541
541
|
throw new Error("No storefront configured");
|
|
542
|
+
const total = computed4(() => {
|
|
543
|
+
const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
|
|
544
|
+
const total2 = storefront.currentOrder.value.items.reduce((agg, item) => {
|
|
545
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
546
|
+
let price;
|
|
547
|
+
if (item.type === "Product") {
|
|
548
|
+
const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
|
|
549
|
+
const variations = (product == null ? void 0 : product.variations) || [];
|
|
550
|
+
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
551
|
+
const eligiblePricingTiers = (_b = (_a = pickedVariation == null ? void 0 : pickedVariation.pricingTiers) == null ? void 0 : _a.filter((tier) => item.quantity >= tier.minQuantity)) != null ? _b : [];
|
|
552
|
+
const matchingPricingTier = eligiblePricingTiers.length > 0 ? eligiblePricingTiers[eligiblePricingTiers.length - 1] : null;
|
|
553
|
+
price = (_f = (_e = (_c = matchingPricingTier == null ? void 0 : matchingPricingTier.price[currency]) != null ? _c : pickedVariation == null ? void 0 : pickedVariation.price[currency]) != null ? _e : (_d = product == null ? void 0 : product.defaultVariation) == null ? void 0 : _d.price[currency]) != null ? _f : 0;
|
|
554
|
+
} else {
|
|
555
|
+
const bundle = storefront.storefront.value.bundles.find((b) => b.id === item.bundleId);
|
|
556
|
+
const variations = (bundle == null ? void 0 : bundle.variations) || [];
|
|
557
|
+
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
558
|
+
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;
|
|
559
|
+
}
|
|
560
|
+
return agg + price * item.quantity;
|
|
561
|
+
}, 0);
|
|
562
|
+
return { amount: total2, currency };
|
|
563
|
+
});
|
|
542
564
|
return {
|
|
543
565
|
items: computed4(() => storefront.currentOrder.value.items.map((item) => {
|
|
544
566
|
var _a, _b;
|
|
@@ -567,28 +589,7 @@ function useCart(context) {
|
|
|
567
589
|
}
|
|
568
590
|
})),
|
|
569
591
|
currency: computed4(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
|
|
570
|
-
total
|
|
571
|
-
const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
|
|
572
|
-
const total = storefront.currentOrder.value.items.reduce((agg, item) => {
|
|
573
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
574
|
-
let price;
|
|
575
|
-
if (item.type === "Product") {
|
|
576
|
-
const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
|
|
577
|
-
const variations = (product == null ? void 0 : product.variations) || [];
|
|
578
|
-
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
579
|
-
const eligiblePricingTiers = (_b = (_a = pickedVariation == null ? void 0 : pickedVariation.pricingTiers) == null ? void 0 : _a.filter((tier) => item.quantity >= tier.minQuantity)) != null ? _b : [];
|
|
580
|
-
const matchingPricingTier = eligiblePricingTiers.length > 0 ? eligiblePricingTiers[eligiblePricingTiers.length - 1] : null;
|
|
581
|
-
price = (_f = (_e = (_c = matchingPricingTier == null ? void 0 : matchingPricingTier.price[currency]) != null ? _c : pickedVariation == null ? void 0 : pickedVariation.price[currency]) != null ? _e : (_d = product == null ? void 0 : product.defaultVariation) == null ? void 0 : _d.price[currency]) != null ? _f : 0;
|
|
582
|
-
} else {
|
|
583
|
-
const bundle = storefront.storefront.value.bundles.find((b) => b.id === item.bundleId);
|
|
584
|
-
const variations = (bundle == null ? void 0 : bundle.variations) || [];
|
|
585
|
-
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
586
|
-
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;
|
|
587
|
-
}
|
|
588
|
-
return agg + price * item.quantity;
|
|
589
|
-
}, 0);
|
|
590
|
-
return { amount: total, currency };
|
|
591
|
-
}),
|
|
592
|
+
total,
|
|
592
593
|
addToCart: (item, variation) => {
|
|
593
594
|
var _a, _b;
|
|
594
595
|
item = unref(item);
|
|
@@ -631,6 +632,12 @@ function useCart(context) {
|
|
|
631
632
|
}
|
|
632
633
|
} else {
|
|
633
634
|
lineItem.quantity += 1;
|
|
635
|
+
if (!lineItem.variation && variation)
|
|
636
|
+
lineItem.variation = variation;
|
|
637
|
+
if (lineItem.type === "Product" && item.type === "product" && !lineItem.product)
|
|
638
|
+
lineItem.product = item;
|
|
639
|
+
if (lineItem.type === "Bundle" && item.type === "bundle" && !lineItem.bundle)
|
|
640
|
+
lineItem.bundle = item;
|
|
634
641
|
}
|
|
635
642
|
const _ = storefront.pushOrderContent();
|
|
636
643
|
return lineItem;
|
|
@@ -660,7 +667,7 @@ function useCart(context) {
|
|
|
660
667
|
returnUrl: absoluteReturnUrl
|
|
661
668
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
662
669
|
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
663
|
-
detail: { order: updatedOrder }
|
|
670
|
+
detail: { order: updatedOrder, total: total.value }
|
|
664
671
|
}));
|
|
665
672
|
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
666
673
|
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
|
@@ -735,7 +742,10 @@ async function useCheckout(items, options, context) {
|
|
|
735
742
|
returnUrl: absoluteReturnUrl
|
|
736
743
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
737
744
|
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
738
|
-
detail: { order: updatedOrder
|
|
745
|
+
detail: { order: updatedOrder, total: { amount: items.reduce((a, item) => {
|
|
746
|
+
var _a2, _b2;
|
|
747
|
+
return a + ((_b2 = (_a2 = item.variation) == null ? void 0 : _a2.price[updatedOrder.currency]) != null ? _b2 : 0);
|
|
748
|
+
}, 0), currency: updatedOrder.currency } }
|
|
739
749
|
}));
|
|
740
750
|
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
741
751
|
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
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
|
+
"version": "0.3.7",
|
|
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.
|
|
22
|
+
"@moonbase.sh/storefront-api": "0.3.7"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/uuid": "^9.0.8",
|