@dads-framework/http 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +219 -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 +69 -0
- package/dist/lib/request-pipeline/feature-state-preview.d.ts.map +1 -0
- package/dist/lib/request-pipeline/feature-state-preview.js +61 -0
- package/dist/lib/request-pipeline/feature-state-preview.js.map +1 -0
- package/dist/lib/request-pipeline/feature-state.d.ts +64 -0
- package/dist/lib/request-pipeline/feature-state.d.ts.map +1 -0
- package/dist/lib/request-pipeline/feature-state.js +38 -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 +215 -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 +55 -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 +98 -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,61 @@
|
|
|
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 { AsyncLocalStorage } from "node:async_hooks";
|
|
13
|
+
import { forbidden } from "@dads-framework/errors";
|
|
14
|
+
import { isWriteMethod } from "./logic/is-write-method.js";
|
|
15
|
+
const previewContext = new AsyncLocalStorage();
|
|
16
|
+
/**
|
|
17
|
+
* The preview the current request carries, or `undefined` outside a request or
|
|
18
|
+
* when it carries none. Evaluators call this, so a capability guard deep in a
|
|
19
|
+
* handler answers the same as the request's own snapshot.
|
|
20
|
+
*/
|
|
21
|
+
export function currentFeatureStatePreview() {
|
|
22
|
+
return previewContext.getStore();
|
|
23
|
+
}
|
|
24
|
+
/** Runs `work` with `preview` as the current preview, for this pipeline and for tests. */
|
|
25
|
+
export function runWithFeatureStatePreview(preview, work) {
|
|
26
|
+
return previewContext.run(preview, work);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Resolves the request's preview id once, refuses a write the preview does not
|
|
30
|
+
* allow, and runs `work` inside the preview.
|
|
31
|
+
*
|
|
32
|
+
* An id that resolves to nothing never fails the request: it is answered as
|
|
33
|
+
* if no preview were sent, with `droppedHeader` telling the client to forget
|
|
34
|
+
* it. A request with no authenticated caller cannot hold a preview, so its id
|
|
35
|
+
* is ignored without a verdict.
|
|
36
|
+
*/
|
|
37
|
+
export async function carryFeatureStatePreview(input) {
|
|
38
|
+
const { protocol } = input;
|
|
39
|
+
if (protocol === undefined || input.authenticatedSubject === null) {
|
|
40
|
+
return input.work();
|
|
41
|
+
}
|
|
42
|
+
const previewId = input.request.headers[protocol.requestHeader];
|
|
43
|
+
if (typeof previewId !== "string" || previewId.length === 0) {
|
|
44
|
+
return input.work();
|
|
45
|
+
}
|
|
46
|
+
const preview = await protocol.resolver.resolve({
|
|
47
|
+
previewId,
|
|
48
|
+
authenticatedSubject: input.authenticatedSubject,
|
|
49
|
+
});
|
|
50
|
+
if (preview === null) {
|
|
51
|
+
void input.reply.header(protocol.droppedHeader, "1");
|
|
52
|
+
return input.work();
|
|
53
|
+
}
|
|
54
|
+
if (!preview.allowsWrites &&
|
|
55
|
+
isWriteMethod(input.method) &&
|
|
56
|
+
input.writesDuringFeaturePreview !== "allowed") {
|
|
57
|
+
throw forbidden("FEATURE_PREVIEW_READ_ONLY", "Saving is turned off while previewing");
|
|
58
|
+
}
|
|
59
|
+
return runWithFeatureStatePreview(preview, input.work);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=feature-state-preview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-state-preview.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/feature-state-preview.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AA6B3D,MAAM,cAAc,GAAG,IAAI,iBAAiB,EAAuB,CAAC;AAEpE;;;;GAIG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO,cAAc,CAAC,QAAQ,EAAE,CAAC;AACnC,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,0BAA0B,CACxC,OAA4B,EAC5B,IAAsB;IAEtB,OAAO,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC;AAMD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAI,KAQjD;IACC,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3B,IAAI,QAAQ,KAAK,SAAS,IAAI,KAAK,CAAC,oBAAoB,KAAK,IAAI,EAAE,CAAC;QAClE,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC;IACD,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAChE,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5D,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;QAC9C,SAAS;QACT,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;KACjD,CAAC,CAAC;IACH,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,KAAK,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QACrD,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC;IACD,IACE,CAAC,OAAO,CAAC,YAAY;QACrB,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC;QAC3B,KAAK,CAAC,0BAA0B,KAAK,SAAS,EAC9C,CAAC;QACD,MAAM,SAAS,CACb,2BAA2B,EAC3B,uCAAuC,CACxC,CAAC;IACJ,CAAC;IACD,OAAO,0BAA0B,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { SubjectRef } from "@dads-framework/access/runtime";
|
|
2
|
+
import type { FeatureStatePreviewProtocol } from "./feature-state-preview.js";
|
|
3
|
+
/**
|
|
4
|
+
* What this kit needs from a request's feature-state snapshot: the hash it
|
|
5
|
+
* writes to the response header and compares on a sensitive write, plus the
|
|
6
|
+
* effective allow-list it hands to handlers untouched. A product's own
|
|
7
|
+
* snapshot type is this shape, so it reaches its handlers without a cast.
|
|
8
|
+
*/
|
|
9
|
+
export type FeatureStateSnapshot = {
|
|
10
|
+
readonly features: string[];
|
|
11
|
+
readonly stateHash: string;
|
|
12
|
+
};
|
|
13
|
+
/** Application-bound snapshot evaluator. Null excludes technical or unauthenticated traffic. */
|
|
14
|
+
export type FeatureStateRequestEvaluator = {
|
|
15
|
+
evaluate(input: {
|
|
16
|
+
readonly authenticatedSubject: SubjectRef;
|
|
17
|
+
readonly subject: SubjectRef;
|
|
18
|
+
readonly context: string | undefined;
|
|
19
|
+
}): Promise<FeatureStateSnapshot | null>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The application's half of the feature-state protocol: who evaluates a
|
|
23
|
+
* request, and the header names its clients speak. The kit owns the
|
|
24
|
+
* once-per-request protocol; the wire spelling is an agreement between a
|
|
25
|
+
* product's own client and API, so the product names it.
|
|
26
|
+
*/
|
|
27
|
+
export type FeatureStateProtocol = {
|
|
28
|
+
readonly evaluator: FeatureStateRequestEvaluator;
|
|
29
|
+
/** Response header the current snapshot's hash is written to. */
|
|
30
|
+
readonly hashHeader: string;
|
|
31
|
+
/** Request header carrying the hash the client last saw. */
|
|
32
|
+
readonly clientHashHeader: string;
|
|
33
|
+
/** Request header naming the caller's context, handed to the evaluator. */
|
|
34
|
+
readonly contextHeader: string;
|
|
35
|
+
/**
|
|
36
|
+
* Optional per-caller preview of one feature. Omitted, a preview id header
|
|
37
|
+
* is ignored like any unknown header.
|
|
38
|
+
*/
|
|
39
|
+
readonly preview?: FeatureStatePreviewProtocol;
|
|
40
|
+
};
|
|
41
|
+
type HeaderCarrier = {
|
|
42
|
+
readonly headers: Record<string, string | string[] | undefined>;
|
|
43
|
+
};
|
|
44
|
+
/** Resolves a request-local snapshot without retaining a database connection. */
|
|
45
|
+
export declare function resolveFeatureState(input: {
|
|
46
|
+
readonly protocol: FeatureStateProtocol;
|
|
47
|
+
readonly request: HeaderCarrier;
|
|
48
|
+
readonly authenticatedSubject: SubjectRef | null;
|
|
49
|
+
readonly subject: SubjectRef | null;
|
|
50
|
+
}): Promise<FeatureStateSnapshot | null>;
|
|
51
|
+
/** Rejects only a supplied stale mutation hash, after its refresh hash is written. */
|
|
52
|
+
export declare function assertFeatureStateWriteIsCurrent(input: {
|
|
53
|
+
readonly snapshot: FeatureStateSnapshot | null;
|
|
54
|
+
readonly clientHashHeader: string;
|
|
55
|
+
readonly request: HeaderCarrier;
|
|
56
|
+
readonly method: string;
|
|
57
|
+
readonly featureStateWrite: "sensitive" | undefined;
|
|
58
|
+
}): void;
|
|
59
|
+
/** Keeps the exact public header spelling at the shared HTTP seam. */
|
|
60
|
+
export declare function writeFeatureStateHash(reply: {
|
|
61
|
+
header(name: string, value: string): unknown;
|
|
62
|
+
}, hashHeader: string, snapshot: FeatureStateSnapshot | null): void;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=feature-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-state.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/feature-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAGjE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAE9E;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,gGAAgG;AAChG,MAAM,MAAM,4BAA4B,GAAG;IACzC,QAAQ,CAAC,KAAK,EAAE;QACd,QAAQ,CAAC,oBAAoB,EAAE,UAAU,CAAC;QAC1C,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;QAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;KACtC,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,SAAS,EAAE,4BAA4B,CAAC;IACjD,iEAAiE;IACjE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,2EAA2E;IAC3E,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,2BAA2B,CAAC;CAChD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;CACjE,CAAC;AAOF,iFAAiF;AACjF,wBAAsB,mBAAmB,CAAC,KAAK,EAAE;IAC/C,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,oBAAoB,EAAE,UAAU,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;CACrC,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAQvC;AAED,sFAAsF;AACtF,wBAAgB,gCAAgC,CAAC,KAAK,EAAE;IACtD,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC/C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,iBAAiB,EAAE,WAAW,GAAG,SAAS,CAAC;CACrD,GAAG,IAAI,CAoBP;AAED,sEAAsE;AACtE,wBAAgB,qBAAqB,CACnC,KAAK,EAAE;IAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EACvD,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,oBAAoB,GAAG,IAAI,GACpC,IAAI,CAEN"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { conflict } from "@dads-framework/errors";
|
|
2
|
+
function oneHeader(request, name) {
|
|
3
|
+
const value = request.headers[name];
|
|
4
|
+
return typeof value === "string" ? value : undefined;
|
|
5
|
+
}
|
|
6
|
+
/** Resolves a request-local snapshot without retaining a database connection. */
|
|
7
|
+
export async function resolveFeatureState(input) {
|
|
8
|
+
if (!input.authenticatedSubject || !input.subject)
|
|
9
|
+
return null;
|
|
10
|
+
const snapshot = await input.protocol.evaluator.evaluate({
|
|
11
|
+
authenticatedSubject: input.authenticatedSubject,
|
|
12
|
+
subject: input.subject,
|
|
13
|
+
context: oneHeader(input.request, input.protocol.contextHeader),
|
|
14
|
+
});
|
|
15
|
+
return snapshot;
|
|
16
|
+
}
|
|
17
|
+
/** Rejects only a supplied stale mutation hash, after its refresh hash is written. */
|
|
18
|
+
export function assertFeatureStateWriteIsCurrent(input) {
|
|
19
|
+
if (!input.snapshot)
|
|
20
|
+
return;
|
|
21
|
+
const supplied = oneHeader(input.request, input.clientHashHeader);
|
|
22
|
+
const writes = input.method === "POST" ||
|
|
23
|
+
input.method === "PUT" ||
|
|
24
|
+
input.method === "PATCH" ||
|
|
25
|
+
input.method === "DELETE";
|
|
26
|
+
if (writes &&
|
|
27
|
+
input.featureStateWrite === "sensitive" &&
|
|
28
|
+
supplied !== undefined &&
|
|
29
|
+
supplied !== input.snapshot.stateHash) {
|
|
30
|
+
throw conflict("STALE_FEATURE_STATE", "Feature state changed; refresh before retrying this write", { currentFeatureStateHash: input.snapshot.stateHash });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Keeps the exact public header spelling at the shared HTTP seam. */
|
|
34
|
+
export function writeFeatureStateHash(reply, hashHeader, snapshot) {
|
|
35
|
+
if (snapshot)
|
|
36
|
+
void reply.header(hashHeader, snapshot.stateHash);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=feature-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-state.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/feature-state.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAiDlD,SAAS,SAAS,CAAC,OAAsB,EAAE,IAAY;IACrD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC;AAED,iFAAiF;AACjF,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,KAKzC;IACC,IAAI,CAAC,KAAK,CAAC,oBAAoB,IAAI,CAAC,KAAK,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC/D,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC;QACvD,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;QAChD,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC;KAChE,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,gCAAgC,CAAC,KAMhD;IACC,IAAI,CAAC,KAAK,CAAC,QAAQ;QAAE,OAAO;IAC5B,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAClE,MAAM,MAAM,GACV,KAAK,CAAC,MAAM,KAAK,MAAM;QACvB,KAAK,CAAC,MAAM,KAAK,KAAK;QACtB,KAAK,CAAC,MAAM,KAAK,OAAO;QACxB,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC;IAC5B,IACE,MAAM;QACN,KAAK,CAAC,iBAAiB,KAAK,WAAW;QACvC,QAAQ,KAAK,SAAS;QACtB,QAAQ,KAAK,KAAK,CAAC,QAAQ,CAAC,SAAS,EACrC,CAAC;QACD,MAAM,QAAQ,CACZ,qBAAqB,EACrB,2DAA2D,EAC3D,EAAE,uBAAuB,EAAE,KAAK,CAAC,QAAQ,CAAC,SAAS,EAAE,CACtD,CAAC;IACJ,CAAC;AACH,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,qBAAqB,CACnC,KAAuD,EACvD,UAAkB,EAClB,QAAqC;IAErC,IAAI,QAAQ;QAAE,KAAK,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-write-method.d.ts","sourceRoot":"","sources":["../../../../src/lib/request-pipeline/logic/is-write-method.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAOrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-write-method.js","sourceRoot":"","sources":["../../../../src/lib/request-pipeline/logic/is-write-method.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,OAAO,CACL,MAAM,KAAK,MAAM;QACjB,MAAM,KAAK,KAAK;QAChB,MAAM,KAAK,OAAO;QAClB,MAAM,KAAK,QAAQ,CACpB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ResourceIdSource } from "../../route/access.js";
|
|
2
|
+
/** The parts of a request that a route's declared id or context source can name. */
|
|
3
|
+
export type SourceReadableRequest = {
|
|
4
|
+
readonly headers: Record<string, string | string[] | undefined>;
|
|
5
|
+
/** Original occurrences let enforcement detect duplicate headers even after joining. */
|
|
6
|
+
readonly raw?: {
|
|
7
|
+
readonly rawHeaders: readonly string[];
|
|
8
|
+
};
|
|
9
|
+
readonly params: unknown;
|
|
10
|
+
/** Fastify's parsed body — read RAW here (enforcement precedes Zod). */
|
|
11
|
+
readonly body?: unknown;
|
|
12
|
+
/** Fastify's parsed query — read RAW here (enforcement precedes Zod). */
|
|
13
|
+
readonly query?: unknown;
|
|
14
|
+
};
|
|
15
|
+
/** Resolve only the explicitly declared request source for a permission check. */
|
|
16
|
+
export declare function resolveResourceId(source: ResourceIdSource, request: SourceReadableRequest): string | undefined;
|
|
17
|
+
/** Only omission selects technical identity; present malformed inputs still fail resolution. */
|
|
18
|
+
export declare function isTechnicalContextAbsent(source: ResourceIdSource, request: SourceReadableRequest): boolean;
|
|
19
|
+
//# sourceMappingURL=read-request-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-request-source.d.ts","sourceRoot":"","sources":["../../../../src/lib/request-pipeline/logic/read-request-source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,oFAAoF;AACpF,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IAChE,wFAAwF;IACxF,QAAQ,CAAC,GAAG,CAAC,EAAE;QAAE,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,CAAC;IAC1D,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,wEAAwE;IACxE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,yEAAyE;IACzE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAQF,kFAAkF;AAClF,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,qBAAqB,GAC7B,MAAM,GAAG,SAAS,CAqBpB;AAED,gGAAgG;AAChG,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAUT"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isObjectValue } from "../../object-value.js";
|
|
2
|
+
import { singleRequestHeader } from "./single-request-header.js";
|
|
3
|
+
function paramOf(params, name) {
|
|
4
|
+
if (!isObjectValue(params))
|
|
5
|
+
return undefined;
|
|
6
|
+
const value = params[name];
|
|
7
|
+
return typeof value === "string" ? value : undefined;
|
|
8
|
+
}
|
|
9
|
+
/** Resolve only the explicitly declared request source for a permission check. */
|
|
10
|
+
export function resolveResourceId(source, request) {
|
|
11
|
+
switch (source.kind) {
|
|
12
|
+
case "fixed":
|
|
13
|
+
return source.id;
|
|
14
|
+
case "param":
|
|
15
|
+
return paramOf(request.params, source.name);
|
|
16
|
+
case "body":
|
|
17
|
+
return paramOf(request.body, source.name);
|
|
18
|
+
case "query":
|
|
19
|
+
return paramOf(request.query, source.name);
|
|
20
|
+
case "header":
|
|
21
|
+
return singleRequestHeader(source.name, request.headers, request.raw?.rawHeaders);
|
|
22
|
+
default: {
|
|
23
|
+
const _exhaustive = source;
|
|
24
|
+
return _exhaustive;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Only omission selects technical identity; present malformed inputs still fail resolution. */
|
|
29
|
+
export function isTechnicalContextAbsent(source, request) {
|
|
30
|
+
if (source.kind === "header")
|
|
31
|
+
return request.headers[source.name.toLowerCase()] === undefined;
|
|
32
|
+
if (source.kind !== "query")
|
|
33
|
+
return false;
|
|
34
|
+
if (request.query === undefined)
|
|
35
|
+
return true;
|
|
36
|
+
return (typeof request.query === "object" &&
|
|
37
|
+
request.query !== null &&
|
|
38
|
+
!Object.prototype.hasOwnProperty.call(request.query, source.name));
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=read-request-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-request-source.js","sourceRoot":"","sources":["../../../../src/lib/request-pipeline/logic/read-request-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAcjE,SAAS,OAAO,CAAC,MAAe,EAAE,IAAY;IAC5C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;QAAE,OAAO,SAAS,CAAC;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,iBAAiB,CAC/B,MAAwB,EACxB,OAA8B;IAE9B,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,OAAO;YACV,OAAO,MAAM,CAAC,EAAE,CAAC;QACnB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9C,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,KAAK,OAAO;YACV,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7C,KAAK,QAAQ;YACX,OAAO,mBAAmB,CACxB,MAAM,CAAC,IAAI,EACX,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,GAAG,EAAE,UAAU,CACxB,CAAC;QACJ,SAAS,CAAC;YACR,MAAM,WAAW,GAAU,MAAM,CAAC;YAClC,OAAO,WAAW,CAAC;QACrB,CAAC;IACH,CAAC;AACH,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,wBAAwB,CACtC,MAAwB,EACxB,OAA8B;IAE9B,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ;QAC1B,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,SAAS,CAAC;IAClE,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAC1C,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAC7C,OAAO,CACL,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;QACjC,OAAO,CAAC,KAAK,KAAK,IAAI;QACtB,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAClE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Single-valued context/resource headers cannot borrow the first of several values. */
|
|
2
|
+
export declare function singleRequestHeader(name: string, headers: Readonly<Record<string, string | string[] | undefined>>, rawHeaders?: readonly string[]): string | undefined;
|
|
3
|
+
//# sourceMappingURL=single-request-header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-request-header.d.ts","sourceRoot":"","sources":["../../../../src/lib/request-pipeline/logic/single-request-header.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,EAChE,UAAU,GAAE,SAAS,MAAM,EAAO,GACjC,MAAM,GAAG,SAAS,CAcpB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Single-valued context/resource headers cannot borrow the first of several values. */
|
|
2
|
+
export function singleRequestHeader(name, headers, rawHeaders = []) {
|
|
3
|
+
const normalizedName = name.toLowerCase();
|
|
4
|
+
const headerValue = headers[normalizedName];
|
|
5
|
+
if (typeof headerValue !== "string" ||
|
|
6
|
+
headerValue.trim().length === 0 ||
|
|
7
|
+
headerValue.includes(","))
|
|
8
|
+
return undefined;
|
|
9
|
+
let occurrences = 0;
|
|
10
|
+
for (let index = 0; index < rawHeaders.length; index += 2) {
|
|
11
|
+
if (rawHeaders[index]?.toLowerCase() === normalizedName)
|
|
12
|
+
occurrences += 1;
|
|
13
|
+
}
|
|
14
|
+
return occurrences > 1 ? undefined : headerValue;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=single-request-header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-request-header.js","sourceRoot":"","sources":["../../../../src/lib/request-pipeline/logic/single-request-header.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,OAAgE,EAChE,UAAU,GAAsB,EAAE;IAElC,MAAM,cAAc,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC1C,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC5C,IACE,OAAO,WAAW,KAAK,QAAQ;QAC/B,WAAW,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAC/B,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC;QAEzB,OAAO,SAAS,CAAC;IACnB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC1D,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,KAAK,cAAc;YAAE,WAAW,IAAI,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RouteCapabilities } from "../route/capabilities.js";
|
|
2
|
+
import type { HttpRoute } from "../route/route-group.js";
|
|
3
|
+
import type { SubjectResolver } from "./enforce-access.js";
|
|
4
|
+
/** The one option a machine-credential route reads beyond the access ports. */
|
|
5
|
+
type MachineCredentialOptions = {
|
|
6
|
+
readonly subjects: SubjectResolver;
|
|
7
|
+
readonly machineCredentials?: Readonly<Record<string, SubjectResolver>>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The options one route enforces access with: a route declaring
|
|
11
|
+
* `capabilities.machineCredential` swaps the session resolver for its named
|
|
12
|
+
* machine resolver, so its caller can only be that machine. Wiring mistakes
|
|
13
|
+
* (a public route, a missing resolver) throw at registration, never per request.
|
|
14
|
+
*/
|
|
15
|
+
export declare function routeOptionsFor<Options extends MachineCredentialOptions>(definition: HttpRoute, options: Options): Options;
|
|
16
|
+
/** A machine credential is declared by a route or its group, never app-wide. */
|
|
17
|
+
export declare function assertNoAppMachineCredential(capabilities: RouteCapabilities | undefined): void;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=machine-credential-access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine-credential-access.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/machine-credential-access.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,+EAA+E;AAC/E,KAAK,wBAAwB,GAAG;IAC9B,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CACzE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,wBAAwB,EACtE,UAAU,EAAE,SAAS,EACrB,OAAO,EAAE,OAAO,GACf,OAAO,CAgBT;AAED,gFAAgF;AAChF,wBAAgB,4BAA4B,CAC1C,YAAY,EAAE,iBAAiB,GAAG,SAAS,GAC1C,IAAI,CAMN"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { HttpWiringError } from "../http-errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* The options one route enforces access with: a route declaring
|
|
4
|
+
* `capabilities.machineCredential` swaps the session resolver for its named
|
|
5
|
+
* machine resolver, so its caller can only be that machine. Wiring mistakes
|
|
6
|
+
* (a public route, a missing resolver) throw at registration, never per request.
|
|
7
|
+
*/
|
|
8
|
+
export function routeOptionsFor(definition, options) {
|
|
9
|
+
const name = definition.capabilities.machineCredential;
|
|
10
|
+
if (name === undefined)
|
|
11
|
+
return options;
|
|
12
|
+
const where = `${definition.method} ${definition.path}`;
|
|
13
|
+
if (definition.access.kind === "public") {
|
|
14
|
+
throw new HttpWiringError(`${where} declares machineCredential "${name}" on a public route — a machine credential needs an access declaration that resolves a subject`);
|
|
15
|
+
}
|
|
16
|
+
const resolver = options.machineCredentials?.[name];
|
|
17
|
+
if (resolver === undefined) {
|
|
18
|
+
throw new HttpWiringError(`${where} declares machineCredential "${name}" but registerRoutes received no machineCredentials["${name}"] resolver`);
|
|
19
|
+
}
|
|
20
|
+
return { ...options, subjects: resolver };
|
|
21
|
+
}
|
|
22
|
+
/** A machine credential is declared by a route or its group, never app-wide. */
|
|
23
|
+
export function assertNoAppMachineCredential(capabilities) {
|
|
24
|
+
if (capabilities?.machineCredential !== undefined) {
|
|
25
|
+
throw new HttpWiringError("registerRoutes capabilities.machineCredential is not allowed — a machine credential is declared by a route or its group, never app-wide");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=machine-credential-access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine-credential-access.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/machine-credential-access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAWpD;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,UAAqB,EACrB,OAAgB;IAEhB,MAAM,IAAI,GAAG,UAAU,CAAC,YAAY,CAAC,iBAAiB,CAAC;IACvD,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IACvC,MAAM,KAAK,GAAG,GAAG,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;IACxD,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,eAAe,CACvB,GAAG,KAAK,gCAAgC,IAAI,gGAAgG,CAC7I,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,CAAC;IACpD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,eAAe,CACvB,GAAG,KAAK,gCAAgC,IAAI,wDAAwD,IAAI,aAAa,CACtH,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AAC5C,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,4BAA4B,CAC1C,YAA2C;IAE3C,IAAI,YAAY,EAAE,iBAAiB,KAAK,SAAS,EAAE,CAAC;QAClD,MAAM,IAAI,eAAe,CACvB,yIAAyI,CAC1I,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RateLimitCapability } from "../route/capabilities.js";
|
|
2
|
+
export type RateLimiter = {
|
|
3
|
+
/** True when the caller still has budget; counts the request. */
|
|
4
|
+
readonly consume: (routeKey: string, callerKey: string) => RateVerdict;
|
|
5
|
+
/** Callers currently tracked — bounded by eviction; for tests and metrics. */
|
|
6
|
+
readonly size: () => number;
|
|
7
|
+
};
|
|
8
|
+
export type RateVerdict = {
|
|
9
|
+
readonly allowed: true;
|
|
10
|
+
} | {
|
|
11
|
+
readonly allowed: false;
|
|
12
|
+
readonly retryAfterSeconds: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function createRateLimiter(limit: Exclude<RateLimitCapability, "unlimited">, now: () => number): RateLimiter;
|
|
15
|
+
//# sourceMappingURL=rate-limit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/rate-limit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAapE,MAAM,MAAM,WAAW,GAAG;IACxB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,WAAW,CAAC;IACvE,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,MAAM,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpE,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,CAAC,mBAAmB,EAAE,WAAW,CAAC,EAChD,GAAG,EAAE,MAAM,MAAM,GAChB,WAAW,CAwCb"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const WINDOW_MS = 60_000;
|
|
2
|
+
export function createRateLimiter(limit, now) {
|
|
3
|
+
const windows = new Map();
|
|
4
|
+
let nextSweepAtMs = 0;
|
|
5
|
+
// Without eviction, every distinct caller ever seen lives in the map for
|
|
6
|
+
// the replica's lifetime — a churning-IP flood becomes unbounded memory
|
|
7
|
+
// growth. One sweep per window keeps the map bounded by a single window's
|
|
8
|
+
// distinct callers, at O(entries) once a minute.
|
|
9
|
+
function sweepExpiredWindows(at) {
|
|
10
|
+
if (at < nextSweepAtMs)
|
|
11
|
+
return;
|
|
12
|
+
nextSweepAtMs = at + WINDOW_MS;
|
|
13
|
+
for (const [key, window] of windows) {
|
|
14
|
+
if (window.resetAtMs <= at)
|
|
15
|
+
windows.delete(key);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
size: () => windows.size,
|
|
20
|
+
consume: (routeKey, callerKey) => {
|
|
21
|
+
const key = `${routeKey}\u0000${callerKey}`;
|
|
22
|
+
const at = now();
|
|
23
|
+
sweepExpiredWindows(at);
|
|
24
|
+
const window = windows.get(key);
|
|
25
|
+
if (!window || window.resetAtMs <= at) {
|
|
26
|
+
windows.set(key, { count: 1, resetAtMs: at + WINDOW_MS });
|
|
27
|
+
return { allowed: true };
|
|
28
|
+
}
|
|
29
|
+
if (window.count < limit.perMinute) {
|
|
30
|
+
window.count += 1;
|
|
31
|
+
return { allowed: true };
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
allowed: false,
|
|
35
|
+
retryAfterSeconds: Math.max(1, Math.ceil((window.resetAtMs - at) / 1000)),
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=rate-limit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/rate-limit.ts"],"names":[],"mappings":"AAWA,MAAM,SAAS,GAAG,MAAM,CAAC;AAazB,MAAM,UAAU,iBAAiB,CAC/B,KAAgD,EAChD,GAAiB;IAEjB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,IAAI,aAAa,GAAG,CAAC,CAAC;IAEtB,yEAAyE;IACzE,wEAAwE;IACxE,0EAA0E;IAC1E,iDAAiD;IACjD,SAAS,mBAAmB,CAAC,EAAU;QACrC,IAAI,EAAE,GAAG,aAAa;YAAE,OAAO;QAC/B,aAAa,GAAG,EAAE,GAAG,SAAS,CAAC;QAC/B,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACpC,IAAI,MAAM,CAAC,SAAS,IAAI,EAAE;gBAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI;QACxB,OAAO,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE;YAC/B,MAAM,GAAG,GAAG,GAAG,QAAQ,SAAS,SAAS,EAAE,CAAC;YAC5C,MAAM,EAAE,GAAG,GAAG,EAAE,CAAC;YACjB,mBAAmB,CAAC,EAAE,CAAC,CAAC;YACxB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAChC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC;gBACtC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;gBAC1D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YAC3B,CAAC;YACD,IAAI,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;gBACnC,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;gBAClB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YAC3B,CAAC;YACD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,iBAAiB,EAAE,IAAI,CAAC,GAAG,CACzB,CAAC,EACD,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAC1C;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FastifyRequest } from "fastify";
|
|
2
|
+
/**
|
|
3
|
+
* The one media type a byte-body route's request is parsed as, whatever the
|
|
4
|
+
* client sent. The app's byte parser answers it (`byteBodyContentTypes`).
|
|
5
|
+
*/
|
|
6
|
+
export declare const BYTE_BODY_PARSE_TYPE = "application/octet-stream";
|
|
7
|
+
/**
|
|
8
|
+
* Makes Fastify parse this request's body as bytes, whatever it was sent as.
|
|
9
|
+
* Fastify picks the parser from the `content-type` header, and its built-in
|
|
10
|
+
* JSON and text parsers beat a catch-all byte parser, so a `text/plain` or
|
|
11
|
+
* `application/json` body would arrive as a string or an object. Run from the
|
|
12
|
+
* route's own `onRequest`, before the parser is chosen, so it reaches this
|
|
13
|
+
* route alone. The header the client sent stays readable through
|
|
14
|
+
* `contentTypeSentWithBytes`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseBodyAsBytes(request: FastifyRequest): void;
|
|
17
|
+
/** The `content-type` the client sent on a byte-body route's request; undefined if it sent none. */
|
|
18
|
+
export declare function contentTypeSentWithBytes(request: FastifyRequest): string | undefined;
|
|
19
|
+
//# sourceMappingURL=raw-route-byte-body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-route-byte-body.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/raw-route-byte-body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,6BAA6B,CAAC;AAI/D;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAG9D;AAED,oGAAoG;AACpG,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,cAAc,GACtB,MAAM,GAAG,SAAS,CAIpB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one media type a byte-body route's request is parsed as, whatever the
|
|
3
|
+
* client sent. The app's byte parser answers it (`byteBodyContentTypes`).
|
|
4
|
+
*/
|
|
5
|
+
export const BYTE_BODY_PARSE_TYPE = "application/octet-stream";
|
|
6
|
+
const sentContentTypes = new WeakMap();
|
|
7
|
+
/**
|
|
8
|
+
* Makes Fastify parse this request's body as bytes, whatever it was sent as.
|
|
9
|
+
* Fastify picks the parser from the `content-type` header, and its built-in
|
|
10
|
+
* JSON and text parsers beat a catch-all byte parser, so a `text/plain` or
|
|
11
|
+
* `application/json` body would arrive as a string or an object. Run from the
|
|
12
|
+
* route's own `onRequest`, before the parser is chosen, so it reaches this
|
|
13
|
+
* route alone. The header the client sent stays readable through
|
|
14
|
+
* `contentTypeSentWithBytes`.
|
|
15
|
+
*/
|
|
16
|
+
export function parseBodyAsBytes(request) {
|
|
17
|
+
sentContentTypes.set(request, request.headers["content-type"]);
|
|
18
|
+
request.headers["content-type"] = BYTE_BODY_PARSE_TYPE;
|
|
19
|
+
}
|
|
20
|
+
/** The `content-type` the client sent on a byte-body route's request; undefined if it sent none. */
|
|
21
|
+
export function contentTypeSentWithBytes(request) {
|
|
22
|
+
return sentContentTypes.has(request)
|
|
23
|
+
? sentContentTypes.get(request)
|
|
24
|
+
: request.headers["content-type"];
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=raw-route-byte-body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-route-byte-body.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/raw-route-byte-body.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAE/D,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAAsC,CAAC;AAE3E;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAuB;IACtD,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;IAC/D,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,oBAAoB,CAAC;AACzD,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,wBAAwB,CACtC,OAAuB;IAEvB,OAAO,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC;QAClC,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC;QAC/B,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type AccessModel } from "@dads-framework/access";
|
|
2
|
+
import type { HttpRoute } from "../route/route-group.js";
|
|
3
|
+
/**
|
|
4
|
+
* A `requiresVisible` route asks SpiceDB for every id the caller may see and
|
|
5
|
+
* hands them to the query as `WHERE id = ANY(...)`. That is bounded for a
|
|
6
|
+
* `scope` or `catalog`, and unbounded for a `record`, whose lists grow with
|
|
7
|
+
* the business until the page is slow and then fails. So a visibility access
|
|
8
|
+
* on a record refuses to register, and the API refuses to boot, unless the
|
|
9
|
+
* API's boot check registered a dated exception for it.
|
|
10
|
+
*
|
|
11
|
+
* An entity with no declared kind is let through here: the kit serves more
|
|
12
|
+
* than one product, and the product's boot check is what refuses an
|
|
13
|
+
* undeclared entity.
|
|
14
|
+
*/
|
|
15
|
+
export declare function refuseVisibleRecordList(route: HttpRoute, model: AccessModel | undefined): void;
|
|
16
|
+
//# sourceMappingURL=refuse-visible-record-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refuse-visible-record-list.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/refuse-visible-record-list.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,WAAW,GAAG,SAAS,GAC7B,IAAI,CAwBN"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { entityKindOf, visibleRecordException, } from "@dads-framework/access";
|
|
2
|
+
import { HttpWiringError } from "../http-errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* A `requiresVisible` route asks SpiceDB for every id the caller may see and
|
|
5
|
+
* hands them to the query as `WHERE id = ANY(...)`. That is bounded for a
|
|
6
|
+
* `scope` or `catalog`, and unbounded for a `record`, whose lists grow with
|
|
7
|
+
* the business until the page is slow and then fails. So a visibility access
|
|
8
|
+
* on a record refuses to register, and the API refuses to boot, unless the
|
|
9
|
+
* API's boot check registered a dated exception for it.
|
|
10
|
+
*
|
|
11
|
+
* An entity with no declared kind is let through here: the kit serves more
|
|
12
|
+
* than one product, and the product's boot check is what refuses an
|
|
13
|
+
* undeclared entity.
|
|
14
|
+
*/
|
|
15
|
+
export function refuseVisibleRecordList(route, model) {
|
|
16
|
+
const access = route.access;
|
|
17
|
+
if (access.kind !== "visibility")
|
|
18
|
+
return;
|
|
19
|
+
if (model === undefined) {
|
|
20
|
+
throw new HttpWiringError(`${route.method} ${route.path} uses requiresVisible without an access model`);
|
|
21
|
+
}
|
|
22
|
+
if (!model.definitions.some(({ entity }) => entity.wireName === access.resourceType)) {
|
|
23
|
+
throw new HttpWiringError(`${route.method} ${route.path} uses requiresVisible for ${access.resourceType}, which is missing from the access model`);
|
|
24
|
+
}
|
|
25
|
+
if (entityKindOf(model, access.resourceType) !== "record")
|
|
26
|
+
return;
|
|
27
|
+
if (visibleRecordException(model, access.resourceType) !== undefined)
|
|
28
|
+
return;
|
|
29
|
+
throw new HttpWiringError(`${route.method} ${route.path} lists ${access.resourceType}, a record, with requiresVisible; ` +
|
|
30
|
+
`a record list must use requiresScoped and declare scope bindings ` +
|
|
31
|
+
`(docs/architecture/authorization.md, "To move a record list onto a scope plan")`);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=refuse-visible-record-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refuse-visible-record-list.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/refuse-visible-record-list.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,sBAAsB,GAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,uBAAuB,CACrC,KAAgB,EAChB,KAA8B;IAE9B,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,IAAI,MAAM,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO;IACzC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,eAAe,CACvB,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,+CAA+C,CAC7E,CAAC;IACJ,CAAC;IACD,IACE,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CACrB,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,YAAY,CACxD,EACD,CAAC;QACD,MAAM,IAAI,eAAe,CACvB,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,6BAA6B,MAAM,CAAC,YAAY,0CAA0C,CACxH,CAAC;IACJ,CAAC;IACD,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC,KAAK,QAAQ;QAAE,OAAO;IAClE,IAAI,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC,KAAK,SAAS;QAAE,OAAO;IAC7E,MAAM,IAAI,eAAe,CACvB,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,UAAU,MAAM,CAAC,YAAY,oCAAoC;QAC5F,mEAAmE;QACnE,iFAAiF,CACpF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AccessModel } from "@dads-framework/access";
|
|
2
|
+
import type { FastifyInstance } from "fastify";
|
|
3
|
+
import type { RouteCapabilities } from "../route/capabilities.js";
|
|
4
|
+
import type { HttpRoute } from "../route/route-group.js";
|
|
5
|
+
import { type AuditActorForSubject } from "./carry-audit-actor.js";
|
|
6
|
+
import { type AccessPorts, type SubjectResolver } from "./enforce-access.js";
|
|
7
|
+
import { type FeatureStateProtocol } from "./feature-state.js";
|
|
8
|
+
export type RegisterRoutesOptions = AccessPorts & {
|
|
9
|
+
readonly routes: readonly HttpRoute[];
|
|
10
|
+
/** Required when a route declares list visibility or scope access. */
|
|
11
|
+
readonly accessModel?: AccessModel;
|
|
12
|
+
/** App rung of the capability ladder (route > group > app). */
|
|
13
|
+
readonly capabilities?: RouteCapabilities;
|
|
14
|
+
/**
|
|
15
|
+
* Hard deadline for a route's handler. Node's `requestTimeout` only bounds
|
|
16
|
+
* receiving the request from a slow client — nothing built-in stops a hung
|
|
17
|
+
* handler from pinning its socket, so the kit races every execute against
|
|
18
|
+
* this. A number, never disable-able. Default 30s.
|
|
19
|
+
*/
|
|
20
|
+
readonly handlerTimeoutMs?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Turns an allowed request's subject into the audit actor its writes are
|
|
23
|
+
* recorded under. The composition root passes what
|
|
24
|
+
* `composeSubjectToAuditActor` from `@dads-framework/audit` built for its own
|
|
25
|
+
* subject kinds; without it the handler keeps the ingress `anonymous`
|
|
26
|
+
* context — writes still succeed, they are just attributed to nobody.
|
|
27
|
+
*/
|
|
28
|
+
readonly auditActorForSubject?: AuditActorForSubject;
|
|
29
|
+
/**
|
|
30
|
+
* Optional application evaluator and the header names its clients speak; the
|
|
31
|
+
* kit owns the once-per-request protocol. Omitted, no snapshot is resolved
|
|
32
|
+
* and no hash header is written.
|
|
33
|
+
*/
|
|
34
|
+
readonly featureState?: FeatureStateProtocol;
|
|
35
|
+
/**
|
|
36
|
+
* Named machine-credential resolvers. A route declaring
|
|
37
|
+
* `capabilities.machineCredential: name` resolves its caller only through
|
|
38
|
+
* `machineCredentials[name]` (never `subjects`); every other route never
|
|
39
|
+
* consults these. A declared name without a resolver throws at registration.
|
|
40
|
+
*/
|
|
41
|
+
readonly machineCredentials?: Readonly<Record<string, SubjectResolver>>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Compiles a route table onto a Fastify instance. Each handler reads as the
|
|
45
|
+
* composition it is: `enforceAccess` → `runRoute` (parse → handler → parse,
|
|
46
|
+
* under `withDeadline`) → `envelope`. Failures propagate to the kit error
|
|
47
|
+
* handler — nothing here invents statuses beyond the access refusals.
|
|
48
|
+
*/
|
|
49
|
+
export declare function registerRoutes(app: FastifyInstance, options: RegisterRoutesOptions): void;
|
|
50
|
+
//# sourceMappingURL=register-routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-routes.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/register-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,SAAS,CAAC;AASjB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EAEL,KAAK,WAAW,EAEhB,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAEL,KAAK,oBAAoB,EAI1B,MAAM,oBAAoB,CAAC;AAkB5B,MAAM,MAAM,qBAAqB,GAAG,WAAW,GAAG;IAChD,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IACtC,sEAAsE;IACtE,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IACnC,+DAA+D;IAC/D,QAAQ,CAAC,YAAY,CAAC,EAAE,iBAAiB,CAAC;IAC1C;;;;;OAKG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC;;;;;;OAMG;IACH,QAAQ,CAAC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IACrD;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,oBAAoB,CAAC;IAC7C;;;;;OAKG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CACzE,CAAC;AA0SF;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,qBAAqB,GAC7B,IAAI,CAMN"}
|