@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,10 @@
|
|
|
1
|
+
import type { AuditActor } from "@dads-framework/audit-actor";
|
|
2
|
+
import { requestIdOf } from "./request-id.js";
|
|
3
|
+
/** Receives ingress correlation and the resolved audit actor's kind. */
|
|
4
|
+
export type RequestTrace = (facts: {
|
|
5
|
+
readonly requestId: string;
|
|
6
|
+
readonly actorKind: AuditActor["kind"];
|
|
7
|
+
}) => void;
|
|
8
|
+
export declare function beginRequestTrace(request: Parameters<typeof requestIdOf>[0], observer: RequestTrace | undefined): void;
|
|
9
|
+
export declare function annotateRequestActor(request: object, actor: AuditActor): void;
|
|
10
|
+
//# sourceMappingURL=request-trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-trace.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/request-trace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,wEAAwE;AACxE,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;CACxC,KAAK,IAAI,CAAC;AAOX,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,EAC1C,QAAQ,EAAE,YAAY,GAAG,SAAS,GACjC,IAAI,CAKN;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAK7E"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { requestIdOf } from "./request-id.js";
|
|
2
|
+
const observers = new WeakMap();
|
|
3
|
+
export function beginRequestTrace(request, observer) {
|
|
4
|
+
if (observer === undefined)
|
|
5
|
+
return;
|
|
6
|
+
const requestId = requestIdOf(request);
|
|
7
|
+
observers.set(request, { observe: observer, requestId });
|
|
8
|
+
annotate(observer, requestId, "anonymous");
|
|
9
|
+
}
|
|
10
|
+
export function annotateRequestActor(request, actor) {
|
|
11
|
+
const observer = observers.get(request);
|
|
12
|
+
if (observer !== undefined) {
|
|
13
|
+
annotate(observer.observe, observer.requestId, actor.kind);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function annotate(observe, requestId, actorKind) {
|
|
17
|
+
try {
|
|
18
|
+
observe({ requestId, actorKind });
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Observability is optional and cannot change request execution.
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=request-trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-trace.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/request-trace.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAQ9C,MAAM,SAAS,GAAG,IAAI,OAAO,EAG1B,CAAC;AAEJ,MAAM,UAAU,iBAAiB,CAC/B,OAA0C,EAC1C,QAAkC;IAElC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO;IACnC,MAAM,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACvC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;IACzD,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAe,EAAE,KAAiB;IACrE,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CACf,OAAqB,EACrB,SAAiB,EACjB,SAA6B;IAE7B,IAAI,CAAC;QACH,OAAO,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,iEAAiE;IACnE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import { type RouteCapabilities } from "../route/capabilities.js";
|
|
3
|
+
import type { HttpRoute } from "../route/route-group.js";
|
|
4
|
+
import { type RateLimiter } from "./rate-limit.js";
|
|
5
|
+
/**
|
|
6
|
+
* Wires the rate-limit engine into the request pipeline: which limiter a
|
|
7
|
+
* route gets, how its budget is spent, and the 429 a spent caller sees.
|
|
8
|
+
*/
|
|
9
|
+
/** The per-route limiter, or null when the effective policy is unlimited. */
|
|
10
|
+
export declare function limiterFor(definition: HttpRoute, appCapabilities: RouteCapabilities | undefined): RateLimiter | null;
|
|
11
|
+
export declare function sendRateLimited(request: FastifyRequest, reply: FastifyReply, retryAfterSeconds: number): FastifyReply;
|
|
12
|
+
/** Budget is consumed AFTER access — a denied caller learns nothing. */
|
|
13
|
+
export declare function consumeBudget(limiter: RateLimiter | null, definition: HttpRoute, request: FastifyRequest, subjectId: string | undefined): {
|
|
14
|
+
allowed: true;
|
|
15
|
+
} | {
|
|
16
|
+
allowed: false;
|
|
17
|
+
retryAfterSeconds: number;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=route-rate-limit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-rate-limit.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/route-rate-limit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG5D,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;GAGG;AAEH,6EAA6E;AAC7E,wBAAgB,UAAU,CACxB,UAAU,EAAE,SAAS,EACrB,eAAe,EAAE,iBAAiB,GAAG,SAAS,GAC7C,WAAW,GAAG,IAAI,CASpB;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,YAAY,EACnB,iBAAiB,EAAE,MAAM,GACxB,YAAY,CASd;AAED,wEAAwE;AACxE,wBAAgB,aAAa,CAC3B,OAAO,EAAE,WAAW,GAAG,IAAI,EAC3B,UAAU,EAAE,SAAS,EACrB,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,MAAM,GAAG,SAAS,GAC5B;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAMnE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { rememberErrorCode } from "../request-log/request-outcome.js";
|
|
2
|
+
import { resolveCapabilities, } from "../route/capabilities.js";
|
|
3
|
+
import { createRateLimiter } from "./rate-limit.js";
|
|
4
|
+
/**
|
|
5
|
+
* Wires the rate-limit engine into the request pipeline: which limiter a
|
|
6
|
+
* route gets, how its budget is spent, and the 429 a spent caller sees.
|
|
7
|
+
*/
|
|
8
|
+
/** The per-route limiter, or null when the effective policy is unlimited. */
|
|
9
|
+
export function limiterFor(definition, appCapabilities) {
|
|
10
|
+
const effective = resolveCapabilities(appCapabilities, undefined, definition.capabilities);
|
|
11
|
+
const limit = effective.rateLimit;
|
|
12
|
+
if (limit === undefined || limit === "unlimited")
|
|
13
|
+
return null;
|
|
14
|
+
return createRateLimiter(limit, Date.now);
|
|
15
|
+
}
|
|
16
|
+
export function sendRateLimited(request, reply, retryAfterSeconds) {
|
|
17
|
+
void reply.header("retry-after", String(retryAfterSeconds));
|
|
18
|
+
rememberErrorCode(request, "TOO_MANY_REQUESTS");
|
|
19
|
+
return reply.status(429).send({
|
|
20
|
+
error: {
|
|
21
|
+
code: "TOO_MANY_REQUESTS",
|
|
22
|
+
message: "Rate limit exceeded — retry after the indicated delay",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Budget is consumed AFTER access — a denied caller learns nothing. */
|
|
27
|
+
export function consumeBudget(limiter, definition, request, subjectId) {
|
|
28
|
+
if (!limiter)
|
|
29
|
+
return { allowed: true };
|
|
30
|
+
return limiter.consume(`${definition.method} ${definition.path}`, subjectId ?? request.ip);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=route-rate-limit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-rate-limit.js","sourceRoot":"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,SAAS,IAAI,OAAO,CAAC,EAAE,CACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FastifyRequest } from "fastify";
|
|
2
|
+
import type { RouteDefinition, RouteResult } from "../route/route-definition.js";
|
|
3
|
+
import type { AccessDecision } from "./enforce-access.js";
|
|
4
|
+
import type { FeatureStateSnapshot } from "./feature-state.js";
|
|
5
|
+
/** Runs the route's typed pipeline (parse → handler → parse) under the deadline. */
|
|
6
|
+
export declare function runRoute(definition: RouteDefinition, request: FastifyRequest, decision: Extract<AccessDecision, {
|
|
7
|
+
outcome: "allow";
|
|
8
|
+
}>, timeoutMs: number, featureState?: FeatureStateSnapshot): Promise<RouteResult>;
|
|
9
|
+
//# sourceMappingURL=run-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-route.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/run-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,KAAK,EAEV,eAAe,EACf,WAAW,EACZ,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAwC/D,oFAAoF;AACpF,wBAAgB,QAAQ,CACtB,UAAU,EAAE,eAAe,EAC3B,OAAO,EAAE,cAAc,EACvB,QAAQ,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,EACvD,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,oBAAoB,GAClC,OAAO,CAAC,WAAW,CAAC,CAkBtB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { requestIdOf } from "./request-id.js";
|
|
2
|
+
import { requestLocaleOf } from "./request-locale.js";
|
|
3
|
+
import { withDeadline } from "./with-deadline.js";
|
|
4
|
+
/**
|
|
5
|
+
* What enforcement settled beyond the subjects, for the route's input. A part
|
|
6
|
+
* enforcement did not set stays absent rather than arriving as `undefined`.
|
|
7
|
+
*/
|
|
8
|
+
function forwardedDecision(decision) {
|
|
9
|
+
return {
|
|
10
|
+
...(decision.untrustedAuthorizationContext === undefined
|
|
11
|
+
? {}
|
|
12
|
+
: {
|
|
13
|
+
untrustedAuthorizationContext: decision.untrustedAuthorizationContext,
|
|
14
|
+
}),
|
|
15
|
+
...(decision.authorizationContext === undefined
|
|
16
|
+
? {}
|
|
17
|
+
: { authorizationContext: decision.authorizationContext }),
|
|
18
|
+
...(decision.sessionReauthenticatedAt === undefined
|
|
19
|
+
? {}
|
|
20
|
+
: { sessionReauthenticatedAt: decision.sessionReauthenticatedAt }),
|
|
21
|
+
...(decision.visibleIds === undefined
|
|
22
|
+
? {}
|
|
23
|
+
: { visibleIds: decision.visibleIds }),
|
|
24
|
+
...(decision.scope === undefined ? {} : { scope: decision.scope }),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Runs the route's typed pipeline (parse → handler → parse) under the deadline. */
|
|
28
|
+
export function runRoute(definition, request, decision, timeoutMs, featureState) {
|
|
29
|
+
return withDeadline(definition.execute({
|
|
30
|
+
params: request.params,
|
|
31
|
+
query: request.query,
|
|
32
|
+
body: request.body,
|
|
33
|
+
subject: decision.subject,
|
|
34
|
+
authenticatedSubject: decision.authenticatedSubject,
|
|
35
|
+
requestId: requestIdOf(request),
|
|
36
|
+
locale: requestLocaleOf(request),
|
|
37
|
+
log: request.log,
|
|
38
|
+
...forwardedDecision(decision),
|
|
39
|
+
...(featureState === undefined ? {} : { featureState }),
|
|
40
|
+
}), timeoutMs, definition.path, request.log);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=run-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-route.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/run-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,CAAC,IAAI;QAClB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB;QACnD,SAAS,EAAE,WAAW,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC;QAChC,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,GAAG,iBAAiB,CAAC,QAAQ,CAAC;QAC9B,GAAG,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC;KACxD,CAAC,EACF,SAAS,EACT,UAAU,CAAC,IAAI,EACf,OAAO,CAAC,GAAG,CACZ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type OrphanLog = {
|
|
2
|
+
warn(obj: object, msg?: string): void;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Races work against a hard deadline (process-discipline bar: a hung
|
|
6
|
+
* handler cannot pin a socket). The timer is cleared on settle and never
|
|
7
|
+
* holds the event loop; on timeout the orphaned work is drained into the
|
|
8
|
+
* log and a `HandlerTimeoutError` propagates to the error handler (503).
|
|
9
|
+
*/
|
|
10
|
+
export declare function withDeadline<T>(work: Promise<T>, ms: number, routePath: string, log: OrphanLog): Promise<T>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=with-deadline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-deadline.d.ts","sourceRoot":"","sources":["../../../src/lib/request-pipeline/with-deadline.ts"],"names":[],"mappings":"AAQA,KAAK,SAAS,GAAG;IAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AA4C3D;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAClC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,CAAC,CAAC,CAYZ"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { HandlerTimeoutError } from "../http-errors.js";
|
|
2
|
+
function startDeadline(ms, routePath) {
|
|
3
|
+
let timedOut = false;
|
|
4
|
+
let timer;
|
|
5
|
+
const promise = new Promise((_, reject) => {
|
|
6
|
+
timer = setTimeout(() => {
|
|
7
|
+
timedOut = true;
|
|
8
|
+
reject(new HandlerTimeoutError(routePath, ms));
|
|
9
|
+
}, ms);
|
|
10
|
+
// The deadline must never keep the process alive on its own.
|
|
11
|
+
timer.unref();
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
promise,
|
|
15
|
+
cancel: () => {
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
},
|
|
18
|
+
didTimeOut: () => timedOut,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A timed-out handler keeps running after its socket is released; its
|
|
23
|
+
* eventual rejection must land in the log, never as an unhandled rejection
|
|
24
|
+
* that kills the process.
|
|
25
|
+
*/
|
|
26
|
+
function drainOrphan(work, routePath, log) {
|
|
27
|
+
void work.catch((error) => {
|
|
28
|
+
log.warn({ event: "handler.orphaned-rejection", routePath, err: error }, "timed-out handler eventually rejected");
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function toError(value) {
|
|
32
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Races work against a hard deadline (process-discipline bar: a hung
|
|
36
|
+
* handler cannot pin a socket). The timer is cleared on settle and never
|
|
37
|
+
* holds the event loop; on timeout the orphaned work is drained into the
|
|
38
|
+
* log and a `HandlerTimeoutError` propagates to the error handler (503).
|
|
39
|
+
*/
|
|
40
|
+
export async function withDeadline(work, ms, routePath, log) {
|
|
41
|
+
const deadline = startDeadline(ms, routePath);
|
|
42
|
+
try {
|
|
43
|
+
return await Promise.race([work, deadline.promise]);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (deadline.didTimeOut()) {
|
|
47
|
+
drainOrphan(work, routePath, log);
|
|
48
|
+
}
|
|
49
|
+
throw toError(error);
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
deadline.cancel();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=with-deadline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-deadline.js","sourceRoot":"","sources":["../../../src/lib/request-pipeline/with-deadline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAUxD,SAAS,aAAa,CAAC,EAAU,EAAE,SAAiB;IAClD,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,KAAiC,CAAC;IACtC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAC/C,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,QAAQ,GAAG,IAAI,CAAC;YAChB,MAAM,CAAC,IAAI,mBAAmB,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;QACjD,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,6DAA6D;QAC7D,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,OAAO;QACL,OAAO;QACP,MAAM,EAAE,GAAG,EAAE;YACX,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,UAAU,EAAE,GAAG,EAAE,CAAC,QAAQ;KAC3B,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAClB,IAAsB,EACtB,SAAiB,EACjB,GAAc;IAEd,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACjC,GAAG,CAAC,IAAI,CACN,EAAE,KAAK,EAAE,4BAA4B,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,EAC9D,uCAAuC,CACxC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAgB,EAChB,EAAU,EACV,SAAiB,EACjB,GAAc;IAEd,MAAM,QAAQ,GAAG,aAAa,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC;YAC1B,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;QACpC,CAAC;QACD,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;YAAS,CAAC;QACT,QAAQ,CAAC,MAAM,EAAE,CAAC;IACpB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { PermissionToken } from "@dads-framework/access";
|
|
2
|
+
/**
|
|
3
|
+
* The route access vocabulary — the entire authorization surface at the HTTP
|
|
4
|
+
* edge. Every route declares exactly one of these three; every verb function
|
|
5
|
+
* requires the declaration at the type level, so an unguarded route does not
|
|
6
|
+
* compile (docs/architecture/authorization.md).
|
|
7
|
+
*
|
|
8
|
+
* Permission math lives in the .zed schema, never here. Typed ask constructors
|
|
9
|
+
* (`requires` / `requiresVisible`) live in `@dads-framework/access` and emit the
|
|
10
|
+
* shapes below; this module keeps session/public constructors and resource-id
|
|
11
|
+
* sources.
|
|
12
|
+
*/
|
|
13
|
+
/** Where the resource id for a permission check comes from. */
|
|
14
|
+
export type ResourceIdSource = {
|
|
15
|
+
readonly kind: "param";
|
|
16
|
+
readonly name: string;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: "body";
|
|
19
|
+
readonly name: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: "query";
|
|
22
|
+
readonly name: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "header";
|
|
25
|
+
readonly name: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: "fixed";
|
|
28
|
+
readonly id: string;
|
|
29
|
+
};
|
|
30
|
+
/** The resource id is the named path parameter (e.g. `fromParam("id")`). */
|
|
31
|
+
export declare function fromParam(name: string): ResourceIdSource;
|
|
32
|
+
/**
|
|
33
|
+
* The resource id is the named top-level body field (e.g.
|
|
34
|
+
* `fromBody("organizationId")`) — for flat-collection creates, where the
|
|
35
|
+
* parent being created into has no path segment. The body names only the
|
|
36
|
+
* RESOURCE side of the question; the SUBJECT is always the session/JWT
|
|
37
|
+
* caller — pointing at a resource you have no relationship to fails closed
|
|
38
|
+
* as 404. Enforcement reads the raw field before body validation: anything
|
|
39
|
+
* but a string resolves like a missing param (404, never a 500).
|
|
40
|
+
*/
|
|
41
|
+
export declare function fromBody(name: string): ResourceIdSource;
|
|
42
|
+
/**
|
|
43
|
+
* The resource id is the named query parameter (e.g. `fromQuery("facilityId")`)
|
|
44
|
+
* — for flat facility-scoped surfaces where the parent is a filter, not a
|
|
45
|
+
* path segment. Same fail-closed rules as fromBody: non-string → 404.
|
|
46
|
+
*/
|
|
47
|
+
export declare function fromQuery(name: string): ResourceIdSource;
|
|
48
|
+
/** Read one request-local header; repeated values are never a valid identity source. */
|
|
49
|
+
export declare function fromHeader(name: string): ResourceIdSource;
|
|
50
|
+
/**
|
|
51
|
+
* The resource id is a compile-time constant (e.g. `fromFixed("command")` for
|
|
52
|
+
* the singleton `platform:command` resource). Use when the route's permission
|
|
53
|
+
* check targets a well-known resource that is not in the path or body.
|
|
54
|
+
*/
|
|
55
|
+
export declare function fromFixed(id: string): ResourceIdSource;
|
|
56
|
+
/**
|
|
57
|
+
* Route-level relationship check: subject must hold `permission` on the
|
|
58
|
+
* resource of `resourceType` identified by `resourceId`.
|
|
59
|
+
*
|
|
60
|
+
* Prefer `requires(token, source)` at call sites.
|
|
61
|
+
*/
|
|
62
|
+
export type PermissionAccess = {
|
|
63
|
+
readonly kind: "permission";
|
|
64
|
+
readonly resourceType: string;
|
|
65
|
+
readonly permission: string;
|
|
66
|
+
readonly resourceId: ResourceIdSource;
|
|
67
|
+
readonly authorizationContext?: ResourceIdSource;
|
|
68
|
+
readonly authorizationContextMode?: "technical-or-business";
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Authenticated subject required; no route-level resource check. For
|
|
72
|
+
* collection routes (create/list) where authorization happens inside the
|
|
73
|
+
* use-case — lookupResources for lists, ownership-tuple writes for creates.
|
|
74
|
+
*/
|
|
75
|
+
export type SessionAccess = {
|
|
76
|
+
readonly kind: "session";
|
|
77
|
+
readonly authorizationContext?: ResourceIdSource;
|
|
78
|
+
readonly authorizationContextMode?: "technical-or-business";
|
|
79
|
+
/** Input only: the owning operation must select and authorize its explicit runtime authority. */
|
|
80
|
+
readonly authorizationContextInput?: ResourceIdSource;
|
|
81
|
+
};
|
|
82
|
+
/** Explicit opt-in for genuinely unauthenticated routes (health, auth). */
|
|
83
|
+
export type PublicAccess = {
|
|
84
|
+
readonly kind: "public";
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* List-route visibility: the kit asks `lookupResources` which resources of
|
|
88
|
+
* `resourceType` the SUBJECT can `permission`, short-circuits an empty set
|
|
89
|
+
* to an empty page (fail-closed — the empty-`IN ()` widening footgun cannot
|
|
90
|
+
* exist), and hands the handler the visible ids. Only `listRoute` admits
|
|
91
|
+
* this kind — a set question makes no sense on a single-resource verb, and
|
|
92
|
+
* the verbs' type constraints enforce that at compile time.
|
|
93
|
+
*
|
|
94
|
+
* Prefer `requiresVisible(token)` at call sites.
|
|
95
|
+
*/
|
|
96
|
+
export type VisibilityAccess = {
|
|
97
|
+
readonly kind: "visibility";
|
|
98
|
+
readonly resourceType: string;
|
|
99
|
+
readonly permission: string;
|
|
100
|
+
readonly authorizationContext?: ResourceIdSource;
|
|
101
|
+
readonly authorizationContextMode?: "technical-or-business";
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Record-list scoping: registration compiles the scope plan for
|
|
105
|
+
* `permission` on `resourceType` (refusing to boot when the record's bindings
|
|
106
|
+
* cannot carry it); each request asks SpiceDB the plan's scope questions once
|
|
107
|
+
* each and hands the handler a `ScopeAnswer` to render as SQL with
|
|
108
|
+
* `scopePredicate`, then re-check the page with `keepPermitted`. No empty-set
|
|
109
|
+
* short-circuit: the SQL decides, since one empty arm of an `any` can still
|
|
110
|
+
* match. Only `listRoute` admits this kind.
|
|
111
|
+
*
|
|
112
|
+
* Prefer `requiresScoped(token)` at call sites.
|
|
113
|
+
*/
|
|
114
|
+
export type ScopedAccess = {
|
|
115
|
+
readonly kind: "scoped";
|
|
116
|
+
readonly resourceType: string;
|
|
117
|
+
readonly permission: string;
|
|
118
|
+
readonly authorizationContext?: ResourceIdSource;
|
|
119
|
+
readonly authorizationContextMode?: "technical-or-business";
|
|
120
|
+
};
|
|
121
|
+
export type RouteAccess = PermissionAccess | SessionAccess | PublicAccess | VisibilityAccess | ScopedAccess;
|
|
122
|
+
/** Require a relationship on the resource identified by the supplied source. */
|
|
123
|
+
export declare function requires(token: PermissionToken, resourceId: ResourceIdSource): PermissionAccess;
|
|
124
|
+
/** List IDs the caller may see for a bounded resource type. */
|
|
125
|
+
export declare function requiresVisible(token: PermissionToken): VisibilityAccess;
|
|
126
|
+
/** Filter a record list using the scope bindings in the app's access model. */
|
|
127
|
+
export declare function requiresScoped(token: PermissionToken): ScopedAccess;
|
|
128
|
+
/** Resolve explicit caller authority before checking this route's business access. */
|
|
129
|
+
export declare function withAuthorizationContext<Access extends Exclude<RouteAccess, PublicAccess>>(access: Access, source: ResourceIdSource): Access & {
|
|
130
|
+
readonly authorizationContext: ResourceIdSource;
|
|
131
|
+
};
|
|
132
|
+
/** Explicitly technical routes may omit context; any supplied context must resolve and never falls back to technical identity. */
|
|
133
|
+
export declare function withTechnicalOrBusinessAuthorizationContext<Access extends Exclude<RouteAccess, PublicAccess>>(access: Access, source: ResourceIdSource): Access & {
|
|
134
|
+
readonly authorizationContext: ResourceIdSource;
|
|
135
|
+
readonly authorizationContextMode: "technical-or-business";
|
|
136
|
+
};
|
|
137
|
+
export declare function requireSession(): SessionAccess;
|
|
138
|
+
/** Capture untrusted context data for a session-only operation; never resolve or authorize an actor here. */
|
|
139
|
+
export declare function withAuthorizationContextInput(access: SessionAccess, source: ResourceIdSource): SessionAccess & {
|
|
140
|
+
readonly authorizationContextInput: ResourceIdSource;
|
|
141
|
+
};
|
|
142
|
+
export declare function publicAccess(): PublicAccess;
|
|
143
|
+
//# sourceMappingURL=access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../../src/lib/route/access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;;;;;;;GAUG;AAEH,+DAA+D;AAC/D,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,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;IAAE,QAAQ,CAAC,oBAAoB,EAAE,gBAAgB,CAAA;CAAE,CAa9D;AAED,kIAAkI;AAClI,wBAAgB,2CAA2C,CACzD,MAAM,SAAS,OAAO,CAAC,WAAW,EAAE,YAAY,CAAC,EAEjD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,gBAAgB,GACvB,MAAM,GAAG;IACV,QAAQ,CAAC,oBAAoB,EAAE,gBAAgB,CAAC;IAChD,QAAQ,CAAC,wBAAwB,EAAE,uBAAuB,CAAC;CAC5D,CAkBA;AAED,wBAAgB,cAAc,IAAI,aAAa,CAE9C;AAED,6GAA6G;AAC7G,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,gBAAgB,GACvB,aAAa,GAAG;IAAE,QAAQ,CAAC,yBAAyB,EAAE,gBAAgB,CAAA;CAAE,CAM1E;AAED,wBAAgB,YAAY,IAAI,YAAY,CAE3C"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/** The resource id is the named path parameter (e.g. `fromParam("id")`). */
|
|
2
|
+
export function fromParam(name) {
|
|
3
|
+
return { kind: "param", name };
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The resource id is the named top-level body field (e.g.
|
|
7
|
+
* `fromBody("organizationId")`) — for flat-collection creates, where the
|
|
8
|
+
* parent being created into has no path segment. The body names only the
|
|
9
|
+
* RESOURCE side of the question; the SUBJECT is always the session/JWT
|
|
10
|
+
* caller — pointing at a resource you have no relationship to fails closed
|
|
11
|
+
* as 404. Enforcement reads the raw field before body validation: anything
|
|
12
|
+
* but a string resolves like a missing param (404, never a 500).
|
|
13
|
+
*/
|
|
14
|
+
export function fromBody(name) {
|
|
15
|
+
return { kind: "body", name };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The resource id is the named query parameter (e.g. `fromQuery("facilityId")`)
|
|
19
|
+
* — for flat facility-scoped surfaces where the parent is a filter, not a
|
|
20
|
+
* path segment. Same fail-closed rules as fromBody: non-string → 404.
|
|
21
|
+
*/
|
|
22
|
+
export function fromQuery(name) {
|
|
23
|
+
return { kind: "query", name };
|
|
24
|
+
}
|
|
25
|
+
/** Read one request-local header; repeated values are never a valid identity source. */
|
|
26
|
+
export function fromHeader(name) {
|
|
27
|
+
return { kind: "header", name: name.toLowerCase() };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The resource id is a compile-time constant (e.g. `fromFixed("command")` for
|
|
31
|
+
* the singleton `platform:command` resource). Use when the route's permission
|
|
32
|
+
* check targets a well-known resource that is not in the path or body.
|
|
33
|
+
*/
|
|
34
|
+
export function fromFixed(id) {
|
|
35
|
+
return { kind: "fixed", id };
|
|
36
|
+
}
|
|
37
|
+
/** Require a relationship on the resource identified by the supplied source. */
|
|
38
|
+
export function requires(token, resourceId) {
|
|
39
|
+
return {
|
|
40
|
+
kind: "permission",
|
|
41
|
+
resourceType: token.entityWireName,
|
|
42
|
+
permission: token.permissionName,
|
|
43
|
+
resourceId,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** List IDs the caller may see for a bounded resource type. */
|
|
47
|
+
export function requiresVisible(token) {
|
|
48
|
+
return {
|
|
49
|
+
kind: "visibility",
|
|
50
|
+
resourceType: token.entityWireName,
|
|
51
|
+
permission: token.permissionName,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Filter a record list using the scope bindings in the app's access model. */
|
|
55
|
+
export function requiresScoped(token) {
|
|
56
|
+
return {
|
|
57
|
+
kind: "scoped",
|
|
58
|
+
resourceType: token.entityWireName,
|
|
59
|
+
permission: token.permissionName,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Resolve explicit caller authority before checking this route's business access. */
|
|
63
|
+
export function withAuthorizationContext(access, source) {
|
|
64
|
+
if (access.kind === "session" &&
|
|
65
|
+
access.authorizationContextInput !== undefined)
|
|
66
|
+
throw new Error("Resolved and input-only authorization contexts cannot be combined");
|
|
67
|
+
if (access.authorizationContextMode !== undefined)
|
|
68
|
+
throw new Error("Required and technical-or-business authorization contexts cannot be combined");
|
|
69
|
+
return { ...access, authorizationContext: source };
|
|
70
|
+
}
|
|
71
|
+
/** Explicitly technical routes may omit context; any supplied context must resolve and never falls back to technical identity. */
|
|
72
|
+
export function withTechnicalOrBusinessAuthorizationContext(access, source) {
|
|
73
|
+
if (source.kind !== "header" && source.kind !== "query")
|
|
74
|
+
throw new Error("Technical-or-business context requires a declared header or query");
|
|
75
|
+
if (access.authorizationContext !== undefined ||
|
|
76
|
+
(access.kind === "session" &&
|
|
77
|
+
access.authorizationContextInput !== undefined))
|
|
78
|
+
throw new Error("Technical-or-business authorization cannot be combined with another context declaration");
|
|
79
|
+
return {
|
|
80
|
+
...access,
|
|
81
|
+
authorizationContext: source,
|
|
82
|
+
authorizationContextMode: "technical-or-business",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export function requireSession() {
|
|
86
|
+
return { kind: "session" };
|
|
87
|
+
}
|
|
88
|
+
/** Capture untrusted context data for a session-only operation; never resolve or authorize an actor here. */
|
|
89
|
+
export function withAuthorizationContextInput(access, source) {
|
|
90
|
+
if (access.authorizationContext !== undefined)
|
|
91
|
+
throw new Error("Resolved and input-only authorization contexts cannot be combined");
|
|
92
|
+
return { ...access, authorizationContextInput: source };
|
|
93
|
+
}
|
|
94
|
+
export function publicAccess() {
|
|
95
|
+
return { kind: "public" };
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.js","sourceRoot":"","sources":["../../../src/lib/route/access.ts"],"names":[],"mappings":"AAsBA,4EAA4E;AAC5E,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACjC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,EAAE,IAAI,EAAE,M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,wBAAwB,KAAK,SAAS;QAC/C,MAAM,IAAI,KAAK,CACb,8EAA8E,CAC/E,CAAC;IACJ,OAAO,EAAE,GAAG,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,CAAC;AACrD,CAAC;AAED,kIAAkI;AAClI,MAAM,UAAU,2CAA2C,CAGzD,MAAc,EACd,MAAwB;IAKxB,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO;QACrD,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,IACE,MAAM,CAAC,oBAAoB,KAAK,SAAS;QACzC,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS;YACxB,MAAM,CAAC,yBAAyB,KAAK,SAAS,CAAC;QAEjD,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;IACJ,OAAO;QACL,GAAG,MAAM;QACT,oBAAoB,EAAE,MAAM;QAC5B,wBAAwB,EAAE,uBAAuB;KAClD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC7B,CAAC;AAED,6GAA6G;AAC7G,MAAM,UAAU,6BAA6B,CAC3C,MAAqB,EACrB,MAAwB;IAExB,IAAI,MAAM,CAAC,oBAAoB,KAAK,SAAS;QAC3C,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,OAAO,EAAE,GAAG,MAAM,EAAE,yBAAyB,EAAE,MAAM,EAAE,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route capabilities — the kit's answer to middleware (design locked with
|
|
3
|
+
* Bryton, 2026-07-09): NAMED, TYPED fields instead of anonymous hook
|
|
4
|
+
* chains. Every capability is declared data, visible on the route, resolved
|
|
5
|
+
* through a three-rung ladder:
|
|
6
|
+
*
|
|
7
|
+
* route field > group capabilities > app default (registerRoutes)
|
|
8
|
+
*
|
|
9
|
+
* "What applies to this route" is answerable by reading at most three named
|
|
10
|
+
* places. Capabilities grow here BY NEED, each with an engine and tests in
|
|
11
|
+
* the kit — never as user-supplied functions.
|
|
12
|
+
*/
|
|
13
|
+
export type RateLimitCapability = {
|
|
14
|
+
/** Requests allowed per minute for one caller (subject id, else ip). */
|
|
15
|
+
readonly perMinute: number;
|
|
16
|
+
} | "unlimited";
|
|
17
|
+
/**
|
|
18
|
+
* What a plant-side copy of the API does with this route. Set only by a
|
|
19
|
+
* applications that run a second deployment of the API.
|
|
20
|
+
* served the site answers it itself
|
|
21
|
+
* write_door the site applies the change locally and sends it to the cloud
|
|
22
|
+
* cloud_only the cloud owns it. The site refuses a cloud_only read or
|
|
23
|
+
* write with 409 after its access check (unless the site build
|
|
24
|
+
* drops the route, which then answers 404); a cloud_only GET is
|
|
25
|
+
* never answered from the site's own copy
|
|
26
|
+
*/
|
|
27
|
+
export type SiteServing = "served" | "write_door" | "cloud_only";
|
|
28
|
+
/**
|
|
29
|
+
* Why a site never answers a `cloud_only` route. The same idea as a table
|
|
30
|
+
* sync label's cloud-only `reason`, in the words a route needs:
|
|
31
|
+
* STAFF_TOOLS an application staff tool
|
|
32
|
+
* COMPANY_DESK company-wide setup done from the office, not a plant's
|
|
33
|
+
* shift work
|
|
34
|
+
* NEEDS_INTERNET talks to an outside service (email, SSO, payments,
|
|
35
|
+
* storage), so a site cannot answer it offline
|
|
36
|
+
* FLEET the cloud's end of a link to sites and devices
|
|
37
|
+
* (enrollment, check-in, the sync feed, releases)
|
|
38
|
+
* NOT_YET should work at a site; `ticket` names the work
|
|
39
|
+
*/
|
|
40
|
+
export type CloudOnlyRouteReason = "STAFF_TOOLS" | "COMPANY_DESK" | "NEEDS_INTERNET" | "FLEET" | "NOT_YET";
|
|
41
|
+
/**
|
|
42
|
+
* The reason on a `cloud_only` label: one closed `reason` plus one plain
|
|
43
|
+
* sentence a reviewer can read. `NOT_YET` names the ticket that will make
|
|
44
|
+
* the route work at a site, so that backlog is one catalog query.
|
|
45
|
+
*/
|
|
46
|
+
export type CloudOnlyRouteLabel = {
|
|
47
|
+
readonly reason: Exclude<CloudOnlyRouteReason, "NOT_YET">;
|
|
48
|
+
readonly why: string;
|
|
49
|
+
readonly ticket?: never;
|
|
50
|
+
} | {
|
|
51
|
+
readonly reason: "NOT_YET";
|
|
52
|
+
readonly why: string;
|
|
53
|
+
readonly ticket: `${string}-${number}`;
|
|
54
|
+
};
|
|
55
|
+
export type RouteCapabilities = {
|
|
56
|
+
/**
|
|
57
|
+
* Per-caller request budget, enforced after access (a denied caller never
|
|
58
|
+
* consumes budget knowledge). Per-replica accounting — a distributed
|
|
59
|
+
* limiter is a deliberate upgrade when multi-instance deploys arrive.
|
|
60
|
+
*/
|
|
61
|
+
readonly rateLimit?: RateLimitCapability;
|
|
62
|
+
/** Reject a stale client feature-state hash before this flag-dependent write runs. */
|
|
63
|
+
readonly featureStateWrite?: "sensitive";
|
|
64
|
+
/**
|
|
65
|
+
* Let this write run while the caller's feature preview refuses writes —
|
|
66
|
+
* for the routes that start, change and end the preview itself.
|
|
67
|
+
*/
|
|
68
|
+
readonly writesDuringFeaturePreview?: "allowed";
|
|
69
|
+
/**
|
|
70
|
+
* The named machine credential this route accepts INSTEAD of user
|
|
71
|
+
* sessions: its caller resolves only through
|
|
72
|
+
* `registerRoutes({ machineCredentials })[name]`, never through the
|
|
73
|
+
* session resolver. Resolved from the route or its group only — the app rung never
|
|
74
|
+
* supplies it (registration throws). A route without it never sees
|
|
75
|
+
* machine credentials.
|
|
76
|
+
*/
|
|
77
|
+
readonly machineCredential?: string;
|
|
78
|
+
/**
|
|
79
|
+
* What a site server does with this route. Resolved from the route or its
|
|
80
|
+
* group only; the app rung never supplies it (registration throws). The kit
|
|
81
|
+
* only carries it; no default, so `undefined` means "not labelled".
|
|
82
|
+
*/
|
|
83
|
+
readonly site?: SiteServing;
|
|
84
|
+
/**
|
|
85
|
+
* Why a `cloud_only` route stays in the cloud. It travels with `site`: a
|
|
86
|
+
* route that overrides its group's label never inherits the group's
|
|
87
|
+
* reason, and a route may give its own reason under its group's label.
|
|
88
|
+
* The app rung never supplies it (registration throws). The product
|
|
89
|
+
* decides whether it is required.
|
|
90
|
+
*/
|
|
91
|
+
readonly cloudOnly?: CloudOnlyRouteLabel;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* route > group > app, field by field, except `cloudOnly`: when a more
|
|
95
|
+
* specific rung than the reason's overrides `site` with another label, the
|
|
96
|
+
* reason explains a label the route no longer has, so it is dropped. A rung
|
|
97
|
+
* that repeats `cloud_only` keeps the reason.
|
|
98
|
+
*/
|
|
99
|
+
export declare function resolveCapabilities(app: RouteCapabilities | undefined, group: RouteCapabilities | undefined, route: RouteCapabilities | undefined): RouteCapabilities;
|
|
100
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../src/lib/route/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,MAAM,mBAAmB,GAC3B;IACE,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,GACD,WAAW,CAAC;AAEhB;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,YAAY,GAAG,YAAY,CAAC;AAEjE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,oBAAoB,GAC9B,aAAa,GAAG,cAAc,GAAG,gBAAgB,GAAG,OAAO,GAAG,SAAS,CAAC;AAE1E;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAC3B;IACE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;IAC1D,QAAQ,CAAC,GAAG,EA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