@moonbase.sh/storefront-api 0.1.94 → 0.1.97

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
@@ -40,7 +40,8 @@ __export(src_exports, {
40
40
  NotAuthorizedError: () => NotAuthorizedError,
41
41
  NotFoundError: () => NotFoundError,
42
42
  OrderStatus: () => OrderStatus,
43
- Platform: () => Platform
43
+ Platform: () => Platform,
44
+ utmToObject: () => utmToObject
44
45
  });
45
46
  module.exports = __toCommonJS(src_exports);
46
47
 
@@ -95,10 +96,10 @@ function quantifiable(itemSchema) {
95
96
  });
96
97
  }
97
98
 
98
- // src/products/schemas.ts
99
+ // src/inventory/products/schemas.ts
99
100
  var import_zod2 = require("zod");
100
101
 
101
- // src/products/models.ts
102
+ // src/inventory/products/models.ts
102
103
  var Platform = /* @__PURE__ */ ((Platform2) => {
103
104
  Platform2["Universal"] = "Universal";
104
105
  Platform2["Windows"] = "Windows";
@@ -107,7 +108,7 @@ var Platform = /* @__PURE__ */ ((Platform2) => {
107
108
  return Platform2;
108
109
  })(Platform || {});
109
110
 
110
- // src/products/schemas.ts
111
+ // src/inventory/products/schemas.ts
111
112
  var downloadSchema = import_zod2.z.object({
112
113
  name: import_zod2.z.string(),
113
114
  key: import_zod2.z.string(),
@@ -152,7 +153,7 @@ var storefrontBundleSchema = import_zod3.z.object({
152
153
  owned: import_zod3.z.boolean(),
153
154
  partial: import_zod3.z.boolean(),
154
155
  products: storefrontProductSchema.and(import_zod3.z.object({
155
- included: import_zod3.z.boolean()
156
+ included: import_zod3.z.boolean().optional()
156
157
  })).array(),
157
158
  defaultVariation: pricingVariationSchema.optional(),
158
159
  variations: pricingVariationSchema.array().optional(),
@@ -374,66 +375,8 @@ var IdentityEndpoints = class {
374
375
  }
375
376
  };
376
377
 
377
- // src/licenses/schemas.ts
378
- var import_zod8 = require("zod");
379
-
380
- // src/licenses/models.ts
381
- var LicenseStatus = /* @__PURE__ */ ((LicenseStatus2) => {
382
- LicenseStatus2["Active"] = "Active";
383
- LicenseStatus2["Revoked"] = "Revoked";
384
- return LicenseStatus2;
385
- })(LicenseStatus || {});
386
- var ActivationStatus = /* @__PURE__ */ ((ActivationStatus2) => {
387
- ActivationStatus2["Active"] = "Active";
388
- ActivationStatus2["Revoked"] = "Revoked";
389
- return ActivationStatus2;
390
- })(ActivationStatus || {});
391
- var ActivationMethod = /* @__PURE__ */ ((ActivationMethod2) => {
392
- ActivationMethod2["Online"] = "Online";
393
- ActivationMethod2["Offline"] = "Offline";
394
- return ActivationMethod2;
395
- })(ActivationMethod || {});
396
-
397
- // src/licenses/schemas.ts
398
- var licenseSchema = import_zod8.z.object({
399
- id: import_zod8.z.string(),
400
- status: import_zod8.z.nativeEnum(LicenseStatus),
401
- product: productSummarySchema.optional(),
402
- activeNumberOfActivations: import_zod8.z.number(),
403
- maxNumberOfActivations: import_zod8.z.number(),
404
- createdAt: import_zod8.z.coerce.date()
405
- });
406
- var activationSchema = import_zod8.z.object({
407
- id: import_zod8.z.string(),
408
- licenseId: import_zod8.z.string(),
409
- name: import_zod8.z.string(),
410
- status: import_zod8.z.nativeEnum(ActivationStatus),
411
- activationMethod: import_zod8.z.nativeEnum(ActivationMethod),
412
- lastValidatedAt: import_zod8.z.coerce.date().nullable()
413
- });
414
-
415
- // src/licenses/endpoints.ts
416
- var LicenseEndpoints = class {
417
- constructor(api) {
418
- this.api = api;
419
- }
420
- async get(nextUrl) {
421
- const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/licenses");
422
- return paged(licenseSchema).parse(response.data);
423
- }
424
- async getActivations(licenseId, nextUrl) {
425
- const response = await this.api.authenticatedFetch(
426
- nextUrl || `/api/customer/licenses/${licenseId}/activations`
427
- );
428
- return paged(activationSchema).parse(response.data);
429
- }
430
- async revokeActivation(licenseId, activationId) {
431
- await this.api.authenticatedFetch(`/api/customer/licenses/${licenseId}/activations/${activationId}/revoke`, "POST");
432
- }
433
- };
434
-
435
378
  // src/orders/schemas.ts
436
- var import_zod9 = require("zod");
379
+ var import_zod8 = require("zod");
437
380
 
438
381
  // src/orders/models.ts
439
382
  var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
@@ -447,65 +390,65 @@ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
447
390
  })(OrderStatus || {});
448
391
 
449
392
  // src/orders/schemas.ts
450
- var couponSchema = import_zod9.z.object({
451
- code: import_zod9.z.string(),
452
- name: import_zod9.z.string(),
453
- description: import_zod9.z.string()
393
+ var couponSchema = import_zod8.z.object({
394
+ code: import_zod8.z.string(),
395
+ name: import_zod8.z.string(),
396
+ description: import_zod8.z.string()
454
397
  });
455
- var percentageOffDiscountSchema2 = import_zod9.z.object({
456
- type: import_zod9.z.literal("PercentageOffDiscount"),
457
- name: import_zod9.z.string(),
458
- description: import_zod9.z.string().optional(),
459
- percentage: import_zod9.z.number(),
398
+ var percentageOffDiscountSchema2 = import_zod8.z.object({
399
+ type: import_zod8.z.literal("PercentageOffDiscount"),
400
+ name: import_zod8.z.string(),
401
+ description: import_zod8.z.string().optional(),
402
+ percentage: import_zod8.z.number(),
460
403
  total: priceCollectionSchema.optional(),
461
- isExclusive: import_zod9.z.boolean()
404
+ isExclusive: import_zod8.z.boolean()
462
405
  });
463
- var flatAmountOffDiscountSchema2 = import_zod9.z.object({
464
- type: import_zod9.z.literal("FlatAmountOffDiscount"),
465
- name: import_zod9.z.string(),
466
- description: import_zod9.z.string().optional(),
406
+ var flatAmountOffDiscountSchema2 = import_zod8.z.object({
407
+ type: import_zod8.z.literal("FlatAmountOffDiscount"),
408
+ name: import_zod8.z.string(),
409
+ description: import_zod8.z.string().optional(),
467
410
  total: priceCollectionSchema.optional(),
468
- isExclusive: import_zod9.z.boolean()
411
+ isExclusive: import_zod8.z.boolean()
469
412
  });
470
- var discountSchema2 = import_zod9.z.discriminatedUnion("type", [
413
+ var discountSchema2 = import_zod8.z.discriminatedUnion("type", [
471
414
  percentageOffDiscountSchema2,
472
415
  flatAmountOffDiscountSchema2
473
416
  ]);
474
- var openProductLineItem = import_zod9.z.object({
475
- id: import_zod9.z.string(),
476
- type: import_zod9.z.literal("Product"),
477
- productId: import_zod9.z.string(),
478
- quantity: import_zod9.z.number(),
479
- variationId: import_zod9.z.string(),
417
+ var openProductLineItem = import_zod8.z.object({
418
+ id: import_zod8.z.string(),
419
+ type: import_zod8.z.literal("Product"),
420
+ productId: import_zod8.z.string(),
421
+ quantity: import_zod8.z.number(),
422
+ variationId: import_zod8.z.string(),
480
423
  price: priceCollectionSchema.optional(),
481
424
  variation: pricingVariationSchema.optional(),
482
425
  product: storefrontProductSchema.optional(),
483
426
  appliedDiscount: discountSchema2.optional()
484
427
  });
485
- var openBundleLineItem = import_zod9.z.object({
486
- id: import_zod9.z.string(),
487
- type: import_zod9.z.literal("Bundle"),
488
- bundleId: import_zod9.z.string(),
489
- quantity: import_zod9.z.number(),
490
- variationId: import_zod9.z.string(),
428
+ var openBundleLineItem = import_zod8.z.object({
429
+ id: import_zod8.z.string(),
430
+ type: import_zod8.z.literal("Bundle"),
431
+ bundleId: import_zod8.z.string(),
432
+ quantity: import_zod8.z.number(),
433
+ variationId: import_zod8.z.string(),
491
434
  price: priceCollectionSchema.optional(),
492
435
  variation: pricingVariationSchema.optional(),
493
436
  bundle: storefrontBundleSchema.optional(),
494
437
  appliedDiscount: discountSchema2.optional()
495
438
  });
496
- var openOrderLineItem = import_zod9.z.discriminatedUnion("type", [
439
+ var openOrderLineItem = import_zod8.z.discriminatedUnion("type", [
497
440
  openProductLineItem,
498
441
  openBundleLineItem
499
442
  ]);
500
- var openOrderSchema = import_zod9.z.object({
501
- id: import_zod9.z.string(),
502
- status: import_zod9.z.literal("Open" /* Open */),
503
- currency: import_zod9.z.string(),
443
+ var openOrderSchema = import_zod8.z.object({
444
+ id: import_zod8.z.string(),
445
+ status: import_zod8.z.literal("Open" /* Open */),
446
+ currency: import_zod8.z.string(),
504
447
  items: openOrderLineItem.array(),
505
448
  couponsApplied: couponSchema.array(),
506
- checkoutUrl: import_zod9.z.string().optional()
449
+ checkoutUrl: import_zod8.z.string().optional()
507
450
  });
508
- var orderSchema = import_zod9.z.discriminatedUnion("status", [
451
+ var orderSchema = import_zod8.z.discriminatedUnion("status", [
509
452
  openOrderSchema
510
453
  ]);
511
454
 
@@ -518,9 +461,16 @@ var OrderEndpoints = class {
518
461
  const response = await this.api.fetch(`/api/customer/orders/${orderId}`);
519
462
  return orderSchema.parse(response.data);
520
463
  }
521
- async pushContent(order, checkout) {
464
+ async pushContent(order, checkout, utm) {
465
+ const query = {
466
+ ...utmToObject(utm)
467
+ };
468
+ if (checkout) {
469
+ query.checkout = "true";
470
+ query.returnUrl = checkout.returnUrl;
471
+ }
522
472
  const response = await this.api.fetch(
523
- `/api/customer/orders/${order.id}${checkout ? `?checkout=true&returnUrl=${encodeURIComponent(checkout.returnUrl)}` : ""}`,
473
+ `/api/customer/orders/${order.id}?${new URLSearchParams(query).toString()}`,
524
474
  "PATCH",
525
475
  {
526
476
  currency: order.currency,
@@ -531,40 +481,29 @@ var OrderEndpoints = class {
531
481
  }
532
482
  };
533
483
 
534
- // src/products/endpoints.ts
535
- var import_zod10 = require("zod");
536
- var ProductEndpoints = class {
537
- constructor(api) {
538
- this.api = api;
539
- }
540
- async getOwned(nextUrl) {
541
- const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/products");
542
- return paged(productSummarySchema).parse(response.data);
543
- }
544
- async getLicenses(productId, nextUrl) {
545
- const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses`);
546
- return paged(licenseSchema).parse(response.data);
547
- }
548
- async getActivations(productId, nextUrl) {
549
- const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses/activations`);
550
- return paged(activationSchema).parse(response.data);
551
- }
552
- async activate(deviceToken, activationMethod) {
553
- const response = await this.api.authenticatedFetch(`/api/customer/products/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
554
- return {
555
- license: licenseSchema.parse(response.data),
556
- url: import_zod10.z.string().parse(response.headers.get("location"))
557
- };
558
- }
559
- };
484
+ // src/globalModels.ts
485
+ function utmToObject(utm) {
486
+ return Object.entries({
487
+ utm_source: utm == null ? void 0 : utm.source,
488
+ utm_medium: utm == null ? void 0 : utm.medium,
489
+ utm_campaign: utm == null ? void 0 : utm.campaign,
490
+ utm_term: utm == null ? void 0 : utm.term,
491
+ utm_content: utm == null ? void 0 : utm.content,
492
+ utm_referrer: utm == null ? void 0 : utm.referrer
493
+ }).filter(([_, value]) => value !== void 0).reduce((obj, [key, value]) => ({
494
+ ...obj,
495
+ [key]: value
496
+ }), {});
497
+ }
560
498
 
561
499
  // src/storefront/endpoints.ts
562
500
  var StorefrontEndpoints = class {
563
501
  constructor(api) {
564
502
  this.api = api;
565
503
  }
566
- async get() {
567
- const response = await this.api.fetch("/api/customer/storefront");
504
+ async get(utm) {
505
+ const query = new URLSearchParams(utmToObject(utm));
506
+ const response = await this.api.fetch(`/api/customer/storefront?${query.toString()}`);
568
507
  return storefrontSchema.parse(response.data);
569
508
  }
570
509
  };
@@ -707,13 +646,13 @@ _TokenStore.storageKey = "moonbase_auth";
707
646
  var TokenStore = _TokenStore;
708
647
 
709
648
  // src/vouchers/schemas.ts
710
- var import_zod11 = require("zod");
711
- var voucherSchema = import_zod11.z.object({
712
- id: import_zod11.z.string(),
713
- name: import_zod11.z.string(),
714
- description: import_zod11.z.string(),
715
- code: import_zod11.z.string(),
716
- redeemed: import_zod11.z.boolean(),
649
+ var import_zod9 = require("zod");
650
+ var voucherSchema = import_zod9.z.object({
651
+ id: import_zod9.z.string(),
652
+ name: import_zod9.z.string(),
653
+ description: import_zod9.z.string(),
654
+ code: import_zod9.z.string(),
655
+ redeemed: import_zod9.z.boolean(),
717
656
  redeemsProducts: quantifiable(storefrontProductSchema).array(),
718
657
  redeemsBundles: quantifiable(storefrontBundleSchema).array()
719
658
  });
@@ -736,6 +675,119 @@ var VoucherEndpoints = class {
736
675
  }
737
676
  };
738
677
 
678
+ // src/inventory/activation/endpoints.ts
679
+ var import_zod11 = require("zod");
680
+
681
+ // src/inventory/licenses/schemas.ts
682
+ var import_zod10 = require("zod");
683
+
684
+ // src/inventory/licenses/models.ts
685
+ var LicenseStatus = /* @__PURE__ */ ((LicenseStatus2) => {
686
+ LicenseStatus2["Active"] = "Active";
687
+ LicenseStatus2["Revoked"] = "Revoked";
688
+ return LicenseStatus2;
689
+ })(LicenseStatus || {});
690
+ var ActivationStatus = /* @__PURE__ */ ((ActivationStatus2) => {
691
+ ActivationStatus2["Active"] = "Active";
692
+ ActivationStatus2["Revoked"] = "Revoked";
693
+ return ActivationStatus2;
694
+ })(ActivationStatus || {});
695
+ var ActivationMethod = /* @__PURE__ */ ((ActivationMethod2) => {
696
+ ActivationMethod2["Online"] = "Online";
697
+ ActivationMethod2["Offline"] = "Offline";
698
+ return ActivationMethod2;
699
+ })(ActivationMethod || {});
700
+
701
+ // src/inventory/licenses/schemas.ts
702
+ var licenseSchema = import_zod10.z.object({
703
+ id: import_zod10.z.string(),
704
+ status: import_zod10.z.nativeEnum(LicenseStatus),
705
+ product: productSummarySchema,
706
+ activeNumberOfActivations: import_zod10.z.number(),
707
+ maxNumberOfActivations: import_zod10.z.number(),
708
+ createdAt: import_zod10.z.coerce.date()
709
+ });
710
+ var activationSchema = import_zod10.z.object({
711
+ id: import_zod10.z.string(),
712
+ licenseId: import_zod10.z.string(),
713
+ name: import_zod10.z.string(),
714
+ status: import_zod10.z.nativeEnum(ActivationStatus),
715
+ activationMethod: import_zod10.z.nativeEnum(ActivationMethod),
716
+ lastValidatedAt: import_zod10.z.coerce.date().nullable()
717
+ });
718
+
719
+ // src/inventory/activation/endpoints.ts
720
+ var ActivationEndpoints = class {
721
+ constructor(api) {
722
+ this.api = api;
723
+ }
724
+ async activate(deviceToken, activationMethod) {
725
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
726
+ return {
727
+ license: licenseSchema.parse(response.data),
728
+ url: import_zod11.z.string().parse(response.headers.get("location"))
729
+ };
730
+ }
731
+ };
732
+
733
+ // src/inventory/licenses/endpoints.ts
734
+ var LicenseEndpoints = class {
735
+ constructor(api) {
736
+ this.api = api;
737
+ }
738
+ async get(nextUrl) {
739
+ const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/licenses");
740
+ return paged(licenseSchema).parse(response.data);
741
+ }
742
+ async getActivations(licenseId, nextUrl) {
743
+ const response = await this.api.authenticatedFetch(
744
+ nextUrl || `/api/customer/inventory/licenses/${licenseId}/activations`
745
+ );
746
+ return paged(activationSchema).parse(response.data);
747
+ }
748
+ async revokeActivation(licenseId, activationId) {
749
+ await this.api.authenticatedFetch(`/api/customer/inventory/licenses/${licenseId}/activations/${activationId}/revoke`, "POST");
750
+ }
751
+ };
752
+
753
+ // src/inventory/products/endpoints.ts
754
+ var import_zod12 = require("zod");
755
+ var ProductEndpoints = class {
756
+ constructor(api) {
757
+ this.api = api;
758
+ }
759
+ async getOwned(nextUrl) {
760
+ const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/products");
761
+ return paged(productSummarySchema).parse(response.data);
762
+ }
763
+ async getLicenses(productId, nextUrl) {
764
+ const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses`);
765
+ return paged(licenseSchema).parse(response.data);
766
+ }
767
+ async getActivations(productId, nextUrl) {
768
+ const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses/activations`);
769
+ return paged(activationSchema).parse(response.data);
770
+ }
771
+ async getDownloadUrl(path) {
772
+ const url = new URL(path);
773
+ url.searchParams.append("redirect", "false");
774
+ const response = await this.api.authenticatedFetch(url.pathname + url.search);
775
+ const content = import_zod12.z.object({
776
+ location: import_zod12.z.string()
777
+ }).parse(response.data);
778
+ return content.location;
779
+ }
780
+ };
781
+
782
+ // src/inventory/index.ts
783
+ var InventoryEndpoints = class {
784
+ constructor(api) {
785
+ this.licenses = new LicenseEndpoints(api);
786
+ this.products = new ProductEndpoints(api);
787
+ this.activation = new ActivationEndpoints(api);
788
+ }
789
+ };
790
+
739
791
  // src/index.ts
740
792
  var MoonbaseClient = class {
741
793
  constructor(configuration) {
@@ -747,9 +799,8 @@ var MoonbaseClient = class {
747
799
  this.identity = new IdentityEndpoints(api, this.tokenStore);
748
800
  this.vouchers = new VoucherEndpoints(api);
749
801
  this.orders = new OrderEndpoints(api);
750
- this.licenses = new LicenseEndpoints(api);
802
+ this.inventory = new InventoryEndpoints(api);
751
803
  this.activationRequests = new ActivationRequestEndpoints(api);
752
- this.products = new ProductEndpoints(api);
753
804
  }
754
805
  };
755
806
  // Annotate the CommonJS export names for ESM import in node:
@@ -764,5 +815,6 @@ var MoonbaseClient = class {
764
815
  NotAuthorizedError,
765
816
  NotFoundError,
766
817
  OrderStatus,
767
- Platform
818
+ Platform,
819
+ utmToObject
768
820
  });