@aglyn/aglyn 1.10.0 → 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.
- package/package.json +11 -11
- package/src/lib/app-utils/docs-help-sections.generated.js +1 -1
- package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
- package/src/lib/app-utils/docs-help.generated.d.ts +1 -1
- package/src/lib/app-utils/docs-help.generated.js +1 -0
- package/src/lib/app-utils/docs-help.generated.js.map +1 -1
- package/src/lib/app-utils/docs-index.generated.js +2 -2
- package/src/lib/app-utils/docs-index.generated.js.map +1 -1
- package/src/lib/app-utils/full-use-cost.d.ts +28 -11
- package/src/lib/app-utils/full-use-cost.js +31 -15
- package/src/lib/app-utils/full-use-cost.js.map +1 -1
- package/src/lib/app-utils/plan-entitlements.d.ts +27 -1
- package/src/lib/app-utils/plan-entitlements.js +44 -3
- package/src/lib/app-utils/plan-entitlements.js.map +1 -1
- package/src/lib/app-utils/upgrade-proposal.d.ts +17 -3
- package/src/lib/app-utils/upgrade-proposal.js +28 -6
- package/src/lib/app-utils/upgrade-proposal.js.map +1 -1
- package/src/lib/foundation/definitions/org-billing.types.d.ts +22 -0
- package/src/lib/foundation/definitions/org-billing.types.js.map +1 -1
|
@@ -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:
|
|
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
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
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
|
|
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
|
|
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
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
-
|
|
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,OAAQnB;AAE5C;;;;CAIC,G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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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8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atAddons | null | undefined):
|
|
|
843
843
|
* somehow set (Stripe coupons carry only one). Rounds to whole cents.
|
|
844
844
|
*/
|
|
845
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;
|
|
846
870
|
/**
|
|
847
871
|
* Whether an org should read as **"Enterprise"** everywhere the plan is shown.
|
|
848
872
|
* Three ways to qualify:
|
|
@@ -895,6 +919,8 @@ export declare const ENTERPRISE_PLAN_LABEL: string;
|
|
|
895
919
|
* (`org.discount`, AGL-1105), and 0 for anyone who is not actually billing. A
|
|
896
920
|
* comped enterprise deal genuinely collects less, so the discount belongs in
|
|
897
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.
|
|
898
924
|
*/
|
|
899
925
|
export declare function orgMonthlyRevenueUsd(org: Partial<AglynOrgBilling> | null | undefined): number;
|
|
900
926
|
/**
|
|
@@ -1509,7 +1535,7 @@ export interface DiscountMarginOptions {
|
|
|
1509
1535
|
* so this never double-counts an existing `org.discount`. A non-billing org
|
|
1510
1536
|
* (list price 0) has no revenue to protect and rates `ok`.
|
|
1511
1537
|
*/
|
|
1512
|
-
export declare function checkDiscountMargin(org: Partial<AglynOrgBilling> | null | undefined, discount:
|
|
1538
|
+
export declare function checkDiscountMargin(org: Partial<AglynOrgBilling> | null | undefined, discount: OrgDiscountTerms, options?: DiscountMarginOptions): DiscountMarginResult;
|
|
1513
1539
|
/**
|
|
1514
1540
|
* The plan the org actually gets (AGL-247): missing/unknown plans resolve
|
|
1515
1541
|
* as `free`, and a paid plan whose subscription is canceled/unpaid/
|
|
@@ -1735,6 +1735,44 @@ function trimmedOrNull(value) {
|
|
|
1735
1735
|
}
|
|
1736
1736
|
return listPriceUsd;
|
|
1737
1737
|
}
|
|
1738
|
+
/**
|
|
1739
|
+
* The org's BASE PLAN line, monthly (annual billing as its monthly
|
|
1740
|
+
* equivalent), and 0 for anyone not billing: the one line a base-price coupon
|
|
1741
|
+
* reaches (AGL-4161). A negotiated custom price is the whole deal, so it is
|
|
1742
|
+
* its own base line.
|
|
1743
|
+
*/ export function orgBasePriceMonthlyUsd(org) {
|
|
1744
|
+
var _org_subscription, _org_subscription1;
|
|
1745
|
+
if (!isBillingSubscription(org)) return 0;
|
|
1746
|
+
const custom = org == null ? void 0 : (_org_subscription = org.subscription) == null ? void 0 : _org_subscription.customMonthlyUsd;
|
|
1747
|
+
if (typeof custom === 'number' && custom > 0) return Math.round(custom * 100) / 100;
|
|
1748
|
+
const pricing = PLAN_PRICING[org == null ? void 0 : org.plan];
|
|
1749
|
+
if (!pricing) return 0;
|
|
1750
|
+
return (org == null ? void 0 : (_org_subscription1 = org.subscription) == null ? void 0 : _org_subscription1.interval) === 'year' ? pricing.basePriceAnnualMonthlyUsd : pricing.basePriceMonthlyUsd;
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* How much of the org's monthly list price a discount reaches (AGL-4161):
|
|
1754
|
+
* all of it for a whole-subscription discount; for a base-price one, the base
|
|
1755
|
+
* plan line, or nothing when the plans it is limited to do not include the
|
|
1756
|
+
* org's plan (Stripe applies it to no line then). An old mirror without the
|
|
1757
|
+
* fields is a whole-subscription discount.
|
|
1758
|
+
*/ export function discountReachMonthlyUsd(org, discount, listPriceUsd = orgListPriceMonthlyUsd(org)) {
|
|
1759
|
+
const list = Math.max(0, listPriceUsd);
|
|
1760
|
+
if (!(discount == null ? void 0 : discount.basePriceOnly)) return list;
|
|
1761
|
+
if (Array.isArray(discount.appliesToPlans) && !discount.appliesToPlans.includes(org == null ? void 0 : org.plan)) {
|
|
1762
|
+
return 0;
|
|
1763
|
+
}
|
|
1764
|
+
return Math.min(list, orgBasePriceMonthlyUsd(org));
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* A monthly list price net of an ORG's discount (AGL-4161): `applyDiscountUsd`
|
|
1768
|
+
* on the part the discount reaches, the rest at list. For a whole-subscription
|
|
1769
|
+
* discount that is `applyDiscountUsd` exactly; a base-price one leaves the
|
|
1770
|
+
* add-ons in full.
|
|
1771
|
+
*/ export function applyOrgDiscountUsd(org, listPriceUsd, discount) {
|
|
1772
|
+
const reach = discountReachMonthlyUsd(org, discount, listPriceUsd);
|
|
1773
|
+
if (!discount || reach >= listPriceUsd) return applyDiscountUsd(listPriceUsd, discount);
|
|
1774
|
+
return Math.round((listPriceUsd - reach + applyDiscountUsd(reach, discount)) * 100) / 100;
|
|
1775
|
+
}
|
|
1738
1776
|
/**
|
|
1739
1777
|
* Whether an org should read as **"Enterprise"** everywhere the plan is shown.
|
|
1740
1778
|
* Three ways to qualify:
|
|
@@ -1793,10 +1831,12 @@ function trimmedOrNull(value) {
|
|
|
1793
1831
|
* (`org.discount`, AGL-1105), and 0 for anyone who is not actually billing. A
|
|
1794
1832
|
* comped enterprise deal genuinely collects less, so the discount belongs in
|
|
1795
1833
|
* MRR; the pre-discount sticker stays available as `orgListPriceMonthlyUsd`.
|
|
1834
|
+
* A base-price discount (AGL-4161) comes off the base plan line only, so the
|
|
1835
|
+
* add-ons an org buys count in full.
|
|
1796
1836
|
*/ export function orgMonthlyRevenueUsd(org) {
|
|
1797
1837
|
const listPrice = orgListPriceMonthlyUsd(org);
|
|
1798
1838
|
if (listPrice <= 0) return 0;
|
|
1799
|
-
return
|
|
1839
|
+
return applyOrgDiscountUsd(org, listPrice, org == null ? void 0 : org.discount);
|
|
1800
1840
|
}
|
|
1801
1841
|
/**
|
|
1802
1842
|
* Stripe's standard processing fee on Aglyn's OWN subscription charges
|
|
@@ -2420,7 +2460,8 @@ export const DISCOUNT_DEPTH_BLOCK_PCT = 70;
|
|
|
2420
2460
|
* the org — `grossUsd` is always the list price (`orgListPriceMonthlyUsd`),
|
|
2421
2461
|
* so this never double-counts an existing `org.discount`. A non-billing org
|
|
2422
2462
|
* (list price 0) has no revenue to protect and rates `ok`.
|
|
2423
|
-
*/ export function checkDiscountMargin(org,
|
|
2463
|
+
*/ export function checkDiscountMargin(org, // A base-price coupon (AGL-4161) is rated on the base line it reaches.
|
|
2464
|
+
discount, options = {}) {
|
|
2424
2465
|
var _options_measuredCogsUsd;
|
|
2425
2466
|
var _org_subscription;
|
|
2426
2467
|
const floorPct = NET_MARGIN_FLOOR_PCT;
|
|
@@ -2447,7 +2488,7 @@ export const DISCOUNT_DEPTH_BLOCK_PCT = 70;
|
|
|
2447
2488
|
floorPct
|
|
2448
2489
|
};
|
|
2449
2490
|
}
|
|
2450
|
-
const discountedUsd =
|
|
2491
|
+
const discountedUsd = applyOrgDiscountUsd(org, grossUsd, discount);
|
|
2451
2492
|
const annual = (org == null ? void 0 : (_org_subscription = org.subscription) == null ? void 0 : _org_subscription.interval) === 'year';
|
|
2452
2493
|
const netUsd = netOfProcessorFee(discountedUsd, annual);
|
|
2453
2494
|
const depthPct = Math.round((grossUsd - discountedUsd) / grossUsd * 10000) / 10000;
|