@moonbase.sh/vue 0.2.28 → 0.2.31
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 -23
- package/dist/index.d.cts +25 -154
- package/dist/index.d.ts +25 -154
- package/dist/index.js +18 -6
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -34,13 +34,13 @@ __export(src_exports, {
|
|
|
34
34
|
useVoucher: () => useVoucher
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(src_exports);
|
|
37
|
-
var
|
|
37
|
+
var import_storefront_api5 = require("@moonbase.sh/storefront-api");
|
|
38
38
|
var import_vue11 = require("vue");
|
|
39
39
|
|
|
40
40
|
// src/context.ts
|
|
41
41
|
var import_uuid = require("uuid");
|
|
42
42
|
var import_vue = require("vue");
|
|
43
|
-
var
|
|
43
|
+
var import_storefront_api2 = require("@moonbase.sh/storefront-api");
|
|
44
44
|
|
|
45
45
|
// src/symbols.ts
|
|
46
46
|
var storefrontKey = Symbol("storefront");
|
|
@@ -58,6 +58,7 @@ function debounce(func, waitMs = 100) {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// src/utils/iframe-checkout.ts
|
|
61
|
+
var import_storefront_api = require("@moonbase.sh/storefront-api");
|
|
61
62
|
var import_zod = require("zod");
|
|
62
63
|
var closeEventSchema = import_zod.z.object({
|
|
63
64
|
source: import_zod.z.literal("moonbase-checkout"),
|
|
@@ -66,9 +67,17 @@ var closeEventSchema = import_zod.z.object({
|
|
|
66
67
|
});
|
|
67
68
|
var completedEventSchema = import_zod.z.object({
|
|
68
69
|
source: import_zod.z.literal("moonbase-checkout"),
|
|
69
|
-
event: import_zod.z.literal("completed")
|
|
70
|
+
event: import_zod.z.literal("completed"),
|
|
71
|
+
order: import_storefront_api.schemas.orders.completedOrderSchema
|
|
70
72
|
});
|
|
71
73
|
var eventSchema = import_zod.z.discriminatedUnion("event", [closeEventSchema, completedEventSchema]);
|
|
74
|
+
function closeCheckout() {
|
|
75
|
+
var _a;
|
|
76
|
+
const iframe = document.getElementById("moonbase-checkout");
|
|
77
|
+
if (!iframe || !(iframe instanceof HTMLIFrameElement))
|
|
78
|
+
return;
|
|
79
|
+
(_a = iframe.contentWindow) == null ? void 0 : _a.postMessage("close", "*");
|
|
80
|
+
}
|
|
72
81
|
function mountCheckout(endpoint) {
|
|
73
82
|
if (typeof window === "undefined") {
|
|
74
83
|
console.warn("Can not mount checkout server side");
|
|
@@ -133,7 +142,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
133
142
|
if (typeof window === "undefined") {
|
|
134
143
|
this.currentOrder = (0, import_vue.ref)({
|
|
135
144
|
id: (0, import_uuid.v4)(),
|
|
136
|
-
status:
|
|
145
|
+
status: import_storefront_api2.OrderStatus.Open,
|
|
137
146
|
currency: "",
|
|
138
147
|
items: [],
|
|
139
148
|
couponsApplied: []
|
|
@@ -164,7 +173,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
164
173
|
} else {
|
|
165
174
|
this.currentOrder = (0, import_vue.ref)({
|
|
166
175
|
id: (0, import_uuid.v4)(),
|
|
167
|
-
status:
|
|
176
|
+
status: import_storefront_api2.OrderStatus.Open,
|
|
168
177
|
currency: "",
|
|
169
178
|
items: [],
|
|
170
179
|
couponsApplied: []
|
|
@@ -219,8 +228,11 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
219
228
|
}, { immediate: true });
|
|
220
229
|
});
|
|
221
230
|
}
|
|
231
|
+
closeCheckout() {
|
|
232
|
+
closeCheckout();
|
|
233
|
+
}
|
|
222
234
|
onCheckoutCompleted(callback) {
|
|
223
|
-
window.addEventListener("moonbase-checkout-completed", () => callback());
|
|
235
|
+
window.addEventListener("moonbase-checkout-completed", (e) => callback(e.detail.order));
|
|
224
236
|
}
|
|
225
237
|
onCheckoutClosed(callback) {
|
|
226
238
|
window.addEventListener("moonbase-checkout-closed", (e) => callback(e.detail.intent));
|
|
@@ -233,7 +245,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
233
245
|
try {
|
|
234
246
|
this.currentUser.value = await this.client.identity.get();
|
|
235
247
|
} catch (err) {
|
|
236
|
-
if (!(err instanceof
|
|
248
|
+
if (!(err instanceof import_storefront_api2.NotAuthenticatedError))
|
|
237
249
|
console.error("Could not load user", err);
|
|
238
250
|
} finally {
|
|
239
251
|
this.loadedUser.value = true;
|
|
@@ -270,7 +282,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
270
282
|
try {
|
|
271
283
|
const latestOrder = await this.client.orders.get(this.currentOrder.value.id);
|
|
272
284
|
if (latestOrder) {
|
|
273
|
-
if (latestOrder.status !==
|
|
285
|
+
if (latestOrder.status !== import_storefront_api2.OrderStatus.Open) {
|
|
274
286
|
this.resetOrder();
|
|
275
287
|
} else {
|
|
276
288
|
if (typeof window !== "undefined")
|
|
@@ -288,7 +300,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
288
300
|
this.currentOrder.value = {
|
|
289
301
|
id: (0, import_uuid.v4)(),
|
|
290
302
|
currency: ((_a = this.storefront.value) == null ? void 0 : _a.suggestedCurrency) || "",
|
|
291
|
-
status:
|
|
303
|
+
status: import_storefront_api2.OrderStatus.Open,
|
|
292
304
|
items: [],
|
|
293
305
|
couponsApplied: []
|
|
294
306
|
};
|
|
@@ -380,7 +392,7 @@ function useInventory(context) {
|
|
|
380
392
|
}
|
|
381
393
|
|
|
382
394
|
// src/composables/useActivationRequest.ts
|
|
383
|
-
var
|
|
395
|
+
var import_storefront_api3 = require("@moonbase.sh/storefront-api");
|
|
384
396
|
var import_vue7 = require("vue");
|
|
385
397
|
function useActivationRequest(token, context) {
|
|
386
398
|
const storefront = context != null ? context : (0, import_vue7.inject)(storefrontKey);
|
|
@@ -398,7 +410,7 @@ function useActivationRequest(token, context) {
|
|
|
398
410
|
const checkCompletion = async () => {
|
|
399
411
|
const completed = await storefront.client.activationRequests.isCompleted(requestId);
|
|
400
412
|
if (completed && activationRequest.value) {
|
|
401
|
-
activationRequest.value.status =
|
|
413
|
+
activationRequest.value.status = import_storefront_api3.ActivationRequestStatus.Completed;
|
|
402
414
|
completing.value = false;
|
|
403
415
|
} else {
|
|
404
416
|
completionTimeout.value = setTimeout(checkCompletion, 1500);
|
|
@@ -407,7 +419,7 @@ function useActivationRequest(token, context) {
|
|
|
407
419
|
if (requestId && requestId.length > 0) {
|
|
408
420
|
storefront.client.activationRequests.get(requestId).then((result) => {
|
|
409
421
|
activationRequest.value = result;
|
|
410
|
-
if (activationRequest.value.status ===
|
|
422
|
+
if (activationRequest.value.status === import_storefront_api3.ActivationRequestStatus.Fulfilled) {
|
|
411
423
|
completing.value = true;
|
|
412
424
|
checkCompletion();
|
|
413
425
|
}
|
|
@@ -431,7 +443,7 @@ function useActivationRequest(token, context) {
|
|
|
431
443
|
loading.value = true;
|
|
432
444
|
try {
|
|
433
445
|
activationRequest.value = await storefront.client.activationRequests.get(requestId);
|
|
434
|
-
if (activationRequest.value.status ===
|
|
446
|
+
if (activationRequest.value.status === import_storefront_api3.ActivationRequestStatus.Fulfilled) {
|
|
435
447
|
completing.value = true;
|
|
436
448
|
checkCompletion();
|
|
437
449
|
}
|
|
@@ -448,7 +460,7 @@ function useActivationRequest(token, context) {
|
|
|
448
460
|
error,
|
|
449
461
|
isInstalled: (0, import_vue7.computed)(() => {
|
|
450
462
|
var _a;
|
|
451
|
-
return activationRequest && ((_a = activationRequest.value) == null ? void 0 : _a.status) ===
|
|
463
|
+
return activationRequest && ((_a = activationRequest.value) == null ? void 0 : _a.status) === import_storefront_api3.ActivationRequestStatus.Completed;
|
|
452
464
|
}),
|
|
453
465
|
fulfillLicense: async () => {
|
|
454
466
|
fulfilling.value = true;
|
|
@@ -466,7 +478,7 @@ function useActivationRequest(token, context) {
|
|
|
466
478
|
},
|
|
467
479
|
cancel: async () => {
|
|
468
480
|
var _a;
|
|
469
|
-
if (((_a = activationRequest.value) == null ? void 0 : _a.status) ===
|
|
481
|
+
if (((_a = activationRequest.value) == null ? void 0 : _a.status) === import_storefront_api3.ActivationRequestStatus.Cancelled)
|
|
470
482
|
return;
|
|
471
483
|
activationRequest.value = await storefront.client.activationRequests.cancel(requestId);
|
|
472
484
|
}
|
|
@@ -474,7 +486,7 @@ function useActivationRequest(token, context) {
|
|
|
474
486
|
}
|
|
475
487
|
|
|
476
488
|
// src/composables/useVoucher.ts
|
|
477
|
-
var
|
|
489
|
+
var import_storefront_api4 = require("@moonbase.sh/storefront-api");
|
|
478
490
|
var import_vue8 = require("vue");
|
|
479
491
|
function useVoucher(context) {
|
|
480
492
|
const storefront = context != null ? context : (0, import_vue8.inject)(storefrontKey);
|
|
@@ -485,7 +497,7 @@ function useVoucher(context) {
|
|
|
485
497
|
try {
|
|
486
498
|
return await storefront.client.vouchers.peek(code);
|
|
487
499
|
} catch (e) {
|
|
488
|
-
if (e instanceof
|
|
500
|
+
if (e instanceof import_storefront_api4.NotFoundError)
|
|
489
501
|
throw new Error("Voucher code invalid");
|
|
490
502
|
throw e;
|
|
491
503
|
}
|
|
@@ -494,7 +506,7 @@ function useVoucher(context) {
|
|
|
494
506
|
try {
|
|
495
507
|
return await storefront.client.vouchers.redeem(code);
|
|
496
508
|
} catch (e) {
|
|
497
|
-
if (e instanceof
|
|
509
|
+
if (e instanceof import_storefront_api4.NotFoundError)
|
|
498
510
|
throw new Error("Voucher code invalid");
|
|
499
511
|
throw e;
|
|
500
512
|
}
|
|
@@ -612,12 +624,12 @@ function useCart(context) {
|
|
|
612
624
|
storefront.currentOrder.value.items.splice(index, 1);
|
|
613
625
|
const _ = storefront.pushOrderContent();
|
|
614
626
|
},
|
|
615
|
-
checkout: async (
|
|
616
|
-
const absoluteReturnUrl = new URL(returnUrl, document.baseURI).href;
|
|
627
|
+
checkout: async (options) => {
|
|
628
|
+
const absoluteReturnUrl = new URL(options.returnUrl, document.baseURI).href;
|
|
617
629
|
const updatedOrder = await storefront.client.orders.pushContent(storefront.currentOrder.value, {
|
|
618
630
|
returnUrl: absoluteReturnUrl
|
|
619
631
|
});
|
|
620
|
-
if (updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
632
|
+
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
621
633
|
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
|
622
634
|
return new Promise((resolve) => {
|
|
623
635
|
mountCheckout(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
|
|
@@ -625,7 +637,7 @@ function useCart(context) {
|
|
|
625
637
|
resolve({ next: e.detail.next });
|
|
626
638
|
});
|
|
627
639
|
});
|
|
628
|
-
} else if (updatedOrder.checkoutUrl && typeof window !== "undefined") {
|
|
640
|
+
} else if (options.redirect && updatedOrder.checkoutUrl && typeof window !== "undefined") {
|
|
629
641
|
window.location.href = updatedOrder.checkoutUrl;
|
|
630
642
|
return { next: void 0 };
|
|
631
643
|
} else {
|
|
@@ -708,7 +720,7 @@ function createStorefront(endpoint, stateFactory) {
|
|
|
708
720
|
};
|
|
709
721
|
return new StorefrontContextImpl(
|
|
710
722
|
configuration,
|
|
711
|
-
new
|
|
723
|
+
new import_storefront_api5.MoonbaseClient(configuration),
|
|
712
724
|
// Default to vue refs but allow stuff like Nuxt useState wrappers
|
|
713
725
|
stateFactory || ((_, state) => (0, import_vue11.ref)(state))
|
|
714
726
|
);
|
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, MoonbaseClient, StorefrontBundle, StorefrontProduct, ActivationMethod, Activation, Download, ActivationRequest, PricingVariation, CommunicationPreferences, LineItem } from '@moonbase.sh/storefront-api';
|
|
2
|
+
import { MoonbaseConfiguration, Storefront, Order, User, MoonbaseClient, CompletedOrder, StorefrontBundle, StorefrontProduct, ActivationMethod, Activation, Download, ActivationRequest, PricingVariation, CommunicationPreferences, 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';
|
|
@@ -20,7 +20,8 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
|
20
20
|
updateStorefront: () => Promise<void>;
|
|
21
21
|
pushOrderContent: () => Promise<void>;
|
|
22
22
|
resetOrder: () => void;
|
|
23
|
-
|
|
23
|
+
closeCheckout: () => void;
|
|
24
|
+
onCheckoutCompleted: (callback: (order: CompletedOrder) => void) => void;
|
|
24
25
|
onCheckoutClosed: (callback: (intent: string | undefined) => void) => void;
|
|
25
26
|
/**
|
|
26
27
|
* Called automatically by `app.use(storefront)`. Should not be called manually by
|
|
@@ -594,63 +595,10 @@ declare function useCart(context?: StorefrontContext): {
|
|
|
594
595
|
variationId: string;
|
|
595
596
|
price?: Record<string, number> | undefined;
|
|
596
597
|
product?: {
|
|
597
|
-
type: "product";
|
|
598
598
|
id: string;
|
|
599
599
|
name: string;
|
|
600
600
|
tagline: string;
|
|
601
601
|
iconUrl: string | null;
|
|
602
|
-
owned: boolean;
|
|
603
|
-
website?: string | null | undefined;
|
|
604
|
-
currentVersion?: string | undefined;
|
|
605
|
-
downloads?: {
|
|
606
|
-
path: string | null;
|
|
607
|
-
name: string;
|
|
608
|
-
key: string;
|
|
609
|
-
platform: _moonbase_sh_storefront_api.Platform;
|
|
610
|
-
size: number;
|
|
611
|
-
}[] | undefined;
|
|
612
|
-
defaultVariation?: {
|
|
613
|
-
id: string;
|
|
614
|
-
name: string;
|
|
615
|
-
originalPrice: Record<string, number>;
|
|
616
|
-
price: Record<string, number>;
|
|
617
|
-
hasDiscount: boolean;
|
|
618
|
-
discount?: {
|
|
619
|
-
type: "PercentageOffDiscount";
|
|
620
|
-
name: string;
|
|
621
|
-
percentage: number;
|
|
622
|
-
isExclusive: boolean;
|
|
623
|
-
description?: string | undefined;
|
|
624
|
-
total?: Record<string, number> | undefined;
|
|
625
|
-
} | {
|
|
626
|
-
type: "FlatAmountOffDiscount";
|
|
627
|
-
name: string;
|
|
628
|
-
isExclusive: boolean;
|
|
629
|
-
description?: string | undefined;
|
|
630
|
-
total?: Record<string, number> | undefined;
|
|
631
|
-
} | undefined;
|
|
632
|
-
} | undefined;
|
|
633
|
-
variations?: {
|
|
634
|
-
id: string;
|
|
635
|
-
name: string;
|
|
636
|
-
originalPrice: Record<string, number>;
|
|
637
|
-
price: Record<string, number>;
|
|
638
|
-
hasDiscount: boolean;
|
|
639
|
-
discount?: {
|
|
640
|
-
type: "PercentageOffDiscount";
|
|
641
|
-
name: string;
|
|
642
|
-
percentage: number;
|
|
643
|
-
isExclusive: boolean;
|
|
644
|
-
description?: string | undefined;
|
|
645
|
-
total?: Record<string, number> | undefined;
|
|
646
|
-
} | {
|
|
647
|
-
type: "FlatAmountOffDiscount";
|
|
648
|
-
name: string;
|
|
649
|
-
isExclusive: boolean;
|
|
650
|
-
description?: string | undefined;
|
|
651
|
-
total?: Record<string, number> | undefined;
|
|
652
|
-
} | undefined;
|
|
653
|
-
}[] | undefined;
|
|
654
602
|
} | undefined;
|
|
655
603
|
variation?: {
|
|
656
604
|
id: string;
|
|
@@ -695,116 +643,19 @@ declare function useCart(context?: StorefrontContext): {
|
|
|
695
643
|
bundleId: string;
|
|
696
644
|
price?: Record<string, number> | undefined;
|
|
697
645
|
bundle?: {
|
|
698
|
-
type: "bundle";
|
|
699
646
|
id: string;
|
|
700
647
|
name: string;
|
|
701
648
|
tagline: string;
|
|
702
649
|
iconUrl: string | null;
|
|
703
|
-
owned: boolean;
|
|
704
650
|
partial: boolean;
|
|
705
651
|
products: ({
|
|
706
|
-
type: "product";
|
|
707
652
|
id: string;
|
|
708
653
|
name: string;
|
|
709
654
|
tagline: string;
|
|
710
655
|
iconUrl: string | null;
|
|
711
|
-
owned: boolean;
|
|
712
|
-
website?: string | null | undefined;
|
|
713
|
-
currentVersion?: string | undefined;
|
|
714
|
-
downloads?: {
|
|
715
|
-
path: string | null;
|
|
716
|
-
name: string;
|
|
717
|
-
key: string;
|
|
718
|
-
platform: _moonbase_sh_storefront_api.Platform;
|
|
719
|
-
size: number;
|
|
720
|
-
}[] | undefined;
|
|
721
|
-
defaultVariation?: {
|
|
722
|
-
id: string;
|
|
723
|
-
name: string;
|
|
724
|
-
originalPrice: Record<string, number>;
|
|
725
|
-
price: Record<string, number>;
|
|
726
|
-
hasDiscount: boolean;
|
|
727
|
-
discount?: {
|
|
728
|
-
type: "PercentageOffDiscount";
|
|
729
|
-
name: string;
|
|
730
|
-
percentage: number;
|
|
731
|
-
isExclusive: boolean;
|
|
732
|
-
description?: string | undefined;
|
|
733
|
-
total?: Record<string, number> | undefined;
|
|
734
|
-
} | {
|
|
735
|
-
type: "FlatAmountOffDiscount";
|
|
736
|
-
name: string;
|
|
737
|
-
isExclusive: boolean;
|
|
738
|
-
description?: string | undefined;
|
|
739
|
-
total?: Record<string, number> | undefined;
|
|
740
|
-
} | undefined;
|
|
741
|
-
} | undefined;
|
|
742
|
-
variations?: {
|
|
743
|
-
id: string;
|
|
744
|
-
name: string;
|
|
745
|
-
originalPrice: Record<string, number>;
|
|
746
|
-
price: Record<string, number>;
|
|
747
|
-
hasDiscount: boolean;
|
|
748
|
-
discount?: {
|
|
749
|
-
type: "PercentageOffDiscount";
|
|
750
|
-
name: string;
|
|
751
|
-
percentage: number;
|
|
752
|
-
isExclusive: boolean;
|
|
753
|
-
description?: string | undefined;
|
|
754
|
-
total?: Record<string, number> | undefined;
|
|
755
|
-
} | {
|
|
756
|
-
type: "FlatAmountOffDiscount";
|
|
757
|
-
name: string;
|
|
758
|
-
isExclusive: boolean;
|
|
759
|
-
description?: string | undefined;
|
|
760
|
-
total?: Record<string, number> | undefined;
|
|
761
|
-
} | undefined;
|
|
762
|
-
}[] | undefined;
|
|
763
656
|
} & {
|
|
764
657
|
included?: boolean | undefined;
|
|
765
658
|
})[];
|
|
766
|
-
defaultVariation?: {
|
|
767
|
-
id: string;
|
|
768
|
-
name: string;
|
|
769
|
-
originalPrice: Record<string, number>;
|
|
770
|
-
price: Record<string, number>;
|
|
771
|
-
hasDiscount: boolean;
|
|
772
|
-
discount?: {
|
|
773
|
-
type: "PercentageOffDiscount";
|
|
774
|
-
name: string;
|
|
775
|
-
percentage: number;
|
|
776
|
-
isExclusive: boolean;
|
|
777
|
-
description?: string | undefined;
|
|
778
|
-
total?: Record<string, number> | undefined;
|
|
779
|
-
} | {
|
|
780
|
-
type: "FlatAmountOffDiscount";
|
|
781
|
-
name: string;
|
|
782
|
-
isExclusive: boolean;
|
|
783
|
-
description?: string | undefined;
|
|
784
|
-
total?: Record<string, number> | undefined;
|
|
785
|
-
} | undefined;
|
|
786
|
-
} | undefined;
|
|
787
|
-
variations?: {
|
|
788
|
-
id: string;
|
|
789
|
-
name: string;
|
|
790
|
-
originalPrice: Record<string, number>;
|
|
791
|
-
price: Record<string, number>;
|
|
792
|
-
hasDiscount: boolean;
|
|
793
|
-
discount?: {
|
|
794
|
-
type: "PercentageOffDiscount";
|
|
795
|
-
name: string;
|
|
796
|
-
percentage: number;
|
|
797
|
-
isExclusive: boolean;
|
|
798
|
-
description?: string | undefined;
|
|
799
|
-
total?: Record<string, number> | undefined;
|
|
800
|
-
} | {
|
|
801
|
-
type: "FlatAmountOffDiscount";
|
|
802
|
-
name: string;
|
|
803
|
-
isExclusive: boolean;
|
|
804
|
-
description?: string | undefined;
|
|
805
|
-
total?: Record<string, number> | undefined;
|
|
806
|
-
} | undefined;
|
|
807
|
-
}[] | undefined;
|
|
808
659
|
} | undefined;
|
|
809
660
|
variation?: {
|
|
810
661
|
id: string;
|
|
@@ -850,7 +701,10 @@ declare function useCart(context?: StorefrontContext): {
|
|
|
850
701
|
addToCart: (item: StorefrontProduct | StorefrontBundle | Ref<StorefrontProduct> | Ref<StorefrontBundle>, variation?: PricingVariation) => void;
|
|
851
702
|
setQuantity: (cartItem: CartItem, quantity: number) => void;
|
|
852
703
|
removeFromCart: (cartItem: CartItem) => void;
|
|
853
|
-
checkout: (
|
|
704
|
+
checkout: (options: {
|
|
705
|
+
redirect: boolean;
|
|
706
|
+
returnUrl: string;
|
|
707
|
+
}) => Promise<{
|
|
854
708
|
next: string | undefined;
|
|
855
709
|
} | undefined>;
|
|
856
710
|
};
|
|
@@ -873,8 +727,25 @@ declare function useAuth(context?: StorefrontContext): {
|
|
|
873
727
|
postCode: string;
|
|
874
728
|
} | undefined;
|
|
875
729
|
ownedProducts?: string[] | undefined;
|
|
730
|
+
} | null, {
|
|
731
|
+
id: string;
|
|
732
|
+
email: string;
|
|
733
|
+
name: string;
|
|
734
|
+
tenantId: string;
|
|
735
|
+
communicationPreferences: {
|
|
736
|
+
newsletterOptIn: boolean;
|
|
737
|
+
};
|
|
738
|
+
address?: {
|
|
739
|
+
countryCode: string;
|
|
740
|
+
streetAddress1: string;
|
|
741
|
+
streetAddress2: string | null;
|
|
742
|
+
locality: string | null;
|
|
743
|
+
region: string | null;
|
|
744
|
+
postCode: string;
|
|
745
|
+
} | undefined;
|
|
746
|
+
ownedProducts?: string[] | undefined;
|
|
876
747
|
} | null>;
|
|
877
|
-
loaded: vue.Ref<boolean>;
|
|
748
|
+
loaded: vue.Ref<boolean, boolean>;
|
|
878
749
|
loadedPromise: Promise<void>;
|
|
879
750
|
signIn: (email: string, password: string) => Promise<{
|
|
880
751
|
id: string;
|
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, MoonbaseClient, StorefrontBundle, StorefrontProduct, ActivationMethod, Activation, Download, ActivationRequest, PricingVariation, CommunicationPreferences, LineItem } from '@moonbase.sh/storefront-api';
|
|
2
|
+
import { MoonbaseConfiguration, Storefront, Order, User, MoonbaseClient, CompletedOrder, StorefrontBundle, StorefrontProduct, ActivationMethod, Activation, Download, ActivationRequest, PricingVariation, CommunicationPreferences, 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';
|
|
@@ -20,7 +20,8 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
|
20
20
|
updateStorefront: () => Promise<void>;
|
|
21
21
|
pushOrderContent: () => Promise<void>;
|
|
22
22
|
resetOrder: () => void;
|
|
23
|
-
|
|
23
|
+
closeCheckout: () => void;
|
|
24
|
+
onCheckoutCompleted: (callback: (order: CompletedOrder) => void) => void;
|
|
24
25
|
onCheckoutClosed: (callback: (intent: string | undefined) => void) => void;
|
|
25
26
|
/**
|
|
26
27
|
* Called automatically by `app.use(storefront)`. Should not be called manually by
|
|
@@ -594,63 +595,10 @@ declare function useCart(context?: StorefrontContext): {
|
|
|
594
595
|
variationId: string;
|
|
595
596
|
price?: Record<string, number> | undefined;
|
|
596
597
|
product?: {
|
|
597
|
-
type: "product";
|
|
598
598
|
id: string;
|
|
599
599
|
name: string;
|
|
600
600
|
tagline: string;
|
|
601
601
|
iconUrl: string | null;
|
|
602
|
-
owned: boolean;
|
|
603
|
-
website?: string | null | undefined;
|
|
604
|
-
currentVersion?: string | undefined;
|
|
605
|
-
downloads?: {
|
|
606
|
-
path: string | null;
|
|
607
|
-
name: string;
|
|
608
|
-
key: string;
|
|
609
|
-
platform: _moonbase_sh_storefront_api.Platform;
|
|
610
|
-
size: number;
|
|
611
|
-
}[] | undefined;
|
|
612
|
-
defaultVariation?: {
|
|
613
|
-
id: string;
|
|
614
|
-
name: string;
|
|
615
|
-
originalPrice: Record<string, number>;
|
|
616
|
-
price: Record<string, number>;
|
|
617
|
-
hasDiscount: boolean;
|
|
618
|
-
discount?: {
|
|
619
|
-
type: "PercentageOffDiscount";
|
|
620
|
-
name: string;
|
|
621
|
-
percentage: number;
|
|
622
|
-
isExclusive: boolean;
|
|
623
|
-
description?: string | undefined;
|
|
624
|
-
total?: Record<string, number> | undefined;
|
|
625
|
-
} | {
|
|
626
|
-
type: "FlatAmountOffDiscount";
|
|
627
|
-
name: string;
|
|
628
|
-
isExclusive: boolean;
|
|
629
|
-
description?: string | undefined;
|
|
630
|
-
total?: Record<string, number> | undefined;
|
|
631
|
-
} | undefined;
|
|
632
|
-
} | undefined;
|
|
633
|
-
variations?: {
|
|
634
|
-
id: string;
|
|
635
|
-
name: string;
|
|
636
|
-
originalPrice: Record<string, number>;
|
|
637
|
-
price: Record<string, number>;
|
|
638
|
-
hasDiscount: boolean;
|
|
639
|
-
discount?: {
|
|
640
|
-
type: "PercentageOffDiscount";
|
|
641
|
-
name: string;
|
|
642
|
-
percentage: number;
|
|
643
|
-
isExclusive: boolean;
|
|
644
|
-
description?: string | undefined;
|
|
645
|
-
total?: Record<string, number> | undefined;
|
|
646
|
-
} | {
|
|
647
|
-
type: "FlatAmountOffDiscount";
|
|
648
|
-
name: string;
|
|
649
|
-
isExclusive: boolean;
|
|
650
|
-
description?: string | undefined;
|
|
651
|
-
total?: Record<string, number> | undefined;
|
|
652
|
-
} | undefined;
|
|
653
|
-
}[] | undefined;
|
|
654
602
|
} | undefined;
|
|
655
603
|
variation?: {
|
|
656
604
|
id: string;
|
|
@@ -695,116 +643,19 @@ declare function useCart(context?: StorefrontContext): {
|
|
|
695
643
|
bundleId: string;
|
|
696
644
|
price?: Record<string, number> | undefined;
|
|
697
645
|
bundle?: {
|
|
698
|
-
type: "bundle";
|
|
699
646
|
id: string;
|
|
700
647
|
name: string;
|
|
701
648
|
tagline: string;
|
|
702
649
|
iconUrl: string | null;
|
|
703
|
-
owned: boolean;
|
|
704
650
|
partial: boolean;
|
|
705
651
|
products: ({
|
|
706
|
-
type: "product";
|
|
707
652
|
id: string;
|
|
708
653
|
name: string;
|
|
709
654
|
tagline: string;
|
|
710
655
|
iconUrl: string | null;
|
|
711
|
-
owned: boolean;
|
|
712
|
-
website?: string | null | undefined;
|
|
713
|
-
currentVersion?: string | undefined;
|
|
714
|
-
downloads?: {
|
|
715
|
-
path: string | null;
|
|
716
|
-
name: string;
|
|
717
|
-
key: string;
|
|
718
|
-
platform: _moonbase_sh_storefront_api.Platform;
|
|
719
|
-
size: number;
|
|
720
|
-
}[] | undefined;
|
|
721
|
-
defaultVariation?: {
|
|
722
|
-
id: string;
|
|
723
|
-
name: string;
|
|
724
|
-
originalPrice: Record<string, number>;
|
|
725
|
-
price: Record<string, number>;
|
|
726
|
-
hasDiscount: boolean;
|
|
727
|
-
discount?: {
|
|
728
|
-
type: "PercentageOffDiscount";
|
|
729
|
-
name: string;
|
|
730
|
-
percentage: number;
|
|
731
|
-
isExclusive: boolean;
|
|
732
|
-
description?: string | undefined;
|
|
733
|
-
total?: Record<string, number> | undefined;
|
|
734
|
-
} | {
|
|
735
|
-
type: "FlatAmountOffDiscount";
|
|
736
|
-
name: string;
|
|
737
|
-
isExclusive: boolean;
|
|
738
|
-
description?: string | undefined;
|
|
739
|
-
total?: Record<string, number> | undefined;
|
|
740
|
-
} | undefined;
|
|
741
|
-
} | undefined;
|
|
742
|
-
variations?: {
|
|
743
|
-
id: string;
|
|
744
|
-
name: string;
|
|
745
|
-
originalPrice: Record<string, number>;
|
|
746
|
-
price: Record<string, number>;
|
|
747
|
-
hasDiscount: boolean;
|
|
748
|
-
discount?: {
|
|
749
|
-
type: "PercentageOffDiscount";
|
|
750
|
-
name: string;
|
|
751
|
-
percentage: number;
|
|
752
|
-
isExclusive: boolean;
|
|
753
|
-
description?: string | undefined;
|
|
754
|
-
total?: Record<string, number> | undefined;
|
|
755
|
-
} | {
|
|
756
|
-
type: "FlatAmountOffDiscount";
|
|
757
|
-
name: string;
|
|
758
|
-
isExclusive: boolean;
|
|
759
|
-
description?: string | undefined;
|
|
760
|
-
total?: Record<string, number> | undefined;
|
|
761
|
-
} | undefined;
|
|
762
|
-
}[] | undefined;
|
|
763
656
|
} & {
|
|
764
657
|
included?: boolean | undefined;
|
|
765
658
|
})[];
|
|
766
|
-
defaultVariation?: {
|
|
767
|
-
id: string;
|
|
768
|
-
name: string;
|
|
769
|
-
originalPrice: Record<string, number>;
|
|
770
|
-
price: Record<string, number>;
|
|
771
|
-
hasDiscount: boolean;
|
|
772
|
-
discount?: {
|
|
773
|
-
type: "PercentageOffDiscount";
|
|
774
|
-
name: string;
|
|
775
|
-
percentage: number;
|
|
776
|
-
isExclusive: boolean;
|
|
777
|
-
description?: string | undefined;
|
|
778
|
-
total?: Record<string, number> | undefined;
|
|
779
|
-
} | {
|
|
780
|
-
type: "FlatAmountOffDiscount";
|
|
781
|
-
name: string;
|
|
782
|
-
isExclusive: boolean;
|
|
783
|
-
description?: string | undefined;
|
|
784
|
-
total?: Record<string, number> | undefined;
|
|
785
|
-
} | undefined;
|
|
786
|
-
} | undefined;
|
|
787
|
-
variations?: {
|
|
788
|
-
id: string;
|
|
789
|
-
name: string;
|
|
790
|
-
originalPrice: Record<string, number>;
|
|
791
|
-
price: Record<string, number>;
|
|
792
|
-
hasDiscount: boolean;
|
|
793
|
-
discount?: {
|
|
794
|
-
type: "PercentageOffDiscount";
|
|
795
|
-
name: string;
|
|
796
|
-
percentage: number;
|
|
797
|
-
isExclusive: boolean;
|
|
798
|
-
description?: string | undefined;
|
|
799
|
-
total?: Record<string, number> | undefined;
|
|
800
|
-
} | {
|
|
801
|
-
type: "FlatAmountOffDiscount";
|
|
802
|
-
name: string;
|
|
803
|
-
isExclusive: boolean;
|
|
804
|
-
description?: string | undefined;
|
|
805
|
-
total?: Record<string, number> | undefined;
|
|
806
|
-
} | undefined;
|
|
807
|
-
}[] | undefined;
|
|
808
659
|
} | undefined;
|
|
809
660
|
variation?: {
|
|
810
661
|
id: string;
|
|
@@ -850,7 +701,10 @@ declare function useCart(context?: StorefrontContext): {
|
|
|
850
701
|
addToCart: (item: StorefrontProduct | StorefrontBundle | Ref<StorefrontProduct> | Ref<StorefrontBundle>, variation?: PricingVariation) => void;
|
|
851
702
|
setQuantity: (cartItem: CartItem, quantity: number) => void;
|
|
852
703
|
removeFromCart: (cartItem: CartItem) => void;
|
|
853
|
-
checkout: (
|
|
704
|
+
checkout: (options: {
|
|
705
|
+
redirect: boolean;
|
|
706
|
+
returnUrl: string;
|
|
707
|
+
}) => Promise<{
|
|
854
708
|
next: string | undefined;
|
|
855
709
|
} | undefined>;
|
|
856
710
|
};
|
|
@@ -873,8 +727,25 @@ declare function useAuth(context?: StorefrontContext): {
|
|
|
873
727
|
postCode: string;
|
|
874
728
|
} | undefined;
|
|
875
729
|
ownedProducts?: string[] | undefined;
|
|
730
|
+
} | null, {
|
|
731
|
+
id: string;
|
|
732
|
+
email: string;
|
|
733
|
+
name: string;
|
|
734
|
+
tenantId: string;
|
|
735
|
+
communicationPreferences: {
|
|
736
|
+
newsletterOptIn: boolean;
|
|
737
|
+
};
|
|
738
|
+
address?: {
|
|
739
|
+
countryCode: string;
|
|
740
|
+
streetAddress1: string;
|
|
741
|
+
streetAddress2: string | null;
|
|
742
|
+
locality: string | null;
|
|
743
|
+
region: string | null;
|
|
744
|
+
postCode: string;
|
|
745
|
+
} | undefined;
|
|
746
|
+
ownedProducts?: string[] | undefined;
|
|
876
747
|
} | null>;
|
|
877
|
-
loaded: vue.Ref<boolean>;
|
|
748
|
+
loaded: vue.Ref<boolean, boolean>;
|
|
878
749
|
loadedPromise: Promise<void>;
|
|
879
750
|
signIn: (email: string, password: string) => Promise<{
|
|
880
751
|
id: string;
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ function debounce(func, waitMs = 100) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// src/utils/iframe-checkout.ts
|
|
26
|
+
import { schemas } from "@moonbase.sh/storefront-api";
|
|
26
27
|
import { z } from "zod";
|
|
27
28
|
var closeEventSchema = z.object({
|
|
28
29
|
source: z.literal("moonbase-checkout"),
|
|
@@ -31,9 +32,17 @@ var closeEventSchema = z.object({
|
|
|
31
32
|
});
|
|
32
33
|
var completedEventSchema = z.object({
|
|
33
34
|
source: z.literal("moonbase-checkout"),
|
|
34
|
-
event: z.literal("completed")
|
|
35
|
+
event: z.literal("completed"),
|
|
36
|
+
order: schemas.orders.completedOrderSchema
|
|
35
37
|
});
|
|
36
38
|
var eventSchema = z.discriminatedUnion("event", [closeEventSchema, completedEventSchema]);
|
|
39
|
+
function closeCheckout() {
|
|
40
|
+
var _a;
|
|
41
|
+
const iframe = document.getElementById("moonbase-checkout");
|
|
42
|
+
if (!iframe || !(iframe instanceof HTMLIFrameElement))
|
|
43
|
+
return;
|
|
44
|
+
(_a = iframe.contentWindow) == null ? void 0 : _a.postMessage("close", "*");
|
|
45
|
+
}
|
|
37
46
|
function mountCheckout(endpoint) {
|
|
38
47
|
if (typeof window === "undefined") {
|
|
39
48
|
console.warn("Can not mount checkout server side");
|
|
@@ -184,8 +193,11 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
184
193
|
}, { immediate: true });
|
|
185
194
|
});
|
|
186
195
|
}
|
|
196
|
+
closeCheckout() {
|
|
197
|
+
closeCheckout();
|
|
198
|
+
}
|
|
187
199
|
onCheckoutCompleted(callback) {
|
|
188
|
-
window.addEventListener("moonbase-checkout-completed", () => callback());
|
|
200
|
+
window.addEventListener("moonbase-checkout-completed", (e) => callback(e.detail.order));
|
|
189
201
|
}
|
|
190
202
|
onCheckoutClosed(callback) {
|
|
191
203
|
window.addEventListener("moonbase-checkout-closed", (e) => callback(e.detail.intent));
|
|
@@ -577,12 +589,12 @@ function useCart(context) {
|
|
|
577
589
|
storefront.currentOrder.value.items.splice(index, 1);
|
|
578
590
|
const _ = storefront.pushOrderContent();
|
|
579
591
|
},
|
|
580
|
-
checkout: async (
|
|
581
|
-
const absoluteReturnUrl = new URL(returnUrl, document.baseURI).href;
|
|
592
|
+
checkout: async (options) => {
|
|
593
|
+
const absoluteReturnUrl = new URL(options.returnUrl, document.baseURI).href;
|
|
582
594
|
const updatedOrder = await storefront.client.orders.pushContent(storefront.currentOrder.value, {
|
|
583
595
|
returnUrl: absoluteReturnUrl
|
|
584
596
|
});
|
|
585
|
-
if (updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
597
|
+
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
586
598
|
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
|
587
599
|
return new Promise((resolve) => {
|
|
588
600
|
mountCheckout(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
|
|
@@ -590,7 +602,7 @@ function useCart(context) {
|
|
|
590
602
|
resolve({ next: e.detail.next });
|
|
591
603
|
});
|
|
592
604
|
});
|
|
593
|
-
} else if (updatedOrder.checkoutUrl && typeof window !== "undefined") {
|
|
605
|
+
} else if (options.redirect && updatedOrder.checkoutUrl && typeof window !== "undefined") {
|
|
594
606
|
window.location.href = updatedOrder.checkoutUrl;
|
|
595
607
|
return { next: void 0 };
|
|
596
608
|
} else {
|
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.31",
|
|
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",
|
|
@@ -16,17 +16,17 @@
|
|
|
16
16
|
"vue": "^3.2.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@vue/devtools-api": "^6.
|
|
19
|
+
"@vue/devtools-api": "^6.6.3",
|
|
20
20
|
"uuid": "^9.0.1",
|
|
21
|
-
"zod": "^3.
|
|
22
|
-
"@moonbase.sh/storefront-api": "0.2.
|
|
21
|
+
"zod": "^3.23.8",
|
|
22
|
+
"@moonbase.sh/storefront-api": "0.2.31"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/uuid": "^9.0.
|
|
26
|
-
"rimraf": "^5.0.
|
|
25
|
+
"@types/uuid": "^9.0.8",
|
|
26
|
+
"rimraf": "^5.0.10",
|
|
27
27
|
"tsup": "^7.2.0",
|
|
28
28
|
"typescript": "~5.1.6",
|
|
29
|
-
"vue": "^3.3
|
|
29
|
+
"vue": "^3.5.3"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|