@moonbase.sh/vue 0.1.123 → 0.2.1
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 +80 -35
- package/dist/index.d.cts +30 -159
- package/dist/index.d.ts +30 -159
- package/dist/index.js +81 -36
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -97,9 +97,11 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
97
97
|
window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
|
|
98
98
|
const cachedOrderJson = localStorage.getItem(_StorefrontContextImpl.sessionKey);
|
|
99
99
|
if (cachedOrderJson) {
|
|
100
|
+
console.log("Found cached session:", cachedOrderJson);
|
|
100
101
|
this.currentOrder = (0, import_vue.ref)(JSON.parse(cachedOrderJson));
|
|
101
102
|
const _1 = this.refreshOrder();
|
|
102
103
|
} else {
|
|
104
|
+
console.log("No cached session found");
|
|
103
105
|
this.currentOrder = (0, import_vue.ref)({
|
|
104
106
|
id: (0, import_uuid.v4)(),
|
|
105
107
|
status: import_storefront_api.OrderStatus.Open,
|
|
@@ -107,7 +109,6 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
107
109
|
items: [],
|
|
108
110
|
couponsApplied: []
|
|
109
111
|
});
|
|
110
|
-
localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(this.currentOrder.value));
|
|
111
112
|
}
|
|
112
113
|
const cachedStorefrontJson = localStorage.getItem(_StorefrontContextImpl.storefrontKey);
|
|
113
114
|
if (cachedStorefrontJson) {
|
|
@@ -124,12 +125,20 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
124
125
|
const _2 = this.updateStorefront();
|
|
125
126
|
const _3 = this.updateUser();
|
|
126
127
|
}
|
|
128
|
+
get loadedStorefrontPromise() {
|
|
129
|
+
return new Promise((resolve) => {
|
|
130
|
+
(0, import_vue.watch)(this.loadedStorefront, (isLoaded) => {
|
|
131
|
+
if (isLoaded)
|
|
132
|
+
resolve();
|
|
133
|
+
}, { immediate: true });
|
|
134
|
+
});
|
|
135
|
+
}
|
|
127
136
|
get loadedUserPromise() {
|
|
128
137
|
return new Promise((resolve) => {
|
|
129
138
|
(0, import_vue.watch)(this.loadedUser, (isLoaded) => {
|
|
130
139
|
if (isLoaded)
|
|
131
140
|
resolve();
|
|
132
|
-
});
|
|
141
|
+
}, { immediate: true });
|
|
133
142
|
});
|
|
134
143
|
}
|
|
135
144
|
install(app) {
|
|
@@ -155,7 +164,6 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
155
164
|
this.loadedStorefront.value = true;
|
|
156
165
|
if (!this.currentOrder.value.currency) {
|
|
157
166
|
this.currentOrder.value.currency = latestStorefront.suggestedCurrency;
|
|
158
|
-
const _ = this.pushOrderContent();
|
|
159
167
|
}
|
|
160
168
|
}
|
|
161
169
|
}
|
|
@@ -201,7 +209,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
201
209
|
couponsApplied: []
|
|
202
210
|
};
|
|
203
211
|
if (typeof window !== "undefined")
|
|
204
|
-
localStorage.
|
|
212
|
+
localStorage.removeItem(_StorefrontContextImpl.sessionKey);
|
|
205
213
|
}
|
|
206
214
|
};
|
|
207
215
|
_StorefrontContextImpl.userKey = "moonbase_user";
|
|
@@ -214,8 +222,8 @@ __reExport(src_exports, require("@moonbase.sh/storefront-api"), module.exports);
|
|
|
214
222
|
|
|
215
223
|
// src/composables/useBundle.ts
|
|
216
224
|
var import_vue2 = require("vue");
|
|
217
|
-
function useBundle(bundleId) {
|
|
218
|
-
const storefront = (0, import_vue2.inject)(storefrontKey);
|
|
225
|
+
function useBundle(bundleId, context) {
|
|
226
|
+
const storefront = context != null ? context : (0, import_vue2.inject)(storefrontKey);
|
|
219
227
|
if (!storefront)
|
|
220
228
|
throw new Error("No storefront configured");
|
|
221
229
|
return (0, import_vue2.computed)(() => storefront.storefront.value.bundles.find((b) => b.id === bundleId) || null);
|
|
@@ -223,8 +231,8 @@ function useBundle(bundleId) {
|
|
|
223
231
|
|
|
224
232
|
// src/composables/useBundles.ts
|
|
225
233
|
var import_vue3 = require("vue");
|
|
226
|
-
function useBundles() {
|
|
227
|
-
const storefront = (0, import_vue3.inject)(storefrontKey);
|
|
234
|
+
function useBundles(context) {
|
|
235
|
+
const storefront = context != null ? context : (0, import_vue3.inject)(storefrontKey);
|
|
228
236
|
if (!storefront)
|
|
229
237
|
throw new Error("No storefront configured");
|
|
230
238
|
return (0, import_vue3.computed)(() => storefront.storefront.value.bundles);
|
|
@@ -232,8 +240,8 @@ function useBundles() {
|
|
|
232
240
|
|
|
233
241
|
// src/composables/useProduct.ts
|
|
234
242
|
var import_vue4 = require("vue");
|
|
235
|
-
function useProduct(productId) {
|
|
236
|
-
const storefront = (0, import_vue4.inject)(storefrontKey);
|
|
243
|
+
function useProduct(productId, context) {
|
|
244
|
+
const storefront = context != null ? context : (0, import_vue4.inject)(storefrontKey);
|
|
237
245
|
if (!storefront)
|
|
238
246
|
throw new Error("No storefront configured");
|
|
239
247
|
return (0, import_vue4.computed)(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
|
|
@@ -241,8 +249,8 @@ function useProduct(productId) {
|
|
|
241
249
|
|
|
242
250
|
// src/composables/useProducts.ts
|
|
243
251
|
var import_vue5 = require("vue");
|
|
244
|
-
function useProducts() {
|
|
245
|
-
const storefront = (0, import_vue5.inject)(storefrontKey);
|
|
252
|
+
function useProducts(context) {
|
|
253
|
+
const storefront = context != null ? context : (0, import_vue5.inject)(storefrontKey);
|
|
246
254
|
if (!storefront)
|
|
247
255
|
throw new Error("No storefront configured");
|
|
248
256
|
return (0, import_vue5.computed)(() => storefront.storefront.value.products);
|
|
@@ -250,8 +258,8 @@ function useProducts() {
|
|
|
250
258
|
|
|
251
259
|
// src/composables/useInventory.ts
|
|
252
260
|
var import_vue6 = require("vue");
|
|
253
|
-
function useInventory() {
|
|
254
|
-
const storefront = (0, import_vue6.inject)(storefrontKey);
|
|
261
|
+
function useInventory(context) {
|
|
262
|
+
const storefront = context != null ? context : (0, import_vue6.inject)(storefrontKey);
|
|
255
263
|
if (!storefront)
|
|
256
264
|
throw new Error("No storefront configured");
|
|
257
265
|
return {
|
|
@@ -287,56 +295,93 @@ function useInventory() {
|
|
|
287
295
|
// src/composables/useActivationRequest.ts
|
|
288
296
|
var import_storefront_api2 = require("@moonbase.sh/storefront-api");
|
|
289
297
|
var import_vue7 = require("vue");
|
|
290
|
-
function useActivationRequest(
|
|
291
|
-
const storefront = (0, import_vue7.inject)(storefrontKey);
|
|
298
|
+
function useActivationRequest(token, context) {
|
|
299
|
+
const storefront = context != null ? context : (0, import_vue7.inject)(storefrontKey);
|
|
300
|
+
const requestId = (0, import_vue7.toValue)(token);
|
|
301
|
+
if (!requestId)
|
|
302
|
+
throw new Error("No request ID was given when calling `useActivationRequest`");
|
|
292
303
|
if (!storefront)
|
|
293
304
|
throw new Error("No storefront configured");
|
|
294
305
|
const activationRequest = storefront.stateFactory(`activation-request-${requestId}`, null);
|
|
295
306
|
const error = storefront.stateFactory(`activation-request-${requestId}-error`, null);
|
|
296
307
|
const loading = storefront.stateFactory(`activation-request-${requestId}-loading`, true);
|
|
308
|
+
const fulfilling = storefront.stateFactory(`activation-request-${requestId}-fulfilling`, false);
|
|
309
|
+
const completing = storefront.stateFactory(`activation-request-${requestId}-completing`, false);
|
|
297
310
|
const completionTimeout = storefront.stateFactory(`activation-request-${requestId}-completion-timeout`, null);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
311
|
+
const checkCompletion = async () => {
|
|
312
|
+
const completed = await storefront.client.activationRequests.isCompleted(requestId);
|
|
313
|
+
if (completed && activationRequest.value) {
|
|
314
|
+
activationRequest.value.status = import_storefront_api2.ActivationRequestStatus.Completed;
|
|
315
|
+
completing.value = false;
|
|
316
|
+
} else {
|
|
317
|
+
completionTimeout.value = setTimeout(checkCompletion, 1500);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
if (requestId && requestId.length > 0) {
|
|
321
|
+
storefront.client.activationRequests.get(requestId).then((result) => {
|
|
322
|
+
activationRequest.value = result;
|
|
323
|
+
if (activationRequest.value.status === import_storefront_api2.ActivationRequestStatus.Fulfilled) {
|
|
324
|
+
completing.value = true;
|
|
325
|
+
checkCompletion();
|
|
326
|
+
}
|
|
327
|
+
loading.value = false;
|
|
328
|
+
}).catch((e) => {
|
|
329
|
+
error.value = e;
|
|
330
|
+
loading.value = false;
|
|
331
|
+
});
|
|
332
|
+
} else {
|
|
333
|
+
error.value = new Error("Missing request id");
|
|
303
334
|
loading.value = false;
|
|
304
|
-
}
|
|
335
|
+
}
|
|
305
336
|
(0, import_vue7.onBeforeUnmount)(() => {
|
|
306
337
|
if (completionTimeout.value)
|
|
307
338
|
clearTimeout(completionTimeout.value);
|
|
308
339
|
});
|
|
309
340
|
(0, import_vue7.watch)(storefront.currentUser, async () => {
|
|
341
|
+
var _a, _b;
|
|
342
|
+
if (!requestId || ((_b = (_a = activationRequest.value) == null ? void 0 : _a.licenseEligibility) == null ? void 0 : _b.eligible))
|
|
343
|
+
return;
|
|
310
344
|
loading.value = true;
|
|
311
345
|
try {
|
|
312
346
|
activationRequest.value = await storefront.client.activationRequests.get(requestId);
|
|
347
|
+
if (activationRequest.value.status === import_storefront_api2.ActivationRequestStatus.Fulfilled) {
|
|
348
|
+
completing.value = true;
|
|
349
|
+
checkCompletion();
|
|
350
|
+
}
|
|
313
351
|
} catch (e) {
|
|
314
352
|
error.value = e;
|
|
315
353
|
}
|
|
316
354
|
loading.value = false;
|
|
317
355
|
});
|
|
318
|
-
const checkCompletion = async () => {
|
|
319
|
-
const completed = await storefront.client.activationRequests.isCompleted(requestId);
|
|
320
|
-
if (completed && activationRequest.value)
|
|
321
|
-
activationRequest.value.status = import_storefront_api2.ActivationRequestStatus.Completed;
|
|
322
|
-
else
|
|
323
|
-
completionTimeout.value = setTimeout(checkCompletion, 1500);
|
|
324
|
-
};
|
|
325
356
|
return {
|
|
326
357
|
activationRequest,
|
|
327
358
|
loading,
|
|
359
|
+
fulfilling,
|
|
360
|
+
completing,
|
|
328
361
|
error,
|
|
329
362
|
isInstalled: (0, import_vue7.computed)(() => {
|
|
330
363
|
var _a;
|
|
331
364
|
return activationRequest && ((_a = activationRequest.value) == null ? void 0 : _a.status) === import_storefront_api2.ActivationRequestStatus.Completed;
|
|
332
365
|
}),
|
|
333
366
|
fulfillLicense: async () => {
|
|
367
|
+
fulfilling.value = true;
|
|
334
368
|
activationRequest.value = await storefront.client.activationRequests.fulfillLicense(requestId);
|
|
369
|
+
fulfilling.value = false;
|
|
370
|
+
completing.value = true;
|
|
335
371
|
const _ = checkCompletion();
|
|
336
372
|
},
|
|
337
373
|
fulfillTrial: async () => {
|
|
374
|
+
fulfilling.value = true;
|
|
338
375
|
activationRequest.value = await storefront.client.activationRequests.fulfillTrial(requestId);
|
|
376
|
+
fulfilling.value = false;
|
|
377
|
+
completing.value = true;
|
|
339
378
|
const _ = checkCompletion();
|
|
379
|
+
},
|
|
380
|
+
cancel: async () => {
|
|
381
|
+
var _a;
|
|
382
|
+
if (((_a = activationRequest.value) == null ? void 0 : _a.status) === import_storefront_api2.ActivationRequestStatus.Cancelled)
|
|
383
|
+
return;
|
|
384
|
+
activationRequest.value = await storefront.client.activationRequests.cancel(requestId);
|
|
340
385
|
}
|
|
341
386
|
};
|
|
342
387
|
}
|
|
@@ -344,8 +389,8 @@ function useActivationRequest(requestId) {
|
|
|
344
389
|
// src/composables/useVoucher.ts
|
|
345
390
|
var import_storefront_api3 = require("@moonbase.sh/storefront-api");
|
|
346
391
|
var import_vue8 = require("vue");
|
|
347
|
-
function useVoucher() {
|
|
348
|
-
const storefront = (0, import_vue8.inject)(storefrontKey);
|
|
392
|
+
function useVoucher(context) {
|
|
393
|
+
const storefront = context != null ? context : (0, import_vue8.inject)(storefrontKey);
|
|
349
394
|
if (!storefront)
|
|
350
395
|
throw new Error("No storefront configured");
|
|
351
396
|
return {
|
|
@@ -372,8 +417,8 @@ function useVoucher() {
|
|
|
372
417
|
|
|
373
418
|
// src/composables/useCart.ts
|
|
374
419
|
var import_vue9 = require("vue");
|
|
375
|
-
function useCart() {
|
|
376
|
-
const storefront = (0, import_vue9.inject)(storefrontKey);
|
|
420
|
+
function useCart(context) {
|
|
421
|
+
const storefront = context != null ? context : (0, import_vue9.inject)(storefrontKey);
|
|
377
422
|
if (!storefront)
|
|
378
423
|
throw new Error("No storefront configured");
|
|
379
424
|
return {
|
|
@@ -491,8 +536,8 @@ function useCart() {
|
|
|
491
536
|
|
|
492
537
|
// src/composables/useAuth.ts
|
|
493
538
|
var import_vue10 = require("vue");
|
|
494
|
-
function useAuth() {
|
|
495
|
-
const storefront = (0, import_vue10.inject)(storefrontKey);
|
|
539
|
+
function useAuth(context) {
|
|
540
|
+
const storefront = context != null ? context : (0, import_vue10.inject)(storefrontKey);
|
|
496
541
|
if (!storefront)
|
|
497
542
|
throw new Error("No storefront configured");
|
|
498
543
|
return {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
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, PricingVariation, CommunicationPreferences, LineItem } 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';
|
|
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';
|
|
6
|
-
import * as _moonbase_sh_storefront_api_src from '@moonbase.sh/storefront-api/src';
|
|
7
6
|
import { Address } from '@moonbase.sh/storefront-api/src';
|
|
8
7
|
|
|
9
8
|
interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
@@ -11,13 +10,14 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
|
11
10
|
stateFactory: StateFactory;
|
|
12
11
|
storefront: Ref<Storefront>;
|
|
13
12
|
loadedStorefront: Ref<boolean>;
|
|
13
|
+
loadedStorefrontPromise: Promise<void>;
|
|
14
14
|
currentOrder: Ref<Order>;
|
|
15
15
|
currentUser: Ref<User | null>;
|
|
16
16
|
loadedUser: Ref<boolean>;
|
|
17
17
|
loadedUserPromise: Promise<void>;
|
|
18
18
|
client: MoonbaseClient;
|
|
19
|
-
updateStorefront()
|
|
20
|
-
pushOrderContent()
|
|
19
|
+
updateStorefront: () => Promise<void>;
|
|
20
|
+
pushOrderContent: () => Promise<void>;
|
|
21
21
|
/**
|
|
22
22
|
* Called automatically by `app.use(storefront)`. Should not be called manually by
|
|
23
23
|
* the user.
|
|
@@ -25,19 +25,19 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
|
25
25
|
* @internal
|
|
26
26
|
* @param app - Application that uses the storefront
|
|
27
27
|
*/
|
|
28
|
-
install(app: App)
|
|
28
|
+
install: (app: App) => any;
|
|
29
29
|
}
|
|
30
30
|
type StateFactory = <T>(key: string, state: T) => Ref<T> | Ref<UnwrapRef<T>>;
|
|
31
31
|
|
|
32
|
-
declare function useBundle(bundleId: string): Ref<StorefrontBundle | null>;
|
|
32
|
+
declare function useBundle(bundleId: string, context?: StorefrontContext): Ref<StorefrontBundle | null>;
|
|
33
33
|
|
|
34
|
-
declare function useBundles(): Ref<StorefrontBundle[]>;
|
|
34
|
+
declare function useBundles(context?: StorefrontContext): Ref<StorefrontBundle[]>;
|
|
35
35
|
|
|
36
|
-
declare function useProduct(productId: string): Ref<StorefrontProduct | null>;
|
|
36
|
+
declare function useProduct(productId: string, context?: StorefrontContext): Ref<StorefrontProduct | null>;
|
|
37
37
|
|
|
38
|
-
declare function useProducts(): Ref<StorefrontProduct[]>;
|
|
38
|
+
declare function useProducts(context?: StorefrontContext): Ref<StorefrontProduct[]>;
|
|
39
39
|
|
|
40
|
-
declare function useInventory(): {
|
|
40
|
+
declare function useInventory(context?: StorefrontContext): {
|
|
41
41
|
getLicenses: (nextUrl?: string) => Promise<_moonbase_sh_storefront_api.Page<{
|
|
42
42
|
status: _moonbase_sh_storefront_api.LicenseStatus;
|
|
43
43
|
id: string;
|
|
@@ -166,155 +166,20 @@ declare function useInventory(): {
|
|
|
166
166
|
downloadProduct: (download: Download) => Promise<void>;
|
|
167
167
|
};
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
activationRequest:
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
name: string;
|
|
177
|
-
tagline: string;
|
|
178
|
-
iconUrl: string | null;
|
|
179
|
-
owned: boolean;
|
|
180
|
-
currentVersion?: string | undefined;
|
|
181
|
-
downloads?: {
|
|
182
|
-
name: string;
|
|
183
|
-
path: string | null;
|
|
184
|
-
key: string;
|
|
185
|
-
platform: _moonbase_sh_storefront_api_src.Platform;
|
|
186
|
-
size: number;
|
|
187
|
-
}[] | undefined;
|
|
188
|
-
defaultVariation?: {
|
|
189
|
-
id: string;
|
|
190
|
-
price: Record<string, number>;
|
|
191
|
-
name: string;
|
|
192
|
-
originalPrice: Record<string, number>;
|
|
193
|
-
hasDiscount: boolean;
|
|
194
|
-
discount?: {
|
|
195
|
-
type: "PercentageOffDiscount";
|
|
196
|
-
name: string;
|
|
197
|
-
percentage: number;
|
|
198
|
-
total: Record<string, number>;
|
|
199
|
-
description?: string | undefined;
|
|
200
|
-
} | {
|
|
201
|
-
type: "FlatAmountOffDiscount";
|
|
202
|
-
name: string;
|
|
203
|
-
total: Record<string, number>;
|
|
204
|
-
description?: string | undefined;
|
|
205
|
-
} | undefined;
|
|
206
|
-
} | undefined;
|
|
207
|
-
variations?: {
|
|
208
|
-
id: string;
|
|
209
|
-
price: Record<string, number>;
|
|
210
|
-
name: string;
|
|
211
|
-
originalPrice: Record<string, number>;
|
|
212
|
-
hasDiscount: boolean;
|
|
213
|
-
discount?: {
|
|
214
|
-
type: "PercentageOffDiscount";
|
|
215
|
-
name: string;
|
|
216
|
-
percentage: number;
|
|
217
|
-
total: Record<string, number>;
|
|
218
|
-
description?: string | undefined;
|
|
219
|
-
} | {
|
|
220
|
-
type: "FlatAmountOffDiscount";
|
|
221
|
-
name: string;
|
|
222
|
-
total: Record<string, number>;
|
|
223
|
-
description?: string | undefined;
|
|
224
|
-
} | undefined;
|
|
225
|
-
}[] | undefined;
|
|
226
|
-
};
|
|
227
|
-
trialEligibility?: {
|
|
228
|
-
eligible: boolean;
|
|
229
|
-
existing: boolean;
|
|
230
|
-
requiresAccount: boolean;
|
|
231
|
-
numberOfDaysPerProduct: number;
|
|
232
|
-
numberOfDaysRemaining: number;
|
|
233
|
-
} | undefined;
|
|
234
|
-
licenseEligibility?: {
|
|
235
|
-
eligible: boolean;
|
|
236
|
-
} | undefined;
|
|
237
|
-
} | null> | vue.Ref<{
|
|
238
|
-
status: _moonbase_sh_storefront_api_src.ActivationRequestStatus;
|
|
239
|
-
id: string;
|
|
240
|
-
product: {
|
|
241
|
-
type: "product";
|
|
242
|
-
id: string;
|
|
243
|
-
name: string;
|
|
244
|
-
tagline: string;
|
|
245
|
-
iconUrl: string | null;
|
|
246
|
-
owned: boolean;
|
|
247
|
-
currentVersion?: string | undefined;
|
|
248
|
-
downloads?: {
|
|
249
|
-
name: string;
|
|
250
|
-
path: string | null;
|
|
251
|
-
key: string;
|
|
252
|
-
platform: _moonbase_sh_storefront_api_src.Platform;
|
|
253
|
-
size: number;
|
|
254
|
-
}[] | undefined;
|
|
255
|
-
defaultVariation?: {
|
|
256
|
-
id: string;
|
|
257
|
-
price: Record<string, number>;
|
|
258
|
-
name: string;
|
|
259
|
-
originalPrice: Record<string, number>;
|
|
260
|
-
hasDiscount: boolean;
|
|
261
|
-
discount?: {
|
|
262
|
-
type: "PercentageOffDiscount";
|
|
263
|
-
name: string;
|
|
264
|
-
percentage: number;
|
|
265
|
-
total: Record<string, number>;
|
|
266
|
-
description?: string | undefined;
|
|
267
|
-
} | {
|
|
268
|
-
type: "FlatAmountOffDiscount";
|
|
269
|
-
name: string;
|
|
270
|
-
total: Record<string, number>;
|
|
271
|
-
description?: string | undefined;
|
|
272
|
-
} | undefined;
|
|
273
|
-
} | undefined;
|
|
274
|
-
variations?: {
|
|
275
|
-
id: string;
|
|
276
|
-
price: Record<string, number>;
|
|
277
|
-
name: string;
|
|
278
|
-
originalPrice: Record<string, number>;
|
|
279
|
-
hasDiscount: boolean;
|
|
280
|
-
discount?: {
|
|
281
|
-
type: "PercentageOffDiscount";
|
|
282
|
-
name: string;
|
|
283
|
-
percentage: number;
|
|
284
|
-
total: Record<string, number>;
|
|
285
|
-
description?: string | undefined;
|
|
286
|
-
} | {
|
|
287
|
-
type: "FlatAmountOffDiscount";
|
|
288
|
-
name: string;
|
|
289
|
-
total: Record<string, number>;
|
|
290
|
-
description?: string | undefined;
|
|
291
|
-
} | undefined;
|
|
292
|
-
}[] | undefined;
|
|
293
|
-
};
|
|
294
|
-
trialEligibility?: {
|
|
295
|
-
eligible: boolean;
|
|
296
|
-
existing: boolean;
|
|
297
|
-
requiresAccount: boolean;
|
|
298
|
-
numberOfDaysPerProduct: number;
|
|
299
|
-
numberOfDaysRemaining: number;
|
|
300
|
-
} | undefined;
|
|
301
|
-
licenseEligibility?: {
|
|
302
|
-
eligible: boolean;
|
|
303
|
-
} | undefined;
|
|
304
|
-
} | null>;
|
|
305
|
-
loading: vue.Ref<boolean>;
|
|
306
|
-
error: vue.Ref<Error | null> | vue.Ref<{
|
|
307
|
-
name: string;
|
|
308
|
-
message: string;
|
|
309
|
-
stack?: string | undefined;
|
|
310
|
-
cause?: unknown;
|
|
311
|
-
} | null>;
|
|
312
|
-
isInstalled: vue.ComputedRef<boolean>;
|
|
169
|
+
interface ActivationRequestComposable {
|
|
170
|
+
activationRequest: Ref<null | ActivationRequest>;
|
|
171
|
+
loading: Ref<boolean>;
|
|
172
|
+
fulfilling: Ref<boolean>;
|
|
173
|
+
completing: Ref<boolean>;
|
|
174
|
+
error: Ref<null | Error>;
|
|
175
|
+
isInstalled: Ref<boolean>;
|
|
313
176
|
fulfillLicense: () => Promise<void>;
|
|
314
177
|
fulfillTrial: () => Promise<void>;
|
|
315
|
-
|
|
178
|
+
cancel: () => Promise<void>;
|
|
179
|
+
}
|
|
180
|
+
declare function useActivationRequest(token: string | Ref<string>, context?: StorefrontContext): ActivationRequestComposable;
|
|
316
181
|
|
|
317
|
-
declare function useVoucher(): {
|
|
182
|
+
declare function useVoucher(context?: StorefrontContext): {
|
|
318
183
|
peek: (code: string) => Promise<{
|
|
319
184
|
code: string;
|
|
320
185
|
id: string;
|
|
@@ -329,6 +194,7 @@ declare function useVoucher(): {
|
|
|
329
194
|
tagline: string;
|
|
330
195
|
iconUrl: string | null;
|
|
331
196
|
owned: boolean;
|
|
197
|
+
website?: string | null | undefined;
|
|
332
198
|
currentVersion?: string | undefined;
|
|
333
199
|
downloads?: {
|
|
334
200
|
path: string | null;
|
|
@@ -394,6 +260,7 @@ declare function useVoucher(): {
|
|
|
394
260
|
tagline: string;
|
|
395
261
|
iconUrl: string | null;
|
|
396
262
|
owned: boolean;
|
|
263
|
+
website?: string | null | undefined;
|
|
397
264
|
currentVersion?: string | undefined;
|
|
398
265
|
downloads?: {
|
|
399
266
|
path: string | null;
|
|
@@ -499,6 +366,7 @@ declare function useVoucher(): {
|
|
|
499
366
|
tagline: string;
|
|
500
367
|
iconUrl: string | null;
|
|
501
368
|
owned: boolean;
|
|
369
|
+
website?: string | null | undefined;
|
|
502
370
|
currentVersion?: string | undefined;
|
|
503
371
|
downloads?: {
|
|
504
372
|
path: string | null;
|
|
@@ -564,6 +432,7 @@ declare function useVoucher(): {
|
|
|
564
432
|
tagline: string;
|
|
565
433
|
iconUrl: string | null;
|
|
566
434
|
owned: boolean;
|
|
435
|
+
website?: string | null | undefined;
|
|
567
436
|
currentVersion?: string | undefined;
|
|
568
437
|
downloads?: {
|
|
569
438
|
path: string | null;
|
|
@@ -657,7 +526,7 @@ declare function useVoucher(): {
|
|
|
657
526
|
}>;
|
|
658
527
|
};
|
|
659
528
|
|
|
660
|
-
declare function useCart(): {
|
|
529
|
+
declare function useCart(context?: StorefrontContext): {
|
|
661
530
|
items: vue.ComputedRef<({
|
|
662
531
|
type: "Product";
|
|
663
532
|
id: string;
|
|
@@ -691,6 +560,7 @@ declare function useCart(): {
|
|
|
691
560
|
tagline: string;
|
|
692
561
|
iconUrl: string | null;
|
|
693
562
|
owned: boolean;
|
|
563
|
+
website?: string | null | undefined;
|
|
694
564
|
currentVersion?: string | undefined;
|
|
695
565
|
downloads?: {
|
|
696
566
|
path: string | null;
|
|
@@ -793,6 +663,7 @@ declare function useCart(): {
|
|
|
793
663
|
tagline: string;
|
|
794
664
|
iconUrl: string | null;
|
|
795
665
|
owned: boolean;
|
|
666
|
+
website?: string | null | undefined;
|
|
796
667
|
currentVersion?: string | undefined;
|
|
797
668
|
downloads?: {
|
|
798
669
|
path: string | null;
|
|
@@ -907,7 +778,7 @@ declare function useCart(): {
|
|
|
907
778
|
checkout: (returnUrl: string) => Promise<void>;
|
|
908
779
|
};
|
|
909
780
|
|
|
910
|
-
declare function useAuth(): {
|
|
781
|
+
declare function useAuth(context?: StorefrontContext): {
|
|
911
782
|
user: vue.Ref<{
|
|
912
783
|
id: string;
|
|
913
784
|
email: string;
|
|
@@ -989,4 +860,4 @@ interface Cart {
|
|
|
989
860
|
type CartItem = LineItem;
|
|
990
861
|
declare function createStorefront(endpoint: string, stateFactory?: StateFactory): StorefrontContext;
|
|
991
862
|
|
|
992
|
-
export { type Cart, type CartItem, createStorefront, storefrontKey, useActivationRequest, useAuth, useBundle, useBundles, useCart, useInventory, useProduct, useProducts, useVoucher };
|
|
863
|
+
export { type ActivationRequestComposable, type Cart, type CartItem, createStorefront, storefrontKey, useActivationRequest, useAuth, useBundle, useBundles, useCart, useInventory, useProduct, useProducts, useVoucher };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
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, PricingVariation, CommunicationPreferences, LineItem } 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';
|
|
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';
|
|
6
|
-
import * as _moonbase_sh_storefront_api_src from '@moonbase.sh/storefront-api/src';
|
|
7
6
|
import { Address } from '@moonbase.sh/storefront-api/src';
|
|
8
7
|
|
|
9
8
|
interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
@@ -11,13 +10,14 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
|
11
10
|
stateFactory: StateFactory;
|
|
12
11
|
storefront: Ref<Storefront>;
|
|
13
12
|
loadedStorefront: Ref<boolean>;
|
|
13
|
+
loadedStorefrontPromise: Promise<void>;
|
|
14
14
|
currentOrder: Ref<Order>;
|
|
15
15
|
currentUser: Ref<User | null>;
|
|
16
16
|
loadedUser: Ref<boolean>;
|
|
17
17
|
loadedUserPromise: Promise<void>;
|
|
18
18
|
client: MoonbaseClient;
|
|
19
|
-
updateStorefront()
|
|
20
|
-
pushOrderContent()
|
|
19
|
+
updateStorefront: () => Promise<void>;
|
|
20
|
+
pushOrderContent: () => Promise<void>;
|
|
21
21
|
/**
|
|
22
22
|
* Called automatically by `app.use(storefront)`. Should not be called manually by
|
|
23
23
|
* the user.
|
|
@@ -25,19 +25,19 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
|
25
25
|
* @internal
|
|
26
26
|
* @param app - Application that uses the storefront
|
|
27
27
|
*/
|
|
28
|
-
install(app: App)
|
|
28
|
+
install: (app: App) => any;
|
|
29
29
|
}
|
|
30
30
|
type StateFactory = <T>(key: string, state: T) => Ref<T> | Ref<UnwrapRef<T>>;
|
|
31
31
|
|
|
32
|
-
declare function useBundle(bundleId: string): Ref<StorefrontBundle | null>;
|
|
32
|
+
declare function useBundle(bundleId: string, context?: StorefrontContext): Ref<StorefrontBundle | null>;
|
|
33
33
|
|
|
34
|
-
declare function useBundles(): Ref<StorefrontBundle[]>;
|
|
34
|
+
declare function useBundles(context?: StorefrontContext): Ref<StorefrontBundle[]>;
|
|
35
35
|
|
|
36
|
-
declare function useProduct(productId: string): Ref<StorefrontProduct | null>;
|
|
36
|
+
declare function useProduct(productId: string, context?: StorefrontContext): Ref<StorefrontProduct | null>;
|
|
37
37
|
|
|
38
|
-
declare function useProducts(): Ref<StorefrontProduct[]>;
|
|
38
|
+
declare function useProducts(context?: StorefrontContext): Ref<StorefrontProduct[]>;
|
|
39
39
|
|
|
40
|
-
declare function useInventory(): {
|
|
40
|
+
declare function useInventory(context?: StorefrontContext): {
|
|
41
41
|
getLicenses: (nextUrl?: string) => Promise<_moonbase_sh_storefront_api.Page<{
|
|
42
42
|
status: _moonbase_sh_storefront_api.LicenseStatus;
|
|
43
43
|
id: string;
|
|
@@ -166,155 +166,20 @@ declare function useInventory(): {
|
|
|
166
166
|
downloadProduct: (download: Download) => Promise<void>;
|
|
167
167
|
};
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
activationRequest:
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
name: string;
|
|
177
|
-
tagline: string;
|
|
178
|
-
iconUrl: string | null;
|
|
179
|
-
owned: boolean;
|
|
180
|
-
currentVersion?: string | undefined;
|
|
181
|
-
downloads?: {
|
|
182
|
-
name: string;
|
|
183
|
-
path: string | null;
|
|
184
|
-
key: string;
|
|
185
|
-
platform: _moonbase_sh_storefront_api_src.Platform;
|
|
186
|
-
size: number;
|
|
187
|
-
}[] | undefined;
|
|
188
|
-
defaultVariation?: {
|
|
189
|
-
id: string;
|
|
190
|
-
price: Record<string, number>;
|
|
191
|
-
name: string;
|
|
192
|
-
originalPrice: Record<string, number>;
|
|
193
|
-
hasDiscount: boolean;
|
|
194
|
-
discount?: {
|
|
195
|
-
type: "PercentageOffDiscount";
|
|
196
|
-
name: string;
|
|
197
|
-
percentage: number;
|
|
198
|
-
total: Record<string, number>;
|
|
199
|
-
description?: string | undefined;
|
|
200
|
-
} | {
|
|
201
|
-
type: "FlatAmountOffDiscount";
|
|
202
|
-
name: string;
|
|
203
|
-
total: Record<string, number>;
|
|
204
|
-
description?: string | undefined;
|
|
205
|
-
} | undefined;
|
|
206
|
-
} | undefined;
|
|
207
|
-
variations?: {
|
|
208
|
-
id: string;
|
|
209
|
-
price: Record<string, number>;
|
|
210
|
-
name: string;
|
|
211
|
-
originalPrice: Record<string, number>;
|
|
212
|
-
hasDiscount: boolean;
|
|
213
|
-
discount?: {
|
|
214
|
-
type: "PercentageOffDiscount";
|
|
215
|
-
name: string;
|
|
216
|
-
percentage: number;
|
|
217
|
-
total: Record<string, number>;
|
|
218
|
-
description?: string | undefined;
|
|
219
|
-
} | {
|
|
220
|
-
type: "FlatAmountOffDiscount";
|
|
221
|
-
name: string;
|
|
222
|
-
total: Record<string, number>;
|
|
223
|
-
description?: string | undefined;
|
|
224
|
-
} | undefined;
|
|
225
|
-
}[] | undefined;
|
|
226
|
-
};
|
|
227
|
-
trialEligibility?: {
|
|
228
|
-
eligible: boolean;
|
|
229
|
-
existing: boolean;
|
|
230
|
-
requiresAccount: boolean;
|
|
231
|
-
numberOfDaysPerProduct: number;
|
|
232
|
-
numberOfDaysRemaining: number;
|
|
233
|
-
} | undefined;
|
|
234
|
-
licenseEligibility?: {
|
|
235
|
-
eligible: boolean;
|
|
236
|
-
} | undefined;
|
|
237
|
-
} | null> | vue.Ref<{
|
|
238
|
-
status: _moonbase_sh_storefront_api_src.ActivationRequestStatus;
|
|
239
|
-
id: string;
|
|
240
|
-
product: {
|
|
241
|
-
type: "product";
|
|
242
|
-
id: string;
|
|
243
|
-
name: string;
|
|
244
|
-
tagline: string;
|
|
245
|
-
iconUrl: string | null;
|
|
246
|
-
owned: boolean;
|
|
247
|
-
currentVersion?: string | undefined;
|
|
248
|
-
downloads?: {
|
|
249
|
-
name: string;
|
|
250
|
-
path: string | null;
|
|
251
|
-
key: string;
|
|
252
|
-
platform: _moonbase_sh_storefront_api_src.Platform;
|
|
253
|
-
size: number;
|
|
254
|
-
}[] | undefined;
|
|
255
|
-
defaultVariation?: {
|
|
256
|
-
id: string;
|
|
257
|
-
price: Record<string, number>;
|
|
258
|
-
name: string;
|
|
259
|
-
originalPrice: Record<string, number>;
|
|
260
|
-
hasDiscount: boolean;
|
|
261
|
-
discount?: {
|
|
262
|
-
type: "PercentageOffDiscount";
|
|
263
|
-
name: string;
|
|
264
|
-
percentage: number;
|
|
265
|
-
total: Record<string, number>;
|
|
266
|
-
description?: string | undefined;
|
|
267
|
-
} | {
|
|
268
|
-
type: "FlatAmountOffDiscount";
|
|
269
|
-
name: string;
|
|
270
|
-
total: Record<string, number>;
|
|
271
|
-
description?: string | undefined;
|
|
272
|
-
} | undefined;
|
|
273
|
-
} | undefined;
|
|
274
|
-
variations?: {
|
|
275
|
-
id: string;
|
|
276
|
-
price: Record<string, number>;
|
|
277
|
-
name: string;
|
|
278
|
-
originalPrice: Record<string, number>;
|
|
279
|
-
hasDiscount: boolean;
|
|
280
|
-
discount?: {
|
|
281
|
-
type: "PercentageOffDiscount";
|
|
282
|
-
name: string;
|
|
283
|
-
percentage: number;
|
|
284
|
-
total: Record<string, number>;
|
|
285
|
-
description?: string | undefined;
|
|
286
|
-
} | {
|
|
287
|
-
type: "FlatAmountOffDiscount";
|
|
288
|
-
name: string;
|
|
289
|
-
total: Record<string, number>;
|
|
290
|
-
description?: string | undefined;
|
|
291
|
-
} | undefined;
|
|
292
|
-
}[] | undefined;
|
|
293
|
-
};
|
|
294
|
-
trialEligibility?: {
|
|
295
|
-
eligible: boolean;
|
|
296
|
-
existing: boolean;
|
|
297
|
-
requiresAccount: boolean;
|
|
298
|
-
numberOfDaysPerProduct: number;
|
|
299
|
-
numberOfDaysRemaining: number;
|
|
300
|
-
} | undefined;
|
|
301
|
-
licenseEligibility?: {
|
|
302
|
-
eligible: boolean;
|
|
303
|
-
} | undefined;
|
|
304
|
-
} | null>;
|
|
305
|
-
loading: vue.Ref<boolean>;
|
|
306
|
-
error: vue.Ref<Error | null> | vue.Ref<{
|
|
307
|
-
name: string;
|
|
308
|
-
message: string;
|
|
309
|
-
stack?: string | undefined;
|
|
310
|
-
cause?: unknown;
|
|
311
|
-
} | null>;
|
|
312
|
-
isInstalled: vue.ComputedRef<boolean>;
|
|
169
|
+
interface ActivationRequestComposable {
|
|
170
|
+
activationRequest: Ref<null | ActivationRequest>;
|
|
171
|
+
loading: Ref<boolean>;
|
|
172
|
+
fulfilling: Ref<boolean>;
|
|
173
|
+
completing: Ref<boolean>;
|
|
174
|
+
error: Ref<null | Error>;
|
|
175
|
+
isInstalled: Ref<boolean>;
|
|
313
176
|
fulfillLicense: () => Promise<void>;
|
|
314
177
|
fulfillTrial: () => Promise<void>;
|
|
315
|
-
|
|
178
|
+
cancel: () => Promise<void>;
|
|
179
|
+
}
|
|
180
|
+
declare function useActivationRequest(token: string | Ref<string>, context?: StorefrontContext): ActivationRequestComposable;
|
|
316
181
|
|
|
317
|
-
declare function useVoucher(): {
|
|
182
|
+
declare function useVoucher(context?: StorefrontContext): {
|
|
318
183
|
peek: (code: string) => Promise<{
|
|
319
184
|
code: string;
|
|
320
185
|
id: string;
|
|
@@ -329,6 +194,7 @@ declare function useVoucher(): {
|
|
|
329
194
|
tagline: string;
|
|
330
195
|
iconUrl: string | null;
|
|
331
196
|
owned: boolean;
|
|
197
|
+
website?: string | null | undefined;
|
|
332
198
|
currentVersion?: string | undefined;
|
|
333
199
|
downloads?: {
|
|
334
200
|
path: string | null;
|
|
@@ -394,6 +260,7 @@ declare function useVoucher(): {
|
|
|
394
260
|
tagline: string;
|
|
395
261
|
iconUrl: string | null;
|
|
396
262
|
owned: boolean;
|
|
263
|
+
website?: string | null | undefined;
|
|
397
264
|
currentVersion?: string | undefined;
|
|
398
265
|
downloads?: {
|
|
399
266
|
path: string | null;
|
|
@@ -499,6 +366,7 @@ declare function useVoucher(): {
|
|
|
499
366
|
tagline: string;
|
|
500
367
|
iconUrl: string | null;
|
|
501
368
|
owned: boolean;
|
|
369
|
+
website?: string | null | undefined;
|
|
502
370
|
currentVersion?: string | undefined;
|
|
503
371
|
downloads?: {
|
|
504
372
|
path: string | null;
|
|
@@ -564,6 +432,7 @@ declare function useVoucher(): {
|
|
|
564
432
|
tagline: string;
|
|
565
433
|
iconUrl: string | null;
|
|
566
434
|
owned: boolean;
|
|
435
|
+
website?: string | null | undefined;
|
|
567
436
|
currentVersion?: string | undefined;
|
|
568
437
|
downloads?: {
|
|
569
438
|
path: string | null;
|
|
@@ -657,7 +526,7 @@ declare function useVoucher(): {
|
|
|
657
526
|
}>;
|
|
658
527
|
};
|
|
659
528
|
|
|
660
|
-
declare function useCart(): {
|
|
529
|
+
declare function useCart(context?: StorefrontContext): {
|
|
661
530
|
items: vue.ComputedRef<({
|
|
662
531
|
type: "Product";
|
|
663
532
|
id: string;
|
|
@@ -691,6 +560,7 @@ declare function useCart(): {
|
|
|
691
560
|
tagline: string;
|
|
692
561
|
iconUrl: string | null;
|
|
693
562
|
owned: boolean;
|
|
563
|
+
website?: string | null | undefined;
|
|
694
564
|
currentVersion?: string | undefined;
|
|
695
565
|
downloads?: {
|
|
696
566
|
path: string | null;
|
|
@@ -793,6 +663,7 @@ declare function useCart(): {
|
|
|
793
663
|
tagline: string;
|
|
794
664
|
iconUrl: string | null;
|
|
795
665
|
owned: boolean;
|
|
666
|
+
website?: string | null | undefined;
|
|
796
667
|
currentVersion?: string | undefined;
|
|
797
668
|
downloads?: {
|
|
798
669
|
path: string | null;
|
|
@@ -907,7 +778,7 @@ declare function useCart(): {
|
|
|
907
778
|
checkout: (returnUrl: string) => Promise<void>;
|
|
908
779
|
};
|
|
909
780
|
|
|
910
|
-
declare function useAuth(): {
|
|
781
|
+
declare function useAuth(context?: StorefrontContext): {
|
|
911
782
|
user: vue.Ref<{
|
|
912
783
|
id: string;
|
|
913
784
|
email: string;
|
|
@@ -989,4 +860,4 @@ interface Cart {
|
|
|
989
860
|
type CartItem = LineItem;
|
|
990
861
|
declare function createStorefront(endpoint: string, stateFactory?: StateFactory): StorefrontContext;
|
|
991
862
|
|
|
992
|
-
export { type Cart, type CartItem, createStorefront, storefrontKey, useActivationRequest, useAuth, useBundle, useBundles, useCart, useInventory, useProduct, useProducts, useVoucher };
|
|
863
|
+
export { type ActivationRequestComposable, type Cart, type CartItem, createStorefront, storefrontKey, useActivationRequest, useAuth, useBundle, useBundles, useCart, useInventory, useProduct, useProducts, useVoucher };
|
package/dist/index.js
CHANGED
|
@@ -62,9 +62,11 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
62
62
|
window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
|
|
63
63
|
const cachedOrderJson = localStorage.getItem(_StorefrontContextImpl.sessionKey);
|
|
64
64
|
if (cachedOrderJson) {
|
|
65
|
+
console.log("Found cached session:", cachedOrderJson);
|
|
65
66
|
this.currentOrder = ref(JSON.parse(cachedOrderJson));
|
|
66
67
|
const _1 = this.refreshOrder();
|
|
67
68
|
} else {
|
|
69
|
+
console.log("No cached session found");
|
|
68
70
|
this.currentOrder = ref({
|
|
69
71
|
id: uuidv4(),
|
|
70
72
|
status: OrderStatus.Open,
|
|
@@ -72,7 +74,6 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
72
74
|
items: [],
|
|
73
75
|
couponsApplied: []
|
|
74
76
|
});
|
|
75
|
-
localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(this.currentOrder.value));
|
|
76
77
|
}
|
|
77
78
|
const cachedStorefrontJson = localStorage.getItem(_StorefrontContextImpl.storefrontKey);
|
|
78
79
|
if (cachedStorefrontJson) {
|
|
@@ -89,12 +90,20 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
89
90
|
const _2 = this.updateStorefront();
|
|
90
91
|
const _3 = this.updateUser();
|
|
91
92
|
}
|
|
93
|
+
get loadedStorefrontPromise() {
|
|
94
|
+
return new Promise((resolve) => {
|
|
95
|
+
watch(this.loadedStorefront, (isLoaded) => {
|
|
96
|
+
if (isLoaded)
|
|
97
|
+
resolve();
|
|
98
|
+
}, { immediate: true });
|
|
99
|
+
});
|
|
100
|
+
}
|
|
92
101
|
get loadedUserPromise() {
|
|
93
102
|
return new Promise((resolve) => {
|
|
94
103
|
watch(this.loadedUser, (isLoaded) => {
|
|
95
104
|
if (isLoaded)
|
|
96
105
|
resolve();
|
|
97
|
-
});
|
|
106
|
+
}, { immediate: true });
|
|
98
107
|
});
|
|
99
108
|
}
|
|
100
109
|
install(app) {
|
|
@@ -120,7 +129,6 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
120
129
|
this.loadedStorefront.value = true;
|
|
121
130
|
if (!this.currentOrder.value.currency) {
|
|
122
131
|
this.currentOrder.value.currency = latestStorefront.suggestedCurrency;
|
|
123
|
-
const _ = this.pushOrderContent();
|
|
124
132
|
}
|
|
125
133
|
}
|
|
126
134
|
}
|
|
@@ -166,7 +174,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
166
174
|
couponsApplied: []
|
|
167
175
|
};
|
|
168
176
|
if (typeof window !== "undefined")
|
|
169
|
-
localStorage.
|
|
177
|
+
localStorage.removeItem(_StorefrontContextImpl.sessionKey);
|
|
170
178
|
}
|
|
171
179
|
};
|
|
172
180
|
_StorefrontContextImpl.userKey = "moonbase_user";
|
|
@@ -179,8 +187,8 @@ export * from "@moonbase.sh/storefront-api";
|
|
|
179
187
|
|
|
180
188
|
// src/composables/useBundle.ts
|
|
181
189
|
import { computed as computed2, inject } from "vue";
|
|
182
|
-
function useBundle(bundleId) {
|
|
183
|
-
const storefront = inject(storefrontKey);
|
|
190
|
+
function useBundle(bundleId, context) {
|
|
191
|
+
const storefront = context != null ? context : inject(storefrontKey);
|
|
184
192
|
if (!storefront)
|
|
185
193
|
throw new Error("No storefront configured");
|
|
186
194
|
return computed2(() => storefront.storefront.value.bundles.find((b) => b.id === bundleId) || null);
|
|
@@ -188,8 +196,8 @@ function useBundle(bundleId) {
|
|
|
188
196
|
|
|
189
197
|
// src/composables/useBundles.ts
|
|
190
198
|
import { computed as computed3, inject as inject2 } from "vue";
|
|
191
|
-
function useBundles() {
|
|
192
|
-
const storefront = inject2(storefrontKey);
|
|
199
|
+
function useBundles(context) {
|
|
200
|
+
const storefront = context != null ? context : inject2(storefrontKey);
|
|
193
201
|
if (!storefront)
|
|
194
202
|
throw new Error("No storefront configured");
|
|
195
203
|
return computed3(() => storefront.storefront.value.bundles);
|
|
@@ -197,8 +205,8 @@ function useBundles() {
|
|
|
197
205
|
|
|
198
206
|
// src/composables/useProduct.ts
|
|
199
207
|
import { computed as computed4, inject as inject3 } from "vue";
|
|
200
|
-
function useProduct(productId) {
|
|
201
|
-
const storefront = inject3(storefrontKey);
|
|
208
|
+
function useProduct(productId, context) {
|
|
209
|
+
const storefront = context != null ? context : inject3(storefrontKey);
|
|
202
210
|
if (!storefront)
|
|
203
211
|
throw new Error("No storefront configured");
|
|
204
212
|
return computed4(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
|
|
@@ -206,8 +214,8 @@ function useProduct(productId) {
|
|
|
206
214
|
|
|
207
215
|
// src/composables/useProducts.ts
|
|
208
216
|
import { computed as computed5, inject as inject4 } from "vue";
|
|
209
|
-
function useProducts() {
|
|
210
|
-
const storefront = inject4(storefrontKey);
|
|
217
|
+
function useProducts(context) {
|
|
218
|
+
const storefront = context != null ? context : inject4(storefrontKey);
|
|
211
219
|
if (!storefront)
|
|
212
220
|
throw new Error("No storefront configured");
|
|
213
221
|
return computed5(() => storefront.storefront.value.products);
|
|
@@ -215,8 +223,8 @@ function useProducts() {
|
|
|
215
223
|
|
|
216
224
|
// src/composables/useInventory.ts
|
|
217
225
|
import { inject as inject5 } from "vue";
|
|
218
|
-
function useInventory() {
|
|
219
|
-
const storefront = inject5(storefrontKey);
|
|
226
|
+
function useInventory(context) {
|
|
227
|
+
const storefront = context != null ? context : inject5(storefrontKey);
|
|
220
228
|
if (!storefront)
|
|
221
229
|
throw new Error("No storefront configured");
|
|
222
230
|
return {
|
|
@@ -251,57 +259,94 @@ function useInventory() {
|
|
|
251
259
|
|
|
252
260
|
// src/composables/useActivationRequest.ts
|
|
253
261
|
import { ActivationRequestStatus } from "@moonbase.sh/storefront-api";
|
|
254
|
-
import { computed as computed6, inject as inject6, onBeforeUnmount, watch as watch2 } from "vue";
|
|
255
|
-
function useActivationRequest(
|
|
256
|
-
const storefront = inject6(storefrontKey);
|
|
262
|
+
import { computed as computed6, inject as inject6, onBeforeUnmount, toValue, watch as watch2 } from "vue";
|
|
263
|
+
function useActivationRequest(token, context) {
|
|
264
|
+
const storefront = context != null ? context : inject6(storefrontKey);
|
|
265
|
+
const requestId = toValue(token);
|
|
266
|
+
if (!requestId)
|
|
267
|
+
throw new Error("No request ID was given when calling `useActivationRequest`");
|
|
257
268
|
if (!storefront)
|
|
258
269
|
throw new Error("No storefront configured");
|
|
259
270
|
const activationRequest = storefront.stateFactory(`activation-request-${requestId}`, null);
|
|
260
271
|
const error = storefront.stateFactory(`activation-request-${requestId}-error`, null);
|
|
261
272
|
const loading = storefront.stateFactory(`activation-request-${requestId}-loading`, true);
|
|
273
|
+
const fulfilling = storefront.stateFactory(`activation-request-${requestId}-fulfilling`, false);
|
|
274
|
+
const completing = storefront.stateFactory(`activation-request-${requestId}-completing`, false);
|
|
262
275
|
const completionTimeout = storefront.stateFactory(`activation-request-${requestId}-completion-timeout`, null);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
276
|
+
const checkCompletion = async () => {
|
|
277
|
+
const completed = await storefront.client.activationRequests.isCompleted(requestId);
|
|
278
|
+
if (completed && activationRequest.value) {
|
|
279
|
+
activationRequest.value.status = ActivationRequestStatus.Completed;
|
|
280
|
+
completing.value = false;
|
|
281
|
+
} else {
|
|
282
|
+
completionTimeout.value = setTimeout(checkCompletion, 1500);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
if (requestId && requestId.length > 0) {
|
|
286
|
+
storefront.client.activationRequests.get(requestId).then((result) => {
|
|
287
|
+
activationRequest.value = result;
|
|
288
|
+
if (activationRequest.value.status === ActivationRequestStatus.Fulfilled) {
|
|
289
|
+
completing.value = true;
|
|
290
|
+
checkCompletion();
|
|
291
|
+
}
|
|
292
|
+
loading.value = false;
|
|
293
|
+
}).catch((e) => {
|
|
294
|
+
error.value = e;
|
|
295
|
+
loading.value = false;
|
|
296
|
+
});
|
|
297
|
+
} else {
|
|
298
|
+
error.value = new Error("Missing request id");
|
|
268
299
|
loading.value = false;
|
|
269
|
-
}
|
|
300
|
+
}
|
|
270
301
|
onBeforeUnmount(() => {
|
|
271
302
|
if (completionTimeout.value)
|
|
272
303
|
clearTimeout(completionTimeout.value);
|
|
273
304
|
});
|
|
274
305
|
watch2(storefront.currentUser, async () => {
|
|
306
|
+
var _a, _b;
|
|
307
|
+
if (!requestId || ((_b = (_a = activationRequest.value) == null ? void 0 : _a.licenseEligibility) == null ? void 0 : _b.eligible))
|
|
308
|
+
return;
|
|
275
309
|
loading.value = true;
|
|
276
310
|
try {
|
|
277
311
|
activationRequest.value = await storefront.client.activationRequests.get(requestId);
|
|
312
|
+
if (activationRequest.value.status === ActivationRequestStatus.Fulfilled) {
|
|
313
|
+
completing.value = true;
|
|
314
|
+
checkCompletion();
|
|
315
|
+
}
|
|
278
316
|
} catch (e) {
|
|
279
317
|
error.value = e;
|
|
280
318
|
}
|
|
281
319
|
loading.value = false;
|
|
282
320
|
});
|
|
283
|
-
const checkCompletion = async () => {
|
|
284
|
-
const completed = await storefront.client.activationRequests.isCompleted(requestId);
|
|
285
|
-
if (completed && activationRequest.value)
|
|
286
|
-
activationRequest.value.status = ActivationRequestStatus.Completed;
|
|
287
|
-
else
|
|
288
|
-
completionTimeout.value = setTimeout(checkCompletion, 1500);
|
|
289
|
-
};
|
|
290
321
|
return {
|
|
291
322
|
activationRequest,
|
|
292
323
|
loading,
|
|
324
|
+
fulfilling,
|
|
325
|
+
completing,
|
|
293
326
|
error,
|
|
294
327
|
isInstalled: computed6(() => {
|
|
295
328
|
var _a;
|
|
296
329
|
return activationRequest && ((_a = activationRequest.value) == null ? void 0 : _a.status) === ActivationRequestStatus.Completed;
|
|
297
330
|
}),
|
|
298
331
|
fulfillLicense: async () => {
|
|
332
|
+
fulfilling.value = true;
|
|
299
333
|
activationRequest.value = await storefront.client.activationRequests.fulfillLicense(requestId);
|
|
334
|
+
fulfilling.value = false;
|
|
335
|
+
completing.value = true;
|
|
300
336
|
const _ = checkCompletion();
|
|
301
337
|
},
|
|
302
338
|
fulfillTrial: async () => {
|
|
339
|
+
fulfilling.value = true;
|
|
303
340
|
activationRequest.value = await storefront.client.activationRequests.fulfillTrial(requestId);
|
|
341
|
+
fulfilling.value = false;
|
|
342
|
+
completing.value = true;
|
|
304
343
|
const _ = checkCompletion();
|
|
344
|
+
},
|
|
345
|
+
cancel: async () => {
|
|
346
|
+
var _a;
|
|
347
|
+
if (((_a = activationRequest.value) == null ? void 0 : _a.status) === ActivationRequestStatus.Cancelled)
|
|
348
|
+
return;
|
|
349
|
+
activationRequest.value = await storefront.client.activationRequests.cancel(requestId);
|
|
305
350
|
}
|
|
306
351
|
};
|
|
307
352
|
}
|
|
@@ -309,8 +354,8 @@ function useActivationRequest(requestId) {
|
|
|
309
354
|
// src/composables/useVoucher.ts
|
|
310
355
|
import { NotFoundError } from "@moonbase.sh/storefront-api";
|
|
311
356
|
import { inject as inject7 } from "vue";
|
|
312
|
-
function useVoucher() {
|
|
313
|
-
const storefront = inject7(storefrontKey);
|
|
357
|
+
function useVoucher(context) {
|
|
358
|
+
const storefront = context != null ? context : inject7(storefrontKey);
|
|
314
359
|
if (!storefront)
|
|
315
360
|
throw new Error("No storefront configured");
|
|
316
361
|
return {
|
|
@@ -337,8 +382,8 @@ function useVoucher() {
|
|
|
337
382
|
|
|
338
383
|
// src/composables/useCart.ts
|
|
339
384
|
import { computed as computed7, inject as inject8, unref } from "vue";
|
|
340
|
-
function useCart() {
|
|
341
|
-
const storefront = inject8(storefrontKey);
|
|
385
|
+
function useCart(context) {
|
|
386
|
+
const storefront = context != null ? context : inject8(storefrontKey);
|
|
342
387
|
if (!storefront)
|
|
343
388
|
throw new Error("No storefront configured");
|
|
344
389
|
return {
|
|
@@ -456,8 +501,8 @@ function useCart() {
|
|
|
456
501
|
|
|
457
502
|
// src/composables/useAuth.ts
|
|
458
503
|
import { inject as inject9 } from "vue";
|
|
459
|
-
function useAuth() {
|
|
460
|
-
const storefront = inject9(storefrontKey);
|
|
504
|
+
function useAuth(context) {
|
|
505
|
+
const storefront = context != null ? context : inject9(storefrontKey);
|
|
461
506
|
if (!storefront)
|
|
462
507
|
throw new Error("No storefront configured");
|
|
463
508
|
return {
|
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.2.1",
|
|
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.2.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/uuid": "^9.0.7",
|