@moonbase.sh/vue 0.1.30 → 0.1.33
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 +26 -26
- package/dist/index.d.cts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.js +24 -23
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -22,7 +22,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var src_exports = {};
|
|
23
23
|
__export(src_exports, {
|
|
24
24
|
createStorefront: () => createStorefront,
|
|
25
|
-
findBestPrice: () => findBestPrice,
|
|
26
25
|
storefrontKey: () => storefrontKey,
|
|
27
26
|
useAuth: () => useAuth,
|
|
28
27
|
useBundle: () => useBundle,
|
|
@@ -32,7 +31,7 @@ __export(src_exports, {
|
|
|
32
31
|
useProducts: () => useProducts
|
|
33
32
|
});
|
|
34
33
|
module.exports = __toCommonJS(src_exports);
|
|
35
|
-
var
|
|
34
|
+
var import_api_client2 = require("@moonbase.sh/api-client");
|
|
36
35
|
|
|
37
36
|
// src/context.ts
|
|
38
37
|
var import_api_client = require("@moonbase.sh/api-client");
|
|
@@ -173,17 +172,7 @@ function useProducts() {
|
|
|
173
172
|
}
|
|
174
173
|
|
|
175
174
|
// src/composables/useCart.ts
|
|
176
|
-
var import_api_client2 = require("@moonbase.sh/api-client");
|
|
177
175
|
var import_vue6 = require("vue");
|
|
178
|
-
|
|
179
|
-
// src/utils/findBestPrice.ts
|
|
180
|
-
function findBestPrice(variations, currency, model) {
|
|
181
|
-
const prices = variations.filter((v) => v.model === model && v.prices[currency] !== void 0).map((v) => v.prices[currency]);
|
|
182
|
-
prices.sort((a, b) => b - a);
|
|
183
|
-
return prices.length === 0 ? 0 : prices[0];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// src/composables/useCart.ts
|
|
187
176
|
function useCart() {
|
|
188
177
|
const storefront = (0, import_vue6.inject)(storefrontKey);
|
|
189
178
|
if (!storefront)
|
|
@@ -194,37 +183,45 @@ function useCart() {
|
|
|
194
183
|
total: (0, import_vue6.computed)(() => {
|
|
195
184
|
const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
|
|
196
185
|
const total = storefront.currentOrder.value.items.reduce((agg, item) => {
|
|
197
|
-
var _a, _b;
|
|
198
|
-
let
|
|
186
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
187
|
+
let price;
|
|
199
188
|
if (item.type === "Product") {
|
|
200
|
-
const
|
|
201
|
-
|
|
189
|
+
const product = useProduct(item.productId);
|
|
190
|
+
const variations = ((_a = product.value) == null ? void 0 : _a.variations) || [];
|
|
191
|
+
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
192
|
+
price = (_e = (_d = pickedVariation == null ? void 0 : pickedVariation.price[currency]) != null ? _d : (_c = (_b = product.value) == null ? void 0 : _b.defaultVariation) == null ? void 0 : _c.price[currency]) != null ? _e : 0;
|
|
202
193
|
} else {
|
|
203
|
-
const
|
|
204
|
-
|
|
194
|
+
const bundle = useBundle(item.bundleId);
|
|
195
|
+
const variations = ((_f = bundle.value) == null ? void 0 : _f.variations) || [];
|
|
196
|
+
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
197
|
+
price = (_j = (_i = pickedVariation == null ? void 0 : pickedVariation.price[currency]) != null ? _i : (_h = (_g = bundle.value) == null ? void 0 : _g.defaultVariation) == null ? void 0 : _h.price[currency]) != null ? _j : 0;
|
|
205
198
|
}
|
|
206
|
-
return agg +
|
|
199
|
+
return agg + price * item.quantity;
|
|
207
200
|
}, 0);
|
|
208
201
|
return { amount: total, currency };
|
|
209
202
|
}),
|
|
210
|
-
addToCart: (item,
|
|
211
|
-
|
|
203
|
+
addToCart: (item, variation) => {
|
|
204
|
+
variation != null ? variation : variation = item.defaultVariation;
|
|
205
|
+
if (!variation)
|
|
206
|
+
throw new Error("Added item does not have a default variation, and none have been specified");
|
|
207
|
+
let lineItem = storefront.currentOrder.value.items.find((i) => i.type === "Product" && i.productId === item.id && i.variationId === variation.id || i.type === "Bundle" && i.bundleId === item.id && i.variationId === variation.id);
|
|
212
208
|
if (!lineItem) {
|
|
213
209
|
if (item.type === "bundle") {
|
|
214
210
|
lineItem = {
|
|
215
211
|
type: "Bundle",
|
|
216
212
|
bundleId: item.id,
|
|
217
213
|
bundle: item,
|
|
218
|
-
quantity: 1
|
|
214
|
+
quantity: 1,
|
|
215
|
+
variationId: variation.id
|
|
219
216
|
};
|
|
220
217
|
storefront.currentOrder.value.items.push(lineItem);
|
|
221
218
|
} else if (item.type === "product") {
|
|
222
219
|
lineItem = {
|
|
223
220
|
type: "Product",
|
|
224
|
-
pricingModel: model,
|
|
225
221
|
productId: item.id,
|
|
226
222
|
product: item,
|
|
227
|
-
quantity: 1
|
|
223
|
+
quantity: 1,
|
|
224
|
+
variationId: variation.id
|
|
228
225
|
};
|
|
229
226
|
storefront.currentOrder.value.items.push(lineItem);
|
|
230
227
|
}
|
|
@@ -267,6 +264,10 @@ function useAuth() {
|
|
|
267
264
|
const _ = storefront.updateStorefront();
|
|
268
265
|
return user;
|
|
269
266
|
},
|
|
267
|
+
signOut: () => {
|
|
268
|
+
storefront.client.tokenStore.setUser(null);
|
|
269
|
+
storefront.currentUser.value = null;
|
|
270
|
+
},
|
|
270
271
|
update: async (name, email, emailConfirmationToken) => {
|
|
271
272
|
const result = await storefront.client.identity.update(name, email, emailConfirmationToken);
|
|
272
273
|
if (storefront.currentUser.value)
|
|
@@ -292,12 +293,11 @@ function createStorefront(endpoint) {
|
|
|
292
293
|
const configuration = {
|
|
293
294
|
endpoint
|
|
294
295
|
};
|
|
295
|
-
return new StorefrontContextImpl(configuration, new
|
|
296
|
+
return new StorefrontContextImpl(configuration, new import_api_client2.MoonbaseClient(configuration));
|
|
296
297
|
}
|
|
297
298
|
// Annotate the CommonJS export names for ESM import in node:
|
|
298
299
|
0 && (module.exports = {
|
|
299
300
|
createStorefront,
|
|
300
|
-
findBestPrice,
|
|
301
301
|
storefrontKey,
|
|
302
302
|
useAuth,
|
|
303
303
|
useBundle,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Storefront, Order, User, MoonbaseClient, StorefrontBundle, StorefrontProduct,
|
|
1
|
+
import { Storefront, Order, User, MoonbaseClient, StorefrontBundle, StorefrontProduct, PricingVariation, OpenLineItem } from '@moonbase.sh/api-client';
|
|
2
2
|
export * from '@moonbase.sh/api-client';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
4
|
import { Ref, App, InjectionKey } from 'vue';
|
|
@@ -37,7 +37,7 @@ declare function useCart(): {
|
|
|
37
37
|
amount: number;
|
|
38
38
|
currency: string;
|
|
39
39
|
}>;
|
|
40
|
-
addToCart: (item: StorefrontProduct | StorefrontBundle,
|
|
40
|
+
addToCart: (item: StorefrontProduct | StorefrontBundle, variation?: PricingVariation) => void;
|
|
41
41
|
removeFromCart: (cartItem: CartItem) => void;
|
|
42
42
|
checkout: (returnUrl: string) => Promise<void>;
|
|
43
43
|
};
|
|
@@ -56,6 +56,7 @@ declare function useAuth(): {
|
|
|
56
56
|
name: string;
|
|
57
57
|
tenantId: string;
|
|
58
58
|
}>;
|
|
59
|
+
signOut: () => void;
|
|
59
60
|
update: (name: string, email: string, emailConfirmationToken?: string) => Promise<{
|
|
60
61
|
needsEmailConfirmationToken: boolean;
|
|
61
62
|
}>;
|
|
@@ -66,12 +67,10 @@ declare function useAuth(): {
|
|
|
66
67
|
|
|
67
68
|
declare const storefrontKey: InjectionKey<StorefrontContext>;
|
|
68
69
|
|
|
69
|
-
declare function findBestPrice(variations: PricingVariation[], currency: string, model: PricingModel): number;
|
|
70
|
-
|
|
71
70
|
interface Cart {
|
|
72
71
|
items: CartItem[];
|
|
73
72
|
}
|
|
74
73
|
type CartItem = OpenLineItem & {};
|
|
75
74
|
declare function createStorefront(endpoint: string): StorefrontContext;
|
|
76
75
|
|
|
77
|
-
export { Cart, CartItem, createStorefront,
|
|
76
|
+
export { Cart, CartItem, createStorefront, storefrontKey, useAuth, useBundle, useBundles, useCart, useProduct, useProducts };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Storefront, Order, User, MoonbaseClient, StorefrontBundle, StorefrontProduct,
|
|
1
|
+
import { Storefront, Order, User, MoonbaseClient, StorefrontBundle, StorefrontProduct, PricingVariation, OpenLineItem } from '@moonbase.sh/api-client';
|
|
2
2
|
export * from '@moonbase.sh/api-client';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
4
|
import { Ref, App, InjectionKey } from 'vue';
|
|
@@ -37,7 +37,7 @@ declare function useCart(): {
|
|
|
37
37
|
amount: number;
|
|
38
38
|
currency: string;
|
|
39
39
|
}>;
|
|
40
|
-
addToCart: (item: StorefrontProduct | StorefrontBundle,
|
|
40
|
+
addToCart: (item: StorefrontProduct | StorefrontBundle, variation?: PricingVariation) => void;
|
|
41
41
|
removeFromCart: (cartItem: CartItem) => void;
|
|
42
42
|
checkout: (returnUrl: string) => Promise<void>;
|
|
43
43
|
};
|
|
@@ -56,6 +56,7 @@ declare function useAuth(): {
|
|
|
56
56
|
name: string;
|
|
57
57
|
tenantId: string;
|
|
58
58
|
}>;
|
|
59
|
+
signOut: () => void;
|
|
59
60
|
update: (name: string, email: string, emailConfirmationToken?: string) => Promise<{
|
|
60
61
|
needsEmailConfirmationToken: boolean;
|
|
61
62
|
}>;
|
|
@@ -66,12 +67,10 @@ declare function useAuth(): {
|
|
|
66
67
|
|
|
67
68
|
declare const storefrontKey: InjectionKey<StorefrontContext>;
|
|
68
69
|
|
|
69
|
-
declare function findBestPrice(variations: PricingVariation[], currency: string, model: PricingModel): number;
|
|
70
|
-
|
|
71
70
|
interface Cart {
|
|
72
71
|
items: CartItem[];
|
|
73
72
|
}
|
|
74
73
|
type CartItem = OpenLineItem & {};
|
|
75
74
|
declare function createStorefront(endpoint: string): StorefrontContext;
|
|
76
75
|
|
|
77
|
-
export { Cart, CartItem, createStorefront,
|
|
76
|
+
export { Cart, CartItem, createStorefront, storefrontKey, useAuth, useBundle, useBundles, useCart, useProduct, useProducts };
|
package/dist/index.js
CHANGED
|
@@ -140,17 +140,7 @@ function useProducts() {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
// src/composables/useCart.ts
|
|
143
|
-
import { PricingModel } from "@moonbase.sh/api-client";
|
|
144
143
|
import { computed as computed5, inject as inject5 } from "vue";
|
|
145
|
-
|
|
146
|
-
// src/utils/findBestPrice.ts
|
|
147
|
-
function findBestPrice(variations, currency, model) {
|
|
148
|
-
const prices = variations.filter((v) => v.model === model && v.prices[currency] !== void 0).map((v) => v.prices[currency]);
|
|
149
|
-
prices.sort((a, b) => b - a);
|
|
150
|
-
return prices.length === 0 ? 0 : prices[0];
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// src/composables/useCart.ts
|
|
154
144
|
function useCart() {
|
|
155
145
|
const storefront = inject5(storefrontKey);
|
|
156
146
|
if (!storefront)
|
|
@@ -161,37 +151,45 @@ function useCart() {
|
|
|
161
151
|
total: computed5(() => {
|
|
162
152
|
const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
|
|
163
153
|
const total = storefront.currentOrder.value.items.reduce((agg, item) => {
|
|
164
|
-
var _a, _b;
|
|
165
|
-
let
|
|
154
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
155
|
+
let price;
|
|
166
156
|
if (item.type === "Product") {
|
|
167
|
-
const
|
|
168
|
-
|
|
157
|
+
const product = useProduct(item.productId);
|
|
158
|
+
const variations = ((_a = product.value) == null ? void 0 : _a.variations) || [];
|
|
159
|
+
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
160
|
+
price = (_e = (_d = pickedVariation == null ? void 0 : pickedVariation.price[currency]) != null ? _d : (_c = (_b = product.value) == null ? void 0 : _b.defaultVariation) == null ? void 0 : _c.price[currency]) != null ? _e : 0;
|
|
169
161
|
} else {
|
|
170
|
-
const
|
|
171
|
-
|
|
162
|
+
const bundle = useBundle(item.bundleId);
|
|
163
|
+
const variations = ((_f = bundle.value) == null ? void 0 : _f.variations) || [];
|
|
164
|
+
const pickedVariation = variations.find((v) => v.id === item.variationId);
|
|
165
|
+
price = (_j = (_i = pickedVariation == null ? void 0 : pickedVariation.price[currency]) != null ? _i : (_h = (_g = bundle.value) == null ? void 0 : _g.defaultVariation) == null ? void 0 : _h.price[currency]) != null ? _j : 0;
|
|
172
166
|
}
|
|
173
|
-
return agg +
|
|
167
|
+
return agg + price * item.quantity;
|
|
174
168
|
}, 0);
|
|
175
169
|
return { amount: total, currency };
|
|
176
170
|
}),
|
|
177
|
-
addToCart: (item,
|
|
178
|
-
|
|
171
|
+
addToCart: (item, variation) => {
|
|
172
|
+
variation != null ? variation : variation = item.defaultVariation;
|
|
173
|
+
if (!variation)
|
|
174
|
+
throw new Error("Added item does not have a default variation, and none have been specified");
|
|
175
|
+
let lineItem = storefront.currentOrder.value.items.find((i) => i.type === "Product" && i.productId === item.id && i.variationId === variation.id || i.type === "Bundle" && i.bundleId === item.id && i.variationId === variation.id);
|
|
179
176
|
if (!lineItem) {
|
|
180
177
|
if (item.type === "bundle") {
|
|
181
178
|
lineItem = {
|
|
182
179
|
type: "Bundle",
|
|
183
180
|
bundleId: item.id,
|
|
184
181
|
bundle: item,
|
|
185
|
-
quantity: 1
|
|
182
|
+
quantity: 1,
|
|
183
|
+
variationId: variation.id
|
|
186
184
|
};
|
|
187
185
|
storefront.currentOrder.value.items.push(lineItem);
|
|
188
186
|
} else if (item.type === "product") {
|
|
189
187
|
lineItem = {
|
|
190
188
|
type: "Product",
|
|
191
|
-
pricingModel: model,
|
|
192
189
|
productId: item.id,
|
|
193
190
|
product: item,
|
|
194
|
-
quantity: 1
|
|
191
|
+
quantity: 1,
|
|
192
|
+
variationId: variation.id
|
|
195
193
|
};
|
|
196
194
|
storefront.currentOrder.value.items.push(lineItem);
|
|
197
195
|
}
|
|
@@ -234,6 +232,10 @@ function useAuth() {
|
|
|
234
232
|
const _ = storefront.updateStorefront();
|
|
235
233
|
return user;
|
|
236
234
|
},
|
|
235
|
+
signOut: () => {
|
|
236
|
+
storefront.client.tokenStore.setUser(null);
|
|
237
|
+
storefront.currentUser.value = null;
|
|
238
|
+
},
|
|
237
239
|
update: async (name, email, emailConfirmationToken) => {
|
|
238
240
|
const result = await storefront.client.identity.update(name, email, emailConfirmationToken);
|
|
239
241
|
if (storefront.currentUser.value)
|
|
@@ -263,7 +265,6 @@ function createStorefront(endpoint) {
|
|
|
263
265
|
}
|
|
264
266
|
export {
|
|
265
267
|
createStorefront,
|
|
266
|
-
findBestPrice,
|
|
267
268
|
storefrontKey,
|
|
268
269
|
useAuth,
|
|
269
270
|
useBundle,
|
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.33",
|
|
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",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@vue/devtools-api": "^6.5.0",
|
|
17
17
|
"uuid": "^9.0.0",
|
|
18
|
-
"@moonbase.sh/api-client": "0.1.
|
|
18
|
+
"@moonbase.sh/api-client": "0.1.33"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"vue": "^3.2.0"
|