@demiurgejs/core 0.2.0-beta.3 → 0.2.0-beta.5
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/README.md +36 -11
- package/bin/demiurge.mjs +47 -13
- package/dist/adapter/index.d.ts +1 -1
- package/dist/adapter/index.d.ts.map +1 -1
- package/dist/browser/file-router.d.ts +388 -5
- package/dist/browser/file-router.d.ts.map +1 -1
- package/dist/browser/focus.d.ts +20 -0
- package/dist/browser/focus.d.ts.map +1 -0
- package/dist/browser/index.d.ts +7 -1
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/mutation-action.d.ts +81 -0
- package/dist/browser/mutation-action.d.ts.map +1 -0
- package/dist/chunks/document-shell-9GPwtcTt.js +36 -0
- package/dist/chunks/document-shell-9GPwtcTt.js.map +1 -0
- package/dist/chunks/{image-codec-Di53WpcH.js → image-codec-Dh1POFhE.js} +2 -2
- package/dist/chunks/{image-codec-Di53WpcH.js.map → image-codec-Dh1POFhE.js.map} +1 -1
- package/dist/chunks/{images-Edar3eU1.js → images-CG7ZzayG.js} +99 -91
- package/dist/chunks/images-CG7ZzayG.js.map +1 -0
- package/dist/chunks/index-0MNiR_wo.js +833 -0
- package/dist/chunks/index-0MNiR_wo.js.map +1 -0
- package/dist/chunks/manifest-vO6c0G0W.js +19 -0
- package/dist/chunks/manifest-vO6c0G0W.js.map +1 -0
- package/dist/chunks/plugin-BZauDxRY.js +2310 -0
- package/dist/chunks/plugin-BZauDxRY.js.map +1 -0
- package/dist/chunks/session-store-ChModVcq.js +92 -0
- package/dist/chunks/session-store-ChModVcq.js.map +1 -0
- package/dist/chunks/static-files-ehaD1kE7.js +51 -0
- package/dist/chunks/static-files-ehaD1kE7.js.map +1 -0
- package/dist/chunks/streaming-GYIsVTQH.js +560 -0
- package/dist/chunks/streaming-GYIsVTQH.js.map +1 -0
- package/dist/chunks/testing-CUwGj2ie.js +4751 -0
- package/dist/chunks/testing-CUwGj2ie.js.map +1 -0
- package/dist/chunks/vite-QoqrGl6f.js +259 -0
- package/dist/chunks/vite-QoqrGl6f.js.map +1 -0
- package/dist/cli.d.ts +19 -25
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +289 -128
- package/dist/cli.js.map +1 -1
- package/dist/config/define.d.ts +3 -0
- package/dist/config/define.d.ts.map +1 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +78 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/load.d.ts +12 -0
- package/dist/config/load.d.ts.map +1 -0
- package/dist/config/types.d.ts +74 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/validate.d.ts +9 -0
- package/dist/config/validate.d.ts.map +1 -0
- package/dist/config/vite.d.ts +12 -0
- package/dist/config/vite.d.ts.map +1 -0
- package/dist/data/cache.d.ts +2 -0
- package/dist/data/cache.d.ts.map +1 -1
- package/dist/data/idempotency.d.ts.map +1 -1
- package/dist/deployment/testing.d.ts +25 -0
- package/dist/deployment/testing.d.ts.map +1 -0
- package/dist/deployment/testing.js +171 -0
- package/dist/deployment/testing.js.map +1 -0
- package/dist/document/hydration.d.ts +9 -0
- package/dist/document/hydration.d.ts.map +1 -1
- package/dist/document/index.d.ts +4 -2
- package/dist/document/index.d.ts.map +1 -1
- package/dist/document/metadata.d.ts +8 -0
- package/dist/document/metadata.d.ts.map +1 -1
- package/dist/document/navigation.d.ts +28 -0
- package/dist/document/navigation.d.ts.map +1 -0
- package/dist/document/render.d.ts +3 -1
- package/dist/document/render.d.ts.map +1 -1
- package/dist/document/seo.d.ts.map +1 -1
- package/dist/edge/assets.d.ts.map +1 -1
- package/dist/edge/index.js +55 -73
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +12 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1883 -692
- package/dist/index.js.map +1 -1
- package/dist/inspect/command.d.ts +28 -0
- package/dist/inspect/command.d.ts.map +1 -0
- package/dist/inspect/index.d.ts +9 -0
- package/dist/inspect/index.d.ts.map +1 -0
- package/dist/inspect/redact.d.ts +35 -0
- package/dist/inspect/redact.d.ts.map +1 -0
- package/dist/inspect/report.d.ts +24 -0
- package/dist/inspect/report.d.ts.map +1 -0
- package/dist/inspect/types.d.ts +102 -0
- package/dist/inspect/types.d.ts.map +1 -0
- package/dist/internal/testing.js +5 -5
- package/dist/kv/index.d.ts +2 -0
- package/dist/kv/index.d.ts.map +1 -1
- package/dist/kv/index.js +170 -73
- package/dist/kv/index.js.map +1 -1
- package/dist/kv/session-store.d.ts +20 -0
- package/dist/kv/session-store.d.ts.map +1 -0
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/node/http.d.ts +5 -0
- package/dist/node/http.d.ts.map +1 -1
- package/dist/node/image.d.ts.map +1 -1
- package/dist/node/index.d.ts +4 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +257 -182
- package/dist/node/index.js.map +1 -1
- package/dist/node/serve.d.ts +47 -0
- package/dist/node/serve.d.ts.map +1 -0
- package/dist/node/static.d.ts.map +1 -1
- package/dist/platform/fonts.d.ts.map +1 -1
- package/dist/platform/image-url.d.ts.map +1 -1
- package/dist/platform/url.d.ts +19 -0
- package/dist/platform/url.d.ts.map +1 -0
- package/dist/platform/web-vitals.d.ts.map +1 -1
- package/dist/redis/index.d.ts +2 -0
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js +186 -69
- package/dist/redis/index.js.map +1 -1
- package/dist/redis/session-store.d.ts +9 -0
- package/dist/redis/session-store.d.ts.map +1 -0
- package/dist/route/index.d.ts +3 -2
- package/dist/route/index.d.ts.map +1 -1
- package/dist/route/mutation.d.ts +97 -0
- package/dist/route/mutation.d.ts.map +1 -0
- package/dist/route/serialization.d.ts +24 -0
- package/dist/route/serialization.d.ts.map +1 -0
- package/dist/route/types.d.ts +6 -1
- package/dist/route/types.d.ts.map +1 -1
- package/dist/route/webhook.d.ts +6 -1
- package/dist/route/webhook.d.ts.map +1 -1
- package/dist/router/manifest.d.ts +8 -0
- package/dist/router/manifest.d.ts.map +1 -1
- package/dist/router/navigation-data.d.ts +9 -1
- package/dist/router/navigation-data.d.ts.map +1 -1
- package/dist/routing/generate.d.ts +3 -0
- package/dist/routing/generate.d.ts.map +1 -1
- package/dist/routing/index.d.ts +3 -1
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/locale.d.ts +43 -0
- package/dist/routing/locale.d.ts.map +1 -0
- package/dist/routing/types.d.ts +12 -0
- package/dist/routing/types.d.ts.map +1 -1
- package/dist/security/audit.d.ts +2 -1
- package/dist/security/audit.d.ts.map +1 -1
- package/dist/security/authorization.d.ts +36 -0
- package/dist/security/authorization.d.ts.map +1 -0
- package/dist/security/cookie-session.d.ts +43 -0
- package/dist/security/cookie-session.d.ts.map +1 -0
- package/dist/security/csrf.d.ts +1 -1
- package/dist/security/csrf.d.ts.map +1 -1
- package/dist/security/env-startup.d.ts +13 -0
- package/dist/security/env-startup.d.ts.map +1 -0
- package/dist/security/env.d.ts +49 -11
- package/dist/security/env.d.ts.map +1 -1
- package/dist/security/exceptions.d.ts +29 -0
- package/dist/security/exceptions.d.ts.map +1 -0
- package/dist/security/finding-codes.d.ts +56 -0
- package/dist/security/finding-codes.d.ts.map +1 -0
- package/dist/security/index.d.ts +14 -3
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/policy.d.ts +2 -5
- package/dist/security/policy.d.ts.map +1 -1
- package/dist/security/report.d.ts +2 -1
- package/dist/security/report.d.ts.map +1 -1
- package/dist/security/request.d.ts +1 -0
- package/dist/security/request.d.ts.map +1 -1
- package/dist/security/session-manager.d.ts +32 -0
- package/dist/security/session-manager.d.ts.map +1 -0
- package/dist/security/session-store.d.ts +51 -0
- package/dist/security/session-store.d.ts.map +1 -0
- package/dist/security/testing.d.ts +10 -0
- package/dist/security/testing.d.ts.map +1 -0
- package/dist/security/testing.js +145 -0
- package/dist/security/testing.js.map +1 -0
- package/dist/security/types.d.ts +139 -5
- package/dist/security/types.d.ts.map +1 -1
- package/dist/security/upload.d.ts +3 -3
- package/dist/security/upload.d.ts.map +1 -1
- package/dist/security/verification.d.ts.map +1 -1
- package/dist/server/document-shell.d.ts.map +1 -1
- package/dist/server/errors.d.ts +1 -0
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/not-found.d.ts +1 -0
- package/dist/server/not-found.d.ts.map +1 -1
- package/dist/server/render-tree.d.ts.map +1 -1
- package/dist/server/request-handler.d.ts +7 -2
- package/dist/server/request-handler.d.ts.map +1 -1
- package/dist/server/request-metadata.d.ts +1 -0
- package/dist/server/request-metadata.d.ts.map +1 -1
- package/dist/server/ssr.d.ts +2 -0
- package/dist/server/ssr.d.ts.map +1 -1
- package/dist/server-only/browser.d.ts +2 -0
- package/dist/server-only/browser.d.ts.map +1 -0
- package/dist/server-only/browser.js +4 -0
- package/dist/server-only/browser.js.map +1 -0
- package/dist/server-only/index.d.ts +2 -0
- package/dist/server-only/index.d.ts.map +1 -0
- package/dist/server-only/index.js +2 -0
- package/dist/server-only/index.js.map +1 -0
- package/dist/static/index.d.ts +2 -0
- package/dist/static/index.d.ts.map +1 -1
- package/dist/static/index.js +380 -363
- package/dist/static/index.js.map +1 -1
- package/dist/static/preview.d.ts.map +1 -1
- package/dist/static/vercel.d.ts +11 -2
- package/dist/static/vercel.d.ts.map +1 -1
- package/dist/static-files.d.ts +12 -0
- package/dist/static-files.d.ts.map +1 -1
- package/dist/type-guards.d.ts +19 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/vite/env-boundary.d.ts +14 -0
- package/dist/vite/env-boundary.d.ts.map +1 -0
- package/dist/vite/index.d.ts +13 -6
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +29 -1560
- package/dist/vite/index.js.map +1 -1
- package/dist/vite/plugin.d.ts +24 -3
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/vite/policy-verification.d.ts +33 -2
- package/dist/vite/policy-verification.d.ts.map +1 -1
- package/dist/vite/route-audit.d.ts +14 -2
- package/dist/vite/route-audit.d.ts.map +1 -1
- package/dist/vite/server-only-boundary.d.ts +8 -0
- package/dist/vite/server-only-boundary.d.ts.map +1 -0
- package/package.json +24 -6
- package/dist/chunks/document-shell-WoM8yZlR.js +0 -35
- package/dist/chunks/document-shell-WoM8yZlR.js.map +0 -1
- package/dist/chunks/images-Edar3eU1.js.map +0 -1
- package/dist/chunks/request-metadata-DaIYq4Ea.js +0 -677
- package/dist/chunks/request-metadata-DaIYq4Ea.js.map +0 -1
- package/dist/chunks/static-files-DUjHw-4H.js +0 -11
- package/dist/chunks/static-files-DUjHw-4H.js.map +0 -1
- package/dist/chunks/streaming-D0fGAuiO.js +0 -469
- package/dist/chunks/streaming-D0fGAuiO.js.map +0 -1
- package/dist/chunks/testing-CRflAw4X.js +0 -3475
- package/dist/chunks/testing-CRflAw4X.js.map +0 -1
- package/dist/route/action.d.ts +0 -33
- package/dist/route/action.d.ts.map +0 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BodySizeException, BodySizeValue, ContentSecurityPolicy, CspException, CsrfException, CsrfPolicy, CsrfPolicyOptions, RequestSecurityPolicy, RoutePolicy, SecurityException, SecurityPolicy } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Reports if a declaration is a typed security exception.
|
|
4
|
+
*
|
|
5
|
+
* An exception carries a `reason` and a `value`. No policy object of the
|
|
6
|
+
* framework uses both names, so the two fields identify the shape.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isSecurityException(value: unknown): value is SecurityException<unknown>;
|
|
9
|
+
/** Returns the Content-Security-Policy that a document declaration selects. */
|
|
10
|
+
export declare function resolveCsp(csp: SecurityPolicy["csp"]): ContentSecurityPolicy | false | undefined;
|
|
11
|
+
/** Returns the exception of a document declaration, or `undefined`. */
|
|
12
|
+
export declare function getCspException(csp: SecurityPolicy["csp"]): CspException | undefined;
|
|
13
|
+
/** Returns the CSRF policy that a route declaration selects. */
|
|
14
|
+
export declare function resolveCsrf(csrf: CsrfPolicy | undefined): true | false | CsrfPolicyOptions | undefined;
|
|
15
|
+
/** Returns the exception of a CSRF declaration, or `undefined`. */
|
|
16
|
+
export declare function getCsrfException(csrf: CsrfPolicy | undefined): CsrfException | undefined;
|
|
17
|
+
/** Returns the request body limit that a route declaration selects. */
|
|
18
|
+
export declare function resolveMaxBodySize(maxBodySize: RequestSecurityPolicy["maxBodySize"]): BodySizeValue | undefined;
|
|
19
|
+
/** Returns the exception of a body limit declaration, or `undefined`. */
|
|
20
|
+
export declare function getBodySizeException(maxBodySize: RequestSecurityPolicy["maxBodySize"]): BodySizeException | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Adds the declaring file to each exception of one policy file.
|
|
23
|
+
*
|
|
24
|
+
* The framework merges the policy cascade into one policy, and the merge
|
|
25
|
+
* keeps no file name. This function stamps the file before the merge, so the
|
|
26
|
+
* audit can report the source of each exception.
|
|
27
|
+
*/
|
|
28
|
+
export declare function attachExceptionSource(policy: RoutePolicy | undefined, source: string | undefined): RoutePolicy | undefined;
|
|
29
|
+
//# sourceMappingURL=exceptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/security/exceptions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAMrC;AAED,+EAA+E;AAC/E,wBAAgB,UAAU,CACxB,GAAG,EAAE,cAAc,CAAC,KAAK,CAAC,GACzB,qBAAqB,GAAG,KAAK,GAAG,SAAS,CAM3C;AAED,uEAAuE;AACvE,wBAAgB,eAAe,CAC7B,GAAG,EAAE,cAAc,CAAC,KAAK,CAAC,GACzB,YAAY,GAAG,SAAS,CAG1B;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,GAAG,SAAS,GAC3B,IAAI,GAAG,KAAK,GAAG,iBAAiB,GAAG,SAAS,CAM9C;AAED,mEAAmE;AACnE,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,UAAU,GAAG,SAAS,GAC3B,aAAa,GAAG,SAAS,CAG3B;AAED,uEAAuE;AACvE,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,qBAAqB,CAAC,aAAa,CAAC,GAChD,aAAa,GAAG,SAAS,CAO3B;AAED,yEAAyE;AACzE,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,qBAAqB,CAAC,aAAa,CAAC,GAChD,iBAAiB,GAAG,SAAS,CAK/B;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,WAAW,GAAG,SAAS,CAazB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The diagnostic code vocabulary of Demiurge.
|
|
3
|
+
*
|
|
4
|
+
* ADR 0018 gives the build verifier and the runtime audit one vocabulary. A
|
|
5
|
+
* code names one condition. The build verifier reports a subset of the codes,
|
|
6
|
+
* because the build cannot read a value that only a request supplies.
|
|
7
|
+
*/
|
|
8
|
+
export type SecurityFindingCode =
|
|
9
|
+
/** The route inherits no access declaration. */
|
|
10
|
+
"access-declaration-missing"
|
|
11
|
+
/** The route runs each inherited authorization hook. */
|
|
12
|
+
| "access-authorized"
|
|
13
|
+
/** An access exception removed each inherited authorization hook. */
|
|
14
|
+
| "access-exception"
|
|
15
|
+
/** The route declares public access. */
|
|
16
|
+
| "access-public"
|
|
17
|
+
/** The CORS policy is invalid. */
|
|
18
|
+
| "cors-invalid"
|
|
19
|
+
/** The CORS policy names a method that the route does not serve. */
|
|
20
|
+
| "cors-method-unavailable"
|
|
21
|
+
/** The document accepts no Content-Security-Policy. */
|
|
22
|
+
| "csp-disabled"
|
|
23
|
+
/** A document script needs a nonce for the effective script-src policy. */
|
|
24
|
+
| "csp-script-missing-nonce"
|
|
25
|
+
/** The effective script-src policy blocks a document script. */
|
|
26
|
+
| "csp-script-src-blocked"
|
|
27
|
+
/** The route accepts no CSRF check for an unsafe method. */
|
|
28
|
+
| "csrf-disabled"
|
|
29
|
+
/** The route inherits no document policy. */
|
|
30
|
+
| "document-policy-missing"
|
|
31
|
+
/** The rate limit policy is invalid. */
|
|
32
|
+
| "rate-limit-invalid"
|
|
33
|
+
/** The unsafe route declares no rate limit. */
|
|
34
|
+
| "rate-limit-missing"
|
|
35
|
+
/** Trusted Types report-only mode has no deliverable target. */
|
|
36
|
+
| "report-only-target-missing"
|
|
37
|
+
/** The route raises the inherited request body limit. */
|
|
38
|
+
| "request-body-limit-raised"
|
|
39
|
+
/** Google Tag Manager is a wide trust boundary. */
|
|
40
|
+
| "script-gtm-wide-trust-boundary"
|
|
41
|
+
/** A third-party script declares no integrity hash. */
|
|
42
|
+
| "script-integrity-missing"
|
|
43
|
+
/** A third-party script declares no purpose. */
|
|
44
|
+
| "script-purpose-missing"
|
|
45
|
+
/** A third-party script runs before the application is interactive. */
|
|
46
|
+
| "script-third-party-before-interactive"
|
|
47
|
+
/** A security exception states no reason. */
|
|
48
|
+
| "security-exception-reason-missing"
|
|
49
|
+
/** The security headers failed to render. */
|
|
50
|
+
| "security-header-render-failed";
|
|
51
|
+
/**
|
|
52
|
+
* The codes that the build verifier reports. Each code is a member of
|
|
53
|
+
* `SecurityFindingCode`.
|
|
54
|
+
*/
|
|
55
|
+
export type StaticPolicyFindingCode = Extract<SecurityFindingCode, "access-declaration-missing" | "cors-invalid" | "cors-method-unavailable" | "document-policy-missing" | "rate-limit-invalid" | "security-exception-reason-missing" | "security-header-render-failed">;
|
|
56
|
+
//# sourceMappingURL=finding-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finding-codes.d.ts","sourceRoot":"","sources":["../../src/security/finding-codes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB;AAC7B,gDAAgD;AAC9C,4BAA4B;AAC9B,wDAAwD;GACtD,mBAAmB;AACrB,qEAAqE;GACnE,kBAAkB;AACpB,wCAAwC;GACtC,eAAe;AACjB,kCAAkC;GAChC,cAAc;AAChB,oEAAoE;GAClE,yBAAyB;AAC3B,uDAAuD;GACrD,cAAc;AAChB,2EAA2E;GACzE,0BAA0B;AAC5B,gEAAgE;GAC9D,wBAAwB;AAC1B,4DAA4D;GAC1D,eAAe;AACjB,6CAA6C;GAC3C,yBAAyB;AAC3B,wCAAwC;GACtC,oBAAoB;AACtB,+CAA+C;GAC7C,oBAAoB;AACtB,gEAAgE;GAC9D,4BAA4B;AAC9B,yDAAyD;GACvD,2BAA2B;AAC7B,mDAAmD;GACjD,gCAAgC;AAClC,uDAAuD;GACrD,0BAA0B;AAC5B,gDAAgD;GAC9C,wBAAwB;AAC1B,uEAAuE;GACrE,uCAAuC;AACzC,6CAA6C;GAC3C,mCAAmC;AACrC,6CAA6C;GAC3C,+BAA+B,CAAC;AAEpC;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAC3C,mBAAmB,EACjB,4BAA4B,GAC5B,cAAc,GACd,yBAAyB,GACzB,yBAAyB,GACzB,oBAAoB,GACpB,mCAAmC,GACnC,+BAA+B,CAClC,CAAC"}
|
package/dist/security/index.d.ts
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
export { auditScriptDependencies, createSecurityAudit, } from "./audit";
|
|
2
|
+
export { authorizeRoute, defineAuthorization, mergeRouteAccess, permitsRequest, resolveRouteAccess, } from "./authorization";
|
|
2
3
|
export { applyCorsHeaders, createCorsHeaders, createCorsPreflightResponse, validateCorsPolicy, } from "./cors";
|
|
3
4
|
export { createSecureCookie, readSecureCookie, secureCookieName, validateSecureCookie, } from "./cookies";
|
|
4
5
|
export type { CookieIssue, CookieIssueCode, CookieSameSite, CookieScope, SecureCookieDeclaration, SecureCookieDefinition, } from "./cookies";
|
|
6
|
+
export { createEncryptedCookieSession, createSignedCookieSession, } from "./cookie-session";
|
|
7
|
+
export type { CookieSession, CookieSessionCreateOptions, CookieSessionManager, CookieSessionOptions, SessionCookieDefinition, SessionCookieKey, } from "./cookie-session";
|
|
5
8
|
export { createCsrfCookie, createCsrfToken, enforceCsrfProtection, issueCsrfToken, parseCookieHeader, } from "./csrf";
|
|
6
9
|
export type { CsrfCookieOptions, IssuedCsrfToken } from "./csrf";
|
|
7
10
|
export { applyFetchMetadataVary, checkFetchMetadata, enforceFetchMetadataPolicy, } from "./fetch-metadata";
|
|
8
11
|
export type { FetchMetadataEnforcement } from "./fetch-metadata";
|
|
9
12
|
export { EnvValidationError, defineEnvSchema, env, validateEnv, } from "./env";
|
|
13
|
+
export { deserializeEnvSchema, readEnv, resetEnvironment as unstable_resetEnvironment, serializeEnvSchema, startEnvironment as unstable_startEnvironment, } from "./env-startup";
|
|
14
|
+
export type { EnvStartupOptions, EnvStartupResult, } from "./env-startup";
|
|
10
15
|
export { createSecurityHeaders, cspNonce, cspHash, defineRoutePolicy, defineSecurityPolicy, mergeRoutePolicies, mergeRouteSecurityPolicies, mergeSecurityPolicies, security, } from "./policy";
|
|
11
16
|
export { createMemoryRateLimitStore, enforceRateLimit, parseRateLimitWindow, validateRateLimitPolicy, } from "./rate-limit";
|
|
17
|
+
export { createMemorySessionStore, parseSessionRecord, serializeSessionNamespace, } from "./session-store";
|
|
18
|
+
export { createSessionManager, SessionStoreConflictError, SessionStoreUnavailableError, } from "./session-manager";
|
|
19
|
+
export type { ServerSession, SessionManager, SessionManagerOptions, } from "./session-manager";
|
|
20
|
+
export type { MemorySessionStoreOptions, SessionData, SessionNamespace, SessionPrimitive, SessionRecord, SessionStore, SessionStoreCandidate, SessionStoreWriteResult, } from "./session-store";
|
|
12
21
|
export { createSecurityReportHandler, } from "./report";
|
|
13
|
-
export { enforceAllowedMethods, enforceRequestSecurity, parseBodySize, } from "./request";
|
|
22
|
+
export { DEFAULT_MAX_BODY_SIZE, enforceAllowedMethods, enforceRequestSecurity, parseBodySize, } from "./request";
|
|
14
23
|
export { validateUploads, } from "./upload";
|
|
15
24
|
export { validateRouteModules } from "./verification";
|
|
16
25
|
export type { RouteModuleVerificationOptions } from "./verification";
|
|
17
26
|
export { checkWebSocketOrigin, enforceWebSocketOrigin, } from "./websocket";
|
|
18
|
-
export type { ContentSecurityPolicy, CorsPolicy, CorsRequestContext, CorsResponseOptions, CsrfPolicy, CspHashAlgorithm, CspDirectiveValue, CspDirectiveReplacement, CspSource, CspSourceDirective, FetchMetadataCheck, FetchMetadataDestination, FetchMetadataPolicy, FetchMetadataPolicyOptions, FetchMetadataReason, MemoryRateLimitStoreOptions, RateLimitKey, RateLimitPolicy, RateLimitResult, RateLimitStore, ReferrerPolicy, ReportingEndpointUrl, ReportingEndpoints, SecurityAudit, SecurityAuditFinding, SecurityAuditOptions, ScriptDependencyAuditOptions, RequestSecurityPolicy, RoutePolicy, RouteSecurityNeeds, RouteSecurityPolicy, SecurityHeadersOptions, SecurityHeaderPolicy, SecurityPolicy, SecurityPreset, StrictTransportSecurityPolicy, TrustedTypesPolicy, } from "./types";
|
|
27
|
+
export type { AuthorizationDecision, AuthorizationDenial, AuthorizationDenialStatus, ContentSecurityPolicy, CorsPolicy, CorsRequestContext, CorsResponseOptions, CsrfPolicy, CspHashAlgorithm, CspDirectiveValue, CspDirectiveReplacement, CspSource, CspSourceDirective, FetchMetadataCheck, FetchMetadataDestination, FetchMetadataPolicy, FetchMetadataPolicyOptions, FetchMetadataReason, BodySizeException, BodySizeValue, CspException, CsrfException, CsrfPolicyOptions, MemoryRateLimitStoreOptions, RateLimitKey, RateLimitPolicy, RateLimitResult, RateLimitStore, ReferrerPolicy, ReportingEndpointUrl, ReportingEndpoints, SecurityAudit, SecurityAuditFinding, SecurityException, SecurityExceptionOrigin, SecurityAuditOptions, ScriptDependencyAuditOptions, MergedRoutePolicy, RequestSecurityPolicy, ResolvedRouteAccess, RouteAccessException, RouteAccessPolicy, RouteAccessSource, RouteAuthorizationEntry, RouteAuthorizationHook, RoutePolicy, RouteSecurityNeeds, RouteSecurityPolicy, SecurityHeadersOptions, SecurityHeaderPolicy, SecurityPolicy, SecurityPreset, StrictTransportSecurityPolicy, TrustedTypesPolicy, } from "./types";
|
|
28
|
+
export type { SecurityFindingCode, StaticPolicyFindingCode, } from "./finding-codes";
|
|
29
|
+
export { attachExceptionSource, getBodySizeException, getCspException, getCsrfException, isSecurityException, resolveCsp, resolveCsrf, resolveMaxBodySize, } from "./exceptions";
|
|
19
30
|
export type { UploadFilePolicy, UploadPolicy, UploadValidationIssue, UploadValidationResult, } from "./upload";
|
|
20
|
-
export type { EnvSchema, EnvSource, EnvValidationIssue, EnvVariable, InferEnvSchema, } from "./env";
|
|
31
|
+
export type { EnvSchema, EnvSchemaDescriptor, EnvSource, EnvValidationIssue, EnvVariable, EnvVariableDescriptor, EnvVariableKind, InferEnvSchema, } from "./env";
|
|
21
32
|
export type { SecurityReportContext, SecurityReportHandlerOptions, SecurityReportPayload, } from "./report";
|
|
22
33
|
export type { WebSocketOriginCheck, WebSocketOriginPolicy, } from "./websocket";
|
|
23
34
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,QAAQ,CAAC;AAChB,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B,EACnB,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,uBAAuB,EACvB,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,2BAA2B,EAC3B,YAAY,EACZ,eAAe,EACf,eAAe,EACf,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,qBAAqB,EACrB,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,6BAA6B,EAC7B,kBAAkB,GACnB,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,SAAS,EACT,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,cAAc,GACf,MAAM,OAAO,CAAC;AACf,YAAY,EACV,qBAAqB,EACrB,4BAA4B,EAC5B,qBAAqB,GACtB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,WAAW,CAAC;AACnB,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,uBAAuB,EACvB,sBAAsB,EACtB,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,6BAA6B,EAC7B,kBAAkB,GACnB,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACrB,eAAe,EACf,cAAc,GACf,MAAM,OAAO,CAAC;AACf,YAAY,EACV,qBAAqB,EACrB,4BAA4B,EAC5B,qBAAqB,GACtB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,aAAa,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CspHashAlgorithm, RoutePolicy, RouteSecurityPolicy, SecurityHeadersOptions, SecurityPolicy, SecurityPreset } from "./types";
|
|
1
|
+
import type { CspHashAlgorithm, MergedRoutePolicy, RoutePolicy, RouteSecurityPolicy, SecurityHeadersOptions, SecurityPolicy, SecurityPreset } from "./types";
|
|
2
2
|
export declare const cspNonce: "'nonce-{nonce}'";
|
|
3
3
|
export declare const security: {
|
|
4
4
|
api(options?: SecurityPolicy): SecurityPolicy;
|
|
@@ -10,10 +10,7 @@ export declare const security: {
|
|
|
10
10
|
export declare function defineSecurityPolicy(policy: SecurityPolicy): SecurityPolicy;
|
|
11
11
|
export declare function defineRoutePolicy(policy: RoutePolicy): RoutePolicy;
|
|
12
12
|
export declare function mergeSecurityPolicies(...policies: Array<SecurityPolicy | false | undefined>): SecurityPolicy;
|
|
13
|
-
export declare function mergeRoutePolicies(...policies: Array<RoutePolicy | false | undefined>):
|
|
14
|
-
document: SecurityPolicy | undefined;
|
|
15
|
-
security?: RouteSecurityPolicy;
|
|
16
|
-
};
|
|
13
|
+
export declare function mergeRoutePolicies(...policies: Array<RoutePolicy | false | undefined>): MergedRoutePolicy;
|
|
17
14
|
export declare function mergeRouteSecurityPolicies(...policies: Array<RouteSecurityPolicy | false | undefined>): RouteSecurityPolicy;
|
|
18
15
|
export declare function cspHash(source: string, algorithm?: CspHashAlgorithm): Promise<string>;
|
|
19
16
|
export declare function createSecurityHeaders(policy: SecurityPolicy, options?: SecurityHeadersOptions): Headers;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/security/policy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/security/policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,gBAAgB,EAGhB,iBAAiB,EACjB,WAAW,EAEX,mBAAmB,EACnB,sBAAsB,EAEtB,cAAc,EACd,cAAc,EAGf,MAAM,SAAS,CAAC;AAKjB,eAAO,MAAM,QAAQ,mBAAmC,CAAC;AAyCzD,eAAO,MAAM,QAAQ;kBACN,cAAc;iBAQd,cAAc,YAAW,cAAc;qBAepC,cAAc;qBASd,cAAc;kCASD,cAAc;CAW5C,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,kBAE1D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,eAEpD;AAED,wBAAgB,qBAAqB,CACnC,GAAG,QAAQ,EAAE,KAAK,CAAC,cAAc,GAAG,KAAK,GAAG,SAAS,CAAC,kBASvD;AAED,wBAAgB,kBAAkB,CAChC,GAAG,QAAQ,EAAE,KAAK,CAAC,WAAW,GAAG,KAAK,GAAG,SAAS,CAAC,GAClD,iBAAiB,CAqBnB;AAED,wBAAgB,0BAA0B,CACxC,GAAG,QAAQ,EAAE,KAAK,CAAC,mBAAmB,GAAG,KAAK,GAAG,SAAS,CAAC,uBAe5D;AA2FD,wBAAsB,OAAO,CAC3B,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,gBAA2B,mBAQvC;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,sBAA2B,WAsCrC;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,cAAc,GAAG,KAAK,GAAG,SAAS,WAc3C;AAED,wBAAgB,cAAc,WAK7B"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { BodySizeValue } from "./types";
|
|
1
2
|
type MaybePromise<T> = Promise<T> | T;
|
|
2
3
|
export type SecurityReportPayload = unknown;
|
|
3
4
|
export type SecurityReportHandlerOptions = {
|
|
4
|
-
maxBodySize?:
|
|
5
|
+
maxBodySize?: BodySizeValue;
|
|
5
6
|
onReport?: (report: SecurityReportPayload, context: SecurityReportContext) => MaybePromise<void>;
|
|
6
7
|
};
|
|
7
8
|
export type SecurityReportContext = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../src/security/report.ts"],"names":[],"mappings":"AAMA,KAAK,YAAY,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEtC,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAE5C,MAAM,MAAM,4BAA4B,GAAG;IACzC,WAAW,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../src/security/report.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,KAAK,YAAY,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEtC,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAE5C,MAAM,MAAM,4BAA4B,GAAG;IACzC,WAAW,CAAC,EAAE,aAAa,CAAC;IAC5B,QAAQ,CAAC,EAAE,CACT,MAAM,EAAE,qBAAqB,EAC7B,OAAO,EAAE,qBAAqB,KAC3B,YAAY,CAAC,IAAI,CAAC,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,wBAAgB,2BAA2B,CACzC,OAAO,GAAE,4BAAiC,IAEC,SAAS,OAAO,uBAqD5D"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { HttpMethod } from "../route/types";
|
|
2
2
|
import type { RequestSecurityPolicy } from "./types";
|
|
3
|
+
export declare const DEFAULT_MAX_BODY_SIZE: "1mb";
|
|
3
4
|
export declare function enforceRequestSecurity(policy: RequestSecurityPolicy | undefined, request: Request, method: HttpMethod): Response | null;
|
|
4
5
|
export declare class RequestBodyTooLargeError extends Error {
|
|
5
6
|
constructor();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/security/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/security/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAcrD,eAAO,MAAM,qBAAqB,EAAG,KAAc,CAAC;AAEpD,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,qBAAqB,GAAG,SAAS,EACzC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,UAAU,mBA+BnB;AAED,qBAAa,wBAAyB,SAAQ,KAAK;;CAKlD;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,qBAAqB,GAAG,SAAS,EACzC,OAAO,EAAE,OAAO,WAoDjB;AAED,wBAAgB,2BAA2B,aAE1C;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,qBAAqB,GAAG,SAAS,EACzC,MAAM,EAAE,UAAU,mBAgBnB;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,UA2BnD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CookieSessionCreateOptions, SessionCookieDefinition, SessionCookieKey } from "./cookie-session";
|
|
2
|
+
import type { SessionData, SessionRecord, SessionStore } from "./session-store";
|
|
3
|
+
export type SessionManagerOptions<TData extends SessionData> = {
|
|
4
|
+
absoluteExpirationMs?: number;
|
|
5
|
+
cookie?: SessionCookieDefinition;
|
|
6
|
+
idleExpirationMs?: false | number;
|
|
7
|
+
keys: readonly SessionCookieKey[];
|
|
8
|
+
now?: () => number;
|
|
9
|
+
randomBytes?: (length: number) => Uint8Array;
|
|
10
|
+
renewal?: boolean;
|
|
11
|
+
store: SessionStore<TData>;
|
|
12
|
+
};
|
|
13
|
+
export type ServerSession<TData extends SessionData> = {
|
|
14
|
+
commit: () => Promise<readonly string[]>;
|
|
15
|
+
create: (data: TData, options?: CookieSessionCreateOptions) => Promise<SessionRecord<TData>>;
|
|
16
|
+
destroy: () => Promise<void>;
|
|
17
|
+
get: () => SessionRecord<TData> | undefined;
|
|
18
|
+
rotate: (data?: TData) => Promise<SessionRecord<TData>>;
|
|
19
|
+
update: (data: TData) => Promise<SessionRecord<TData>>;
|
|
20
|
+
};
|
|
21
|
+
export type SessionManager<TData extends SessionData> = {
|
|
22
|
+
cookieName: string;
|
|
23
|
+
open: (request: Request) => Promise<ServerSession<TData>>;
|
|
24
|
+
};
|
|
25
|
+
export declare class SessionStoreConflictError extends Error {
|
|
26
|
+
constructor(operation: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class SessionStoreUnavailableError extends Error {
|
|
29
|
+
constructor(operation: string);
|
|
30
|
+
}
|
|
31
|
+
export declare function createSessionManager<TData extends SessionData>(input: SessionManagerOptions<TData>): SessionManager<TData>;
|
|
32
|
+
//# sourceMappingURL=session-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../src/security/session-manager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,0BAA0B,EAC1B,uBAAuB,EACvB,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,YAAY,EAEb,MAAM,iBAAiB,CAAC;AAKzB,MAAM,MAAM,qBAAqB,CAAC,KAAK,SAAS,WAAW,IAAI;IAC7D,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,CAAC,EAAE,uBAAuB,CAAC;IACjC,gBAAgB,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAClC,IAAI,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAClC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,UAAU,CAAC;IAC7C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,KAAK,SAAS,WAAW,IAAI;IACrD,MAAM,EAAE,MAAM,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;IACzC,MAAM,EAAE,CACN,IAAI,EAAE,KAAK,EACX,OAAO,CAAC,EAAE,0BAA0B,KACjC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IACnC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,GAAG,EAAE,MAAM,aAAa,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;IAC5C,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IACxD,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,WAAW,IAAI;IACtD,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;CAC3D,CAAC;AAEF,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,SAAS,EAAE,MAAM;CAM9B;AAED,qBAAa,4BAA6B,SAAQ,KAAK;gBACzC,SAAS,EAAE,MAAM;CAM9B;AAED,wBAAgB,oBAAoB,CAAC,KAAK,SAAS,WAAW,EAC5D,KAAK,EAAE,qBAAqB,CAAC,KAAK,CAAC,GAClC,cAAc,CAAC,KAAK,CAAC,CAkKvB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type SessionPrimitive = boolean | null | number | string;
|
|
2
|
+
export type SessionData = SessionPrimitive | {
|
|
3
|
+
readonly [key: string]: SessionData;
|
|
4
|
+
} | readonly SessionData[];
|
|
5
|
+
export type SessionNamespace = {
|
|
6
|
+
app: string;
|
|
7
|
+
environment: string;
|
|
8
|
+
schemaVersion: number | string;
|
|
9
|
+
};
|
|
10
|
+
export type SessionRecord<TData extends SessionData = SessionData> = {
|
|
11
|
+
createdAt: number;
|
|
12
|
+
data: TData;
|
|
13
|
+
expiresAt: number;
|
|
14
|
+
id: string;
|
|
15
|
+
idleExpiresAt?: number;
|
|
16
|
+
version: number;
|
|
17
|
+
};
|
|
18
|
+
export type SessionStoreCandidate<TData extends SessionData = SessionData> = Omit<SessionRecord<TData>, "version">;
|
|
19
|
+
export type SessionStoreWriteResult<TData extends SessionData = SessionData> = {
|
|
20
|
+
record: SessionRecord<TData>;
|
|
21
|
+
status: "stored";
|
|
22
|
+
} | {
|
|
23
|
+
status: "conflict";
|
|
24
|
+
} | {
|
|
25
|
+
status: "unavailable";
|
|
26
|
+
};
|
|
27
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
28
|
+
export type SessionStore<TData extends SessionData = SessionData> = {
|
|
29
|
+
create: (candidate: SessionStoreCandidate<TData>) => MaybePromise<SessionStoreWriteResult<TData>>;
|
|
30
|
+
destroy: (id: string) => MaybePromise<boolean>;
|
|
31
|
+
read: (id: string, now: number) => MaybePromise<SessionRecord<TData> | undefined>;
|
|
32
|
+
rotate: (currentId: string, candidate: SessionStoreCandidate<TData>, expectedVersion: number) => MaybePromise<SessionStoreWriteResult<TData>>;
|
|
33
|
+
update: (candidate: SessionStoreCandidate<TData>, expectedVersion: number) => MaybePromise<SessionStoreWriteResult<TData>>;
|
|
34
|
+
};
|
|
35
|
+
export type MemorySessionStoreOptions<TData extends SessionData = SessionData> = {
|
|
36
|
+
entries?: Map<string, SessionRecord<TData>>;
|
|
37
|
+
namespace: SessionNamespace;
|
|
38
|
+
};
|
|
39
|
+
export declare function createMemorySessionStore<TData extends SessionData = SessionData>(options: MemorySessionStoreOptions<TData>): SessionStore<TData>;
|
|
40
|
+
/**
|
|
41
|
+
* Validates that an untrusted parsed value conforms to the `SessionRecord`
|
|
42
|
+
* envelope before it is trusted as a session. Backend session stores read
|
|
43
|
+
* raw JSON from shared infrastructure (KV, Redis) that a corrupted entry,
|
|
44
|
+
* manual edit, or deployment version skew could have produced, so the shape
|
|
45
|
+
* must be proven rather than assumed. Mirrors the validation cookie-session
|
|
46
|
+
* applies to its own decoded payloads.
|
|
47
|
+
*/
|
|
48
|
+
export declare function parseSessionRecord<TData extends SessionData = SessionData>(value: unknown): SessionRecord<TData> | undefined;
|
|
49
|
+
export declare function serializeSessionNamespace(namespace: SessionNamespace): string;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=session-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-store.d.ts","sourceRoot":"","sources":["../../src/security/session-store.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;AAEhE,MAAM,MAAM,WAAW,GACnB,gBAAgB,GAChB;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW,CAAA;CAAE,GACvC,SAAS,WAAW,EAAE,CAAC;AAE3B,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,KAAK,SAAS,WAAW,GAAG,WAAW,IAAI;IACnE,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,KAAK,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAAC,KAAK,SAAS,WAAW,GAAG,WAAW,IACvE,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC;AAExC,MAAM,MAAM,uBAAuB,CAAC,KAAK,SAAS,WAAW,GAAG,WAAW,IACvE;IAAE,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;IAAC,MAAM,EAAE,QAAQ,CAAA;CAAE,GAClD;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,GACtB;IAAE,MAAM,EAAE,aAAa,CAAA;CAAE,CAAC;AAE9B,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEt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AS,EAAE,gBAAgB,UAsBpE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SessionData, SessionNamespace, SessionStore } from "./session-store";
|
|
2
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
3
|
+
export type SessionStoreFactory<TData extends SessionData = SessionData> = (namespace: SessionNamespace) => MaybePromise<SessionStore<TData>>;
|
|
4
|
+
type ContractData = {
|
|
5
|
+
authenticated: boolean;
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function verifySessionStoreContract(createStore: SessionStoreFactory<ContractData>): Promise<void>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../src/security/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAEhB,YAAY,EAEb,MAAM,iBAAiB,CAAC;AAEzB,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtC,MAAM,MAAM,mBAAmB,CAAC,KAAK,SAAS,WAAW,GAAG,WAAW,IAAI,CACzE,SAAS,EAAE,gBAAgB,KACxB,YAAY,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;AAEvC,KAAK,YAAY,GAAG;IAClB,aAAa,EAAE,OAAO,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,mBAAmB,CAAC,YAAY,CAAC,iBAsJ/C"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
async function S(o) {
|
|
2
|
+
const t = `${Date.now()}-${Math.random()}`, n = {
|
|
3
|
+
app: `contract-${t}`,
|
|
4
|
+
environment: "test",
|
|
5
|
+
schemaVersion: 1
|
|
6
|
+
}, m = {
|
|
7
|
+
...n,
|
|
8
|
+
environment: "isolated"
|
|
9
|
+
}, a = await o(n), l = await o(n), f = await o(m), r = Date.now(), i = p(`session-${t}`, r, {
|
|
10
|
+
authenticated: !1,
|
|
11
|
+
name: "alpha"
|
|
12
|
+
}), d = p(`rotated-${t}`, r, {
|
|
13
|
+
authenticated: !0,
|
|
14
|
+
name: "alpha"
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
e(
|
|
18
|
+
await a.read(i.id, r) === void 0,
|
|
19
|
+
"read() must return undefined for a missing identifier"
|
|
20
|
+
);
|
|
21
|
+
const x = await a.create(i);
|
|
22
|
+
s(x, "create() must store a missing identifier"), b(
|
|
23
|
+
await l.read(i.id, r),
|
|
24
|
+
{ ...i, version: 0 },
|
|
25
|
+
"create() must make a record available to another store instance"
|
|
26
|
+
), e(
|
|
27
|
+
(await a.create(i)).status === "conflict",
|
|
28
|
+
"create() must report a conflict for an existing identifier"
|
|
29
|
+
), e(
|
|
30
|
+
await f.read(i.id, r) === void 0,
|
|
31
|
+
"a namespace must not read another namespace's record"
|
|
32
|
+
);
|
|
33
|
+
const g = await f.create({
|
|
34
|
+
...i,
|
|
35
|
+
data: { authenticated: !1, name: "isolated" }
|
|
36
|
+
});
|
|
37
|
+
s(
|
|
38
|
+
g,
|
|
39
|
+
"create() must allow the same identifier in another namespace"
|
|
40
|
+
);
|
|
41
|
+
const $ = {
|
|
42
|
+
...i,
|
|
43
|
+
data: { authenticated: !0, name: "beta" }
|
|
44
|
+
}, h = await l.update($, 0);
|
|
45
|
+
s(h, "update() must replace the expected version"), e(
|
|
46
|
+
h.record.version === 1,
|
|
47
|
+
"update() must increment the stored version"
|
|
48
|
+
), e(
|
|
49
|
+
(await a.update(i, 0)).status === "conflict",
|
|
50
|
+
"update() must reject an obsolete version"
|
|
51
|
+
);
|
|
52
|
+
const w = await Promise.all([
|
|
53
|
+
a.rotate(i.id, d, 1),
|
|
54
|
+
l.rotate(
|
|
55
|
+
i.id,
|
|
56
|
+
{ ...d, id: `${d.id}-competitor` },
|
|
57
|
+
1
|
|
58
|
+
)
|
|
59
|
+
]);
|
|
60
|
+
e(
|
|
61
|
+
w.filter((u) => u.status === "stored").length === 1,
|
|
62
|
+
"only one concurrent rotation can succeed"
|
|
63
|
+
), e(
|
|
64
|
+
w.filter((u) => u.status === "conflict").length === 1,
|
|
65
|
+
"one concurrent rotation must report a conflict"
|
|
66
|
+
), e(
|
|
67
|
+
await a.read(i.id, r) === void 0,
|
|
68
|
+
"rotation must invalidate the previous identifier"
|
|
69
|
+
);
|
|
70
|
+
const c = w.find(
|
|
71
|
+
(u) => u.status === "stored"
|
|
72
|
+
);
|
|
73
|
+
s(c, "rotation must return its stored record"), e(
|
|
74
|
+
c.record.version === 2,
|
|
75
|
+
"rotation must increment the stored version"
|
|
76
|
+
), e(
|
|
77
|
+
await l.destroy(c.record.id),
|
|
78
|
+
"destroy() must remove an existing identifier"
|
|
79
|
+
), e(
|
|
80
|
+
await a.read(c.record.id, r) === void 0,
|
|
81
|
+
"destroy() must revoke a session for another store instance"
|
|
82
|
+
), e(
|
|
83
|
+
!await a.destroy(c.record.id),
|
|
84
|
+
"destroy() must report a missing identifier"
|
|
85
|
+
);
|
|
86
|
+
const v = p(`expired-${t}`, r, {
|
|
87
|
+
authenticated: !1,
|
|
88
|
+
name: "expired"
|
|
89
|
+
}, -1);
|
|
90
|
+
s(
|
|
91
|
+
await a.create(v),
|
|
92
|
+
"create() must accept a record before read-time expiration checks"
|
|
93
|
+
), e(
|
|
94
|
+
await a.read(v.id, r) === void 0,
|
|
95
|
+
"read() must not return an absolutely expired record"
|
|
96
|
+
);
|
|
97
|
+
const y = {
|
|
98
|
+
...p(`idle-${t}`, r, {
|
|
99
|
+
authenticated: !1,
|
|
100
|
+
name: "idle"
|
|
101
|
+
}),
|
|
102
|
+
idleExpiresAt: r - 1
|
|
103
|
+
};
|
|
104
|
+
s(
|
|
105
|
+
await a.create(y),
|
|
106
|
+
"create() must accept a record with idle expiration"
|
|
107
|
+
), e(
|
|
108
|
+
await a.read(y.id, r) === void 0,
|
|
109
|
+
"read() must not return an idle-expired record"
|
|
110
|
+
);
|
|
111
|
+
} finally {
|
|
112
|
+
await Promise.all([
|
|
113
|
+
a.destroy(i.id),
|
|
114
|
+
a.destroy(d.id),
|
|
115
|
+
a.destroy(`${d.id}-competitor`),
|
|
116
|
+
f.destroy(i.id)
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function p(o, t, n, m = 6e4) {
|
|
121
|
+
return {
|
|
122
|
+
createdAt: t,
|
|
123
|
+
data: n,
|
|
124
|
+
expiresAt: t + m,
|
|
125
|
+
id: o,
|
|
126
|
+
idleExpiresAt: t + m
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function s(o, t) {
|
|
130
|
+
e(o?.status === "stored", t);
|
|
131
|
+
}
|
|
132
|
+
function b(o, t, n) {
|
|
133
|
+
e(
|
|
134
|
+
JSON.stringify(o) === JSON.stringify(t),
|
|
135
|
+
n
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
function e(o, t) {
|
|
139
|
+
if (!o)
|
|
140
|
+
throw new Error(`Session store contract failed: ${t}.`);
|
|
141
|
+
}
|
|
142
|
+
export {
|
|
143
|
+
S as verifySessionStoreContract
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sources":["../../src/security/testing.ts"],"sourcesContent":["import type {\n SessionData,\n SessionNamespace,\n SessionRecord,\n SessionStore,\n SessionStoreCandidate,\n} from \"./session-store\";\n\ntype MaybePromise<T> = T | Promise<T>;\n\nexport type SessionStoreFactory<TData extends SessionData = SessionData> = (\n namespace: SessionNamespace,\n) => MaybePromise<SessionStore<TData>>;\n\ntype ContractData = {\n authenticated: boolean;\n name: string;\n};\n\nexport async function verifySessionStoreContract(\n createStore: SessionStoreFactory<ContractData>,\n) {\n const token = `${Date.now()}-${Math.random()}`;\n const namespace = {\n app: `contract-${token}`,\n environment: \"test\",\n schemaVersion: 1,\n } satisfies SessionNamespace;\n const isolatedNamespace = {\n ...namespace,\n environment: \"isolated\",\n } satisfies SessionNamespace;\n const store = await createStore(namespace);\n const secondReplica = await createStore(namespace);\n const isolatedStore = await createStore(isolatedNamespace);\n const now = Date.now();\n const original = candidate(`session-${token}`, now, {\n authenticated: false,\n name: \"alpha\",\n });\n const rotated = candidate(`rotated-${token}`, now, {\n authenticated: true,\n name: \"alpha\",\n });\n\n try {\n assert(\n await store.read(original.id, now) === undefined,\n \"read() must return undefined for a missing identifier\",\n );\n\n const created = await store.create(original);\n assertStored(created, \"create() must store a missing identifier\");\n assertRecord(\n await secondReplica.read(original.id, now),\n { ...original, version: 0 },\n \"create() must make a record available to another store instance\",\n );\n\n assert(\n (await store.create(original)).status === \"conflict\",\n \"create() must report a conflict for an existing identifier\",\n );\n assert(\n await isolatedStore.read(original.id, now) === undefined,\n \"a namespace must not read another namespace's record\",\n );\n\n const isolatedCreated = await isolatedStore.create({\n ...original,\n data: { authenticated: false, name: \"isolated\" },\n });\n assertStored(\n isolatedCreated,\n \"create() must allow the same identifier in another namespace\",\n );\n\n const updatedCandidate = {\n ...original,\n data: { authenticated: true, name: \"beta\" },\n } satisfies SessionStoreCandidate<ContractData>;\n const updated = await secondReplica.update(updatedCandidate, 0);\n assertStored(updated, \"update() must replace the expected version\");\n assert(\n updated.record.version === 1,\n \"update() must increment the stored version\",\n );\n assert(\n (await store.update(original, 0)).status === \"conflict\",\n \"update() must reject an obsolete version\",\n );\n\n const rotations = await Promise.all([\n store.rotate(original.id, rotated, 1),\n secondReplica.rotate(\n original.id,\n { ...rotated, id: `${rotated.id}-competitor` },\n 1,\n ),\n ]);\n assert(\n rotations.filter((result) => result.status === \"stored\").length === 1,\n \"only one concurrent rotation can succeed\",\n );\n assert(\n rotations.filter((result) => result.status === \"conflict\").length === 1,\n \"one concurrent rotation must report a conflict\",\n );\n assert(\n await store.read(original.id, now) === undefined,\n \"rotation must invalidate the previous identifier\",\n );\n\n const successfulRotation = rotations.find(\n (result) => result.status === \"stored\",\n );\n assertStored(successfulRotation, \"rotation must return its stored record\");\n assert(\n successfulRotation.record.version === 2,\n \"rotation must increment the stored version\",\n );\n assert(\n await secondReplica.destroy(successfulRotation.record.id),\n \"destroy() must remove an existing identifier\",\n );\n assert(\n await store.read(successfulRotation.record.id, now) === undefined,\n \"destroy() must revoke a session for another store instance\",\n );\n assert(\n !await store.destroy(successfulRotation.record.id),\n \"destroy() must report a missing identifier\",\n );\n\n const expired = candidate(`expired-${token}`, now, {\n authenticated: false,\n name: \"expired\",\n }, -1);\n assertStored(\n await store.create(expired),\n \"create() must accept a record before read-time expiration checks\",\n );\n assert(\n await store.read(expired.id, now) === undefined,\n \"read() must not return an absolutely expired record\",\n );\n\n const idleExpired = {\n ...candidate(`idle-${token}`, now, {\n authenticated: false,\n name: \"idle\",\n }),\n idleExpiresAt: now - 1,\n };\n assertStored(\n await store.create(idleExpired),\n \"create() must accept a record with idle expiration\",\n );\n assert(\n await store.read(idleExpired.id, now) === undefined,\n \"read() must not return an idle-expired record\",\n );\n } finally {\n await Promise.all([\n store.destroy(original.id),\n store.destroy(rotated.id),\n store.destroy(`${rotated.id}-competitor`),\n isolatedStore.destroy(original.id),\n ]);\n }\n}\n\nfunction candidate(\n id: string,\n now: number,\n data: ContractData,\n expirationOffset = 60_000,\n): SessionStoreCandidate<ContractData> {\n return {\n createdAt: now,\n data,\n expiresAt: now + expirationOffset,\n id,\n idleExpiresAt: now + expirationOffset,\n };\n}\n\nfunction assertStored<TData extends SessionData>(\n result:\n | Awaited<ReturnType<SessionStore<TData>[\"create\"]>>\n | undefined,\n requirement: string,\n): asserts result is { record: SessionRecord<TData>; status: \"stored\" } {\n assert(result?.status === \"stored\", requirement);\n}\n\nfunction assertRecord<TData extends SessionData>(\n actual: SessionRecord<TData> | undefined,\n expected: SessionRecord<TData>,\n requirement: string,\n) {\n assert(\n JSON.stringify(actual) === JSON.stringify(expected),\n requirement,\n );\n}\n\nfunction assert(condition: boolean, requirement: string): asserts condition {\n if (!condition) {\n throw new Error(`Session store contract failed: ${requirement}.`);\n }\n}\n"],"names":["verifySessionStoreContract","createStore","token","namespace","isolatedNamespace","store","secondReplica","isolatedStore","now","original","candidate","rotated","assert","created","assertStored","assertRecord","isolatedCreated","updatedCandidate","updated","rotations","result","successfulRotation","expired","idleExpired","id","data","expirationOffset","requirement","actual","expected","condition"],"mappings":"AAmBA,eAAsBA,EACpBC,GACA;AACA,QAAMC,IAAQ,GAAG,KAAK,IAAA,CAAK,IAAI,KAAK,QAAQ,IACtCC,IAAY;AAAA,IAChB,KAAK,YAAYD,CAAK;AAAA,IACtB,aAAa;AAAA,IACb,eAAe;AAAA,EAAA,GAEXE,IAAoB;AAAA,IACxB,GAAGD;AAAA,IACH,aAAa;AAAA,EAAA,GAETE,IAAQ,MAAMJ,EAAYE,CAAS,GACnCG,IAAgB,MAAML,EAAYE,CAAS,GAC3CI,IAAgB,MAAMN,EAAYG,CAAiB,GACnDI,IAAM,KAAK,IAAA,GACXC,IAAWC,EAAU,WAAWR,CAAK,IAAIM,GAAK;AAAA,IAClD,eAAe;AAAA,IACf,MAAM;AAAA,EAAA,CACP,GACKG,IAAUD,EAAU,WAAWR,CAAK,IAAIM,GAAK;AAAA,IACjD,eAAe;AAAA,IACf,MAAM;AAAA,EAAA,CACP;AAED,MAAI;AACF,IAAAI;AAAA,MACE,MAAMP,EAAM,KAAKI,EAAS,IAAID,CAAG,MAAM;AAAA,MACvC;AAAA,IAAA;AAGF,UAAMK,IAAU,MAAMR,EAAM,OAAOI,CAAQ;AAC3C,IAAAK,EAAaD,GAAS,0CAA0C,GAChEE;AAAA,MACE,MAAMT,EAAc,KAAKG,EAAS,IAAID,CAAG;AAAA,MACzC,EAAE,GAAGC,GAAU,SAAS,EAAA;AAAA,MACxB;AAAA,IAAA,GAGFG;AAAA,OACG,MAAMP,EAAM,OAAOI,CAAQ,GAAG,WAAW;AAAA,MAC1C;AAA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