@moonbase.sh/vue 0.1.84 → 0.1.86
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 +73 -14
- package/dist/index.d.cts +150 -1
- package/dist/index.d.ts +150 -1
- package/dist/index.js +67 -9
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,7 @@ var src_exports = {};
|
|
|
23
23
|
__export(src_exports, {
|
|
24
24
|
createStorefront: () => createStorefront,
|
|
25
25
|
storefrontKey: () => storefrontKey,
|
|
26
|
+
useActivationRequest: () => useActivationRequest,
|
|
26
27
|
useAuth: () => useAuth,
|
|
27
28
|
useBundle: () => useBundle,
|
|
28
29
|
useBundles: () => useBundles,
|
|
@@ -33,8 +34,8 @@ __export(src_exports, {
|
|
|
33
34
|
useVoucher: () => useVoucher
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(src_exports);
|
|
36
|
-
var
|
|
37
|
-
var
|
|
37
|
+
var import_storefront_api3 = require("@moonbase.sh/storefront-api");
|
|
38
|
+
var import_vue11 = require("vue");
|
|
38
39
|
|
|
39
40
|
// src/context.ts
|
|
40
41
|
var import_uuid = require("uuid");
|
|
@@ -255,10 +256,67 @@ function useInventory() {
|
|
|
255
256
|
};
|
|
256
257
|
}
|
|
257
258
|
|
|
258
|
-
// src/composables/
|
|
259
|
+
// src/composables/useActivationRequest.ts
|
|
260
|
+
var import_storefront_api2 = require("@moonbase.sh/storefront-api");
|
|
259
261
|
var import_vue7 = require("vue");
|
|
260
|
-
function
|
|
262
|
+
function useActivationRequest(requestId) {
|
|
261
263
|
const storefront = (0, import_vue7.inject)(storefrontKey);
|
|
264
|
+
if (!storefront)
|
|
265
|
+
throw new Error("No storefront configured");
|
|
266
|
+
const activationRequest = storefront.stateFactory(`activation-request-${requestId}`, null);
|
|
267
|
+
const error = storefront.stateFactory(`activation-request-${requestId}-error`, null);
|
|
268
|
+
const loading = storefront.stateFactory(`activation-request-${requestId}-loading`, true);
|
|
269
|
+
const completionTimeout = storefront.stateFactory(`activation-request-${requestId}-completion-timeout`, null);
|
|
270
|
+
storefront.client.activationRequests.get(requestId).then((result) => {
|
|
271
|
+
activationRequest.value = result;
|
|
272
|
+
loading.value = false;
|
|
273
|
+
}).catch((e) => {
|
|
274
|
+
error.value = e;
|
|
275
|
+
loading.value = false;
|
|
276
|
+
});
|
|
277
|
+
(0, import_vue7.onBeforeUnmount)(() => {
|
|
278
|
+
if (completionTimeout.value)
|
|
279
|
+
clearTimeout(completionTimeout.value);
|
|
280
|
+
});
|
|
281
|
+
(0, import_vue7.watch)(storefront.currentUser, async () => {
|
|
282
|
+
loading.value = true;
|
|
283
|
+
try {
|
|
284
|
+
activationRequest.value = await storefront.client.activationRequests.get(requestId);
|
|
285
|
+
} catch (e) {
|
|
286
|
+
error.value = e;
|
|
287
|
+
}
|
|
288
|
+
loading.value = false;
|
|
289
|
+
});
|
|
290
|
+
const checkCompletion = async () => {
|
|
291
|
+
const completed = await storefront.client.activationRequests.isCompleted(requestId);
|
|
292
|
+
if (completed && activationRequest.value)
|
|
293
|
+
activationRequest.value.status = import_storefront_api2.ActivationRequestStatus.Completed;
|
|
294
|
+
else
|
|
295
|
+
completionTimeout.value = setTimeout(checkCompletion, 1500);
|
|
296
|
+
};
|
|
297
|
+
return {
|
|
298
|
+
activationRequest,
|
|
299
|
+
loading,
|
|
300
|
+
error,
|
|
301
|
+
isInstalled: (0, import_vue7.computed)(() => {
|
|
302
|
+
var _a;
|
|
303
|
+
return activationRequest && ((_a = activationRequest.value) == null ? void 0 : _a.status) === import_storefront_api2.ActivationRequestStatus.Completed;
|
|
304
|
+
}),
|
|
305
|
+
fulfillLicense: async () => {
|
|
306
|
+
activationRequest.value = await storefront.client.activationRequests.fulfillLicense(requestId);
|
|
307
|
+
const _ = checkCompletion();
|
|
308
|
+
},
|
|
309
|
+
fulfillTrial: async () => {
|
|
310
|
+
activationRequest.value = await storefront.client.activationRequests.fulfillTrial(requestId);
|
|
311
|
+
const _ = checkCompletion();
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/composables/useVoucher.ts
|
|
317
|
+
var import_vue8 = require("vue");
|
|
318
|
+
function useVoucher() {
|
|
319
|
+
const storefront = (0, import_vue8.inject)(storefrontKey);
|
|
262
320
|
if (!storefront)
|
|
263
321
|
throw new Error("No storefront configured");
|
|
264
322
|
return {
|
|
@@ -272,13 +330,13 @@ function useVoucher() {
|
|
|
272
330
|
}
|
|
273
331
|
|
|
274
332
|
// src/composables/useCart.ts
|
|
275
|
-
var
|
|
333
|
+
var import_vue9 = require("vue");
|
|
276
334
|
function useCart() {
|
|
277
|
-
const storefront = (0,
|
|
335
|
+
const storefront = (0, import_vue9.inject)(storefrontKey);
|
|
278
336
|
if (!storefront)
|
|
279
337
|
throw new Error("No storefront configured");
|
|
280
338
|
return {
|
|
281
|
-
items: (0,
|
|
339
|
+
items: (0, import_vue9.computed)(() => storefront.currentOrder.value.items.map((item) => {
|
|
282
340
|
if (item.type === "Product") {
|
|
283
341
|
const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
|
|
284
342
|
const variations = (product == null ? void 0 : product.variations) || [];
|
|
@@ -301,8 +359,8 @@ function useCart() {
|
|
|
301
359
|
};
|
|
302
360
|
}
|
|
303
361
|
})),
|
|
304
|
-
currency: (0,
|
|
305
|
-
total: (0,
|
|
362
|
+
currency: (0, import_vue9.computed)(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
|
|
363
|
+
total: (0, import_vue9.computed)(() => {
|
|
306
364
|
const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
|
|
307
365
|
const total = storefront.currentOrder.value.items.reduce((agg, item) => {
|
|
308
366
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -323,7 +381,7 @@ function useCart() {
|
|
|
323
381
|
return { amount: total, currency };
|
|
324
382
|
}),
|
|
325
383
|
addToCart: (item, variation) => {
|
|
326
|
-
item = (0,
|
|
384
|
+
item = (0, import_vue9.unref)(item);
|
|
327
385
|
variation != null ? variation : variation = item.defaultVariation;
|
|
328
386
|
if (!variation)
|
|
329
387
|
throw new Error("Added item does not have a default variation, and none have been specified");
|
|
@@ -391,9 +449,9 @@ function useCart() {
|
|
|
391
449
|
}
|
|
392
450
|
|
|
393
451
|
// src/composables/useAuth.ts
|
|
394
|
-
var
|
|
452
|
+
var import_vue10 = require("vue");
|
|
395
453
|
function useAuth() {
|
|
396
|
-
const storefront = (0,
|
|
454
|
+
const storefront = (0, import_vue10.inject)(storefrontKey);
|
|
397
455
|
if (!storefront)
|
|
398
456
|
throw new Error("No storefront configured");
|
|
399
457
|
return {
|
|
@@ -450,15 +508,16 @@ function createStorefront(endpoint, stateFactory) {
|
|
|
450
508
|
};
|
|
451
509
|
return new StorefrontContextImpl(
|
|
452
510
|
configuration,
|
|
453
|
-
new
|
|
511
|
+
new import_storefront_api3.MoonbaseClient(configuration),
|
|
454
512
|
// Default to vue refs but allow stuff like Nuxt useState wrappers
|
|
455
|
-
stateFactory || ((_, state) => (0,
|
|
513
|
+
stateFactory || ((_, state) => (0, import_vue11.ref)(state))
|
|
456
514
|
);
|
|
457
515
|
}
|
|
458
516
|
// Annotate the CommonJS export names for ESM import in node:
|
|
459
517
|
0 && (module.exports = {
|
|
460
518
|
createStorefront,
|
|
461
519
|
storefrontKey,
|
|
520
|
+
useActivationRequest,
|
|
462
521
|
useAuth,
|
|
463
522
|
useBundle,
|
|
464
523
|
useBundles,
|
package/dist/index.d.cts
CHANGED
|
@@ -3,6 +3,7 @@ import { MoonbaseConfiguration, Storefront, Order, User, MoonbaseClient, Storefr
|
|
|
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';
|
|
6
7
|
import { Address } from '@moonbase.sh/storefront-api/src';
|
|
7
8
|
|
|
8
9
|
interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
@@ -132,6 +133,154 @@ declare function useInventory(): {
|
|
|
132
133
|
revokeActivation: (activation: Activation) => Promise<void>;
|
|
133
134
|
};
|
|
134
135
|
|
|
136
|
+
declare function useActivationRequest(requestId: string): {
|
|
137
|
+
activationRequest: vue.Ref<{
|
|
138
|
+
status: _moonbase_sh_storefront_api_src.ActivationRequestStatus;
|
|
139
|
+
id: string;
|
|
140
|
+
product: {
|
|
141
|
+
type: "product";
|
|
142
|
+
id: string;
|
|
143
|
+
name: string;
|
|
144
|
+
tagline: string;
|
|
145
|
+
iconUrl: string | null;
|
|
146
|
+
owned: boolean;
|
|
147
|
+
currentVersion?: string | undefined;
|
|
148
|
+
downloads?: {
|
|
149
|
+
name: string;
|
|
150
|
+
path: string | null;
|
|
151
|
+
key: string;
|
|
152
|
+
platform: _moonbase_sh_storefront_api_src.Platform;
|
|
153
|
+
size: number;
|
|
154
|
+
}[] | undefined;
|
|
155
|
+
defaultVariation?: {
|
|
156
|
+
id: string;
|
|
157
|
+
price: Record<string, number>;
|
|
158
|
+
name: string;
|
|
159
|
+
originalPrice: Record<string, number>;
|
|
160
|
+
hasDiscount: boolean;
|
|
161
|
+
discount?: {
|
|
162
|
+
type: "PercentageOffDiscount";
|
|
163
|
+
name: string;
|
|
164
|
+
percentage: number;
|
|
165
|
+
total: Record<string, number>;
|
|
166
|
+
description?: string | undefined;
|
|
167
|
+
} | {
|
|
168
|
+
type: "FlatAmountOffDiscount";
|
|
169
|
+
name: string;
|
|
170
|
+
total: Record<string, number>;
|
|
171
|
+
description?: string | undefined;
|
|
172
|
+
} | undefined;
|
|
173
|
+
} | undefined;
|
|
174
|
+
variations?: {
|
|
175
|
+
id: string;
|
|
176
|
+
price: Record<string, number>;
|
|
177
|
+
name: string;
|
|
178
|
+
originalPrice: Record<string, number>;
|
|
179
|
+
hasDiscount: boolean;
|
|
180
|
+
discount?: {
|
|
181
|
+
type: "PercentageOffDiscount";
|
|
182
|
+
name: string;
|
|
183
|
+
percentage: number;
|
|
184
|
+
total: Record<string, number>;
|
|
185
|
+
description?: string | undefined;
|
|
186
|
+
} | {
|
|
187
|
+
type: "FlatAmountOffDiscount";
|
|
188
|
+
name: string;
|
|
189
|
+
total: Record<string, number>;
|
|
190
|
+
description?: string | undefined;
|
|
191
|
+
} | undefined;
|
|
192
|
+
}[] | undefined;
|
|
193
|
+
};
|
|
194
|
+
trialEligibility?: {
|
|
195
|
+
eligible: boolean;
|
|
196
|
+
existing: boolean;
|
|
197
|
+
requiresAccount: boolean;
|
|
198
|
+
numberOfDaysPerProduct: number;
|
|
199
|
+
numberOfDaysRemaining: number;
|
|
200
|
+
} | undefined;
|
|
201
|
+
licenseEligibility?: {
|
|
202
|
+
eligible: boolean;
|
|
203
|
+
} | undefined;
|
|
204
|
+
} | null> | vue.Ref<{
|
|
205
|
+
status: _moonbase_sh_storefront_api_src.ActivationRequestStatus;
|
|
206
|
+
id: string;
|
|
207
|
+
product: {
|
|
208
|
+
type: "product";
|
|
209
|
+
id: string;
|
|
210
|
+
name: string;
|
|
211
|
+
tagline: string;
|
|
212
|
+
iconUrl: string | null;
|
|
213
|
+
owned: boolean;
|
|
214
|
+
currentVersion?: string | undefined;
|
|
215
|
+
downloads?: {
|
|
216
|
+
name: string;
|
|
217
|
+
path: string | null;
|
|
218
|
+
key: string;
|
|
219
|
+
platform: _moonbase_sh_storefront_api_src.Platform;
|
|
220
|
+
size: number;
|
|
221
|
+
}[] | undefined;
|
|
222
|
+
defaultVariation?: {
|
|
223
|
+
id: string;
|
|
224
|
+
price: Record<string, number>;
|
|
225
|
+
name: string;
|
|
226
|
+
originalPrice: Record<string, number>;
|
|
227
|
+
hasDiscount: boolean;
|
|
228
|
+
discount?: {
|
|
229
|
+
type: "PercentageOffDiscount";
|
|
230
|
+
name: string;
|
|
231
|
+
percentage: number;
|
|
232
|
+
total: Record<string, number>;
|
|
233
|
+
description?: string | undefined;
|
|
234
|
+
} | {
|
|
235
|
+
type: "FlatAmountOffDiscount";
|
|
236
|
+
name: string;
|
|
237
|
+
total: Record<string, number>;
|
|
238
|
+
description?: string | undefined;
|
|
239
|
+
} | undefined;
|
|
240
|
+
} | undefined;
|
|
241
|
+
variations?: {
|
|
242
|
+
id: string;
|
|
243
|
+
price: Record<string, number>;
|
|
244
|
+
name: string;
|
|
245
|
+
originalPrice: Record<string, number>;
|
|
246
|
+
hasDiscount: boolean;
|
|
247
|
+
discount?: {
|
|
248
|
+
type: "PercentageOffDiscount";
|
|
249
|
+
name: string;
|
|
250
|
+
percentage: number;
|
|
251
|
+
total: Record<string, number>;
|
|
252
|
+
description?: string | undefined;
|
|
253
|
+
} | {
|
|
254
|
+
type: "FlatAmountOffDiscount";
|
|
255
|
+
name: string;
|
|
256
|
+
total: Record<string, number>;
|
|
257
|
+
description?: string | undefined;
|
|
258
|
+
} | undefined;
|
|
259
|
+
}[] | undefined;
|
|
260
|
+
};
|
|
261
|
+
trialEligibility?: {
|
|
262
|
+
eligible: boolean;
|
|
263
|
+
existing: boolean;
|
|
264
|
+
requiresAccount: boolean;
|
|
265
|
+
numberOfDaysPerProduct: number;
|
|
266
|
+
numberOfDaysRemaining: number;
|
|
267
|
+
} | undefined;
|
|
268
|
+
licenseEligibility?: {
|
|
269
|
+
eligible: boolean;
|
|
270
|
+
} | undefined;
|
|
271
|
+
} | null>;
|
|
272
|
+
loading: vue.Ref<boolean>;
|
|
273
|
+
error: vue.Ref<Error | null> | vue.Ref<{
|
|
274
|
+
name: string;
|
|
275
|
+
message: string;
|
|
276
|
+
stack?: string | undefined;
|
|
277
|
+
cause?: unknown;
|
|
278
|
+
} | null>;
|
|
279
|
+
isInstalled: vue.ComputedRef<boolean>;
|
|
280
|
+
fulfillLicense: () => Promise<void>;
|
|
281
|
+
fulfillTrial: () => Promise<void>;
|
|
282
|
+
};
|
|
283
|
+
|
|
135
284
|
declare function useVoucher(): {
|
|
136
285
|
peek: (code: string) => Promise<{
|
|
137
286
|
code: string;
|
|
@@ -795,4 +944,4 @@ interface Cart {
|
|
|
795
944
|
type CartItem = LineItem;
|
|
796
945
|
declare function createStorefront(endpoint: string, stateFactory?: StateFactory): StorefrontContext;
|
|
797
946
|
|
|
798
|
-
export { type Cart, type CartItem, createStorefront, storefrontKey, useAuth, useBundle, useBundles, useCart, useInventory, useProduct, useProducts, useVoucher };
|
|
947
|
+
export { type Cart, type CartItem, createStorefront, storefrontKey, useActivationRequest, useAuth, useBundle, useBundles, useCart, useInventory, useProduct, useProducts, useVoucher };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { MoonbaseConfiguration, Storefront, Order, User, MoonbaseClient, Storefr
|
|
|
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';
|
|
6
7
|
import { Address } from '@moonbase.sh/storefront-api/src';
|
|
7
8
|
|
|
8
9
|
interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
|
|
@@ -132,6 +133,154 @@ declare function useInventory(): {
|
|
|
132
133
|
revokeActivation: (activation: Activation) => Promise<void>;
|
|
133
134
|
};
|
|
134
135
|
|
|
136
|
+
declare function useActivationRequest(requestId: string): {
|
|
137
|
+
activationRequest: vue.Ref<{
|
|
138
|
+
status: _moonbase_sh_storefront_api_src.ActivationRequestStatus;
|
|
139
|
+
id: string;
|
|
140
|
+
product: {
|
|
141
|
+
type: "product";
|
|
142
|
+
id: string;
|
|
143
|
+
name: string;
|
|
144
|
+
tagline: string;
|
|
145
|
+
iconUrl: string | null;
|
|
146
|
+
owned: boolean;
|
|
147
|
+
currentVersion?: string | undefined;
|
|
148
|
+
downloads?: {
|
|
149
|
+
name: string;
|
|
150
|
+
path: string | null;
|
|
151
|
+
key: string;
|
|
152
|
+
platform: _moonbase_sh_storefront_api_src.Platform;
|
|
153
|
+
size: number;
|
|
154
|
+
}[] | undefined;
|
|
155
|
+
defaultVariation?: {
|
|
156
|
+
id: string;
|
|
157
|
+
price: Record<string, number>;
|
|
158
|
+
name: string;
|
|
159
|
+
originalPrice: Record<string, number>;
|
|
160
|
+
hasDiscount: boolean;
|
|
161
|
+
discount?: {
|
|
162
|
+
type: "PercentageOffDiscount";
|
|
163
|
+
name: string;
|
|
164
|
+
percentage: number;
|
|
165
|
+
total: Record<string, number>;
|
|
166
|
+
description?: string | undefined;
|
|
167
|
+
} | {
|
|
168
|
+
type: "FlatAmountOffDiscount";
|
|
169
|
+
name: string;
|
|
170
|
+
total: Record<string, number>;
|
|
171
|
+
description?: string | undefined;
|
|
172
|
+
} | undefined;
|
|
173
|
+
} | undefined;
|
|
174
|
+
variations?: {
|
|
175
|
+
id: string;
|
|
176
|
+
price: Record<string, number>;
|
|
177
|
+
name: string;
|
|
178
|
+
originalPrice: Record<string, number>;
|
|
179
|
+
hasDiscount: boolean;
|
|
180
|
+
discount?: {
|
|
181
|
+
type: "PercentageOffDiscount";
|
|
182
|
+
name: string;
|
|
183
|
+
percentage: number;
|
|
184
|
+
total: Record<string, number>;
|
|
185
|
+
description?: string | undefined;
|
|
186
|
+
} | {
|
|
187
|
+
type: "FlatAmountOffDiscount";
|
|
188
|
+
name: string;
|
|
189
|
+
total: Record<string, number>;
|
|
190
|
+
description?: string | undefined;
|
|
191
|
+
} | undefined;
|
|
192
|
+
}[] | undefined;
|
|
193
|
+
};
|
|
194
|
+
trialEligibility?: {
|
|
195
|
+
eligible: boolean;
|
|
196
|
+
existing: boolean;
|
|
197
|
+
requiresAccount: boolean;
|
|
198
|
+
numberOfDaysPerProduct: number;
|
|
199
|
+
numberOfDaysRemaining: number;
|
|
200
|
+
} | undefined;
|
|
201
|
+
licenseEligibility?: {
|
|
202
|
+
eligible: boolean;
|
|
203
|
+
} | undefined;
|
|
204
|
+
} | null> | vue.Ref<{
|
|
205
|
+
status: _moonbase_sh_storefront_api_src.ActivationRequestStatus;
|
|
206
|
+
id: string;
|
|
207
|
+
product: {
|
|
208
|
+
type: "product";
|
|
209
|
+
id: string;
|
|
210
|
+
name: string;
|
|
211
|
+
tagline: string;
|
|
212
|
+
iconUrl: string | null;
|
|
213
|
+
owned: boolean;
|
|
214
|
+
currentVersion?: string | undefined;
|
|
215
|
+
downloads?: {
|
|
216
|
+
name: string;
|
|
217
|
+
path: string | null;
|
|
218
|
+
key: string;
|
|
219
|
+
platform: _moonbase_sh_storefront_api_src.Platform;
|
|
220
|
+
size: number;
|
|
221
|
+
}[] | undefined;
|
|
222
|
+
defaultVariation?: {
|
|
223
|
+
id: string;
|
|
224
|
+
price: Record<string, number>;
|
|
225
|
+
name: string;
|
|
226
|
+
originalPrice: Record<string, number>;
|
|
227
|
+
hasDiscount: boolean;
|
|
228
|
+
discount?: {
|
|
229
|
+
type: "PercentageOffDiscount";
|
|
230
|
+
name: string;
|
|
231
|
+
percentage: number;
|
|
232
|
+
total: Record<string, number>;
|
|
233
|
+
description?: string | undefined;
|
|
234
|
+
} | {
|
|
235
|
+
type: "FlatAmountOffDiscount";
|
|
236
|
+
name: string;
|
|
237
|
+
total: Record<string, number>;
|
|
238
|
+
description?: string | undefined;
|
|
239
|
+
} | undefined;
|
|
240
|
+
} | undefined;
|
|
241
|
+
variations?: {
|
|
242
|
+
id: string;
|
|
243
|
+
price: Record<string, number>;
|
|
244
|
+
name: string;
|
|
245
|
+
originalPrice: Record<string, number>;
|
|
246
|
+
hasDiscount: boolean;
|
|
247
|
+
discount?: {
|
|
248
|
+
type: "PercentageOffDiscount";
|
|
249
|
+
name: string;
|
|
250
|
+
percentage: number;
|
|
251
|
+
total: Record<string, number>;
|
|
252
|
+
description?: string | undefined;
|
|
253
|
+
} | {
|
|
254
|
+
type: "FlatAmountOffDiscount";
|
|
255
|
+
name: string;
|
|
256
|
+
total: Record<string, number>;
|
|
257
|
+
description?: string | undefined;
|
|
258
|
+
} | undefined;
|
|
259
|
+
}[] | undefined;
|
|
260
|
+
};
|
|
261
|
+
trialEligibility?: {
|
|
262
|
+
eligible: boolean;
|
|
263
|
+
existing: boolean;
|
|
264
|
+
requiresAccount: boolean;
|
|
265
|
+
numberOfDaysPerProduct: number;
|
|
266
|
+
numberOfDaysRemaining: number;
|
|
267
|
+
} | undefined;
|
|
268
|
+
licenseEligibility?: {
|
|
269
|
+
eligible: boolean;
|
|
270
|
+
} | undefined;
|
|
271
|
+
} | null>;
|
|
272
|
+
loading: vue.Ref<boolean>;
|
|
273
|
+
error: vue.Ref<Error | null> | vue.Ref<{
|
|
274
|
+
name: string;
|
|
275
|
+
message: string;
|
|
276
|
+
stack?: string | undefined;
|
|
277
|
+
cause?: unknown;
|
|
278
|
+
} | null>;
|
|
279
|
+
isInstalled: vue.ComputedRef<boolean>;
|
|
280
|
+
fulfillLicense: () => Promise<void>;
|
|
281
|
+
fulfillTrial: () => Promise<void>;
|
|
282
|
+
};
|
|
283
|
+
|
|
135
284
|
declare function useVoucher(): {
|
|
136
285
|
peek: (code: string) => Promise<{
|
|
137
286
|
code: string;
|
|
@@ -795,4 +944,4 @@ interface Cart {
|
|
|
795
944
|
type CartItem = LineItem;
|
|
796
945
|
declare function createStorefront(endpoint: string, stateFactory?: StateFactory): StorefrontContext;
|
|
797
946
|
|
|
798
|
-
export { type Cart, type CartItem, createStorefront, storefrontKey, useAuth, useBundle, useBundles, useCart, useInventory, useProduct, useProducts, useVoucher };
|
|
947
|
+
export { type Cart, type CartItem, createStorefront, storefrontKey, useActivationRequest, useAuth, useBundle, useBundles, useCart, useInventory, useProduct, useProducts, useVoucher };
|
package/dist/index.js
CHANGED
|
@@ -221,10 +221,67 @@ function useInventory() {
|
|
|
221
221
|
};
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
// src/composables/useActivationRequest.ts
|
|
225
|
+
import { ActivationRequestStatus } from "@moonbase.sh/storefront-api";
|
|
226
|
+
import { computed as computed5, inject as inject6, onBeforeUnmount, watch } from "vue";
|
|
227
|
+
function useActivationRequest(requestId) {
|
|
228
|
+
const storefront = inject6(storefrontKey);
|
|
229
|
+
if (!storefront)
|
|
230
|
+
throw new Error("No storefront configured");
|
|
231
|
+
const activationRequest = storefront.stateFactory(`activation-request-${requestId}`, null);
|
|
232
|
+
const error = storefront.stateFactory(`activation-request-${requestId}-error`, null);
|
|
233
|
+
const loading = storefront.stateFactory(`activation-request-${requestId}-loading`, true);
|
|
234
|
+
const completionTimeout = storefront.stateFactory(`activation-request-${requestId}-completion-timeout`, null);
|
|
235
|
+
storefront.client.activationRequests.get(requestId).then((result) => {
|
|
236
|
+
activationRequest.value = result;
|
|
237
|
+
loading.value = false;
|
|
238
|
+
}).catch((e) => {
|
|
239
|
+
error.value = e;
|
|
240
|
+
loading.value = false;
|
|
241
|
+
});
|
|
242
|
+
onBeforeUnmount(() => {
|
|
243
|
+
if (completionTimeout.value)
|
|
244
|
+
clearTimeout(completionTimeout.value);
|
|
245
|
+
});
|
|
246
|
+
watch(storefront.currentUser, async () => {
|
|
247
|
+
loading.value = true;
|
|
248
|
+
try {
|
|
249
|
+
activationRequest.value = await storefront.client.activationRequests.get(requestId);
|
|
250
|
+
} catch (e) {
|
|
251
|
+
error.value = e;
|
|
252
|
+
}
|
|
253
|
+
loading.value = false;
|
|
254
|
+
});
|
|
255
|
+
const checkCompletion = async () => {
|
|
256
|
+
const completed = await storefront.client.activationRequests.isCompleted(requestId);
|
|
257
|
+
if (completed && activationRequest.value)
|
|
258
|
+
activationRequest.value.status = ActivationRequestStatus.Completed;
|
|
259
|
+
else
|
|
260
|
+
completionTimeout.value = setTimeout(checkCompletion, 1500);
|
|
261
|
+
};
|
|
262
|
+
return {
|
|
263
|
+
activationRequest,
|
|
264
|
+
loading,
|
|
265
|
+
error,
|
|
266
|
+
isInstalled: computed5(() => {
|
|
267
|
+
var _a;
|
|
268
|
+
return activationRequest && ((_a = activationRequest.value) == null ? void 0 : _a.status) === ActivationRequestStatus.Completed;
|
|
269
|
+
}),
|
|
270
|
+
fulfillLicense: async () => {
|
|
271
|
+
activationRequest.value = await storefront.client.activationRequests.fulfillLicense(requestId);
|
|
272
|
+
const _ = checkCompletion();
|
|
273
|
+
},
|
|
274
|
+
fulfillTrial: async () => {
|
|
275
|
+
activationRequest.value = await storefront.client.activationRequests.fulfillTrial(requestId);
|
|
276
|
+
const _ = checkCompletion();
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
224
281
|
// src/composables/useVoucher.ts
|
|
225
|
-
import { inject as
|
|
282
|
+
import { inject as inject7 } from "vue";
|
|
226
283
|
function useVoucher() {
|
|
227
|
-
const storefront =
|
|
284
|
+
const storefront = inject7(storefrontKey);
|
|
228
285
|
if (!storefront)
|
|
229
286
|
throw new Error("No storefront configured");
|
|
230
287
|
return {
|
|
@@ -238,13 +295,13 @@ function useVoucher() {
|
|
|
238
295
|
}
|
|
239
296
|
|
|
240
297
|
// src/composables/useCart.ts
|
|
241
|
-
import { computed as
|
|
298
|
+
import { computed as computed6, inject as inject8, unref } from "vue";
|
|
242
299
|
function useCart() {
|
|
243
|
-
const storefront =
|
|
300
|
+
const storefront = inject8(storefrontKey);
|
|
244
301
|
if (!storefront)
|
|
245
302
|
throw new Error("No storefront configured");
|
|
246
303
|
return {
|
|
247
|
-
items:
|
|
304
|
+
items: computed6(() => storefront.currentOrder.value.items.map((item) => {
|
|
248
305
|
if (item.type === "Product") {
|
|
249
306
|
const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
|
|
250
307
|
const variations = (product == null ? void 0 : product.variations) || [];
|
|
@@ -267,8 +324,8 @@ function useCart() {
|
|
|
267
324
|
};
|
|
268
325
|
}
|
|
269
326
|
})),
|
|
270
|
-
currency:
|
|
271
|
-
total:
|
|
327
|
+
currency: computed6(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
|
|
328
|
+
total: computed6(() => {
|
|
272
329
|
const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
|
|
273
330
|
const total = storefront.currentOrder.value.items.reduce((agg, item) => {
|
|
274
331
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -357,9 +414,9 @@ function useCart() {
|
|
|
357
414
|
}
|
|
358
415
|
|
|
359
416
|
// src/composables/useAuth.ts
|
|
360
|
-
import { inject as
|
|
417
|
+
import { inject as inject9 } from "vue";
|
|
361
418
|
function useAuth() {
|
|
362
|
-
const storefront =
|
|
419
|
+
const storefront = inject9(storefrontKey);
|
|
363
420
|
if (!storefront)
|
|
364
421
|
throw new Error("No storefront configured");
|
|
365
422
|
return {
|
|
@@ -424,6 +481,7 @@ function createStorefront(endpoint, stateFactory) {
|
|
|
424
481
|
export {
|
|
425
482
|
createStorefront,
|
|
426
483
|
storefrontKey,
|
|
484
|
+
useActivationRequest,
|
|
427
485
|
useAuth,
|
|
428
486
|
useBundle,
|
|
429
487
|
useBundles,
|
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.86",
|
|
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.86"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/uuid": "^9.0.7",
|