@moonbase.sh/storefront-api 3.3.1 → 3.5.0

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,8 @@ __export(index_exports, {
46
46
  OfferUtils: () => OfferUtils,
47
47
  OrderStatus: () => OrderStatus,
48
48
  Platform: () => Platform,
49
+ StoreClosedError: () => StoreClosedError,
50
+ SubscriptionCancellationReason: () => SubscriptionCancellationReason,
49
51
  SubscriptionStatus: () => SubscriptionStatus,
50
52
  TokenStore: () => TokenStore,
51
53
  imageWidths: () => imageWidths,
@@ -633,6 +635,13 @@ var NotFoundError = class extends Error {
633
635
  this.message = message != null ? message : "Not found";
634
636
  }
635
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
+ };
636
645
  var MoonbaseError = class extends Error {
637
646
  constructor(title, detail, status, errors) {
638
647
  super();
@@ -657,7 +666,8 @@ var problemDetailsSchema = import_zod7.z.object({
657
666
  detail: import_zod7.z.string().optional(),
658
667
  status: import_zod7.z.number().optional(),
659
668
  instance: import_zod7.z.string().optional(),
660
- 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()
661
671
  });
662
672
 
663
673
  // src/utils/problemHandler.ts
@@ -687,6 +697,8 @@ async function handleResponseProblem(response, logger) {
687
697
  throw new Error("An unknown problem occurred");
688
698
  }
689
699
  logger.debug("The response indicates a problem", problemDetails);
700
+ if (problemDetails.errorType === "StoreClosed")
701
+ throw new StoreClosedError(problemDetails.detail);
690
702
  throw new MoonbaseError(
691
703
  problemDetails.title,
692
704
  problemDetails.detail,
@@ -1141,7 +1153,8 @@ var MoonbaseApi = class {
1141
1153
  try {
1142
1154
  await handleResponseProblem(response, this.logger);
1143
1155
  } catch (err) {
1144
- this.reportRequestProblem(path, request, response, err);
1156
+ if (!(err instanceof StoreClosedError))
1157
+ this.reportRequestProblem(path, request, response, err);
1145
1158
  throw err;
1146
1159
  }
1147
1160
  }
@@ -1382,6 +1395,15 @@ var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
1382
1395
  SubscriptionStatus2["Completed"] = "Completed";
1383
1396
  return SubscriptionStatus2;
1384
1397
  })(SubscriptionStatus || {});
1398
+ var SubscriptionCancellationReason = /* @__PURE__ */ ((SubscriptionCancellationReason2) => {
1399
+ SubscriptionCancellationReason2["TooExpensive"] = "TooExpensive";
1400
+ SubscriptionCancellationReason2["Unused"] = "Unused";
1401
+ SubscriptionCancellationReason2["MissingFeatures"] = "MissingFeatures";
1402
+ SubscriptionCancellationReason2["TechnicalIssues"] = "TechnicalIssues";
1403
+ SubscriptionCancellationReason2["SwitchedService"] = "SwitchedService";
1404
+ SubscriptionCancellationReason2["Other"] = "Other";
1405
+ return SubscriptionCancellationReason2;
1406
+ })(SubscriptionCancellationReason || {});
1385
1407
 
1386
1408
  // src/inventory/subscriptions/schemas.ts
1387
1409
  var baseMilestoneProgressEventSchema = import_zod13.z.object({
@@ -1455,8 +1477,19 @@ var SubscriptionEndpoints = class {
1455
1477
  const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}?${objectToQuery(options)}`, subscriptionSchema);
1456
1478
  return response.data;
1457
1479
  }
1458
- async cancel(subscriptionId) {
1459
- const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/cancel`, subscriptionSchema, { method: "POST" });
1480
+ /**
1481
+ * Turns off auto-renew. The customer keeps access until the subscription's current
1482
+ * period ends. Pass `feedback` to record why they are cancelling.
1483
+ */
1484
+ async cancel(subscriptionId, feedback) {
1485
+ var _a, _b;
1486
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/cancel`, subscriptionSchema, {
1487
+ method: "POST",
1488
+ body: {
1489
+ reason: (_a = feedback == null ? void 0 : feedback.reason) != null ? _a : void 0,
1490
+ comment: ((_b = feedback == null ? void 0 : feedback.comment) == null ? void 0 : _b.trim()) || void 0
1491
+ }
1492
+ });
1460
1493
  return response.data;
1461
1494
  }
1462
1495
  async renew(subscriptionId, returnUrl, embedded) {
@@ -2586,6 +2619,8 @@ var MoonbaseClient = class {
2586
2619
  OfferUtils,
2587
2620
  OrderStatus,
2588
2621
  Platform,
2622
+ StoreClosedError,
2623
+ SubscriptionCancellationReason,
2589
2624
  SubscriptionStatus,
2590
2625
  TokenStore,
2591
2626
  imageWidths,
package/dist/index.d.cts CHANGED
@@ -6539,6 +6539,27 @@ declare enum SubscriptionStatus {
6539
6539
  Cancelled = "Cancelled",
6540
6540
  Completed = "Completed"
6541
6541
  }
6542
+ /**
6543
+ * Why a customer is cancelling a subscription, as they would pick it from a list. The
6544
+ * merchant has two further reasons of its own that a customer cannot give.
6545
+ */
6546
+ declare enum SubscriptionCancellationReason {
6547
+ TooExpensive = "TooExpensive",
6548
+ Unused = "Unused",
6549
+ MissingFeatures = "MissingFeatures",
6550
+ TechnicalIssues = "TechnicalIssues",
6551
+ SwitchedService = "SwitchedService",
6552
+ Other = "Other"
6553
+ }
6554
+ /**
6555
+ * What a customer said about why they are cancelling. Both parts are optional, and
6556
+ * the merchant sees them alongside the cancellation.
6557
+ */
6558
+ interface SubscriptionCancellationFeedback {
6559
+ reason?: SubscriptionCancellationReason | null;
6560
+ /** Free text, at most 1000 characters. */
6561
+ comment?: string | null;
6562
+ }
6542
6563
  type Subscription = z.infer<typeof subscriptionSchema>;
6543
6564
  type MilestoneProgress = z.infer<typeof milestoneProgressSchema>;
6544
6565
 
@@ -6551,7 +6572,11 @@ declare class SubscriptionEndpoints {
6551
6572
  toUpdatePaymentMethod?: boolean;
6552
6573
  returnUrl?: string;
6553
6574
  }): Promise<Subscription>;
6554
- cancel(subscriptionId: string): Promise<Subscription>;
6575
+ /**
6576
+ * Turns off auto-renew. The customer keeps access until the subscription's current
6577
+ * period ends. Pass `feedback` to record why they are cancelling.
6578
+ */
6579
+ cancel(subscriptionId: string, feedback?: SubscriptionCancellationFeedback): Promise<Subscription>;
6555
6580
  renew(subscriptionId: string, returnUrl: string, embedded: boolean): Promise<{
6556
6581
  location: string;
6557
6582
  }>;
@@ -46981,6 +47006,13 @@ declare class NotAuthenticatedError extends Error {
46981
47006
  declare class NotFoundError extends Error {
46982
47007
  constructor(message?: string);
46983
47008
  }
47009
+ /**
47010
+ * The store has closed its Moonbase account, so it answers nothing: no catalog, no cart, no
47011
+ * checkout and no sign-in. Not transient, so there is nothing to retry.
47012
+ */
47013
+ declare class StoreClosedError extends Error {
47014
+ constructor(message?: string);
47015
+ }
46984
47016
  declare class MoonbaseError extends Error {
46985
47017
  readonly title: string;
46986
47018
  readonly detail: string | undefined;
@@ -47090,6 +47122,7 @@ declare const problemDetailsSchema: z.ZodObject<{
47090
47122
  status: z.ZodOptional<z.ZodNumber>;
47091
47123
  instance: z.ZodOptional<z.ZodString>;
47092
47124
  errors: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
47125
+ errorType: z.ZodOptional<z.ZodString>;
47093
47126
  }, "strip", z.ZodTypeAny, {
47094
47127
  title: string;
47095
47128
  type?: string | undefined;
@@ -47097,6 +47130,7 @@ declare const problemDetailsSchema: z.ZodObject<{
47097
47130
  detail?: string | undefined;
47098
47131
  instance?: string | undefined;
47099
47132
  errors?: Record<string, string[]> | undefined;
47133
+ errorType?: string | undefined;
47100
47134
  }, {
47101
47135
  title: string;
47102
47136
  type?: string | undefined;
@@ -47104,6 +47138,7 @@ declare const problemDetailsSchema: z.ZodObject<{
47104
47138
  detail?: string | undefined;
47105
47139
  instance?: string | undefined;
47106
47140
  errors?: Record<string, string[]> | undefined;
47141
+ errorType?: string | undefined;
47107
47142
  }>;
47108
47143
  type ProblemDetails = z.infer<typeof problemDetailsSchema>;
47109
47144
 
@@ -47157,4 +47192,4 @@ declare class MoonbaseClient {
47157
47192
  orders: OrderEndpoints;
47158
47193
  }
47159
47194
 
47160
- 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, 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 };
47195
+ 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
@@ -6539,6 +6539,27 @@ declare enum SubscriptionStatus {
6539
6539
  Cancelled = "Cancelled",
6540
6540
  Completed = "Completed"
6541
6541
  }
6542
+ /**
6543
+ * Why a customer is cancelling a subscription, as they would pick it from a list. The
6544
+ * merchant has two further reasons of its own that a customer cannot give.
6545
+ */
6546
+ declare enum SubscriptionCancellationReason {
6547
+ TooExpensive = "TooExpensive",
6548
+ Unused = "Unused",
6549
+ MissingFeatures = "MissingFeatures",
6550
+ TechnicalIssues = "TechnicalIssues",
6551
+ SwitchedService = "SwitchedService",
6552
+ Other = "Other"
6553
+ }
6554
+ /**
6555
+ * What a customer said about why they are cancelling. Both parts are optional, and
6556
+ * the merchant sees them alongside the cancellation.
6557
+ */
6558
+ interface SubscriptionCancellationFeedback {
6559
+ reason?: SubscriptionCancellationReason | null;
6560
+ /** Free text, at most 1000 characters. */
6561
+ comment?: string | null;
6562
+ }
6542
6563
  type Subscription = z.infer<typeof subscriptionSchema>;
6543
6564
  type MilestoneProgress = z.infer<typeof milestoneProgressSchema>;
6544
6565
 
@@ -6551,7 +6572,11 @@ declare class SubscriptionEndpoints {
6551
6572
  toUpdatePaymentMethod?: boolean;
6552
6573
  returnUrl?: string;
6553
6574
  }): Promise<Subscription>;
6554
- cancel(subscriptionId: string): Promise<Subscription>;
6575
+ /**
6576
+ * Turns off auto-renew. The customer keeps access until the subscription's current
6577
+ * period ends. Pass `feedback` to record why they are cancelling.
6578
+ */
6579
+ cancel(subscriptionId: string, feedback?: SubscriptionCancellationFeedback): Promise<Subscription>;
6555
6580
  renew(subscriptionId: string, returnUrl: string, embedded: boolean): Promise<{
6556
6581
  location: string;
6557
6582
  }>;
@@ -46981,6 +47006,13 @@ declare class NotAuthenticatedError extends Error {
46981
47006
  declare class NotFoundError extends Error {
46982
47007
  constructor(message?: string);
46983
47008
  }
47009
+ /**
47010
+ * The store has closed its Moonbase account, so it answers nothing: no catalog, no cart, no
47011
+ * checkout and no sign-in. Not transient, so there is nothing to retry.
47012
+ */
47013
+ declare class StoreClosedError extends Error {
47014
+ constructor(message?: string);
47015
+ }
46984
47016
  declare class MoonbaseError extends Error {
46985
47017
  readonly title: string;
46986
47018
  readonly detail: string | undefined;
@@ -47090,6 +47122,7 @@ declare const problemDetailsSchema: z.ZodObject<{
47090
47122
  status: z.ZodOptional<z.ZodNumber>;
47091
47123
  instance: z.ZodOptional<z.ZodString>;
47092
47124
  errors: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
47125
+ errorType: z.ZodOptional<z.ZodString>;
47093
47126
  }, "strip", z.ZodTypeAny, {
47094
47127
  title: string;
47095
47128
  type?: string | undefined;
@@ -47097,6 +47130,7 @@ declare const problemDetailsSchema: z.ZodObject<{
47097
47130
  detail?: string | undefined;
47098
47131
  instance?: string | undefined;
47099
47132
  errors?: Record<string, string[]> | undefined;
47133
+ errorType?: string | undefined;
47100
47134
  }, {
47101
47135
  title: string;
47102
47136
  type?: string | undefined;
@@ -47104,6 +47138,7 @@ declare const problemDetailsSchema: z.ZodObject<{
47104
47138
  detail?: string | undefined;
47105
47139
  instance?: string | undefined;
47106
47140
  errors?: Record<string, string[]> | undefined;
47141
+ errorType?: string | undefined;
47107
47142
  }>;
47108
47143
  type ProblemDetails = z.infer<typeof problemDetailsSchema>;
47109
47144
 
@@ -47157,4 +47192,4 @@ declare class MoonbaseClient {
47157
47192
  orders: OrderEndpoints;
47158
47193
  }
47159
47194
 
47160
- 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, 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 };
47195
+ 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,
@@ -1081,7 +1091,8 @@ var MoonbaseApi = class {
1081
1091
  try {
1082
1092
  await handleResponseProblem(response, this.logger);
1083
1093
  } catch (err) {
1084
- this.reportRequestProblem(path, request, response, err);
1094
+ if (!(err instanceof StoreClosedError))
1095
+ this.reportRequestProblem(path, request, response, err);
1085
1096
  throw err;
1086
1097
  }
1087
1098
  }
@@ -1322,6 +1333,15 @@ var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
1322
1333
  SubscriptionStatus2["Completed"] = "Completed";
1323
1334
  return SubscriptionStatus2;
1324
1335
  })(SubscriptionStatus || {});
1336
+ var SubscriptionCancellationReason = /* @__PURE__ */ ((SubscriptionCancellationReason2) => {
1337
+ SubscriptionCancellationReason2["TooExpensive"] = "TooExpensive";
1338
+ SubscriptionCancellationReason2["Unused"] = "Unused";
1339
+ SubscriptionCancellationReason2["MissingFeatures"] = "MissingFeatures";
1340
+ SubscriptionCancellationReason2["TechnicalIssues"] = "TechnicalIssues";
1341
+ SubscriptionCancellationReason2["SwitchedService"] = "SwitchedService";
1342
+ SubscriptionCancellationReason2["Other"] = "Other";
1343
+ return SubscriptionCancellationReason2;
1344
+ })(SubscriptionCancellationReason || {});
1325
1345
 
1326
1346
  // src/inventory/subscriptions/schemas.ts
1327
1347
  var baseMilestoneProgressEventSchema = z13.object({
@@ -1395,8 +1415,19 @@ var SubscriptionEndpoints = class {
1395
1415
  const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}?${objectToQuery(options)}`, subscriptionSchema);
1396
1416
  return response.data;
1397
1417
  }
1398
- async cancel(subscriptionId) {
1399
- const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/cancel`, subscriptionSchema, { method: "POST" });
1418
+ /**
1419
+ * Turns off auto-renew. The customer keeps access until the subscription's current
1420
+ * period ends. Pass `feedback` to record why they are cancelling.
1421
+ */
1422
+ async cancel(subscriptionId, feedback) {
1423
+ var _a, _b;
1424
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/cancel`, subscriptionSchema, {
1425
+ method: "POST",
1426
+ body: {
1427
+ reason: (_a = feedback == null ? void 0 : feedback.reason) != null ? _a : void 0,
1428
+ comment: ((_b = feedback == null ? void 0 : feedback.comment) == null ? void 0 : _b.trim()) || void 0
1429
+ }
1430
+ });
1400
1431
  return response.data;
1401
1432
  }
1402
1433
  async renew(subscriptionId, returnUrl, embedded) {
@@ -2525,6 +2556,8 @@ export {
2525
2556
  OfferUtils,
2526
2557
  OrderStatus,
2527
2558
  Platform,
2559
+ StoreClosedError,
2560
+ SubscriptionCancellationReason,
2528
2561
  SubscriptionStatus,
2529
2562
  TokenStore,
2530
2563
  imageWidths,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "3.3.1",
4
+ "version": "3.5.0",
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",
@@ -27,6 +27,8 @@
27
27
  "dev": "tsup src/index.ts --format esm,cjs --watch --dts",
28
28
  "version": "npm version",
29
29
  "type-check": "tsc --noEmit -p tsconfig.typecheck.json",
30
+ "lint": "eslint . --cache --cache-location node_modules/.cache/eslint/ --cache-strategy content",
31
+ "lint:fix": "eslint . --cache --cache-location node_modules/.cache/eslint/ --cache-strategy content --fix",
30
32
  "test": "vitest run",
31
33
  "test:watch": "vitest",
32
34
  "test:integration": "TEST_INTEGRATION=true vitest run"