@moonbase.sh/storefront-api 0.2.34 → 0.2.35

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
@@ -49,6 +49,44 @@ module.exports = __toCommonJS(src_exports);
49
49
  // src/activationRequests/endpoints.ts
50
50
  var import_zod5 = require("zod");
51
51
 
52
+ // src/utils/errors.ts
53
+ var NotAuthorizedError = class extends Error {
54
+ constructor() {
55
+ super();
56
+ this.name = "NotAuthorizedError";
57
+ this.message = "Not allowed";
58
+ }
59
+ };
60
+ var NotAuthenticatedError = class extends Error {
61
+ constructor() {
62
+ super();
63
+ this.name = "NotAuthenticatedError";
64
+ this.message = "Not authenticated";
65
+ }
66
+ };
67
+ var NotFoundError = class extends Error {
68
+ constructor(message) {
69
+ super();
70
+ this.name = "NotFoundError";
71
+ this.message = message != null ? message : "Not found";
72
+ }
73
+ };
74
+ var MoonbaseError = class extends Error {
75
+ constructor(title, detail, status, errors) {
76
+ super();
77
+ this.title = title;
78
+ this.detail = detail;
79
+ this.status = status;
80
+ this.errors = errors;
81
+ this.name = "MoonbaseError";
82
+ if (errors && Object.values(errors).length === 1) {
83
+ this.message = Object.values(errors)[0];
84
+ } else {
85
+ this.message = detail != null ? detail : title;
86
+ }
87
+ }
88
+ };
89
+
52
90
  // src/activationRequests/schemas.ts
53
91
  var import_zod4 = require("zod");
54
92
 
@@ -204,7 +242,12 @@ var ActivationRequestEndpoints = class {
204
242
  }
205
243
  async get(requestId) {
206
244
  const response = await this.api.fetch(`/api/customer/activations/${requestId}`);
207
- return activationRequestSchema.parse(response.data);
245
+ try {
246
+ return activationRequestSchema.parse(response.data);
247
+ } catch (err) {
248
+ console.error("Could not fetch activation request", { requestId, response, err });
249
+ throw new MoonbaseError("Bad response", "Activation request could not be fetched", response.status);
250
+ }
208
251
  }
209
252
  async isCompleted(requestId) {
210
253
  const response = await this.api.fetch(`/api/customer/activations/${requestId}/completed`);
@@ -212,15 +255,30 @@ var ActivationRequestEndpoints = class {
212
255
  }
213
256
  async fulfillLicense(requestId) {
214
257
  const response = await this.api.authenticatedFetch(`/api/customer/activations/${requestId}/license`, "POST");
215
- return activationRequestSchema.parse(response.data);
258
+ try {
259
+ return activationRequestSchema.parse(response.data);
260
+ } catch (err) {
261
+ console.error("Could not fulfill license", { requestId, response, err });
262
+ throw new MoonbaseError("Bad response", "Activation request could not be fulfilled", response.status);
263
+ }
216
264
  }
217
265
  async fulfillTrial(requestId) {
218
266
  const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, "POST");
219
- return activationRequestSchema.parse(response.data);
267
+ try {
268
+ return activationRequestSchema.parse(response.data);
269
+ } catch (err) {
270
+ console.error("Could not fulfill trial", { requestId, response, err });
271
+ throw new MoonbaseError("Bad response", "Activation request could not be fulfilled", response.status);
272
+ }
220
273
  }
221
274
  async cancel(requestId) {
222
275
  const response = await this.api.fetch(`/api/customer/activations/${requestId}/cancel`, "POST");
223
- return activationRequestSchema.parse(response.data);
276
+ try {
277
+ return activationRequestSchema.parse(response.data);
278
+ } catch (err) {
279
+ console.error("Could not cancel activation request", { requestId, response, err });
280
+ throw new MoonbaseError("Bad response", "Activation request could not be cancelled", response.status);
281
+ }
224
282
  }
225
283
  };
226
284
 
@@ -229,46 +287,6 @@ var import_cross_fetch = __toESM(require("cross-fetch"), 1);
229
287
 
230
288
  // src/utils/problemHandler.ts
231
289
  var import_zod6 = require("zod");
232
-
233
- // src/utils/errors.ts
234
- var NotAuthorizedError = class extends Error {
235
- constructor() {
236
- super();
237
- this.name = "NotAuthorizedError";
238
- this.message = "Not allowed";
239
- }
240
- };
241
- var NotAuthenticatedError = class extends Error {
242
- constructor() {
243
- super();
244
- this.name = "NotAuthenticatedError";
245
- this.message = "Not authenticated";
246
- }
247
- };
248
- var NotFoundError = class extends Error {
249
- constructor(message) {
250
- super();
251
- this.name = "NotFoundError";
252
- this.message = message != null ? message : "Not found";
253
- }
254
- };
255
- var MoonbaseError = class extends Error {
256
- constructor(title, detail, status, errors) {
257
- super();
258
- this.title = title;
259
- this.detail = detail;
260
- this.status = status;
261
- this.errors = errors;
262
- this.name = "MoonbaseError";
263
- if (errors && Object.values(errors).length === 1) {
264
- this.message = Object.values(errors)[0];
265
- } else {
266
- this.message = detail != null ? detail : title;
267
- }
268
- }
269
- };
270
-
271
- // src/utils/problemHandler.ts
272
290
  var problemDetailsSchema = import_zod6.z.object({
273
291
  type: import_zod6.z.string(),
274
292
  title: import_zod6.z.string(),
@@ -349,7 +367,12 @@ var IdentityEndpoints = class {
349
367
  }
350
368
  async get() {
351
369
  const response = await this.api.authenticatedFetch("/api/customer/meta/user");
352
- return userSchema.parse(response.data);
370
+ try {
371
+ return userSchema.parse(response.data);
372
+ } catch (err) {
373
+ console.error("Could not fetch user", { response, err });
374
+ throw new MoonbaseError("Bad response", "Could not fetch user", response.status);
375
+ }
353
376
  }
354
377
  async signIn(email, password) {
355
378
  const response = await (0, import_cross_fetch.default)(`${this.api.baseUrl}/api/customer/identity/sign-in?email=${email}&scheme=JWT`, {
@@ -365,10 +388,15 @@ var IdentityEndpoints = class {
365
388
  throw new NotFoundError("User not found");
366
389
  if (response.status >= 400)
367
390
  await handleResponseProblem(response);
368
- const data = await response.json();
369
- const user = identityUserSchema.parse(data);
370
- this.tokenStore.setUser(user);
371
- return user;
391
+ try {
392
+ const data = await response.json();
393
+ const user = identityUserSchema.parse(data);
394
+ this.tokenStore.setUser(user);
395
+ return user;
396
+ } catch (err) {
397
+ console.error("Could not sign in user", { email, response, err });
398
+ throw new MoonbaseError("Bad response", "Could not sign in user", response.status);
399
+ }
372
400
  }
373
401
  async signUp(name, email, password, address, acceptedPrivacyPolicy, acceptedTermsAndConditions, communicationOptIn) {
374
402
  const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`, "POST", {
@@ -379,9 +407,14 @@ var IdentityEndpoints = class {
379
407
  acceptedPrivacyPolicy,
380
408
  acceptedTermsAndConditions
381
409
  });
382
- const user = identityUserSchema.parse(response.data);
383
- this.tokenStore.setUser(user);
384
- return user;
410
+ try {
411
+ const user = identityUserSchema.parse(response.data);
412
+ this.tokenStore.setUser(user);
413
+ return user;
414
+ } catch (err) {
415
+ console.error("Could not sign up user", { email, response, err });
416
+ throw new MoonbaseError("Bad response", "Could not sign up user", response.status);
417
+ }
385
418
  }
386
419
  async update(name, email, emailConfirmationToken, communicationPreferences) {
387
420
  const response = await this.api.authenticatedFetch("/api/customer/identity", "PATCH", {
@@ -418,7 +451,12 @@ var IdentityEndpoints = class {
418
451
  }
419
452
  async confirmAccount(email, code) {
420
453
  const response = await this.api.fetch(`/api/customer/identity/confirm-account?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, "POST");
421
- return userAccountConfirmedSchema.parse(response.data);
454
+ try {
455
+ return userAccountConfirmedSchema.parse(response.data);
456
+ } catch (err) {
457
+ console.error("Could not confirm user account", { email, code, response, err });
458
+ throw new MoonbaseError("Bad response", "Could not confirm user account", response.status);
459
+ }
422
460
  }
423
461
  async confirmEmail(email, code) {
424
462
  await this.api.fetch(`/api/customer/identity/confirm-email?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, "POST");
@@ -563,7 +601,12 @@ var OrderEndpoints = class {
563
601
  items: order.items
564
602
  }
565
603
  );
566
- return openOrderSchema.parse(response.data);
604
+ try {
605
+ return openOrderSchema.parse(response.data);
606
+ } catch (err) {
607
+ console.error("Could not fetch order", { orderId: order.id, checkout, response, err });
608
+ throw new MoonbaseError("Bad response", "Could not fetch order", response.status);
609
+ }
567
610
  }
568
611
  };
569
612
 
@@ -590,7 +633,12 @@ var StorefrontEndpoints = class {
590
633
  async get(utm) {
591
634
  const query = new URLSearchParams(utmToObject(utm));
592
635
  const response = await this.api.fetch(`/api/customer/storefront?${query.toString()}`);
593
- return storefrontSchema.parse(response.data);
636
+ try {
637
+ return storefrontSchema.parse(response.data);
638
+ } catch (err) {
639
+ console.error("Could not fetch storefront", { response, err });
640
+ throw new MoonbaseError("Bad response", "Could not fetch storefront", response.status);
641
+ }
594
642
  }
595
643
  };
596
644
 
@@ -624,12 +672,25 @@ var MoonbaseApi = class {
624
672
  });
625
673
  if (response.status >= 400)
626
674
  await handleResponseProblem(response);
627
- const contentLength = Number(response.headers.get("Content-Length")) || 0;
628
- return {
629
- data: contentLength > 0 ? await response.json() : null,
630
- headers: response.headers,
631
- status: response.status
632
- };
675
+ try {
676
+ const contentLength = Number(response.headers.get("Content-Length")) || 0;
677
+ const data = contentLength > 0 ? await response.json() : null;
678
+ return {
679
+ data,
680
+ headers: response.headers,
681
+ status: response.status
682
+ };
683
+ } catch (err) {
684
+ console.error("Could not parse response", {
685
+ status: response.status,
686
+ content: await response.text(),
687
+ contentType: response.headers.get("Content-Type"),
688
+ contentLength: response.headers.get("Content-Length"),
689
+ userAgent: window && window.navigator && window.navigator.userAgent,
690
+ err
691
+ });
692
+ throw new MoonbaseError("Bad response", "Could not parse server response", response.status);
693
+ }
633
694
  }
634
695
  };
635
696
 
@@ -764,7 +825,12 @@ var VoucherEndpoints = class {
764
825
  `/api/customer/vouchers/redeem?code=${encodeURIComponent(code)}`,
765
826
  "POST"
766
827
  );
767
- return voucherSchema.parse(response.data);
828
+ try {
829
+ return voucherSchema.parse(response.data);
830
+ } catch (err) {
831
+ console.error("Could not redeem voucher", { response, err });
832
+ throw new MoonbaseError("Bad response", "Could not redeem voucher", response.status);
833
+ }
768
834
  }
769
835
  };
770
836
 
@@ -816,10 +882,15 @@ var ActivationEndpoints = class {
816
882
  }
817
883
  async activate(deviceToken, activationMethod) {
818
884
  const response = await this.api.authenticatedFetch(`/api/customer/inventory/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
819
- return {
820
- license: licenseSchema.parse(response.data),
821
- url: import_zod11.z.string().parse(response.headers.get("location"))
822
- };
885
+ try {
886
+ return {
887
+ license: licenseSchema.parse(response.data),
888
+ url: import_zod11.z.string().parse(response.headers.get("location"))
889
+ };
890
+ } catch (err) {
891
+ console.error("Could not activate product", { deviceToken, activationMethod, response, err });
892
+ throw new MoonbaseError("Bad response", "Product could not be activated", response.status);
893
+ }
823
894
  }
824
895
  };
825
896
 
@@ -830,13 +901,23 @@ var LicenseEndpoints = class {
830
901
  }
831
902
  async get(nextUrl) {
832
903
  const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/licenses");
833
- return paged(licenseSchema).parse(response.data);
904
+ try {
905
+ return paged(licenseSchema).parse(response.data);
906
+ } catch (err) {
907
+ console.error("Could not fetch licenses", { nextUrl, response, err });
908
+ throw new MoonbaseError("Bad response", "Licenses could not be fetched", response.status);
909
+ }
834
910
  }
835
911
  async getActivations(licenseId, nextUrl) {
836
912
  const response = await this.api.authenticatedFetch(
837
913
  nextUrl || `/api/customer/inventory/licenses/${licenseId}/activations`
838
914
  );
839
- return paged(activationSchema).parse(response.data);
915
+ try {
916
+ return paged(activationSchema).parse(response.data);
917
+ } catch (err) {
918
+ console.error("Could not fetch license activations", { nextUrl, response, err });
919
+ throw new MoonbaseError("Bad response", "License activations could not be fetched", response.status);
920
+ }
840
921
  }
841
922
  async revokeActivation(licenseId, activationId) {
842
923
  await this.api.authenticatedFetch(`/api/customer/inventory/licenses/${licenseId}/activations/${activationId}/revoke`, "POST");
@@ -851,19 +932,39 @@ var ProductEndpoints = class {
851
932
  }
852
933
  async get(productId, version) {
853
934
  const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version ? `?version=${version}` : ""}`);
854
- return productSummarySchema.parse(response.data);
935
+ try {
936
+ return productSummarySchema.parse(response.data);
937
+ } catch (err) {
938
+ console.error("Could not fetch product", { productId, version, response, err });
939
+ throw new MoonbaseError("Bad response", "Product could not be fetched", response.status);
940
+ }
855
941
  }
856
942
  async getOwned(nextUrl) {
857
943
  const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/products");
858
- return paged(productSummarySchema).parse(response.data);
944
+ try {
945
+ return paged(productSummarySchema).parse(response.data);
946
+ } catch (err) {
947
+ console.error("Could not fetch products", { nextUrl, response, err });
948
+ throw new MoonbaseError("Bad response", "Products could not be fetched", response.status);
949
+ }
859
950
  }
860
951
  async getLicenses(productId, nextUrl) {
861
952
  const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses`);
862
- return paged(licenseSchema).parse(response.data);
953
+ try {
954
+ return paged(licenseSchema).parse(response.data);
955
+ } catch (err) {
956
+ console.error("Could not fetch product licenses", { productId, nextUrl, response, err });
957
+ throw new MoonbaseError("Bad response", "Product licenses could not be fetched", response.status);
958
+ }
863
959
  }
864
960
  async getActivations(productId, nextUrl) {
865
961
  const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses/activations`);
866
- return paged(activationSchema).parse(response.data);
962
+ try {
963
+ return paged(activationSchema).parse(response.data);
964
+ } catch (err) {
965
+ console.error("Could not fetch product activations", { productId, nextUrl, response, err });
966
+ throw new MoonbaseError("Bad response", "Product activations could not be fetched", response.status);
967
+ }
867
968
  }
868
969
  async getDownloadUrl(path) {
869
970
  const url = new URL(path);
package/dist/index.d.cts CHANGED
@@ -10725,9 +10725,9 @@ declare class NotFoundError extends Error {
10725
10725
  declare class MoonbaseError extends Error {
10726
10726
  readonly title: string;
10727
10727
  readonly detail: string | undefined;
10728
- readonly status: number;
10728
+ readonly status?: number | undefined;
10729
10729
  readonly errors?: Record<string, string> | undefined;
10730
- constructor(title: string, detail: string | undefined, status: number, errors?: Record<string, string> | undefined);
10730
+ constructor(title: string, detail: string | undefined, status?: number | undefined, errors?: Record<string, string> | undefined);
10731
10731
  }
10732
10732
 
10733
10733
  declare namespace schemas {
package/dist/index.d.ts CHANGED
@@ -10725,9 +10725,9 @@ declare class NotFoundError extends Error {
10725
10725
  declare class MoonbaseError extends Error {
10726
10726
  readonly title: string;
10727
10727
  readonly detail: string | undefined;
10728
- readonly status: number;
10728
+ readonly status?: number | undefined;
10729
10729
  readonly errors?: Record<string, string> | undefined;
10730
- constructor(title: string, detail: string | undefined, status: number, errors?: Record<string, string> | undefined);
10730
+ constructor(title: string, detail: string | undefined, status?: number | undefined, errors?: Record<string, string> | undefined);
10731
10731
  }
10732
10732
 
10733
10733
  declare namespace schemas {
package/dist/index.js CHANGED
@@ -7,6 +7,44 @@ var __export = (target, all) => {
7
7
  // src/activationRequests/endpoints.ts
8
8
  import { z as z5 } from "zod";
9
9
 
10
+ // src/utils/errors.ts
11
+ var NotAuthorizedError = class extends Error {
12
+ constructor() {
13
+ super();
14
+ this.name = "NotAuthorizedError";
15
+ this.message = "Not allowed";
16
+ }
17
+ };
18
+ var NotAuthenticatedError = class extends Error {
19
+ constructor() {
20
+ super();
21
+ this.name = "NotAuthenticatedError";
22
+ this.message = "Not authenticated";
23
+ }
24
+ };
25
+ var NotFoundError = class extends Error {
26
+ constructor(message) {
27
+ super();
28
+ this.name = "NotFoundError";
29
+ this.message = message != null ? message : "Not found";
30
+ }
31
+ };
32
+ var MoonbaseError = class extends Error {
33
+ constructor(title, detail, status, errors) {
34
+ super();
35
+ this.title = title;
36
+ this.detail = detail;
37
+ this.status = status;
38
+ this.errors = errors;
39
+ this.name = "MoonbaseError";
40
+ if (errors && Object.values(errors).length === 1) {
41
+ this.message = Object.values(errors)[0];
42
+ } else {
43
+ this.message = detail != null ? detail : title;
44
+ }
45
+ }
46
+ };
47
+
10
48
  // src/activationRequests/schemas.ts
11
49
  import { z as z4 } from "zod";
12
50
 
@@ -162,7 +200,12 @@ var ActivationRequestEndpoints = class {
162
200
  }
163
201
  async get(requestId) {
164
202
  const response = await this.api.fetch(`/api/customer/activations/${requestId}`);
165
- return activationRequestSchema.parse(response.data);
203
+ try {
204
+ return activationRequestSchema.parse(response.data);
205
+ } catch (err) {
206
+ console.error("Could not fetch activation request", { requestId, response, err });
207
+ throw new MoonbaseError("Bad response", "Activation request could not be fetched", response.status);
208
+ }
166
209
  }
167
210
  async isCompleted(requestId) {
168
211
  const response = await this.api.fetch(`/api/customer/activations/${requestId}/completed`);
@@ -170,15 +213,30 @@ var ActivationRequestEndpoints = class {
170
213
  }
171
214
  async fulfillLicense(requestId) {
172
215
  const response = await this.api.authenticatedFetch(`/api/customer/activations/${requestId}/license`, "POST");
173
- return activationRequestSchema.parse(response.data);
216
+ try {
217
+ return activationRequestSchema.parse(response.data);
218
+ } catch (err) {
219
+ console.error("Could not fulfill license", { requestId, response, err });
220
+ throw new MoonbaseError("Bad response", "Activation request could not be fulfilled", response.status);
221
+ }
174
222
  }
175
223
  async fulfillTrial(requestId) {
176
224
  const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, "POST");
177
- return activationRequestSchema.parse(response.data);
225
+ try {
226
+ return activationRequestSchema.parse(response.data);
227
+ } catch (err) {
228
+ console.error("Could not fulfill trial", { requestId, response, err });
229
+ throw new MoonbaseError("Bad response", "Activation request could not be fulfilled", response.status);
230
+ }
178
231
  }
179
232
  async cancel(requestId) {
180
233
  const response = await this.api.fetch(`/api/customer/activations/${requestId}/cancel`, "POST");
181
- return activationRequestSchema.parse(response.data);
234
+ try {
235
+ return activationRequestSchema.parse(response.data);
236
+ } catch (err) {
237
+ console.error("Could not cancel activation request", { requestId, response, err });
238
+ throw new MoonbaseError("Bad response", "Activation request could not be cancelled", response.status);
239
+ }
182
240
  }
183
241
  };
184
242
 
@@ -187,46 +245,6 @@ import fetch from "cross-fetch";
187
245
 
188
246
  // src/utils/problemHandler.ts
189
247
  import { z as z6 } from "zod";
190
-
191
- // src/utils/errors.ts
192
- var NotAuthorizedError = class extends Error {
193
- constructor() {
194
- super();
195
- this.name = "NotAuthorizedError";
196
- this.message = "Not allowed";
197
- }
198
- };
199
- var NotAuthenticatedError = class extends Error {
200
- constructor() {
201
- super();
202
- this.name = "NotAuthenticatedError";
203
- this.message = "Not authenticated";
204
- }
205
- };
206
- var NotFoundError = class extends Error {
207
- constructor(message) {
208
- super();
209
- this.name = "NotFoundError";
210
- this.message = message != null ? message : "Not found";
211
- }
212
- };
213
- var MoonbaseError = class extends Error {
214
- constructor(title, detail, status, errors) {
215
- super();
216
- this.title = title;
217
- this.detail = detail;
218
- this.status = status;
219
- this.errors = errors;
220
- this.name = "MoonbaseError";
221
- if (errors && Object.values(errors).length === 1) {
222
- this.message = Object.values(errors)[0];
223
- } else {
224
- this.message = detail != null ? detail : title;
225
- }
226
- }
227
- };
228
-
229
- // src/utils/problemHandler.ts
230
248
  var problemDetailsSchema = z6.object({
231
249
  type: z6.string(),
232
250
  title: z6.string(),
@@ -307,7 +325,12 @@ var IdentityEndpoints = class {
307
325
  }
308
326
  async get() {
309
327
  const response = await this.api.authenticatedFetch("/api/customer/meta/user");
310
- return userSchema.parse(response.data);
328
+ try {
329
+ return userSchema.parse(response.data);
330
+ } catch (err) {
331
+ console.error("Could not fetch user", { response, err });
332
+ throw new MoonbaseError("Bad response", "Could not fetch user", response.status);
333
+ }
311
334
  }
312
335
  async signIn(email, password) {
313
336
  const response = await fetch(`${this.api.baseUrl}/api/customer/identity/sign-in?email=${email}&scheme=JWT`, {
@@ -323,10 +346,15 @@ var IdentityEndpoints = class {
323
346
  throw new NotFoundError("User not found");
324
347
  if (response.status >= 400)
325
348
  await handleResponseProblem(response);
326
- const data = await response.json();
327
- const user = identityUserSchema.parse(data);
328
- this.tokenStore.setUser(user);
329
- return user;
349
+ try {
350
+ const data = await response.json();
351
+ const user = identityUserSchema.parse(data);
352
+ this.tokenStore.setUser(user);
353
+ return user;
354
+ } catch (err) {
355
+ console.error("Could not sign in user", { email, response, err });
356
+ throw new MoonbaseError("Bad response", "Could not sign in user", response.status);
357
+ }
330
358
  }
331
359
  async signUp(name, email, password, address, acceptedPrivacyPolicy, acceptedTermsAndConditions, communicationOptIn) {
332
360
  const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`, "POST", {
@@ -337,9 +365,14 @@ var IdentityEndpoints = class {
337
365
  acceptedPrivacyPolicy,
338
366
  acceptedTermsAndConditions
339
367
  });
340
- const user = identityUserSchema.parse(response.data);
341
- this.tokenStore.setUser(user);
342
- return user;
368
+ try {
369
+ const user = identityUserSchema.parse(response.data);
370
+ this.tokenStore.setUser(user);
371
+ return user;
372
+ } catch (err) {
373
+ console.error("Could not sign up user", { email, response, err });
374
+ throw new MoonbaseError("Bad response", "Could not sign up user", response.status);
375
+ }
343
376
  }
344
377
  async update(name, email, emailConfirmationToken, communicationPreferences) {
345
378
  const response = await this.api.authenticatedFetch("/api/customer/identity", "PATCH", {
@@ -376,7 +409,12 @@ var IdentityEndpoints = class {
376
409
  }
377
410
  async confirmAccount(email, code) {
378
411
  const response = await this.api.fetch(`/api/customer/identity/confirm-account?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, "POST");
379
- return userAccountConfirmedSchema.parse(response.data);
412
+ try {
413
+ return userAccountConfirmedSchema.parse(response.data);
414
+ } catch (err) {
415
+ console.error("Could not confirm user account", { email, code, response, err });
416
+ throw new MoonbaseError("Bad response", "Could not confirm user account", response.status);
417
+ }
380
418
  }
381
419
  async confirmEmail(email, code) {
382
420
  await this.api.fetch(`/api/customer/identity/confirm-email?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, "POST");
@@ -521,7 +559,12 @@ var OrderEndpoints = class {
521
559
  items: order.items
522
560
  }
523
561
  );
524
- return openOrderSchema.parse(response.data);
562
+ try {
563
+ return openOrderSchema.parse(response.data);
564
+ } catch (err) {
565
+ console.error("Could not fetch order", { orderId: order.id, checkout, response, err });
566
+ throw new MoonbaseError("Bad response", "Could not fetch order", response.status);
567
+ }
525
568
  }
526
569
  };
527
570
 
@@ -548,7 +591,12 @@ var StorefrontEndpoints = class {
548
591
  async get(utm) {
549
592
  const query = new URLSearchParams(utmToObject(utm));
550
593
  const response = await this.api.fetch(`/api/customer/storefront?${query.toString()}`);
551
- return storefrontSchema.parse(response.data);
594
+ try {
595
+ return storefrontSchema.parse(response.data);
596
+ } catch (err) {
597
+ console.error("Could not fetch storefront", { response, err });
598
+ throw new MoonbaseError("Bad response", "Could not fetch storefront", response.status);
599
+ }
552
600
  }
553
601
  };
554
602
 
@@ -582,12 +630,25 @@ var MoonbaseApi = class {
582
630
  });
583
631
  if (response.status >= 400)
584
632
  await handleResponseProblem(response);
585
- const contentLength = Number(response.headers.get("Content-Length")) || 0;
586
- return {
587
- data: contentLength > 0 ? await response.json() : null,
588
- headers: response.headers,
589
- status: response.status
590
- };
633
+ try {
634
+ const contentLength = Number(response.headers.get("Content-Length")) || 0;
635
+ const data = contentLength > 0 ? await response.json() : null;
636
+ return {
637
+ data,
638
+ headers: response.headers,
639
+ status: response.status
640
+ };
641
+ } catch (err) {
642
+ console.error("Could not parse response", {
643
+ status: response.status,
644
+ content: await response.text(),
645
+ contentType: response.headers.get("Content-Type"),
646
+ contentLength: response.headers.get("Content-Length"),
647
+ userAgent: window && window.navigator && window.navigator.userAgent,
648
+ err
649
+ });
650
+ throw new MoonbaseError("Bad response", "Could not parse server response", response.status);
651
+ }
591
652
  }
592
653
  };
593
654
 
@@ -722,7 +783,12 @@ var VoucherEndpoints = class {
722
783
  `/api/customer/vouchers/redeem?code=${encodeURIComponent(code)}`,
723
784
  "POST"
724
785
  );
725
- return voucherSchema.parse(response.data);
786
+ try {
787
+ return voucherSchema.parse(response.data);
788
+ } catch (err) {
789
+ console.error("Could not redeem voucher", { response, err });
790
+ throw new MoonbaseError("Bad response", "Could not redeem voucher", response.status);
791
+ }
726
792
  }
727
793
  };
728
794
 
@@ -774,10 +840,15 @@ var ActivationEndpoints = class {
774
840
  }
775
841
  async activate(deviceToken, activationMethod) {
776
842
  const response = await this.api.authenticatedFetch(`/api/customer/inventory/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
777
- return {
778
- license: licenseSchema.parse(response.data),
779
- url: z11.string().parse(response.headers.get("location"))
780
- };
843
+ try {
844
+ return {
845
+ license: licenseSchema.parse(response.data),
846
+ url: z11.string().parse(response.headers.get("location"))
847
+ };
848
+ } catch (err) {
849
+ console.error("Could not activate product", { deviceToken, activationMethod, response, err });
850
+ throw new MoonbaseError("Bad response", "Product could not be activated", response.status);
851
+ }
781
852
  }
782
853
  };
783
854
 
@@ -788,13 +859,23 @@ var LicenseEndpoints = class {
788
859
  }
789
860
  async get(nextUrl) {
790
861
  const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/licenses");
791
- return paged(licenseSchema).parse(response.data);
862
+ try {
863
+ return paged(licenseSchema).parse(response.data);
864
+ } catch (err) {
865
+ console.error("Could not fetch licenses", { nextUrl, response, err });
866
+ throw new MoonbaseError("Bad response", "Licenses could not be fetched", response.status);
867
+ }
792
868
  }
793
869
  async getActivations(licenseId, nextUrl) {
794
870
  const response = await this.api.authenticatedFetch(
795
871
  nextUrl || `/api/customer/inventory/licenses/${licenseId}/activations`
796
872
  );
797
- return paged(activationSchema).parse(response.data);
873
+ try {
874
+ return paged(activationSchema).parse(response.data);
875
+ } catch (err) {
876
+ console.error("Could not fetch license activations", { nextUrl, response, err });
877
+ throw new MoonbaseError("Bad response", "License activations could not be fetched", response.status);
878
+ }
798
879
  }
799
880
  async revokeActivation(licenseId, activationId) {
800
881
  await this.api.authenticatedFetch(`/api/customer/inventory/licenses/${licenseId}/activations/${activationId}/revoke`, "POST");
@@ -809,19 +890,39 @@ var ProductEndpoints = class {
809
890
  }
810
891
  async get(productId, version) {
811
892
  const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version ? `?version=${version}` : ""}`);
812
- return productSummarySchema.parse(response.data);
893
+ try {
894
+ return productSummarySchema.parse(response.data);
895
+ } catch (err) {
896
+ console.error("Could not fetch product", { productId, version, response, err });
897
+ throw new MoonbaseError("Bad response", "Product could not be fetched", response.status);
898
+ }
813
899
  }
814
900
  async getOwned(nextUrl) {
815
901
  const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/products");
816
- return paged(productSummarySchema).parse(response.data);
902
+ try {
903
+ return paged(productSummarySchema).parse(response.data);
904
+ } catch (err) {
905
+ console.error("Could not fetch products", { nextUrl, response, err });
906
+ throw new MoonbaseError("Bad response", "Products could not be fetched", response.status);
907
+ }
817
908
  }
818
909
  async getLicenses(productId, nextUrl) {
819
910
  const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses`);
820
- return paged(licenseSchema).parse(response.data);
911
+ try {
912
+ return paged(licenseSchema).parse(response.data);
913
+ } catch (err) {
914
+ console.error("Could not fetch product licenses", { productId, nextUrl, response, err });
915
+ throw new MoonbaseError("Bad response", "Product licenses could not be fetched", response.status);
916
+ }
821
917
  }
822
918
  async getActivations(productId, nextUrl) {
823
919
  const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses/activations`);
824
- return paged(activationSchema).parse(response.data);
920
+ try {
921
+ return paged(activationSchema).parse(response.data);
922
+ } catch (err) {
923
+ console.error("Could not fetch product activations", { productId, nextUrl, response, err });
924
+ throw new MoonbaseError("Bad response", "Product activations could not be fetched", response.status);
925
+ }
825
926
  }
826
927
  async getDownloadUrl(path) {
827
928
  const url = new URL(path);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "0.2.34",
4
+ "version": "0.2.35",
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",