@moonbase.sh/vue 0.4.26 → 0.4.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 +101 -2
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +102 -3
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -136,6 +136,65 @@ function mountCheckout(endpoint) {
|
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
// src/utils/iframe-subscription.ts
|
|
140
|
+
var import_zod2 = require("zod");
|
|
141
|
+
var closeEventSchema2 = import_zod2.z.object({
|
|
142
|
+
source: import_zod2.z.literal("moonbase-subscription"),
|
|
143
|
+
event: import_zod2.z.literal("close"),
|
|
144
|
+
completed: import_zod2.z.boolean()
|
|
145
|
+
});
|
|
146
|
+
var updatedPaymentMethodSchema = import_zod2.z.object({
|
|
147
|
+
source: import_zod2.z.literal("moonbase-subscription"),
|
|
148
|
+
event: import_zod2.z.literal("updated-payment-method")
|
|
149
|
+
});
|
|
150
|
+
var eventSchema2 = import_zod2.z.discriminatedUnion("event", [closeEventSchema2, updatedPaymentMethodSchema]);
|
|
151
|
+
function mountSubscription(endpoint) {
|
|
152
|
+
if (typeof window === "undefined") {
|
|
153
|
+
console.warn("Can not mount subscription server side");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (document.getElementById("moonbase-subscription"))
|
|
157
|
+
return;
|
|
158
|
+
const iframe = document.createElement("iframe");
|
|
159
|
+
iframe.id = "moonbase-subscription";
|
|
160
|
+
iframe.src = endpoint;
|
|
161
|
+
iframe.style.position = "fixed";
|
|
162
|
+
iframe.style.top = "0px";
|
|
163
|
+
iframe.style.left = "0px";
|
|
164
|
+
iframe.style.right = "0px";
|
|
165
|
+
iframe.style.border = "none";
|
|
166
|
+
iframe.style.colorScheme = "normal";
|
|
167
|
+
iframe.style.backgroundColor = "transparent";
|
|
168
|
+
iframe.style.zIndex = Number.MAX_SAFE_INTEGER.toString();
|
|
169
|
+
iframe.setAttribute("background", "transparent");
|
|
170
|
+
iframe.setAttribute("frameborder", "0");
|
|
171
|
+
iframe.setAttribute("allowtransparency", "true");
|
|
172
|
+
iframe.setAttribute("allow", "payment");
|
|
173
|
+
iframe.height = "100%";
|
|
174
|
+
iframe.width = "100%";
|
|
175
|
+
document.body.append(iframe);
|
|
176
|
+
document.documentElement.style.overflow = "hidden";
|
|
177
|
+
window.onmessage = function(e) {
|
|
178
|
+
var _a;
|
|
179
|
+
try {
|
|
180
|
+
const evnt = eventSchema2.parse(e.data);
|
|
181
|
+
if (evnt.event === "close") {
|
|
182
|
+
if (document.body.contains(iframe)) {
|
|
183
|
+
document.documentElement.style.removeProperty("overflow");
|
|
184
|
+
document.body.removeChild(iframe);
|
|
185
|
+
}
|
|
186
|
+
window.dispatchEvent(new CustomEvent("moonbase-subscription-closed", {
|
|
187
|
+
detail: evnt
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
} catch (err) {
|
|
191
|
+
if (((_a = e.data) == null ? void 0 : _a.source) === "moonbase-subscription") {
|
|
192
|
+
console.error("Could not parse event:", e.data, err);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
139
198
|
// src/context.ts
|
|
140
199
|
var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
141
200
|
constructor(configuration, client, stateFactory) {
|
|
@@ -157,6 +216,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
157
216
|
});
|
|
158
217
|
this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, {
|
|
159
218
|
suggestedCurrency: "",
|
|
219
|
+
enabledCurrencies: [],
|
|
160
220
|
bundles: [],
|
|
161
221
|
products: [],
|
|
162
222
|
offers: []
|
|
@@ -211,6 +271,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
211
271
|
} else {
|
|
212
272
|
this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, {
|
|
213
273
|
suggestedCurrency: "",
|
|
274
|
+
enabledCurrencies: [],
|
|
214
275
|
bundles: [],
|
|
215
276
|
products: [],
|
|
216
277
|
offers: []
|
|
@@ -235,6 +296,15 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
235
296
|
mountCheckout(finalEndpoint.toString());
|
|
236
297
|
window.history.replaceState(null, "", window.location.href.split("?")[0]);
|
|
237
298
|
}
|
|
299
|
+
if (intent === "update_subscription" && urlParams2.get("mb_complete") && endpoint) {
|
|
300
|
+
const parameters = Object.fromEntries([...urlParams2.entries()].filter(([key]) => !key.startsWith("mb_")));
|
|
301
|
+
const finalEndpoint = new URL(decodeURIComponent(endpoint));
|
|
302
|
+
for (const prop of Object.keys(parameters)) {
|
|
303
|
+
finalEndpoint.searchParams.append(prop, parameters[prop]);
|
|
304
|
+
}
|
|
305
|
+
mountSubscription(finalEndpoint.toString());
|
|
306
|
+
window.history.replaceState(null, "", window.location.href.split("?")[0]);
|
|
307
|
+
}
|
|
238
308
|
}
|
|
239
309
|
window.addEventListener("moonbase-checkout-completed", (e) => {
|
|
240
310
|
const order = e.detail.order;
|
|
@@ -295,13 +365,14 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
295
365
|
return this.currentUser.value;
|
|
296
366
|
}
|
|
297
367
|
async updateStorefront() {
|
|
368
|
+
var _a;
|
|
298
369
|
const latestStorefront = await this.client.storefront.get(this.hasUtm ? this.utm.value : void 0);
|
|
299
370
|
if (latestStorefront) {
|
|
300
371
|
if (typeof window !== "undefined")
|
|
301
372
|
localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
|
|
302
373
|
this.storefront.value = latestStorefront;
|
|
303
374
|
this.loadedStorefront.value = true;
|
|
304
|
-
if (!this.currentOrder.value.currency) {
|
|
375
|
+
if (!this.currentOrder.value.currency || !((_a = latestStorefront.enabledCurrencies) == null ? void 0 : _a.includes(this.currentOrder.value.currency))) {
|
|
305
376
|
this.currentOrder.value.currency = latestStorefront.suggestedCurrency;
|
|
306
377
|
}
|
|
307
378
|
this.currentOrder.value.items = this.enrichLineItems(this.currentOrder.value.items);
|
|
@@ -343,6 +414,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
343
414
|
}
|
|
344
415
|
}
|
|
345
416
|
async refreshOrder() {
|
|
417
|
+
var _a;
|
|
346
418
|
try {
|
|
347
419
|
const latestOrder = await this.client.orders.get(this.currentOrder.value.id, { abort: this.refreshOrderAbortController.signal });
|
|
348
420
|
if (latestOrder) {
|
|
@@ -352,6 +424,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
352
424
|
latestOrder.items = this.enrichLineItems(latestOrder.items);
|
|
353
425
|
if (typeof window !== "undefined")
|
|
354
426
|
localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
|
|
427
|
+
if (this.storefront.value && !((_a = this.storefront.value.enabledCurrencies) == null ? void 0 : _a.includes(latestOrder.currency))) {
|
|
428
|
+
latestOrder.currency = this.storefront.value.suggestedCurrency;
|
|
429
|
+
}
|
|
355
430
|
this.currentOrder.value = latestOrder;
|
|
356
431
|
}
|
|
357
432
|
}
|
|
@@ -638,7 +713,7 @@ function useCart(context) {
|
|
|
638
713
|
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
639
714
|
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;
|
|
640
715
|
}
|
|
641
|
-
const offer = (_j = storefront.storefront.value.offers) == null ? void 0 : _j.find((o) => o.id === item.offerId);
|
|
716
|
+
const offer = item.offerId ? (_j = storefront.storefront.value.offers) == null ? void 0 : _j.find((o) => o.id === item.offerId) : null;
|
|
642
717
|
if (offer && import_storefront_api4.OfferUtils.eligible(offer, storefront.currentOrder.value)) {
|
|
643
718
|
const offerDiscount = import_storefront_api4.DiscountUtils.apply(offer.discount, { [currency]: price });
|
|
644
719
|
price -= offerDiscount[currency];
|
|
@@ -933,6 +1008,30 @@ function useInventory(context) {
|
|
|
933
1008
|
}, { once: true });
|
|
934
1009
|
});
|
|
935
1010
|
}
|
|
1011
|
+
},
|
|
1012
|
+
updateSubscriptionPaymentMethod: async (subscription, options) => {
|
|
1013
|
+
var _a;
|
|
1014
|
+
const fallbackPath = typeof window !== "undefined" ? window.location.pathname : "";
|
|
1015
|
+
const absoluteReturnUrl = new URL((_a = options.returnUrl) != null ? _a : fallbackPath, document.baseURI).href;
|
|
1016
|
+
const response = await storefront.client.inventory.subscriptions.getById(subscription.id, {
|
|
1017
|
+
toUpdatePaymentMethod: true,
|
|
1018
|
+
returnUrl: absoluteReturnUrl
|
|
1019
|
+
});
|
|
1020
|
+
window.dispatchEvent(new CustomEvent("moonbase-subscription-payment-method-update-initiated", {
|
|
1021
|
+
detail: { subscription: (0, import_vue8.toRaw)(subscription) }
|
|
1022
|
+
}));
|
|
1023
|
+
if (response.embeddedUpdatePaymentUrl && typeof window !== "undefined") {
|
|
1024
|
+
const embeddedUrl = response.embeddedUpdatePaymentUrl;
|
|
1025
|
+
return new Promise((resolve) => {
|
|
1026
|
+
mountSubscription(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
|
|
1027
|
+
window.addEventListener("moonbase-subscription-closed", (e) => {
|
|
1028
|
+
const evnt = e;
|
|
1029
|
+
resolve({ completed: evnt.detail.completed });
|
|
1030
|
+
}, { once: true });
|
|
1031
|
+
});
|
|
1032
|
+
} else {
|
|
1033
|
+
throw new Error("No update URL found");
|
|
1034
|
+
}
|
|
936
1035
|
}
|
|
937
1036
|
};
|
|
938
1037
|
}
|
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, LineItem, OpenOrder, Money, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, StorefrontOffer, ActivationMethod, Activation, Download, Vendor } from '@moonbase.sh/storefront-api';
|
|
2
|
+
import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, LineItem, OpenOrder, Money, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, StorefrontOffer, ActivationMethod, Activation, Download, Subscription, Vendor } from '@moonbase.sh/storefront-api';
|
|
3
3
|
export * from '@moonbase.sh/storefront-api';
|
|
4
4
|
import * as vue from 'vue';
|
|
5
5
|
import { Ref, UnwrapRef, Plugin, App, MaybeRef, InjectionKey } from 'vue';
|
|
@@ -901,6 +901,8 @@ declare function useInventory(context?: StorefrontContext): {
|
|
|
901
901
|
}[] | undefined;
|
|
902
902
|
};
|
|
903
903
|
};
|
|
904
|
+
paymentMethod?: string | undefined;
|
|
905
|
+
embeddedUpdatePaymentUrl?: string | undefined;
|
|
904
906
|
}>>;
|
|
905
907
|
getSubscription: (subscriptionId: string) => Promise<{
|
|
906
908
|
id: string;
|
|
@@ -1207,6 +1209,8 @@ declare function useInventory(context?: StorefrontContext): {
|
|
|
1207
1209
|
}[] | undefined;
|
|
1208
1210
|
};
|
|
1209
1211
|
};
|
|
1212
|
+
paymentMethod?: string | undefined;
|
|
1213
|
+
embeddedUpdatePaymentUrl?: string | undefined;
|
|
1210
1214
|
}>;
|
|
1211
1215
|
cancelSubscription: (subscriptionId: string) => Promise<{
|
|
1212
1216
|
id: string;
|
|
@@ -1513,6 +1517,8 @@ declare function useInventory(context?: StorefrontContext): {
|
|
|
1513
1517
|
}[] | undefined;
|
|
1514
1518
|
};
|
|
1515
1519
|
};
|
|
1520
|
+
paymentMethod?: string | undefined;
|
|
1521
|
+
embeddedUpdatePaymentUrl?: string | undefined;
|
|
1516
1522
|
}>;
|
|
1517
1523
|
renewSubscription: (subscriptionId: string, options: {
|
|
1518
1524
|
redirect: boolean;
|
|
@@ -1521,6 +1527,11 @@ declare function useInventory(context?: StorefrontContext): {
|
|
|
1521
1527
|
next: string | undefined;
|
|
1522
1528
|
completed: boolean;
|
|
1523
1529
|
}>;
|
|
1530
|
+
updateSubscriptionPaymentMethod: (subscription: Subscription, options: {
|
|
1531
|
+
returnUrl?: string;
|
|
1532
|
+
}) => Promise<{
|
|
1533
|
+
completed: boolean;
|
|
1534
|
+
} | undefined>;
|
|
1524
1535
|
};
|
|
1525
1536
|
|
|
1526
1537
|
declare function useOffer(offerId: string, context?: StorefrontContext): Ref<StorefrontOffer | null>;
|
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, LineItem, OpenOrder, Money, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, StorefrontOffer, ActivationMethod, Activation, Download, Vendor } from '@moonbase.sh/storefront-api';
|
|
2
|
+
import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, LineItem, OpenOrder, Money, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, StorefrontOffer, ActivationMethod, Activation, Download, Subscription, Vendor } from '@moonbase.sh/storefront-api';
|
|
3
3
|
export * from '@moonbase.sh/storefront-api';
|
|
4
4
|
import * as vue from 'vue';
|
|
5
5
|
import { Ref, UnwrapRef, Plugin, App, MaybeRef, InjectionKey } from 'vue';
|
|
@@ -901,6 +901,8 @@ declare function useInventory(context?: StorefrontContext): {
|
|
|
901
901
|
}[] | undefined;
|
|
902
902
|
};
|
|
903
903
|
};
|
|
904
|
+
paymentMethod?: string | undefined;
|
|
905
|
+
embeddedUpdatePaymentUrl?: string | undefined;
|
|
904
906
|
}>>;
|
|
905
907
|
getSubscription: (subscriptionId: string) => Promise<{
|
|
906
908
|
id: string;
|
|
@@ -1207,6 +1209,8 @@ declare function useInventory(context?: StorefrontContext): {
|
|
|
1207
1209
|
}[] | undefined;
|
|
1208
1210
|
};
|
|
1209
1211
|
};
|
|
1212
|
+
paymentMethod?: string | undefined;
|
|
1213
|
+
embeddedUpdatePaymentUrl?: string | undefined;
|
|
1210
1214
|
}>;
|
|
1211
1215
|
cancelSubscription: (subscriptionId: string) => Promise<{
|
|
1212
1216
|
id: string;
|
|
@@ -1513,6 +1517,8 @@ declare function useInventory(context?: StorefrontContext): {
|
|
|
1513
1517
|
}[] | undefined;
|
|
1514
1518
|
};
|
|
1515
1519
|
};
|
|
1520
|
+
paymentMethod?: string | undefined;
|
|
1521
|
+
embeddedUpdatePaymentUrl?: string | undefined;
|
|
1516
1522
|
}>;
|
|
1517
1523
|
renewSubscription: (subscriptionId: string, options: {
|
|
1518
1524
|
redirect: boolean;
|
|
@@ -1521,6 +1527,11 @@ declare function useInventory(context?: StorefrontContext): {
|
|
|
1521
1527
|
next: string | undefined;
|
|
1522
1528
|
completed: boolean;
|
|
1523
1529
|
}>;
|
|
1530
|
+
updateSubscriptionPaymentMethod: (subscription: Subscription, options: {
|
|
1531
|
+
returnUrl?: string;
|
|
1532
|
+
}) => Promise<{
|
|
1533
|
+
completed: boolean;
|
|
1534
|
+
} | undefined>;
|
|
1524
1535
|
};
|
|
1525
1536
|
|
|
1526
1537
|
declare function useOffer(offerId: string, context?: StorefrontContext): Ref<StorefrontOffer | null>;
|
package/dist/index.js
CHANGED
|
@@ -104,6 +104,65 @@ function mountCheckout(endpoint) {
|
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
// src/utils/iframe-subscription.ts
|
|
108
|
+
import { z as z2 } from "zod";
|
|
109
|
+
var closeEventSchema2 = z2.object({
|
|
110
|
+
source: z2.literal("moonbase-subscription"),
|
|
111
|
+
event: z2.literal("close"),
|
|
112
|
+
completed: z2.boolean()
|
|
113
|
+
});
|
|
114
|
+
var updatedPaymentMethodSchema = z2.object({
|
|
115
|
+
source: z2.literal("moonbase-subscription"),
|
|
116
|
+
event: z2.literal("updated-payment-method")
|
|
117
|
+
});
|
|
118
|
+
var eventSchema2 = z2.discriminatedUnion("event", [closeEventSchema2, updatedPaymentMethodSchema]);
|
|
119
|
+
function mountSubscription(endpoint) {
|
|
120
|
+
if (typeof window === "undefined") {
|
|
121
|
+
console.warn("Can not mount subscription server side");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (document.getElementById("moonbase-subscription"))
|
|
125
|
+
return;
|
|
126
|
+
const iframe = document.createElement("iframe");
|
|
127
|
+
iframe.id = "moonbase-subscription";
|
|
128
|
+
iframe.src = endpoint;
|
|
129
|
+
iframe.style.position = "fixed";
|
|
130
|
+
iframe.style.top = "0px";
|
|
131
|
+
iframe.style.left = "0px";
|
|
132
|
+
iframe.style.right = "0px";
|
|
133
|
+
iframe.style.border = "none";
|
|
134
|
+
iframe.style.colorScheme = "normal";
|
|
135
|
+
iframe.style.backgroundColor = "transparent";
|
|
136
|
+
iframe.style.zIndex = Number.MAX_SAFE_INTEGER.toString();
|
|
137
|
+
iframe.setAttribute("background", "transparent");
|
|
138
|
+
iframe.setAttribute("frameborder", "0");
|
|
139
|
+
iframe.setAttribute("allowtransparency", "true");
|
|
140
|
+
iframe.setAttribute("allow", "payment");
|
|
141
|
+
iframe.height = "100%";
|
|
142
|
+
iframe.width = "100%";
|
|
143
|
+
document.body.append(iframe);
|
|
144
|
+
document.documentElement.style.overflow = "hidden";
|
|
145
|
+
window.onmessage = function(e) {
|
|
146
|
+
var _a;
|
|
147
|
+
try {
|
|
148
|
+
const evnt = eventSchema2.parse(e.data);
|
|
149
|
+
if (evnt.event === "close") {
|
|
150
|
+
if (document.body.contains(iframe)) {
|
|
151
|
+
document.documentElement.style.removeProperty("overflow");
|
|
152
|
+
document.body.removeChild(iframe);
|
|
153
|
+
}
|
|
154
|
+
window.dispatchEvent(new CustomEvent("moonbase-subscription-closed", {
|
|
155
|
+
detail: evnt
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
} catch (err) {
|
|
159
|
+
if (((_a = e.data) == null ? void 0 : _a.source) === "moonbase-subscription") {
|
|
160
|
+
console.error("Could not parse event:", e.data, err);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
107
166
|
// src/context.ts
|
|
108
167
|
var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
109
168
|
constructor(configuration, client, stateFactory) {
|
|
@@ -125,6 +184,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
125
184
|
});
|
|
126
185
|
this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, {
|
|
127
186
|
suggestedCurrency: "",
|
|
187
|
+
enabledCurrencies: [],
|
|
128
188
|
bundles: [],
|
|
129
189
|
products: [],
|
|
130
190
|
offers: []
|
|
@@ -179,6 +239,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
179
239
|
} else {
|
|
180
240
|
this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, {
|
|
181
241
|
suggestedCurrency: "",
|
|
242
|
+
enabledCurrencies: [],
|
|
182
243
|
bundles: [],
|
|
183
244
|
products: [],
|
|
184
245
|
offers: []
|
|
@@ -203,6 +264,15 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
203
264
|
mountCheckout(finalEndpoint.toString());
|
|
204
265
|
window.history.replaceState(null, "", window.location.href.split("?")[0]);
|
|
205
266
|
}
|
|
267
|
+
if (intent === "update_subscription" && urlParams2.get("mb_complete") && endpoint) {
|
|
268
|
+
const parameters = Object.fromEntries([...urlParams2.entries()].filter(([key]) => !key.startsWith("mb_")));
|
|
269
|
+
const finalEndpoint = new URL(decodeURIComponent(endpoint));
|
|
270
|
+
for (const prop of Object.keys(parameters)) {
|
|
271
|
+
finalEndpoint.searchParams.append(prop, parameters[prop]);
|
|
272
|
+
}
|
|
273
|
+
mountSubscription(finalEndpoint.toString());
|
|
274
|
+
window.history.replaceState(null, "", window.location.href.split("?")[0]);
|
|
275
|
+
}
|
|
206
276
|
}
|
|
207
277
|
window.addEventListener("moonbase-checkout-completed", (e) => {
|
|
208
278
|
const order = e.detail.order;
|
|
@@ -263,13 +333,14 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
263
333
|
return this.currentUser.value;
|
|
264
334
|
}
|
|
265
335
|
async updateStorefront() {
|
|
336
|
+
var _a;
|
|
266
337
|
const latestStorefront = await this.client.storefront.get(this.hasUtm ? this.utm.value : void 0);
|
|
267
338
|
if (latestStorefront) {
|
|
268
339
|
if (typeof window !== "undefined")
|
|
269
340
|
localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
|
|
270
341
|
this.storefront.value = latestStorefront;
|
|
271
342
|
this.loadedStorefront.value = true;
|
|
272
|
-
if (!this.currentOrder.value.currency) {
|
|
343
|
+
if (!this.currentOrder.value.currency || !((_a = latestStorefront.enabledCurrencies) == null ? void 0 : _a.includes(this.currentOrder.value.currency))) {
|
|
273
344
|
this.currentOrder.value.currency = latestStorefront.suggestedCurrency;
|
|
274
345
|
}
|
|
275
346
|
this.currentOrder.value.items = this.enrichLineItems(this.currentOrder.value.items);
|
|
@@ -311,6 +382,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
311
382
|
}
|
|
312
383
|
}
|
|
313
384
|
async refreshOrder() {
|
|
385
|
+
var _a;
|
|
314
386
|
try {
|
|
315
387
|
const latestOrder = await this.client.orders.get(this.currentOrder.value.id, { abort: this.refreshOrderAbortController.signal });
|
|
316
388
|
if (latestOrder) {
|
|
@@ -320,6 +392,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
320
392
|
latestOrder.items = this.enrichLineItems(latestOrder.items);
|
|
321
393
|
if (typeof window !== "undefined")
|
|
322
394
|
localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
|
|
395
|
+
if (this.storefront.value && !((_a = this.storefront.value.enabledCurrencies) == null ? void 0 : _a.includes(latestOrder.currency))) {
|
|
396
|
+
latestOrder.currency = this.storefront.value.suggestedCurrency;
|
|
397
|
+
}
|
|
323
398
|
this.currentOrder.value = latestOrder;
|
|
324
399
|
}
|
|
325
400
|
}
|
|
@@ -606,7 +681,7 @@ function useCart(context) {
|
|
|
606
681
|
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
607
682
|
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;
|
|
608
683
|
}
|
|
609
|
-
const offer = (_j = storefront.storefront.value.offers) == null ? void 0 : _j.find((o) => o.id === item.offerId);
|
|
684
|
+
const offer = item.offerId ? (_j = storefront.storefront.value.offers) == null ? void 0 : _j.find((o) => o.id === item.offerId) : null;
|
|
610
685
|
if (offer && OfferUtils2.eligible(offer, storefront.currentOrder.value)) {
|
|
611
686
|
const offerDiscount = DiscountUtils.apply(offer.discount, { [currency]: price });
|
|
612
687
|
price -= offerDiscount[currency];
|
|
@@ -840,7 +915,7 @@ async function useCheckout(items, options, context) {
|
|
|
840
915
|
}
|
|
841
916
|
|
|
842
917
|
// src/composables/useInventory.ts
|
|
843
|
-
import { inject as inject7 } from "vue";
|
|
918
|
+
import { inject as inject7, toRaw } from "vue";
|
|
844
919
|
function useInventory(context) {
|
|
845
920
|
const storefront = context != null ? context : inject7(storefrontKey);
|
|
846
921
|
if (!storefront)
|
|
@@ -901,6 +976,30 @@ function useInventory(context) {
|
|
|
901
976
|
}, { once: true });
|
|
902
977
|
});
|
|
903
978
|
}
|
|
979
|
+
},
|
|
980
|
+
updateSubscriptionPaymentMethod: async (subscription, options) => {
|
|
981
|
+
var _a;
|
|
982
|
+
const fallbackPath = typeof window !== "undefined" ? window.location.pathname : "";
|
|
983
|
+
const absoluteReturnUrl = new URL((_a = options.returnUrl) != null ? _a : fallbackPath, document.baseURI).href;
|
|
984
|
+
const response = await storefront.client.inventory.subscriptions.getById(subscription.id, {
|
|
985
|
+
toUpdatePaymentMethod: true,
|
|
986
|
+
returnUrl: absoluteReturnUrl
|
|
987
|
+
});
|
|
988
|
+
window.dispatchEvent(new CustomEvent("moonbase-subscription-payment-method-update-initiated", {
|
|
989
|
+
detail: { subscription: toRaw(subscription) }
|
|
990
|
+
}));
|
|
991
|
+
if (response.embeddedUpdatePaymentUrl && typeof window !== "undefined") {
|
|
992
|
+
const embeddedUrl = response.embeddedUpdatePaymentUrl;
|
|
993
|
+
return new Promise((resolve) => {
|
|
994
|
+
mountSubscription(embeddedUrl.replace("acme-co.beta.moonbase.sh", "localhost:3002"));
|
|
995
|
+
window.addEventListener("moonbase-subscription-closed", (e) => {
|
|
996
|
+
const evnt = e;
|
|
997
|
+
resolve({ completed: evnt.detail.completed });
|
|
998
|
+
}, { once: true });
|
|
999
|
+
});
|
|
1000
|
+
} else {
|
|
1001
|
+
throw new Error("No update URL found");
|
|
1002
|
+
}
|
|
904
1003
|
}
|
|
905
1004
|
};
|
|
906
1005
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.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",
|
|
@@ -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.4.
|
|
22
|
+
"@moonbase.sh/storefront-api": "0.4.31"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/uuid": "^9.0.8",
|