@noodleseed/one 0.46.0 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (334) hide show
  1. package/dist/commands/assistant-ops.d.ts.map +1 -1
  2. package/dist/commands/assistant-ops.js +65 -1
  3. package/dist/commands/assistant-ops.js.map +1 -1
  4. package/dist/commands/auth-ops.d.ts.map +1 -1
  5. package/dist/commands/auth-ops.js +28 -4
  6. package/dist/commands/auth-ops.js.map +1 -1
  7. package/dist/commands/billing-enforcement-ops.d.ts +2 -0
  8. package/dist/commands/billing-enforcement-ops.d.ts.map +1 -0
  9. package/dist/commands/billing-enforcement-ops.js +312 -0
  10. package/dist/commands/billing-enforcement-ops.js.map +1 -0
  11. package/dist/commands/billing-metering-ops.d.ts +2 -0
  12. package/dist/commands/billing-metering-ops.d.ts.map +1 -0
  13. package/dist/commands/billing-metering-ops.js +128 -0
  14. package/dist/commands/billing-metering-ops.js.map +1 -0
  15. package/dist/commands/billing-metering-validation-ops.d.ts +2 -0
  16. package/dist/commands/billing-metering-validation-ops.d.ts.map +1 -0
  17. package/dist/commands/billing-metering-validation-ops.js +186 -0
  18. package/dist/commands/billing-metering-validation-ops.js.map +1 -0
  19. package/dist/commands/billing-ops.d.ts.map +1 -1
  20. package/dist/commands/billing-ops.js +6 -0
  21. package/dist/commands/billing-ops.js.map +1 -1
  22. package/dist/commands/catalog-data-resources.d.ts.map +1 -1
  23. package/dist/commands/catalog-data-resources.js +25 -4
  24. package/dist/commands/catalog-data-resources.js.map +1 -1
  25. package/dist/commands/catalog-render.d.ts.map +1 -1
  26. package/dist/commands/catalog-render.js +7 -5
  27. package/dist/commands/catalog-render.js.map +1 -1
  28. package/dist/commands/deploy-ops.d.ts.map +1 -1
  29. package/dist/commands/deploy-ops.js +10 -1
  30. package/dist/commands/deploy-ops.js.map +1 -1
  31. package/dist/commands/deploy-output.d.ts.map +1 -1
  32. package/dist/commands/deploy-output.js +4 -0
  33. package/dist/commands/deploy-output.js.map +1 -1
  34. package/dist/commands/deploy-version-resolution.d.ts +1 -0
  35. package/dist/commands/deploy-version-resolution.d.ts.map +1 -1
  36. package/dist/commands/deploy-version-resolution.js +8 -0
  37. package/dist/commands/deploy-version-resolution.js.map +1 -1
  38. package/dist/commands/mcp-apps-chatgpt.d.ts +7 -0
  39. package/dist/commands/mcp-apps-chatgpt.d.ts.map +1 -0
  40. package/dist/commands/mcp-apps-chatgpt.js +143 -0
  41. package/dist/commands/mcp-apps-chatgpt.js.map +1 -0
  42. package/dist/commands/mcp-apps.d.ts.map +1 -1
  43. package/dist/commands/mcp-apps.js +2 -114
  44. package/dist/commands/mcp-apps.js.map +1 -1
  45. package/dist/deploy-payload-size.d.ts +3 -0
  46. package/dist/deploy-payload-size.d.ts.map +1 -0
  47. package/dist/deploy-payload-size.js +29 -0
  48. package/dist/deploy-payload-size.js.map +1 -0
  49. package/dist/deploy.d.ts.map +1 -1
  50. package/dist/deploy.js +19 -8
  51. package/dist/deploy.js.map +1 -1
  52. package/dist/sdk-version-skew.d.ts +3 -0
  53. package/dist/sdk-version-skew.d.ts.map +1 -0
  54. package/dist/sdk-version-skew.js +34 -0
  55. package/dist/sdk-version-skew.js.map +1 -0
  56. package/node_modules/@noodle-borg/agent-kit/dist/generated/example-files.js +3 -3
  57. package/node_modules/@noodle-borg/agent-kit/dist/generated/example-files.js.map +1 -1
  58. package/node_modules/@noodle-borg/agent-kit/dist/skill-authoring-refs.js +1 -1
  59. package/node_modules/@noodle-borg/agent-kit/dist/skill-authoring-refs.js.map +1 -1
  60. package/node_modules/@noodle-borg/agent-kit/dist/skill-content.js +1 -1
  61. package/node_modules/@noodle-borg/agent-kit/dist/skill-content.js.map +1 -1
  62. package/node_modules/@noodle-borg/agent-kit/dist/skill-embedded-assistant-ref.d.ts.map +1 -1
  63. package/node_modules/@noodle-borg/agent-kit/dist/skill-embedded-assistant-ref.js +10 -2
  64. package/node_modules/@noodle-borg/agent-kit/dist/skill-embedded-assistant-ref.js.map +1 -1
  65. package/node_modules/@noodle-borg/agent-kit/package.json +1 -1
  66. package/node_modules/@noodle-borg/authoring/dist/server.d.ts +5 -0
  67. package/node_modules/@noodle-borg/authoring/dist/server.d.ts.map +1 -1
  68. package/node_modules/@noodle-borg/authoring/dist/server.js +1 -0
  69. package/node_modules/@noodle-borg/authoring/dist/server.js.map +1 -1
  70. package/node_modules/@noodle-borg/compiler/dist/artifact/types.d.ts +7 -1
  71. package/node_modules/@noodle-borg/compiler/dist/artifact/types.d.ts.map +1 -1
  72. package/node_modules/@noodle-borg/compiler/dist/artifact/types.js +4 -1
  73. package/node_modules/@noodle-borg/compiler/dist/artifact/types.js.map +1 -1
  74. package/node_modules/@noodle-borg/compiler/dist/compile.d.ts.map +1 -1
  75. package/node_modules/@noodle-borg/compiler/dist/compile.js +3 -0
  76. package/node_modules/@noodle-borg/compiler/dist/compile.js.map +1 -1
  77. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.d.ts +12 -0
  78. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.d.ts.map +1 -1
  79. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.js +7 -0
  80. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.js.map +1 -1
  81. package/node_modules/@noodle-borg/protocol/dist/mapping.d.ts.map +1 -1
  82. package/node_modules/@noodle-borg/protocol/dist/mapping.js +40 -1
  83. package/node_modules/@noodle-borg/protocol/dist/mapping.js.map +1 -1
  84. package/node_modules/@noodle-borg/protocol/dist/sdk-server.d.ts.map +1 -1
  85. package/node_modules/@noodle-borg/protocol/dist/sdk-server.js +109 -1
  86. package/node_modules/@noodle-borg/protocol/dist/sdk-server.js.map +1 -1
  87. package/node_modules/@noodle-borg/protocol/dist/tool-interaction.d.ts +10 -3
  88. package/node_modules/@noodle-borg/protocol/dist/tool-interaction.d.ts.map +1 -1
  89. package/node_modules/@noodle-borg/protocol/dist/tool-interaction.js +69 -5
  90. package/node_modules/@noodle-borg/protocol/dist/tool-interaction.js.map +1 -1
  91. package/node_modules/@noodle-borg/protocol/dist/widget/action-wiring-bootstrap.d.ts +3 -0
  92. package/node_modules/@noodle-borg/protocol/dist/widget/action-wiring-bootstrap.d.ts.map +1 -0
  93. package/node_modules/@noodle-borg/protocol/dist/widget/action-wiring-bootstrap.js +17 -0
  94. package/node_modules/@noodle-borg/protocol/dist/widget/action-wiring-bootstrap.js.map +1 -0
  95. package/node_modules/@noodle-borg/protocol/dist/widget/bootstrap.d.ts.map +1 -1
  96. package/node_modules/@noodle-borg/protocol/dist/widget/bootstrap.js +8 -16
  97. package/node_modules/@noodle-borg/protocol/dist/widget/bootstrap.js.map +1 -1
  98. package/node_modules/@noodle-borg/protocol/dist/widget/interaction-bootstrap.d.ts +3 -0
  99. package/node_modules/@noodle-borg/protocol/dist/widget/interaction-bootstrap.d.ts.map +1 -0
  100. package/node_modules/@noodle-borg/protocol/dist/widget/interaction-bootstrap.js +177 -0
  101. package/node_modules/@noodle-borg/protocol/dist/widget/interaction-bootstrap.js.map +1 -0
  102. package/node_modules/@noodle-borg/service/dist/billing/enforcement-profile.d.ts +96 -0
  103. package/node_modules/@noodle-borg/service/dist/billing/enforcement-profile.d.ts.map +1 -0
  104. package/node_modules/@noodle-borg/service/dist/billing/enforcement-profile.js +198 -0
  105. package/node_modules/@noodle-borg/service/dist/billing/enforcement-profile.js.map +1 -0
  106. package/node_modules/@noodle-borg/service/dist/billing/integration.d.ts +25 -2
  107. package/node_modules/@noodle-borg/service/dist/billing/integration.d.ts.map +1 -1
  108. package/node_modules/@noodle-borg/service/dist/billing/integration.js +51 -5
  109. package/node_modules/@noodle-borg/service/dist/billing/integration.js.map +1 -1
  110. package/node_modules/@noodle-borg/service/dist/billing/meter-capacity.d.ts +77 -0
  111. package/node_modules/@noodle-borg/service/dist/billing/meter-capacity.d.ts.map +1 -0
  112. package/node_modules/@noodle-borg/service/dist/billing/meter-capacity.js +202 -0
  113. package/node_modules/@noodle-borg/service/dist/billing/meter-capacity.js.map +1 -0
  114. package/node_modules/@noodle-borg/service/dist/billing/meter-live-validation-contract.d.ts +8 -0
  115. package/node_modules/@noodle-borg/service/dist/billing/meter-live-validation-contract.d.ts.map +1 -0
  116. package/node_modules/@noodle-borg/service/dist/billing/meter-live-validation-contract.js +93 -0
  117. package/node_modules/@noodle-borg/service/dist/billing/meter-live-validation-contract.js.map +1 -0
  118. package/node_modules/@noodle-borg/service/dist/billing/meter-live-validation.d.ts +76 -0
  119. package/node_modules/@noodle-borg/service/dist/billing/meter-live-validation.d.ts.map +1 -0
  120. package/node_modules/@noodle-borg/service/dist/billing/meter-live-validation.js +233 -0
  121. package/node_modules/@noodle-borg/service/dist/billing/meter-live-validation.js.map +1 -0
  122. package/node_modules/@noodle-borg/service/dist/billing/meter-readiness-health.d.ts +89 -0
  123. package/node_modules/@noodle-borg/service/dist/billing/meter-readiness-health.d.ts.map +1 -0
  124. package/node_modules/@noodle-borg/service/dist/billing/meter-readiness-health.js +191 -0
  125. package/node_modules/@noodle-borg/service/dist/billing/meter-readiness-health.js.map +1 -0
  126. package/node_modules/@noodle-borg/service/dist/billing/meter-readiness.d.ts +99 -0
  127. package/node_modules/@noodle-borg/service/dist/billing/meter-readiness.d.ts.map +1 -0
  128. package/node_modules/@noodle-borg/service/dist/billing/meter-readiness.js +136 -0
  129. package/node_modules/@noodle-borg/service/dist/billing/meter-readiness.js.map +1 -0
  130. package/node_modules/@noodle-borg/service/dist/billing/meter-runtime-config.d.ts +9 -0
  131. package/node_modules/@noodle-borg/service/dist/billing/meter-runtime-config.d.ts.map +1 -0
  132. package/node_modules/@noodle-borg/service/dist/billing/meter-runtime-config.js +24 -0
  133. package/node_modules/@noodle-borg/service/dist/billing/meter-runtime-config.js.map +1 -0
  134. package/node_modules/@noodle-borg/service/dist/billing/meter-validation-epoch.d.ts +75 -0
  135. package/node_modules/@noodle-borg/service/dist/billing/meter-validation-epoch.d.ts.map +1 -0
  136. package/node_modules/@noodle-borg/service/dist/billing/meter-validation-epoch.js +127 -0
  137. package/node_modules/@noodle-borg/service/dist/billing/meter-validation-epoch.js.map +1 -0
  138. package/node_modules/@noodle-borg/service/dist/billing/postgres-enforcement-profile-schema.d.ts +4 -0
  139. package/node_modules/@noodle-borg/service/dist/billing/postgres-enforcement-profile-schema.d.ts.map +1 -0
  140. package/node_modules/@noodle-borg/service/dist/billing/postgres-enforcement-profile-schema.js +107 -0
  141. package/node_modules/@noodle-borg/service/dist/billing/postgres-enforcement-profile-schema.js.map +1 -0
  142. package/node_modules/@noodle-borg/service/dist/billing/postgres-enforcement-profile.d.ts +18 -0
  143. package/node_modules/@noodle-borg/service/dist/billing/postgres-enforcement-profile.d.ts.map +1 -0
  144. package/node_modules/@noodle-borg/service/dist/billing/postgres-enforcement-profile.js +341 -0
  145. package/node_modules/@noodle-borg/service/dist/billing/postgres-enforcement-profile.js.map +1 -0
  146. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-clock.d.ts +3 -0
  147. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-clock.d.ts.map +1 -0
  148. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-clock.js +9 -0
  149. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-clock.js.map +1 -0
  150. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-epoch-fixtures.d.ts +13 -0
  151. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-epoch-fixtures.d.ts.map +1 -0
  152. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-epoch-fixtures.js +102 -0
  153. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-epoch-fixtures.js.map +1 -0
  154. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-epochs.d.ts +41 -0
  155. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-epochs.d.ts.map +1 -0
  156. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-epochs.js +289 -0
  157. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-epochs.js.map +1 -0
  158. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-evidence-retention.d.ts +16 -0
  159. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-evidence-retention.d.ts.map +1 -0
  160. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-evidence-retention.js +126 -0
  161. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-evidence-retention.js.map +1 -0
  162. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-live-validation.d.ts +33 -0
  163. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-live-validation.d.ts.map +1 -0
  164. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-live-validation.js +436 -0
  165. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-live-validation.js.map +1 -0
  166. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-maintenance.d.ts +26 -0
  167. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-maintenance.d.ts.map +1 -0
  168. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-maintenance.js +146 -0
  169. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-maintenance.js.map +1 -0
  170. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-partition.d.ts +8 -0
  171. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-partition.d.ts.map +1 -0
  172. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-partition.js +42 -0
  173. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-partition.js.map +1 -0
  174. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-prepare-preflight.d.ts +8 -0
  175. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-prepare-preflight.d.ts.map +1 -0
  176. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-prepare-preflight.js +44 -0
  177. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-prepare-preflight.js.map +1 -0
  178. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-readiness-live.d.ts +13 -0
  179. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-readiness-live.d.ts.map +1 -0
  180. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-readiness-live.js +189 -0
  181. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-readiness-live.js.map +1 -0
  182. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-readiness.d.ts +18 -0
  183. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-readiness.d.ts.map +1 -0
  184. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-readiness.js +342 -0
  185. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-readiness.js.map +1 -0
  186. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-reconciliation.d.ts +27 -0
  187. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-reconciliation.d.ts.map +1 -0
  188. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-reconciliation.js +304 -0
  189. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-reconciliation.js.map +1 -0
  190. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-retention.d.ts +22 -0
  191. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-retention.d.ts.map +1 -0
  192. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-retention.js +224 -0
  193. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-retention.js.map +1 -0
  194. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-runtime.d.ts +33 -0
  195. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-runtime.d.ts.map +1 -0
  196. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-runtime.js +173 -0
  197. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-runtime.js.map +1 -0
  198. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-scheduler-schema.d.ts +7 -0
  199. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-scheduler-schema.d.ts.map +1 -0
  200. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-scheduler-schema.js +50 -0
  201. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-scheduler-schema.js.map +1 -0
  202. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-scheduler-store.d.ts +34 -0
  203. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-scheduler-store.d.ts.map +1 -0
  204. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-scheduler-store.js +157 -0
  205. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-scheduler-store.js.map +1 -0
  206. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-scheduler.d.ts +56 -0
  207. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-scheduler.d.ts.map +1 -0
  208. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-scheduler.js +264 -0
  209. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-scheduler.js.map +1 -0
  210. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-schema.d.ts +6 -0
  211. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-schema.d.ts.map +1 -0
  212. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-schema.js +414 -0
  213. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-schema.js.map +1 -0
  214. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-validation.d.ts +43 -0
  215. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-validation.d.ts.map +1 -0
  216. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-validation.js +321 -0
  217. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-validation.js.map +1 -0
  218. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-window-lock.d.ts +10 -0
  219. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-window-lock.d.ts.map +1 -0
  220. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-window-lock.js +13 -0
  221. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-window-lock.js.map +1 -0
  222. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-window-schema.d.ts +6 -0
  223. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-window-schema.d.ts.map +1 -0
  224. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-window-schema.js +248 -0
  225. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-window-schema.js.map +1 -0
  226. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-writer-compaction.d.ts +29 -0
  227. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-writer-compaction.d.ts.map +1 -0
  228. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-writer-compaction.js +240 -0
  229. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-writer-compaction.js.map +1 -0
  230. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-writer-health-schema.d.ts +4 -0
  231. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-writer-health-schema.d.ts.map +1 -0
  232. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-writer-health-schema.js +140 -0
  233. package/node_modules/@noodle-borg/service/dist/billing/postgres-meter-writer-health-schema.js.map +1 -0
  234. package/node_modules/@noodle-borg/service/dist/billing/postgres-migration.d.ts.map +1 -1
  235. package/node_modules/@noodle-borg/service/dist/billing/postgres-migration.js +4 -0
  236. package/node_modules/@noodle-borg/service/dist/billing/postgres-migration.js.map +1 -1
  237. package/node_modules/@noodle-borg/service/dist/billing/postgres-schema.d.ts.map +1 -1
  238. package/node_modules/@noodle-borg/service/dist/billing/postgres-schema.js +6 -0
  239. package/node_modules/@noodle-borg/service/dist/billing/postgres-schema.js.map +1 -1
  240. package/node_modules/@noodle-borg/service/dist/billing/postgres.d.ts.map +1 -1
  241. package/node_modules/@noodle-borg/service/dist/billing/postgres.js +3 -0
  242. package/node_modules/@noodle-borg/service/dist/billing/postgres.js.map +1 -1
  243. package/node_modules/@noodle-borg/service/dist/billing/service-meter-runtime.d.ts +7 -0
  244. package/node_modules/@noodle-borg/service/dist/billing/service-meter-runtime.d.ts.map +1 -0
  245. package/node_modules/@noodle-borg/service/dist/billing/service-meter-runtime.js +19 -0
  246. package/node_modules/@noodle-borg/service/dist/billing/service-meter-runtime.js.map +1 -0
  247. package/node_modules/@noodle-borg/service/dist/billing/shadow-meter.d.ts +9 -4
  248. package/node_modules/@noodle-borg/service/dist/billing/shadow-meter.d.ts.map +1 -1
  249. package/node_modules/@noodle-borg/service/dist/billing/shadow-meter.js +34 -95
  250. package/node_modules/@noodle-borg/service/dist/billing/shadow-meter.js.map +1 -1
  251. package/node_modules/@noodle-borg/service/dist/billing/usage-identity.d.ts +14 -0
  252. package/node_modules/@noodle-borg/service/dist/billing/usage-identity.d.ts.map +1 -0
  253. package/node_modules/@noodle-borg/service/dist/billing/usage-identity.js +87 -0
  254. package/node_modules/@noodle-borg/service/dist/billing/usage-identity.js.map +1 -0
  255. package/node_modules/@noodle-borg/service/dist/billing/usage-observer.d.ts +6 -0
  256. package/node_modules/@noodle-borg/service/dist/billing/usage-observer.d.ts.map +1 -0
  257. package/node_modules/@noodle-borg/service/dist/billing/usage-observer.js +26 -0
  258. package/node_modules/@noodle-borg/service/dist/billing/usage-observer.js.map +1 -0
  259. package/node_modules/@noodle-borg/service/dist/billing-public.d.ts +16 -0
  260. package/node_modules/@noodle-borg/service/dist/billing-public.d.ts.map +1 -0
  261. package/node_modules/@noodle-borg/service/dist/billing-public.js +15 -0
  262. package/node_modules/@noodle-borg/service/dist/billing-public.js.map +1 -0
  263. package/node_modules/@noodle-borg/service/dist/customer-verifier.d.ts +1 -0
  264. package/node_modules/@noodle-borg/service/dist/customer-verifier.d.ts.map +1 -1
  265. package/node_modules/@noodle-borg/service/dist/customer-verifier.js +15 -0
  266. package/node_modules/@noodle-borg/service/dist/customer-verifier.js.map +1 -1
  267. package/node_modules/@noodle-borg/service/dist/http-util.d.ts +13 -0
  268. package/node_modules/@noodle-borg/service/dist/http-util.d.ts.map +1 -1
  269. package/node_modules/@noodle-borg/service/dist/http-util.js +42 -2
  270. package/node_modules/@noodle-borg/service/dist/http-util.js.map +1 -1
  271. package/node_modules/@noodle-borg/service/dist/index.d.ts +2 -7
  272. package/node_modules/@noodle-borg/service/dist/index.d.ts.map +1 -1
  273. package/node_modules/@noodle-borg/service/dist/index.js +1 -6
  274. package/node_modules/@noodle-borg/service/dist/index.js.map +1 -1
  275. package/node_modules/@noodle-borg/service/dist/main.js +3 -0
  276. package/node_modules/@noodle-borg/service/dist/main.js.map +1 -1
  277. package/node_modules/@noodle-borg/service/dist/options.d.ts +18 -0
  278. package/node_modules/@noodle-borg/service/dist/options.d.ts.map +1 -1
  279. package/node_modules/@noodle-borg/service/dist/persistence-options.d.ts +4 -0
  280. package/node_modules/@noodle-borg/service/dist/persistence-options.d.ts.map +1 -0
  281. package/node_modules/@noodle-borg/service/dist/persistence-options.js +22 -0
  282. package/node_modules/@noodle-borg/service/dist/persistence-options.js.map +1 -0
  283. package/node_modules/@noodle-borg/service/dist/routes/assistant-dispatch.d.ts.map +1 -1
  284. package/node_modules/@noodle-borg/service/dist/routes/assistant-dispatch.js +10 -1
  285. package/node_modules/@noodle-borg/service/dist/routes/assistant-dispatch.js.map +1 -1
  286. package/node_modules/@noodle-borg/service/dist/routes/assistant.d.ts +2 -0
  287. package/node_modules/@noodle-borg/service/dist/routes/assistant.d.ts.map +1 -1
  288. package/node_modules/@noodle-borg/service/dist/routes/assistant.js +85 -0
  289. package/node_modules/@noodle-borg/service/dist/routes/assistant.js.map +1 -1
  290. package/node_modules/@noodle-borg/service/dist/routes/billing-enforcement-cohort.d.ts +17 -0
  291. package/node_modules/@noodle-borg/service/dist/routes/billing-enforcement-cohort.d.ts.map +1 -0
  292. package/node_modules/@noodle-borg/service/dist/routes/billing-enforcement-cohort.js +145 -0
  293. package/node_modules/@noodle-borg/service/dist/routes/billing-enforcement-cohort.js.map +1 -0
  294. package/node_modules/@noodle-borg/service/dist/routes/billing-meter-readiness.d.ts +15 -0
  295. package/node_modules/@noodle-borg/service/dist/routes/billing-meter-readiness.d.ts.map +1 -0
  296. package/node_modules/@noodle-borg/service/dist/routes/billing-meter-readiness.js +78 -0
  297. package/node_modules/@noodle-borg/service/dist/routes/billing-meter-readiness.js.map +1 -0
  298. package/node_modules/@noodle-borg/service/dist/routes/billing-meter-validation.d.ts +15 -0
  299. package/node_modules/@noodle-borg/service/dist/routes/billing-meter-validation.d.ts.map +1 -0
  300. package/node_modules/@noodle-borg/service/dist/routes/billing-meter-validation.js +108 -0
  301. package/node_modules/@noodle-borg/service/dist/routes/billing-meter-validation.js.map +1 -0
  302. package/node_modules/@noodle-borg/service/dist/routes/commercial-dispatch.d.ts +6 -0
  303. package/node_modules/@noodle-borg/service/dist/routes/commercial-dispatch.d.ts.map +1 -1
  304. package/node_modules/@noodle-borg/service/dist/routes/commercial-dispatch.js +99 -0
  305. package/node_modules/@noodle-borg/service/dist/routes/commercial-dispatch.js.map +1 -1
  306. package/node_modules/@noodle-borg/service/dist/routes/commercial-service-deps.d.ts +25 -0
  307. package/node_modules/@noodle-borg/service/dist/routes/commercial-service-deps.d.ts.map +1 -0
  308. package/node_modules/@noodle-borg/service/dist/routes/commercial-service-deps.js +35 -0
  309. package/node_modules/@noodle-borg/service/dist/routes/commercial-service-deps.js.map +1 -0
  310. package/node_modules/@noodle-borg/service/dist/routes/control-plane.js +3 -3
  311. package/node_modules/@noodle-borg/service/dist/routes/control-plane.js.map +1 -1
  312. package/node_modules/@noodle-borg/service/dist/serve-options.d.ts +93 -0
  313. package/node_modules/@noodle-borg/service/dist/serve-options.d.ts.map +1 -0
  314. package/node_modules/@noodle-borg/service/dist/serve-options.js +2 -0
  315. package/node_modules/@noodle-borg/service/dist/serve-options.js.map +1 -0
  316. package/node_modules/@noodle-borg/service/dist/serve.d.ts +2 -92
  317. package/node_modules/@noodle-borg/service/dist/serve.d.ts.map +1 -1
  318. package/node_modules/@noodle-borg/service/dist/serve.js +64 -59
  319. package/node_modules/@noodle-borg/service/dist/serve.js.map +1 -1
  320. package/node_modules/@noodle-borg/service/dist/service-resource-cleanup.d.ts +22 -0
  321. package/node_modules/@noodle-borg/service/dist/service-resource-cleanup.d.ts.map +1 -0
  322. package/node_modules/@noodle-borg/service/dist/service-resource-cleanup.js +51 -0
  323. package/node_modules/@noodle-borg/service/dist/service-resource-cleanup.js.map +1 -0
  324. package/node_modules/@noodle-borg/service/dist/service.d.ts.map +1 -1
  325. package/node_modules/@noodle-borg/service/dist/service.js +10 -21
  326. package/node_modules/@noodle-borg/service/dist/service.js.map +1 -1
  327. package/node_modules/@noodle-borg/service/dist/store/cloudsql-pool.d.ts.map +1 -1
  328. package/node_modules/@noodle-borg/service/dist/store/cloudsql-pool.js +7 -1
  329. package/node_modules/@noodle-borg/service/dist/store/cloudsql-pool.js.map +1 -1
  330. package/node_modules/@noodle-borg/service/dist/store/postgres-billing.d.ts +6 -2
  331. package/node_modules/@noodle-borg/service/dist/store/postgres-billing.d.ts.map +1 -1
  332. package/node_modules/@noodle-borg/service/dist/store/postgres-billing.js +11 -1
  333. package/node_modules/@noodle-borg/service/dist/store/postgres-billing.js.map +1 -1
  334. package/package.json +1 -1
@@ -0,0 +1,341 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { insertAuditEvent } from '@noodle-borg/module-audit';
3
+ import { BILLING_ENFORCEMENT_COHORT_KIND, BillingEnforcementCohortConflictError, BillingEnforcementCohortSealResponseSchema, BillingEnforcementCohortStatusResponseSchema, billingEnforcementCohortRequestFingerprint, billingEnforcementCohortSuccessAudit, normalizeBillingEnforcementServiceUrl, parseBillingEnforcementCohortSealRequest, } from './enforcement-profile.js';
4
+ import { normalizeBillingEmail, validateBillingAccountId } from './model.js';
5
+ import { readBillingMeterTransactionTime } from './postgres-meter-clock.js';
6
+ import { validateScalarId } from './postgres-records.js';
7
+ export const BILLING_ENFORCEMENT_COHORT_LIFECYCLE_LOCK_KEY = 'billing-enforcement-cohort-seal:legacy-internal-v1';
8
+ export async function getEnforcementCohortStatusRow(pool) {
9
+ const client = await pool.connect();
10
+ try {
11
+ await client.query('BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY');
12
+ const response = await readEnforcementCohortStatus(client);
13
+ await client.query('COMMIT');
14
+ return response;
15
+ }
16
+ catch (error) {
17
+ await rollbackQuietly(client);
18
+ throw error;
19
+ }
20
+ finally {
21
+ client.release();
22
+ }
23
+ }
24
+ export function getActiveBillingAccountEnforcementProfileRow(pool, billingAccountId) {
25
+ return getActiveBillingAccountEnforcementProfileQuery(pool, validateBillingAccountId(billingAccountId));
26
+ }
27
+ export async function sealEnforcementCohortRow(pool, input) {
28
+ const request = parseBillingEnforcementCohortSealRequest(input.request);
29
+ const actor = normalizeActor(input.actor);
30
+ const service = normalizeBillingEnforcementServiceUrl(input.service);
31
+ const fingerprint = billingEnforcementCohortRequestFingerprint({
32
+ action: 'seal',
33
+ request,
34
+ actor,
35
+ service,
36
+ });
37
+ const idempotencyHash = hashIdempotencyKey(request.idempotencyKey);
38
+ const client = await pool.connect();
39
+ try {
40
+ await client.query('BEGIN ISOLATION LEVEL READ COMMITTED');
41
+ await lockLifecycle(client);
42
+ const replay = await findOperation(client, idempotencyHash);
43
+ if (replay !== undefined) {
44
+ const response = replayOperation(replay, fingerprint);
45
+ const replayedAt = await readBillingMeterTransactionTime(client);
46
+ await insertAuditEvent(client, billingEnforcementCohortSuccessAudit(response, actor), {
47
+ now: () => new Date(replayedAt),
48
+ });
49
+ await client.query('COMMIT');
50
+ return response;
51
+ }
52
+ const existing = await findSeal(client);
53
+ if (existing !== undefined) {
54
+ throw new BillingEnforcementCohortConflictError('enforcement_cohort_already_sealed', 'the legacy internal enforcement cohort was already sealed under a different key');
55
+ }
56
+ // The order matches normal workspace provisioning (organization, account, billing tuple). A writer
57
+ // already holding an insert lock finishes first and is included; later writers wait and observe the seal.
58
+ await client.query(`
59
+ LOCK TABLE orgs, billing_accounts, billing_entitlement_snapshots,
60
+ billing_account_active_snapshots, org_billing_links
61
+ IN SHARE ROW EXCLUSIVE MODE
62
+ `);
63
+ const attributionBlockerCount = await countAttributionBlockers(client);
64
+ if (attributionBlockerCount !== 0) {
65
+ throw new BillingEnforcementCohortConflictError('billing_attribution_incomplete', 'every managed organization must have verified billing attribution before sealing');
66
+ }
67
+ const sealedAt = await readBillingMeterTransactionTime(client);
68
+ const sealId = `becs_${randomUUID()}`;
69
+ await client.query(`INSERT INTO billing_enforcement_cohort_seals
70
+ (id, singleton, schema_version, cohort_kind, state, legacy_account_profile,
71
+ post_seal_account_profile, sealed_at, sealed_by_subject, sealed_by_email,
72
+ service_origin, reason)
73
+ VALUES ($1, true, 1, $2, 'sealed', 'legacy_internal_exempt', 'enforced',
74
+ $3, $4, $5, $6, $7)`, [
75
+ sealId,
76
+ BILLING_ENFORCEMENT_COHORT_KIND,
77
+ sealedAt,
78
+ actor.subject,
79
+ actor.email,
80
+ service,
81
+ request.reason,
82
+ ]);
83
+ const profiles = await client.query(`INSERT INTO billing_account_enforcement_profiles
84
+ (billing_account_id, version, schema_version, mode, cohort_kind, cohort_seal_id,
85
+ source, effective_from, created_at)
86
+ SELECT id, 1, 1, 'legacy_internal_exempt', $2, $1,
87
+ 'legacy_cohort_seal', $3, $3
88
+ FROM billing_accounts
89
+ ORDER BY id`, [sealId, BILLING_ENFORCEMENT_COHORT_KIND, sealedAt]);
90
+ await client.query(`INSERT INTO billing_account_active_enforcement_profiles
91
+ (billing_account_id, profile_version)
92
+ SELECT billing_account_id, version
93
+ FROM billing_account_enforcement_profiles
94
+ WHERE cohort_seal_id = $1`, [sealId]);
95
+ const status = await readEnforcementCohortStatus(client);
96
+ if (status.state !== 'sealed' ||
97
+ status.sealId !== sealId ||
98
+ status.billingAccountCount !== profiles.rowCount ||
99
+ status.unprofiledAccountCount !== 0 ||
100
+ status.enforcedAccountCount !== 0) {
101
+ throw new BillingEnforcementCohortConflictError('enforcement_profile_state_conflict', 'the legacy internal cohort could not be classified completely');
102
+ }
103
+ const response = BillingEnforcementCohortSealResponseSchema.parse({
104
+ ...status,
105
+ replayed: false,
106
+ activationState: 'not_active',
107
+ });
108
+ await insertOperation(client, {
109
+ response,
110
+ idempotencyHash,
111
+ fingerprint,
112
+ actor,
113
+ service,
114
+ reason: request.reason,
115
+ createdAt: sealedAt,
116
+ });
117
+ await insertAuditEvent(client, billingEnforcementCohortSuccessAudit(response, actor), {
118
+ now: () => new Date(sealedAt),
119
+ });
120
+ await client.query('COMMIT');
121
+ return response;
122
+ }
123
+ catch (error) {
124
+ await rollbackQuietly(client);
125
+ throw translateTransactionError(error);
126
+ }
127
+ finally {
128
+ client.release();
129
+ }
130
+ }
131
+ /**
132
+ * Application-side defense in depth after account insertion. The database trigger normally creates the
133
+ * profile first; the active-profile lookup keeps this helper idempotent with that trigger-created state.
134
+ */
135
+ export async function ensurePostSealBillingAccountEnforcementProfileTx(client, billingAccountId) {
136
+ const accountId = validateBillingAccountId(billingAccountId);
137
+ const seal = await findSeal(client);
138
+ if (seal === undefined)
139
+ return undefined;
140
+ const existing = await getActiveBillingAccountEnforcementProfileQuery(client, accountId);
141
+ if (existing !== undefined)
142
+ return existing;
143
+ const effectiveFrom = await readBillingMeterTransactionTime(client);
144
+ const { rows } = await client.query(`INSERT INTO billing_account_enforcement_profiles
145
+ (billing_account_id, version, schema_version, mode, cohort_kind, cohort_seal_id,
146
+ source, effective_from, created_at)
147
+ VALUES ($1, 1, 1, 'enforced', $2, $3, 'post_seal_account', $4, $4)
148
+ RETURNING *`, [accountId, BILLING_ENFORCEMENT_COHORT_KIND, seal.id, effectiveFrom]);
149
+ await client.query(`INSERT INTO billing_account_active_enforcement_profiles
150
+ (billing_account_id, profile_version)
151
+ VALUES ($1, 1)`, [accountId]);
152
+ return profileRowToRecord(rows[0]);
153
+ }
154
+ export async function requireBillingAccountEnforcementProfileIfSealedTx(client, billingAccountId) {
155
+ if ((await findSeal(client)) === undefined)
156
+ return;
157
+ if ((await getActiveBillingAccountEnforcementProfileQuery(client, billingAccountId)) === undefined) {
158
+ throw new Error('default billing account is incomplete');
159
+ }
160
+ }
161
+ async function readEnforcementCohortStatus(queryable) {
162
+ const seal = await findSeal(queryable);
163
+ const counts = await queryable.query(`
164
+ SELECT
165
+ count(account.id)::text AS billing_account_count,
166
+ count(profile.billing_account_id)::text AS profiled_account_count,
167
+ count(*) FILTER (WHERE profile.mode = 'legacy_internal_exempt')::text
168
+ AS legacy_internal_exempt_account_count,
169
+ count(*) FILTER (WHERE profile.mode = 'enforced')::text AS enforced_account_count,
170
+ count(*) FILTER (WHERE profile.billing_account_id IS NULL)::text AS unprofiled_account_count
171
+ FROM billing_accounts AS account
172
+ LEFT JOIN billing_account_active_enforcement_profiles AS active
173
+ ON active.billing_account_id = account.id
174
+ LEFT JOIN billing_account_enforcement_profiles AS profile
175
+ ON profile.billing_account_id = active.billing_account_id
176
+ AND profile.version = active.profile_version
177
+ `);
178
+ const attributionBlockerCount = await countAttributionBlockers(queryable);
179
+ const row = counts.rows[0];
180
+ return BillingEnforcementCohortStatusResponseSchema.parse({
181
+ schemaVersion: 1,
182
+ cohortKind: BILLING_ENFORCEMENT_COHORT_KIND,
183
+ state: seal === undefined ? 'unsealed' : 'sealed',
184
+ sealId: seal?.id ?? null,
185
+ sealedAt: seal === undefined ? null : toIso(seal.sealed_at),
186
+ legacyAccountProfile: 'legacy_internal_exempt',
187
+ postSealAccountProfile: 'enforced',
188
+ billingAccountCount: parseCount(row?.billing_account_count),
189
+ profiledAccountCount: parseCount(row?.profiled_account_count),
190
+ legacyInternalExemptAccountCount: parseCount(row?.legacy_internal_exempt_account_count),
191
+ enforcedAccountCount: parseCount(row?.enforced_account_count),
192
+ unprofiledAccountCount: parseCount(row?.unprofiled_account_count),
193
+ billingAttributionComplete: attributionBlockerCount === 0,
194
+ attributionBlockerCount,
195
+ });
196
+ }
197
+ async function countAttributionBlockers(queryable) {
198
+ const { rows } = await queryable.query(`
199
+ SELECT count(*)::text AS incomplete
200
+ FROM (
201
+ -- Blocker units are distinct entities: each unlinked managed organization and each incomplete
202
+ -- account used by at least one active non-local organization link contributes exactly once.
203
+ -- Unlinked draft/snapshotless accounts are valid and do not block the cohort seal.
204
+ SELECT 'organization' AS blocker_kind, org.slug AS blocker_id
205
+ FROM orgs AS org
206
+ WHERE org.slug <> 'local'
207
+ AND NOT EXISTS (
208
+ SELECT 1
209
+ FROM org_billing_links AS link
210
+ WHERE link.org_slug = org.slug AND link.active
211
+ )
212
+ UNION ALL
213
+ SELECT DISTINCT 'billing_account' AS blocker_kind, link.billing_account_id AS blocker_id
214
+ FROM org_billing_links AS link
215
+ JOIN orgs AS org ON org.slug = link.org_slug
216
+ WHERE org.slug <> 'local'
217
+ AND link.active
218
+ AND NOT EXISTS (
219
+ SELECT 1
220
+ FROM billing_account_active_snapshots AS active
221
+ JOIN billing_entitlement_snapshots AS snapshot
222
+ ON snapshot.billing_account_id = active.billing_account_id
223
+ AND snapshot.id = active.snapshot_id
224
+ WHERE active.billing_account_id = link.billing_account_id
225
+ AND snapshot.verification_status = 'verified'
226
+ )
227
+ ) AS blockers
228
+ `);
229
+ return parseCount(rows[0]?.incomplete);
230
+ }
231
+ async function findSeal(queryable) {
232
+ const { rows } = await queryable.query(`SELECT id, cohort_kind, state, legacy_account_profile,
233
+ post_seal_account_profile, sealed_at
234
+ FROM billing_enforcement_cohort_seals
235
+ WHERE singleton = true`);
236
+ return rows[0];
237
+ }
238
+ async function getActiveBillingAccountEnforcementProfileQuery(queryable, billingAccountId) {
239
+ const { rows } = await queryable.query(`SELECT profile.*
240
+ FROM billing_account_active_enforcement_profiles AS active
241
+ JOIN billing_account_enforcement_profiles AS profile
242
+ ON profile.billing_account_id = active.billing_account_id
243
+ AND profile.version = active.profile_version
244
+ WHERE active.billing_account_id = $1`, [validateBillingAccountId(billingAccountId)]);
245
+ return rows[0] === undefined ? undefined : profileRowToRecord(rows[0]);
246
+ }
247
+ function profileRowToRecord(row) {
248
+ if (row.schema_version !== 1 ||
249
+ row.cohort_kind !== BILLING_ENFORCEMENT_COHORT_KIND ||
250
+ !((row.mode === 'legacy_internal_exempt' && row.source === 'legacy_cohort_seal') ||
251
+ (row.mode === 'enforced' && row.source === 'post_seal_account'))) {
252
+ throw new Error('billing enforcement profile is invalid');
253
+ }
254
+ return {
255
+ schemaVersion: 1,
256
+ billingAccountId: validateBillingAccountId(row.billing_account_id),
257
+ version: row.version,
258
+ mode: row.mode,
259
+ cohortKind: row.cohort_kind,
260
+ cohortSealId: validateScalarId('billing enforcement cohort seal id', row.cohort_seal_id),
261
+ source: row.source,
262
+ effectiveFrom: toIso(row.effective_from),
263
+ createdAt: toIso(row.created_at),
264
+ };
265
+ }
266
+ function normalizeActor(actor) {
267
+ return {
268
+ ...actor,
269
+ subject: validateScalarId('billing enforcement actor subject', actor.subject),
270
+ email: normalizeBillingEmail(actor.email),
271
+ };
272
+ }
273
+ function hashIdempotencyKey(value) {
274
+ return createHash('sha256').update(value).digest('hex');
275
+ }
276
+ function lockLifecycle(client) {
277
+ return client.query('SELECT pg_advisory_xact_lock(hashtextextended($1, 0))', [
278
+ BILLING_ENFORCEMENT_COHORT_LIFECYCLE_LOCK_KEY,
279
+ ]);
280
+ }
281
+ async function findOperation(client, idempotencyHash) {
282
+ const { rows } = await client.query(`SELECT action, request_fingerprint, result
283
+ FROM billing_enforcement_cohort_operations
284
+ WHERE idempotency_key_hash = $1`, [idempotencyHash]);
285
+ return rows[0];
286
+ }
287
+ function replayOperation(row, fingerprint) {
288
+ if (row.action !== 'seal' || row.request_fingerprint !== fingerprint) {
289
+ throw new BillingEnforcementCohortConflictError('idempotency_key_conflict', 'idempotency key was already used by a different request or actor');
290
+ }
291
+ const response = BillingEnforcementCohortSealResponseSchema.parse(row.result);
292
+ return { ...response, replayed: true };
293
+ }
294
+ async function insertOperation(client, input) {
295
+ await client.query(`INSERT INTO billing_enforcement_cohort_operations
296
+ (operation_id, action, idempotency_key_hash, request_fingerprint, cohort_seal_id,
297
+ result, actor_subject, actor_email, service_origin, reason, created_at)
298
+ VALUES ($1, 'seal', $2, $3, $4, $5::jsonb, $6, $7, $8, $9, $10)`, [
299
+ `beco_${randomUUID()}`,
300
+ input.idempotencyHash,
301
+ input.fingerprint,
302
+ input.response.sealId,
303
+ JSON.stringify(input.response),
304
+ input.actor.subject,
305
+ input.actor.email,
306
+ input.service,
307
+ input.reason,
308
+ input.createdAt,
309
+ ]);
310
+ }
311
+ function parseCount(value) {
312
+ const parsed = Number(value ?? '0');
313
+ if (!Number.isSafeInteger(parsed) || parsed < 0) {
314
+ throw new Error('billing enforcement aggregate count is invalid');
315
+ }
316
+ return parsed;
317
+ }
318
+ function translateTransactionError(error) {
319
+ const code = typeof error === 'object' && error !== null && 'code' in error
320
+ ? String(error.code)
321
+ : undefined;
322
+ if (code === '40001' || code === '40P01') {
323
+ return new BillingEnforcementCohortConflictError('serialization_conflict', 'billing enforcement cohort state changed concurrently; retry the exact request');
324
+ }
325
+ return error;
326
+ }
327
+ function toIso(value) {
328
+ const date = value instanceof Date ? value : new Date(value);
329
+ if (!Number.isFinite(date.getTime()))
330
+ throw new Error('billing enforcement timestamp is invalid');
331
+ return date.toISOString();
332
+ }
333
+ async function rollbackQuietly(client) {
334
+ try {
335
+ await client.query('ROLLBACK');
336
+ }
337
+ catch {
338
+ // Preserve the original transaction failure.
339
+ }
340
+ }
341
+ //# sourceMappingURL=postgres-enforcement-profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-enforcement-profile.js","sourceRoot":"","sources":["../../src/billing/postgres-enforcement-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,EACL,+BAA+B,EAE/B,qCAAqC,EAGrC,0CAA0C,EAE1C,4CAA4C,EAC5C,0CAA0C,EAC1C,oCAAoC,EACpC,qCAAqC,EACrC,wCAAwC,GACzC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO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CAAC;IAChB,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACzC,OAAO,IAAI,qCAAqC,CAC9C,wBAAwB,EACxB,gFAAgF,CACjF,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,KAAK,CAAC,KAAoB;IACjC,MAAM,IAAI,GAAG,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAClG,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;AAC5B,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,MAAkB;IAC/C,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,6CAA6C;IAC/C,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Pool, PoolClient } from 'pg';
2
+ export declare function readBillingMeterTransactionTime(client: Pool | PoolClient): Promise<string>;
3
+ //# sourceMappingURL=postgres-meter-clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-meter-clock.d.ts","sourceRoot":"","sources":["../../src/billing/postgres-meter-clock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAG3C,wBAAsB,+BAA+B,CAAC,MAAM,EAAE,IAAI,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAUhG"}
@@ -0,0 +1,9 @@
1
+ import { normalizeBillingUsageInstant } from './usage-window.js';
2
+ export async function readBillingMeterTransactionTime(client) {
3
+ const result = await client.query('SELECT billing_meter_transaction_time() AS transaction_time');
4
+ const value = result.rows[0]?.transaction_time;
5
+ if (value === undefined)
6
+ throw new Error('billing meter database clock returned no result');
7
+ return normalizeBillingUsageInstant('billing meter database transaction time', value instanceof Date ? value.toISOString() : value);
8
+ }
9
+ //# sourceMappingURL=postgres-meter-clock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-meter-clock.js","sourceRoot":"","sources":["../../src/billing/postgres-meter-clock.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AAEjE,MAAM,CAAC,KAAK,UAAU,+BAA+B,CAAC,MAAyB;IAC7E,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAC/B,6DAA6D,CAC9D,CAAC;IACF,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC;IAC/C,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAC5F,OAAO,4BAA4B,CACjC,yCAAyC,EACzC,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CACpD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Pool } from 'pg';
2
+ /** Internal fixture setup only; production lifecycle mutations use the audited epoch store. */
3
+ export declare function prepareBillingMeterValidationEpoch(pool: Pool, input: {
4
+ readonly epochId: string;
5
+ readonly keyGeneration: string;
6
+ readonly releaseSha: string;
7
+ readonly retryIdentityVersion: number;
8
+ readonly writerContractVersion?: number;
9
+ }): Promise<void>;
10
+ export declare function retireBillingMeterValidationEpoch(pool: Pool, input: {
11
+ readonly epochId: string;
12
+ }): Promise<void>;
13
+ //# sourceMappingURL=postgres-meter-epoch-fixtures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-meter-epoch-fixtures.d.ts","sourceRoot":"","sources":["../../src/billing/postgres-meter-epoch-fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,IAAI,CAAC;AAK3C,+FAA+F;AAC/F,wBAAsB,kCAAkC,CACtD,IAAI,EAAE,IAAI,EACV,KAAK,EAAE;IACL,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;CACzC,GACA,OAAO,CAAC,IAAI,CAAC,CAsDf;AAED,wBAAsB,iCAAiC,CACrD,IAAI,EAAE,IAAI,EACV,KAAK,EAAE;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAClC,OAAO,CAAC,IAAI,CAAC,CA6Bf"}
@@ -0,0 +1,102 @@
1
+ import { BILLING_METER_VALIDATION_WRITER_CONTRACT_VERSION } from './meter-validation-epoch.js';
2
+ import { readBillingMeterTransactionTime } from './postgres-meter-clock.js';
3
+ import { validateScalarId } from './postgres-records.js';
4
+ /** Internal fixture setup only; production lifecycle mutations use the audited epoch store. */
5
+ export async function prepareBillingMeterValidationEpoch(pool, input) {
6
+ const epochId = validateScalarId('billing meter epoch id', input.epochId);
7
+ const generation = validateGeneration(input.keyGeneration);
8
+ const releaseSha = validateReleaseSha(input.releaseSha);
9
+ const writerContractVersion = validatePositiveVersion('billing meter writer contract version', input.writerContractVersion ?? BILLING_METER_VALIDATION_WRITER_CONTRACT_VERSION);
10
+ if (!Number.isSafeInteger(input.retryIdentityVersion) || input.retryIdentityVersion < 1) {
11
+ throw new Error('billing meter retry identity version must be positive');
12
+ }
13
+ const client = await pool.connect();
14
+ try {
15
+ await client.query('BEGIN');
16
+ const preparedAt = await readBillingMeterTransactionTime(client);
17
+ const existing = await client.query('SELECT * FROM billing_meter_epochs WHERE id = $1 FOR UPDATE', [epochId]);
18
+ const row = existing.rows[0];
19
+ if (row === undefined) {
20
+ await client.query(`INSERT INTO billing_meter_epochs
21
+ (id, schema_version, state, key_generation, release_sha, retry_identity_version,
22
+ writer_contract_version, prepared_at)
23
+ VALUES ($1, 1, 'prepared', $2, $3, $4, $5, $6)`, [
24
+ epochId,
25
+ generation,
26
+ releaseSha,
27
+ input.retryIdentityVersion,
28
+ writerContractVersion,
29
+ preparedAt,
30
+ ]);
31
+ }
32
+ else if (row.state !== 'prepared' ||
33
+ row.key_generation !== generation ||
34
+ row.release_sha !== releaseSha ||
35
+ row.retry_identity_version !== input.retryIdentityVersion ||
36
+ row.writer_contract_version !== writerContractVersion) {
37
+ throw new Error('billing meter validation epoch already exists with different semantics');
38
+ }
39
+ await client.query('COMMIT');
40
+ }
41
+ catch (error) {
42
+ await rollbackQuietly(client);
43
+ throw error;
44
+ }
45
+ finally {
46
+ client.release();
47
+ }
48
+ }
49
+ export async function retireBillingMeterValidationEpoch(pool, input) {
50
+ const epochId = validateScalarId('billing meter epoch id', input.epochId);
51
+ const client = await pool.connect();
52
+ try {
53
+ await client.query('BEGIN');
54
+ const retiredAt = await readBillingMeterTransactionTime(client);
55
+ const existing = await client.query('SELECT state FROM billing_meter_epochs WHERE id = $1 FOR UPDATE', [epochId]);
56
+ const state = existing.rows[0]?.state;
57
+ if (state === undefined)
58
+ throw new Error('billing meter validation epoch does not exist');
59
+ if (state === 'prepared') {
60
+ await client.query(`UPDATE billing_meter_epochs
61
+ SET state = 'retired', retired_at = $2
62
+ WHERE id = $1`, [epochId, retiredAt]);
63
+ }
64
+ else if (state !== 'retired') {
65
+ throw new Error('billing meter validation epoch cannot be retired from its current state');
66
+ }
67
+ await client.query('COMMIT');
68
+ }
69
+ catch (error) {
70
+ await rollbackQuietly(client);
71
+ throw error;
72
+ }
73
+ finally {
74
+ client.release();
75
+ }
76
+ }
77
+ function validateGeneration(value) {
78
+ if (!/^[0-9a-f]{64}$/.test(value)) {
79
+ throw new Error('billing meter key generation must be a SHA-256 digest');
80
+ }
81
+ return value;
82
+ }
83
+ function validateReleaseSha(value) {
84
+ if (!/^[0-9a-f]{40}$/.test(value)) {
85
+ throw new Error('billing meter release SHA must be a full 40-character commit digest');
86
+ }
87
+ return value;
88
+ }
89
+ function validatePositiveVersion(name, value) {
90
+ if (!Number.isSafeInteger(value) || value < 1)
91
+ throw new Error(`${name} must be positive`);
92
+ return value;
93
+ }
94
+ async function rollbackQuietly(client) {
95
+ try {
96
+ await client.query('ROLLBACK');
97
+ }
98
+ catch {
99
+ // Preserve the original transaction failure.
100
+ }
101
+ }
102
+ //# sourceMappingURL=postgres-meter-epoch-fixtures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-meter-epoch-fixtures.js","sourceRoot":"","sources":["../../src/billing/postgres-meter-epoch-fixtures.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gDAAgD,EAAE,MAAM,6BAA6B,CAAC;AAC/F,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,+FAA+F;AAC/F,MAAM,CAAC,KAAK,UAAU,kCAAkC,CACtD,IAAU,EACV,KAMC;IAED,MAAM,OAAO,GAAG,gBAAgB,CAAC,wBAAwB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1E,MAAM,UAAU,GAAG,kBAAkB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAC3D,MAAM,UAAU,GAAG,kBAAkB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACxD,MAAM,qBAAqB,GAAG,uBAAuB,CACnD,uCAAuC,EACvC,KAAK,CAAC,qBAAqB,IAAI,gDAAgD,CAChF,CAAC;IACF,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,oBAAoB,CAAC,IAAI,KAAK,CAAC,oBAAoB,GAAG,CAAC,EAAE,CAAC;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;AAED,SAAS,kBAAkB,CAAC,KAAa;IACvC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,uBAAuB,CAAC,IAAY,EAAE,KAAa;IAC1D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAC;IAC3F,OAAO,KAAK,CAAC;AACf,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,MAAkB;IAC/C,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,6CAA6C;IAC/C,CAAC;AACH,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { Pool, PoolClient } from 'pg';
2
+ import type { ControlPlaneIdentity } from '../auth/deploy-gate.js';
3
+ import { type BillingMeterValidationEpochPrepareRequest, type BillingMeterValidationEpochResult, type BillingMeterValidationEpochRetireRequest, type BillingMeterValidationEpochStore } from './meter-validation-epoch.js';
4
+ export declare const BILLING_METER_VALIDATION_EPOCH_LIFECYCLE_LOCK_KEY = "billing-meter-validation-epoch-lifecycle:v1";
5
+ export interface BillingMeterValidationEpochPrepareBindings {
6
+ readonly keyGeneration: string;
7
+ readonly releaseSha: string;
8
+ readonly retryIdentityVersion: number;
9
+ readonly writerContractVersion: number;
10
+ }
11
+ export type BillingMeterValidationEpochPreparePreflight = (input: {
12
+ readonly client: PoolClient;
13
+ readonly epochId: string;
14
+ readonly bindings: BillingMeterValidationEpochPrepareBindings;
15
+ }) => Promise<boolean>;
16
+ export interface PostgresBillingMeterValidationEpochStoreOptions {
17
+ readonly billingUsageHmacKey?: string;
18
+ readonly releaseSha?: string;
19
+ readonly retryIdentityVersion?: number;
20
+ readonly writerContractVersion?: number;
21
+ /** Required for prepare; retirement and exact replay remain available while health is degraded. */
22
+ readonly preparePreflight?: BillingMeterValidationEpochPreparePreflight;
23
+ readonly id?: () => string;
24
+ }
25
+ /** Durable, validation-only lifecycle. It never creates an active meter epoch. */
26
+ export declare class PostgresBillingMeterValidationEpochStore implements BillingMeterValidationEpochStore {
27
+ #private;
28
+ readonly successAuditMode: "transactional";
29
+ constructor(pool: Pool, options: PostgresBillingMeterValidationEpochStoreOptions);
30
+ prepareValidationEpoch(input: {
31
+ readonly request: BillingMeterValidationEpochPrepareRequest;
32
+ readonly actor: ControlPlaneIdentity;
33
+ readonly service: string;
34
+ }): Promise<BillingMeterValidationEpochResult>;
35
+ retireValidationEpoch(input: {
36
+ readonly request: BillingMeterValidationEpochRetireRequest;
37
+ readonly actor: ControlPlaneIdentity;
38
+ readonly service: string;
39
+ }): Promise<BillingMeterValidationEpochResult>;
40
+ }
41
+ //# sourceMappingURL=postgres-meter-epochs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-meter-epochs.d.ts","sourceRoot":"","sources":["../../src/billing/postgres-meter-epochs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAKnE,OAAO,EAGL,KAAK,yCAAyC,EAC9C,KAAK,iCAAiC,EAEtC,KAAK,wCAAwC,EAC7C,KAAK,gCAAgC,EAMtC,MAAM,6BAA6B,CAAC;AAKrC,eAAO,MAAM,iDAAiD,gDACf,CAAC;AAEhD,MAAM,WAAW,0CAA0C;IACzD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,qBAAqB,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