@moonbase.sh/vue 0.1.49 → 0.1.52
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 +37 -35
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +17 -15
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -32,11 +32,12 @@ __export(src_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(src_exports);
|
|
34
34
|
var import_api_client2 = require("@moonbase.sh/api-client");
|
|
35
|
-
var
|
|
35
|
+
var import_vue8 = require("vue");
|
|
36
36
|
|
|
37
37
|
// src/context.ts
|
|
38
38
|
var import_api_client = require("@moonbase.sh/api-client");
|
|
39
39
|
var import_uuid = require("uuid");
|
|
40
|
+
var import_vue = require("vue");
|
|
40
41
|
|
|
41
42
|
// src/symbols.ts
|
|
42
43
|
var storefrontKey = Symbol("storefront");
|
|
@@ -59,32 +60,32 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
59
60
|
this.configuration = configuration;
|
|
60
61
|
this.client = client;
|
|
61
62
|
this.stateFactory = stateFactory;
|
|
63
|
+
this.currentUser = (0, import_vue.ref)(null);
|
|
64
|
+
this.loadedUser = (0, import_vue.ref)(false);
|
|
62
65
|
this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order), 500);
|
|
63
|
-
this.currentUser = stateFactory("moonbase_user", null);
|
|
64
|
-
this.loadedUser = stateFactory("moonbase_loaded_user", false);
|
|
65
66
|
if (typeof window === "undefined") {
|
|
66
|
-
this.currentOrder =
|
|
67
|
+
this.currentOrder = (0, import_vue.ref)({
|
|
67
68
|
id: (0, import_uuid.v4)(),
|
|
68
69
|
status: import_api_client.OrderStatus.Open,
|
|
69
70
|
currency: "",
|
|
70
71
|
items: [],
|
|
71
72
|
couponsApplied: []
|
|
72
73
|
});
|
|
73
|
-
this.storefront = stateFactory(
|
|
74
|
+
this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, {
|
|
74
75
|
suggestedCurrency: "",
|
|
75
76
|
bundles: [],
|
|
76
77
|
products: []
|
|
77
78
|
});
|
|
78
|
-
this.loadedStorefront = stateFactory(
|
|
79
|
+
this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
81
82
|
window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
|
|
82
|
-
const cachedOrderJson = localStorage.getItem(
|
|
83
|
+
const cachedOrderJson = localStorage.getItem(_StorefrontContextImpl.sessionKey);
|
|
83
84
|
if (cachedOrderJson) {
|
|
84
|
-
this.currentOrder =
|
|
85
|
+
this.currentOrder = (0, import_vue.ref)(JSON.parse(cachedOrderJson));
|
|
85
86
|
const _1 = this.refreshOrder();
|
|
86
87
|
} else {
|
|
87
|
-
this.currentOrder =
|
|
88
|
+
this.currentOrder = (0, import_vue.ref)({
|
|
88
89
|
id: (0, import_uuid.v4)(),
|
|
89
90
|
status: import_api_client.OrderStatus.Open,
|
|
90
91
|
currency: "",
|
|
@@ -95,22 +96,22 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
95
96
|
}
|
|
96
97
|
const cachedStorefrontJson = localStorage.getItem(_StorefrontContextImpl.storefrontKey);
|
|
97
98
|
if (cachedStorefrontJson) {
|
|
98
|
-
this.storefront = stateFactory(
|
|
99
|
-
this.loadedStorefront = stateFactory(
|
|
99
|
+
this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, JSON.parse(cachedStorefrontJson));
|
|
100
|
+
this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, true);
|
|
100
101
|
} else {
|
|
101
|
-
this.storefront = stateFactory(
|
|
102
|
+
this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, {
|
|
102
103
|
suggestedCurrency: "",
|
|
103
104
|
bundles: [],
|
|
104
105
|
products: []
|
|
105
106
|
});
|
|
106
|
-
this.loadedStorefront = stateFactory(
|
|
107
|
+
this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
|
|
107
108
|
}
|
|
108
109
|
const _2 = this.updateStorefront();
|
|
109
110
|
const _3 = this.updateUser();
|
|
110
111
|
}
|
|
111
112
|
install(app) {
|
|
112
113
|
app.provide(storefrontKey, this);
|
|
113
|
-
console.log("Moonbase.sh storefront installed");
|
|
114
|
+
console.log("Moonbase.sh storefront installed, learn more at https://moonbase.sh/docs");
|
|
114
115
|
}
|
|
115
116
|
async updateUser() {
|
|
116
117
|
try {
|
|
@@ -180,6 +181,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
180
181
|
localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(this.currentOrder.value));
|
|
181
182
|
}
|
|
182
183
|
};
|
|
184
|
+
_StorefrontContextImpl.userKey = "moonbase_user";
|
|
183
185
|
_StorefrontContextImpl.sessionKey = "moonbase_session";
|
|
184
186
|
_StorefrontContextImpl.storefrontKey = "moonbase_storefront";
|
|
185
187
|
var StorefrontContextImpl = _StorefrontContextImpl;
|
|
@@ -188,51 +190,51 @@ var StorefrontContextImpl = _StorefrontContextImpl;
|
|
|
188
190
|
__reExport(src_exports, require("@moonbase.sh/api-client"), module.exports);
|
|
189
191
|
|
|
190
192
|
// src/composables/useBundle.ts
|
|
191
|
-
var
|
|
193
|
+
var import_vue2 = require("vue");
|
|
192
194
|
function useBundle(bundleId) {
|
|
193
|
-
const storefront = (0,
|
|
195
|
+
const storefront = (0, import_vue2.inject)(storefrontKey);
|
|
194
196
|
if (!storefront)
|
|
195
197
|
throw new Error("No storefront configured");
|
|
196
|
-
return (0,
|
|
198
|
+
return (0, import_vue2.computed)(() => storefront.storefront.value.bundles.find((b) => b.id === bundleId) || null);
|
|
197
199
|
}
|
|
198
200
|
|
|
199
201
|
// src/composables/useBundles.ts
|
|
200
|
-
var
|
|
202
|
+
var import_vue3 = require("vue");
|
|
201
203
|
function useBundles() {
|
|
202
|
-
const storefront = (0,
|
|
204
|
+
const storefront = (0, import_vue3.inject)(storefrontKey);
|
|
203
205
|
if (!storefront)
|
|
204
206
|
throw new Error("No storefront configured");
|
|
205
|
-
return (0,
|
|
207
|
+
return (0, import_vue3.computed)(() => storefront.storefront.value.bundles);
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
// src/composables/useProduct.ts
|
|
209
|
-
var
|
|
211
|
+
var import_vue4 = require("vue");
|
|
210
212
|
function useProduct(productId) {
|
|
211
|
-
const storefront = (0,
|
|
213
|
+
const storefront = (0, import_vue4.inject)(storefrontKey);
|
|
212
214
|
if (!storefront)
|
|
213
215
|
throw new Error("No storefront configured");
|
|
214
|
-
return (0,
|
|
216
|
+
return (0, import_vue4.computed)(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
// src/composables/useProducts.ts
|
|
218
|
-
var
|
|
220
|
+
var import_vue5 = require("vue");
|
|
219
221
|
function useProducts() {
|
|
220
|
-
const storefront = (0,
|
|
222
|
+
const storefront = (0, import_vue5.inject)(storefrontKey);
|
|
221
223
|
if (!storefront)
|
|
222
224
|
throw new Error("No storefront configured");
|
|
223
|
-
return (0,
|
|
225
|
+
return (0, import_vue5.computed)(() => storefront.storefront.value.products);
|
|
224
226
|
}
|
|
225
227
|
|
|
226
228
|
// src/composables/useCart.ts
|
|
227
|
-
var
|
|
229
|
+
var import_vue6 = require("vue");
|
|
228
230
|
function useCart() {
|
|
229
|
-
const storefront = (0,
|
|
231
|
+
const storefront = (0, import_vue6.inject)(storefrontKey);
|
|
230
232
|
if (!storefront)
|
|
231
233
|
throw new Error("No storefront configured");
|
|
232
234
|
return {
|
|
233
|
-
items: (0,
|
|
234
|
-
currency: (0,
|
|
235
|
-
total: (0,
|
|
235
|
+
items: (0, import_vue6.computed)(() => storefront.currentOrder.value.items),
|
|
236
|
+
currency: (0, import_vue6.computed)(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
|
|
237
|
+
total: (0, import_vue6.computed)(() => {
|
|
236
238
|
const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
|
|
237
239
|
const total = storefront.currentOrder.value.items.reduce((agg, item) => {
|
|
238
240
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
@@ -253,7 +255,7 @@ function useCart() {
|
|
|
253
255
|
return { amount: total, currency };
|
|
254
256
|
}),
|
|
255
257
|
addToCart: (item, variation) => {
|
|
256
|
-
item = (0,
|
|
258
|
+
item = (0, import_vue6.unref)(item);
|
|
257
259
|
variation != null ? variation : variation = item.defaultVariation;
|
|
258
260
|
if (!variation)
|
|
259
261
|
throw new Error("Added item does not have a default variation, and none have been specified");
|
|
@@ -314,9 +316,9 @@ function useCart() {
|
|
|
314
316
|
}
|
|
315
317
|
|
|
316
318
|
// src/composables/useAuth.ts
|
|
317
|
-
var
|
|
319
|
+
var import_vue7 = require("vue");
|
|
318
320
|
function useAuth() {
|
|
319
|
-
const storefront = (0,
|
|
321
|
+
const storefront = (0, import_vue7.inject)(storefrontKey);
|
|
320
322
|
if (!storefront)
|
|
321
323
|
throw new Error("No storefront configured");
|
|
322
324
|
return {
|
|
@@ -374,7 +376,7 @@ function createStorefront(endpoint, stateFactory) {
|
|
|
374
376
|
configuration,
|
|
375
377
|
new import_api_client2.MoonbaseClient(configuration),
|
|
376
378
|
// Default to vue refs but allow stuff like Nuxt useState wrappers
|
|
377
|
-
stateFactory || ((_, state) => (0,
|
|
379
|
+
stateFactory || ((_, state) => (0, import_vue8.ref)(state))
|
|
378
380
|
);
|
|
379
381
|
}
|
|
380
382
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Address, LineItem } from '@moonbase.sh/api-client/src';
|
|
2
|
+
import { Storefront, Order, User, MoonbaseClient, StorefrontBundle, StorefrontProduct, PricingVariation } from '@moonbase.sh/api-client';
|
|
2
3
|
export * from '@moonbase.sh/api-client';
|
|
3
4
|
import * as vue from 'vue';
|
|
4
5
|
import { Plugin, Ref, App, InjectionKey } from 'vue';
|
|
5
|
-
import { Address } from '@moonbase.sh/api-client/src';
|
|
6
6
|
|
|
7
7
|
interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
8
8
|
storefront: Ref<Storefront>;
|
|
@@ -103,7 +103,7 @@ declare const storefrontKey: InjectionKey<StorefrontContext>;
|
|
|
103
103
|
interface Cart {
|
|
104
104
|
items: CartItem[];
|
|
105
105
|
}
|
|
106
|
-
type CartItem =
|
|
106
|
+
type CartItem = LineItem & {};
|
|
107
107
|
declare function createStorefront(endpoint: string, stateFactory?: StateFactory): StorefrontContext;
|
|
108
108
|
|
|
109
109
|
export { type Cart, type CartItem, createStorefront, storefrontKey, useAuth, useBundle, useBundles, useCart, useProduct, useProducts };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Address, LineItem } from '@moonbase.sh/api-client/src';
|
|
2
|
+
import { Storefront, Order, User, MoonbaseClient, StorefrontBundle, StorefrontProduct, PricingVariation } from '@moonbase.sh/api-client';
|
|
2
3
|
export * from '@moonbase.sh/api-client';
|
|
3
4
|
import * as vue from 'vue';
|
|
4
5
|
import { Plugin, Ref, App, InjectionKey } from 'vue';
|
|
5
|
-
import { Address } from '@moonbase.sh/api-client/src';
|
|
6
6
|
|
|
7
7
|
interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
8
8
|
storefront: Ref<Storefront>;
|
|
@@ -103,7 +103,7 @@ declare const storefrontKey: InjectionKey<StorefrontContext>;
|
|
|
103
103
|
interface Cart {
|
|
104
104
|
items: CartItem[];
|
|
105
105
|
}
|
|
106
|
-
type CartItem =
|
|
106
|
+
type CartItem = LineItem & {};
|
|
107
107
|
declare function createStorefront(endpoint: string, stateFactory?: StateFactory): StorefrontContext;
|
|
108
108
|
|
|
109
109
|
export { type Cart, type CartItem, createStorefront, storefrontKey, useAuth, useBundle, useBundles, useCart, useProduct, useProducts };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { MoonbaseClient } from "@moonbase.sh/api-client";
|
|
3
|
-
import { ref } from "vue";
|
|
3
|
+
import { ref as ref2 } from "vue";
|
|
4
4
|
|
|
5
5
|
// src/context.ts
|
|
6
6
|
import { NotAuthenticatedError, OrderStatus } from "@moonbase.sh/api-client";
|
|
7
7
|
import { v4 as uuidv4 } from "uuid";
|
|
8
|
+
import { ref } from "vue";
|
|
8
9
|
|
|
9
10
|
// src/symbols.ts
|
|
10
11
|
var storefrontKey = Symbol("storefront");
|
|
@@ -27,32 +28,32 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
27
28
|
this.configuration = configuration;
|
|
28
29
|
this.client = client;
|
|
29
30
|
this.stateFactory = stateFactory;
|
|
31
|
+
this.currentUser = ref(null);
|
|
32
|
+
this.loadedUser = ref(false);
|
|
30
33
|
this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order), 500);
|
|
31
|
-
this.currentUser = stateFactory("moonbase_user", null);
|
|
32
|
-
this.loadedUser = stateFactory("moonbase_loaded_user", false);
|
|
33
34
|
if (typeof window === "undefined") {
|
|
34
|
-
this.currentOrder =
|
|
35
|
+
this.currentOrder = ref({
|
|
35
36
|
id: uuidv4(),
|
|
36
37
|
status: OrderStatus.Open,
|
|
37
38
|
currency: "",
|
|
38
39
|
items: [],
|
|
39
40
|
couponsApplied: []
|
|
40
41
|
});
|
|
41
|
-
this.storefront = stateFactory(
|
|
42
|
+
this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, {
|
|
42
43
|
suggestedCurrency: "",
|
|
43
44
|
bundles: [],
|
|
44
45
|
products: []
|
|
45
46
|
});
|
|
46
|
-
this.loadedStorefront = stateFactory(
|
|
47
|
+
this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
|
|
47
48
|
return;
|
|
48
49
|
}
|
|
49
50
|
window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
|
|
50
|
-
const cachedOrderJson = localStorage.getItem(
|
|
51
|
+
const cachedOrderJson = localStorage.getItem(_StorefrontContextImpl.sessionKey);
|
|
51
52
|
if (cachedOrderJson) {
|
|
52
|
-
this.currentOrder =
|
|
53
|
+
this.currentOrder = ref(JSON.parse(cachedOrderJson));
|
|
53
54
|
const _1 = this.refreshOrder();
|
|
54
55
|
} else {
|
|
55
|
-
this.currentOrder =
|
|
56
|
+
this.currentOrder = ref({
|
|
56
57
|
id: uuidv4(),
|
|
57
58
|
status: OrderStatus.Open,
|
|
58
59
|
currency: "",
|
|
@@ -63,22 +64,22 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
63
64
|
}
|
|
64
65
|
const cachedStorefrontJson = localStorage.getItem(_StorefrontContextImpl.storefrontKey);
|
|
65
66
|
if (cachedStorefrontJson) {
|
|
66
|
-
this.storefront = stateFactory(
|
|
67
|
-
this.loadedStorefront = stateFactory(
|
|
67
|
+
this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, JSON.parse(cachedStorefrontJson));
|
|
68
|
+
this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, true);
|
|
68
69
|
} else {
|
|
69
|
-
this.storefront = stateFactory(
|
|
70
|
+
this.storefront = stateFactory(_StorefrontContextImpl.storefrontKey, {
|
|
70
71
|
suggestedCurrency: "",
|
|
71
72
|
bundles: [],
|
|
72
73
|
products: []
|
|
73
74
|
});
|
|
74
|
-
this.loadedStorefront = stateFactory(
|
|
75
|
+
this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
|
|
75
76
|
}
|
|
76
77
|
const _2 = this.updateStorefront();
|
|
77
78
|
const _3 = this.updateUser();
|
|
78
79
|
}
|
|
79
80
|
install(app) {
|
|
80
81
|
app.provide(storefrontKey, this);
|
|
81
|
-
console.log("Moonbase.sh storefront installed");
|
|
82
|
+
console.log("Moonbase.sh storefront installed, learn more at https://moonbase.sh/docs");
|
|
82
83
|
}
|
|
83
84
|
async updateUser() {
|
|
84
85
|
try {
|
|
@@ -148,6 +149,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
148
149
|
localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(this.currentOrder.value));
|
|
149
150
|
}
|
|
150
151
|
};
|
|
152
|
+
_StorefrontContextImpl.userKey = "moonbase_user";
|
|
151
153
|
_StorefrontContextImpl.sessionKey = "moonbase_session";
|
|
152
154
|
_StorefrontContextImpl.storefrontKey = "moonbase_storefront";
|
|
153
155
|
var StorefrontContextImpl = _StorefrontContextImpl;
|
|
@@ -342,7 +344,7 @@ function createStorefront(endpoint, stateFactory) {
|
|
|
342
344
|
configuration,
|
|
343
345
|
new MoonbaseClient(configuration),
|
|
344
346
|
// Default to vue refs but allow stuff like Nuxt useState wrappers
|
|
345
|
-
stateFactory || ((_, state) =>
|
|
347
|
+
stateFactory || ((_, state) => ref2(state))
|
|
346
348
|
);
|
|
347
349
|
}
|
|
348
350
|
export {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.52",
|
|
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",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@vue/devtools-api": "^6.5.1",
|
|
20
20
|
"uuid": "^9.0.1",
|
|
21
|
-
"@moonbase.sh/api-client": "0.1.
|
|
21
|
+
"@moonbase.sh/api-client": "0.1.52"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/uuid": "^9.0.7",
|