@shoppexio/storefront-react 0.6.1 → 0.6.3

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.d.ts CHANGED
@@ -1583,6 +1583,12 @@ interface StorefrontPriceVariant {
1583
1583
  * with the product's (`subscriptionForVariant`).
1584
1584
  */
1585
1585
  ownTrial: SubscriptionTrial | 'none' | null;
1586
+ /**
1587
+ * A buyer of this option can switch its plan in their account (the option's
1588
+ * `plan_change_offered`): under "Upgrades only" the top plan has nothing to
1589
+ * switch to. False when the wire does not say so.
1590
+ */
1591
+ planChangeOffered: boolean;
1586
1592
  }
1587
1593
  interface VolumeDiscountRule {
1588
1594
  quantity: number;
@@ -1783,6 +1789,12 @@ interface ProductSubscription {
1783
1789
  intervalCount: number;
1784
1790
  /** The trial the plan starts with; null when it has none. */
1785
1791
  trial: SubscriptionTrial | null;
1792
+ /**
1793
+ * The buyer can switch plans in their account (`plan_change_offered`): the shop allows buyer
1794
+ * plan changes and the product has a second plan the change offers. False when the wire
1795
+ * does not say so.
1796
+ */
1797
+ planChangeOffered: boolean;
1786
1798
  }
1787
1799
  /**
1788
1800
  * A free trial, or a paid intro: `price` in `currency` (the product currency,
@@ -1800,6 +1812,12 @@ type SubscriptionTrial = {
1800
1812
  };
1801
1813
  /** The cadence as it reads next to a price: "per month", "every 3 months". */
1802
1814
  declare function formatSubscriptionCadence(subscription: ProductSubscription): string;
1815
+ /**
1816
+ * The line under a subscription's buy buttons: "Renews every month until you cancel." and, when the
1817
+ * producer says the buyer can switch plans, "Switch plans any time in your account." Empty for a plan
1818
+ * without an interval. Same wording as the Easy-lane buy boxes.
1819
+ */
1820
+ declare function formatSubscriptionRenewal(subscription: ProductSubscription): string;
1803
1821
  /**
1804
1822
  * "7-day free trial" for a free trial, "$4.99 for 7 days" for a paid intro
1805
1823
  * (`formatAmount` prints its price); empty when the plan has no trial.
@@ -1810,9 +1828,11 @@ declare function formatSubscriptionTrial(subscription: ProductSubscription, form
1810
1828
  * interval (`billing_interval`, stored with its count or not at all) is charged
1811
1829
  * at that cadence, every other one at the product's. An option with its own
1812
1830
  * trial ("No trial" included) starts with it, every other one with the
1813
- * product's: the rule checkout's `resolveProductTrial` applies.
1831
+ * product's: the rule checkout's `resolveProductTrial` applies. Whether the
1832
+ * buyer can switch plans is the option's own answer (`plan_change_offered`),
1833
+ * the rule the Easy-lane buy box applies.
1814
1834
  */
1815
- declare function subscriptionForVariant(subscription: ProductSubscription, variant: Pick<StorefrontPriceVariant, 'billingInterval' | 'ownTrial'> | null | undefined): ProductSubscription;
1835
+ declare function subscriptionForVariant(subscription: ProductSubscription, variant: Pick<StorefrontPriceVariant, 'billingInterval' | 'ownTrial' | 'planChangeOffered'> | null | undefined): ProductSubscription;
1816
1836
  /**
1817
1837
  * What a product image shows, from the backend's pixel analysis. `art` is a
1818
1838
  * cover, artwork or photo; `logo` is a flat mark, drawn on a contrasting plate.
@@ -3734,4 +3754,4 @@ declare function useOnlineUserCount(): number | null;
3734
3754
  */
3735
3755
  declare function resolveProductVideoEmbedSrc(value: unknown): string | null;
3736
3756
 
3737
- export { ACCOUNT_ARTIFACT_CAPABILITIES, ACCOUNT_PATH, ACCOUNT_PATH_ALIAS, ACCOUNT_ROUTE_MESSAGE_KEYS, ACCOUNT_STOREFRONT_ROUTES, ACCOUNT_TABS, type AccountRouteMessageKey, type AccountRouteParts, type AccountTab, type AccountView, type BuyBoxVariantModel, CATALOG_PAGE_SIZE, CATALOG_SORTS, CATALOG_SORT_LABELS, type CartBoundsHeal, CartProvider, type CartQuoteLineBounds, type CartTotals, type CartView, type CartViewLine, type CatalogCardModel, type CatalogPage, type CatalogSort, type CheckoutFieldGroup, type CheckoutFieldValues, type CheckoutFields, type ContactFormValues, type ContactSubmissionContext, DEFAULT_ACCOUNT_TAB, DEFAULT_LOW_STOCK_THRESHOLD, DELIVERY_TIME_UNITS, type DeliveryPromise, type DeliveryTimeUnit, FAVORITES_CHANGED_EVENT, type FavoriteToggleResult, type FavoritesApi, FavoritesProvider, type FavoritesSnapshot, type FavoritesStatus, type FavoritesStore, type FavoritesTransport, type GroupCardModel, IMPLEMENTED_ACCOUNT_TABS, type ImplementedAccountTab, type LicenseStatement, type LicenseTerm, type LinePricing, MAX_PAY_WHAT_YOU_WANT_PRICE, type MenuNavLink, type MenuSlot, type NavLink, type NavigationLinks, PRODUCT_BADGE_ICON_NAMES, type PagedShopReviewsState, type ProductAddon, type ProductAutomaticDeal, type ProductBadge, type ProductBadgeIconName, type ProductBundle, type ProductBundleItem, type ProductCardModel, type ProductCategoryRef, type ProductContentTab, type ProductCustomField, type ProductDeliverable, type ProductDeliveryType, type ProductDetailModel, type ProductFaq, type ProductImage, type ProductImageKind, type ProductRatingModel, type ProductServiceStatus, type ProductSubscription, type ProductType, QUOTE_UNAVAILABLE_CHECKOUT_ERROR, type RatingStars, type ResellerProgramSummary, type RewardProgramItem, type RewardProgramSummary, SERVICE_STATES, SERVING_CONTEXT_HINT, SHOP_REVIEW_PAGE_SIZE, STOREFRONT_SORT_KEYS, type SdkCartAddOptions, type SdkCartAddon, type SdkCartAppliedDiscount, type SdkCartCodeSource, type SdkCartItem, type SdkCartQuote, type SdkCartQuoteLine, type SdkCheckoutResult, type SdkCustomerAffiliateLedgerStatus, type SdkCustomerAffiliateLink, type SdkCustomerAffiliateLinkCreated, type SdkCustomerAffiliateRates, type SdkCustomerAffiliateSummary, type SdkCustomerDashboard, type SdkCustomerDashboardOrder, type SdkCustomerDeliverable, type SdkCustomerDeliveryStatus, type SdkCustomerDeliverySummary, type SdkCustomerFileAccess, type SdkCustomerInvoicePdf, type SdkCustomerLicense, type SdkCustomerLoyalty, type SdkCustomerLoyaltyRedeem, type SdkCustomerLoyaltyTransactionType, type SdkCustomerNotificationPreferences, type SdkCustomerOpenRenewal, type SdkCustomerOrderDetail, type SdkCustomerOrderPage, type SdkCustomerOrderReview, type SdkCustomerOrderSummary, type SdkCustomerPause, type SdkCustomerPauseOptions, type SdkCustomerPauseReason, type SdkCustomerRewardActivity, type SdkCustomerRewards, type SdkCustomerSubscription, type SdkCustomerSubscriptionDiscount, type SdkCustomerTicketSummary, type SdkCustomerWarranty, type SdkCustomerWarrantyClaim, type SdkCustomerWarrantyClaimStatus, type SdkCustomerWarrantyList, type SdkCustomerWarrantyStatus, type SdkEligibleCartDeal, type SdkInitOptions, type SdkMenu, type SdkMenuItem, type SdkPage, type SdkRecentSaleEntry, type SdkResponse, type SdkShopReview, type SdkShopReviewsSummary, type ServiceState, type ShopPageFaqItem, type ShopPageModel, type ShopPageState, type ShopReview, type ShopReviewLabels, type ShopReviewsPageResult, type ShopReviewsState, type ShoppexSdk, type SocialLink, type SocialNetwork, type StatusPageEntry, type StatusPageModel, type StockAlertRequest, type StockAlertResult, type StockChip, type StockTone, type StorefrontAddon, type StorefrontCatalog, type StorefrontCategory, type StorefrontData, type StorefrontGroup, type StorefrontListingItem, type StorefrontPaymentMethod, type StorefrontPaymentMethodKind, type StorefrontPriceVariant, type StorefrontProduct, StorefrontProvider, type StorefrontSettings, type StorefrontShop, type StorefrontShopStats, type StorefrontSortKey, type SubscriptionIntervalUnit, type SubscriptionTrial, type SupportChannel, type VolumeDiscountRule, type YouReceive, accountOrderHref, accountRouteMessage, accountTabHref, accountTabLabelKey, addonChoiceMissing, averageRating, badgesForCard, badgesForProductPage, buildCartTotals, buildCartView, buildCustomFieldPayload, buildInitialCheckoutFieldValues, buildProductDetail, buildStatusPageModel, buildStorefrontCatalog, calculateDisplayLineTotal, calculateLinePricing, canRequestStockAlert, canonicalAccountPath, checkoutFieldKey, checkoutFieldWriteRepriced, checkoutNeedsDetails, clampQuantity, clearRecoveredQuoteCheckoutError, createFavoritesStore, filterCatalogCards, findStorefrontProduct, firstOptionalString, flattenMerchantHtmlToText, formatCompactCount, formatDeliveryTime, formatLicenseTerm, formatMoney, formatSubscriptionCadence, formatSubscriptionTrial, getAuthoredContent, getBuyerCurrency, getProductGroups, getProducts, getShoppex, getStorefrontAddons, getStorefrontCategories, getStorefrontListing, getStorefrontSettings, getStorefrontShop, hasInjectedStorefrontData, isAccountTab, isBlankMerchantHtml, isCardSoldOut, isCheckboxValueChecked, isImplementedAccountTab, isProductSoldOut, isRecord, isSelectionSoldOut, loadLatestWrittenReviews, loadShopPage, loadShopReviewsPage, missingRequiredCheckoutValues, notifyFavoritesChanged, optionalBoolean, optionalString, optionalStringWithDefault, paginateCatalogCards, parseAccountPath, parseCartQuoteLines, parseEnum, parseFiniteNumber, parseProductBadges, parseServiceStatus, parseStorefrontSortKey, readCheckoutNeedsDetails, readStorefrontData, requestStockAlert, requireArray, requireBoolean, requireNumber, requireRecord, requireString, requireStringFromKeys, requireUnknownRecord, resolveAccountView, resolveBadgeForeground, resolveCartBoundsHeals, resolveCategorySelection, resolveCheckoutFields, resolveDeliveryPromise, resolveDisplayStock, resolveHideStockCounter, resolveLicenseTerm, resolveMenuLinksForSlot, resolvePayWhatYouWantMinimum, resolveProductVideoEmbedSrc, resolveQuantityBounds, resolveSupportChannels, resolveUnsellableLineIds, resolveVariantStock, resolveYouReceive, reviewsForProduct, roundCurrency, sanitizeMerchantHtml, sdkFavoritesTransport, sortCatalogCards, startCartMutation, stripMerchantHtmlImages, submitContactTicket, subscriptionForVariant, toShopReviews, toStarCount, useCart, useFavorites, useNavigationLinks, useOnlineUserCount, usePagedShopReviews, useShopReviews, useStorefront, validateCheckoutFieldValue, validateCheckoutFields, validateContactSubmission, withRequiredAddons };
3757
+ export { ACCOUNT_ARTIFACT_CAPABILITIES, ACCOUNT_PATH, ACCOUNT_PATH_ALIAS, ACCOUNT_ROUTE_MESSAGE_KEYS, ACCOUNT_STOREFRONT_ROUTES, ACCOUNT_TABS, type AccountRouteMessageKey, type AccountRouteParts, type AccountTab, type AccountView, type BuyBoxVariantModel, CATALOG_PAGE_SIZE, CATALOG_SORTS, CATALOG_SORT_LABELS, type CartBoundsHeal, CartProvider, type CartQuoteLineBounds, type CartTotals, type CartView, type CartViewLine, type CatalogCardModel, type CatalogPage, type CatalogSort, type CheckoutFieldGroup, type CheckoutFieldValues, type CheckoutFields, type ContactFormValues, type ContactSubmissionContext, DEFAULT_ACCOUNT_TAB, DEFAULT_LOW_STOCK_THRESHOLD, DELIVERY_TIME_UNITS, type DeliveryPromise, type DeliveryTimeUnit, FAVORITES_CHANGED_EVENT, type FavoriteToggleResult, type FavoritesApi, FavoritesProvider, type FavoritesSnapshot, type FavoritesStatus, type FavoritesStore, type FavoritesTransport, type GroupCardModel, IMPLEMENTED_ACCOUNT_TABS, type ImplementedAccountTab, type LicenseStatement, type LicenseTerm, type LinePricing, MAX_PAY_WHAT_YOU_WANT_PRICE, type MenuNavLink, type MenuSlot, type NavLink, type NavigationLinks, PRODUCT_BADGE_ICON_NAMES, type PagedShopReviewsState, type ProductAddon, type ProductAutomaticDeal, type ProductBadge, type ProductBadgeIconName, type ProductBundle, type ProductBundleItem, type ProductCardModel, type ProductCategoryRef, type ProductContentTab, type ProductCustomField, type ProductDeliverable, type ProductDeliveryType, type ProductDetailModel, type ProductFaq, type ProductImage, type ProductImageKind, type ProductRatingModel, type ProductServiceStatus, type ProductSubscription, type ProductType, QUOTE_UNAVAILABLE_CHECKOUT_ERROR, type RatingStars, type ResellerProgramSummary, type RewardProgramItem, type RewardProgramSummary, SERVICE_STATES, SERVING_CONTEXT_HINT, SHOP_REVIEW_PAGE_SIZE, STOREFRONT_SORT_KEYS, type SdkCartAddOptions, type SdkCartAddon, type SdkCartAppliedDiscount, type SdkCartCodeSource, type SdkCartItem, type SdkCartQuote, type SdkCartQuoteLine, type SdkCheckoutResult, type SdkCustomerAffiliateLedgerStatus, type SdkCustomerAffiliateLink, type SdkCustomerAffiliateLinkCreated, type SdkCustomerAffiliateRates, type SdkCustomerAffiliateSummary, type SdkCustomerDashboard, type SdkCustomerDashboardOrder, type SdkCustomerDeliverable, type SdkCustomerDeliveryStatus, type SdkCustomerDeliverySummary, type SdkCustomerFileAccess, type SdkCustomerInvoicePdf, type SdkCustomerLicense, type SdkCustomerLoyalty, type SdkCustomerLoyaltyRedeem, type SdkCustomerLoyaltyTransactionType, type SdkCustomerNotificationPreferences, type SdkCustomerOpenRenewal, type SdkCustomerOrderDetail, type SdkCustomerOrderPage, type SdkCustomerOrderReview, type SdkCustomerOrderSummary, type SdkCustomerPause, type SdkCustomerPauseOptions, type SdkCustomerPauseReason, type SdkCustomerRewardActivity, type SdkCustomerRewards, type SdkCustomerSubscription, type SdkCustomerSubscriptionDiscount, type SdkCustomerTicketSummary, type SdkCustomerWarranty, type SdkCustomerWarrantyClaim, type SdkCustomerWarrantyClaimStatus, type SdkCustomerWarrantyList, type SdkCustomerWarrantyStatus, type SdkEligibleCartDeal, type SdkInitOptions, type SdkMenu, type SdkMenuItem, type SdkPage, type SdkRecentSaleEntry, type SdkResponse, type SdkShopReview, type SdkShopReviewsSummary, type ServiceState, type ShopPageFaqItem, type ShopPageModel, type ShopPageState, type ShopReview, type ShopReviewLabels, type ShopReviewsPageResult, type ShopReviewsState, type ShoppexSdk, type SocialLink, type SocialNetwork, type StatusPageEntry, type StatusPageModel, type StockAlertRequest, type StockAlertResult, type StockChip, type StockTone, type StorefrontAddon, type StorefrontCatalog, type StorefrontCategory, type StorefrontData, type StorefrontGroup, type StorefrontListingItem, type StorefrontPaymentMethod, type StorefrontPaymentMethodKind, type StorefrontPriceVariant, type StorefrontProduct, StorefrontProvider, type StorefrontSettings, type StorefrontShop, type StorefrontShopStats, type StorefrontSortKey, type SubscriptionIntervalUnit, type SubscriptionTrial, type SupportChannel, type VolumeDiscountRule, type YouReceive, accountOrderHref, accountRouteMessage, accountTabHref, accountTabLabelKey, addonChoiceMissing, averageRating, badgesForCard, badgesForProductPage, buildCartTotals, buildCartView, buildCustomFieldPayload, buildInitialCheckoutFieldValues, buildProductDetail, buildStatusPageModel, buildStorefrontCatalog, calculateDisplayLineTotal, calculateLinePricing, canRequestStockAlert, canonicalAccountPath, checkoutFieldKey, checkoutFieldWriteRepriced, checkoutNeedsDetails, clampQuantity, clearRecoveredQuoteCheckoutError, createFavoritesStore, filterCatalogCards, findStorefrontProduct, firstOptionalString, flattenMerchantHtmlToText, formatCompactCount, formatDeliveryTime, formatLicenseTerm, formatMoney, formatSubscriptionCadence, formatSubscriptionRenewal, formatSubscriptionTrial, getAuthoredContent, getBuyerCurrency, getProductGroups, getProducts, getShoppex, getStorefrontAddons, getStorefrontCategories, getStorefrontListing, getStorefrontSettings, getStorefrontShop, hasInjectedStorefrontData, isAccountTab, isBlankMerchantHtml, isCardSoldOut, isCheckboxValueChecked, isImplementedAccountTab, isProductSoldOut, isRecord, isSelectionSoldOut, loadLatestWrittenReviews, loadShopPage, loadShopReviewsPage, missingRequiredCheckoutValues, notifyFavoritesChanged, optionalBoolean, optionalString, optionalStringWithDefault, paginateCatalogCards, parseAccountPath, parseCartQuoteLines, parseEnum, parseFiniteNumber, parseProductBadges, parseServiceStatus, parseStorefrontSortKey, readCheckoutNeedsDetails, readStorefrontData, requestStockAlert, requireArray, requireBoolean, requireNumber, requireRecord, requireString, requireStringFromKeys, requireUnknownRecord, resolveAccountView, resolveBadgeForeground, resolveCartBoundsHeals, resolveCategorySelection, resolveCheckoutFields, resolveDeliveryPromise, resolveDisplayStock, resolveHideStockCounter, resolveLicenseTerm, resolveMenuLinksForSlot, resolvePayWhatYouWantMinimum, resolveProductVideoEmbedSrc, resolveQuantityBounds, resolveSupportChannels, resolveUnsellableLineIds, resolveVariantStock, resolveYouReceive, reviewsForProduct, roundCurrency, sanitizeMerchantHtml, sdkFavoritesTransport, sortCatalogCards, startCartMutation, stripMerchantHtmlImages, submitContactTicket, subscriptionForVariant, toShopReviews, toStarCount, useCart, useFavorites, useNavigationLinks, useOnlineUserCount, usePagedShopReviews, useShopReviews, useStorefront, validateCheckoutFieldValue, validateCheckoutFields, validateContactSubmission, withRequiredAddons };
package/dist/index.js CHANGED
@@ -575,6 +575,14 @@ function formatSubscriptionCadence(subscription) {
575
575
  const noun = SUBSCRIPTION_INTERVAL_NOUNS[unit];
576
576
  return subscription.intervalCount === 1 ? `per ${noun}` : `every ${subscription.intervalCount} ${noun}s`;
577
577
  }
578
+ function formatSubscriptionRenewal(subscription) {
579
+ const unit = subscription.intervalUnit;
580
+ if (unit === null) return "";
581
+ const noun = SUBSCRIPTION_INTERVAL_NOUNS[unit];
582
+ const every = subscription.intervalCount === 1 ? `every ${noun}` : `every ${subscription.intervalCount} ${noun}s`;
583
+ const renews = `Renews ${every} until you cancel.`;
584
+ return subscription.planChangeOffered ? `${renews} Switch plans any time in your account.` : renews;
585
+ }
578
586
  function formatSubscriptionTrial(subscription, formatAmount) {
579
587
  const trial = subscription.trial;
580
588
  if (!trial) return "";
@@ -582,13 +590,14 @@ function formatSubscriptionTrial(subscription, formatAmount) {
582
590
  return `${formatAmount(trial.price, trial.currency)} for ${trial.days} ${trial.days === 1 ? "day" : "days"}`;
583
591
  }
584
592
  function subscriptionForVariant(subscription, variant) {
585
- const own = variant?.billingInterval;
586
- const ownTrial = variant?.ownTrial;
587
- if (!own && !ownTrial) return subscription;
593
+ if (!variant) return subscription;
594
+ const own = variant.billingInterval;
595
+ const ownTrial = variant.ownTrial;
588
596
  return {
589
597
  ...subscription,
590
598
  ...own ? { intervalUnit: own.unit, intervalCount: own.count } : {},
591
- ...ownTrial ? { trial: ownTrial === "none" ? null : ownTrial } : {}
599
+ ...ownTrial ? { trial: ownTrial === "none" ? null : ownTrial } : {},
600
+ planChangeOffered: variant.planChangeOffered
592
601
  };
593
602
  }
594
603
  function parseSubscription(product, productType) {
@@ -599,7 +608,8 @@ function parseSubscription(product, productType) {
599
608
  return {
600
609
  intervalUnit: unit,
601
610
  intervalCount: count,
602
- trial: parseTrial(product)
611
+ trial: parseTrial(product),
612
+ planChangeOffered: product.plan_change_offered === true
603
613
  };
604
614
  }
605
615
  function parseVariantBillingInterval(variant) {
@@ -1049,6 +1059,7 @@ function parsePriceVariants(value, productContext) {
1049
1059
  license: parseVariantLicense(variant),
1050
1060
  billingInterval: parseVariantBillingInterval(variant),
1051
1061
  ownTrial: parseVariantTrial(variant),
1062
+ planChangeOffered: variant.plan_change_offered === true,
1052
1063
  price: unitPrice,
1053
1064
  baseUnitPrice: unitPrice,
1054
1065
  stock: normalizeStock(variant.stock, `${context}.stock`),
@@ -3141,6 +3152,7 @@ export {
3141
3152
  formatLicenseTerm,
3142
3153
  formatMoney,
3143
3154
  formatSubscriptionCadence,
3155
+ formatSubscriptionRenewal,
3144
3156
  formatSubscriptionTrial,
3145
3157
  getAuthoredContent,
3146
3158
  getBuyerCurrency,