@moonbase.sh/vue 0.3.5 → 0.3.6
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 +29 -25
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -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);
|
|
@@ -690,7 +691,7 @@ function useCart(context) {
|
|
|
690
691
|
returnUrl: absoluteReturnUrl
|
|
691
692
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
692
693
|
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
693
|
-
detail: { order: updatedOrder }
|
|
694
|
+
detail: { order: updatedOrder, total: total.value }
|
|
694
695
|
}));
|
|
695
696
|
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
696
697
|
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
|
@@ -765,7 +766,10 @@ async function useCheckout(items, options, context) {
|
|
|
765
766
|
returnUrl: absoluteReturnUrl
|
|
766
767
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
767
768
|
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
768
|
-
detail: { order: updatedOrder
|
|
769
|
+
detail: { order: updatedOrder, total: { amount: items.reduce((a, item) => {
|
|
770
|
+
var _a2, _b2;
|
|
771
|
+
return a + ((_b2 = (_a2 = item.variation) == null ? void 0 : _a2.price[updatedOrder.currency]) != null ? _b2 : 0);
|
|
772
|
+
}, 0), currency: updatedOrder.currency } }
|
|
769
773
|
}));
|
|
770
774
|
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
771
775
|
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);
|
|
@@ -660,7 +661,7 @@ function useCart(context) {
|
|
|
660
661
|
returnUrl: absoluteReturnUrl
|
|
661
662
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
662
663
|
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
663
|
-
detail: { order: updatedOrder }
|
|
664
|
+
detail: { order: updatedOrder, total: total.value }
|
|
664
665
|
}));
|
|
665
666
|
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
666
667
|
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
|
@@ -735,7 +736,10 @@ async function useCheckout(items, options, context) {
|
|
|
735
736
|
returnUrl: absoluteReturnUrl
|
|
736
737
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
737
738
|
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
738
|
-
detail: { order: updatedOrder
|
|
739
|
+
detail: { order: updatedOrder, total: { amount: items.reduce((a, item) => {
|
|
740
|
+
var _a2, _b2;
|
|
741
|
+
return a + ((_b2 = (_a2 = item.variation) == null ? void 0 : _a2.price[updatedOrder.currency]) != null ? _b2 : 0);
|
|
742
|
+
}, 0), currency: updatedOrder.currency } }
|
|
739
743
|
}));
|
|
740
744
|
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
741
745
|
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.6",
|
|
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.6"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/uuid": "^9.0.8",
|