@moonbase.sh/storefront-api 3.4.0 → 3.5.1

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
@@ -46,6 +46,7 @@ __export(index_exports, {
46
46
  OfferUtils: () => OfferUtils,
47
47
  OrderStatus: () => OrderStatus,
48
48
  Platform: () => Platform,
49
+ StoreClosedError: () => StoreClosedError,
49
50
  SubscriptionCancellationReason: () => SubscriptionCancellationReason,
50
51
  SubscriptionStatus: () => SubscriptionStatus,
51
52
  TokenStore: () => TokenStore,
@@ -634,6 +635,13 @@ var NotFoundError = class extends Error {
634
635
  this.message = message != null ? message : "Not found";
635
636
  }
636
637
  };
638
+ var StoreClosedError = class extends Error {
639
+ constructor(message) {
640
+ super();
641
+ this.name = "StoreClosedError";
642
+ this.message = message != null ? message : "This store has closed";
643
+ }
644
+ };
637
645
  var MoonbaseError = class extends Error {
638
646
  constructor(title, detail, status, errors) {
639
647
  super();
@@ -658,7 +666,8 @@ var problemDetailsSchema = import_zod7.z.object({
658
666
  detail: import_zod7.z.string().optional(),
659
667
  status: import_zod7.z.number().optional(),
660
668
  instance: import_zod7.z.string().optional(),
661
- errors: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.string().array()).optional()
669
+ errors: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.string().array()).optional(),
670
+ errorType: import_zod7.z.string().optional()
662
671
  });
663
672
 
664
673
  // src/utils/problemHandler.ts
@@ -688,6 +697,8 @@ async function handleResponseProblem(response, logger) {
688
697
  throw new Error("An unknown problem occurred");
689
698
  }
690
699
  logger.debug("The response indicates a problem", problemDetails);
700
+ if (problemDetails.errorType === "StoreClosed")
701
+ throw new StoreClosedError(problemDetails.detail);
691
702
  throw new MoonbaseError(
692
703
  problemDetails.title,
693
704
  problemDetails.detail,
@@ -797,7 +808,8 @@ var IdentityEndpoints = class {
797
808
  headers: {
798
809
  "Accept": "application/json",
799
810
  "Content-Type": "text/plain",
800
- "x-mb-cors": "1"
811
+ "x-mb-cors": "1",
812
+ "x-mb-client": this.api.clientHeader
801
813
  },
802
814
  body: password
803
815
  });
@@ -822,7 +834,8 @@ var IdentityEndpoints = class {
822
834
  headers: {
823
835
  "Accept": "application/json",
824
836
  "Content-Type": "application/json",
825
- "x-mb-cors": "1"
837
+ "x-mb-cors": "1",
838
+ "x-mb-client": this.api.clientHeader
826
839
  },
827
840
  body: JSON.stringify({
828
841
  name,
@@ -888,7 +901,8 @@ var IdentityEndpoints = class {
888
901
  headers: {
889
902
  "Accept": "application/json",
890
903
  "Content-Type": "text/plain",
891
- "x-mb-cors": "1"
904
+ "x-mb-cors": "1",
905
+ "x-mb-client": this.api.clientHeader
892
906
  },
893
907
  body: newPassword
894
908
  });
@@ -1054,8 +1068,8 @@ var ProductEndpoints = class {
1054
1068
  this.api = api;
1055
1069
  this.configuration = configuration;
1056
1070
  }
1057
- async get(productId, version) {
1058
- const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version ? `?version=${version}${this.configuration.includeManifests ? "&includeManifests=true" : ""}` : this.configuration.includeManifests ? "?includeManifests=true" : ""}`, productSummarySchema);
1071
+ async get(productId, version2) {
1072
+ const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version2 ? `?version=${version2}${this.configuration.includeManifests ? "&includeManifests=true" : ""}` : this.configuration.includeManifests ? "?includeManifests=true" : ""}`, productSummarySchema);
1059
1073
  return response.data;
1060
1074
  }
1061
1075
  async getOwned(nextUrl) {
@@ -1083,15 +1097,24 @@ var ProductEndpoints = class {
1083
1097
  // src/inventory/subscriptions/endpoints.ts
1084
1098
  var import_zod14 = require("zod");
1085
1099
 
1100
+ // package.json
1101
+ var version = "3.5.1";
1102
+
1103
+ // src/utils/client.ts
1104
+ function buildClientHeader(sdk) {
1105
+ return `${sdk != null ? sdk : ""} @moonbase.sh/storefront-api/${version}`.trim().replace(/\s+/g, " ");
1106
+ }
1107
+
1086
1108
  // src/utils/api.ts
1087
1109
  function objectToQuery(obj) {
1088
1110
  return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
1089
1111
  }
1090
1112
  var MoonbaseApi = class {
1091
- constructor(baseUrl, tokenStore, logger) {
1113
+ constructor(baseUrl, tokenStore, logger, sdk) {
1092
1114
  this.baseUrl = baseUrl;
1093
1115
  this.tokenStore = tokenStore;
1094
1116
  this.logger = logger;
1117
+ this.clientHeader = buildClientHeader(sdk);
1095
1118
  }
1096
1119
  async authenticatedFetch(path, schema, options) {
1097
1120
  if (!this.tokenStore.user)
@@ -1116,7 +1139,8 @@ var MoonbaseApi = class {
1116
1139
  // While this fetch can be anonymous, we add the token if we have it
1117
1140
  ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
1118
1141
  // Force CORS on all calls
1119
- "x-mb-cors": "1"
1142
+ "x-mb-cors": "1",
1143
+ "x-mb-client": this.clientHeader
1120
1144
  },
1121
1145
  body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
1122
1146
  signal: options == null ? void 0 : options.abort,
@@ -1142,7 +1166,8 @@ var MoonbaseApi = class {
1142
1166
  try {
1143
1167
  await handleResponseProblem(response, this.logger);
1144
1168
  } catch (err) {
1145
- this.reportRequestProblem(path, request, response, err);
1169
+ if (!(err instanceof StoreClosedError))
1170
+ this.reportRequestProblem(path, request, response, err);
1146
1171
  throw err;
1147
1172
  }
1148
1173
  }
@@ -1174,7 +1199,8 @@ var MoonbaseApi = class {
1174
1199
  method: "POST",
1175
1200
  headers: {
1176
1201
  "Accept": "application/json",
1177
- "Content-Type": "application/json"
1202
+ "Content-Type": "application/json",
1203
+ "x-mb-client": this.clientHeader
1178
1204
  },
1179
1205
  body: JSON.stringify({
1180
1206
  title: "Parse error",
@@ -1196,7 +1222,8 @@ var MoonbaseApi = class {
1196
1222
  method: "POST",
1197
1223
  headers: {
1198
1224
  "Accept": "application/json",
1199
- "Content-Type": "application/json"
1225
+ "Content-Type": "application/json",
1226
+ "x-mb-client": this.clientHeader
1200
1227
  },
1201
1228
  body: JSON.stringify({
1202
1229
  title: "Request error",
@@ -1848,7 +1875,8 @@ var _TokenStore = class _TokenStore {
1848
1875
  headers: {
1849
1876
  "Accept": "application/json",
1850
1877
  "Content-Type": "text/plain",
1851
- "x-mb-cors": "1"
1878
+ "x-mb-cors": "1",
1879
+ "x-mb-client": buildClientHeader(this.configuration.sdk)
1852
1880
  },
1853
1881
  body: this.tokens.accessToken
1854
1882
  });
@@ -2567,7 +2595,7 @@ var MoonbaseClient = class {
2567
2595
  this.configuration.endpoint = this.configuration.endpoint.replace(/\/$/, "");
2568
2596
  this.logger = (_a = this.configuration.logger) != null ? _a : new ConsoleLogger();
2569
2597
  this.tokenStore = new TokenStore(configuration);
2570
- this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger);
2598
+ this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger, this.configuration.sdk);
2571
2599
  this.storefront = new StorefrontEndpoints(this.api, this.configuration);
2572
2600
  this.identity = new IdentityEndpoints(this.api, this.tokenStore, this.logger);
2573
2601
  this.communications = new CommunicationsEndpoints(this.api);
@@ -2607,6 +2635,7 @@ var MoonbaseClient = class {
2607
2635
  OfferUtils,
2608
2636
  OrderStatus,
2609
2637
  Platform,
2638
+ StoreClosedError,
2610
2639
  SubscriptionCancellationReason,
2611
2640
  SubscriptionStatus,
2612
2641
  TokenStore,
package/dist/index.d.cts CHANGED
@@ -132,7 +132,13 @@ declare class MoonbaseApi {
132
132
  baseUrl: string;
133
133
  private tokenStore;
134
134
  private logger;
135
- constructor(baseUrl: string, tokenStore: ITokenStore, logger: ILogger);
135
+ /**
136
+ * The `x-mb-client` header this client sends with every request.
137
+ *
138
+ * @internal
139
+ */
140
+ readonly clientHeader: string;
141
+ constructor(baseUrl: string, tokenStore: ITokenStore, logger: ILogger, sdk?: string);
136
142
  authenticatedFetch<T extends ZodTypeAny>(path: string, schema: T | null, options?: FetchOptions): Promise<Response<z.infer<T>>>;
137
143
  fetch<T extends ZodTypeAny>(path: string, schema: T | null, options?: FetchOptions): Promise<Response<z.infer<T>>>;
138
144
  private reportParsingProblem;
@@ -47006,6 +47012,13 @@ declare class NotAuthenticatedError extends Error {
47006
47012
  declare class NotFoundError extends Error {
47007
47013
  constructor(message?: string);
47008
47014
  }
47015
+ /**
47016
+ * The store has closed its Moonbase account, so it answers nothing: no catalog, no cart, no
47017
+ * checkout and no sign-in. Not transient, so there is nothing to retry.
47018
+ */
47019
+ declare class StoreClosedError extends Error {
47020
+ constructor(message?: string);
47021
+ }
47009
47022
  declare class MoonbaseError extends Error {
47010
47023
  readonly title: string;
47011
47024
  readonly detail: string | undefined;
@@ -47115,6 +47128,7 @@ declare const problemDetailsSchema: z.ZodObject<{
47115
47128
  status: z.ZodOptional<z.ZodNumber>;
47116
47129
  instance: z.ZodOptional<z.ZodString>;
47117
47130
  errors: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
47131
+ errorType: z.ZodOptional<z.ZodString>;
47118
47132
  }, "strip", z.ZodTypeAny, {
47119
47133
  title: string;
47120
47134
  type?: string | undefined;
@@ -47122,6 +47136,7 @@ declare const problemDetailsSchema: z.ZodObject<{
47122
47136
  detail?: string | undefined;
47123
47137
  instance?: string | undefined;
47124
47138
  errors?: Record<string, string[]> | undefined;
47139
+ errorType?: string | undefined;
47125
47140
  }, {
47126
47141
  title: string;
47127
47142
  type?: string | undefined;
@@ -47129,6 +47144,7 @@ declare const problemDetailsSchema: z.ZodObject<{
47129
47144
  detail?: string | undefined;
47130
47145
  instance?: string | undefined;
47131
47146
  errors?: Record<string, string[]> | undefined;
47147
+ errorType?: string | undefined;
47132
47148
  }>;
47133
47149
  type ProblemDetails = z.infer<typeof problemDetailsSchema>;
47134
47150
 
@@ -47164,6 +47180,14 @@ interface MoonbaseConfiguration {
47164
47180
  includeManifests?: boolean;
47165
47181
  store?: IStore;
47166
47182
  logger?: ILogger;
47183
+ /**
47184
+ * Product tokens (`name/version`) of an SDK wrapping this one, such as
47185
+ * `@moonbase.sh/vue/3.6.1`, sent ahead of this package's own token in the
47186
+ * `x-mb-client` header.
47187
+ *
47188
+ * @internal
47189
+ */
47190
+ sdk?: string;
47167
47191
  }
47168
47192
  declare class MoonbaseClient {
47169
47193
  private readonly configuration;
@@ -47182,4 +47206,4 @@ declare class MoonbaseClient {
47182
47206
  orders: OrderEndpoints;
47183
47207
  }
47184
47208
 
47185
- export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CartCatalog, type CartOrder, type CartTotal, type CartTotalCondition, CartUtils, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, type ImageFit, type ImageFormat, type ImageTransform, ImageUtils, InMemoryStore, type License, LicenseStatus, type LineItem, type LineItemTotal, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, type OfferConditionContext, type OfferProgress, type OfferScope, OfferUtils, type OpenOrder, type Order, OrderStatus, type OrderTotal, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type PromotionDisplay, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpOptions, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontOfferTarget, type StorefrontProduct, type StorefrontPromotion, type StorefrontPromotionCta, type StorefrontPromotionTarget, type SubscribeInput, type SubscribeResponse, type Subscription, type SubscriptionCancellationFeedback, SubscriptionCancellationReason, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, imageWidths, isLocalStorageAvailable, isPromotionDisplay, isTransformableImageUrl, maxImageDimension, normalizeGroupIds, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, promotionDisplays, resolveUtm, schemas, utmToObject };
47209
+ export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CartCatalog, type CartOrder, type CartTotal, type CartTotalCondition, CartUtils, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, type ImageFit, type ImageFormat, type ImageTransform, ImageUtils, InMemoryStore, type License, LicenseStatus, type LineItem, type LineItemTotal, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, type OfferConditionContext, type OfferProgress, type OfferScope, OfferUtils, type OpenOrder, type Order, OrderStatus, type OrderTotal, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type PromotionDisplay, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpOptions, type SignUpResult, type SingleOrMultiple, StoreClosedError, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontOfferTarget, type StorefrontProduct, type StorefrontPromotion, type StorefrontPromotionCta, type StorefrontPromotionTarget, type SubscribeInput, type SubscribeResponse, type Subscription, type SubscriptionCancellationFeedback, SubscriptionCancellationReason, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, imageWidths, isLocalStorageAvailable, isPromotionDisplay, isTransformableImageUrl, maxImageDimension, normalizeGroupIds, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, promotionDisplays, resolveUtm, schemas, utmToObject };
package/dist/index.d.ts CHANGED
@@ -132,7 +132,13 @@ declare class MoonbaseApi {
132
132
  baseUrl: string;
133
133
  private tokenStore;
134
134
  private logger;
135
- constructor(baseUrl: string, tokenStore: ITokenStore, logger: ILogger);
135
+ /**
136
+ * The `x-mb-client` header this client sends with every request.
137
+ *
138
+ * @internal
139
+ */
140
+ readonly clientHeader: string;
141
+ constructor(baseUrl: string, tokenStore: ITokenStore, logger: ILogger, sdk?: string);
136
142
  authenticatedFetch<T extends ZodTypeAny>(path: string, schema: T | null, options?: FetchOptions): Promise<Response<z.infer<T>>>;
137
143
  fetch<T extends ZodTypeAny>(path: string, schema: T | null, options?: FetchOptions): Promise<Response<z.infer<T>>>;
138
144
  private reportParsingProblem;
@@ -47006,6 +47012,13 @@ declare class NotAuthenticatedError extends Error {
47006
47012
  declare class NotFoundError extends Error {
47007
47013
  constructor(message?: string);
47008
47014
  }
47015
+ /**
47016
+ * The store has closed its Moonbase account, so it answers nothing: no catalog, no cart, no
47017
+ * checkout and no sign-in. Not transient, so there is nothing to retry.
47018
+ */
47019
+ declare class StoreClosedError extends Error {
47020
+ constructor(message?: string);
47021
+ }
47009
47022
  declare class MoonbaseError extends Error {
47010
47023
  readonly title: string;
47011
47024
  readonly detail: string | undefined;
@@ -47115,6 +47128,7 @@ declare const problemDetailsSchema: z.ZodObject<{
47115
47128
  status: z.ZodOptional<z.ZodNumber>;
47116
47129
  instance: z.ZodOptional<z.ZodString>;
47117
47130
  errors: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
47131
+ errorType: z.ZodOptional<z.ZodString>;
47118
47132
  }, "strip", z.ZodTypeAny, {
47119
47133
  title: string;
47120
47134
  type?: string | undefined;
@@ -47122,6 +47136,7 @@ declare const problemDetailsSchema: z.ZodObject<{
47122
47136
  detail?: string | undefined;
47123
47137
  instance?: string | undefined;
47124
47138
  errors?: Record<string, string[]> | undefined;
47139
+ errorType?: string | undefined;
47125
47140
  }, {
47126
47141
  title: string;
47127
47142
  type?: string | undefined;
@@ -47129,6 +47144,7 @@ declare const problemDetailsSchema: z.ZodObject<{
47129
47144
  detail?: string | undefined;
47130
47145
  instance?: string | undefined;
47131
47146
  errors?: Record<string, string[]> | undefined;
47147
+ errorType?: string | undefined;
47132
47148
  }>;
47133
47149
  type ProblemDetails = z.infer<typeof problemDetailsSchema>;
47134
47150
 
@@ -47164,6 +47180,14 @@ interface MoonbaseConfiguration {
47164
47180
  includeManifests?: boolean;
47165
47181
  store?: IStore;
47166
47182
  logger?: ILogger;
47183
+ /**
47184
+ * Product tokens (`name/version`) of an SDK wrapping this one, such as
47185
+ * `@moonbase.sh/vue/3.6.1`, sent ahead of this package's own token in the
47186
+ * `x-mb-client` header.
47187
+ *
47188
+ * @internal
47189
+ */
47190
+ sdk?: string;
47167
47191
  }
47168
47192
  declare class MoonbaseClient {
47169
47193
  private readonly configuration;
@@ -47182,4 +47206,4 @@ declare class MoonbaseClient {
47182
47206
  orders: OrderEndpoints;
47183
47207
  }
47184
47208
 
47185
- export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CartCatalog, type CartOrder, type CartTotal, type CartTotalCondition, CartUtils, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, type ImageFit, type ImageFormat, type ImageTransform, ImageUtils, InMemoryStore, type License, LicenseStatus, type LineItem, type LineItemTotal, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, type OfferConditionContext, type OfferProgress, type OfferScope, OfferUtils, type OpenOrder, type Order, OrderStatus, type OrderTotal, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type PromotionDisplay, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpOptions, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontOfferTarget, type StorefrontProduct, type StorefrontPromotion, type StorefrontPromotionCta, type StorefrontPromotionTarget, type SubscribeInput, type SubscribeResponse, type Subscription, type SubscriptionCancellationFeedback, SubscriptionCancellationReason, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, imageWidths, isLocalStorageAvailable, isPromotionDisplay, isTransformableImageUrl, maxImageDimension, normalizeGroupIds, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, promotionDisplays, resolveUtm, schemas, utmToObject };
47209
+ export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CartCatalog, type CartOrder, type CartTotal, type CartTotalCondition, CartUtils, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, type ImageFit, type ImageFormat, type ImageTransform, ImageUtils, InMemoryStore, type License, LicenseStatus, type LineItem, type LineItemTotal, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, type OfferConditionContext, type OfferProgress, type OfferScope, OfferUtils, type OpenOrder, type Order, OrderStatus, type OrderTotal, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type PromotionDisplay, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpOptions, type SignUpResult, type SingleOrMultiple, StoreClosedError, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontOfferTarget, type StorefrontProduct, type StorefrontPromotion, type StorefrontPromotionCta, type StorefrontPromotionTarget, type SubscribeInput, type SubscribeResponse, type Subscription, type SubscriptionCancellationFeedback, SubscriptionCancellationReason, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, imageWidths, isLocalStorageAvailable, isPromotionDisplay, isTransformableImageUrl, maxImageDimension, normalizeGroupIds, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, promotionDisplays, resolveUtm, schemas, utmToObject };
package/dist/index.js CHANGED
@@ -573,6 +573,13 @@ var NotFoundError = class extends Error {
573
573
  this.message = message != null ? message : "Not found";
574
574
  }
575
575
  };
576
+ var StoreClosedError = class extends Error {
577
+ constructor(message) {
578
+ super();
579
+ this.name = "StoreClosedError";
580
+ this.message = message != null ? message : "This store has closed";
581
+ }
582
+ };
576
583
  var MoonbaseError = class extends Error {
577
584
  constructor(title, detail, status, errors) {
578
585
  super();
@@ -597,7 +604,8 @@ var problemDetailsSchema = z7.object({
597
604
  detail: z7.string().optional(),
598
605
  status: z7.number().optional(),
599
606
  instance: z7.string().optional(),
600
- errors: z7.record(z7.string(), z7.string().array()).optional()
607
+ errors: z7.record(z7.string(), z7.string().array()).optional(),
608
+ errorType: z7.string().optional()
601
609
  });
602
610
 
603
611
  // src/utils/problemHandler.ts
@@ -627,6 +635,8 @@ async function handleResponseProblem(response, logger) {
627
635
  throw new Error("An unknown problem occurred");
628
636
  }
629
637
  logger.debug("The response indicates a problem", problemDetails);
638
+ if (problemDetails.errorType === "StoreClosed")
639
+ throw new StoreClosedError(problemDetails.detail);
630
640
  throw new MoonbaseError(
631
641
  problemDetails.title,
632
642
  problemDetails.detail,
@@ -736,7 +746,8 @@ var IdentityEndpoints = class {
736
746
  headers: {
737
747
  "Accept": "application/json",
738
748
  "Content-Type": "text/plain",
739
- "x-mb-cors": "1"
749
+ "x-mb-cors": "1",
750
+ "x-mb-client": this.api.clientHeader
740
751
  },
741
752
  body: password
742
753
  });
@@ -761,7 +772,8 @@ var IdentityEndpoints = class {
761
772
  headers: {
762
773
  "Accept": "application/json",
763
774
  "Content-Type": "application/json",
764
- "x-mb-cors": "1"
775
+ "x-mb-cors": "1",
776
+ "x-mb-client": this.api.clientHeader
765
777
  },
766
778
  body: JSON.stringify({
767
779
  name,
@@ -827,7 +839,8 @@ var IdentityEndpoints = class {
827
839
  headers: {
828
840
  "Accept": "application/json",
829
841
  "Content-Type": "text/plain",
830
- "x-mb-cors": "1"
842
+ "x-mb-cors": "1",
843
+ "x-mb-client": this.api.clientHeader
831
844
  },
832
845
  body: newPassword
833
846
  });
@@ -993,8 +1006,8 @@ var ProductEndpoints = class {
993
1006
  this.api = api;
994
1007
  this.configuration = configuration;
995
1008
  }
996
- async get(productId, version) {
997
- const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version ? `?version=${version}${this.configuration.includeManifests ? "&includeManifests=true" : ""}` : this.configuration.includeManifests ? "?includeManifests=true" : ""}`, productSummarySchema);
1009
+ async get(productId, version2) {
1010
+ const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version2 ? `?version=${version2}${this.configuration.includeManifests ? "&includeManifests=true" : ""}` : this.configuration.includeManifests ? "?includeManifests=true" : ""}`, productSummarySchema);
998
1011
  return response.data;
999
1012
  }
1000
1013
  async getOwned(nextUrl) {
@@ -1022,15 +1035,24 @@ var ProductEndpoints = class {
1022
1035
  // src/inventory/subscriptions/endpoints.ts
1023
1036
  import { z as z14 } from "zod";
1024
1037
 
1038
+ // package.json
1039
+ var version = "3.5.1";
1040
+
1041
+ // src/utils/client.ts
1042
+ function buildClientHeader(sdk) {
1043
+ return `${sdk != null ? sdk : ""} @moonbase.sh/storefront-api/${version}`.trim().replace(/\s+/g, " ");
1044
+ }
1045
+
1025
1046
  // src/utils/api.ts
1026
1047
  function objectToQuery(obj) {
1027
1048
  return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
1028
1049
  }
1029
1050
  var MoonbaseApi = class {
1030
- constructor(baseUrl, tokenStore, logger) {
1051
+ constructor(baseUrl, tokenStore, logger, sdk) {
1031
1052
  this.baseUrl = baseUrl;
1032
1053
  this.tokenStore = tokenStore;
1033
1054
  this.logger = logger;
1055
+ this.clientHeader = buildClientHeader(sdk);
1034
1056
  }
1035
1057
  async authenticatedFetch(path, schema, options) {
1036
1058
  if (!this.tokenStore.user)
@@ -1055,7 +1077,8 @@ var MoonbaseApi = class {
1055
1077
  // While this fetch can be anonymous, we add the token if we have it
1056
1078
  ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
1057
1079
  // Force CORS on all calls
1058
- "x-mb-cors": "1"
1080
+ "x-mb-cors": "1",
1081
+ "x-mb-client": this.clientHeader
1059
1082
  },
1060
1083
  body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
1061
1084
  signal: options == null ? void 0 : options.abort,
@@ -1081,7 +1104,8 @@ var MoonbaseApi = class {
1081
1104
  try {
1082
1105
  await handleResponseProblem(response, this.logger);
1083
1106
  } catch (err) {
1084
- this.reportRequestProblem(path, request, response, err);
1107
+ if (!(err instanceof StoreClosedError))
1108
+ this.reportRequestProblem(path, request, response, err);
1085
1109
  throw err;
1086
1110
  }
1087
1111
  }
@@ -1113,7 +1137,8 @@ var MoonbaseApi = class {
1113
1137
  method: "POST",
1114
1138
  headers: {
1115
1139
  "Accept": "application/json",
1116
- "Content-Type": "application/json"
1140
+ "Content-Type": "application/json",
1141
+ "x-mb-client": this.clientHeader
1117
1142
  },
1118
1143
  body: JSON.stringify({
1119
1144
  title: "Parse error",
@@ -1135,7 +1160,8 @@ var MoonbaseApi = class {
1135
1160
  method: "POST",
1136
1161
  headers: {
1137
1162
  "Accept": "application/json",
1138
- "Content-Type": "application/json"
1163
+ "Content-Type": "application/json",
1164
+ "x-mb-client": this.clientHeader
1139
1165
  },
1140
1166
  body: JSON.stringify({
1141
1167
  title: "Request error",
@@ -1787,7 +1813,8 @@ var _TokenStore = class _TokenStore {
1787
1813
  headers: {
1788
1814
  "Accept": "application/json",
1789
1815
  "Content-Type": "text/plain",
1790
- "x-mb-cors": "1"
1816
+ "x-mb-cors": "1",
1817
+ "x-mb-client": buildClientHeader(this.configuration.sdk)
1791
1818
  },
1792
1819
  body: this.tokens.accessToken
1793
1820
  });
@@ -2506,7 +2533,7 @@ var MoonbaseClient = class {
2506
2533
  this.configuration.endpoint = this.configuration.endpoint.replace(/\/$/, "");
2507
2534
  this.logger = (_a = this.configuration.logger) != null ? _a : new ConsoleLogger();
2508
2535
  this.tokenStore = new TokenStore(configuration);
2509
- this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger);
2536
+ this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger, this.configuration.sdk);
2510
2537
  this.storefront = new StorefrontEndpoints(this.api, this.configuration);
2511
2538
  this.identity = new IdentityEndpoints(this.api, this.tokenStore, this.logger);
2512
2539
  this.communications = new CommunicationsEndpoints(this.api);
@@ -2545,6 +2572,7 @@ export {
2545
2572
  OfferUtils,
2546
2573
  OrderStatus,
2547
2574
  Platform,
2575
+ StoreClosedError,
2548
2576
  SubscriptionCancellationReason,
2549
2577
  SubscriptionStatus,
2550
2578
  TokenStore,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "3.4.0",
4
+ "version": "3.5.1",
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",