@moonbase.sh/api 0.4.35 → 0.4.40

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
@@ -182,6 +182,7 @@ var importLicenseRequestSchema = z3.object({
182
182
  productId: z3.string(),
183
183
  externalId: z3.string().optional(),
184
184
  createdAt: z3.date().optional(),
185
+ expiresAt: z3.date().optional(),
185
186
  maxNumberOfActivations: z3.number().optional(),
186
187
  offlineActivationsAllowed: z3.boolean().optional(),
187
188
  activations: z3.object({
@@ -684,6 +685,116 @@ var ProductEndpoints = class {
684
685
  }
685
686
  };
686
687
 
688
+ // src/subscriptions/schemas.ts
689
+ import { z as z9 } from "zod";
690
+
691
+ // src/subscriptions/models.ts
692
+ var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
693
+ SubscriptionStatus2["Active"] = "Active";
694
+ SubscriptionStatus2["Expired"] = "Expired";
695
+ SubscriptionStatus2["Cancelled"] = "Cancelled";
696
+ return SubscriptionStatus2;
697
+ })(SubscriptionStatus || {});
698
+ var CycleLength = /* @__PURE__ */ ((CycleLength2) => {
699
+ CycleLength2["Daily"] = "Daily";
700
+ CycleLength2["Weekly"] = "Weekly";
701
+ CycleLength2["Monthly"] = "Monthly";
702
+ CycleLength2["Quarterly"] = "Quarterly";
703
+ CycleLength2["Yearly"] = "Yearly";
704
+ return CycleLength2;
705
+ })(CycleLength || {});
706
+
707
+ // src/subscriptions/schemas.ts
708
+ var subscriptionContentSchema = z9.discriminatedUnion("type", [
709
+ z9.object({
710
+ type: z9.literal("Product"),
711
+ productId: z9.string(),
712
+ quantity: z9.number(),
713
+ fulfillment: licenseLineItemFulfillmentSchema
714
+ }),
715
+ z9.object({
716
+ type: z9.literal("Bundle"),
717
+ bundleId: z9.string(),
718
+ quantity: z9.number(),
719
+ fulfillment: bundleLineItemFulfillmentSchema
720
+ })
721
+ ]);
722
+ var subscriptionSchema = z9.object({
723
+ id: z9.string(),
724
+ externalId: z9.string().optional(),
725
+ ownerId: z9.string(),
726
+ status: z9.nativeEnum(SubscriptionStatus),
727
+ expiresAt: z9.coerce.date(),
728
+ startedAt: z9.coerce.date(),
729
+ licenseExpiry: z9.coerce.date(),
730
+ renewedAt: z9.coerce.date().nullable(),
731
+ nextPaymentScheduledAt: z9.coerce.date().nullable(),
732
+ total: orderTotalSchema,
733
+ currency: z9.string(),
734
+ cycleLength: z9.nativeEnum(CycleLength),
735
+ currentCycle: z9.number(),
736
+ content: subscriptionContentSchema,
737
+ pricingVariation: pricingVariationSchema,
738
+ lastUpdated: entityChangeSchema,
739
+ created: entityChangeSchema
740
+ });
741
+ var importSubscriptionLicenseSchema = z9.object({
742
+ externalId: z9.string().optional(),
743
+ createdAt: z9.date().optional(),
744
+ maxNumberOfActivations: z9.number().optional(),
745
+ offlineActivationsAllowed: z9.boolean().optional(),
746
+ activations: z9.object({
747
+ activationMethod: z9.nativeEnum(ActivationMethod),
748
+ deviceName: z9.string(),
749
+ deviceSignature: z9.string(),
750
+ lastValidation: z9.date().optional()
751
+ }).array().optional()
752
+ });
753
+ var importSubscriptionContentSchema = z9.discriminatedUnion("type", [
754
+ z9.object({
755
+ type: z9.literal("Product"),
756
+ productId: z9.string(),
757
+ variationId: z9.string().optional(),
758
+ license: importSubscriptionLicenseSchema
759
+ }),
760
+ z9.object({
761
+ type: z9.literal("Bundle"),
762
+ bundleId: z9.string(),
763
+ variationId: z9.string().optional(),
764
+ licenses: z9.record(z9.string(), importSubscriptionLicenseSchema).optional()
765
+ })
766
+ ]);
767
+ var importSubscriptionRequestSchema = z9.object({
768
+ ownerId: z9.string(),
769
+ externalId: z9.string().optional(),
770
+ status: z9.nativeEnum(SubscriptionStatus),
771
+ startedAt: z9.date(),
772
+ expiresAt: z9.date(),
773
+ currentCycle: z9.number().optional(),
774
+ currency: z9.string().optional(),
775
+ content: importSubscriptionContentSchema
776
+ });
777
+
778
+ // src/subscriptions/endpoints.ts
779
+ var SubscriptionEndpoints = class {
780
+ constructor(api) {
781
+ this.api = api;
782
+ }
783
+ async query(opts) {
784
+ const response = await this.api.fetch(`/api/subscriptions?${objectToQuery(opts)}`);
785
+ return paged(subscriptionSchema, this.api).parse(response.data);
786
+ }
787
+ async get(subscriptionId) {
788
+ const response = await this.api.fetch(`/api/subscriptions/${subscriptionId}`);
789
+ return subscriptionSchema.parse(response.data);
790
+ }
791
+ async import(subscription) {
792
+ const request = importSubscriptionRequestSchema.parse(subscription);
793
+ const response = await this.api.fetch(`/api/subscriptions/import`, "POST", request);
794
+ return subscriptionSchema.parse(response.data);
795
+ }
796
+ };
797
+
687
798
  // src/trials/endpoints.ts
688
799
  var TrialEndpoints = class {
689
800
  constructor(api) {
@@ -709,43 +820,43 @@ var TrialEndpoints = class {
709
820
  };
710
821
 
711
822
  // src/vouchers/schemas.ts
712
- import { z as z10 } from "zod";
823
+ import { z as z11 } from "zod";
713
824
 
714
825
  // src/bundles/schemas.ts
715
- import { z as z9 } from "zod";
716
- var bundleSchema = z9.object({
717
- id: z9.string(),
718
- name: z9.string(),
719
- tagline: z9.string(),
720
- description: z9.string(),
721
- iconUrl: z9.string().nullable(),
722
- purchasable: z9.boolean(),
723
- partialPurchaseEnabled: z9.boolean()
826
+ import { z as z10 } from "zod";
827
+ var bundleSchema = z10.object({
828
+ id: z10.string(),
829
+ name: z10.string(),
830
+ tagline: z10.string(),
831
+ description: z10.string(),
832
+ iconUrl: z10.string().nullable(),
833
+ purchasable: z10.boolean(),
834
+ partialPurchaseEnabled: z10.boolean()
724
835
  });
725
836
 
726
837
  // src/vouchers/schemas.ts
727
- var voucherSchema = z10.object({
728
- id: z10.string(),
729
- description: z10.string(),
730
- numberOfCodes: z10.number(),
731
- numberOfRedemptions: z10.number(),
838
+ var voucherSchema = z11.object({
839
+ id: z11.string(),
840
+ description: z11.string(),
841
+ numberOfCodes: z11.number(),
842
+ numberOfRedemptions: z11.number(),
732
843
  redeemsProducts: quantifiable(productSchema).array(),
733
844
  redeemsBundles: quantifiable(bundleSchema).array(),
734
845
  lastUpdated: entityChangeSchema,
735
846
  created: entityChangeSchema
736
847
  });
737
- var createVoucherRequestSchema = z10.object({
738
- name: z10.string(),
739
- description: z10.string(),
740
- productEntitlements: z10.record(z10.string(), z10.number()).optional(),
741
- bundleEntitlements: z10.record(z10.string(), z10.number()).optional()
848
+ var createVoucherRequestSchema = z11.object({
849
+ name: z11.string(),
850
+ description: z11.string(),
851
+ productEntitlements: z11.record(z11.string(), z11.number()).optional(),
852
+ bundleEntitlements: z11.record(z11.string(), z11.number()).optional()
742
853
  });
743
- var voucherCodeSchema = z10.object({
744
- voucherId: z10.string(),
745
- code: z10.string(),
746
- isRedeemed: z10.boolean(),
747
- redeemedAt: z10.coerce.date().nullable(),
748
- redeemedBy: z10.string().nullable()
854
+ var voucherCodeSchema = z11.object({
855
+ voucherId: z11.string(),
856
+ code: z11.string(),
857
+ isRedeemed: z11.boolean(),
858
+ redeemedAt: z11.coerce.date().nullable(),
859
+ redeemedBy: z11.string().nullable()
749
860
  });
750
861
 
751
862
  // src/vouchers/endpoints.ts
@@ -787,6 +898,7 @@ var MoonbaseClient = class {
787
898
  this.activationRequests = new ActivationRequestEndpoints(this.api);
788
899
  this.customers = new CustomerEndpoints(this.api);
789
900
  this.licenses = new LicenseEndpoints(this.api);
901
+ this.subscriptions = new SubscriptionEndpoints(this.api);
790
902
  this.products = new ProductEndpoints(this.api);
791
903
  this.trials = new TrialEndpoints(this.api);
792
904
  this.vouchers = new VoucherEndpoints(this.api);
@@ -798,6 +910,7 @@ export {
798
910
  ActivationRequestStatus,
799
911
  ActivationStatus,
800
912
  ConflictError,
913
+ CycleLength,
801
914
  LicenseStatus,
802
915
  MoonbaseApi,
803
916
  MoonbaseClient,
@@ -808,6 +921,7 @@ export {
808
921
  OrderStatus,
809
922
  Platform,
810
923
  ProductStatus,
924
+ SubscriptionStatus,
811
925
  TrialStatus,
812
926
  objectToQuery
813
927
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/api",
3
3
  "type": "module",
4
- "version": "0.4.35",
4
+ "version": "0.4.40",
5
5
  "description": "Package to let you integrate backends with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",