@moonbase.sh/storefront-api 0.4.26 → 0.4.27

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
@@ -53,6 +53,7 @@ __export(index_exports, {
53
53
  Platform: () => Platform,
54
54
  SubscriptionStatus: () => SubscriptionStatus,
55
55
  TokenStore: () => TokenStore,
56
+ objectToQuery: () => objectToQuery,
56
57
  problemDetailsSchema: () => problemDetailsSchema,
57
58
  schemas: () => schemas_exports3,
58
59
  utmToObject: () => utmToObject
@@ -251,6 +252,7 @@ var storefrontOfferSchema = import_zod3.z.object({
251
252
  });
252
253
  var storefrontSchema = import_zod3.z.object({
253
254
  suggestedCurrency: import_zod3.z.string(),
255
+ enabledCurrencies: import_zod3.z.string().array(),
254
256
  products: storefrontProductSchema.array(),
255
257
  bundles: storefrontBundleSchema.array(),
256
258
  // Offers need to be optional since we may still have old, cached representations in browsers
@@ -678,6 +680,132 @@ var ProductEndpoints = class {
678
680
  }
679
681
  };
680
682
 
683
+ // src/utils/api.ts
684
+ var import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
685
+ function objectToQuery(obj) {
686
+ return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
687
+ }
688
+ var MoonbaseApi = class {
689
+ constructor(baseUrl, tokenStore, logger) {
690
+ this.baseUrl = baseUrl;
691
+ this.tokenStore = tokenStore;
692
+ this.logger = logger;
693
+ }
694
+ async authenticatedFetch(path, schema, options) {
695
+ if (!this.tokenStore.user)
696
+ throw new NotAuthenticatedError();
697
+ return await this.fetch(path, schema, options);
698
+ }
699
+ async fetch(path, schema, options) {
700
+ var _a;
701
+ const accessToken = await this.tokenStore.getAccessToken();
702
+ const contentType = (_a = options == null ? void 0 : options.contentType) != null ? _a : "application/json";
703
+ this.logger.debug("Making request to Moonbase API...", {
704
+ path,
705
+ body: options == null ? void 0 : options.body
706
+ });
707
+ const startedAt = /* @__PURE__ */ new Date();
708
+ const request = {
709
+ method: (options == null ? void 0 : options.method) || "GET",
710
+ mode: "cors",
711
+ headers: {
712
+ "Accept": "application/json",
713
+ "Content-Type": contentType,
714
+ // While this fetch can be anonymous, we add the token if we have it
715
+ ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
716
+ // Force CORS on all calls
717
+ "x-mb-cors": "1"
718
+ },
719
+ body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
720
+ signal: options == null ? void 0 : options.abort,
721
+ redirect: "manual"
722
+ };
723
+ const response = await (0, import_cross_fetch2.default)(this.baseUrl + path, request);
724
+ const finishedAt = /* @__PURE__ */ new Date();
725
+ this.logger.debug("Received response from Moonbase", {
726
+ path,
727
+ status: response.status,
728
+ duration: finishedAt.getTime() - startedAt.getTime()
729
+ });
730
+ if (response.status >= 400) {
731
+ try {
732
+ await handleResponseProblem(response, this.logger);
733
+ } catch (err) {
734
+ this.reportRequestProblem(path, request, response, err);
735
+ throw err;
736
+ }
737
+ }
738
+ let json;
739
+ try {
740
+ json = schema ? await response.json() : null;
741
+ return {
742
+ data: schema ? schema.parse(json) : null,
743
+ headers: Object.fromEntries(response.headers.entries()),
744
+ status: response.status
745
+ };
746
+ } catch (err) {
747
+ this.logger.warn("Could not parse response", {
748
+ status: response.status,
749
+ path,
750
+ content: json || (response.bodyUsed ? "unknown" : await response.text()),
751
+ headers: Object.fromEntries(response.headers.entries()),
752
+ userAgent: window && window.navigator && window.navigator.userAgent,
753
+ err
754
+ });
755
+ this.reportParsingProblem(path, err, json || (response.bodyUsed ? "unknown" : await response.text()));
756
+ throw new MoonbaseError("Bad response", "Could not parse server response", response.status);
757
+ }
758
+ }
759
+ async reportParsingProblem(path, err, body) {
760
+ try {
761
+ await (0, import_cross_fetch2.default)(`${this.baseUrl}/api/customer/insights/error`, {
762
+ mode: "cors",
763
+ method: "POST",
764
+ headers: {
765
+ "Accept": "application/json",
766
+ "Content-Type": "application/json"
767
+ },
768
+ body: JSON.stringify({
769
+ title: "Parse error",
770
+ detail: `Could not parse response body`,
771
+ path,
772
+ origin: window == null ? void 0 : window.location.href,
773
+ userAgent: window && window.navigator && window.navigator.userAgent,
774
+ err,
775
+ body
776
+ })
777
+ });
778
+ } catch (e) {
779
+ }
780
+ }
781
+ async reportRequestProblem(path, request, response, err) {
782
+ try {
783
+ await (0, import_cross_fetch2.default)(`${this.baseUrl}/api/customer/insights/warn`, {
784
+ mode: "cors",
785
+ method: "POST",
786
+ headers: {
787
+ "Accept": "application/json",
788
+ "Content-Type": "application/json"
789
+ },
790
+ body: JSON.stringify({
791
+ title: "Request error",
792
+ detail: `Request failed with status ${response.status}`,
793
+ status: response.status,
794
+ request: {
795
+ ...request,
796
+ headers: void 0,
797
+ body: void 0
798
+ },
799
+ error: err,
800
+ path,
801
+ origin: window == null ? void 0 : window.location.href
802
+ })
803
+ });
804
+ } catch (e) {
805
+ }
806
+ }
807
+ };
808
+
681
809
  // src/inventory/subscriptions/endpoints.ts
682
810
  var import_zod13 = require("zod");
683
811
 
@@ -838,6 +966,8 @@ var subscriptionSchema = import_zod12.z.object({
838
966
  startedAt: import_zod12.z.coerce.date(),
839
967
  total: orderTotalSchema,
840
968
  cycleLength: import_zod12.z.nativeEnum(CycleLength),
969
+ paymentMethod: import_zod12.z.string().optional(),
970
+ embeddedUpdatePaymentUrl: import_zod12.z.string().optional(),
841
971
  content: import_zod12.z.discriminatedUnion("type", [
842
972
  import_zod12.z.object({
843
973
  type: import_zod12.z.literal("Product"),
@@ -862,8 +992,8 @@ var SubscriptionEndpoints = class {
862
992
  const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/subscriptions", paged(subscriptionSchema));
863
993
  return response.data;
864
994
  }
865
- async getById(subscriptionId) {
866
- const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}`, subscriptionSchema);
995
+ async getById(subscriptionId, options) {
996
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}?${objectToQuery(options)}`, subscriptionSchema);
867
997
  return response.data;
868
998
  }
869
999
  async cancel(subscriptionId) {
@@ -954,129 +1084,6 @@ var StorefrontEndpoints = class {
954
1084
  }
955
1085
  };
956
1086
 
957
- // src/utils/api.ts
958
- var import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
959
- var MoonbaseApi = class {
960
- constructor(baseUrl, tokenStore, logger) {
961
- this.baseUrl = baseUrl;
962
- this.tokenStore = tokenStore;
963
- this.logger = logger;
964
- }
965
- async authenticatedFetch(path, schema, options) {
966
- if (!this.tokenStore.user)
967
- throw new NotAuthenticatedError();
968
- return await this.fetch(path, schema, options);
969
- }
970
- async fetch(path, schema, options) {
971
- var _a;
972
- const accessToken = await this.tokenStore.getAccessToken();
973
- const contentType = (_a = options == null ? void 0 : options.contentType) != null ? _a : "application/json";
974
- this.logger.debug("Making request to Moonbase API...", {
975
- path,
976
- body: options == null ? void 0 : options.body
977
- });
978
- const startedAt = /* @__PURE__ */ new Date();
979
- const request = {
980
- method: (options == null ? void 0 : options.method) || "GET",
981
- mode: "cors",
982
- headers: {
983
- "Accept": "application/json",
984
- "Content-Type": contentType,
985
- // While this fetch can be anonymous, we add the token if we have it
986
- ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
987
- // Force CORS on all calls
988
- "x-mb-cors": "1"
989
- },
990
- body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
991
- signal: options == null ? void 0 : options.abort,
992
- redirect: "manual"
993
- };
994
- const response = await (0, import_cross_fetch2.default)(this.baseUrl + path, request);
995
- const finishedAt = /* @__PURE__ */ new Date();
996
- this.logger.debug("Received response from Moonbase", {
997
- path,
998
- status: response.status,
999
- duration: finishedAt.getTime() - startedAt.getTime()
1000
- });
1001
- if (response.status >= 400) {
1002
- try {
1003
- await handleResponseProblem(response, this.logger);
1004
- } catch (err) {
1005
- this.reportRequestProblem(path, request, response, err);
1006
- throw err;
1007
- }
1008
- }
1009
- let json;
1010
- try {
1011
- json = schema ? await response.json() : null;
1012
- return {
1013
- data: schema ? schema.parse(json) : null,
1014
- headers: Object.fromEntries(response.headers.entries()),
1015
- status: response.status
1016
- };
1017
- } catch (err) {
1018
- this.logger.warn("Could not parse response", {
1019
- status: response.status,
1020
- path,
1021
- content: json || (response.bodyUsed ? "unknown" : await response.text()),
1022
- headers: Object.fromEntries(response.headers.entries()),
1023
- userAgent: window && window.navigator && window.navigator.userAgent,
1024
- err
1025
- });
1026
- this.reportParsingProblem(path, err, json || (response.bodyUsed ? "unknown" : await response.text()));
1027
- throw new MoonbaseError("Bad response", "Could not parse server response", response.status);
1028
- }
1029
- }
1030
- async reportParsingProblem(path, err, body) {
1031
- try {
1032
- await (0, import_cross_fetch2.default)(`${this.baseUrl}/api/customer/insights/error`, {
1033
- mode: "cors",
1034
- method: "POST",
1035
- headers: {
1036
- "Accept": "application/json",
1037
- "Content-Type": "application/json"
1038
- },
1039
- body: JSON.stringify({
1040
- title: "Parse error",
1041
- detail: `Could not parse response body`,
1042
- path,
1043
- origin: window == null ? void 0 : window.location.href,
1044
- userAgent: window && window.navigator && window.navigator.userAgent,
1045
- err,
1046
- body
1047
- })
1048
- });
1049
- } catch (e) {
1050
- }
1051
- }
1052
- async reportRequestProblem(path, request, response, err) {
1053
- try {
1054
- await (0, import_cross_fetch2.default)(`${this.baseUrl}/api/customer/insights/warn`, {
1055
- mode: "cors",
1056
- method: "POST",
1057
- headers: {
1058
- "Accept": "application/json",
1059
- "Content-Type": "application/json"
1060
- },
1061
- body: JSON.stringify({
1062
- title: "Request error",
1063
- detail: `Request failed with status ${response.status}`,
1064
- status: response.status,
1065
- request: {
1066
- ...request,
1067
- headers: void 0,
1068
- body: void 0
1069
- },
1070
- error: err,
1071
- path,
1072
- origin: window == null ? void 0 : window.location.href
1073
- })
1074
- });
1075
- } catch (e) {
1076
- }
1077
- }
1078
- };
1079
-
1080
1087
  // src/utils/tokenStore.ts
1081
1088
  var import_cross_fetch3 = __toESM(require("cross-fetch"), 1);
1082
1089
 
@@ -1417,6 +1424,7 @@ var MoonbaseClient = class {
1417
1424
  Platform,
1418
1425
  SubscriptionStatus,
1419
1426
  TokenStore,
1427
+ objectToQuery,
1420
1428
  problemDetailsSchema,
1421
1429
  schemas,
1422
1430
  utmToObject
package/dist/index.d.cts CHANGED
@@ -59,6 +59,7 @@ interface FetchOptions {
59
59
  contentType?: string;
60
60
  abort?: AbortSignal;
61
61
  }
62
+ declare function objectToQuery(obj?: Record<string, string | number | boolean | Date>): string;
62
63
  declare class MoonbaseApi {
63
64
  baseUrl: string;
64
65
  private tokenStore;
@@ -2084,6 +2085,8 @@ declare const subscriptionSchema: z.ZodObject<{
2084
2085
  };
2085
2086
  }>;
2086
2087
  cycleLength: z.ZodNativeEnum<typeof CycleLength>;
2088
+ paymentMethod: z.ZodOptional<z.ZodString>;
2089
+ embeddedUpdatePaymentUrl: z.ZodOptional<z.ZodString>;
2087
2090
  content: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
2088
2091
  type: z.ZodLiteral<"Product">;
2089
2092
  quantity: z.ZodNumber;
@@ -4694,6 +4697,8 @@ declare const subscriptionSchema: z.ZodObject<{
4694
4697
  }[] | undefined;
4695
4698
  };
4696
4699
  };
4700
+ paymentMethod?: string | undefined;
4701
+ embeddedUpdatePaymentUrl?: string | undefined;
4697
4702
  }, {
4698
4703
  id: string;
4699
4704
  status: SubscriptionStatus;
@@ -4999,6 +5004,8 @@ declare const subscriptionSchema: z.ZodObject<{
4999
5004
  }[] | undefined;
5000
5005
  };
5001
5006
  };
5007
+ paymentMethod?: string | undefined;
5008
+ embeddedUpdatePaymentUrl?: string | undefined;
5002
5009
  }>;
5003
5010
 
5004
5011
  declare enum SubscriptionStatus {
@@ -5013,7 +5020,10 @@ declare class SubscriptionEndpoints {
5013
5020
  private readonly configuration;
5014
5021
  constructor(api: MoonbaseApi, configuration: MoonbaseConfiguration);
5015
5022
  get(nextUrl?: string): Promise<Page<Subscription>>;
5016
- getById(subscriptionId: string): Promise<Subscription>;
5023
+ getById(subscriptionId: string, options?: {
5024
+ toUpdatePaymentMethod?: boolean;
5025
+ returnUrl?: string;
5026
+ }): Promise<Subscription>;
5017
5027
  cancel(subscriptionId: string): Promise<Subscription>;
5018
5028
  renew(subscriptionId: string, returnUrl: string, embedded: boolean): Promise<{
5019
5029
  location: string;
@@ -19177,6 +19187,7 @@ declare class StorefrontEndpoints {
19177
19187
  }[] | undefined;
19178
19188
  }[];
19179
19189
  suggestedCurrency: string;
19190
+ enabledCurrencies: string[];
19180
19191
  bundles: {
19181
19192
  id: string;
19182
19193
  name: string;
@@ -26726,6 +26737,7 @@ declare const storefrontOfferSchema: z.ZodObject<{
26726
26737
  }>;
26727
26738
  declare const storefrontSchema: z.ZodObject<{
26728
26739
  suggestedCurrency: z.ZodString;
26740
+ enabledCurrencies: z.ZodArray<z.ZodString, "many">;
26729
26741
  products: z.ZodArray<z.ZodObject<{
26730
26742
  id: z.ZodString;
26731
26743
  name: z.ZodString;
@@ -30969,6 +30981,7 @@ declare const storefrontSchema: z.ZodObject<{
30969
30981
  }[] | undefined;
30970
30982
  }[];
30971
30983
  suggestedCurrency: string;
30984
+ enabledCurrencies: string[];
30972
30985
  bundles: {
30973
30986
  id: string;
30974
30987
  name: string;
@@ -31527,6 +31540,7 @@ declare const storefrontSchema: z.ZodObject<{
31527
31540
  }[] | undefined;
31528
31541
  }[];
31529
31542
  suggestedCurrency: string;
31543
+ enabledCurrencies: string[];
31530
31544
  bundles: {
31531
31545
  id: string;
31532
31546
  name: string;
@@ -32075,4 +32089,4 @@ declare class MoonbaseClient {
32075
32089
  orders: OrderEndpoints;
32076
32090
  }
32077
32091
 
32078
- export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type CompletedOrder, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, LogLevel, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, OfferUtils, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontProduct, type Subscription, SubscriptionStatus, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type Vendor, type Voucher, problemDetailsSchema, schemas, utmToObject };
32092
+ export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type CompletedOrder, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, LogLevel, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, OfferUtils, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontProduct, type Subscription, SubscriptionStatus, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type Vendor, type Voucher, objectToQuery, problemDetailsSchema, schemas, utmToObject };
package/dist/index.d.ts CHANGED
@@ -59,6 +59,7 @@ interface FetchOptions {
59
59
  contentType?: string;
60
60
  abort?: AbortSignal;
61
61
  }
62
+ declare function objectToQuery(obj?: Record<string, string | number | boolean | Date>): string;
62
63
  declare class MoonbaseApi {
63
64
  baseUrl: string;
64
65
  private tokenStore;
@@ -2084,6 +2085,8 @@ declare const subscriptionSchema: z.ZodObject<{
2084
2085
  };
2085
2086
  }>;
2086
2087
  cycleLength: z.ZodNativeEnum<typeof CycleLength>;
2088
+ paymentMethod: z.ZodOptional<z.ZodString>;
2089
+ embeddedUpdatePaymentUrl: z.ZodOptional<z.ZodString>;
2087
2090
  content: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
2088
2091
  type: z.ZodLiteral<"Product">;
2089
2092
  quantity: z.ZodNumber;
@@ -4694,6 +4697,8 @@ declare const subscriptionSchema: z.ZodObject<{
4694
4697
  }[] | undefined;
4695
4698
  };
4696
4699
  };
4700
+ paymentMethod?: string | undefined;
4701
+ embeddedUpdatePaymentUrl?: string | undefined;
4697
4702
  }, {
4698
4703
  id: string;
4699
4704
  status: SubscriptionStatus;
@@ -4999,6 +5004,8 @@ declare const subscriptionSchema: z.ZodObject<{
4999
5004
  }[] | undefined;
5000
5005
  };
5001
5006
  };
5007
+ paymentMethod?: string | undefined;
5008
+ embeddedUpdatePaymentUrl?: string | undefined;
5002
5009
  }>;
5003
5010
 
5004
5011
  declare enum SubscriptionStatus {
@@ -5013,7 +5020,10 @@ declare class SubscriptionEndpoints {
5013
5020
  private readonly configuration;
5014
5021
  constructor(api: MoonbaseApi, configuration: MoonbaseConfiguration);
5015
5022
  get(nextUrl?: string): Promise<Page<Subscription>>;
5016
- getById(subscriptionId: string): Promise<Subscription>;
5023
+ getById(subscriptionId: string, options?: {
5024
+ toUpdatePaymentMethod?: boolean;
5025
+ returnUrl?: string;
5026
+ }): Promise<Subscription>;
5017
5027
  cancel(subscriptionId: string): Promise<Subscription>;
5018
5028
  renew(subscriptionId: string, returnUrl: string, embedded: boolean): Promise<{
5019
5029
  location: string;
@@ -19177,6 +19187,7 @@ declare class StorefrontEndpoints {
19177
19187
  }[] | undefined;
19178
19188
  }[];
19179
19189
  suggestedCurrency: string;
19190
+ enabledCurrencies: string[];
19180
19191
  bundles: {
19181
19192
  id: string;
19182
19193
  name: string;
@@ -26726,6 +26737,7 @@ declare const storefrontOfferSchema: z.ZodObject<{
26726
26737
  }>;
26727
26738
  declare const storefrontSchema: z.ZodObject<{
26728
26739
  suggestedCurrency: z.ZodString;
26740
+ enabledCurrencies: z.ZodArray<z.ZodString, "many">;
26729
26741
  products: z.ZodArray<z.ZodObject<{
26730
26742
  id: z.ZodString;
26731
26743
  name: z.ZodString;
@@ -30969,6 +30981,7 @@ declare const storefrontSchema: z.ZodObject<{
30969
30981
  }[] | undefined;
30970
30982
  }[];
30971
30983
  suggestedCurrency: string;
30984
+ enabledCurrencies: string[];
30972
30985
  bundles: {
30973
30986
  id: string;
30974
30987
  name: string;
@@ -31527,6 +31540,7 @@ declare const storefrontSchema: z.ZodObject<{
31527
31540
  }[] | undefined;
31528
31541
  }[];
31529
31542
  suggestedCurrency: string;
31543
+ enabledCurrencies: string[];
31530
31544
  bundles: {
31531
31545
  id: string;
31532
31546
  name: string;
@@ -32075,4 +32089,4 @@ declare class MoonbaseClient {
32075
32089
  orders: OrderEndpoints;
32076
32090
  }
32077
32091
 
32078
- export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type CompletedOrder, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, LogLevel, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, OfferUtils, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontProduct, type Subscription, SubscriptionStatus, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type Vendor, type Voucher, problemDetailsSchema, schemas, utmToObject };
32092
+ export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type CompletedOrder, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, LogLevel, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, OfferUtils, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontProduct, type Subscription, SubscriptionStatus, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type Vendor, type Voucher, objectToQuery, problemDetailsSchema, schemas, utmToObject };
package/dist/index.js CHANGED
@@ -196,6 +196,7 @@ var storefrontOfferSchema = z3.object({
196
196
  });
197
197
  var storefrontSchema = z3.object({
198
198
  suggestedCurrency: z3.string(),
199
+ enabledCurrencies: z3.string().array(),
199
200
  products: storefrontProductSchema.array(),
200
201
  bundles: storefrontBundleSchema.array(),
201
202
  // Offers need to be optional since we may still have old, cached representations in browsers
@@ -623,6 +624,132 @@ var ProductEndpoints = class {
623
624
  }
624
625
  };
625
626
 
627
+ // src/utils/api.ts
628
+ import fetch2 from "cross-fetch";
629
+ function objectToQuery(obj) {
630
+ return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
631
+ }
632
+ var MoonbaseApi = class {
633
+ constructor(baseUrl, tokenStore, logger) {
634
+ this.baseUrl = baseUrl;
635
+ this.tokenStore = tokenStore;
636
+ this.logger = logger;
637
+ }
638
+ async authenticatedFetch(path, schema, options) {
639
+ if (!this.tokenStore.user)
640
+ throw new NotAuthenticatedError();
641
+ return await this.fetch(path, schema, options);
642
+ }
643
+ async fetch(path, schema, options) {
644
+ var _a;
645
+ const accessToken = await this.tokenStore.getAccessToken();
646
+ const contentType = (_a = options == null ? void 0 : options.contentType) != null ? _a : "application/json";
647
+ this.logger.debug("Making request to Moonbase API...", {
648
+ path,
649
+ body: options == null ? void 0 : options.body
650
+ });
651
+ const startedAt = /* @__PURE__ */ new Date();
652
+ const request = {
653
+ method: (options == null ? void 0 : options.method) || "GET",
654
+ mode: "cors",
655
+ headers: {
656
+ "Accept": "application/json",
657
+ "Content-Type": contentType,
658
+ // While this fetch can be anonymous, we add the token if we have it
659
+ ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
660
+ // Force CORS on all calls
661
+ "x-mb-cors": "1"
662
+ },
663
+ body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
664
+ signal: options == null ? void 0 : options.abort,
665
+ redirect: "manual"
666
+ };
667
+ const response = await fetch2(this.baseUrl + path, request);
668
+ const finishedAt = /* @__PURE__ */ new Date();
669
+ this.logger.debug("Received response from Moonbase", {
670
+ path,
671
+ status: response.status,
672
+ duration: finishedAt.getTime() - startedAt.getTime()
673
+ });
674
+ if (response.status >= 400) {
675
+ try {
676
+ await handleResponseProblem(response, this.logger);
677
+ } catch (err) {
678
+ this.reportRequestProblem(path, request, response, err);
679
+ throw err;
680
+ }
681
+ }
682
+ let json;
683
+ try {
684
+ json = schema ? await response.json() : null;
685
+ return {
686
+ data: schema ? schema.parse(json) : null,
687
+ headers: Object.fromEntries(response.headers.entries()),
688
+ status: response.status
689
+ };
690
+ } catch (err) {
691
+ this.logger.warn("Could not parse response", {
692
+ status: response.status,
693
+ path,
694
+ content: json || (response.bodyUsed ? "unknown" : await response.text()),
695
+ headers: Object.fromEntries(response.headers.entries()),
696
+ userAgent: window && window.navigator && window.navigator.userAgent,
697
+ err
698
+ });
699
+ this.reportParsingProblem(path, err, json || (response.bodyUsed ? "unknown" : await response.text()));
700
+ throw new MoonbaseError("Bad response", "Could not parse server response", response.status);
701
+ }
702
+ }
703
+ async reportParsingProblem(path, err, body) {
704
+ try {
705
+ await fetch2(`${this.baseUrl}/api/customer/insights/error`, {
706
+ mode: "cors",
707
+ method: "POST",
708
+ headers: {
709
+ "Accept": "application/json",
710
+ "Content-Type": "application/json"
711
+ },
712
+ body: JSON.stringify({
713
+ title: "Parse error",
714
+ detail: `Could not parse response body`,
715
+ path,
716
+ origin: window == null ? void 0 : window.location.href,
717
+ userAgent: window && window.navigator && window.navigator.userAgent,
718
+ err,
719
+ body
720
+ })
721
+ });
722
+ } catch (e) {
723
+ }
724
+ }
725
+ async reportRequestProblem(path, request, response, err) {
726
+ try {
727
+ await fetch2(`${this.baseUrl}/api/customer/insights/warn`, {
728
+ mode: "cors",
729
+ method: "POST",
730
+ headers: {
731
+ "Accept": "application/json",
732
+ "Content-Type": "application/json"
733
+ },
734
+ body: JSON.stringify({
735
+ title: "Request error",
736
+ detail: `Request failed with status ${response.status}`,
737
+ status: response.status,
738
+ request: {
739
+ ...request,
740
+ headers: void 0,
741
+ body: void 0
742
+ },
743
+ error: err,
744
+ path,
745
+ origin: window == null ? void 0 : window.location.href
746
+ })
747
+ });
748
+ } catch (e) {
749
+ }
750
+ }
751
+ };
752
+
626
753
  // src/inventory/subscriptions/endpoints.ts
627
754
  import { z as z13 } from "zod";
628
755
 
@@ -783,6 +910,8 @@ var subscriptionSchema = z12.object({
783
910
  startedAt: z12.coerce.date(),
784
911
  total: orderTotalSchema,
785
912
  cycleLength: z12.nativeEnum(CycleLength),
913
+ paymentMethod: z12.string().optional(),
914
+ embeddedUpdatePaymentUrl: z12.string().optional(),
786
915
  content: z12.discriminatedUnion("type", [
787
916
  z12.object({
788
917
  type: z12.literal("Product"),
@@ -807,8 +936,8 @@ var SubscriptionEndpoints = class {
807
936
  const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/subscriptions", paged(subscriptionSchema));
808
937
  return response.data;
809
938
  }
810
- async getById(subscriptionId) {
811
- const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}`, subscriptionSchema);
939
+ async getById(subscriptionId, options) {
940
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}?${objectToQuery(options)}`, subscriptionSchema);
812
941
  return response.data;
813
942
  }
814
943
  async cancel(subscriptionId) {
@@ -899,129 +1028,6 @@ var StorefrontEndpoints = class {
899
1028
  }
900
1029
  };
901
1030
 
902
- // src/utils/api.ts
903
- import fetch2 from "cross-fetch";
904
- var MoonbaseApi = class {
905
- constructor(baseUrl, tokenStore, logger) {
906
- this.baseUrl = baseUrl;
907
- this.tokenStore = tokenStore;
908
- this.logger = logger;
909
- }
910
- async authenticatedFetch(path, schema, options) {
911
- if (!this.tokenStore.user)
912
- throw new NotAuthenticatedError();
913
- return await this.fetch(path, schema, options);
914
- }
915
- async fetch(path, schema, options) {
916
- var _a;
917
- const accessToken = await this.tokenStore.getAccessToken();
918
- const contentType = (_a = options == null ? void 0 : options.contentType) != null ? _a : "application/json";
919
- this.logger.debug("Making request to Moonbase API...", {
920
- path,
921
- body: options == null ? void 0 : options.body
922
- });
923
- const startedAt = /* @__PURE__ */ new Date();
924
- const request = {
925
- method: (options == null ? void 0 : options.method) || "GET",
926
- mode: "cors",
927
- headers: {
928
- "Accept": "application/json",
929
- "Content-Type": contentType,
930
- // While this fetch can be anonymous, we add the token if we have it
931
- ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
932
- // Force CORS on all calls
933
- "x-mb-cors": "1"
934
- },
935
- body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
936
- signal: options == null ? void 0 : options.abort,
937
- redirect: "manual"
938
- };
939
- const response = await fetch2(this.baseUrl + path, request);
940
- const finishedAt = /* @__PURE__ */ new Date();
941
- this.logger.debug("Received response from Moonbase", {
942
- path,
943
- status: response.status,
944
- duration: finishedAt.getTime() - startedAt.getTime()
945
- });
946
- if (response.status >= 400) {
947
- try {
948
- await handleResponseProblem(response, this.logger);
949
- } catch (err) {
950
- this.reportRequestProblem(path, request, response, err);
951
- throw err;
952
- }
953
- }
954
- let json;
955
- try {
956
- json = schema ? await response.json() : null;
957
- return {
958
- data: schema ? schema.parse(json) : null,
959
- headers: Object.fromEntries(response.headers.entries()),
960
- status: response.status
961
- };
962
- } catch (err) {
963
- this.logger.warn("Could not parse response", {
964
- status: response.status,
965
- path,
966
- content: json || (response.bodyUsed ? "unknown" : await response.text()),
967
- headers: Object.fromEntries(response.headers.entries()),
968
- userAgent: window && window.navigator && window.navigator.userAgent,
969
- err
970
- });
971
- this.reportParsingProblem(path, err, json || (response.bodyUsed ? "unknown" : await response.text()));
972
- throw new MoonbaseError("Bad response", "Could not parse server response", response.status);
973
- }
974
- }
975
- async reportParsingProblem(path, err, body) {
976
- try {
977
- await fetch2(`${this.baseUrl}/api/customer/insights/error`, {
978
- mode: "cors",
979
- method: "POST",
980
- headers: {
981
- "Accept": "application/json",
982
- "Content-Type": "application/json"
983
- },
984
- body: JSON.stringify({
985
- title: "Parse error",
986
- detail: `Could not parse response body`,
987
- path,
988
- origin: window == null ? void 0 : window.location.href,
989
- userAgent: window && window.navigator && window.navigator.userAgent,
990
- err,
991
- body
992
- })
993
- });
994
- } catch (e) {
995
- }
996
- }
997
- async reportRequestProblem(path, request, response, err) {
998
- try {
999
- await fetch2(`${this.baseUrl}/api/customer/insights/warn`, {
1000
- mode: "cors",
1001
- method: "POST",
1002
- headers: {
1003
- "Accept": "application/json",
1004
- "Content-Type": "application/json"
1005
- },
1006
- body: JSON.stringify({
1007
- title: "Request error",
1008
- detail: `Request failed with status ${response.status}`,
1009
- status: response.status,
1010
- request: {
1011
- ...request,
1012
- headers: void 0,
1013
- body: void 0
1014
- },
1015
- error: err,
1016
- path,
1017
- origin: window == null ? void 0 : window.location.href
1018
- })
1019
- });
1020
- } catch (e) {
1021
- }
1022
- }
1023
- };
1024
-
1025
1031
  // src/utils/tokenStore.ts
1026
1032
  import fetch3 from "cross-fetch";
1027
1033
 
@@ -1361,6 +1367,7 @@ export {
1361
1367
  Platform,
1362
1368
  SubscriptionStatus,
1363
1369
  TokenStore,
1370
+ objectToQuery,
1364
1371
  problemDetailsSchema,
1365
1372
  schemas_exports3 as schemas,
1366
1373
  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.4.26",
4
+ "version": "0.4.27",
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",