@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.js CHANGED
@@ -7,44 +7,6 @@ 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
-
48
10
  // src/activationRequests/schemas.ts
49
11
  import { z as z4 } from "zod";
50
12
 
@@ -199,52 +161,73 @@ var ActivationRequestEndpoints = class {
199
161
  this.api = api;
200
162
  }
201
163
  async get(requestId) {
202
- const response = await this.api.fetch(`/api/customer/activations/${requestId}`);
203
- try {
204
- return activationRequestSchema.parse(response.data);
205
- } catch (err) {
206
- console.warn("Could not fetch activation request", { requestId, response, err });
207
- throw new MoonbaseError("Bad response", "Activation request could not be fetched", response.status);
208
- }
164
+ const response = await this.api.fetch(`/api/customer/activations/${requestId}`, activationRequestSchema);
165
+ return response.data;
209
166
  }
210
167
  async isCompleted(requestId) {
211
- const response = await this.api.fetch(`/api/customer/activations/${requestId}/completed`);
168
+ const response = await this.api.fetch(`/api/customer/activations/${requestId}/completed`, z5.boolean());
212
169
  return z5.boolean().parse(response.data);
213
170
  }
214
171
  async fulfillLicense(requestId) {
215
- const response = await this.api.authenticatedFetch(`/api/customer/activations/${requestId}/license`, "POST");
216
- try {
217
- return activationRequestSchema.parse(response.data);
218
- } catch (err) {
219
- console.warn("Could not fulfill license", { requestId, response, err });
220
- throw new MoonbaseError("Bad response", "Activation request could not be fulfilled", response.status);
221
- }
172
+ const response = await this.api.authenticatedFetch(`/api/customer/activations/${requestId}/license`, activationRequestSchema, { method: "POST" });
173
+ return response.data;
222
174
  }
223
175
  async fulfillTrial(requestId) {
224
- const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, "POST");
225
- try {
226
- return activationRequestSchema.parse(response.data);
227
- } catch (err) {
228
- console.warn("Could not fulfill trial", { requestId, response, err });
229
- throw new MoonbaseError("Bad response", "Activation request could not be fulfilled", response.status);
230
- }
176
+ const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, activationRequestSchema, { method: "POST" });
177
+ return response.data;
231
178
  }
232
179
  async cancel(requestId) {
233
- const response = await this.api.fetch(`/api/customer/activations/${requestId}/cancel`, "POST");
234
- try {
235
- return activationRequestSchema.parse(response.data);
236
- } catch (err) {
237
- console.warn("Could not cancel activation request", { requestId, response, err });
238
- throw new MoonbaseError("Bad response", "Activation request could not be cancelled", response.status);
239
- }
180
+ const response = await this.api.fetch(`/api/customer/activations/${requestId}/cancel`, activationRequestSchema, { method: "POST" });
181
+ return response.data;
240
182
  }
241
183
  };
242
184
 
243
185
  // src/identity/endpoints.ts
244
186
  import fetch from "cross-fetch";
187
+ import { z as z8 } from "zod";
245
188
 
246
189
  // src/utils/problemHandler.ts
247
190
  import { z as z6 } from "zod";
191
+
192
+ // src/utils/errors.ts
193
+ var NotAuthorizedError = class extends Error {
194
+ constructor() {
195
+ super();
196
+ this.name = "NotAuthorizedError";
197
+ this.message = "Not allowed";
198
+ }
199
+ };
200
+ var NotAuthenticatedError = class extends Error {
201
+ constructor() {
202
+ super();
203
+ this.name = "NotAuthenticatedError";
204
+ this.message = "Not authenticated";
205
+ }
206
+ };
207
+ var NotFoundError = class extends Error {
208
+ constructor(message) {
209
+ super();
210
+ this.name = "NotFoundError";
211
+ this.message = message != null ? message : "Not found";
212
+ }
213
+ };
214
+ var MoonbaseError = class extends Error {
215
+ constructor(title, detail, status, errors) {
216
+ super();
217
+ this.title = title;
218
+ this.detail = detail;
219
+ this.status = status;
220
+ this.errors = errors;
221
+ this.name = "MoonbaseError";
222
+ if (errors && Object.values(errors).length === 1) {
223
+ this.message = Object.values(errors)[0];
224
+ } else {
225
+ this.message = detail != null ? detail : title;
226
+ }
227
+ }
228
+ };
229
+
230
+ // src/utils/problemHandler.ts
248
231
  var problemDetailsSchema = z6.object({
249
232
  type: z6.string(),
250
233
  title: z6.string(),
@@ -324,13 +307,8 @@ var IdentityEndpoints = class {
324
307
  this.tokenStore = tokenStore;
325
308
  }
326
309
  async get() {
327
- const response = await this.api.authenticatedFetch("/api/customer/meta/user");
328
- try {
329
- return userSchema.parse(response.data);
330
- } catch (err) {
331
- console.warn("Could not fetch user", { response, err });
332
- throw new MoonbaseError("Bad response", "Could not fetch user", response.status);
333
- }
310
+ const response = await this.api.authenticatedFetch("/api/customer/meta/user", userSchema);
311
+ return response.data;
334
312
  }
335
313
  async signIn(email, password) {
336
314
  const response = await fetch(`${this.api.baseUrl}/api/customer/identity/sign-in?email=${email}&scheme=JWT`, {
@@ -357,42 +335,45 @@ var IdentityEndpoints = class {
357
335
  }
358
336
  }
359
337
  async signUp(name, email, password, address, acceptedPrivacyPolicy, acceptedTermsAndConditions, communicationOptIn) {
360
- const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`, "POST", {
361
- name,
362
- email,
363
- password,
364
- address,
365
- acceptedPrivacyPolicy,
366
- acceptedTermsAndConditions
338
+ const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`, identityUserSchema, {
339
+ method: "POST",
340
+ body: {
341
+ name,
342
+ email,
343
+ password,
344
+ address,
345
+ acceptedPrivacyPolicy,
346
+ acceptedTermsAndConditions
347
+ }
367
348
  });
368
- try {
369
- const user = identityUserSchema.parse(response.data);
370
- this.tokenStore.setUser(user);
371
- return user;
372
- } catch (err) {
373
- console.warn("Could not sign up user", { email, response, err });
374
- throw new MoonbaseError("Bad response", "Could not sign up user", response.status);
375
- }
349
+ this.tokenStore.setUser(response.data);
350
+ return response.data;
376
351
  }
377
352
  async update(name, email, emailConfirmationToken, communicationPreferences) {
378
- const response = await this.api.authenticatedFetch("/api/customer/identity", "PATCH", {
379
- name,
380
- email,
381
- emailConfirmationToken,
382
- communicationPreferences
353
+ const response = await this.api.authenticatedFetch("/api/customer/identity", z8.null(), {
354
+ method: "PATCH",
355
+ body: {
356
+ name,
357
+ email,
358
+ emailConfirmationToken,
359
+ communicationPreferences
360
+ }
383
361
  });
384
362
  return {
385
363
  needsEmailConfirmationToken: response.status === 201
386
364
  };
387
365
  }
388
366
  async setPassword(currentPassword, newPassword) {
389
- await this.api.authenticatedFetch(`/api/customer/identity/set-password`, "POST", {
390
- currentPassword,
391
- newPassword
367
+ await this.api.authenticatedFetch(`/api/customer/identity/set-password`, z8.null(), {
368
+ method: "POST",
369
+ body: {
370
+ currentPassword,
371
+ newPassword
372
+ }
392
373
  });
393
374
  }
394
375
  async forgotPassword(email) {
395
- await this.api.fetch(`/api/customer/identity/forgot-password?email=${encodeURIComponent(email)}`, "POST");
376
+ await this.api.fetch(`/api/customer/identity/forgot-password?email=${encodeURIComponent(email)}`, z8.null(), { method: "POST" });
396
377
  }
397
378
  async resetPassword(email, newPassword, code) {
398
379
  const response = await fetch(`${this.api.baseUrl}/api/customer/identity/reset-password?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, {
@@ -408,7 +389,7 @@ var IdentityEndpoints = class {
408
389
  await handleResponseProblem(response);
409
390
  }
410
391
  async confirmAccount(email, code) {
411
- const response = await this.api.fetch(`/api/customer/identity/confirm-account?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, "POST");
392
+ const response = await this.api.fetch(`/api/customer/identity/confirm-account?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, userAccountConfirmedSchema, { method: "POST" });
412
393
  try {
413
394
  return userAccountConfirmedSchema.parse(response.data);
414
395
  } catch (err) {
@@ -417,10 +398,10 @@ var IdentityEndpoints = class {
417
398
  }
418
399
  }
419
400
  async confirmEmail(email, code) {
420
- await this.api.fetch(`/api/customer/identity/confirm-email?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, "POST");
401
+ await this.api.fetch(`/api/customer/identity/confirm-email?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, z8.null(), { method: "POST" });
421
402
  }
422
403
  async confirmEmailChange(email, code) {
423
- await this.api.authenticatedFetch(`/api/customer/identity/confirm-email-change?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, "POST");
404
+ await this.api.authenticatedFetch(`/api/customer/identity/confirm-email-change?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}`, z8.null(), { method: "POST" });
424
405
  }
425
406
  };
426
407
 
@@ -434,7 +415,7 @@ __export(schemas_exports, {
434
415
  openProductLineItem: () => openProductLineItem,
435
416
  orderSchema: () => orderSchema
436
417
  });
437
- import { z as z8 } from "zod";
418
+ import { z as z9 } from "zod";
438
419
 
439
420
  // src/orders/models.ts
440
421
  var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
@@ -446,90 +427,90 @@ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
446
427
  })(OrderStatus || {});
447
428
 
448
429
  // src/orders/schemas.ts
449
- var couponSchema = z8.object({
450
- code: z8.string(),
451
- name: z8.string(),
452
- description: z8.string()
430
+ var couponSchema = z9.object({
431
+ code: z9.string(),
432
+ name: z9.string(),
433
+ description: z9.string()
453
434
  });
454
- var lineItemProductSchema = z8.object({
455
- id: z8.string(),
456
- name: z8.string(),
457
- tagline: z8.string(),
458
- iconUrl: z8.string().nullable()
435
+ var lineItemProductSchema = z9.object({
436
+ id: z9.string(),
437
+ name: z9.string(),
438
+ tagline: z9.string(),
439
+ iconUrl: z9.string().nullable()
459
440
  });
460
- var openProductLineItem = z8.object({
461
- id: z8.string(),
462
- type: z8.literal("Product"),
463
- productId: z8.string(),
464
- quantity: z8.number(),
465
- variationId: z8.string(),
441
+ var openProductLineItem = z9.object({
442
+ id: z9.string(),
443
+ type: z9.literal("Product"),
444
+ productId: z9.string(),
445
+ quantity: z9.number(),
446
+ variationId: z9.string(),
466
447
  price: priceCollectionSchema.optional(),
467
448
  variation: pricingVariationSchema.optional(),
468
449
  product: lineItemProductSchema.optional(),
469
450
  appliedDiscount: discountSchema.optional()
470
451
  });
471
- var lineItemBundleSchema = z8.object({
472
- id: z8.string(),
473
- name: z8.string(),
474
- tagline: z8.string(),
475
- iconUrl: z8.string().nullable(),
476
- partial: z8.boolean(),
477
- products: lineItemProductSchema.and(z8.object({
478
- included: z8.boolean().optional()
452
+ var lineItemBundleSchema = z9.object({
453
+ id: z9.string(),
454
+ name: z9.string(),
455
+ tagline: z9.string(),
456
+ iconUrl: z9.string().nullable(),
457
+ partial: z9.boolean(),
458
+ products: lineItemProductSchema.and(z9.object({
459
+ included: z9.boolean().optional()
479
460
  })).array()
480
461
  });
481
- var openBundleLineItem = z8.object({
482
- id: z8.string(),
483
- type: z8.literal("Bundle"),
484
- bundleId: z8.string(),
485
- quantity: z8.number(),
486
- variationId: z8.string(),
462
+ var openBundleLineItem = z9.object({
463
+ id: z9.string(),
464
+ type: z9.literal("Bundle"),
465
+ bundleId: z9.string(),
466
+ quantity: z9.number(),
467
+ variationId: z9.string(),
487
468
  price: priceCollectionSchema.optional(),
488
469
  variation: pricingVariationSchema.optional(),
489
470
  bundle: lineItemBundleSchema.optional(),
490
471
  appliedDiscount: discountSchema.optional()
491
472
  });
492
- var openOrderLineItem = z8.discriminatedUnion("type", [
473
+ var openOrderLineItem = z9.discriminatedUnion("type", [
493
474
  openProductLineItem,
494
475
  openBundleLineItem
495
476
  ]);
496
- var openOrderSchema = z8.object({
497
- id: z8.string(),
498
- status: z8.literal("Open" /* Open */),
499
- currency: z8.string(),
477
+ var openOrderSchema = z9.object({
478
+ id: z9.string(),
479
+ status: z9.literal("Open" /* Open */),
480
+ currency: z9.string(),
500
481
  items: openOrderLineItem.array(),
501
482
  couponsApplied: couponSchema.array(),
502
- checkoutUrl: z8.string().optional(),
503
- embeddedCheckoutUrl: z8.string().optional()
483
+ checkoutUrl: z9.string().optional(),
484
+ embeddedCheckoutUrl: z9.string().optional()
504
485
  });
505
- var moneySchema = z8.object({
506
- currency: z8.string(),
507
- amount: z8.number()
486
+ var moneySchema = z9.object({
487
+ currency: z9.string(),
488
+ amount: z9.number()
508
489
  });
509
- var orderTotalSchema = z8.object({
490
+ var orderTotalSchema = z9.object({
510
491
  original: moneySchema,
511
492
  discount: moneySchema,
512
493
  subtotal: moneySchema,
513
494
  taxes: moneySchema,
514
495
  due: moneySchema
515
496
  });
516
- var customerSnapshotSchema = z8.object({
517
- name: z8.string().nullable(),
518
- businessName: z8.string().nullable(),
519
- taxId: z8.string().nullable(),
520
- email: z8.string().nullable(),
497
+ var customerSnapshotSchema = z9.object({
498
+ name: z9.string().nullable(),
499
+ businessName: z9.string().nullable(),
500
+ taxId: z9.string().nullable(),
501
+ email: z9.string().nullable(),
521
502
  address: addressSchema.nullable()
522
503
  });
523
- var completedOrderSchema = z8.object({
524
- id: z8.string(),
525
- status: z8.literal("Completed" /* Completed */),
526
- currency: z8.string(),
504
+ var completedOrderSchema = z9.object({
505
+ id: z9.string(),
506
+ status: z9.literal("Completed" /* Completed */),
507
+ currency: z9.string(),
527
508
  customer: customerSnapshotSchema,
528
509
  total: orderTotalSchema,
529
510
  items: openOrderLineItem.array(),
530
511
  couponsApplied: couponSchema.array()
531
512
  });
532
- var orderSchema = z8.discriminatedUnion("status", [
513
+ var orderSchema = z9.discriminatedUnion("status", [
533
514
  openOrderSchema,
534
515
  completedOrderSchema
535
516
  ]);
@@ -540,8 +521,8 @@ var OrderEndpoints = class {
540
521
  this.api = api;
541
522
  }
542
523
  async get(orderId) {
543
- const response = await this.api.fetch(`/api/customer/orders/${orderId}`);
544
- return orderSchema.parse(response.data);
524
+ const response = await this.api.fetch(`/api/customer/orders/${orderId}`, orderSchema);
525
+ return response.data;
545
526
  }
546
527
  async pushContent(order, checkout, utm) {
547
528
  const query = {
@@ -553,18 +534,16 @@ var OrderEndpoints = class {
553
534
  }
554
535
  const response = await this.api.fetch(
555
536
  `/api/customer/orders/${order.id}?${new URLSearchParams(query).toString()}`,
556
- "PATCH",
537
+ openOrderSchema,
557
538
  {
558
- currency: order.currency || void 0,
559
- items: order.items
539
+ method: "PATCH",
540
+ body: {
541
+ currency: order.currency || void 0,
542
+ items: order.items
543
+ }
560
544
  }
561
545
  );
562
- try {
563
- return openOrderSchema.parse(response.data);
564
- } catch (err) {
565
- console.warn("Could not fetch order", { orderId: order.id, checkout, response, err });
566
- throw new MoonbaseError("Bad response", "Could not fetch order", response.status);
567
- }
546
+ return response.data;
568
547
  }
569
548
  };
570
549
 
@@ -590,33 +569,30 @@ var StorefrontEndpoints = class {
590
569
  }
591
570
  async get(utm) {
592
571
  const query = new URLSearchParams(utmToObject(utm));
593
- const response = await this.api.fetch(`/api/customer/storefront?${query.toString()}`);
594
- try {
595
- return storefrontSchema.parse(response.data);
596
- } catch (err) {
597
- console.warn("Could not fetch storefront", { response, err });
598
- throw new MoonbaseError("Bad response", "Could not fetch storefront", response.status);
599
- }
572
+ const response = await this.api.fetch(`/api/customer/storefront?${query.toString()}`, storefrontSchema);
573
+ return response.data;
600
574
  }
601
575
  };
602
576
 
603
577
  // src/utils/api.ts
604
578
  import fetch2 from "cross-fetch";
579
+ import { ZodNull } from "zod";
605
580
  var MoonbaseApi = class {
606
581
  constructor(baseUrl, tokenStore) {
607
582
  this.baseUrl = baseUrl;
608
583
  this.tokenStore = tokenStore;
609
584
  }
610
- async authenticatedFetch(path, method, body, contentType) {
585
+ async authenticatedFetch(path, schema, options) {
611
586
  if (!this.tokenStore.hasAccessToken)
612
587
  throw new NotAuthenticatedError();
613
- return await this.fetch(path, method, body, contentType);
588
+ return await this.fetch(path, schema, options);
614
589
  }
615
- async fetch(path, method, body, contentType) {
590
+ async fetch(path, schema, options) {
591
+ var _a;
616
592
  const accessToken = await this.tokenStore.getAccessToken();
617
- contentType != null ? contentType : contentType = "application/json";
593
+ const contentType = (_a = options == null ? void 0 : options.contentType) != null ? _a : "application/json";
618
594
  const response = await fetch2(this.baseUrl + path, {
619
- method: method || "GET",
595
+ method: (options == null ? void 0 : options.method) || "GET",
620
596
  mode: "cors",
621
597
  headers: {
622
598
  "Accept": "application/json",
@@ -626,15 +602,13 @@ var MoonbaseApi = class {
626
602
  // Force CORS on all calls
627
603
  "x-mb-cors": "1"
628
604
  },
629
- body: body ? contentType !== "application/json" ? body : JSON.stringify(body) : void 0
605
+ body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0
630
606
  });
631
607
  if (response.status >= 400)
632
608
  await handleResponseProblem(response);
633
609
  try {
634
- const contentLength = Number(response.headers.get("Content-Length")) || 0;
635
- const data = contentLength > 0 ? await response.json() : null;
636
610
  return {
637
- data,
611
+ data: schema instanceof ZodNull ? null : schema.parse(await response.json()),
638
612
  headers: Object.fromEntries(response.headers.entries()),
639
613
  status: response.status
640
614
  };
@@ -642,8 +616,7 @@ var MoonbaseApi = class {
642
616
  console.warn("Could not parse response", {
643
617
  status: response.status,
644
618
  content: await response.text(),
645
- contentType: response.headers.get("Content-Type"),
646
- contentLength: response.headers.get("Content-Length"),
619
+ headers: Object.fromEntries(response.headers.entries()),
647
620
  userAgent: window && window.navigator && window.navigator.userAgent,
648
621
  err
649
622
  });
@@ -758,13 +731,13 @@ _TokenStore.storageKey = "moonbase_auth";
758
731
  var TokenStore = _TokenStore;
759
732
 
760
733
  // src/vouchers/schemas.ts
761
- import { z as z9 } from "zod";
762
- var voucherSchema = z9.object({
763
- id: z9.string(),
764
- name: z9.string(),
765
- description: z9.string(),
766
- code: z9.string(),
767
- redeemed: z9.boolean(),
734
+ import { z as z10 } from "zod";
735
+ var voucherSchema = z10.object({
736
+ id: z10.string(),
737
+ name: z10.string(),
738
+ description: z10.string(),
739
+ code: z10.string(),
740
+ redeemed: z10.boolean(),
768
741
  redeemsProducts: quantifiable(storefrontProductSchema).array(),
769
742
  redeemsBundles: quantifiable(storefrontBundleSchema).array()
770
743
  });
@@ -775,28 +748,26 @@ var VoucherEndpoints = class {
775
748
  this.api = api;
776
749
  }
777
750
  async peek(code) {
778
- const response = await this.api.fetch(`/api/customer/vouchers?code=${encodeURIComponent(code)}`);
779
- return voucherSchema.parse(response.data);
751
+ const response = await this.api.fetch(`/api/customer/vouchers?code=${encodeURIComponent(code)}`, voucherSchema);
752
+ return response.data;
780
753
  }
781
754
  async redeem(code) {
782
755
  const response = await this.api.authenticatedFetch(
783
756
  `/api/customer/vouchers/redeem?code=${encodeURIComponent(code)}`,
784
- "POST"
757
+ voucherSchema,
758
+ {
759
+ method: "POST"
760
+ }
785
761
  );
786
- try {
787
- return voucherSchema.parse(response.data);
788
- } catch (err) {
789
- console.warn("Could not redeem voucher", { response, err });
790
- throw new MoonbaseError("Bad response", "Could not redeem voucher", response.status);
791
- }
762
+ return response.data;
792
763
  }
793
764
  };
794
765
 
795
766
  // src/inventory/activation/endpoints.ts
796
- import { z as z11 } from "zod";
767
+ import { z as z12 } from "zod";
797
768
 
798
769
  // src/inventory/licenses/schemas.ts
799
- import { z as z10 } from "zod";
770
+ import { z as z11 } from "zod";
800
771
 
801
772
  // src/inventory/licenses/models.ts
802
773
  var LicenseStatus = /* @__PURE__ */ ((LicenseStatus2) => {
@@ -816,21 +787,21 @@ var ActivationMethod = /* @__PURE__ */ ((ActivationMethod2) => {
816
787
  })(ActivationMethod || {});
817
788
 
818
789
  // src/inventory/licenses/schemas.ts
819
- var licenseSchema = z10.object({
820
- id: z10.string(),
821
- status: z10.nativeEnum(LicenseStatus),
790
+ var licenseSchema = z11.object({
791
+ id: z11.string(),
792
+ status: z11.nativeEnum(LicenseStatus),
822
793
  product: productSummarySchema,
823
- activeNumberOfActivations: z10.number(),
824
- maxNumberOfActivations: z10.number(),
825
- createdAt: z10.coerce.date()
794
+ activeNumberOfActivations: z11.number(),
795
+ maxNumberOfActivations: z11.number(),
796
+ createdAt: z11.coerce.date()
826
797
  });
827
- var activationSchema = z10.object({
828
- id: z10.string(),
829
- licenseId: z10.string(),
830
- name: z10.string(),
831
- status: z10.nativeEnum(ActivationStatus),
832
- activationMethod: z10.nativeEnum(ActivationMethod),
833
- lastValidatedAt: z10.coerce.date().nullable()
798
+ var activationSchema = z11.object({
799
+ id: z11.string(),
800
+ licenseId: z11.string(),
801
+ name: z11.string(),
802
+ status: z11.nativeEnum(ActivationStatus),
803
+ activationMethod: z11.nativeEnum(ActivationMethod),
804
+ lastValidatedAt: z11.coerce.date().nullable()
834
805
  });
835
806
 
836
807
  // src/inventory/activation/endpoints.ts
@@ -839,99 +810,69 @@ var ActivationEndpoints = class {
839
810
  this.api = api;
840
811
  }
841
812
  async activate(deviceToken, activationMethod) {
842
- const response = await this.api.authenticatedFetch(`/api/customer/inventory/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
843
- try {
844
- return {
845
- license: licenseSchema.parse(response.data),
846
- url: z11.string().parse(response.headers.location)
847
- };
848
- } catch (err) {
849
- console.warn("Could not activate product", { deviceToken, activationMethod, response, err });
850
- throw new MoonbaseError("Bad response", "Product could not be activated", response.status);
851
- }
813
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/activate?method=${activationMethod}`, licenseSchema, {
814
+ method: "POST",
815
+ body: deviceToken,
816
+ contentType: "text/plain"
817
+ });
818
+ return {
819
+ license: response.data,
820
+ url: z12.string().parse(response.headers.location)
821
+ };
852
822
  }
853
823
  };
854
824
 
855
825
  // src/inventory/licenses/endpoints.ts
826
+ import { z as z13 } from "zod";
856
827
  var LicenseEndpoints = class {
857
828
  constructor(api) {
858
829
  this.api = api;
859
830
  }
860
831
  async get(nextUrl) {
861
- const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/licenses");
862
- try {
863
- return paged(licenseSchema).parse(response.data);
864
- } catch (err) {
865
- console.warn("Could not fetch licenses", { nextUrl, response, err });
866
- throw new MoonbaseError("Bad response", "Licenses could not be fetched", response.status);
867
- }
832
+ const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/licenses", paged(licenseSchema));
833
+ return response.data;
868
834
  }
869
835
  async getActivations(licenseId, nextUrl) {
870
836
  const response = await this.api.authenticatedFetch(
871
- nextUrl || `/api/customer/inventory/licenses/${licenseId}/activations`
837
+ nextUrl || `/api/customer/inventory/licenses/${licenseId}/activations`,
838
+ paged(activationSchema)
872
839
  );
873
- try {
874
- return paged(activationSchema).parse(response.data);
875
- } catch (err) {
876
- console.warn("Could not fetch license activations", { nextUrl, response, err });
877
- throw new MoonbaseError("Bad response", "License activations could not be fetched", response.status);
878
- }
840
+ return response.data;
879
841
  }
880
842
  async revokeActivation(licenseId, activationId) {
881
- await this.api.authenticatedFetch(`/api/customer/inventory/licenses/${licenseId}/activations/${activationId}/revoke`, "POST");
843
+ await this.api.authenticatedFetch(`/api/customer/inventory/licenses/${licenseId}/activations/${activationId}/revoke`, z13.null(), { method: "POST" });
882
844
  }
883
845
  };
884
846
 
885
847
  // src/inventory/products/endpoints.ts
886
- import { z as z12 } from "zod";
848
+ import { z as z14 } from "zod";
887
849
  var ProductEndpoints = class {
888
850
  constructor(api) {
889
851
  this.api = api;
890
852
  }
891
853
  async get(productId, version) {
892
- const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version ? `?version=${version}` : ""}`);
893
- try {
894
- return productSummarySchema.parse(response.data);
895
- } catch (err) {
896
- console.warn("Could not fetch product", { productId, version, response, err });
897
- throw new MoonbaseError("Bad response", "Product could not be fetched", response.status);
898
- }
854
+ const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version ? `?version=${version}` : ""}`, productSummarySchema);
855
+ return response.data;
899
856
  }
900
857
  async getOwned(nextUrl) {
901
- const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/products");
902
- try {
903
- return paged(productSummarySchema).parse(response.data);
904
- } catch (err) {
905
- console.warn("Could not fetch products", { nextUrl, response, err });
906
- throw new MoonbaseError("Bad response", "Products could not be fetched", response.status);
907
- }
858
+ const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/products", paged(productSummarySchema));
859
+ return response.data;
908
860
  }
909
861
  async getLicenses(productId, nextUrl) {
910
- const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses`);
911
- try {
912
- return paged(licenseSchema).parse(response.data);
913
- } catch (err) {
914
- console.warn("Could not fetch product licenses", { productId, nextUrl, response, err });
915
- throw new MoonbaseError("Bad response", "Product licenses could not be fetched", response.status);
916
- }
862
+ const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses`, paged(licenseSchema));
863
+ return response.data;
917
864
  }
918
865
  async getActivations(productId, nextUrl) {
919
- const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses/activations`);
920
- try {
921
- return paged(activationSchema).parse(response.data);
922
- } catch (err) {
923
- console.warn("Could not fetch product activations", { productId, nextUrl, response, err });
924
- throw new MoonbaseError("Bad response", "Product activations could not be fetched", response.status);
925
- }
866
+ const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses/activations`, paged(activationSchema));
867
+ return response.data;
926
868
  }
927
869
  async getDownloadUrl(path) {
928
870
  const url = new URL(path);
929
871
  url.searchParams.append("redirect", "false");
930
- const response = await this.api.fetch(url.pathname + url.search);
931
- const content = z12.object({
932
- location: z12.string()
933
- }).parse(response.data);
934
- return content.location;
872
+ const response = await this.api.fetch(url.pathname + url.search, z14.object({
873
+ location: z14.string()
874
+ }));
875
+ return response.data.location;
935
876
  }
936
877
  };
937
878