@aglyn/aglyn 1.9.1 → 1.11.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.
@@ -179,8 +179,9 @@ export const PLAN_ENTITLEMENTS = {
179
179
  // A `Form` node placed on a page still needs no definition to collect,
180
180
  // and the 20 submissions above are the band those replies spend.
181
181
  //
182
- // The ladder: Free 1, Starter 5, Pro 25, Business 100, and
183
- // `FORMS_PER_HOST_CEILING` on Scale and above.
182
+ // The ladder: Free 1, Starter 5, Pro and Custom UNLIMITED; the retired
183
+ // rows keep theirs (Business 100, `FORMS_PER_HOST_CEILING` on Scale,
184
+ // Advanced and Agency).
184
185
  formsPerHost: 1,
185
186
  // One reusable component per Free site (AGL-3615), counted the way the
186
187
  // one saved form is: the create is refused on this number, with the
@@ -867,8 +868,8 @@ export const PLAN_ENTITLEMENTS = {
867
868
  // ceiling still flags and pages staff at 3× the band, and does NOT degrade
868
869
  // the render on this plan — see `bandwidthCeilingDegradesRender`.
869
870
  //
870
- // `formsPerHost` is `FORMS_PER_HOST_CEILING`, the top of the saved-form
871
- // ladder (AGL-3597), shared with Scale, Advanced and Agency.
871
+ // `formsPerHost` is UNLIMITED, as on Pro (AGL-4158): Custom is never below
872
+ // Pro, and a contract that wants a bound sets the per-org override.
872
873
  enterprise: {
873
874
  hostLimit: 200,
874
875
  screensPerHost: UNLIMITED,
@@ -880,7 +881,7 @@ export const PLAN_ENTITLEMENTS = {
880
881
  maxManagersPerOrg: 1000,
881
882
  maxMembersPerHost: 2000,
882
883
  bandwidthGb: 790,
883
- formsPerHost: FORMS_PER_HOST_CEILING,
884
+ formsPerHost: UNLIMITED,
884
885
  componentsPerHost: UNLIMITED,
885
886
  variablesPerHost: UNLIMITED,
886
887
  functionsPerHost: UNLIMITED,
@@ -1009,6 +1010,16 @@ fillPluginPlanEntitlements(PLAN_ENTITLEMENTS);
1009
1010
  ...RETIRED_PLANS,
1010
1011
  'enterprise'
1011
1012
  ];
1013
+ /**
1014
+ * The plans a staff custom-billing deal may ride on (AGL-4158): Custom first,
1015
+ * the default a negotiated deal lands on, then the paid self-serve plans from
1016
+ * the top down (Pro, Starter) for a deal scoped to that plan's capability.
1017
+ * Built from `SELF_SERVE_PLANS`, so a retired plan is never offered and the
1018
+ * staff "Base plan" picker and the provisioning route agree by construction.
1019
+ */ export const CUSTOM_BILLING_BASE_PLANS = [
1020
+ 'enterprise',
1021
+ ...SELF_SERVE_PLANS.filter((plan)=>plan !== 'free').reverse()
1022
+ ];
1012
1023
  /** Whether a plan is one pricing v4 retired (`RETIRED_PLANS`). */ export function isRetiredPlan(plan) {
1013
1024
  return RETIRED_PLANS.includes(plan);
1014
1025
  }
@@ -1724,6 +1735,44 @@ function trimmedOrNull(value) {
1724
1735
  }
1725
1736
  return listPriceUsd;
1726
1737
  }
1738
+ /**
1739
+ * The org's BASE PLAN line, monthly (annual billing as its monthly
1740
+ * equivalent), and 0 for anyone not billing: the one line a base-price coupon
1741
+ * reaches (AGL-4161). A negotiated custom price is the whole deal, so it is
1742
+ * its own base line.
1743
+ */ export function orgBasePriceMonthlyUsd(org) {
1744
+ var _org_subscription, _org_subscription1;
1745
+ if (!isBillingSubscription(org)) return 0;
1746
+ const custom = org == null ? void 0 : (_org_subscription = org.subscription) == null ? void 0 : _org_subscription.customMonthlyUsd;
1747
+ if (typeof custom === 'number' && custom > 0) return Math.round(custom * 100) / 100;
1748
+ const pricing = PLAN_PRICING[org == null ? void 0 : org.plan];
1749
+ if (!pricing) return 0;
1750
+ return (org == null ? void 0 : (_org_subscription1 = org.subscription) == null ? void 0 : _org_subscription1.interval) === 'year' ? pricing.basePriceAnnualMonthlyUsd : pricing.basePriceMonthlyUsd;
1751
+ }
1752
+ /**
1753
+ * How much of the org's monthly list price a discount reaches (AGL-4161):
1754
+ * all of it for a whole-subscription discount; for a base-price one, the base
1755
+ * plan line, or nothing when the plans it is limited to do not include the
1756
+ * org's plan (Stripe applies it to no line then). An old mirror without the
1757
+ * fields is a whole-subscription discount.
1758
+ */ export function discountReachMonthlyUsd(org, discount, listPriceUsd = orgListPriceMonthlyUsd(org)) {
1759
+ const list = Math.max(0, listPriceUsd);
1760
+ if (!(discount == null ? void 0 : discount.basePriceOnly)) return list;
1761
+ if (Array.isArray(discount.appliesToPlans) && !discount.appliesToPlans.includes(org == null ? void 0 : org.plan)) {
1762
+ return 0;
1763
+ }
1764
+ return Math.min(list, orgBasePriceMonthlyUsd(org));
1765
+ }
1766
+ /**
1767
+ * A monthly list price net of an ORG's discount (AGL-4161): `applyDiscountUsd`
1768
+ * on the part the discount reaches, the rest at list. For a whole-subscription
1769
+ * discount that is `applyDiscountUsd` exactly; a base-price one leaves the
1770
+ * add-ons in full.
1771
+ */ export function applyOrgDiscountUsd(org, listPriceUsd, discount) {
1772
+ const reach = discountReachMonthlyUsd(org, discount, listPriceUsd);
1773
+ if (!discount || reach >= listPriceUsd) return applyDiscountUsd(listPriceUsd, discount);
1774
+ return Math.round((listPriceUsd - reach + applyDiscountUsd(reach, discount)) * 100) / 100;
1775
+ }
1727
1776
  /**
1728
1777
  * Whether an org should read as **"Enterprise"** everywhere the plan is shown.
1729
1778
  * Three ways to qualify:
@@ -1782,10 +1831,12 @@ function trimmedOrNull(value) {
1782
1831
  * (`org.discount`, AGL-1105), and 0 for anyone who is not actually billing. A
1783
1832
  * comped enterprise deal genuinely collects less, so the discount belongs in
1784
1833
  * MRR; the pre-discount sticker stays available as `orgListPriceMonthlyUsd`.
1834
+ * A base-price discount (AGL-4161) comes off the base plan line only, so the
1835
+ * add-ons an org buys count in full.
1785
1836
  */ export function orgMonthlyRevenueUsd(org) {
1786
1837
  const listPrice = orgListPriceMonthlyUsd(org);
1787
1838
  if (listPrice <= 0) return 0;
1788
- return applyDiscountUsd(listPrice, org == null ? void 0 : org.discount);
1839
+ return applyOrgDiscountUsd(org, listPrice, org == null ? void 0 : org.discount);
1789
1840
  }
1790
1841
  /**
1791
1842
  * Stripe's standard processing fee on Aglyn's OWN subscription charges
@@ -2409,7 +2460,8 @@ export const DISCOUNT_DEPTH_BLOCK_PCT = 70;
2409
2460
  * the org — `grossUsd` is always the list price (`orgListPriceMonthlyUsd`),
2410
2461
  * so this never double-counts an existing `org.discount`. A non-billing org
2411
2462
  * (list price 0) has no revenue to protect and rates `ok`.
2412
- */ export function checkDiscountMargin(org, discount, options = {}) {
2463
+ */ export function checkDiscountMargin(org, // A base-price coupon (AGL-4161) is rated on the base line it reaches.
2464
+ discount, options = {}) {
2413
2465
  var _options_measuredCogsUsd;
2414
2466
  var _org_subscription;
2415
2467
  const floorPct = NET_MARGIN_FLOOR_PCT;
@@ -2436,7 +2488,7 @@ export const DISCOUNT_DEPTH_BLOCK_PCT = 70;
2436
2488
  floorPct
2437
2489
  };
2438
2490
  }
2439
- const discountedUsd = applyDiscountUsd(grossUsd, discount);
2491
+ const discountedUsd = applyOrgDiscountUsd(org, grossUsd, discount);
2440
2492
  const annual = (org == null ? void 0 : (_org_subscription = org.subscription) == null ? void 0 : _org_subscription.interval) === 'year';
2441
2493
  const netUsd = netOfProcessorFee(discountedUsd, annual);
2442
2494
  const depthPct = Math.round((grossUsd - discountedUsd) / grossUsd * 10000) / 10000;
@@ -3380,7 +3432,7 @@ export function saleProcessingCostCents(chargeCents) {
3380
3432
  ].find((plan)=>Boolean(PLAN_ENTITLEMENTS[plan].features[feature]));
3381
3433
  }
3382
3434
  /**
3383
- * The plan name an upsell should name, ready to interpolate — "Business",
3435
+ * The plan name an upsell should name, ready to interpolate — "Pro",
3384
3436
  * or undefined when {@link planGrantingFeature} has no answer.
3385
3437
  */ export function planLabelGrantingFeature(feature) {
3386
3438
  const plan = planGrantingFeature(feature);
@@ -3388,7 +3440,7 @@ export function saleProcessingCostCents(chargeCents) {
3388
3440
  }
3389
3441
  /**
3390
3442
  * The one sentence a locked control carries, on hover and for a screen
3391
- * reader: "Scheduled publishing is included from Business."
3443
+ * reader: "Scheduled publishing is included from Pro."
3392
3444
  */ export function planLockReason(subject, planLabel) {
3393
3445
  return planLabel ? `${subject} is included from ${planLabel}.` : `${subject} is a paid add-on.`;
3394
3446
  }