@proofoftech/flowsafe 0.10.0 → 0.12.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 (391) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +77 -47
  3. package/deployment-identity-protocol.d.mts +52 -0
  4. package/deployment-identity-protocol.mjs +231 -0
  5. package/dist/agent-host/approval-resumer.d.ts +3 -3
  6. package/dist/agent-host/approval-resumer.d.ts.map +1 -1
  7. package/dist/agent-host/approval-resumer.js +6 -7
  8. package/dist/agent-host/approval-resumer.js.map +1 -1
  9. package/dist/agent-host/catalog.d.ts +1 -1
  10. package/dist/agent-host/catalog.d.ts.map +1 -1
  11. package/dist/agent-host/catalog.js +26 -2
  12. package/dist/agent-host/catalog.js.map +1 -1
  13. package/dist/agent-host/index.d.ts +4 -3
  14. package/dist/agent-host/index.d.ts.map +1 -1
  15. package/dist/agent-host/index.js +1 -0
  16. package/dist/agent-host/index.js.map +1 -1
  17. package/dist/agent-host/router.d.ts +2 -2
  18. package/dist/agent-host/router.d.ts.map +1 -1
  19. package/dist/agent-host/router.js +22 -54
  20. package/dist/agent-host/router.js.map +1 -1
  21. package/dist/agent-host/thread-host.d.ts +53 -9
  22. package/dist/agent-host/thread-host.d.ts.map +1 -1
  23. package/dist/agent-host/thread-host.js +624 -109
  24. package/dist/agent-host/thread-host.js.map +1 -1
  25. package/dist/agent-host/thread-topology.d.ts +28 -7
  26. package/dist/agent-host/thread-topology.d.ts.map +1 -1
  27. package/dist/agent-host/thread-topology.js +97 -39
  28. package/dist/agent-host/thread-topology.js.map +1 -1
  29. package/dist/agent-host/trusted-context.d.ts.map +1 -1
  30. package/dist/agent-host/trusted-context.js +9 -2
  31. package/dist/agent-host/trusted-context.js.map +1 -1
  32. package/dist/agent-host/types.d.ts +48 -0
  33. package/dist/agent-host/types.d.ts.map +1 -1
  34. package/dist/agent-host/types.js +1 -1
  35. package/dist/agent-host/types.js.map +1 -1
  36. package/dist/agent-runner/agent-run-state.d.ts +9 -8
  37. package/dist/agent-runner/agent-run-state.d.ts.map +1 -1
  38. package/dist/agent-runner/agent-run-state.js +78 -40
  39. package/dist/agent-runner/agent-run-state.js.map +1 -1
  40. package/dist/agent-runner/durable-agent-runner.d.ts +18 -16
  41. package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
  42. package/dist/agent-runner/durable-agent-runner.js +120 -43
  43. package/dist/agent-runner/durable-agent-runner.js.map +1 -1
  44. package/dist/agent-runner/index.d.ts +1 -1
  45. package/dist/agent-runner/index.d.ts.map +1 -1
  46. package/dist/agent-runner/index.js +1 -1
  47. package/dist/agent-runner/index.js.map +1 -1
  48. package/dist/approval-api/actor-context.d.ts +67 -0
  49. package/dist/approval-api/actor-context.d.ts.map +1 -0
  50. package/dist/approval-api/actor-context.js +120 -0
  51. package/dist/approval-api/actor-context.js.map +1 -0
  52. package/dist/approval-api/contract.d.ts +13 -24
  53. package/dist/approval-api/contract.d.ts.map +1 -1
  54. package/dist/approval-api/contract.js +1 -1
  55. package/dist/approval-api/contract.js.map +1 -1
  56. package/dist/approval-api/d1-store.d.ts +7 -15
  57. package/dist/approval-api/d1-store.d.ts.map +1 -1
  58. package/dist/approval-api/d1-store.js +83 -159
  59. package/dist/approval-api/d1-store.js.map +1 -1
  60. package/dist/approval-api/grants.d.ts +3 -17
  61. package/dist/approval-api/grants.d.ts.map +1 -1
  62. package/dist/approval-api/grants.js +19 -39
  63. package/dist/approval-api/grants.js.map +1 -1
  64. package/dist/approval-api/index.d.ts +9 -9
  65. package/dist/approval-api/index.d.ts.map +1 -1
  66. package/dist/approval-api/index.js +6 -6
  67. package/dist/approval-api/index.js.map +1 -1
  68. package/dist/approval-api/principal.d.ts +29 -30
  69. package/dist/approval-api/principal.d.ts.map +1 -1
  70. package/dist/approval-api/principal.js +73 -54
  71. package/dist/approval-api/principal.js.map +1 -1
  72. package/dist/approval-api/resource-ownership.d.ts +64 -0
  73. package/dist/approval-api/resource-ownership.d.ts.map +1 -0
  74. package/dist/approval-api/resource-ownership.js +329 -0
  75. package/dist/approval-api/resource-ownership.js.map +1 -0
  76. package/dist/approval-api/retention.d.ts +6 -11
  77. package/dist/approval-api/retention.d.ts.map +1 -1
  78. package/dist/approval-api/retention.js +7 -12
  79. package/dist/approval-api/retention.js.map +1 -1
  80. package/dist/approval-api/router.d.ts +9 -8
  81. package/dist/approval-api/router.d.ts.map +1 -1
  82. package/dist/approval-api/router.js +50 -18
  83. package/dist/approval-api/router.js.map +1 -1
  84. package/dist/approval-api/service.d.ts +26 -36
  85. package/dist/approval-api/service.d.ts.map +1 -1
  86. package/dist/approval-api/service.js +104 -166
  87. package/dist/approval-api/service.js.map +1 -1
  88. package/dist/approval-api/store-factory.d.ts +19 -0
  89. package/dist/approval-api/store-factory.d.ts.map +1 -0
  90. package/dist/approval-api/store-factory.js +49 -0
  91. package/dist/approval-api/store-factory.js.map +1 -0
  92. package/dist/approval-api/store.d.ts +22 -36
  93. package/dist/approval-api/store.d.ts.map +1 -1
  94. package/dist/approval-api/store.js +48 -66
  95. package/dist/approval-api/store.js.map +1 -1
  96. package/dist/approval-api/types.d.ts +28 -22
  97. package/dist/approval-api/types.d.ts.map +1 -1
  98. package/dist/approval-api/types.js +51 -3
  99. package/dist/approval-api/types.js.map +1 -1
  100. package/dist/approval-ui/client.js +3 -3
  101. package/dist/approval-ui/client.js.map +1 -1
  102. package/dist/approval-ui/stream.d.ts +4 -4
  103. package/dist/approval-ui/stream.d.ts.map +1 -1
  104. package/dist/approval-ui/stream.js +2 -2
  105. package/dist/approval-ui/tips.d.ts +1 -1
  106. package/dist/approval-ui/tips.js +1 -1
  107. package/dist/approval-ui/tips.js.map +1 -1
  108. package/dist/approval-ui/use-approval-dashboard.d.ts +3 -3
  109. package/dist/approval-ui/use-approval-dashboard.js +1 -1
  110. package/dist/artifacts/index.d.ts +2 -3
  111. package/dist/artifacts/index.d.ts.map +1 -1
  112. package/dist/artifacts/index.js +9 -8
  113. package/dist/artifacts/index.js.map +1 -1
  114. package/dist/audit-export/audit-proxy.d.ts +71 -0
  115. package/dist/audit-export/audit-proxy.d.ts.map +1 -0
  116. package/dist/audit-export/audit-proxy.js +142 -0
  117. package/dist/audit-export/audit-proxy.js.map +1 -0
  118. package/dist/audit-export/index.d.ts +4 -7
  119. package/dist/audit-export/index.d.ts.map +1 -1
  120. package/dist/audit-export/index.js +1 -4
  121. package/dist/audit-export/index.js.map +1 -1
  122. package/dist/audit-export/queue-types.d.ts +5 -0
  123. package/dist/audit-export/queue-types.d.ts.map +1 -0
  124. package/dist/audit-export/queue-types.js +3 -0
  125. package/dist/audit-export/queue-types.js.map +1 -0
  126. package/dist/background-tasks/d1-storage.d.ts +9 -19
  127. package/dist/background-tasks/d1-storage.d.ts.map +1 -1
  128. package/dist/background-tasks/d1-storage.js +22 -52
  129. package/dist/background-tasks/d1-storage.js.map +1 -1
  130. package/dist/background-tasks/host.d.ts +4 -6
  131. package/dist/background-tasks/host.d.ts.map +1 -1
  132. package/dist/background-tasks/host.js +14 -17
  133. package/dist/background-tasks/host.js.map +1 -1
  134. package/dist/background-tasks/index.d.ts +1 -1
  135. package/dist/background-tasks/index.d.ts.map +1 -1
  136. package/dist/background-tasks/index.js +3 -3
  137. package/dist/background-tasks/index.js.map +1 -1
  138. package/dist/background-tasks/routes.d.ts +8 -4
  139. package/dist/background-tasks/routes.d.ts.map +1 -1
  140. package/dist/background-tasks/routes.js +33 -31
  141. package/dist/background-tasks/routes.js.map +1 -1
  142. package/dist/deployment-identity-protocol.d.ts +3 -0
  143. package/dist/deployment-identity-protocol.d.ts.map +1 -0
  144. package/dist/deployment-identity-protocol.js +3 -0
  145. package/dist/deployment-identity-protocol.js.map +1 -0
  146. package/dist/do-runner/breakwater-keys.d.ts +16 -5
  147. package/dist/do-runner/breakwater-keys.d.ts.map +1 -1
  148. package/dist/do-runner/breakwater-keys.js +16 -5
  149. package/dist/do-runner/breakwater-keys.js.map +1 -1
  150. package/dist/do-runner/cf-types.d.ts +18 -12
  151. package/dist/do-runner/cf-types.d.ts.map +1 -1
  152. package/dist/do-runner/cf-types.js.map +1 -1
  153. package/dist/do-runner/d1-storage.d.ts +44 -182
  154. package/dist/do-runner/d1-storage.d.ts.map +1 -1
  155. package/dist/do-runner/d1-storage.js +102 -353
  156. package/dist/do-runner/d1-storage.js.map +1 -1
  157. package/dist/do-runner/deployment-identity.d.ts +121 -0
  158. package/dist/do-runner/deployment-identity.d.ts.map +1 -0
  159. package/dist/do-runner/deployment-identity.js +272 -0
  160. package/dist/do-runner/deployment-identity.js.map +1 -0
  161. package/dist/do-runner/do-error-response.d.ts +1 -1
  162. package/dist/do-runner/do-error-response.d.ts.map +1 -1
  163. package/dist/do-runner/do-error-response.js +7 -1
  164. package/dist/do-runner/do-error-response.js.map +1 -1
  165. package/dist/do-runner/durable-object.d.ts +23 -16
  166. package/dist/do-runner/durable-object.d.ts.map +1 -1
  167. package/dist/do-runner/durable-object.js +303 -70
  168. package/dist/do-runner/durable-object.js.map +1 -1
  169. package/dist/do-runner/execution-context.d.ts +1 -0
  170. package/dist/do-runner/execution-context.d.ts.map +1 -1
  171. package/dist/do-runner/execution-context.js +6 -8
  172. package/dist/do-runner/execution-context.js.map +1 -1
  173. package/dist/do-runner/execution-principal-header.d.ts +16 -0
  174. package/dist/do-runner/execution-principal-header.d.ts.map +1 -0
  175. package/dist/do-runner/execution-principal-header.js +20 -0
  176. package/dist/do-runner/execution-principal-header.js.map +1 -0
  177. package/dist/do-runner/hub-do.d.ts +17 -25
  178. package/dist/do-runner/hub-do.d.ts.map +1 -1
  179. package/dist/do-runner/hub-do.js +63 -59
  180. package/dist/do-runner/hub-do.js.map +1 -1
  181. package/dist/do-runner/index.d.ts +12 -10
  182. package/dist/do-runner/index.d.ts.map +1 -1
  183. package/dist/do-runner/index.js +10 -9
  184. package/dist/do-runner/index.js.map +1 -1
  185. package/dist/do-runner/init.d.ts +0 -7
  186. package/dist/do-runner/init.d.ts.map +1 -1
  187. package/dist/do-runner/init.js +1 -2
  188. package/dist/do-runner/init.js.map +1 -1
  189. package/dist/do-runner/memory-id.d.ts +8 -25
  190. package/dist/do-runner/memory-id.d.ts.map +1 -1
  191. package/dist/do-runner/memory-id.js +25 -52
  192. package/dist/do-runner/memory-id.js.map +1 -1
  193. package/dist/do-runner/path-safe-id.d.ts +2 -48
  194. package/dist/do-runner/path-safe-id.d.ts.map +1 -1
  195. package/dist/do-runner/path-safe-id.js +3 -93
  196. package/dist/do-runner/path-safe-id.js.map +1 -1
  197. package/dist/do-runner/pubsub.d.ts +1 -1
  198. package/dist/do-runner/pubsub.js +1 -1
  199. package/dist/do-runner/runtime.d.ts +47 -34
  200. package/dist/do-runner/runtime.d.ts.map +1 -1
  201. package/dist/do-runner/runtime.js +281 -143
  202. package/dist/do-runner/runtime.js.map +1 -1
  203. package/dist/do-runner/schedule-source.d.ts +81 -0
  204. package/dist/do-runner/schedule-source.d.ts.map +1 -0
  205. package/dist/do-runner/schedule-source.js +64 -0
  206. package/dist/do-runner/schedule-source.js.map +1 -0
  207. package/dist/do-runner/thread-do.d.ts +18 -32
  208. package/dist/do-runner/thread-do.d.ts.map +1 -1
  209. package/dist/do-runner/thread-do.js +52 -74
  210. package/dist/do-runner/thread-do.js.map +1 -1
  211. package/dist/goals/objective-routes.d.ts +7 -4
  212. package/dist/goals/objective-routes.d.ts.map +1 -1
  213. package/dist/goals/objective-routes.js +58 -43
  214. package/dist/goals/objective-routes.js.map +1 -1
  215. package/dist/host-kit/approval-bridge.d.ts +18 -21
  216. package/dist/host-kit/approval-bridge.d.ts.map +1 -1
  217. package/dist/host-kit/approval-bridge.js +37 -37
  218. package/dist/host-kit/approval-bridge.js.map +1 -1
  219. package/dist/host-kit/bearer-auth.d.ts +3 -4
  220. package/dist/host-kit/bearer-auth.d.ts.map +1 -1
  221. package/dist/host-kit/bearer-auth.js +7 -11
  222. package/dist/host-kit/bearer-auth.js.map +1 -1
  223. package/dist/host-kit/do-run-topology.d.ts +14 -5
  224. package/dist/host-kit/do-run-topology.d.ts.map +1 -1
  225. package/dist/host-kit/do-run-topology.js +47 -15
  226. package/dist/host-kit/do-run-topology.js.map +1 -1
  227. package/dist/host-kit/env-vars.d.ts +1 -1
  228. package/dist/host-kit/env-vars.js +1 -1
  229. package/dist/host-kit/flowsafe-worker.d.ts +149 -73
  230. package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
  231. package/dist/host-kit/flowsafe-worker.js +619 -141
  232. package/dist/host-kit/flowsafe-worker.js.map +1 -1
  233. package/dist/host-kit/host-approval-service.d.ts +62 -54
  234. package/dist/host-kit/host-approval-service.d.ts.map +1 -1
  235. package/dist/host-kit/host-approval-service.js +90 -61
  236. package/dist/host-kit/host-approval-service.js.map +1 -1
  237. package/dist/host-kit/hub-topology.d.ts +6 -7
  238. package/dist/host-kit/hub-topology.d.ts.map +1 -1
  239. package/dist/host-kit/hub-topology.js +16 -12
  240. package/dist/host-kit/hub-topology.js.map +1 -1
  241. package/dist/host-kit/index.d.ts +13 -11
  242. package/dist/host-kit/index.d.ts.map +1 -1
  243. package/dist/host-kit/index.js +9 -12
  244. package/dist/host-kit/index.js.map +1 -1
  245. package/dist/host-kit/maintenance-capability.d.ts +58 -0
  246. package/dist/host-kit/maintenance-capability.d.ts.map +1 -0
  247. package/dist/host-kit/maintenance-capability.js +268 -0
  248. package/dist/host-kit/maintenance-capability.js.map +1 -0
  249. package/dist/host-kit/memory-boundary.d.ts +4 -19
  250. package/dist/host-kit/memory-boundary.d.ts.map +1 -1
  251. package/dist/host-kit/memory-boundary.js +12 -27
  252. package/dist/host-kit/memory-boundary.js.map +1 -1
  253. package/dist/host-kit/resource-access.d.ts +4 -0
  254. package/dist/host-kit/resource-access.d.ts.map +1 -0
  255. package/dist/host-kit/resource-access.js +12 -0
  256. package/dist/host-kit/resource-access.js.map +1 -0
  257. package/dist/host-kit/run-router.d.ts +25 -15
  258. package/dist/host-kit/run-router.d.ts.map +1 -1
  259. package/dist/host-kit/run-router.js +61 -46
  260. package/dist/host-kit/run-router.js.map +1 -1
  261. package/dist/host-kit/state-egress.d.ts +51 -0
  262. package/dist/host-kit/state-egress.d.ts.map +1 -0
  263. package/dist/host-kit/state-egress.js +120 -0
  264. package/dist/host-kit/state-egress.js.map +1 -0
  265. package/dist/host-kit/stream-router.d.ts +9 -4
  266. package/dist/host-kit/stream-router.d.ts.map +1 -1
  267. package/dist/host-kit/stream-router.js +45 -38
  268. package/dist/host-kit/stream-router.js.map +1 -1
  269. package/dist/host-kit/stream-ticket.d.ts +10 -10
  270. package/dist/host-kit/stream-ticket.d.ts.map +1 -1
  271. package/dist/host-kit/stream-ticket.js +60 -90
  272. package/dist/host-kit/stream-ticket.js.map +1 -1
  273. package/dist/host-kit/thread-topology.d.ts +17 -11
  274. package/dist/host-kit/thread-topology.d.ts.map +1 -1
  275. package/dist/host-kit/thread-topology.js +33 -59
  276. package/dist/host-kit/thread-topology.js.map +1 -1
  277. package/dist/host-kit/verifier.d.ts +6 -6
  278. package/dist/host-kit/verifier.d.ts.map +1 -1
  279. package/dist/host-kit/verifier.js +51 -119
  280. package/dist/host-kit/verifier.js.map +1 -1
  281. package/dist/http-body.d.ts +20 -0
  282. package/dist/http-body.d.ts.map +1 -0
  283. package/dist/http-body.js +67 -0
  284. package/dist/http-body.js.map +1 -0
  285. package/dist/schedules/index.d.ts +3 -2
  286. package/dist/schedules/index.d.ts.map +1 -1
  287. package/dist/schedules/index.js +5 -4
  288. package/dist/schedules/index.js.map +1 -1
  289. package/dist/schedules/router.d.ts +16 -10
  290. package/dist/schedules/router.d.ts.map +1 -1
  291. package/dist/schedules/router.js +153 -91
  292. package/dist/schedules/router.js.map +1 -1
  293. package/dist/schedules/schedules-d1.d.ts +88 -0
  294. package/dist/schedules/schedules-d1.d.ts.map +1 -1
  295. package/dist/schedules/schedules-d1.js +411 -50
  296. package/dist/schedules/schedules-d1.js.map +1 -1
  297. package/dist/schedules/target-policy.d.ts +29 -0
  298. package/dist/schedules/target-policy.d.ts.map +1 -0
  299. package/dist/schedules/target-policy.js +70 -0
  300. package/dist/schedules/target-policy.js.map +1 -0
  301. package/dist/schedules/tick.d.ts +125 -21
  302. package/dist/schedules/tick.d.ts.map +1 -1
  303. package/dist/schedules/tick.js +637 -160
  304. package/dist/schedules/tick.js.map +1 -1
  305. package/dist/signal-providers/delivery.d.ts +0 -19
  306. package/dist/signal-providers/delivery.d.ts.map +1 -1
  307. package/dist/signal-providers/delivery.js +5 -54
  308. package/dist/signal-providers/delivery.js.map +1 -1
  309. package/dist/signal-providers/github-provider.d.ts.map +1 -1
  310. package/dist/signal-providers/github-provider.js +9 -16
  311. package/dist/signal-providers/github-provider.js.map +1 -1
  312. package/dist/signal-providers/host-do.d.ts +3 -45
  313. package/dist/signal-providers/host-do.d.ts.map +1 -1
  314. package/dist/signal-providers/host-do.js +86 -106
  315. package/dist/signal-providers/host-do.js.map +1 -1
  316. package/dist/signal-providers/host-topology.d.ts +5 -14
  317. package/dist/signal-providers/host-topology.d.ts.map +1 -1
  318. package/dist/signal-providers/host-topology.js +11 -25
  319. package/dist/signal-providers/host-topology.js.map +1 -1
  320. package/dist/signal-providers/index.d.ts +3 -3
  321. package/dist/signal-providers/index.d.ts.map +1 -1
  322. package/dist/signal-providers/index.js +3 -3
  323. package/dist/signal-providers/index.js.map +1 -1
  324. package/dist/signal-providers/provider.d.ts +4 -5
  325. package/dist/signal-providers/provider.d.ts.map +1 -1
  326. package/dist/signal-providers/provider.js +5 -6
  327. package/dist/signal-providers/provider.js.map +1 -1
  328. package/dist/signal-providers/subscription-d1.d.ts +10 -57
  329. package/dist/signal-providers/subscription-d1.d.ts.map +1 -1
  330. package/dist/signal-providers/subscription-d1.js +208 -155
  331. package/dist/signal-providers/subscription-d1.js.map +1 -1
  332. package/dist/signal-providers/webhook-route.d.ts +28 -14
  333. package/dist/signal-providers/webhook-route.d.ts.map +1 -1
  334. package/dist/signal-providers/webhook-route.js +117 -88
  335. package/dist/signal-providers/webhook-route.js.map +1 -1
  336. package/dist/signals/client.js +8 -8
  337. package/dist/signals/client.js.map +1 -1
  338. package/dist/signals/d1-shared.js +1 -1
  339. package/dist/signals/d1-shared.js.map +1 -1
  340. package/dist/signals/index.d.ts +1 -1
  341. package/dist/signals/index.d.ts.map +1 -1
  342. package/dist/signals/index.js.map +1 -1
  343. package/dist/signals/notification-dispatch.d.ts +12 -6
  344. package/dist/signals/notification-dispatch.d.ts.map +1 -1
  345. package/dist/signals/notification-dispatch.js +37 -21
  346. package/dist/signals/notification-dispatch.js.map +1 -1
  347. package/dist/signals/notifications-d1.d.ts +5 -8
  348. package/dist/signals/notifications-d1.d.ts.map +1 -1
  349. package/dist/signals/notifications-d1.js +8 -13
  350. package/dist/signals/notifications-d1.js.map +1 -1
  351. package/dist/signals/router.d.ts +10 -10
  352. package/dist/signals/router.d.ts.map +1 -1
  353. package/dist/signals/router.js +49 -51
  354. package/dist/signals/router.js.map +1 -1
  355. package/dist/signals/thread-do-routes.d.ts +74 -15
  356. package/dist/signals/thread-do-routes.d.ts.map +1 -1
  357. package/dist/signals/thread-do-routes.js +484 -41
  358. package/dist/signals/thread-do-routes.js.map +1 -1
  359. package/dist/signals/thread-state-d1.d.ts.map +1 -1
  360. package/dist/signals/thread-state-d1.js +2 -3
  361. package/dist/signals/thread-state-d1.js.map +1 -1
  362. package/package.json +30 -7
  363. package/scripts/seed-deployment-identity.mjs +252 -0
  364. package/dist/approval-api/tenant-brand.d.ts +0 -35
  365. package/dist/approval-api/tenant-brand.d.ts.map +0 -1
  366. package/dist/approval-api/tenant-brand.js +0 -19
  367. package/dist/approval-api/tenant-brand.js.map +0 -1
  368. package/dist/approval-api/tenant-context.d.ts +0 -84
  369. package/dist/approval-api/tenant-context.d.ts.map +0 -1
  370. package/dist/approval-api/tenant-context.js +0 -112
  371. package/dist/approval-api/tenant-context.js.map +0 -1
  372. package/dist/approval-api/tenant-store.d.ts +0 -36
  373. package/dist/approval-api/tenant-store.d.ts.map +0 -1
  374. package/dist/approval-api/tenant-store.js +0 -129
  375. package/dist/approval-api/tenant-store.js.map +0 -1
  376. package/dist/do-runner/resume-ledger.d.ts +0 -48
  377. package/dist/do-runner/resume-ledger.d.ts.map +0 -1
  378. package/dist/do-runner/resume-ledger.js +0 -60
  379. package/dist/do-runner/resume-ledger.js.map +0 -1
  380. package/dist/do-runner/thread-header.d.ts +0 -31
  381. package/dist/do-runner/thread-header.d.ts.map +0 -1
  382. package/dist/do-runner/thread-header.js +0 -39
  383. package/dist/do-runner/thread-header.js.map +0 -1
  384. package/dist/host-kit/subdomain-check.d.ts +0 -23
  385. package/dist/host-kit/subdomain-check.d.ts.map +0 -1
  386. package/dist/host-kit/subdomain-check.js +0 -61
  387. package/dist/host-kit/subdomain-check.js.map +0 -1
  388. package/dist/host-kit/tenant-registry.d.ts +0 -51
  389. package/dist/host-kit/tenant-registry.d.ts.map +0 -1
  390. package/dist/host-kit/tenant-registry.js +0 -88
  391. package/dist/host-kit/tenant-registry.js.map +0 -1
@@ -7,11 +7,11 @@
7
7
  // of approval grants. decide() persists the decision; the grant provider
8
8
  // (grants.ts) derives requestContext grants from approved records at
9
9
  // start/resume. Nothing here ever reads capability data from client input.
10
- import { PATH_SAFE_ID_PATTERN, tenantOwnsSaltedId, } from '../do-runner/path-safe-id.js';
10
+ import { isPathSafeId } from '../do-runner/path-safe-id.js';
11
11
  import { APPROVAL_ROLES, DECIDER_ROLES } from './contract.js';
12
- import { canonicalAutomatedPrincipal, isExecutionPrincipal, isTrustedAutomationPrincipal, principalActor, principalAuditFields, } from './principal.js';
13
- import { listAllApprovedForRun } from './store.js';
14
- import { APPROVAL_PRIORITIES, approvalCursor, MAX_APPROVAL_BATCH_DECIDE, MAX_APPROVAL_LIST_LIMIT, OPEN_STATUSES, } from './types.js';
12
+ import { canonicalApprovalActor, canonicalAutomatedPrincipal, EXECUTION_PRINCIPAL_KINDS, isExecutionPrincipalId, isExecutionPrincipalKind, isTrustedAutomationPrincipal, principalActor, principalAuditFields, } from './principal.js';
13
+ import { listAllApprovedForRun, } from './store.js';
14
+ import { APPROVAL_PRIORITIES, approvalCursor, canonicalApprovalResumeTarget, MAX_APPROVAL_BATCH_DECIDE, MAX_APPROVAL_LIST_LIMIT, OPEN_STATUSES, } from './types.js';
15
15
  /** Requester failed role authorization — HTTP 403. */
16
16
  export class ApprovalAuthzError extends Error {
17
17
  constructor(message) {
@@ -56,7 +56,7 @@ export function selfDecisionExempts(policy, role) {
56
56
  }
57
57
  // Role policy from security-threat-model.md: reviewers decide, operators run
58
58
  // the system, admins do both; every authenticated role may read. (The SLA
59
- // sweep has no role: it is cron-owned TCB code — see sweepSLA below.)
59
+ // sweep has no role: it is maintenance-owned TCB code; see sweepSLA below.)
60
60
  // CAN_REVIEW IS the exported DECIDER_ROLES — one source, so the run-router's
61
61
  // canSelfDecide echo and this gate can never disagree on who may decide.
62
62
  const CAN_REVIEW = DECIDER_ROLES;
@@ -73,14 +73,6 @@ export class ApprovalService {
73
73
  #resumeRun;
74
74
  #allowSelfDecision;
75
75
  #now;
76
- /**
77
- * The tenant this service is bound to. Exposed so the host-kit bridges can
78
- * mint their own bookkeeping principal against it instead of making every
79
- * host construct one and vouch for it.
80
- */
81
- get tenantId() {
82
- return this.#store.tenantId;
83
- }
84
76
  constructor(options) {
85
77
  this.#store = options.store;
86
78
  this.#audit = options.audit;
@@ -92,8 +84,12 @@ export class ApprovalService {
92
84
  this.#now = options.now ?? (() => new Date());
93
85
  }
94
86
  async create(input, actor, resumeTarget) {
95
- this.#authorize(actor, CAN_CREATE, 'approval.create', 'approval');
96
- return this.#createAuthorized(input, actor, resumeTarget);
87
+ const authorized = this.#authorize(actor, CAN_CREATE, 'approval.create', 'approval');
88
+ if (input.requestedByKind !== undefined &&
89
+ input.requestedByKind !== 'human') {
90
+ throw new InvalidApprovalInputError("human approval creation may only use requestedByKind 'human'");
91
+ }
92
+ return this.#createAuthorized(input, authorized, 'human', resumeTarget);
97
93
  }
98
94
  /**
99
95
  * File an approval on behalf of an AUTOMATED principal — the trusted entry
@@ -104,7 +100,7 @@ export class ApprovalService {
104
100
  * They cannot simply project onto a role instead: automated principals
105
101
  * project to the least-privileged role precisely so they can never decide,
106
102
  * and `viewer` is not in CAN_CREATE. So the role gate is replaced here — not
107
- * widened — by a kind-and-tenant check.
103
+ * widened — by a trusted-kind check.
108
104
  *
109
105
  * There is deliberately NO principal-taking claim/decide/delegate. Filing a
110
106
  * request is trusted platform work; deciding one is a human judgement, and an
@@ -113,9 +109,9 @@ export class ApprovalService {
113
109
  */
114
110
  async createAsPrincipal(input, principal, resumeTarget) {
115
111
  this.#authorizeAutomated(principal, 'approval.create', 'approval');
116
- return this.#createAuthorized(input, principalActor(principal), resumeTarget, principalAuditFields(principal));
112
+ return this.#createAuthorized(input, principalActor(principal), principal.kind, resumeTarget, principalAuditFields(principal));
117
113
  }
118
- async #createAuthorized(input, actor, resumeTarget, provenance) {
114
+ async #createAuthorized(input, actor, defaultRequestedByKind, resumeTarget, provenance) {
119
115
  this.#validateCreate(input);
120
116
  const now = this.#now();
121
117
  const slaSeconds = input.slaSeconds ?? this.#defaultSlaSeconds;
@@ -135,9 +131,6 @@ export class ApprovalService {
135
131
  }
136
132
  const record = {
137
133
  id: crypto.randomUUID(),
138
- // The bound store re-stamps this from its own field either way; setting
139
- // it here keeps the literal honest for the type and the audit trail.
140
- tenantId: this.#store.tenantId,
141
134
  workflowId: input.workflowId,
142
135
  runId: input.runId,
143
136
  title: input.title,
@@ -169,20 +162,18 @@ export class ApprovalService {
169
162
  if (input.payload !== undefined)
170
163
  record.payload = input.payload;
171
164
  if (resumeTarget !== undefined) {
172
- this.#validateResumeTarget(resumeTarget);
173
- record.resumeTarget = structuredClone(resumeTarget);
165
+ record.resumeTarget = this.#canonicalResumeTarget(resumeTarget);
174
166
  }
175
- // Attribution powers the self-approval check: default to the creating
176
- // actor. An explicit override stays possible for system bridges — the
177
- // caller already holds a CAN_CREATE role either way.
167
+ // Attribution powers the self-approval check. Trusted bridges may file on
168
+ // behalf of the run requester; direct human creation defaults to its actor.
178
169
  record.requestedBy = input.requestedBy ?? actor.id;
170
+ record.requestedByKind = input.requestedByKind ?? defaultRequestedByKind;
179
171
  if (slaSeconds !== undefined) {
180
172
  record.slaDeadlineAt = new Date(now.getTime() + slaSeconds * 1000).toISOString();
181
173
  }
182
174
  const result = await this.#store.create(record);
183
175
  this.#record(actor, 'approval.create', `approval:${result.record.id}`, 'allowed', {
184
176
  detail: {
185
- tenantId: result.record.tenantId,
186
177
  workflowId: result.record.workflowId,
187
178
  runId: result.record.runId,
188
179
  grantScope: result.record.grantScope,
@@ -200,11 +191,11 @@ export class ApprovalService {
200
191
  // incident unreconstructable: the failures are the rows an operator reads.
201
192
  fireNotification(this.#notify, { type: 'created', record: result.record }, (reason) => this.#record(actor, 'approval.notify', `approval:${result.record.id}`, 'error', {
202
193
  reason,
203
- detail: { tenantId: result.record.tenantId, ...provenance },
194
+ detail: { ...provenance },
204
195
  }));
205
196
  fireStreamEvent(this.#stream, { type: 'created', record: result.record }, (reason) => this.#record(actor, 'approval.stream', `approval:${result.record.id}`, 'error', {
206
197
  reason,
207
- detail: { tenantId: result.record.tenantId, ...provenance },
198
+ detail: { ...provenance },
208
199
  }));
209
200
  }
210
201
  return result;
@@ -221,43 +212,42 @@ export class ApprovalService {
221
212
  return this.#store.list(filter);
222
213
  }
223
214
  async claim(id, actor) {
224
- this.#authorize(actor, CAN_REVIEW, 'approval.claim', `approval:${id}`);
215
+ const authorized = this.#authorize(actor, CAN_REVIEW, 'approval.claim', `approval:${id}`);
225
216
  const now = this.#now().toISOString();
226
217
  // 'claimed' is deliberately not claimable — reassignment is delegate()'s
227
218
  // job, so a claim can never silently steal another reviewer's item.
228
- const updated = await this.#transitionOrExplain(id, 'claim', actor, {
219
+ const updated = await this.#transitionOrExplain(id, 'claim', authorized, {
229
220
  from: ['pending', 'escalated'],
230
221
  patch: {
231
222
  status: 'claimed',
232
- claimedBy: actor.id,
223
+ claimedBy: authorized.id,
233
224
  claimedAt: now,
234
225
  updatedAt: now,
235
226
  },
236
227
  });
237
- this.#record(actor, 'approval.claim', `approval:${id}`, 'allowed');
238
- fireStreamEvent(this.#stream, { type: 'claimed', record: updated }, (reason) => this.#record(actor, 'approval.stream', `approval:${id}`, 'error', {
228
+ this.#record(authorized, 'approval.claim', `approval:${id}`, 'allowed');
229
+ fireStreamEvent(this.#stream, { type: 'claimed', record: updated }, (reason) => this.#record(authorized, 'approval.stream', `approval:${id}`, 'error', {
239
230
  reason,
240
- detail: { tenantId: updated.tenantId },
241
231
  }));
242
232
  return updated;
243
233
  }
244
234
  async decide(id, input, actor) {
245
- this.#authorize(actor, CAN_REVIEW, 'approval.decide', `approval:${id}`);
235
+ const authorized = this.#authorize(actor, CAN_REVIEW, 'approval.decide', `approval:${id}`);
246
236
  this.#assertDecisionInput(input);
247
237
  // Role-scoped SoD: an exempt decider (allowSelfDecision: true, or a role
248
238
  // named in { roles }) skips the pre-read entirely; everyone else keeps
249
239
  // today's read-then-CAS self-request denial.
250
- if (!selfDecisionExempts(this.#allowSelfDecision, actor.role)) {
240
+ if (!selfDecisionExempts(this.#allowSelfDecision, authorized.role)) {
251
241
  const existing = await this.#store.get(id);
252
242
  if (!existing)
253
243
  throw new UnknownApprovalError(id);
254
- // requestedBy is immutable after create, so read-then-CAS carries no
255
- // TOCTOU hazard here. An ABSENT requestedBy passes this check by
256
- // design: create() always attributes it, so only records injected
257
- // straight into the store (TCB code) can lack it — a bulk-import path
258
- // added later must attribute requesters or accept self-decidability.
259
- if (existing.requestedBy === actor.id) {
260
- this.#record(actor, 'approval.decide', `approval:${id}`, 'denied', {
244
+ // requestedBy and requestedByKind are immutable after create, so this
245
+ // read-then-CAS has no TOCTOU hazard. Missing kind denotes a legacy row
246
+ // and is treated as human: ambiguity must preserve the SoD bar, not let
247
+ // an old row become self-decidable after this field is introduced.
248
+ if (existing.requestedBy === authorized.id &&
249
+ (existing.requestedByKind ?? 'human') === 'human') {
250
+ this.#record(authorized, 'approval.decide', `approval:${id}`, 'denied', {
261
251
  reason: 'self-approval: decider is the requester',
262
252
  });
263
253
  throw new ApprovalAuthzError('the requester cannot decide their own approval (separation of duties; set allowSelfDecision to permit)');
@@ -265,7 +255,7 @@ export class ApprovalService {
265
255
  // Cross-gate causal SoD: a reviewer who APPROVED an earlier gate of THIS
266
256
  // run advanced it to the gate now before them, so they must not also
267
257
  // decide this one. requestedBy attribution cannot carry this on its own —
268
- // reconcileApprovalsForSummary files the next gate as the SYSTEM actor,
258
+ // reconcileApprovalsForSummary files the next gate as the SYSTEM principal,
269
259
  // which the requestedBy check above never blocks — so the bar is derived
270
260
  // from the run's own APPROVED history instead.
271
261
  //
@@ -299,7 +289,7 @@ export class ApprovalService {
299
289
  const barred = priorApproved.some((prior) => {
300
290
  if (prior.id === existing.id)
301
291
  return false;
302
- if (prior.decidedBy !== actor.id)
292
+ if (prior.decidedBy !== authorized.id)
303
293
  return false;
304
294
  if (typeof prior.decidedAt !== 'string')
305
295
  return false;
@@ -307,7 +297,7 @@ export class ApprovalService {
307
297
  return (Number.isNaN(priorAt) || Number.isNaN(gateAt) || priorAt <= gateAt);
308
298
  });
309
299
  if (barred) {
310
- this.#record(actor, 'approval.decide', `approval:${id}`, 'denied', {
300
+ this.#record(authorized, 'approval.decide', `approval:${id}`, 'denied', {
311
301
  reason: 'cross-gate separation of duties: this actor approved an earlier gate of the run',
312
302
  });
313
303
  throw new ApprovalAuthzError('the reviewer who advanced this run at an earlier gate cannot also decide this gate (separation of duties; set allowSelfDecision to permit)');
@@ -316,29 +306,29 @@ export class ApprovalService {
316
306
  const now = this.#now().toISOString();
317
307
  const patch = {
318
308
  status: input.decision === 'approve' ? 'approved' : 'rejected',
319
- decidedBy: actor.id,
309
+ decidedBy: authorized.id,
320
310
  decision: input.decision,
321
311
  decidedAt: now,
322
312
  updatedAt: now,
323
313
  };
324
314
  if (input.comment !== undefined)
325
315
  patch.comment = input.comment;
326
- const updated = await this.#transitionOrExplain(id, 'decide', actor, {
316
+ const updated = await this.#transitionOrExplain(id, 'decide', authorized, {
327
317
  from: OPEN_STATUSES,
328
318
  patch,
329
319
  });
330
320
  // Annotate a PERMITTED self-decision from the post-transition record (no
331
321
  // extra read): an exercised SoD exemption must leave an audit trail. Fires
332
322
  // for both a global `true` and a role-scoped exemption.
333
- const selfDecision = updated.requestedBy === actor.id;
334
- this.#record(actor, 'approval.decide', `approval:${id}`, 'allowed', {
323
+ const selfDecision = updated.requestedBy === authorized.id &&
324
+ (updated.requestedByKind ?? 'human') === 'human';
325
+ this.#record(authorized, 'approval.decide', `approval:${id}`, 'allowed', {
335
326
  detail: {
336
327
  decision: input.decision,
337
328
  // Queue dwell time (created -> decided), in seconds. Feeds the
338
329
  // generic durationSeconds histogram convention breakwater's
339
330
  // metricsAuditSink observes — any emitter may adopt the field.
340
331
  durationSeconds: (Date.parse(now) - Date.parse(updated.createdAt)) / 1000,
341
- tenantId: updated.tenantId,
342
332
  workflowId: updated.workflowId,
343
333
  runId: updated.runId,
344
334
  grantScope: updated.grantScope,
@@ -361,11 +351,13 @@ export class ApprovalService {
361
351
  // Fire the live-stream event AFTER the transition + audit and BEFORE
362
352
  // #resume: the queue fan-out reflects the durable decision immediately,
363
353
  // independent of whether the subsequent run resume succeeds.
364
- fireStreamEvent(this.#stream, { type: 'decided', record: updated }, (reason) => this.#record(actor, 'approval.stream', `approval:${id}`, 'error', {
354
+ fireStreamEvent(this.#stream, { type: 'decided', record: updated }, (reason) => this.#record(authorized, 'approval.stream', `approval:${id}`, 'error', {
365
355
  reason,
366
- detail: { tenantId: updated.tenantId },
367
356
  }));
368
- return { record: updated, resume: await this.#resume(updated, actor) };
357
+ return {
358
+ record: updated,
359
+ resume: await this.#resume(updated, authorized),
360
+ };
369
361
  }
370
362
  /**
371
363
  * Triage fan-out: apply ONE decision to up to MAX_APPROVAL_BATCH_DECIDE
@@ -381,7 +373,7 @@ export class ApprovalService {
381
373
  * a batch is a reviewer clicking once, not a throughput path.
382
374
  */
383
375
  async decideBatch(ids, input, actor) {
384
- this.#authorize(actor, CAN_REVIEW, 'approval.decide', 'approval');
376
+ const authorized = this.#authorize(actor, CAN_REVIEW, 'approval.decide', 'approval');
385
377
  if (!Array.isArray(ids) || ids.length === 0) {
386
378
  throw new InvalidApprovalInputError('ids must be a non-empty array of approval ids');
387
379
  }
@@ -400,7 +392,7 @@ export class ApprovalService {
400
392
  const results = [];
401
393
  for (const id of unique) {
402
394
  try {
403
- const { record, resume } = await this.decide(id, input, actor);
395
+ const { record, resume } = await this.decide(id, input, authorized);
404
396
  results.push({ id, ok: true, record, resume });
405
397
  }
406
398
  catch (error) {
@@ -416,7 +408,7 @@ export class ApprovalService {
416
408
  const failed = results.length - decided;
417
409
  // Summary only — each decide() above already left its own per-record
418
410
  // trail (allowed/denied), so this is the batch's one-line correlation.
419
- this.#record(actor, 'approval.decide.batch', 'approval', 'allowed', {
411
+ this.#record(authorized, 'approval.decide.batch', 'approval', 'allowed', {
420
412
  detail: { requested: unique.length, decided, failed },
421
413
  });
422
414
  return { results, decided, failed };
@@ -445,7 +437,7 @@ export class ApprovalService {
445
437
  * reconcileApprovalsForSummary, itself only invoked from createRunRouter's
446
438
  * optional reconcileApprovals hook on a status() read, never from a
447
439
  * request body. Authorized like create() (CAN_CREATE, not CAN_REVIEW):
448
- * the only actor that ever calls this is the same system actor create()
440
+ * the only principal that ever calls this is the same system principal create()
449
441
  * already accepts for reconcile-filed records — superseding is the
450
442
  * symmetric "un-file" half of that same self-healing operation, not a
451
443
  * reviewer decision.
@@ -457,8 +449,8 @@ export class ApprovalService {
457
449
  * contract sweepSLA uses for its own store-level CAS.
458
450
  */
459
451
  async supersedeStale(id, actor, reason) {
460
- this.#authorize(actor, CAN_CREATE, 'approval.supersede', `approval:${id}`);
461
- return this.#supersedeAuthorized(id, actor, reason);
452
+ const authorized = this.#authorize(actor, CAN_CREATE, 'approval.supersede', `approval:${id}`);
453
+ return this.#supersedeAuthorized(id, authorized, reason);
462
454
  }
463
455
  /**
464
456
  * Supersede on behalf of an AUTOMATED principal — the reconcile bridge's
@@ -488,7 +480,6 @@ export class ApprovalService {
488
480
  this.#record(actor, 'approval.supersede', `approval:${id}`, 'allowed', {
489
481
  reason,
490
482
  detail: {
491
- tenantId: updated.tenantId,
492
483
  workflowId: updated.workflowId,
493
484
  runId: updated.runId,
494
485
  ...provenance,
@@ -498,12 +489,12 @@ export class ApprovalService {
498
489
  // is renamed so it does not shadow it.
499
490
  fireStreamEvent(this.#stream, { type: 'superseded', record: updated }, (streamError) => this.#record(actor, 'approval.stream', `approval:${id}`, 'error', {
500
491
  reason: streamError,
501
- detail: { tenantId: updated.tenantId, ...provenance },
492
+ detail: { ...provenance },
502
493
  }));
503
494
  return updated;
504
495
  }
505
496
  async delegate(id, input, actor) {
506
- this.#authorize(actor, CAN_REVIEW, 'approval.delegate', `approval:${id}`);
497
+ const authorized = this.#authorize(actor, CAN_REVIEW, 'approval.delegate', `approval:${id}`);
507
498
  if (!isNonEmptyString(input.to)) {
508
499
  throw new InvalidApprovalInputError("delegate requires a non-empty 'to' reviewer id");
509
500
  }
@@ -513,7 +504,7 @@ export class ApprovalService {
513
504
  // assignee is the last write. Delegation is reassignment — unlike decide
514
505
  // (mutual exclusion) or claim (no-steal), there is no side effect to
515
506
  // protect, only a pointer to move.
516
- const updated = await this.#transitionOrExplain(id, 'delegate', actor, {
507
+ const updated = await this.#transitionOrExplain(id, 'delegate', authorized, {
517
508
  from: OPEN_STATUSES,
518
509
  patch: {
519
510
  status: 'claimed',
@@ -523,12 +514,11 @@ export class ApprovalService {
523
514
  updatedAt: now,
524
515
  },
525
516
  });
526
- this.#record(actor, 'approval.delegate', `approval:${id}`, 'allowed', {
517
+ this.#record(authorized, 'approval.delegate', `approval:${id}`, 'allowed', {
527
518
  detail: { to: input.to },
528
519
  });
529
- fireStreamEvent(this.#stream, { type: 'delegated', record: updated }, (reason) => this.#record(actor, 'approval.stream', `approval:${id}`, 'error', {
520
+ fireStreamEvent(this.#stream, { type: 'delegated', record: updated }, (reason) => this.#record(authorized, 'approval.stream', `approval:${id}`, 'error', {
530
521
  reason,
531
- detail: { tenantId: updated.tenantId },
532
522
  }));
533
523
  return updated;
534
524
  }
@@ -557,7 +547,15 @@ export class ApprovalService {
557
547
  throw new ApprovalConflictError(id, action, current.status);
558
548
  }
559
549
  async #resume(record, actor) {
560
- if (!this.#resumeRun)
550
+ // A plain queue record is a decision log, not proof that a suspended run
551
+ // exists. Only trusted in-process creation can author one of these three
552
+ // resumability anchors; the optional HTTP create route rejects all three.
553
+ // Without an anchor, calling resumeRun would turn an attacker-selected
554
+ // runId on an inert record into a target invocation after review.
555
+ const resumable = record.stepPath !== undefined ||
556
+ record.runScoped === true ||
557
+ record.resumeTarget !== undefined;
558
+ if (!this.#resumeRun || !resumable)
561
559
  return { attempted: false };
562
560
  // record.decision is set by decide()'s patch before this runs.
563
561
  const decision = record.decision;
@@ -565,7 +563,6 @@ export class ApprovalService {
565
563
  const summary = await this.#resumeRun(record, decision);
566
564
  this.#record(actor, 'approval.resume', `approval:${record.id}`, 'allowed', {
567
565
  detail: {
568
- tenantId: record.tenantId,
569
566
  workflowId: record.workflowId,
570
567
  runId: record.runId,
571
568
  },
@@ -579,7 +576,6 @@ export class ApprovalService {
579
576
  this.#record(actor, 'approval.resume', `approval:${record.id}`, 'error', {
580
577
  reason: message,
581
578
  detail: {
582
- tenantId: record.tenantId,
583
579
  workflowId: record.workflowId,
584
580
  runId: record.runId,
585
581
  },
@@ -588,34 +584,19 @@ export class ApprovalService {
588
584
  }
589
585
  }
590
586
  #authorize(actor, roles, action, resource) {
591
- if (isNonEmptyString(actor?.id) &&
592
- APPROVAL_ROLES.includes(actor.role) &&
593
- roles.includes(actor.role) &&
594
- // INV-2 belt at the service layer: the acting principal's tenant must
595
- // BE the store's binding. The resolver constructs the service from the
596
- // actor's own tenant so this can only fire on a wiring bug — which is
597
- // exactly when it must fail closed rather than act cross-tenant.
598
- isNonEmptyString(actor.tenantId) &&
599
- actor.tenantId === this.#store.tenantId) {
600
- return;
587
+ const canonical = canonicalApprovalActor(actor);
588
+ if (canonical && roles.includes(canonical.role)) {
589
+ return canonical;
601
590
  }
602
- const roleOk = actor !== null &&
603
- actor !== undefined &&
604
- APPROVAL_ROLES.includes(actor.role) &&
605
- roles.includes(actor.role);
606
- this.#record(actor ?? null, action, resource, 'denied', {
607
- reason: !actor
591
+ this.#record(canonical ?? null, action, resource, 'denied', {
592
+ reason: !canonical
608
593
  ? 'no actor'
609
- : !roleOk
610
- ? `role '${actor.role}' is not in [${roles.join(', ')}]`
611
- : `actor tenant '${actor.tenantId}' does not match the store binding '${this.#store.tenantId}'`,
594
+ : `role '${canonical.role}' is not in [${roles.join(', ')}]`,
612
595
  });
613
- throw new ApprovalAuthzError(roleOk && actor
614
- ? `${action}: actor tenant does not match this service's tenant binding`
615
- : `${action} requires one of roles [${roles.join(', ')}]`);
596
+ throw new ApprovalAuthzError(`${action} requires one of roles [${roles.join(', ')}]`);
616
597
  }
617
598
  /**
618
- * Authorize an automated caller on kind, brand, and tenant.
599
+ * Authorize an automated caller on kind and brand.
619
600
  *
620
601
  * The parameter type is NOT the enforcement. `trustAutomationPrincipal` is
621
602
  * the only minter, but TypeScript is erased at runtime, so a cast or a value
@@ -623,10 +604,6 @@ export class ApprovalService {
623
604
  * caller left it. Re-reading the brand and the shape is what turns "only the
624
605
  * minter produces this" from a convention into a check — and it is what stops
625
606
  * a principal validated as `system` from being read back as a human `admin`.
626
- *
627
- * The tenant is checked for the same reason `#authorize` checks it: the
628
- * resolver builds the service from the principal's own tenant, so a mismatch
629
- * can only be a wiring bug — exactly when it must fail closed.
630
607
  */
631
608
  #authorizeAutomated(principal, action, resource) {
632
609
  if (!isTrustedAutomationPrincipal(principal)) {
@@ -638,15 +615,6 @@ export class ApprovalService {
638
615
  });
639
616
  throw new ApprovalAuthzError(`${action}: principal is not a vouched automated principal`);
640
617
  }
641
- if (principal.tenantId === this.#store.tenantId)
642
- return;
643
- this.#record(principalActor(principal), action, resource, 'denied', {
644
- reason: `principal tenant '${principal.tenantId}' does not match the store binding '${this.#store.tenantId}'`,
645
- // A denial is an automated event too: without these the only automated
646
- // audit rows carrying provenance would be the ones that succeeded.
647
- detail: principalAuditFields(principal),
648
- });
649
- throw new ApprovalAuthzError(`${action}: principal tenant does not match this service's tenant binding`);
650
618
  }
651
619
  // Callers pass the final resource string ('approval' for collection-level
652
620
  // actions, 'approval:<id>' for record-level) — no format inference here.
@@ -693,12 +661,12 @@ export class ApprovalService {
693
661
  if (!isNonEmptyString(input.runId)) {
694
662
  throw new InvalidApprovalInputError('runId is required');
695
663
  }
696
- // Cheap INV-1 belt: every read path filters on the tenant_id COLUMN (not
697
- // by parsing run_id), so a foreign-prefixed record would not leak — but it
698
- // would be an orphan row no tenant's queue ever shows. Turn it into a
699
- // loud error at the only write path.
700
- if (!tenantOwnsSaltedId(this.#store.tenantId, input.runId)) {
701
- throw new InvalidApprovalInputError(`runId '${input.runId}' does not carry this tenant's prefix '${this.#store.tenantId}_' — approvals bind to tenant-salted runs (INV-1)`);
664
+ // Cheap INV-1 belt at the only write path: an approval binds to a
665
+ // server-minted run, and every context a runId keys (D1 row, DO name,
666
+ // URL path) requires the path-safe charset. A record filed under a
667
+ // malformed runId would be an orphan no resume can ever reach.
668
+ if (!isPathSafeId(input.runId)) {
669
+ throw new InvalidApprovalInputError(`runId '${input.runId}' is not path-safe — approvals bind to server-minted runs (INV-1)`);
702
670
  }
703
671
  if (!isNonEmptyString(input.title)) {
704
672
  throw new InvalidApprovalInputError('title is required');
@@ -722,8 +690,16 @@ export class ApprovalService {
722
690
  // explicit one must be a usable identity — an empty string would silently
723
691
  // match no actor and, worse, read as "attributed" to any later reader.
724
692
  if (input.requestedBy !== undefined &&
725
- !isNonEmptyString(input.requestedBy)) {
726
- throw new InvalidApprovalInputError('requestedBy must be a non-empty string');
693
+ !isExecutionPrincipalId(input.requestedBy)) {
694
+ throw new InvalidApprovalInputError('requestedBy must be a valid execution principal id');
695
+ }
696
+ if (input.requestedByKind !== undefined &&
697
+ !isExecutionPrincipalKind(input.requestedByKind)) {
698
+ throw new InvalidApprovalInputError(`requestedByKind must be one of [${EXECUTION_PRINCIPAL_KINDS.join(', ')}]`);
699
+ }
700
+ if ((input.requestedBy === undefined) !==
701
+ (input.requestedByKind === undefined)) {
702
+ throw new InvalidApprovalInputError('requestedBy and requestedByKind must be provided together');
727
703
  }
728
704
  // runScoped is a capability switch (mints on every leg); only a real
729
705
  // boolean opts in, never a truthy string from a lax caller.
@@ -797,35 +773,12 @@ export class ApprovalService {
797
773
  }
798
774
  }
799
775
  }
800
- #validateResumeTarget(target) {
801
- if (target === null || typeof target !== 'object') {
802
- throw new InvalidApprovalInputError('resumeTarget must be a trusted thread or agent-thread target');
803
- }
804
- const ownsPathSafeId = (value) => typeof value === 'string' &&
805
- PATH_SAFE_ID_PATTERN.test(value) &&
806
- tenantOwnsSaltedId(this.#store.tenantId, value);
807
- if (target.kind === 'thread') {
808
- if (!ownsPathSafeId(target.threadId) ||
809
- (target.resourceId !== undefined && !ownsPathSafeId(target.resourceId))) {
810
- throw new InvalidApprovalInputError('resumeTarget must name path-safe thread/resource ids owned by the bound tenant');
811
- }
812
- return;
813
- }
814
- if (target.kind === 'agent-thread') {
815
- if (typeof target.agentId !== 'string' ||
816
- !PATH_SAFE_ID_PATTERN.test(target.agentId) ||
817
- !ownsPathSafeId(target.threadId) ||
818
- !ownsPathSafeId(target.resourceId) ||
819
- // Fails closed on the pre-principal `{id, role, tenantId}` form: an
820
- // ApprovalActor is not an ExecutionPrincipal, and coercing one would
821
- // resurrect a fabricated operator as a human.
822
- !isExecutionPrincipal(target.principal) ||
823
- target.principal.tenantId !== this.#store.tenantId) {
824
- throw new InvalidApprovalInputError('agent resumeTarget must name path-safe ids and a valid execution principal owned by the bound tenant');
825
- }
826
- return;
776
+ #canonicalResumeTarget(target) {
777
+ const canonical = canonicalApprovalResumeTarget(target);
778
+ if (!canonical) {
779
+ throw new InvalidApprovalInputError('resumeTarget must be a trusted thread or agent-thread target with path-safe ids and a valid execution principal');
827
780
  }
828
- throw new InvalidApprovalInputError('resumeTarget must be a trusted thread or agent-thread target');
781
+ return canonical;
829
782
  }
830
783
  }
831
784
  function errorMessage(error) {
@@ -873,7 +826,7 @@ function fireNotification(notify, event, reportError) {
873
826
  // the AUDIT sink (as `approval.stream`/'error') so the mutation that fired it
874
827
  // never fails. Deliberately not awaited: a host that must keep a hub publish
875
828
  // alive past the response wraps it in ctx.waitUntil itself (see
876
- // ApprovalStreamSink); the cron sweep collects it into pendingSends instead.
829
+ // ApprovalStreamSink); the maintenance sweep collects it into pendingSends instead.
877
830
  function fireStreamEvent(stream, event, reportError) {
878
831
  if (!stream)
879
832
  return;
@@ -888,22 +841,14 @@ function fireStreamEvent(stream, event, reportError) {
888
841
  }
889
842
  }
890
843
  /**
891
- * Escalate every open request past its SLA deadline, ACROSS TENANTS.
844
+ * Escalate every open request past its SLA deadline in this deployment.
892
845
  * Idempotent: already escalated records are not re-escalated (their status
893
- * left the guard set). Cron-owned TCB code — deliberately NOT a service
894
- * method and NOT reachable over HTTP: an unfiltered cross-tenant read+write
895
- * behind a role check was an IDOR-shaped hole (any CAN_SWEEP actor could
896
- * escalate every tenant's queue). The distinct SystemApprovalStore parameter
897
- * type makes "cross-tenant reads happen only inside the TCB" a compile-time
898
- * property, not a convention.
846
+ * left the guard set). Trusted-maintenance code — deliberately not a service
847
+ * method and not reachable over HTTP.
899
848
  */
900
849
  export async function sweepSLA(store, options) {
901
- // The principal is attribution, not authorization — the SystemApprovalStore
902
- // type is the authorization. The parameter type already excludes a human;
903
- // this is the erased-type half, because this is the one exported cross-tenant
904
- // function that CARRIES an attribution principal (purgeExpiredApprovals takes
905
- // none, so it has no attribution to corrupt), and a bad principal here makes
906
- // every escalation it emits, for every tenant, unattributable.
850
+ // The principal is attribution, not authorization. The parameter type
851
+ // excludes a human, and the runtime check closes the erased-type boundary.
907
852
  const systemPrincipal = canonicalAutomatedPrincipal(options.systemPrincipal);
908
853
  if (systemPrincipal === undefined) {
909
854
  throw new Error('sweepSLA: systemPrincipal must be a valid automated execution principal');
@@ -942,9 +887,8 @@ export async function sweepSLA(store, options) {
942
887
  const at = now();
943
888
  const nowIso = at.toISOString();
944
889
  const escalated = [];
945
- // D3: page the cross-tenant open set with an explicit cursor instead of one
946
- // unbounded SELECT (the system view is deliberately un-defaulted, so a bare
947
- // list() here would be the whole table). Keyset paging is on (createdAt, id);
890
+ // D3: page the deployment's open set with an explicit cursor. Keyset paging
891
+ // is on (createdAt, id);
948
892
  // escalating a record only drops it from the pending/claimed filter and never
949
893
  // changes its cursor position, so every currently-open record is visited
950
894
  // exactly once — no skips, no repeats — and every breach as of `at` still
@@ -968,10 +912,7 @@ export async function sweepSLA(store, options) {
968
912
  escalated.push(updated);
969
913
  record('approval.escalate', `approval:${updated.id}`, 'allowed', {
970
914
  reason: `SLA deadline ${updated.slaDeadlineAt} breached`,
971
- // tenantId attributes the escalation: a cross-tenant sweep without it
972
- // emits unattributable audit events.
973
915
  detail: {
974
- tenantId: updated.tenantId,
975
916
  workflowId: updated.workflowId,
976
917
  runId: updated.runId,
977
918
  },
@@ -985,17 +926,14 @@ export async function sweepSLA(store, options) {
985
926
  // abort the sweep. The audit trail keeps the evidence.
986
927
  record('approval.escalate', `approval:${updated.id}`, 'error', {
987
928
  reason: `onEscalation threw: ${errorMessage(error)}`,
988
- detail: { tenantId: updated.tenantId },
989
929
  });
990
930
  }
991
931
  }
992
932
  fireNotification(options.notify, { type: 'escalated', record: updated }, (reason) => record('approval.notify', `approval:${updated.id}`, 'error', {
993
933
  reason,
994
- detail: { tenantId: updated.tenantId },
995
934
  }));
996
935
  fireStreamEvent(options.stream, { type: 'escalated', record: updated }, (reason) => record('approval.stream', `approval:${updated.id}`, 'error', {
997
936
  reason,
998
- detail: { tenantId: updated.tenantId },
999
937
  }));
1000
938
  }
1001
939
  // Full page ⇒ there may be more; cursor past the last row (FIFO order, so