@moonbase.sh/vue 0.1.94 → 0.1.97
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 +51 -18
- package/dist/index.d.cts +22 -21
- package/dist/index.d.ts +22 -21
- package/dist/index.js +64 -31
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -34,7 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
useVoucher: () => useVoucher
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(src_exports);
|
|
37
|
-
var
|
|
37
|
+
var import_storefront_api4 = require("@moonbase.sh/storefront-api");
|
|
38
38
|
var import_vue11 = require("vue");
|
|
39
39
|
|
|
40
40
|
// src/context.ts
|
|
@@ -63,9 +63,11 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
63
63
|
this.configuration = configuration;
|
|
64
64
|
this.client = client;
|
|
65
65
|
this.stateFactory = stateFactory;
|
|
66
|
+
this.hasUtm = (0, import_vue.computed)(() => !!this.utm.value && Object.values(this.utm.value).some((v) => !!v));
|
|
66
67
|
this.currentUser = (0, import_vue.ref)(null);
|
|
67
68
|
this.loadedUser = (0, import_vue.ref)(false);
|
|
68
|
-
this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order), 500);
|
|
69
|
+
this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order, void 0, this.hasUtm.value ? this.utm.value : void 0), 500);
|
|
70
|
+
var _a;
|
|
69
71
|
if (typeof window === "undefined") {
|
|
70
72
|
this.currentOrder = (0, import_vue.ref)({
|
|
71
73
|
id: (0, import_uuid.v4)(),
|
|
@@ -80,8 +82,18 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
80
82
|
products: []
|
|
81
83
|
});
|
|
82
84
|
this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
|
|
85
|
+
this.utm = stateFactory(`${_StorefrontContextImpl.storefrontKey}_utm`, void 0);
|
|
83
86
|
return;
|
|
84
87
|
}
|
|
88
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
89
|
+
this.utm = stateFactory(`${_StorefrontContextImpl.storefrontKey}_utm`, {
|
|
90
|
+
referrer: ((_a = window.document.referrer) == null ? void 0 : _a.replace(/https?:\/\//g, "").split("/")[0]) || void 0,
|
|
91
|
+
source: urlParams.get("utm_source") || void 0,
|
|
92
|
+
medium: urlParams.get("utm_medium") || void 0,
|
|
93
|
+
campaign: urlParams.get("utm_campaign") || void 0,
|
|
94
|
+
term: urlParams.get("utm_term") || void 0,
|
|
95
|
+
content: urlParams.get("utm_content") || void 0
|
|
96
|
+
});
|
|
85
97
|
window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
|
|
86
98
|
const cachedOrderJson = localStorage.getItem(_StorefrontContextImpl.sessionKey);
|
|
87
99
|
if (cachedOrderJson) {
|
|
@@ -127,7 +139,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
127
139
|
}
|
|
128
140
|
}
|
|
129
141
|
async updateStorefront() {
|
|
130
|
-
const latestStorefront = await this.client.storefront.get();
|
|
142
|
+
const latestStorefront = await this.client.storefront.get(this.hasUtm.value ? this.utm.value : void 0);
|
|
131
143
|
if (latestStorefront) {
|
|
132
144
|
if (typeof window !== "undefined")
|
|
133
145
|
localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
|
|
@@ -236,25 +248,30 @@ function useInventory() {
|
|
|
236
248
|
throw new Error("No storefront configured");
|
|
237
249
|
return {
|
|
238
250
|
getLicenses: async (nextUrl) => {
|
|
239
|
-
return storefront.client.licenses.get(nextUrl);
|
|
251
|
+
return storefront.client.inventory.licenses.get(nextUrl);
|
|
240
252
|
},
|
|
241
253
|
getLicenseActivations: async (licenseId, nextUrl) => {
|
|
242
|
-
return storefront.client.licenses.getActivations(licenseId, nextUrl);
|
|
254
|
+
return storefront.client.inventory.licenses.getActivations(licenseId, nextUrl);
|
|
243
255
|
},
|
|
244
256
|
getProducts: async (nextUrl) => {
|
|
245
|
-
return storefront.client.products.getOwned(nextUrl);
|
|
257
|
+
return storefront.client.inventory.products.getOwned(nextUrl);
|
|
246
258
|
},
|
|
247
259
|
getProductLicenses: async (productId, nextUrl) => {
|
|
248
|
-
return storefront.client.products.getLicenses(productId, nextUrl);
|
|
260
|
+
return storefront.client.inventory.products.getLicenses(productId, nextUrl);
|
|
249
261
|
},
|
|
250
262
|
getProductActivations: async (productId, nextUrl) => {
|
|
251
|
-
return storefront.client.products.getActivations(productId, nextUrl);
|
|
263
|
+
return storefront.client.inventory.products.getActivations(productId, nextUrl);
|
|
252
264
|
},
|
|
253
265
|
revokeActivation: async (activation) => {
|
|
254
|
-
return storefront.client.licenses.revokeActivation(activation.licenseId, activation.id);
|
|
266
|
+
return storefront.client.inventory.licenses.revokeActivation(activation.licenseId, activation.id);
|
|
255
267
|
},
|
|
256
268
|
activateProduct: async (deviceToken, activationMethod) => {
|
|
257
|
-
return storefront.client.
|
|
269
|
+
return storefront.client.inventory.activation.activate(deviceToken, activationMethod);
|
|
270
|
+
},
|
|
271
|
+
downloadProduct: async (download) => {
|
|
272
|
+
if (!download.path)
|
|
273
|
+
throw new Error("Product is not downloadable");
|
|
274
|
+
window.location.href = await storefront.client.inventory.products.getDownloadUrl(download.path);
|
|
258
275
|
}
|
|
259
276
|
};
|
|
260
277
|
}
|
|
@@ -317,6 +334,7 @@ function useActivationRequest(requestId) {
|
|
|
317
334
|
}
|
|
318
335
|
|
|
319
336
|
// src/composables/useVoucher.ts
|
|
337
|
+
var import_storefront_api3 = require("@moonbase.sh/storefront-api");
|
|
320
338
|
var import_vue8 = require("vue");
|
|
321
339
|
function useVoucher() {
|
|
322
340
|
const storefront = (0, import_vue8.inject)(storefrontKey);
|
|
@@ -324,10 +342,22 @@ function useVoucher() {
|
|
|
324
342
|
throw new Error("No storefront configured");
|
|
325
343
|
return {
|
|
326
344
|
peek: async (code) => {
|
|
327
|
-
|
|
345
|
+
try {
|
|
346
|
+
return await storefront.client.vouchers.peek(code);
|
|
347
|
+
} catch (e) {
|
|
348
|
+
if (e instanceof import_storefront_api3.NotFoundError)
|
|
349
|
+
throw new Error("Voucher code invalid");
|
|
350
|
+
throw e;
|
|
351
|
+
}
|
|
328
352
|
},
|
|
329
353
|
redeem: async (code) => {
|
|
330
|
-
|
|
354
|
+
try {
|
|
355
|
+
return await storefront.client.vouchers.redeem(code);
|
|
356
|
+
} catch (e) {
|
|
357
|
+
if (e instanceof import_storefront_api3.NotFoundError)
|
|
358
|
+
throw new Error("Voucher code invalid");
|
|
359
|
+
throw e;
|
|
360
|
+
}
|
|
331
361
|
}
|
|
332
362
|
};
|
|
333
363
|
}
|
|
@@ -479,15 +509,18 @@ function useAuth() {
|
|
|
479
509
|
const _ = storefront.updateStorefront();
|
|
480
510
|
return user;
|
|
481
511
|
},
|
|
482
|
-
signOut: () => {
|
|
512
|
+
signOut: async () => {
|
|
483
513
|
storefront.client.tokenStore.setUser(null);
|
|
514
|
+
await storefront.updateStorefront();
|
|
484
515
|
storefront.currentUser.value = null;
|
|
485
|
-
const _ = storefront.updateStorefront();
|
|
486
516
|
},
|
|
487
|
-
update: async (name, email, emailConfirmationToken) => {
|
|
488
|
-
const result = await storefront.client.identity.update(name, email, emailConfirmationToken);
|
|
489
|
-
if (storefront.currentUser.value)
|
|
517
|
+
update: async (name, email, emailConfirmationToken, communicationPreferences) => {
|
|
518
|
+
const result = await storefront.client.identity.update(name, email, emailConfirmationToken, communicationPreferences);
|
|
519
|
+
if (storefront.currentUser.value) {
|
|
490
520
|
storefront.currentUser.value.name = name;
|
|
521
|
+
if (communicationPreferences)
|
|
522
|
+
storefront.currentUser.value.communicationPreferences = communicationPreferences;
|
|
523
|
+
}
|
|
491
524
|
return result;
|
|
492
525
|
},
|
|
493
526
|
setPassword: async (currentPassword, newPassword) => {
|
|
@@ -511,7 +544,7 @@ function createStorefront(endpoint, stateFactory) {
|
|
|
511
544
|
};
|
|
512
545
|
return new StorefrontContextImpl(
|
|
513
546
|
configuration,
|
|
514
|
-
new
|
|
547
|
+
new import_storefront_api4.MoonbaseClient(configuration),
|
|
515
548
|
// Default to vue refs but allow stuff like Nuxt useState wrappers
|
|
516
549
|
stateFactory || ((_, state) => (0, import_vue11.ref)(state))
|
|
517
550
|
);
|
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, PricingVariation, LineItem } from '@moonbase.sh/storefront-api';
|
|
2
|
+
import { MoonbaseConfiguration, Storefront, Order, User, MoonbaseClient, StorefrontBundle, StorefrontProduct, ActivationMethod, Activation, Download, 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';
|
|
@@ -40,10 +40,7 @@ declare function useInventory(): {
|
|
|
40
40
|
getLicenses: (nextUrl?: string) => Promise<_moonbase_sh_storefront_api.Page<{
|
|
41
41
|
status: _moonbase_sh_storefront_api.LicenseStatus;
|
|
42
42
|
id: string;
|
|
43
|
-
|
|
44
|
-
maxNumberOfActivations: number;
|
|
45
|
-
createdAt: Date;
|
|
46
|
-
product?: {
|
|
43
|
+
product: {
|
|
47
44
|
id: string;
|
|
48
45
|
name: string;
|
|
49
46
|
tagline: string;
|
|
@@ -63,7 +60,10 @@ declare function useInventory(): {
|
|
|
63
60
|
platform: _moonbase_sh_storefront_api.Platform;
|
|
64
61
|
size: number;
|
|
65
62
|
}[] | undefined;
|
|
66
|
-
}
|
|
63
|
+
};
|
|
64
|
+
activeNumberOfActivations: number;
|
|
65
|
+
maxNumberOfActivations: number;
|
|
66
|
+
createdAt: Date;
|
|
67
67
|
}>>;
|
|
68
68
|
getLicenseActivations: (licenseId: string, nextUrl?: string) => Promise<_moonbase_sh_storefront_api.Page<{
|
|
69
69
|
status: _moonbase_sh_storefront_api.ActivationStatus;
|
|
@@ -97,10 +97,7 @@ declare function useInventory(): {
|
|
|
97
97
|
getProductLicenses: (productId: string, nextUrl?: string) => Promise<_moonbase_sh_storefront_api.Page<{
|
|
98
98
|
status: _moonbase_sh_storefront_api.LicenseStatus;
|
|
99
99
|
id: string;
|
|
100
|
-
|
|
101
|
-
maxNumberOfActivations: number;
|
|
102
|
-
createdAt: Date;
|
|
103
|
-
product?: {
|
|
100
|
+
product: {
|
|
104
101
|
id: string;
|
|
105
102
|
name: string;
|
|
106
103
|
tagline: string;
|
|
@@ -120,7 +117,10 @@ declare function useInventory(): {
|
|
|
120
117
|
platform: _moonbase_sh_storefront_api.Platform;
|
|
121
118
|
size: number;
|
|
122
119
|
}[] | undefined;
|
|
123
|
-
}
|
|
120
|
+
};
|
|
121
|
+
activeNumberOfActivations: number;
|
|
122
|
+
maxNumberOfActivations: number;
|
|
123
|
+
createdAt: Date;
|
|
124
124
|
}>>;
|
|
125
125
|
getProductActivations: (productId: string, nextUrl?: string) => Promise<_moonbase_sh_storefront_api.Page<{
|
|
126
126
|
status: _moonbase_sh_storefront_api.ActivationStatus;
|
|
@@ -135,10 +135,7 @@ declare function useInventory(): {
|
|
|
135
135
|
license: {
|
|
136
136
|
status: _moonbase_sh_storefront_api.LicenseStatus;
|
|
137
137
|
id: string;
|
|
138
|
-
|
|
139
|
-
maxNumberOfActivations: number;
|
|
140
|
-
createdAt: Date;
|
|
141
|
-
product?: {
|
|
138
|
+
product: {
|
|
142
139
|
id: string;
|
|
143
140
|
name: string;
|
|
144
141
|
tagline: string;
|
|
@@ -158,10 +155,14 @@ declare function useInventory(): {
|
|
|
158
155
|
platform: _moonbase_sh_storefront_api.Platform;
|
|
159
156
|
size: number;
|
|
160
157
|
}[] | undefined;
|
|
161
|
-
}
|
|
158
|
+
};
|
|
159
|
+
activeNumberOfActivations: number;
|
|
160
|
+
maxNumberOfActivations: number;
|
|
161
|
+
createdAt: Date;
|
|
162
162
|
};
|
|
163
163
|
url: string;
|
|
164
164
|
}>;
|
|
165
|
+
downloadProduct: (download: Download) => Promise<void>;
|
|
165
166
|
};
|
|
166
167
|
|
|
167
168
|
declare function useActivationRequest(requestId: string): {
|
|
@@ -439,7 +440,7 @@ declare function useVoucher(): {
|
|
|
439
440
|
} | undefined;
|
|
440
441
|
}[] | undefined;
|
|
441
442
|
} & {
|
|
442
|
-
included
|
|
443
|
+
included?: boolean | undefined;
|
|
443
444
|
})[];
|
|
444
445
|
defaultVariation?: {
|
|
445
446
|
id: string;
|
|
@@ -609,7 +610,7 @@ declare function useVoucher(): {
|
|
|
609
610
|
} | undefined;
|
|
610
611
|
}[] | undefined;
|
|
611
612
|
} & {
|
|
612
|
-
included
|
|
613
|
+
included?: boolean | undefined;
|
|
613
614
|
})[];
|
|
614
615
|
defaultVariation?: {
|
|
615
616
|
id: string;
|
|
@@ -838,7 +839,7 @@ declare function useCart(): {
|
|
|
838
839
|
} | undefined;
|
|
839
840
|
}[] | undefined;
|
|
840
841
|
} & {
|
|
841
|
-
included
|
|
842
|
+
included?: boolean | undefined;
|
|
842
843
|
})[];
|
|
843
844
|
defaultVariation?: {
|
|
844
845
|
id: string;
|
|
@@ -958,8 +959,8 @@ declare function useAuth(): {
|
|
|
958
959
|
postCode: string;
|
|
959
960
|
} | undefined;
|
|
960
961
|
}>;
|
|
961
|
-
signOut: () => void
|
|
962
|
-
update: (name: string, email: string, emailConfirmationToken?: string) => Promise<{
|
|
962
|
+
signOut: () => Promise<void>;
|
|
963
|
+
update: (name: string, email: string, emailConfirmationToken?: string, communicationPreferences?: CommunicationPreferences) => Promise<{
|
|
963
964
|
needsEmailConfirmationToken: boolean;
|
|
964
965
|
}>;
|
|
965
966
|
setPassword: (currentPassword: string, newPassword: string) => Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _moonbase_sh_storefront_api from '@moonbase.sh/storefront-api';
|
|
2
|
-
import { MoonbaseConfiguration, Storefront, Order, User, MoonbaseClient, StorefrontBundle, StorefrontProduct, ActivationMethod, Activation, PricingVariation, LineItem } from '@moonbase.sh/storefront-api';
|
|
2
|
+
import { MoonbaseConfiguration, Storefront, Order, User, MoonbaseClient, StorefrontBundle, StorefrontProduct, ActivationMethod, Activation, Download, 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';
|
|
@@ -40,10 +40,7 @@ declare function useInventory(): {
|
|
|
40
40
|
getLicenses: (nextUrl?: string) => Promise<_moonbase_sh_storefront_api.Page<{
|
|
41
41
|
status: _moonbase_sh_storefront_api.LicenseStatus;
|
|
42
42
|
id: string;
|
|
43
|
-
|
|
44
|
-
maxNumberOfActivations: number;
|
|
45
|
-
createdAt: Date;
|
|
46
|
-
product?: {
|
|
43
|
+
product: {
|
|
47
44
|
id: string;
|
|
48
45
|
name: string;
|
|
49
46
|
tagline: string;
|
|
@@ -63,7 +60,10 @@ declare function useInventory(): {
|
|
|
63
60
|
platform: _moonbase_sh_storefront_api.Platform;
|
|
64
61
|
size: number;
|
|
65
62
|
}[] | undefined;
|
|
66
|
-
}
|
|
63
|
+
};
|
|
64
|
+
activeNumberOfActivations: number;
|
|
65
|
+
maxNumberOfActivations: number;
|
|
66
|
+
createdAt: Date;
|
|
67
67
|
}>>;
|
|
68
68
|
getLicenseActivations: (licenseId: string, nextUrl?: string) => Promise<_moonbase_sh_storefront_api.Page<{
|
|
69
69
|
status: _moonbase_sh_storefront_api.ActivationStatus;
|
|
@@ -97,10 +97,7 @@ declare function useInventory(): {
|
|
|
97
97
|
getProductLicenses: (productId: string, nextUrl?: string) => Promise<_moonbase_sh_storefront_api.Page<{
|
|
98
98
|
status: _moonbase_sh_storefront_api.LicenseStatus;
|
|
99
99
|
id: string;
|
|
100
|
-
|
|
101
|
-
maxNumberOfActivations: number;
|
|
102
|
-
createdAt: Date;
|
|
103
|
-
product?: {
|
|
100
|
+
product: {
|
|
104
101
|
id: string;
|
|
105
102
|
name: string;
|
|
106
103
|
tagline: string;
|
|
@@ -120,7 +117,10 @@ declare function useInventory(): {
|
|
|
120
117
|
platform: _moonbase_sh_storefront_api.Platform;
|
|
121
118
|
size: number;
|
|
122
119
|
}[] | undefined;
|
|
123
|
-
}
|
|
120
|
+
};
|
|
121
|
+
activeNumberOfActivations: number;
|
|
122
|
+
maxNumberOfActivations: number;
|
|
123
|
+
createdAt: Date;
|
|
124
124
|
}>>;
|
|
125
125
|
getProductActivations: (productId: string, nextUrl?: string) => Promise<_moonbase_sh_storefront_api.Page<{
|
|
126
126
|
status: _moonbase_sh_storefront_api.ActivationStatus;
|
|
@@ -135,10 +135,7 @@ declare function useInventory(): {
|
|
|
135
135
|
license: {
|
|
136
136
|
status: _moonbase_sh_storefront_api.LicenseStatus;
|
|
137
137
|
id: string;
|
|
138
|
-
|
|
139
|
-
maxNumberOfActivations: number;
|
|
140
|
-
createdAt: Date;
|
|
141
|
-
product?: {
|
|
138
|
+
product: {
|
|
142
139
|
id: string;
|
|
143
140
|
name: string;
|
|
144
141
|
tagline: string;
|
|
@@ -158,10 +155,14 @@ declare function useInventory(): {
|
|
|
158
155
|
platform: _moonbase_sh_storefront_api.Platform;
|
|
159
156
|
size: number;
|
|
160
157
|
}[] | undefined;
|
|
161
|
-
}
|
|
158
|
+
};
|
|
159
|
+
activeNumberOfActivations: number;
|
|
160
|
+
maxNumberOfActivations: number;
|
|
161
|
+
createdAt: Date;
|
|
162
162
|
};
|
|
163
163
|
url: string;
|
|
164
164
|
}>;
|
|
165
|
+
downloadProduct: (download: Download) => Promise<void>;
|
|
165
166
|
};
|
|
166
167
|
|
|
167
168
|
declare function useActivationRequest(requestId: string): {
|
|
@@ -439,7 +440,7 @@ declare function useVoucher(): {
|
|
|
439
440
|
} | undefined;
|
|
440
441
|
}[] | undefined;
|
|
441
442
|
} & {
|
|
442
|
-
included
|
|
443
|
+
included?: boolean | undefined;
|
|
443
444
|
})[];
|
|
444
445
|
defaultVariation?: {
|
|
445
446
|
id: string;
|
|
@@ -609,7 +610,7 @@ declare function useVoucher(): {
|
|
|
609
610
|
} | undefined;
|
|
610
611
|
}[] | undefined;
|
|
611
612
|
} & {
|
|
612
|
-
included
|
|
613
|
+
included?: boolean | undefined;
|
|
613
614
|
})[];
|
|
614
615
|
defaultVariation?: {
|
|
615
616
|
id: string;
|
|
@@ -838,7 +839,7 @@ declare function useCart(): {
|
|
|
838
839
|
} | undefined;
|
|
839
840
|
}[] | undefined;
|
|
840
841
|
} & {
|
|
841
|
-
included
|
|
842
|
+
included?: boolean | undefined;
|
|
842
843
|
})[];
|
|
843
844
|
defaultVariation?: {
|
|
844
845
|
id: string;
|
|
@@ -958,8 +959,8 @@ declare function useAuth(): {
|
|
|
958
959
|
postCode: string;
|
|
959
960
|
} | undefined;
|
|
960
961
|
}>;
|
|
961
|
-
signOut: () => void
|
|
962
|
-
update: (name: string, email: string, emailConfirmationToken?: string) => Promise<{
|
|
962
|
+
signOut: () => Promise<void>;
|
|
963
|
+
update: (name: string, email: string, emailConfirmationToken?: string, communicationPreferences?: CommunicationPreferences) => Promise<{
|
|
963
964
|
needsEmailConfirmationToken: boolean;
|
|
964
965
|
}>;
|
|
965
966
|
setPassword: (currentPassword: string, newPassword: string) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { ref as ref2 } from "vue";
|
|
|
4
4
|
|
|
5
5
|
// src/context.ts
|
|
6
6
|
import { v4 as uuidv4 } from "uuid";
|
|
7
|
-
import { ref } from "vue";
|
|
7
|
+
import { computed, ref } from "vue";
|
|
8
8
|
import { NotAuthenticatedError, OrderStatus } from "@moonbase.sh/storefront-api";
|
|
9
9
|
|
|
10
10
|
// src/symbols.ts
|
|
@@ -28,9 +28,11 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
28
28
|
this.configuration = configuration;
|
|
29
29
|
this.client = client;
|
|
30
30
|
this.stateFactory = stateFactory;
|
|
31
|
+
this.hasUtm = computed(() => !!this.utm.value && Object.values(this.utm.value).some((v) => !!v));
|
|
31
32
|
this.currentUser = ref(null);
|
|
32
33
|
this.loadedUser = ref(false);
|
|
33
|
-
this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order), 500);
|
|
34
|
+
this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order, void 0, this.hasUtm.value ? this.utm.value : void 0), 500);
|
|
35
|
+
var _a;
|
|
34
36
|
if (typeof window === "undefined") {
|
|
35
37
|
this.currentOrder = ref({
|
|
36
38
|
id: uuidv4(),
|
|
@@ -45,8 +47,18 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
45
47
|
products: []
|
|
46
48
|
});
|
|
47
49
|
this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
|
|
50
|
+
this.utm = stateFactory(`${_StorefrontContextImpl.storefrontKey}_utm`, void 0);
|
|
48
51
|
return;
|
|
49
52
|
}
|
|
53
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
54
|
+
this.utm = stateFactory(`${_StorefrontContextImpl.storefrontKey}_utm`, {
|
|
55
|
+
referrer: ((_a = window.document.referrer) == null ? void 0 : _a.replace(/https?:\/\//g, "").split("/")[0]) || void 0,
|
|
56
|
+
source: urlParams.get("utm_source") || void 0,
|
|
57
|
+
medium: urlParams.get("utm_medium") || void 0,
|
|
58
|
+
campaign: urlParams.get("utm_campaign") || void 0,
|
|
59
|
+
term: urlParams.get("utm_term") || void 0,
|
|
60
|
+
content: urlParams.get("utm_content") || void 0
|
|
61
|
+
});
|
|
50
62
|
window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
|
|
51
63
|
const cachedOrderJson = localStorage.getItem(_StorefrontContextImpl.sessionKey);
|
|
52
64
|
if (cachedOrderJson) {
|
|
@@ -92,7 +104,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
92
104
|
}
|
|
93
105
|
}
|
|
94
106
|
async updateStorefront() {
|
|
95
|
-
const latestStorefront = await this.client.storefront.get();
|
|
107
|
+
const latestStorefront = await this.client.storefront.get(this.hasUtm.value ? this.utm.value : void 0);
|
|
96
108
|
if (latestStorefront) {
|
|
97
109
|
if (typeof window !== "undefined")
|
|
98
110
|
localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
|
|
@@ -158,39 +170,39 @@ var StorefrontContextImpl = _StorefrontContextImpl;
|
|
|
158
170
|
export * from "@moonbase.sh/storefront-api";
|
|
159
171
|
|
|
160
172
|
// src/composables/useBundle.ts
|
|
161
|
-
import { computed, inject } from "vue";
|
|
173
|
+
import { computed as computed2, inject } from "vue";
|
|
162
174
|
function useBundle(bundleId) {
|
|
163
175
|
const storefront = inject(storefrontKey);
|
|
164
176
|
if (!storefront)
|
|
165
177
|
throw new Error("No storefront configured");
|
|
166
|
-
return
|
|
178
|
+
return computed2(() => storefront.storefront.value.bundles.find((b) => b.id === bundleId) || null);
|
|
167
179
|
}
|
|
168
180
|
|
|
169
181
|
// src/composables/useBundles.ts
|
|
170
|
-
import { computed as
|
|
182
|
+
import { computed as computed3, inject as inject2 } from "vue";
|
|
171
183
|
function useBundles() {
|
|
172
184
|
const storefront = inject2(storefrontKey);
|
|
173
185
|
if (!storefront)
|
|
174
186
|
throw new Error("No storefront configured");
|
|
175
|
-
return
|
|
187
|
+
return computed3(() => storefront.storefront.value.bundles);
|
|
176
188
|
}
|
|
177
189
|
|
|
178
190
|
// src/composables/useProduct.ts
|
|
179
|
-
import { computed as
|
|
191
|
+
import { computed as computed4, inject as inject3 } from "vue";
|
|
180
192
|
function useProduct(productId) {
|
|
181
193
|
const storefront = inject3(storefrontKey);
|
|
182
194
|
if (!storefront)
|
|
183
195
|
throw new Error("No storefront configured");
|
|
184
|
-
return
|
|
196
|
+
return computed4(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
|
|
185
197
|
}
|
|
186
198
|
|
|
187
199
|
// src/composables/useProducts.ts
|
|
188
|
-
import { computed as
|
|
200
|
+
import { computed as computed5, inject as inject4 } from "vue";
|
|
189
201
|
function useProducts() {
|
|
190
202
|
const storefront = inject4(storefrontKey);
|
|
191
203
|
if (!storefront)
|
|
192
204
|
throw new Error("No storefront configured");
|
|
193
|
-
return
|
|
205
|
+
return computed5(() => storefront.storefront.value.products);
|
|
194
206
|
}
|
|
195
207
|
|
|
196
208
|
// src/composables/useInventory.ts
|
|
@@ -201,32 +213,37 @@ function useInventory() {
|
|
|
201
213
|
throw new Error("No storefront configured");
|
|
202
214
|
return {
|
|
203
215
|
getLicenses: async (nextUrl) => {
|
|
204
|
-
return storefront.client.licenses.get(nextUrl);
|
|
216
|
+
return storefront.client.inventory.licenses.get(nextUrl);
|
|
205
217
|
},
|
|
206
218
|
getLicenseActivations: async (licenseId, nextUrl) => {
|
|
207
|
-
return storefront.client.licenses.getActivations(licenseId, nextUrl);
|
|
219
|
+
return storefront.client.inventory.licenses.getActivations(licenseId, nextUrl);
|
|
208
220
|
},
|
|
209
221
|
getProducts: async (nextUrl) => {
|
|
210
|
-
return storefront.client.products.getOwned(nextUrl);
|
|
222
|
+
return storefront.client.inventory.products.getOwned(nextUrl);
|
|
211
223
|
},
|
|
212
224
|
getProductLicenses: async (productId, nextUrl) => {
|
|
213
|
-
return storefront.client.products.getLicenses(productId, nextUrl);
|
|
225
|
+
return storefront.client.inventory.products.getLicenses(productId, nextUrl);
|
|
214
226
|
},
|
|
215
227
|
getProductActivations: async (productId, nextUrl) => {
|
|
216
|
-
return storefront.client.products.getActivations(productId, nextUrl);
|
|
228
|
+
return storefront.client.inventory.products.getActivations(productId, nextUrl);
|
|
217
229
|
},
|
|
218
230
|
revokeActivation: async (activation) => {
|
|
219
|
-
return storefront.client.licenses.revokeActivation(activation.licenseId, activation.id);
|
|
231
|
+
return storefront.client.inventory.licenses.revokeActivation(activation.licenseId, activation.id);
|
|
220
232
|
},
|
|
221
233
|
activateProduct: async (deviceToken, activationMethod) => {
|
|
222
|
-
return storefront.client.
|
|
234
|
+
return storefront.client.inventory.activation.activate(deviceToken, activationMethod);
|
|
235
|
+
},
|
|
236
|
+
downloadProduct: async (download) => {
|
|
237
|
+
if (!download.path)
|
|
238
|
+
throw new Error("Product is not downloadable");
|
|
239
|
+
window.location.href = await storefront.client.inventory.products.getDownloadUrl(download.path);
|
|
223
240
|
}
|
|
224
241
|
};
|
|
225
242
|
}
|
|
226
243
|
|
|
227
244
|
// src/composables/useActivationRequest.ts
|
|
228
245
|
import { ActivationRequestStatus } from "@moonbase.sh/storefront-api";
|
|
229
|
-
import { computed as
|
|
246
|
+
import { computed as computed6, inject as inject6, onBeforeUnmount, watch } from "vue";
|
|
230
247
|
function useActivationRequest(requestId) {
|
|
231
248
|
const storefront = inject6(storefrontKey);
|
|
232
249
|
if (!storefront)
|
|
@@ -266,7 +283,7 @@ function useActivationRequest(requestId) {
|
|
|
266
283
|
activationRequest,
|
|
267
284
|
loading,
|
|
268
285
|
error,
|
|
269
|
-
isInstalled:
|
|
286
|
+
isInstalled: computed6(() => {
|
|
270
287
|
var _a;
|
|
271
288
|
return activationRequest && ((_a = activationRequest.value) == null ? void 0 : _a.status) === ActivationRequestStatus.Completed;
|
|
272
289
|
}),
|
|
@@ -282,6 +299,7 @@ function useActivationRequest(requestId) {
|
|
|
282
299
|
}
|
|
283
300
|
|
|
284
301
|
// src/composables/useVoucher.ts
|
|
302
|
+
import { NotFoundError } from "@moonbase.sh/storefront-api";
|
|
285
303
|
import { inject as inject7 } from "vue";
|
|
286
304
|
function useVoucher() {
|
|
287
305
|
const storefront = inject7(storefrontKey);
|
|
@@ -289,22 +307,34 @@ function useVoucher() {
|
|
|
289
307
|
throw new Error("No storefront configured");
|
|
290
308
|
return {
|
|
291
309
|
peek: async (code) => {
|
|
292
|
-
|
|
310
|
+
try {
|
|
311
|
+
return await storefront.client.vouchers.peek(code);
|
|
312
|
+
} catch (e) {
|
|
313
|
+
if (e instanceof NotFoundError)
|
|
314
|
+
throw new Error("Voucher code invalid");
|
|
315
|
+
throw e;
|
|
316
|
+
}
|
|
293
317
|
},
|
|
294
318
|
redeem: async (code) => {
|
|
295
|
-
|
|
319
|
+
try {
|
|
320
|
+
return await storefront.client.vouchers.redeem(code);
|
|
321
|
+
} catch (e) {
|
|
322
|
+
if (e instanceof NotFoundError)
|
|
323
|
+
throw new Error("Voucher code invalid");
|
|
324
|
+
throw e;
|
|
325
|
+
}
|
|
296
326
|
}
|
|
297
327
|
};
|
|
298
328
|
}
|
|
299
329
|
|
|
300
330
|
// src/composables/useCart.ts
|
|
301
|
-
import { computed as
|
|
331
|
+
import { computed as computed7, inject as inject8, unref } from "vue";
|
|
302
332
|
function useCart() {
|
|
303
333
|
const storefront = inject8(storefrontKey);
|
|
304
334
|
if (!storefront)
|
|
305
335
|
throw new Error("No storefront configured");
|
|
306
336
|
return {
|
|
307
|
-
items:
|
|
337
|
+
items: computed7(() => storefront.currentOrder.value.items.map((item) => {
|
|
308
338
|
if (item.type === "Product") {
|
|
309
339
|
const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
|
|
310
340
|
const variations = (product == null ? void 0 : product.variations) || [];
|
|
@@ -327,8 +357,8 @@ function useCart() {
|
|
|
327
357
|
};
|
|
328
358
|
}
|
|
329
359
|
})),
|
|
330
|
-
currency:
|
|
331
|
-
total:
|
|
360
|
+
currency: computed7(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
|
|
361
|
+
total: computed7(() => {
|
|
332
362
|
const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
|
|
333
363
|
const total = storefront.currentOrder.value.items.reduce((agg, item) => {
|
|
334
364
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -444,15 +474,18 @@ function useAuth() {
|
|
|
444
474
|
const _ = storefront.updateStorefront();
|
|
445
475
|
return user;
|
|
446
476
|
},
|
|
447
|
-
signOut: () => {
|
|
477
|
+
signOut: async () => {
|
|
448
478
|
storefront.client.tokenStore.setUser(null);
|
|
479
|
+
await storefront.updateStorefront();
|
|
449
480
|
storefront.currentUser.value = null;
|
|
450
|
-
const _ = storefront.updateStorefront();
|
|
451
481
|
},
|
|
452
|
-
update: async (name, email, emailConfirmationToken) => {
|
|
453
|
-
const result = await storefront.client.identity.update(name, email, emailConfirmationToken);
|
|
454
|
-
if (storefront.currentUser.value)
|
|
482
|
+
update: async (name, email, emailConfirmationToken, communicationPreferences) => {
|
|
483
|
+
const result = await storefront.client.identity.update(name, email, emailConfirmationToken, communicationPreferences);
|
|
484
|
+
if (storefront.currentUser.value) {
|
|
455
485
|
storefront.currentUser.value.name = name;
|
|
486
|
+
if (communicationPreferences)
|
|
487
|
+
storefront.currentUser.value.communicationPreferences = communicationPreferences;
|
|
488
|
+
}
|
|
456
489
|
return result;
|
|
457
490
|
},
|
|
458
491
|
setPassword: async (currentPassword, newPassword) => {
|
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.97",
|
|
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/storefront-api": "0.1.
|
|
21
|
+
"@moonbase.sh/storefront-api": "0.1.97"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/uuid": "^9.0.7",
|