@dads-framework/http 0.1.0 → 0.3.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 (143) hide show
  1. package/README.md +131 -16
  2. package/dist/health/index.d.ts +2 -0
  3. package/dist/health/index.d.ts.map +1 -0
  4. package/dist/health/index.js +2 -0
  5. package/dist/health/index.js.map +1 -0
  6. package/dist/health/lib/health.route-handlers.d.ts +14 -0
  7. package/dist/health/lib/health.route-handlers.d.ts.map +1 -0
  8. package/dist/health/lib/health.route-handlers.js +19 -0
  9. package/dist/health/lib/health.route-handlers.js.map +1 -0
  10. package/dist/health/lib/health.routes.d.ts +6 -0
  11. package/dist/health/lib/health.routes.d.ts.map +1 -0
  12. package/dist/health/lib/health.routes.js +28 -0
  13. package/dist/health/lib/health.routes.js.map +1 -0
  14. package/dist/health/lib/health.schemas.d.ts +10 -0
  15. package/dist/health/lib/health.schemas.d.ts.map +1 -0
  16. package/dist/health/lib/health.schemas.js +10 -0
  17. package/dist/health/lib/health.schemas.js.map +1 -0
  18. package/dist/http.tsbuildinfo +1 -1
  19. package/dist/lib/create-http-app.d.ts +1 -1
  20. package/dist/lib/create-http-app.d.ts.map +1 -1
  21. package/dist/lib/create-http-app.js +2 -2
  22. package/dist/lib/create-http-app.js.map +1 -1
  23. package/dist/lib/openapi/build-document.js +1 -1
  24. package/dist/lib/openapi/build-document.js.map +1 -1
  25. package/dist/lib/request-log/authorization-warning-faults.d.ts +1 -1
  26. package/dist/lib/request-log/authorization-warning-faults.d.ts.map +1 -1
  27. package/dist/lib/request-log/capture-request-record.d.ts +1 -1
  28. package/dist/lib/request-log/capture-request-record.d.ts.map +1 -1
  29. package/dist/lib/request-log/capture-request-record.js +2 -2
  30. package/dist/lib/request-log/capture-request-record.js.map +1 -1
  31. package/dist/lib/request-log/request-outcome.d.ts +1 -1
  32. package/dist/lib/request-log/request-outcome.d.ts.map +1 -1
  33. package/dist/lib/request-log/request-record.d.ts +3 -3
  34. package/dist/lib/request-log/request-record.d.ts.map +1 -1
  35. package/dist/lib/request-log/request-record.js +1 -1
  36. package/dist/lib/request-log/request-record.js.map +1 -1
  37. package/dist/lib/request-pipeline/carry-audit-actor.d.ts +1 -1
  38. package/dist/lib/request-pipeline/carry-audit-actor.d.ts.map +1 -1
  39. package/dist/lib/request-pipeline/carry-audit-actor.js +1 -1
  40. package/dist/lib/request-pipeline/carry-audit-actor.js.map +1 -1
  41. package/dist/lib/request-pipeline/enforce-access.d.ts +9 -9
  42. package/dist/lib/request-pipeline/enforce-access.d.ts.map +1 -1
  43. package/dist/lib/request-pipeline/enforce-access.js.map +1 -1
  44. package/dist/lib/request-pipeline/enforce-scope.d.ts +2 -1
  45. package/dist/lib/request-pipeline/enforce-scope.d.ts.map +1 -1
  46. package/dist/lib/request-pipeline/enforce-scope.js.map +1 -1
  47. package/dist/lib/request-pipeline/envelope.d.ts +1 -1
  48. package/dist/lib/request-pipeline/error-handler.d.ts +1 -1
  49. package/dist/lib/request-pipeline/error-handler.d.ts.map +1 -1
  50. package/dist/lib/request-pipeline/error-handler.js +2 -2
  51. package/dist/lib/request-pipeline/error-handler.js.map +1 -1
  52. package/dist/lib/request-pipeline/feature-state-preview.d.ts +13 -3
  53. package/dist/lib/request-pipeline/feature-state-preview.d.ts.map +1 -1
  54. package/dist/lib/request-pipeline/feature-state-preview.js +20 -4
  55. package/dist/lib/request-pipeline/feature-state-preview.js.map +1 -1
  56. package/dist/lib/request-pipeline/feature-state.d.ts +6 -0
  57. package/dist/lib/request-pipeline/feature-state.d.ts.map +1 -1
  58. package/dist/lib/request-pipeline/feature-state.js +10 -2
  59. package/dist/lib/request-pipeline/feature-state.js.map +1 -1
  60. package/dist/lib/request-pipeline/refuse-visible-record-list.d.ts +6 -10
  61. package/dist/lib/request-pipeline/refuse-visible-record-list.d.ts.map +1 -1
  62. package/dist/lib/request-pipeline/refuse-visible-record-list.js +9 -14
  63. package/dist/lib/request-pipeline/refuse-visible-record-list.js.map +1 -1
  64. package/dist/lib/request-pipeline/register-routes.d.ts.map +1 -1
  65. package/dist/lib/request-pipeline/register-routes.js +5 -3
  66. package/dist/lib/request-pipeline/register-routes.js.map +1 -1
  67. package/dist/lib/request-pipeline/request-id.d.ts.map +1 -1
  68. package/dist/lib/request-pipeline/request-id.js +1 -1
  69. package/dist/lib/request-pipeline/request-id.js.map +1 -1
  70. package/dist/lib/request-pipeline/request-locale.d.ts +1 -1
  71. package/dist/lib/request-pipeline/request-locale.d.ts.map +1 -1
  72. package/dist/lib/request-pipeline/request-locale.js +1 -1
  73. package/dist/lib/request-pipeline/request-locale.js.map +1 -1
  74. package/dist/lib/request-pipeline/request-trace.d.ts +1 -1
  75. package/dist/lib/request-pipeline/request-trace.d.ts.map +1 -1
  76. package/dist/lib/route/list-route.d.ts +1 -1
  77. package/dist/lib/route/list-route.d.ts.map +1 -1
  78. package/dist/lib/route/list-route.js +1 -1
  79. package/dist/lib/route/list-route.js.map +1 -1
  80. package/dist/lib/route/route-definition.d.ts +2 -2
  81. package/dist/lib/route/route-definition.d.ts.map +1 -1
  82. package/dist/lib/route/route-execution.d.ts +1 -1
  83. package/dist/lib/route/route-execution.d.ts.map +1 -1
  84. package/dist/lib/route/sse-route.d.ts.map +1 -1
  85. package/dist/lib/route/sse-route.js +1 -1
  86. package/dist/lib/route/sse-route.js.map +1 -1
  87. package/dist/protocol-mounts/lib/mcp/mcp-endpoint.js +1 -1
  88. package/dist/protocol-mounts/lib/mcp/mcp-endpoint.js.map +1 -1
  89. package/dist/protocol-mounts/lib/mcp/mcp-methods.js +1 -1
  90. package/dist/protocol-mounts/lib/mcp/mcp-methods.js.map +1 -1
  91. package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.d.ts +5 -3
  92. package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.d.ts.map +1 -1
  93. package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.js +3 -1
  94. package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.js.map +1 -1
  95. package/dist/telemetry/core/index.d.ts +2 -0
  96. package/dist/telemetry/core/index.d.ts.map +1 -0
  97. package/dist/telemetry/core/index.js +2 -0
  98. package/dist/telemetry/core/index.js.map +1 -0
  99. package/dist/telemetry/core/request-trace-attributes.d.ts +8 -0
  100. package/dist/telemetry/core/request-trace-attributes.d.ts.map +1 -0
  101. package/dist/telemetry/core/request-trace-attributes.js +10 -0
  102. package/dist/telemetry/core/request-trace-attributes.js.map +1 -0
  103. package/dist/telemetry/core/testing/in-memory-request-trace.d.ts +7 -0
  104. package/dist/telemetry/core/testing/in-memory-request-trace.d.ts.map +1 -0
  105. package/dist/telemetry/core/testing/in-memory-request-trace.js +12 -0
  106. package/dist/telemetry/core/testing/in-memory-request-trace.js.map +1 -0
  107. package/dist/telemetry/core/testing/index.d.ts +3 -0
  108. package/dist/telemetry/core/testing/index.d.ts.map +1 -0
  109. package/dist/telemetry/core/testing/index.js +3 -0
  110. package/dist/telemetry/core/testing/index.js.map +1 -0
  111. package/dist/telemetry/core/testing/trace-attribution-conformance.d.ts +9 -0
  112. package/dist/telemetry/core/testing/trace-attribution-conformance.d.ts.map +1 -0
  113. package/dist/telemetry/core/testing/trace-attribution-conformance.js +16 -0
  114. package/dist/telemetry/core/testing/trace-attribution-conformance.js.map +1 -0
  115. package/dist/telemetry/index.d.ts +2 -0
  116. package/dist/telemetry/index.d.ts.map +1 -0
  117. package/dist/telemetry/index.js +2 -0
  118. package/dist/telemetry/index.js.map +1 -0
  119. package/dist/telemetry/node-telemetry.d.ts +3 -0
  120. package/dist/telemetry/node-telemetry.d.ts.map +1 -0
  121. package/dist/telemetry/node-telemetry.js +36 -0
  122. package/dist/telemetry/node-telemetry.js.map +1 -0
  123. package/dist/telemetry/otlp-trace-endpoint.d.ts +3 -0
  124. package/dist/telemetry/otlp-trace-endpoint.d.ts.map +1 -0
  125. package/dist/telemetry/otlp-trace-endpoint.js +27 -0
  126. package/dist/telemetry/otlp-trace-endpoint.js.map +1 -0
  127. package/dist/telemetry/privacy-filtered-exporter.d.ts +4 -0
  128. package/dist/telemetry/privacy-filtered-exporter.d.ts.map +1 -0
  129. package/dist/telemetry/privacy-filtered-exporter.js +34 -0
  130. package/dist/telemetry/privacy-filtered-exporter.js.map +1 -0
  131. package/dist/telemetry/request-trace-conformance.test-support.d.ts +13 -0
  132. package/dist/telemetry/request-trace-conformance.test-support.d.ts.map +1 -0
  133. package/dist/telemetry/request-trace-conformance.test-support.js +48 -0
  134. package/dist/telemetry/request-trace-conformance.test-support.js.map +1 -0
  135. package/dist/telemetry/start-telemetry.d.ts +14 -0
  136. package/dist/telemetry/start-telemetry.d.ts.map +1 -0
  137. package/dist/telemetry/start-telemetry.js +11 -0
  138. package/dist/telemetry/start-telemetry.js.map +1 -0
  139. package/dist/telemetry/trace-request.d.ts +4 -0
  140. package/dist/telemetry/trace-request.d.ts.map +1 -0
  141. package/dist/telemetry/trace-request.js +12 -0
  142. package/dist/telemetry/trace-request.js.map +1 -0
  143. package/package.json +63 -7
package/README.md CHANGED
@@ -1,8 +1,64 @@
1
1
  # @dads-framework/http — HTTP routes
2
2
 
3
- The one way routes exist. You should be able to ship an endpoint from this
4
- page alone — no Fastify knowledge required (Fastify is an implementation
5
- detail inside this lib; importing it anywhere else is banned).
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)
6
62
 
7
63
  ## Define a route — the verb IS the function
8
64
 
@@ -114,7 +170,7 @@ handler: ({ request, reply }) => ... })` — the ONE escape hatch. Same
114
170
  ## Errors
115
171
 
116
172
  Throw typed `DomainError`s from domain code (`notFound`, `conflict`,
117
- `validation`, `forbidden` from `@dads-framework/errors`); the kit maps kinds to
173
+ `validation`, `forbidden` from `@dads-framework/core/errors`); the kit maps kinds to
118
174
  statuses in one place. Kit-produced failures: request validation → 400,
119
175
  response drift / wiring bugs → masked 500 (logged loud), handler past its
120
176
  deadline → 503 `HANDLER_TIMEOUT`. Unknown errors are always masked — no
@@ -140,22 +196,29 @@ observability.
140
196
  ## Testing
141
197
 
142
198
  ```ts
143
- import {
144
- buildTestApp,
145
- dataBodyOf,
146
- errorBodyOf,
147
- } from "@dads-framework/http/testing";
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
+ });
148
210
 
149
211
  const app = await buildTestApp({
150
212
  routes: routeGroup("Organizations", [getOrganization]),
151
- authorization: seededFake,
213
+ authorization,
152
214
  });
153
215
  const res = await app.inject({
154
216
  method: "GET",
155
- url: "/organizations/xyz",
217
+ url: `/organizations/${id}`,
156
218
  headers: { "x-test-subject": "u1" },
157
219
  });
158
- expect(dataBodyOf(res, organizationSchema).id).toBe("xyz");
220
+ console.log(dataBodyOf(res, organizationSchema).id); // ca498064-95f7-4334-8d66-12703cd044a9
221
+ await app.close();
159
222
  ```
160
223
 
161
224
  `buildTestApp` never opens a port (`listen` does not exist on it — pinned
@@ -169,7 +232,7 @@ an arbitrary schema) — `res.json()` is `any` and defeats the type walls.
169
232
  - `lib/route/` — authoring: one file per verb, `route-group`, `access`, `capabilities`, `define-raw-route`, `sse-route`, and `route-definition` (parse → handler → parse).
170
233
  - `lib/create-http-app.ts` — builds the Fastify instance (logger, CORS, timeouts, request-id, trustedProxyHops).
171
234
  - `lib/request-pipeline/` — `register-routes` (enforce → run under deadline → envelope), `enforce-access`, `with-deadline`, `error-handler`, `envelope`, `rate-limit`, `request-id`.
172
- - `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.
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/core/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.
173
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).
174
237
  - `lib/http-errors.ts` — typed failures this library produces while running a route.
175
238
  - `src/testing/` — `buildTestApp` + typed inject-response helpers.
@@ -178,9 +241,7 @@ an arbitrary schema) — `res.json()` is `any` and defeats the type walls.
178
241
 
179
242
  A surface that implements another party's protocol (Better Auth's
180
243
  `/api/auth/*`, the remote MCP endpoint) is not a route: it is a fetch-style
181
- handler mounted whole. That code is its own Nx project, `api-http-protocol-mount`
182
- in [`protocol-mount/`](./src/protocol-mounts/README.md), imported as
183
- `@dads-framework/http/protocol-mounts`.
244
+ handler mounted whole. Import the bridge from [`@dads-framework/http/protocol-mounts`](./src/protocol-mounts/README.md) in the API composition root.
184
245
  `mountFetchHandler` is the one bridge for that — every content type arrives as
185
246
  raw bytes, the request crosses to a WHATWG `Request` whose clones never share
186
247
  a stream (`to-web-request.ts`, the Node 22 undici clone trap), and the
@@ -193,6 +254,43 @@ API can clear an authorization-consistency cookie on sign-out.
193
254
  await app.register(mountFetchHandler(auth), { prefix: "/api/auth" });
194
255
  ```
195
256
 
257
+ ## Liveness and readiness
258
+
259
+ Use `createHealthRoutes(checks)` to expose separate checks for processes and
260
+ traffic routers. `/health` confirms the process responds. `/ready` evaluates
261
+ the application's readiness probes. Register the routes during API composition
262
+ and supply probes for dependencies required to serve traffic.
263
+
264
+ Save this as `example.mts` and run `node --experimental-strip-types example.mts`.
265
+
266
+ <!-- dads:check-example -->
267
+
268
+ ```ts
269
+ import { createHealthRoutes } from "@dads-framework/http/health";
270
+ import { buildTestApp } from "@dads-framework/http/testing";
271
+
272
+ const app = await buildTestApp({
273
+ routes: createHealthRoutes({
274
+ pingDatabase: () => Promise.reject(new Error("Database unavailable")),
275
+ pingCriticalServices: () => Promise.resolve(),
276
+ }),
277
+ });
278
+ try {
279
+ const live = await app.inject({ method: "GET", url: "/health" });
280
+ const ready = await app.inject({ method: "GET", url: "/ready" });
281
+ console.log(live.statusCode, ready.statusCode);
282
+ } finally {
283
+ await app.close();
284
+ }
285
+ ```
286
+
287
+ The simulated outage prints `200 503`. Liveness still succeeds. Replace
288
+ the example probes with your application’s dependency checks when
289
+ registering the routes in your HTTP app.
290
+
291
+ In the generated app, `assembly/start-app.ts` registers probes for the
292
+ database, job queue, and file store. [Starter health wiring](../../../apps/kit-workbench/assembly/start-app.ts)
293
+
196
294
  ## Compose authorization for lists
197
295
 
198
296
  Use `requires`, `requiresVisible`, or `requiresScoped` from
@@ -204,8 +302,21 @@ model and a fake lookup port to `buildTestApp`.
204
302
 
205
303
  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.
206
304
 
305
+ ## Feature state previews
306
+
307
+ When a host configures `featureState.preview`, the resolver receives the
308
+ preview ID, authenticated subject, effective subject, and feature-state
309
+ context. By default the context comes from a request header. The host verifies the effective identity and context before
310
+ returning a preview. Set `featureState.contextFromRequest` to derive context
311
+ from matched route parameters instead of the caller’s header. Preview responses
312
+ are private and non-cacheable. A resolver may return a `scopeKey` for its feature
313
+ evaluator to match against
314
+ the context being evaluated.
315
+
207
316
  ## What it refuses to do
208
317
 
318
+ Readiness reports the results of probes supplied by the application.
319
+
209
320
  Application code supplies identity, access policies, and business handlers. The HTTP kit enforces the declared route boundary and owns transport.
210
321
 
211
322
  A public POST that only appends internal telemetry can declare
@@ -218,3 +329,7 @@ Its transport conformance runs over a real Fastify socket and against the
218
329
  contract package's independent in-memory Fetch host. The shared proof covers
219
330
  GET and POST beneath a prefix. Fastify-specific hooks and limits have their own
220
331
  tests.
332
+
333
+ A subject resolver can read the matched route's decoded `params` when its
334
+ session policy depends on a route parameter. Validate those values before
335
+ using them to select a policy.
@@ -0,0 +1,2 @@
1
+ export { createHealthRoutes, type ReadinessChecks, } from "./lib/health.routes.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/health/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,eAAe,GACrB,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { createHealthRoutes, } from "./lib/health.routes.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/health/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAEnB,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { HealthStatus, ReadyStatus } from "./health.schemas.js";
2
+ /** Dependency probes required before serving traffic. */
3
+ export type ReadinessChecks = {
4
+ pingDatabase(): Promise<void>;
5
+ pingCriticalServices(): Promise<void>;
6
+ };
7
+ /** Named handlers for the public liveness and readiness routes. */
8
+ export type HealthRouteHandlers = {
9
+ readonly getHealth: () => HealthStatus;
10
+ readonly getReady: () => Promise<ReadyStatus>;
11
+ };
12
+ /** Maps dependency probes to named route handlers. */
13
+ export declare function createHealthRouteHandlers(checks: ReadinessChecks): HealthRouteHandlers;
14
+ //# sourceMappingURL=health.route-handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.route-handlers.d.ts","sourceRoot":"","sources":["../../../src/health/lib/health.route-handlers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAErE,yDAAyD;AACzD,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC,CAAC;AAEF,mEAAmE;AACnE,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,YAAY,CAAC;IACvC,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;CAC/C,CAAC;AAEF,sDAAsD;AACtD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,eAAe,GACtB,mBAAmB,CAmBrB"}
@@ -0,0 +1,19 @@
1
+ import { ServiceUnavailableError } from "../../index.js";
2
+ /** Maps dependency probes to named route handlers. */
3
+ export function createHealthRouteHandlers(checks) {
4
+ function getHealth() {
5
+ return { status: "ok" };
6
+ }
7
+ async function getReady() {
8
+ try {
9
+ await checks.pingDatabase();
10
+ await checks.pingCriticalServices();
11
+ }
12
+ catch {
13
+ throw new ServiceUnavailableError("NOT_READY", "A critical dependency is unreachable");
14
+ }
15
+ return { status: "ready" };
16
+ }
17
+ return { getHealth, getReady };
18
+ }
19
+ //# sourceMappingURL=health.route-handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.route-handlers.js","sourceRoot":"","sources":["../../../src/health/lib/health.route-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAgBzD,sDAAsD;AACtD,MAAM,UAAU,yBAAyB,CACvC,MAAuB;IAEvB,SAAS,SAAS;QAChB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK,UAAU,QAAQ;QACrB,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,YAAY,EAAE,CAAC;YAC5B,MAAM,MAAM,CAAC,oBAAoB,EAAE,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,uBAAuB,CAC/B,WAAW,EACX,sCAAsC,CACvC,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { type HttpRoute } from "../../index.js";
2
+ import { type ReadinessChecks } from "./health.route-handlers.js";
3
+ export type { ReadinessChecks } from "./health.route-handlers.js";
4
+ /** /health is liveness; /ready checks dependencies before serving traffic. */
5
+ export declare function createHealthRoutes(checks: ReadinessChecks): HttpRoute[];
6
+ //# sourceMappingURL=health.routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.routes.d.ts","sourceRoot":"","sources":["../../../src/health/lib/health.routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,SAAS,EAEf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,4BAA4B,CAAC;AAGpC,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,EAAE,CAGvE"}
@@ -0,0 +1,28 @@
1
+ import { getRoute, publicAccess, routeGroup, } from "../../index.js";
2
+ import { createHealthRouteHandlers, } from "./health.route-handlers.js";
3
+ import { healthStatusSchema, readyStatusSchema } from "./health.schemas.js";
4
+ /** /health is liveness; /ready checks dependencies before serving traffic. */
5
+ export function createHealthRoutes(checks) {
6
+ const handlers = createHealthRouteHandlers(checks);
7
+ return routeGroup("Health", healthRouteCards(handlers));
8
+ }
9
+ /** Reviewed infrastructure probes use local schemas and no client binding. */
10
+ function healthRouteCards(handlers) {
11
+ return [
12
+ getRoute({
13
+ path: "/health",
14
+ summary: "Liveness — answers without touching dependencies",
15
+ access: publicAccess(),
16
+ response: healthStatusSchema,
17
+ handler: handlers.getHealth,
18
+ }),
19
+ getRoute({
20
+ path: "/ready",
21
+ summary: "Readiness — critical services reachable",
22
+ access: publicAccess(),
23
+ response: readyStatusSchema,
24
+ handler: handlers.getReady,
25
+ }),
26
+ ];
27
+ }
28
+ //# sourceMappingURL=health.routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.routes.js","sourceRoot":"","sources":["../../../src/health/lib/health.routes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,UAAU,GAGX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,yBAAyB,GAG1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAI5E,8EAA8E;AAC9E,MAAM,UAAU,kBAAkB,CAAC,MAAuB;IACxD,MAAM,QAAQ,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;IACnD,OAAO,UAAU,CAAC,QAAQ,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,8EAA8E;AAC9E,SAAS,gBAAgB,CAAC,QAA6B;IACrD,OAAO;QACL,QAAQ,CAAC;YACP,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,kDAAkD;YAC3D,MAAM,EAAE,YAAY,EAAE;YACtB,QAAQ,EAAE,kBAAkB;YAC5B,OAAO,EAAE,QAAQ,CAAC,SAAS;SAC5B,CAAC;QACF,QAAQ,CAAC;YACP,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,yCAAyC;YAClD,MAAM,EAAE,YAAY,EAAE;YACtB,QAAQ,EAAE,iBAAiB;YAC3B,OAAO,EAAE,QAAQ,CAAC,QAAQ;SAC3B,CAAC;KACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+ export declare const healthStatusSchema: z.ZodObject<{
3
+ status: z.ZodLiteral<"ok">;
4
+ }, z.core.$strip>;
5
+ export declare const readyStatusSchema: z.ZodObject<{
6
+ status: z.ZodLiteral<"ready">;
7
+ }, z.core.$strip>;
8
+ export type HealthStatus = z.infer<typeof healthStatusSchema>;
9
+ export type ReadyStatus = z.infer<typeof readyStatusSchema>;
10
+ //# sourceMappingURL=health.schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.schemas.d.ts","sourceRoot":"","sources":["../../../src/health/lib/health.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,kBAAkB;;iBAE7B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;iBAI5B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+ export const healthStatusSchema = z.object({
3
+ status: z.literal("ok").meta({ description: "Process liveness" }),
4
+ });
5
+ export const readyStatusSchema = z.object({
6
+ status: z.literal("ready").meta({
7
+ description: "Service readiness — critical services reachable",
8
+ }),
9
+ });
10
+ //# sourceMappingURL=health.schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.schemas.js","sourceRoot":"","sources":["../../../src/health/lib/health.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;CAClE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC;QAC9B,WAAW,EAAE,iDAAiD;KAC/D,CAAC;CACH,CAAC,CAAC"}