@proofoftech/flowsafe 0.11.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 (384) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +65 -43
  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.js +2 -2
  10. package/dist/agent-host/catalog.js.map +1 -1
  11. package/dist/agent-host/index.d.ts +2 -2
  12. package/dist/agent-host/index.d.ts.map +1 -1
  13. package/dist/agent-host/index.js.map +1 -1
  14. package/dist/agent-host/router.d.ts +2 -2
  15. package/dist/agent-host/router.d.ts.map +1 -1
  16. package/dist/agent-host/router.js +22 -54
  17. package/dist/agent-host/router.js.map +1 -1
  18. package/dist/agent-host/thread-host.d.ts +42 -8
  19. package/dist/agent-host/thread-host.d.ts.map +1 -1
  20. package/dist/agent-host/thread-host.js +533 -106
  21. package/dist/agent-host/thread-host.js.map +1 -1
  22. package/dist/agent-host/thread-topology.d.ts +28 -7
  23. package/dist/agent-host/thread-topology.d.ts.map +1 -1
  24. package/dist/agent-host/thread-topology.js +97 -39
  25. package/dist/agent-host/thread-topology.js.map +1 -1
  26. package/dist/agent-host/trusted-context.d.ts.map +1 -1
  27. package/dist/agent-host/trusted-context.js +3 -1
  28. package/dist/agent-host/trusted-context.js.map +1 -1
  29. package/dist/agent-host/types.d.ts +2 -0
  30. package/dist/agent-host/types.d.ts.map +1 -1
  31. package/dist/agent-runner/agent-run-state.d.ts +9 -8
  32. package/dist/agent-runner/agent-run-state.d.ts.map +1 -1
  33. package/dist/agent-runner/agent-run-state.js +78 -40
  34. package/dist/agent-runner/agent-run-state.js.map +1 -1
  35. package/dist/agent-runner/durable-agent-runner.d.ts +18 -16
  36. package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
  37. package/dist/agent-runner/durable-agent-runner.js +120 -43
  38. package/dist/agent-runner/durable-agent-runner.js.map +1 -1
  39. package/dist/agent-runner/index.d.ts +1 -1
  40. package/dist/agent-runner/index.d.ts.map +1 -1
  41. package/dist/agent-runner/index.js +1 -1
  42. package/dist/agent-runner/index.js.map +1 -1
  43. package/dist/approval-api/actor-context.d.ts +67 -0
  44. package/dist/approval-api/actor-context.d.ts.map +1 -0
  45. package/dist/approval-api/actor-context.js +120 -0
  46. package/dist/approval-api/actor-context.js.map +1 -0
  47. package/dist/approval-api/contract.d.ts +12 -23
  48. package/dist/approval-api/contract.d.ts.map +1 -1
  49. package/dist/approval-api/d1-store.d.ts +7 -15
  50. package/dist/approval-api/d1-store.d.ts.map +1 -1
  51. package/dist/approval-api/d1-store.js +83 -159
  52. package/dist/approval-api/d1-store.js.map +1 -1
  53. package/dist/approval-api/grants.d.ts +3 -17
  54. package/dist/approval-api/grants.d.ts.map +1 -1
  55. package/dist/approval-api/grants.js +19 -39
  56. package/dist/approval-api/grants.js.map +1 -1
  57. package/dist/approval-api/index.d.ts +8 -8
  58. package/dist/approval-api/index.d.ts.map +1 -1
  59. package/dist/approval-api/index.js +5 -5
  60. package/dist/approval-api/index.js.map +1 -1
  61. package/dist/approval-api/principal.d.ts +29 -30
  62. package/dist/approval-api/principal.d.ts.map +1 -1
  63. package/dist/approval-api/principal.js +73 -54
  64. package/dist/approval-api/principal.js.map +1 -1
  65. package/dist/approval-api/resource-ownership.d.ts +64 -0
  66. package/dist/approval-api/resource-ownership.d.ts.map +1 -0
  67. package/dist/approval-api/resource-ownership.js +329 -0
  68. package/dist/approval-api/resource-ownership.js.map +1 -0
  69. package/dist/approval-api/retention.d.ts +6 -11
  70. package/dist/approval-api/retention.d.ts.map +1 -1
  71. package/dist/approval-api/retention.js +7 -12
  72. package/dist/approval-api/retention.js.map +1 -1
  73. package/dist/approval-api/router.d.ts +9 -8
  74. package/dist/approval-api/router.d.ts.map +1 -1
  75. package/dist/approval-api/router.js +50 -18
  76. package/dist/approval-api/router.js.map +1 -1
  77. package/dist/approval-api/service.d.ts +26 -36
  78. package/dist/approval-api/service.d.ts.map +1 -1
  79. package/dist/approval-api/service.js +104 -166
  80. package/dist/approval-api/service.js.map +1 -1
  81. package/dist/approval-api/store-factory.d.ts +19 -0
  82. package/dist/approval-api/store-factory.d.ts.map +1 -0
  83. package/dist/approval-api/store-factory.js +49 -0
  84. package/dist/approval-api/store-factory.js.map +1 -0
  85. package/dist/approval-api/store.d.ts +22 -36
  86. package/dist/approval-api/store.d.ts.map +1 -1
  87. package/dist/approval-api/store.js +48 -66
  88. package/dist/approval-api/store.js.map +1 -1
  89. package/dist/approval-api/types.d.ts +28 -22
  90. package/dist/approval-api/types.d.ts.map +1 -1
  91. package/dist/approval-api/types.js +51 -3
  92. package/dist/approval-api/types.js.map +1 -1
  93. package/dist/approval-ui/client.js +3 -3
  94. package/dist/approval-ui/client.js.map +1 -1
  95. package/dist/approval-ui/stream.d.ts +4 -4
  96. package/dist/approval-ui/stream.d.ts.map +1 -1
  97. package/dist/approval-ui/stream.js +2 -2
  98. package/dist/approval-ui/tips.d.ts +1 -1
  99. package/dist/approval-ui/tips.js +1 -1
  100. package/dist/approval-ui/tips.js.map +1 -1
  101. package/dist/approval-ui/use-approval-dashboard.d.ts +3 -3
  102. package/dist/approval-ui/use-approval-dashboard.js +1 -1
  103. package/dist/artifacts/index.d.ts +2 -3
  104. package/dist/artifacts/index.d.ts.map +1 -1
  105. package/dist/artifacts/index.js +9 -8
  106. package/dist/artifacts/index.js.map +1 -1
  107. package/dist/audit-export/audit-proxy.d.ts +71 -0
  108. package/dist/audit-export/audit-proxy.d.ts.map +1 -0
  109. package/dist/audit-export/audit-proxy.js +142 -0
  110. package/dist/audit-export/audit-proxy.js.map +1 -0
  111. package/dist/audit-export/index.d.ts +4 -7
  112. package/dist/audit-export/index.d.ts.map +1 -1
  113. package/dist/audit-export/index.js +1 -4
  114. package/dist/audit-export/index.js.map +1 -1
  115. package/dist/audit-export/queue-types.d.ts +5 -0
  116. package/dist/audit-export/queue-types.d.ts.map +1 -0
  117. package/dist/audit-export/queue-types.js +3 -0
  118. package/dist/audit-export/queue-types.js.map +1 -0
  119. package/dist/background-tasks/d1-storage.d.ts +9 -19
  120. package/dist/background-tasks/d1-storage.d.ts.map +1 -1
  121. package/dist/background-tasks/d1-storage.js +22 -52
  122. package/dist/background-tasks/d1-storage.js.map +1 -1
  123. package/dist/background-tasks/host.d.ts +4 -6
  124. package/dist/background-tasks/host.d.ts.map +1 -1
  125. package/dist/background-tasks/host.js +14 -17
  126. package/dist/background-tasks/host.js.map +1 -1
  127. package/dist/background-tasks/index.d.ts +1 -1
  128. package/dist/background-tasks/index.d.ts.map +1 -1
  129. package/dist/background-tasks/index.js +3 -3
  130. package/dist/background-tasks/index.js.map +1 -1
  131. package/dist/background-tasks/routes.d.ts +8 -4
  132. package/dist/background-tasks/routes.d.ts.map +1 -1
  133. package/dist/background-tasks/routes.js +33 -31
  134. package/dist/background-tasks/routes.js.map +1 -1
  135. package/dist/deployment-identity-protocol.d.ts +3 -0
  136. package/dist/deployment-identity-protocol.d.ts.map +1 -0
  137. package/dist/deployment-identity-protocol.js +3 -0
  138. package/dist/deployment-identity-protocol.js.map +1 -0
  139. package/dist/do-runner/breakwater-keys.d.ts +7 -5
  140. package/dist/do-runner/breakwater-keys.d.ts.map +1 -1
  141. package/dist/do-runner/breakwater-keys.js +7 -5
  142. package/dist/do-runner/breakwater-keys.js.map +1 -1
  143. package/dist/do-runner/cf-types.d.ts +18 -12
  144. package/dist/do-runner/cf-types.d.ts.map +1 -1
  145. package/dist/do-runner/cf-types.js.map +1 -1
  146. package/dist/do-runner/d1-storage.d.ts +44 -182
  147. package/dist/do-runner/d1-storage.d.ts.map +1 -1
  148. package/dist/do-runner/d1-storage.js +102 -353
  149. package/dist/do-runner/d1-storage.js.map +1 -1
  150. package/dist/do-runner/deployment-identity.d.ts +121 -0
  151. package/dist/do-runner/deployment-identity.d.ts.map +1 -0
  152. package/dist/do-runner/deployment-identity.js +272 -0
  153. package/dist/do-runner/deployment-identity.js.map +1 -0
  154. package/dist/do-runner/do-error-response.d.ts +1 -1
  155. package/dist/do-runner/do-error-response.d.ts.map +1 -1
  156. package/dist/do-runner/do-error-response.js +7 -1
  157. package/dist/do-runner/do-error-response.js.map +1 -1
  158. package/dist/do-runner/durable-object.d.ts +23 -16
  159. package/dist/do-runner/durable-object.d.ts.map +1 -1
  160. package/dist/do-runner/durable-object.js +303 -70
  161. package/dist/do-runner/durable-object.js.map +1 -1
  162. package/dist/do-runner/execution-context.d.ts +1 -0
  163. package/dist/do-runner/execution-context.d.ts.map +1 -1
  164. package/dist/do-runner/execution-context.js +4 -7
  165. package/dist/do-runner/execution-context.js.map +1 -1
  166. package/dist/do-runner/execution-principal-header.d.ts +16 -0
  167. package/dist/do-runner/execution-principal-header.d.ts.map +1 -0
  168. package/dist/do-runner/execution-principal-header.js +20 -0
  169. package/dist/do-runner/execution-principal-header.js.map +1 -0
  170. package/dist/do-runner/hub-do.d.ts +17 -25
  171. package/dist/do-runner/hub-do.d.ts.map +1 -1
  172. package/dist/do-runner/hub-do.js +63 -59
  173. package/dist/do-runner/hub-do.js.map +1 -1
  174. package/dist/do-runner/index.d.ts +12 -10
  175. package/dist/do-runner/index.d.ts.map +1 -1
  176. package/dist/do-runner/index.js +10 -9
  177. package/dist/do-runner/index.js.map +1 -1
  178. package/dist/do-runner/init.d.ts +0 -7
  179. package/dist/do-runner/init.d.ts.map +1 -1
  180. package/dist/do-runner/init.js +1 -2
  181. package/dist/do-runner/init.js.map +1 -1
  182. package/dist/do-runner/memory-id.d.ts +8 -25
  183. package/dist/do-runner/memory-id.d.ts.map +1 -1
  184. package/dist/do-runner/memory-id.js +25 -52
  185. package/dist/do-runner/memory-id.js.map +1 -1
  186. package/dist/do-runner/path-safe-id.d.ts +2 -48
  187. package/dist/do-runner/path-safe-id.d.ts.map +1 -1
  188. package/dist/do-runner/path-safe-id.js +3 -93
  189. package/dist/do-runner/path-safe-id.js.map +1 -1
  190. package/dist/do-runner/pubsub.d.ts +1 -1
  191. package/dist/do-runner/pubsub.js +1 -1
  192. package/dist/do-runner/runtime.d.ts +47 -34
  193. package/dist/do-runner/runtime.d.ts.map +1 -1
  194. package/dist/do-runner/runtime.js +281 -143
  195. package/dist/do-runner/runtime.js.map +1 -1
  196. package/dist/do-runner/schedule-source.d.ts +81 -0
  197. package/dist/do-runner/schedule-source.d.ts.map +1 -0
  198. package/dist/do-runner/schedule-source.js +64 -0
  199. package/dist/do-runner/schedule-source.js.map +1 -0
  200. package/dist/do-runner/thread-do.d.ts +18 -32
  201. package/dist/do-runner/thread-do.d.ts.map +1 -1
  202. package/dist/do-runner/thread-do.js +52 -74
  203. package/dist/do-runner/thread-do.js.map +1 -1
  204. package/dist/goals/objective-routes.d.ts +7 -4
  205. package/dist/goals/objective-routes.d.ts.map +1 -1
  206. package/dist/goals/objective-routes.js +58 -43
  207. package/dist/goals/objective-routes.js.map +1 -1
  208. package/dist/host-kit/approval-bridge.d.ts +18 -21
  209. package/dist/host-kit/approval-bridge.d.ts.map +1 -1
  210. package/dist/host-kit/approval-bridge.js +37 -37
  211. package/dist/host-kit/approval-bridge.js.map +1 -1
  212. package/dist/host-kit/bearer-auth.d.ts +3 -4
  213. package/dist/host-kit/bearer-auth.d.ts.map +1 -1
  214. package/dist/host-kit/bearer-auth.js +7 -11
  215. package/dist/host-kit/bearer-auth.js.map +1 -1
  216. package/dist/host-kit/do-run-topology.d.ts +14 -5
  217. package/dist/host-kit/do-run-topology.d.ts.map +1 -1
  218. package/dist/host-kit/do-run-topology.js +47 -15
  219. package/dist/host-kit/do-run-topology.js.map +1 -1
  220. package/dist/host-kit/env-vars.d.ts +1 -1
  221. package/dist/host-kit/env-vars.js +1 -1
  222. package/dist/host-kit/flowsafe-worker.d.ts +149 -73
  223. package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
  224. package/dist/host-kit/flowsafe-worker.js +619 -141
  225. package/dist/host-kit/flowsafe-worker.js.map +1 -1
  226. package/dist/host-kit/host-approval-service.d.ts +62 -54
  227. package/dist/host-kit/host-approval-service.d.ts.map +1 -1
  228. package/dist/host-kit/host-approval-service.js +90 -61
  229. package/dist/host-kit/host-approval-service.js.map +1 -1
  230. package/dist/host-kit/hub-topology.d.ts +6 -7
  231. package/dist/host-kit/hub-topology.d.ts.map +1 -1
  232. package/dist/host-kit/hub-topology.js +16 -12
  233. package/dist/host-kit/hub-topology.js.map +1 -1
  234. package/dist/host-kit/index.d.ts +13 -11
  235. package/dist/host-kit/index.d.ts.map +1 -1
  236. package/dist/host-kit/index.js +9 -12
  237. package/dist/host-kit/index.js.map +1 -1
  238. package/dist/host-kit/maintenance-capability.d.ts +58 -0
  239. package/dist/host-kit/maintenance-capability.d.ts.map +1 -0
  240. package/dist/host-kit/maintenance-capability.js +268 -0
  241. package/dist/host-kit/maintenance-capability.js.map +1 -0
  242. package/dist/host-kit/memory-boundary.d.ts +4 -19
  243. package/dist/host-kit/memory-boundary.d.ts.map +1 -1
  244. package/dist/host-kit/memory-boundary.js +12 -27
  245. package/dist/host-kit/memory-boundary.js.map +1 -1
  246. package/dist/host-kit/resource-access.d.ts +4 -0
  247. package/dist/host-kit/resource-access.d.ts.map +1 -0
  248. package/dist/host-kit/resource-access.js +12 -0
  249. package/dist/host-kit/resource-access.js.map +1 -0
  250. package/dist/host-kit/run-router.d.ts +25 -15
  251. package/dist/host-kit/run-router.d.ts.map +1 -1
  252. package/dist/host-kit/run-router.js +61 -46
  253. package/dist/host-kit/run-router.js.map +1 -1
  254. package/dist/host-kit/state-egress.d.ts +51 -0
  255. package/dist/host-kit/state-egress.d.ts.map +1 -0
  256. package/dist/host-kit/state-egress.js +120 -0
  257. package/dist/host-kit/state-egress.js.map +1 -0
  258. package/dist/host-kit/stream-router.d.ts +9 -4
  259. package/dist/host-kit/stream-router.d.ts.map +1 -1
  260. package/dist/host-kit/stream-router.js +45 -38
  261. package/dist/host-kit/stream-router.js.map +1 -1
  262. package/dist/host-kit/stream-ticket.d.ts +10 -10
  263. package/dist/host-kit/stream-ticket.d.ts.map +1 -1
  264. package/dist/host-kit/stream-ticket.js +60 -90
  265. package/dist/host-kit/stream-ticket.js.map +1 -1
  266. package/dist/host-kit/thread-topology.d.ts +17 -11
  267. package/dist/host-kit/thread-topology.d.ts.map +1 -1
  268. package/dist/host-kit/thread-topology.js +33 -59
  269. package/dist/host-kit/thread-topology.js.map +1 -1
  270. package/dist/host-kit/verifier.d.ts +6 -6
  271. package/dist/host-kit/verifier.d.ts.map +1 -1
  272. package/dist/host-kit/verifier.js +51 -119
  273. package/dist/host-kit/verifier.js.map +1 -1
  274. package/dist/http-body.d.ts +20 -0
  275. package/dist/http-body.d.ts.map +1 -0
  276. package/dist/http-body.js +67 -0
  277. package/dist/http-body.js.map +1 -0
  278. package/dist/schedules/index.d.ts +3 -2
  279. package/dist/schedules/index.d.ts.map +1 -1
  280. package/dist/schedules/index.js +5 -4
  281. package/dist/schedules/index.js.map +1 -1
  282. package/dist/schedules/router.d.ts +16 -10
  283. package/dist/schedules/router.d.ts.map +1 -1
  284. package/dist/schedules/router.js +153 -91
  285. package/dist/schedules/router.js.map +1 -1
  286. package/dist/schedules/schedules-d1.d.ts +88 -0
  287. package/dist/schedules/schedules-d1.d.ts.map +1 -1
  288. package/dist/schedules/schedules-d1.js +411 -50
  289. package/dist/schedules/schedules-d1.js.map +1 -1
  290. package/dist/schedules/target-policy.d.ts +29 -0
  291. package/dist/schedules/target-policy.d.ts.map +1 -0
  292. package/dist/schedules/target-policy.js +70 -0
  293. package/dist/schedules/target-policy.js.map +1 -0
  294. package/dist/schedules/tick.d.ts +125 -21
  295. package/dist/schedules/tick.d.ts.map +1 -1
  296. package/dist/schedules/tick.js +637 -160
  297. package/dist/schedules/tick.js.map +1 -1
  298. package/dist/signal-providers/delivery.d.ts +0 -19
  299. package/dist/signal-providers/delivery.d.ts.map +1 -1
  300. package/dist/signal-providers/delivery.js +5 -54
  301. package/dist/signal-providers/delivery.js.map +1 -1
  302. package/dist/signal-providers/github-provider.d.ts.map +1 -1
  303. package/dist/signal-providers/github-provider.js +9 -16
  304. package/dist/signal-providers/github-provider.js.map +1 -1
  305. package/dist/signal-providers/host-do.d.ts +3 -45
  306. package/dist/signal-providers/host-do.d.ts.map +1 -1
  307. package/dist/signal-providers/host-do.js +86 -106
  308. package/dist/signal-providers/host-do.js.map +1 -1
  309. package/dist/signal-providers/host-topology.d.ts +5 -14
  310. package/dist/signal-providers/host-topology.d.ts.map +1 -1
  311. package/dist/signal-providers/host-topology.js +11 -25
  312. package/dist/signal-providers/host-topology.js.map +1 -1
  313. package/dist/signal-providers/index.d.ts +3 -3
  314. package/dist/signal-providers/index.d.ts.map +1 -1
  315. package/dist/signal-providers/index.js +3 -3
  316. package/dist/signal-providers/index.js.map +1 -1
  317. package/dist/signal-providers/provider.d.ts +4 -5
  318. package/dist/signal-providers/provider.d.ts.map +1 -1
  319. package/dist/signal-providers/provider.js +5 -6
  320. package/dist/signal-providers/provider.js.map +1 -1
  321. package/dist/signal-providers/subscription-d1.d.ts +10 -57
  322. package/dist/signal-providers/subscription-d1.d.ts.map +1 -1
  323. package/dist/signal-providers/subscription-d1.js +208 -155
  324. package/dist/signal-providers/subscription-d1.js.map +1 -1
  325. package/dist/signal-providers/webhook-route.d.ts +28 -14
  326. package/dist/signal-providers/webhook-route.d.ts.map +1 -1
  327. package/dist/signal-providers/webhook-route.js +117 -88
  328. package/dist/signal-providers/webhook-route.js.map +1 -1
  329. package/dist/signals/client.js +8 -8
  330. package/dist/signals/client.js.map +1 -1
  331. package/dist/signals/d1-shared.js +1 -1
  332. package/dist/signals/d1-shared.js.map +1 -1
  333. package/dist/signals/index.d.ts +1 -1
  334. package/dist/signals/index.d.ts.map +1 -1
  335. package/dist/signals/index.js.map +1 -1
  336. package/dist/signals/notification-dispatch.d.ts +12 -6
  337. package/dist/signals/notification-dispatch.d.ts.map +1 -1
  338. package/dist/signals/notification-dispatch.js +37 -21
  339. package/dist/signals/notification-dispatch.js.map +1 -1
  340. package/dist/signals/notifications-d1.d.ts +5 -8
  341. package/dist/signals/notifications-d1.d.ts.map +1 -1
  342. package/dist/signals/notifications-d1.js +8 -13
  343. package/dist/signals/notifications-d1.js.map +1 -1
  344. package/dist/signals/router.d.ts +10 -10
  345. package/dist/signals/router.d.ts.map +1 -1
  346. package/dist/signals/router.js +49 -51
  347. package/dist/signals/router.js.map +1 -1
  348. package/dist/signals/thread-do-routes.d.ts +74 -15
  349. package/dist/signals/thread-do-routes.d.ts.map +1 -1
  350. package/dist/signals/thread-do-routes.js +484 -41
  351. package/dist/signals/thread-do-routes.js.map +1 -1
  352. package/dist/signals/thread-state-d1.d.ts.map +1 -1
  353. package/dist/signals/thread-state-d1.js +2 -3
  354. package/dist/signals/thread-state-d1.js.map +1 -1
  355. package/package.json +29 -6
  356. package/scripts/seed-deployment-identity.mjs +252 -0
  357. package/dist/approval-api/tenant-brand.d.ts +0 -35
  358. package/dist/approval-api/tenant-brand.d.ts.map +0 -1
  359. package/dist/approval-api/tenant-brand.js +0 -19
  360. package/dist/approval-api/tenant-brand.js.map +0 -1
  361. package/dist/approval-api/tenant-context.d.ts +0 -84
  362. package/dist/approval-api/tenant-context.d.ts.map +0 -1
  363. package/dist/approval-api/tenant-context.js +0 -112
  364. package/dist/approval-api/tenant-context.js.map +0 -1
  365. package/dist/approval-api/tenant-store.d.ts +0 -36
  366. package/dist/approval-api/tenant-store.d.ts.map +0 -1
  367. package/dist/approval-api/tenant-store.js +0 -129
  368. package/dist/approval-api/tenant-store.js.map +0 -1
  369. package/dist/do-runner/resume-ledger.d.ts +0 -48
  370. package/dist/do-runner/resume-ledger.d.ts.map +0 -1
  371. package/dist/do-runner/resume-ledger.js +0 -60
  372. package/dist/do-runner/resume-ledger.js.map +0 -1
  373. package/dist/do-runner/thread-header.d.ts +0 -31
  374. package/dist/do-runner/thread-header.d.ts.map +0 -1
  375. package/dist/do-runner/thread-header.js +0 -39
  376. package/dist/do-runner/thread-header.js.map +0 -1
  377. package/dist/host-kit/subdomain-check.d.ts +0 -23
  378. package/dist/host-kit/subdomain-check.d.ts.map +0 -1
  379. package/dist/host-kit/subdomain-check.js +0 -61
  380. package/dist/host-kit/subdomain-check.js.map +0 -1
  381. package/dist/host-kit/tenant-registry.d.ts +0 -51
  382. package/dist/host-kit/tenant-registry.d.ts.map +0 -1
  383. package/dist/host-kit/tenant-registry.js +0 -88
  384. package/dist/host-kit/tenant-registry.js.map +0 -1
@@ -1,84 +0,0 @@
1
- import { type ApprovalActor, type ApprovalRole } from './contract.js';
2
- import { type ExecutionPrincipal } from './principal.js';
3
- import { type ApprovalService, type SelfDecisionPolicy } from './service.js';
4
- import type { TenantBoundApprovalStore } from './tenant-brand.js';
5
- export interface TenantContext {
6
- /** Already authenticated; tenantId equals actor.tenantId and matches the tenant-ID pattern. */
7
- readonly actor: ApprovalActor;
8
- /**
9
- * WHO is executing. For an authenticated HTTP request this is the human in
10
- * `actor`; trusted internal contexts (schedule ticks, provider delivery, cron
11
- * maintenance) carry an automated principal instead of fabricating a role.
12
- */
13
- readonly principal: ExecutionPrincipal;
14
- readonly tenantId: string;
15
- /** The approval service over a store bound to THIS tenant. */
16
- service(): ApprovalService;
17
- /** Mint a tenant-salted runId: `${tenantId}_${uuid}`. */
18
- newRunId(): string;
19
- /** Exact ownership: `runId.startsWith(`${tenantId}_`)`. */
20
- ownsRun(runId: string): boolean;
21
- /**
22
- * Mint a tenant-salted agent-memory threadId: `${tenantId}_${uuid}` —
23
- * extending the tenant-salted identifier scheme to Mastra memory
24
- * (docs/agent-memory-tenancy.md). Hosts never accept a client-supplied
25
- * threadId; this is the constructor.
26
- */
27
- newThreadId(): string;
28
- /**
29
- * Mint a tenant-salted agent-memory resourceId over the host's business
30
- * key (a user id, a lead id): `${tenantId}_${resourceKey}`. Same key, two
31
- * tenants, disjoint ids — the memory-leak class the salting closes.
32
- */
33
- newResourceId(resourceKey: string): string;
34
- /**
35
- * Exact ownership over memory ids (threadId or resourceId) — assert on
36
- * every memory read/write path; answer 404 on a foreign id.
37
- */
38
- ownsMemoryId(id: string): boolean;
39
- /**
40
- * Display hint only: whether THIS actor may decide its OWN request — true
41
- * iff the actor holds a decider role AND the deployment's self-decision
42
- * policy exempts that role. Enforcement stays in ApprovalService.decide();
43
- * the GET /workflows echo reads this so the SPA can drop its "the server
44
- * will refuse your decision" hint for an exempt role.
45
- */
46
- canSelfDecide(role: ApprovalRole): boolean;
47
- }
48
- /**
49
- * undefined => no identity => 401. Throws TenantResolutionError when an
50
- * authenticated actor carries an invalid tenant ID or names a reserved
51
- * identity ('system') — either is a verifier or claim-mapping bug, surfaced
52
- * as 403 by the routers, never concatenated into a runId ("undefined" is
53
- * itself a pattern-valid string, so an unvalidated `String(undefined)` would
54
- * silently authorize a tenant literally named 'undefined').
55
- */
56
- export type TenantResolver = (request: Request) => Promise<TenantContext | undefined>;
57
- export declare class TenantResolutionError extends Error {
58
- constructor(message: string);
59
- }
60
- export interface CreateTenantResolverOptions {
61
- /** The host's authenticate seam (bearerActorAuthenticator over a verifier). */
62
- authenticate: (request: Request) => Promise<ApprovalActor | undefined> | ApprovalActor | undefined;
63
- /** Store factory (D1 or in-memory) — binds per request, DDL memoized once. */
64
- storeFactory: {
65
- forTenant(tenantId: string): TenantBoundApprovalStore;
66
- };
67
- /**
68
- * Host-specific service assembly (resumeRun topology, audit sink, SLA
69
- * defaults) over the request's bound store. Called lazily, at most once per
70
- * request.
71
- */
72
- buildService: (store: TenantBoundApprovalStore, actor: ApprovalActor) => ApprovalService;
73
- /** The uuid half of minted runIds. Default: crypto.randomUUID. */
74
- newRunId?: () => string;
75
- /**
76
- * The SoD exemption policy the resolver builds `canSelfDecide` from — pass
77
- * the SAME value the host feeds ApprovalService so the display hint can
78
- * never contradict the server's decide() verdict. Absent => SoD on
79
- * (`canSelfDecide` false for every role).
80
- */
81
- allowSelfDecision?: SelfDecisionPolicy;
82
- }
83
- export declare function createTenantResolver(options: CreateTenantResolverOptions): TenantResolver;
84
- //# sourceMappingURL=tenant-context.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tenant-context.d.ts","sourceRoot":"","sources":["../../src/approval-api/tenant-context.ts"],"names":[],"mappings":"AAqBA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,YAAY,EAElB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,kBAAkB,EAAkB,MAAM,gBAAgB,CAAC;AACzE,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EAExB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAElE,MAAM,WAAW,aAAa;IAC5B,+FAA+F;IAC/F,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC;IACvC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,8DAA8D;IAC9D,OAAO,IAAI,eAAe,CAAC;IAC3B,yDAAyD;IACzD,QAAQ,IAAI,MAAM,CAAC;IACnB,2DAA2D;IAC3D,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC;;;;;OAKG;IACH,WAAW,IAAI,MAAM,CAAC;IACtB;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3C;;;OAGG;IACH,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC;;;;;;OAMG;IACH,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC;CAC5C;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;AAExC,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,EAAE,MAAM;CAI5B;AAUD,MAAM,WAAW,2BAA2B;IAC1C,+EAA+E;IAC/E,YAAY,EAAE,CACZ,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,GAAG,aAAa,GAAG,SAAS,CAAC;IACpE,8EAA8E;IAC9E,YAAY,EAAE;QAAE,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,wBAAwB,CAAA;KAAE,CAAC;IACxE;;;;OAIG;IACH,YAAY,EAAE,CACZ,KAAK,EAAE,wBAAwB,EAC/B,KAAK,EAAE,aAAa,KACjB,eAAe,CAAC;IACrB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,MAAM,CAAC;IACxB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,kBAAkB,CAAC;CACxC;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,2BAA2B,GACnC,cAAc,CAmGhB"}
@@ -1,112 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- // The request-scoped tenant context — the seam that makes INV-2
3
- // CONSTRUCTIBLE. The stores must be bound to the authenticated tenant, but a
4
- // host's fetch() historically built its ApprovalService from `env` before
5
- // anyone was authenticated, so "bind at construction from actor.tenantId" had
6
- // no valid call site — the exact ordering hole a rushed fix plugs with an
7
- // unauthenticated header. TenantResolver inverts the order: routers resolve
8
- // the request FIRST (authenticate -> validate INV-3 -> bind), and everything
9
- // downstream reads tenant.service() / tenant.newRunId() / tenant.ownsRun().
10
- import { mintResourceId, mintThreadId } from '../do-runner/memory-id.js';
11
- import { mintSaltedId, RESERVED_TENANT_IDS, TENANT_ID_PATTERN, tenantOwnsSaltedId, } from '../do-runner/path-safe-id.js';
12
- import { THREAD_PRINCIPAL_HEADER, THREAD_TENANT_HEADER, } from '../do-runner/thread-header.js';
13
- import { APPROVAL_ROLES, DECIDER_ROLES, } from './contract.js';
14
- import { humanPrincipal } from './principal.js';
15
- import { selfDecisionExempts, } from './service.js';
16
- export class TenantResolutionError extends Error {
17
- constructor(message) {
18
- super(message);
19
- this.name = 'TenantResolutionError';
20
- }
21
- }
22
- function containsHeaderControl(value) {
23
- for (const character of value) {
24
- const code = character.charCodeAt(0);
25
- if (code <= 0x1f || code === 0x7f)
26
- return true;
27
- }
28
- return false;
29
- }
30
- export function createTenantResolver(options) {
31
- const mintUuid = options.newRunId ?? (() => crypto.randomUUID());
32
- return async (request) => {
33
- // The thread-DO tenant header is SERVER-STAMPED by createThreadTopology on
34
- // the stub fetches it forwards, which never traverse this request pipeline,
35
- // so no legitimate inbound request carries it. Refuse one that does, before
36
- // authenticating or binding — it closes the last inch of the forged-header
37
- // write the topology's minter guards against: a route copying the house
38
- // `stub.fetch(request)` idiom would forward a client's own x-flowsafe-tenant
39
- // verbatim, and the DO's name-prefix assertion would then PASS for the
40
- // client's chosen thread. `Headers.has` is case-insensitive, so no spelling
41
- // slips past. Same posture as the RESERVED_TENANT_IDS belt below: this
42
- // resolver is the one chokepoint every routed request crosses.
43
- if (request.headers.has(THREAD_TENANT_HEADER) ||
44
- // Retired from the wire, still refused: a client forging them means it
45
- // expects an older flowsafe, and a mixed-version deployment should fail
46
- // loudly rather than have the header quietly ignored.
47
- request.headers.has('x-flowsafe-actor') ||
48
- request.headers.has('x-flowsafe-role') ||
49
- // Without this an external caller could assert its own principal kind,
50
- // and the agent host's automation gate would be answering a question the
51
- // client got to ask.
52
- request.headers.has(THREAD_PRINCIPAL_HEADER)) {
53
- throw new TenantResolutionError(`inbound request carries a server-stamped thread header — refusing to scope it`);
54
- }
55
- const actor = await options.authenticate(request);
56
- if (!actor)
57
- return undefined;
58
- if (typeof actor !== 'object' ||
59
- typeof actor.id !== 'string' ||
60
- actor.id.trim() === '' ||
61
- containsHeaderControl(actor.id) ||
62
- typeof actor.role !== 'string' ||
63
- !APPROVAL_ROLES.includes(actor.role)) {
64
- throw new TenantResolutionError('authenticated claims carry an invalid actor id or role — fix the verifier; refusing to scope the request');
65
- }
66
- if (typeof actor.tenantId !== 'string' ||
67
- !TENANT_ID_PATTERN.test(actor.tenantId)) {
68
- throw new TenantResolutionError(`authenticated actor '${actor.id}' carries a non-INV-3 tenantId — fix the verifier; refusing to scope the request`);
69
- }
70
- // Belt over the verifier seam: the built-in toApprovalActor already drops
71
- // reserved identities, but a custom TokenVerifier or a hand-built actor
72
- // map handed to staticTokenVerifier never crosses it. This resolver is
73
- // the one chokepoint every routed request passes before a store binds or
74
- // a runId mints, so the TCB's own audit identity is re-refused here
75
- // whatever the verifier admitted. ('system' is INV-3-valid — the pattern
76
- // check above cannot catch it.)
77
- if (RESERVED_TENANT_IDS.includes(actor.tenantId)) {
78
- throw new TenantResolutionError(`authenticated actor '${actor.id}' carries the reserved tenantId '${actor.tenantId}' (the TCB's own audit identity) — fix the verifier; refusing to scope the request`);
79
- }
80
- const tenantId = actor.tenantId;
81
- let service;
82
- return {
83
- actor,
84
- // An authenticated HTTP request is by definition a person; automated
85
- // principals never arrive through this resolver.
86
- principal: humanPrincipal(actor),
87
- tenantId,
88
- service: () => {
89
- service ??= options.buildService(options.storeFactory.forTenant(tenantId), actor);
90
- return service;
91
- },
92
- // mintUuid passed LAZILY: mintSaltedId validates the tenant before
93
- // evaluating it (a no-op guard here — the resolver already refused a bad
94
- // tenant above — but it keeps the safe validate-then-mint idiom uniform).
95
- newRunId: () => mintSaltedId(tenantId, mintUuid, 'newRunId'),
96
- ownsRun: (runId) => tenantOwnsSaltedId(tenantId, runId),
97
- // Memory ids ride the same uuid seam as runIds so tests inject one
98
- // generator for both; mint* re-refuses reserved/non-INV-3 tenants,
99
- // a no-op here (this resolver already refused them above).
100
- newThreadId: () => mintThreadId(tenantId, mintUuid),
101
- newResourceId: (resourceKey) => mintResourceId(tenantId, resourceKey),
102
- ownsMemoryId: (id) => tenantOwnsSaltedId(tenantId, id),
103
- // Display hint, not enforcement: the DECIDER_ROLES guard means a
104
- // non-decider never echoes true (it cannot decide at all), so the hint
105
- // never affirms a role decide() would reject. Fed the SAME
106
- // allowSelfDecision the service enforces (ApprovalService.decide).
107
- canSelfDecide: (role) => DECIDER_ROLES.includes(role) &&
108
- selfDecisionExempts(options.allowSelfDecision, role),
109
- };
110
- };
111
- }
112
- //# sourceMappingURL=tenant-context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tenant-context.js","sourceRoot":"","sources":["../../src/approval-api/tenant-context.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,gEAAgE;AAChE,6EAA6E;AAC7E,0EAA0E;AAC1E,8EAA8E;AAC9E,0EAA0E;AAC1E,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAE5E,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,cAAc,EAGd,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAA2B,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAGL,mBAAmB,GACpB,MAAM,cAAc,CAAC;AA2DtB,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,SAAS,qBAAqB,CAAC,KAAa;IAC1C,KAAK,MAAM,SAAS,IAAI,KAAK,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AA6B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C,WAAmB,EAAE,EAAE,CACrC,cAAc,CAAC,QAAQ,EAAE,WAAW,CAAC;YACvC,YAAY,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,kBAAkB,CAAC,QAAQ,EAAE,EAAE,CAAC;YAC9D,iEAAiE;YACjE,uEAAuE;YACvE,2DAA2D;YAC3D,mEAAmE;YACnE,aAAa,EAAE,CAAC,IAAkB,EAAE,EAAE,CACpC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAC5B,mBAAmB,CAAC,OAAO,CAAC,iBAAiB,EAAE,IAAI,CAAC;SACvD,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -1,36 +0,0 @@
1
- import { type ApprovalDatabase } from './d1-store.js';
2
- import type { SystemApprovalStore, TenantBoundApprovalStore } from './tenant-brand.js';
3
- export interface ApprovalStoreFactory {
4
- /** Bind a store to one tenant. Throws unless tenantId satisfies TENANT_ID_PATTERN. */
5
- forTenant(tenantId: string): TenantBoundApprovalStore;
6
- /** The cron-only cross-tenant view (SLA sweep). Never request-scoped. */
7
- system(): SystemApprovalStore;
8
- }
9
- export declare class D1ApprovalStoreFactory implements ApprovalStoreFactory {
10
- #private;
11
- constructor(db: ApprovalDatabase);
12
- forTenant(tenantId: string): TenantBoundApprovalStore;
13
- system(): SystemApprovalStore;
14
- }
15
- /**
16
- * In-memory factory over ONE shared Map. Not decoration: two independent
17
- * `new InMemoryApprovalStore(...)` instances hold separate Maps, so a
18
- * cross-tenant get/transition test against them passes trivially without
19
- * exercising the tenant predicate — the exact "InMemory hides what D1 does"
20
- * divergence the shared contract suite exists to close. Tenant A and tenant B
21
- * views minted here share the backend, like two bound D1 stores share the
22
- * table.
23
- */
24
- export declare class InMemoryApprovalStoreFactory implements ApprovalStoreFactory {
25
- #private;
26
- forTenant(tenantId: string): TenantBoundApprovalStore;
27
- /**
28
- * Delete every record stamped with this tenant, returning the count — the
29
- * in-memory mirror of the D1 `purgeTenant` approvals delete (in-memory hosts
30
- * have no D1 for that function to run against). Factory-level like
31
- * `system()`: offboarding is not a request-scoped capability.
32
- */
33
- purgeTenant(tenantId: string): number;
34
- system(): SystemApprovalStore;
35
- }
36
- //# sourceMappingURL=tenant-store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tenant-store.d.ts","sourceRoot":"","sources":["../../src/approval-api/tenant-store.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,gBAAgB,EAItB,MAAM,eAAe,CAAC;AAQvB,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,mBAAmB,CAAC;AAW3B,MAAM,WAAW,oBAAoB;IACnC,sFAAsF;IACtF,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,wBAAwB,CAAC;IACtD,yEAAyE;IACzE,MAAM,IAAI,mBAAmB,CAAC;CAC/B;AAUD,qBAAa,sBAAuB,YAAW,oBAAoB;;gBAIrD,EAAE,EAAE,gBAAgB;IAiBhC,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,wBAAwB;IAKrD,MAAM,IAAI,mBAAmB;CAG9B;AAED;;;;;;;;GAQG;AACH,qBAAa,4BAA6B,YAAW,oBAAoB;;IAGvE,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,wBAAwB;IAKrD;;;;;OAKG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAYrC,MAAM,IAAI,mBAAmB;CA0D9B"}
@@ -1,129 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- // Store factories — the ONLY way hosts obtain approval stores (INV-2: "no
3
- // caller can obtain an approval store that is not bound to exactly one tenant
4
- // at construction"). Each factory owns its backend handle and its schema-init
5
- // memo, so a per-request forTenant() does not re-run DDL; system() hands the
6
- // cron the cross-tenant view, distinctly TYPED so it cannot flow into
7
- // request-scoped code (SystemApprovalStore is not an ApprovalStore).
8
- import { TENANT_ID_PATTERN } from '../do-runner/path-safe-id.js';
9
- import { createApprovalSchema, D1ApprovalStore, d1SystemApprovalStore, } from './d1-store.js';
10
- import { approvalListComparator, InMemoryApprovalStore, matchesFilter, paginateApprovalList, } from './store.js';
11
- import { assertApprovalTimeBounds, TERMINAL_APPROVAL_STATUSES, } from './types.js';
12
- function assertTenantId(tenantId) {
13
- if (typeof tenantId !== 'string' || !TENANT_ID_PATTERN.test(tenantId)) {
14
- throw new Error(`forTenant: tenantId '${tenantId}' violates INV-3 (^[a-z0-9]{3,32}$)`);
15
- }
16
- }
17
- export class D1ApprovalStoreFactory {
18
- #db;
19
- #schemaReady;
20
- constructor(db) {
21
- this.#db = db;
22
- }
23
- // One memoized DDL pass per factory (per isolate), shared by every bound
24
- // store and the system view; a failed attempt clears the memo so the next
25
- // call retries instead of pinning everything to a dead promise.
26
- #ready = () => {
27
- this.#schemaReady ??= createApprovalSchema(this.#db).catch((error) => {
28
- this.#schemaReady = undefined;
29
- throw error;
30
- });
31
- return this.#schemaReady;
32
- };
33
- forTenant(tenantId) {
34
- assertTenantId(tenantId);
35
- return new D1ApprovalStore(this.#db, { tenantId, ready: this.#ready });
36
- }
37
- system() {
38
- return d1SystemApprovalStore(this.#db, this.#ready);
39
- }
40
- }
41
- /**
42
- * In-memory factory over ONE shared Map. Not decoration: two independent
43
- * `new InMemoryApprovalStore(...)` instances hold separate Maps, so a
44
- * cross-tenant get/transition test against them passes trivially without
45
- * exercising the tenant predicate — the exact "InMemory hides what D1 does"
46
- * divergence the shared contract suite exists to close. Tenant A and tenant B
47
- * views minted here share the backend, like two bound D1 stores share the
48
- * table.
49
- */
50
- export class InMemoryApprovalStoreFactory {
51
- #records = new Map();
52
- forTenant(tenantId) {
53
- assertTenantId(tenantId);
54
- return new InMemoryApprovalStore(tenantId, this.#records);
55
- }
56
- /**
57
- * Delete every record stamped with this tenant, returning the count — the
58
- * in-memory mirror of the D1 `purgeTenant` approvals delete (in-memory hosts
59
- * have no D1 for that function to run against). Factory-level like
60
- * `system()`: offboarding is not a request-scoped capability.
61
- */
62
- purgeTenant(tenantId) {
63
- assertTenantId(tenantId);
64
- let purged = 0;
65
- for (const [id, record] of this.#records) {
66
- if (record.tenantId === tenantId) {
67
- this.#records.delete(id);
68
- purged += 1;
69
- }
70
- }
71
- return purged;
72
- }
73
- system() {
74
- const records = this.#records;
75
- return {
76
- // Identical to the bound store's list() minus the tenant predicate —
77
- // hence the shared matchesFilter/approvalListComparator/
78
- // paginateApprovalList rather than a copy.
79
- async list(filter = {}) {
80
- // Same eager time-bound validation as the tenant-bound store's list()
81
- // (store.ts): a zero-match view must reject a garbage createdBefore/
82
- // createdAfter identically to D1's system view, not return [] — the
83
- // shared assertApprovalTimeBounds closes the whole class across BOTH
84
- // in-memory list paths (DL-006).
85
- assertApprovalTimeBounds(filter);
86
- const matched = [...records.values()]
87
- .filter((record) => matchesFilter(record, filter))
88
- .sort(approvalListComparator(filter));
89
- return paginateApprovalList(matched, filter).map((record) => structuredClone(record));
90
- },
91
- async transition(id, from, patch) {
92
- const current = records.get(id);
93
- if (!current || !from.includes(current.status))
94
- return null;
95
- const updated = { ...current };
96
- for (const [field, value] of Object.entries(patch)) {
97
- if (value !== undefined) {
98
- updated[field] = value;
99
- }
100
- }
101
- records.set(id, updated);
102
- return structuredClone(updated);
103
- },
104
- // Retention purge (D3/PART 4): mirrors the D1 system view's
105
- // purgeExpired — terminal-only, cutoff is exclusive (strictly before),
106
- // bounded by `limit`. Map iteration order is insertion order; no
107
- // ordering guarantee is required (purgeExpiredWorkflowRuns' row-only
108
- // batching path makes the same no-ORDER-BY choice — the shrinking
109
- // eligible set across firings is what matters, not which N rows a
110
- // single firing picks).
111
- async purgeExpired(cutoffIso, limit) {
112
- let purged = 0;
113
- for (const [id, record] of records) {
114
- if (purged >= limit)
115
- break;
116
- if (!TERMINAL_APPROVAL_STATUSES.includes(record.status))
117
- continue;
118
- const terminalAt = record.decidedAt ?? record.updatedAt;
119
- if (terminalAt < cutoffIso) {
120
- records.delete(id);
121
- purged += 1;
122
- }
123
- }
124
- return purged;
125
- },
126
- };
127
- }
128
- }
129
- //# sourceMappingURL=tenant-store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tenant-store.js","sourceRoot":"","sources":["../../src/approval-api/tenant-store.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,0EAA0E;AAC1E,8EAA8E;AAC9E,8EAA8E;AAC9E,6EAA6E;AAC7E,sEAAsE;AACtE,qEAAqE;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAEL,oBAAoB,EACpB,eAAe,EACf,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAUpB,OAAO,EACL,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AASpB,SAAS,cAAc,CAAC,QAAgB;IACtC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CACb,wBAAwB,QAAQ,qCAAqC,CACtE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,OAAO,sBAAsB;IACxB,GAAG,CAAmB;IAC/B,YAAY,CAAiB;IAE7B,YAAY,EAAoB;QAC9B,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,yEAAyE;IACzE,0EAA0E;IAC1E,gEAAgE;IAChE,MAAM,GAAG,GAAkB,EAAE;QAC3B,IAAI,CAAC,YAAY,KAAK,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CACxD,CAAC,KAAc,EAAE,EAAE;YACjB,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;YAC9B,MAAM,KAAK,CAAC;QACd,CAAC,CACF,CAAC;QACF,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC,CAAC;IAEF,SAAS,CAA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AO,EAAE,CAAC;oBACnC,IAAI,MAAM,IAAI,KAAK;wBAAE,MAAM;oBAC3B,IAAI,CAAC,0BAA0B,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;wBAAE,SAAS;oBAClE,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC;oBACxD,IAAI,UAAU,GAAG,SAAS,EAAE,CAAC;wBAC3B,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;wBACnB,MAAM,IAAI,CAAC,CAAC;oBACd,CAAC;gBACH,CAAC;gBACD,OAAO,MAAM,CAAC;YAChB,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -1,48 +0,0 @@
1
- export interface ResumeLedger {
2
- /**
3
- * stepKey -> prior resume count for the run; undefined when the run has no
4
- * recorded resumes. Read BEFORE an increment, the count is the ordinal of
5
- * the suspension currently being resumed (undefined = first suspension).
6
- */
7
- counts(runKey: string): Promise<ReadonlyMap<string, number> | undefined>;
8
- /**
9
- * Record one more resume of stepKey; resolves to the run's updated counts.
10
- * `prior` is a read-elision hint: the run's current counts as read by
11
- * counts() under the SAME per-run lock, with nothing writing in between
12
- * (an empty map when the run has none). An I/O-backed ledger uses it to
13
- * skip re-reading what the lock guarantees unchanged; implementations with
14
- * free reads may ignore it. Omit when no such fresh read exists.
15
- */
16
- increment(runKey: string, stepKey: string, prior?: ReadonlyMap<string, number>): Promise<ReadonlyMap<string, number>>;
17
- /** Drop the run's ledger — call only once the run is terminal. */
18
- delete(runKey: string): Promise<void>;
19
- }
20
- export declare class InMemoryResumeLedger implements ResumeLedger {
21
- #private;
22
- counts(runKey: string): Promise<ReadonlyMap<string, number> | undefined>;
23
- increment(runKey: string, stepKey: string): Promise<ReadonlyMap<string, number>>;
24
- delete(runKey: string): Promise<void>;
25
- }
26
- /**
27
- * Structural subset of DurableObjectStorage the ledger needs — a seam, so
28
- * node tests can back it with a plain Map and this module needs no
29
- * workers-only import.
30
- */
31
- export interface ResumeLedgerStorage {
32
- get<T = unknown>(key: string): Promise<T | undefined>;
33
- put<T>(key: string, value: T): Promise<void>;
34
- delete(key: string): Promise<boolean>;
35
- }
36
- /**
37
- * ctx.storage-backed ledger. One storage key per run; reads and writes ride
38
- * the DO's own serialization (the runtime's per-run FIFO lock already orders
39
- * the increment after the fingerprint read within one resume).
40
- */
41
- export declare class DurableStorageResumeLedger implements ResumeLedger {
42
- #private;
43
- constructor(storage: ResumeLedgerStorage);
44
- counts(runKey: string): Promise<ReadonlyMap<string, number> | undefined>;
45
- increment(runKey: string, stepKey: string, prior?: ReadonlyMap<string, number>): Promise<ReadonlyMap<string, number>>;
46
- delete(runKey: string): Promise<void>;
47
- }
48
- //# sourceMappingURL=resume-ledger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resume-ledger.d.ts","sourceRoot":"","sources":["../../src/do-runner/resume-ledger.ts"],"names":[],"mappings":"AAiBA,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC;IACzE;;;;;;;OAOG;IACH,SAAS,CACP,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACxC,kEAAkE;IAClE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED,qBAAa,oBAAqB,YAAW,YAAY;;IAGjD,MAAM,CACV,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAI7C,SAAS,CACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAOjC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG5C;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IACtD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACvC;AAUD;;;;GAIG;AACH,qBAAa,0BAA2B,YAAW,YAAY;;gBAGjD,OAAO,EAAE,mBAAmB;IAIlC,MAAM,CACV,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAK7C,SAAS,CACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAYjC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG5C"}
@@ -1,60 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- // The per-run resume ledger: runKey (`${workflowId}:${runId}`, composed by
3
- // RunnerRuntime.#runKey) -> (stepKey -> times that step has been resumed).
4
- // The count is the grant-binding tie-breaker (RunLeg.resumeCount /
5
- // RunSummary.resumeCount): approvals capture it at suspension time and the
6
- // provider must see the same value on the resuming leg.
7
- //
8
- // Durability contract: a lost ledger is fail-closed for grants — the leg
9
- // reads resumeCount undefined against an approval's captured ordinal, the
10
- // pair mismatch denies, and the APPROVED action silently no-ops. That is an
11
- // availability bug, not a leak, and it is exactly what a Durable Object
12
- // eviction (~70-140s idle), hibernation, or code deploy does to in-memory
13
- // state. ctx.storage survives all three, so the DO shell adopts
14
- // DurableStorageResumeLedger (see durable-object.ts); InMemoryResumeLedger
15
- // remains the default for node tests and non-DO hosts, preserving the
16
- // pre-seam behavior exactly.
17
- export class InMemoryResumeLedger {
18
- #counts = new Map();
19
- async counts(runKey) {
20
- return this.#counts.get(runKey);
21
- }
22
- async increment(runKey, stepKey) {
23
- const counts = this.#counts.get(runKey) ?? new Map();
24
- counts.set(stepKey, (counts.get(stepKey) ?? 0) + 1);
25
- this.#counts.set(runKey, counts);
26
- return counts;
27
- }
28
- async delete(runKey) {
29
- this.#counts.delete(runKey);
30
- }
31
- }
32
- const KEY_PREFIX = 'flowsafe:resume-ledger:';
33
- /**
34
- * ctx.storage-backed ledger. One storage key per run; reads and writes ride
35
- * the DO's own serialization (the runtime's per-run FIFO lock already orders
36
- * the increment after the fingerprint read within one resume).
37
- */
38
- export class DurableStorageResumeLedger {
39
- #storage;
40
- constructor(storage) {
41
- this.#storage = storage;
42
- }
43
- async counts(runKey) {
44
- const stored = await this.#storage.get(KEY_PREFIX + runKey);
45
- return stored ? new Map(stored) : undefined;
46
- }
47
- async increment(runKey, stepKey, prior) {
48
- const key = KEY_PREFIX + runKey;
49
- // `prior` (read under the run lock) elides a second billed storage.get
50
- // for the value the lock guarantees unchanged.
51
- const counts = new Map(prior ?? (await this.#storage.get(key)) ?? []);
52
- counts.set(stepKey, (counts.get(stepKey) ?? 0) + 1);
53
- await this.#storage.put(key, [...counts.entries()]);
54
- return counts;
55
- }
56
- async delete(runKey) {
57
- await this.#storage.delete(KEY_PREFIX + runKey);
58
- }
59
- }
60
- //# sourceMappingURL=resume-ledger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resume-ledger.js","sourceRoot":"","sources":["../../src/do-runner/resume-ledger.ts"],"names":[],"mappings":"AAAA,sCAAsC;A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,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,SAAS,CACb,MAAc,EACd,OAAe,EACf,KAAmC;QAEnC,MAAM,GAAG,GAAG,UAAU,GAAG,MAAM,CAAC;QAChC,uEAAuE;QACvE,+CAA+C;QAC/C,MAAM,MAAM,GAAG,IAAI,GAAG,CACpB,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAe,GAAG,CAAC,CAAC,IAAI,EAAE,CAC5D,CAAC;QACF,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACpD,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACpD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAc;QACzB,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,CAAC;IAClD,CAAC;CACF"}
@@ -1,31 +0,0 @@
1
- /**
2
- * The header the trusted Worker stamps with the AUTHENTICATED tenant on every
3
- * request it forwards to a thread DO. ONE literal for all three enforcement
4
- * points — a typo on any of them must fail closed (the DO's assertion rejects),
5
- * and two spellings would silently disable the check on the day one side
6
- * changed.
7
- *
8
- * SERVER-STAMPED, never client-supplied. A thread DO is reached only through a
9
- * stub fetch from `createThreadTopology`, which never traverses the Worker's
10
- * request pipeline, so no legitimate inbound request carries this header — which
11
- * is why `createTenantResolver` refuses one that does, before any store binds.
12
- */
13
- export declare const THREAD_TENANT_HEADER = "x-flowsafe-tenant";
14
- /**
15
- * The trusted Worker-stamped EXECUTION PRINCIPAL — WHO is executing, which the
16
- * id/role/tenant headers cannot express.
17
- *
18
- * REQUIRED, and the SOLE identity channel: the DO projects `scope.actor` from
19
- * it, so there is no separate actor or role header to disagree with what
20
- * executes. `createThreadTopology` stamps it on every `send` and `forward`, the
21
- * only sanctioned way to reach a thread DO, and `ThreadDurableObject` refuses a
22
- * request without it. There is deliberately no human default — a dropped
23
- * principal header fails the request rather than admitting automation as a
24
- * human whose entry the agent host never authorized against `allowedAutomation`.
25
- *
26
- * `createTenantResolver` refuses any inbound request that carries this header,
27
- * or the retired `x-flowsafe-actor` / `x-flowsafe-role` names, before a store
28
- * binds — so a mixed-version client fails loudly instead of being trusted.
29
- */
30
- export declare const THREAD_PRINCIPAL_HEADER = "x-flowsafe-principal";
31
- //# sourceMappingURL=thread-header.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"thread-header.d.ts","sourceRoot":"","sources":["../../src/do-runner/thread-header.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,sBAAsB,CAAC;AAExD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,uBAAuB,yBAAyB,CAAC"}
@@ -1,39 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- // The thread DO's tenant header — its own leaf because THREE layers hold one
3
- // end of it each and none may depend on another's module: do-runner's
4
- // ThreadDurableObject VERIFIES it, host-kit's createThreadTopology MINTS it, and
5
- // approval-api's createTenantResolver REFUSES it inbound. Same reasoning that
6
- // puts RESERVED_TENANT_IDS in path-safe-id.ts and the breakwater key literals in
7
- // breakwater-keys.ts: a constant two layers enforce lives below both of them,
8
- // never in whichever one happened to declare it first.
9
- /**
10
- * The header the trusted Worker stamps with the AUTHENTICATED tenant on every
11
- * request it forwards to a thread DO. ONE literal for all three enforcement
12
- * points — a typo on any of them must fail closed (the DO's assertion rejects),
13
- * and two spellings would silently disable the check on the day one side
14
- * changed.
15
- *
16
- * SERVER-STAMPED, never client-supplied. A thread DO is reached only through a
17
- * stub fetch from `createThreadTopology`, which never traverses the Worker's
18
- * request pipeline, so no legitimate inbound request carries this header — which
19
- * is why `createTenantResolver` refuses one that does, before any store binds.
20
- */
21
- export const THREAD_TENANT_HEADER = 'x-flowsafe-tenant';
22
- /**
23
- * The trusted Worker-stamped EXECUTION PRINCIPAL — WHO is executing, which the
24
- * id/role/tenant headers cannot express.
25
- *
26
- * REQUIRED, and the SOLE identity channel: the DO projects `scope.actor` from
27
- * it, so there is no separate actor or role header to disagree with what
28
- * executes. `createThreadTopology` stamps it on every `send` and `forward`, the
29
- * only sanctioned way to reach a thread DO, and `ThreadDurableObject` refuses a
30
- * request without it. There is deliberately no human default — a dropped
31
- * principal header fails the request rather than admitting automation as a
32
- * human whose entry the agent host never authorized against `allowedAutomation`.
33
- *
34
- * `createTenantResolver` refuses any inbound request that carries this header,
35
- * or the retired `x-flowsafe-actor` / `x-flowsafe-role` names, before a store
36
- * binds — so a mixed-version client fails loudly instead of being trusted.
37
- */
38
- export const THREAD_PRINCIPAL_HEADER = 'x-flowsafe-principal';
39
- //# sourceMappingURL=thread-header.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"thread-header.js","sourceRoot":"","sources":["../../src/do-runner/thread-header.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,6EAA6E;AAC7E,sEAAsE;AACtE,iFAAiF;AACjF,8EAA8E;AAC9E,iFAAiF;AACjF,8EAA8E;AAC9E,uDAAuD;AAEvD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAExD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,sBAAsB,CAAC"}
@@ -1,23 +0,0 @@
1
- import type { TenantResolver } from '../approval-api/index.js';
2
- export interface SubdomainCrossCheckOptions {
3
- /**
4
- * The apex under which tenant subdomains live, e.g. 'example.com'. Hosts
5
- * NOT under it (workers.dev previews, localhost) skip the check.
6
- */
7
- apexDomain: string;
8
- /** Subdomains that are shared infrastructure, never tenants. */
9
- reserved?: readonly string[];
10
- }
11
- /**
12
- * The tenant slug a hostname addresses: `<slug>.<apex>` => slug; the apex
13
- * itself, hosts outside the apex, multi-level subdomains, and reserved slugs
14
- * => undefined (not tenant-addressed).
15
- */
16
- export declare function subdomainTenantOf(hostname: string, options: SubdomainCrossCheckOptions): string | undefined;
17
- /**
18
- * Decorate a TenantResolver: when the request addresses a tenant subdomain,
19
- * the resolved token tenant must BE that tenant — mismatch throws
20
- * TenantResolutionError (the routers' 403). Non-tenant hosts pass through.
21
- */
22
- export declare function withSubdomainCrossCheck(resolve: TenantResolver, options: SubdomainCrossCheckOptions): TenantResolver;
23
- //# sourceMappingURL=subdomain-check.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subdomain-check.d.ts","sourceRoot":"","sources":["../../src/host-kit/subdomain-check.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAI9E,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,0BAA0B,GAClC,MAAM,GAAG,SAAS,CAkBpB;AAMD;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,0BAA0B,GAClC,cAAc,CAehB"}