@moonbase.sh/storefront-api 0.3.3 → 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(),
@@ -320,6 +324,14 @@ async function handleResponseProblem(response) {
320
324
  }
321
325
 
322
326
  // src/identity/schemas.ts
327
+ var schemas_exports = {};
328
+ __export(schemas_exports, {
329
+ addressSchema: () => addressSchema,
330
+ communicationPreferencesSchema: () => communicationPreferencesSchema,
331
+ identityUserSchema: () => identityUserSchema,
332
+ userAccountConfirmedSchema: () => userAccountConfirmedSchema,
333
+ userSchema: () => userSchema
334
+ });
323
335
  import { z as z7 } from "zod";
324
336
  var addressSchema = z7.object({
325
337
  countryCode: z7.string(),
@@ -340,7 +352,10 @@ var userSchema = z7.object({
340
352
  tenantId: z7.string(),
341
353
  address: addressSchema.optional(),
342
354
  communicationPreferences: communicationPreferencesSchema,
343
- 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()
344
359
  });
345
360
  var identityUserSchema = userSchema.and(z7.object({
346
361
  accessToken: z7.string(),
@@ -489,6 +504,7 @@ var licenseSchema = z8.object({
489
504
  activeNumberOfActivations: z8.number(),
490
505
  maxNumberOfActivations: z8.number(),
491
506
  externalFulfillment: z8.string().optional(),
507
+ expiresAt: z8.coerce.date().optional(),
492
508
  createdAt: z8.coerce.date()
493
509
  });
494
510
  var activationSchema = z8.object({
@@ -575,24 +591,30 @@ var ProductEndpoints = class {
575
591
  }
576
592
  };
577
593
 
578
- // src/inventory/index.ts
579
- var InventoryEndpoints = class {
580
- constructor(api, configuration) {
581
- this.licenses = new LicenseEndpoints(api, configuration);
582
- this.products = new ProductEndpoints(api, configuration);
583
- this.activation = new ActivationEndpoints(api, configuration);
584
- }
585
- };
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 || {});
586
607
 
587
608
  // src/orders/schemas.ts
588
- var schemas_exports = {};
589
- __export(schemas_exports, {
609
+ var schemas_exports2 = {};
610
+ __export(schemas_exports2, {
590
611
  completedOrderSchema: () => completedOrderSchema,
591
612
  openBundleLineItem: () => openBundleLineItem,
592
613
  openOrderLineItem: () => openOrderLineItem,
593
614
  openOrderSchema: () => openOrderSchema,
594
615
  openProductLineItem: () => openProductLineItem,
595
- orderSchema: () => orderSchema
616
+ orderSchema: () => orderSchema,
617
+ orderTotalSchema: () => orderTotalSchema
596
618
  });
597
619
  import { z as z11 } from "zod";
598
620
 
@@ -666,10 +688,6 @@ var openOrderSchema = z11.object({
666
688
  checkoutUrl: z11.string().optional(),
667
689
  embeddedCheckoutUrl: z11.string().optional()
668
690
  });
669
- var moneySchema = z11.object({
670
- currency: z11.string(),
671
- amount: z11.number()
672
- });
673
691
  var orderTotalSchema = z11.object({
674
692
  original: moneySchema,
675
693
  discount: moneySchema,
@@ -709,6 +727,66 @@ var orderSchema = z11.discriminatedUnion("status", [
709
727
  completedOrderSchema
710
728
  ]);
711
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
+
712
790
  // src/orders/endpoints.ts
713
791
  var OrderEndpoints = class {
714
792
  constructor(api) {
@@ -791,7 +869,8 @@ var MoonbaseApi = class {
791
869
  "x-mb-cors": "1"
792
870
  },
793
871
  body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
794
- signal: options == null ? void 0 : options.abort
872
+ signal: options == null ? void 0 : options.abort,
873
+ redirect: "manual"
795
874
  });
796
875
  if (response.status >= 400)
797
876
  await handleResponseProblem(response);
@@ -920,11 +999,11 @@ _TokenStore.storageKey = "moonbase_auth";
920
999
  var TokenStore = _TokenStore;
921
1000
 
922
1001
  // src/vendor/schemas.ts
923
- import { z as z12 } from "zod";
924
- var vendorSchema = z12.object({
925
- id: z12.string(),
926
- name: z12.string(),
927
- 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()
928
1007
  });
929
1008
 
930
1009
  // src/vendor/endpoints.ts
@@ -939,13 +1018,13 @@ var VendorEndpoints = class {
939
1018
  };
940
1019
 
941
1020
  // src/vouchers/schemas.ts
942
- import { z as z13 } from "zod";
943
- var voucherSchema = z13.object({
944
- id: z13.string(),
945
- name: z13.string(),
946
- description: z13.string(),
947
- code: z13.string(),
948
- 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(),
949
1028
  redeemsProducts: quantifiable(storefrontProductSchema).array(),
950
1029
  redeemsBundles: quantifiable(storefrontBundleSchema).array()
951
1030
  });
@@ -972,9 +1051,10 @@ var VoucherEndpoints = class {
972
1051
  };
973
1052
 
974
1053
  // src/schemas.ts
975
- var schemas_exports2 = {};
976
- __export(schemas_exports2, {
977
- orders: () => schemas_exports
1054
+ var schemas_exports3 = {};
1055
+ __export(schemas_exports3, {
1056
+ identity: () => schemas_exports,
1057
+ orders: () => schemas_exports2
978
1058
  });
979
1059
 
980
1060
  // src/index.ts
@@ -1007,6 +1087,8 @@ export {
1007
1087
  NotFoundError,
1008
1088
  OrderStatus,
1009
1089
  Platform,
1010
- schemas_exports2 as schemas,
1090
+ SubscriptionStatus,
1091
+ TokenStore,
1092
+ schemas_exports3 as schemas,
1011
1093
  utmToObject
1012
1094
  };
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.3",
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",