@moonbase.sh/storefront-api 0.1.92 → 0.1.93

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
@@ -195,19 +195,19 @@ var ActivationRequestEndpoints = class {
195
195
  }
196
196
  async get(requestId) {
197
197
  const response = await this.api.fetch(`/api/customer/activations/${requestId}`);
198
- return activationRequestSchema.parse(response);
198
+ return activationRequestSchema.parse(response.data);
199
199
  }
200
200
  async isCompleted(requestId) {
201
201
  const response = await this.api.fetch(`/api/customer/activations/${requestId}/completed`);
202
- return import_zod5.z.boolean().parse(response);
202
+ return import_zod5.z.boolean().parse(response.data);
203
203
  }
204
204
  async fulfillLicense(requestId) {
205
205
  const response = await this.api.authenticatedFetch(`/api/customer/activations/${requestId}/license`, "POST");
206
- return activationRequestSchema.parse(response);
206
+ return activationRequestSchema.parse(response.data);
207
207
  }
208
208
  async fulfillTrial(requestId) {
209
209
  const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, "POST");
210
- return activationRequestSchema.parse(response);
210
+ return activationRequestSchema.parse(response.data);
211
211
  }
212
212
  };
213
213
 
@@ -300,7 +300,7 @@ var IdentityEndpoints = class {
300
300
  }
301
301
  async get() {
302
302
  const response = await this.api.authenticatedFetch("/api/customer/meta/user");
303
- return userSchema.parse(response);
303
+ return userSchema.parse(response.data);
304
304
  }
305
305
  async signIn(email, password) {
306
306
  const response = await (0, import_cross_fetch.default)(`${this.api.baseUrl}/api/customer/identity/sign-in?email=${email}&scheme=JWT`, {
@@ -328,7 +328,7 @@ var IdentityEndpoints = class {
328
328
  acceptedPrivacyPolicy,
329
329
  acceptedTermsAndConditions
330
330
  });
331
- const user = identityUserSchema.parse(response);
331
+ const user = identityUserSchema.parse(response.data);
332
332
  this.tokenStore.setUser(user);
333
333
  return user;
334
334
  }
@@ -412,13 +412,13 @@ var LicenseEndpoints = class {
412
412
  }
413
413
  async get(nextUrl) {
414
414
  const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/licenses");
415
- return paged(licenseSchema).parse(response);
415
+ return paged(licenseSchema).parse(response.data);
416
416
  }
417
417
  async getActivations(licenseId, nextUrl) {
418
418
  const response = await this.api.authenticatedFetch(
419
419
  nextUrl || `/api/customer/licenses/${licenseId}/activations`
420
420
  );
421
- return paged(activationSchema).parse(response);
421
+ return paged(activationSchema).parse(response.data);
422
422
  }
423
423
  async revokeActivation(licenseId, activationId) {
424
424
  await this.api.authenticatedFetch(`/api/customer/licenses/${licenseId}/activations/${activationId}/revoke`, "POST");
@@ -509,7 +509,7 @@ var OrderEndpoints = class {
509
509
  }
510
510
  async get(orderId) {
511
511
  const response = await this.api.fetch(`/api/customer/orders/${orderId}`);
512
- return orderSchema.parse(response);
512
+ return orderSchema.parse(response.data);
513
513
  }
514
514
  async pushContent(order, checkout) {
515
515
  const response = await this.api.fetch(
@@ -520,12 +520,11 @@ var OrderEndpoints = class {
520
520
  items: order.items
521
521
  }
522
522
  );
523
- return openOrderSchema.parse(response);
523
+ return openOrderSchema.parse(response.data);
524
524
  }
525
525
  };
526
526
 
527
527
  // src/products/endpoints.ts
528
- var import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
529
528
  var import_zod10 = require("zod");
530
529
  var ProductEndpoints = class {
531
530
  constructor(api) {
@@ -533,30 +532,20 @@ var ProductEndpoints = class {
533
532
  }
534
533
  async getOwned(nextUrl) {
535
534
  const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/products");
536
- return paged(productSummarySchema).parse(response);
535
+ return paged(productSummarySchema).parse(response.data);
537
536
  }
538
537
  async getLicenses(productId, nextUrl) {
539
538
  const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses`);
540
- return paged(licenseSchema).parse(response);
539
+ return paged(licenseSchema).parse(response.data);
541
540
  }
542
541
  async getActivations(productId, nextUrl) {
543
542
  const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses/activations`);
544
- return paged(activationSchema).parse(response);
543
+ return paged(activationSchema).parse(response.data);
545
544
  }
546
545
  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();
546
+ const response = await this.api.authenticatedFetch(`/api/customer/products/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
558
547
  return {
559
- license: licenseSchema.parse(data),
548
+ license: licenseSchema.parse(response.data),
560
549
  url: import_zod10.z.string().parse(response.headers.get("location"))
561
550
  };
562
551
  }
@@ -569,46 +558,51 @@ var StorefrontEndpoints = class {
569
558
  }
570
559
  async get() {
571
560
  const response = await this.api.fetch("/api/customer/storefront");
572
- return storefrontSchema.parse(response);
561
+ return storefrontSchema.parse(response.data);
573
562
  }
574
563
  };
575
564
 
576
565
  // src/utils/api.ts
577
- var import_cross_fetch3 = __toESM(require("cross-fetch"), 1);
566
+ var import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
578
567
  var MoonbaseApi = class {
579
568
  constructor(baseUrl, tokenStore) {
580
569
  this.baseUrl = baseUrl;
581
570
  this.tokenStore = tokenStore;
582
571
  }
583
- async authenticatedFetch(path, method, body) {
572
+ async authenticatedFetch(path, method, body, contentType) {
584
573
  if (!this.tokenStore.hasAccessToken)
585
574
  throw new NotAuthenticatedError();
586
- return await this.fetch(path, method, body);
575
+ return await this.fetch(path, method, body, contentType);
587
576
  }
588
- async fetch(path, method, body) {
577
+ async fetch(path, method, body, contentType) {
589
578
  const accessToken = await this.tokenStore.getAccessToken();
590
- const response = await (0, import_cross_fetch3.default)(this.baseUrl + path, {
579
+ contentType != null ? contentType : contentType = "application/json";
580
+ const response = await (0, import_cross_fetch2.default)(this.baseUrl + path, {
591
581
  method: method || "GET",
592
582
  mode: "cors",
593
583
  headers: {
594
584
  "Accept": "application/json",
595
- "Content-Type": "application/json",
585
+ "Content-Type": contentType,
596
586
  // While this fetch can be anonymous, we add the token if we have it
597
587
  ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
598
588
  // Force CORS on all calls
599
589
  "x-mb-cors": "1"
600
590
  },
601
- body: body ? JSON.stringify(body) : void 0
591
+ body: body ? contentType !== "application/json" ? body : JSON.stringify(body) : void 0
602
592
  });
603
593
  if (response.status >= 400)
604
594
  await handleResponseProblem(response);
605
595
  const contentLength = Number(response.headers.get("Content-Length")) || 0;
606
- return contentLength > 0 ? await response.json() : null;
596
+ return {
597
+ data: contentLength > 0 ? await response.json() : null,
598
+ headers: response.headers,
599
+ status: response.status
600
+ };
607
601
  }
608
602
  };
609
603
 
610
604
  // src/utils/tokenStore.ts
611
- var import_cross_fetch4 = __toESM(require("cross-fetch"), 1);
605
+ var import_cross_fetch3 = __toESM(require("cross-fetch"), 1);
612
606
  var _TokenStore = class _TokenStore {
613
607
  constructor(configuration) {
614
608
  this.configuration = configuration;
@@ -674,7 +668,7 @@ var _TokenStore = class _TokenStore {
674
668
  async refreshTokens() {
675
669
  if (!this.tokens)
676
670
  throw new Error("No tokens found to refresh");
677
- const response = await (0, import_cross_fetch4.default)(`${this.configuration.endpoint}/api/customer/identity/refresh?token=${this.tokens.refreshToken}`, {
671
+ const response = await (0, import_cross_fetch3.default)(`${this.configuration.endpoint}/api/customer/identity/refresh?token=${this.tokens.refreshToken}`, {
678
672
  method: "POST",
679
673
  headers: {
680
674
  "Accept": "application/json",
@@ -724,14 +718,14 @@ var VoucherEndpoints = class {
724
718
  }
725
719
  async peek(code) {
726
720
  const response = await this.api.fetch(`/api/customer/vouchers?code=${encodeURIComponent(code)}`);
727
- return voucherSchema.parse(response);
721
+ return voucherSchema.parse(response.data);
728
722
  }
729
723
  async redeem(code) {
730
724
  const response = await this.api.authenticatedFetch(
731
725
  `/api/customer/vouchers/redeem?code=${encodeURIComponent(code)}`,
732
726
  "POST"
733
727
  );
734
- return voucherSchema.parse(response);
728
+ return voucherSchema.parse(response.data);
735
729
  }
736
730
  };
737
731
 
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<any>;
202
- fetch(path: string, method?: HttpMethods, body?: any): Promise<any>;
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<{
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<any>;
202
- fetch(path: string, method?: HttpMethods, body?: any): Promise<any>;
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<{
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
 
@@ -255,7 +255,7 @@ var IdentityEndpoints = class {
255
255
  }
256
256
  async get() {
257
257
  const response = await this.api.authenticatedFetch("/api/customer/meta/user");
258
- return userSchema.parse(response);
258
+ return userSchema.parse(response.data);
259
259
  }
260
260
  async signIn(email, password) {
261
261
  const response = await fetch(`${this.api.baseUrl}/api/customer/identity/sign-in?email=${email}&scheme=JWT`, {
@@ -283,7 +283,7 @@ var IdentityEndpoints = class {
283
283
  acceptedPrivacyPolicy,
284
284
  acceptedTermsAndConditions
285
285
  });
286
- const user = identityUserSchema.parse(response);
286
+ const user = identityUserSchema.parse(response.data);
287
287
  this.tokenStore.setUser(user);
288
288
  return user;
289
289
  }
@@ -367,13 +367,13 @@ var LicenseEndpoints = class {
367
367
  }
368
368
  async get(nextUrl) {
369
369
  const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/licenses");
370
- return paged(licenseSchema).parse(response);
370
+ return paged(licenseSchema).parse(response.data);
371
371
  }
372
372
  async getActivations(licenseId, nextUrl) {
373
373
  const response = await this.api.authenticatedFetch(
374
374
  nextUrl || `/api/customer/licenses/${licenseId}/activations`
375
375
  );
376
- return paged(activationSchema).parse(response);
376
+ return paged(activationSchema).parse(response.data);
377
377
  }
378
378
  async revokeActivation(licenseId, activationId) {
379
379
  await this.api.authenticatedFetch(`/api/customer/licenses/${licenseId}/activations/${activationId}/revoke`, "POST");
@@ -464,7 +464,7 @@ var OrderEndpoints = class {
464
464
  }
465
465
  async get(orderId) {
466
466
  const response = await this.api.fetch(`/api/customer/orders/${orderId}`);
467
- return orderSchema.parse(response);
467
+ return orderSchema.parse(response.data);
468
468
  }
469
469
  async pushContent(order, checkout) {
470
470
  const response = await this.api.fetch(
@@ -475,12 +475,11 @@ var OrderEndpoints = class {
475
475
  items: order.items
476
476
  }
477
477
  );
478
- return openOrderSchema.parse(response);
478
+ return openOrderSchema.parse(response.data);
479
479
  }
480
480
  };
481
481
 
482
482
  // src/products/endpoints.ts
483
- import fetch2 from "cross-fetch";
484
483
  import { z as z10 } from "zod";
485
484
  var ProductEndpoints = class {
486
485
  constructor(api) {
@@ -488,30 +487,20 @@ var ProductEndpoints = class {
488
487
  }
489
488
  async getOwned(nextUrl) {
490
489
  const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/products");
491
- return paged(productSummarySchema).parse(response);
490
+ return paged(productSummarySchema).parse(response.data);
492
491
  }
493
492
  async getLicenses(productId, nextUrl) {
494
493
  const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses`);
495
- return paged(licenseSchema).parse(response);
494
+ return paged(licenseSchema).parse(response.data);
496
495
  }
497
496
  async getActivations(productId, nextUrl) {
498
497
  const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses/activations`);
499
- return paged(activationSchema).parse(response);
498
+ return paged(activationSchema).parse(response.data);
500
499
  }
501
500
  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();
501
+ const response = await this.api.authenticatedFetch(`/api/customer/products/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
513
502
  return {
514
- license: licenseSchema.parse(data),
503
+ license: licenseSchema.parse(response.data),
515
504
  url: z10.string().parse(response.headers.get("location"))
516
505
  };
517
506
  }
@@ -524,46 +513,51 @@ var StorefrontEndpoints = class {
524
513
  }
525
514
  async get() {
526
515
  const response = await this.api.fetch("/api/customer/storefront");
527
- return storefrontSchema.parse(response);
516
+ return storefrontSchema.parse(response.data);
528
517
  }
529
518
  };
530
519
 
531
520
  // src/utils/api.ts
532
- import fetch3 from "cross-fetch";
521
+ import fetch2 from "cross-fetch";
533
522
  var MoonbaseApi = class {
534
523
  constructor(baseUrl, tokenStore) {
535
524
  this.baseUrl = baseUrl;
536
525
  this.tokenStore = tokenStore;
537
526
  }
538
- async authenticatedFetch(path, method, body) {
527
+ async authenticatedFetch(path, method, body, contentType) {
539
528
  if (!this.tokenStore.hasAccessToken)
540
529
  throw new NotAuthenticatedError();
541
- return await this.fetch(path, method, body);
530
+ return await this.fetch(path, method, body, contentType);
542
531
  }
543
- async fetch(path, method, body) {
532
+ async fetch(path, method, body, contentType) {
544
533
  const accessToken = await this.tokenStore.getAccessToken();
545
- const response = await fetch3(this.baseUrl + path, {
534
+ contentType != null ? contentType : contentType = "application/json";
535
+ const response = await fetch2(this.baseUrl + path, {
546
536
  method: method || "GET",
547
537
  mode: "cors",
548
538
  headers: {
549
539
  "Accept": "application/json",
550
- "Content-Type": "application/json",
540
+ "Content-Type": contentType,
551
541
  // While this fetch can be anonymous, we add the token if we have it
552
542
  ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
553
543
  // Force CORS on all calls
554
544
  "x-mb-cors": "1"
555
545
  },
556
- body: body ? JSON.stringify(body) : void 0
546
+ body: body ? contentType !== "application/json" ? body : JSON.stringify(body) : void 0
557
547
  });
558
548
  if (response.status >= 400)
559
549
  await handleResponseProblem(response);
560
550
  const contentLength = Number(response.headers.get("Content-Length")) || 0;
561
- return contentLength > 0 ? await response.json() : null;
551
+ return {
552
+ data: contentLength > 0 ? await response.json() : null,
553
+ headers: response.headers,
554
+ status: response.status
555
+ };
562
556
  }
563
557
  };
564
558
 
565
559
  // src/utils/tokenStore.ts
566
- import fetch4 from "cross-fetch";
560
+ import fetch3 from "cross-fetch";
567
561
  var _TokenStore = class _TokenStore {
568
562
  constructor(configuration) {
569
563
  this.configuration = configuration;
@@ -629,7 +623,7 @@ var _TokenStore = class _TokenStore {
629
623
  async refreshTokens() {
630
624
  if (!this.tokens)
631
625
  throw new Error("No tokens found to refresh");
632
- const response = await fetch4(`${this.configuration.endpoint}/api/customer/identity/refresh?token=${this.tokens.refreshToken}`, {
626
+ const response = await fetch3(`${this.configuration.endpoint}/api/customer/identity/refresh?token=${this.tokens.refreshToken}`, {
633
627
  method: "POST",
634
628
  headers: {
635
629
  "Accept": "application/json",
@@ -679,14 +673,14 @@ var VoucherEndpoints = class {
679
673
  }
680
674
  async peek(code) {
681
675
  const response = await this.api.fetch(`/api/customer/vouchers?code=${encodeURIComponent(code)}`);
682
- return voucherSchema.parse(response);
676
+ return voucherSchema.parse(response.data);
683
677
  }
684
678
  async redeem(code) {
685
679
  const response = await this.api.authenticatedFetch(
686
680
  `/api/customer/vouchers/redeem?code=${encodeURIComponent(code)}`,
687
681
  "POST"
688
682
  );
689
- return voucherSchema.parse(response);
683
+ return voucherSchema.parse(response.data);
690
684
  }
691
685
  };
692
686
 
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.92",
4
+ "version": "0.1.93",
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",