@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.
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import type { AglynOrgBilling, OrgDiscount, OrgPlan } from '../foundation';
18
- import { type ResolvedOrgEntitlements } from './plan-entitlements';
18
+ import { type OrgDiscountTerms, type ResolvedOrgEntitlements } from './plan-entitlements';
19
19
  /**
20
20
  * WHAT A WORKSPACE COSTS IF IT SPENDS EXACTLY WHAT IT BOUGHT (AGL-3473).
21
21
  *
@@ -148,6 +148,12 @@ export declare function rateAgainstFullUse(input: {
148
148
  cogs: FullUseCogsResult;
149
149
  multiple: number;
150
150
  discount?: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null;
151
+ /**
152
+ * The part of the monthly list price the discount reaches (AGL-4161): the
153
+ * base plan line for a base-price coupon, the rest billing in full.
154
+ * Absent, all of it.
155
+ */
156
+ reachMonthlyUsd?: number;
151
157
  }): FullUseFloorResult;
152
158
  /**
153
159
  * An org's subscription after `discount`, against `multiple` × its full-use
@@ -219,14 +225,18 @@ export declare function assessDiscountAgainstFullUse(input: {
219
225
  cogs: FullUseCogsResult;
220
226
  discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null | undefined;
221
227
  duration: CouponDuration | null | undefined;
228
+ /** What the discount reaches of the list price (AGL-4161); absent, all of it. */
229
+ reachMonthlyUsd?: number;
222
230
  }): DiscountFullUseAssessment;
223
231
  /**
224
232
  * A discount on an org as it bills — its plan, overrides, add-ons, interval
225
233
  * and the price it pays — against its full-use cost: the warning behind
226
234
  * applying a coupon to an org and behind the winback. A list price of 0 (no
227
- * subscription on record) is reported as such, never as covered.
235
+ * subscription on record) is reported as such, never as covered. A
236
+ * base-price discount (AGL-4161) comes off the base plan line alone, so the
237
+ * add-ons are judged at the price they bill.
228
238
  */
229
- export declare function orgDiscountFullUse(org: Partial<AglynOrgBilling> | null | undefined, discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null | undefined, duration: CouponDuration | null | undefined): DiscountFullUseAssessment;
239
+ export declare function orgDiscountFullUse(org: Partial<AglynOrgBilling> | null | undefined, discount: OrgDiscountTerms | null | undefined, duration: CouponDuration | null | undefined): DiscountFullUseAssessment;
230
240
  /** One plan and interval a coupon could be redeemed on, judged. */
231
241
  export interface CouponFullUseCase extends DiscountFullUseAssessment {
232
242
  plan: OrgPlan;
@@ -235,7 +245,7 @@ export interface CouponFullUseCase extends DiscountFullUseAssessment {
235
245
  export interface CouponFullUseVerdict {
236
246
  /** Every case clears: no discounted charge, on any plan, falls under its full-use cost. */
237
247
  ok: boolean;
238
- /** Every paid self-serve plan, monthly and annual, judged. */
248
+ /** Every paid self-serve plan the coupon reaches, monthly and annual, judged. */
239
249
  cases: CouponFullUseCase[];
240
250
  /** The case with the least cover — the one the warning leads with. */
241
251
  worst: CouponFullUseCase;
@@ -248,14 +258,21 @@ export interface CouponFullUseVerdict {
248
258
  * Judge a coupon or promotion code against full-use cost before it is minted
249
259
  * (AGL-3473) — a WARNING for staff, never a refusal.
250
260
  *
251
- * A coupon here carries no plan restriction, so its code can be redeemed on
252
- * any paid self-serve plan, on either interval, by a customer using
253
- * everything the plan includes; each case is that plan's list price against
254
- * its own bands at 100%, on the charges `duration` reaches. Enterprise is
255
- * quoted per deal and never takes a code at checkout; a coupon applied to one
256
- * is judged on that org.
261
+ * A coupon with no plan restriction can be redeemed on any paid self-serve
262
+ * plan, on either interval, by a customer using everything the plan
263
+ * includes; each case is that plan's list price against its own bands at
264
+ * 100%, on the charges `duration` reaches. Enterprise is quoted per deal and
265
+ * never takes a code at checkout; a coupon applied to one is judged on that
266
+ * org.
267
+ *
268
+ * `plans` narrows the cases to the plans a coupon is limited to (AGL-4159): a
269
+ * coupon that takes its discount off one plan's base price is redeemed on
270
+ * that plan only, so the others are not its risk. Each case still prices the
271
+ * plan's own list price, which is exactly the line such a coupon reaches —
272
+ * add-ons and usage past the bands bill in full. A restriction that names no
273
+ * paid self-serve plan is judged on all of them, the cautious reading.
257
274
  */
258
- export declare function rateCouponAgainstFullUse(discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'>, duration?: CouponDuration | null): CouponFullUseVerdict;
275
+ export declare function rateCouponAgainstFullUse(discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'>, duration?: CouponDuration | null, plans?: readonly OrgPlan[] | null): CouponFullUseVerdict;
259
276
  /**
260
277
  * The deepest whole percent off a coupon can take with every discounted
261
278
  * charge, on every paid self-serve plan, still covering its full-use cost —
@@ -17,7 +17,7 @@
17
17
  // that refuse a quote or a discount — so it may import neither entry barrel,
18
18
  // for the reason `margin-utilization.ts` states at its own head.
19
19
  import { _ as _extends } from "@swc/helpers/_/_extends";
20
- import { ESTIMATED_PAGE_TRANSFER_BYTES, INFRA_COGS_PER_SITE_USD, METERED_MARKUP, ORG_COGS_UNIT_RATES_USD, PAGE_VIEW_CDN_REQUEST_COST_USD, PLAN_LABELS, PLAN_PRICING, SELF_SERVE_PLANS, applyDiscountUsd, checkSeatQuota, netOfProcessorFee, orgListPriceMonthlyUsd, resolveCollaboratorSeatPool, resolveOrgEntitlements } from "./plan-entitlements.js";
20
+ import { ESTIMATED_PAGE_TRANSFER_BYTES, INFRA_COGS_PER_SITE_USD, METERED_MARKUP, ORG_COGS_UNIT_RATES_USD, PAGE_VIEW_CDN_REQUEST_COST_USD, PLAN_LABELS, PLAN_PRICING, SELF_SERVE_PLANS, applyDiscountUsd, checkSeatQuota, discountReachMonthlyUsd, netOfProcessorFee, orgListPriceMonthlyUsd, resolveCollaboratorSeatPool, resolveOrgEntitlements } from "./plan-entitlements.js";
21
21
  import { planQuotaOf } from "../plugin-manager/plugin-plan-entitlements.js";
22
22
  import { pluginCostAxes, pluginUsageBands } from "../plugin-manager/plugin-usage-axes.js";
23
23
  /**
@@ -194,7 +194,9 @@ import { pluginCostAxes, pluginUsageBands } from "../plugin-manager/plugin-usage
194
194
  * times a full-use cost. Pure: the callers below bring the price and the cost.
195
195
  */ export function rateAgainstFullUse(input) {
196
196
  const listUsd = Math.max(0, Number(input.listMonthlyUsd) || 0);
197
- const discountedUsd = applyDiscountUsd(listUsd, monthlyDiscount(input.discount, input.annual));
197
+ const reachUsd = typeof input.reachMonthlyUsd === 'number' ? Math.min(listUsd, Math.max(0, input.reachMonthlyUsd)) : listUsd;
198
+ const monthly = monthlyDiscount(input.discount, input.annual);
199
+ const discountedUsd = reachUsd >= listUsd ? applyDiscountUsd(listUsd, monthly) : Math.round((listUsd - reachUsd + applyDiscountUsd(reachUsd, monthly)) * 100) / 100;
198
200
  const netUsd = netOfProcessorFee(discountedUsd, input.annual);
199
201
  const fullUseCogsUsd = input.cogs.cogsUsd;
200
202
  const requiredNetUsd = input.multiple * fullUseCogsUsd;
@@ -303,32 +305,46 @@ import { pluginCostAxes, pluginUsageBands } from "../plugin-manager/plugin-usage
303
305
  * A discount on an org as it bills — its plan, overrides, add-ons, interval
304
306
  * and the price it pays — against its full-use cost: the warning behind
305
307
  * applying a coupon to an org and behind the winback. A list price of 0 (no
306
- * subscription on record) is reported as such, never as covered.
308
+ * subscription on record) is reported as such, never as covered. A
309
+ * base-price discount (AGL-4161) comes off the base plan line alone, so the
310
+ * add-ons are judged at the price they bill.
307
311
  */ export function orgDiscountFullUse(org, discount, duration) {
308
312
  var _org_subscription;
313
+ const listMonthlyUsd = orgListPriceMonthlyUsd(org);
309
314
  return assessDiscountAgainstFullUse({
310
- listMonthlyUsd: orgListPriceMonthlyUsd(org),
315
+ listMonthlyUsd,
311
316
  annual: (org == null ? void 0 : (_org_subscription = org.subscription) == null ? void 0 : _org_subscription.interval) === 'year',
312
317
  cogs: orgFullUseCogs(org),
313
318
  discount,
314
- duration
319
+ duration,
320
+ reachMonthlyUsd: discountReachMonthlyUsd(org, discount, listMonthlyUsd)
315
321
  });
316
322
  }
317
323
  /**
318
324
  * Judge a coupon or promotion code against full-use cost before it is minted
319
325
  * (AGL-3473) — a WARNING for staff, never a refusal.
320
326
  *
321
- * A coupon here carries no plan restriction, so its code can be redeemed on
322
- * any paid self-serve plan, on either interval, by a customer using
323
- * everything the plan includes; each case is that plan's list price against
324
- * its own bands at 100%, on the charges `duration` reaches. Enterprise is
325
- * quoted per deal and never takes a code at checkout; a coupon applied to one
326
- * is judged on that org.
327
- */ export function rateCouponAgainstFullUse(discount, duration) {
328
- const cases = [];
329
- for (const plan of SELF_SERVE_PLANS){
327
+ * A coupon with no plan restriction can be redeemed on any paid self-serve
328
+ * plan, on either interval, by a customer using everything the plan
329
+ * includes; each case is that plan's list price against its own bands at
330
+ * 100%, on the charges `duration` reaches. Enterprise is quoted per deal and
331
+ * never takes a code at checkout; a coupon applied to one is judged on that
332
+ * org.
333
+ *
334
+ * `plans` narrows the cases to the plans a coupon is limited to (AGL-4159): a
335
+ * coupon that takes its discount off one plan's base price is redeemed on
336
+ * that plan only, so the others are not its risk. Each case still prices the
337
+ * plan's own list price, which is exactly the line such a coupon reaches —
338
+ * add-ons and usage past the bands bill in full. A restriction that names no
339
+ * paid self-serve plan is judged on all of them, the cautious reading.
340
+ */ export function rateCouponAgainstFullUse(discount, duration, plans) {
341
+ const paid = SELF_SERVE_PLANS.filter((plan)=>{
330
342
  var _PLAN_PRICING_plan;
331
- if (!(((_PLAN_PRICING_plan = PLAN_PRICING[plan]) == null ? void 0 : _PLAN_PRICING_plan.basePriceMonthlyUsd) > 0)) continue;
343
+ return ((_PLAN_PRICING_plan = PLAN_PRICING[plan]) == null ? void 0 : _PLAN_PRICING_plan.basePriceMonthlyUsd) > 0;
344
+ });
345
+ const limited = (plans == null ? void 0 : plans.length) ? paid.filter((plan)=>plans.includes(plan)) : [];
346
+ const cases = [];
347
+ for (const plan of limited.length ? limited : paid){
332
348
  for (const interval of [
333
349
  'month',
334
350
  'year'
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/full-use-cost.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Imported from BOTH graphs — the staff pages (client) and the App Routes\n// that refuse a quote or a discount — so it may import neither entry barrel,\n// for the reason `margin-utilization.ts` states at its own head.\nimport type { AglynOrgBilling, OrgDiscount, OrgPlan } from '../foundation'\nimport {\n ESTIMATED_PAGE_TRANSFER_BYTES,\n INFRA_COGS_PER_SITE_USD,\n METERED_MARKUP,\n ORG_COGS_UNIT_RATES_USD,\n PAGE_VIEW_CDN_REQUEST_COST_USD,\n PLAN_LABELS,\n PLAN_PRICING,\n SELF_SERVE_PLANS,\n applyDiscountUsd,\n checkSeatQuota,\n netOfProcessorFee,\n orgListPriceMonthlyUsd,\n resolveCollaboratorSeatPool,\n resolveOrgEntitlements,\n type ResolvedOrgEntitlements,\n} from './plan-entitlements'\nimport { planQuotaOf } from '../plugin-manager/plugin-plan-entitlements'\nimport {\n pluginCostAxes,\n pluginUsageBands,\n type ResolvedPluginUsageBand,\n} from '../plugin-manager/plugin-usage-axes'\n\n/**\n * WHAT A WORKSPACE COSTS IF IT SPENDS EXACTLY WHAT IT BOUGHT (AGL-3473).\n *\n * `orgMonthlyCogsUsd` prices what an org DID use, from its rollup. Every\n * guard that rated a price against it — the discount guardrail, the\n * enterprise quote card — therefore approved deals on the strength of how\n * little the customer had used so far, and a deal is a promise about the\n * whole allowance. Agency at 20% off read \"ok, 75.5%\" against its measured\n * month while sitting under what its bands cost at 100%.\n *\n * This is the same multiplication `tier-margin-floor.spec.ts` does for the\n * price list — every band at 100%, at the rates the platform's own model\n * uses — over RESOLVED entitlements, so a staff override, a comp's plan and\n * a purchased add-on all cost what they deliver. That spec holds its own\n * independent model and asserts this function agrees with it on every plan.\n *\n * Two readers, held to it differently. An enterprise quote must clear\n * `FULL_USE_QUOTE_MULTIPLE` × the cost and is refused below it. A coupon or\n * discount is judged on the charges it reaches and WARNED about below 1× —\n * never refused, because a first-month or first-year discount that spends\n * cost to close a deal is a decision staff are allowed to make.\n *\n * ## An unbounded band costs Infinity, never 0\n *\n * A band that is `UNLIMITED` cannot be costed, and every cost model in this\n * repo that scored one as zero reported the largest line item on a plan as\n * contributing nothing. So a non-finite term — or one that is `NaN` because a\n * zero met an infinity — is `Infinity`, the total is `Infinity`, and no price\n * clears it. The term is named in `unbounded` so a refusal or a warning can\n * say which band to bound.\n */\n\n/**\n * What one console seat costs to serve for a month — about 60,000 reads and\n * 10,000 writes at `nam5` list prices, ≈$0.054, carried as $0.06 (the Drive\n * pricing decision of 2026-09-05).\n *\n * NOT in `ORG_COGS_UNIT_RATES_USD`: no rollup meter counts seat-months, so a\n * rate there would be one no axis of `orgMonthlyCogsUsd` reads.\n */\nexport const SEAT_COGS_USD_PER_MONTH = 0.06\n\n/**\n * Days a daily band is spent at 100% in a month: the one-to-one email cap is\n * a pace per UTC day, and the whole month at that pace is thirty of them.\n */\nconst DAYS_PER_FULL_MONTH = 30\n\n/** Page views one GB of included bandwidth buys — `pageViewsFromBandwidthGb`'s constant. */\nconst VIEWS_PER_GB = (1024 * 1024 * 1024) / ESTIMATED_PAGE_TRANSFER_BYTES\n\n/**\n * How many times its full-use cost an enterprise quote must cover, net of\n * Stripe: cost + 30%, the markup every metered overage already carries, so a\n * negotiated deal earns what the price list does.\n */\nexport const FULL_USE_QUOTE_MULTIPLE = METERED_MARKUP\n\n/**\n * The full-use cost a discounted charge is judged against, net of Stripe: 1×.\n * A discount that spends only the 30% a price carries above cost clears it;\n * one that reaches into the cost is WARNED about, never refused — a coupon is\n * a tool for closing a deal, and staff choose to spend cost on one knowingly.\n */\nexport const FULL_USE_DISCOUNT_MULTIPLE = 1\n\nexport interface FullUseCogsResult {\n /** `measuredUsd` or the per-site floor, whichever is larger; `Infinity` when any band is unbounded. */\n cogsUsd: number\n /** The sum of every term at 100% of its band. */\n measuredUsd: number\n /** `INFRA_COGS_PER_SITE_USD × hostLimit` — the sites sold, not the sites built. */\n floorUsd: number\n /** Every term, in USD a month, for showing the working. */\n breakdown: Record<string, number>\n /** The terms whose band is unbounded, sorted. Empty when the plan can be costed. */\n unbounded: string[]\n}\n\nexport interface FullUseCogsOptions {\n /**\n * Seats bought on top of the plan's — the org-wide manager add-on and the\n * collaborator pool, neither of which `resolveOrgEntitlements` folds into\n * a band.\n */\n extraSeats?: number\n}\n\n/** A term that cannot be costed is unbounded, never free. */\nfunction termUsd(value: number): number {\n return Number.isFinite(value) ? value : Number.POSITIVE_INFINITY\n}\n\n/**\n * The USD one unit of a plugin's declared band costs.\n *\n * A band sold in a unit OF cost declares that unit's price (`unitCostUsd`).\n * Every other band is priced by the cost axis that records the same rollup\n * field the band is measured by — the meter `orgMonthlyCogsUsd` already\n * prices its usage on — at that axis's `ORG_COGS_UNIT_RATES_USD` rate, or at\n * ×1 where the axis records dollars.\n *\n * ⚑ A band no axis records, or an axis naming a rate core does not carry,\n * THROWS. Pricing it at zero would make a plan cost less than it does, which\n * is the direction that approves a quote.\n */\nfunction declaredBandUnitCostUsd(band: ResolvedPluginUsageBand): number {\n if (typeof band.unitCostUsd === 'number') return band.unitCostUsd\n const measuredBy = [...band.fields, ...(band.fallbackFields ?? [])]\n const axis = pluginCostAxes().find((candidate) =>\n measuredBy.some(\n (field) =>\n candidate.fields.includes(field) ||\n (candidate.fallbackFields ?? []).includes(field),\n ),\n )\n if (!axis) {\n throw new Error(\n `usage band \"${band.id}\" is measured by no declared cost axis, so its full-use cost has no rate`,\n )\n }\n if (axis.rate === undefined) return 1\n const rate = (ORG_COGS_UNIT_RATES_USD as Record<string, number>)[axis.rate]\n if (typeof rate !== 'number' || !Number.isFinite(rate)) {\n throw new Error(\n `cost axis \"${axis.id}\" names the rate \"${axis.rate}\", which ORG_COGS_UNIT_RATES_USD does not carry`,\n )\n }\n return rate\n}\n\n/**\n * Every cost a workspace's RESOLVED bands imply at 100%, per month.\n *\n * The platform's own bands, each at the rate `orgMonthlyCogsUsd` prices its\n * meter on: media storage per site (× `hostLimit`), bandwidth at its weight\n * (`perPageView`) and at its CDN requests (`PAGE_VIEW_CDN_REQUEST_COST_USD`),\n * stored data (`dataStorageMbPerOrg`), API requests and every email the\n * campaign band sends. Then every band a plugin declares\n * (`plugin-usage-axes.ts`), a per-site one expanded by `hostLimit`. Then the\n * two costs no meter records:\n *\n * - SEATS — every collaborator each site admits on every site\n * (`membersPerHost × hostLimit`), the org's managers (`managersPerOrg`)\n * and any bought on top, at `SEAT_COGS_USD_PER_MONTH`;\n * - ONE-TO-ONE EMAIL — the CRM's daily cap spent every day of the month, at\n * the rate every other send costs.\n *\n * `INFRA_COGS_PER_SITE_USD × hostLimit` is a FLOOR rather than an added\n * term, exactly as in `orgMonthlyCogsUsd`.\n */\nexport function fullUseCogs(\n entitlements: ResolvedOrgEntitlements,\n options: FullUseCogsOptions = {},\n): FullUseCogsResult {\n const rates = ORG_COGS_UNIT_RATES_USD\n const hosts = entitlements.hostLimit\n const quota = (key: string) => planQuotaOf(entitlements, key)\n const extraSeats = Math.max(0, Number(options.extraSeats ?? 0) || 0)\n const breakdown: Record<string, number> = {\n mediaStorage: termUsd(\n ((hosts * entitlements.storagePerHostMb) / 1024) * rates.storagePerGbMonth,\n ),\n bandwidth: termUsd(entitlements.bandwidthGb * VIEWS_PER_GB * rates.perPageView),\n cdnRequests: termUsd(\n entitlements.bandwidthGb * VIEWS_PER_GB * PAGE_VIEW_CDN_REQUEST_COST_USD,\n ),\n dataStorage: termUsd(\n (entitlements.dataStorageMbPerOrg / 1024) * rates.dataStoragePerGbMonth,\n ),\n apiRequests: termUsd(entitlements.apiRequestsPerMonth * rates.perApiRequest),\n emailSends: termUsd(entitlements.emailSendsPerMonth * rates.perEmailSend),\n }\n for (const band of pluginUsageBands()) {\n const units = quota(band.entitlement) * (band.perHost ? hosts : 1)\n breakdown[band.id] = termUsd(units * declaredBandUnitCostUsd(band))\n }\n breakdown['seats'] = termUsd(\n (entitlements.membersPerHost * hosts + entitlements.managersPerOrg + extraSeats) *\n SEAT_COGS_USD_PER_MONTH,\n )\n // Read by key, as `checkCrmEmailQuota` reads it: a daily pace is not a\n // monthly band, so no usage-band declaration carries it.\n breakdown['crmEmail'] = termUsd(\n quota('crmEmailsPerDay') * DAYS_PER_FULL_MONTH * rates.perEmailSend,\n )\n const unbounded = Object.entries(breakdown)\n .filter(([, usd]) => !Number.isFinite(usd))\n .map(([term]) => term)\n .sort()\n const measuredUsd = Object.values(breakdown).reduce((sum, usd) => sum + usd, 0)\n const floorUsd = termUsd(Math.max(0, hosts) * INFRA_COGS_PER_SITE_USD)\n return {\n cogsUsd: Math.max(measuredUsd, floorUsd),\n measuredUsd,\n floorUsd,\n breakdown,\n unbounded,\n }\n}\n\n/** `fullUseCogs(entitlements).cogsUsd` — the figure every guard compares against. */\nexport function fullUseMonthlyCogsUsd(\n entitlements: ResolvedOrgEntitlements,\n options: FullUseCogsOptions = {},\n): number {\n return fullUseCogs(entitlements, options).cogsUsd\n}\n\n/**\n * The full-use cost of an org as it stands: its resolved entitlements, plus\n * the manager and collaborator seats it bought, which no band carries.\n */\nexport function orgFullUseCogs(\n org: Partial<AglynOrgBilling> | null | undefined,\n): FullUseCogsResult {\n return fullUseCogs(resolveOrgEntitlements(org), {\n extraSeats:\n checkSeatQuota(org, 'managers', 0).purchased +\n resolveCollaboratorSeatPool(org).purchased,\n })\n}\n\n/** A price rated against what the bands it buys cost at 100%. */\nexport interface FullUseFloorResult {\n /** The monthly list price before the discount (annual billing as its monthly equivalent). */\n listUsd: number\n /** The same after the discount. */\n discountedUsd: number\n /** The discounted price net of Stripe's fee — what is kept before any cost. */\n netUsd: number\n annual: boolean\n /** `fullUseCogs(…).cogsUsd`; `Infinity` when a band is unbounded. */\n fullUseCogsUsd: number\n /** The multiple of full-use cost the net price must reach. */\n multiple: number\n /** `multiple × fullUseCogsUsd` — the net price the floor asks for. */\n requiredNetUsd: number\n /** `netUsd / fullUseCogsUsd`: 1.30 is cost + 30%. 0 when the cost is unbounded. */\n coverage: number\n ok: boolean\n /** The unbounded terms, when that is why it fails. */\n unbounded: string[]\n}\n\n/**\n * A discount as it reaches a MONTH of the price. A percentage scales every\n * charge alike. An amount comes off each CHARGE, and an annual subscription\n * is charged once for twelve months, so it is a twelfth of that a month.\n */\nfunction monthlyDiscount(\n discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null | undefined,\n annual: boolean,\n): Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null {\n if (!discount) return null\n if (typeof discount.percentOff === 'number') return { percentOff: discount.percentOff }\n if (typeof discount.amountOffUsd === 'number') {\n return { amountOffUsd: annual ? discount.amountOffUsd / 12 : discount.amountOffUsd }\n }\n return null\n}\n\n/**\n * Rate a monthly price — after `discount`, net of Stripe — against `multiple`\n * times a full-use cost. Pure: the callers below bring the price and the cost.\n */\nexport function rateAgainstFullUse(input: {\n listMonthlyUsd: number\n annual: boolean\n cogs: FullUseCogsResult\n multiple: number\n discount?: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null\n}): FullUseFloorResult {\n const listUsd = Math.max(0, Number(input.listMonthlyUsd) || 0)\n const discountedUsd = applyDiscountUsd(listUsd, monthlyDiscount(input.discount, input.annual))\n const netUsd = netOfProcessorFee(discountedUsd, input.annual)\n const fullUseCogsUsd = input.cogs.cogsUsd\n const requiredNetUsd = input.multiple * fullUseCogsUsd\n const coverage =\n Number.isFinite(fullUseCogsUsd) && fullUseCogsUsd > 0 ? netUsd / fullUseCogsUsd : 0\n return {\n listUsd,\n discountedUsd,\n netUsd,\n annual: input.annual,\n fullUseCogsUsd,\n multiple: input.multiple,\n requiredNetUsd,\n coverage,\n ok: netUsd >= requiredNetUsd,\n unbounded: input.cogs.unbounded,\n }\n}\n\n/**\n * An org's subscription after `discount`, against `multiple` × its full-use\n * cost — the enterprise quote floor, where the negotiated `customMonthlyUsd`\n * is the list price. `org` must carry its subscription: a list price of 0\n * rates against nothing and fails, so a caller holding a stale mirror is\n * refused rather than waved through.\n */\nexport function orgFullUseFloor(\n org: Partial<AglynOrgBilling> | null | undefined,\n options: {\n multiple: number\n discount?: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null\n },\n): FullUseFloorResult {\n return rateAgainstFullUse({\n listMonthlyUsd: orgListPriceMonthlyUsd(org),\n annual: org?.subscription?.interval === 'year',\n cogs: orgFullUseCogs(org),\n multiple: options.multiple,\n discount: options.discount,\n })\n}\n\n/** How long a coupon takes its discount off — Stripe's `duration` and `duration_in_months`. */\nexport interface CouponDuration {\n duration?: string | null\n durationInMonths?: number | null\n}\n\n/** Which charges a discount reaches on one billing interval. */\nexport interface DiscountReach {\n /** Stripe's duration, or `unknown` when none is on record — judged as `forever`. */\n duration: 'once' | 'repeating' | 'forever' | 'unknown'\n /** How many charges it comes off; `Infinity` for every one. */\n charges: number\n /** The months one charge pays for: 1 billed monthly, 12 billed annually. */\n monthsPerCharge: 1 | 12\n /** How many of the first twelve months the discounted charges pay for. */\n monthsOfFirstYear: number\n}\n\n/**\n * Which charges a coupon of `duration` comes off (AGL-3473).\n *\n * `once` is the first charge: the first month billed monthly, the whole first\n * year billed annually. `repeating` covers the invoices dated within its\n * months of redemption: N monthly charges, or — billed annually — the annual\n * charges that fall inside them, which is the first one for any N up to 12.\n * `forever` is every charge. A duration not on record is judged as\n * `forever`, the reading that cannot understate what a discount gives away.\n */\nexport function discountReach(\n coupon: CouponDuration | null | undefined,\n annual: boolean,\n): DiscountReach {\n const monthsPerCharge = annual ? 12 : 1\n const months = Math.floor(Number(coupon?.durationInMonths))\n if (coupon?.duration === 'once') {\n return { duration: 'once', charges: 1, monthsPerCharge, monthsOfFirstYear: monthsPerCharge }\n }\n if (coupon?.duration === 'repeating' && months >= 1) {\n return annual\n ? { duration: 'repeating', charges: Math.ceil(months / 12), monthsPerCharge, monthsOfFirstYear: 12 }\n : { duration: 'repeating', charges: months, monthsPerCharge, monthsOfFirstYear: Math.min(months, 12) }\n }\n return {\n duration: coupon?.duration === 'forever' ? 'forever' : 'unknown',\n charges: Number.POSITIVE_INFINITY,\n monthsPerCharge,\n monthsOfFirstYear: 12,\n }\n}\n\n/**\n * A discount against full-use cost on the charges it actually reaches, and on\n * the first year as a whole. `ok` and `coverage` are one DISCOUNTED charge's:\n * the warning is about the charges a coupon touches, never about the ones it\n * does not.\n */\nexport interface DiscountFullUseAssessment extends FullUseFloorResult {\n reach: DiscountReach\n /** What one discounted charge keeps, net of Stripe. */\n chargeNetUsd: number\n /** What the months one charge pays for cost at full use. */\n chargeCogsUsd: number\n /** How far under its full-use cost each discounted charge falls; 0 when it clears. */\n chargeUnderCostUsd: number\n /** The first twelve months together: the discounted charges, the rest at list. */\n firstYearNetUsd: number\n firstYearCogsUsd: number\n /** `firstYearNetUsd / firstYearCogsUsd`; 0 when the cost is unbounded. */\n firstYearCoverage: number\n /** How far under twelve months of full-use cost the first year falls; 0 when covered. */\n firstYearUnderCostUsd: number\n}\n\n/** `cost − net`, never negative; an unbounded cost is an unbounded shortfall. */\nfunction shortfall(cogsUsd: number, netUsd: number): number {\n if (!Number.isFinite(cogsUsd)) return Number.POSITIVE_INFINITY\n return Math.max(0, Math.round((cogsUsd - netUsd) * 100) / 100)\n}\n\n/**\n * Judge a discount on one price against full-use cost — pure: the callers\n * below bring the price, the cost and the coupon.\n */\nexport function assessDiscountAgainstFullUse(input: {\n listMonthlyUsd: number\n annual: boolean\n cogs: FullUseCogsResult\n discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null | undefined\n duration: CouponDuration | null | undefined\n}): DiscountFullUseAssessment {\n const charge = rateAgainstFullUse({ ...input, multiple: FULL_USE_DISCOUNT_MULTIPLE })\n const undiscounted = rateAgainstFullUse({\n ...input,\n discount: null,\n multiple: FULL_USE_DISCOUNT_MULTIPLE,\n })\n const reach = discountReach(input.duration, input.annual)\n const chargeNetUsd = Math.round(charge.netUsd * reach.monthsPerCharge * 100) / 100\n const chargeCogsUsd = charge.fullUseCogsUsd * reach.monthsPerCharge\n const firstYearNetUsd =\n Math.round(\n (charge.netUsd * reach.monthsOfFirstYear +\n undiscounted.netUsd * (12 - reach.monthsOfFirstYear)) *\n 100,\n ) / 100\n const firstYearCogsUsd = charge.fullUseCogsUsd * 12\n return {\n ...charge,\n reach,\n chargeNetUsd,\n chargeCogsUsd,\n chargeUnderCostUsd: shortfall(chargeCogsUsd, chargeNetUsd),\n firstYearNetUsd,\n firstYearCogsUsd,\n firstYearCoverage:\n Number.isFinite(firstYearCogsUsd) && firstYearCogsUsd > 0\n ? firstYearNetUsd / firstYearCogsUsd\n : 0,\n firstYearUnderCostUsd: shortfall(firstYearCogsUsd, firstYearNetUsd),\n }\n}\n\n/**\n * A discount on an org as it bills — its plan, overrides, add-ons, interval\n * and the price it pays — against its full-use cost: the warning behind\n * applying a coupon to an org and behind the winback. A list price of 0 (no\n * subscription on record) is reported as such, never as covered.\n */\nexport function orgDiscountFullUse(\n org: Partial<AglynOrgBilling> | null | undefined,\n discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null | undefined,\n duration: CouponDuration | null | undefined,\n): DiscountFullUseAssessment {\n return assessDiscountAgainstFullUse({\n listMonthlyUsd: orgListPriceMonthlyUsd(org),\n annual: org?.subscription?.interval === 'year',\n cogs: orgFullUseCogs(org),\n discount,\n duration,\n })\n}\n\n/** One plan and interval a coupon could be redeemed on, judged. */\nexport interface CouponFullUseCase extends DiscountFullUseAssessment {\n plan: OrgPlan\n interval: 'month' | 'year'\n}\n\nexport interface CouponFullUseVerdict {\n /** Every case clears: no discounted charge, on any plan, falls under its full-use cost. */\n ok: boolean\n /** Every paid self-serve plan, monthly and annual, judged. */\n cases: CouponFullUseCase[]\n /** The case with the least cover — the one the warning leads with. */\n worst: CouponFullUseCase\n /** The cases under full-use cost, as \"Agency, annual\". */\n under: string[]\n /** The staff warning, with the figures; `null` when every case clears. */\n warning: string | null\n}\n\n/**\n * Judge a coupon or promotion code against full-use cost before it is minted\n * (AGL-3473) — a WARNING for staff, never a refusal.\n *\n * A coupon here carries no plan restriction, so its code can be redeemed on\n * any paid self-serve plan, on either interval, by a customer using\n * everything the plan includes; each case is that plan's list price against\n * its own bands at 100%, on the charges `duration` reaches. Enterprise is\n * quoted per deal and never takes a code at checkout; a coupon applied to one\n * is judged on that org.\n */\nexport function rateCouponAgainstFullUse(\n discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'>,\n duration?: CouponDuration | null,\n): CouponFullUseVerdict {\n const cases: CouponFullUseCase[] = []\n for (const plan of SELF_SERVE_PLANS) {\n if (!(PLAN_PRICING[plan]?.basePriceMonthlyUsd > 0)) continue\n for (const interval of ['month', 'year'] as const) {\n const org = { plan, subscription: { status: 'active', interval } } as never\n cases.push({ plan, interval, ...orgDiscountFullUse(org, discount, duration) })\n }\n }\n const worst = cases.reduce((least, one) => (one.coverage < least.coverage ? one : least))\n const under = cases.filter((one) => !one.ok).map(couponCaseLabel)\n const ok = under.length === 0\n return {\n ok,\n cases,\n worst,\n under,\n warning: ok\n ? null\n : `Under full-use cost on ${under.length} of ${cases.length} plan and billing ` +\n `combinations (${under.join('; ')}). Worst case ` +\n describeDiscountFullUse(worst, couponCaseLabel(worst)),\n }\n}\n\n/**\n * The deepest whole percent off a coupon can take with every discounted\n * charge, on every paid self-serve plan, still covering its full-use cost —\n * or `null` when a plan is under it at list price.\n */\nexport function deepestCouponPercentWithinFullUse(): number | null {\n if (!rateCouponAgainstFullUse({}).ok) return null\n let deepest = 0\n while (deepest < 100 && rateCouponAgainstFullUse({ percentOff: deepest + 1 }).ok) {\n deepest += 1\n }\n return deepest\n}\n\n/** Which charges a reach names, in words. */\nfunction chargesReached(reach: DiscountReach): string {\n const annual = reach.monthsPerCharge === 12\n if (reach.duration === 'unknown') return 'every charge (no duration on record)'\n if (!Number.isFinite(reach.charges)) {\n return annual ? 'every annual charge' : 'every monthly charge'\n }\n if (annual) {\n return reach.charges === 1\n ? 'the first annual charge (the whole first year)'\n : `the first ${reach.charges} annual charges`\n }\n return reach.charges === 1\n ? \"the first month's charge\"\n : `the first ${reach.charges} monthly charges`\n}\n\n/**\n * The staff sentence for a discount against full-use cost: which charges it\n * reaches, what each keeps against what its months cost, how far under, and\n * the first year as a whole. Staff-facing only — it names Aglyn's cost.\n */\nexport function describeDiscountFullUse(\n result: DiscountFullUseAssessment,\n subject?: string,\n): string {\n const about = subject ? `${subject}: ` : ''\n if (result.unbounded.length) {\n return (\n `${about}cannot be costed — ${result.unbounded.join(', ')} ` +\n `${result.unbounded.length === 1 ? 'is' : 'are'} unbounded, so the full-use cost is too.`\n )\n }\n if (!(result.listUsd > 0)) {\n return `${about}no subscription price is on record to judge the discount against.`\n }\n const each =\n `${chargesReached(result.reach)}: each keeps ${usd(result.chargeNetUsd)} net of ` +\n `Stripe against ${usd(result.chargeCogsUsd)} of full-use cost ` +\n `(${result.coverage.toFixed(2)}×`\n if (result.ok) return `${about}clears full-use cost on ${each}).`\n const year =\n `It touches ${result.reach.monthsOfFirstYear} of the first 12 months; the first ` +\n `year as a whole covers ${result.firstYearCoverage.toFixed(2)}×` +\n (result.firstYearUnderCostUsd > 0\n ? ` (${usd(result.firstYearUnderCostUsd)} under).`\n : '.')\n return (\n `${about}under full-use cost on ${each}, ${usd(result.chargeUnderCostUsd)} under ` +\n `each). ${year}`\n )\n}\n\n/** Two decimals, or \"unbounded\". */\nfunction usd(value: number): string {\n return Number.isFinite(value) ? `$${value.toFixed(2)}` : 'unbounded'\n}\n\n/**\n * The sentence an enterprise quote refusal or verdict states: the floor, and\n * the figures that missed it. Staff-facing only — it names Aglyn's cost.\n */\nexport function describeFullUseFloor(\n result: FullUseFloorResult,\n subject?: string,\n): string {\n const floor =\n result.multiple === 1\n ? 'its full-use cost'\n : `${result.multiple.toFixed(2)}× its full-use cost`\n const about = subject ? `${subject}: ` : ''\n if (result.unbounded.length) {\n return (\n `${about}cannot be rated — ${result.unbounded.join(', ')} ` +\n `${result.unbounded.length === 1 ? 'is' : 'are'} unbounded, so the full-use cost is too. ` +\n 'Bound the band with an entitlement override first.'\n )\n }\n return (\n `${about}keeps ${usd(result.netUsd)}/mo net of Stripe ` +\n `against ${usd(result.requiredNetUsd)} (${floor}, ${usd(result.fullUseCogsUsd)}) — ` +\n `${result.coverage.toFixed(2)}× full-use cost.`\n )\n}\n\n/** \"Agency, annual\" — how a coupon case names itself. */\nexport function couponCaseLabel(one: Pick<CouponFullUseCase, 'plan' | 'interval'>): string {\n return `${PLAN_LABELS[one.plan] ?? one.plan}, ${one.interval === 'year' ? 'annual' : 'monthly'}`\n}\n"],"names":["ESTIMATED_PAGE_TRANSFER_BYTES","INFRA_COGS_PER_SITE_USD","METERED_MARKUP","ORG_COGS_UNIT_RATES_USD","PAGE_VIEW_CDN_REQUEST_COST_USD","PLAN_LABELS","PLAN_PRICING","SELF_SERVE_PLANS","applyDiscountUsd","checkSeatQuota","netOfProcessorFee","orgListPriceMonthlyUsd","resolveCollaboratorSeatPool","resolveOrgEntitlements","planQuotaOf","pluginCostAxes","pluginUsageBands","SEAT_COGS_USD_PER_MONTH","DAYS_PER_FULL_MONTH","VIEWS_PER_GB","FULL_USE_QUOTE_MULTIPLE","FULL_USE_DISCOUNT_MULTIPLE","termUsd","value","Number","isFinite","POSITIVE_INFINITY","declaredBandUnitCostUsd","band","unitCostUsd","measuredBy","fields","fallbackFields","axis","find","candidate","some","field","includes","Error","id","rate","undefined","fullUseCogs","entitlements","options","rates","hosts","hostLimit","quota","key","extraSeats","Math","max","breakdown","mediaStorage","storagePerHostMb","storagePerGbMonth","bandwidth","bandwidthGb","perPageView","cdnRequests","dataStorage","dataStorageMbPerOrg","dataStoragePerGbMonth","apiRequests","apiRequestsPerMonth","perApiRequest","emailSends","emailSendsPerMonth","perEmailSend","units","entitlement","perHost","membersPerHost","managersPerOrg","unbounded","Object","entries","filter","usd","map","term","sort","measuredUsd","values","reduce","sum","floorUsd","cogsUsd","fullUseMonthlyCogsUsd","orgFullUseCogs","org","purchased","monthlyDiscount","discount","annual","percentOff","amountOffUsd","rateAgainstFullUse","input","listUsd","listMonthlyUsd","discountedUsd","netUsd","fullUseCogsUsd","cogs","requiredNetUsd","multiple","coverage","ok","orgFullUseFloor","subscription","interval","discountReach","coupon","monthsPerCharge","months","floor","durationInMonths","duration","charges","monthsOfFirstYear","ceil","min","shortfall","round","assessDiscountAgainstFullUse","charge","undiscounted","reach","chargeNetUsd","chargeCogsUsd","firstYearNetUsd","firstYearCogsUsd","chargeUnderCostUsd","firstYearCoverage","firstYearUnderCostUsd","orgDiscountFullUse","rateCouponAgainstFullUse","cases","plan","basePriceMonthlyUsd","status","push","worst","least","one","under","couponCaseLabel","length","warning","join","describeDiscountFullUse","deepestCouponPercentWithinFullUse","deepest","chargesReached","result","subject","about","each","toFixed","year","describeFullUseFloor"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,0EAA0E;AAC1E,6EAA6E;AAC7E,iEAAiE;;AAEjE,SACEA,6BAA6B,EAC7BC,uBAAuB,EACvBC,cAAc,EACdC,uBAAuB,EACvBC,8BAA8B,EAC9BC,WAAW,EACXC,YAAY,EACZC,gBAAgB,EAChBC,gBAAgB,EAChBC,cAAc,EACdC,iBAAiB,EACjBC,sBAAsB,EACtBC,2BAA2B,EAC3BC,sBAAsB,QAEjB,yBAAqB;AAC5B,SAASC,WAAW,QAAQ,gDAA4C;AACxE,SACEC,cAAc,EACdC,gBAAgB,QAEX,yCAAqC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BC,GAED;;;;;;;CAOC,GACD,OAAO,MAAMC,0BAA0B,KAAI;AAE3C;;;CAGC,GACD,MAAMC,sBAAsB;AAE5B,0FAA0F,GAC1F,MAAMC,eAAe,AAAC,OAAO,OAAO,OAA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AEJ;IACA,OACE,GAAGS,MAAM,MAAM,EAAE/E,IAAI6E,OAAOrD,MAAM,EAAE,kBAAkB,CAAC,GACvD,CAAC,QAAQ,EAAExB,IAAI6E,OAAOlD,cAAc,EAAE,EAAE,EAAEW,MAAM,EAAE,EAAEtC,IAAI6E,OAAOpD,cAAc,EAAE,IAAI,CAAC,GACpF,GAAGoD,OAAOhD,QAAQ,CAACoD,OAAO,CAAC,GAAG,gBAAgB,CAAC;AAEnD;AAEA,uDAAuD,GACvD,OAAO,SAASZ,gBAAgBF,GAAiD;QACrE9I;IAAV,OAAO,IAAGA,wBAAAA,WAAW,CAAC8I,IAAIN,IAAI,CAAC,YAArBxI,wBAAyB8I,IAAIN,IAAI,CAAC,EAAE,EAAEM,IAAIlC,QAAQ,KAAK,SAAS,WAAW,WAAW;AAClG"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/full-use-cost.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Imported from BOTH graphs — the staff pages (client) and the App Routes\n// that refuse a quote or a discount — so it may import neither entry barrel,\n// for the reason `margin-utilization.ts` states at its own head.\nimport type { AglynOrgBilling, OrgDiscount, OrgPlan } from '../foundation'\nimport {\n ESTIMATED_PAGE_TRANSFER_BYTES,\n INFRA_COGS_PER_SITE_USD,\n METERED_MARKUP,\n ORG_COGS_UNIT_RATES_USD,\n PAGE_VIEW_CDN_REQUEST_COST_USD,\n PLAN_LABELS,\n PLAN_PRICING,\n SELF_SERVE_PLANS,\n applyDiscountUsd,\n checkSeatQuota,\n discountReachMonthlyUsd,\n netOfProcessorFee,\n orgListPriceMonthlyUsd,\n resolveCollaboratorSeatPool,\n resolveOrgEntitlements,\n type OrgDiscountTerms,\n type ResolvedOrgEntitlements,\n} from './plan-entitlements'\nimport { planQuotaOf } from '../plugin-manager/plugin-plan-entitlements'\nimport {\n pluginCostAxes,\n pluginUsageBands,\n type ResolvedPluginUsageBand,\n} from '../plugin-manager/plugin-usage-axes'\n\n/**\n * WHAT A WORKSPACE COSTS IF IT SPENDS EXACTLY WHAT IT BOUGHT (AGL-3473).\n *\n * `orgMonthlyCogsUsd` prices what an org DID use, from its rollup. Every\n * guard that rated a price against it — the discount guardrail, the\n * enterprise quote card — therefore approved deals on the strength of how\n * little the customer had used so far, and a deal is a promise about the\n * whole allowance. Agency at 20% off read \"ok, 75.5%\" against its measured\n * month while sitting under what its bands cost at 100%.\n *\n * This is the same multiplication `tier-margin-floor.spec.ts` does for the\n * price list — every band at 100%, at the rates the platform's own model\n * uses — over RESOLVED entitlements, so a staff override, a comp's plan and\n * a purchased add-on all cost what they deliver. That spec holds its own\n * independent model and asserts this function agrees with it on every plan.\n *\n * Two readers, held to it differently. An enterprise quote must clear\n * `FULL_USE_QUOTE_MULTIPLE` × the cost and is refused below it. A coupon or\n * discount is judged on the charges it reaches and WARNED about below 1× —\n * never refused, because a first-month or first-year discount that spends\n * cost to close a deal is a decision staff are allowed to make.\n *\n * ## An unbounded band costs Infinity, never 0\n *\n * A band that is `UNLIMITED` cannot be costed, and every cost model in this\n * repo that scored one as zero reported the largest line item on a plan as\n * contributing nothing. So a non-finite term — or one that is `NaN` because a\n * zero met an infinity — is `Infinity`, the total is `Infinity`, and no price\n * clears it. The term is named in `unbounded` so a refusal or a warning can\n * say which band to bound.\n */\n\n/**\n * What one console seat costs to serve for a month — about 60,000 reads and\n * 10,000 writes at `nam5` list prices, ≈$0.054, carried as $0.06 (the Drive\n * pricing decision of 2026-09-05).\n *\n * NOT in `ORG_COGS_UNIT_RATES_USD`: no rollup meter counts seat-months, so a\n * rate there would be one no axis of `orgMonthlyCogsUsd` reads.\n */\nexport const SEAT_COGS_USD_PER_MONTH = 0.06\n\n/**\n * Days a daily band is spent at 100% in a month: the one-to-one email cap is\n * a pace per UTC day, and the whole month at that pace is thirty of them.\n */\nconst DAYS_PER_FULL_MONTH = 30\n\n/** Page views one GB of included bandwidth buys — `pageViewsFromBandwidthGb`'s constant. */\nconst VIEWS_PER_GB = (1024 * 1024 * 1024) / ESTIMATED_PAGE_TRANSFER_BYTES\n\n/**\n * How many times its full-use cost an enterprise quote must cover, net of\n * Stripe: cost + 30%, the markup every metered overage already carries, so a\n * negotiated deal earns what the price list does.\n */\nexport const FULL_USE_QUOTE_MULTIPLE = METERED_MARKUP\n\n/**\n * The full-use cost a discounted charge is judged against, net of Stripe: 1×.\n * A discount that spends only the 30% a price carries above cost clears it;\n * one that reaches into the cost is WARNED about, never refused — a coupon is\n * a tool for closing a deal, and staff choose to spend cost on one knowingly.\n */\nexport const FULL_USE_DISCOUNT_MULTIPLE = 1\n\nexport interface FullUseCogsResult {\n /** `measuredUsd` or the per-site floor, whichever is larger; `Infinity` when any band is unbounded. */\n cogsUsd: number\n /** The sum of every term at 100% of its band. */\n measuredUsd: number\n /** `INFRA_COGS_PER_SITE_USD × hostLimit` — the sites sold, not the sites built. */\n floorUsd: number\n /** Every term, in USD a month, for showing the working. */\n breakdown: Record<string, number>\n /** The terms whose band is unbounded, sorted. Empty when the plan can be costed. */\n unbounded: string[]\n}\n\nexport interface FullUseCogsOptions {\n /**\n * Seats bought on top of the plan's — the org-wide manager add-on and the\n * collaborator pool, neither of which `resolveOrgEntitlements` folds into\n * a band.\n */\n extraSeats?: number\n}\n\n/** A term that cannot be costed is unbounded, never free. */\nfunction termUsd(value: number): number {\n return Number.isFinite(value) ? value : Number.POSITIVE_INFINITY\n}\n\n/**\n * The USD one unit of a plugin's declared band costs.\n *\n * A band sold in a unit OF cost declares that unit's price (`unitCostUsd`).\n * Every other band is priced by the cost axis that records the same rollup\n * field the band is measured by — the meter `orgMonthlyCogsUsd` already\n * prices its usage on — at that axis's `ORG_COGS_UNIT_RATES_USD` rate, or at\n * ×1 where the axis records dollars.\n *\n * ⚑ A band no axis records, or an axis naming a rate core does not carry,\n * THROWS. Pricing it at zero would make a plan cost less than it does, which\n * is the direction that approves a quote.\n */\nfunction declaredBandUnitCostUsd(band: ResolvedPluginUsageBand): number {\n if (typeof band.unitCostUsd === 'number') return band.unitCostUsd\n const measuredBy = [...band.fields, ...(band.fallbackFields ?? [])]\n const axis = pluginCostAxes().find((candidate) =>\n measuredBy.some(\n (field) =>\n candidate.fields.includes(field) ||\n (candidate.fallbackFields ?? []).includes(field),\n ),\n )\n if (!axis) {\n throw new Error(\n `usage band \"${band.id}\" is measured by no declared cost axis, so its full-use cost has no rate`,\n )\n }\n if (axis.rate === undefined) return 1\n const rate = (ORG_COGS_UNIT_RATES_USD as Record<string, number>)[axis.rate]\n if (typeof rate !== 'number' || !Number.isFinite(rate)) {\n throw new Error(\n `cost axis \"${axis.id}\" names the rate \"${axis.rate}\", which ORG_COGS_UNIT_RATES_USD does not carry`,\n )\n }\n return rate\n}\n\n/**\n * Every cost a workspace's RESOLVED bands imply at 100%, per month.\n *\n * The platform's own bands, each at the rate `orgMonthlyCogsUsd` prices its\n * meter on: media storage per site (× `hostLimit`), bandwidth at its weight\n * (`perPageView`) and at its CDN requests (`PAGE_VIEW_CDN_REQUEST_COST_USD`),\n * stored data (`dataStorageMbPerOrg`), API requests and every email the\n * campaign band sends. Then every band a plugin declares\n * (`plugin-usage-axes.ts`), a per-site one expanded by `hostLimit`. Then the\n * two costs no meter records:\n *\n * - SEATS — every collaborator each site admits on every site\n * (`membersPerHost × hostLimit`), the org's managers (`managersPerOrg`)\n * and any bought on top, at `SEAT_COGS_USD_PER_MONTH`;\n * - ONE-TO-ONE EMAIL — the CRM's daily cap spent every day of the month, at\n * the rate every other send costs.\n *\n * `INFRA_COGS_PER_SITE_USD × hostLimit` is a FLOOR rather than an added\n * term, exactly as in `orgMonthlyCogsUsd`.\n */\nexport function fullUseCogs(\n entitlements: ResolvedOrgEntitlements,\n options: FullUseCogsOptions = {},\n): FullUseCogsResult {\n const rates = ORG_COGS_UNIT_RATES_USD\n const hosts = entitlements.hostLimit\n const quota = (key: string) => planQuotaOf(entitlements, key)\n const extraSeats = Math.max(0, Number(options.extraSeats ?? 0) || 0)\n const breakdown: Record<string, number> = {\n mediaStorage: termUsd(\n ((hosts * entitlements.storagePerHostMb) / 1024) * rates.storagePerGbMonth,\n ),\n bandwidth: termUsd(entitlements.bandwidthGb * VIEWS_PER_GB * rates.perPageView),\n cdnRequests: termUsd(\n entitlements.bandwidthGb * VIEWS_PER_GB * PAGE_VIEW_CDN_REQUEST_COST_USD,\n ),\n dataStorage: termUsd(\n (entitlements.dataStorageMbPerOrg / 1024) * rates.dataStoragePerGbMonth,\n ),\n apiRequests: termUsd(entitlements.apiRequestsPerMonth * rates.perApiRequest),\n emailSends: termUsd(entitlements.emailSendsPerMonth * rates.perEmailSend),\n }\n for (const band of pluginUsageBands()) {\n const units = quota(band.entitlement) * (band.perHost ? hosts : 1)\n breakdown[band.id] = termUsd(units * declaredBandUnitCostUsd(band))\n }\n breakdown['seats'] = termUsd(\n (entitlements.membersPerHost * hosts + entitlements.managersPerOrg + extraSeats) *\n SEAT_COGS_USD_PER_MONTH,\n )\n // Read by key, as `checkCrmEmailQuota` reads it: a daily pace is not a\n // monthly band, so no usage-band declaration carries it.\n breakdown['crmEmail'] = termUsd(\n quota('crmEmailsPerDay') * DAYS_PER_FULL_MONTH * rates.perEmailSend,\n )\n const unbounded = Object.entries(breakdown)\n .filter(([, usd]) => !Number.isFinite(usd))\n .map(([term]) => term)\n .sort()\n const measuredUsd = Object.values(breakdown).reduce((sum, usd) => sum + usd, 0)\n const floorUsd = termUsd(Math.max(0, hosts) * INFRA_COGS_PER_SITE_USD)\n return {\n cogsUsd: Math.max(measuredUsd, floorUsd),\n measuredUsd,\n floorUsd,\n breakdown,\n unbounded,\n }\n}\n\n/** `fullUseCogs(entitlements).cogsUsd` — the figure every guard compares against. */\nexport function fullUseMonthlyCogsUsd(\n entitlements: ResolvedOrgEntitlements,\n options: FullUseCogsOptions = {},\n): number {\n return fullUseCogs(entitlements, options).cogsUsd\n}\n\n/**\n * The full-use cost of an org as it stands: its resolved entitlements, plus\n * the manager and collaborator seats it bought, which no band carries.\n */\nexport function orgFullUseCogs(\n org: Partial<AglynOrgBilling> | null | undefined,\n): FullUseCogsResult {\n return fullUseCogs(resolveOrgEntitlements(org), {\n extraSeats:\n checkSeatQuota(org, 'managers', 0).purchased +\n resolveCollaboratorSeatPool(org).purchased,\n })\n}\n\n/** A price rated against what the bands it buys cost at 100%. */\nexport interface FullUseFloorResult {\n /** The monthly list price before the discount (annual billing as its monthly equivalent). */\n listUsd: number\n /** The same after the discount. */\n discountedUsd: number\n /** The discounted price net of Stripe's fee — what is kept before any cost. */\n netUsd: number\n annual: boolean\n /** `fullUseCogs(…).cogsUsd`; `Infinity` when a band is unbounded. */\n fullUseCogsUsd: number\n /** The multiple of full-use cost the net price must reach. */\n multiple: number\n /** `multiple × fullUseCogsUsd` — the net price the floor asks for. */\n requiredNetUsd: number\n /** `netUsd / fullUseCogsUsd`: 1.30 is cost + 30%. 0 when the cost is unbounded. */\n coverage: number\n ok: boolean\n /** The unbounded terms, when that is why it fails. */\n unbounded: string[]\n}\n\n/**\n * A discount as it reaches a MONTH of the price. A percentage scales every\n * charge alike. An amount comes off each CHARGE, and an annual subscription\n * is charged once for twelve months, so it is a twelfth of that a month.\n */\nfunction monthlyDiscount(\n discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null | undefined,\n annual: boolean,\n): Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null {\n if (!discount) return null\n if (typeof discount.percentOff === 'number') return { percentOff: discount.percentOff }\n if (typeof discount.amountOffUsd === 'number') {\n return { amountOffUsd: annual ? discount.amountOffUsd / 12 : discount.amountOffUsd }\n }\n return null\n}\n\n/**\n * Rate a monthly price — after `discount`, net of Stripe — against `multiple`\n * times a full-use cost. Pure: the callers below bring the price and the cost.\n */\nexport function rateAgainstFullUse(input: {\n listMonthlyUsd: number\n annual: boolean\n cogs: FullUseCogsResult\n multiple: number\n discount?: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null\n /**\n * The part of the monthly list price the discount reaches (AGL-4161): the\n * base plan line for a base-price coupon, the rest billing in full.\n * Absent, all of it.\n */\n reachMonthlyUsd?: number\n}): FullUseFloorResult {\n const listUsd = Math.max(0, Number(input.listMonthlyUsd) || 0)\n const reachUsd =\n typeof input.reachMonthlyUsd === 'number'\n ? Math.min(listUsd, Math.max(0, input.reachMonthlyUsd))\n : listUsd\n const monthly = monthlyDiscount(input.discount, input.annual)\n const discountedUsd =\n reachUsd >= listUsd\n ? applyDiscountUsd(listUsd, monthly)\n : Math.round((listUsd - reachUsd + applyDiscountUsd(reachUsd, monthly)) * 100) / 100\n const netUsd = netOfProcessorFee(discountedUsd, input.annual)\n const fullUseCogsUsd = input.cogs.cogsUsd\n const requiredNetUsd = input.multiple * fullUseCogsUsd\n const coverage =\n Number.isFinite(fullUseCogsUsd) && fullUseCogsUsd > 0 ? netUsd / fullUseCogsUsd : 0\n return {\n listUsd,\n discountedUsd,\n netUsd,\n annual: input.annual,\n fullUseCogsUsd,\n multiple: input.multiple,\n requiredNetUsd,\n coverage,\n ok: netUsd >= requiredNetUsd,\n unbounded: input.cogs.unbounded,\n }\n}\n\n/**\n * An org's subscription after `discount`, against `multiple` × its full-use\n * cost — the enterprise quote floor, where the negotiated `customMonthlyUsd`\n * is the list price. `org` must carry its subscription: a list price of 0\n * rates against nothing and fails, so a caller holding a stale mirror is\n * refused rather than waved through.\n */\nexport function orgFullUseFloor(\n org: Partial<AglynOrgBilling> | null | undefined,\n options: {\n multiple: number\n discount?: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null\n },\n): FullUseFloorResult {\n return rateAgainstFullUse({\n listMonthlyUsd: orgListPriceMonthlyUsd(org),\n annual: org?.subscription?.interval === 'year',\n cogs: orgFullUseCogs(org),\n multiple: options.multiple,\n discount: options.discount,\n })\n}\n\n/** How long a coupon takes its discount off — Stripe's `duration` and `duration_in_months`. */\nexport interface CouponDuration {\n duration?: string | null\n durationInMonths?: number | null\n}\n\n/** Which charges a discount reaches on one billing interval. */\nexport interface DiscountReach {\n /** Stripe's duration, or `unknown` when none is on record — judged as `forever`. */\n duration: 'once' | 'repeating' | 'forever' | 'unknown'\n /** How many charges it comes off; `Infinity` for every one. */\n charges: number\n /** The months one charge pays for: 1 billed monthly, 12 billed annually. */\n monthsPerCharge: 1 | 12\n /** How many of the first twelve months the discounted charges pay for. */\n monthsOfFirstYear: number\n}\n\n/**\n * Which charges a coupon of `duration` comes off (AGL-3473).\n *\n * `once` is the first charge: the first month billed monthly, the whole first\n * year billed annually. `repeating` covers the invoices dated within its\n * months of redemption: N monthly charges, or — billed annually — the annual\n * charges that fall inside them, which is the first one for any N up to 12.\n * `forever` is every charge. A duration not on record is judged as\n * `forever`, the reading that cannot understate what a discount gives away.\n */\nexport function discountReach(\n coupon: CouponDuration | null | undefined,\n annual: boolean,\n): DiscountReach {\n const monthsPerCharge = annual ? 12 : 1\n const months = Math.floor(Number(coupon?.durationInMonths))\n if (coupon?.duration === 'once') {\n return { duration: 'once', charges: 1, monthsPerCharge, monthsOfFirstYear: monthsPerCharge }\n }\n if (coupon?.duration === 'repeating' && months >= 1) {\n return annual\n ? { duration: 'repeating', charges: Math.ceil(months / 12), monthsPerCharge, monthsOfFirstYear: 12 }\n : { duration: 'repeating', charges: months, monthsPerCharge, monthsOfFirstYear: Math.min(months, 12) }\n }\n return {\n duration: coupon?.duration === 'forever' ? 'forever' : 'unknown',\n charges: Number.POSITIVE_INFINITY,\n monthsPerCharge,\n monthsOfFirstYear: 12,\n }\n}\n\n/**\n * A discount against full-use cost on the charges it actually reaches, and on\n * the first year as a whole. `ok` and `coverage` are one DISCOUNTED charge's:\n * the warning is about the charges a coupon touches, never about the ones it\n * does not.\n */\nexport interface DiscountFullUseAssessment extends FullUseFloorResult {\n reach: DiscountReach\n /** What one discounted charge keeps, net of Stripe. */\n chargeNetUsd: number\n /** What the months one charge pays for cost at full use. */\n chargeCogsUsd: number\n /** How far under its full-use cost each discounted charge falls; 0 when it clears. */\n chargeUnderCostUsd: number\n /** The first twelve months together: the discounted charges, the rest at list. */\n firstYearNetUsd: number\n firstYearCogsUsd: number\n /** `firstYearNetUsd / firstYearCogsUsd`; 0 when the cost is unbounded. */\n firstYearCoverage: number\n /** How far under twelve months of full-use cost the first year falls; 0 when covered. */\n firstYearUnderCostUsd: number\n}\n\n/** `cost − net`, never negative; an unbounded cost is an unbounded shortfall. */\nfunction shortfall(cogsUsd: number, netUsd: number): number {\n if (!Number.isFinite(cogsUsd)) return Number.POSITIVE_INFINITY\n return Math.max(0, Math.round((cogsUsd - netUsd) * 100) / 100)\n}\n\n/**\n * Judge a discount on one price against full-use cost — pure: the callers\n * below bring the price, the cost and the coupon.\n */\nexport function assessDiscountAgainstFullUse(input: {\n listMonthlyUsd: number\n annual: boolean\n cogs: FullUseCogsResult\n discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null | undefined\n duration: CouponDuration | null | undefined\n /** What the discount reaches of the list price (AGL-4161); absent, all of it. */\n reachMonthlyUsd?: number\n}): DiscountFullUseAssessment {\n const charge = rateAgainstFullUse({ ...input, multiple: FULL_USE_DISCOUNT_MULTIPLE })\n const undiscounted = rateAgainstFullUse({\n ...input,\n discount: null,\n multiple: FULL_USE_DISCOUNT_MULTIPLE,\n })\n const reach = discountReach(input.duration, input.annual)\n const chargeNetUsd = Math.round(charge.netUsd * reach.monthsPerCharge * 100) / 100\n const chargeCogsUsd = charge.fullUseCogsUsd * reach.monthsPerCharge\n const firstYearNetUsd =\n Math.round(\n (charge.netUsd * reach.monthsOfFirstYear +\n undiscounted.netUsd * (12 - reach.monthsOfFirstYear)) *\n 100,\n ) / 100\n const firstYearCogsUsd = charge.fullUseCogsUsd * 12\n return {\n ...charge,\n reach,\n chargeNetUsd,\n chargeCogsUsd,\n chargeUnderCostUsd: shortfall(chargeCogsUsd, chargeNetUsd),\n firstYearNetUsd,\n firstYearCogsUsd,\n firstYearCoverage:\n Number.isFinite(firstYearCogsUsd) && firstYearCogsUsd > 0\n ? firstYearNetUsd / firstYearCogsUsd\n : 0,\n firstYearUnderCostUsd: shortfall(firstYearCogsUsd, firstYearNetUsd),\n }\n}\n\n/**\n * A discount on an org as it bills — its plan, overrides, add-ons, interval\n * and the price it pays — against its full-use cost: the warning behind\n * applying a coupon to an org and behind the winback. A list price of 0 (no\n * subscription on record) is reported as such, never as covered. A\n * base-price discount (AGL-4161) comes off the base plan line alone, so the\n * add-ons are judged at the price they bill.\n */\nexport function orgDiscountFullUse(\n org: Partial<AglynOrgBilling> | null | undefined,\n discount: OrgDiscountTerms | null | undefined,\n duration: CouponDuration | null | undefined,\n): DiscountFullUseAssessment {\n const listMonthlyUsd = orgListPriceMonthlyUsd(org)\n return assessDiscountAgainstFullUse({\n listMonthlyUsd,\n annual: org?.subscription?.interval === 'year',\n cogs: orgFullUseCogs(org),\n discount,\n duration,\n reachMonthlyUsd: discountReachMonthlyUsd(org, discount, listMonthlyUsd),\n })\n}\n\n/** One plan and interval a coupon could be redeemed on, judged. */\nexport interface CouponFullUseCase extends DiscountFullUseAssessment {\n plan: OrgPlan\n interval: 'month' | 'year'\n}\n\nexport interface CouponFullUseVerdict {\n /** Every case clears: no discounted charge, on any plan, falls under its full-use cost. */\n ok: boolean\n /** Every paid self-serve plan the coupon reaches, monthly and annual, judged. */\n cases: CouponFullUseCase[]\n /** The case with the least cover — the one the warning leads with. */\n worst: CouponFullUseCase\n /** The cases under full-use cost, as \"Agency, annual\". */\n under: string[]\n /** The staff warning, with the figures; `null` when every case clears. */\n warning: string | null\n}\n\n/**\n * Judge a coupon or promotion code against full-use cost before it is minted\n * (AGL-3473) — a WARNING for staff, never a refusal.\n *\n * A coupon with no plan restriction can be redeemed on any paid self-serve\n * plan, on either interval, by a customer using everything the plan\n * includes; each case is that plan's list price against its own bands at\n * 100%, on the charges `duration` reaches. Enterprise is quoted per deal and\n * never takes a code at checkout; a coupon applied to one is judged on that\n * org.\n *\n * `plans` narrows the cases to the plans a coupon is limited to (AGL-4159): a\n * coupon that takes its discount off one plan's base price is redeemed on\n * that plan only, so the others are not its risk. Each case still prices the\n * plan's own list price, which is exactly the line such a coupon reaches —\n * add-ons and usage past the bands bill in full. A restriction that names no\n * paid self-serve plan is judged on all of them, the cautious reading.\n */\nexport function rateCouponAgainstFullUse(\n discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'>,\n duration?: CouponDuration | null,\n plans?: readonly OrgPlan[] | null,\n): CouponFullUseVerdict {\n const paid = SELF_SERVE_PLANS.filter((plan) => PLAN_PRICING[plan]?.basePriceMonthlyUsd > 0)\n const limited = plans?.length ? paid.filter((plan) => plans.includes(plan)) : []\n const cases: CouponFullUseCase[] = []\n for (const plan of limited.length ? limited : paid) {\n for (const interval of ['month', 'year'] as const) {\n const org = { plan, subscription: { status: 'active', interval } } as never\n cases.push({ plan, interval, ...orgDiscountFullUse(org, discount, duration) })\n }\n }\n const worst = cases.reduce((least, one) => (one.coverage < least.coverage ? one : least))\n const under = cases.filter((one) => !one.ok).map(couponCaseLabel)\n const ok = under.length === 0\n return {\n ok,\n cases,\n worst,\n under,\n warning: ok\n ? null\n : `Under full-use cost on ${under.length} of ${cases.length} plan and billing ` +\n `combinations (${under.join('; ')}). Worst case ` +\n describeDiscountFullUse(worst, couponCaseLabel(worst)),\n }\n}\n\n/**\n * The deepest whole percent off a coupon can take with every discounted\n * charge, on every paid self-serve plan, still covering its full-use cost —\n * or `null` when a plan is under it at list price.\n */\nexport function deepestCouponPercentWithinFullUse(): number | null {\n if (!rateCouponAgainstFullUse({}).ok) return null\n let deepest = 0\n while (deepest < 100 && rateCouponAgainstFullUse({ percentOff: deepest + 1 }).ok) {\n deepest += 1\n }\n return deepest\n}\n\n/** Which charges a reach names, in words. */\nfunction chargesReached(reach: DiscountReach): string {\n const annual = reach.monthsPerCharge === 12\n if (reach.duration === 'unknown') return 'every charge (no duration on record)'\n if (!Number.isFinite(reach.charges)) {\n return annual ? 'every annual charge' : 'every monthly charge'\n }\n if (annual) {\n return reach.charges === 1\n ? 'the first annual charge (the whole first year)'\n : `the first ${reach.charges} annual charges`\n }\n return reach.charges === 1\n ? \"the first month's charge\"\n : `the first ${reach.charges} monthly charges`\n}\n\n/**\n * The staff sentence for a discount against full-use cost: which charges it\n * reaches, what each keeps against what its months cost, how far under, and\n * the first year as a whole. Staff-facing only — it names Aglyn's cost.\n */\nexport function describeDiscountFullUse(\n result: DiscountFullUseAssessment,\n subject?: string,\n): string {\n const about = subject ? `${subject}: ` : ''\n if (result.unbounded.length) {\n return (\n `${about}cannot be costed — ${result.unbounded.join(', ')} ` +\n `${result.unbounded.length === 1 ? 'is' : 'are'} unbounded, so the full-use cost is too.`\n )\n }\n if (!(result.listUsd > 0)) {\n return `${about}no subscription price is on record to judge the discount against.`\n }\n const each =\n `${chargesReached(result.reach)}: each keeps ${usd(result.chargeNetUsd)} net of ` +\n `Stripe against ${usd(result.chargeCogsUsd)} of full-use cost ` +\n `(${result.coverage.toFixed(2)}×`\n if (result.ok) return `${about}clears full-use cost on ${each}).`\n const year =\n `It touches ${result.reach.monthsOfFirstYear} of the first 12 months; the first ` +\n `year as a whole covers ${result.firstYearCoverage.toFixed(2)}×` +\n (result.firstYearUnderCostUsd > 0\n ? ` (${usd(result.firstYearUnderCostUsd)} under).`\n : '.')\n return (\n `${about}under full-use cost on ${each}, ${usd(result.chargeUnderCostUsd)} under ` +\n `each). ${year}`\n )\n}\n\n/** Two decimals, or \"unbounded\". */\nfunction usd(value: number): string {\n return Number.isFinite(value) ? `$${value.toFixed(2)}` : 'unbounded'\n}\n\n/**\n * The sentence an enterprise quote refusal or verdict states: the floor, and\n * the figures that missed it. Staff-facing only — it names Aglyn's cost.\n */\nexport function describeFullUseFloor(\n result: FullUseFloorResult,\n subject?: string,\n): string {\n const floor =\n result.multiple === 1\n ? 'its full-use cost'\n : `${result.multiple.toFixed(2)}× its full-use cost`\n const about = subject ? `${subject}: ` : ''\n if (result.unbounded.length) {\n return (\n `${about}cannot be rated — ${result.unbounded.join(', ')} ` +\n `${result.unbounded.length === 1 ? 'is' : 'are'} unbounded, so the full-use cost is too. ` +\n 'Bound the band with an entitlement override first.'\n )\n }\n return (\n `${about}keeps ${usd(result.netUsd)}/mo net of Stripe ` +\n `against ${usd(result.requiredNetUsd)} (${floor}, ${usd(result.fullUseCogsUsd)}) — ` +\n `${result.coverage.toFixed(2)}× full-use cost.`\n )\n}\n\n/** \"Agency, annual\" — how a coupon case names itself. */\nexport function couponCaseLabel(one: Pick<CouponFullUseCase, 'plan' | 'interval'>): string {\n return `${PLAN_LABELS[one.plan] ?? one.plan}, ${one.interval === 'year' ? 'annual' : 'monthly'}`\n}\n"],"names":["ESTIMATED_PAGE_TRANSFER_BYTES","INFRA_COGS_PER_SITE_USD","METERED_MARKUP","ORG_COGS_UNIT_RATES_USD","PAGE_VIEW_CDN_REQUEST_COST_USD","PLAN_LABELS","PLAN_PRICING","SELF_SERVE_PLANS","applyDiscountUsd","checkSeatQuota","discountReachMonthlyUsd","netOfProcessorFee","orgListPriceMonthlyUsd","resolveCollaboratorSeatPool","resolveOrgEntitlements","planQuotaOf","pluginCostAxes","pluginUsageBands","SEAT_COGS_USD_PER_MONTH","DAYS_PER_FULL_MONTH","VIEWS_PER_GB","FULL_USE_QUOTE_MULTIPLE","FULL_USE_DISCOUNT_MULTIPLE","termUsd","value","Number","isFinite","POSITIVE_INFINITY","declaredBandUnitCostUsd","band","unitCostUsd","measuredBy","fields","fallbackFields","axis","find","candidate","some","field","includes","Error","id","rate","undefined","fullUseCogs","entitlements","options","rates","hosts","hostLimit","quota","key","extraSeats","Math","max","breakdown","mediaStorage","storagePerHostMb","storagePerGbMonth","bandwidth","bandwidthGb","perPageView","cdnRequests","dataStorage","dataStorageMbPerOrg","dataStoragePerGbMonth","apiRequests","apiRequestsPerMonth","perApiRequest","emailSends","emailSendsPerMonth","perEmailSend","units","entitlement","perHost","membersPerHost","managersPerOrg","unbounded","Object","entries","filter","usd","map","term","sort","measuredUsd","values","reduce","sum","floorUsd","cogsUsd","fullUseMonthlyCogsUsd","orgFullUseCogs","org","purchased","monthlyDiscount","discount","annual","percentOff","amountOffUsd","rateAgainstFullUse","input","listUsd","listMonthlyUsd","reachUsd","reachMonthlyUsd","min","monthly","discountedUsd","round","netUsd","fullUseCogsUsd","cogs","requiredNetUsd","multiple","coverage","ok","orgFullUseFloor","subscription","interval","discountReach","coupon","monthsPerCharge","months","floor","durationInMonths","duration","charges","monthsOfFirstYear","ceil","shortfall","assessDiscountAgainstFullUse","charge","undiscounted","reach","chargeNetUsd","chargeCogsUsd","firstYearNetUsd","firstYearCogsUsd","chargeUnderCostUsd","firstYearCoverage","firstYearUnderCostUsd","orgDiscountFullUse","rateCouponAgainstFullUse","plans","paid","plan","basePriceMonthlyUsd","limited","length","cases","status","push","worst","least","one","under","couponCaseLabel","warning","join","describeDiscountFullUse","deepestCouponPercentWithinFullUse","deepest","chargesReached","result","subject","about","each","toFixed","year","describeFullUseFloor"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,0EAA0E;AAC1E,6EAA6E;AAC7E,iEAAiE;;AAEjE,SACEA,6BAA6B,EAC7BC,uBAAuB,EACvBC,cAAc,EACdC,uBAAuB,EACvBC,8BAA8B,EAC9BC,WAAW,EACXC,YAAY,EACZC,gBAAgB,EAChBC,gBAAgB,EAChBC,cAAc,EACdC,uBAAuB,EACvBC,iBAAiB,EACjBC,sBAAsB,EACtBC,2BAA2B,EAC3BC,sBAAsB,QAGjB,yBAAqB;AAC5B,SAASC,WAAW,QAAQ,gDAA4C;AACxE,SACEC,cAAc,EACdC,gBAAgB,QAEX,yCAAqC;AAE5C;;;;;;;;;;;;;;;;;;;;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(host: {
70
70
  suspendedUntilMs?: number;
71
71
  }): HostStatus;
72
72
  /**
73
- * `6 of 10 sites · Business plan` — the meta line the Sites mockup puts
73
+ * `6 of 10 sites · Pro plan` — the meta line the Sites mockup puts
74
74
  * opposite the section heading.
75
75
  *
76
76
  * Returns `undefined` rather than a partial line while the org or its plan
77
77
  * is still resolving. A count against the FREE limit is what an unresolved
78
- * org produces, and telling a Business customer they are at "1 of 1 sites"
78
+ * org produces, and telling a Pro customer they are at "1 of 1 sites"
79
79
  * is how a correct page delivers a false upgrade prompt.
80
80
  */
81
81
  export declare function describeSiteAllowance(options: {
@@ -98,12 +98,12 @@
98
98
  };
99
99
  }
100
100
  /**
101
- * `6 of 10 sites · Business plan` — the meta line the Sites mockup puts
101
+ * `6 of 10 sites · Pro plan` — the meta line the Sites mockup puts
102
102
  * opposite the section heading.
103
103
  *
104
104
  * Returns `undefined` rather than a partial line while the org or its plan
105
105
  * is still resolving. A count against the FREE limit is what an unresolved
106
- * org produces, and telling a Business customer they are at "1 of 1 sites"
106
+ * org produces, and telling a Pro customer they are at "1 of 1 sites"
107
107
  * is how a correct page delivers a false upgrade prompt.
108
108
  */ export function describeSiteAllowance(options) {
109
109
  const { used, limit, planLabel, ready } = options;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/host-status.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface HostStatus {\n /** `Live`, `Draft`, `In preview`, `Maintenance`, `Suspended`. */\n label: string\n color: 'success' | 'default' | 'warning' | 'error'\n /** Why, in one sentence — the pill's tooltip. */\n detail: string\n}\n\n/**\n * How many pages this site publishes.\n *\n * Read off `host.screens` — the map publishing writes into the host document\n * (`hosts/{hostId}.screens[screenId] = slug`, see `template-screens.ts`) and\n * the tenant reads to route a request. So a site with an entry has at least\n * one page a visitor can reach, and one without has none. That makes this a\n * fact already sitting in a document its readers hold: **no extra read**, on\n * a page that can list a hundred sites.\n *\n * ⚠️ It counts PUBLISHED ROUTES, not authored work. A site with five\n * unpublished drafts counts 0 — the map is written by publishing and by\n * nothing else. Every caller is asking \"what can a visitor reach?\"; a caller\n * that means \"has anyone worked on this?\" is asking a different question and\n * this is the wrong number for it.\n *\n * The placeholder home page a new site is created with (AGL-3408) COUNTS\n * here: it is a page a visitor reaches, so a new site is Live. The first-run\n * offer asks a different question — has the OWNER published anything? — and\n * reads `hostIsBlankSite`, which discounts it.\n */\nexport function publishedScreenCount(\n host: { screens?: Record<string, unknown> } | null | undefined,\n): number {\n return Object.keys(host?.screens ?? {}).length\n}\n\n/**\n * The `Live` / `Draft` pill the console Sites mockup puts on every card\n * (AGL-2166).\n *\n * Derived from {@link publishedScreenCount}: the pill reports what a visitor\n * can reach, placeholder home page included.\n *\n * The staff admin host page has rendered a `published` / `draft` chip since\n * AGL-390 off `host.published`, which is not a field on `AglynHost` and is\n * written by nothing — so that chip has always said `draft`. Deriving from\n * `screens` is what it should have done.\n *\n * Order matters. A suspended site is not \"live\" whatever it has published,\n * and a site in maintenance is serving the 503 screen rather than its\n * pages — reporting either as `Live` would be the console agreeing with a\n * customer who thinks their site is up.\n */\nexport function describeHostStatus(host: {\n screens?: Record<string, unknown>\n maintenance?: boolean\n preview?: boolean\n suspendedAt?: number\n suspendedUntilMs?: number\n}): HostStatus {\n if (host?.suspendedAt) {\n // A timed suspension that has elapsed is over, even though the fields\n // are still on the document — the tenant makes the same check.\n const until = host.suspendedUntilMs\n if (!until || until > Date.now()) {\n return {\n label: 'Suspended',\n color: 'error',\n detail: 'This site is serving a lockdown notice instead of content.',\n }\n }\n }\n if (host?.maintenance) {\n return {\n label: 'Maintenance',\n color: 'warning',\n detail: 'Every path serves the maintenance page.',\n }\n }\n // A site in preview (AGL-4086) is not live to its visitors whatever it has\n // published: they get the 503 page or \"Coming soon\", and only the team\n // sees the pages.\n if (host?.preview === true) {\n return {\n label: 'In preview',\n color: 'default',\n detail:\n 'Only your team can see this site. Visitors see the 503 page or \"Coming soon\".',\n }\n }\n const published = publishedScreenCount(host)\n if (published > 0) {\n return {\n label: 'Live',\n color: 'success',\n detail: `${published} published page${published === 1 ? '' : 's'}.`,\n }\n }\n return {\n label: 'Draft',\n color: 'default',\n detail: 'Nothing published yet — visitors see the placeholder.',\n }\n}\n\n/**\n * `6 of 10 sites · Business plan` — the meta line the Sites mockup puts\n * opposite the section heading.\n *\n * Returns `undefined` rather than a partial line while the org or its plan\n * is still resolving. A count against the FREE limit is what an unresolved\n * org produces, and telling a Business customer they are at \"1 of 1 sites\"\n * is how a correct page delivers a false upgrade prompt.\n */\nexport function describeSiteAllowance(options: {\n used: number\n limit: number | undefined\n planLabel: string | undefined\n ready: boolean\n}): string | undefined {\n const { used, limit, planLabel, ready } = options\n if (!ready || !planLabel) return undefined\n /*\n * `Number.isFinite`, not `limit < 0` (AGL-2223).\n *\n * `UNLIMITED` is `Number.POSITIVE_INFINITY`, and Enterprise's `hostLimit`\n * is exactly that — so the `< 0` test was never true for the one plan the\n * Unlimited branch existed for, and an Enterprise organization read\n * `4 of Infinity sites · Enterprise plan`. The negative case is kept: an\n * entitlement override can carry a negative sentinel, and reading that as a\n * cap of \"-1 sites\" would be the same class of nonsense.\n */\n const cap =\n limit === undefined || limit === null\n ? undefined\n : !Number.isFinite(limit) || limit < 0\n ? 'Unlimited'\n : String(limit)\n const sites =\n cap === undefined\n ? `${used} site${used === 1 ? '' : 's'}`\n : `${used} of ${cap} site${cap === '1' ? '' : 's'}`\n return `${sites} · ${planLabel} plan`\n}\n"],"names":["publishedScreenCount","host","Object","keys","screens","length","describeHostStatus","suspendedAt","until","suspendedUntilMs","Date","now","label","color","detail","maintenance","preview","published","describeSiteAllowance","options","used","limit","planLabel","ready","undefined","cap","Number","isFinite","String","sites"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAUD;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,SAASA,qBACdC,IAA8D;;IAE9D,OAAOC,OAAOC,IAAI,SAACF,wBAAAA,KAAMG,OAAO,mBAAI,CAAC,GAAGC,MAAM;AAChD;AAEA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASC,mBAAmBL,IAMlC;IACC,IAAIA,wBAAAA,KAAMM,WAAW,EAAE;QACrB,sEAAsE;QACtE,+DAA+D;QAC/D,MAAMC,QAAQP,KAAKQ,gBAAgB;QACnC,IAAI,CAACD,SAASA,QAAQE,KAAKC,GAAG,IAAI;YAChC,OAAO;gBACLC,OAAO;gBACPC,OAAO;gBACPC,QAAQ;YACV;QACF;IACF;IACA,IAAIb,wBAAAA,KAAMc,WAAW,EAAE;QACrB,OAAO;YACLH,OAAO;YACPC,OAAO;YACPC,QAAQ;QACV;IACF;IACA,2EAA2E;IAC3E,uEAAuE;IACvE,kBAAkB;IAClB,IAAIb,CAAAA,wBAAAA,KAAMe,OAAO,MAAK,MAAM;QAC1B,OAAO;YACLJ,OAAO;YACPC,OAAO;YACPC,QACE;QACJ;IACF;IACA,MAAMG,YAAYjB,qBAAqBC;IACvC,IAAIgB,YAAY,GAAG;QACjB,OAAO;YACLL,OAAO;YACPC,OAAO;YACPC,QAAQ,GAAGG,UAAU,eAAe,EAAEA,cAAc,IAAI,KAAK,IAAI,CAAC,CAAC;QACrE;IACF;IACA,OAAO;QACLL,OAAO;QACPC,OAAO;QACPC,QAAQ;IACV;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASI,sBAAsBC,OAKrC;IACC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGJ;IAC1C,IAAI,CAACI,SAAS,CAACD,WAAW,OAAOE;IACjC;;;;;;;;;GASC,GACD,MAAMC,MACJJ,UAAUG,aAAaH,UAAU,OAC7BG,YACA,CAACE,OAAOC,QAAQ,CAACN,UAAUA,QAAQ,IACjC,cACAO,OAAOP;IACf,MAAMQ,QACJJ,QAAQD,YACJ,GAAGJ,KAAK,KAAK,EAAEA,SAAS,IAAI,KAAK,KAAK,GACtC,GAAGA,KAAK,IAAI,EAAEK,IAAI,KAAK,EAAEA,QAAQ,MAAM,KAAK,KAAK;IACvD,OAAO,GAAGI,MAAM,GAAG,EAAEP,UAAU,KAAK,CAAC;AACvC"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/host-status.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface HostStatus {\n /** `Live`, `Draft`, `In preview`, `Maintenance`, `Suspended`. */\n label: string\n color: 'success' | 'default' | 'warning' | 'error'\n /** Why, in one sentence — the pill's tooltip. */\n detail: string\n}\n\n/**\n * How many pages this site publishes.\n *\n * Read off `host.screens` — the map publishing writes into the host document\n * (`hosts/{hostId}.screens[screenId] = slug`, see `template-screens.ts`) and\n * the tenant reads to route a request. So a site with an entry has at least\n * one page a visitor can reach, and one without has none. That makes this a\n * fact already sitting in a document its readers hold: **no extra read**, on\n * a page that can list a hundred sites.\n *\n * ⚠️ It counts PUBLISHED ROUTES, not authored work. A site with five\n * unpublished drafts counts 0 — the map is written by publishing and by\n * nothing else. Every caller is asking \"what can a visitor reach?\"; a caller\n * that means \"has anyone worked on this?\" is asking a different question and\n * this is the wrong number for it.\n *\n * The placeholder home page a new site is created with (AGL-3408) COUNTS\n * here: it is a page a visitor reaches, so a new site is Live. The first-run\n * offer asks a different question — has the OWNER published anything? — and\n * reads `hostIsBlankSite`, which discounts it.\n */\nexport function publishedScreenCount(\n host: { screens?: Record<string, unknown> } | null | undefined,\n): number {\n return Object.keys(host?.screens ?? {}).length\n}\n\n/**\n * The `Live` / `Draft` pill the console Sites mockup puts on every card\n * (AGL-2166).\n *\n * Derived from {@link publishedScreenCount}: the pill reports what a visitor\n * can reach, placeholder home page included.\n *\n * The staff admin host page has rendered a `published` / `draft` chip since\n * AGL-390 off `host.published`, which is not a field on `AglynHost` and is\n * written by nothing — so that chip has always said `draft`. Deriving from\n * `screens` is what it should have done.\n *\n * Order matters. A suspended site is not \"live\" whatever it has published,\n * and a site in maintenance is serving the 503 screen rather than its\n * pages — reporting either as `Live` would be the console agreeing with a\n * customer who thinks their site is up.\n */\nexport function describeHostStatus(host: {\n screens?: Record<string, unknown>\n maintenance?: boolean\n preview?: boolean\n suspendedAt?: number\n suspendedUntilMs?: number\n}): HostStatus {\n if (host?.suspendedAt) {\n // A timed suspension that has elapsed is over, even though the fields\n // are still on the document — the tenant makes the same check.\n const until = host.suspendedUntilMs\n if (!until || until > Date.now()) {\n return {\n label: 'Suspended',\n color: 'error',\n detail: 'This site is serving a lockdown notice instead of content.',\n }\n }\n }\n if (host?.maintenance) {\n return {\n label: 'Maintenance',\n color: 'warning',\n detail: 'Every path serves the maintenance page.',\n }\n }\n // A site in preview (AGL-4086) is not live to its visitors whatever it has\n // published: they get the 503 page or \"Coming soon\", and only the team\n // sees the pages.\n if (host?.preview === true) {\n return {\n label: 'In preview',\n color: 'default',\n detail:\n 'Only your team can see this site. Visitors see the 503 page or \"Coming soon\".',\n }\n }\n const published = publishedScreenCount(host)\n if (published > 0) {\n return {\n label: 'Live',\n color: 'success',\n detail: `${published} published page${published === 1 ? '' : 's'}.`,\n }\n }\n return {\n label: 'Draft',\n color: 'default',\n detail: 'Nothing published yet — visitors see the placeholder.',\n }\n}\n\n/**\n * `6 of 10 sites · Pro plan` — the meta line the Sites mockup puts\n * opposite the section heading.\n *\n * Returns `undefined` rather than a partial line while the org or its plan\n * is still resolving. A count against the FREE limit is what an unresolved\n * org produces, and telling a Pro customer they are at \"1 of 1 sites\"\n * is how a correct page delivers a false upgrade prompt.\n */\nexport function describeSiteAllowance(options: {\n used: number\n limit: number | undefined\n planLabel: string | undefined\n ready: boolean\n}): string | undefined {\n const { used, limit, planLabel, ready } = options\n if (!ready || !planLabel) return undefined\n /*\n * `Number.isFinite`, not `limit < 0` (AGL-2223).\n *\n * `UNLIMITED` is `Number.POSITIVE_INFINITY`, and Enterprise's `hostLimit`\n * is exactly that — so the `< 0` test was never true for the one plan the\n * Unlimited branch existed for, and an Enterprise organization read\n * `4 of Infinity sites · Enterprise plan`. The negative case is kept: an\n * entitlement override can carry a negative sentinel, and reading that as a\n * cap of \"-1 sites\" would be the same class of nonsense.\n */\n const cap =\n limit === undefined || limit === null\n ? undefined\n : !Number.isFinite(limit) || limit < 0\n ? 'Unlimited'\n : String(limit)\n const sites =\n cap === undefined\n ? `${used} site${used === 1 ? '' : 's'}`\n : `${used} of ${cap} site${cap === '1' ? '' : 's'}`\n return `${sites} · ${planLabel} plan`\n}\n"],"names":["publishedScreenCount","host","Object","keys","screens","length","describeHostStatus","suspendedAt","until","suspendedUntilMs","Date","now","label","color","detail","maintenance","preview","published","describeSiteAllowance","options","used","limit","planLabel","ready","undefined","cap","Number","isFinite","String","sites"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAUD;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,SAASA,qBACdC,IAA8D;;IAE9D,OAAOC,OAAOC,IAAI,SAACF,wBAAAA,KAAMG,OAAO,mBAAI,CAAC,GAAGC,MAAM;AAChD;AAEA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASC,mBAAmBL,IAMlC;IACC,IAAI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CAAC;AACvC"}
@@ -234,6 +234,14 @@ export declare const RETIRED_PLANS: readonly OrgPlan[];
234
234
  * ladder; the SALE question ("what may be bought?") reads `SELF_SERVE_PLANS`.
235
235
  */
236
236
  export declare const PLAN_LADDER: readonly OrgPlan[];
237
+ /**
238
+ * The plans a staff custom-billing deal may ride on (AGL-4158): Custom first,
239
+ * the default a negotiated deal lands on, then the paid self-serve plans from
240
+ * the top down (Pro, Starter) for a deal scoped to that plan's capability.
241
+ * Built from `SELF_SERVE_PLANS`, so a retired plan is never offered and the
242
+ * staff "Base plan" picker and the provisioning route agree by construction.
243
+ */
244
+ export declare const CUSTOM_BILLING_BASE_PLANS: readonly OrgPlan[];
237
245
  /** Whether a plan is one pricing v4 retired (`RETIRED_PLANS`). */
238
246
  export declare function isRetiredPlan(plan: OrgPlan | string | undefined | null): boolean;
239
247
  /**
@@ -835,6 +843,30 @@ export declare function siteCareUnits(addons: OrgSeatAddons | null | undefined):
835
843
  * somehow set (Stripe coupons carry only one). Rounds to whole cents.
836
844
  */
837
845
  export declare function applyDiscountUsd(listPriceUsd: number, discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'> | null | undefined): number;
846
+ /** A discount as the net-of-discount readers take it (AGL-1105, AGL-4161). */
847
+ export type OrgDiscountTerms = Pick<OrgDiscount, 'percentOff' | 'amountOffUsd' | 'basePriceOnly' | 'appliesToPlans'>;
848
+ /**
849
+ * The org's BASE PLAN line, monthly (annual billing as its monthly
850
+ * equivalent), and 0 for anyone not billing: the one line a base-price coupon
851
+ * reaches (AGL-4161). A negotiated custom price is the whole deal, so it is
852
+ * its own base line.
853
+ */
854
+ export declare function orgBasePriceMonthlyUsd(org: Partial<AglynOrgBilling> | null | undefined): number;
855
+ /**
856
+ * How much of the org's monthly list price a discount reaches (AGL-4161):
857
+ * all of it for a whole-subscription discount; for a base-price one, the base
858
+ * plan line, or nothing when the plans it is limited to do not include the
859
+ * org's plan (Stripe applies it to no line then). An old mirror without the
860
+ * fields is a whole-subscription discount.
861
+ */
862
+ export declare function discountReachMonthlyUsd(org: Partial<AglynOrgBilling> | null | undefined, discount: OrgDiscountTerms | null | undefined, listPriceUsd?: number): number;
863
+ /**
864
+ * A monthly list price net of an ORG's discount (AGL-4161): `applyDiscountUsd`
865
+ * on the part the discount reaches, the rest at list. For a whole-subscription
866
+ * discount that is `applyDiscountUsd` exactly; a base-price one leaves the
867
+ * add-ons in full.
868
+ */
869
+ export declare function applyOrgDiscountUsd(org: Partial<AglynOrgBilling> | null | undefined, listPriceUsd: number, discount: OrgDiscountTerms | null | undefined): number;
838
870
  /**
839
871
  * Whether an org should read as **"Enterprise"** everywhere the plan is shown.
840
872
  * Three ways to qualify:
@@ -887,6 +919,8 @@ export declare const ENTERPRISE_PLAN_LABEL: string;
887
919
  * (`org.discount`, AGL-1105), and 0 for anyone who is not actually billing. A
888
920
  * comped enterprise deal genuinely collects less, so the discount belongs in
889
921
  * MRR; the pre-discount sticker stays available as `orgListPriceMonthlyUsd`.
922
+ * A base-price discount (AGL-4161) comes off the base plan line only, so the
923
+ * add-ons an org buys count in full.
890
924
  */
891
925
  export declare function orgMonthlyRevenueUsd(org: Partial<AglynOrgBilling> | null | undefined): number;
892
926
  /**
@@ -1501,7 +1535,7 @@ export interface DiscountMarginOptions {
1501
1535
  * so this never double-counts an existing `org.discount`. A non-billing org
1502
1536
  * (list price 0) has no revenue to protect and rates `ok`.
1503
1537
  */
1504
- export declare function checkDiscountMargin(org: Partial<AglynOrgBilling> | null | undefined, discount: Pick<OrgDiscount, 'percentOff' | 'amountOffUsd'>, options?: DiscountMarginOptions): DiscountMarginResult;
1538
+ export declare function checkDiscountMargin(org: Partial<AglynOrgBilling> | null | undefined, discount: OrgDiscountTerms, options?: DiscountMarginOptions): DiscountMarginResult;
1505
1539
  /**
1506
1540
  * The plan the org actually gets (AGL-247): missing/unknown plans resolve
1507
1541
  * as `free`, and a paid plan whose subscription is canceled/unpaid/
@@ -2052,13 +2086,13 @@ export declare const SALE_PROCESSING_FIXED_CENTS = 30;
2052
2086
  */
2053
2087
  export declare function planGrantingFeature(feature: keyof OrgFeatureFlags): OrgPlan | undefined;
2054
2088
  /**
2055
- * The plan name an upsell should name, ready to interpolate — "Business",
2089
+ * The plan name an upsell should name, ready to interpolate — "Pro",
2056
2090
  * or undefined when {@link planGrantingFeature} has no answer.
2057
2091
  */
2058
2092
  export declare function planLabelGrantingFeature(feature: keyof OrgFeatureFlags): string | undefined;
2059
2093
  /**
2060
2094
  * The one sentence a locked control carries, on hover and for a screen
2061
- * reader: "Scheduled publishing is included from Business."
2095
+ * reader: "Scheduled publishing is included from Pro."
2062
2096
  */
2063
2097
  export declare function planLockReason(subject: string, planLabel: string | undefined): string;
2064
2098
  /**