@moonbase.sh/vue 0.2.31 → 0.2.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -396,19 +396,18 @@ var import_storefront_api3 = require("@moonbase.sh/storefront-api");
396
396
  var import_vue7 = require("vue");
397
397
  function useActivationRequest(token, context) {
398
398
  const storefront = context != null ? context : (0, import_vue7.inject)(storefrontKey);
399
- const requestId = (0, import_vue7.toValue)(token);
400
- if (!requestId)
401
- throw new Error("No request ID was given when calling `useActivationRequest`");
402
399
  if (!storefront)
403
400
  throw new Error("No storefront configured");
404
- const activationRequest = storefront.stateFactory(`activation-request-${requestId}`, null);
405
- const error = storefront.stateFactory(`activation-request-${requestId}-error`, null);
406
- const loading = storefront.stateFactory(`activation-request-${requestId}-loading`, true);
407
- const fulfilling = storefront.stateFactory(`activation-request-${requestId}-fulfilling`, false);
408
- const completing = storefront.stateFactory(`activation-request-${requestId}-completing`, false);
409
- const completionTimeout = storefront.stateFactory(`activation-request-${requestId}-completion-timeout`, null);
401
+ const activationRequest = storefront.stateFactory(`activation-request-${(0, import_vue7.toValue)(token)}`, null);
402
+ const error = storefront.stateFactory(`activation-request-${(0, import_vue7.toValue)(token)}-error`, null);
403
+ const loading = storefront.stateFactory(`activation-request-${(0, import_vue7.toValue)(token)}-loading`, true);
404
+ const fulfilling = storefront.stateFactory(`activation-request-${(0, import_vue7.toValue)(token)}-fulfilling`, false);
405
+ const completing = storefront.stateFactory(`activation-request-${(0, import_vue7.toValue)(token)}-completing`, false);
406
+ const completionTimeout = storefront.stateFactory(`activation-request-${(0, import_vue7.toValue)(token)}-completion-timeout`, null);
410
407
  const checkCompletion = async () => {
411
- const completed = await storefront.client.activationRequests.isCompleted(requestId);
408
+ if (!activationRequest.value)
409
+ return;
410
+ const completed = await storefront.client.activationRequests.isCompleted(activationRequest.value.id);
412
411
  if (completed && activationRequest.value) {
413
412
  activationRequest.value.status = import_storefront_api3.ActivationRequestStatus.Completed;
414
413
  completing.value = false;
@@ -416,28 +415,31 @@ function useActivationRequest(token, context) {
416
415
  completionTimeout.value = setTimeout(checkCompletion, 1500);
417
416
  }
418
417
  };
419
- if (requestId && requestId.length > 0) {
420
- storefront.client.activationRequests.get(requestId).then((result) => {
421
- activationRequest.value = result;
422
- if (activationRequest.value.status === import_storefront_api3.ActivationRequestStatus.Fulfilled) {
423
- completing.value = true;
424
- checkCompletion();
418
+ (0, import_vue7.watch)(() => (0, import_vue7.toValue)(token), async (newRequestId) => {
419
+ try {
420
+ if (newRequestId && newRequestId.length > 0) {
421
+ activationRequest.value = await storefront.client.activationRequests.get(newRequestId);
422
+ if (activationRequest.value.status === import_storefront_api3.ActivationRequestStatus.Fulfilled) {
423
+ completing.value = true;
424
+ checkCompletion();
425
+ }
426
+ loading.value = false;
427
+ } else {
428
+ error.value = new import_storefront_api3.MoonbaseError("Invalid input", "Missing request id", -1);
429
+ loading.value = false;
425
430
  }
431
+ } catch (err) {
432
+ error.value = err;
426
433
  loading.value = false;
427
- }).catch((e) => {
428
- error.value = e;
429
- loading.value = false;
430
- });
431
- } else {
432
- error.value = new Error("Missing request id");
433
- loading.value = false;
434
- }
434
+ }
435
+ }, { immediate: true });
435
436
  (0, import_vue7.onBeforeUnmount)(() => {
436
437
  if (completionTimeout.value)
437
438
  clearTimeout(completionTimeout.value);
438
439
  });
439
440
  (0, import_vue7.watch)(storefront.currentUser, async () => {
440
441
  var _a, _b;
442
+ const requestId = (0, import_vue7.toValue)(token);
441
443
  if (!requestId || ((_b = (_a = activationRequest.value) == null ? void 0 : _a.licenseEligibility) == null ? void 0 : _b.eligible))
442
444
  return;
443
445
  loading.value = true;
@@ -464,23 +466,22 @@ function useActivationRequest(token, context) {
464
466
  }),
465
467
  fulfillLicense: async () => {
466
468
  fulfilling.value = true;
467
- activationRequest.value = await storefront.client.activationRequests.fulfillLicense(requestId);
469
+ activationRequest.value = await storefront.client.activationRequests.fulfillLicense(activationRequest.value.id);
468
470
  fulfilling.value = false;
469
471
  completing.value = true;
470
472
  const _ = checkCompletion();
471
473
  },
472
474
  fulfillTrial: async () => {
473
475
  fulfilling.value = true;
474
- activationRequest.value = await storefront.client.activationRequests.fulfillTrial(requestId);
476
+ activationRequest.value = await storefront.client.activationRequests.fulfillTrial(activationRequest.value.id);
475
477
  fulfilling.value = false;
476
478
  completing.value = true;
477
479
  const _ = checkCompletion();
478
480
  },
479
481
  cancel: async () => {
480
- var _a;
481
- if (((_a = activationRequest.value) == null ? void 0 : _a.status) === import_storefront_api3.ActivationRequestStatus.Cancelled)
482
+ if (!activationRequest.value || activationRequest.value.status === import_storefront_api3.ActivationRequestStatus.Cancelled)
482
483
  return;
483
- activationRequest.value = await storefront.client.activationRequests.cancel(requestId);
484
+ activationRequest.value = await storefront.client.activationRequests.cancel(activationRequest.value.id);
484
485
  }
485
486
  };
486
487
  }
package/dist/index.js CHANGED
@@ -357,23 +357,22 @@ function useInventory(context) {
357
357
  }
358
358
 
359
359
  // src/composables/useActivationRequest.ts
360
- import { ActivationRequestStatus } from "@moonbase.sh/storefront-api";
360
+ import { ActivationRequestStatus, MoonbaseError } from "@moonbase.sh/storefront-api";
361
361
  import { computed as computed6, inject as inject6, onBeforeUnmount, toValue, watch as watch2 } from "vue";
362
362
  function useActivationRequest(token, context) {
363
363
  const storefront = context != null ? context : inject6(storefrontKey);
364
- const requestId = toValue(token);
365
- if (!requestId)
366
- throw new Error("No request ID was given when calling `useActivationRequest`");
367
364
  if (!storefront)
368
365
  throw new Error("No storefront configured");
369
- const activationRequest = storefront.stateFactory(`activation-request-${requestId}`, null);
370
- const error = storefront.stateFactory(`activation-request-${requestId}-error`, null);
371
- const loading = storefront.stateFactory(`activation-request-${requestId}-loading`, true);
372
- const fulfilling = storefront.stateFactory(`activation-request-${requestId}-fulfilling`, false);
373
- const completing = storefront.stateFactory(`activation-request-${requestId}-completing`, false);
374
- const completionTimeout = storefront.stateFactory(`activation-request-${requestId}-completion-timeout`, null);
366
+ const activationRequest = storefront.stateFactory(`activation-request-${toValue(token)}`, null);
367
+ const error = storefront.stateFactory(`activation-request-${toValue(token)}-error`, null);
368
+ const loading = storefront.stateFactory(`activation-request-${toValue(token)}-loading`, true);
369
+ const fulfilling = storefront.stateFactory(`activation-request-${toValue(token)}-fulfilling`, false);
370
+ const completing = storefront.stateFactory(`activation-request-${toValue(token)}-completing`, false);
371
+ const completionTimeout = storefront.stateFactory(`activation-request-${toValue(token)}-completion-timeout`, null);
375
372
  const checkCompletion = async () => {
376
- const completed = await storefront.client.activationRequests.isCompleted(requestId);
373
+ if (!activationRequest.value)
374
+ return;
375
+ const completed = await storefront.client.activationRequests.isCompleted(activationRequest.value.id);
377
376
  if (completed && activationRequest.value) {
378
377
  activationRequest.value.status = ActivationRequestStatus.Completed;
379
378
  completing.value = false;
@@ -381,28 +380,31 @@ function useActivationRequest(token, context) {
381
380
  completionTimeout.value = setTimeout(checkCompletion, 1500);
382
381
  }
383
382
  };
384
- if (requestId && requestId.length > 0) {
385
- storefront.client.activationRequests.get(requestId).then((result) => {
386
- activationRequest.value = result;
387
- if (activationRequest.value.status === ActivationRequestStatus.Fulfilled) {
388
- completing.value = true;
389
- checkCompletion();
383
+ watch2(() => toValue(token), async (newRequestId) => {
384
+ try {
385
+ if (newRequestId && newRequestId.length > 0) {
386
+ activationRequest.value = await storefront.client.activationRequests.get(newRequestId);
387
+ if (activationRequest.value.status === ActivationRequestStatus.Fulfilled) {
388
+ completing.value = true;
389
+ checkCompletion();
390
+ }
391
+ loading.value = false;
392
+ } else {
393
+ error.value = new MoonbaseError("Invalid input", "Missing request id", -1);
394
+ loading.value = false;
390
395
  }
396
+ } catch (err) {
397
+ error.value = err;
391
398
  loading.value = false;
392
- }).catch((e) => {
393
- error.value = e;
394
- loading.value = false;
395
- });
396
- } else {
397
- error.value = new Error("Missing request id");
398
- loading.value = false;
399
- }
399
+ }
400
+ }, { immediate: true });
400
401
  onBeforeUnmount(() => {
401
402
  if (completionTimeout.value)
402
403
  clearTimeout(completionTimeout.value);
403
404
  });
404
405
  watch2(storefront.currentUser, async () => {
405
406
  var _a, _b;
407
+ const requestId = toValue(token);
406
408
  if (!requestId || ((_b = (_a = activationRequest.value) == null ? void 0 : _a.licenseEligibility) == null ? void 0 : _b.eligible))
407
409
  return;
408
410
  loading.value = true;
@@ -429,23 +431,22 @@ function useActivationRequest(token, context) {
429
431
  }),
430
432
  fulfillLicense: async () => {
431
433
  fulfilling.value = true;
432
- activationRequest.value = await storefront.client.activationRequests.fulfillLicense(requestId);
434
+ activationRequest.value = await storefront.client.activationRequests.fulfillLicense(activationRequest.value.id);
433
435
  fulfilling.value = false;
434
436
  completing.value = true;
435
437
  const _ = checkCompletion();
436
438
  },
437
439
  fulfillTrial: async () => {
438
440
  fulfilling.value = true;
439
- activationRequest.value = await storefront.client.activationRequests.fulfillTrial(requestId);
441
+ activationRequest.value = await storefront.client.activationRequests.fulfillTrial(activationRequest.value.id);
440
442
  fulfilling.value = false;
441
443
  completing.value = true;
442
444
  const _ = checkCompletion();
443
445
  },
444
446
  cancel: async () => {
445
- var _a;
446
- if (((_a = activationRequest.value) == null ? void 0 : _a.status) === ActivationRequestStatus.Cancelled)
447
+ if (!activationRequest.value || activationRequest.value.status === ActivationRequestStatus.Cancelled)
447
448
  return;
448
- activationRequest.value = await storefront.client.activationRequests.cancel(requestId);
449
+ activationRequest.value = await storefront.client.activationRequests.cancel(activationRequest.value.id);
449
450
  }
450
451
  };
451
452
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/vue",
3
3
  "type": "module",
4
- "version": "0.2.31",
4
+ "version": "0.2.33",
5
5
  "description": "Package to let you build vue.js storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",
@@ -19,7 +19,7 @@
19
19
  "@vue/devtools-api": "^6.6.3",
20
20
  "uuid": "^9.0.1",
21
21
  "zod": "^3.23.8",
22
- "@moonbase.sh/storefront-api": "0.2.31"
22
+ "@moonbase.sh/storefront-api": "0.2.33"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/uuid": "^9.0.8",