@moonbase.sh/storefront-api 0.3.4 → 0.3.5

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
@@ -56,6 +56,10 @@ var flatAmountOffDiscountSchema = z.object({
56
56
  total: priceCollectionSchema.optional(),
57
57
  isExclusive: z.boolean()
58
58
  });
59
+ var moneySchema = z.object({
60
+ currency: z.string(),
61
+ amount: z.number()
62
+ });
59
63
  var discountSchema = z.discriminatedUnion("type", [
60
64
  percentageOffDiscountSchema,
61
65
  flatAmountOffDiscountSchema
@@ -76,8 +80,7 @@ var pricingVariationSchema = z.object({
76
80
  price: priceCollectionSchema,
77
81
  hasDiscount: z.boolean(),
78
82
  discount: discountSchema.optional(),
79
- // TODO: Remove default once subscriptions are live
80
- recurrence: recurrenceSchema.default({ type: "OneOff" }),
83
+ recurrence: recurrenceSchema,
81
84
  pricingTiers: z.array(pricingTierSchema).nullish()
82
85
  });
83
86
  function paged(itemSchema) {
@@ -134,6 +137,7 @@ var productSummarySchema = z2.object({
134
137
  currentActivations: z2.number().optional(),
135
138
  maxActivations: z2.number().optional(),
136
139
  externalLicenses: z2.number().optional(),
140
+ subscriptionLicenses: z2.number().optional(),
137
141
  currentVersion: z2.string().nullable(),
138
142
  version: z2.string().optional(),
139
143
  prerelease: z2.boolean().optional(),
@@ -348,7 +352,10 @@ var userSchema = z7.object({
348
352
  tenantId: z7.string(),
349
353
  address: addressSchema.optional(),
350
354
  communicationPreferences: communicationPreferencesSchema,
351
- ownedProducts: z7.string().array().optional()
355
+ ownedProducts: z7.string().array().optional(),
356
+ subscribedProducts: z7.string().array().optional(),
357
+ hasProducts: z7.boolean().nullish(),
358
+ hasSubscriptions: z7.boolean().nullish()
352
359
  });
353
360
  var identityUserSchema = userSchema.and(z7.object({
354
361
  accessToken: z7.string(),
@@ -497,6 +504,7 @@ var licenseSchema = z8.object({
497
504
  activeNumberOfActivations: z8.number(),
498
505
  maxNumberOfActivations: z8.number(),
499
506
  externalFulfillment: z8.string().optional(),
507
+ expiresAt: z8.coerce.date().optional(),
500
508
  createdAt: z8.coerce.date()
501
509
  });
502
510
  var activationSchema = z8.object({
@@ -583,14 +591,19 @@ var ProductEndpoints = class {
583
591
  }
584
592
  };
585
593
 
586
- // src/inventory/index.ts
587
- var InventoryEndpoints = class {
588
- constructor(api, configuration) {
589
- this.licenses = new LicenseEndpoints(api, configuration);
590
- this.products = new ProductEndpoints(api, configuration);
591
- this.activation = new ActivationEndpoints(api, configuration);
592
- }
593
- };
594
+ // src/inventory/subscriptions/endpoints.ts
595
+ import { z as z13 } from "zod";
596
+
597
+ // src/inventory/subscriptions/schemas.ts
598
+ import { z as z12 } from "zod";
599
+
600
+ // src/inventory/subscriptions/models.ts
601
+ var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
602
+ SubscriptionStatus2["Active"] = "Active";
603
+ SubscriptionStatus2["Expired"] = "Expired";
604
+ SubscriptionStatus2["Cancelled"] = "Cancelled";
605
+ return SubscriptionStatus2;
606
+ })(SubscriptionStatus || {});
594
607
 
595
608
  // src/orders/schemas.ts
596
609
  var schemas_exports2 = {};
@@ -600,7 +613,8 @@ __export(schemas_exports2, {
600
613
  openOrderLineItem: () => openOrderLineItem,
601
614
  openOrderSchema: () => openOrderSchema,
602
615
  openProductLineItem: () => openProductLineItem,
603
- orderSchema: () => orderSchema
616
+ orderSchema: () => orderSchema,
617
+ orderTotalSchema: () => orderTotalSchema
604
618
  });
605
619
  import { z as z11 } from "zod";
606
620
 
@@ -674,10 +688,6 @@ var openOrderSchema = z11.object({
674
688
  checkoutUrl: z11.string().optional(),
675
689
  embeddedCheckoutUrl: z11.string().optional()
676
690
  });
677
- var moneySchema = z11.object({
678
- currency: z11.string(),
679
- amount: z11.number()
680
- });
681
691
  var orderTotalSchema = z11.object({
682
692
  original: moneySchema,
683
693
  discount: moneySchema,
@@ -717,6 +727,66 @@ var orderSchema = z11.discriminatedUnion("status", [
717
727
  completedOrderSchema
718
728
  ]);
719
729
 
730
+ // src/inventory/subscriptions/schemas.ts
731
+ var subscriptionSchema = z12.object({
732
+ id: z12.string(),
733
+ status: z12.nativeEnum(SubscriptionStatus),
734
+ hasPaymentMethod: z12.boolean(),
735
+ expiresAt: z12.coerce.date(),
736
+ renewedAt: z12.coerce.date().nullable(),
737
+ startedAt: z12.coerce.date(),
738
+ total: orderTotalSchema,
739
+ cycleLength: z12.nativeEnum(CycleLength),
740
+ content: z12.discriminatedUnion("type", [
741
+ z12.object({
742
+ type: z12.literal("Product"),
743
+ quantity: z12.number(),
744
+ product: storefrontProductSchema
745
+ }),
746
+ z12.object({
747
+ type: z12.literal("Bundle"),
748
+ quantity: z12.number(),
749
+ bundle: storefrontBundleSchema
750
+ })
751
+ ])
752
+ });
753
+
754
+ // src/inventory/subscriptions/endpoints.ts
755
+ var SubscriptionEndpoints = class {
756
+ constructor(api, configuration) {
757
+ this.api = api;
758
+ this.configuration = configuration;
759
+ }
760
+ async get(nextUrl) {
761
+ const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/subscriptions", paged(subscriptionSchema));
762
+ return response.data;
763
+ }
764
+ async getById(subscriptionId) {
765
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}`, subscriptionSchema);
766
+ return response.data;
767
+ }
768
+ async cancel(subscriptionId) {
769
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/cancel`, subscriptionSchema, { method: "POST" });
770
+ return response.data;
771
+ }
772
+ async renew(subscriptionId, returnUrl, embedded) {
773
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/renew?redirect=false&return=${returnUrl}&embedded=${embedded ? "true" : "false"}`, z13.object({
774
+ location: z13.string()
775
+ }), { method: "POST" });
776
+ return response.data;
777
+ }
778
+ };
779
+
780
+ // src/inventory/index.ts
781
+ var InventoryEndpoints = class {
782
+ constructor(api, configuration) {
783
+ this.licenses = new LicenseEndpoints(api, configuration);
784
+ this.products = new ProductEndpoints(api, configuration);
785
+ this.activation = new ActivationEndpoints(api, configuration);
786
+ this.subscriptions = new SubscriptionEndpoints(api, configuration);
787
+ }
788
+ };
789
+
720
790
  // src/orders/endpoints.ts
721
791
  var OrderEndpoints = class {
722
792
  constructor(api) {
@@ -799,7 +869,8 @@ var MoonbaseApi = class {
799
869
  "x-mb-cors": "1"
800
870
  },
801
871
  body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
802
- signal: options == null ? void 0 : options.abort
872
+ signal: options == null ? void 0 : options.abort,
873
+ redirect: "manual"
803
874
  });
804
875
  if (response.status >= 400)
805
876
  await handleResponseProblem(response);
@@ -928,11 +999,11 @@ _TokenStore.storageKey = "moonbase_auth";
928
999
  var TokenStore = _TokenStore;
929
1000
 
930
1001
  // src/vendor/schemas.ts
931
- import { z as z12 } from "zod";
932
- var vendorSchema = z12.object({
933
- id: z12.string(),
934
- name: z12.string(),
935
- logoUrl: z12.string().nullable()
1002
+ import { z as z14 } from "zod";
1003
+ var vendorSchema = z14.object({
1004
+ id: z14.string(),
1005
+ name: z14.string(),
1006
+ logoUrl: z14.string().nullable()
936
1007
  });
937
1008
 
938
1009
  // src/vendor/endpoints.ts
@@ -947,13 +1018,13 @@ var VendorEndpoints = class {
947
1018
  };
948
1019
 
949
1020
  // src/vouchers/schemas.ts
950
- import { z as z13 } from "zod";
951
- var voucherSchema = z13.object({
952
- id: z13.string(),
953
- name: z13.string(),
954
- description: z13.string(),
955
- code: z13.string(),
956
- redeemed: z13.boolean(),
1021
+ import { z as z15 } from "zod";
1022
+ var voucherSchema = z15.object({
1023
+ id: z15.string(),
1024
+ name: z15.string(),
1025
+ description: z15.string(),
1026
+ code: z15.string(),
1027
+ redeemed: z15.boolean(),
957
1028
  redeemsProducts: quantifiable(storefrontProductSchema).array(),
958
1029
  redeemsBundles: quantifiable(storefrontBundleSchema).array()
959
1030
  });
@@ -1016,6 +1087,7 @@ export {
1016
1087
  NotFoundError,
1017
1088
  OrderStatus,
1018
1089
  Platform,
1090
+ SubscriptionStatus,
1019
1091
  TokenStore,
1020
1092
  schemas_exports3 as schemas,
1021
1093
  utmToObject
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "0.3.4",
4
+ "version": "0.3.5",
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",