@moonbase.sh/storefront-api 0.1.91 → 0.1.92
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 +30 -11
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +30 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -525,6 +525,8 @@ var OrderEndpoints = class {
|
|
|
525
525
|
};
|
|
526
526
|
|
|
527
527
|
// src/products/endpoints.ts
|
|
528
|
+
var import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
|
|
529
|
+
var import_zod10 = require("zod");
|
|
528
530
|
var ProductEndpoints = class {
|
|
529
531
|
constructor(api) {
|
|
530
532
|
this.api = api;
|
|
@@ -541,6 +543,23 @@ var ProductEndpoints = class {
|
|
|
541
543
|
const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses/activations`);
|
|
542
544
|
return paged(activationSchema).parse(response);
|
|
543
545
|
}
|
|
546
|
+
async activate(deviceToken, activationMethod) {
|
|
547
|
+
const response = await (0, import_cross_fetch2.default)(`${this.api.baseUrl}/api/customer/products/activate?method=${activationMethod}`, {
|
|
548
|
+
method: "POST",
|
|
549
|
+
headers: {
|
|
550
|
+
"Accept": "application/json",
|
|
551
|
+
"Content-Type": "text/plain"
|
|
552
|
+
},
|
|
553
|
+
body: deviceToken
|
|
554
|
+
});
|
|
555
|
+
if (response.status >= 400)
|
|
556
|
+
await handleResponseProblem(response);
|
|
557
|
+
const data = await response.json();
|
|
558
|
+
return {
|
|
559
|
+
license: licenseSchema.parse(data),
|
|
560
|
+
url: import_zod10.z.string().parse(response.headers.get("location"))
|
|
561
|
+
};
|
|
562
|
+
}
|
|
544
563
|
};
|
|
545
564
|
|
|
546
565
|
// src/storefront/endpoints.ts
|
|
@@ -555,7 +574,7 @@ var StorefrontEndpoints = class {
|
|
|
555
574
|
};
|
|
556
575
|
|
|
557
576
|
// src/utils/api.ts
|
|
558
|
-
var
|
|
577
|
+
var import_cross_fetch3 = __toESM(require("cross-fetch"), 1);
|
|
559
578
|
var MoonbaseApi = class {
|
|
560
579
|
constructor(baseUrl, tokenStore) {
|
|
561
580
|
this.baseUrl = baseUrl;
|
|
@@ -568,7 +587,7 @@ var MoonbaseApi = class {
|
|
|
568
587
|
}
|
|
569
588
|
async fetch(path, method, body) {
|
|
570
589
|
const accessToken = await this.tokenStore.getAccessToken();
|
|
571
|
-
const response = await (0,
|
|
590
|
+
const response = await (0, import_cross_fetch3.default)(this.baseUrl + path, {
|
|
572
591
|
method: method || "GET",
|
|
573
592
|
mode: "cors",
|
|
574
593
|
headers: {
|
|
@@ -589,7 +608,7 @@ var MoonbaseApi = class {
|
|
|
589
608
|
};
|
|
590
609
|
|
|
591
610
|
// src/utils/tokenStore.ts
|
|
592
|
-
var
|
|
611
|
+
var import_cross_fetch4 = __toESM(require("cross-fetch"), 1);
|
|
593
612
|
var _TokenStore = class _TokenStore {
|
|
594
613
|
constructor(configuration) {
|
|
595
614
|
this.configuration = configuration;
|
|
@@ -655,7 +674,7 @@ var _TokenStore = class _TokenStore {
|
|
|
655
674
|
async refreshTokens() {
|
|
656
675
|
if (!this.tokens)
|
|
657
676
|
throw new Error("No tokens found to refresh");
|
|
658
|
-
const response = await (0,
|
|
677
|
+
const response = await (0, import_cross_fetch4.default)(`${this.configuration.endpoint}/api/customer/identity/refresh?token=${this.tokens.refreshToken}`, {
|
|
659
678
|
method: "POST",
|
|
660
679
|
headers: {
|
|
661
680
|
"Accept": "application/json",
|
|
@@ -687,13 +706,13 @@ _TokenStore.storageKey = "moonbase_auth";
|
|
|
687
706
|
var TokenStore = _TokenStore;
|
|
688
707
|
|
|
689
708
|
// src/vouchers/schemas.ts
|
|
690
|
-
var
|
|
691
|
-
var voucherSchema =
|
|
692
|
-
id:
|
|
693
|
-
name:
|
|
694
|
-
description:
|
|
695
|
-
code:
|
|
696
|
-
redeemed:
|
|
709
|
+
var import_zod11 = require("zod");
|
|
710
|
+
var voucherSchema = import_zod11.z.object({
|
|
711
|
+
id: import_zod11.z.string(),
|
|
712
|
+
name: import_zod11.z.string(),
|
|
713
|
+
description: import_zod11.z.string(),
|
|
714
|
+
code: import_zod11.z.string(),
|
|
715
|
+
redeemed: import_zod11.z.boolean(),
|
|
697
716
|
redeemsProducts: quantifiable(storefrontProductSchema).array(),
|
|
698
717
|
redeemsBundles: quantifiable(storefrontBundleSchema).array()
|
|
699
718
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -9058,6 +9058,10 @@ declare class ProductEndpoints {
|
|
|
9058
9058
|
getOwned(nextUrl?: string): Promise<Page<OwnedProduct>>;
|
|
9059
9059
|
getLicenses(productId: string, nextUrl?: string): Promise<Page<License>>;
|
|
9060
9060
|
getActivations(productId: string, nextUrl?: string): Promise<Page<Activation>>;
|
|
9061
|
+
activate(deviceToken: string, activationMethod: ActivationMethod): Promise<{
|
|
9062
|
+
license: License;
|
|
9063
|
+
url: string;
|
|
9064
|
+
}>;
|
|
9061
9065
|
}
|
|
9062
9066
|
|
|
9063
9067
|
declare class StorefrontEndpoints {
|
package/dist/index.d.ts
CHANGED
|
@@ -9058,6 +9058,10 @@ declare class ProductEndpoints {
|
|
|
9058
9058
|
getOwned(nextUrl?: string): Promise<Page<OwnedProduct>>;
|
|
9059
9059
|
getLicenses(productId: string, nextUrl?: string): Promise<Page<License>>;
|
|
9060
9060
|
getActivations(productId: string, nextUrl?: string): Promise<Page<Activation>>;
|
|
9061
|
+
activate(deviceToken: string, activationMethod: ActivationMethod): Promise<{
|
|
9062
|
+
license: License;
|
|
9063
|
+
url: string;
|
|
9064
|
+
}>;
|
|
9061
9065
|
}
|
|
9062
9066
|
|
|
9063
9067
|
declare class StorefrontEndpoints {
|
package/dist/index.js
CHANGED
|
@@ -480,6 +480,8 @@ var OrderEndpoints = class {
|
|
|
480
480
|
};
|
|
481
481
|
|
|
482
482
|
// src/products/endpoints.ts
|
|
483
|
+
import fetch2 from "cross-fetch";
|
|
484
|
+
import { z as z10 } from "zod";
|
|
483
485
|
var ProductEndpoints = class {
|
|
484
486
|
constructor(api) {
|
|
485
487
|
this.api = api;
|
|
@@ -496,6 +498,23 @@ var ProductEndpoints = class {
|
|
|
496
498
|
const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses/activations`);
|
|
497
499
|
return paged(activationSchema).parse(response);
|
|
498
500
|
}
|
|
501
|
+
async activate(deviceToken, activationMethod) {
|
|
502
|
+
const response = await fetch2(`${this.api.baseUrl}/api/customer/products/activate?method=${activationMethod}`, {
|
|
503
|
+
method: "POST",
|
|
504
|
+
headers: {
|
|
505
|
+
"Accept": "application/json",
|
|
506
|
+
"Content-Type": "text/plain"
|
|
507
|
+
},
|
|
508
|
+
body: deviceToken
|
|
509
|
+
});
|
|
510
|
+
if (response.status >= 400)
|
|
511
|
+
await handleResponseProblem(response);
|
|
512
|
+
const data = await response.json();
|
|
513
|
+
return {
|
|
514
|
+
license: licenseSchema.parse(data),
|
|
515
|
+
url: z10.string().parse(response.headers.get("location"))
|
|
516
|
+
};
|
|
517
|
+
}
|
|
499
518
|
};
|
|
500
519
|
|
|
501
520
|
// src/storefront/endpoints.ts
|
|
@@ -510,7 +529,7 @@ var StorefrontEndpoints = class {
|
|
|
510
529
|
};
|
|
511
530
|
|
|
512
531
|
// src/utils/api.ts
|
|
513
|
-
import
|
|
532
|
+
import fetch3 from "cross-fetch";
|
|
514
533
|
var MoonbaseApi = class {
|
|
515
534
|
constructor(baseUrl, tokenStore) {
|
|
516
535
|
this.baseUrl = baseUrl;
|
|
@@ -523,7 +542,7 @@ var MoonbaseApi = class {
|
|
|
523
542
|
}
|
|
524
543
|
async fetch(path, method, body) {
|
|
525
544
|
const accessToken = await this.tokenStore.getAccessToken();
|
|
526
|
-
const response = await
|
|
545
|
+
const response = await fetch3(this.baseUrl + path, {
|
|
527
546
|
method: method || "GET",
|
|
528
547
|
mode: "cors",
|
|
529
548
|
headers: {
|
|
@@ -544,7 +563,7 @@ var MoonbaseApi = class {
|
|
|
544
563
|
};
|
|
545
564
|
|
|
546
565
|
// src/utils/tokenStore.ts
|
|
547
|
-
import
|
|
566
|
+
import fetch4 from "cross-fetch";
|
|
548
567
|
var _TokenStore = class _TokenStore {
|
|
549
568
|
constructor(configuration) {
|
|
550
569
|
this.configuration = configuration;
|
|
@@ -610,7 +629,7 @@ var _TokenStore = class _TokenStore {
|
|
|
610
629
|
async refreshTokens() {
|
|
611
630
|
if (!this.tokens)
|
|
612
631
|
throw new Error("No tokens found to refresh");
|
|
613
|
-
const response = await
|
|
632
|
+
const response = await fetch4(`${this.configuration.endpoint}/api/customer/identity/refresh?token=${this.tokens.refreshToken}`, {
|
|
614
633
|
method: "POST",
|
|
615
634
|
headers: {
|
|
616
635
|
"Accept": "application/json",
|
|
@@ -642,13 +661,13 @@ _TokenStore.storageKey = "moonbase_auth";
|
|
|
642
661
|
var TokenStore = _TokenStore;
|
|
643
662
|
|
|
644
663
|
// src/vouchers/schemas.ts
|
|
645
|
-
import { z as
|
|
646
|
-
var voucherSchema =
|
|
647
|
-
id:
|
|
648
|
-
name:
|
|
649
|
-
description:
|
|
650
|
-
code:
|
|
651
|
-
redeemed:
|
|
664
|
+
import { z as z11 } from "zod";
|
|
665
|
+
var voucherSchema = z11.object({
|
|
666
|
+
id: z11.string(),
|
|
667
|
+
name: z11.string(),
|
|
668
|
+
description: z11.string(),
|
|
669
|
+
code: z11.string(),
|
|
670
|
+
redeemed: z11.boolean(),
|
|
652
671
|
redeemsProducts: quantifiable(storefrontProductSchema).array(),
|
|
653
672
|
redeemsBundles: quantifiable(storefrontBundleSchema).array()
|
|
654
673
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/storefront-api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.92",
|
|
5
5
|
"description": "Package to let you build storefronts with Moonbase.sh as payment and delivery provider",
|
|
6
6
|
"author": "Tobias Lønnerød Madsen <m@dsen.tv>",
|
|
7
7
|
"license": "MIT",
|