@aglyn/tenant-data-admin 1.0.0-beta.270 → 1.0.0-beta.271
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 +7 -7
- package/src/lib/server/append-only-history-write.d.ts +38 -0
- package/src/lib/server/append-only-history-write.js +60 -0
- package/src/lib/server/append-only-history-write.js.map +1 -0
- package/src/lib/server/billing-addons.d.ts +58 -32
- package/src/lib/server/billing-addons.js +100 -86
- package/src/lib/server/billing-addons.js.map +1 -1
- package/src/lib/server/bundle-links.d.ts +166 -0
- package/src/lib/server/bundle-links.js +286 -0
- package/src/lib/server/bundle-links.js.map +1 -0
- package/src/lib/server/client-build.d.ts +74 -0
- package/src/lib/server/client-build.js +264 -0
- package/src/lib/server/client-build.js.map +1 -0
- package/src/lib/server/host-memberships.d.ts +35 -2
- package/src/lib/server/host-memberships.js +63 -2
- package/src/lib/server/host-memberships.js.map +1 -1
- package/src/lib/server/org-billing.d.ts +4 -2
- package/src/lib/server/org-billing.js +5 -0
- package/src/lib/server/org-billing.js.map +1 -1
- package/src/lib/server/site-care-emails.d.ts +52 -0
- package/src/lib/server/site-care-emails.js +97 -0
- package/src/lib/server/site-care-emails.js.map +1 -0
- package/src/lib/server/site-care-inbound.d.ts +80 -0
- package/src/lib/server/site-care-inbound.js +171 -0
- package/src/lib/server/site-care-inbound.js.map +1 -0
- package/src/lib/server/site-care-project-reconcile.d.ts +64 -0
- package/src/lib/server/site-care-project-reconcile.js +211 -0
- package/src/lib/server/site-care-project-reconcile.js.map +1 -0
- package/src/lib/server/site-care-project-stripe.d.ts +114 -0
- package/src/lib/server/site-care-project-stripe.js +305 -0
- package/src/lib/server/site-care-project-stripe.js.map +1 -0
- package/src/lib/server/site-care-projects.d.ts +169 -0
- package/src/lib/server/site-care-projects.js +882 -0
- package/src/lib/server/site-care-projects.js.map +1 -0
- package/src/lib/server/site-care-reconcile.d.ts +81 -0
- package/src/lib/server/site-care-reconcile.js +349 -0
- package/src/lib/server/site-care-reconcile.js.map +1 -0
- package/src/lib/server/site-care-requests.d.ts +243 -0
- package/src/lib/server/site-care-requests.js +1414 -0
- package/src/lib/server/site-care-requests.js.map +1 -0
- package/src/lib/server/site-care-stripe.d.ts +175 -0
- package/src/lib/server/site-care-stripe.js +375 -0
- package/src/lib/server/site-care-stripe.js.map +1 -0
- package/src/lib/server/upgrade-proposal.d.ts +40 -1
- package/src/lib/server/upgrade-proposal.js +92 -50
- package/src/lib/server/upgrade-proposal.js.map +1 -1
- package/src/tenancy.d.ts +1 -0
- package/src/tenancy.js +2 -0
- package/src/tenancy.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/tenant-data-admin",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.271",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.0.0-beta.
|
|
29
|
-
"@aglyn/shared-util-email": "1.0.0-beta.
|
|
30
|
-
"@aglyn/shared-util-fbserver": "1.0.0-beta.
|
|
31
|
-
"@aglyn/shared-util-first-touch": "1.0.0-beta.
|
|
32
|
-
"@aglyn/shared-util-http": "1.0.0-beta.
|
|
33
|
-
"@aglyn/shared-util-tools": "1.0.0-beta.
|
|
28
|
+
"@aglyn/aglyn": "1.0.0-beta.271",
|
|
29
|
+
"@aglyn/shared-util-email": "1.0.0-beta.271",
|
|
30
|
+
"@aglyn/shared-util-fbserver": "1.0.0-beta.271",
|
|
31
|
+
"@aglyn/shared-util-first-touch": "1.0.0-beta.271",
|
|
32
|
+
"@aglyn/shared-util-http": "1.0.0-beta.271",
|
|
33
|
+
"@aglyn/shared-util-tools": "1.0.0-beta.271",
|
|
34
34
|
"@msgpack/msgpack": "^3.1.3",
|
|
35
35
|
"@swc/helpers": "0.5.23",
|
|
36
36
|
"sharp": "^0.35.5",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { type AppendOnlyHistoryRow } from '@aglyn/aglyn/app-utils/append-only-history';
|
|
18
|
+
/** A batch or a transaction: anything that creates and sets a document. */
|
|
19
|
+
type HistoryWriter = Pick<FirebaseFirestore.WriteBatch, 'create' | 'set'> | Pick<FirebaseFirestore.Transaction, 'create' | 'set'>;
|
|
20
|
+
/** The staff audit row a history row is mirrored to. */
|
|
21
|
+
export interface HistoryAudit {
|
|
22
|
+
action: string;
|
|
23
|
+
scope: string;
|
|
24
|
+
/** A path naming the org, so the staff org page's audit card finds it. */
|
|
25
|
+
target: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates one history row in the writer, and its audit row beside it when
|
|
29
|
+
* `audit` is given. Returns the new row's reference.
|
|
30
|
+
*/
|
|
31
|
+
export declare function appendHistoryRow(writer: HistoryWriter, firestore: FirebaseFirestore.Firestore, history: FirebaseFirestore.CollectionReference, row: AppendOnlyHistoryRow, audit?: HistoryAudit | null): FirebaseFirestore.DocumentReference;
|
|
32
|
+
/** Writes one row on its own (with its audit row), for a step with no other write. */
|
|
33
|
+
export declare function commitHistoryRow(firestore: FirebaseFirestore.Firestore, history: FirebaseFirestore.CollectionReference, row: AppendOnlyHistoryRow, audit?: HistoryAudit | null): Promise<void>;
|
|
34
|
+
/** A history's rows, oldest first, with their ids. */
|
|
35
|
+
export declare function readHistoryRows(history: FirebaseFirestore.CollectionReference, limit?: number): Promise<Array<AppendOnlyHistoryRow & {
|
|
36
|
+
$id: string;
|
|
37
|
+
}>>;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ import { sortHistoryRows } from "@aglyn/aglyn/app-utils/append-only-history";
|
|
18
|
+
import { createResourceUid } from "@aglyn/aglyn/app-utils/create-resource-uid";
|
|
19
|
+
import { FieldValue } from "firebase-admin/firestore";
|
|
20
|
+
import { setAdminAudit } from "./admin-audit-write.js";
|
|
21
|
+
/**
|
|
22
|
+
* Creates one history row in the writer, and its audit row beside it when
|
|
23
|
+
* `audit` is given. Returns the new row's reference.
|
|
24
|
+
*/ export function appendHistoryRow(writer, firestore, history, row, audit) {
|
|
25
|
+
// Minted once, before the write: the id is what the row's Stripe
|
|
26
|
+
// idempotency key is built from, so it never changes once written.
|
|
27
|
+
const ref = history.doc(createResourceUid());
|
|
28
|
+
writer.create(ref, row);
|
|
29
|
+
if (audit) {
|
|
30
|
+
setAdminAudit(writer, firestore, _extends({
|
|
31
|
+
actorUid: row.byUid,
|
|
32
|
+
actorEmail: row.byEmail,
|
|
33
|
+
action: audit.action,
|
|
34
|
+
scope: audit.scope,
|
|
35
|
+
target: audit.target,
|
|
36
|
+
reason: row.reason,
|
|
37
|
+
note: row.summary,
|
|
38
|
+
before: row.before,
|
|
39
|
+
after: row.after
|
|
40
|
+
}, row.stripe ? {
|
|
41
|
+
stripe: row.stripe
|
|
42
|
+
} : {}, {
|
|
43
|
+
at: FieldValue.serverTimestamp()
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
return ref;
|
|
47
|
+
}
|
|
48
|
+
/** Writes one row on its own (with its audit row), for a step with no other write. */ export async function commitHistoryRow(firestore, history, row, audit) {
|
|
49
|
+
const batch = firestore.batch();
|
|
50
|
+
appendHistoryRow(batch, firestore, history, row, audit);
|
|
51
|
+
await batch.commit();
|
|
52
|
+
}
|
|
53
|
+
/** A history's rows, oldest first, with their ids. */ export async function readHistoryRows(history, limit = 500) {
|
|
54
|
+
const snapshot = await history.orderBy('atMs', 'asc').limit(limit).get();
|
|
55
|
+
return sortHistoryRows(snapshot.docs.map((doc)=>_extends({
|
|
56
|
+
$id: doc.id
|
|
57
|
+
}, doc.data())));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=append-only-history-write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/append-only-history-write.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\nimport {\n type AppendOnlyHistoryRow,\n sortHistoryRows,\n} from '@aglyn/aglyn/app-utils/append-only-history'\nimport { createResourceUid } from '@aglyn/aglyn/app-utils/create-resource-uid'\nimport { FieldValue } from 'firebase-admin/firestore'\nimport { setAdminAudit } from './admin-audit-write'\n\n/*\n * THE WRITE SIDE OF AN APPEND-ONLY HISTORY (AGL-3959).\n *\n * A row is CREATED, never set over and never updated: `create` fails on an\n * id that exists, so no code path here can rewrite what happened. Each row\n * goes into the caller's batch beside the change it records, and — when a\n * staff member made the change — beside its `adminAudit` row, so the two\n * commit together or not at all. Reused by every approval-gated charge\n * (Site Care extra time now, AGL-3970's project invoices next); the row's\n * shape and rules are `@aglyn/aglyn/app-utils/append-only-history`.\n */\n\n/** A batch or a transaction: anything that creates and sets a document. */\ntype HistoryWriter =\n | Pick<FirebaseFirestore.WriteBatch, 'create' | 'set'>\n | Pick<FirebaseFirestore.Transaction, 'create' | 'set'>\n\n/** The staff audit row a history row is mirrored to. */\nexport interface HistoryAudit {\n action: string\n scope: string\n /** A path naming the org, so the staff org page's audit card finds it. */\n target: string\n}\n\n/**\n * Creates one history row in the writer, and its audit row beside it when\n * `audit` is given. Returns the new row's reference.\n */\nexport function appendHistoryRow(\n writer: HistoryWriter,\n firestore: FirebaseFirestore.Firestore,\n history: FirebaseFirestore.CollectionReference,\n row: AppendOnlyHistoryRow,\n audit?: HistoryAudit | null,\n): FirebaseFirestore.DocumentReference {\n // Minted once, before the write: the id is what the row's Stripe\n // idempotency key is built from, so it never changes once written.\n const ref = history.doc(createResourceUid())\n ;(writer as Pick<FirebaseFirestore.WriteBatch, 'create'>).create(ref, row)\n if (audit) {\n setAdminAudit(writer as Pick<FirebaseFirestore.WriteBatch, 'set'>, firestore, {\n actorUid: row.byUid,\n actorEmail: row.byEmail,\n action: audit.action,\n scope: audit.scope,\n target: audit.target,\n reason: row.reason,\n note: row.summary,\n before: row.before,\n after: row.after,\n ...(row.stripe ? { stripe: row.stripe } : {}),\n at: FieldValue.serverTimestamp(),\n })\n }\n return ref\n}\n\n/** Writes one row on its own (with its audit row), for a step with no other write. */\nexport async function commitHistoryRow(\n firestore: FirebaseFirestore.Firestore,\n history: FirebaseFirestore.CollectionReference,\n row: AppendOnlyHistoryRow,\n audit?: HistoryAudit | null,\n): Promise<void> {\n const batch = firestore.batch()\n appendHistoryRow(batch, firestore, history, row, audit)\n await batch.commit()\n}\n\n/** A history's rows, oldest first, with their ids. */\nexport async function readHistoryRows(\n history: FirebaseFirestore.CollectionReference,\n limit = 500,\n): Promise<Array<AppendOnlyHistoryRow & { $id: string }>> {\n const snapshot = await history.orderBy('atMs', 'asc').limit(limit).get()\n return sortHistoryRows(\n snapshot.docs.map((doc) => ({ $id: doc.id, ...(doc.data() as AppendOnlyHistoryRow) })),\n )\n}\n"],"names":["sortHistoryRows","createResourceUid","FieldValue","setAdminAudit","appendHistoryRow","writer","firestore","history","row","audit","ref","doc","create","actorUid","byUid","actorEmail","byEmail","action","scope","target","reason","note","summary","before","after","stripe","at","serverTimestamp","commitHistoryRow","batch","commit","readHistoryRows","limit","snapshot","orderBy","get","docs","map","$id","id","data"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAEEA,eAAe,QACV,6CAA4C;AACnD,SAASC,iBAAiB,QAAQ,6CAA4C;AAC9E,SAASC,UAAU,QAAQ,2BAA0B;AACrD,SAASC,aAAa,QAAQ,yBAAqB;AA2BnD;;;CAGC,GACD,OAAO,SAASC,iBACdC,MAAqB,EACrBC,SAAsC,EACtCC,OAA8C,EAC9CC,GAAyB,EACzBC,KAA2B;IAE3B,iEAAiE;IACjE,mEAAmE;IACnE,MAAMC,MAAMH,QAAQI,GAAG,CAACV;IACtBI,OAAwDO,MAAM,CAACF,KAAKF;IACtE,IAAIC,OAAO;QACTN,cAAcE,QAAqDC,WAAW;YAC5EO,UAAUL,IAAIM,KAAK;YACnBC,YAAYP,IAAIQ,OAAO;YACvBC,QAAQR,MAAMQ,MAAM;YACpBC,OAAOT,MAAMS,KAAK;YAClBC,QAAQV,MAAMU,MAAM;YACpBC,QAAQZ,IAAIY,MAAM;YAClBC,MAAMb,IAAIc,OAAO;YACjBC,QAAQf,IAAIe,MAAM;YAClBC,OAAOhB,IAAIgB,KAAK;WACZhB,IAAIiB,MAAM,GAAG;YAAEA,QAAQjB,IAAIiB,MAAM;QAAC,IAAI,CAAC;YAC3CC,IAAIxB,WAAWyB,eAAe;;IAElC;IACA,OAAOjB;AACT;AAEA,oFAAoF,GACpF,OAAO,eAAekB,iBACpBtB,SAAsC,EACtCC,OAA8C,EAC9CC,GAAyB,EACzBC,KAA2B;IAE3B,MAAMoB,QAAQvB,UAAUuB,KAAK;IAC7BzB,iBAAiByB,OAAOvB,WAAWC,SAASC,KAAKC;IACjD,MAAMoB,MAAMC,MAAM;AACpB;AAEA,oDAAoD,GACpD,OAAO,eAAeC,gBACpBxB,OAA8C,EAC9CyB,QAAQ,GAAG;IAEX,MAAMC,WAAW,MAAM1B,QAAQ2B,OAAO,CAAC,QAAQ,OAAOF,KAAK,CAACA,OAAOG,GAAG;IACtE,OAAOnC,gBACLiC,SAASG,IAAI,CAACC,GAAG,CAAC,CAAC1B,MAAS;YAAE2B,KAAK3B,IAAI4B,EAAE;WAAM5B,IAAI6B,IAAI;AAE3D"}
|
|
@@ -14,20 +14,21 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import {
|
|
17
|
+
import { type AiTierId, type OrgPlan } from '@aglyn/aglyn/server';
|
|
18
|
+
import { ADDON_KINDS, addonMaxForBaseline, addonMaxForPlan, addonUnitUsd, type AddonKind } from '@aglyn/aglyn/app-utils/bundle-intent';
|
|
19
|
+
export { ADDON_KINDS, addonMaxForBaseline, addonMaxForPlan, addonUnitUsd, type AddonKind };
|
|
18
20
|
/**
|
|
19
21
|
* Self-serve add-on price map (AGL-525): the bridge between
|
|
20
22
|
* `STRIPE_PRICE_*` env price ids, `org.seatAddons` keys, and
|
|
21
23
|
* `PLAN_PRICING` USD amounts. Add-ons bill as extra items on the org's
|
|
22
24
|
* one subscription, so every kind has a monthly and a yearly price
|
|
23
25
|
* (Stripe allows a single interval per subscription; annual orgs attach
|
|
24
|
-
* the `_YEARLY` variants). Seat/member/dataset/host prices
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
26
|
+
* the `_YEARLY` variants). Seat/member/dataset/host prices are per-plan;
|
|
27
|
+
* POS registers, the Event Calendar and Site Care (AGL-3954) are flat; the
|
|
28
|
+
* Aglyn AI add-on is priced per TIER (AGL-3965, `STRIPE_PRICE_AI_{TIER}`),
|
|
29
|
+
* on any paid plan. Prices are minted by `tools/scripts/setup-stripe.mjs` —
|
|
30
|
+
* keep the three in sync.
|
|
28
31
|
*/
|
|
29
|
-
export type AddonKind = keyof Required<OrgSeatAddons>;
|
|
30
|
-
export declare const ADDON_KINDS: readonly AddonKind[];
|
|
31
32
|
export type BillingInterval = 'month' | 'year';
|
|
32
33
|
/**
|
|
33
34
|
* Every plan that is sold with a Stripe price — DERIVED, never hand-listed
|
|
@@ -49,16 +50,65 @@ export type BillingInterval = 'month' | 'year';
|
|
|
49
50
|
* by definition a paid, priced plan.
|
|
50
51
|
*/
|
|
51
52
|
export declare const PAID_PLANS: readonly OrgPlan[];
|
|
53
|
+
/**
|
|
54
|
+
* The Stripe price id of an Aglyn AI tier (AGL-3965):
|
|
55
|
+
* `STRIPE_PRICE_AI_{TIER}[_YEARLY]`, lookup key `aglyn_ai_{tier}[_yearly]`.
|
|
56
|
+
* The same price on every plan; null when the env isn't configured.
|
|
57
|
+
*/
|
|
58
|
+
export declare function aiTierPriceId(tier: AiTierId, interval: BillingInterval): string | null;
|
|
59
|
+
/**
|
|
60
|
+
* The per-plan AI add-on price sold before tiers existed
|
|
61
|
+
* (`STRIPE_PRICE_{PLAN}_AI_ADDON[_YEARLY]`, AGL-2897). Never sold again; read
|
|
62
|
+
* only so an item still carrying one is recognised as the add-on and as the
|
|
63
|
+
* tier with its price and band until `migrate-ai-addon-tiers.mjs` moves it.
|
|
64
|
+
*/
|
|
65
|
+
export declare function legacyAiAddonPriceId(plan: OrgPlan, interval: BillingInterval): string | null;
|
|
66
|
+
/**
|
|
67
|
+
* Which Aglyn AI tier a price id sells (AGL-3965): a tier price, or a legacy
|
|
68
|
+
* per-plan add-on price read as the tier with the same price and band
|
|
69
|
+
* (`LEGACY_AI_ADDON_TIER_BY_PLAN`). Null for anything else.
|
|
70
|
+
*/
|
|
71
|
+
export declare function aiTierFromPriceId(priceId: string | null | undefined): AiTierId | null;
|
|
72
|
+
/**
|
|
73
|
+
* The tier a subscription's items carry (AGL-3965), or null when none is an
|
|
74
|
+
* Aglyn AI item with a quantity. Written to `org.aiTier` beside the
|
|
75
|
+
* `seatAddons` map `addonQuantitiesFromItems` derives from the same items.
|
|
76
|
+
*/
|
|
77
|
+
export declare function aiTierFromItems(items: ReadonlyArray<{
|
|
78
|
+
price?: {
|
|
79
|
+
id?: string;
|
|
80
|
+
} | null;
|
|
81
|
+
quantity?: number | null;
|
|
82
|
+
}> | null | undefined): AiTierId | null;
|
|
52
83
|
/**
|
|
53
84
|
* The Stripe price id for an add-on kind on a plan at a billing interval;
|
|
54
85
|
* null when the plan doesn't sell it (free) or the env isn't configured.
|
|
86
|
+
*
|
|
87
|
+
* `tier` picks the Aglyn AI tier; absent, the tier a plan-named purchase
|
|
88
|
+
* means (`defaultAiTierForPlan`). Ignored for every other kind.
|
|
55
89
|
*/
|
|
56
|
-
export declare function addonPriceId(kind: AddonKind, plan: OrgPlan, interval: BillingInterval): string | null;
|
|
90
|
+
export declare function addonPriceId(kind: AddonKind, plan: OrgPlan, interval: BillingInterval, tier?: AiTierId | null): string | null;
|
|
91
|
+
/**
|
|
92
|
+
* The env var that holds an add-on's price id on a plan at an interval, or
|
|
93
|
+
* null where the plan sells no such price. Named on its own so a checkout
|
|
94
|
+
* that Stripe refuses can say which variable points at a missing price.
|
|
95
|
+
* For the Aglyn AI add-on it is the tier's (`STRIPE_PRICE_AI_{TIER}`,
|
|
96
|
+
* AGL-3965), `tier` read as `addonPriceId` reads it.
|
|
97
|
+
*/
|
|
98
|
+
export declare function addonPriceEnvName(kind: AddonKind, plan: OrgPlan, interval: BillingInterval, tier?: AiTierId | null): string | null;
|
|
57
99
|
/**
|
|
58
100
|
* Reverse map: which add-on kind a subscription item's price id sells.
|
|
59
101
|
* Null for non-add-on prices (the base plan item, unknown prices).
|
|
60
102
|
*/
|
|
61
103
|
export declare function addonKindFromPriceId(priceId: string | null | undefined): AddonKind | null;
|
|
104
|
+
/**
|
|
105
|
+
* The price an add-on item moves to on a target plan/interval: the kind's
|
|
106
|
+
* price there, and for the Aglyn AI add-on the SAME tier the item carries
|
|
107
|
+
* now (AGL-3965) — a tier is chosen on its own, so a plan change re-prices
|
|
108
|
+
* only its interval, and a legacy per-plan item becomes the tier with its
|
|
109
|
+
* price and band.
|
|
110
|
+
*/
|
|
111
|
+
export declare function addonTargetPriceId(kind: AddonKind, plan: OrgPlan, interval: BillingInterval, currentPriceId: string | null | undefined): string | null;
|
|
62
112
|
/**
|
|
63
113
|
* The BASE plan's Stripe price id at an interval
|
|
64
114
|
* (`STRIPE_PRICE_{PLAN}[_YEARLY]`); null for `free`, for the custom-priced
|
|
@@ -136,12 +186,6 @@ export declare function findPlanItem<T extends {
|
|
|
136
186
|
id?: string;
|
|
137
187
|
} | null;
|
|
138
188
|
}>(items: readonly T[] | null | undefined): T | null;
|
|
139
|
-
/**
|
|
140
|
-
* Monthly USD per unit for an add-on on a plan (yearly prices are ×12 of
|
|
141
|
-
* this); null when the plan doesn't sell the kind. Single pricing source
|
|
142
|
-
* of truth: `PLAN_PRICING` + the three flat add-on constants.
|
|
143
|
-
*/
|
|
144
|
-
export declare function addonUnitUsd(kind: AddonKind, plan: OrgPlan): number | null;
|
|
145
189
|
/**
|
|
146
190
|
* Full add-on quantity map (explicit zeros for absent kinds) from a
|
|
147
191
|
* subscription's items — the shape written to `org.seatAddons` so
|
|
@@ -153,21 +197,3 @@ export declare function addonQuantitiesFromItems(items: Array<{
|
|
|
153
197
|
} | null;
|
|
154
198
|
quantity?: number | null;
|
|
155
199
|
}> | null | undefined): Record<AddonKind, number>;
|
|
156
|
-
/**
|
|
157
|
-
* Max purchasable quantity per kind, from a purchases-free entitlement
|
|
158
|
-
* resolution (plan defaults + staff overrides only) so the ceiling does not
|
|
159
|
-
* drift as the org buys: seat/dataset kinds stop at the plan's hard max,
|
|
160
|
-
* hosts/registers use flat ceilings, the Event Calendar, Aglyn AI and Site
|
|
161
|
-
* Care are 0/1 toggles. POS registers additionally require the `pos`
|
|
162
|
-
* feature, and Site Care a plan that sells it (`planSellsSiteCare`), which is
|
|
163
|
-
* why the plan travels with the baseline.
|
|
164
|
-
*
|
|
165
|
-
* Lives here rather than inside `/api/billing/addons` because a PLAN CHANGE
|
|
166
|
-
* needs the same ceiling for a different plan. The addons route asks "how many
|
|
167
|
-
* may this org buy on the plan it is on"; `buildTargetItems` asks "how many of
|
|
168
|
-
* what it already bought can the plan it is moving to actually deliver". Two
|
|
169
|
-
* readers, one definition — a second copy is how they answer differently.
|
|
170
|
-
*/
|
|
171
|
-
export declare function addonMaxForBaseline(kind: AddonKind, baseline: ReturnType<typeof resolveOrgEntitlements>, plan: OrgPlan): number;
|
|
172
|
-
/** The ceiling a PLAN would impose on an add-on kind, purchases excluded. */
|
|
173
|
-
export declare function addonMaxForPlan(kind: AddonKind, plan: OrgPlan): number;
|
|
@@ -13,23 +13,24 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/ import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
*/ import { SELF_SERVE_PLANS } from "@aglyn/aglyn/server";
|
|
17
|
+
import { ADDON_KINDS, addonMaxForBaseline, addonMaxForPlan, addonUnitUsd } from "@aglyn/aglyn/app-utils/bundle-intent";
|
|
18
|
+
// The Aglyn AI tiers (AGL-3965) by their own module rather than the server
|
|
19
|
+
// barrel: the webhook and every billing route read a subscription's AI item
|
|
20
|
+
// through here, and the many route specs that stub `@aglyn/aglyn/server`
|
|
21
|
+
// with a partial object would otherwise see every tier helper as undefined.
|
|
22
|
+
import { AI_TIER_IDS, defaultAiTierForPlan, LEGACY_AI_ADDON_TIER_BY_PLAN, planSellsAiTiers } from "@aglyn/aglyn/app-utils/plan-entitlements";
|
|
23
|
+
/*
|
|
24
|
+
* The add-on kinds, their unit prices (the Aglyn AI tier's included) and
|
|
25
|
+
* their ceilings live beside the bundle-link parser (AGL-3955), so the link,
|
|
26
|
+
* the Billing card and this price map read one list. Re-exported here for
|
|
27
|
+
* every server reader that already imports them from this module.
|
|
28
|
+
*/ export { ADDON_KINDS, addonMaxForBaseline, addonMaxForPlan, addonUnitUsd };
|
|
27
29
|
/** Kinds priced per plan (env `STRIPE_PRICE_{PLAN}_{SUFFIX}[_YEARLY]`). */ const PER_PLAN_ENV_SUFFIX = {
|
|
28
30
|
managers: 'EXTRA_SEAT',
|
|
29
31
|
members: 'EXTRA_MEMBER',
|
|
30
32
|
datasets: 'EXTRA_DATASET',
|
|
31
|
-
hosts: 'EXTRA_HOST'
|
|
32
|
-
aiAddon: 'AI_ADDON'
|
|
33
|
+
hosts: 'EXTRA_HOST'
|
|
33
34
|
};
|
|
34
35
|
/** Kinds priced flat across plans (env `STRIPE_PRICE_{SUFFIX}[_YEARLY]`). */ const FLAT_ENV_NAME = {
|
|
35
36
|
posRegisters: 'POS_REGISTER',
|
|
@@ -59,23 +60,96 @@ function env(name) {
|
|
|
59
60
|
const value = process.env[name];
|
|
60
61
|
return value ? value : null;
|
|
61
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* The Stripe price id of an Aglyn AI tier (AGL-3965):
|
|
65
|
+
* `STRIPE_PRICE_AI_{TIER}[_YEARLY]`, lookup key `aglyn_ai_{tier}[_yearly]`.
|
|
66
|
+
* The same price on every plan; null when the env isn't configured.
|
|
67
|
+
*/ export function aiTierPriceId(tier, interval) {
|
|
68
|
+
const yearly = interval === 'year' ? '_YEARLY' : '';
|
|
69
|
+
return env(`STRIPE_PRICE_AI_${tier.toUpperCase()}${yearly}`);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The per-plan AI add-on price sold before tiers existed
|
|
73
|
+
* (`STRIPE_PRICE_{PLAN}_AI_ADDON[_YEARLY]`, AGL-2897). Never sold again; read
|
|
74
|
+
* only so an item still carrying one is recognised as the add-on and as the
|
|
75
|
+
* tier with its price and band until `migrate-ai-addon-tiers.mjs` moves it.
|
|
76
|
+
*/ export function legacyAiAddonPriceId(plan, interval) {
|
|
77
|
+
if (!PAID_PLANS.includes(plan)) return null;
|
|
78
|
+
const yearly = interval === 'year' ? '_YEARLY' : '';
|
|
79
|
+
return env(`STRIPE_PRICE_${plan.toUpperCase()}_AI_ADDON${yearly}`);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Which Aglyn AI tier a price id sells (AGL-3965): a tier price, or a legacy
|
|
83
|
+
* per-plan add-on price read as the tier with the same price and band
|
|
84
|
+
* (`LEGACY_AI_ADDON_TIER_BY_PLAN`). Null for anything else.
|
|
85
|
+
*/ export function aiTierFromPriceId(priceId) {
|
|
86
|
+
if (!priceId) return null;
|
|
87
|
+
for (const interval of [
|
|
88
|
+
'month',
|
|
89
|
+
'year'
|
|
90
|
+
]){
|
|
91
|
+
for (const tier of AI_TIER_IDS){
|
|
92
|
+
if (aiTierPriceId(tier, interval) === priceId) return tier;
|
|
93
|
+
}
|
|
94
|
+
for (const plan of PAID_PLANS){
|
|
95
|
+
if (legacyAiAddonPriceId(plan, interval) === priceId) {
|
|
96
|
+
var _LEGACY_AI_ADDON_TIER_BY_PLAN_plan;
|
|
97
|
+
return (_LEGACY_AI_ADDON_TIER_BY_PLAN_plan = LEGACY_AI_ADDON_TIER_BY_PLAN[plan]) != null ? _LEGACY_AI_ADDON_TIER_BY_PLAN_plan : null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The tier a subscription's items carry (AGL-3965), or null when none is an
|
|
105
|
+
* Aglyn AI item with a quantity. Written to `org.aiTier` beside the
|
|
106
|
+
* `seatAddons` map `addonQuantitiesFromItems` derives from the same items.
|
|
107
|
+
*/ export function aiTierFromItems(items) {
|
|
108
|
+
for (const item of items != null ? items : []){
|
|
109
|
+
var _ref;
|
|
110
|
+
var _item_price;
|
|
111
|
+
const tier = aiTierFromPriceId(item == null ? void 0 : (_item_price = item.price) == null ? void 0 : _item_price.id);
|
|
112
|
+
if (tier && Number((_ref = item == null ? void 0 : item.quantity) != null ? _ref : 1) >= 1) return tier;
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
62
116
|
/**
|
|
63
117
|
* The Stripe price id for an add-on kind on a plan at a billing interval;
|
|
64
118
|
* null when the plan doesn't sell it (free) or the env isn't configured.
|
|
65
|
-
|
|
119
|
+
*
|
|
120
|
+
* `tier` picks the Aglyn AI tier; absent, the tier a plan-named purchase
|
|
121
|
+
* means (`defaultAiTierForPlan`). Ignored for every other kind.
|
|
122
|
+
*/ export function addonPriceId(kind, plan, interval, tier) {
|
|
123
|
+
const name = addonPriceEnvName(kind, plan, interval, tier);
|
|
124
|
+
return name ? env(name) : null;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The env var that holds an add-on's price id on a plan at an interval, or
|
|
128
|
+
* null where the plan sells no such price. Named on its own so a checkout
|
|
129
|
+
* that Stripe refuses can say which variable points at a missing price.
|
|
130
|
+
* For the Aglyn AI add-on it is the tier's (`STRIPE_PRICE_AI_{TIER}`,
|
|
131
|
+
* AGL-3965), `tier` read as `addonPriceId` reads it.
|
|
132
|
+
*/ export function addonPriceEnvName(kind, plan, interval, tier) {
|
|
66
133
|
const yearly = interval === 'year' ? '_YEARLY' : '';
|
|
134
|
+
if (kind === 'aiAddon') {
|
|
135
|
+
if (!planSellsAiTiers(plan)) return null;
|
|
136
|
+
const chosen = tier != null ? tier : defaultAiTierForPlan(plan);
|
|
137
|
+
return chosen ? `STRIPE_PRICE_AI_${chosen.toUpperCase()}${yearly}` : null;
|
|
138
|
+
}
|
|
67
139
|
const flat = FLAT_ENV_NAME[kind];
|
|
68
|
-
if (flat) return
|
|
140
|
+
if (flat) return `STRIPE_PRICE_${flat}${yearly}`;
|
|
69
141
|
const suffix = PER_PLAN_ENV_SUFFIX[kind];
|
|
70
142
|
if (!suffix || plan === 'free') return null;
|
|
71
|
-
return
|
|
143
|
+
return `STRIPE_PRICE_${plan.toUpperCase()}_${suffix}${yearly}`;
|
|
72
144
|
}
|
|
73
145
|
/**
|
|
74
146
|
* Reverse map: which add-on kind a subscription item's price id sells.
|
|
75
147
|
* Null for non-add-on prices (the base plan item, unknown prices).
|
|
76
148
|
*/ export function addonKindFromPriceId(priceId) {
|
|
77
149
|
if (!priceId) return null;
|
|
150
|
+
if (aiTierFromPriceId(priceId)) return 'aiAddon';
|
|
78
151
|
for (const kind of ADDON_KINDS){
|
|
152
|
+
if (kind === 'aiAddon') continue;
|
|
79
153
|
for (const interval of [
|
|
80
154
|
'month',
|
|
81
155
|
'year'
|
|
@@ -91,6 +165,16 @@ function env(name) {
|
|
|
91
165
|
}
|
|
92
166
|
return null;
|
|
93
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* The price an add-on item moves to on a target plan/interval: the kind's
|
|
170
|
+
* price there, and for the Aglyn AI add-on the SAME tier the item carries
|
|
171
|
+
* now (AGL-3965) — a tier is chosen on its own, so a plan change re-prices
|
|
172
|
+
* only its interval, and a legacy per-plan item becomes the tier with its
|
|
173
|
+
* price and band.
|
|
174
|
+
*/ export function addonTargetPriceId(kind, plan, interval, currentPriceId) {
|
|
175
|
+
const tier = kind === 'aiAddon' ? aiTierFromPriceId(currentPriceId) : null;
|
|
176
|
+
return addonPriceId(kind, plan, interval, tier);
|
|
177
|
+
}
|
|
94
178
|
/**
|
|
95
179
|
* The BASE plan's Stripe price id at an interval
|
|
96
180
|
* (`STRIPE_PRICE_{PLAN}[_YEARLY]`); null for `free`, for the custom-priced
|
|
@@ -195,31 +279,6 @@ function env(name) {
|
|
|
195
279
|
});
|
|
196
280
|
return (_ref = notAnAddon != null ? notAnAddon : list[0]) != null ? _ref : null;
|
|
197
281
|
}
|
|
198
|
-
/**
|
|
199
|
-
* Monthly USD per unit for an add-on on a plan (yearly prices are ×12 of
|
|
200
|
-
* this); null when the plan doesn't sell the kind. Single pricing source
|
|
201
|
-
* of truth: `PLAN_PRICING` + the three flat add-on constants.
|
|
202
|
-
*/ export function addonUnitUsd(kind, plan) {
|
|
203
|
-
const pricing = PLAN_PRICING[plan];
|
|
204
|
-
switch(kind){
|
|
205
|
-
case 'managers':
|
|
206
|
-
return pricing.extraSeatMonthlyUsd;
|
|
207
|
-
case 'members':
|
|
208
|
-
return pricing.extraCollaboratorMonthlyUsd;
|
|
209
|
-
case 'datasets':
|
|
210
|
-
return pricing.extraDatasetMonthlyUsd;
|
|
211
|
-
case 'hosts':
|
|
212
|
-
return pricing.extraHostMonthlyUsd;
|
|
213
|
-
case 'posRegisters':
|
|
214
|
-
return POS_REGISTER_ADDON_MONTHLY_USD;
|
|
215
|
-
case 'eventCalendar':
|
|
216
|
-
return EVENT_CALENDAR_ADDON_MONTHLY_USD;
|
|
217
|
-
case 'aiAddon':
|
|
218
|
-
return pricing.aiAddonMonthlyUsd;
|
|
219
|
-
case 'siteCare':
|
|
220
|
-
return SITE_CARE_ADDON_MONTHLY_USD;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
282
|
/**
|
|
224
283
|
* Full add-on quantity map (explicit zeros for absent kinds) from a
|
|
225
284
|
* subscription's items — the shape written to `org.seatAddons` so
|
|
@@ -239,50 +298,5 @@ function env(name) {
|
|
|
239
298
|
}
|
|
240
299
|
return quantities;
|
|
241
300
|
}
|
|
242
|
-
/**
|
|
243
|
-
* Max purchasable quantity per kind, from a purchases-free entitlement
|
|
244
|
-
* resolution (plan defaults + staff overrides only) so the ceiling does not
|
|
245
|
-
* drift as the org buys: seat/dataset kinds stop at the plan's hard max,
|
|
246
|
-
* hosts/registers use flat ceilings, the Event Calendar, Aglyn AI and Site
|
|
247
|
-
* Care are 0/1 toggles. POS registers additionally require the `pos`
|
|
248
|
-
* feature, and Site Care a plan that sells it (`planSellsSiteCare`), which is
|
|
249
|
-
* why the plan travels with the baseline.
|
|
250
|
-
*
|
|
251
|
-
* Lives here rather than inside `/api/billing/addons` because a PLAN CHANGE
|
|
252
|
-
* needs the same ceiling for a different plan. The addons route asks "how many
|
|
253
|
-
* may this org buy on the plan it is on"; `buildTargetItems` asks "how many of
|
|
254
|
-
* what it already bought can the plan it is moving to actually deliver". Two
|
|
255
|
-
* readers, one definition — a second copy is how they answer differently.
|
|
256
|
-
*/ export function addonMaxForBaseline(kind, baseline, plan) {
|
|
257
|
-
const bounded = (included, max)=>Number.isFinite(max) ? Math.max(0, max - included) : EXTRA_HOSTS_ADDON_MAX;
|
|
258
|
-
switch(kind){
|
|
259
|
-
case 'managers':
|
|
260
|
-
return bounded(baseline.managersPerOrg, baseline.maxManagersPerOrg);
|
|
261
|
-
case 'members':
|
|
262
|
-
return bounded(baseline.membersPerHost, baseline.maxMembersPerHost);
|
|
263
|
-
case 'datasets':
|
|
264
|
-
return bounded(baseline.datasetsPerOrg, baseline.maxDatasetsPerOrg);
|
|
265
|
-
case 'hosts':
|
|
266
|
-
return baseline.hostLimit === UNLIMITED ? 0 : EXTRA_HOSTS_ADDON_MAX;
|
|
267
|
-
case 'posRegisters':
|
|
268
|
-
return baseline.features.pos ? POS_REGISTERS_ADDON_MAX : 0;
|
|
269
|
-
case 'eventCalendar':
|
|
270
|
-
return 1;
|
|
271
|
-
case 'aiAddon':
|
|
272
|
-
// Org-wide like the Event Calendar: one purchase, and the price map
|
|
273
|
-
// (null on Free and Enterprise) says whether the plan sells it at all.
|
|
274
|
-
return 1;
|
|
275
|
-
case 'siteCare':
|
|
276
|
-
// Flat-priced, so the price map cannot say "not sold here" the way it
|
|
277
|
-
// does for Aglyn AI. This ceiling is the rule that keeps Free (no
|
|
278
|
-
// subscription) and Enterprise (quoted per deal) from buying it.
|
|
279
|
-
return planSellsSiteCare(plan) ? 1 : 0;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
/** The ceiling a PLAN would impose on an add-on kind, purchases excluded. */ export function addonMaxForPlan(kind, plan) {
|
|
283
|
-
return addonMaxForBaseline(kind, resolveOrgEntitlements({
|
|
284
|
-
plan
|
|
285
|
-
}), plan);
|
|
286
|
-
}
|
|
287
301
|
|
|
288
302
|
//# sourceMappingURL=billing-addons.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/billing-addons.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\nimport {\n EVENT_CALENDAR_ADDON_MONTHLY_USD,\n EXTRA_HOSTS_ADDON_MAX,\n PLAN_PRICING,\n planSellsSiteCare,\n POS_REGISTER_ADDON_MONTHLY_USD,\n POS_REGISTERS_ADDON_MAX,\n resolveOrgEntitlements,\n SELF_SERVE_PLANS,\n SITE_CARE_ADDON_MONTHLY_USD,\n UNLIMITED,\n type OrgPlan,\n type OrgSeatAddons,\n} from '@aglyn/aglyn/server'\n\n/**\n * Self-serve add-on price map (AGL-525): the bridge between\n * `STRIPE_PRICE_*` env price ids, `org.seatAddons` keys, and\n * `PLAN_PRICING` USD amounts. Add-ons bill as extra items on the org's\n * one subscription, so every kind has a monthly and a yearly price\n * (Stripe allows a single interval per subscription; annual orgs attach\n * the `_YEARLY` variants). Seat/member/dataset/host prices and the Aglyn AI\n * add-on (AGL-2896) are per-plan; POS registers, the Event Calendar and\n * Site Care (AGL-3954) are flat. Prices are minted by `tools/scripts/setup-stripe.mjs` — keep the\n * three in sync.\n */\nexport type AddonKind = keyof Required<OrgSeatAddons>\n\nexport const ADDON_KINDS: readonly AddonKind[] = [\n 'managers',\n 'members',\n 'datasets',\n 'hosts',\n 'posRegisters',\n 'eventCalendar',\n 'aiAddon',\n 'siteCare',\n]\n\nexport type BillingInterval = 'month' | 'year'\n\n/** Kinds priced per plan (env `STRIPE_PRICE_{PLAN}_{SUFFIX}[_YEARLY]`). */\nconst PER_PLAN_ENV_SUFFIX: Partial<Record<AddonKind, string>> = {\n managers: 'EXTRA_SEAT',\n members: 'EXTRA_MEMBER',\n datasets: 'EXTRA_DATASET',\n hosts: 'EXTRA_HOST',\n aiAddon: 'AI_ADDON',\n}\n\n/** Kinds priced flat across plans (env `STRIPE_PRICE_{SUFFIX}[_YEARLY]`). */\nconst FLAT_ENV_NAME: Partial<Record<AddonKind, string>> = {\n posRegisters: 'POS_REGISTER',\n eventCalendar: 'EVENT_CALENDAR',\n siteCare: 'SITE_CARE',\n}\n\n/**\n * Every plan that is sold with a Stripe price — DERIVED, never hand-listed\n * (AGL-1340).\n *\n * The literal that used to sit here listed starter, pro, business and\n * advanced only — it predated the Scale and Agency tiers, so\n * `addonKindFromPriceId()` could not recognise a single Scale/Agency add-on\n * price coming back from Stripe. `addonPriceId()` still SOLD them (it only\n * uppercases the plan), so the money moved and the read-back returned\n * nothing: the webhook wrote `seatAddons: {all zeros}` for the\n * highest-paying orgs on the next subscription event, and `seatAddons` is an\n * ENTITLEMENT INPUT (`plan-entitlements.ts` — it raises `hostLimit` and\n * `posRegisters`, and flips the `eventCalendar` feature).\n *\n * Deriving from `SELF_SERVE_PLANS` is what stops the next tier from\n * reintroducing it: `free` has nothing to sell and `enterprise` is quoted\n * per deal (no `STRIPE_PRICE_ENTERPRISE_*` exists), so everything else is\n * by definition a paid, priced plan.\n */\nexport const PAID_PLANS: readonly OrgPlan[] = SELF_SERVE_PLANS.filter(\n (plan) => plan !== 'free',\n)\n\nfunction env(name: string): string | null {\n const value = process.env[name]\n return value ? value : null\n}\n\n/**\n * The Stripe price id for an add-on kind on a plan at a billing interval;\n * null when the plan doesn't sell it (free) or the env isn't configured.\n */\nexport function addonPriceId(\n kind: AddonKind,\n plan: OrgPlan,\n interval: BillingInterval,\n): string | null {\n const yearly = interval === 'year' ? '_YEARLY' : ''\n const flat = FLAT_ENV_NAME[kind]\n if (flat) return env(`STRIPE_PRICE_${flat}${yearly}`)\n const suffix = PER_PLAN_ENV_SUFFIX[kind]\n if (!suffix || plan === 'free') return null\n return env(`STRIPE_PRICE_${plan.toUpperCase()}_${suffix}${yearly}`)\n}\n\n/**\n * Reverse map: which add-on kind a subscription item's price id sells.\n * Null for non-add-on prices (the base plan item, unknown prices).\n */\nexport function addonKindFromPriceId(\n priceId: string | null | undefined,\n): AddonKind | null {\n if (!priceId) return null\n for (const kind of ADDON_KINDS) {\n for (const interval of ['month', 'year'] as const) {\n if (FLAT_ENV_NAME[kind]) {\n if (addonPriceId(kind, 'starter', interval) === priceId) return kind\n continue\n }\n for (const plan of PAID_PLANS) {\n if (addonPriceId(kind, plan, interval) === priceId) return kind\n }\n }\n }\n return null\n}\n\n/**\n * The BASE plan's Stripe price id at an interval\n * (`STRIPE_PRICE_{PLAN}[_YEARLY]`); null for `free`, for the custom-priced\n * `enterprise`, and for an env that isn't configured. Read at call time, so\n * it never freezes a stale value at module load the way the routes'\n * `PRICE_ENV` maps do.\n */\nexport function planPriceId(\n plan: OrgPlan,\n interval: BillingInterval,\n): string | null {\n if (!PAID_PLANS.includes(plan)) return null\n const yearly = interval === 'year' ? '_YEARLY' : ''\n return env(`STRIPE_PRICE_${plan.toUpperCase()}${yearly}`)\n}\n\n/**\n * Which plan a subscription item's price sells AND on which interval; null for\n * an add-on price, the metered price, an ad-hoc enterprise price, and anything\n * unknown.\n *\n * The interval half exists because a schedule phase read back from Stripe\n * carries price IDS and nothing else (AGL-2150): rebuilding that phase's item\n * list needs to know which interval it is priced on, and guessing it from the\n * live subscription is wrong exactly when the pending change is also an\n * interval change.\n */\nexport function planAndIntervalFromPriceId(\n priceId: string | null | undefined,\n): { plan: OrgPlan; interval: BillingInterval } | null {\n if (!priceId) return null\n for (const plan of PAID_PLANS) {\n for (const interval of ['month', 'year'] as const) {\n if (planPriceId(plan, interval) === priceId) return { plan, interval }\n }\n }\n return null\n}\n\n/**\n * Which plan a subscription item's price sells; null for an add-on price,\n * the metered price, an ad-hoc enterprise price, and anything unknown.\n */\nexport function planFromPriceId(\n priceId: string | null | undefined,\n): OrgPlan | null {\n return planAndIntervalFromPriceId(priceId)?.plan ?? null\n}\n\n/**\n * The shared metered-usage price (AGL-635) that makes reported usage\n * billable, for a given billing interval.\n *\n * Stripe rejects a subscription whose items mix `recurring.interval`, so the\n * metered item has to recur the same way the plan does. There are two prices\n * — `aglyn_metered_usage` (monthly) and `aglyn_metered_usage_yearly` — and\n * both bill $0.01 per aggregated unit against the SAME meter, because the\n * rollup posts an already-computed value in CENTS. The interval is therefore\n * the only thing that differs, and it is the only thing a caller must get\n * right.\n *\n * `interval` is REQUIRED on purpose (AGL-1280). It used to be monthly-only\n * with no argument, so the failure mode of forgetting it was attaching a\n * monthly price to a yearly subscription — the exact mixed-interval crash\n * this signature now makes unrepresentable. A default would hand that\n * footgun straight back.\n */\nexport function meteredPriceId(interval: 'month' | 'year'): string | null {\n return env(\n interval === 'year' ? 'STRIPE_PRICE_METERED_YEARLY' : 'STRIPE_PRICE_METERED',\n )\n}\n\n/**\n * Whether a price id is EITHER shared metered-usage price.\n *\n * Interval-agnostic by design: callers ask this to exclude the metered item\n * from plan/add-on reasoning, and an annual subscription's metered item must\n * be excluded just as thoroughly as a monthly one.\n */\nexport function isMeteredPriceId(priceId: string | null | undefined): boolean {\n if (!priceId) return false\n return (\n priceId === meteredPriceId('month') || priceId === meteredPriceId('year')\n )\n}\n\n/**\n * The subscription's BASE PLAN item, identified POSITIVELY (AGL-1340).\n *\n * This used to be \"whatever no add-on price claims\" — identification by\n * elimination, which quietly returns the wrong item the moment a\n * subscription carries anything the add-on map doesn't recognise: the\n * metered item, a grandfathered v1 price, a coupon-era SKU, an item added\n * by hand in the Stripe dashboard. Picking an add-on item as the plan item\n * means a plan switch re-prices the ADD-ON, and reads the billing interval\n * off it.\n *\n * So: match a known `STRIPE_PRICE_{PLAN}[_YEARLY]` first. Only when nothing\n * matches — an enterprise deal bills on an ad-hoc price, and grandfathered\n * subscriptions predate the current SKUs — fall back to the old rule,\n * minus the metered item, and finally to `items[0]` so behaviour for those\n * subscriptions is unchanged.\n */\nexport function findPlanItem<T extends { price?: { id?: string } | null }>(\n items: readonly T[] | null | undefined,\n): T | null {\n const list = items ?? []\n const byPlanPrice = list.find((item) => planFromPriceId(item?.price?.id))\n if (byPlanPrice) return byPlanPrice\n const notAnAddon = list.find(\n (item) =>\n !addonKindFromPriceId(item?.price?.id) &&\n !isMeteredPriceId(item?.price?.id),\n )\n return notAnAddon ?? list[0] ?? null\n}\n\n/**\n * Monthly USD per unit for an add-on on a plan (yearly prices are ×12 of\n * this); null when the plan doesn't sell the kind. Single pricing source\n * of truth: `PLAN_PRICING` + the three flat add-on constants.\n */\nexport function addonUnitUsd(kind: AddonKind, plan: OrgPlan): number | null {\n const pricing = PLAN_PRICING[plan]\n switch (kind) {\n case 'managers':\n return pricing.extraSeatMonthlyUsd\n case 'members':\n return pricing.extraCollaboratorMonthlyUsd\n case 'datasets':\n return pricing.extraDatasetMonthlyUsd\n case 'hosts':\n return pricing.extraHostMonthlyUsd\n case 'posRegisters':\n return POS_REGISTER_ADDON_MONTHLY_USD\n case 'eventCalendar':\n return EVENT_CALENDAR_ADDON_MONTHLY_USD\n case 'aiAddon':\n return pricing.aiAddonMonthlyUsd\n case 'siteCare':\n return SITE_CARE_ADDON_MONTHLY_USD\n }\n}\n\n/**\n * Full add-on quantity map (explicit zeros for absent kinds) from a\n * subscription's items — the shape written to `org.seatAddons` so\n * removals and dashboard edits converge on sync (AGL-527).\n */\nexport function addonQuantitiesFromItems(\n items:\n | Array<{ price?: { id?: string } | null; quantity?: number | null }>\n | null\n | undefined,\n): Record<AddonKind, number> {\n const quantities = Object.fromEntries(\n ADDON_KINDS.map((kind) => [kind, 0]),\n ) as Record<AddonKind, number>\n for (const item of items ?? []) {\n const kind = addonKindFromPriceId(item?.price?.id)\n if (kind) {\n quantities[kind] += Math.max(0, Math.floor(Number(item?.quantity ?? 0)))\n }\n }\n return quantities\n}\n\n/**\n * Max purchasable quantity per kind, from a purchases-free entitlement\n * resolution (plan defaults + staff overrides only) so the ceiling does not\n * drift as the org buys: seat/dataset kinds stop at the plan's hard max,\n * hosts/registers use flat ceilings, the Event Calendar, Aglyn AI and Site\n * Care are 0/1 toggles. POS registers additionally require the `pos`\n * feature, and Site Care a plan that sells it (`planSellsSiteCare`), which is\n * why the plan travels with the baseline.\n *\n * Lives here rather than inside `/api/billing/addons` because a PLAN CHANGE\n * needs the same ceiling for a different plan. The addons route asks \"how many\n * may this org buy on the plan it is on\"; `buildTargetItems` asks \"how many of\n * what it already bought can the plan it is moving to actually deliver\". Two\n * readers, one definition — a second copy is how they answer differently.\n */\nexport function addonMaxForBaseline(\n kind: AddonKind,\n baseline: ReturnType<typeof resolveOrgEntitlements>,\n plan: OrgPlan,\n): number {\n const bounded = (included: number, max: number) =>\n Number.isFinite(max) ? Math.max(0, max - included) : EXTRA_HOSTS_ADDON_MAX\n switch (kind) {\n case 'managers':\n return bounded(baseline.managersPerOrg, baseline.maxManagersPerOrg)\n case 'members':\n return bounded(baseline.membersPerHost, baseline.maxMembersPerHost)\n case 'datasets':\n return bounded(baseline.datasetsPerOrg, baseline.maxDatasetsPerOrg)\n case 'hosts':\n return baseline.hostLimit === UNLIMITED ? 0 : EXTRA_HOSTS_ADDON_MAX\n case 'posRegisters':\n return baseline.features.pos ? POS_REGISTERS_ADDON_MAX : 0\n case 'eventCalendar':\n return 1\n case 'aiAddon':\n // Org-wide like the Event Calendar: one purchase, and the price map\n // (null on Free and Enterprise) says whether the plan sells it at all.\n return 1\n case 'siteCare':\n // Flat-priced, so the price map cannot say \"not sold here\" the way it\n // does for Aglyn AI. This ceiling is the rule that keeps Free (no\n // subscription) and Enterprise (quoted per deal) from buying it.\n return planSellsSiteCare(plan) ? 1 : 0\n }\n}\n\n/** The ceiling a PLAN would impose on an add-on kind, purchases excluded. */\nexport function addonMaxForPlan(kind: AddonKind, plan: OrgPlan): number {\n return addonMaxForBaseline(\n kind,\n resolveOrgEntitlements({ plan } as never),\n plan,\n )\n}\n"],"names":["EVENT_CALENDAR_ADDON_MONTHLY_USD","EXTRA_HOSTS_ADDON_MAX","PLAN_PRICING","planSellsSiteCare","POS_REGISTER_ADDON_MONTHLY_USD","POS_REGISTERS_ADDON_MAX","resolveOrgEntitlements","SELF_SERVE_PLANS","SITE_CARE_ADDON_MONTHLY_USD","UNLIMITED","ADDON_KINDS","PER_PLAN_ENV_SUFFIX","managers","members","datasets","hosts","aiAddon","FLAT_ENV_NAME","posRegisters","eventCalendar","siteCare","PAID_PLANS","filter","plan","env","name","value","process","addonPriceId","kind","interval","yearly","flat","suffix","toUpperCase","addonKindFromPriceId","priceId","planPriceId","includes","planAndIntervalFromPriceId","planFromPriceId","meteredPriceId","isMeteredPriceId","findPlanItem","items","notAnAddon","list","byPlanPrice","find","item","price","id","addonUnitUsd","pricing","extraSeatMonthlyUsd","extraCollaboratorMonthlyUsd","extraDatasetMonthlyUsd","extraHostMonthlyUsd","aiAddonMonthlyUsd","addonQuantitiesFromItems","quantities","Object","fromEntries","map","Math","max","floor","Number","quantity","addonMaxForBaseline","baseline","bounded","included","isFinite","managersPerOrg","maxManagersPerOrg","membersPerHost","maxMembersPerHost","datasetsPerOrg","maxDatasetsPerOrg","hostLimit","features","pos","addonMaxForPlan"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,gCAAgC,EAChCC,qBAAqB,EACrBC,YAAY,EACZC,iBAAiB,EACjBC,8BAA8B,EAC9BC,uBAAuB,EACvBC,sBAAsB,EACtBC,gBAAgB,EAChBC,2BAA2B,EAC3BC,SAAS,QAGJ,sBAAqB;AAe5B,OAAO,MAAMC,cAAoC;IAC/C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAID,yEAAyE,GACzE,MAAMC,sBAA0D;IAC9DC,UAAU;IACVC,SAAS;IACTC,UAAU;IACVC,OAAO;IACPC,SAAS;AACX;AAEA,2EAA2E,GAC3E,MAAMC,gBAAoD;IACxDC,cAAc;IACdC,eAAe;IACfC,UAAU;AACZ;AAEA;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,MAAMC,aAAiCd,iBAAiBe,MAAM,CACnE,CAACC,OAASA,SAAS,QACpB;AAED,SAASC,IAAIC,IAAY;IACvB,MAAMC,QAAQC,QAAQH,GAAG,CAACC,KAAK;IAC/B,OAAOC,QAAQA,QAAQ;AACzB;AAEA;;;CAGC,GACD,OAAO,SAASE,aACdC,IAAe,EACfN,IAAa,EACbO,QAAyB;IAEzB,MAAMC,SAASD,aAAa,SAAS,YAAY;IACjD,MAAME,OAAOf,aAAa,CAACY,KAAK;IAChC,IAAIG,MAAM,OAAOR,IAAI,CAAC,aAAa,EAAEQ,OAAOD,QAAQ;IACpD,MAAME,SAAStB,mBAAmB,CAACkB,KAAK;IACxC,IAAI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AMoB,QAAQL,gBAAAA,QAAS,EAAE,CAAE;YACIK;QAAlC,MAAMpB,OAAOM,qBAAqBc,yBAAAA,cAAAA,KAAMC,KAAK,qBAAXD,YAAaE,EAAE;QACjD,IAAItB,MAAM;;YACR+B,UAAU,CAAC/B,KAAK,IAAImC,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,CAACC,eAAOlB,wBAAAA,KAAMmB,QAAQ,mBAAI;QACtE;IACF;IACA,OAAOR;AACT;AAEA;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASS,oBACdxC,IAAe,EACfyC,QAAmD,EACnD/C,IAAa;IAEb,MAAMgD,UAAU,CAACC,UAAkBP,MACjCE,OAAOM,QAAQ,CAACR,OAAOD,KAAKC,GAAG,CAAC,GAAGA,MAAMO,YAAYvE;IACvD,OAAQ4B;QACN,KAAK;YACH,OAAO0C,QAAQD,SAASI,cAAc,EAAEJ,SAASK,iBAAiB;QACpE,KAAK;YACH,OAAOJ,QAAQD,SAASM,cAAc,EAAEN,SAASO,iBAAiB;QACpE,KAAK;YACH,OAAON,QAAQD,SAASQ,cAAc,EAAER,SAASS,iBAAiB;QACpE,KAAK;YACH,OAAOT,SAASU,SAAS,KAAKvE,YAAY,IAAIR;QAChD,KAAK;YACH,OAAOqE,SAASW,QAAQ,CAACC,GAAG,GAAG7E,0BAA0B;QAC3D,KAAK;YACH,OAAO;QACT,KAAK;YACH,oEAAoE;YACpE,uEAAuE;YACvE,OAAO;QACT,KAAK;YACH,sEAAsE;YACtE,kEAAkE;YAClE,iEAAiE;YACjE,OAAOF,kBAAkBoB,QAAQ,IAAI;IACzC;AACF;AAEA,2EAA2E,GAC3E,OAAO,SAAS4D,gBAAgBtD,IAAe,EAAEN,IAAa;IAC5D,OAAO8C,oBACLxC,MACAvB,uBAAuB;QAAEiB;IAAK,IAC9BA;AAEJ"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/billing-addons.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\nimport {\n SELF_SERVE_PLANS,\n type AiTierId,\n type OrgPlan,\n} from '@aglyn/aglyn/server'\nimport {\n ADDON_KINDS,\n addonMaxForBaseline,\n addonMaxForPlan,\n addonUnitUsd,\n type AddonKind,\n} from '@aglyn/aglyn/app-utils/bundle-intent'\n// The Aglyn AI tiers (AGL-3965) by their own module rather than the server\n// barrel: the webhook and every billing route read a subscription's AI item\n// through here, and the many route specs that stub `@aglyn/aglyn/server`\n// with a partial object would otherwise see every tier helper as undefined.\nimport {\n AI_TIER_IDS,\n defaultAiTierForPlan,\n LEGACY_AI_ADDON_TIER_BY_PLAN,\n planSellsAiTiers,\n} from '@aglyn/aglyn/app-utils/plan-entitlements'\n\n/*\n * The add-on kinds, their unit prices (the Aglyn AI tier's included) and\n * their ceilings live beside the bundle-link parser (AGL-3955), so the link,\n * the Billing card and this price map read one list. Re-exported here for\n * every server reader that already imports them from this module.\n */\nexport { ADDON_KINDS, addonMaxForBaseline, addonMaxForPlan, addonUnitUsd, type AddonKind }\n\n/**\n * Self-serve add-on price map (AGL-525): the bridge between\n * `STRIPE_PRICE_*` env price ids, `org.seatAddons` keys, and\n * `PLAN_PRICING` USD amounts. Add-ons bill as extra items on the org's\n * one subscription, so every kind has a monthly and a yearly price\n * (Stripe allows a single interval per subscription; annual orgs attach\n * the `_YEARLY` variants). Seat/member/dataset/host prices are per-plan;\n * POS registers, the Event Calendar and Site Care (AGL-3954) are flat; the\n * Aglyn AI add-on is priced per TIER (AGL-3965, `STRIPE_PRICE_AI_{TIER}`),\n * on any paid plan. Prices are minted by `tools/scripts/setup-stripe.mjs` —\n * keep the three in sync.\n */\nexport type BillingInterval = 'month' | 'year'\n\n/** Kinds priced per plan (env `STRIPE_PRICE_{PLAN}_{SUFFIX}[_YEARLY]`). */\nconst PER_PLAN_ENV_SUFFIX: Partial<Record<AddonKind, string>> = {\n managers: 'EXTRA_SEAT',\n members: 'EXTRA_MEMBER',\n datasets: 'EXTRA_DATASET',\n hosts: 'EXTRA_HOST',\n}\n\n/** Kinds priced flat across plans (env `STRIPE_PRICE_{SUFFIX}[_YEARLY]`). */\nconst FLAT_ENV_NAME: Partial<Record<AddonKind, string>> = {\n posRegisters: 'POS_REGISTER',\n eventCalendar: 'EVENT_CALENDAR',\n siteCare: 'SITE_CARE',\n}\n\n/**\n * Every plan that is sold with a Stripe price — DERIVED, never hand-listed\n * (AGL-1340).\n *\n * The literal that used to sit here listed starter, pro, business and\n * advanced only — it predated the Scale and Agency tiers, so\n * `addonKindFromPriceId()` could not recognise a single Scale/Agency add-on\n * price coming back from Stripe. `addonPriceId()` still SOLD them (it only\n * uppercases the plan), so the money moved and the read-back returned\n * nothing: the webhook wrote `seatAddons: {all zeros}` for the\n * highest-paying orgs on the next subscription event, and `seatAddons` is an\n * ENTITLEMENT INPUT (`plan-entitlements.ts` — it raises `hostLimit` and\n * `posRegisters`, and flips the `eventCalendar` feature).\n *\n * Deriving from `SELF_SERVE_PLANS` is what stops the next tier from\n * reintroducing it: `free` has nothing to sell and `enterprise` is quoted\n * per deal (no `STRIPE_PRICE_ENTERPRISE_*` exists), so everything else is\n * by definition a paid, priced plan.\n */\nexport const PAID_PLANS: readonly OrgPlan[] = SELF_SERVE_PLANS.filter(\n (plan) => plan !== 'free',\n)\n\nfunction env(name: string): string | null {\n const value = process.env[name]\n return value ? value : null\n}\n\n/**\n * The Stripe price id of an Aglyn AI tier (AGL-3965):\n * `STRIPE_PRICE_AI_{TIER}[_YEARLY]`, lookup key `aglyn_ai_{tier}[_yearly]`.\n * The same price on every plan; null when the env isn't configured.\n */\nexport function aiTierPriceId(\n tier: AiTierId,\n interval: BillingInterval,\n): string | null {\n const yearly = interval === 'year' ? '_YEARLY' : ''\n return env(`STRIPE_PRICE_AI_${tier.toUpperCase()}${yearly}`)\n}\n\n/**\n * The per-plan AI add-on price sold before tiers existed\n * (`STRIPE_PRICE_{PLAN}_AI_ADDON[_YEARLY]`, AGL-2897). Never sold again; read\n * only so an item still carrying one is recognised as the add-on and as the\n * tier with its price and band until `migrate-ai-addon-tiers.mjs` moves it.\n */\nexport function legacyAiAddonPriceId(\n plan: OrgPlan,\n interval: BillingInterval,\n): string | null {\n if (!PAID_PLANS.includes(plan)) return null\n const yearly = interval === 'year' ? '_YEARLY' : ''\n return env(`STRIPE_PRICE_${plan.toUpperCase()}_AI_ADDON${yearly}`)\n}\n\n/**\n * Which Aglyn AI tier a price id sells (AGL-3965): a tier price, or a legacy\n * per-plan add-on price read as the tier with the same price and band\n * (`LEGACY_AI_ADDON_TIER_BY_PLAN`). Null for anything else.\n */\nexport function aiTierFromPriceId(\n priceId: string | null | undefined,\n): AiTierId | null {\n if (!priceId) return null\n for (const interval of ['month', 'year'] as const) {\n for (const tier of AI_TIER_IDS) {\n if (aiTierPriceId(tier, interval) === priceId) return tier\n }\n for (const plan of PAID_PLANS) {\n if (legacyAiAddonPriceId(plan, interval) === priceId) {\n return LEGACY_AI_ADDON_TIER_BY_PLAN[plan] ?? null\n }\n }\n }\n return null\n}\n\n/**\n * The tier a subscription's items carry (AGL-3965), or null when none is an\n * Aglyn AI item with a quantity. Written to `org.aiTier` beside the\n * `seatAddons` map `addonQuantitiesFromItems` derives from the same items.\n */\nexport function aiTierFromItems(\n items:\n | ReadonlyArray<{ price?: { id?: string } | null; quantity?: number | null }>\n | null\n | undefined,\n): AiTierId | null {\n for (const item of items ?? []) {\n const tier = aiTierFromPriceId(item?.price?.id)\n if (tier && Number(item?.quantity ?? 1) >= 1) return tier\n }\n return null\n}\n\n/**\n * The Stripe price id for an add-on kind on a plan at a billing interval;\n * null when the plan doesn't sell it (free) or the env isn't configured.\n *\n * `tier` picks the Aglyn AI tier; absent, the tier a plan-named purchase\n * means (`defaultAiTierForPlan`). Ignored for every other kind.\n */\nexport function addonPriceId(\n kind: AddonKind,\n plan: OrgPlan,\n interval: BillingInterval,\n tier?: AiTierId | null,\n): string | null {\n const name = addonPriceEnvName(kind, plan, interval, tier)\n return name ? env(name) : null\n}\n\n/**\n * The env var that holds an add-on's price id on a plan at an interval, or\n * null where the plan sells no such price. Named on its own so a checkout\n * that Stripe refuses can say which variable points at a missing price.\n * For the Aglyn AI add-on it is the tier's (`STRIPE_PRICE_AI_{TIER}`,\n * AGL-3965), `tier` read as `addonPriceId` reads it.\n */\nexport function addonPriceEnvName(\n kind: AddonKind,\n plan: OrgPlan,\n interval: BillingInterval,\n tier?: AiTierId | null,\n): string | null {\n const yearly = interval === 'year' ? '_YEARLY' : ''\n if (kind === 'aiAddon') {\n if (!planSellsAiTiers(plan)) return null\n const chosen = tier ?? defaultAiTierForPlan(plan)\n return chosen ? `STRIPE_PRICE_AI_${chosen.toUpperCase()}${yearly}` : null\n }\n const flat = FLAT_ENV_NAME[kind]\n if (flat) return `STRIPE_PRICE_${flat}${yearly}`\n const suffix = PER_PLAN_ENV_SUFFIX[kind]\n if (!suffix || plan === 'free') return null\n return `STRIPE_PRICE_${plan.toUpperCase()}_${suffix}${yearly}`\n}\n\n/**\n * Reverse map: which add-on kind a subscription item's price id sells.\n * Null for non-add-on prices (the base plan item, unknown prices).\n */\nexport function addonKindFromPriceId(\n priceId: string | null | undefined,\n): AddonKind | null {\n if (!priceId) return null\n if (aiTierFromPriceId(priceId)) return 'aiAddon'\n for (const kind of ADDON_KINDS) {\n if (kind === 'aiAddon') continue\n for (const interval of ['month', 'year'] as const) {\n if (FLAT_ENV_NAME[kind]) {\n if (addonPriceId(kind, 'starter', interval) === priceId) return kind\n continue\n }\n for (const plan of PAID_PLANS) {\n if (addonPriceId(kind, plan, interval) === priceId) return kind\n }\n }\n }\n return null\n}\n\n/**\n * The price an add-on item moves to on a target plan/interval: the kind's\n * price there, and for the Aglyn AI add-on the SAME tier the item carries\n * now (AGL-3965) — a tier is chosen on its own, so a plan change re-prices\n * only its interval, and a legacy per-plan item becomes the tier with its\n * price and band.\n */\nexport function addonTargetPriceId(\n kind: AddonKind,\n plan: OrgPlan,\n interval: BillingInterval,\n currentPriceId: string | null | undefined,\n): string | null {\n const tier = kind === 'aiAddon' ? aiTierFromPriceId(currentPriceId) : null\n return addonPriceId(kind, plan, interval, tier)\n}\n\n/**\n * The BASE plan's Stripe price id at an interval\n * (`STRIPE_PRICE_{PLAN}[_YEARLY]`); null for `free`, for the custom-priced\n * `enterprise`, and for an env that isn't configured. Read at call time, so\n * it never freezes a stale value at module load the way the routes'\n * `PRICE_ENV` maps do.\n */\nexport function planPriceId(\n plan: OrgPlan,\n interval: BillingInterval,\n): string | null {\n if (!PAID_PLANS.includes(plan)) return null\n const yearly = interval === 'year' ? '_YEARLY' : ''\n return env(`STRIPE_PRICE_${plan.toUpperCase()}${yearly}`)\n}\n\n/**\n * Which plan a subscription item's price sells AND on which interval; null for\n * an add-on price, the metered price, an ad-hoc enterprise price, and anything\n * unknown.\n *\n * The interval half exists because a schedule phase read back from Stripe\n * carries price IDS and nothing else (AGL-2150): rebuilding that phase's item\n * list needs to know which interval it is priced on, and guessing it from the\n * live subscription is wrong exactly when the pending change is also an\n * interval change.\n */\nexport function planAndIntervalFromPriceId(\n priceId: string | null | undefined,\n): { plan: OrgPlan; interval: BillingInterval } | null {\n if (!priceId) return null\n for (const plan of PAID_PLANS) {\n for (const interval of ['month', 'year'] as const) {\n if (planPriceId(plan, interval) === priceId) return { plan, interval }\n }\n }\n return null\n}\n\n/**\n * Which plan a subscription item's price sells; null for an add-on price,\n * the metered price, an ad-hoc enterprise price, and anything unknown.\n */\nexport function planFromPriceId(\n priceId: string | null | undefined,\n): OrgPlan | null {\n return planAndIntervalFromPriceId(priceId)?.plan ?? null\n}\n\n/**\n * The shared metered-usage price (AGL-635) that makes reported usage\n * billable, for a given billing interval.\n *\n * Stripe rejects a subscription whose items mix `recurring.interval`, so the\n * metered item has to recur the same way the plan does. There are two prices\n * — `aglyn_metered_usage` (monthly) and `aglyn_metered_usage_yearly` — and\n * both bill $0.01 per aggregated unit against the SAME meter, because the\n * rollup posts an already-computed value in CENTS. The interval is therefore\n * the only thing that differs, and it is the only thing a caller must get\n * right.\n *\n * `interval` is REQUIRED on purpose (AGL-1280). It used to be monthly-only\n * with no argument, so the failure mode of forgetting it was attaching a\n * monthly price to a yearly subscription — the exact mixed-interval crash\n * this signature now makes unrepresentable. A default would hand that\n * footgun straight back.\n */\nexport function meteredPriceId(interval: 'month' | 'year'): string | null {\n return env(\n interval === 'year' ? 'STRIPE_PRICE_METERED_YEARLY' : 'STRIPE_PRICE_METERED',\n )\n}\n\n/**\n * Whether a price id is EITHER shared metered-usage price.\n *\n * Interval-agnostic by design: callers ask this to exclude the metered item\n * from plan/add-on reasoning, and an annual subscription's metered item must\n * be excluded just as thoroughly as a monthly one.\n */\nexport function isMeteredPriceId(priceId: string | null | undefined): boolean {\n if (!priceId) return false\n return (\n priceId === meteredPriceId('month') || priceId === meteredPriceId('year')\n )\n}\n\n/**\n * The subscription's BASE PLAN item, identified POSITIVELY (AGL-1340).\n *\n * This used to be \"whatever no add-on price claims\" — identification by\n * elimination, which quietly returns the wrong item the moment a\n * subscription carries anything the add-on map doesn't recognise: the\n * metered item, a grandfathered v1 price, a coupon-era SKU, an item added\n * by hand in the Stripe dashboard. Picking an add-on item as the plan item\n * means a plan switch re-prices the ADD-ON, and reads the billing interval\n * off it.\n *\n * So: match a known `STRIPE_PRICE_{PLAN}[_YEARLY]` first. Only when nothing\n * matches — an enterprise deal bills on an ad-hoc price, and grandfathered\n * subscriptions predate the current SKUs — fall back to the old rule,\n * minus the metered item, and finally to `items[0]` so behaviour for those\n * subscriptions is unchanged.\n */\nexport function findPlanItem<T extends { price?: { id?: string } | null }>(\n items: readonly T[] | null | undefined,\n): T | null {\n const list = items ?? []\n const byPlanPrice = list.find((item) => planFromPriceId(item?.price?.id))\n if (byPlanPrice) return byPlanPrice\n const notAnAddon = list.find(\n (item) =>\n !addonKindFromPriceId(item?.price?.id) &&\n !isMeteredPriceId(item?.price?.id),\n )\n return notAnAddon ?? list[0] ?? null\n}\n\n/**\n * Full add-on quantity map (explicit zeros for absent kinds) from a\n * subscription's items — the shape written to `org.seatAddons` so\n * removals and dashboard edits converge on sync (AGL-527).\n */\nexport function addonQuantitiesFromItems(\n items:\n | Array<{ price?: { id?: string } | null; quantity?: number | null }>\n | null\n | undefined,\n): Record<AddonKind, number> {\n const quantities = Object.fromEntries(\n ADDON_KINDS.map((kind) => [kind, 0]),\n ) as Record<AddonKind, number>\n for (const item of items ?? []) {\n const kind = addonKindFromPriceId(item?.price?.id)\n if (kind) {\n quantities[kind] += Math.max(0, Math.floor(Number(item?.quantity ?? 0)))\n }\n }\n return quantities\n}\n"],"names":["SELF_SERVE_PLANS","ADDON_KINDS","addonMaxForBaseline","addonMaxForPlan","addonUnitUsd","AI_TIER_IDS","defaultAiTierForPlan","LEGACY_AI_ADDON_TIER_BY_PLAN","planSellsAiTiers","PER_PLAN_ENV_SUFFIX","managers","members","datasets","hosts","FLAT_ENV_NAME","posRegisters","eventCalendar","siteCare","PAID_PLANS","filter","plan","env","name","value","process","aiTierPriceId","tier","interval","yearly","toUpperCase","legacyAiAddonPriceId","includes","aiTierFromPriceId","priceId","aiTierFromItems","items","item","price","id","Number","quantity","addonPriceId","kind","addonPriceEnvName","chosen","flat","suffix","addonKindFromPriceId","addonTargetPriceId","currentPriceId","planPriceId","planAndIntervalFromPriceId","planFromPriceId","meteredPriceId","isMeteredPriceId","findPlanItem","notAnAddon","list","byPlanPrice","find","addonQuantitiesFromItems","quantities","Object","fromEntries","map","Math","max","floor"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,gBAAgB,QAGX,sBAAqB;AAC5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