@moonbase.sh/storefront-api 0.1.90 → 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 +32 -12
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +32 -12
- 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: {
|
|
@@ -583,12 +602,13 @@ var MoonbaseApi = class {
|
|
|
583
602
|
});
|
|
584
603
|
if (response.status >= 400)
|
|
585
604
|
await handleResponseProblem(response);
|
|
586
|
-
|
|
605
|
+
const contentLength = Number(response.headers.get("Content-Length")) || 0;
|
|
606
|
+
return contentLength > 0 ? await response.json() : null;
|
|
587
607
|
}
|
|
588
608
|
};
|
|
589
609
|
|
|
590
610
|
// src/utils/tokenStore.ts
|
|
591
|
-
var
|
|
611
|
+
var import_cross_fetch4 = __toESM(require("cross-fetch"), 1);
|
|
592
612
|
var _TokenStore = class _TokenStore {
|
|
593
613
|
constructor(configuration) {
|
|
594
614
|
this.configuration = configuration;
|
|
@@ -654,7 +674,7 @@ var _TokenStore = class _TokenStore {
|
|
|
654
674
|
async refreshTokens() {
|
|
655
675
|
if (!this.tokens)
|
|
656
676
|
throw new Error("No tokens found to refresh");
|
|
657
|
-
const response = await (0,
|
|
677
|
+
const response = await (0, import_cross_fetch4.default)(`${this.configuration.endpoint}/api/customer/identity/refresh?token=${this.tokens.refreshToken}`, {
|
|
658
678
|
method: "POST",
|
|
659
679
|
headers: {
|
|
660
680
|
"Accept": "application/json",
|
|
@@ -686,13 +706,13 @@ _TokenStore.storageKey = "moonbase_auth";
|
|
|
686
706
|
var TokenStore = _TokenStore;
|
|
687
707
|
|
|
688
708
|
// src/vouchers/schemas.ts
|
|
689
|
-
var
|
|
690
|
-
var voucherSchema =
|
|
691
|
-
id:
|
|
692
|
-
name:
|
|
693
|
-
description:
|
|
694
|
-
code:
|
|
695
|
-
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(),
|
|
696
716
|
redeemsProducts: quantifiable(storefrontProductSchema).array(),
|
|
697
717
|
redeemsBundles: quantifiable(storefrontBundleSchema).array()
|
|
698
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: {
|
|
@@ -538,12 +557,13 @@ var MoonbaseApi = class {
|
|
|
538
557
|
});
|
|
539
558
|
if (response.status >= 400)
|
|
540
559
|
await handleResponseProblem(response);
|
|
541
|
-
|
|
560
|
+
const contentLength = Number(response.headers.get("Content-Length")) || 0;
|
|
561
|
+
return contentLength > 0 ? await response.json() : null;
|
|
542
562
|
}
|
|
543
563
|
};
|
|
544
564
|
|
|
545
565
|
// src/utils/tokenStore.ts
|
|
546
|
-
import
|
|
566
|
+
import fetch4 from "cross-fetch";
|
|
547
567
|
var _TokenStore = class _TokenStore {
|
|
548
568
|
constructor(configuration) {
|
|
549
569
|
this.configuration = configuration;
|
|
@@ -609,7 +629,7 @@ var _TokenStore = class _TokenStore {
|
|
|
609
629
|
async refreshTokens() {
|
|
610
630
|
if (!this.tokens)
|
|
611
631
|
throw new Error("No tokens found to refresh");
|
|
612
|
-
const response = await
|
|
632
|
+
const response = await fetch4(`${this.configuration.endpoint}/api/customer/identity/refresh?token=${this.tokens.refreshToken}`, {
|
|
613
633
|
method: "POST",
|
|
614
634
|
headers: {
|
|
615
635
|
"Accept": "application/json",
|
|
@@ -641,13 +661,13 @@ _TokenStore.storageKey = "moonbase_auth";
|
|
|
641
661
|
var TokenStore = _TokenStore;
|
|
642
662
|
|
|
643
663
|
// src/vouchers/schemas.ts
|
|
644
|
-
import { z as
|
|
645
|
-
var voucherSchema =
|
|
646
|
-
id:
|
|
647
|
-
name:
|
|
648
|
-
description:
|
|
649
|
-
code:
|
|
650
|
-
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(),
|
|
651
671
|
redeemsProducts: quantifiable(storefrontProductSchema).array(),
|
|
652
672
|
redeemsBundles: quantifiable(storefrontBundleSchema).array()
|
|
653
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",
|