@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.
- package/LICENSE.md +21 -0
- package/README.md +295 -2
- package/dist/http.tsbuildinfo +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/create-http-app.d.ts +108 -0
- package/dist/lib/create-http-app.d.ts.map +1 -0
- package/dist/lib/create-http-app.js +181 -0
- package/dist/lib/create-http-app.js.map +1 -0
- package/dist/lib/http-errors.d.ts +52 -0
- package/dist/lib/http-errors.d.ts.map +1 -0
- package/dist/lib/http-errors.js +66 -0
- package/dist/lib/http-errors.js.map +1 -0
- package/dist/lib/mcp/mcp-tool.d.ts +94 -0
- package/dist/lib/mcp/mcp-tool.d.ts.map +1 -0
- package/dist/lib/mcp/mcp-tool.js +11 -0
- package/dist/lib/mcp/mcp-tool.js.map +1 -0
- package/dist/lib/object-value.d.ts +3 -0
- package/dist/lib/object-value.d.ts.map +1 -0
- package/dist/lib/object-value.js +5 -0
- package/dist/lib/object-value.js.map +1 -0
- package/dist/lib/openapi/build-document.d.ts +27 -0
- package/dist/lib/openapi/build-document.d.ts.map +1 -0
- package/dist/lib/openapi/build-document.js +192 -0
- package/dist/lib/openapi/build-document.js.map +1 -0
- package/dist/lib/openapi/logic/add-discriminators.d.ts +16 -0
- package/dist/lib/openapi/logic/add-discriminators.d.ts.map +1 -0
- package/dist/lib/openapi/logic/add-discriminators.js +235 -0
- package/dist/lib/openapi/logic/add-discriminators.js.map +1 -0
- package/dist/lib/openapi/logic/by-code-point.d.ts +2 -0
- package/dist/lib/openapi/logic/by-code-point.d.ts.map +1 -0
- package/dist/lib/openapi/logic/by-code-point.js +6 -0
- package/dist/lib/openapi/logic/by-code-point.js.map +1 -0
- package/dist/lib/openapi/logic/capitalize-initial.d.ts +2 -0
- package/dist/lib/openapi/logic/capitalize-initial.d.ts.map +1 -0
- package/dist/lib/openapi/logic/capitalize-initial.js +4 -0
- package/dist/lib/openapi/logic/capitalize-initial.js.map +1 -0
- package/dist/lib/openapi/logic/document-record.d.ts +5 -0
- package/dist/lib/openapi/logic/document-record.d.ts.map +1 -0
- package/dist/lib/openapi/logic/document-record.js +14 -0
- package/dist/lib/openapi/logic/document-record.js.map +1 -0
- package/dist/lib/openapi/logic/list-order.d.ts +23 -0
- package/dist/lib/openapi/logic/list-order.d.ts.map +1 -0
- package/dist/lib/openapi/logic/list-order.js +102 -0
- package/dist/lib/openapi/logic/list-order.js.map +1 -0
- package/dist/lib/openapi/logic/open-response-objects.d.ts +14 -0
- package/dist/lib/openapi/logic/open-response-objects.d.ts.map +1 -0
- package/dist/lib/openapi/logic/open-response-objects.js +130 -0
- package/dist/lib/openapi/logic/open-response-objects.js.map +1 -0
- package/dist/lib/openapi/logic/openapi-parts.d.ts +37 -0
- package/dist/lib/openapi/logic/openapi-parts.d.ts.map +1 -0
- package/dist/lib/openapi/logic/openapi-parts.js +243 -0
- package/dist/lib/openapi/logic/openapi-parts.js.map +1 -0
- package/dist/lib/openapi/logic/schema-components.d.ts +5 -0
- package/dist/lib/openapi/logic/schema-components.d.ts.map +1 -0
- package/dist/lib/openapi/logic/schema-components.js +47 -0
- package/dist/lib/openapi/logic/schema-components.js.map +1 -0
- package/dist/lib/request-log/authorization-warning-faults.d.ts +30 -0
- package/dist/lib/request-log/authorization-warning-faults.d.ts.map +1 -0
- package/dist/lib/request-log/authorization-warning-faults.js +35 -0
- package/dist/lib/request-log/authorization-warning-faults.js.map +1 -0
- package/dist/lib/request-log/capture-request-record.d.ts +50 -0
- package/dist/lib/request-log/capture-request-record.d.ts.map +1 -0
- package/dist/lib/request-log/capture-request-record.js +132 -0
- package/dist/lib/request-log/capture-request-record.js.map +1 -0
- package/dist/lib/request-log/request-log-sink.d.ts +31 -0
- package/dist/lib/request-log/request-log-sink.d.ts.map +1 -0
- package/dist/lib/request-log/request-log-sink.js +26 -0
- package/dist/lib/request-log/request-log-sink.js.map +1 -0
- package/dist/lib/request-log/request-outcome.d.ts +53 -0
- package/dist/lib/request-log/request-outcome.d.ts.map +1 -0
- package/dist/lib/request-log/request-outcome.js +96 -0
- package/dist/lib/request-log/request-outcome.js.map +1 -0
- package/dist/lib/request-log/request-record.d.ts +114 -0
- package/dist/lib/request-log/request-record.d.ts.map +1 -0
- package/dist/lib/request-log/request-record.js +231 -0
- package/dist/lib/request-log/request-record.js.map +1 -0
- package/dist/lib/request-pipeline/assert-no-app-site-serving.d.ts +8 -0
- package/dist/lib/request-pipeline/assert-no-app-site-serving.d.ts.map +1 -0
- package/dist/lib/request-pipeline/assert-no-app-site-serving.js +15 -0
- package/dist/lib/request-pipeline/assert-no-app-site-serving.js.map +1 -0
- package/dist/lib/request-pipeline/carry-audit-actor.d.ts +71 -0
- package/dist/lib/request-pipeline/carry-audit-actor.d.ts.map +1 -0
- package/dist/lib/request-pipeline/carry-audit-actor.js +79 -0
- package/dist/lib/request-pipeline/carry-audit-actor.js.map +1 -0
- package/dist/lib/request-pipeline/carry-authorization-consistency.d.ts +4 -0
- package/dist/lib/request-pipeline/carry-authorization-consistency.d.ts.map +1 -0
- package/dist/lib/request-pipeline/carry-authorization-consistency.js +21 -0
- package/dist/lib/request-pipeline/carry-authorization-consistency.js.map +1 -0
- package/dist/lib/request-pipeline/enforce-access.d.ts +146 -0
- package/dist/lib/request-pipeline/enforce-access.d.ts.map +1 -0
- package/dist/lib/request-pipeline/enforce-access.js +238 -0
- package/dist/lib/request-pipeline/enforce-access.js.map +1 -0
- package/dist/lib/request-pipeline/enforce-scope.d.ts +23 -0
- package/dist/lib/request-pipeline/enforce-scope.d.ts.map +1 -0
- package/dist/lib/request-pipeline/enforce-scope.js +58 -0
- package/dist/lib/request-pipeline/enforce-scope.js.map +1 -0
- package/dist/lib/request-pipeline/envelope.d.ts +17 -0
- package/dist/lib/request-pipeline/envelope.d.ts.map +1 -0
- package/dist/lib/request-pipeline/envelope.js +4 -0
- package/dist/lib/request-pipeline/envelope.js.map +1 -0
- package/dist/lib/request-pipeline/error-handler.d.ts +14 -0
- package/dist/lib/request-pipeline/error-handler.d.ts.map +1 -0
- package/dist/lib/request-pipeline/error-handler.js +138 -0
- package/dist/lib/request-pipeline/error-handler.js.map +1 -0
- package/dist/lib/request-pipeline/feature-state-preview.d.ts +79 -0
- package/dist/lib/request-pipeline/feature-state-preview.d.ts.map +1 -0
- package/dist/lib/request-pipeline/feature-state-preview.js +77 -0
- package/dist/lib/request-pipeline/feature-state-preview.js.map +1 -0
- package/dist/lib/request-pipeline/feature-state.d.ts +70 -0
- package/dist/lib/request-pipeline/feature-state.d.ts.map +1 -0
- package/dist/lib/request-pipeline/feature-state.js +46 -0
- package/dist/lib/request-pipeline/feature-state.js.map +1 -0
- package/dist/lib/request-pipeline/logic/is-write-method.d.ts +2 -0
- package/dist/lib/request-pipeline/logic/is-write-method.d.ts.map +1 -0
- package/dist/lib/request-pipeline/logic/is-write-method.js +7 -0
- package/dist/lib/request-pipeline/logic/is-write-method.js.map +1 -0
- package/dist/lib/request-pipeline/logic/read-request-source.d.ts +19 -0
- package/dist/lib/request-pipeline/logic/read-request-source.d.ts.map +1 -0
- package/dist/lib/request-pipeline/logic/read-request-source.js +40 -0
- package/dist/lib/request-pipeline/logic/read-request-source.js.map +1 -0
- package/dist/lib/request-pipeline/logic/single-request-header.d.ts +3 -0
- package/dist/lib/request-pipeline/logic/single-request-header.d.ts.map +1 -0
- package/dist/lib/request-pipeline/logic/single-request-header.js +16 -0
- package/dist/lib/request-pipeline/logic/single-request-header.js.map +1 -0
- package/dist/lib/request-pipeline/machine-credential-access.d.ts +19 -0
- package/dist/lib/request-pipeline/machine-credential-access.d.ts.map +1 -0
- package/dist/lib/request-pipeline/machine-credential-access.js +28 -0
- package/dist/lib/request-pipeline/machine-credential-access.js.map +1 -0
- package/dist/lib/request-pipeline/rate-limit.d.ts +15 -0
- package/dist/lib/request-pipeline/rate-limit.d.ts.map +1 -0
- package/dist/lib/request-pipeline/rate-limit.js +40 -0
- package/dist/lib/request-pipeline/rate-limit.js.map +1 -0
- package/dist/lib/request-pipeline/raw-route-byte-body.d.ts +19 -0
- package/dist/lib/request-pipeline/raw-route-byte-body.d.ts.map +1 -0
- package/dist/lib/request-pipeline/raw-route-byte-body.js +26 -0
- package/dist/lib/request-pipeline/raw-route-byte-body.js.map +1 -0
- package/dist/lib/request-pipeline/refuse-visible-record-list.d.ts +16 -0
- package/dist/lib/request-pipeline/refuse-visible-record-list.d.ts.map +1 -0
- package/dist/lib/request-pipeline/refuse-visible-record-list.js +33 -0
- package/dist/lib/request-pipeline/refuse-visible-record-list.js.map +1 -0
- package/dist/lib/request-pipeline/register-routes.d.ts +50 -0
- package/dist/lib/request-pipeline/register-routes.d.ts.map +1 -0
- package/dist/lib/request-pipeline/register-routes.js +217 -0
- package/dist/lib/request-pipeline/register-routes.js.map +1 -0
- package/dist/lib/request-pipeline/request-id.d.ts +22 -0
- package/dist/lib/request-pipeline/request-id.d.ts.map +1 -0
- package/dist/lib/request-pipeline/request-id.js +26 -0
- package/dist/lib/request-pipeline/request-id.js.map +1 -0
- package/dist/lib/request-pipeline/request-language-response.d.ts +14 -0
- package/dist/lib/request-pipeline/request-language-response.d.ts.map +1 -0
- package/dist/lib/request-pipeline/request-language-response.js +47 -0
- package/dist/lib/request-pipeline/request-language-response.js.map +1 -0
- package/dist/lib/request-pipeline/request-locale.d.ts +38 -0
- package/dist/lib/request-pipeline/request-locale.d.ts.map +1 -0
- package/dist/lib/request-pipeline/request-locale.js +102 -0
- package/dist/lib/request-pipeline/request-locale.js.map +1 -0
- package/dist/lib/request-pipeline/request-origin.d.ts +17 -0
- package/dist/lib/request-pipeline/request-origin.d.ts.map +1 -0
- package/dist/lib/request-pipeline/request-origin.js +38 -0
- package/dist/lib/request-pipeline/request-origin.js.map +1 -0
- package/dist/lib/request-pipeline/request-trace.d.ts +10 -0
- package/dist/lib/request-pipeline/request-trace.d.ts.map +1 -0
- package/dist/lib/request-pipeline/request-trace.js +24 -0
- package/dist/lib/request-pipeline/request-trace.js.map +1 -0
- package/dist/lib/request-pipeline/route-rate-limit.d.ts +19 -0
- package/dist/lib/request-pipeline/route-rate-limit.d.ts.map +1 -0
- package/dist/lib/request-pipeline/route-rate-limit.js +32 -0
- package/dist/lib/request-pipeline/route-rate-limit.js.map +1 -0
- package/dist/lib/request-pipeline/run-route.d.ts +9 -0
- package/dist/lib/request-pipeline/run-route.d.ts.map +1 -0
- package/dist/lib/request-pipeline/run-route.js +42 -0
- package/dist/lib/request-pipeline/run-route.js.map +1 -0
- package/dist/lib/request-pipeline/with-deadline.d.ts +12 -0
- package/dist/lib/request-pipeline/with-deadline.d.ts.map +1 -0
- package/dist/lib/request-pipeline/with-deadline.js +55 -0
- package/dist/lib/request-pipeline/with-deadline.js.map +1 -0
- package/dist/lib/route/access.d.ts +143 -0
- package/dist/lib/route/access.d.ts.map +1 -0
- package/dist/lib/route/access.js +97 -0
- package/dist/lib/route/access.js.map +1 -0
- package/dist/lib/route/capabilities.d.ts +100 -0
- package/dist/lib/route/capabilities.d.ts.map +1 -0
- package/dist/lib/route/capabilities.js +42 -0
- package/dist/lib/route/capabilities.js.map +1 -0
- package/dist/lib/route/define-raw-route.d.ts +81 -0
- package/dist/lib/route/define-raw-route.d.ts.map +1 -0
- package/dist/lib/route/define-raw-route.js +5 -0
- package/dist/lib/route/define-raw-route.js.map +1 -0
- package/dist/lib/route/delete-route.d.ts +26 -0
- package/dist/lib/route/delete-route.d.ts.map +1 -0
- package/dist/lib/route/delete-route.js +6 -0
- package/dist/lib/route/delete-route.js.map +1 -0
- package/dist/lib/route/get-route.d.ts +43 -0
- package/dist/lib/route/get-route.d.ts.map +1 -0
- package/dist/lib/route/get-route.js +18 -0
- package/dist/lib/route/get-route.js.map +1 -0
- package/dist/lib/route/list-result.d.ts +11 -0
- package/dist/lib/route/list-result.d.ts.map +1 -0
- package/dist/lib/route/list-result.js +8 -0
- package/dist/lib/route/list-result.js.map +1 -0
- package/dist/lib/route/list-route.d.ts +60 -0
- package/dist/lib/route/list-route.d.ts.map +1 -0
- package/dist/lib/route/list-route.js +68 -0
- package/dist/lib/route/list-route.js.map +1 -0
- package/dist/lib/route/patch-route.d.ts +27 -0
- package/dist/lib/route/patch-route.d.ts.map +1 -0
- package/dist/lib/route/patch-route.js +8 -0
- package/dist/lib/route/patch-route.js.map +1 -0
- package/dist/lib/route/post-no-content-route.d.ts +18 -0
- package/dist/lib/route/post-no-content-route.d.ts.map +1 -0
- package/dist/lib/route/post-no-content-route.js +8 -0
- package/dist/lib/route/post-no-content-route.js.map +1 -0
- package/dist/lib/route/post-route.d.ts +34 -0
- package/dist/lib/route/post-route.d.ts.map +1 -0
- package/dist/lib/route/post-route.js +23 -0
- package/dist/lib/route/post-route.js.map +1 -0
- package/dist/lib/route/route-definition.d.ts +224 -0
- package/dist/lib/route/route-definition.d.ts.map +1 -0
- package/dist/lib/route/route-definition.js +32 -0
- package/dist/lib/route/route-definition.js.map +1 -0
- package/dist/lib/route/route-execution.d.ts +47 -0
- package/dist/lib/route/route-execution.d.ts.map +1 -0
- package/dist/lib/route/route-execution.js +162 -0
- package/dist/lib/route/route-execution.js.map +1 -0
- package/dist/lib/route/route-group.d.ts +21 -0
- package/dist/lib/route/route-group.d.ts.map +1 -0
- package/dist/lib/route/route-group.js +18 -0
- package/dist/lib/route/route-group.js.map +1 -0
- package/dist/lib/route/route-guards.test-support.d.ts +2 -0
- package/dist/lib/route/route-guards.test-support.d.ts.map +1 -0
- package/dist/lib/route/route-guards.test-support.js +2 -0
- package/dist/lib/route/route-guards.test-support.js.map +1 -0
- package/dist/lib/route/sse-route.d.ts +54 -0
- package/dist/lib/route/sse-route.d.ts.map +1 -0
- package/dist/lib/route/sse-route.js +63 -0
- package/dist/lib/route/sse-route.js.map +1 -0
- package/dist/lib/route/web-socket-route.d.ts +45 -0
- package/dist/lib/route/web-socket-route.d.ts.map +1 -0
- package/dist/lib/route/web-socket-route.js +180 -0
- package/dist/lib/route/web-socket-route.js.map +1 -0
- package/dist/lib/route-catalog/route-catalog-parts.d.ts +27 -0
- package/dist/lib/route-catalog/route-catalog-parts.d.ts.map +1 -0
- package/dist/lib/route-catalog/route-catalog-parts.js +87 -0
- package/dist/lib/route-catalog/route-catalog-parts.js.map +1 -0
- package/dist/protocol-mounts/index.d.ts +19 -0
- package/dist/protocol-mounts/index.d.ts.map +1 -0
- package/dist/protocol-mounts/index.js +19 -0
- package/dist/protocol-mounts/index.js.map +1 -0
- package/dist/protocol-mounts/lib/mcp/json-rpc.d.ts +54 -0
- package/dist/protocol-mounts/lib/mcp/json-rpc.d.ts.map +1 -0
- package/dist/protocol-mounts/lib/mcp/json-rpc.js +53 -0
- package/dist/protocol-mounts/lib/mcp/json-rpc.js.map +1 -0
- package/dist/protocol-mounts/lib/mcp/mcp-endpoint.d.ts +31 -0
- package/dist/protocol-mounts/lib/mcp/mcp-endpoint.d.ts.map +1 -0
- package/dist/protocol-mounts/lib/mcp/mcp-endpoint.js +179 -0
- package/dist/protocol-mounts/lib/mcp/mcp-endpoint.js.map +1 -0
- package/dist/protocol-mounts/lib/mcp/mcp-methods.d.ts +68 -0
- package/dist/protocol-mounts/lib/mcp/mcp-methods.d.ts.map +1 -0
- package/dist/protocol-mounts/lib/mcp/mcp-methods.js +201 -0
- package/dist/protocol-mounts/lib/mcp/mcp-methods.js.map +1 -0
- package/dist/protocol-mounts/lib/mcp/protected-resource-metadata.d.ts +18 -0
- package/dist/protocol-mounts/lib/mcp/protected-resource-metadata.d.ts.map +1 -0
- package/dist/protocol-mounts/lib/mcp/protected-resource-metadata.js +34 -0
- package/dist/protocol-mounts/lib/mcp/protected-resource-metadata.js.map +1 -0
- package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.d.ts +57 -0
- package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.d.ts.map +1 -0
- package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.js +100 -0
- package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.js.map +1 -0
- package/dist/protocol-mounts/lib/protocol-mount/to-web-request.d.ts +14 -0
- package/dist/protocol-mounts/lib/protocol-mount/to-web-request.d.ts.map +1 -0
- package/dist/protocol-mounts/lib/protocol-mount/to-web-request.js +60 -0
- package/dist/protocol-mounts/lib/protocol-mount/to-web-request.js.map +1 -0
- package/dist/testing/build-test-app.d.ts +47 -0
- package/dist/testing/build-test-app.d.ts.map +1 -0
- package/dist/testing/build-test-app.js +79 -0
- package/dist/testing/build-test-app.js.map +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +3 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/parse-inject-response.d.ts +32 -0
- package/dist/testing/parse-inject-response.d.ts.map +1 -0
- package/dist/testing/parse-inject-response.js +39 -0
- package/dist/testing/parse-inject-response.js.map +1 -0
- package/package.json +55 -4
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One `request_log` row, and the pure function that builds it.
|
|
3
|
+
*
|
|
4
|
+
* Nothing here touches Fastify. The capture hook hands over a plain object —
|
|
5
|
+
* method, status, elapsed time, the headers, the actor in force, what access
|
|
6
|
+
* settled — and gets back the row. That keeps the redaction rules testable
|
|
7
|
+
* without a server: the allowlist below is the ONLY place a request header is
|
|
8
|
+
* read, so "no cookie, no authorization, no query string, no body" is a
|
|
9
|
+
* property of nine lines rather than a promise
|
|
10
|
+
* (docs/architecture/observability.md).
|
|
11
|
+
*/
|
|
12
|
+
import { CLIENT_CONTEXT_HEADER, decodeClientContext, } from "@dads-framework/contract";
|
|
13
|
+
const USER_AGENT_HEADER = "user-agent";
|
|
14
|
+
const ACCEPT_LANGUAGE_HEADER = "accept-language";
|
|
15
|
+
const FORWARDED_FOR_HEADER = "x-forwarded-for";
|
|
16
|
+
/** Client hints are a family, not a header: `sec-ch-ua`, `-platform`, `-mobile`, … */
|
|
17
|
+
const CLIENT_HINT_PREFIX = "sec-ch-ua";
|
|
18
|
+
/** One absurd user agent must not decide how wide a row gets. */
|
|
19
|
+
const MAX_HEADER_VALUE_LENGTH = 512;
|
|
20
|
+
/** A client that invents client hints cannot turn one row into a document. */
|
|
21
|
+
const MAX_CLIENT_HINTS = 16;
|
|
22
|
+
/**
|
|
23
|
+
* What the request cost, or nulls when nothing measured it.
|
|
24
|
+
*
|
|
25
|
+
* All seven move together on purpose: a row with a query count but no duration
|
|
26
|
+
* would invite the reader to assume the missing half is zero. Either the
|
|
27
|
+
* counters ran for this request or they did not.
|
|
28
|
+
*/
|
|
29
|
+
function whatItCost(work) {
|
|
30
|
+
if (work === undefined) {
|
|
31
|
+
return {
|
|
32
|
+
dbQueryCount: null,
|
|
33
|
+
dbMs: null,
|
|
34
|
+
authzCheckCount: null,
|
|
35
|
+
authzMs: null,
|
|
36
|
+
authzCachedReadCount: null,
|
|
37
|
+
authzFullyConsistentReadCount: null,
|
|
38
|
+
authzLargestLookupCount: null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
dbQueryCount: work.dbQueryCount,
|
|
43
|
+
dbMs: Math.round(work.dbMs),
|
|
44
|
+
authzCheckCount: work.authzCheckCount,
|
|
45
|
+
authzMs: Math.round(work.authzMs),
|
|
46
|
+
authzCachedReadCount: work.authzCachedReadCount,
|
|
47
|
+
authzFullyConsistentReadCount: work.authzFullyConsistentReadCount,
|
|
48
|
+
authzLargestLookupCount: work.authzLargestLookupCount,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A path segment safe to keep verbatim when no route pattern is available:
|
|
53
|
+
* letters and hyphens only, so `orders` and `sign-up` survive while anything
|
|
54
|
+
* carrying a digit — every id shape this system mints — does not.
|
|
55
|
+
*/
|
|
56
|
+
const NON_IDENTIFYING_SEGMENT = /^[A-Za-z][A-Za-z-]*$/;
|
|
57
|
+
export function buildRequestRecord(input) {
|
|
58
|
+
return {
|
|
59
|
+
requestId: input.requestId,
|
|
60
|
+
recordedAt: input.recordedAt,
|
|
61
|
+
method: input.method,
|
|
62
|
+
routeId: input.routePattern ?? null,
|
|
63
|
+
path: input.routePattern ?? maskUnmatchedPath(input.url),
|
|
64
|
+
status: input.status,
|
|
65
|
+
durationMs: input.durationMs,
|
|
66
|
+
decision: resolveDecision(input.status, input.access),
|
|
67
|
+
errorCode: input.errorCode ?? null,
|
|
68
|
+
...whoServedIt(input),
|
|
69
|
+
...whatFailed(input.exception),
|
|
70
|
+
...whatItCost(input.work),
|
|
71
|
+
...whoAsked(input.actor),
|
|
72
|
+
...whatAccessSettled(input.access),
|
|
73
|
+
...whereItCameFrom(input),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Which build, which process, which trace.
|
|
78
|
+
*
|
|
79
|
+
* Grouped because they answer one question — "where was this served" — and
|
|
80
|
+
* because they are the three fields most likely to be null together: a
|
|
81
|
+
* deployment that stamps no release tends also to run no tracing.
|
|
82
|
+
*/
|
|
83
|
+
function whoServedIt(input) {
|
|
84
|
+
return {
|
|
85
|
+
apiRelease: input.apiRelease ?? null,
|
|
86
|
+
instanceId: input.instanceId ?? null,
|
|
87
|
+
traceId: input.traceId ?? null,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* What failed, or nulls.
|
|
92
|
+
*
|
|
93
|
+
* Both move together: a type without a fingerprint could not be grouped, and
|
|
94
|
+
* a fingerprint without a type could not be read.
|
|
95
|
+
*/
|
|
96
|
+
function whatFailed(exception) {
|
|
97
|
+
if (exception === undefined) {
|
|
98
|
+
return { exceptionType: null, exceptionFingerprint: null };
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
exceptionType: exception.type,
|
|
102
|
+
exceptionFingerprint: exception.fingerprint,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** The actor in force, or nobody — a request outside any context is anonymous. */
|
|
106
|
+
function whoAsked(actor) {
|
|
107
|
+
if (actor === undefined) {
|
|
108
|
+
return {
|
|
109
|
+
actorKind: "anonymous",
|
|
110
|
+
actorId: "",
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
actorKind: actor.kind,
|
|
115
|
+
actorId: actor.id,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** Nulls throughout for a response that never reached access enforcement. */
|
|
119
|
+
function whatAccessSettled(access) {
|
|
120
|
+
if (access === undefined) {
|
|
121
|
+
return {
|
|
122
|
+
authMethod: null,
|
|
123
|
+
accessKind: null,
|
|
124
|
+
permission: null,
|
|
125
|
+
resourceType: null,
|
|
126
|
+
resourceId: null,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
authMethod: access.authMethod ?? null,
|
|
131
|
+
accessKind: access.accessKind,
|
|
132
|
+
permission: access.permission ?? null,
|
|
133
|
+
resourceType: access.resourceType ?? null,
|
|
134
|
+
resourceId: access.resourceId ?? null,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** The allowlisted environment — the only place request headers are read. */
|
|
138
|
+
function whereItCameFrom(input) {
|
|
139
|
+
return {
|
|
140
|
+
ip: input.ip ?? null,
|
|
141
|
+
forwardedFor: headerValue(input.headers, FORWARDED_FOR_HEADER),
|
|
142
|
+
userAgent: headerValue(input.headers, USER_AGENT_HEADER),
|
|
143
|
+
clientHints: clientHintsOf(input.headers),
|
|
144
|
+
acceptLanguage: headerValue(input.headers, ACCEPT_LANGUAGE_HEADER),
|
|
145
|
+
clientContext: clientContextOf(input.headers),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Status plus access outcome, settled in one place.
|
|
150
|
+
*
|
|
151
|
+
* A server fault outranks everything — a 500 on an allowed route is an error,
|
|
152
|
+
* not an allow. Below that, an access refusal is the more specific fact than
|
|
153
|
+
* the status it produced, which is why `not-found` from enforcement becomes
|
|
154
|
+
* `denied` while a plain 404 stays `not-found`.
|
|
155
|
+
*/
|
|
156
|
+
function resolveDecision(status, access) {
|
|
157
|
+
if (status >= 500)
|
|
158
|
+
return "error";
|
|
159
|
+
if (access?.outcome === "unauthenticated" || status === 401) {
|
|
160
|
+
return "unauthenticated";
|
|
161
|
+
}
|
|
162
|
+
if (access?.outcome === "not-found" || status === 403)
|
|
163
|
+
return "denied";
|
|
164
|
+
if (status === 404)
|
|
165
|
+
return "not-found";
|
|
166
|
+
if (status >= 400)
|
|
167
|
+
return "error";
|
|
168
|
+
return "allow";
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* What `path` holds when Fastify matched no route — a 404, a 426 from the
|
|
172
|
+
* client gate, a probe for someone else's software.
|
|
173
|
+
*
|
|
174
|
+
* The raw path is never stored: it may carry ids, and a route
|
|
175
|
+
* pattern is exactly the thing that strips them. With no pattern to lean on,
|
|
176
|
+
* every segment that could be an identifier is replaced, which keeps the
|
|
177
|
+
* useful half of the answer — /api/orders/:id/lines says where the caller
|
|
178
|
+
* went — without carrying the identifying half.
|
|
179
|
+
*/
|
|
180
|
+
function maskUnmatchedPath(url) {
|
|
181
|
+
const [rawPath = ""] = url.split("?");
|
|
182
|
+
return rawPath
|
|
183
|
+
.split("/")
|
|
184
|
+
.map((segment) => segment.length === 0 || NON_IDENTIFYING_SEGMENT.test(segment)
|
|
185
|
+
? segment
|
|
186
|
+
: ":id")
|
|
187
|
+
.join("/");
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* One allowlisted header, bounded. A repeated header yields its first
|
|
191
|
+
* occurrence rather than a joined blob: the values here are diagnostic, and
|
|
192
|
+
* the first is the one the client meant.
|
|
193
|
+
*/
|
|
194
|
+
function headerValue(headers, name) {
|
|
195
|
+
const value = firstHeaderValue(headers[name]);
|
|
196
|
+
if (value === undefined || value.length === 0)
|
|
197
|
+
return null;
|
|
198
|
+
return value.slice(0, MAX_HEADER_VALUE_LENGTH);
|
|
199
|
+
}
|
|
200
|
+
/** A repeated header arrives as an array; only its first occurrence is read. */
|
|
201
|
+
function firstHeaderValue(raw) {
|
|
202
|
+
if (raw === undefined)
|
|
203
|
+
return undefined;
|
|
204
|
+
return typeof raw === "string" ? raw : raw[0];
|
|
205
|
+
}
|
|
206
|
+
/** Every `sec-ch-ua*` header and nothing else, or null when none were sent. */
|
|
207
|
+
function clientHintsOf(headers) {
|
|
208
|
+
const hints = {};
|
|
209
|
+
let kept = 0;
|
|
210
|
+
for (const name of Object.keys(headers)) {
|
|
211
|
+
if (!name.toLowerCase().startsWith(CLIENT_HINT_PREFIX))
|
|
212
|
+
continue;
|
|
213
|
+
if (kept >= MAX_CLIENT_HINTS)
|
|
214
|
+
break;
|
|
215
|
+
const value = headerValue(headers, name);
|
|
216
|
+
if (value === null)
|
|
217
|
+
continue;
|
|
218
|
+
hints[name.toLowerCase()] = value;
|
|
219
|
+
kept += 1;
|
|
220
|
+
}
|
|
221
|
+
return kept === 0 ? null : hints;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* The client's self-reported environment. `decodeClientContext` swallows every
|
|
225
|
+
* failure — missing, oversized, malformed, or a shape this build does not know
|
|
226
|
+
* — so a debugging header can never decide whether a row is written.
|
|
227
|
+
*/
|
|
228
|
+
function clientContextOf(headers) {
|
|
229
|
+
return decodeClientContext(firstHeaderValue(headers[CLIENT_CONTEXT_HEADER]));
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=request-record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-record.js","sourceRoot":"","sources":["../../../src/lib/request-log/request-record.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EACL,qBAAqB,EACrB,mBAAmB,GAEpB,MAAM,0BAA0B,CAAC;AA0GlC,MAAM,iBAAiB,GAAG,YAAY,CAAC;AACvC,MAAM,sBAAsB,GAAG,iBAAiB,CAAC;AACjD,MAAM,oBAAoB,GAAG,iBAAi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IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC;YAAE,SAAS;QACjE,IAAI,IAAI,IAAI,gBAAgB;YAAE,MAAM;QACpC,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACzC,IAAI,KAAK,KAAK,IAAI;YAAE,SAAS;QAC7B,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;QAClC,IAAI,IAAI,CAAC,CAAC;IACZ,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,OAA6B;IACpD,OAAO,mBAAmB,CAAC,gBAAgB,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RouteCapabilities } from "../route/capabilities.js";
|
|
2
|
+
/**
|
|
3
|
+
* A site label is declared by a route or its group, never app-wide: an app
|
|
4
|
+
* default would label every route at once and defeat the product's check
|
|
5
|
+
* that each route says whether a secondary deployment may serve it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function assertNoAppSiteServing(capabilities: RouteCapabilities | undefined): void;
|
|
8
|
+
//# sourceMappingURL=assert-no-app-site-serving.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-no-app-site-serving.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/assert-no-app-site-serving.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,iBAAiB,GAAG,SAAS,GAC1C,IAAI,CAWN"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HttpWiringError } from "../http-errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* A site label is declared by a route or its group, never app-wide: an app
|
|
4
|
+
* default would label every route at once and defeat the product's check
|
|
5
|
+
* that each route says whether a secondary deployment may serve it.
|
|
6
|
+
*/
|
|
7
|
+
export function assertNoAppSiteServing(capabilities) {
|
|
8
|
+
if (capabilities?.site !== undefined) {
|
|
9
|
+
throw new HttpWiringError("registerRoutes capabilities.site is not allowed — a route's site label is declared by the route or its group, never app-wide");
|
|
10
|
+
}
|
|
11
|
+
if (capabilities?.cloudOnly !== undefined) {
|
|
12
|
+
throw new HttpWiringError("registerRoutes capabilities.cloudOnly is not allowed — a cloud-only reason is declared with its site label, by the route or its group, never app-wide");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=assert-no-app-site-serving.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-no-app-site-serving.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/assert-no-app-site-serving.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAA2C;IAE3C,IAAI,YAAY,EAAE,IAAI,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,IAAI,eAAe,CACvB,8HAA8H,CAC/H,CAAC;IACJ,CAAC;IACD,IAAI,YAAY,EAAE,SAAS,KAAK,SAAS,EAAE,CAAC;QAC1C,MAAM,IAAI,eAAe,CACvB,uJAAuJ,CACxJ,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP end of the actor context: who the database believes is
|
|
3
|
+
* writing, for the whole of a request.
|
|
4
|
+
*
|
|
5
|
+
* Two moments, because a request has two answers to "who is this":
|
|
6
|
+
*
|
|
7
|
+
* 1. **Ingress**, before anything has authenticated: `anonymous` with the
|
|
8
|
+
* request id. This is not a formality — Better Auth's login flow writes
|
|
9
|
+
* `session` and `user` rows on a request that by definition has no subject
|
|
10
|
+
* yet, and the `audit_record` trigger refuses any write that reaches it
|
|
11
|
+
* unattributed. Without this the login endpoint would 500.
|
|
12
|
+
* 2. **After access enforcement decides**, for the handler: the subject the
|
|
13
|
+
* request resolved to. A refusal of a resolved caller names that caller on
|
|
14
|
+
* the request row too, so a signed-in user's denial is not filed under
|
|
15
|
+
* `anonymous`; only an unauthenticated refusal keeps the ingress actor.
|
|
16
|
+
*
|
|
17
|
+
* The kit does NOT know how to turn a `SubjectRef` into an `AuditActor`. The
|
|
18
|
+
* generic half of that mapping lives in `@dads-framework/audit`, which depends on
|
|
19
|
+
* this kit and so cannot be depended on back; the subject kinds themselves are
|
|
20
|
+
* the application's, named in its own access barrels. So the composition root
|
|
21
|
+
* composes the mapping and injects it, and the kit calls what it is handed.
|
|
22
|
+
*/
|
|
23
|
+
import type { FastifyRequest } from "fastify";
|
|
24
|
+
import { type AuditActor } from "@dads-framework/audit-actor";
|
|
25
|
+
import type { SubjectRef } from "@dads-framework/access/runtime";
|
|
26
|
+
import type { AccessDecision } from "./enforce-access.js";
|
|
27
|
+
/**
|
|
28
|
+
* How a resolved request becomes an actor — what
|
|
29
|
+
* `composeSubjectToAuditActor` from `@dads-framework/audit` produces, and what
|
|
30
|
+
* the composition root passes.
|
|
31
|
+
*/
|
|
32
|
+
export type AuditActorForSubject = (input: {
|
|
33
|
+
readonly subject: SubjectRef | null;
|
|
34
|
+
readonly authenticatedSubject: SubjectRef | null;
|
|
35
|
+
readonly requestId: string;
|
|
36
|
+
}) => AuditActor;
|
|
37
|
+
/**
|
|
38
|
+
* Attributes everything this request goes on to do to `anonymous`, from the
|
|
39
|
+
* earliest hook Fastify runs.
|
|
40
|
+
*
|
|
41
|
+
* `enterWith`, not `run`: an `onRequest` hook has to return for the request to
|
|
42
|
+
* continue, so it cannot wrap the handler in a callback. Setting the store on
|
|
43
|
+
* the request's own async context is the mechanism Fastify context plugins use
|
|
44
|
+
* for exactly this reason, and it carries into every later hook, the route
|
|
45
|
+
* handler, the protocol mounts (`/api/auth`, `/scim/v2`), and the error
|
|
46
|
+
* handler.
|
|
47
|
+
*/
|
|
48
|
+
export declare function enterAnonymousRequestActor(request: FastifyRequest): void;
|
|
49
|
+
/**
|
|
50
|
+
* Runs `work` as the subject the request resolved to, keeping the request id
|
|
51
|
+
* the ingress actor already minted so the handler's rows and the request's own
|
|
52
|
+
* row join.
|
|
53
|
+
*
|
|
54
|
+
* Without a mapper the ingress `anonymous` context stands: writes are still
|
|
55
|
+
* attributed and still accepted, just to nobody in particular. That is a
|
|
56
|
+
* deliberately quiet fallback for tests and small embedders — every real app
|
|
57
|
+
* wires the mapper at its composition root.
|
|
58
|
+
*/
|
|
59
|
+
export declare function carryResolvedAuditActor<T>(auditActorForSubject: AuditActorForSubject | undefined, request: FastifyRequest, decision: {
|
|
60
|
+
readonly subject: SubjectRef | null;
|
|
61
|
+
readonly authenticatedSubject: SubjectRef | null;
|
|
62
|
+
}, work: () => Promise<T>): Promise<T>;
|
|
63
|
+
/**
|
|
64
|
+
* Names the caller a refusal turned away on the request's own row. Nothing
|
|
65
|
+
* runs after a refusal, so there is no context to enter — only the row to
|
|
66
|
+
* correct. An unauthenticated refusal proved no one and keeps `anonymous`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function rememberRefusedAuditActor(auditActorForSubject: AuditActorForSubject | undefined, request: FastifyRequest, refusal: Exclude<AccessDecision, {
|
|
69
|
+
outcome: "allow";
|
|
70
|
+
}>): void;
|
|
71
|
+
//# sourceMappingURL=carry-audit-actor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carry-audit-actor.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/carry-aud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of the actor context: who the database believes is
|
|
3
|
+
* writing, for the whole of a request.
|
|
4
|
+
*
|
|
5
|
+
* Two moments, because a request has two answers to "who is this":
|
|
6
|
+
*
|
|
7
|
+
* 1. **Ingress**, before anything has authenticated: `anonymous` with the
|
|
8
|
+
* request id. This is not a formality — Better Auth's login flow writes
|
|
9
|
+
* `session` and `user` rows on a request that by definition has no subject
|
|
10
|
+
* yet, and the `audit_record` trigger refuses any write that reaches it
|
|
11
|
+
* unattributed. Without this the login endpoint would 500.
|
|
12
|
+
* 2. **After access enforcement decides**, for the handler: the subject the
|
|
13
|
+
* request resolved to. A refusal of a resolved caller names that caller on
|
|
14
|
+
* the request row too, so a signed-in user's denial is not filed under
|
|
15
|
+
* `anonymous`; only an unauthenticated refusal keeps the ingress actor.
|
|
16
|
+
*
|
|
17
|
+
* The kit does NOT know how to turn a `SubjectRef` into an `AuditActor`. The
|
|
18
|
+
* generic half of that mapping lives in `@dads-framework/audit`, which depends on
|
|
19
|
+
* this kit and so cannot be depended on back; the subject kinds themselves are
|
|
20
|
+
* the application's, named in its own access barrels. So the composition root
|
|
21
|
+
* composes the mapping and injects it, and the kit calls what it is handed.
|
|
22
|
+
*/
|
|
23
|
+
import { anonymousActor, enterAuditActor, runWithAuditActor, } from "@dads-framework/audit-actor";
|
|
24
|
+
import { rememberRequestActor } from "../request-log/request-outcome.js";
|
|
25
|
+
import { requestIdOf } from "./request-id.js";
|
|
26
|
+
/**
|
|
27
|
+
* Attributes everything this request goes on to do to `anonymous`, from the
|
|
28
|
+
* earliest hook Fastify runs.
|
|
29
|
+
*
|
|
30
|
+
* `enterWith`, not `run`: an `onRequest` hook has to return for the request to
|
|
31
|
+
* continue, so it cannot wrap the handler in a callback. Setting the store on
|
|
32
|
+
* the request's own async context is the mechanism Fastify context plugins use
|
|
33
|
+
* for exactly this reason, and it carries into every later hook, the route
|
|
34
|
+
* handler, the protocol mounts (`/api/auth`, `/scim/v2`), and the error
|
|
35
|
+
* handler.
|
|
36
|
+
*/
|
|
37
|
+
export function enterAnonymousRequestActor(request) {
|
|
38
|
+
enterAuditActor(anonymousActor(requestIdOf(request)));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Runs `work` as the subject the request resolved to, keeping the request id
|
|
42
|
+
* the ingress actor already minted so the handler's rows and the request's own
|
|
43
|
+
* row join.
|
|
44
|
+
*
|
|
45
|
+
* Without a mapper the ingress `anonymous` context stands: writes are still
|
|
46
|
+
* attributed and still accepted, just to nobody in particular. That is a
|
|
47
|
+
* deliberately quiet fallback for tests and small embedders — every real app
|
|
48
|
+
* wires the mapper at its composition root.
|
|
49
|
+
*/
|
|
50
|
+
export function carryResolvedAuditActor(auditActorForSubject, request, decision, work) {
|
|
51
|
+
if (auditActorForSubject === undefined)
|
|
52
|
+
return work();
|
|
53
|
+
const actor = auditActorForSubject({
|
|
54
|
+
subject: decision.subject,
|
|
55
|
+
authenticatedSubject: decision.authenticatedSubject,
|
|
56
|
+
requestId: requestIdOf(request),
|
|
57
|
+
});
|
|
58
|
+
// The context below closes when the handler returns, and the request row is
|
|
59
|
+
// built after that. Written down here, the row still knows who this was.
|
|
60
|
+
rememberRequestActor(request, actor);
|
|
61
|
+
return runWithAuditActor(actor, work);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Names the caller a refusal turned away on the request's own row. Nothing
|
|
65
|
+
* runs after a refusal, so there is no context to enter — only the row to
|
|
66
|
+
* correct. An unauthenticated refusal proved no one and keeps `anonymous`.
|
|
67
|
+
*/
|
|
68
|
+
export function rememberRefusedAuditActor(auditActorForSubject, request, refusal) {
|
|
69
|
+
if (auditActorForSubject === undefined)
|
|
70
|
+
return;
|
|
71
|
+
if (refusal.outcome === "unauthenticated")
|
|
72
|
+
return;
|
|
73
|
+
rememberRequestActor(request, auditActorForSubject({
|
|
74
|
+
subject: refusal.subject,
|
|
75
|
+
authenticatedSubject: refusal.authenticatedSubject,
|
|
76
|
+
requestId: requestIdOf(request),
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=carry-audit-actor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carry-audit-actor.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/carry-audit-actor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,EACL,cAAc,EAEd,eAAe,EACf,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAa9C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,0BAA0B,CAAC,OAAuB;IAChE,eAAe,CAAC,cAAc,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CACrC,oBAAsD,EACtD,OAAuB,EACvB,QAGC,EACD,IAAsB;IAEtB,IAAI,oBAAoB,KAAK,SAAS;QAAE,OAAO,IAAI,EAAE,CAAC;IACtD,MAAM,KAAK,GAAG,oBAAoB,CAAC;QACjC,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB;QACnD,SAAS,EAAE,WAAW,CAAC,OAAO,CAAC;KAChC,CAAC,CAAC;IACH,4EAA4E;IAC5E,yEAAyE;IACzE,oBAAoB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,oBAAsD,EACtD,OAAuB,EACvB,OAAsD;IAEtD,IAAI,oBAAoB,KAAK,SAAS;QAAE,OAAO;IAC/C,IAAI,OAAO,CAAC,OAAO,KAAK,iBAAiB;QAAE,OAAO;IAClD,oBAAoB,CAClB,OAAO,EACP,oBAAoB,CAAC;QACnB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;QAClD,SAAS,EAAE,WAAW,CAAC,OAAO,CAAC;KAChC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
export declare function carryAuthorizationConsistency<T>(request: FastifyRequest, work: () => T): T;
|
|
3
|
+
export declare function attachWrittenAuthorizationConsistencyCookie(request: FastifyRequest, reply: FastifyReply): void;
|
|
4
|
+
//# sourceMappingURL=carry-authorization-consistency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carry-authorization-consistency.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/carry-authorization-consistency.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAS5D,wBAAgB,6BAA6B,CAAC,CAAC,EAC7C,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,MAAM,CAAC,GACZ,CAAC,CAKH;AAED,wBAAgB,2CAA2C,CACzD,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,YAAY,GAClB,IAAI,CASN"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { authorizationConsistencySetCookie, authorizationConsistencyTokenFromCookieHeader, runWithAuthorizationConsistency, writtenAuthorizationConsistencyOnThisRequest, } from "@dads-framework/access/runtime";
|
|
2
|
+
export function carryAuthorizationConsistency(request, work) {
|
|
3
|
+
return runWithAuthorizationConsistency(authorizationConsistencyTokenFromCookieHeader(request.headers.cookie), work);
|
|
4
|
+
}
|
|
5
|
+
export function attachWrittenAuthorizationConsistencyCookie(request, reply) {
|
|
6
|
+
const written = writtenAuthorizationConsistencyOnThisRequest();
|
|
7
|
+
if (written === undefined)
|
|
8
|
+
return;
|
|
9
|
+
void reply.header("set-cookie", authorizationConsistencySetCookie(written, {
|
|
10
|
+
secure: requestIsHttps(request),
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
function requestIsHttps(request) {
|
|
14
|
+
const forwarded = request.headers["x-forwarded-proto"];
|
|
15
|
+
if (forwarded === "https")
|
|
16
|
+
return true;
|
|
17
|
+
if (Array.isArray(forwarded) && forwarded[0] === "https")
|
|
18
|
+
return true;
|
|
19
|
+
return request.protocol === "https";
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=carry-authorization-consistency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carry-authorization-consistency.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/carry-authorization-consistency.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iCAAiC,EACjC,6CAA6C,EAC7C,+BAA+B,EAC/B,4CAA4C,GAC7C,MAAM,gCAAgC,CAAC;AAExC,MAAM,UAAU,6BAA6B,CAC3C,OAAuB,EACvB,IAAa;IAEb,OAAO,+BAA+B,CACpC,6CAA6C,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EACrE,IAAI,CACL,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2CAA2C,CACzD,OAAuB,EACvB,KAAmB;IAEnB,MAAM,OAAO,GAAG,4CAA4C,EAAE,CAAC;IAC/D,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO;IAClC,KAAK,KAAK,CAAC,MAAM,CACf,YAAY,EACZ,iCAAiC,CAAC,OAAO,EAAE;QACzC,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC;KAChC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,OAAuB;IAC7C,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACvD,IAAI,SAAS,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IACvC,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IACtE,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { ScopePlan } from "@dads-framework/access";
|
|
2
|
+
import { type AuthMethod, type ResolvedSubject, type ScopeAnswer, type SubjectRef } from "@dads-framework/access/runtime";
|
|
3
|
+
import type { RouteAccess } from "../route/access.js";
|
|
4
|
+
/**
|
|
5
|
+
* The two ports access enforcement needs — structurally satisfied by the
|
|
6
|
+
* authz lib's `RequestSubject` and `Authorization` (and by the fakes in
|
|
7
|
+
* `@dads-framework/access/testing`). The kit never does permission math: the
|
|
8
|
+
* decision table is the same pure `evaluateRouteAccess` the old guard used,
|
|
9
|
+
* so denied checks keep surfacing as 404 (never leaking existence) and
|
|
10
|
+
* missing subjects as 401.
|
|
11
|
+
*/
|
|
12
|
+
type SubjectRequest = {
|
|
13
|
+
headers: Record<string, string | string[] | undefined>;
|
|
14
|
+
readonly url?: string;
|
|
15
|
+
/** Decoded parameters for the matched route, before application validation. */
|
|
16
|
+
readonly params?: unknown;
|
|
17
|
+
};
|
|
18
|
+
export type SubjectResolver = {
|
|
19
|
+
resolve(request: SubjectRequest): Promise<SubjectRef | null>;
|
|
20
|
+
/**
|
|
21
|
+
* The same resolution, plus which credential answered. Optional on purpose:
|
|
22
|
+
* a resolver that cannot say enforces exactly as before and simply reports
|
|
23
|
+
* no method.
|
|
24
|
+
*/
|
|
25
|
+
resolveWithMethod?(request: SubjectRequest): Promise<ResolvedSubject | null>;
|
|
26
|
+
};
|
|
27
|
+
export type PermissionChecker = {
|
|
28
|
+
check(query: {
|
|
29
|
+
subject: SubjectRef;
|
|
30
|
+
permission: string;
|
|
31
|
+
resource: {
|
|
32
|
+
type: string;
|
|
33
|
+
id: string;
|
|
34
|
+
};
|
|
35
|
+
}): Promise<boolean>;
|
|
36
|
+
};
|
|
37
|
+
/** The set-question port `requireVisibility` and `requiresScoped` need (Authorization has it). */
|
|
38
|
+
export type VisibleResourceLookup = {
|
|
39
|
+
lookupResources(query: {
|
|
40
|
+
subject: SubjectRef;
|
|
41
|
+
permission: string;
|
|
42
|
+
resourceType: string;
|
|
43
|
+
}): Promise<readonly string[]>;
|
|
44
|
+
};
|
|
45
|
+
/** Domain-owned context policy; the HTTP kit never constructs a business actor. */
|
|
46
|
+
export type AuthorizationContextResolver = {
|
|
47
|
+
execute(authenticatedSubject: SubjectRef, requestedContext: unknown): Promise<{
|
|
48
|
+
readonly subject: SubjectRef;
|
|
49
|
+
} | null>;
|
|
50
|
+
};
|
|
51
|
+
/** A failed check, for server-side diagnostics — the wire stays a bare 404. */
|
|
52
|
+
export type AccessDenial = {
|
|
53
|
+
readonly subjectType: string;
|
|
54
|
+
readonly subjectId: string;
|
|
55
|
+
readonly permission: string;
|
|
56
|
+
readonly resourceType: string;
|
|
57
|
+
readonly resourceId: string;
|
|
58
|
+
readonly url: string | undefined;
|
|
59
|
+
/** Which credential authenticated the denied caller, when the resolver says. */
|
|
60
|
+
readonly authMethod?: AuthMethod;
|
|
61
|
+
};
|
|
62
|
+
export type AccessPorts = {
|
|
63
|
+
readonly subjects: SubjectResolver;
|
|
64
|
+
readonly authorization: PermissionChecker;
|
|
65
|
+
/** Required only by requireVisibility and requiresScoped routes; the Authorization battery satisfies it. */
|
|
66
|
+
readonly lookups?: VisibleResourceLookup;
|
|
67
|
+
/** Required by routes explicitly declared with withAuthorizationContext. */
|
|
68
|
+
readonly authorizationContexts?: AuthorizationContextResolver;
|
|
69
|
+
/**
|
|
70
|
+
* Denial breadcrumb (docs/architecture/authorization.md): fired when a
|
|
71
|
+
* RESOLVED subject fails a check — the "you probably forgot the tuple or
|
|
72
|
+
* typo'd the type string" signal. Never fired for 401s, never on allow.
|
|
73
|
+
*/
|
|
74
|
+
readonly onDenied?: (denial: AccessDenial) => void;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* What the route handler does with an enforced request. The fields below
|
|
78
|
+
* `visibleIds` are the settled decision, recorded downstream (the request log)
|
|
79
|
+
* and read by nothing that decides: enforcement reports them, it never
|
|
80
|
+
* consults them.
|
|
81
|
+
*/
|
|
82
|
+
export type AccessDecision = {
|
|
83
|
+
readonly outcome: "allow";
|
|
84
|
+
readonly subject: SubjectRef | null;
|
|
85
|
+
/** Login identity, never replaced by the selected business actor. */
|
|
86
|
+
readonly authenticatedSubject: SubjectRef | null;
|
|
87
|
+
readonly untrustedAuthorizationContext?: string;
|
|
88
|
+
/** The context the resolver accepted, as the caller named it. One subject may answer several contexts, so the subject alone does not say which. */
|
|
89
|
+
readonly authorizationContext?: string;
|
|
90
|
+
/** Present exactly when the route declared requireVisibility. */
|
|
91
|
+
readonly visibleIds?: readonly string[];
|
|
92
|
+
/** Present exactly when the route declared requiresScoped. */
|
|
93
|
+
readonly scope?: ScopeAnswer;
|
|
94
|
+
/** Which access declaration answered this request. */
|
|
95
|
+
readonly accessKind: RouteAccess["kind"];
|
|
96
|
+
/** The settled permission — permission and visibility routes only. */
|
|
97
|
+
readonly permission?: string;
|
|
98
|
+
/** What the permission was checked against — permission routes only. */
|
|
99
|
+
readonly resource?: {
|
|
100
|
+
readonly type: string;
|
|
101
|
+
readonly id: string;
|
|
102
|
+
};
|
|
103
|
+
/** Which credential authenticated the caller, when the resolver says. */
|
|
104
|
+
readonly authMethod?: AuthMethod;
|
|
105
|
+
/** When the caller last signed in again on their session, when the resolver read one stamped so. */
|
|
106
|
+
readonly sessionReauthenticatedAt?: Date;
|
|
107
|
+
}
|
|
108
|
+
/** Nobody proved who they are, so there is no one to name. */
|
|
109
|
+
| {
|
|
110
|
+
readonly outcome: "unauthenticated";
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Refused after a caller was resolved. The identities ride along for the
|
|
114
|
+
* request log alone, so the refusal row names who was refused; the wire
|
|
115
|
+
* stays a bare 404.
|
|
116
|
+
*/
|
|
117
|
+
| {
|
|
118
|
+
readonly outcome: "not-found";
|
|
119
|
+
/** The business actor, or null when it never resolved (context refused). */
|
|
120
|
+
readonly subject: SubjectRef | null;
|
|
121
|
+
/** Login identity the credential proved. */
|
|
122
|
+
readonly authenticatedSubject: SubjectRef | null;
|
|
123
|
+
};
|
|
124
|
+
type EnforceableRequest = {
|
|
125
|
+
readonly headers: Record<string, string | string[] | undefined>;
|
|
126
|
+
/** Original occurrences let enforcement detect duplicate headers even after joining. */
|
|
127
|
+
readonly raw?: {
|
|
128
|
+
readonly rawHeaders: readonly string[];
|
|
129
|
+
};
|
|
130
|
+
readonly params: unknown;
|
|
131
|
+
/** Fastify's parsed body — read RAW here (enforcement precedes Zod). */
|
|
132
|
+
readonly body?: unknown;
|
|
133
|
+
/** Fastify's parsed query — read RAW here (enforcement precedes Zod). */
|
|
134
|
+
readonly query?: unknown;
|
|
135
|
+
readonly url?: string;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Enforces a route's `access` declaration: resolve the subject, evaluate
|
|
139
|
+
* the pure decision table, check the business permission after any required
|
|
140
|
+
* authorization-context resolution, and hand
|
|
141
|
+
* back exactly what the caller may do. A `scoped` route passes the plan
|
|
142
|
+
* `registerRoutes` compiled for it at registration.
|
|
143
|
+
*/
|
|
144
|
+
export declare function enforceAccess(access: RouteAccess, request: EnforceableRequest, ports: AccessPorts, scopePlan?: ScopePlan): Promise<AccessDecision>;
|
|
145
|
+
export {};
|
|
146
|
+
//# sourceMappingURL=enforce-access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforce-access.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/enforce-access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,eAAe,EAGpB,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,gCAAgC,CAAC;AAEx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