@moonbase.sh/storefront-api 0.2.38 → 0.2.39

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,44 +49,6 @@ 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
-
90
52
  // src/activationRequests/schemas.ts
91
53
  var import_zod4 = require("zod");
92
54
 
@@ -241,52 +203,73 @@ var ActivationRequestEndpoints = class {
241
203
  this.api = api;
242
204
  }
243
205
  async get(requestId) {
244
- const response = await this.api.fetch(`/api/customer/activations/${requestId}`);
245
- try {
246
- return activationRequestSchema.parse(response.data);
247
- } catch (err) {
248
- console.warn("Could not fetch activation request", { requestId, response, err });
249
- throw new MoonbaseError("Bad response", "Activation request could not be fetched", response.status);
250
- }
206
+ const response = await this.api.fetch(`/api/customer/activations/${requestId}`, activationRequestSchema);
207
+ return response.data;
251
208
  }
252
209
  async isCompleted(requestId) {
253
- const response = await this.api.fetch(`/api/customer/activations/${requestId}/completed`);
210
+ const response = await this.api.fetch(`/api/customer/activations/${requestId}/completed`, import_zod5.z.boolean());
254
211
  return import_zod5.z.boolean().parse(response.data);
255
212
  }
256
213
  async fulfillLicense(requestId) {
257
- const response = await this.api.authenticatedFetch(`/api/customer/activations/${requestId}/license`, "POST");
258
- try {
259
- return activationRequestSchema.parse(response.data);
260
- } catch (err) {
261
- console.warn("Could not fulfill license", { requestId, response, err });
262
- throw new MoonbaseError("Bad response", "Activation request could not be fulfilled", response.status);
263
- }
214
+ const response = await this.api.authenticatedFetch(`/api/customer/activations/${requestId}/license`, activationRequestSchema, { method: "POST" });
215
+ return response.data;
264
216
  }
265
217
  async fulfillTrial(requestId) {
266
- const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, "POST");
267
- try {
268
- return activationRequestSchema.parse(response.data);
269
- } catch (err) {
270
- console.warn("Could not fulfill trial", { requestId, response, err });
271
- throw new MoonbaseError("Bad response", "Activation request could not be fulfilled", response.status);
272
- }
218
+ const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, activationRequestSchema, { method: "POST" });
219
+ return response.data;
273
220
  }
274
221
  async cancel(requestId) {
275
- const response = await this.api.fetch(`/api/customer/activations/${requestId}/cancel`, "POST");
276
- try {
277
- return activationRequestSchema.parse(response.data);
278
- } catch (err) {
279
- console.warn("Could not cancel activation request", { requestId, response, err });
280
- throw new MoonbaseError("Bad response", "Activation request could not be cancelled", response.status);
281
- }
222
+ const response = await this.api.fetch(`/api/customer/activations/${requestId}/cancel`, activationRequestSchema, { method: "POST" });
223
+ return response.data;
282
224
  }
283
225
  };
284
226
 
285
227
  // src/identity/endpoints.ts
286
228
  var import_cross_fetch = __toESM(require("cross-fetch"), 1);
229
+ var import_zod8 = require("zod");
287
230
 
288
231
  // src/utils/problemHandler.ts
289
232
  var import_zod6 = require("zod");
233
+
234
+ // src/utils/errors.ts
235
+ var NotAuthorizedError = class extends Error {
236
+ constructor() {
237
+ super();
238
+ this.name = "NotAuthorizedError";
239
+ this.message = "Not allowed";
240
+ }
241
+ };
242
+ var NotAuthenticatedError = class extends Error {
243
+ constructor() {
244
+ super();
245
+ this.name = "NotAuthenticatedError";
246
+ this.message = "Not authenticated";
247
+ }
248
+ };
249
+ var NotFoundError = class extends Error {
250
+ constructor(message) {
251
+ super();
252
+ this.name = "NotFoundError";
253
+ this.message = message != null ? message : "Not found";
254
+ }
255
+ };
256
+ var MoonbaseError = class extends Error {
257
+ constructor(title, detail, status, errors) {
258
+ super();
259
+ this.title = title;
260
+ this.detail = detail;
261
+ this.status = status;
262
+ this.errors = errors;
263
+ this.name = "MoonbaseError";
264
+ if (errors && Object.values(errors).length === 1) {
265
+ this.message = Object.values(errors)[0];
266
+ } else {
267
+ this.message = detail != null ? detail : title;
268
+ }
269
+ }
270
+ };
271
+
272
+ // src/utils/problemHandler.ts
290
273
  var problemDetailsSchema = import_zod6.z.object({
291
274
  type: import_zod6.z.string(),
292
275
  title: import_zod6.z.string(),
@@ -366,13 +349,8 @@ var IdentityEndpoints = class {
366
349
  this.tokenStore = tokenStore;
367
350
  }
368
351
  async get() {
369
- const response = await this.api.authenticatedFetch("/api/customer/meta/user");
370
- try {
371
- return userSchema.parse(response.data);
372
- } catch (err) {
373
- console.warn("Could not fetch user", { response, err });
374
- throw new MoonbaseError("Bad response", "Could not fetch user", response.status);
375
- }
352
+ const response = await this.api.authenticatedFetch("/api/customer/meta/user", userSchema);
353
+ return response.data;
376
354
  }
377
355
  async signIn(email, password) {
378
356
  const response = await (0, import_cross_fetch.default)(`${this.api.baseUrl}/api/customer/identity/sign-in?email=${email}&scheme=JWT`, {
@@ -399,42 +377,45 @@ var IdentityEndpoints = class {
399
377
  }
400
378
  }
401
379
  async signUp(name, email, password, address, acceptedPrivacyPolicy, acceptedTermsAndConditions, communicationOptIn) {
402
- const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`, "POST", {
403
- name,
404
- email,
405
- password,
406
- address,
407
- acceptedPrivacyPolicy,
408
- acceptedTermsAndConditions
380
+ const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`, identityUserSchema, {
381
+ method: "POST",
382
+ body: {
383
+ name,
384
+ email,
385
+ password,
386
+ address,
387
+ acceptedPrivacyPolicy,
388
+ acceptedTermsAndConditions
389
+ }
409
390
  });
410
- try {
411
- const user = identityUserSchema.parse(response.data);
412
- this.tokenStore.setUser(user);
413
- return user;
414
- } catch (err) {
415
- console.warn("Could not sign up user", { email, response, err });
416
- throw new MoonbaseError("Bad response", "Could not sign up user", response.status);
417
- }
391
+ this.tokenStore.setUser(response.data);
392
+ return response.data;
418
393
  }
419
394
  async update(name, email, emailConfirmationToken, communicationPreferences) {
420
- const response = await this.api.authenticatedFetch("/api/customer/identity", "PATCH", {
421
- name,
422
- email,
423
- emailConfirmationToken,
424
- communicationPreferences
395
+ const response = await this.api.authenticatedFetch("/api/customer/identity", import_zod8.z.null(), {
396
+ method: "PATCH",
397
+ body: {
398
+ name,
399
+ email,
400
+ emailConfirmationToken,
401
+ communicationPreferences
402
+ }
425
403
  });
426
404
  return {
427
405
  needsEmailConfirmationToken: response.status === 201
428
406
  };
429
407
  }
430
408
  async setPassword(currentPassword, newPassword) {
431
- await this.api.authenticatedFetch(`/api/customer/identity/set-password`, "POST", {
432
- currentPassword,
433
- newPassword
409
+ await this.api.authenticatedFetch(`/api/customer/identity/set-password`, import_zod8.z.null(), {
410
+ method: "POST",
411
+ body: {
412
+ currentPassword,
413
+ newPassword
414
+ }
434
415
  });
435
416
  }
436
417
  async forgotPassword(email) {
437
- await this.api.fetch(`/api/customer/identity/forgot-password?email=${encodeURIComponent(email)}`, "POST");
418
+ await this.api.fetch(`/api/customer/identity/forgot-password?email=${encodeURIComponent(email)}`, import_zod8.z.null(), { method: "POST" });
438
419
  }
439
420
  async resetPassword(email, newPassword, code) {
440
421
  const response = await (0, import_cross_fetch.default)(`${this.api.baseUrl}/api/customer/identity/reset-password?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, {
@@ -450,7 +431,7 @@ var IdentityEndpoints = class {
450
431
  await handleResponseProblem(response);
451
432
  }
452
433
  async confirmAccount(email, code) {
453
- const response = await this.api.fetch(`/api/customer/identity/confirm-account?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, "POST");
434
+ const response = await this.api.fetch(`/api/customer/identity/confirm-account?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, userAccountConfirmedSchema, { method: "POST" });
454
435
  try {
455
436
  return userAccountConfirmedSchema.parse(response.data);
456
437
  } catch (err) {
@@ -459,10 +440,10 @@ var IdentityEndpoints = class {
459
440
  }
460
441
  }
461
442
  async confirmEmail(email, code) {
462
- await this.api.fetch(`/api/customer/identity/confirm-email?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, "POST");
443
+ await this.api.fetch(`/api/customer/identity/confirm-email?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, import_zod8.z.null(), { method: "POST" });
463
444
  }
464
445
  async confirmEmailChange(email, code) {
465
- await this.api.authenticatedFetch(`/api/customer/identity/confirm-email-change?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, "POST");
446
+ await this.api.authenticatedFetch(`/api/customer/identity/confirm-email-change?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, import_zod8.z.null(), { method: "POST" });
466
447
  }
467
448
  };
468
449
 
@@ -476,7 +457,7 @@ __export(schemas_exports, {
476
457
  openProductLineItem: () => openProductLineItem,
477
458
  orderSchema: () => orderSchema
478
459
  });
479
- var import_zod8 = require("zod");
460
+ var import_zod9 = require("zod");
480
461
 
481
462
  // src/orders/models.ts
482
463
  var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
@@ -488,90 +469,90 @@ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
488
469
  })(OrderStatus || {});
489
470
 
490
471
  // src/orders/schemas.ts
491
- var couponSchema = import_zod8.z.object({
492
- code: import_zod8.z.string(),
493
- name: import_zod8.z.string(),
494
- description: import_zod8.z.string()
472
+ var couponSchema = import_zod9.z.object({
473
+ code: import_zod9.z.string(),
474
+ name: import_zod9.z.string(),
475
+ description: import_zod9.z.string()
495
476
  });
496
- var lineItemProductSchema = import_zod8.z.object({
497
- id: import_zod8.z.string(),
498
- name: import_zod8.z.string(),
499
- tagline: import_zod8.z.string(),
500
- iconUrl: import_zod8.z.string().nullable()
477
+ var lineItemProductSchema = import_zod9.z.object({
478
+ id: import_zod9.z.string(),
479
+ name: import_zod9.z.string(),
480
+ tagline: import_zod9.z.string(),
481
+ iconUrl: import_zod9.z.string().nullable()
501
482
  });
502
- var openProductLineItem = import_zod8.z.object({
503
- id: import_zod8.z.string(),
504
- type: import_zod8.z.literal("Product"),
505
- productId: import_zod8.z.string(),
506
- quantity: import_zod8.z.number(),
507
- variationId: import_zod8.z.string(),
483
+ var openProductLineItem = import_zod9.z.object({
484
+ id: import_zod9.z.string(),
485
+ type: import_zod9.z.literal("Product"),
486
+ productId: import_zod9.z.string(),
487
+ quantity: import_zod9.z.number(),
488
+ variationId: import_zod9.z.string(),
508
489
  price: priceCollectionSchema.optional(),
509
490
  variation: pricingVariationSchema.optional(),
510
491
  product: lineItemProductSchema.optional(),
511
492
  appliedDiscount: discountSchema.optional()
512
493
  });
513
- var lineItemBundleSchema = import_zod8.z.object({
514
- id: import_zod8.z.string(),
515
- name: import_zod8.z.string(),
516
- tagline: import_zod8.z.string(),
517
- iconUrl: import_zod8.z.string().nullable(),
518
- partial: import_zod8.z.boolean(),
519
- products: lineItemProductSchema.and(import_zod8.z.object({
520
- included: import_zod8.z.boolean().optional()
494
+ var lineItemBundleSchema = import_zod9.z.object({
495
+ id: import_zod9.z.string(),
496
+ name: import_zod9.z.string(),
497
+ tagline: import_zod9.z.string(),
498
+ iconUrl: import_zod9.z.string().nullable(),
499
+ partial: import_zod9.z.boolean(),
500
+ products: lineItemProductSchema.and(import_zod9.z.object({
501
+ included: import_zod9.z.boolean().optional()
521
502
  })).array()
522
503
  });
523
- var openBundleLineItem = import_zod8.z.object({
524
- id: import_zod8.z.string(),
525
- type: import_zod8.z.literal("Bundle"),
526
- bundleId: import_zod8.z.string(),
527
- quantity: import_zod8.z.number(),
528
- variationId: import_zod8.z.string(),
504
+ var openBundleLineItem = import_zod9.z.object({
505
+ id: import_zod9.z.string(),
506
+ type: import_zod9.z.literal("Bundle"),
507
+ bundleId: import_zod9.z.string(),
508
+ quantity: import_zod9.z.number(),
509
+ variationId: import_zod9.z.string(),
529
510
  price: priceCollectionSchema.optional(),
530
511
  variation: pricingVariationSchema.optional(),
531
512
  bundle: lineItemBundleSchema.optional(),
532
513
  appliedDiscount: discountSchema.optional()
533
514
  });
534
- var openOrderLineItem = import_zod8.z.discriminatedUnion("type", [
515
+ var openOrderLineItem = import_zod9.z.discriminatedUnion("type", [
535
516
  openProductLineItem,
536
517
  openBundleLineItem
537
518
  ]);
538
- var openOrderSchema = import_zod8.z.object({
539
- id: import_zod8.z.string(),
540
- status: import_zod8.z.literal("Open" /* Open */),
541
- currency: import_zod8.z.string(),
519
+ var openOrderSchema = import_zod9.z.object({
520
+ id: import_zod9.z.string(),
521
+ status: import_zod9.z.literal("Open" /* Open */),
522
+ currency: import_zod9.z.string(),
542
523
  items: openOrderLineItem.array(),
543
524
  couponsApplied: couponSchema.array(),
544
- checkoutUrl: import_zod8.z.string().optional(),
545
- embeddedCheckoutUrl: import_zod8.z.string().optional()
525
+ checkoutUrl: import_zod9.z.string().optional(),
526
+ embeddedCheckoutUrl: import_zod9.z.string().optional()
546
527
  });
547
- var moneySchema = import_zod8.z.object({
548
- currency: import_zod8.z.string(),
549
- amount: import_zod8.z.number()
528
+ var moneySchema = import_zod9.z.object({
529
+ currency: import_zod9.z.string(),
530
+ amount: import_zod9.z.number()
550
531
  });
551
- var orderTotalSchema = import_zod8.z.object({
532
+ var orderTotalSchema = import_zod9.z.object({
552
533
  original: moneySchema,
553
534
  discount: moneySchema,
554
535
  subtotal: moneySchema,
555
536
  taxes: moneySchema,
556
537
  due: moneySchema
557
538
  });
558
- var customerSnapshotSchema = import_zod8.z.object({
559
- name: import_zod8.z.string().nullable(),
560
- businessName: import_zod8.z.string().nullable(),
561
- taxId: import_zod8.z.string().nullable(),
562
- email: import_zod8.z.string().nullable(),
539
+ var customerSnapshotSchema = import_zod9.z.object({
540
+ name: import_zod9.z.string().nullable(),
541
+ businessName: import_zod9.z.string().nullable(),
542
+ taxId: import_zod9.z.string().nullable(),
543
+ email: import_zod9.z.string().nullable(),
563
544
  address: addressSchema.nullable()
564
545
  });
565
- var completedOrderSchema = import_zod8.z.object({
566
- id: import_zod8.z.string(),
567
- status: import_zod8.z.literal("Completed" /* Completed */),
568
- currency: import_zod8.z.string(),
546
+ var completedOrderSchema = import_zod9.z.object({
547
+ id: import_zod9.z.string(),
548
+ status: import_zod9.z.literal("Completed" /* Completed */),
549
+ currency: import_zod9.z.string(),
569
550
  customer: customerSnapshotSchema,
570
551
  total: orderTotalSchema,
571
552
  items: openOrderLineItem.array(),
572
553
  couponsApplied: couponSchema.array()
573
554
  });
574
- var orderSchema = import_zod8.z.discriminatedUnion("status", [
555
+ var orderSchema = import_zod9.z.discriminatedUnion("status", [
575
556
  openOrderSchema,
576
557
  completedOrderSchema
577
558
  ]);
@@ -582,8 +563,8 @@ var OrderEndpoints = class {
582
563
  this.api = api;
583
564
  }
584
565
  async get(orderId) {
585
- const response = await this.api.fetch(`/api/customer/orders/${orderId}`);
586
- return orderSchema.parse(response.data);
566
+ const response = await this.api.fetch(`/api/customer/orders/${orderId}`, orderSchema);
567
+ return response.data;
587
568
  }
588
569
  async pushContent(order, checkout, utm) {
589
570
  const query = {
@@ -595,18 +576,16 @@ var OrderEndpoints = class {
595
576
  }
596
577
  const response = await this.api.fetch(
597
578
  `/api/customer/orders/${order.id}?${new URLSearchParams(query).toString()}`,
598
- "PATCH",
579
+ openOrderSchema,
599
580
  {
600
- currency: order.currency || void 0,
601
- items: order.items
581
+ method: "PATCH",
582
+ body: {
583
+ currency: order.currency || void 0,
584
+ items: order.items
585
+ }
602
586
  }
603
587
  );
604
- try {
605
- return openOrderSchema.parse(response.data);
606
- } catch (err) {
607
- console.warn("Could not fetch order", { orderId: order.id, checkout, response, err });
608
- throw new MoonbaseError("Bad response", "Could not fetch order", response.status);
609
- }
588
+ return response.data;
610
589
  }
611
590
  };
612
591
 
@@ -632,33 +611,30 @@ var StorefrontEndpoints = class {
632
611
  }
633
612
  async get(utm) {
634
613
  const query = new URLSearchParams(utmToObject(utm));
635
- const response = await this.api.fetch(`/api/customer/storefront?${query.toString()}`);
636
- try {
637
- return storefrontSchema.parse(response.data);
638
- } catch (err) {
639
- console.warn("Could not fetch storefront", { response, err });
640
- throw new MoonbaseError("Bad response", "Could not fetch storefront", response.status);
641
- }
614
+ const response = await this.api.fetch(`/api/customer/storefront?${query.toString()}`, storefrontSchema);
615
+ return response.data;
642
616
  }
643
617
  };
644
618
 
645
619
  // src/utils/api.ts
646
620
  var import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
621
+ var import_zod10 = require("zod");
647
622
  var MoonbaseApi = class {
648
623
  constructor(baseUrl, tokenStore) {
649
624
  this.baseUrl = baseUrl;
650
625
  this.tokenStore = tokenStore;
651
626
  }
652
- async authenticatedFetch(path, method, body, contentType) {
627
+ async authenticatedFetch(path, schema, options) {
653
628
  if (!this.tokenStore.hasAccessToken)
654
629
  throw new NotAuthenticatedError();
655
- return await this.fetch(path, method, body, contentType);
630
+ return await this.fetch(path, schema, options);
656
631
  }
657
- async fetch(path, method, body, contentType) {
632
+ async fetch(path, schema, options) {
633
+ var _a;
658
634
  const accessToken = await this.tokenStore.getAccessToken();
659
- contentType != null ? contentType : contentType = "application/json";
635
+ const contentType = (_a = options == null ? void 0 : options.contentType) != null ? _a : "application/json";
660
636
  const response = await (0, import_cross_fetch2.default)(this.baseUrl + path, {
661
- method: method || "GET",
637
+ method: (options == null ? void 0 : options.method) || "GET",
662
638
  mode: "cors",
663
639
  headers: {
664
640
  "Accept": "application/json",
@@ -668,15 +644,13 @@ var MoonbaseApi = class {
668
644
  // Force CORS on all calls
669
645
  "x-mb-cors": "1"
670
646
  },
671
- body: body ? contentType !== "application/json" ? body : JSON.stringify(body) : void 0
647
+ body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0
672
648
  });
673
649
  if (response.status >= 400)
674
650
  await handleResponseProblem(response);
675
651
  try {
676
- const contentLength = Number(response.headers.get("Content-Length")) || 0;
677
- const data = contentLength > 0 ? await response.json() : null;
678
652
  return {
679
- data,
653
+ data: schema instanceof import_zod10.ZodNull ? null : schema.parse(await response.json()),
680
654
  headers: Object.fromEntries(response.headers.entries()),
681
655
  status: response.status
682
656
  };
@@ -684,8 +658,7 @@ var MoonbaseApi = class {
684
658
  console.warn("Could not parse response", {
685
659
  status: response.status,
686
660
  content: await response.text(),
687
- contentType: response.headers.get("Content-Type"),
688
- contentLength: response.headers.get("Content-Length"),
661
+ headers: Object.fromEntries(response.headers.entries()),
689
662
  userAgent: window && window.navigator && window.navigator.userAgent,
690
663
  err
691
664
  });
@@ -800,13 +773,13 @@ _TokenStore.storageKey = "moonbase_auth";
800
773
  var TokenStore = _TokenStore;
801
774
 
802
775
  // src/vouchers/schemas.ts
803
- var import_zod9 = require("zod");
804
- var voucherSchema = import_zod9.z.object({
805
- id: import_zod9.z.string(),
806
- name: import_zod9.z.string(),
807
- description: import_zod9.z.string(),
808
- code: import_zod9.z.string(),
809
- redeemed: import_zod9.z.boolean(),
776
+ var import_zod11 = require("zod");
777
+ var voucherSchema = import_zod11.z.object({
778
+ id: import_zod11.z.string(),
779
+ name: import_zod11.z.string(),
780
+ description: import_zod11.z.string(),
781
+ code: import_zod11.z.string(),
782
+ redeemed: import_zod11.z.boolean(),
810
783
  redeemsProducts: quantifiable(storefrontProductSchema).array(),
811
784
  redeemsBundles: quantifiable(storefrontBundleSchema).array()
812
785
  });
@@ -817,28 +790,26 @@ var VoucherEndpoints = class {
817
790
  this.api = api;
818
791
  }
819
792
  async peek(code) {
820
- const response = await this.api.fetch(`/api/customer/vouchers?code=${encodeURIComponent(code)}`);
821
- return voucherSchema.parse(response.data);
793
+ const response = await this.api.fetch(`/api/customer/vouchers?code=${encodeURIComponent(code)}`, voucherSchema);
794
+ return response.data;
822
795
  }
823
796
  async redeem(code) {
824
797
  const response = await this.api.authenticatedFetch(
825
798
  `/api/customer/vouchers/redeem?code=${encodeURIComponent(code)}`,
826
- "POST"
799
+ voucherSchema,
800
+ {
801
+ method: "POST"
802
+ }
827
803
  );
828
- try {
829
- return voucherSchema.parse(response.data);
830
- } catch (err) {
831
- console.warn("Could not redeem voucher", { response, err });
832
- throw new MoonbaseError("Bad response", "Could not redeem voucher", response.status);
833
- }
804
+ return response.data;
834
805
  }
835
806
  };
836
807
 
837
808
  // src/inventory/activation/endpoints.ts
838
- var import_zod11 = require("zod");
809
+ var import_zod13 = require("zod");
839
810
 
840
811
  // src/inventory/licenses/schemas.ts
841
- var import_zod10 = require("zod");
812
+ var import_zod12 = require("zod");
842
813
 
843
814
  // src/inventory/licenses/models.ts
844
815
  var LicenseStatus = /* @__PURE__ */ ((LicenseStatus2) => {
@@ -858,21 +829,21 @@ var ActivationMethod = /* @__PURE__ */ ((ActivationMethod2) => {
858
829
  })(ActivationMethod || {});
859
830
 
860
831
  // src/inventory/licenses/schemas.ts
861
- var licenseSchema = import_zod10.z.object({
862
- id: import_zod10.z.string(),
863
- status: import_zod10.z.nativeEnum(LicenseStatus),
832
+ var licenseSchema = import_zod12.z.object({
833
+ id: import_zod12.z.string(),
834
+ status: import_zod12.z.nativeEnum(LicenseStatus),
864
835
  product: productSummarySchema,
865
- activeNumberOfActivations: import_zod10.z.number(),
866
- maxNumberOfActivations: import_zod10.z.number(),
867
- createdAt: import_zod10.z.coerce.date()
836
+ activeNumberOfActivations: import_zod12.z.number(),
837
+ maxNumberOfActivations: import_zod12.z.number(),
838
+ createdAt: import_zod12.z.coerce.date()
868
839
  });
869
- var activationSchema = import_zod10.z.object({
870
- id: import_zod10.z.string(),
871
- licenseId: import_zod10.z.string(),
872
- name: import_zod10.z.string(),
873
- status: import_zod10.z.nativeEnum(ActivationStatus),
874
- activationMethod: import_zod10.z.nativeEnum(ActivationMethod),
875
- lastValidatedAt: import_zod10.z.coerce.date().nullable()
840
+ var activationSchema = import_zod12.z.object({
841
+ id: import_zod12.z.string(),
842
+ licenseId: import_zod12.z.string(),
843
+ name: import_zod12.z.string(),
844
+ status: import_zod12.z.nativeEnum(ActivationStatus),
845
+ activationMethod: import_zod12.z.nativeEnum(ActivationMethod),
846
+ lastValidatedAt: import_zod12.z.coerce.date().nullable()
876
847
  });
877
848
 
878
849
  // src/inventory/activation/endpoints.ts
@@ -881,99 +852,69 @@ var ActivationEndpoints = class {
881
852
  this.api = api;
882
853
  }
883
854
  async activate(deviceToken, activationMethod) {
884
- const response = await this.api.authenticatedFetch(`/api/customer/inventory/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
885
- try {
886
- return {
887
- license: licenseSchema.parse(response.data),
888
- url: import_zod11.z.string().parse(response.headers.location)
889
- };
890
- } catch (err) {
891
- console.warn("Could not activate product", { deviceToken, activationMethod, response, err });
892
- throw new MoonbaseError("Bad response", "Product could not be activated", response.status);
893
- }
855
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/activate?method=${activationMethod}`, licenseSchema, {
856
+ method: "POST",
857
+ body: deviceToken,
858
+ contentType: "text/plain"
859
+ });
860
+ return {
861
+ license: response.data,
862
+ url: import_zod13.z.string().parse(response.headers.location)
863
+ };
894
864
  }
895
865
  };
896
866
 
897
867
  // src/inventory/licenses/endpoints.ts
868
+ var import_zod14 = require("zod");
898
869
  var LicenseEndpoints = class {
899
870
  constructor(api) {
900
871
  this.api = api;
901
872
  }
902
873
  async get(nextUrl) {
903
- const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/licenses");
904
- try {
905
- return paged(licenseSchema).parse(response.data);
906
- } catch (err) {
907
- console.warn("Could not fetch licenses", { nextUrl, response, err });
908
- throw new MoonbaseError("Bad response", "Licenses could not be fetched", response.status);
909
- }
874
+ const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/licenses", paged(licenseSchema));
875
+ return response.data;
910
876
  }
911
877
  async getActivations(licenseId, nextUrl) {
912
878
  const response = await this.api.authenticatedFetch(
913
- nextUrl || `/api/customer/inventory/licenses/${licenseId}/activations`
879
+ nextUrl || `/api/customer/inventory/licenses/${licenseId}/activations`,
880
+ paged(activationSchema)
914
881
  );
915
- try {
916
- return paged(activationSchema).parse(response.data);
917
- } catch (err) {
918
- console.warn("Could not fetch license activations", { nextUrl, response, err });
919
- throw new MoonbaseError("Bad response", "License activations could not be fetched", response.status);
920
- }
882
+ return response.data;
921
883
  }
922
884
  async revokeActivation(licenseId, activationId) {
923
- await this.api.authenticatedFetch(`/api/customer/inventory/licenses/${licenseId}/activations/${activationId}/revoke`, "POST");
885
+ await this.api.authenticatedFetch(`/api/customer/inventory/licenses/${licenseId}/activations/${activationId}/revoke`, import_zod14.z.null(), { method: "POST" });
924
886
  }
925
887
  };
926
888
 
927
889
  // src/inventory/products/endpoints.ts
928
- var import_zod12 = require("zod");
890
+ var import_zod15 = require("zod");
929
891
  var ProductEndpoints = class {
930
892
  constructor(api) {
931
893
  this.api = api;
932
894
  }
933
895
  async get(productId, version) {
934
- const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version ? `?version=${version}` : ""}`);
935
- try {
936
- return productSummarySchema.parse(response.data);
937
- } catch (err) {
938
- console.warn("Could not fetch product", { productId, version, response, err });
939
- throw new MoonbaseError("Bad response", "Product could not be fetched", response.status);
940
- }
896
+ const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version ? `?version=${version}` : ""}`, productSummarySchema);
897
+ return response.data;
941
898
  }
942
899
  async getOwned(nextUrl) {
943
- const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/products");
944
- try {
945
- return paged(productSummarySchema).parse(response.data);
946
- } catch (err) {
947
- console.warn("Could not fetch products", { nextUrl, response, err });
948
- throw new MoonbaseError("Bad response", "Products could not be fetched", response.status);
949
- }
900
+ const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/products", paged(productSummarySchema));
901
+ return response.data;
950
902
  }
951
903
  async getLicenses(productId, nextUrl) {
952
- const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses`);
953
- try {
954
- return paged(licenseSchema).parse(response.data);
955
- } catch (err) {
956
- console.warn("Could not fetch product licenses", { productId, nextUrl, response, err });
957
- throw new MoonbaseError("Bad response", "Product licenses could not be fetched", response.status);
958
- }
904
+ const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses`, paged(licenseSchema));
905
+ return response.data;
959
906
  }
960
907
  async getActivations(productId, nextUrl) {
961
- const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses/activations`);
962
- try {
963
- return paged(activationSchema).parse(response.data);
964
- } catch (err) {
965
- console.warn("Could not fetch product activations", { productId, nextUrl, response, err });
966
- throw new MoonbaseError("Bad response", "Product activations could not be fetched", response.status);
967
- }
908
+ const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses/activations`, paged(activationSchema));
909
+ return response.data;
968
910
  }
969
911
  async getDownloadUrl(path) {
970
912
  const url = new URL(path);
971
913
  url.searchParams.append("redirect", "false");
972
- const response = await this.api.fetch(url.pathname + url.search);
973
- const content = import_zod12.z.object({
974
- location: import_zod12.z.string()
975
- }).parse(response.data);
976
- return content.location;
914
+ const response = await this.api.fetch(url.pathname + url.search, import_zod15.z.object({
915
+ location: import_zod15.z.string()
916
+ }));
917
+ return response.data.location;
977
918
  }
978
919
  };
979
920