@moonbase.sh/storefront-api 0.1.92 → 0.1.94
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 +46 -44
- package/dist/index.d.cts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +45 -44
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -35,6 +35,7 @@ __export(src_exports, {
|
|
|
35
35
|
ActivationStatus: () => ActivationStatus,
|
|
36
36
|
LicenseStatus: () => LicenseStatus,
|
|
37
37
|
MoonbaseClient: () => MoonbaseClient,
|
|
38
|
+
MoonbaseError: () => MoonbaseError,
|
|
38
39
|
NotAuthenticatedError: () => NotAuthenticatedError,
|
|
39
40
|
NotAuthorizedError: () => NotAuthorizedError,
|
|
40
41
|
NotFoundError: () => NotFoundError,
|
|
@@ -195,19 +196,19 @@ var ActivationRequestEndpoints = class {
|
|
|
195
196
|
}
|
|
196
197
|
async get(requestId) {
|
|
197
198
|
const response = await this.api.fetch(`/api/customer/activations/${requestId}`);
|
|
198
|
-
return activationRequestSchema.parse(response);
|
|
199
|
+
return activationRequestSchema.parse(response.data);
|
|
199
200
|
}
|
|
200
201
|
async isCompleted(requestId) {
|
|
201
202
|
const response = await this.api.fetch(`/api/customer/activations/${requestId}/completed`);
|
|
202
|
-
return import_zod5.z.boolean().parse(response);
|
|
203
|
+
return import_zod5.z.boolean().parse(response.data);
|
|
203
204
|
}
|
|
204
205
|
async fulfillLicense(requestId) {
|
|
205
206
|
const response = await this.api.authenticatedFetch(`/api/customer/activations/${requestId}/license`, "POST");
|
|
206
|
-
return activationRequestSchema.parse(response);
|
|
207
|
+
return activationRequestSchema.parse(response.data);
|
|
207
208
|
}
|
|
208
209
|
async fulfillTrial(requestId) {
|
|
209
210
|
const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, "POST");
|
|
210
|
-
return activationRequestSchema.parse(response);
|
|
211
|
+
return activationRequestSchema.parse(response.data);
|
|
211
212
|
}
|
|
212
213
|
};
|
|
213
214
|
|
|
@@ -236,6 +237,16 @@ var NotFoundError = class extends Error {
|
|
|
236
237
|
this.name = "NotFoundError";
|
|
237
238
|
}
|
|
238
239
|
};
|
|
240
|
+
var MoonbaseError = class extends Error {
|
|
241
|
+
constructor(title, detail, status) {
|
|
242
|
+
super();
|
|
243
|
+
this.title = title;
|
|
244
|
+
this.detail = detail;
|
|
245
|
+
this.status = status;
|
|
246
|
+
this.name = "MoonbaseError";
|
|
247
|
+
this.message = detail != null ? detail : title;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
239
250
|
|
|
240
251
|
// src/utils/problemHandler.ts
|
|
241
252
|
var problemDetailsSchema = import_zod6.z.object({
|
|
@@ -258,11 +269,7 @@ async function handleResponseProblem(response) {
|
|
|
258
269
|
} catch (e) {
|
|
259
270
|
throw new Error("An unknown problem occurred");
|
|
260
271
|
}
|
|
261
|
-
|
|
262
|
-
throw new Error(problemDetails.detail);
|
|
263
|
-
if (problemDetails.title)
|
|
264
|
-
throw new Error(problemDetails.title);
|
|
265
|
-
throw new Error("An unknown problem occurred");
|
|
272
|
+
throw new MoonbaseError(problemDetails.title, problemDetails.detail, problemDetails.status);
|
|
266
273
|
}
|
|
267
274
|
|
|
268
275
|
// src/identity/schemas.ts
|
|
@@ -300,7 +307,7 @@ var IdentityEndpoints = class {
|
|
|
300
307
|
}
|
|
301
308
|
async get() {
|
|
302
309
|
const response = await this.api.authenticatedFetch("/api/customer/meta/user");
|
|
303
|
-
return userSchema.parse(response);
|
|
310
|
+
return userSchema.parse(response.data);
|
|
304
311
|
}
|
|
305
312
|
async signIn(email, password) {
|
|
306
313
|
const response = await (0, import_cross_fetch.default)(`${this.api.baseUrl}/api/customer/identity/sign-in?email=${email}&scheme=JWT`, {
|
|
@@ -328,7 +335,7 @@ var IdentityEndpoints = class {
|
|
|
328
335
|
acceptedPrivacyPolicy,
|
|
329
336
|
acceptedTermsAndConditions
|
|
330
337
|
});
|
|
331
|
-
const user = identityUserSchema.parse(response);
|
|
338
|
+
const user = identityUserSchema.parse(response.data);
|
|
332
339
|
this.tokenStore.setUser(user);
|
|
333
340
|
return user;
|
|
334
341
|
}
|
|
@@ -412,13 +419,13 @@ var LicenseEndpoints = class {
|
|
|
412
419
|
}
|
|
413
420
|
async get(nextUrl) {
|
|
414
421
|
const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/licenses");
|
|
415
|
-
return paged(licenseSchema).parse(response);
|
|
422
|
+
return paged(licenseSchema).parse(response.data);
|
|
416
423
|
}
|
|
417
424
|
async getActivations(licenseId, nextUrl) {
|
|
418
425
|
const response = await this.api.authenticatedFetch(
|
|
419
426
|
nextUrl || `/api/customer/licenses/${licenseId}/activations`
|
|
420
427
|
);
|
|
421
|
-
return paged(activationSchema).parse(response);
|
|
428
|
+
return paged(activationSchema).parse(response.data);
|
|
422
429
|
}
|
|
423
430
|
async revokeActivation(licenseId, activationId) {
|
|
424
431
|
await this.api.authenticatedFetch(`/api/customer/licenses/${licenseId}/activations/${activationId}/revoke`, "POST");
|
|
@@ -509,7 +516,7 @@ var OrderEndpoints = class {
|
|
|
509
516
|
}
|
|
510
517
|
async get(orderId) {
|
|
511
518
|
const response = await this.api.fetch(`/api/customer/orders/${orderId}`);
|
|
512
|
-
return orderSchema.parse(response);
|
|
519
|
+
return orderSchema.parse(response.data);
|
|
513
520
|
}
|
|
514
521
|
async pushContent(order, checkout) {
|
|
515
522
|
const response = await this.api.fetch(
|
|
@@ -520,12 +527,11 @@ var OrderEndpoints = class {
|
|
|
520
527
|
items: order.items
|
|
521
528
|
}
|
|
522
529
|
);
|
|
523
|
-
return openOrderSchema.parse(response);
|
|
530
|
+
return openOrderSchema.parse(response.data);
|
|
524
531
|
}
|
|
525
532
|
};
|
|
526
533
|
|
|
527
534
|
// src/products/endpoints.ts
|
|
528
|
-
var import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
|
|
529
535
|
var import_zod10 = require("zod");
|
|
530
536
|
var ProductEndpoints = class {
|
|
531
537
|
constructor(api) {
|
|
@@ -533,30 +539,20 @@ var ProductEndpoints = class {
|
|
|
533
539
|
}
|
|
534
540
|
async getOwned(nextUrl) {
|
|
535
541
|
const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/products");
|
|
536
|
-
return paged(productSummarySchema).parse(response);
|
|
542
|
+
return paged(productSummarySchema).parse(response.data);
|
|
537
543
|
}
|
|
538
544
|
async getLicenses(productId, nextUrl) {
|
|
539
545
|
const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses`);
|
|
540
|
-
return paged(licenseSchema).parse(response);
|
|
546
|
+
return paged(licenseSchema).parse(response.data);
|
|
541
547
|
}
|
|
542
548
|
async getActivations(productId, nextUrl) {
|
|
543
549
|
const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses/activations`);
|
|
544
|
-
return paged(activationSchema).parse(response);
|
|
550
|
+
return paged(activationSchema).parse(response.data);
|
|
545
551
|
}
|
|
546
552
|
async activate(deviceToken, activationMethod) {
|
|
547
|
-
const response = await
|
|
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();
|
|
553
|
+
const response = await this.api.authenticatedFetch(`/api/customer/products/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
|
|
558
554
|
return {
|
|
559
|
-
license: licenseSchema.parse(data),
|
|
555
|
+
license: licenseSchema.parse(response.data),
|
|
560
556
|
url: import_zod10.z.string().parse(response.headers.get("location"))
|
|
561
557
|
};
|
|
562
558
|
}
|
|
@@ -569,46 +565,51 @@ var StorefrontEndpoints = class {
|
|
|
569
565
|
}
|
|
570
566
|
async get() {
|
|
571
567
|
const response = await this.api.fetch("/api/customer/storefront");
|
|
572
|
-
return storefrontSchema.parse(response);
|
|
568
|
+
return storefrontSchema.parse(response.data);
|
|
573
569
|
}
|
|
574
570
|
};
|
|
575
571
|
|
|
576
572
|
// src/utils/api.ts
|
|
577
|
-
var
|
|
573
|
+
var import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
|
|
578
574
|
var MoonbaseApi = class {
|
|
579
575
|
constructor(baseUrl, tokenStore) {
|
|
580
576
|
this.baseUrl = baseUrl;
|
|
581
577
|
this.tokenStore = tokenStore;
|
|
582
578
|
}
|
|
583
|
-
async authenticatedFetch(path, method, body) {
|
|
579
|
+
async authenticatedFetch(path, method, body, contentType) {
|
|
584
580
|
if (!this.tokenStore.hasAccessToken)
|
|
585
581
|
throw new NotAuthenticatedError();
|
|
586
|
-
return await this.fetch(path, method, body);
|
|
582
|
+
return await this.fetch(path, method, body, contentType);
|
|
587
583
|
}
|
|
588
|
-
async fetch(path, method, body) {
|
|
584
|
+
async fetch(path, method, body, contentType) {
|
|
589
585
|
const accessToken = await this.tokenStore.getAccessToken();
|
|
590
|
-
|
|
586
|
+
contentType != null ? contentType : contentType = "application/json";
|
|
587
|
+
const response = await (0, import_cross_fetch2.default)(this.baseUrl + path, {
|
|
591
588
|
method: method || "GET",
|
|
592
589
|
mode: "cors",
|
|
593
590
|
headers: {
|
|
594
591
|
"Accept": "application/json",
|
|
595
|
-
"Content-Type":
|
|
592
|
+
"Content-Type": contentType,
|
|
596
593
|
// While this fetch can be anonymous, we add the token if we have it
|
|
597
594
|
...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
|
|
598
595
|
// Force CORS on all calls
|
|
599
596
|
"x-mb-cors": "1"
|
|
600
597
|
},
|
|
601
|
-
body: body ? JSON.stringify(body) : void 0
|
|
598
|
+
body: body ? contentType !== "application/json" ? body : JSON.stringify(body) : void 0
|
|
602
599
|
});
|
|
603
600
|
if (response.status >= 400)
|
|
604
601
|
await handleResponseProblem(response);
|
|
605
602
|
const contentLength = Number(response.headers.get("Content-Length")) || 0;
|
|
606
|
-
return
|
|
603
|
+
return {
|
|
604
|
+
data: contentLength > 0 ? await response.json() : null,
|
|
605
|
+
headers: response.headers,
|
|
606
|
+
status: response.status
|
|
607
|
+
};
|
|
607
608
|
}
|
|
608
609
|
};
|
|
609
610
|
|
|
610
611
|
// src/utils/tokenStore.ts
|
|
611
|
-
var
|
|
612
|
+
var import_cross_fetch3 = __toESM(require("cross-fetch"), 1);
|
|
612
613
|
var _TokenStore = class _TokenStore {
|
|
613
614
|
constructor(configuration) {
|
|
614
615
|
this.configuration = configuration;
|
|
@@ -674,7 +675,7 @@ var _TokenStore = class _TokenStore {
|
|
|
674
675
|
async refreshTokens() {
|
|
675
676
|
if (!this.tokens)
|
|
676
677
|
throw new Error("No tokens found to refresh");
|
|
677
|
-
const response = await (0,
|
|
678
|
+
const response = await (0, import_cross_fetch3.default)(`${this.configuration.endpoint}/api/customer/identity/refresh?token=${this.tokens.refreshToken}`, {
|
|
678
679
|
method: "POST",
|
|
679
680
|
headers: {
|
|
680
681
|
"Accept": "application/json",
|
|
@@ -724,14 +725,14 @@ var VoucherEndpoints = class {
|
|
|
724
725
|
}
|
|
725
726
|
async peek(code) {
|
|
726
727
|
const response = await this.api.fetch(`/api/customer/vouchers?code=${encodeURIComponent(code)}`);
|
|
727
|
-
return voucherSchema.parse(response);
|
|
728
|
+
return voucherSchema.parse(response.data);
|
|
728
729
|
}
|
|
729
730
|
async redeem(code) {
|
|
730
731
|
const response = await this.api.authenticatedFetch(
|
|
731
732
|
`/api/customer/vouchers/redeem?code=${encodeURIComponent(code)}`,
|
|
732
733
|
"POST"
|
|
733
734
|
);
|
|
734
|
-
return voucherSchema.parse(response);
|
|
735
|
+
return voucherSchema.parse(response.data);
|
|
735
736
|
}
|
|
736
737
|
};
|
|
737
738
|
|
|
@@ -758,6 +759,7 @@ var MoonbaseClient = class {
|
|
|
758
759
|
ActivationStatus,
|
|
759
760
|
LicenseStatus,
|
|
760
761
|
MoonbaseClient,
|
|
762
|
+
MoonbaseError,
|
|
761
763
|
NotAuthenticatedError,
|
|
762
764
|
NotAuthorizedError,
|
|
763
765
|
NotFoundError,
|
package/dist/index.d.cts
CHANGED
|
@@ -194,12 +194,17 @@ declare class TokenStore {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
type HttpMethods = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
197
|
+
interface Response {
|
|
198
|
+
data: unknown;
|
|
199
|
+
headers: Headers;
|
|
200
|
+
status: number;
|
|
201
|
+
}
|
|
197
202
|
declare class MoonbaseApi {
|
|
198
203
|
baseUrl: string;
|
|
199
204
|
private tokenStore;
|
|
200
205
|
constructor(baseUrl: string, tokenStore: TokenStore);
|
|
201
|
-
authenticatedFetch(path: string, method?: HttpMethods, body?: any): Promise<
|
|
202
|
-
fetch(path: string, method?: HttpMethods, body?: any): Promise<
|
|
206
|
+
authenticatedFetch(path: string, method?: HttpMethods, body?: any, contentType?: string): Promise<Response>;
|
|
207
|
+
fetch(path: string, method?: HttpMethods, body?: any, contentType?: string): Promise<Response>;
|
|
203
208
|
}
|
|
204
209
|
|
|
205
210
|
declare const activationRequestSchema: z.ZodObject<{
|
|
@@ -13094,6 +13099,12 @@ declare class NotAuthenticatedError extends Error {
|
|
|
13094
13099
|
declare class NotFoundError extends Error {
|
|
13095
13100
|
constructor();
|
|
13096
13101
|
}
|
|
13102
|
+
declare class MoonbaseError extends Error {
|
|
13103
|
+
readonly title: string;
|
|
13104
|
+
readonly detail: string | undefined;
|
|
13105
|
+
readonly status: number;
|
|
13106
|
+
constructor(title: string, detail: string | undefined, status: number);
|
|
13107
|
+
}
|
|
13097
13108
|
|
|
13098
13109
|
interface MoonbaseConfiguration {
|
|
13099
13110
|
endpoint: string;
|
|
@@ -13111,4 +13122,4 @@ declare class MoonbaseClient {
|
|
|
13111
13122
|
orders: OrderEndpoints;
|
|
13112
13123
|
}
|
|
13113
13124
|
|
|
13114
|
-
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type Download, type License, LicenseStatus, type LineItem, MoonbaseClient, type MoonbaseConfiguration, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingVariation, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontProduct, type User, type Voucher };
|
|
13125
|
+
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type Download, type License, LicenseStatus, type LineItem, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingVariation, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontProduct, type User, type Voucher };
|
package/dist/index.d.ts
CHANGED
|
@@ -194,12 +194,17 @@ declare class TokenStore {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
type HttpMethods = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
197
|
+
interface Response {
|
|
198
|
+
data: unknown;
|
|
199
|
+
headers: Headers;
|
|
200
|
+
status: number;
|
|
201
|
+
}
|
|
197
202
|
declare class MoonbaseApi {
|
|
198
203
|
baseUrl: string;
|
|
199
204
|
private tokenStore;
|
|
200
205
|
constructor(baseUrl: string, tokenStore: TokenStore);
|
|
201
|
-
authenticatedFetch(path: string, method?: HttpMethods, body?: any): Promise<
|
|
202
|
-
fetch(path: string, method?: HttpMethods, body?: any): Promise<
|
|
206
|
+
authenticatedFetch(path: string, method?: HttpMethods, body?: any, contentType?: string): Promise<Response>;
|
|
207
|
+
fetch(path: string, method?: HttpMethods, body?: any, contentType?: string): Promise<Response>;
|
|
203
208
|
}
|
|
204
209
|
|
|
205
210
|
declare const activationRequestSchema: z.ZodObject<{
|
|
@@ -13094,6 +13099,12 @@ declare class NotAuthenticatedError extends Error {
|
|
|
13094
13099
|
declare class NotFoundError extends Error {
|
|
13095
13100
|
constructor();
|
|
13096
13101
|
}
|
|
13102
|
+
declare class MoonbaseError extends Error {
|
|
13103
|
+
readonly title: string;
|
|
13104
|
+
readonly detail: string | undefined;
|
|
13105
|
+
readonly status: number;
|
|
13106
|
+
constructor(title: string, detail: string | undefined, status: number);
|
|
13107
|
+
}
|
|
13097
13108
|
|
|
13098
13109
|
interface MoonbaseConfiguration {
|
|
13099
13110
|
endpoint: string;
|
|
@@ -13111,4 +13122,4 @@ declare class MoonbaseClient {
|
|
|
13111
13122
|
orders: OrderEndpoints;
|
|
13112
13123
|
}
|
|
13113
13124
|
|
|
13114
|
-
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type Download, type License, LicenseStatus, type LineItem, MoonbaseClient, type MoonbaseConfiguration, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingVariation, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontProduct, type User, type Voucher };
|
|
13125
|
+
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type Download, type License, LicenseStatus, type LineItem, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingVariation, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontProduct, type User, type Voucher };
|
package/dist/index.js
CHANGED
|
@@ -150,19 +150,19 @@ var ActivationRequestEndpoints = class {
|
|
|
150
150
|
}
|
|
151
151
|
async get(requestId) {
|
|
152
152
|
const response = await this.api.fetch(`/api/customer/activations/${requestId}`);
|
|
153
|
-
return activationRequestSchema.parse(response);
|
|
153
|
+
return activationRequestSchema.parse(response.data);
|
|
154
154
|
}
|
|
155
155
|
async isCompleted(requestId) {
|
|
156
156
|
const response = await this.api.fetch(`/api/customer/activations/${requestId}/completed`);
|
|
157
|
-
return z5.boolean().parse(response);
|
|
157
|
+
return z5.boolean().parse(response.data);
|
|
158
158
|
}
|
|
159
159
|
async fulfillLicense(requestId) {
|
|
160
160
|
const response = await this.api.authenticatedFetch(`/api/customer/activations/${requestId}/license`, "POST");
|
|
161
|
-
return activationRequestSchema.parse(response);
|
|
161
|
+
return activationRequestSchema.parse(response.data);
|
|
162
162
|
}
|
|
163
163
|
async fulfillTrial(requestId) {
|
|
164
164
|
const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, "POST");
|
|
165
|
-
return activationRequestSchema.parse(response);
|
|
165
|
+
return activationRequestSchema.parse(response.data);
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
168
|
|
|
@@ -191,6 +191,16 @@ var NotFoundError = class extends Error {
|
|
|
191
191
|
this.name = "NotFoundError";
|
|
192
192
|
}
|
|
193
193
|
};
|
|
194
|
+
var MoonbaseError = class extends Error {
|
|
195
|
+
constructor(title, detail, status) {
|
|
196
|
+
super();
|
|
197
|
+
this.title = title;
|
|
198
|
+
this.detail = detail;
|
|
199
|
+
this.status = status;
|
|
200
|
+
this.name = "MoonbaseError";
|
|
201
|
+
this.message = detail != null ? detail : title;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
194
204
|
|
|
195
205
|
// src/utils/problemHandler.ts
|
|
196
206
|
var problemDetailsSchema = z6.object({
|
|
@@ -213,11 +223,7 @@ async function handleResponseProblem(response) {
|
|
|
213
223
|
} catch (e) {
|
|
214
224
|
throw new Error("An unknown problem occurred");
|
|
215
225
|
}
|
|
216
|
-
|
|
217
|
-
throw new Error(problemDetails.detail);
|
|
218
|
-
if (problemDetails.title)
|
|
219
|
-
throw new Error(problemDetails.title);
|
|
220
|
-
throw new Error("An unknown problem occurred");
|
|
226
|
+
throw new MoonbaseError(problemDetails.title, problemDetails.detail, problemDetails.status);
|
|
221
227
|
}
|
|
222
228
|
|
|
223
229
|
// src/identity/schemas.ts
|
|
@@ -255,7 +261,7 @@ var IdentityEndpoints = class {
|
|
|
255
261
|
}
|
|
256
262
|
async get() {
|
|
257
263
|
const response = await this.api.authenticatedFetch("/api/customer/meta/user");
|
|
258
|
-
return userSchema.parse(response);
|
|
264
|
+
return userSchema.parse(response.data);
|
|
259
265
|
}
|
|
260
266
|
async signIn(email, password) {
|
|
261
267
|
const response = await fetch(`${this.api.baseUrl}/api/customer/identity/sign-in?email=${email}&scheme=JWT`, {
|
|
@@ -283,7 +289,7 @@ var IdentityEndpoints = class {
|
|
|
283
289
|
acceptedPrivacyPolicy,
|
|
284
290
|
acceptedTermsAndConditions
|
|
285
291
|
});
|
|
286
|
-
const user = identityUserSchema.parse(response);
|
|
292
|
+
const user = identityUserSchema.parse(response.data);
|
|
287
293
|
this.tokenStore.setUser(user);
|
|
288
294
|
return user;
|
|
289
295
|
}
|
|
@@ -367,13 +373,13 @@ var LicenseEndpoints = class {
|
|
|
367
373
|
}
|
|
368
374
|
async get(nextUrl) {
|
|
369
375
|
const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/licenses");
|
|
370
|
-
return paged(licenseSchema).parse(response);
|
|
376
|
+
return paged(licenseSchema).parse(response.data);
|
|
371
377
|
}
|
|
372
378
|
async getActivations(licenseId, nextUrl) {
|
|
373
379
|
const response = await this.api.authenticatedFetch(
|
|
374
380
|
nextUrl || `/api/customer/licenses/${licenseId}/activations`
|
|
375
381
|
);
|
|
376
|
-
return paged(activationSchema).parse(response);
|
|
382
|
+
return paged(activationSchema).parse(response.data);
|
|
377
383
|
}
|
|
378
384
|
async revokeActivation(licenseId, activationId) {
|
|
379
385
|
await this.api.authenticatedFetch(`/api/customer/licenses/${licenseId}/activations/${activationId}/revoke`, "POST");
|
|
@@ -464,7 +470,7 @@ var OrderEndpoints = class {
|
|
|
464
470
|
}
|
|
465
471
|
async get(orderId) {
|
|
466
472
|
const response = await this.api.fetch(`/api/customer/orders/${orderId}`);
|
|
467
|
-
return orderSchema.parse(response);
|
|
473
|
+
return orderSchema.parse(response.data);
|
|
468
474
|
}
|
|
469
475
|
async pushContent(order, checkout) {
|
|
470
476
|
const response = await this.api.fetch(
|
|
@@ -475,12 +481,11 @@ var OrderEndpoints = class {
|
|
|
475
481
|
items: order.items
|
|
476
482
|
}
|
|
477
483
|
);
|
|
478
|
-
return openOrderSchema.parse(response);
|
|
484
|
+
return openOrderSchema.parse(response.data);
|
|
479
485
|
}
|
|
480
486
|
};
|
|
481
487
|
|
|
482
488
|
// src/products/endpoints.ts
|
|
483
|
-
import fetch2 from "cross-fetch";
|
|
484
489
|
import { z as z10 } from "zod";
|
|
485
490
|
var ProductEndpoints = class {
|
|
486
491
|
constructor(api) {
|
|
@@ -488,30 +493,20 @@ var ProductEndpoints = class {
|
|
|
488
493
|
}
|
|
489
494
|
async getOwned(nextUrl) {
|
|
490
495
|
const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/products");
|
|
491
|
-
return paged(productSummarySchema).parse(response);
|
|
496
|
+
return paged(productSummarySchema).parse(response.data);
|
|
492
497
|
}
|
|
493
498
|
async getLicenses(productId, nextUrl) {
|
|
494
499
|
const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses`);
|
|
495
|
-
return paged(licenseSchema).parse(response);
|
|
500
|
+
return paged(licenseSchema).parse(response.data);
|
|
496
501
|
}
|
|
497
502
|
async getActivations(productId, nextUrl) {
|
|
498
503
|
const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses/activations`);
|
|
499
|
-
return paged(activationSchema).parse(response);
|
|
504
|
+
return paged(activationSchema).parse(response.data);
|
|
500
505
|
}
|
|
501
506
|
async activate(deviceToken, activationMethod) {
|
|
502
|
-
const response = await
|
|
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();
|
|
507
|
+
const response = await this.api.authenticatedFetch(`/api/customer/products/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
|
|
513
508
|
return {
|
|
514
|
-
license: licenseSchema.parse(data),
|
|
509
|
+
license: licenseSchema.parse(response.data),
|
|
515
510
|
url: z10.string().parse(response.headers.get("location"))
|
|
516
511
|
};
|
|
517
512
|
}
|
|
@@ -524,46 +519,51 @@ var StorefrontEndpoints = class {
|
|
|
524
519
|
}
|
|
525
520
|
async get() {
|
|
526
521
|
const response = await this.api.fetch("/api/customer/storefront");
|
|
527
|
-
return storefrontSchema.parse(response);
|
|
522
|
+
return storefrontSchema.parse(response.data);
|
|
528
523
|
}
|
|
529
524
|
};
|
|
530
525
|
|
|
531
526
|
// src/utils/api.ts
|
|
532
|
-
import
|
|
527
|
+
import fetch2 from "cross-fetch";
|
|
533
528
|
var MoonbaseApi = class {
|
|
534
529
|
constructor(baseUrl, tokenStore) {
|
|
535
530
|
this.baseUrl = baseUrl;
|
|
536
531
|
this.tokenStore = tokenStore;
|
|
537
532
|
}
|
|
538
|
-
async authenticatedFetch(path, method, body) {
|
|
533
|
+
async authenticatedFetch(path, method, body, contentType) {
|
|
539
534
|
if (!this.tokenStore.hasAccessToken)
|
|
540
535
|
throw new NotAuthenticatedError();
|
|
541
|
-
return await this.fetch(path, method, body);
|
|
536
|
+
return await this.fetch(path, method, body, contentType);
|
|
542
537
|
}
|
|
543
|
-
async fetch(path, method, body) {
|
|
538
|
+
async fetch(path, method, body, contentType) {
|
|
544
539
|
const accessToken = await this.tokenStore.getAccessToken();
|
|
545
|
-
|
|
540
|
+
contentType != null ? contentType : contentType = "application/json";
|
|
541
|
+
const response = await fetch2(this.baseUrl + path, {
|
|
546
542
|
method: method || "GET",
|
|
547
543
|
mode: "cors",
|
|
548
544
|
headers: {
|
|
549
545
|
"Accept": "application/json",
|
|
550
|
-
"Content-Type":
|
|
546
|
+
"Content-Type": contentType,
|
|
551
547
|
// While this fetch can be anonymous, we add the token if we have it
|
|
552
548
|
...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
|
|
553
549
|
// Force CORS on all calls
|
|
554
550
|
"x-mb-cors": "1"
|
|
555
551
|
},
|
|
556
|
-
body: body ? JSON.stringify(body) : void 0
|
|
552
|
+
body: body ? contentType !== "application/json" ? body : JSON.stringify(body) : void 0
|
|
557
553
|
});
|
|
558
554
|
if (response.status >= 400)
|
|
559
555
|
await handleResponseProblem(response);
|
|
560
556
|
const contentLength = Number(response.headers.get("Content-Length")) || 0;
|
|
561
|
-
return
|
|
557
|
+
return {
|
|
558
|
+
data: contentLength > 0 ? await response.json() : null,
|
|
559
|
+
headers: response.headers,
|
|
560
|
+
status: response.status
|
|
561
|
+
};
|
|
562
562
|
}
|
|
563
563
|
};
|
|
564
564
|
|
|
565
565
|
// src/utils/tokenStore.ts
|
|
566
|
-
import
|
|
566
|
+
import fetch3 from "cross-fetch";
|
|
567
567
|
var _TokenStore = class _TokenStore {
|
|
568
568
|
constructor(configuration) {
|
|
569
569
|
this.configuration = configuration;
|
|
@@ -629,7 +629,7 @@ var _TokenStore = class _TokenStore {
|
|
|
629
629
|
async refreshTokens() {
|
|
630
630
|
if (!this.tokens)
|
|
631
631
|
throw new Error("No tokens found to refresh");
|
|
632
|
-
const response = await
|
|
632
|
+
const response = await fetch3(`${this.configuration.endpoint}/api/customer/identity/refresh?token=${this.tokens.refreshToken}`, {
|
|
633
633
|
method: "POST",
|
|
634
634
|
headers: {
|
|
635
635
|
"Accept": "application/json",
|
|
@@ -679,14 +679,14 @@ var VoucherEndpoints = class {
|
|
|
679
679
|
}
|
|
680
680
|
async peek(code) {
|
|
681
681
|
const response = await this.api.fetch(`/api/customer/vouchers?code=${encodeURIComponent(code)}`);
|
|
682
|
-
return voucherSchema.parse(response);
|
|
682
|
+
return voucherSchema.parse(response.data);
|
|
683
683
|
}
|
|
684
684
|
async redeem(code) {
|
|
685
685
|
const response = await this.api.authenticatedFetch(
|
|
686
686
|
`/api/customer/vouchers/redeem?code=${encodeURIComponent(code)}`,
|
|
687
687
|
"POST"
|
|
688
688
|
);
|
|
689
|
-
return voucherSchema.parse(response);
|
|
689
|
+
return voucherSchema.parse(response.data);
|
|
690
690
|
}
|
|
691
691
|
};
|
|
692
692
|
|
|
@@ -712,6 +712,7 @@ export {
|
|
|
712
712
|
ActivationStatus,
|
|
713
713
|
LicenseStatus,
|
|
714
714
|
MoonbaseClient,
|
|
715
|
+
MoonbaseError,
|
|
715
716
|
NotAuthenticatedError,
|
|
716
717
|
NotAuthorizedError,
|
|
717
718
|
NotFoundError,
|
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.94",
|
|
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",
|