@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,238 @@
|
|
|
1
|
+
import { evaluateRouteAccess, } from "@dads-framework/access/runtime";
|
|
2
|
+
import { HttpWiringError } from "../http-errors.js";
|
|
3
|
+
import { enforceScope } from "./enforce-scope.js";
|
|
4
|
+
import { isTechnicalContextAbsent, resolveResourceId, } from "./logic/read-request-source.js";
|
|
5
|
+
/** One construction site for allows, so no path can forget a breadcrumb. */
|
|
6
|
+
function allow(decision) {
|
|
7
|
+
return { outcome: "allow", ...decision };
|
|
8
|
+
}
|
|
9
|
+
/** One construction site for refusals, so no path can drop who was refused. */
|
|
10
|
+
function notFound(subject, authenticatedSubject) {
|
|
11
|
+
return {
|
|
12
|
+
outcome: "not-found",
|
|
13
|
+
subject,
|
|
14
|
+
authenticatedSubject,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* What the resolver said about the caller beyond who they are. Each fact is
|
|
19
|
+
* present only when the resolver stated it; an absent fact is left out, never
|
|
20
|
+
* written as `undefined`.
|
|
21
|
+
*/
|
|
22
|
+
function callerFacts(caller) {
|
|
23
|
+
return {
|
|
24
|
+
...(caller.authMethod === undefined
|
|
25
|
+
? {}
|
|
26
|
+
: { authMethod: caller.authMethod }),
|
|
27
|
+
...(caller.sessionReauthenticatedAt === undefined
|
|
28
|
+
? {}
|
|
29
|
+
: { sessionReauthenticatedAt: caller.sessionReauthenticatedAt }),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Prefer the widened port; fall back to the narrow one. A resolver that
|
|
34
|
+
* implements `resolveWithMethod` owns the answer outright — a null from it is
|
|
35
|
+
* "nobody", never a reason to ask `resolve` for a second opinion.
|
|
36
|
+
*/
|
|
37
|
+
async function resolveAuthenticatedCaller(request, ports) {
|
|
38
|
+
const reported = await ports.subjects.resolveWithMethod?.(request);
|
|
39
|
+
if (reported !== undefined) {
|
|
40
|
+
return reported === null
|
|
41
|
+
? null
|
|
42
|
+
: {
|
|
43
|
+
subject: reported.subject,
|
|
44
|
+
authMethod: reported.method,
|
|
45
|
+
sessionReauthenticatedAt: reported.sessionReauthenticatedAt,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const subject = await ports.subjects.resolve(request);
|
|
49
|
+
return subject === null
|
|
50
|
+
? null
|
|
51
|
+
: {
|
|
52
|
+
subject,
|
|
53
|
+
authMethod: undefined,
|
|
54
|
+
sessionReauthenticatedAt: undefined,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function resolveRequestSubjects(access, request, ports) {
|
|
58
|
+
const accessKind = access.kind;
|
|
59
|
+
if (access.kind === "public") {
|
|
60
|
+
return allow({ subject: null, authenticatedSubject: null, accessKind });
|
|
61
|
+
}
|
|
62
|
+
const caller = await resolveAuthenticatedCaller(request, ports);
|
|
63
|
+
if (caller === null)
|
|
64
|
+
return { outcome: "unauthenticated" };
|
|
65
|
+
const { subject: authenticatedSubject } = caller;
|
|
66
|
+
if (authenticatedSubject.type === "facilities/edge_device") {
|
|
67
|
+
return allow({
|
|
68
|
+
subject: authenticatedSubject,
|
|
69
|
+
authenticatedSubject,
|
|
70
|
+
accessKind,
|
|
71
|
+
...callerFacts(caller),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (access.authorizationContext === undefined) {
|
|
75
|
+
return retainAuthenticatedSubject(access, request, caller);
|
|
76
|
+
}
|
|
77
|
+
if (access.authorizationContextMode === "technical-or-business" &&
|
|
78
|
+
isTechnicalContextAbsent(access.authorizationContext, request)) {
|
|
79
|
+
return allow({
|
|
80
|
+
subject: authenticatedSubject,
|
|
81
|
+
authenticatedSubject,
|
|
82
|
+
accessKind,
|
|
83
|
+
...callerFacts(caller),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return resolveBusinessActor(access.authorizationContext, request, caller, ports, accessKind);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The business actor the requested authorization context names. A refusal
|
|
90
|
+
* here still names the login identity, so the request row records who asked.
|
|
91
|
+
*/
|
|
92
|
+
async function resolveBusinessActor(source, request, caller, ports, accessKind) {
|
|
93
|
+
const { subject: authenticatedSubject } = caller;
|
|
94
|
+
if (ports.authorizationContexts === undefined) {
|
|
95
|
+
throw new HttpWiringError("authorization-context route registered without a resolver");
|
|
96
|
+
}
|
|
97
|
+
const requestedContext = resolveResourceId(source, request);
|
|
98
|
+
if (requestedContext === undefined) {
|
|
99
|
+
return notFound(null, authenticatedSubject);
|
|
100
|
+
}
|
|
101
|
+
const authorizationContext = await ports.authorizationContexts.execute(authenticatedSubject, requestedContext);
|
|
102
|
+
if (authorizationContext === null) {
|
|
103
|
+
return notFound(null, authenticatedSubject);
|
|
104
|
+
}
|
|
105
|
+
return allow({
|
|
106
|
+
subject: authorizationContext.subject,
|
|
107
|
+
authenticatedSubject,
|
|
108
|
+
authorizationContext: requestedContext,
|
|
109
|
+
accessKind,
|
|
110
|
+
...callerFacts(caller),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/** Input-only routes retain identity; their domain resolves the explicit purpose. */
|
|
114
|
+
function retainAuthenticatedSubject(access, request, caller) {
|
|
115
|
+
const inputSource = access.kind === "session" ? access.authorizationContextInput : undefined;
|
|
116
|
+
const input = inputSource === undefined
|
|
117
|
+
? undefined
|
|
118
|
+
: resolveResourceId(inputSource, request);
|
|
119
|
+
if (inputSource?.kind === "header" &&
|
|
120
|
+
input === undefined &&
|
|
121
|
+
request.headers[inputSource.name.toLowerCase()] !== undefined)
|
|
122
|
+
return notFound(caller.subject, caller.subject);
|
|
123
|
+
return allow({
|
|
124
|
+
subject: caller.subject,
|
|
125
|
+
authenticatedSubject: caller.subject,
|
|
126
|
+
accessKind: access.kind,
|
|
127
|
+
...callerFacts(caller),
|
|
128
|
+
...(input === undefined ? {} : { untrustedAuthorizationContext: input }),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function buildVerdictInput(access, request, subject) {
|
|
132
|
+
return {
|
|
133
|
+
isPublic: access.kind === "public",
|
|
134
|
+
sessionOnly: access.kind === "session",
|
|
135
|
+
permission: access.kind === "permission"
|
|
136
|
+
? {
|
|
137
|
+
resourceType: access.resourceType,
|
|
138
|
+
permission: access.permission,
|
|
139
|
+
source: access.resourceId,
|
|
140
|
+
}
|
|
141
|
+
: undefined,
|
|
142
|
+
subject,
|
|
143
|
+
resourceId: access.kind === "permission"
|
|
144
|
+
? resolveResourceId(access.resourceId, request)
|
|
145
|
+
: undefined,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
async function settleCheck(input, verdict, subject, authorization) {
|
|
149
|
+
const checkResult = await authorization.check({
|
|
150
|
+
subject,
|
|
151
|
+
permission: verdict.permission,
|
|
152
|
+
resource: verdict.resource,
|
|
153
|
+
});
|
|
154
|
+
return evaluateRouteAccess({ ...input, checkResult });
|
|
155
|
+
}
|
|
156
|
+
function toDecision(verdict, subjects) {
|
|
157
|
+
switch (verdict.outcome) {
|
|
158
|
+
case "allow":
|
|
159
|
+
return subjects;
|
|
160
|
+
case "unauthenticated":
|
|
161
|
+
return { outcome: "unauthenticated" };
|
|
162
|
+
case "not-found":
|
|
163
|
+
return notFound(subjects.subject, subjects.authenticatedSubject);
|
|
164
|
+
case "check":
|
|
165
|
+
// Impossible: settleCheck resolved it above; fail closed regardless.
|
|
166
|
+
return notFound(subjects.subject, subjects.authenticatedSubject);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Enforces a route's `access` declaration: resolve the subject, evaluate
|
|
171
|
+
* the pure decision table, check the business permission after any required
|
|
172
|
+
* authorization-context resolution, and hand
|
|
173
|
+
* back exactly what the caller may do. A `scoped` route passes the plan
|
|
174
|
+
* `registerRoutes` compiled for it at registration.
|
|
175
|
+
*/
|
|
176
|
+
export async function enforceAccess(access, request, ports, scopePlan) {
|
|
177
|
+
const subjects = await resolveRequestSubjects(access, request, ports);
|
|
178
|
+
if (subjects.outcome !== "allow")
|
|
179
|
+
return subjects;
|
|
180
|
+
if (access.kind === "visibility") {
|
|
181
|
+
return enforceVisibility(access, subjects, ports);
|
|
182
|
+
}
|
|
183
|
+
if (access.kind === "scoped") {
|
|
184
|
+
return enforceScope(access, subjects, ports, scopePlan);
|
|
185
|
+
}
|
|
186
|
+
const subject = subjects.subject;
|
|
187
|
+
const input = buildVerdictInput(access, request, subject);
|
|
188
|
+
let verdict = evaluateRouteAccess(input);
|
|
189
|
+
if (verdict.outcome === "check") {
|
|
190
|
+
if (subject === null)
|
|
191
|
+
return { outcome: "unauthenticated" };
|
|
192
|
+
const resource = verdict.resource;
|
|
193
|
+
const permission = verdict.permission;
|
|
194
|
+
verdict = await settleCheck(input, verdict, subject, ports.authorization);
|
|
195
|
+
if (verdict.outcome === "not-found") {
|
|
196
|
+
ports.onDenied?.({
|
|
197
|
+
subjectType: subject.type,
|
|
198
|
+
subjectId: subject.id,
|
|
199
|
+
permission,
|
|
200
|
+
resourceType: resource.type,
|
|
201
|
+
resourceId: resource.id,
|
|
202
|
+
url: request.url,
|
|
203
|
+
...(subjects.authMethod === undefined
|
|
204
|
+
? {}
|
|
205
|
+
: { authMethod: subjects.authMethod }),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
if (verdict.outcome === "allow") {
|
|
209
|
+
return { ...subjects, permission, resource };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return toDecision(verdict, subjects);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The set question, handled apart from the boolean table: resolve the
|
|
216
|
+
* subject (401 without one), ask lookupResources, allow with the visible
|
|
217
|
+
* set. An empty set is a VALID allow — the list verb short-circuits it to
|
|
218
|
+
* an empty page without running the handler (fail-closed by construction).
|
|
219
|
+
*/
|
|
220
|
+
async function enforceVisibility(access, subjects, ports) {
|
|
221
|
+
const subject = subjects.subject;
|
|
222
|
+
if (subject === null) {
|
|
223
|
+
return { outcome: "unauthenticated" };
|
|
224
|
+
}
|
|
225
|
+
if (!ports.lookups) {
|
|
226
|
+
// Wired wrong (a visibility route without a lookup port) — loud 500.
|
|
227
|
+
throw new HttpWiringError("requireVisibility route registered without a lookups port");
|
|
228
|
+
}
|
|
229
|
+
const visibleIds = await ports.lookups.lookupResources({
|
|
230
|
+
subject,
|
|
231
|
+
permission: access.permission,
|
|
232
|
+
resourceType: access.resourceType,
|
|
233
|
+
});
|
|
234
|
+
// A set question settles a permission but no single resource, so only the
|
|
235
|
+
// permission is reported.
|
|
236
|
+
return { ...subjects, visibleIds, permission: access.permission };
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=enforce-access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforce-access.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/enforce-access.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,GAOpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAo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Q,CAAC,CAAC;AACvC,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,iBAAiB,CAC9B,MAAoD,EACpD,QAAuD,EACvD,KAAkB;IAElB,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IACjC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;IACxC,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,qEAAqE;QACrE,MAAM,IAAI,eAAe,CACvB,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IACD,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;QACrD,OAAO;QACP,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,YAAY,EAAE,MAAM,CAAC,YAAY;KAClC,CAAC,CAAC;IACH,0EAA0E;IAC1E,0BAA0B;IAC1B,OAAO,EAAE,GAAG,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AccessModel, ScopePlan } from "@dads-framework/access";
|
|
2
|
+
import type { ScopedAccess } from "../route/access.js";
|
|
3
|
+
import type { HttpRoute } from "../route/route-group.js";
|
|
4
|
+
import type { AccessDecision, AccessPorts } from "./enforce-access.js";
|
|
5
|
+
/**
|
|
6
|
+
* The scope questions, handled apart from the boolean table: resolve the
|
|
7
|
+
* subject (401 without one), ask each distinct question of the compiled plan
|
|
8
|
+
* once, in parallel, and allow with the answers. Empty answers are a valid
|
|
9
|
+
* allow and are NOT short-circuited — the SQL decides, since one empty arm of
|
|
10
|
+
* an `any` can still match.
|
|
11
|
+
*/
|
|
12
|
+
export declare function enforceScope(access: ScopedAccess, subjects: Extract<AccessDecision, {
|
|
13
|
+
outcome: "allow";
|
|
14
|
+
}>, ports: AccessPorts, plan: ScopePlan | undefined): Promise<AccessDecision>;
|
|
15
|
+
/**
|
|
16
|
+
* A scoped route's plan, compiled once as the route registers. A model whose
|
|
17
|
+
* scope bindings cannot carry the permission refuses to register, so the API
|
|
18
|
+
* cannot boot with a list it cannot scope. Only list routes render a scope.
|
|
19
|
+
* A `requiresVisible` on a record refuses here too: it is the list a scope
|
|
20
|
+
* plan exists to replace.
|
|
21
|
+
*/
|
|
22
|
+
export declare function compileRouteScopePlan(route: HttpRoute, model: AccessModel | undefined): ScopePlan | undefined;
|
|
23
|
+
//# sourceMappingURL=enforce-scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforce-scope.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/enforce-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAIrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvE;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,EACvD,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,SAAS,GAAG,SAAS,GAC1B,OAAO,CAAC,cAAc,CAAC,CAwBzB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,WAAW,GAAG,SAAS,GAC7B,SAAS,GAAG,SAAS,CAsBvB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { answerScope, planScopedList } from "@dads-framework/access/runtime";
|
|
2
|
+
import { HttpWiringError } from "../http-errors.js";
|
|
3
|
+
import { refuseVisibleRecordList } from "./refuse-visible-record-list.js";
|
|
4
|
+
/**
|
|
5
|
+
* The scope questions, handled apart from the boolean table: resolve the
|
|
6
|
+
* subject (401 without one), ask each distinct question of the compiled plan
|
|
7
|
+
* once, in parallel, and allow with the answers. Empty answers are a valid
|
|
8
|
+
* allow and are NOT short-circuited — the SQL decides, since one empty arm of
|
|
9
|
+
* an `any` can still match.
|
|
10
|
+
*/
|
|
11
|
+
export async function enforceScope(access, subjects, ports, plan) {
|
|
12
|
+
const subject = subjects.subject;
|
|
13
|
+
if (subject === null) {
|
|
14
|
+
return { outcome: "unauthenticated" };
|
|
15
|
+
}
|
|
16
|
+
if (plan === undefined) {
|
|
17
|
+
// Enforced outside registerRoutes, which compiles the plan — loud 500.
|
|
18
|
+
throw new HttpWiringError(`requiresScoped route for ${access.resourceType}.${access.permission} enforced without its compiled scope plan`);
|
|
19
|
+
}
|
|
20
|
+
if (!ports.lookups) {
|
|
21
|
+
throw new HttpWiringError("requiresScoped route registered without a lookups port");
|
|
22
|
+
}
|
|
23
|
+
const scope = await answerScope({
|
|
24
|
+
resourceType: access.resourceType,
|
|
25
|
+
permission: access.permission,
|
|
26
|
+
plan,
|
|
27
|
+
subject,
|
|
28
|
+
lookups: ports.lookups,
|
|
29
|
+
});
|
|
30
|
+
return { ...subjects, scope, permission: access.permission };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A scoped route's plan, compiled once as the route registers. A model whose
|
|
34
|
+
* scope bindings cannot carry the permission refuses to register, so the API
|
|
35
|
+
* cannot boot with a list it cannot scope. Only list routes render a scope.
|
|
36
|
+
* A `requiresVisible` on a record refuses here too: it is the list a scope
|
|
37
|
+
* plan exists to replace.
|
|
38
|
+
*/
|
|
39
|
+
export function compileRouteScopePlan(route, model) {
|
|
40
|
+
refuseVisibleRecordList(route, model);
|
|
41
|
+
const access = route.access;
|
|
42
|
+
if (access.kind !== "scoped")
|
|
43
|
+
return undefined;
|
|
44
|
+
if (route.kind === "raw-route") {
|
|
45
|
+
throw new HttpWiringError(`raw route ${route.method} ${route.path} declares requiresScoped; only listRoute renders a scope`);
|
|
46
|
+
}
|
|
47
|
+
if (model === undefined) {
|
|
48
|
+
throw new HttpWiringError(`${route.method} ${route.path} uses requiresScoped without an access model`);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return planScopedList(model, access.resourceType, access.permission);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
55
|
+
throw new HttpWiringError(`list route ${route.method} ${route.path} cannot be scoped: ${reason}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=enforce-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforce-scope.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/enforce-scope.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAoB,EACpB,QAAuD,EACvD,KAAkB,EAClB,IAA2B;IAE3B,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IACjC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;IACxC,CAAC;IACD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,uEAAuE;QACvE,MAAM,IAAI,eAAe,CACvB,4BAA4B,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,UAAU,2CAA2C,CAChH,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,IA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I,KAAK,CAAC,IAAI,sBAAsB,MAAM,EAAE,CACvE,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The success envelope (docs/architecture/api-conventions.md): every data
|
|
3
|
+
* response is `{ data }` — `{ data, meta }` when the route declares meta
|
|
4
|
+
* (paginated lists) — built here and nowhere else. Error responses use the
|
|
5
|
+
* error envelope from `@dads-framework/errors/map-error-to-http-response`.
|
|
6
|
+
*/
|
|
7
|
+
export type DataEnvelope<T, Meta = undefined> = Meta extends undefined ? {
|
|
8
|
+
readonly data: T;
|
|
9
|
+
} : {
|
|
10
|
+
readonly data: T;
|
|
11
|
+
readonly meta: Meta;
|
|
12
|
+
};
|
|
13
|
+
export declare function envelope(data: unknown, meta?: unknown): {
|
|
14
|
+
data: unknown;
|
|
15
|
+
meta?: unknown;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/envelope.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,IAAI,GAAG,SAAS,IAAI,IAAI,SAAS,SAAS,GAClE;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GACpB;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC;AAE9C,wBAAgB,QAAQ,CACtB,IAAI,EAAE,OAAO,EACb,IAAI,CAAC,EAAE,OAAO,GACb;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAEnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/envelope.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,QAAQ,CACtB,IAAa,EACb,IAAc;IAEd,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FastifyInstance } from "fastify";
|
|
2
|
+
import { type DiagnosticsReporter } from "@dads-framework/diagnostics";
|
|
3
|
+
export type ErrorHandlingOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Where a fault goes besides the log line. Optional so the test
|
|
6
|
+
* harness and every existing caller are unchanged; the default reports
|
|
7
|
+
* nowhere, which is what a caller that never asked for one should get.
|
|
8
|
+
*/
|
|
9
|
+
readonly diagnostics?: DiagnosticsReporter;
|
|
10
|
+
readonly release?: string;
|
|
11
|
+
readonly instanceId?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function installErrorHandling(app: FastifyInstance, options?: ErrorHandlingOptions): void;
|
|
14
|
+
//# sourceMappingURL=error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAE7E,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,6BAA6B,CAAC;AAyGrC,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,eAAe,EACpB,OAAO,GAAE,oBAAyB,GACjC,IAAI,CA+DN"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { describeException, } from "@dads-framework/diagnostics";
|
|
2
|
+
import { mapErrorToHttpResponse, } from "@dads-framework/errors/map-error-to-http-response";
|
|
3
|
+
import { HandlerTimeoutError, HttpWiringError, RequestValidationError, ResponseDriftError, ServiceUnavailableError, } from "../http-errors.js";
|
|
4
|
+
import { rememberErrorCode, rememberException, } from "../request-log/request-outcome.js";
|
|
5
|
+
import { requestIdOf } from "./request-id.js";
|
|
6
|
+
/**
|
|
7
|
+
* The one place errors become HTTP at this library's edge. Library-native
|
|
8
|
+
* failures are mapped first (they carry structure `mapErrorToHttpResponse`
|
|
9
|
+
* cannot know about); Fastify transport errors (payload too large, malformed
|
|
10
|
+
* JSON) keep their status but get the house error envelope; everything else —
|
|
11
|
+
* domain errors and the unknown — delegates to the existing pure
|
|
12
|
+
* `mapErrorToHttpResponse`, so the kind→status table lives in exactly one
|
|
13
|
+
* file.
|
|
14
|
+
*/
|
|
15
|
+
const TRANSPORT_CODES = {
|
|
16
|
+
400: "VALIDATION_FAILED",
|
|
17
|
+
413: "PAYLOAD_TOO_LARGE",
|
|
18
|
+
415: "UNSUPPORTED_MEDIA_TYPE",
|
|
19
|
+
408: "REQUEST_TIMEOUT",
|
|
20
|
+
};
|
|
21
|
+
/** Fastify decorates its own errors with a 4xx/5xx statusCode. */
|
|
22
|
+
function isTransportError(error) {
|
|
23
|
+
return (typeof error === "object" &&
|
|
24
|
+
error !== null &&
|
|
25
|
+
"statusCode" in error &&
|
|
26
|
+
typeof error.statusCode === "number" &&
|
|
27
|
+
error.statusCode >= 400 &&
|
|
28
|
+
error.statusCode <= 599);
|
|
29
|
+
}
|
|
30
|
+
function mapHttpException(error, requestId) {
|
|
31
|
+
if (error instanceof RequestValidationError) {
|
|
32
|
+
return {
|
|
33
|
+
status: 400,
|
|
34
|
+
body: {
|
|
35
|
+
error: {
|
|
36
|
+
code: "VALIDATION_FAILED",
|
|
37
|
+
message: `Request ${error.part} failed validation`,
|
|
38
|
+
details: { part: error.part, issues: error.cause.issues },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
unexpected: false,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (error instanceof ServiceUnavailableError) {
|
|
45
|
+
return {
|
|
46
|
+
status: 503,
|
|
47
|
+
body: { error: { code: error.code, message: error.message } },
|
|
48
|
+
unexpected: false,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (error instanceof HandlerTimeoutError) {
|
|
52
|
+
return {
|
|
53
|
+
status: 503,
|
|
54
|
+
body: {
|
|
55
|
+
error: {
|
|
56
|
+
code: "HANDLER_TIMEOUT",
|
|
57
|
+
message: "The request could not be completed in time",
|
|
58
|
+
requestId,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
unexpected: true,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Response drift and wiring bugs are programming errors: the client
|
|
65
|
+
// sees only a masked 500; the log carries the loud specifics.
|
|
66
|
+
if (error instanceof ResponseDriftError || error instanceof HttpWiringError) {
|
|
67
|
+
return {
|
|
68
|
+
status: 500,
|
|
69
|
+
body: {
|
|
70
|
+
error: {
|
|
71
|
+
code: "INTERNAL_ERROR",
|
|
72
|
+
message: "An unexpected error occurred",
|
|
73
|
+
requestId,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
unexpected: true,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
export function installErrorHandling(app, options = {}) {
|
|
82
|
+
app.setErrorHandler((error, request, reply) => {
|
|
83
|
+
const requestId = requestIdOf(request);
|
|
84
|
+
const httpMapped = mapHttpException(error, requestId);
|
|
85
|
+
const mapped = httpMapped ??
|
|
86
|
+
(isTransportError(error) && error.statusCode < 500
|
|
87
|
+
? {
|
|
88
|
+
status: error.statusCode,
|
|
89
|
+
body: {
|
|
90
|
+
error: {
|
|
91
|
+
code: TRANSPORT_CODES[error.statusCode] ?? "HTTP_ERROR",
|
|
92
|
+
message: error.message,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
unexpected: false,
|
|
96
|
+
}
|
|
97
|
+
: mapErrorToHttpResponse(error, requestId));
|
|
98
|
+
if (mapped.unexpected) {
|
|
99
|
+
request.log.error({
|
|
100
|
+
event: "unhandled.exception",
|
|
101
|
+
requestId,
|
|
102
|
+
err: error,
|
|
103
|
+
}, "request failed unexpectedly");
|
|
104
|
+
// Beside the line, not instead of it: the line carries the full `err`
|
|
105
|
+
// serialization a human reads, and this carries the type and
|
|
106
|
+
// fingerprint a query groups by.
|
|
107
|
+
rememberException(request, describeException(error));
|
|
108
|
+
options.diagnostics?.captureException({
|
|
109
|
+
error,
|
|
110
|
+
source: "request",
|
|
111
|
+
requestId,
|
|
112
|
+
...(request.routeOptions.url === undefined
|
|
113
|
+
? {}
|
|
114
|
+
: { routeId: request.routeOptions.url }),
|
|
115
|
+
...(options.release === undefined
|
|
116
|
+
? {}
|
|
117
|
+
: { release: options.release }),
|
|
118
|
+
...(options.instanceId === undefined
|
|
119
|
+
? {}
|
|
120
|
+
: { instanceId: options.instanceId }),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// The envelope is the only place the code exists; the request row wants
|
|
124
|
+
// it, and by `onResponse` the body is already on the wire.
|
|
125
|
+
rememberErrorCode(request, mapped.body.error.code);
|
|
126
|
+
void reply.status(mapped.status).send(mapped.body);
|
|
127
|
+
});
|
|
128
|
+
app.setNotFoundHandler((request, reply) => {
|
|
129
|
+
rememberErrorCode(request, "NOT_FOUND");
|
|
130
|
+
void reply.status(404).send({
|
|
131
|
+
error: {
|
|
132
|
+
code: "NOT_FOUND",
|
|
133
|
+
message: `Route ${request.method} ${request.url} does not exist`,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/error-handler.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iBAAiB,GAElB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAEL,sBAAsB,GACvB,MAAM,mDAAmD,CAAC;AAE3D,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;;;;;;;GAQG;AAEH,MAAM,eAAe,GAA2B;IAC9C,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,wBAAwB;IAC7B,GAAG,EAAE,iBAAiB;CACvB,CAAC;AAEF,kEAAkE;AAClE,SAAS,gBAAgB,CACvB,KAAc;IAEd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,YAAY,IAAI,KAAK;QACrB,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ;QACpC,KAAK,CAAC,UAAU,IAAI,GAAG;QACvB,KAAK,CAAC,UAAU,IAAI,GAAG,CACxB,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CACvB,KAAc,EACd,SAAiB;IAEjB,IAAI,KAAK,YAAY,sBAAsB,EAAE,CAAC;QAC5C,OAAO;YACL,MAAM,EAAE,GAAG;YACX,IAAI,EAAE;gBACJ,KAAK,EAAE;oBACL,IAAI,EAAE,mBAAmB;oBACzB,OAAO,EAAE,WAAW,KAAK,CAAC,IAAI,oBAAoB;oBAClD,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE;iBAC1D;aACF;YACD,UAAU,EAAE,KAAK;SACl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I,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACnD,KAAK,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC,CACF,CAAC;IAEF,GAAG,CAAC,kBAAkB,CAAC,CAAC,OAAuB,EAAE,KAAmB,EAAE,EAAE;QACtE,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACxC,KAAK,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YAC1B,KAAK,EAAE;gBACL,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,SAAS,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,iBAAiB;aACjE;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A feature preview: one caller forcing one feature on or off for their own
|
|
3
|
+
* requests, without changing anybody's saved audience.
|
|
4
|
+
*
|
|
5
|
+
* The kit owns the once-per-request protocol — read the preview id header,
|
|
6
|
+
* ask the application whether it names a live preview for this caller, refuse
|
|
7
|
+
* a write the preview does not allow, and carry the preview for the rest of
|
|
8
|
+
* the request so every evaluation inside it (the snapshot, capability guards,
|
|
9
|
+
* a handler's own flag check) sees the same answer. What a preview id means,
|
|
10
|
+
* who may hold one and which features exist are the application's.
|
|
11
|
+
*/
|
|
12
|
+
import type { SubjectRef } from "@dads-framework/access/runtime";
|
|
13
|
+
/** A live preview, as the application resolved it for this request. */
|
|
14
|
+
export type FeatureStatePreview = {
|
|
15
|
+
/** The one feature this preview forces. */
|
|
16
|
+
readonly feature: string;
|
|
17
|
+
/** Whether that feature reads as on while the preview applies. */
|
|
18
|
+
readonly active: boolean;
|
|
19
|
+
/** Whether writes run while this preview applies; false refuses them. */
|
|
20
|
+
readonly allowsWrites: boolean;
|
|
21
|
+
/** Application-defined context key for evaluations inside the request. */
|
|
22
|
+
readonly scopeKey?: string;
|
|
23
|
+
};
|
|
24
|
+
/** Application-bound resolver. Null means the id names no live preview for this caller. */
|
|
25
|
+
export type FeatureStatePreviewResolver = {
|
|
26
|
+
resolve(input: {
|
|
27
|
+
readonly previewId: string;
|
|
28
|
+
readonly authenticatedSubject: SubjectRef;
|
|
29
|
+
readonly subject: SubjectRef | null;
|
|
30
|
+
readonly context: string | undefined;
|
|
31
|
+
}): Promise<FeatureStatePreview | null>;
|
|
32
|
+
};
|
|
33
|
+
/** The application's half of the preview protocol: who resolves an id, and the header names its clients speak. */
|
|
34
|
+
export type FeatureStatePreviewProtocol = {
|
|
35
|
+
readonly resolver: FeatureStatePreviewResolver;
|
|
36
|
+
/** Request header carrying the caller's preview id. */
|
|
37
|
+
readonly requestHeader: string;
|
|
38
|
+
/** Response header written when the supplied id names no live preview, so the client forgets it. */
|
|
39
|
+
readonly droppedHeader: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The preview the current request carries, or `undefined` outside a request or
|
|
43
|
+
* when it carries none. Evaluators call this, so a capability guard deep in a
|
|
44
|
+
* handler answers the same as the request's own snapshot.
|
|
45
|
+
*/
|
|
46
|
+
export declare function currentFeatureStatePreview(): FeatureStatePreview | undefined;
|
|
47
|
+
/** Runs `work` with `preview` as the current preview, for this pipeline and for tests. */
|
|
48
|
+
export declare function runWithFeatureStatePreview<T>(preview: FeatureStatePreview, work: () => Promise<T>): Promise<T>;
|
|
49
|
+
type PreviewReply = {
|
|
50
|
+
header(name: string, value: string): unknown;
|
|
51
|
+
readonly raw: {
|
|
52
|
+
setHeader(name: string, value: string): unknown;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
type PreviewRequest = {
|
|
56
|
+
readonly headers: Record<string, string | string[] | undefined>;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Resolves the request's preview id once, refuses a write the preview does not
|
|
60
|
+
* allow, and runs `work` inside the preview.
|
|
61
|
+
*
|
|
62
|
+
* An id that resolves to nothing never fails the request: it is answered as
|
|
63
|
+
* if no preview were sent, with `droppedHeader` telling the client to forget
|
|
64
|
+
* it. A request with no authenticated caller cannot hold a preview, so its id
|
|
65
|
+
* is ignored without a verdict.
|
|
66
|
+
*/
|
|
67
|
+
export declare function carryFeatureStatePreview<T>(input: {
|
|
68
|
+
readonly protocol: FeatureStatePreviewProtocol | undefined;
|
|
69
|
+
readonly request: PreviewRequest;
|
|
70
|
+
readonly reply: PreviewReply;
|
|
71
|
+
readonly authenticatedSubject: SubjectRef | null;
|
|
72
|
+
readonly subject: SubjectRef | null;
|
|
73
|
+
readonly context: string | undefined;
|
|
74
|
+
readonly method: string;
|
|
75
|
+
readonly writesDuringFeaturePreview: "allowed" | undefined;
|
|
76
|
+
readonly work: () => Promise<T>;
|
|
77
|
+
}): Promise<T>;
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=feature-state-preview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-state-preview.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/feature-state-preview.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAKjE,uEAAuE;AACvE,MAAM,MAAM,mBAAmB,GAAG;IAChC,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,yEAAyE;IACzE,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,2FAA2F;AAC3F,MAAM,MAAM,2BAA2B,GAAG;IACxC,OAAO,CAAC,KAAK,EAAE;QACb,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,Q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