@aglyn/aglyn 1.0.0-beta.219 → 1.0.0-beta.221

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.
Files changed (188) hide show
  1. package/package.json +12 -12
  2. package/src/lib/app-utils/actions.d.ts +1 -59
  3. package/src/lib/app-utils/actions.js +7 -72
  4. package/src/lib/app-utils/actions.js.map +1 -1
  5. package/src/lib/app-utils/consent-groups.d.ts +1 -1
  6. package/src/lib/app-utils/consent-groups.js.map +1 -1
  7. package/src/lib/app-utils/console-routes.d.ts +0 -36
  8. package/src/lib/app-utils/console-routes.js +2 -37
  9. package/src/lib/app-utils/console-routes.js.map +1 -1
  10. package/src/lib/app-utils/contacts.d.ts +1 -1
  11. package/src/lib/app-utils/contacts.js.map +1 -1
  12. package/src/lib/app-utils/container-membership.d.ts +93 -0
  13. package/src/lib/app-utils/container-membership.js +165 -0
  14. package/src/lib/app-utils/container-membership.js.map +1 -0
  15. package/src/lib/app-utils/crm-task-reminders.d.ts +23 -6
  16. package/src/lib/app-utils/crm-task-reminders.js +32 -11
  17. package/src/lib/app-utils/crm-task-reminders.js.map +1 -1
  18. package/src/lib/app-utils/crm.d.ts +24 -4
  19. package/src/lib/app-utils/crm.js +23 -0
  20. package/src/lib/app-utils/crm.js.map +1 -1
  21. package/src/lib/app-utils/csv-upload.d.ts +1 -1
  22. package/src/lib/app-utils/csv-upload.js +1 -1
  23. package/src/lib/app-utils/csv-upload.js.map +1 -1
  24. package/src/lib/app-utils/{dataset-csv.d.ts → csv.d.ts} +10 -43
  25. package/src/lib/app-utils/{dataset-csv.js → csv.js} +10 -81
  26. package/src/lib/app-utils/csv.js.map +1 -0
  27. package/src/lib/app-utils/datasets.d.ts +0 -19
  28. package/src/lib/app-utils/datasets.js +0 -13
  29. package/src/lib/app-utils/datasets.js.map +1 -1
  30. package/src/lib/app-utils/docs-help.generated.d.ts +4 -4
  31. package/src/lib/app-utils/docs-help.generated.js +5 -0
  32. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  33. package/src/lib/app-utils/docs-index.generated.js +71 -36
  34. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  35. package/src/lib/app-utils/dynamic-list-rule.js +3 -3
  36. package/src/lib/app-utils/dynamic-list-rule.js.map +1 -1
  37. package/src/lib/app-utils/email-text.d.ts +80 -0
  38. package/src/lib/app-utils/email-text.js +189 -0
  39. package/src/lib/app-utils/email-text.js.map +1 -0
  40. package/src/lib/app-utils/{list-assignment-policy.d.ts → enrollment-basis.d.ts} +4 -0
  41. package/src/lib/app-utils/{list-assignment-policy.js → enrollment-basis.js} +5 -1
  42. package/src/lib/app-utils/enrollment-basis.js.map +1 -0
  43. package/src/lib/app-utils/expand-repeatables.js +4 -4
  44. package/src/lib/app-utils/expand-repeatables.js.map +1 -1
  45. package/src/lib/app-utils/forms.js +2 -2
  46. package/src/lib/app-utils/forms.js.map +1 -1
  47. package/src/lib/app-utils/health-report.d.ts +2 -3
  48. package/src/lib/app-utils/health-report.js +30 -6
  49. package/src/lib/app-utils/health-report.js.map +1 -1
  50. package/src/lib/app-utils/inbound-mail-domain.d.ts +27 -0
  51. package/src/lib/app-utils/inbound-mail-domain.js +31 -0
  52. package/src/lib/app-utils/inbound-mail-domain.js.map +1 -0
  53. package/src/lib/app-utils/leaving-notice.d.ts +96 -0
  54. package/src/lib/app-utils/leaving-notice.js +157 -0
  55. package/src/lib/app-utils/leaving-notice.js.map +1 -0
  56. package/src/lib/app-utils/lockdown.d.ts +11 -0
  57. package/src/lib/app-utils/lockdown.js +33 -3
  58. package/src/lib/app-utils/lockdown.js.map +1 -1
  59. package/src/lib/app-utils/member-email-aliases.d.ts +25 -0
  60. package/src/lib/app-utils/member-email-aliases.js +29 -0
  61. package/src/lib/app-utils/member-email-aliases.js.map +1 -1
  62. package/src/lib/app-utils/notifications.d.ts +69 -0
  63. package/src/lib/app-utils/notifications.js +119 -0
  64. package/src/lib/app-utils/notifications.js.map +1 -1
  65. package/src/lib/app-utils/operator-alerts.d.ts +15 -1
  66. package/src/lib/app-utils/operator-alerts.js +64 -10
  67. package/src/lib/app-utils/operator-alerts.js.map +1 -1
  68. package/src/lib/app-utils/plan-entitlements.d.ts +164 -178
  69. package/src/lib/app-utils/plan-entitlements.js +200 -224
  70. package/src/lib/app-utils/plan-entitlements.js.map +1 -1
  71. package/src/lib/app-utils/platform-marketing-consent.d.ts +56 -2
  72. package/src/lib/app-utils/platform-marketing-consent.js +6 -5
  73. package/src/lib/app-utils/platform-marketing-consent.js.map +1 -1
  74. package/src/lib/app-utils/plugin-starter-templates.generated.d.ts +12 -0
  75. package/src/lib/app-utils/plugin-starter-templates.generated.js +711 -0
  76. package/src/lib/app-utils/plugin-starter-templates.generated.js.map +1 -0
  77. package/src/lib/app-utils/repeat-query.d.ts +56 -0
  78. package/src/lib/app-utils/{dataset-query.js → repeat-query.js} +16 -16
  79. package/src/lib/app-utils/repeat-query.js.map +1 -0
  80. package/src/lib/app-utils/screen-link-context-value.d.ts +7 -0
  81. package/src/lib/app-utils/screen-link-context-value.js.map +1 -1
  82. package/src/lib/app-utils/screen-link-context.js +14 -2
  83. package/src/lib/app-utils/screen-link-context.js.map +1 -1
  84. package/src/lib/app-utils/screen-route.d.ts +3 -0
  85. package/src/lib/app-utils/screen-route.js +6 -1
  86. package/src/lib/app-utils/screen-route.js.map +1 -1
  87. package/src/lib/app-utils/server.d.ts +7 -9
  88. package/src/lib/app-utils/server.js +18 -26
  89. package/src/lib/app-utils/server.js.map +1 -1
  90. package/src/lib/app-utils/starter-template-nodes.d.ts +137 -0
  91. package/src/lib/app-utils/starter-template-nodes.js +129 -0
  92. package/src/lib/app-utils/starter-template-nodes.js.map +1 -0
  93. package/src/lib/app-utils/starter-templates.d.ts +11 -34
  94. package/src/lib/app-utils/starter-templates.js +19 -230
  95. package/src/lib/app-utils/starter-templates.js.map +1 -1
  96. package/src/lib/app-utils/{email-topics.d.ts → subscription-topics.d.ts} +64 -48
  97. package/src/lib/app-utils/{email-topics.js → subscription-topics.js} +39 -109
  98. package/src/lib/app-utils/subscription-topics.js.map +1 -0
  99. package/src/lib/app-utils/usage-budget.d.ts +73 -188
  100. package/src/lib/app-utils/usage-budget.js +58 -194
  101. package/src/lib/app-utils/usage-budget.js.map +1 -1
  102. package/src/lib/app-utils/utm-attribution.d.ts +1 -1
  103. package/src/lib/app-utils/utm-attribution.js +1 -1
  104. package/src/lib/app-utils/utm-attribution.js.map +1 -1
  105. package/src/lib/app-utils/{campaign-touch.d.ts → utm-touch.d.ts} +21 -13
  106. package/src/lib/app-utils/{campaign-touch.js → utm-touch.js} +30 -22
  107. package/src/lib/app-utils/utm-touch.js.map +1 -0
  108. package/src/lib/app-utils/variables.d.ts +9 -9
  109. package/src/lib/app-utils/variables.js.map +1 -1
  110. package/src/lib/app-utils/visitor-record-ceiling.d.ts +32 -0
  111. package/src/lib/app-utils/visitor-record-ceiling.js +39 -0
  112. package/src/lib/app-utils/visitor-record-ceiling.js.map +1 -1
  113. package/src/lib/foundation/definitions/org-billing.types.d.ts +2 -2
  114. package/src/lib/foundation/definitions/org-billing.types.js.map +1 -1
  115. package/src/lib/plugin-manager/feature-plugins.d.ts +80 -79
  116. package/src/lib/plugin-manager/feature-plugins.js +22 -35
  117. package/src/lib/plugin-manager/feature-plugins.js.map +1 -1
  118. package/src/lib/plugin-manager/first-party-plugins.generated.d.ts +18 -1
  119. package/src/lib/plugin-manager/first-party-plugins.generated.js +62 -2
  120. package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
  121. package/src/lib/plugin-manager/index.d.ts +0 -1
  122. package/src/lib/plugin-manager/index.js +0 -1
  123. package/src/lib/plugin-manager/index.js.map +1 -1
  124. package/src/lib/plugin-manager/plugin-contact-capture.d.ts +9 -4
  125. package/src/lib/plugin-manager/plugin-contact-capture.js.map +1 -1
  126. package/src/lib/plugin-manager/plugin-containers.d.ts +68 -0
  127. package/src/lib/plugin-manager/plugin-containers.generated.d.ts +10 -0
  128. package/src/lib/plugin-manager/plugin-containers.generated.js +20 -0
  129. package/src/lib/plugin-manager/plugin-containers.generated.js.map +1 -0
  130. package/src/lib/plugin-manager/plugin-containers.js +27 -0
  131. package/src/lib/plugin-manager/plugin-containers.js.map +1 -0
  132. package/src/lib/plugin-manager/plugin-entitlements.d.ts +8 -0
  133. package/src/lib/plugin-manager/plugin-entitlements.js.map +1 -1
  134. package/src/lib/plugin-manager/plugin-membership-detach.js +1 -1
  135. package/src/lib/plugin-manager/plugin-membership-detach.js.map +1 -1
  136. package/src/lib/plugin-manager/plugin-record-email-state.d.ts +69 -0
  137. package/src/lib/plugin-manager/plugin-record-email-state.js +32 -0
  138. package/src/lib/plugin-manager/plugin-record-email-state.js.map +1 -1
  139. package/src/lib/plugin-manager/plugin-record-lists.d.ts +115 -0
  140. package/src/lib/plugin-manager/plugin-record-lists.js +75 -0
  141. package/src/lib/plugin-manager/plugin-record-lists.js.map +1 -0
  142. package/src/lib/plugin-manager/plugin-record-timeline.d.ts +42 -8
  143. package/src/lib/plugin-manager/plugin-record-timeline.js.map +1 -1
  144. package/src/lib/plugin-manager/plugin-server-steps.d.ts +170 -0
  145. package/src/lib/plugin-manager/plugin-server-steps.js +116 -0
  146. package/src/lib/plugin-manager/plugin-server-steps.js.map +1 -0
  147. package/src/lib/plugin-manager/plugin-site-beacons.d.ts +71 -0
  148. package/src/lib/plugin-manager/plugin-site-beacons.js +54 -0
  149. package/src/lib/plugin-manager/plugin-site-beacons.js.map +1 -0
  150. package/src/lib/plugin-manager/plugin-subscription-topics.generated.d.ts +11 -0
  151. package/src/lib/plugin-manager/plugin-subscription-topics.generated.js +41 -0
  152. package/src/lib/plugin-manager/plugin-subscription-topics.generated.js.map +1 -0
  153. package/src/lib/plugin-manager/plugin-usage-axes.d.ts +212 -0
  154. package/src/lib/plugin-manager/plugin-usage-axes.js +82 -3
  155. package/src/lib/plugin-manager/plugin-usage-axes.js.map +1 -1
  156. package/src/lib/plugin-manager/plugin-usage-meters.d.ts +108 -0
  157. package/src/lib/plugin-manager/plugin-usage-meters.js +105 -0
  158. package/src/lib/plugin-manager/plugin-usage-meters.js.map +1 -0
  159. package/src/lib/plugin-manager/usage-alert-contributors.d.ts +76 -6
  160. package/src/lib/plugin-manager/usage-alert-contributors.js +23 -10
  161. package/src/lib/plugin-manager/usage-alert-contributors.js.map +1 -1
  162. package/src/lib/app-utils/assist-credits.d.ts +0 -482
  163. package/src/lib/app-utils/assist-credits.js +0 -510
  164. package/src/lib/app-utils/assist-credits.js.map +0 -1
  165. package/src/lib/app-utils/campaign-membership.d.ts +0 -121
  166. package/src/lib/app-utils/campaign-membership.js +0 -189
  167. package/src/lib/app-utils/campaign-membership.js.map +0 -1
  168. package/src/lib/app-utils/campaign-touch.js.map +0 -1
  169. package/src/lib/app-utils/console-record-links.d.ts +0 -84
  170. package/src/lib/app-utils/console-record-links.js +0 -76
  171. package/src/lib/app-utils/console-record-links.js.map +0 -1
  172. package/src/lib/app-utils/crm-booking.d.ts +0 -75
  173. package/src/lib/app-utils/crm-booking.js +0 -133
  174. package/src/lib/app-utils/crm-booking.js.map +0 -1
  175. package/src/lib/app-utils/crm-inbound.d.ts +0 -245
  176. package/src/lib/app-utils/crm-inbound.js +0 -407
  177. package/src/lib/app-utils/crm-inbound.js.map +0 -1
  178. package/src/lib/app-utils/crm-reports.d.ts +0 -479
  179. package/src/lib/app-utils/crm-reports.js +0 -680
  180. package/src/lib/app-utils/crm-reports.js.map +0 -1
  181. package/src/lib/app-utils/dataset-csv.js.map +0 -1
  182. package/src/lib/app-utils/dataset-query.d.ts +0 -57
  183. package/src/lib/app-utils/dataset-query.js.map +0 -1
  184. package/src/lib/app-utils/email-topics.js.map +0 -1
  185. package/src/lib/app-utils/list-assignment-policy.js.map +0 -1
  186. package/src/lib/plugin-manager/plugin-metered-lines.d.ts +0 -97
  187. package/src/lib/plugin-manager/plugin-metered-lines.js +0 -123
  188. package/src/lib/plugin-manager/plugin-metered-lines.js.map +0 -1
@@ -0,0 +1,54 @@
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 { getRegisteringPluginId } from "../app-utils/registering-plugin.js";
18
+ import { definePluginServiceContract, registerPluginService, resolvePluginServices } from "./plugin-services.js";
19
+ export const PLUGIN_SITE_BEACONS = definePluginServiceContract('core.site-beacons', {
20
+ multiple: true
21
+ });
22
+ /**
23
+ * Registers a beacon. The owner is the loader's marker inside a register fn,
24
+ * else `options.pluginId`; with neither the registration throws. A field
25
+ * another plugin claims throws naming both.
26
+ */ export function registerPluginSiteBeacon(beacon, options) {
27
+ var _beacon_field, _ref, _getRegisteringPluginId;
28
+ const field = String((_beacon_field = beacon.field) != null ? _beacon_field : '').trim();
29
+ if (!field) throw new Error('a site beacon needs the body field that marks it');
30
+ const pluginId = ((_ref = (_getRegisteringPluginId = getRegisteringPluginId()) != null ? _getRegisteringPluginId : options == null ? void 0 : options.pluginId) != null ? _ref : '').trim();
31
+ if (!pluginId) throw new Error(`the site beacon "${field}" was registered with no owner`);
32
+ const incumbent = resolvePluginServices(PLUGIN_SITE_BEACONS).find((entry)=>entry.key === field);
33
+ if (incumbent && incumbent.pluginId !== pluginId) {
34
+ throw new Error(`site beacon field "${field}" is already counted by "${incumbent.pluginId}"; refused "${pluginId}"`);
35
+ }
36
+ registerPluginService(PLUGIN_SITE_BEACONS, _extends({}, beacon, {
37
+ field
38
+ }), {
39
+ pluginId,
40
+ key: field
41
+ });
42
+ }
43
+ /** The owner of a beacon body, or `null` when no registered field marks it. */ export function pluginSiteBeaconFor(body) {
44
+ for (const entry of resolvePluginServices(PLUGIN_SITE_BEACONS)){
45
+ const value = body[entry.impl.field];
46
+ if (typeof value === 'string' && value) return {
47
+ pluginId: entry.pluginId,
48
+ beacon: entry.impl
49
+ };
50
+ }
51
+ return null;
52
+ }
53
+
54
+ //# sourceMappingURL=plugin-site-beacons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-site-beacons.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 { getRegisteringPluginId } from '../app-utils/registering-plugin'\nimport {\n definePluginServiceContract,\n registerPluginService,\n resolvePluginServices,\n} from './plugin-services'\n\n/**\n * A plugin's own beacons, posted to the platform's site collector.\n *\n * A published page has one place to report what visitors did — the\n * collector behind `sendAnalyticsBeacon` — and that endpoint owns what every\n * beacon owes before anything is counted: the host must exist, a platform,\n * org or site lockdown refuses it silently, and the per-address rate limit\n * applies. What a plugin's site runtime reports beyond a pageview (an\n * announcement bar seen, a popup dismissed) is the plugin's to count, in its\n * own documents.\n *\n * So the plugin registers a beacon by the body FIELD that marks it as its\n * own, and the collector hands a beacon carrying that field to the plugin\n * after its own gates, then answers 204 without counting a pageview. The\n * field is the beacon's whole claim: one owner per field, refused naming\n * both, and the incumbent keeps serving.\n *\n * Registered from the plugin's `serverDeclarations`, so every server process\n * has it from boot; keep the registration light and import the counting\n * code on the first beacon.\n */\n\n/** What the collector hands the owner, after the host and lockdown gates. */\nexport interface PluginSiteBeaconRequest {\n hostId: string\n /** The collector's day bucket, `YYYY-MM-DD` in UTC. */\n day: string\n /**\n * When the site's analytics document for {@link day} expires: the\n * platform's retention. An owner that writes into that document stamps it,\n * so a document created by its beacons alone is still swept.\n */\n dayExpiresAt: Date\n /** The beacon as the browser sent it. Untrusted: validate every field read. */\n body: Readonly<Record<string, unknown>>\n}\n\nexport interface PluginSiteBeacon {\n /** The body field whose non-empty string marks a beacon as this plugin's. */\n field: string\n /** Counts one beacon. A throw is logged by the collector, never surfaced. */\n count(request: PluginSiteBeaconRequest): Promise<void>\n}\n\nexport const PLUGIN_SITE_BEACONS = definePluginServiceContract<PluginSiteBeacon>(\n 'core.site-beacons',\n { multiple: true },\n)\n\n/**\n * Registers a beacon. The owner is the loader's marker inside a register fn,\n * else `options.pluginId`; with neither the registration throws. A field\n * another plugin claims throws naming both.\n */\nexport function registerPluginSiteBeacon(\n beacon: PluginSiteBeacon,\n options?: { pluginId?: string },\n): void {\n const field = String(beacon.field ?? '').trim()\n if (!field) throw new Error('a site beacon needs the body field that marks it')\n const pluginId = (getRegisteringPluginId() ?? options?.pluginId ?? '').trim()\n if (!pluginId) throw new Error(`the site beacon \"${field}\" was registered with no owner`)\n const incumbent = resolvePluginServices(PLUGIN_SITE_BEACONS).find((entry) => entry.key === field)\n if (incumbent && incumbent.pluginId !== pluginId) {\n throw new Error(\n `site beacon field \"${field}\" is already counted by \"${incumbent.pluginId}\"; refused \"${pluginId}\"`,\n )\n }\n registerPluginService(PLUGIN_SITE_BEACONS, { ...beacon, field }, { pluginId, key: field })\n}\n\n/** The owner of a beacon body, or `null` when no registered field marks it. */\nexport function pluginSiteBeaconFor(\n body: Readonly<Record<string, unknown>>,\n): { pluginId: string; beacon: PluginSiteBeacon } | null {\n for (const entry of resolvePluginServices(PLUGIN_SITE_BEACONS)) {\n const value = body[entry.impl.field]\n if (typeof value === 'string' && value) return { pluginId: entry.pluginId, beacon: entry.impl }\n }\n return null\n}\n"],"names":["getRegisteringPluginId","definePluginServiceContract","registerPluginService","resolvePluginServices","PLUGIN_SITE_BEACONS","multiple","registerPluginSiteBeacon","beacon","options","field","String","trim","Error","pluginId","incumbent","find","entry","key","pluginSiteBeaconFor","body","value","impl"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,sBAAsB,QAAQ,qCAAiC;AACxE,SACEC,2BAA2B,EAC3BC,qBAAqB,EACrBC,qBAAqB,QAChB,uBAAmB;AA8C1B,OAAO,MAAMC,sBAAsBH,4BACjC,qBACA;IAAEI,UAAU;AAAK,GAClB;AAED;;;;CAIC,GACD,OAAO,SAASC,yBACdC,MAAwB,EACxBC,OAA+B;QAEVD,eAEHP,MAAAA;IAFlB,MAAMS,QAAQC,QAAOH,gBAAAA,OAAOE,KAAK,YAAZF,gBAAgB,IAAII,IAAI;IAC7C,IAAI,CAACF,OAAO,MAAM,IAAIG,MAAM;IAC5B,MAAMC,WAAW,EAACb,QAAAA,0BAAAA,oCAAAA,0BAA4BQ,2BAAAA,QAASK,QAAQ,YAA7Cb,OAAiD,IAAIW,IAAI;IAC3E,IAAI,CAACE,UAAU,MAAM,IAAID,MAAM,CAAC,iBAAiB,EAAEH,MAAM,8BAA8B,CAAC;IACxF,MAAMK,YAAYX,sBAAsBC,qBAAqBW,IAAI,CAAC,CAACC,QAAUA,MAAMC,GAAG,KAAKR;IAC3F,IAAIK,aAAaA,UAAUD,QAAQ,KAAKA,UAAU;QAChD,MAAM,IAAID,MACR,CAAC,mBAAmB,EAAEH,MAAM,yBAAyB,EAAEK,UAAUD,QAAQ,CAAC,YAAY,EAAEA,SAAS,CAAC,CAAC;IAEvG;IACAX,sBAAsBE,qBAAqB,aAAKG;QAAQE;QAAS;QAAEI;QAAUI,KAAKR;IAAM;AAC1F;AAEA,6EAA6E,GAC7E,OAAO,SAASS,oBACdC,IAAuC;IAEvC,KAAK,MAAMH,SAASb,sBAAsBC,qBAAsB;QAC9D,MAAMgB,QAAQD,IAAI,CAACH,MAAMK,IAAI,CAACZ,KAAK,CAAC;QACpC,IAAI,OAAOW,UAAU,YAAYA,OAAO,OAAO;YAAEP,UAAUG,MAAMH,QAAQ;YAAEN,QAAQS,MAAMK,IAAI;QAAC;IAChG;IACA,OAAO;AACT"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * GENERATED FILE — do not edit. Regenerate with:
3
+ * node tools/scripts/generate-plugin-manifests.mjs
4
+ *
5
+ * The subscription topics plugins declare (AGL-3080): each plugin's
6
+ * `subscriptionTopics` block in plugins.config.json, in preference-page
7
+ * order. Core's `app-utils/subscription-topics.ts` reads them as the
8
+ * built-in floor of every org's topic catalog; core names no stream.
9
+ */
10
+ import type { DeclaredSubscriptionTopic } from '../app-utils/subscription-topics';
11
+ export declare const PLUGIN_SUBSCRIPTION_TOPICS_DECLARED: readonly DeclaredSubscriptionTopic[];
@@ -0,0 +1,41 @@
1
+ /**
2
+ * GENERATED FILE — do not edit. Regenerate with:
3
+ * node tools/scripts/generate-plugin-manifests.mjs
4
+ *
5
+ * The subscription topics plugins declare (AGL-3080): each plugin's
6
+ * `subscriptionTopics` block in plugins.config.json, in preference-page
7
+ * order. Core's `app-utils/subscription-topics.ts` reads them as the
8
+ * built-in floor of every org's topic catalog; core names no stream.
9
+ */ export const PLUGIN_SUBSCRIPTION_TOPICS_DECLARED = [
10
+ {
11
+ "pluginId": "marketing",
12
+ "id": "marketing",
13
+ "name": "Promotions and offers",
14
+ "description": "Sales, discounts and seasonal campaigns.",
15
+ "order": 10,
16
+ "default": true
17
+ },
18
+ {
19
+ "pluginId": "commerce",
20
+ "id": "newsletter",
21
+ "name": "Newsletter",
22
+ "description": "Regular news and stories from us.",
23
+ "order": 20
24
+ },
25
+ {
26
+ "pluginId": "commerce",
27
+ "id": "product-updates",
28
+ "name": "Product updates",
29
+ "description": "New products, restocks and changes to what we offer.",
30
+ "order": 30
31
+ },
32
+ {
33
+ "pluginId": "outreach",
34
+ "id": "sales",
35
+ "name": "Sales outreach",
36
+ "description": "Messages from a person here about working together.",
37
+ "order": 40
38
+ }
39
+ ];
40
+
41
+ //# sourceMappingURL=plugin-subscription-topics.generated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-subscription-topics.generated.ts"],"sourcesContent":["/**\n * GENERATED FILE — do not edit. Regenerate with:\n * node tools/scripts/generate-plugin-manifests.mjs\n *\n * The subscription topics plugins declare (AGL-3080): each plugin's\n * `subscriptionTopics` block in plugins.config.json, in preference-page\n * order. Core's `app-utils/subscription-topics.ts` reads them as the\n * built-in floor of every org's topic catalog; core names no stream.\n */\n\nimport type { DeclaredSubscriptionTopic } from '../app-utils/subscription-topics'\n\nexport const PLUGIN_SUBSCRIPTION_TOPICS_DECLARED: readonly DeclaredSubscriptionTopic[] = [\n {\n \"pluginId\": \"marketing\",\n \"id\": \"marketing\",\n \"name\": \"Promotions and offers\",\n \"description\": \"Sales, discounts and seasonal campaigns.\",\n \"order\": 10,\n \"default\": true\n },\n {\n \"pluginId\": \"commerce\",\n \"id\": \"newsletter\",\n \"name\": \"Newsletter\",\n \"description\": \"Regular news and stories from us.\",\n \"order\": 20\n },\n {\n \"pluginId\": \"commerce\",\n \"id\": \"product-updates\",\n \"name\": \"Product updates\",\n \"description\": \"New products, restocks and changes to what we offer.\",\n \"order\": 30\n },\n {\n \"pluginId\": \"outreach\",\n \"id\": \"sales\",\n \"name\": \"Sales outreach\",\n \"description\": \"Messages from a person here about working together.\",\n \"order\": 40\n }\n]\n"],"names":["PLUGIN_SUBSCRIPTION_TOPICS_DECLARED"],"mappings":"AAAA;;;;;;;;CAQC,GAID,OAAO,MAAMA,sCAA4E;IACvF;QACE,YAAY;QACZ,MAAM;QACN,QAAQ;QACR,eAAe;QACf,SAAS;QACT,WAAW;IACb;IACA;QACE,YAAY;QACZ,MAAM;QACN,QAAQ;QACR,eAAe;QACf,SAAS;IACX;IACA;QACE,YAAY;QACZ,MAAM;QACN,QAAQ;QACR,eAAe;QACf,SAAS;IACX;IACA;QACE,YAAY;QACZ,MAAM;QACN,QAAQ;QACR,eAAe;QACf,SAAS;IACX;CACD,CAAA"}
@@ -14,6 +14,60 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ /**
18
+ * WHAT A PLUGIN'S USAGE COSTS, AND HOW MUCH OF ITS BAND IT SPENT (AGL-3080).
19
+ *
20
+ * The platform keeps one cost model (`orgMonthlyCogsUsd`) and one
21
+ * utilization table (`margin-utilization.ts`), and both read the monthly
22
+ * usage rollup. Several of the rollup's meters are a plugin's: the AI
23
+ * plugin's provider spend, the CRM's records, the forms plugin's
24
+ * submissions, the workflows plugin's runs. Core used to name each of them —
25
+ * its rollup field, the unit rate that prices it, the band it is measured
26
+ * against — so a plugin that metered something new could not reach the
27
+ * discount guardrail without a core edit, and core could not be taken
28
+ * without the plugins it named.
29
+ *
30
+ * So a plugin declares its meters, and core composes them:
31
+ *
32
+ * - a COST AXIS names the rollup fields a meter is recorded under and the
33
+ * `ORG_COGS_UNIT_RATES_USD` key that prices one unit, or no key when the
34
+ * field is already dollars. `orgMonthlyCogsUsd` prices it beside core's
35
+ * own axes, and `orgCogsInputFrom` forwards its fields.
36
+ * - a BAND names the rollup fields that measure it and the entitlement that
37
+ * says what the plan includes. The utilization table reads it beside
38
+ * core's own bands. A METERED band is also billed past what the plan
39
+ * includes, at cost × `METERED_MARKUP`, beside storage and bandwidth: the
40
+ * invoice sweep, the Billing card's estimate, the monthly summary and the
41
+ * staff usage rows read it from here.
42
+ * - a SPEND LINE names the month document holding what the plugin's usage
43
+ * came to at the rates it bills, the deployment variable naming the month
44
+ * it is first charged for, and the unit a customer sees it in. The usage
45
+ * budget shows it beside the metered figure and counts it once charged.
46
+ * - a METER names what the plugin measures in the monthly usage sweep
47
+ * (`plugin-usage-meters.ts`), so the sweep can refuse to bill a month the
48
+ * registered meter is missing from.
49
+ *
50
+ * ## What core keeps
51
+ *
52
+ * The MONEY. Every unit rate stays in `ORG_COGS_UNIT_RATES_USD`, beside the
53
+ * billed table it is reconciled against (`METERED_UNIT_RATES_USD`, which a
54
+ * metered band names its rate in), and every included figure stays in
55
+ * `PLAN_ENTITLEMENTS`. A declaration names fields and keys; it carries no
56
+ * price. The one number a declaration may carry is a band's unit cost, where
57
+ * the band is sold in a unit OF cost (a credit is a fixed quantity of
58
+ * dollars), and that number is the plugin's own definition of its unit.
59
+ *
60
+ * ## Compiled, never registered
61
+ *
62
+ * The cost model's readers include the staff org page, which prices a rollup
63
+ * in the browser, and the discount guardrail, whose every wrong answer is in
64
+ * the approving direction: a cost axis a registry had not filled would price
65
+ * at nothing and approve a discount the margin cannot carry. So these are
66
+ * compiled from each plugin's `usage-axes` declaration by the manifest
67
+ * generator, like the plan figures, and a rate key core does not have is an
68
+ * error rather than a zero.
69
+ */
70
+ import type { ReleaseFlagKey } from '../app-utils/release-flags';
17
71
  /** A meter a plugin contributes to the platform's cost model. */
18
72
  export interface PluginCostAxisDeclaration {
19
73
  /** The breakdown key every staff reader shows it under. */
@@ -32,6 +86,12 @@ export interface PluginCostAxisDeclaration {
32
86
  * by `orgCogsInputFrom` and never priced.
33
87
  */
34
88
  recordedFields?: readonly string[];
89
+ /**
90
+ * Rollup fields the plugin's usage sweep writes beside the meter for its
91
+ * staff surfaces to read — served on the staff usage rows, `null` where a
92
+ * rollup never wrote one, and never forwarded to the cost model.
93
+ */
94
+ staffFields?: readonly string[];
35
95
  /**
36
96
  * The `ORG_COGS_UNIT_RATES_USD` key pricing one unit. Absent when the
37
97
  * fields are already dollars, which then enter the model at ×1.
@@ -67,6 +127,101 @@ export interface PluginUsageBandDeclaration {
67
127
  * made never reads as less of the band.
68
128
  */
69
129
  unitCostUsd?: number;
130
+ /**
131
+ * The per-site monthly counter the band is measured by:
132
+ * `hosts/{hostId}/counters/{hostCounter}`, field `{month}`, summed over the
133
+ * workspace's sites.
134
+ */
135
+ hostCounter?: string;
136
+ /**
137
+ * The workspace is WARNED as it approaches and reaches this band, by the
138
+ * usage-alerts sweep, from its `hostCounter` against what the plan includes
139
+ * of `entitlement`, once per threshold per month. `label` names the band in
140
+ * the title ("monthly workflow runs") and `noun` in the opening sentence
141
+ * ("workflow runs"); `outcome` is what happens at the band — `stops`,
142
+ * `bills` or `continues` — and `reached` and `approach` are the sentences
143
+ * that say so, at the band and approaching it.
144
+ */
145
+ alert?: {
146
+ label: string;
147
+ noun: string;
148
+ outcome: 'stops' | 'bills' | 'continues';
149
+ reached: string;
150
+ approach: string;
151
+ };
152
+ /**
153
+ * The band is one of the INFRASTRUCTURE meters (AGL-1280): what the
154
+ * workspace uses past it is billed at our cost × `METERED_MARKUP`, beside
155
+ * storage and bandwidth, on the same invoice line and the same estimate.
156
+ * A metered band names one rollup field and the `hostCounter` it is
157
+ * measured by.
158
+ */
159
+ metered?: PluginMeteredBand;
160
+ }
161
+ /** How a metered band is priced, quoted and withheld. */
162
+ export interface PluginMeteredBand {
163
+ /**
164
+ * The `METERED_UNIT_RATES_USD` key holding our cost per unit — never a
165
+ * number: the rate table is the platform's, beside the markup it is
166
+ * published with.
167
+ */
168
+ rate: string;
169
+ /** The count a published price is quoted per: `1000` reads "per 1,000". */
170
+ quotedPer: number;
171
+ /** The band in running prose, plural and lowercase: "form submissions". */
172
+ noun: string;
173
+ /**
174
+ * A release flag the overage waits behind: while it is off for the
175
+ * workspace, the units are counted and the charge is recorded as withheld
176
+ * rather than billed — nobody is charged for what they cannot reach
177
+ * (AGL-1604). The rollup records the verdict as `{field}Billed` and what
178
+ * was forgone, at cost, as `{field}OverageWithheldUsd`.
179
+ */
180
+ withheldUntil?: ReleaseFlagKey;
181
+ }
182
+ /**
183
+ * A line of a workspace's monthly SPEND a plugin contributes to its usage
184
+ * budget (`usage-budget.ts`): what the plugin's usage came to this month, in
185
+ * the dollars it is billed at, shown on the customer's budget card and
186
+ * counted toward the budget from the month the plugin starts charging for it.
187
+ */
188
+ export interface PluginSpendLineDeclaration {
189
+ /** The line's key. */
190
+ id: string;
191
+ /** What the budget card and the budget alert call it. */
192
+ label: string;
193
+ /**
194
+ * Where the month's figure is read: `orgs/{orgId}/{collection}/{month}`,
195
+ * field `field`, in dollars.
196
+ */
197
+ live: {
198
+ collection: string;
199
+ field: string;
200
+ };
201
+ /**
202
+ * The deployment variable naming the first month (`YYYY-MM`) the line is
203
+ * charged for. Until it names this month or an earlier one — and on any
204
+ * value that is not a month — the line is shown and never counted.
205
+ */
206
+ billedFromEnv: string;
207
+ /**
208
+ * The unit the customer is shown the line in, when the stored dollars are
209
+ * not theirs to see: `ceil(dollars / costUsd)` of `label`, and the dollar
210
+ * figure never crosses to the browser.
211
+ */
212
+ unit?: {
213
+ costUsd: number;
214
+ label: string;
215
+ };
216
+ }
217
+ /**
218
+ * A meter the plugin measures in the platform's monthly usage sweep and
219
+ * registers at runtime (`plugin-usage-meters.ts`). Declared as well as
220
+ * registered so the sweep can refuse to bill a workspace's month without it.
221
+ */
222
+ export interface PluginUsageMeterDeclaration {
223
+ /** As `registerPluginUsageMeter` names it. */
224
+ id: string;
70
225
  }
71
226
  export type ResolvedPluginCostAxis = PluginCostAxisDeclaration & {
72
227
  pluginId: string;
@@ -74,13 +229,55 @@ export type ResolvedPluginCostAxis = PluginCostAxisDeclaration & {
74
229
  export type ResolvedPluginUsageBand = PluginUsageBandDeclaration & {
75
230
  pluginId: string;
76
231
  };
232
+ export type ResolvedPluginSpendLine = PluginSpendLineDeclaration & {
233
+ pluginId: string;
234
+ };
235
+ export type ResolvedPluginUsageMeter = PluginUsageMeterDeclaration & {
236
+ pluginId: string;
237
+ };
77
238
  /** What a plugin's `usageAxes` function answers. */
78
239
  export interface PluginUsageAxesDeclaration {
79
240
  costAxes?: readonly PluginCostAxisDeclaration[];
80
241
  bands?: readonly PluginUsageBandDeclaration[];
242
+ spendLines?: readonly PluginSpendLineDeclaration[];
243
+ meters?: readonly PluginUsageMeterDeclaration[];
81
244
  }
82
245
  export declare function pluginCostAxes(): readonly ResolvedPluginCostAxis[];
83
246
  export declare function pluginUsageBands(): readonly ResolvedPluginUsageBand[];
247
+ /** A declared band that is metered, with its one field and its counter. */
248
+ export type ResolvedPluginMeteredBand = ResolvedPluginUsageBand & {
249
+ metered: PluginMeteredBand;
250
+ hostCounter: string;
251
+ };
252
+ /**
253
+ * Every band billed at cost past what the plan includes, in band order — the
254
+ * infrastructure meters a plugin adds beside storage and bandwidth.
255
+ */
256
+ export declare function meteredPluginBands(): readonly ResolvedPluginMeteredBand[];
257
+ /** A declared band measured by a per-site counter and never billed past it. */
258
+ export type ResolvedPluginCountedBand = ResolvedPluginUsageBand & {
259
+ hostCounter: string;
260
+ };
261
+ /**
262
+ * Every band measured by a per-site counter and not metered, in band order:
263
+ * the usage sweep sums each across the workspace's sites and records it under
264
+ * the band's first field, and the staff usage rows show the count. A metered
265
+ * band's counter is read with the infrastructure meters instead.
266
+ */
267
+ export declare function countedPluginBands(): readonly ResolvedPluginCountedBand[];
268
+ /** The rollup field a metered band records its count under. */
269
+ export declare function meteredBandField(band: ResolvedPluginMeteredBand): string;
270
+ /**
271
+ * Where the rollup records a withheld band's verdict (`metered.withheldUntil`):
272
+ * whether the month billed the band's overage, and what was forgone, at cost,
273
+ * when it did not. Without the second a withheld month reads as a month that
274
+ * stayed inside the band.
275
+ */
276
+ export declare function meteredBandVerdictFields(band: ResolvedPluginMeteredBand): {
277
+ billed: string;
278
+ withheldUsd: string;
279
+ };
280
+ export declare function pluginSpendLines(): readonly ResolvedPluginSpendLine[];
84
281
  /**
85
282
  * What a rollup recorded for a declared meter: `fields` summed, or
86
283
  * `fallbackFields` summed when the rollup carries none of `fields` at all.
@@ -105,3 +302,18 @@ export declare function liveMeterReading(document: {
105
302
  }): number | undefined;
106
303
  /** Every rollup field the declared cost axes read or record, in order. */
107
304
  export declare function pluginCostAxisFields(): string[];
305
+ /**
306
+ * A month's rollup as a staff reader is served it, one entry per field the
307
+ * declared cost axes read, record or serve to staff (`get` reads one rollup
308
+ * field).
309
+ *
310
+ * A field an axis prices reads zero where the rollup lacks it, as the cost
311
+ * model reads it — except where the axis falls back to an older basis when
312
+ * the rollup carries none of its fields: there absence is the answer that
313
+ * selects the fallback, so it is served as `null`, and a reader pricing the
314
+ * served row reads the month the way the sweep did. A field an axis only
315
+ * records or serves reads `null` when the rollup never wrote it: "not
316
+ * recorded" and "recorded zero" are different answers, and a projection
317
+ * that collapses them invents history (AGL-2321).
318
+ */
319
+ export declare function pluginCostAxisProjection(get: (field: string) => unknown): Record<string, number | null>;
@@ -34,12 +34,23 @@
34
34
  * own axes, and `orgCogsInputFrom` forwards its fields.
35
35
  * - a BAND names the rollup fields that measure it and the entitlement that
36
36
  * says what the plan includes. The utilization table reads it beside
37
- * core's own bands.
37
+ * core's own bands. A METERED band is also billed past what the plan
38
+ * includes, at cost × `METERED_MARKUP`, beside storage and bandwidth: the
39
+ * invoice sweep, the Billing card's estimate, the monthly summary and the
40
+ * staff usage rows read it from here.
41
+ * - a SPEND LINE names the month document holding what the plugin's usage
42
+ * came to at the rates it bills, the deployment variable naming the month
43
+ * it is first charged for, and the unit a customer sees it in. The usage
44
+ * budget shows it beside the metered figure and counts it once charged.
45
+ * - a METER names what the plugin measures in the monthly usage sweep
46
+ * (`plugin-usage-meters.ts`), so the sweep can refuse to bill a month the
47
+ * registered meter is missing from.
38
48
  *
39
49
  * ## What core keeps
40
50
  *
41
51
  * The MONEY. Every unit rate stays in `ORG_COGS_UNIT_RATES_USD`, beside the
42
- * billed table it is reconciled against, and every included figure stays in
52
+ * billed table it is reconciled against (`METERED_UNIT_RATES_USD`, which a
53
+ * metered band names its rate in), and every included figure stays in
43
54
  * `PLAN_ENTITLEMENTS`. A declaration names fields and keys; it carries no
44
55
  * price. The one number a declaration may carry is a band's unit cost, where
45
56
  * the band is sold in a unit OF cost (a credit is a fixed quantity of
@@ -54,13 +65,45 @@
54
65
  * compiled from each plugin's `usage-axes` declaration by the manifest
55
66
  * generator, like the plan figures, and a rate key core does not have is an
56
67
  * error rather than a zero.
57
- */ import { PLUGIN_USAGE_BANDS_DECLARED, PLUGIN_COST_AXES_DECLARED } from "./first-party-plugins.generated.js";
68
+ */ import { PLUGIN_COST_AXES_DECLARED, PLUGIN_SPEND_LINES_DECLARED, PLUGIN_USAGE_BANDS_DECLARED } from "./first-party-plugins.generated.js";
58
69
  export function pluginCostAxes() {
59
70
  return PLUGIN_COST_AXES_DECLARED;
60
71
  }
61
72
  export function pluginUsageBands() {
62
73
  return PLUGIN_USAGE_BANDS_DECLARED;
63
74
  }
75
+ /**
76
+ * Every band billed at cost past what the plan includes, in band order — the
77
+ * infrastructure meters a plugin adds beside storage and bandwidth.
78
+ */ export function meteredPluginBands() {
79
+ return PLUGIN_USAGE_BANDS_DECLARED.filter((band)=>Boolean(band.metered && band.hostCounter));
80
+ }
81
+ /**
82
+ * Every band measured by a per-site counter and not metered, in band order:
83
+ * the usage sweep sums each across the workspace's sites and records it under
84
+ * the band's first field, and the staff usage rows show the count. A metered
85
+ * band's counter is read with the infrastructure meters instead.
86
+ */ export function countedPluginBands() {
87
+ return PLUGIN_USAGE_BANDS_DECLARED.filter((band)=>Boolean(band.hostCounter && !band.metered));
88
+ }
89
+ /** The rollup field a metered band records its count under. */ export function meteredBandField(band) {
90
+ return band.fields[0];
91
+ }
92
+ /**
93
+ * Where the rollup records a withheld band's verdict (`metered.withheldUntil`):
94
+ * whether the month billed the band's overage, and what was forgone, at cost,
95
+ * when it did not. Without the second a withheld month reads as a month that
96
+ * stayed inside the band.
97
+ */ export function meteredBandVerdictFields(band) {
98
+ const field = meteredBandField(band);
99
+ return {
100
+ billed: `${field}Billed`,
101
+ withheldUsd: `${field}OverageWithheldUsd`
102
+ };
103
+ }
104
+ export function pluginSpendLines() {
105
+ return PLUGIN_SPEND_LINES_DECLARED;
106
+ }
64
107
  /** A positive finite number, or 0 — the reading every meter is priced from. */ function meterValue(value) {
65
108
  const parsed = Number(value != null ? value : 0);
66
109
  return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
@@ -103,5 +146,41 @@ export function pluginUsageBands() {
103
146
  }
104
147
  return fields;
105
148
  }
149
+ /**
150
+ * A month's rollup as a staff reader is served it, one entry per field the
151
+ * declared cost axes read, record or serve to staff (`get` reads one rollup
152
+ * field).
153
+ *
154
+ * A field an axis prices reads zero where the rollup lacks it, as the cost
155
+ * model reads it — except where the axis falls back to an older basis when
156
+ * the rollup carries none of its fields: there absence is the answer that
157
+ * selects the fallback, so it is served as `null`, and a reader pricing the
158
+ * served row reads the month the way the sweep did. A field an axis only
159
+ * records or serves reads `null` when the rollup never wrote it: "not
160
+ * recorded" and "recorded zero" are different answers, and a projection
161
+ * that collapses them invents history (AGL-2321).
162
+ */ export function pluginCostAxisProjection(get) {
163
+ const out = {};
164
+ for (const axis of PLUGIN_COST_AXES_DECLARED){
165
+ var _axis_recordedFields, _axis_staffFields, _axis_fallbackFields, _axis_recordedFields1, _axis_staffFields1;
166
+ var _axis_fallbackFields1;
167
+ const absentIsNull = [
168
+ ...((_axis_fallbackFields1 = axis.fallbackFields) == null ? void 0 : _axis_fallbackFields1.length) ? axis.fields : [],
169
+ ...(_axis_recordedFields = axis.recordedFields) != null ? _axis_recordedFields : [],
170
+ ...(_axis_staffFields = axis.staffFields) != null ? _axis_staffFields : []
171
+ ];
172
+ for (const field of [
173
+ ...axis.fields,
174
+ ...(_axis_fallbackFields = axis.fallbackFields) != null ? _axis_fallbackFields : [],
175
+ ...(_axis_recordedFields1 = axis.recordedFields) != null ? _axis_recordedFields1 : [],
176
+ ...(_axis_staffFields1 = axis.staffFields) != null ? _axis_staffFields1 : []
177
+ ]){
178
+ if (field in out) continue;
179
+ const value = get(field);
180
+ out[field] = value != null ? Number(value) : absentIsNull.includes(field) ? null : 0;
181
+ }
182
+ }
183
+ return out;
184
+ }
106
185
 
107
186
  //# sourceMappingURL=plugin-usage-axes.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-usage-axes.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/**\n * WHAT A PLUGIN'S USAGE COSTS, AND HOW MUCH OF ITS BAND IT SPENT (AGL-3080).\n *\n * The platform keeps one cost model (`orgMonthlyCogsUsd`) and one\n * utilization table (`margin-utilization.ts`), and both read the monthly\n * usage rollup. Several of the rollup's meters are a plugin's: the AI\n * plugin's provider spend, the CRM's records, the forms plugin's\n * submissions, the workflows plugin's runs. Core used to name each of them —\n * its rollup field, the unit rate that prices it, the band it is measured\n * against — so a plugin that metered something new could not reach the\n * discount guardrail without a core edit, and core could not be taken\n * without the plugins it named.\n *\n * So a plugin declares its meters, and core composes them:\n *\n * - a COST AXIS names the rollup fields a meter is recorded under and the\n * `ORG_COGS_UNIT_RATES_USD` key that prices one unit, or no key when the\n * field is already dollars. `orgMonthlyCogsUsd` prices it beside core's\n * own axes, and `orgCogsInputFrom` forwards its fields.\n * - a BAND names the rollup fields that measure it and the entitlement that\n * says what the plan includes. The utilization table reads it beside\n * core's own bands.\n *\n * ## What core keeps\n *\n * The MONEY. Every unit rate stays in `ORG_COGS_UNIT_RATES_USD`, beside the\n * billed table it is reconciled against, and every included figure stays in\n * `PLAN_ENTITLEMENTS`. A declaration names fields and keys; it carries no\n * price. The one number a declaration may carry is a band's unit cost, where\n * the band is sold in a unit OF cost (a credit is a fixed quantity of\n * dollars), and that number is the plugin's own definition of its unit.\n *\n * ## Compiled, never registered\n *\n * The cost model's readers include the staff org page, which prices a rollup\n * in the browser, and the discount guardrail, whose every wrong answer is in\n * the approving direction: a cost axis a registry had not filled would price\n * at nothing and approve a discount the margin cannot carry. So these are\n * compiled from each plugin's `usage-axes` declaration by the manifest\n * generator, like the plan figures, and a rate key core does not have is an\n * error rather than a zero.\n */\n\nimport {\n PLUGIN_USAGE_BANDS_DECLARED,\n PLUGIN_COST_AXES_DECLARED,\n} from './first-party-plugins.generated'\n\n/** A meter a plugin contributes to the platform's cost model. */\nexport interface PluginCostAxisDeclaration {\n /** The breakdown key every staff reader shows it under. */\n id: string\n /** Where it sorts among the cost model's axes; core's own are multiples of 10. */\n order: number\n /** Rollup fields summed for the axis. */\n fields: readonly string[]\n /**\n * Read only when every one of `fields` is absent from a rollup — the\n * narrower field an older rollup recorded the same meter under.\n */\n fallbackFields?: readonly string[]\n /**\n * Rollup fields recorded beside the meter so its sum is legible, forwarded\n * by `orgCogsInputFrom` and never priced.\n */\n recordedFields?: readonly string[]\n /**\n * The `ORG_COGS_UNIT_RATES_USD` key pricing one unit. Absent when the\n * fields are already dollars, which then enter the model at ×1.\n */\n rate?: string\n /**\n * The month's LIVE reading, when the rollup's figure is a snapshot a meter\n * keeps adding to: `orgs/{orgId}/{collection}/{month}`, the first of\n * `fields` that is a positive number. It replaces the axis's first rollup\n * field wherever a reader fetches it.\n */\n live?: { collection: string; fields: readonly string[] }\n}\n\n/** A band a plugin contributes to the utilization table. */\nexport interface PluginUsageBandDeclaration {\n /** The band's key, and the column the staff table shows it under. */\n id: string\n label: string\n order: number\n /** Rollup fields summed for what the org used. */\n fields: readonly string[]\n fallbackFields?: readonly string[]\n /** The resolved entitlement holding what the plan includes. */\n entitlement: string\n /** The entitlement is per SITE and the org-wide band is it × `hostLimit`. */\n perHost?: boolean\n /**\n * The band is sold in a unit of cost and the rollup records dollars: what\n * was used is `ceil(dollars / unitCostUsd)`, rounded UP so spend already\n * made never reads as less of the band.\n */\n unitCostUsd?: number\n}\n\nexport type ResolvedPluginCostAxis = PluginCostAxisDeclaration & { pluginId: string }\nexport type ResolvedPluginUsageBand = PluginUsageBandDeclaration & { pluginId: string }\n\n/** What a plugin's `usageAxes` function answers. */\nexport interface PluginUsageAxesDeclaration {\n costAxes?: readonly PluginCostAxisDeclaration[]\n bands?: readonly PluginUsageBandDeclaration[]\n}\n\nexport function pluginCostAxes(): readonly ResolvedPluginCostAxis[] {\n return PLUGIN_COST_AXES_DECLARED\n}\n\nexport function pluginUsageBands(): readonly ResolvedPluginUsageBand[] {\n return PLUGIN_USAGE_BANDS_DECLARED\n}\n\n/** A positive finite number, or 0 — the reading every meter is priced from. */\nfunction meterValue(value: unknown): number {\n const parsed = Number(value ?? 0)\n return Number.isFinite(parsed) && parsed > 0 ? parsed : 0\n}\n\n/**\n * What a rollup recorded for a declared meter: `fields` summed, or\n * `fallbackFields` summed when the rollup carries none of `fields` at all.\n *\n * \"Carries none\" is `null` or absent, never zero. A rollup that measured\n * zero has answered, and must not fall back to a figure recorded under an\n * older, narrower basis.\n */\nexport function declaredMeterReading(\n source: Readonly<Record<string, unknown>> | null | undefined,\n declared: {\n fields: readonly string[]\n fallbackFields?: readonly string[]\n },\n): number {\n const present = declared.fields.some((field) => source?.[field] != null)\n const fields =\n !present && declared.fallbackFields?.length\n ? declared.fallbackFields\n : declared.fields\n return fields.reduce((sum, field) => sum + meterValue(source?.[field]), 0)\n}\n\n/**\n * The live reading a cost axis names: the first of its `live.fields` that is\n * a positive number on the month's document, or `undefined` when none is.\n * `undefined` is \"keep the rollup's snapshot\", never zero.\n */\nexport function liveMeterReading(\n document: { get(field: string): unknown } | null | undefined,\n live: { fields: readonly string[] },\n): number | undefined {\n for (const field of live.fields) {\n const value = meterValue(document?.get(field))\n if (value > 0) return value\n }\n return undefined\n}\n\n/** Every rollup field the declared cost axes read or record, in order. */\nexport function pluginCostAxisFields(): string[] {\n const fields: string[] = []\n for (const axis of PLUGIN_COST_AXES_DECLARED) {\n for (const field of [\n ...axis.fields,\n ...(axis.fallbackFields ?? []),\n ...(axis.recordedFields ?? []),\n ]) {\n if (!fields.includes(field)) fields.push(field)\n }\n }\n return fields\n}\n"],"names":["PLUGIN_USAGE_BANDS_DECLARED","PLUGIN_COST_AXES_DECLARED","pluginCostAxes","pluginUsageBands","meterValue","value","parsed","Number","isFinite","declaredMeterReading","source","declared","present","fields","some","field","fallbackFields","length","reduce","sum","liveMeterReading","document","live","get","undefined","pluginCostAxisFields","axis","recordedFields","includes","push"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyCC,GAED,SACEA,2BAA2B,EAC3BC,yBAAyB,QACpB,qCAAiC;AAgExC,OAAO,SAASC;IACd,OAAOD;AACT;AAEA,OAAO,SAASE;IACd,OAAOH;AACT;AAEA,6EAA6E,GAC7E,SAASI,WAAWC,KAAc;IAChC,MAAMC,SAASC,OAAOF,gBAAAA,QAAS;IAC/B,OAAOE,OAAOC,QAAQ,CAACF,WAAWA,SAAS,IAAIA,SAAS;AAC1D;AAEA;;;;;;;CAOC,GACD,OAAO,SAASG,qBACdC,MAA4D,EAC5DC,QAGC;QAIaA;IAFd,MAAMC,UAAUD,SAASE,MAAM,CAACC,IAAI,CAAC,CAACC,QAAUL,CAAAA,0BAAAA,MAAQ,CAACK,MAAM,KAAI;IACnE,MAAMF,SACJ,CAACD,aAAWD,2BAAAA,SAASK,cAAc,qBAAvBL,yBAAyBM,MAAM,IACvCN,SAASK,cAAc,GACvBL,SAASE,MAAM;IACrB,OAAOA,OAAOK,MAAM,CAAC,CAACC,KAAKJ,QAAUI,MAAMf,WAAWM,0BAAAA,MAAQ,CAACK,MAAM,GAAG;AAC1E;AAEA;;;;CAIC,GACD,OAAO,SAASK,iBACdC,QAA4D,EAC5DC,IAAmC;IAEnC,KAAK,MAAMP,SAASO,KAAKT,MAAM,CAAE;QAC/B,MAAMR,QAAQD,WAAWiB,4BAAAA,SAAUE,GAAG,CAACR;QACvC,IAAIV,QAAQ,GAAG,OAAOA;IACxB;IACA,OAAOmB;AACT;AAEA,wEAAwE,GACxE,OAAO,SAASC;IACd,MAAMZ,SAAmB,EAAE;IAC3B,KAAK,MAAMa,QAAQzB,0BAA2B;YAGtCyB,sBACAA;QAHN,KAAK,MAAMX,SAAS;eACfW,KAAKb,MAAM;gBACVa,uBAAAA,KAAKV,cAAc,YAAnBU,uBAAuB,EAAE;gBACzBA,uBAAAA,KAAKC,cAAc,YAAnBD,uBAAuB,EAAE;SAC9B,CAAE;YACD,IAAI,CAACb,OAAOe,QAAQ,CAACb,QAAQF,OAAOgB,IAAI,CAACd;QAC3C;IACF;IACA,OAAOF;AACT"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-usage-axes.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/**\n * WHAT A PLUGIN'S USAGE COSTS, AND HOW MUCH OF ITS BAND IT SPENT (AGL-3080).\n *\n * The platform keeps one cost model (`orgMonthlyCogsUsd`) and one\n * utilization table (`margin-utilization.ts`), and both read the monthly\n * usage rollup. Several of the rollup's meters are a plugin's: the AI\n * plugin's provider spend, the CRM's records, the forms plugin's\n * submissions, the workflows plugin's runs. Core used to name each of them —\n * its rollup field, the unit rate that prices it, the band it is measured\n * against — so a plugin that metered something new could not reach the\n * discount guardrail without a core edit, and core could not be taken\n * without the plugins it named.\n *\n * So a plugin declares its meters, and core composes them:\n *\n * - a COST AXIS names the rollup fields a meter is recorded under and the\n * `ORG_COGS_UNIT_RATES_USD` key that prices one unit, or no key when the\n * field is already dollars. `orgMonthlyCogsUsd` prices it beside core's\n * own axes, and `orgCogsInputFrom` forwards its fields.\n * - a BAND names the rollup fields that measure it and the entitlement that\n * says what the plan includes. The utilization table reads it beside\n * core's own bands. A METERED band is also billed past what the plan\n * includes, at cost × `METERED_MARKUP`, beside storage and bandwidth: the\n * invoice sweep, the Billing card's estimate, the monthly summary and the\n * staff usage rows read it from here.\n * - a SPEND LINE names the month document holding what the plugin's usage\n * came to at the rates it bills, the deployment variable naming the month\n * it is first charged for, and the unit a customer sees it in. The usage\n * budget shows it beside the metered figure and counts it once charged.\n * - a METER names what the plugin measures in the monthly usage sweep\n * (`plugin-usage-meters.ts`), so the sweep can refuse to bill a month the\n * registered meter is missing from.\n *\n * ## What core keeps\n *\n * The MONEY. Every unit rate stays in `ORG_COGS_UNIT_RATES_USD`, beside the\n * billed table it is reconciled against (`METERED_UNIT_RATES_USD`, which a\n * metered band names its rate in), and every included figure stays in\n * `PLAN_ENTITLEMENTS`. A declaration names fields and keys; it carries no\n * price. The one number a declaration may carry is a band's unit cost, where\n * the band is sold in a unit OF cost (a credit is a fixed quantity of\n * dollars), and that number is the plugin's own definition of its unit.\n *\n * ## Compiled, never registered\n *\n * The cost model's readers include the staff org page, which prices a rollup\n * in the browser, and the discount guardrail, whose every wrong answer is in\n * the approving direction: a cost axis a registry had not filled would price\n * at nothing and approve a discount the margin cannot carry. So these are\n * compiled from each plugin's `usage-axes` declaration by the manifest\n * generator, like the plan figures, and a rate key core does not have is an\n * error rather than a zero.\n */\n\nimport type { ReleaseFlagKey } from '../app-utils/release-flags'\nimport {\n PLUGIN_COST_AXES_DECLARED,\n PLUGIN_SPEND_LINES_DECLARED,\n PLUGIN_USAGE_BANDS_DECLARED,\n} from './first-party-plugins.generated'\n\n/** A meter a plugin contributes to the platform's cost model. */\nexport interface PluginCostAxisDeclaration {\n /** The breakdown key every staff reader shows it under. */\n id: string\n /** Where it sorts among the cost model's axes; core's own are multiples of 10. */\n order: number\n /** Rollup fields summed for the axis. */\n fields: readonly string[]\n /**\n * Read only when every one of `fields` is absent from a rollup — the\n * narrower field an older rollup recorded the same meter under.\n */\n fallbackFields?: readonly string[]\n /**\n * Rollup fields recorded beside the meter so its sum is legible, forwarded\n * by `orgCogsInputFrom` and never priced.\n */\n recordedFields?: readonly string[]\n /**\n * Rollup fields the plugin's usage sweep writes beside the meter for its\n * staff surfaces to read — served on the staff usage rows, `null` where a\n * rollup never wrote one, and never forwarded to the cost model.\n */\n staffFields?: readonly string[]\n /**\n * The `ORG_COGS_UNIT_RATES_USD` key pricing one unit. Absent when the\n * fields are already dollars, which then enter the model at ×1.\n */\n rate?: string\n /**\n * The month's LIVE reading, when the rollup's figure is a snapshot a meter\n * keeps adding to: `orgs/{orgId}/{collection}/{month}`, the first of\n * `fields` that is a positive number. It replaces the axis's first rollup\n * field wherever a reader fetches it.\n */\n live?: { collection: string; fields: readonly string[] }\n}\n\n/** A band a plugin contributes to the utilization table. */\nexport interface PluginUsageBandDeclaration {\n /** The band's key, and the column the staff table shows it under. */\n id: string\n label: string\n order: number\n /** Rollup fields summed for what the org used. */\n fields: readonly string[]\n fallbackFields?: readonly string[]\n /** The resolved entitlement holding what the plan includes. */\n entitlement: string\n /** The entitlement is per SITE and the org-wide band is it × `hostLimit`. */\n perHost?: boolean\n /**\n * The band is sold in a unit of cost and the rollup records dollars: what\n * was used is `ceil(dollars / unitCostUsd)`, rounded UP so spend already\n * made never reads as less of the band.\n */\n unitCostUsd?: number\n /**\n * The per-site monthly counter the band is measured by:\n * `hosts/{hostId}/counters/{hostCounter}`, field `{month}`, summed over the\n * workspace's sites.\n */\n hostCounter?: string\n /**\n * The workspace is WARNED as it approaches and reaches this band, by the\n * usage-alerts sweep, from its `hostCounter` against what the plan includes\n * of `entitlement`, once per threshold per month. `label` names the band in\n * the title (\"monthly workflow runs\") and `noun` in the opening sentence\n * (\"workflow runs\"); `outcome` is what happens at the band — `stops`,\n * `bills` or `continues` — and `reached` and `approach` are the sentences\n * that say so, at the band and approaching it.\n */\n alert?: {\n label: string\n noun: string\n outcome: 'stops' | 'bills' | 'continues'\n reached: string\n approach: string\n }\n /**\n * The band is one of the INFRASTRUCTURE meters (AGL-1280): what the\n * workspace uses past it is billed at our cost × `METERED_MARKUP`, beside\n * storage and bandwidth, on the same invoice line and the same estimate.\n * A metered band names one rollup field and the `hostCounter` it is\n * measured by.\n */\n metered?: PluginMeteredBand\n}\n\n/** How a metered band is priced, quoted and withheld. */\nexport interface PluginMeteredBand {\n /**\n * The `METERED_UNIT_RATES_USD` key holding our cost per unit — never a\n * number: the rate table is the platform's, beside the markup it is\n * published with.\n */\n rate: string\n /** The count a published price is quoted per: `1000` reads \"per 1,000\". */\n quotedPer: number\n /** The band in running prose, plural and lowercase: \"form submissions\". */\n noun: string\n /**\n * A release flag the overage waits behind: while it is off for the\n * workspace, the units are counted and the charge is recorded as withheld\n * rather than billed — nobody is charged for what they cannot reach\n * (AGL-1604). The rollup records the verdict as `{field}Billed` and what\n * was forgone, at cost, as `{field}OverageWithheldUsd`.\n */\n withheldUntil?: ReleaseFlagKey\n}\n\n/**\n * A line of a workspace's monthly SPEND a plugin contributes to its usage\n * budget (`usage-budget.ts`): what the plugin's usage came to this month, in\n * the dollars it is billed at, shown on the customer's budget card and\n * counted toward the budget from the month the plugin starts charging for it.\n */\nexport interface PluginSpendLineDeclaration {\n /** The line's key. */\n id: string\n /** What the budget card and the budget alert call it. */\n label: string\n /**\n * Where the month's figure is read: `orgs/{orgId}/{collection}/{month}`,\n * field `field`, in dollars.\n */\n live: { collection: string; field: string }\n /**\n * The deployment variable naming the first month (`YYYY-MM`) the line is\n * charged for. Until it names this month or an earlier one — and on any\n * value that is not a month — the line is shown and never counted.\n */\n billedFromEnv: string\n /**\n * The unit the customer is shown the line in, when the stored dollars are\n * not theirs to see: `ceil(dollars / costUsd)` of `label`, and the dollar\n * figure never crosses to the browser.\n */\n unit?: { costUsd: number; label: string }\n}\n\n/**\n * A meter the plugin measures in the platform's monthly usage sweep and\n * registers at runtime (`plugin-usage-meters.ts`). Declared as well as\n * registered so the sweep can refuse to bill a workspace's month without it.\n */\nexport interface PluginUsageMeterDeclaration {\n /** As `registerPluginUsageMeter` names it. */\n id: string\n}\n\nexport type ResolvedPluginCostAxis = PluginCostAxisDeclaration & { pluginId: string }\nexport type ResolvedPluginUsageBand = PluginUsageBandDeclaration & { pluginId: string }\nexport type ResolvedPluginSpendLine = PluginSpendLineDeclaration & { pluginId: string }\nexport type ResolvedPluginUsageMeter = PluginUsageMeterDeclaration & { pluginId: string }\n\n/** What a plugin's `usageAxes` function answers. */\nexport interface PluginUsageAxesDeclaration {\n costAxes?: readonly PluginCostAxisDeclaration[]\n bands?: readonly PluginUsageBandDeclaration[]\n spendLines?: readonly PluginSpendLineDeclaration[]\n meters?: readonly PluginUsageMeterDeclaration[]\n}\n\nexport function pluginCostAxes(): readonly ResolvedPluginCostAxis[] {\n return PLUGIN_COST_AXES_DECLARED\n}\n\nexport function pluginUsageBands(): readonly ResolvedPluginUsageBand[] {\n return PLUGIN_USAGE_BANDS_DECLARED\n}\n\n/** A declared band that is metered, with its one field and its counter. */\nexport type ResolvedPluginMeteredBand = ResolvedPluginUsageBand & {\n metered: PluginMeteredBand\n hostCounter: string\n}\n\n/**\n * Every band billed at cost past what the plan includes, in band order — the\n * infrastructure meters a plugin adds beside storage and bandwidth.\n */\nexport function meteredPluginBands(): readonly ResolvedPluginMeteredBand[] {\n return PLUGIN_USAGE_BANDS_DECLARED.filter(\n (band): band is ResolvedPluginMeteredBand =>\n Boolean(band.metered && band.hostCounter),\n )\n}\n\n/** A declared band measured by a per-site counter and never billed past it. */\nexport type ResolvedPluginCountedBand = ResolvedPluginUsageBand & {\n hostCounter: string\n}\n\n/**\n * Every band measured by a per-site counter and not metered, in band order:\n * the usage sweep sums each across the workspace's sites and records it under\n * the band's first field, and the staff usage rows show the count. A metered\n * band's counter is read with the infrastructure meters instead.\n */\nexport function countedPluginBands(): readonly ResolvedPluginCountedBand[] {\n return PLUGIN_USAGE_BANDS_DECLARED.filter(\n (band): band is ResolvedPluginCountedBand =>\n Boolean(band.hostCounter && !band.metered),\n )\n}\n\n/** The rollup field a metered band records its count under. */\nexport function meteredBandField(band: ResolvedPluginMeteredBand): string {\n return band.fields[0]!\n}\n\n/**\n * Where the rollup records a withheld band's verdict (`metered.withheldUntil`):\n * whether the month billed the band's overage, and what was forgone, at cost,\n * when it did not. Without the second a withheld month reads as a month that\n * stayed inside the band.\n */\nexport function meteredBandVerdictFields(band: ResolvedPluginMeteredBand): {\n billed: string\n withheldUsd: string\n} {\n const field = meteredBandField(band)\n return { billed: `${field}Billed`, withheldUsd: `${field}OverageWithheldUsd` }\n}\n\nexport function pluginSpendLines(): readonly ResolvedPluginSpendLine[] {\n return PLUGIN_SPEND_LINES_DECLARED\n}\n\n/** A positive finite number, or 0 — the reading every meter is priced from. */\nfunction meterValue(value: unknown): number {\n const parsed = Number(value ?? 0)\n return Number.isFinite(parsed) && parsed > 0 ? parsed : 0\n}\n\n/**\n * What a rollup recorded for a declared meter: `fields` summed, or\n * `fallbackFields` summed when the rollup carries none of `fields` at all.\n *\n * \"Carries none\" is `null` or absent, never zero. A rollup that measured\n * zero has answered, and must not fall back to a figure recorded under an\n * older, narrower basis.\n */\nexport function declaredMeterReading(\n source: Readonly<Record<string, unknown>> | null | undefined,\n declared: {\n fields: readonly string[]\n fallbackFields?: readonly string[]\n },\n): number {\n const present = declared.fields.some((field) => source?.[field] != null)\n const fields =\n !present && declared.fallbackFields?.length\n ? declared.fallbackFields\n : declared.fields\n return fields.reduce((sum, field) => sum + meterValue(source?.[field]), 0)\n}\n\n/**\n * The live reading a cost axis names: the first of its `live.fields` that is\n * a positive number on the month's document, or `undefined` when none is.\n * `undefined` is \"keep the rollup's snapshot\", never zero.\n */\nexport function liveMeterReading(\n document: { get(field: string): unknown } | null | undefined,\n live: { fields: readonly string[] },\n): number | undefined {\n for (const field of live.fields) {\n const value = meterValue(document?.get(field))\n if (value > 0) return value\n }\n return undefined\n}\n\n/** Every rollup field the declared cost axes read or record, in order. */\nexport function pluginCostAxisFields(): string[] {\n const fields: string[] = []\n for (const axis of PLUGIN_COST_AXES_DECLARED) {\n for (const field of [\n ...axis.fields,\n ...(axis.fallbackFields ?? []),\n ...(axis.recordedFields ?? []),\n ]) {\n if (!fields.includes(field)) fields.push(field)\n }\n }\n return fields\n}\n\n/**\n * A month's rollup as a staff reader is served it, one entry per field the\n * declared cost axes read, record or serve to staff (`get` reads one rollup\n * field).\n *\n * A field an axis prices reads zero where the rollup lacks it, as the cost\n * model reads it — except where the axis falls back to an older basis when\n * the rollup carries none of its fields: there absence is the answer that\n * selects the fallback, so it is served as `null`, and a reader pricing the\n * served row reads the month the way the sweep did. A field an axis only\n * records or serves reads `null` when the rollup never wrote it: \"not\n * recorded\" and \"recorded zero\" are different answers, and a projection\n * that collapses them invents history (AGL-2321).\n */\nexport function pluginCostAxisProjection(\n get: (field: string) => unknown,\n): Record<string, number | null> {\n const out: Record<string, number | null> = {}\n for (const axis of PLUGIN_COST_AXES_DECLARED) {\n const absentIsNull = [\n ...(axis.fallbackFields?.length ? axis.fields : []),\n ...(axis.recordedFields ?? []),\n ...(axis.staffFields ?? []),\n ]\n for (const field of [\n ...axis.fields,\n ...(axis.fallbackFields ?? []),\n ...(axis.recordedFields ?? []),\n ...(axis.staffFields ?? []),\n ]) {\n if (field in out) continue\n const value = get(field)\n out[field] =\n value != null ? Number(value) : absentIsNull.includes(field) ? null : 0\n }\n }\n return out\n}\n"],"names":["PLUGIN_COST_AXES_DECLARED","PLUGIN_SPEND_LINES_DECLARED","PLUGIN_USAGE_BANDS_DECLARED","pluginCostAxes","pluginUsageBands","meteredPluginBands","filter","band","Boolean","metered","hostCounter","countedPluginBands","meteredBandField","fields","meteredBandVerdictFields","field","billed","withheldUsd","pluginSpendLines","meterValue","value","parsed","Number","isFinite","declaredMeterReading","source","declared","present","some","fallbackFields","length","reduce","sum","liveMeterReading","document","live","get","undefined","pluginCostAxisFields","axis","recordedFields","includes","push","pluginCostAxisProjection","out","absentIsNull","staffFields"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDC,GAGD,SACEA,yBAAyB,EACzBC,2BAA2B,EAC3BC,2BAA2B,QACtB,qCAAiC;AAsKxC,OAAO,SAASC;IACd,OAAOH;AACT;AAEA,OAAO,SAASI;IACd,OAAOF;AACT;AAQA;;;CAGC,GACD,OAAO,SAASG;IACd,OAAOH,4BAA4BI,MAAM,CACvC,CAACC,OACCC,QAAQD,KAAKE,OAAO,IAAIF,KAAKG,WAAW;AAE9C;AAOA;;;;;CAKC,GACD,OAAO,SAASC;IACd,OAAOT,4BAA4BI,MAAM,CACvC,CAACC,OACCC,QAAQD,KAAKG,WAAW,IAAI,CAACH,KAAKE,OAAO;AAE/C;AAEA,6DAA6D,GAC7D,OAAO,SAASG,iBAAiBL,IAA+B;IAC9D,OAAOA,KAAKM,MAAM,CAAC,EAAE;AACvB;AAEA;;;;;CAKC,GACD,OAAO,SAASC,yBAAyBP,IAA+B;IAItE,MAAMQ,QAAQH,iBAAiBL;IAC/B,OAAO;QAAES,QAAQ,GAAGD,MAAM,MAAM,CAAC;QAAEE,aAAa,GAAGF,MAAM,kBAAkB,CAAC;IAAC;AAC/E;AAEA,OAAO,SAASG;IACd,OAAOjB;AACT;AAEA,6EAA6E,GAC7E,SAASkB,WAAWC,KAAc;IAChC,MAAMC,SAASC,OAAOF,gBAAAA,QAAS;IAC/B,OAAOE,OAAOC,QAAQ,CAACF,WAAWA,SAAS,IAAIA,SAAS;AAC1D;AAEA;;;;;;;CAOC,GACD,OAAO,SAASG,qBACdC,MAA4D,EAC5DC,QAGC;QAIaA;IAFd,MAAMC,UAAUD,SAASb,MAAM,CAACe,IAAI,CAAC,CAACb,QAAUU,CAAAA,0BAAAA,MAAQ,CAACV,MAAM,KAAI;IACnE,MAAMF,SACJ,CAACc,aAAWD,2BAAAA,SAASG,cAAc,qBAAvBH,yBAAyBI,MAAM,IACvCJ,SAASG,cAAc,GACvBH,SAASb,MAAM;IACrB,OAAOA,OAAOkB,MAAM,CAAC,CAACC,KAAKjB,QAAUiB,MAAMb,WAAWM,0BAAAA,MAAQ,CAACV,MAAM,GAAG;AAC1E;AAEA;;;;CAIC,GACD,OAAO,SAASkB,iBACdC,QAA4D,EAC5DC,IAAmC;IAEnC,KAAK,MAAMpB,SAASoB,KAAKtB,MAAM,CAAE;QAC/B,MAAMO,QAAQD,WAAWe,4BAAAA,SAAUE,GAAG,CAACrB;QACvC,IAAIK,QAAQ,GAAG,OAAOA;IACxB;IACA,OAAOiB;AACT;AAEA,wEAAwE,GACxE,OAAO,SAASC;IACd,MAAMzB,SAAmB,EAAE;IAC3B,KAAK,MAAM0B,QAAQvC,0BAA2B;YAGtCuC,sBACAA;QAHN,KAAK,MAAMxB,SAAS;eACfwB,KAAK1B,MAAM;gBACV0B,uBAAAA,KAAKV,cAAc,YAAnBU,uBAAuB,EAAE;gBACzBA,uBAAAA,KAAKC,cAAc,YAAnBD,uBAAuB,EAAE;SAC9B,CAAE;YACD,IAAI,CAAC1B,OAAO4B,QAAQ,CAAC1B,QAAQF,OAAO6B,IAAI,CAAC3B;QAC3C;IACF;IACA,OAAOF;AACT;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAAS8B,yBACdP,GAA+B;IAE/B,MAAMQ,MAAqC,CAAC;IAC5C,KAAK,MAAML,QAAQvC,0BAA2B;YAGtCuC,sBACAA,mBAIAA,sBACAA,uBACAA;YARAA;QADN,MAAMM,eAAe;eACfN,EAAAA,wBAAAA,KAAKV,cAAc,qBAAnBU,sBAAqBT,MAAM,IAAGS,KAAK1B,MAAM,GAAG,EAAE;gBAC9C0B,uBAAAA,KAAKC,cAAc,YAAnBD,uBAAuB,EAAE;gBACzBA,oBAAAA,KAAKO,WAAW,YAAhBP,oBAAoB,EAAE;SAC3B;QACD,KAAK,MAAMxB,SAAS;eACfwB,KAAK1B,MAAM;gBACV0B,uBAAAA,KAAKV,cAAc,YAAnBU,uBAAuB,EAAE;gBACzBA,wBAAAA,KAAKC,cAAc,YAAnBD,wBAAuB,EAAE;gBACzBA,qBAAAA,KAAKO,WAAW,YAAhBP,qBAAoB,EAAE;SAC3B,CAAE;YACD,IAAIxB,SAAS6B,KAAK;YAClB,MAAMxB,QAAQgB,IAAIrB;YAClB6B,GAAG,CAAC7B,MAAM,GACRK,SAAS,OAAOE,OAAOF,SAASyB,aAAaJ,QAAQ,CAAC1B,SAAS,OAAO;QAC1E;IACF;IACA,OAAO6B;AACT"}