@kya-os/checkpoint-nextjs 1.10.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 (210) hide show
  1. package/CHANGELOG.md +245 -0
  2. package/README.md +205 -31
  3. package/dist/{adapt.mjs → adapt-BdQ9R7Iw.mjs} +15 -4
  4. package/dist/adapt-BdQ9R7Iw.mjs.map +1 -0
  5. package/dist/{adapt.js → adapt-CCSKGjVH.js} +34 -13
  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 -204
  11. package/dist/api-client.d.ts +2 -204
  12. package/dist/api-client.js +19 -18
  13. package/dist/api-client.mjs +20 -16
  14. package/dist/api-client.mjs.map +1 -1
  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-CDSh3TSE.js → api-middleware-Bf3xmM9W.js} +75 -63
  18. package/dist/{api-middleware-CMDRoQik.mjs → api-middleware-C-ngFX_8.mjs} +68 -38
  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 -152
  23. package/dist/api-middleware.d.ts +2 -152
  24. package/dist/api-middleware.js +1 -5
  25. package/dist/api-middleware.mjs +2 -3
  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-Doe0Tn53.d.mts → config-CPP1RV0f.d.mts} +65 -29
  34. package/dist/config-CPP1RV0f.d.mts.map +1 -0
  35. package/dist/{config-CbAg2mze.d.ts → config-DVgOFxJs.d.ts} +66 -30
  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 -10
  49. package/dist/index.d.ts +8 -10
  50. package/dist/index.js +20 -49
  51. package/dist/index.mjs +21 -8
  52. package/dist/index.mjs.map +1 -1
  53. package/dist/middleware-bundler.d.mts +1 -1
  54. package/dist/middleware-bundler.d.mts.map +1 -1
  55. package/dist/middleware-bundler.d.ts +1 -1
  56. package/dist/middleware-bundler.d.ts.map +1 -1
  57. package/dist/middleware-bundler.js +4 -4
  58. package/dist/middleware-bundler.mjs +4 -4
  59. package/dist/middleware-bundler.mjs.map +1 -1
  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 +11 -3
  68. package/dist/middleware-edge.d.mts.map +1 -1
  69. package/dist/middleware-edge.d.ts +11 -3
  70. package/dist/middleware-edge.d.ts.map +1 -1
  71. package/dist/middleware-edge.js +77 -24
  72. package/dist/middleware-edge.mjs +74 -23
  73. package/dist/middleware-edge.mjs.map +1 -1
  74. package/dist/{middleware-node-context-rgnc7UNR.js → middleware-node-context-591KsiYg.js} +8 -7
  75. package/dist/{middleware-node-context-BqPbf-fI.mjs → middleware-node-context-D_ZyUEcA.mjs} +6 -5
  76. package/dist/middleware-node-context-D_ZyUEcA.mjs.map +1 -0
  77. package/dist/middleware-node.d.mts +12 -3
  78. package/dist/middleware-node.d.mts.map +1 -0
  79. package/dist/middleware-node.d.ts +12 -3
  80. package/dist/middleware-node.d.ts.map +1 -0
  81. package/dist/middleware-node.js +13 -5
  82. package/dist/middleware-node.mjs +13 -5
  83. package/dist/middleware-node.mjs.map +1 -1
  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 +27 -62
  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 -11
  101. package/dist/adapt.d.mts.map +0 -1
  102. package/dist/adapt.d.ts +0 -11
  103. package/dist/adapt.d.ts.map +0 -1
  104. package/dist/adapt.mjs.map +0 -1
  105. package/dist/api-client.d.mts.map +0 -1
  106. package/dist/api-client.d.ts.map +0 -1
  107. package/dist/api-middleware-CMDRoQik.mjs.map +0 -1
  108. package/dist/api-middleware.d.mts.map +0 -1
  109. package/dist/api-middleware.d.ts.map +0 -1
  110. package/dist/composed-policy-BCaNiVHv.d.mts +0 -98
  111. package/dist/composed-policy-BCaNiVHv.d.mts.map +0 -1
  112. package/dist/composed-policy-zzJYNFTb.d.ts +0 -98
  113. package/dist/composed-policy-zzJYNFTb.d.ts.map +0 -1
  114. package/dist/composed-policy.d.mts +0 -2
  115. package/dist/composed-policy.d.ts +0 -2
  116. package/dist/composed-policy.js +0 -136
  117. package/dist/composed-policy.mjs +0 -132
  118. package/dist/composed-policy.mjs.map +0 -1
  119. package/dist/config-CbAg2mze.d.ts.map +0 -1
  120. package/dist/config-Doe0Tn53.d.mts.map +0 -1
  121. package/dist/create-middleware.d.mts +0 -11
  122. package/dist/create-middleware.d.mts.map +0 -1
  123. package/dist/create-middleware.d.ts +0 -11
  124. package/dist/create-middleware.d.ts.map +0 -1
  125. package/dist/create-middleware.js +0 -39
  126. package/dist/create-middleware.mjs +0 -38
  127. package/dist/create-middleware.mjs.map +0 -1
  128. package/dist/edge/index.d.mts +0 -88
  129. package/dist/edge/index.d.mts.map +0 -1
  130. package/dist/edge/index.d.ts +0 -88
  131. package/dist/edge/index.d.ts.map +0 -1
  132. package/dist/edge/index.js +0 -362
  133. package/dist/edge/index.mjs +0 -362
  134. package/dist/edge/index.mjs.map +0 -1
  135. package/dist/edge-runtime-loader.d.mts +0 -49
  136. package/dist/edge-runtime-loader.d.mts.map +0 -1
  137. package/dist/edge-runtime-loader.d.ts +0 -49
  138. package/dist/edge-runtime-loader.d.ts.map +0 -1
  139. package/dist/edge-runtime-loader.js +0 -297
  140. package/dist/edge-runtime-loader.mjs +0 -292
  141. package/dist/edge-runtime-loader.mjs.map +0 -1
  142. package/dist/edge-wasm-middleware.d.mts +0 -43
  143. package/dist/edge-wasm-middleware.d.mts.map +0 -1
  144. package/dist/edge-wasm-middleware.d.ts +0 -43
  145. package/dist/edge-wasm-middleware.d.ts.map +0 -1
  146. package/dist/edge-wasm-middleware.js +0 -37
  147. package/dist/edge-wasm-middleware.mjs +0 -35
  148. package/dist/edge-wasm-middleware.mjs.map +0 -1
  149. package/dist/middleware-core-BYQP9FND.mjs +0 -165
  150. package/dist/middleware-core-BYQP9FND.mjs.map +0 -1
  151. package/dist/middleware-core-D6TijE6P.js +0 -175
  152. package/dist/middleware-node-CE4GevYs.d.ts +0 -20
  153. package/dist/middleware-node-CE4GevYs.d.ts.map +0 -1
  154. package/dist/middleware-node-DtyOuPta.d.mts +0 -20
  155. package/dist/middleware-node-DtyOuPta.d.mts.map +0 -1
  156. package/dist/middleware-node-context-BqPbf-fI.mjs.map +0 -1
  157. package/dist/middleware.d.mts +0 -25
  158. package/dist/middleware.d.mts.map +0 -1
  159. package/dist/middleware.d.ts +0 -25
  160. package/dist/middleware.d.ts.map +0 -1
  161. package/dist/middleware.js +0 -53
  162. package/dist/middleware.mjs +0 -51
  163. package/dist/middleware.mjs.map +0 -1
  164. package/dist/nodejs-wasm-loader.d.mts +0 -42
  165. package/dist/nodejs-wasm-loader.d.mts.map +0 -1
  166. package/dist/nodejs-wasm-loader.d.ts +0 -42
  167. package/dist/nodejs-wasm-loader.d.ts.map +0 -1
  168. package/dist/nodejs-wasm-loader.js +0 -70
  169. package/dist/nodejs-wasm-loader.mjs +0 -66
  170. package/dist/nodejs-wasm-loader.mjs.map +0 -1
  171. package/dist/policy.d.mts +0 -138
  172. package/dist/policy.d.mts.map +0 -1
  173. package/dist/policy.d.ts +0 -138
  174. package/dist/policy.d.ts.map +0 -1
  175. package/dist/policy.js +0 -236
  176. package/dist/policy.mjs +0 -205
  177. package/dist/policy.mjs.map +0 -1
  178. package/dist/session-tracker.d.mts +0 -50
  179. package/dist/session-tracker.d.mts.map +0 -1
  180. package/dist/session-tracker.d.ts +0 -50
  181. package/dist/session-tracker.d.ts.map +0 -1
  182. package/dist/session-tracker.js +0 -148
  183. package/dist/session-tracker.mjs +0 -147
  184. package/dist/session-tracker.mjs.map +0 -1
  185. package/dist/translate.d.mts +0 -48
  186. package/dist/translate.d.mts.map +0 -1
  187. package/dist/translate.d.ts +0 -48
  188. package/dist/translate.d.ts.map +0 -1
  189. package/dist/translate.js +0 -79
  190. package/dist/translate.mjs +0 -79
  191. package/dist/translate.mjs.map +0 -1
  192. package/dist/types-C0SkqLMM.d.mts +0 -102
  193. package/dist/types-C0SkqLMM.d.mts.map +0 -1
  194. package/dist/types-C7DNSCTO.d.ts +0 -102
  195. package/dist/types-C7DNSCTO.d.ts.map +0 -1
  196. package/dist/utils-Cj4XNhIY.mjs +0 -35
  197. package/dist/utils-Cj4XNhIY.mjs.map +0 -1
  198. package/dist/utils-DAisnYnI.js +0 -45
  199. package/dist/wasm-setup.d.mts +0 -47
  200. package/dist/wasm-setup.d.mts.map +0 -1
  201. package/dist/wasm-setup.d.ts +0 -47
  202. package/dist/wasm-setup.d.ts.map +0 -1
  203. package/dist/wasm-setup.js +0 -91
  204. package/dist/wasm-setup.mjs +0 -95
  205. package/dist/wasm-setup.mjs.map +0 -1
  206. package/wasm/agentshield_wasm.d.ts +0 -479
  207. package/wasm/agentshield_wasm.js +0 -1536
  208. package/wasm/agentshield_wasm_bg.wasm +0 -0
  209. package/wasm/package.json +0 -30
  210. package/wasm.d.ts +0 -21
@@ -1,98 +0,0 @@
1
- import { ComposedPolicyCompile } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
2
- import { PolicyFetcher } from "@kya-os/checkpoint-shared";
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-BCaNiVHv.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"composed-policy-BCaNiVHv.d.mts","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,98 +0,0 @@
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
@@ -1 +0,0 @@
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,2 +0,0 @@
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,2 +0,0 @@
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 };
@@ -1,136 +0,0 @@
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");
4
-
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: () => {}
28
- };
29
- function makeComposedPolicyContext(opts) {
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
- };
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
- */
93
- async function resolveTrustedDelegationRootsForRequest(resolver, headers) {
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;
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
- */
107
- async function applyComposedPolicy(context, result, path) {
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 {}
116
- }
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
- }
129
- };
130
-
131
- //#endregion
132
- exports.DEFAULT_DASHBOARD_URL = DEFAULT_DASHBOARD_URL;
133
- exports.applyComposedPolicy = applyComposedPolicy;
134
- exports.consoleComposedPolicyLogger = consoleComposedPolicyLogger;
135
- exports.makeComposedPolicyContext = makeComposedPolicyContext;
136
- exports.resolveTrustedDelegationRootsForRequest = resolveTrustedDelegationRootsForRequest;
@@ -1,132 +0,0 @@
1
- import { evaluateComposedPolicy, isCredentialVerificationBlock, makeComposedPolicyCache, verifyResultToAuthorizeInput } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
2
- import { requestCarriesDelegationProof } from "@kya-os/checkpoint-shared";
3
-
4
- //#region src/composed-policy.ts
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
- /** Dashboard the composed-policy fetch defaults to when no base URL is set. */
23
- const DEFAULT_DASHBOARD_URL = "https://kya.vouched.id";
24
- const NOOP_LOGGER = {
25
- shadowDivergence: () => {},
26
- evaluationError: () => {}
27
- };
28
- function makeComposedPolicyContext(opts) {
29
- const { projectId, fetcher } = opts;
30
- const cache = makeComposedPolicyCache({
31
- compile: opts.compile,
32
- cacheMax: opts.cacheMax
33
- });
34
- const logger = opts.logger ?? NOOP_LOGGER;
35
- return {
36
- async apply(result, path) {
37
- const structured = {
38
- decision: result.decision,
39
- acted: false
40
- };
41
- if (isCredentialVerificationBlock(result.decision)) return structured;
42
- const policy = await fetcher.getPolicy(projectId);
43
- const outcome = await evaluateComposedPolicy({
44
- cache,
45
- projectId,
46
- flags: {
47
- policyLanguage: policy.policyLanguage,
48
- policySourceText: policy.policySourceText,
49
- engineEnforcementEnabled: policy.engineEnforcementEnabled,
50
- enabled: policy.enabled
51
- },
52
- authorizeInput: verifyResultToAuthorizeInput(result, {
53
- tenantId: projectId,
54
- path
55
- }),
56
- baselineDecisionKind: result.decision.kind
57
- });
58
- if ((outcome.status === "acting" || outcome.status === "shadow") && outcome.diverged) logger.shadowDivergence({
59
- projectId,
60
- path,
61
- engineDecision: outcome.engineDecision.kind,
62
- structuredDecision: result.decision.kind,
63
- detectionClass: result.detectionDetail.detectionClass.type,
64
- verificationMethod: result.detectionDetail.verificationMethod,
65
- confidence: result.detectionDetail.confidence,
66
- agentName: result.detectionDetail.detectedAgent?.name
67
- });
68
- if (outcome.status === "error") {
69
- logger.evaluationError(projectId, outcome.error);
70
- return structured;
71
- }
72
- if (outcome.status === "acting") return {
73
- decision: outcome.engineDecision,
74
- acted: true,
75
- ...policy.policySourceHash ? { composedBlobHash: policy.policySourceHash } : {}
76
- };
77
- return structured;
78
- },
79
- async trustedDelegationRoots() {
80
- return (await fetcher.getPolicy(projectId)).trustedDelegationRoots ?? [];
81
- }
82
- };
83
- }
84
- /**
85
- * Resolve the org trusted-delegation roots to inject into the engine for THIS
86
- * request (P2 / DR-1). Returns `undefined` — leaving `VerifyRequestOpts`
87
- * byte-identical to pre-P2 — unless (a) a resolver is configured and (b) the
88
- * request actually carries a delegation-proof header (so the human /
89
- * no-delegation hot path never pays the early policy fetch). Shared by the Node
90
- * and Edge middleware entries.
91
- */
92
- async function resolveTrustedDelegationRootsForRequest(resolver, headers) {
93
- if (!resolver) return void 0;
94
- if (!requestCarriesDelegationProof(headers)) return void 0;
95
- const roots = await resolver();
96
- return roots.length > 0 ? roots : void 0;
97
- }
98
- /**
99
- * The per-request seam shared by both middleware entries. Evaluates the composed
100
- * policy and swaps `result.decision` IN PLACE when the engine acts — so the
101
- * swap happens BEFORE the detection reporter fires and before
102
- * `renderDecisionAsResponse`, exactly like the Express runtime (the reporter
103
- * records the enforced decision). Fail-OPEN: any fault keeps the structured
104
- * decision; a policy fault never breaks the response.
105
- */
106
- async function applyComposedPolicy(context, result, path) {
107
- if (!context) return;
108
- try {
109
- const outcome = await context.apply(result, path);
110
- if (outcome.acted) {
111
- result.decision = outcome.decision;
112
- if (outcome.composedBlobHash) result.composedBlobHash = outcome.composedBlobHash;
113
- }
114
- } catch {}
115
- }
116
- /**
117
- * Debug logger mirroring the worker's `console.warn`/`console.error` shadow +
118
- * fail-open telemetry. Wired by `withCheckpoint` only when `config.debug` is
119
- * set, so the default SDK posture stays silent.
120
- */
121
- const consoleComposedPolicyLogger = {
122
- shadowDivergence(info) {
123
- console.warn("[checkpoint/composed-policy] shadow-divergence", info);
124
- },
125
- evaluationError(projectId, error) {
126
- console.error(`[checkpoint/composed-policy] evaluation failed for ${projectId}; using structured decision:`, error);
127
- }
128
- };
129
-
130
- //#endregion
131
- export { DEFAULT_DASHBOARD_URL, applyComposedPolicy, consoleComposedPolicyLogger, makeComposedPolicyContext, resolveTrustedDelegationRootsForRequest };
132
- //# sourceMappingURL=composed-policy.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"composed-policy.mjs","names":[],"sources":["../src/composed-policy.ts"],"sourcesContent":["/**\n * Composed-policy (kya-os-engine) wiring for the Next.js middleware.\n *\n * A THIN layer on top of the shared core\n * (`@kya-os/checkpoint-wasm-runtime/composed-policy`): the core owns all the\n * logic (empty-Cedar deny-all guard, compile-once LRU cache, act-gate,\n * divergence, and the `verifyResultToAuthorizeInput` parity projection), so this\n * module only fetches the project's `PolicyConfig`, drives the core once per\n * request, maps the tagged outcome to a decision-swap signal, and logs\n * (debug-gated). Runtime-neutral — the caller injects the compiler:\n * - Node: `(language, source) => createPolicyEvaluator(source)` (`./policy`)\n * - Edge: `(language, source) => evaluatePolicy(language, source)` (`./policy-edge`)\n *\n * This is the SDK sibling of `@kya-os/checkpoint-express`'s composed-policy\n * wiring; both consume the same core so the DNS Gateway, Express, and Next.js\n * produce the same decision for the same composed Cedar bundle.\n */\n\nimport {\n evaluateComposedPolicy,\n isCredentialVerificationBlock,\n makeComposedPolicyCache,\n verifyResultToAuthorizeInput,\n type ComposedPolicyCompile,\n} from '@kya-os/checkpoint-wasm-runtime/composed-policy';\nimport type { Decision, VerifyResult } from '@kya-os/checkpoint-wasm-runtime/engine';\nimport { requestCarriesDelegationProof, type PolicyFetcher } from '@kya-os/checkpoint-shared';\n\n/** Dashboard the composed-policy fetch defaults to when no base URL is set. */\nexport const DEFAULT_DASHBOARD_URL = 'https://kya.vouched.id';\n\n/**\n * Telemetry sink. The shadow-divergence signal is the go/no-go instrument for\n * flipping a project to ENFORCE. Defaults to a no-op so the SDK never logs\n * unprompted — `withCheckpoint({ debug: true })` wires the console logger.\n */\nexport interface ComposedPolicyLogger {\n shadowDivergence(info: ShadowDivergenceInfo): void;\n evaluationError(projectId: string, error: unknown): void;\n}\n\nexport interface ShadowDivergenceInfo {\n projectId: string;\n path?: string;\n engineDecision: Decision['kind'];\n structuredDecision: Decision['kind'];\n detectionClass: string;\n verificationMethod?: string;\n confidence: number;\n agentName?: string;\n}\n\nconst NOOP_LOGGER: ComposedPolicyLogger = {\n shadowDivergence: () => {},\n evaluationError: () => {},\n};\n\n/** Result of one composed-policy evaluation: the decision to enforce + whether it replaced the baseline. */\nexport interface ComposedPolicyApplyResult {\n decision: Decision;\n acted: boolean;\n /**\n * SSOT-served revision pin (sha256 of the evaluated bundle, byte-identical\n * to `policy_revisions.composed_blob_hash`) — set ONLY when `acted`, echoed\n * from `PolicyConfig.policySourceHash` (#3246 PR5). Absent on structured\n * decisions and when the dashboard predates the field.\n */\n composedBlobHash?: string;\n}\n\nexport interface ComposedPolicyContext {\n /**\n * Evaluate the project's composed policy for one request. Reads\n * `result.decision` as the structured baseline for the divergence comparison;\n * the caller applies `acted ? decision` afterwards. Never throws.\n */\n apply(result: VerifyResult, path: string | undefined): Promise<ComposedPolicyApplyResult>;\n /**\n * Resolve the org's trusted Layer-2 delegation root DIDs from the project's\n * policy payload (P2 / DR-1). The middleware forwards these into the engine's\n * `ContextSpec.trustedDelegationRoots` on delegation requests. Optional so an\n * injected `composedPolicyEnforcer` (advanced/testing) need not implement it —\n * absence ⇒ no roots ⇒ the engine's open default. Never throws (a fetch fault\n * resolves to `[]`).\n */\n trustedDelegationRoots?(): Promise<string[]>;\n}\n\nexport interface MakeComposedPolicyContextOptions {\n projectId: string;\n /** Fetches the project's `PolicyConfig` (carries the composed-policy fields). */\n fetcher: PolicyFetcher;\n /** Target compiler — Node `createPolicyEvaluator`-backed or edge `evaluatePolicy`. */\n compile: ComposedPolicyCompile;\n logger?: ComposedPolicyLogger;\n cacheMax?: number;\n}\n\nexport function makeComposedPolicyContext(\n opts: MakeComposedPolicyContextOptions\n): ComposedPolicyContext {\n const { projectId, fetcher } = opts;\n const cache = makeComposedPolicyCache({ compile: opts.compile, cacheMax: opts.cacheMax });\n const logger = opts.logger ?? NOOP_LOGGER;\n\n return {\n async apply(result, path): Promise<ComposedPolicyApplyResult> {\n const structured: ComposedPolicyApplyResult = { decision: result.decision, acted: false };\n if (isCredentialVerificationBlock(result.decision)) return structured;\n\n // PolicyFetcher.getPolicy is itself fail-open (returns DEFAULT_POLICY on a\n // fetch/parse fault → no composed fields → the core's no-policy branch),\n // so this resolves to the structured decision on a dashboard outage.\n const policy = await fetcher.getPolicy(projectId);\n\n const outcome = await evaluateComposedPolicy({\n cache,\n projectId,\n flags: {\n policyLanguage: policy.policyLanguage,\n policySourceText: policy.policySourceText,\n engineEnforcementEnabled: policy.engineEnforcementEnabled,\n enabled: policy.enabled,\n },\n authorizeInput: verifyResultToAuthorizeInput(result, { tenantId: projectId, path }),\n baselineDecisionKind: result.decision.kind,\n });\n\n // Divergence telemetry (acting OR shadow): the engine decided differently\n // than the structured baseline. `result.decision` is still the baseline\n // here — the caller swaps it only after this returns.\n if ((outcome.status === 'acting' || outcome.status === 'shadow') && outcome.diverged) {\n logger.shadowDivergence({\n projectId,\n path,\n engineDecision: outcome.engineDecision.kind,\n structuredDecision: result.decision.kind,\n detectionClass: result.detectionDetail.detectionClass.type,\n verificationMethod: result.detectionDetail.verificationMethod,\n confidence: result.detectionDetail.confidence,\n agentName: result.detectionDetail.detectedAgent?.name,\n });\n }\n\n if (outcome.status === 'error') {\n logger.evaluationError(projectId, outcome.error);\n return structured;\n }\n if (outcome.status === 'acting') {\n return {\n decision: outcome.engineDecision,\n acted: true,\n // Echo the SSOT revision pin with the decision it produced (#3246\n // PR5). Conditional spread: absent upstream stays absent here.\n ...(policy.policySourceHash ? { composedBlobHash: policy.policySourceHash } : {}),\n };\n }\n // 'shadow' | 'no-policy' → structured decision stands.\n return structured;\n },\n\n async trustedDelegationRoots(): Promise<string[]> {\n // Reuse the SAME (cached) PolicyFetcher the `apply` path uses, so the\n // early root-resolution and the later composed-policy fetch coalesce into\n // one network call. `getPolicy` is fail-open (DEFAULT_POLICY → no field),\n // so a dashboard outage resolves to `[]` (root pinning disabled).\n const policy = await fetcher.getPolicy(projectId);\n return policy.trustedDelegationRoots ?? [];\n },\n };\n}\n\n/**\n * Resolves the org's trusted delegation roots (empty when none). Built per\n * middleware factory from whatever source can supply them — the composed\n * context's accessor, or (when no context exists, e.g. Edge without\n * `cedarWasmModule`) a `projectId`-only policy fetch.\n */\nexport type TrustedDelegationRootsResolver = () => Promise<string[]>;\n\n/**\n * Resolve the org trusted-delegation roots to inject into the engine for THIS\n * request (P2 / DR-1). Returns `undefined` — leaving `VerifyRequestOpts`\n * byte-identical to pre-P2 — unless (a) a resolver is configured and (b) the\n * request actually carries a delegation-proof header (so the human /\n * no-delegation hot path never pays the early policy fetch). Shared by the Node\n * and Edge middleware entries.\n */\nexport async function resolveTrustedDelegationRootsForRequest(\n resolver: TrustedDelegationRootsResolver | null,\n headers: Headers\n): Promise<string[] | undefined> {\n if (!resolver) return undefined;\n if (!requestCarriesDelegationProof(headers)) return undefined;\n const roots = await resolver();\n return roots.length > 0 ? roots : undefined;\n}\n\n/**\n * The per-request seam shared by both middleware entries. Evaluates the composed\n * policy and swaps `result.decision` IN PLACE when the engine acts — so the\n * swap happens BEFORE the detection reporter fires and before\n * `renderDecisionAsResponse`, exactly like the Express runtime (the reporter\n * records the enforced decision). Fail-OPEN: any fault keeps the structured\n * decision; a policy fault never breaks the response.\n */\nexport async function applyComposedPolicy(\n context: ComposedPolicyContext | null,\n result: VerifyResult,\n path: string | undefined\n): Promise<void> {\n if (!context) return;\n try {\n const outcome = await context.apply(result, path);\n if (outcome.acted) {\n result.decision = outcome.decision;\n if (outcome.composedBlobHash) {\n result.composedBlobHash = outcome.composedBlobHash;\n }\n }\n } catch {\n // Defense-in-depth: the context catches engine/compile faults internally\n // (the core never throws), but an unexpected throw must still degrade to the\n // structured decision rather than reach the middleware's response path.\n }\n}\n\n/**\n * Debug logger mirroring the worker's `console.warn`/`console.error` shadow +\n * fail-open telemetry. Wired by `withCheckpoint` only when `config.debug` is\n * set, so the default SDK posture stays silent.\n */\nexport const consoleComposedPolicyLogger: ComposedPolicyLogger = {\n shadowDivergence(info) {\n // eslint-disable-next-line no-console -- debug-gated telemetry (see withCheckpoint)\n console.warn('[checkpoint/composed-policy] shadow-divergence', info);\n },\n evaluationError(projectId, error) {\n // eslint-disable-next-line no-console -- debug-gated telemetry (see withCheckpoint)\n console.error(\n `[checkpoint/composed-policy] evaluation failed for ${projectId}; using structured decision:`,\n error\n );\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,wBAAwB;AAuBrC,MAAM,cAAoC;CACxC,wBAAwB,CAAC;CACzB,uBAAuB,CAAC;AAC1B;AA2CA,SAAgB,0BACd,MACuB;CACvB,MAAM,EAAE,WAAW,YAAY;CAC/B,MAAM,QAAQ,wBAAwB;EAAE,SAAS,KAAK;EAAS,UAAU,KAAK;CAAS,CAAC;CACxF,MAAM,SAAS,KAAK,UAAU;CAE9B,OAAO;EACL,MAAM,MAAM,QAAQ,MAA0C;GAC5D,MAAM,aAAwC;IAAE,UAAU,OAAO;IAAU,OAAO;GAAM;GACxF,IAAI,8BAA8B,OAAO,QAAQ,GAAG,OAAO;GAK3D,MAAM,SAAS,MAAM,QAAQ,UAAU,SAAS;GAEhD,MAAM,UAAU,MAAM,uBAAuB;IAC3C;IACA;IACA,OAAO;KACL,gBAAgB,OAAO;KACvB,kBAAkB,OAAO;KACzB,0BAA0B,OAAO;KACjC,SAAS,OAAO;IAClB;IACA,gBAAgB,6BAA6B,QAAQ;KAAE,UAAU;KAAW;IAAK,CAAC;IAClF,sBAAsB,OAAO,SAAS;GACxC,CAAC;GAKD,KAAK,QAAQ,WAAW,YAAY,QAAQ,WAAW,aAAa,QAAQ,UAC1E,OAAO,iBAAiB;IACtB;IACA;IACA,gBAAgB,QAAQ,eAAe;IACvC,oBAAoB,OAAO,SAAS;IACpC,gBAAgB,OAAO,gBAAgB,eAAe;IACtD,oBAAoB,OAAO,gBAAgB;IAC3C,YAAY,OAAO,gBAAgB;IACnC,WAAW,OAAO,gBAAgB,eAAe;GACnD,CAAC;GAGH,IAAI,QAAQ,WAAW,SAAS;IAC9B,OAAO,gBAAgB,WAAW,QAAQ,KAAK;IAC/C,OAAO;GACT;GACA,IAAI,QAAQ,WAAW,UACrB,OAAO;IACL,UAAU,QAAQ;IAClB,OAAO;IAGP,GAAI,OAAO,mBAAmB,EAAE,kBAAkB,OAAO,iBAAiB,IAAI,CAAC;GACjF;GAGF,OAAO;EACT;EAEA,MAAM,yBAA4C;GAMhD,QAAO,MADc,QAAQ,UAAU,SAAS,EACnC,CAAC,0BAA0B,CAAC;EAC3C;CACF;AACF;;;;;;;;;AAkBA,eAAsB,wCACpB,UACA,SAC+B;CAC/B,IAAI,CAAC,UAAU,OAAO;CACtB,IAAI,CAAC,8BAA8B,OAAO,GAAG,OAAO;CACpD,MAAM,QAAQ,MAAM,SAAS;CAC7B,OAAO,MAAM,SAAS,IAAI,QAAQ;AACpC;;;;;;;;;AAUA,eAAsB,oBACpB,SACA,QACA,MACe;CACf,IAAI,CAAC,SAAS;CACd,IAAI;EACF,MAAM,UAAU,MAAM,QAAQ,MAAM,QAAQ,IAAI;EAChD,IAAI,QAAQ,OAAO;GACjB,OAAO,WAAW,QAAQ;GAC1B,IAAI,QAAQ,kBACV,OAAO,mBAAmB,QAAQ;EAEtC;CACF,QAAQ,CAIR;AACF;;;;;;AAOA,MAAa,8BAAoD;CAC/D,iBAAiB,MAAM;EAErB,QAAQ,KAAK,kDAAkD,IAAI;CACrE;CACA,gBAAgB,WAAW,OAAO;EAEhC,QAAQ,MACN,sDAAsD,UAAU,+BAChE,KACF;CACF;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-CbAg2mze.d.ts","names":[],"sources":["../src/config.ts"],"mappings":";;;;;;;;;;;;;;UAuCiB;;;;;;;EAOf,iBAAiB;;;;;;EAMjB;;EAEA;;EAEA;;;;;;;EAQA,kBAAkB;;;;;;;;;;EAWlB,0BAA0B;;;;;;EAO1B,8BAA8B;IAC5B,QAAQ;IACR,SAAS;QACL,iCAAiC,QAAQ;;;;;;EAO/C;;EAGA,gCAAgC,OAAO;;;;;;EAOvC;;;;;EAMA;;;;;;;EAQA;;;;;;;EAQA,WAAW;IACT,aAAa;IACb,iBAAiB;IACjB,kBAAkB;IAClB,iBAAiB;;;;;;;;;EAUnB,YAAY,QAAQ,cAAc,KAAK,uBAAuB;;;;;;;;;;;;;;;;;;;;EAqB9D;;;;;;;;;;;;;;;;;;;EAoBA;;;;;;;;;;;;;;;;EAiBA,eAAe;;;;;;;;;;;;;;EAef;;;;;;EAOA;;;;;;;;;;;EAYA;;;;;;;;;;;;;;;;;;;EAoBA;;EAEA,iBAAiB;;;;;;;;;;;;;;EAejB;;;;;;;EAQA,yBAAyB;;;;;;;;;;;;;;;;;;;EAoBzB,kBAAkB,YAAY"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-Doe0Tn53.d.mts","names":[],"sources":["../src/config.ts"],"mappings":";;;;;;;;;;;;;;UAuCiB;;;;;;;EAOf,iBAAiB;;;;;;EAMjB;;EAEA;;EAEA;;;;;;;EAQA,kBAAkB;;;;;;;;;;EAWlB,0BAA0B;;;;;;EAO1B,8BAA8B;IAC5B,QAAQ;IACR,SAAS;QACL,iCAAiC,QAAQ;;;;;;EAO/C;;EAGA,gCAAgC,OAAO;;;;;;EAOvC;;;;;EAMA;;;;;;;EAQA;;;;;;;EAQA,WAAW;IACT,aAAa;IACb,iBAAiB;IACjB,kBAAkB;IAClB,iBAAiB;;;;;;;;;EAUnB,YAAY,QAAQ,cAAc,KAAK,uBAAuB;;;;;;;;;;;;;;;;;;;;EAqB9D;;;;;;;;;;;;;;;;;;;EAoBA;;;;;;;;;;;;;;;;EAiBA,eAAe;;;;;;;;;;;;;;EAef;;;;;;EAOA;;;;;;;;;;;EAYA;;;;;;;;;;;;;;;;;;;EAoBA;;EAEA,iBAAiB;;;;;;;;;;;;;;EAejB;;;;;;;EAQA,yBAAyB;;;;;;;;;;;;;;;;;;;EAoBzB,kBAAkB,YAAY"}
@@ -1,11 +0,0 @@
1
- import { r as NextJSMiddlewareConfig } from "./types-C0SkqLMM.mjs";
2
- import { NextRequest, NextResponse } from "next/server";
3
- //#region src/create-middleware.d.ts
4
- /**
5
- * Create an AgentShield middleware with automatic WASM initialization
6
- * This version handles initialization internally to avoid top-level await
7
- */
8
- export declare function createAgentShieldMiddleware(config: NextJSMiddlewareConfig): (request: NextRequest) => Promise<NextResponse>;
9
- //#endregion
10
- export { createAgentShieldMiddleware as createMiddleware };
11
- //# sourceMappingURL=create-middleware.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-middleware.d.mts","names":[],"sources":["../src/create-middleware.ts"],"mappings":";;;;;;;wBAwBgB,4BAA4B,QAAQ,0BACN,SAAS,gBAAc,QAAQ"}
@@ -1,11 +0,0 @@
1
- import { r as NextJSMiddlewareConfig } from "./types-C7DNSCTO.js";
2
- import { NextRequest, NextResponse } from "next/server";
3
- //#region src/create-middleware.d.ts
4
- /**
5
- * Create an AgentShield middleware with automatic WASM initialization
6
- * This version handles initialization internally to avoid top-level await
7
- */
8
- export declare function createAgentShieldMiddleware(config: NextJSMiddlewareConfig): (request: NextRequest) => Promise<NextResponse>;
9
- //#endregion
10
- export { createAgentShieldMiddleware as createMiddleware };
11
- //# sourceMappingURL=create-middleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-middleware.d.ts","names":[],"sources":["../src/create-middleware.ts"],"mappings":";;;;;;;wBAwBgB,4BAA4B,QAAQ,0BACN,SAAS,gBAAc,QAAQ"}
@@ -1,39 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_middleware = require('./middleware.js');
3
- let next_server = require("next/server");
4
-
5
- //#region src/create-middleware.ts
6
- /**
7
- * Enhanced middleware creator for Edge Runtime.
8
- *
9
- * NOTE (post-Phase D): this wrapper delegates to
10
- * `createAgentShieldMiddleware` from `./middleware`, which is itself a
11
- * throw-stub pointing at `withCheckpoint`. See `middleware.ts`
12
- * for the migration error message + canonical replacement recipe.
13
- */
14
- let middlewareInstance = null;
15
- let isInitializing = false;
16
- let initPromise = null;
17
- /**
18
- * Create an AgentShield middleware with automatic WASM initialization
19
- * This version handles initialization internally to avoid top-level await
20
- */
21
- function createAgentShieldMiddleware(config) {
22
- return async function agentShieldMiddleware(request) {
23
- if (!middlewareInstance) {
24
- if (!isInitializing) {
25
- isInitializing = true;
26
- initPromise = (async () => {
27
- middlewareInstance = require_middleware.createAgentShieldMiddleware(config);
28
- return middlewareInstance;
29
- })();
30
- }
31
- if (initPromise) middlewareInstance = await initPromise;
32
- }
33
- return middlewareInstance ? middlewareInstance(request) : next_server.NextResponse.next();
34
- };
35
- }
36
-
37
- //#endregion
38
- exports.createAgentShieldMiddleware = createAgentShieldMiddleware;
39
- exports.createMiddleware = createAgentShieldMiddleware;
@@ -1,38 +0,0 @@
1
- import { createAgentShieldMiddleware as createAgentShieldMiddleware$1 } from "./middleware.mjs";
2
- import { NextResponse } from "next/server";
3
-
4
- //#region src/create-middleware.ts
5
- /**
6
- * Enhanced middleware creator for Edge Runtime.
7
- *
8
- * NOTE (post-Phase D): this wrapper delegates to
9
- * `createAgentShieldMiddleware` from `./middleware`, which is itself a
10
- * throw-stub pointing at `withCheckpoint`. See `middleware.ts`
11
- * for the migration error message + canonical replacement recipe.
12
- */
13
- let middlewareInstance = null;
14
- let isInitializing = false;
15
- let initPromise = null;
16
- /**
17
- * Create an AgentShield middleware with automatic WASM initialization
18
- * This version handles initialization internally to avoid top-level await
19
- */
20
- function createAgentShieldMiddleware(config) {
21
- return async function agentShieldMiddleware(request) {
22
- if (!middlewareInstance) {
23
- if (!isInitializing) {
24
- isInitializing = true;
25
- initPromise = (async () => {
26
- middlewareInstance = createAgentShieldMiddleware$1(config);
27
- return middlewareInstance;
28
- })();
29
- }
30
- if (initPromise) middlewareInstance = await initPromise;
31
- }
32
- return middlewareInstance ? middlewareInstance(request) : NextResponse.next();
33
- };
34
- }
35
-
36
- //#endregion
37
- export { createAgentShieldMiddleware, createAgentShieldMiddleware as createMiddleware };
38
- //# sourceMappingURL=create-middleware.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-middleware.mjs","names":["createBaseMiddleware"],"sources":["../src/create-middleware.ts"],"sourcesContent":["/**\n * Enhanced middleware creator for Edge Runtime.\n *\n * NOTE (post-Phase D): this wrapper delegates to\n * `createAgentShieldMiddleware` from `./middleware`, which is itself a\n * throw-stub pointing at `withCheckpoint`. See `middleware.ts`\n * for the migration error message + canonical replacement recipe.\n */\n\nimport { NextResponse } from 'next/server';\nimport type { NextRequest } from 'next/server';\nimport { createAgentShieldMiddleware as createBaseMiddleware } from './middleware';\nimport type { NextJSMiddlewareConfig } from './types';\n\ntype MiddlewareFunction = (request: NextRequest) => Promise<NextResponse>;\n\nlet middlewareInstance: MiddlewareFunction | null = null;\nlet isInitializing = false;\nlet initPromise: Promise<MiddlewareFunction> | null = null;\n\n/**\n * Create an AgentShield middleware with automatic WASM initialization\n * This version handles initialization internally to avoid top-level await\n */\nexport function createAgentShieldMiddleware(config: NextJSMiddlewareConfig) {\n return async function agentShieldMiddleware(request: NextRequest): Promise<NextResponse> {\n // Initialize middleware on first request. The base factory is now\n // a Phase D throw-stub that surfaces a migration error pointing at\n // `withCheckpoint` — this wrapper is here only for the compile-time\n // export shape during the deprecation window.\n if (!middlewareInstance) {\n if (!isInitializing) {\n isInitializing = true;\n initPromise = (async () => {\n middlewareInstance = createBaseMiddleware(config);\n return middlewareInstance;\n })();\n }\n\n // Wait for initialization to complete\n if (initPromise) {\n middlewareInstance = await initPromise;\n }\n }\n\n // Run the middleware\n return middlewareInstance ? middlewareInstance(request) : NextResponse.next();\n };\n}\n\n/**\n * Export the original function as well for backward compatibility\n */\nexport { createAgentShieldMiddleware as createMiddleware };\n"],"mappings":";;;;;;;;;;;;AAgBA,IAAI,qBAAgD;AACpD,IAAI,iBAAiB;AACrB,IAAI,cAAkD;;;;;AAMtD,SAAgB,4BAA4B,QAAgC;CAC1E,OAAO,eAAe,sBAAsB,SAA6C;EAKvF,IAAI,CAAC,oBAAoB;GACvB,IAAI,CAAC,gBAAgB;IACnB,iBAAiB;IACjB,eAAe,YAAY;KACzB,qBAAqBA,8BAAqB,MAAM;KAChD,OAAO;IACT,EAAC,CAAE;GACL;GAGA,IAAI,aACF,qBAAqB,MAAM;EAE/B;EAGA,OAAO,qBAAqB,mBAAmB,OAAO,IAAI,aAAa,KAAK;CAC9E;AACF"}