@moonbase.sh/vue 0.3.7 → 0.3.9
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 +40 -26
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +40 -26
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -291,6 +291,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
291
291
|
if (!this.currentOrder.value.currency) {
|
|
292
292
|
this.currentOrder.value.currency = latestStorefront.suggestedCurrency;
|
|
293
293
|
}
|
|
294
|
+
this.currentOrder.value.items = this.enrichLineItems(this.currentOrder.value.items);
|
|
294
295
|
}
|
|
295
296
|
return latestStorefront;
|
|
296
297
|
}
|
|
@@ -335,6 +336,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
335
336
|
if (latestOrder.status !== import_storefront_api2.OrderStatus.Open) {
|
|
336
337
|
this.resetOrder();
|
|
337
338
|
} else {
|
|
339
|
+
latestOrder.items = this.enrichLineItems(latestOrder.items);
|
|
338
340
|
if (typeof window !== "undefined")
|
|
339
341
|
localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
|
|
340
342
|
this.currentOrder.value = latestOrder;
|
|
@@ -367,6 +369,37 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
367
369
|
console.warn("Could not surrender order:", err);
|
|
368
370
|
}
|
|
369
371
|
}
|
|
372
|
+
enrichLineItems(lineItems) {
|
|
373
|
+
if (this.storefront) {
|
|
374
|
+
return lineItems.map((item) => {
|
|
375
|
+
var _a, _b;
|
|
376
|
+
if (item.type === "Product") {
|
|
377
|
+
const product = this.storefront.value.products.find((p) => p.id === item.productId);
|
|
378
|
+
const variations = (product == null ? void 0 : product.variations) || [];
|
|
379
|
+
const variation = variations.find((v) => v.id === item.variationId);
|
|
380
|
+
return {
|
|
381
|
+
...item,
|
|
382
|
+
product,
|
|
383
|
+
variation,
|
|
384
|
+
price: variation == null ? void 0 : variation.price,
|
|
385
|
+
appliedDiscount: (_a = variation == null ? void 0 : variation.discount) != null ? _a : item.appliedDiscount
|
|
386
|
+
};
|
|
387
|
+
} else {
|
|
388
|
+
const bundle = this.storefront.value.bundles.find((b) => b.id === item.bundleId);
|
|
389
|
+
const variations = (bundle == null ? void 0 : bundle.variations) || [];
|
|
390
|
+
const variation = variations.find((v) => v.id === item.variationId);
|
|
391
|
+
return {
|
|
392
|
+
...item,
|
|
393
|
+
bundle,
|
|
394
|
+
variation,
|
|
395
|
+
price: variation == null ? void 0 : variation.price,
|
|
396
|
+
appliedDiscount: (_b = variation == null ? void 0 : variation.discount) != null ? _b : item.appliedDiscount
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
return lineItems;
|
|
402
|
+
}
|
|
370
403
|
};
|
|
371
404
|
_StorefrontContextImpl.userKey = "moonbase_user";
|
|
372
405
|
_StorefrontContextImpl.sessionKey = "moonbase_session";
|
|
@@ -592,32 +625,7 @@ function useCart(context) {
|
|
|
592
625
|
return { amount: total2, currency };
|
|
593
626
|
});
|
|
594
627
|
return {
|
|
595
|
-
items: (0, import_vue6.computed)(() => storefront.currentOrder.value.items
|
|
596
|
-
var _a, _b;
|
|
597
|
-
if (item.type === "Product") {
|
|
598
|
-
const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
|
|
599
|
-
const variations = (product == null ? void 0 : product.variations) || [];
|
|
600
|
-
const variation = variations.find((v) => v.id === item.variationId);
|
|
601
|
-
return {
|
|
602
|
-
...item,
|
|
603
|
-
product,
|
|
604
|
-
variation,
|
|
605
|
-
price: variation == null ? void 0 : variation.price,
|
|
606
|
-
appliedDiscount: (_a = variation == null ? void 0 : variation.discount) != null ? _a : item.appliedDiscount
|
|
607
|
-
};
|
|
608
|
-
} else {
|
|
609
|
-
const bundle = storefront.storefront.value.bundles.find((b) => b.id === item.bundleId);
|
|
610
|
-
const variations = (bundle == null ? void 0 : bundle.variations) || [];
|
|
611
|
-
const variation = variations.find((v) => v.id === item.variationId);
|
|
612
|
-
return {
|
|
613
|
-
...item,
|
|
614
|
-
bundle,
|
|
615
|
-
variation,
|
|
616
|
-
price: variation == null ? void 0 : variation.price,
|
|
617
|
-
appliedDiscount: (_b = variation == null ? void 0 : variation.discount) != null ? _b : item.appliedDiscount
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
})),
|
|
628
|
+
items: (0, import_vue6.computed)(() => storefront.enrichLineItems(storefront.currentOrder.value.items)),
|
|
621
629
|
currency: (0, import_vue6.computed)(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
|
|
622
630
|
total,
|
|
623
631
|
addToCart: (item, variation) => {
|
|
@@ -664,6 +672,10 @@ function useCart(context) {
|
|
|
664
672
|
lineItem.quantity += 1;
|
|
665
673
|
if (!lineItem.variation && variation)
|
|
666
674
|
lineItem.variation = variation;
|
|
675
|
+
if (!lineItem.price && variation)
|
|
676
|
+
lineItem.price = variation.price;
|
|
677
|
+
if (!lineItem.appliedDiscount && variation.discount)
|
|
678
|
+
lineItem.appliedDiscount = variation.discount;
|
|
667
679
|
if (lineItem.type === "Product" && item.type === "product" && !lineItem.product)
|
|
668
680
|
lineItem.product = item;
|
|
669
681
|
if (lineItem.type === "Bundle" && item.type === "bundle" && !lineItem.bundle)
|
|
@@ -696,6 +708,7 @@ function useCart(context) {
|
|
|
696
708
|
const updatedOrder = await storefront.client.orders.pushContent(storefront.currentOrder.value, {
|
|
697
709
|
returnUrl: absoluteReturnUrl
|
|
698
710
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
711
|
+
updatedOrder.items = storefront.enrichLineItems(updatedOrder.items);
|
|
699
712
|
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
700
713
|
detail: { order: updatedOrder, total: total.value }
|
|
701
714
|
}));
|
|
@@ -771,6 +784,7 @@ async function useCheckout(items, options, context) {
|
|
|
771
784
|
}, {
|
|
772
785
|
returnUrl: absoluteReturnUrl
|
|
773
786
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
787
|
+
updatedOrder.items = storefront.enrichLineItems(updatedOrder.items);
|
|
774
788
|
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
775
789
|
detail: { order: updatedOrder, total: { amount: items.reduce((a, item) => {
|
|
776
790
|
var _a2, _b2;
|
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, Money, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor
|
|
2
|
+
import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, LineItem, OpenOrder, Money, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor } 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';
|
|
@@ -22,6 +22,7 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
|
22
22
|
pushOrderContent: () => Promise<void>;
|
|
23
23
|
resetOrder: () => void;
|
|
24
24
|
surrenderOrder: () => Promise<void>;
|
|
25
|
+
enrichLineItems: (lineItems: LineItem[]) => LineItem[];
|
|
25
26
|
closeCheckout: () => void;
|
|
26
27
|
onCheckoutInitiated: (callback: (order: OpenOrder, total: Money) => void) => void;
|
|
27
28
|
onCheckoutCompleted: (callback: (order: CompletedOrder) => void) => void;
|
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, Money, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor
|
|
2
|
+
import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, LineItem, OpenOrder, Money, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor } 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';
|
|
@@ -22,6 +22,7 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
|
22
22
|
pushOrderContent: () => Promise<void>;
|
|
23
23
|
resetOrder: () => void;
|
|
24
24
|
surrenderOrder: () => Promise<void>;
|
|
25
|
+
enrichLineItems: (lineItems: LineItem[]) => LineItem[];
|
|
25
26
|
closeCheckout: () => void;
|
|
26
27
|
onCheckoutInitiated: (callback: (order: OpenOrder, total: Money) => void) => void;
|
|
27
28
|
onCheckoutCompleted: (callback: (order: CompletedOrder) => void) => void;
|
package/dist/index.js
CHANGED
|
@@ -261,6 +261,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
261
261
|
if (!this.currentOrder.value.currency) {
|
|
262
262
|
this.currentOrder.value.currency = latestStorefront.suggestedCurrency;
|
|
263
263
|
}
|
|
264
|
+
this.currentOrder.value.items = this.enrichLineItems(this.currentOrder.value.items);
|
|
264
265
|
}
|
|
265
266
|
return latestStorefront;
|
|
266
267
|
}
|
|
@@ -305,6 +306,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
305
306
|
if (latestOrder.status !== OrderStatus.Open) {
|
|
306
307
|
this.resetOrder();
|
|
307
308
|
} else {
|
|
309
|
+
latestOrder.items = this.enrichLineItems(latestOrder.items);
|
|
308
310
|
if (typeof window !== "undefined")
|
|
309
311
|
localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
|
|
310
312
|
this.currentOrder.value = latestOrder;
|
|
@@ -337,6 +339,37 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
337
339
|
console.warn("Could not surrender order:", err);
|
|
338
340
|
}
|
|
339
341
|
}
|
|
342
|
+
enrichLineItems(lineItems) {
|
|
343
|
+
if (this.storefront) {
|
|
344
|
+
return lineItems.map((item) => {
|
|
345
|
+
var _a, _b;
|
|
346
|
+
if (item.type === "Product") {
|
|
347
|
+
const product = this.storefront.value.products.find((p) => p.id === item.productId);
|
|
348
|
+
const variations = (product == null ? void 0 : product.variations) || [];
|
|
349
|
+
const variation = variations.find((v) => v.id === item.variationId);
|
|
350
|
+
return {
|
|
351
|
+
...item,
|
|
352
|
+
product,
|
|
353
|
+
variation,
|
|
354
|
+
price: variation == null ? void 0 : variation.price,
|
|
355
|
+
appliedDiscount: (_a = variation == null ? void 0 : variation.discount) != null ? _a : item.appliedDiscount
|
|
356
|
+
};
|
|
357
|
+
} else {
|
|
358
|
+
const bundle = this.storefront.value.bundles.find((b) => b.id === item.bundleId);
|
|
359
|
+
const variations = (bundle == null ? void 0 : bundle.variations) || [];
|
|
360
|
+
const variation = variations.find((v) => v.id === item.variationId);
|
|
361
|
+
return {
|
|
362
|
+
...item,
|
|
363
|
+
bundle,
|
|
364
|
+
variation,
|
|
365
|
+
price: variation == null ? void 0 : variation.price,
|
|
366
|
+
appliedDiscount: (_b = variation == null ? void 0 : variation.discount) != null ? _b : item.appliedDiscount
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
return lineItems;
|
|
372
|
+
}
|
|
340
373
|
};
|
|
341
374
|
_StorefrontContextImpl.userKey = "moonbase_user";
|
|
342
375
|
_StorefrontContextImpl.sessionKey = "moonbase_session";
|
|
@@ -562,32 +595,7 @@ function useCart(context) {
|
|
|
562
595
|
return { amount: total2, currency };
|
|
563
596
|
});
|
|
564
597
|
return {
|
|
565
|
-
items: computed4(() => storefront.currentOrder.value.items
|
|
566
|
-
var _a, _b;
|
|
567
|
-
if (item.type === "Product") {
|
|
568
|
-
const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
|
|
569
|
-
const variations = (product == null ? void 0 : product.variations) || [];
|
|
570
|
-
const variation = variations.find((v) => v.id === item.variationId);
|
|
571
|
-
return {
|
|
572
|
-
...item,
|
|
573
|
-
product,
|
|
574
|
-
variation,
|
|
575
|
-
price: variation == null ? void 0 : variation.price,
|
|
576
|
-
appliedDiscount: (_a = variation == null ? void 0 : variation.discount) != null ? _a : item.appliedDiscount
|
|
577
|
-
};
|
|
578
|
-
} else {
|
|
579
|
-
const bundle = storefront.storefront.value.bundles.find((b) => b.id === item.bundleId);
|
|
580
|
-
const variations = (bundle == null ? void 0 : bundle.variations) || [];
|
|
581
|
-
const variation = variations.find((v) => v.id === item.variationId);
|
|
582
|
-
return {
|
|
583
|
-
...item,
|
|
584
|
-
bundle,
|
|
585
|
-
variation,
|
|
586
|
-
price: variation == null ? void 0 : variation.price,
|
|
587
|
-
appliedDiscount: (_b = variation == null ? void 0 : variation.discount) != null ? _b : item.appliedDiscount
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
|
-
})),
|
|
598
|
+
items: computed4(() => storefront.enrichLineItems(storefront.currentOrder.value.items)),
|
|
591
599
|
currency: computed4(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
|
|
592
600
|
total,
|
|
593
601
|
addToCart: (item, variation) => {
|
|
@@ -634,6 +642,10 @@ function useCart(context) {
|
|
|
634
642
|
lineItem.quantity += 1;
|
|
635
643
|
if (!lineItem.variation && variation)
|
|
636
644
|
lineItem.variation = variation;
|
|
645
|
+
if (!lineItem.price && variation)
|
|
646
|
+
lineItem.price = variation.price;
|
|
647
|
+
if (!lineItem.appliedDiscount && variation.discount)
|
|
648
|
+
lineItem.appliedDiscount = variation.discount;
|
|
637
649
|
if (lineItem.type === "Product" && item.type === "product" && !lineItem.product)
|
|
638
650
|
lineItem.product = item;
|
|
639
651
|
if (lineItem.type === "Bundle" && item.type === "bundle" && !lineItem.bundle)
|
|
@@ -666,6 +678,7 @@ function useCart(context) {
|
|
|
666
678
|
const updatedOrder = await storefront.client.orders.pushContent(storefront.currentOrder.value, {
|
|
667
679
|
returnUrl: absoluteReturnUrl
|
|
668
680
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
681
|
+
updatedOrder.items = storefront.enrichLineItems(updatedOrder.items);
|
|
669
682
|
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
670
683
|
detail: { order: updatedOrder, total: total.value }
|
|
671
684
|
}));
|
|
@@ -741,6 +754,7 @@ async function useCheckout(items, options, context) {
|
|
|
741
754
|
}, {
|
|
742
755
|
returnUrl: absoluteReturnUrl
|
|
743
756
|
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
757
|
+
updatedOrder.items = storefront.enrichLineItems(updatedOrder.items);
|
|
744
758
|
window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
|
|
745
759
|
detail: { order: updatedOrder, total: { amount: items.reduce((a, item) => {
|
|
746
760
|
var _a2, _b2;
|
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.9",
|
|
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.9"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/uuid": "^9.0.8",
|