@kya-os/checkpoint-nextjs 1.9.0 → 1.11.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.
Files changed (156) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/README.md +205 -31
  3. package/dist/adapt-BdQ9R7Iw.mjs +97 -0
  4. package/dist/adapt-BdQ9R7Iw.mjs.map +1 -0
  5. package/dist/adapt-CCSKGjVH.js +107 -0
  6. package/dist/api-client-JHOrRUA_.d.mts +222 -0
  7. package/dist/api-client-JHOrRUA_.d.mts.map +1 -0
  8. package/dist/api-client-JHOrRUA_.d.ts +222 -0
  9. package/dist/api-client-JHOrRUA_.d.ts.map +1 -0
  10. package/dist/api-client.d.mts +2 -213
  11. package/dist/api-client.d.ts +2 -213
  12. package/dist/api-client.js +221 -206
  13. package/dist/api-client.mjs +222 -202
  14. package/dist/api-client.mjs.map +1 -0
  15. package/dist/api-middleware-BWjokNis.d.mts +131 -0
  16. package/dist/api-middleware-BWjokNis.d.mts.map +1 -0
  17. package/dist/api-middleware-Bf3xmM9W.js +391 -0
  18. package/dist/api-middleware-C-ngFX_8.mjs +387 -0
  19. package/dist/api-middleware-C-ngFX_8.mjs.map +1 -0
  20. package/dist/api-middleware-DyLDqOYF.d.ts +131 -0
  21. package/dist/api-middleware-DyLDqOYF.d.ts.map +1 -0
  22. package/dist/api-middleware.d.mts +2 -166
  23. package/dist/api-middleware.d.ts +2 -166
  24. package/dist/api-middleware.js +3 -526
  25. package/dist/api-middleware.mjs +2 -521
  26. package/dist/cedar-wasm.d.mts +20 -0
  27. package/dist/cedar-wasm.d.mts.map +1 -0
  28. package/dist/cedar-wasm.d.ts +19 -0
  29. package/dist/cedar-wasm.d.ts.map +1 -0
  30. package/dist/cedar-wasm.js +24 -0
  31. package/dist/cedar-wasm.mjs +23 -0
  32. package/dist/cedar-wasm.mjs.map +1 -0
  33. package/dist/config-CPP1RV0f.d.mts +291 -0
  34. package/dist/config-CPP1RV0f.d.mts.map +1 -0
  35. package/dist/config-DVgOFxJs.d.ts +291 -0
  36. package/dist/config-DVgOFxJs.d.ts.map +1 -0
  37. package/dist/engine-wasm.d.mts +20 -0
  38. package/dist/engine-wasm.d.mts.map +1 -0
  39. package/dist/engine-wasm.d.ts +19 -0
  40. package/dist/engine-wasm.d.ts.map +1 -0
  41. package/dist/engine-wasm.js +24 -0
  42. package/dist/engine-wasm.mjs +23 -0
  43. package/dist/engine-wasm.mjs.map +1 -0
  44. package/dist/index-edge.d.mts +8 -0
  45. package/dist/index-edge.d.ts +8 -0
  46. package/dist/index-edge.js +14 -0
  47. package/dist/index-edge.mjs +7 -0
  48. package/dist/index.d.mts +8 -17
  49. package/dist/index.d.ts +8 -17
  50. package/dist/index.js +36 -1275
  51. package/dist/index.mjs +29 -1234
  52. package/dist/index.mjs.map +1 -0
  53. package/dist/middleware-bundler.d.mts +6 -12
  54. package/dist/middleware-bundler.d.mts.map +1 -0
  55. package/dist/middleware-bundler.d.ts +6 -12
  56. package/dist/middleware-bundler.d.ts.map +1 -0
  57. package/dist/middleware-bundler.js +12 -350
  58. package/dist/middleware-bundler.mjs +11 -347
  59. package/dist/middleware-bundler.mjs.map +1 -0
  60. package/dist/middleware-core-B0jf5_Hm.mjs +264 -0
  61. package/dist/middleware-core-B0jf5_Hm.mjs.map +1 -0
  62. package/dist/middleware-core-Bol44X9C.d.ts +17 -0
  63. package/dist/middleware-core-Bol44X9C.d.ts.map +1 -0
  64. package/dist/middleware-core-CMc-2QkU.js +274 -0
  65. package/dist/middleware-core-DycsbHUd.d.mts +17 -0
  66. package/dist/middleware-core-DycsbHUd.d.mts.map +1 -0
  67. package/dist/middleware-edge.d.mts +16 -14
  68. package/dist/middleware-edge.d.mts.map +1 -0
  69. package/dist/middleware-edge.d.ts +16 -14
  70. package/dist/middleware-edge.d.ts.map +1 -0
  71. package/dist/middleware-edge.js +94 -355
  72. package/dist/middleware-edge.mjs +90 -347
  73. package/dist/middleware-edge.mjs.map +1 -0
  74. package/dist/middleware-node-context-591KsiYg.js +39 -0
  75. package/dist/middleware-node-context-D_ZyUEcA.mjs +35 -0
  76. package/dist/middleware-node-context-D_ZyUEcA.mjs.map +1 -0
  77. package/dist/middleware-node.d.mts +10 -25
  78. package/dist/middleware-node.d.mts.map +1 -0
  79. package/dist/middleware-node.d.ts +10 -25
  80. package/dist/middleware-node.d.ts.map +1 -0
  81. package/dist/middleware-node.js +21 -351
  82. package/dist/middleware-node.mjs +19 -347
  83. package/dist/middleware-node.mjs.map +1 -0
  84. package/dist/posture-outcome-Ccujx_9V.d.mts +14 -0
  85. package/dist/posture-outcome-Ccujx_9V.d.mts.map +1 -0
  86. package/dist/posture-outcome-Ccujx_9V.d.ts +14 -0
  87. package/dist/posture-outcome-Ccujx_9V.d.ts.map +1 -0
  88. package/dist/posture-outcome-DQ4fdMfq.mjs +21 -0
  89. package/dist/posture-outcome-DQ4fdMfq.mjs.map +1 -0
  90. package/dist/posture-outcome-DddsJtL8.js +25 -0
  91. package/dist/public-api-CYsHrTQI.d.ts +5 -0
  92. package/dist/public-api-DkG7pRE0.d.mts +5 -0
  93. package/dist/rolldown-runtime-C24Yb2bl.js +33 -0
  94. package/dist/utils-Cnwg0VrY.mjs +88 -0
  95. package/dist/utils-Cnwg0VrY.mjs.map +1 -0
  96. package/dist/utils-dyFxqlFI.js +104 -0
  97. package/package.json +31 -66
  98. package/EDGE_RUNTIME_WASM_SETUP.md +0 -342
  99. package/bin/setup-edge-wasm.js +0 -513
  100. package/dist/adapt.d.mts +0 -39
  101. package/dist/adapt.d.ts +0 -39
  102. package/dist/adapt.js +0 -59
  103. package/dist/adapt.mjs +0 -57
  104. package/dist/composed-policy.d.mts +0 -115
  105. package/dist/composed-policy.d.ts +0 -115
  106. package/dist/composed-policy.js +0 -103
  107. package/dist/composed-policy.mjs +0 -97
  108. package/dist/config-CleTeeoW.d.mts +0 -233
  109. package/dist/config-XMOIkxFN.d.ts +0 -233
  110. package/dist/create-middleware.d.mts +0 -22
  111. package/dist/create-middleware.d.ts +0 -22
  112. package/dist/create-middleware.js +0 -34
  113. package/dist/create-middleware.mjs +0 -31
  114. package/dist/edge/index.d.mts +0 -112
  115. package/dist/edge/index.d.ts +0 -112
  116. package/dist/edge/index.js +0 -277
  117. package/dist/edge/index.mjs +0 -275
  118. package/dist/edge-runtime-loader.d.mts +0 -77
  119. package/dist/edge-runtime-loader.d.ts +0 -77
  120. package/dist/edge-runtime-loader.js +0 -242
  121. package/dist/edge-runtime-loader.mjs +0 -235
  122. package/dist/edge-wasm-middleware.d.mts +0 -62
  123. package/dist/edge-wasm-middleware.d.ts +0 -62
  124. package/dist/edge-wasm-middleware.js +0 -26
  125. package/dist/edge-wasm-middleware.mjs +0 -22
  126. package/dist/middleware.d.mts +0 -45
  127. package/dist/middleware.d.ts +0 -45
  128. package/dist/middleware.js +0 -19
  129. package/dist/middleware.mjs +0 -15
  130. package/dist/nodejs-wasm-loader.d.mts +0 -41
  131. package/dist/nodejs-wasm-loader.d.ts +0 -41
  132. package/dist/nodejs-wasm-loader.js +0 -36
  133. package/dist/nodejs-wasm-loader.mjs +0 -30
  134. package/dist/policy.d.mts +0 -162
  135. package/dist/policy.d.ts +0 -162
  136. package/dist/policy.js +0 -198
  137. package/dist/policy.mjs +0 -174
  138. package/dist/session-tracker.d.mts +0 -55
  139. package/dist/session-tracker.d.ts +0 -55
  140. package/dist/session-tracker.js +0 -172
  141. package/dist/session-tracker.mjs +0 -169
  142. package/dist/translate.d.mts +0 -63
  143. package/dist/translate.d.ts +0 -63
  144. package/dist/translate.js +0 -44
  145. package/dist/translate.mjs +0 -42
  146. package/dist/types-Chgi5TFC.d.mts +0 -105
  147. package/dist/types-Chgi5TFC.d.ts +0 -105
  148. package/dist/wasm-setup.d.mts +0 -46
  149. package/dist/wasm-setup.d.ts +0 -46
  150. package/dist/wasm-setup.js +0 -122
  151. package/dist/wasm-setup.mjs +0 -118
  152. package/wasm/agentshield_wasm.d.ts +0 -479
  153. package/wasm/agentshield_wasm.js +0 -1536
  154. package/wasm/agentshield_wasm_bg.wasm +0 -0
  155. package/wasm/package.json +0 -30
  156. package/wasm.d.ts +0 -21
package/dist/adapt.mjs DELETED
@@ -1,57 +0,0 @@
1
- import { NextResponse } from 'next/server';
2
- import { acceptsHtml, encodeVerdictCookie, classifyResponseShape, BLOCKED_PATH, VERDICT_COOKIE_NAME } from '@kya-os/checkpoint-shared';
3
-
4
- // src/adapt.ts
5
- function adaptToNextResponse(rendered, req) {
6
- const clientAcceptsHtml = acceptsHtml(req.headers);
7
- const verdictCookie = encodeVerdictCookie(rendered);
8
- const shape = classifyResponseShape(rendered, clientAcceptsHtml);
9
- switch (shape) {
10
- case "pass-through": {
11
- const res = NextResponse.next();
12
- applyHeaders(res, rendered);
13
- setVerdictCookie(res, verdictCookie);
14
- return res;
15
- }
16
- case "redirect": {
17
- const target = new URL(rendered.headers.Location);
18
- const res = NextResponse.redirect(target);
19
- applyHeaders(res, rendered);
20
- setVerdictCookie(res, verdictCookie);
21
- return res;
22
- }
23
- case "html-block": {
24
- const blockedUrl = new URL(BLOCKED_PATH, req.url);
25
- const res = NextResponse.rewrite(blockedUrl, { status: 200 });
26
- applyHeaders(res, rendered);
27
- setVerdictCookie(res, verdictCookie);
28
- return res;
29
- }
30
- case "json-block": {
31
- const body = rendered.body ?? {};
32
- const res = NextResponse.json(body, { status: rendered.status });
33
- applyHeaders(res, rendered);
34
- setVerdictCookie(res, verdictCookie);
35
- return res;
36
- }
37
- }
38
- }
39
- function setVerdictCookie(res, value) {
40
- res.cookies.set({
41
- name: VERDICT_COOKIE_NAME,
42
- value,
43
- path: "/",
44
- sameSite: "lax",
45
- httpOnly: false
46
- });
47
- }
48
- function applyHeaders(res, rendered) {
49
- for (const [key, value] of Object.entries(rendered.headers)) {
50
- res.headers.set(key, value);
51
- }
52
- for (const [key, value] of rendered.headerEntries ?? []) {
53
- res.headers.append(key, value);
54
- }
55
- }
56
-
57
- export { adaptToNextResponse };
@@ -1,115 +0,0 @@
1
- import { ComposedPolicyCompile } from '@kya-os/checkpoint-wasm-runtime/composed-policy';
2
- import { Decision, VerifyResult } from '@kya-os/checkpoint-wasm-runtime/engine';
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,115 +0,0 @@
1
- import { ComposedPolicyCompile } from '@kya-os/checkpoint-wasm-runtime/composed-policy';
2
- import { Decision, VerifyResult } from '@kya-os/checkpoint-wasm-runtime/engine';
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,103 +0,0 @@
1
- 'use strict';
2
-
3
- var composedPolicy = require('@kya-os/checkpoint-wasm-runtime/composed-policy');
4
- var checkpointShared = require('@kya-os/checkpoint-shared');
5
-
6
- // src/composed-policy.ts
7
- var DEFAULT_DASHBOARD_URL = "https://kya.vouched.id";
8
- var NOOP_LOGGER = {
9
- shadowDivergence: () => {
10
- },
11
- evaluationError: () => {
12
- }
13
- };
14
- function makeComposedPolicyContext(opts) {
15
- const { projectId, fetcher } = opts;
16
- const cache = composedPolicy.makeComposedPolicyCache({ compile: opts.compile, cacheMax: opts.cacheMax });
17
- const logger = opts.logger ?? NOOP_LOGGER;
18
- return {
19
- async apply(result, path) {
20
- const structured = { decision: result.decision, acted: false };
21
- if (composedPolicy.isCredentialVerificationBlock(result.decision)) return structured;
22
- const policy = await fetcher.getPolicy(projectId);
23
- const outcome = await composedPolicy.evaluateComposedPolicy({
24
- cache,
25
- projectId,
26
- flags: {
27
- policyLanguage: policy.policyLanguage,
28
- policySourceText: policy.policySourceText,
29
- engineEnforcementEnabled: policy.engineEnforcementEnabled,
30
- enabled: policy.enabled
31
- },
32
- authorizeInput: composedPolicy.verifyResultToAuthorizeInput(result, { tenantId: projectId, path }),
33
- baselineDecisionKind: result.decision.kind
34
- });
35
- if ((outcome.status === "acting" || outcome.status === "shadow") && outcome.diverged) {
36
- logger.shadowDivergence({
37
- projectId,
38
- path,
39
- engineDecision: outcome.engineDecision.kind,
40
- structuredDecision: result.decision.kind,
41
- detectionClass: result.detectionDetail.detectionClass.type,
42
- verificationMethod: result.detectionDetail.verificationMethod,
43
- confidence: result.detectionDetail.confidence,
44
- agentName: result.detectionDetail.detectedAgent?.name
45
- });
46
- }
47
- if (outcome.status === "error") {
48
- logger.evaluationError(projectId, outcome.error);
49
- return structured;
50
- }
51
- if (outcome.status === "acting") {
52
- return {
53
- decision: outcome.engineDecision,
54
- acted: true,
55
- // Echo the SSOT revision pin with the decision it produced (#3246
56
- // PR5). Conditional spread: absent upstream stays absent here.
57
- ...policy.policySourceHash ? { composedBlobHash: policy.policySourceHash } : {}
58
- };
59
- }
60
- return structured;
61
- },
62
- async trustedDelegationRoots() {
63
- const policy = await fetcher.getPolicy(projectId);
64
- return policy.trustedDelegationRoots ?? [];
65
- }
66
- };
67
- }
68
- async function resolveTrustedDelegationRootsForRequest(resolver, headers) {
69
- if (!resolver) return void 0;
70
- if (!checkpointShared.requestCarriesDelegationProof(headers)) return void 0;
71
- const roots = await resolver();
72
- return roots.length > 0 ? roots : void 0;
73
- }
74
- async function applyComposedPolicy(context, result, path) {
75
- if (!context) return;
76
- try {
77
- const outcome = await context.apply(result, path);
78
- if (outcome.acted) {
79
- result.decision = outcome.decision;
80
- if (outcome.composedBlobHash) {
81
- result.composedBlobHash = outcome.composedBlobHash;
82
- }
83
- }
84
- } catch {
85
- }
86
- }
87
- var consoleComposedPolicyLogger = {
88
- shadowDivergence(info) {
89
- console.warn("[checkpoint/composed-policy] shadow-divergence", info);
90
- },
91
- evaluationError(projectId, error) {
92
- console.error(
93
- `[checkpoint/composed-policy] evaluation failed for ${projectId}; using structured decision:`,
94
- error
95
- );
96
- }
97
- };
98
-
99
- exports.DEFAULT_DASHBOARD_URL = DEFAULT_DASHBOARD_URL;
100
- exports.applyComposedPolicy = applyComposedPolicy;
101
- exports.consoleComposedPolicyLogger = consoleComposedPolicyLogger;
102
- exports.makeComposedPolicyContext = makeComposedPolicyContext;
103
- exports.resolveTrustedDelegationRootsForRequest = resolveTrustedDelegationRootsForRequest;
@@ -1,97 +0,0 @@
1
- import { makeComposedPolicyCache, isCredentialVerificationBlock, evaluateComposedPolicy, verifyResultToAuthorizeInput } from '@kya-os/checkpoint-wasm-runtime/composed-policy';
2
- import { requestCarriesDelegationProof } from '@kya-os/checkpoint-shared';
3
-
4
- // src/composed-policy.ts
5
- var DEFAULT_DASHBOARD_URL = "https://kya.vouched.id";
6
- var NOOP_LOGGER = {
7
- shadowDivergence: () => {
8
- },
9
- evaluationError: () => {
10
- }
11
- };
12
- function makeComposedPolicyContext(opts) {
13
- const { projectId, fetcher } = opts;
14
- const cache = makeComposedPolicyCache({ compile: opts.compile, cacheMax: opts.cacheMax });
15
- const logger = opts.logger ?? NOOP_LOGGER;
16
- return {
17
- async apply(result, path) {
18
- const structured = { decision: result.decision, acted: false };
19
- if (isCredentialVerificationBlock(result.decision)) return structured;
20
- const policy = await fetcher.getPolicy(projectId);
21
- const outcome = await evaluateComposedPolicy({
22
- cache,
23
- projectId,
24
- flags: {
25
- policyLanguage: policy.policyLanguage,
26
- policySourceText: policy.policySourceText,
27
- engineEnforcementEnabled: policy.engineEnforcementEnabled,
28
- enabled: policy.enabled
29
- },
30
- authorizeInput: verifyResultToAuthorizeInput(result, { tenantId: projectId, path }),
31
- baselineDecisionKind: result.decision.kind
32
- });
33
- if ((outcome.status === "acting" || outcome.status === "shadow") && outcome.diverged) {
34
- logger.shadowDivergence({
35
- projectId,
36
- path,
37
- engineDecision: outcome.engineDecision.kind,
38
- structuredDecision: result.decision.kind,
39
- detectionClass: result.detectionDetail.detectionClass.type,
40
- verificationMethod: result.detectionDetail.verificationMethod,
41
- confidence: result.detectionDetail.confidence,
42
- agentName: result.detectionDetail.detectedAgent?.name
43
- });
44
- }
45
- if (outcome.status === "error") {
46
- logger.evaluationError(projectId, outcome.error);
47
- return structured;
48
- }
49
- if (outcome.status === "acting") {
50
- return {
51
- decision: outcome.engineDecision,
52
- acted: true,
53
- // Echo the SSOT revision pin with the decision it produced (#3246
54
- // PR5). Conditional spread: absent upstream stays absent here.
55
- ...policy.policySourceHash ? { composedBlobHash: policy.policySourceHash } : {}
56
- };
57
- }
58
- return structured;
59
- },
60
- async trustedDelegationRoots() {
61
- const policy = await fetcher.getPolicy(projectId);
62
- return policy.trustedDelegationRoots ?? [];
63
- }
64
- };
65
- }
66
- async function resolveTrustedDelegationRootsForRequest(resolver, headers) {
67
- if (!resolver) return void 0;
68
- if (!requestCarriesDelegationProof(headers)) return void 0;
69
- const roots = await resolver();
70
- return roots.length > 0 ? roots : void 0;
71
- }
72
- async function applyComposedPolicy(context, result, path) {
73
- if (!context) return;
74
- try {
75
- const outcome = await context.apply(result, path);
76
- if (outcome.acted) {
77
- result.decision = outcome.decision;
78
- if (outcome.composedBlobHash) {
79
- result.composedBlobHash = outcome.composedBlobHash;
80
- }
81
- }
82
- } catch {
83
- }
84
- }
85
- var consoleComposedPolicyLogger = {
86
- shadowDivergence(info) {
87
- console.warn("[checkpoint/composed-policy] shadow-divergence", info);
88
- },
89
- evaluationError(projectId, error) {
90
- console.error(
91
- `[checkpoint/composed-policy] evaluation failed for ${projectId}; using structured decision:`,
92
- error
93
- );
94
- }
95
- };
96
-
97
- export { DEFAULT_DASHBOARD_URL, applyComposedPolicy, consoleComposedPolicyLogger, makeComposedPolicyContext, resolveTrustedDelegationRootsForRequest };