@kya-os/checkpoint-nextjs 1.7.1 → 1.10.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/CHANGELOG.md +107 -0
- package/EDGE_RUNTIME_WASM_SETUP.md +11 -11
- package/README.md +144 -251
- package/bin/setup-edge-wasm.js +9 -1
- package/dist/adapt.d.mts +6 -34
- package/dist/adapt.d.mts.map +1 -0
- package/dist/adapt.d.ts +6 -34
- package/dist/adapt.d.ts.map +1 -0
- package/dist/adapt.js +79 -49
- package/dist/adapt.mjs +78 -46
- package/dist/adapt.mjs.map +1 -0
- package/dist/api-client.d.mts +150 -150
- package/dist/api-client.d.mts.map +1 -0
- package/dist/api-client.d.ts +150 -150
- package/dist/api-client.d.ts.map +1 -0
- package/dist/api-client.js +218 -204
- package/dist/api-client.mjs +217 -201
- package/dist/api-client.mjs.map +1 -0
- package/dist/api-middleware-CDSh3TSE.js +379 -0
- package/dist/api-middleware-CMDRoQik.mjs +357 -0
- package/dist/api-middleware-CMDRoQik.mjs.map +1 -0
- package/dist/api-middleware.d.mts +117 -129
- package/dist/api-middleware.d.mts.map +1 -0
- package/dist/api-middleware.d.ts +117 -129
- package/dist/api-middleware.d.ts.map +1 -0
- package/dist/api-middleware.js +8 -540
- package/dist/api-middleware.mjs +3 -534
- package/dist/composed-policy-BCaNiVHv.d.mts +98 -0
- package/dist/composed-policy-BCaNiVHv.d.mts.map +1 -0
- package/dist/composed-policy-zzJYNFTb.d.ts +98 -0
- package/dist/composed-policy-zzJYNFTb.d.ts.map +1 -0
- package/dist/composed-policy.d.mts +2 -115
- package/dist/composed-policy.d.ts +2 -115
- package/dist/composed-policy.js +122 -88
- package/dist/composed-policy.mjs +121 -85
- package/dist/composed-policy.mjs.map +1 -0
- package/dist/config-CbAg2mze.d.ts +255 -0
- package/dist/config-CbAg2mze.d.ts.map +1 -0
- package/dist/config-Doe0Tn53.d.mts +255 -0
- package/dist/config-Doe0Tn53.d.mts.map +1 -0
- package/dist/create-middleware.d.mts +7 -18
- package/dist/create-middleware.d.mts.map +1 -0
- package/dist/create-middleware.d.ts +7 -18
- package/dist/create-middleware.d.ts.map +1 -0
- package/dist/create-middleware.js +36 -31
- package/dist/create-middleware.mjs +35 -28
- package/dist/create-middleware.mjs.map +1 -0
- package/dist/edge/index.d.mts +64 -86
- package/dist/edge/index.d.mts.map +1 -0
- package/dist/edge/index.d.ts +64 -86
- package/dist/edge/index.d.ts.map +1 -0
- package/dist/edge/index.js +349 -275
- package/dist/edge/index.mjs +348 -272
- package/dist/edge/index.mjs.map +1 -0
- package/dist/edge-runtime-loader.d.mts +37 -63
- package/dist/edge-runtime-loader.d.mts.map +1 -0
- package/dist/edge-runtime-loader.d.ts +37 -63
- package/dist/edge-runtime-loader.d.ts.map +1 -0
- package/dist/edge-runtime-loader.js +268 -225
- package/dist/edge-runtime-loader.mjs +267 -222
- package/dist/edge-runtime-loader.mjs.map +1 -0
- package/dist/edge-wasm-middleware.d.mts +27 -46
- package/dist/edge-wasm-middleware.d.mts.map +1 -0
- package/dist/edge-wasm-middleware.d.ts +27 -46
- package/dist/edge-wasm-middleware.d.ts.map +1 -0
- package/dist/edge-wasm-middleware.js +26 -15
- package/dist/edge-wasm-middleware.mjs +25 -12
- package/dist/edge-wasm-middleware.mjs.map +1 -0
- package/dist/index.d.mts +10 -17
- package/dist/index.d.ts +10 -17
- package/dist/index.js +55 -1224
- package/dist/index.mjs +16 -1193
- package/dist/index.mjs.map +1 -0
- package/dist/middleware-bundler.d.mts +7 -0
- package/dist/middleware-bundler.d.mts.map +1 -0
- package/dist/middleware-bundler.d.ts +7 -0
- package/dist/middleware-bundler.d.ts.map +1 -0
- package/dist/middleware-bundler.js +16 -0
- package/dist/middleware-bundler.mjs +16 -0
- package/dist/middleware-bundler.mjs.map +1 -0
- package/dist/middleware-core-BYQP9FND.mjs +165 -0
- package/dist/middleware-core-BYQP9FND.mjs.map +1 -0
- package/dist/middleware-core-D6TijE6P.js +175 -0
- package/dist/middleware-edge.d.mts +8 -50
- package/dist/middleware-edge.d.mts.map +1 -0
- package/dist/middleware-edge.d.ts +8 -50
- package/dist/middleware-edge.d.ts.map +1 -0
- package/dist/middleware-edge.js +41 -307
- package/dist/middleware-edge.mjs +39 -299
- package/dist/middleware-edge.mjs.map +1 -0
- package/dist/middleware-node-CE4GevYs.d.ts +20 -0
- package/dist/middleware-node-CE4GevYs.d.ts.map +1 -0
- package/dist/middleware-node-DtyOuPta.d.mts +20 -0
- package/dist/middleware-node-DtyOuPta.d.mts.map +1 -0
- package/dist/middleware-node-context-BqPbf-fI.mjs +34 -0
- package/dist/middleware-node-context-BqPbf-fI.mjs.map +1 -0
- package/dist/middleware-node-context-rgnc7UNR.js +38 -0
- package/dist/middleware-node.d.mts +3 -63
- package/dist/middleware-node.d.ts +3 -63
- package/dist/middleware-node.js +13 -308
- package/dist/middleware-node.mjs +12 -301
- package/dist/middleware-node.mjs.map +1 -0
- package/dist/middleware.d.mts +8 -28
- package/dist/middleware.d.mts.map +1 -0
- package/dist/middleware.d.ts +8 -28
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +43 -9
- package/dist/middleware.mjs +42 -6
- package/dist/middleware.mjs.map +1 -0
- package/dist/nodejs-wasm-loader.d.mts +8 -7
- package/dist/nodejs-wasm-loader.d.mts.map +1 -0
- package/dist/nodejs-wasm-loader.d.ts +8 -7
- package/dist/nodejs-wasm-loader.d.ts.map +1 -0
- package/dist/nodejs-wasm-loader.js +53 -19
- package/dist/nodejs-wasm-loader.mjs +52 -16
- package/dist/nodejs-wasm-loader.mjs.map +1 -0
- package/dist/policy.d.mts +86 -110
- package/dist/policy.d.mts.map +1 -0
- package/dist/policy.d.ts +86 -110
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +203 -160
- package/dist/policy.mjs +183 -147
- package/dist/policy.mjs.map +1 -0
- package/dist/session-tracker.d.mts +42 -47
- package/dist/session-tracker.d.mts.map +1 -0
- package/dist/session-tracker.d.ts +42 -47
- package/dist/session-tracker.d.ts.map +1 -0
- package/dist/session-tracker.js +141 -163
- package/dist/session-tracker.mjs +140 -160
- package/dist/session-tracker.mjs.map +1 -0
- package/dist/translate.d.mts +18 -30
- package/dist/translate.d.mts.map +1 -0
- package/dist/translate.d.ts +18 -30
- package/dist/translate.d.ts.map +1 -0
- package/dist/translate.js +70 -34
- package/dist/translate.mjs +70 -32
- package/dist/translate.mjs.map +1 -0
- package/dist/types-C0SkqLMM.d.mts +102 -0
- package/dist/types-C0SkqLMM.d.mts.map +1 -0
- package/dist/types-C7DNSCTO.d.ts +102 -0
- package/dist/types-C7DNSCTO.d.ts.map +1 -0
- package/dist/utils-Cj4XNhIY.mjs +35 -0
- package/dist/utils-Cj4XNhIY.mjs.map +1 -0
- package/dist/utils-DAisnYnI.js +45 -0
- package/dist/wasm-setup.d.mts +6 -5
- package/dist/wasm-setup.d.mts.map +1 -0
- package/dist/wasm-setup.d.ts +6 -5
- package/dist/wasm-setup.d.ts.map +1 -0
- package/dist/wasm-setup.js +82 -113
- package/dist/wasm-setup.mjs +85 -108
- package/dist/wasm-setup.mjs.map +1 -0
- package/package.json +22 -15
- package/dist/config-DAwIA4DB.d.mts +0 -214
- package/dist/config-DyU4l5er.d.ts +0 -214
- package/dist/types-D9RQvPNy.d.mts +0 -105
- package/dist/types-D9RQvPNy.d.ts +0 -105
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { PolicyFetcher } from "@kya-os/checkpoint-shared";
|
|
2
|
+
import { ComposedPolicyCompile } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
|
|
3
|
+
import { Decision, VerifyResult } from "@kya-os/checkpoint-wasm-runtime/engine";
|
|
4
|
+
//#region src/composed-policy.d.ts
|
|
5
|
+
/** Dashboard the composed-policy fetch defaults to when no base URL is set. */
|
|
6
|
+
declare const DEFAULT_DASHBOARD_URL = "https://kya.vouched.id";
|
|
7
|
+
/**
|
|
8
|
+
* Telemetry sink. The shadow-divergence signal is the go/no-go instrument for
|
|
9
|
+
* flipping a project to ENFORCE. Defaults to a no-op so the SDK never logs
|
|
10
|
+
* unprompted — `withCheckpoint({ debug: true })` wires the console logger.
|
|
11
|
+
*/
|
|
12
|
+
interface ComposedPolicyLogger {
|
|
13
|
+
shadowDivergence(info: ShadowDivergenceInfo): void;
|
|
14
|
+
evaluationError(projectId: string, error: unknown): void;
|
|
15
|
+
}
|
|
16
|
+
interface ShadowDivergenceInfo {
|
|
17
|
+
projectId: string;
|
|
18
|
+
path?: string;
|
|
19
|
+
engineDecision: Decision['kind'];
|
|
20
|
+
structuredDecision: Decision['kind'];
|
|
21
|
+
detectionClass: string;
|
|
22
|
+
verificationMethod?: string;
|
|
23
|
+
confidence: number;
|
|
24
|
+
agentName?: string;
|
|
25
|
+
}
|
|
26
|
+
/** Result of one composed-policy evaluation: the decision to enforce + whether it replaced the baseline. */
|
|
27
|
+
interface ComposedPolicyApplyResult {
|
|
28
|
+
decision: Decision;
|
|
29
|
+
acted: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* SSOT-served revision pin (sha256 of the evaluated bundle, byte-identical
|
|
32
|
+
* to `policy_revisions.composed_blob_hash`) — set ONLY when `acted`, echoed
|
|
33
|
+
* from `PolicyConfig.policySourceHash` (#3246 PR5). Absent on structured
|
|
34
|
+
* decisions and when the dashboard predates the field.
|
|
35
|
+
*/
|
|
36
|
+
composedBlobHash?: string;
|
|
37
|
+
}
|
|
38
|
+
interface ComposedPolicyContext {
|
|
39
|
+
/**
|
|
40
|
+
* Evaluate the project's composed policy for one request. Reads
|
|
41
|
+
* `result.decision` as the structured baseline for the divergence comparison;
|
|
42
|
+
* the caller applies `acted ? decision` afterwards. Never throws.
|
|
43
|
+
*/
|
|
44
|
+
apply(result: VerifyResult, path: string | undefined): Promise<ComposedPolicyApplyResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Resolve the org's trusted Layer-2 delegation root DIDs from the project's
|
|
47
|
+
* policy payload (P2 / DR-1). The middleware forwards these into the engine's
|
|
48
|
+
* `ContextSpec.trustedDelegationRoots` on delegation requests. Optional so an
|
|
49
|
+
* injected `composedPolicyEnforcer` (advanced/testing) need not implement it —
|
|
50
|
+
* absence ⇒ no roots ⇒ the engine's open default. Never throws (a fetch fault
|
|
51
|
+
* resolves to `[]`).
|
|
52
|
+
*/
|
|
53
|
+
trustedDelegationRoots?(): Promise<string[]>;
|
|
54
|
+
}
|
|
55
|
+
interface MakeComposedPolicyContextOptions {
|
|
56
|
+
projectId: string;
|
|
57
|
+
/** Fetches the project's `PolicyConfig` (carries the composed-policy fields). */
|
|
58
|
+
fetcher: PolicyFetcher;
|
|
59
|
+
/** Target compiler — Node `createPolicyEvaluator`-backed or edge `evaluatePolicy`. */
|
|
60
|
+
compile: ComposedPolicyCompile;
|
|
61
|
+
logger?: ComposedPolicyLogger;
|
|
62
|
+
cacheMax?: number;
|
|
63
|
+
}
|
|
64
|
+
declare function makeComposedPolicyContext(opts: MakeComposedPolicyContextOptions): ComposedPolicyContext;
|
|
65
|
+
/**
|
|
66
|
+
* Resolves the org's trusted delegation roots (empty when none). Built per
|
|
67
|
+
* middleware factory from whatever source can supply them — the composed
|
|
68
|
+
* context's accessor, or (when no context exists, e.g. Edge without
|
|
69
|
+
* `cedarWasmModule`) a `projectId`-only policy fetch.
|
|
70
|
+
*/
|
|
71
|
+
type TrustedDelegationRootsResolver = () => Promise<string[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Resolve the org trusted-delegation roots to inject into the engine for THIS
|
|
74
|
+
* request (P2 / DR-1). Returns `undefined` — leaving `VerifyRequestOpts`
|
|
75
|
+
* byte-identical to pre-P2 — unless (a) a resolver is configured and (b) the
|
|
76
|
+
* request actually carries a delegation-proof header (so the human /
|
|
77
|
+
* no-delegation hot path never pays the early policy fetch). Shared by the Node
|
|
78
|
+
* and Edge middleware entries.
|
|
79
|
+
*/
|
|
80
|
+
declare function resolveTrustedDelegationRootsForRequest(resolver: TrustedDelegationRootsResolver | null, headers: Headers): Promise<string[] | undefined>;
|
|
81
|
+
/**
|
|
82
|
+
* The per-request seam shared by both middleware entries. Evaluates the composed
|
|
83
|
+
* policy and swaps `result.decision` IN PLACE when the engine acts — so the
|
|
84
|
+
* swap happens BEFORE the detection reporter fires and before
|
|
85
|
+
* `renderDecisionAsResponse`, exactly like the Express runtime (the reporter
|
|
86
|
+
* records the enforced decision). Fail-OPEN: any fault keeps the structured
|
|
87
|
+
* decision; a policy fault never breaks the response.
|
|
88
|
+
*/
|
|
89
|
+
declare function applyComposedPolicy(context: ComposedPolicyContext | null, result: VerifyResult, path: string | undefined): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Debug logger mirroring the worker's `console.warn`/`console.error` shadow +
|
|
92
|
+
* fail-open telemetry. Wired by `withCheckpoint` only when `config.debug` is
|
|
93
|
+
* set, so the default SDK posture stays silent.
|
|
94
|
+
*/
|
|
95
|
+
declare const consoleComposedPolicyLogger: ComposedPolicyLogger;
|
|
96
|
+
//#endregion
|
|
97
|
+
export { MakeComposedPolicyContextOptions as a, applyComposedPolicy as c, resolveTrustedDelegationRootsForRequest as d, DEFAULT_DASHBOARD_URL as i, consoleComposedPolicyLogger as l, ComposedPolicyContext as n, ShadowDivergenceInfo as o, ComposedPolicyLogger as r, TrustedDelegationRootsResolver as s, ComposedPolicyApplyResult as t, makeComposedPolicyContext as u };
|
|
98
|
+
//# sourceMappingURL=composed-policy-zzJYNFTb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composed-policy-zzJYNFTb.d.ts","names":[],"sources":["../src/composed-policy.ts"],"mappings":";;;;;cA6Ba;;;;;;UAOI;EACf,iBAAiB,MAAM;EACvB,gBAAgB,mBAAmB;;UAGpB;EACf;EACA;EACA,gBAAgB;EAChB,oBAAoB;EACpB;EACA;EACA;EACA;;;UASe;EACf,UAAU;EACV;;;;;;;EAOA;;UAGe;;;;;;EAMf,MAAM,QAAQ,cAAc,2BAA2B,QAAQ;;;;;;;;;EAS/D,2BAA2B;;UAGZ;EACf;;EAEA,SAAS;;EAET,SAAS;EACT,SAAS;EACT;;iBAGc,0BACd,MAAM,mCACL;;;;;;;KA8ES,uCAAuC;;;;;;;;;iBAU7B,wCACpB,UAAU,uCACV,SAAS,UACR;;;;;;;;;iBAemB,oBACpB,SAAS,8BACT,QAAQ,cACR,2BACC;;;;;;cAsBU,6BAA6B"}
|
|
@@ -1,115 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { PolicyFetcher } from '@kya-os/checkpoint-shared';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Composed-policy (kya-os-engine) wiring for the Next.js middleware.
|
|
7
|
-
*
|
|
8
|
-
* A THIN layer on top of the shared core
|
|
9
|
-
* (`@kya-os/checkpoint-wasm-runtime/composed-policy`): the core owns all the
|
|
10
|
-
* logic (empty-Cedar deny-all guard, compile-once LRU cache, act-gate,
|
|
11
|
-
* divergence, and the `verifyResultToAuthorizeInput` parity projection), so this
|
|
12
|
-
* module only fetches the project's `PolicyConfig`, drives the core once per
|
|
13
|
-
* request, maps the tagged outcome to a decision-swap signal, and logs
|
|
14
|
-
* (debug-gated). Runtime-neutral — the caller injects the compiler:
|
|
15
|
-
* - Node: `(language, source) => createPolicyEvaluator(source)` (`./policy`)
|
|
16
|
-
* - Edge: `(language, source) => evaluatePolicy(language, source)` (`./policy-edge`)
|
|
17
|
-
*
|
|
18
|
-
* This is the SDK sibling of `@kya-os/checkpoint-express`'s composed-policy
|
|
19
|
-
* wiring; both consume the same core so the DNS Gateway, Express, and Next.js
|
|
20
|
-
* produce the same decision for the same composed Cedar bundle.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/** Dashboard the composed-policy fetch defaults to when no base URL is set. */
|
|
24
|
-
declare const DEFAULT_DASHBOARD_URL = "https://kya.vouched.id";
|
|
25
|
-
/**
|
|
26
|
-
* Telemetry sink. The shadow-divergence signal is the go/no-go instrument for
|
|
27
|
-
* flipping a project to ENFORCE. Defaults to a no-op so the SDK never logs
|
|
28
|
-
* unprompted — `withCheckpoint({ debug: true })` wires the console logger.
|
|
29
|
-
*/
|
|
30
|
-
interface ComposedPolicyLogger {
|
|
31
|
-
shadowDivergence(info: ShadowDivergenceInfo): void;
|
|
32
|
-
evaluationError(projectId: string, error: unknown): void;
|
|
33
|
-
}
|
|
34
|
-
interface ShadowDivergenceInfo {
|
|
35
|
-
projectId: string;
|
|
36
|
-
path?: string;
|
|
37
|
-
engineDecision: Decision['kind'];
|
|
38
|
-
structuredDecision: Decision['kind'];
|
|
39
|
-
detectionClass: string;
|
|
40
|
-
verificationMethod?: string;
|
|
41
|
-
confidence: number;
|
|
42
|
-
agentName?: string;
|
|
43
|
-
}
|
|
44
|
-
/** Result of one composed-policy evaluation: the decision to enforce + whether it replaced the baseline. */
|
|
45
|
-
interface ComposedPolicyApplyResult {
|
|
46
|
-
decision: Decision;
|
|
47
|
-
acted: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* SSOT-served revision pin (sha256 of the evaluated bundle, byte-identical
|
|
50
|
-
* to `policy_revisions.composed_blob_hash`) — set ONLY when `acted`, echoed
|
|
51
|
-
* from `PolicyConfig.policySourceHash` (#3246 PR5). Absent on structured
|
|
52
|
-
* decisions and when the dashboard predates the field.
|
|
53
|
-
*/
|
|
54
|
-
composedBlobHash?: string;
|
|
55
|
-
}
|
|
56
|
-
interface ComposedPolicyContext {
|
|
57
|
-
/**
|
|
58
|
-
* Evaluate the project's composed policy for one request. Reads
|
|
59
|
-
* `result.decision` as the structured baseline for the divergence comparison;
|
|
60
|
-
* the caller applies `acted ? decision` afterwards. Never throws.
|
|
61
|
-
*/
|
|
62
|
-
apply(result: VerifyResult, path: string | undefined): Promise<ComposedPolicyApplyResult>;
|
|
63
|
-
/**
|
|
64
|
-
* Resolve the org's trusted Layer-2 delegation root DIDs from the project's
|
|
65
|
-
* policy payload (P2 / DR-1). The middleware forwards these into the engine's
|
|
66
|
-
* `ContextSpec.trustedDelegationRoots` on delegation requests. Optional so an
|
|
67
|
-
* injected `composedPolicyEnforcer` (advanced/testing) need not implement it —
|
|
68
|
-
* absence ⇒ no roots ⇒ the engine's open default. Never throws (a fetch fault
|
|
69
|
-
* resolves to `[]`).
|
|
70
|
-
*/
|
|
71
|
-
trustedDelegationRoots?(): Promise<string[]>;
|
|
72
|
-
}
|
|
73
|
-
interface MakeComposedPolicyContextOptions {
|
|
74
|
-
projectId: string;
|
|
75
|
-
/** Fetches the project's `PolicyConfig` (carries the composed-policy fields). */
|
|
76
|
-
fetcher: PolicyFetcher;
|
|
77
|
-
/** Target compiler — Node `createPolicyEvaluator`-backed or edge `evaluatePolicy`. */
|
|
78
|
-
compile: ComposedPolicyCompile;
|
|
79
|
-
logger?: ComposedPolicyLogger;
|
|
80
|
-
cacheMax?: number;
|
|
81
|
-
}
|
|
82
|
-
declare function makeComposedPolicyContext(opts: MakeComposedPolicyContextOptions): ComposedPolicyContext;
|
|
83
|
-
/**
|
|
84
|
-
* Resolves the org's trusted delegation roots (empty when none). Built per
|
|
85
|
-
* middleware factory from whatever source can supply them — the composed
|
|
86
|
-
* context's accessor, or (when no context exists, e.g. Edge without
|
|
87
|
-
* `cedarWasmModule`) a `projectId`-only policy fetch.
|
|
88
|
-
*/
|
|
89
|
-
type TrustedDelegationRootsResolver = () => Promise<string[]>;
|
|
90
|
-
/**
|
|
91
|
-
* Resolve the org trusted-delegation roots to inject into the engine for THIS
|
|
92
|
-
* request (P2 / DR-1). Returns `undefined` — leaving `VerifyRequestOpts`
|
|
93
|
-
* byte-identical to pre-P2 — unless (a) a resolver is configured and (b) the
|
|
94
|
-
* request actually carries a delegation-proof header (so the human /
|
|
95
|
-
* no-delegation hot path never pays the early policy fetch). Shared by the Node
|
|
96
|
-
* and Edge middleware entries.
|
|
97
|
-
*/
|
|
98
|
-
declare function resolveTrustedDelegationRootsForRequest(resolver: TrustedDelegationRootsResolver | null, headers: Headers): Promise<string[] | undefined>;
|
|
99
|
-
/**
|
|
100
|
-
* The per-request seam shared by both middleware entries. Evaluates the composed
|
|
101
|
-
* policy and swaps `result.decision` IN PLACE when the engine acts — so the
|
|
102
|
-
* swap happens BEFORE the detection reporter fires and before
|
|
103
|
-
* `renderDecisionAsResponse`, exactly like the Express runtime (the reporter
|
|
104
|
-
* records the enforced decision). Fail-OPEN: any fault keeps the structured
|
|
105
|
-
* decision; a policy fault never breaks the response.
|
|
106
|
-
*/
|
|
107
|
-
declare function applyComposedPolicy(context: ComposedPolicyContext | null, result: VerifyResult, path: string | undefined): Promise<void>;
|
|
108
|
-
/**
|
|
109
|
-
* Debug logger mirroring the worker's `console.warn`/`console.error` shadow +
|
|
110
|
-
* fail-open telemetry. Wired by `withCheckpoint` only when `config.debug` is
|
|
111
|
-
* set, so the default SDK posture stays silent.
|
|
112
|
-
*/
|
|
113
|
-
declare const consoleComposedPolicyLogger: ComposedPolicyLogger;
|
|
114
|
-
|
|
115
|
-
export { type ComposedPolicyApplyResult, type ComposedPolicyContext, type ComposedPolicyLogger, DEFAULT_DASHBOARD_URL, type MakeComposedPolicyContextOptions, type ShadowDivergenceInfo, type TrustedDelegationRootsResolver, applyComposedPolicy, consoleComposedPolicyLogger, makeComposedPolicyContext, resolveTrustedDelegationRootsForRequest };
|
|
1
|
+
import { a as MakeComposedPolicyContextOptions, c as applyComposedPolicy, d as resolveTrustedDelegationRootsForRequest, i as DEFAULT_DASHBOARD_URL, l as consoleComposedPolicyLogger, n as ComposedPolicyContext, o as ShadowDivergenceInfo, r as ComposedPolicyLogger, s as TrustedDelegationRootsResolver, t as ComposedPolicyApplyResult, u as makeComposedPolicyContext } from "./composed-policy-BCaNiVHv.mjs";
|
|
2
|
+
export { ComposedPolicyApplyResult, ComposedPolicyContext, ComposedPolicyLogger, DEFAULT_DASHBOARD_URL, MakeComposedPolicyContextOptions, ShadowDivergenceInfo, TrustedDelegationRootsResolver, applyComposedPolicy, consoleComposedPolicyLogger, makeComposedPolicyContext, resolveTrustedDelegationRootsForRequest };
|
|
@@ -1,115 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { PolicyFetcher } from '@kya-os/checkpoint-shared';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Composed-policy (kya-os-engine) wiring for the Next.js middleware.
|
|
7
|
-
*
|
|
8
|
-
* A THIN layer on top of the shared core
|
|
9
|
-
* (`@kya-os/checkpoint-wasm-runtime/composed-policy`): the core owns all the
|
|
10
|
-
* logic (empty-Cedar deny-all guard, compile-once LRU cache, act-gate,
|
|
11
|
-
* divergence, and the `verifyResultToAuthorizeInput` parity projection), so this
|
|
12
|
-
* module only fetches the project's `PolicyConfig`, drives the core once per
|
|
13
|
-
* request, maps the tagged outcome to a decision-swap signal, and logs
|
|
14
|
-
* (debug-gated). Runtime-neutral — the caller injects the compiler:
|
|
15
|
-
* - Node: `(language, source) => createPolicyEvaluator(source)` (`./policy`)
|
|
16
|
-
* - Edge: `(language, source) => evaluatePolicy(language, source)` (`./policy-edge`)
|
|
17
|
-
*
|
|
18
|
-
* This is the SDK sibling of `@kya-os/checkpoint-express`'s composed-policy
|
|
19
|
-
* wiring; both consume the same core so the DNS Gateway, Express, and Next.js
|
|
20
|
-
* produce the same decision for the same composed Cedar bundle.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/** Dashboard the composed-policy fetch defaults to when no base URL is set. */
|
|
24
|
-
declare const DEFAULT_DASHBOARD_URL = "https://kya.vouched.id";
|
|
25
|
-
/**
|
|
26
|
-
* Telemetry sink. The shadow-divergence signal is the go/no-go instrument for
|
|
27
|
-
* flipping a project to ENFORCE. Defaults to a no-op so the SDK never logs
|
|
28
|
-
* unprompted — `withCheckpoint({ debug: true })` wires the console logger.
|
|
29
|
-
*/
|
|
30
|
-
interface ComposedPolicyLogger {
|
|
31
|
-
shadowDivergence(info: ShadowDivergenceInfo): void;
|
|
32
|
-
evaluationError(projectId: string, error: unknown): void;
|
|
33
|
-
}
|
|
34
|
-
interface ShadowDivergenceInfo {
|
|
35
|
-
projectId: string;
|
|
36
|
-
path?: string;
|
|
37
|
-
engineDecision: Decision['kind'];
|
|
38
|
-
structuredDecision: Decision['kind'];
|
|
39
|
-
detectionClass: string;
|
|
40
|
-
verificationMethod?: string;
|
|
41
|
-
confidence: number;
|
|
42
|
-
agentName?: string;
|
|
43
|
-
}
|
|
44
|
-
/** Result of one composed-policy evaluation: the decision to enforce + whether it replaced the baseline. */
|
|
45
|
-
interface ComposedPolicyApplyResult {
|
|
46
|
-
decision: Decision;
|
|
47
|
-
acted: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* SSOT-served revision pin (sha256 of the evaluated bundle, byte-identical
|
|
50
|
-
* to `policy_revisions.composed_blob_hash`) — set ONLY when `acted`, echoed
|
|
51
|
-
* from `PolicyConfig.policySourceHash` (#3246 PR5). Absent on structured
|
|
52
|
-
* decisions and when the dashboard predates the field.
|
|
53
|
-
*/
|
|
54
|
-
composedBlobHash?: string;
|
|
55
|
-
}
|
|
56
|
-
interface ComposedPolicyContext {
|
|
57
|
-
/**
|
|
58
|
-
* Evaluate the project's composed policy for one request. Reads
|
|
59
|
-
* `result.decision` as the structured baseline for the divergence comparison;
|
|
60
|
-
* the caller applies `acted ? decision` afterwards. Never throws.
|
|
61
|
-
*/
|
|
62
|
-
apply(result: VerifyResult, path: string | undefined): Promise<ComposedPolicyApplyResult>;
|
|
63
|
-
/**
|
|
64
|
-
* Resolve the org's trusted Layer-2 delegation root DIDs from the project's
|
|
65
|
-
* policy payload (P2 / DR-1). The middleware forwards these into the engine's
|
|
66
|
-
* `ContextSpec.trustedDelegationRoots` on delegation requests. Optional so an
|
|
67
|
-
* injected `composedPolicyEnforcer` (advanced/testing) need not implement it —
|
|
68
|
-
* absence ⇒ no roots ⇒ the engine's open default. Never throws (a fetch fault
|
|
69
|
-
* resolves to `[]`).
|
|
70
|
-
*/
|
|
71
|
-
trustedDelegationRoots?(): Promise<string[]>;
|
|
72
|
-
}
|
|
73
|
-
interface MakeComposedPolicyContextOptions {
|
|
74
|
-
projectId: string;
|
|
75
|
-
/** Fetches the project's `PolicyConfig` (carries the composed-policy fields). */
|
|
76
|
-
fetcher: PolicyFetcher;
|
|
77
|
-
/** Target compiler — Node `createPolicyEvaluator`-backed or edge `evaluatePolicy`. */
|
|
78
|
-
compile: ComposedPolicyCompile;
|
|
79
|
-
logger?: ComposedPolicyLogger;
|
|
80
|
-
cacheMax?: number;
|
|
81
|
-
}
|
|
82
|
-
declare function makeComposedPolicyContext(opts: MakeComposedPolicyContextOptions): ComposedPolicyContext;
|
|
83
|
-
/**
|
|
84
|
-
* Resolves the org's trusted delegation roots (empty when none). Built per
|
|
85
|
-
* middleware factory from whatever source can supply them — the composed
|
|
86
|
-
* context's accessor, or (when no context exists, e.g. Edge without
|
|
87
|
-
* `cedarWasmModule`) a `projectId`-only policy fetch.
|
|
88
|
-
*/
|
|
89
|
-
type TrustedDelegationRootsResolver = () => Promise<string[]>;
|
|
90
|
-
/**
|
|
91
|
-
* Resolve the org trusted-delegation roots to inject into the engine for THIS
|
|
92
|
-
* request (P2 / DR-1). Returns `undefined` — leaving `VerifyRequestOpts`
|
|
93
|
-
* byte-identical to pre-P2 — unless (a) a resolver is configured and (b) the
|
|
94
|
-
* request actually carries a delegation-proof header (so the human /
|
|
95
|
-
* no-delegation hot path never pays the early policy fetch). Shared by the Node
|
|
96
|
-
* and Edge middleware entries.
|
|
97
|
-
*/
|
|
98
|
-
declare function resolveTrustedDelegationRootsForRequest(resolver: TrustedDelegationRootsResolver | null, headers: Headers): Promise<string[] | undefined>;
|
|
99
|
-
/**
|
|
100
|
-
* The per-request seam shared by both middleware entries. Evaluates the composed
|
|
101
|
-
* policy and swaps `result.decision` IN PLACE when the engine acts — so the
|
|
102
|
-
* swap happens BEFORE the detection reporter fires and before
|
|
103
|
-
* `renderDecisionAsResponse`, exactly like the Express runtime (the reporter
|
|
104
|
-
* records the enforced decision). Fail-OPEN: any fault keeps the structured
|
|
105
|
-
* decision; a policy fault never breaks the response.
|
|
106
|
-
*/
|
|
107
|
-
declare function applyComposedPolicy(context: ComposedPolicyContext | null, result: VerifyResult, path: string | undefined): Promise<void>;
|
|
108
|
-
/**
|
|
109
|
-
* Debug logger mirroring the worker's `console.warn`/`console.error` shadow +
|
|
110
|
-
* fail-open telemetry. Wired by `withCheckpoint` only when `config.debug` is
|
|
111
|
-
* set, so the default SDK posture stays silent.
|
|
112
|
-
*/
|
|
113
|
-
declare const consoleComposedPolicyLogger: ComposedPolicyLogger;
|
|
114
|
-
|
|
115
|
-
export { type ComposedPolicyApplyResult, type ComposedPolicyContext, type ComposedPolicyLogger, DEFAULT_DASHBOARD_URL, type MakeComposedPolicyContextOptions, type ShadowDivergenceInfo, type TrustedDelegationRootsResolver, applyComposedPolicy, consoleComposedPolicyLogger, makeComposedPolicyContext, resolveTrustedDelegationRootsForRequest };
|
|
1
|
+
import { a as MakeComposedPolicyContextOptions, c as applyComposedPolicy, d as resolveTrustedDelegationRootsForRequest, i as DEFAULT_DASHBOARD_URL, l as consoleComposedPolicyLogger, n as ComposedPolicyContext, o as ShadowDivergenceInfo, r as ComposedPolicyLogger, s as TrustedDelegationRootsResolver, t as ComposedPolicyApplyResult, u as makeComposedPolicyContext } from "./composed-policy-zzJYNFTb.js";
|
|
2
|
+
export { ComposedPolicyApplyResult, ComposedPolicyContext, ComposedPolicyLogger, DEFAULT_DASHBOARD_URL, MakeComposedPolicyContextOptions, ShadowDivergenceInfo, TrustedDelegationRootsResolver, applyComposedPolicy, consoleComposedPolicyLogger, makeComposedPolicyContext, resolveTrustedDelegationRootsForRequest };
|
package/dist/composed-policy.js
CHANGED
|
@@ -1,102 +1,136 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _kya_os_checkpoint_wasm_runtime_composed_policy = require("@kya-os/checkpoint-wasm-runtime/composed-policy");
|
|
3
|
+
let _kya_os_checkpoint_shared = require("@kya-os/checkpoint-shared");
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
//#region src/composed-policy.ts
|
|
6
|
+
/**
|
|
7
|
+
* Composed-policy (kya-os-engine) wiring for the Next.js middleware.
|
|
8
|
+
*
|
|
9
|
+
* A THIN layer on top of the shared core
|
|
10
|
+
* (`@kya-os/checkpoint-wasm-runtime/composed-policy`): the core owns all the
|
|
11
|
+
* logic (empty-Cedar deny-all guard, compile-once LRU cache, act-gate,
|
|
12
|
+
* divergence, and the `verifyResultToAuthorizeInput` parity projection), so this
|
|
13
|
+
* module only fetches the project's `PolicyConfig`, drives the core once per
|
|
14
|
+
* request, maps the tagged outcome to a decision-swap signal, and logs
|
|
15
|
+
* (debug-gated). Runtime-neutral — the caller injects the compiler:
|
|
16
|
+
* - Node: `(language, source) => createPolicyEvaluator(source)` (`./policy`)
|
|
17
|
+
* - Edge: `(language, source) => evaluatePolicy(language, source)` (`./policy-edge`)
|
|
18
|
+
*
|
|
19
|
+
* This is the SDK sibling of `@kya-os/checkpoint-express`'s composed-policy
|
|
20
|
+
* wiring; both consume the same core so the DNS Gateway, Express, and Next.js
|
|
21
|
+
* produce the same decision for the same composed Cedar bundle.
|
|
22
|
+
*/
|
|
23
|
+
/** Dashboard the composed-policy fetch defaults to when no base URL is set. */
|
|
24
|
+
const DEFAULT_DASHBOARD_URL = "https://kya.vouched.id";
|
|
25
|
+
const NOOP_LOGGER = {
|
|
26
|
+
shadowDivergence: () => {},
|
|
27
|
+
evaluationError: () => {}
|
|
13
28
|
};
|
|
14
29
|
function makeComposedPolicyContext(opts) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
30
|
+
const { projectId, fetcher } = opts;
|
|
31
|
+
const cache = (0, _kya_os_checkpoint_wasm_runtime_composed_policy.makeComposedPolicyCache)({
|
|
32
|
+
compile: opts.compile,
|
|
33
|
+
cacheMax: opts.cacheMax
|
|
34
|
+
});
|
|
35
|
+
const logger = opts.logger ?? NOOP_LOGGER;
|
|
36
|
+
return {
|
|
37
|
+
async apply(result, path) {
|
|
38
|
+
const structured = {
|
|
39
|
+
decision: result.decision,
|
|
40
|
+
acted: false
|
|
41
|
+
};
|
|
42
|
+
if ((0, _kya_os_checkpoint_wasm_runtime_composed_policy.isCredentialVerificationBlock)(result.decision)) return structured;
|
|
43
|
+
const policy = await fetcher.getPolicy(projectId);
|
|
44
|
+
const outcome = await (0, _kya_os_checkpoint_wasm_runtime_composed_policy.evaluateComposedPolicy)({
|
|
45
|
+
cache,
|
|
46
|
+
projectId,
|
|
47
|
+
flags: {
|
|
48
|
+
policyLanguage: policy.policyLanguage,
|
|
49
|
+
policySourceText: policy.policySourceText,
|
|
50
|
+
engineEnforcementEnabled: policy.engineEnforcementEnabled,
|
|
51
|
+
enabled: policy.enabled
|
|
52
|
+
},
|
|
53
|
+
authorizeInput: (0, _kya_os_checkpoint_wasm_runtime_composed_policy.verifyResultToAuthorizeInput)(result, {
|
|
54
|
+
tenantId: projectId,
|
|
55
|
+
path
|
|
56
|
+
}),
|
|
57
|
+
baselineDecisionKind: result.decision.kind
|
|
58
|
+
});
|
|
59
|
+
if ((outcome.status === "acting" || outcome.status === "shadow") && outcome.diverged) logger.shadowDivergence({
|
|
60
|
+
projectId,
|
|
61
|
+
path,
|
|
62
|
+
engineDecision: outcome.engineDecision.kind,
|
|
63
|
+
structuredDecision: result.decision.kind,
|
|
64
|
+
detectionClass: result.detectionDetail.detectionClass.type,
|
|
65
|
+
verificationMethod: result.detectionDetail.verificationMethod,
|
|
66
|
+
confidence: result.detectionDetail.confidence,
|
|
67
|
+
agentName: result.detectionDetail.detectedAgent?.name
|
|
68
|
+
});
|
|
69
|
+
if (outcome.status === "error") {
|
|
70
|
+
logger.evaluationError(projectId, outcome.error);
|
|
71
|
+
return structured;
|
|
72
|
+
}
|
|
73
|
+
if (outcome.status === "acting") return {
|
|
74
|
+
decision: outcome.engineDecision,
|
|
75
|
+
acted: true,
|
|
76
|
+
...policy.policySourceHash ? { composedBlobHash: policy.policySourceHash } : {}
|
|
77
|
+
};
|
|
78
|
+
return structured;
|
|
79
|
+
},
|
|
80
|
+
async trustedDelegationRoots() {
|
|
81
|
+
return (await fetcher.getPolicy(projectId)).trustedDelegationRoots ?? [];
|
|
82
|
+
}
|
|
83
|
+
};
|
|
66
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Resolve the org trusted-delegation roots to inject into the engine for THIS
|
|
87
|
+
* request (P2 / DR-1). Returns `undefined` — leaving `VerifyRequestOpts`
|
|
88
|
+
* byte-identical to pre-P2 — unless (a) a resolver is configured and (b) the
|
|
89
|
+
* request actually carries a delegation-proof header (so the human /
|
|
90
|
+
* no-delegation hot path never pays the early policy fetch). Shared by the Node
|
|
91
|
+
* and Edge middleware entries.
|
|
92
|
+
*/
|
|
67
93
|
async function resolveTrustedDelegationRootsForRequest(resolver, headers) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
94
|
+
if (!resolver) return void 0;
|
|
95
|
+
if (!(0, _kya_os_checkpoint_shared.requestCarriesDelegationProof)(headers)) return void 0;
|
|
96
|
+
const roots = await resolver();
|
|
97
|
+
return roots.length > 0 ? roots : void 0;
|
|
72
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* The per-request seam shared by both middleware entries. Evaluates the composed
|
|
101
|
+
* policy and swaps `result.decision` IN PLACE when the engine acts — so the
|
|
102
|
+
* swap happens BEFORE the detection reporter fires and before
|
|
103
|
+
* `renderDecisionAsResponse`, exactly like the Express runtime (the reporter
|
|
104
|
+
* records the enforced decision). Fail-OPEN: any fault keeps the structured
|
|
105
|
+
* decision; a policy fault never breaks the response.
|
|
106
|
+
*/
|
|
73
107
|
async function applyComposedPolicy(context, result, path) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
} catch {
|
|
84
|
-
}
|
|
108
|
+
if (!context) return;
|
|
109
|
+
try {
|
|
110
|
+
const outcome = await context.apply(result, path);
|
|
111
|
+
if (outcome.acted) {
|
|
112
|
+
result.decision = outcome.decision;
|
|
113
|
+
if (outcome.composedBlobHash) result.composedBlobHash = outcome.composedBlobHash;
|
|
114
|
+
}
|
|
115
|
+
} catch {}
|
|
85
116
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Debug logger mirroring the worker's `console.warn`/`console.error` shadow +
|
|
119
|
+
* fail-open telemetry. Wired by `withCheckpoint` only when `config.debug` is
|
|
120
|
+
* set, so the default SDK posture stays silent.
|
|
121
|
+
*/
|
|
122
|
+
const consoleComposedPolicyLogger = {
|
|
123
|
+
shadowDivergence(info) {
|
|
124
|
+
console.warn("[checkpoint/composed-policy] shadow-divergence", info);
|
|
125
|
+
},
|
|
126
|
+
evaluationError(projectId, error) {
|
|
127
|
+
console.error(`[checkpoint/composed-policy] evaluation failed for ${projectId}; using structured decision:`, error);
|
|
128
|
+
}
|
|
96
129
|
};
|
|
97
130
|
|
|
131
|
+
//#endregion
|
|
98
132
|
exports.DEFAULT_DASHBOARD_URL = DEFAULT_DASHBOARD_URL;
|
|
99
133
|
exports.applyComposedPolicy = applyComposedPolicy;
|
|
100
134
|
exports.consoleComposedPolicyLogger = consoleComposedPolicyLogger;
|
|
101
135
|
exports.makeComposedPolicyContext = makeComposedPolicyContext;
|
|
102
|
-
exports.resolveTrustedDelegationRootsForRequest = resolveTrustedDelegationRootsForRequest;
|
|
136
|
+
exports.resolveTrustedDelegationRootsForRequest = resolveTrustedDelegationRootsForRequest;
|