@shoppexio/storefront-react 0.6.2 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.3
4
+
5
+ - Product: whether a subscription's buyer can switch plans is the selected option's answer. `StorefrontPriceVariant.planChangeOffered` reads each option's `plan_change_offered` (false when the backend does not send it), and `subscriptionForVariant` puts it on the subscription, so `formatSubscriptionRenewal` promises "Switch plans any time in your account." only for an option that has another plan to switch to (under "Upgrades only" the top plan has none). With no option selected the product's answer stands.
6
+
3
7
  ## 0.6.2
4
8
 
5
9
  - Product: `formatSubscriptionRenewal(subscription)` gives the line under a subscription's buy buttons, "Renews every month until you cancel.", plus "Switch plans any time in your account." only when the catalog's `plan_change_offered` says the buyer can switch (the shop allows buyer plan changes and a second plan is offered); `ProductSubscription.planChangeOffered` carries it, false when the backend does not send the field. Empty for a plan without an interval.
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;
@@ -1822,9 +1828,11 @@ declare function formatSubscriptionTrial(subscription: ProductSubscription, form
1822
1828
  * interval (`billing_interval`, stored with its count or not at all) is charged
1823
1829
  * at that cadence, every other one at the product's. An option with its own
1824
1830
  * trial ("No trial" included) starts with it, every other one with the
1825
- * 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.
1826
1834
  */
1827
- 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;
1828
1836
  /**
1829
1837
  * What a product image shows, from the backend's pixel analysis. `art` is a
1830
1838
  * cover, artwork or photo; `logo` is a flat mark, drawn on a contrasting plate.
package/dist/index.js CHANGED
@@ -590,13 +590,14 @@ function formatSubscriptionTrial(subscription, formatAmount) {
590
590
  return `${formatAmount(trial.price, trial.currency)} for ${trial.days} ${trial.days === 1 ? "day" : "days"}`;
591
591
  }
592
592
  function subscriptionForVariant(subscription, variant) {
593
- const own = variant?.billingInterval;
594
- const ownTrial = variant?.ownTrial;
595
- if (!own && !ownTrial) return subscription;
593
+ if (!variant) return subscription;
594
+ const own = variant.billingInterval;
595
+ const ownTrial = variant.ownTrial;
596
596
  return {
597
597
  ...subscription,
598
598
  ...own ? { intervalUnit: own.unit, intervalCount: own.count } : {},
599
- ...ownTrial ? { trial: ownTrial === "none" ? null : ownTrial } : {}
599
+ ...ownTrial ? { trial: ownTrial === "none" ? null : ownTrial } : {},
600
+ planChangeOffered: variant.planChangeOffered
600
601
  };
601
602
  }
602
603
  function parseSubscription(product, productType) {
@@ -1058,6 +1059,7 @@ function parsePriceVariants(value, productContext) {
1058
1059
  license: parseVariantLicense(variant),
1059
1060
  billingInterval: parseVariantBillingInterval(variant),
1060
1061
  ownTrial: parseVariantTrial(variant),
1062
+ planChangeOffered: variant.plan_change_offered === true,
1061
1063
  price: unitPrice,
1062
1064
  baseUnitPrice: unitPrice,
1063
1065
  stock: normalizeStock(variant.stock, `${context}.stock`),