@dads-framework/http 0.0.0-stage → 0.1.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 (288) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +219 -2
  3. package/dist/http.tsbuildinfo +1 -0
  4. package/dist/index.d.ts +56 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +37 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/lib/create-http-app.d.ts +108 -0
  9. package/dist/lib/create-http-app.d.ts.map +1 -0
  10. package/dist/lib/create-http-app.js +181 -0
  11. package/dist/lib/create-http-app.js.map +1 -0
  12. package/dist/lib/http-errors.d.ts +52 -0
  13. package/dist/lib/http-errors.d.ts.map +1 -0
  14. package/dist/lib/http-errors.js +66 -0
  15. package/dist/lib/http-errors.js.map +1 -0
  16. package/dist/lib/mcp/mcp-tool.d.ts +94 -0
  17. package/dist/lib/mcp/mcp-tool.d.ts.map +1 -0
  18. package/dist/lib/mcp/mcp-tool.js +11 -0
  19. package/dist/lib/mcp/mcp-tool.js.map +1 -0
  20. package/dist/lib/object-value.d.ts +3 -0
  21. package/dist/lib/object-value.d.ts.map +1 -0
  22. package/dist/lib/object-value.js +5 -0
  23. package/dist/lib/object-value.js.map +1 -0
  24. package/dist/lib/openapi/build-document.d.ts +27 -0
  25. package/dist/lib/openapi/build-document.d.ts.map +1 -0
  26. package/dist/lib/openapi/build-document.js +192 -0
  27. package/dist/lib/openapi/build-document.js.map +1 -0
  28. package/dist/lib/openapi/logic/add-discriminators.d.ts +16 -0
  29. package/dist/lib/openapi/logic/add-discriminators.d.ts.map +1 -0
  30. package/dist/lib/openapi/logic/add-discriminators.js +235 -0
  31. package/dist/lib/openapi/logic/add-discriminators.js.map +1 -0
  32. package/dist/lib/openapi/logic/by-code-point.d.ts +2 -0
  33. package/dist/lib/openapi/logic/by-code-point.d.ts.map +1 -0
  34. package/dist/lib/openapi/logic/by-code-point.js +6 -0
  35. package/dist/lib/openapi/logic/by-code-point.js.map +1 -0
  36. package/dist/lib/openapi/logic/capitalize-initial.d.ts +2 -0
  37. package/dist/lib/openapi/logic/capitalize-initial.d.ts.map +1 -0
  38. package/dist/lib/openapi/logic/capitalize-initial.js +4 -0
  39. package/dist/lib/openapi/logic/capitalize-initial.js.map +1 -0
  40. package/dist/lib/openapi/logic/document-record.d.ts +5 -0
  41. package/dist/lib/openapi/logic/document-record.d.ts.map +1 -0
  42. package/dist/lib/openapi/logic/document-record.js +14 -0
  43. package/dist/lib/openapi/logic/document-record.js.map +1 -0
  44. package/dist/lib/openapi/logic/list-order.d.ts +23 -0
  45. package/dist/lib/openapi/logic/list-order.d.ts.map +1 -0
  46. package/dist/lib/openapi/logic/list-order.js +102 -0
  47. package/dist/lib/openapi/logic/list-order.js.map +1 -0
  48. package/dist/lib/openapi/logic/open-response-objects.d.ts +14 -0
  49. package/dist/lib/openapi/logic/open-response-objects.d.ts.map +1 -0
  50. package/dist/lib/openapi/logic/open-response-objects.js +130 -0
  51. package/dist/lib/openapi/logic/open-response-objects.js.map +1 -0
  52. package/dist/lib/openapi/logic/openapi-parts.d.ts +37 -0
  53. package/dist/lib/openapi/logic/openapi-parts.d.ts.map +1 -0
  54. package/dist/lib/openapi/logic/openapi-parts.js +243 -0
  55. package/dist/lib/openapi/logic/openapi-parts.js.map +1 -0
  56. package/dist/lib/openapi/logic/schema-components.d.ts +5 -0
  57. package/dist/lib/openapi/logic/schema-components.d.ts.map +1 -0
  58. package/dist/lib/openapi/logic/schema-components.js +47 -0
  59. package/dist/lib/openapi/logic/schema-components.js.map +1 -0
  60. package/dist/lib/request-log/authorization-warning-faults.d.ts +30 -0
  61. package/dist/lib/request-log/authorization-warning-faults.d.ts.map +1 -0
  62. package/dist/lib/request-log/authorization-warning-faults.js +35 -0
  63. package/dist/lib/request-log/authorization-warning-faults.js.map +1 -0
  64. package/dist/lib/request-log/capture-request-record.d.ts +50 -0
  65. package/dist/lib/request-log/capture-request-record.d.ts.map +1 -0
  66. package/dist/lib/request-log/capture-request-record.js +132 -0
  67. package/dist/lib/request-log/capture-request-record.js.map +1 -0
  68. package/dist/lib/request-log/request-log-sink.d.ts +31 -0
  69. package/dist/lib/request-log/request-log-sink.d.ts.map +1 -0
  70. package/dist/lib/request-log/request-log-sink.js +26 -0
  71. package/dist/lib/request-log/request-log-sink.js.map +1 -0
  72. package/dist/lib/request-log/request-outcome.d.ts +53 -0
  73. package/dist/lib/request-log/request-outcome.d.ts.map +1 -0
  74. package/dist/lib/request-log/request-outcome.js +96 -0
  75. package/dist/lib/request-log/request-outcome.js.map +1 -0
  76. package/dist/lib/request-log/request-record.d.ts +114 -0
  77. package/dist/lib/request-log/request-record.d.ts.map +1 -0
  78. package/dist/lib/request-log/request-record.js +231 -0
  79. package/dist/lib/request-log/request-record.js.map +1 -0
  80. package/dist/lib/request-pipeline/assert-no-app-site-serving.d.ts +8 -0
  81. package/dist/lib/request-pipeline/assert-no-app-site-serving.d.ts.map +1 -0
  82. package/dist/lib/request-pipeline/assert-no-app-site-serving.js +15 -0
  83. package/dist/lib/request-pipeline/assert-no-app-site-serving.js.map +1 -0
  84. package/dist/lib/request-pipeline/carry-audit-actor.d.ts +71 -0
  85. package/dist/lib/request-pipeline/carry-audit-actor.d.ts.map +1 -0
  86. package/dist/lib/request-pipeline/carry-audit-actor.js +79 -0
  87. package/dist/lib/request-pipeline/carry-audit-actor.js.map +1 -0
  88. package/dist/lib/request-pipeline/carry-authorization-consistency.d.ts +4 -0
  89. package/dist/lib/request-pipeline/carry-authorization-consistency.d.ts.map +1 -0
  90. package/dist/lib/request-pipeline/carry-authorization-consistency.js +21 -0
  91. package/dist/lib/request-pipeline/carry-authorization-consistency.js.map +1 -0
  92. package/dist/lib/request-pipeline/enforce-access.d.ts +146 -0
  93. package/dist/lib/request-pipeline/enforce-access.d.ts.map +1 -0
  94. package/dist/lib/request-pipeline/enforce-access.js +238 -0
  95. package/dist/lib/request-pipeline/enforce-access.js.map +1 -0
  96. package/dist/lib/request-pipeline/enforce-scope.d.ts +23 -0
  97. package/dist/lib/request-pipeline/enforce-scope.d.ts.map +1 -0
  98. package/dist/lib/request-pipeline/enforce-scope.js +58 -0
  99. package/dist/lib/request-pipeline/enforce-scope.js.map +1 -0
  100. package/dist/lib/request-pipeline/envelope.d.ts +17 -0
  101. package/dist/lib/request-pipeline/envelope.d.ts.map +1 -0
  102. package/dist/lib/request-pipeline/envelope.js +4 -0
  103. package/dist/lib/request-pipeline/envelope.js.map +1 -0
  104. package/dist/lib/request-pipeline/error-handler.d.ts +14 -0
  105. package/dist/lib/request-pipeline/error-handler.d.ts.map +1 -0
  106. package/dist/lib/request-pipeline/error-handler.js +138 -0
  107. package/dist/lib/request-pipeline/error-handler.js.map +1 -0
  108. package/dist/lib/request-pipeline/feature-state-preview.d.ts +69 -0
  109. package/dist/lib/request-pipeline/feature-state-preview.d.ts.map +1 -0
  110. package/dist/lib/request-pipeline/feature-state-preview.js +61 -0
  111. package/dist/lib/request-pipeline/feature-state-preview.js.map +1 -0
  112. package/dist/lib/request-pipeline/feature-state.d.ts +64 -0
  113. package/dist/lib/request-pipeline/feature-state.d.ts.map +1 -0
  114. package/dist/lib/request-pipeline/feature-state.js +38 -0
  115. package/dist/lib/request-pipeline/feature-state.js.map +1 -0
  116. package/dist/lib/request-pipeline/logic/is-write-method.d.ts +2 -0
  117. package/dist/lib/request-pipeline/logic/is-write-method.d.ts.map +1 -0
  118. package/dist/lib/request-pipeline/logic/is-write-method.js +7 -0
  119. package/dist/lib/request-pipeline/logic/is-write-method.js.map +1 -0
  120. package/dist/lib/request-pipeline/logic/read-request-source.d.ts +19 -0
  121. package/dist/lib/request-pipeline/logic/read-request-source.d.ts.map +1 -0
  122. package/dist/lib/request-pipeline/logic/read-request-source.js +40 -0
  123. package/dist/lib/request-pipeline/logic/read-request-source.js.map +1 -0
  124. package/dist/lib/request-pipeline/logic/single-request-header.d.ts +3 -0
  125. package/dist/lib/request-pipeline/logic/single-request-header.d.ts.map +1 -0
  126. package/dist/lib/request-pipeline/logic/single-request-header.js +16 -0
  127. package/dist/lib/request-pipeline/logic/single-request-header.js.map +1 -0
  128. package/dist/lib/request-pipeline/machine-credential-access.d.ts +19 -0
  129. package/dist/lib/request-pipeline/machine-credential-access.d.ts.map +1 -0
  130. package/dist/lib/request-pipeline/machine-credential-access.js +28 -0
  131. package/dist/lib/request-pipeline/machine-credential-access.js.map +1 -0
  132. package/dist/lib/request-pipeline/rate-limit.d.ts +15 -0
  133. package/dist/lib/request-pipeline/rate-limit.d.ts.map +1 -0
  134. package/dist/lib/request-pipeline/rate-limit.js +40 -0
  135. package/dist/lib/request-pipeline/rate-limit.js.map +1 -0
  136. package/dist/lib/request-pipeline/raw-route-byte-body.d.ts +19 -0
  137. package/dist/lib/request-pipeline/raw-route-byte-body.d.ts.map +1 -0
  138. package/dist/lib/request-pipeline/raw-route-byte-body.js +26 -0
  139. package/dist/lib/request-pipeline/raw-route-byte-body.js.map +1 -0
  140. package/dist/lib/request-pipeline/refuse-visible-record-list.d.ts +16 -0
  141. package/dist/lib/request-pipeline/refuse-visible-record-list.d.ts.map +1 -0
  142. package/dist/lib/request-pipeline/refuse-visible-record-list.js +33 -0
  143. package/dist/lib/request-pipeline/refuse-visible-record-list.js.map +1 -0
  144. package/dist/lib/request-pipeline/register-routes.d.ts +50 -0
  145. package/dist/lib/request-pipeline/register-routes.d.ts.map +1 -0
  146. package/dist/lib/request-pipeline/register-routes.js +215 -0
  147. package/dist/lib/request-pipeline/register-routes.js.map +1 -0
  148. package/dist/lib/request-pipeline/request-id.d.ts +22 -0
  149. package/dist/lib/request-pipeline/request-id.d.ts.map +1 -0
  150. package/dist/lib/request-pipeline/request-id.js +26 -0
  151. package/dist/lib/request-pipeline/request-id.js.map +1 -0
  152. package/dist/lib/request-pipeline/request-language-response.d.ts +14 -0
  153. package/dist/lib/request-pipeline/request-language-response.d.ts.map +1 -0
  154. package/dist/lib/request-pipeline/request-language-response.js +47 -0
  155. package/dist/lib/request-pipeline/request-language-response.js.map +1 -0
  156. package/dist/lib/request-pipeline/request-locale.d.ts +38 -0
  157. package/dist/lib/request-pipeline/request-locale.d.ts.map +1 -0
  158. package/dist/lib/request-pipeline/request-locale.js +102 -0
  159. package/dist/lib/request-pipeline/request-locale.js.map +1 -0
  160. package/dist/lib/request-pipeline/request-origin.d.ts +17 -0
  161. package/dist/lib/request-pipeline/request-origin.d.ts.map +1 -0
  162. package/dist/lib/request-pipeline/request-origin.js +38 -0
  163. package/dist/lib/request-pipeline/request-origin.js.map +1 -0
  164. package/dist/lib/request-pipeline/request-trace.d.ts +10 -0
  165. package/dist/lib/request-pipeline/request-trace.d.ts.map +1 -0
  166. package/dist/lib/request-pipeline/request-trace.js +24 -0
  167. package/dist/lib/request-pipeline/request-trace.js.map +1 -0
  168. package/dist/lib/request-pipeline/route-rate-limit.d.ts +19 -0
  169. package/dist/lib/request-pipeline/route-rate-limit.d.ts.map +1 -0
  170. package/dist/lib/request-pipeline/route-rate-limit.js +32 -0
  171. package/dist/lib/request-pipeline/route-rate-limit.js.map +1 -0
  172. package/dist/lib/request-pipeline/run-route.d.ts +9 -0
  173. package/dist/lib/request-pipeline/run-route.d.ts.map +1 -0
  174. package/dist/lib/request-pipeline/run-route.js +42 -0
  175. package/dist/lib/request-pipeline/run-route.js.map +1 -0
  176. package/dist/lib/request-pipeline/with-deadline.d.ts +12 -0
  177. package/dist/lib/request-pipeline/with-deadline.d.ts.map +1 -0
  178. package/dist/lib/request-pipeline/with-deadline.js +55 -0
  179. package/dist/lib/request-pipeline/with-deadline.js.map +1 -0
  180. package/dist/lib/route/access.d.ts +143 -0
  181. package/dist/lib/route/access.d.ts.map +1 -0
  182. package/dist/lib/route/access.js +97 -0
  183. package/dist/lib/route/access.js.map +1 -0
  184. package/dist/lib/route/capabilities.d.ts +100 -0
  185. package/dist/lib/route/capabilities.d.ts.map +1 -0
  186. package/dist/lib/route/capabilities.js +42 -0
  187. package/dist/lib/route/capabilities.js.map +1 -0
  188. package/dist/lib/route/define-raw-route.d.ts +81 -0
  189. package/dist/lib/route/define-raw-route.d.ts.map +1 -0
  190. package/dist/lib/route/define-raw-route.js +5 -0
  191. package/dist/lib/route/define-raw-route.js.map +1 -0
  192. package/dist/lib/route/delete-route.d.ts +26 -0
  193. package/dist/lib/route/delete-route.d.ts.map +1 -0
  194. package/dist/lib/route/delete-route.js +6 -0
  195. package/dist/lib/route/delete-route.js.map +1 -0
  196. package/dist/lib/route/get-route.d.ts +43 -0
  197. package/dist/lib/route/get-route.d.ts.map +1 -0
  198. package/dist/lib/route/get-route.js +18 -0
  199. package/dist/lib/route/get-route.js.map +1 -0
  200. package/dist/lib/route/list-result.d.ts +11 -0
  201. package/dist/lib/route/list-result.d.ts.map +1 -0
  202. package/dist/lib/route/list-result.js +8 -0
  203. package/dist/lib/route/list-result.js.map +1 -0
  204. package/dist/lib/route/list-route.d.ts +60 -0
  205. package/dist/lib/route/list-route.d.ts.map +1 -0
  206. package/dist/lib/route/list-route.js +68 -0
  207. package/dist/lib/route/list-route.js.map +1 -0
  208. package/dist/lib/route/patch-route.d.ts +27 -0
  209. package/dist/lib/route/patch-route.d.ts.map +1 -0
  210. package/dist/lib/route/patch-route.js +8 -0
  211. package/dist/lib/route/patch-route.js.map +1 -0
  212. package/dist/lib/route/post-no-content-route.d.ts +18 -0
  213. package/dist/lib/route/post-no-content-route.d.ts.map +1 -0
  214. package/dist/lib/route/post-no-content-route.js +8 -0
  215. package/dist/lib/route/post-no-content-route.js.map +1 -0
  216. package/dist/lib/route/post-route.d.ts +34 -0
  217. package/dist/lib/route/post-route.d.ts.map +1 -0
  218. package/dist/lib/route/post-route.js +23 -0
  219. package/dist/lib/route/post-route.js.map +1 -0
  220. package/dist/lib/route/route-definition.d.ts +224 -0
  221. package/dist/lib/route/route-definition.d.ts.map +1 -0
  222. package/dist/lib/route/route-definition.js +32 -0
  223. package/dist/lib/route/route-definition.js.map +1 -0
  224. package/dist/lib/route/route-execution.d.ts +47 -0
  225. package/dist/lib/route/route-execution.d.ts.map +1 -0
  226. package/dist/lib/route/route-execution.js +162 -0
  227. package/dist/lib/route/route-execution.js.map +1 -0
  228. package/dist/lib/route/route-group.d.ts +21 -0
  229. package/dist/lib/route/route-group.d.ts.map +1 -0
  230. package/dist/lib/route/route-group.js +18 -0
  231. package/dist/lib/route/route-group.js.map +1 -0
  232. package/dist/lib/route/route-guards.test-support.d.ts +2 -0
  233. package/dist/lib/route/route-guards.test-support.d.ts.map +1 -0
  234. package/dist/lib/route/route-guards.test-support.js +2 -0
  235. package/dist/lib/route/route-guards.test-support.js.map +1 -0
  236. package/dist/lib/route/sse-route.d.ts +54 -0
  237. package/dist/lib/route/sse-route.d.ts.map +1 -0
  238. package/dist/lib/route/sse-route.js +63 -0
  239. package/dist/lib/route/sse-route.js.map +1 -0
  240. package/dist/lib/route/web-socket-route.d.ts +45 -0
  241. package/dist/lib/route/web-socket-route.d.ts.map +1 -0
  242. package/dist/lib/route/web-socket-route.js +180 -0
  243. package/dist/lib/route/web-socket-route.js.map +1 -0
  244. package/dist/lib/route-catalog/route-catalog-parts.d.ts +27 -0
  245. package/dist/lib/route-catalog/route-catalog-parts.d.ts.map +1 -0
  246. package/dist/lib/route-catalog/route-catalog-parts.js +87 -0
  247. package/dist/lib/route-catalog/route-catalog-parts.js.map +1 -0
  248. package/dist/protocol-mounts/index.d.ts +19 -0
  249. package/dist/protocol-mounts/index.d.ts.map +1 -0
  250. package/dist/protocol-mounts/index.js +19 -0
  251. package/dist/protocol-mounts/index.js.map +1 -0
  252. package/dist/protocol-mounts/lib/mcp/json-rpc.d.ts +54 -0
  253. package/dist/protocol-mounts/lib/mcp/json-rpc.d.ts.map +1 -0
  254. package/dist/protocol-mounts/lib/mcp/json-rpc.js +53 -0
  255. package/dist/protocol-mounts/lib/mcp/json-rpc.js.map +1 -0
  256. package/dist/protocol-mounts/lib/mcp/mcp-endpoint.d.ts +31 -0
  257. package/dist/protocol-mounts/lib/mcp/mcp-endpoint.d.ts.map +1 -0
  258. package/dist/protocol-mounts/lib/mcp/mcp-endpoint.js +179 -0
  259. package/dist/protocol-mounts/lib/mcp/mcp-endpoint.js.map +1 -0
  260. package/dist/protocol-mounts/lib/mcp/mcp-methods.d.ts +68 -0
  261. package/dist/protocol-mounts/lib/mcp/mcp-methods.d.ts.map +1 -0
  262. package/dist/protocol-mounts/lib/mcp/mcp-methods.js +201 -0
  263. package/dist/protocol-mounts/lib/mcp/mcp-methods.js.map +1 -0
  264. package/dist/protocol-mounts/lib/mcp/protected-resource-metadata.d.ts +18 -0
  265. package/dist/protocol-mounts/lib/mcp/protected-resource-metadata.d.ts.map +1 -0
  266. package/dist/protocol-mounts/lib/mcp/protected-resource-metadata.js +34 -0
  267. package/dist/protocol-mounts/lib/mcp/protected-resource-metadata.js.map +1 -0
  268. package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.d.ts +55 -0
  269. package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.d.ts.map +1 -0
  270. package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.js +98 -0
  271. package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.js.map +1 -0
  272. package/dist/protocol-mounts/lib/protocol-mount/to-web-request.d.ts +14 -0
  273. package/dist/protocol-mounts/lib/protocol-mount/to-web-request.d.ts.map +1 -0
  274. package/dist/protocol-mounts/lib/protocol-mount/to-web-request.js +60 -0
  275. package/dist/protocol-mounts/lib/protocol-mount/to-web-request.js.map +1 -0
  276. package/dist/testing/build-test-app.d.ts +47 -0
  277. package/dist/testing/build-test-app.d.ts.map +1 -0
  278. package/dist/testing/build-test-app.js +79 -0
  279. package/dist/testing/build-test-app.js.map +1 -0
  280. package/dist/testing/index.d.ts +3 -0
  281. package/dist/testing/index.d.ts.map +1 -0
  282. package/dist/testing/index.js +3 -0
  283. package/dist/testing/index.js.map +1 -0
  284. package/dist/testing/parse-inject-response.d.ts +32 -0
  285. package/dist/testing/parse-inject-response.d.ts.map +1 -0
  286. package/dist/testing/parse-inject-response.js +39 -0
  287. package/dist/testing/parse-inject-response.js.map +1 -0
  288. package/package.json +55 -4
@@ -0,0 +1,19 @@
1
+ import type { FastifyReply, FastifyRequest } from "fastify";
2
+ import { type RouteCapabilities } from "../route/capabilities.js";
3
+ import type { HttpRoute } from "../route/route-group.js";
4
+ import { type RateLimiter } from "./rate-limit.js";
5
+ /**
6
+ * Wires the rate-limit engine into the request pipeline: which limiter a
7
+ * route gets, how its budget is spent, and the 429 a spent caller sees.
8
+ */
9
+ /** The per-route limiter, or null when the effective policy is unlimited. */
10
+ export declare function limiterFor(definition: HttpRoute, appCapabilities: RouteCapabilities | undefined): RateLimiter | null;
11
+ export declare function sendRateLimited(request: FastifyRequest, reply: FastifyReply, retryAfterSeconds: number): FastifyReply;
12
+ /** Budget is consumed AFTER access — a denied caller learns nothing. */
13
+ export declare function consumeBudget(limiter: RateLimiter | null, definition: HttpRoute, request: FastifyRequest, subjectId: string | undefined): {
14
+ allowed: true;
15
+ } | {
16
+ allowed: false;
17
+ retryAfterSeconds: number;
18
+ };
19
+ //# sourceMappingURL=route-rate-limit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-rate-limit.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/route-rate-limit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG5D,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;GAGG;AAEH,6EAA6E;AAC7E,wBAAgB,UAAU,CACxB,UAAU,EAAE,SAAS,EACrB,eAAe,EAAE,iBAAiB,GAAG,SAAS,GAC7C,WAAW,GAAG,IAAI,CASpB;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,YAAY,EACnB,iBAAiB,EAAE,MAAM,GACxB,YAAY,CASd;AAED,wEAAwE;AACxE,wBAAgB,aAAa,CAC3B,OAAO,EAAE,WAAW,GAAG,IAAI,EAC3B,UAAU,EAAE,SAAS,EACrB,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,MAAM,GAAG,SAAS,GAC5B;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAMnE"}
@@ -0,0 +1,32 @@
1
+ import { rememberErrorCode } from "../request-log/request-outcome.js";
2
+ import { resolveCapabilities, } from "../route/capabilities.js";
3
+ import { createRateLimiter } from "./rate-limit.js";
4
+ /**
5
+ * Wires the rate-limit engine into the request pipeline: which limiter a
6
+ * route gets, how its budget is spent, and the 429 a spent caller sees.
7
+ */
8
+ /** The per-route limiter, or null when the effective policy is unlimited. */
9
+ export function limiterFor(definition, appCapabilities) {
10
+ const effective = resolveCapabilities(appCapabilities, undefined, definition.capabilities);
11
+ const limit = effective.rateLimit;
12
+ if (limit === undefined || limit === "unlimited")
13
+ return null;
14
+ return createRateLimiter(limit, Date.now);
15
+ }
16
+ export function sendRateLimited(request, reply, retryAfterSeconds) {
17
+ void reply.header("retry-after", String(retryAfterSeconds));
18
+ rememberErrorCode(request, "TOO_MANY_REQUESTS");
19
+ return reply.status(429).send({
20
+ error: {
21
+ code: "TOO_MANY_REQUESTS",
22
+ message: "Rate limit exceeded — retry after the indicated delay",
23
+ },
24
+ });
25
+ }
26
+ /** Budget is consumed AFTER access — a denied caller learns nothing. */
27
+ export function consumeBudget(limiter, definition, request, subjectId) {
28
+ if (!limiter)
29
+ return { allowed: true };
30
+ return limiter.consume(`${definition.method} ${definition.path}`, subjectId ?? request.ip);
31
+ }
32
+ //# sourceMappingURL=route-rate-limit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-rate-lim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AI,EAAE,EACzC,SAAS,IAAI,OAAO,CAAC,EAAE,CACxB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { FastifyRequest } from "fastify";
2
+ import type { RouteDefinition, RouteResult } from "../route/route-definition.js";
3
+ import type { AccessDecision } from "./enforce-access.js";
4
+ import type { FeatureStateSnapshot } from "./feature-state.js";
5
+ /** Runs the route's typed pipeline (parse → handler → parse) under the deadline. */
6
+ export declare function runRoute(definition: RouteDefinition, request: FastifyRequest, decision: Extract<AccessDecision, {
7
+ outcome: "allow";
8
+ }>, timeoutMs: number, featureState?: FeatureStateSnapshot): Promise<RouteResult>;
9
+ //# sourceMappingURL=run-route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-route.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/run-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,KAAK,EAEV,eAAe,EACf,WAAW,EACZ,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAwC/D,oFAAoF;AACpF,wBAAgB,QAAQ,CACtB,UAAU,EAAE,eAAe,EAC3B,OAAO,EAAE,cAAc,EACvB,QAAQ,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,EACvD,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,oBAAoB,GAClC,OAAO,CAAC,WAAW,CAAC,CAkBtB"}
@@ -0,0 +1,42 @@
1
+ import { requestIdOf } from "./request-id.js";
2
+ import { requestLocaleOf } from "./request-locale.js";
3
+ import { withDeadline } from "./with-deadline.js";
4
+ /**
5
+ * What enforcement settled beyond the subjects, for the route's input. A part
6
+ * enforcement did not set stays absent rather than arriving as `undefined`.
7
+ */
8
+ function forwardedDecision(decision) {
9
+ return {
10
+ ...(decision.untrustedAuthorizationContext === undefined
11
+ ? {}
12
+ : {
13
+ untrustedAuthorizationContext: decision.untrustedAuthorizationContext,
14
+ }),
15
+ ...(decision.authorizationContext === undefined
16
+ ? {}
17
+ : { authorizationContext: decision.authorizationContext }),
18
+ ...(decision.sessionReauthenticatedAt === undefined
19
+ ? {}
20
+ : { sessionReauthenticatedAt: decision.sessionReauthenticatedAt }),
21
+ ...(decision.visibleIds === undefined
22
+ ? {}
23
+ : { visibleIds: decision.visibleIds }),
24
+ ...(decision.scope === undefined ? {} : { scope: decision.scope }),
25
+ };
26
+ }
27
+ /** Runs the route's typed pipeline (parse → handler → parse) under the deadline. */
28
+ export function runRoute(definition, request, decision, timeoutMs, featureState) {
29
+ return withDeadline(definition.execute({
30
+ params: request.params,
31
+ query: request.query,
32
+ body: request.body,
33
+ subject: decision.subject,
34
+ authenticatedSubject: decision.authenticatedSubject,
35
+ requestId: requestIdOf(request),
36
+ locale: requestLocaleOf(request),
37
+ log: request.log,
38
+ ...forwardedDecision(decision),
39
+ ...(featureState === undefined ? {} : { featureState }),
40
+ }), timeoutMs, definition.path, request.log);
41
+ }
42
+ //# sourceMappingURL=run-route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-route.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/run-route.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;GAGG;AACH,SAAS,iBAAiB,CACxB,QAAuD;IAWvD,OAAO;QACL,GAAG,CAAC,QAAQ,CAAC,6BAA6B,KAAK,SAAS;YACtD,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC;gBACE,6BAA6B,EAAE,QAAQ,CAAC,6BAA6B;aACtE,CAAC;QACN,G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UAAU,CAAC,IAAI,EACf,OAAO,CAAC,GAAG,CACZ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ type OrphanLog = {
2
+ warn(obj: object, msg?: string): void;
3
+ };
4
+ /**
5
+ * Races work against a hard deadline (process-discipline bar: a hung
6
+ * handler cannot pin a socket). The timer is cleared on settle and never
7
+ * holds the event loop; on timeout the orphaned work is drained into the
8
+ * log and a `HandlerTimeoutError` propagates to the error handler (503).
9
+ */
10
+ export declare function withDeadline<T>(work: Promise<T>, ms: number, routePath: string, log: OrphanLog): Promise<T>;
11
+ export {};
12
+ //# sourceMappingURL=with-deadline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-deadline.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/with-deadline.ts"],"names":[],"mappings":"AAQA,KAAK,SAAS,GAAG;IAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AA4C3D;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAClC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,CAAC,CAAC,CAYZ"}
@@ -0,0 +1,55 @@
1
+ import { HandlerTimeoutError } from "../http-errors.js";
2
+ function startDeadline(ms, routePath) {
3
+ let timedOut = false;
4
+ let timer;
5
+ const promise = new Promise((_, reject) => {
6
+ timer = setTimeout(() => {
7
+ timedOut = true;
8
+ reject(new HandlerTimeoutError(routePath, ms));
9
+ }, ms);
10
+ // The deadline must never keep the process alive on its own.
11
+ timer.unref();
12
+ });
13
+ return {
14
+ promise,
15
+ cancel: () => {
16
+ clearTimeout(timer);
17
+ },
18
+ didTimeOut: () => timedOut,
19
+ };
20
+ }
21
+ /**
22
+ * A timed-out handler keeps running after its socket is released; its
23
+ * eventual rejection must land in the log, never as an unhandled rejection
24
+ * that kills the process.
25
+ */
26
+ function drainOrphan(work, routePath, log) {
27
+ void work.catch((error) => {
28
+ log.warn({ event: "handler.orphaned-rejection", routePath, err: error }, "timed-out handler eventually rejected");
29
+ });
30
+ }
31
+ function toError(value) {
32
+ return value instanceof Error ? value : new Error(String(value));
33
+ }
34
+ /**
35
+ * Races work against a hard deadline (process-discipline bar: a hung
36
+ * handler cannot pin a socket). The timer is cleared on settle and never
37
+ * holds the event loop; on timeout the orphaned work is drained into the
38
+ * log and a `HandlerTimeoutError` propagates to the error handler (503).
39
+ */
40
+ export async function withDeadline(work, ms, routePath, log) {
41
+ const deadline = startDeadline(ms, routePath);
42
+ try {
43
+ return await Promise.race([work, deadline.promise]);
44
+ }
45
+ catch (error) {
46
+ if (deadline.didTimeOut()) {
47
+ drainOrphan(work, routePath, log);
48
+ }
49
+ throw toError(error);
50
+ }
51
+ finally {
52
+ deadline.cancel();
53
+ }
54
+ }
55
+ //# sourceMappingURL=with-deadline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-deadline.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/with-deadline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAUxD,SAAS,aAAa,CAAC,EAAU,EAAE,SAAiB;IAClD,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,KAAiC,CAAC;IACtC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAC/C,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,QAAQ,GAAG,IAAI,CAAC;YAChB,MAAM,CAAC,IAAI,mBAAmB,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;QACjD,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,6DAA6D;QAC7D,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;I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"@dads-framework/access";
2
+ /**
3
+ * The route access vocabulary — the entire authorization surface at the HTTP
4
+ * edge. Every route declares exactly one of these three; every verb function
5
+ * requires the declaration at the type level, so an unguarded route does not
6
+ * compile (docs/architecture/authorization.md).
7
+ *
8
+ * Permission math lives in the .zed schema, never here. Typed ask constructors
9
+ * (`requires` / `requiresVisible`) live in `@dads-framework/access` and emit the
10
+ * shapes below; this module keeps session/public constructors and resource-id
11
+ * sources.
12
+ */
13
+ /** Where the resource id for a permission check comes from. */
14
+ export type ResourceIdSource = {
15
+ readonly kind: "param";
16
+ readonly name: string;
17
+ } | {
18
+ readonly kind: "body";
19
+ readonly name: string;
20
+ } | {
21
+ readonly kind: "query";
22
+ readonly name: string;
23
+ } | {
24
+ readonly kind: "header";
25
+ readonly name: string;
26
+ } | {
27
+ readonly kind: "fixed";
28
+ readonly id: string;
29
+ };
30
+ /** The resource id is the named path parameter (e.g. `fromParam("id")`). */
31
+ export declare function fromParam(name: string): ResourceIdSource;
32
+ /**
33
+ * The resource id is the named top-level body field (e.g.
34
+ * `fromBody("organizationId")`) — for flat-collection creates, where the
35
+ * parent being created into has no path segment. The body names only the
36
+ * RESOURCE side of the question; the SUBJECT is always the session/JWT
37
+ * caller — pointing at a resource you have no relationship to fails closed
38
+ * as 404. Enforcement reads the raw field before body validation: anything
39
+ * but a string resolves like a missing param (404, never a 500).
40
+ */
41
+ export declare function fromBody(name: string): ResourceIdSource;
42
+ /**
43
+ * The resource id is the named query parameter (e.g. `fromQuery("facilityId")`)
44
+ * — for flat facility-scoped surfaces where the parent is a filter, not a
45
+ * path segment. Same fail-closed rules as fromBody: non-string → 404.
46
+ */
47
+ export declare function fromQuery(name: string): ResourceIdSource;
48
+ /** Read one request-local header; repeated values are never a valid identity source. */
49
+ export declare function fromHeader(name: string): ResourceIdSource;
50
+ /**
51
+ * The resource id is a compile-time constant (e.g. `fromFixed("command")` for
52
+ * the singleton `platform:command` resource). Use when the route's permission
53
+ * check targets a well-known resource that is not in the path or body.
54
+ */
55
+ export declare function fromFixed(id: string): ResourceIdSource;
56
+ /**
57
+ * Route-level relationship check: subject must hold `permission` on the
58
+ * resource of `resourceType` identified by `resourceId`.
59
+ *
60
+ * Prefer `requires(token, source)` at call sites.
61
+ */
62
+ export type PermissionAccess = {
63
+ readonly kind: "permission";
64
+ readonly resourceType: string;
65
+ readonly permission: string;
66
+ readonly resourceId: ResourceIdSource;
67
+ readonly authorizationContext?: ResourceIdSource;
68
+ readonly authorizationContextMode?: "technical-or-business";
69
+ };
70
+ /**
71
+ * Authenticated subject required; no route-level resource check. For
72
+ * collection routes (create/list) where authorization happens inside the
73
+ * use-case — lookupResources for lists, ownership-tuple writes for creates.
74
+ */
75
+ export type SessionAccess = {
76
+ readonly kind: "session";
77
+ readonly authorizationContext?: ResourceIdSource;
78
+ readonly authorizationContextMode?: "technical-or-business";
79
+ /** Input only: the owning operation must select and authorize its explicit runtime authority. */
80
+ readonly authorizationContextInput?: ResourceIdSource;
81
+ };
82
+ /** Explicit opt-in for genuinely unauthenticated routes (health, auth). */
83
+ export type PublicAccess = {
84
+ readonly kind: "public";
85
+ };
86
+ /**
87
+ * List-route visibility: the kit asks `lookupResources` which resources of
88
+ * `resourceType` the SUBJECT can `permission`, short-circuits an empty set
89
+ * to an empty page (fail-closed — the empty-`IN ()` widening footgun cannot
90
+ * exist), and hands the handler the visible ids. Only `listRoute` admits
91
+ * this kind — a set question makes no sense on a single-resource verb, and
92
+ * the verbs' type constraints enforce that at compile time.
93
+ *
94
+ * Prefer `requiresVisible(token)` at call sites.
95
+ */
96
+ export type VisibilityAccess = {
97
+ readonly kind: "visibility";
98
+ readonly resourceType: string;
99
+ readonly permission: string;
100
+ readonly authorizationContext?: ResourceIdSource;
101
+ readonly authorizationContextMode?: "technical-or-business";
102
+ };
103
+ /**
104
+ * Record-list scoping: registration compiles the scope plan for
105
+ * `permission` on `resourceType` (refusing to boot when the record's bindings
106
+ * cannot carry it); each request asks SpiceDB the plan's scope questions once
107
+ * each and hands the handler a `ScopeAnswer` to render as SQL with
108
+ * `scopePredicate`, then re-check the page with `keepPermitted`. No empty-set
109
+ * short-circuit: the SQL decides, since one empty arm of an `any` can still
110
+ * match. Only `listRoute` admits this kind.
111
+ *
112
+ * Prefer `requiresScoped(token)` at call sites.
113
+ */
114
+ export type ScopedAccess = {
115
+ readonly kind: "scoped";
116
+ readonly resourceType: string;
117
+ readonly permission: string;
118
+ readonly authorizationContext?: ResourceIdSource;
119
+ readonly authorizationContextMode?: "technical-or-business";
120
+ };
121
+ export type RouteAccess = PermissionAccess | SessionAccess | PublicAccess | VisibilityAccess | ScopedAccess;
122
+ /** Require a relationship on the resource identified by the supplied source. */
123
+ export declare function requires(token: PermissionToken, resourceId: ResourceIdSource): PermissionAccess;
124
+ /** List IDs the caller may see for a bounded resource type. */
125
+ export declare function requiresVisible(token: PermissionToken): VisibilityAccess;
126
+ /** Filter a record list using the scope bindings in the app's access model. */
127
+ export declare function requiresScoped(token: PermissionToken): ScopedAccess;
128
+ /** Resolve explicit caller authority before checking this route's business access. */
129
+ export declare function withAuthorizationContext<Access extends Exclude<RouteAccess, PublicAccess>>(access: Access, source: ResourceIdSource): Access & {
130
+ readonly authorizationContext: ResourceIdSource;
131
+ };
132
+ /** Explicitly technical routes may omit context; any supplied context must resolve and never falls back to technical identity. */
133
+ export declare function withTechnicalOrBusinessAuthorizationContext<Access extends Exclude<RouteAccess, PublicAccess>>(access: Access, source: ResourceIdSource): Access & {
134
+ readonly authorizationContext: ResourceIdSource;
135
+ readonly authorizationContextMode: "technical-or-business";
136
+ };
137
+ export declare function requireSession(): SessionAccess;
138
+ /** Capture untrusted context data for a session-only operation; never resolve or authorize an actor here. */
139
+ export declare function withAuthorizationContextInput(access: SessionAccess, source: ResourceIdSource): SessionAccess & {
140
+ readonly authorizationContextInput: ResourceIdSource;
141
+ };
142
+ export declare function publicAccess(): PublicAccess;
143
+ //# sourceMappingURL=access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.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B,GAChB,aAAa,GACb,YAAY,GACZ,gBAAgB,GAChB,YAAY,CAAC;AAEjB,gFAAgF;AAChF,wBAAgB,QAAQ,CACtB,KAAK,EAAE,eAAe,EACtB,UAAU,EAAE,gBAAgB,GAC3B,gBAAgB,CAOlB;AAED,+DAA+D;AAC/D,wBAAgB,eAAe,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,CAMxE;AAED,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,KAAK,EAAE,eAAe,GAAG,YAAY,CAMnE;AAED,sFAAsF;AACtF,wBAAgB,wBAAwB,CACtC,MAAM,SAAS,OAAO,CAAC,WAAW,EAAE,YAAY,CAAC,EAEjD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,gBAAgB,GACvB,MAAM,GAAG;IAAE,QAAQ,CAAC,oBAAoB,EAAE,gBAAgB,CAAA;CAAE,CAa9D;AAED,kIAAkI;AAClI,wBAAgB,2CAA2C,CACzD,MAAM,SAAS,OAAO,CAAC,WAAW,EAAE,YAAY,CAAC,EAEjD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,gBAAgB,GACvB,MAAM,GAAG;IACV,QAAQ,CAAC,oBAAoB,EAAE,gBAAgB,CAAC;IAChD,QAAQ,CAAC,wBAAwB,EAAE,uBAAuB,CAAC;CAC5D,CAkBA;AAED,wBAAgB,cAAc,IAAI,aAAa,CAE9C;AAED,6GAA6G;AAC7G,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,gBAAgB,GACvB,aAAa,GAAG;IAAE,QAAQ,CAAC,yBAAyB,EAAE,gBAAgB,CAAA;CAAE,CAM1E;AAED,wBAAgB,YAAY,IAAI,YAAY,CAE3C"}
@@ -0,0 +1,97 @@
1
+ /** The resource id is the named path parameter (e.g. `fromParam("id")`). */
2
+ export function fromParam(name) {
3
+ return { kind: "param", name };
4
+ }
5
+ /**
6
+ * The resource id is the named top-level body field (e.g.
7
+ * `fromBody("organizationId")`) — for flat-collection creates, where the
8
+ * parent being created into has no path segment. The body names only the
9
+ * RESOURCE side of the question; the SUBJECT is always the session/JWT
10
+ * caller — pointing at a resource you have no relationship to fails closed
11
+ * as 404. Enforcement reads the raw field before body validation: anything
12
+ * but a string resolves like a missing param (404, never a 500).
13
+ */
14
+ export function fromBody(name) {
15
+ return { kind: "body", name };
16
+ }
17
+ /**
18
+ * The resource id is the named query parameter (e.g. `fromQuery("facilityId")`)
19
+ * — for flat facility-scoped surfaces where the parent is a filter, not a
20
+ * path segment. Same fail-closed rules as fromBody: non-string → 404.
21
+ */
22
+ export function fromQuery(name) {
23
+ return { kind: "query", name };
24
+ }
25
+ /** Read one request-local header; repeated values are never a valid identity source. */
26
+ export function fromHeader(name) {
27
+ return { kind: "header", name: name.toLowerCase() };
28
+ }
29
+ /**
30
+ * The resource id is a compile-time constant (e.g. `fromFixed("command")` for
31
+ * the singleton `platform:command` resource). Use when the route's permission
32
+ * check targets a well-known resource that is not in the path or body.
33
+ */
34
+ export function fromFixed(id) {
35
+ return { kind: "fixed", id };
36
+ }
37
+ /** Require a relationship on the resource identified by the supplied source. */
38
+ export function requires(token, resourceId) {
39
+ return {
40
+ kind: "permission",
41
+ resourceType: token.entityWireName,
42
+ permission: token.permissionName,
43
+ resourceId,
44
+ };
45
+ }
46
+ /** List IDs the caller may see for a bounded resource type. */
47
+ export function requiresVisible(token) {
48
+ return {
49
+ kind: "visibility",
50
+ resourceType: token.entityWireName,
51
+ permission: token.permissionName,
52
+ };
53
+ }
54
+ /** Filter a record list using the scope bindings in the app's access model. */
55
+ export function requiresScoped(token) {
56
+ return {
57
+ kind: "scoped",
58
+ resourceType: token.entityWireName,
59
+ permission: token.permissionName,
60
+ };
61
+ }
62
+ /** Resolve explicit caller authority before checking this route's business access. */
63
+ export function withAuthorizationContext(access, source) {
64
+ if (access.kind === "session" &&
65
+ access.authorizationContextInput !== undefined)
66
+ throw new Error("Resolved and input-only authorization contexts cannot be combined");
67
+ if (access.authorizationContextMode !== undefined)
68
+ throw new Error("Required and technical-or-business authorization contexts cannot be combined");
69
+ return { ...access, authorizationContext: source };
70
+ }
71
+ /** Explicitly technical routes may omit context; any supplied context must resolve and never falls back to technical identity. */
72
+ export function withTechnicalOrBusinessAuthorizationContext(access, source) {
73
+ if (source.kind !== "header" && source.kind !== "query")
74
+ throw new Error("Technical-or-business context requires a declared header or query");
75
+ if (access.authorizationContext !== undefined ||
76
+ (access.kind === "session" &&
77
+ access.authorizationContextInput !== undefined))
78
+ throw new Error("Technical-or-business authorization cannot be combined with another context declaration");
79
+ return {
80
+ ...access,
81
+ authorizationContext: source,
82
+ authorizationContextMode: "technical-or-business",
83
+ };
84
+ }
85
+ export function requireSession() {
86
+ return { kind: "session" };
87
+ }
88
+ /** Capture untrusted context data for a session-only operation; never resolve or authorize an actor here. */
89
+ export function withAuthorizationContextInput(access, source) {
90
+ if (access.authorizationContext !== undefined)
91
+ throw new Error("Resolved and input-only authorization contexts cannot be combined");
92
+ return { ...access, authorizationContextInput: source };
93
+ }
94
+ export function publicAccess() {
95
+ return { kind: "public" };
96
+ }
97
+ //# sourceMappingURL=access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.js","sourceRoot":"","sources":["../../../src/lib/route/access.ts"],"names":[],"mappings":"AAsBA,4EAA4E;AAC5E,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACjC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACjC,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,EAAE,IAAI,EAA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AAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO;QACrD,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,IACE,MAAM,CAAC,oBAAoB,KAAK,SAAS;QACzC,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS;YACxB,MAAM,CAAC,yBAAyB,KAAK,SAAS,CAAC;QAEjD,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;IACJ,OAAO;QACL,GAAG,MAAM;QACT,oBAAoB,EAAE,MAAM;QAC5B,wBAAwB,EAAE,uBAAuB;KAClD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC7B,CAAC;AAED,6GAA6G;AAC7G,MAAM,UAAU,6BAA6B,CAC3C,MAAqB,EACrB,MAAwB;IAExB,IAAI,MAAM,CAAC,oBAAoB,KAAK,SAAS;QAC3C,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,OAAO,EAAE,GAAG,MAAM,EAAE,yBAAyB,EAAE,MAAM,EAAE,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Route capabilities — the kit's answer to middleware (design locked with
3
+ * Bryton, 2026-07-09): NAMED, TYPED fields instead of anonymous hook
4
+ * chains. Every capability is declared data, visible on the route, resolved
5
+ * through a three-rung ladder:
6
+ *
7
+ * route field > group capabilities > app default (registerRoutes)
8
+ *
9
+ * "What applies to this route" is answerable by reading at most three named
10
+ * places. Capabilities grow here BY NEED, each with an engine and tests in
11
+ * the kit — never as user-supplied functions.
12
+ */
13
+ export type RateLimitCapability = {
14
+ /** Requests allowed per minute for one caller (subject id, else ip). */
15
+ readonly perMinute: number;
16
+ } | "unlimited";
17
+ /**
18
+ * What a plant-side copy of the API does with this route. Set only by a
19
+ * applications that run a second deployment of the API.
20
+ * served the site answers it itself
21
+ * write_door the site applies the change locally and sends it to the cloud
22
+ * cloud_only the cloud owns it. The site refuses a cloud_only read or
23
+ * write with 409 after its access check (unless the site build
24
+ * drops the route, which then answers 404); a cloud_only GET is
25
+ * never answered from the site's own copy
26
+ */
27
+ export type SiteServing = "served" | "write_door" | "cloud_only";
28
+ /**
29
+ * Why a site never answers a `cloud_only` route. The same idea as a table
30
+ * sync label's cloud-only `reason`, in the words a route needs:
31
+ * STAFF_TOOLS an application staff tool
32
+ * COMPANY_DESK company-wide setup done from the office, not a plant's
33
+ * shift work
34
+ * NEEDS_INTERNET talks to an outside service (email, SSO, payments,
35
+ * storage), so a site cannot answer it offline
36
+ * FLEET the cloud's end of a link to sites and devices
37
+ * (enrollment, check-in, the sync feed, releases)
38
+ * NOT_YET should work at a site; `ticket` names the work
39
+ */
40
+ export type CloudOnlyRouteReason = "STAFF_TOOLS" | "COMPANY_DESK" | "NEEDS_INTERNET" | "FLEET" | "NOT_YET";
41
+ /**
42
+ * The reason on a `cloud_only` label: one closed `reason` plus one plain
43
+ * sentence a reviewer can read. `NOT_YET` names the ticket that will make
44
+ * the route work at a site, so that backlog is one catalog query.
45
+ */
46
+ export type CloudOnlyRouteLabel = {
47
+ readonly reason: Exclude<CloudOnlyRouteReason, "NOT_YET">;
48
+ readonly why: string;
49
+ readonly ticket?: never;
50
+ } | {
51
+ readonly reason: "NOT_YET";
52
+ readonly why: string;
53
+ readonly ticket: `${string}-${number}`;
54
+ };
55
+ export type RouteCapabilities = {
56
+ /**
57
+ * Per-caller request budget, enforced after access (a denied caller never
58
+ * consumes budget knowledge). Per-replica accounting — a distributed
59
+ * limiter is a deliberate upgrade when multi-instance deploys arrive.
60
+ */
61
+ readonly rateLimit?: RateLimitCapability;
62
+ /** Reject a stale client feature-state hash before this flag-dependent write runs. */
63
+ readonly featureStateWrite?: "sensitive";
64
+ /**
65
+ * Let this write run while the caller's feature preview refuses writes —
66
+ * for the routes that start, change and end the preview itself.
67
+ */
68
+ readonly writesDuringFeaturePreview?: "allowed";
69
+ /**
70
+ * The named machine credential this route accepts INSTEAD of user
71
+ * sessions: its caller resolves only through
72
+ * `registerRoutes({ machineCredentials })[name]`, never through the
73
+ * session resolver. Resolved from the route or its group only — the app rung never
74
+ * supplies it (registration throws). A route without it never sees
75
+ * machine credentials.
76
+ */
77
+ readonly machineCredential?: string;
78
+ /**
79
+ * What a site server does with this route. Resolved from the route or its
80
+ * group only; the app rung never supplies it (registration throws). The kit
81
+ * only carries it; no default, so `undefined` means "not labelled".
82
+ */
83
+ readonly site?: SiteServing;
84
+ /**
85
+ * Why a `cloud_only` route stays in the cloud. It travels with `site`: a
86
+ * route that overrides its group's label never inherits the group's
87
+ * reason, and a route may give its own reason under its group's label.
88
+ * The app rung never supplies it (registration throws). The product
89
+ * decides whether it is required.
90
+ */
91
+ readonly cloudOnly?: CloudOnlyRouteLabel;
92
+ };
93
+ /**
94
+ * route > group > app, field by field, except `cloudOnly`: when a more
95
+ * specific rung than the reason's overrides `site` with another label, the
96
+ * reason explains a label the route no longer has, so it is dropped. A rung
97
+ * that repeats `cloud_only` keeps the reason.
98
+ */
99
+ export declare function resolveCapabilities(app: RouteCapabilities | undefined, group: RouteCapabilities | undefined, route: RouteCapabilities | undefined): RouteCapabilities;
100
+ //# sourceMappingURL=capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../src/lib/route/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,MAAM,mBAAmB,GAC3B;IACE,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,GACD,WAAW,CAAC;AAEhB;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,YAAY,GAAG,YAAY,CAAC;AAEjE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,oBAAoB,GAC9B,aAAa,GAAG,cAAc,GAAG,gBAAgB,GAAG,OAAO,GAAG,SAAS,CAAC;AAE1E;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAC3B;IACE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;IAC1D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC;CACzB,GACD;IACE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;CACxC,CAAC;AAEN,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,mBAAmB,CAAC;IACzC,sFAAsF;IACtF,QAAQ,CAAC,iBAAiB,CAAC,EAAE,WAAW,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,0BAA0B,CAAC,EAAE,SAAS,CAAC;IAChD;;;;;;;OAOG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC;IAC5B;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,mBAAmB,CAAC;CAC1C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,iBAAiB,GAAG,SAAS,EAClC,KAAK,EAAE,iBAAiB,GAAG,SAAS,EACpC,KAAK,EAAE,iBAAiB,GAAG,SAAS,GACnC,iBAAiB,CAUnB"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Route capabilities — the kit's answer to middleware (design locked with
3
+ * Bryton, 2026-07-09): NAMED, TYPED fields instead of anonymous hook
4
+ * chains. Every capability is declared data, visible on the route, resolved
5
+ * through a three-rung ladder:
6
+ *
7
+ * route field > group capabilities > app default (registerRoutes)
8
+ *
9
+ * "What applies to this route" is answerable by reading at most three named
10
+ * places. Capabilities grow here BY NEED, each with an engine and tests in
11
+ * the kit — never as user-supplied functions.
12
+ */
13
+ /**
14
+ * route > group > app, field by field, except `cloudOnly`: when a more
15
+ * specific rung than the reason's overrides `site` with another label, the
16
+ * reason explains a label the route no longer has, so it is dropped. A rung
17
+ * that repeats `cloud_only` keeps the reason.
18
+ */
19
+ export function resolveCapabilities(app, group, route) {
20
+ const merged = { ...app, ...group, ...route };
21
+ const rungs = [app, group, route];
22
+ const siteRung = lastRungSetting(rungs, (rung) => rung.site !== undefined);
23
+ const reasonRung = lastRungSetting(rungs, (rung) => rung.cloudOnly !== undefined);
24
+ const labelOverridden = reasonRung < siteRung && merged.site !== "cloud_only";
25
+ return labelOverridden ? withoutCloudOnlyLabel(merged) : merged;
26
+ }
27
+ /** The capabilities with the cloud-only reason removed, not set to undefined. */
28
+ function withoutCloudOnlyLabel(capabilities) {
29
+ const copy = { ...capabilities };
30
+ delete copy.cloudOnly;
31
+ return copy;
32
+ }
33
+ /** The index of the most specific rung for which `sets` holds; -1 for none. */
34
+ function lastRungSetting(rungs, sets) {
35
+ let found = -1;
36
+ rungs.forEach((rung, index) => {
37
+ if (rung !== undefined && sets(rung))
38
+ found = index;
39
+ });
40
+ return found;
41
+ }
42
+ //# sourceMappingURL=capabilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../src/lib/route/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA4FH;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAkC,EAClC,KAAoC,EACpC,KAAoC;IAEpC,MAAM,MAAM,GAAsB,EAAE,GAAG,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC;IACjE,MAAM,KAAK,GAAG,CAAC,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