@dads-framework/http 0.0.0-stage → 0.2.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 +295 -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 +79 -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 +77 -0
  111. package/dist/lib/request-pipeline/feature-state-preview.js.map +1 -0
  112. package/dist/lib/request-pipeline/feature-state.d.ts +70 -0
  113. package/dist/lib/request-pipeline/feature-state.d.ts.map +1 -0
  114. package/dist/lib/request-pipeline/feature-state.js +46 -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 +217 -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 +57 -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 +100 -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
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bryton Cooper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,296 @@
1
- # Temporary Holding Version
1
+ # @dads-framework/http — HTTP routes
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Ship an endpoint with one declaration for the input schema, access policy,
4
+ handler, response, and generated OpenAPI. Define the route in its domain,
5
+ register it in the API, and test both allowed and denied requests. This
6
+ package owns the Fastify integration.
7
+
8
+ ## Try it
9
+
10
+ In a Node.js 22+ project, install the packages.
11
+
12
+ ```sh
13
+ npm install @dads-framework/http zod
14
+ ```
15
+
16
+ Save this as `example.mts` and run `node --experimental-strip-types example.mts`.
17
+
18
+ <!-- dads:check-example -->
19
+
20
+ ```ts
21
+ import {
22
+ createHttpApp,
23
+ getRoute,
24
+ publicAccess,
25
+ registerRoutes,
26
+ routeGroup,
27
+ } from "@dads-framework/http";
28
+ import { z } from "zod";
29
+
30
+ const greeting = getRoute({
31
+ path: "/greeting",
32
+ summary: "Read a public greeting",
33
+ access: publicAccess(),
34
+ response: z.object({ message: z.string() }),
35
+ handler: () => ({ message: "Hello" }),
36
+ });
37
+
38
+ const app = await createHttpApp({
39
+ nodeEnv: "test",
40
+ trustedOrigins: [],
41
+ logger: false,
42
+ });
43
+ try {
44
+ registerRoutes(app, {
45
+ routes: routeGroup("Greetings", [greeting]),
46
+ subjects: { resolve: () => Promise.resolve(null) },
47
+ authorization: { check: () => Promise.resolve(false) },
48
+ });
49
+ const response = await app.inject({ method: "GET", url: "/greeting" });
50
+ console.log(response.statusCode, response.body);
51
+ } finally {
52
+ await app.close();
53
+ }
54
+ ```
55
+
56
+ The injected request prints `200 {"data":{"message":"Hello"}}`. It runs
57
+ through the HTTP app without opening a port.
58
+
59
+ In the generated app, route declarations live with the owning domain.
60
+ `assembly/start-app.ts` registers them with identity and authorization.
61
+ [Notes routes](../../../apps/kit-workbench/domains/notes/server/routes.ts) · [Starter HTTP wiring](../../../apps/kit-workbench/assembly/start-app.ts)
62
+
63
+ ## Define a route — the verb IS the function
64
+
65
+ ```ts
66
+ import { permissionToken } from "@dads-framework/access";
67
+ import { getRoute, requires, fromParam } from "@dads-framework/http";
68
+ import { z } from "zod";
69
+
70
+ // In a real route this comes from the owning domain's contract lib.
71
+ const organizationSchema = z.object({ id: z.uuid(), name: z.string() });
72
+
73
+ export const getOrganization = getRoute({
74
+ route: { method: "GET", template: "/organizations/:id" },
75
+ summary: "Get an organization",
76
+ access: requires(
77
+ permissionToken("organizations/organization", "view"),
78
+ fromParam("id"),
79
+ ),
80
+ params: z.object({ id: z.uuid() }),
81
+ response: organizationSchema, // the DATA shape from the contract lib
82
+ handler: ({ params }) => ({ id: params.id, name: "Example Organization" }),
83
+ });
84
+ ```
85
+
86
+ One function per verb, each carrying its own compile rules:
87
+
88
+ | Verb | Rules the compiler enforces |
89
+ | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
90
+ | `getRoute` | A single read: no `body` key, no ARRAY responses (collections are `listRoute`); always 200 |
91
+ | `listRoute` | THE collection verb: query must extend `paginationQuerySchema`, handler returns `{ items, total }`, the kit builds `{ data, meta }` — pagination is compile-enforced |
92
+ | `postRoute` | 201 by default (`status: 200` for command-style posts) |
93
+ | `postNoContentRoute` | A guarded POST that reports and learns nothing back: no response schema, handler returns nothing, 204 |
94
+ | `patchRoute` / `putRoute` | `body` is REQUIRED; no query/meta/status; always 200 |
95
+ | `deleteRoute` | THE no-content shape — no response schema, handler returns nothing, 204; optional request `body` when path params alone are not enough |
96
+
97
+ Handlers may be sync or async — the return type is `X | Promise<X>` and the
98
+ kit awaits either, so you only write `async` when you `await` inside (and
99
+ forgetting it there is a compile error, not a runtime bug).
100
+
101
+ ## Groups — the only door to registration
102
+
103
+ Verbs return **blueprints**; `registerRoutes` accepts only grouped routes,
104
+ so forgetting the group is a compile error:
105
+
106
+ ```ts
107
+ export function createOrganizationsRoutes(deps: Deps): HttpRoute[] {
108
+ return routeGroup("Organizations", [
109
+ listRoute({ ... }),
110
+ getRoute({ ... }),
111
+ ]);
112
+ }
113
+ ```
114
+
115
+ The tag is stamped once per group (it is not a route field). Groups compose
116
+ — a domain owning two tags returns `[...groupA, ...groupB]`.
117
+
118
+ ## Capabilities — named fields, never middleware
119
+
120
+ Cross-cutting behavior is declared data resolved through a three-rung
121
+ ladder — **route field > group capabilities > app default**
122
+ (`registerRoutes({ capabilities })`) — so "what applies to this route" is
123
+ answerable by reading at most three named places. There are no middleware
124
+ arrays and never will be; true universals live in the kit pipeline itself.
125
+
126
+ ```ts
127
+ routeGroup("Auth", { rateLimit: { perMinute: 30 } }, [
128
+ postRoute({ ..., capabilities: { rateLimit: { perMinute: 5 } } }), // route wins
129
+ getRoute({ ... }), // inherits the group's 30/min
130
+ ]);
131
+ ```
132
+
133
+ First shipped capability: `rateLimit` (per-caller fixed window, per
134
+ replica; 429 + `retry-after` once spent, budget consumed only AFTER access
135
+ so denied callers learn nothing). `machineCredential: "<name>"` (route or
136
+ group only; the app rung throws) makes the route resolve its caller only
137
+ through `registerRoutes({ machineCredentials })[name]` instead of sessions;
138
+ a missing resolver or a public route throws `HttpWiringError` at registration.
139
+ Capabilities grow by need — each lands with an engine and tests in the kit.
140
+
141
+ The kit does the rest: parses `params`/`query`/`body` (bad input → 400 with
142
+ field issues), runs your handler, parses the return through `response`
143
+ (drift → loud 500), and wraps it in the `{ data }` envelope. You never
144
+ touch statuses, envelopes, or serialization.
145
+
146
+ **The compiler is the reviewer.** These do not compile: a route without
147
+ `access`; a GET with a body; a PATCH without one; a `params` schema that
148
+ doesn't cover the path's `:params`; a handler return that doesn't satisfy
149
+ `response`; touching `subject` as non-null on a public route.
150
+
151
+ ## The access vocabulary — all of it
152
+
153
+ | Constructor | Meaning | Handler's `subject` |
154
+ | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------- |
155
+ | `requires(token, fromParam("id"))` | Relationship check on the resource; denied → **404** (existence never leaks), anon 401 | `SubjectRef` |
156
+ | `… fromBody("organizationId")` / `fromQuery("workspaceId")` / `fromFixed("app")` | Same check; id from body field, query param, or a compile-time constant (singleton platform) | `SubjectRef` |
157
+ | `requireSession()` | Authenticated caller; the mutation/query owns authorization (lists/creates) | `SubjectRef` |
158
+ | `publicAccess()` | Explicitly unauthenticated (health, auth) | `SubjectRef \| null` |
159
+
160
+ ## Variants
161
+
162
+ - **Streams (SSE, downloads, multipart)**: `defineRawRoute({ ..., method, openapi,
163
+ handler: ({ request, reply }) => ... })` — the ONE escape hatch. Same
164
+ `access` requirement and error envelope; no handler deadline (streams own
165
+ their lifetime); its hand-written `openapi` operation lands in the
166
+ artifact marked `x-raw-route: true`. The bar for using it: the kit can't
167
+ express what you need AND growing the kit was considered first — never
168
+ import `fastify` in a domain.
169
+
170
+ ## Errors
171
+
172
+ Throw typed `DomainError`s from domain code (`notFound`, `conflict`,
173
+ `validation`, `forbidden` from `@dads-framework/errors`); the kit maps kinds to
174
+ statuses in one place. Kit-produced failures: request validation → 400,
175
+ response drift / wiring bugs → masked 500 (logged loud), handler past its
176
+ deadline → 503 `HANDLER_TIMEOUT`. Unknown errors are always masked — no
177
+ internals in bodies, correlation id included.
178
+
179
+ ## Process discipline (defaults you can raise, never disable)
180
+
181
+ `createHttpApp` sets: body limit 1 MiB, request/connection/keep-alive
182
+ timeouts, `trustProxy` as a hop count (`trustedProxyHops`, default 0 — never
183
+ trust-all XFF; CloudFront + ALB is 2 so `request.ip` is the viewer),
184
+ request-id correlation (inbound `x-request-id` honored, always
185
+ echoed), credential-redacting pino, CORS for trusted origins. Every typed
186
+ route runs under a hard handler deadline — a hung handler answers 503 and
187
+ frees its socket; its orphaned promise drains into the log.
188
+
189
+ Given a `requestLog` lookup and an `apiRelease` stamp, `createHttpApp` also
190
+ captures one `request_log` row per answer from an `onResponse` hook — routes,
191
+ 404s, the 426 gate, 429s, error-handler responses, and protocol mounts alike.
192
+ Nothing per route: it is a pipeline universal, successful reads are skipped,
193
+ and capture can never change a response. What is stored, and for how long:
194
+ observability.
195
+
196
+ ## Testing
197
+
198
+ ```ts
199
+ import { buildTestApp, dataBodyOf } from "@dads-framework/http/testing";
200
+ import { FakeAuthorization } from "@dads-framework/access/testing";
201
+ import { routeGroup } from "@dads-framework/http";
202
+
203
+ const id = "ca498064-95f7-4334-8d66-12703cd044a9";
204
+ const authorization = new FakeAuthorization();
205
+ authorization.seed({
206
+ resource: { type: "organizations/organization", id },
207
+ subject: { type: "user", id: "u1" },
208
+ relation: "view",
209
+ });
210
+
211
+ const app = await buildTestApp({
212
+ routes: routeGroup("Organizations", [getOrganization]),
213
+ authorization,
214
+ });
215
+ const res = await app.inject({
216
+ method: "GET",
217
+ url: `/organizations/${id}`,
218
+ headers: { "x-test-subject": "u1" },
219
+ });
220
+ console.log(dataBodyOf(res, organizationSchema).id); // ca498064-95f7-4334-8d66-12703cd044a9
221
+ await app.close();
222
+ ```
223
+
224
+ `buildTestApp` never opens a port (`listen` does not exist on it — pinned
225
+ by a type test). Default subject = `x-test-subject` header; default
226
+ authorization denies everything until you pass a seeded `FakeAuthorization`.
227
+ Parse bodies with `dataBodyOf`/`listBodyOf`/`errorBodyOf` (or `bodyOf` for
228
+ an arbitrary schema) — `res.json()` is `any` and defeats the type walls.
229
+
230
+ ## Folder story
231
+
232
+ - `lib/route/` — authoring: one file per verb, `route-group`, `access`, `capabilities`, `define-raw-route`, `sse-route`, and `route-definition` (parse → handler → parse).
233
+ - `lib/create-http-app.ts` — builds the Fastify instance (logger, CORS, timeouts, request-id, trustedProxyHops).
234
+ - `lib/request-pipeline/` — `register-routes` (enforce → run under deadline → envelope), `enforce-access`, `with-deadline`, `error-handler`, `envelope`, `rate-limit`, `request-id`.
235
+ - `lib/openapi/` — the generated document. The kit knows how to convert a route table, never which domains exist: nothing here imports a domain contract lib (`@dads-framework/contract` is the kit's own vocabulary). The parity golden test that pins the generated document against the committed artifact needs real domain schemas, so it lives with the composition root that already knows them.
236
+ - `lib/request-log/` — the captured row: `request-record` (pure builder plus the header allowlist), `request-outcome` (what the pipeline learned and the response no longer shows), `capture-request-record` (the `onResponse` hook), `request-log-sink` (the seam `@dads-framework/audit` implements).
237
+ - `lib/http-errors.ts` — typed failures this library produces while running a route.
238
+ - `src/testing/` — `buildTestApp` + typed inject-response helpers.
239
+
240
+ ## Protocol mounts — someone else's wire spec
241
+
242
+ A surface that implements another party's protocol (Better Auth's
243
+ `/api/auth/*`, the remote MCP endpoint) is not a route: it is a fetch-style
244
+ handler mounted whole. Import the bridge from [`@dads-framework/http/protocol-mounts`](./src/protocol-mounts/README.md) in the API composition root.
245
+ `mountFetchHandler` is the one bridge for that — every content type arrives as
246
+ raw bytes, the request crosses to a WHATWG `Request` whose clones never share
247
+ a stream (`to-web-request.ts`, the Node 22 undici clone trap), and the
248
+ handler's `Response` is copied back status, headers and body. Register it with
249
+ a literal prefix so the `protocol-mount boundary` wall can read it; an
250
+ `extraSetCookies` hook appends cookies to one answer, which is how an
251
+ API can clear an authorization-consistency cookie on sign-out.
252
+
253
+ ```ts
254
+ await app.register(mountFetchHandler(auth), { prefix: "/api/auth" });
255
+ ```
256
+
257
+ ## Compose authorization for lists
258
+
259
+ Use `requires`, `requiresVisible`, or `requiresScoped` from
260
+ `@dads-framework/http` with an access permission token. Pass the app's
261
+ `accessModel` as `registerRoutes`'s `accessModel` option for visibility and
262
+ scoped routes. Registration refuses an omitted model or a missing list
263
+ resource definition. Record routes use `requiresScoped` with scope bindings. Tests can pass the same
264
+ model and a fake lookup port to `buildTestApp`.
265
+
266
+ Set `currentTraceId` and `requestTrace` on `createHttpApp` to correlate request records and annotate the active request span. The observer receives the request ID and the audit actor kind.
267
+
268
+ ## Feature state previews
269
+
270
+ When a host configures `featureState.preview`, the resolver receives the
271
+ preview ID, authenticated subject, effective subject, and feature-state
272
+ context. By default the context comes from a request header. The host verifies the effective identity and context before
273
+ returning a preview. Set `featureState.contextFromRequest` to derive context
274
+ from matched route parameters instead of the caller’s header. Preview responses
275
+ are private and non-cacheable. A resolver may return a `scopeKey` for its feature
276
+ evaluator to match against
277
+ the context being evaluated.
278
+
279
+ ## What it refuses to do
280
+
281
+ Application code supplies identity, access policies, and business handlers. The HTTP kit enforces the declared route boundary and owns transport.
282
+
283
+ A public POST that only appends internal telemetry can declare
284
+ `resourcePolicy: { kind: "resource-free", purpose: "append-only-telemetry" }`.
285
+ Use status `200` and a bounded body schema. Return an acknowledgement of the
286
+ report. The telemetry entries remain internal to the application.
287
+
288
+ `mountFetchHandler` implements the shared `FetchHandler` protocol boundary.
289
+ Its transport conformance runs over a real Fastify socket and against the
290
+ contract package's independent in-memory Fetch host. The shared proof covers
291
+ GET and POST beneath a prefix. Fastify-specific hooks and limits have their own
292
+ tests.
293
+
294
+ A subject resolver can read the matched route's decoded `params` when its
295
+ session policy depends on a route parameter. Validate those values before
296
+ using them to select a policy.