@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
@@ -1,233 +0,0 @@
1
- import { BrowserPostureConfig } from '@kya-os/checkpoint-shared/browser-posture';
2
- import { NextRequest } from 'next/server';
3
- import { DidResolverAdapter, StatusListCacheAdapter, ReputationOracleAdapter, PolicyEvaluatorAdapter } from '@kya-os/checkpoint-wasm-runtime/adapters';
4
- import { EnforcementMode, VerifyResult, EngineConfig } from '@kya-os/checkpoint-wasm-runtime/engine';
5
- import { ClientIpTrustPolicy, ChallengeEnvelopeMode, ChallengeWireInput, ChallengeContextFailureEvent } from '@kya-os/checkpoint-shared';
6
- import { ComposedPolicyContext } from './composed-policy.mjs';
7
-
8
- /**
9
- * Configuration for `withCheckpoint`.
10
- *
11
- * The new minimal shape Phase D's middleware needs. Legacy
12
- * `AgentShieldMiddlewareConfig` (from `./api-middleware`) remains
13
- * exported during the deprecation window — see D.4 cutover.
14
- */
15
- interface CheckpointConfig {
16
- /**
17
- * Selects the infrastructure allowed to vouch for client IP headers.
18
- * Defaults to direct peer/framework resolution; set `platform: 'vercel'`
19
- * for Vercel-hosted requests or `platform: 'trusted-proxy'` with an
20
- * explicit hop count for a configured proxy chain.
21
- */
22
- clientIpPolicy?: ClientIpTrustPolicy;
23
- /**
24
- * Tenant identifier — typically the customer's dashboard hostname
25
- * (e.g. `acme.checkpoint.example`). The PolicyEvaluator uses this
26
- * to look up tenant policy from the dashboard.
27
- */
28
- tenantHost: string;
29
- /** Exact org DID used to verify the consent credential's audience. */
30
- resourceOrgDid?: string;
31
- /** Explicit trusted delegation issuers; otherwise resolved from project policy. */
32
- trustedDelegationRoots?: string[];
33
- /**
34
- * `'enforce'` (default) blocks; `'observe'` passes everything
35
- * through with `X-Checkpoint-Would-Have-Been` headers. Per Phase 0.2.
36
- */
37
- enforcementMode?: EnforcementMode;
38
- /**
39
- * Challenge-emission envelope mode (draft-kya-http-02 §8.1 fetcher-200).
40
- * `negotiated` serves a body-readable HTTP 200 step-up response to
41
- * cooperative agents (fetchers that drop 4xx/5xx bodies), keeping the spec
42
- * 401/422 for everyone else. Defaults to `negotiated` (#3530). A cooperative-UX
43
- * bridge, NOT an access control.
44
- */
45
- delegationChallengeMode?: ChallengeEnvelopeMode;
46
- /**
47
- * Resolve a policy `Challenge` into complete registered wire context.
48
- * The callback performs any Authorization-Host registration asynchronously;
49
- * the synchronous engine renderer never fabricates a sid, consent URI, or proof.
50
- */
51
- resolveDelegationChallenge?: (context: {
52
- result: VerifyResult;
53
- request: NextRequest;
54
- }) => ChallengeWireInput | undefined | Promise<ChallengeWireInput | undefined>;
55
- /** Registration/resolution budget. Defaults to 3000 milliseconds. */
56
- delegationChallengeTimeoutMs?: number;
57
- /** Sanitized registration failure hook for metrics and operator warnings. */
58
- onDelegationChallengeFailure?: (event: ChallengeContextFailureEvent) => void;
59
- /**
60
- * Argus reputation oracle base URL. Omit to use the trust-by-default
61
- * baseline (reputation defaults to 1.0; orchestrator logs a one-shot
62
- * warning at first request).
63
- */
64
- argusUrl?: string;
65
- /**
66
- * Dashboard base URL for the PolicyEvaluator to fetch tenant policy
67
- * from. Omit to use the open-by-default tenant policy.
68
- */
69
- dashboardUrl?: string;
70
- /**
71
- * Returned to the PolicyEvaluator for anonymous requests (no agent
72
- * DID). Default 1.0 (trust-by-default).
73
- */
74
- reputationBaseline?: number;
75
- /**
76
- * Pre-built adapter instances. Production deployments use the
77
- * factory-built defaults from `@kya-os/checkpoint-wasm-runtime/adapters`;
78
- * tests use stubs. The factory composes any provided overrides over
79
- * defaults — partial overrides are supported.
80
- */
81
- adapters?: Partial<{
82
- didResolver: DidResolverAdapter;
83
- statusListCache: StatusListCacheAdapter;
84
- reputationOracle: ReputationOracleAdapter;
85
- policyEvaluator: PolicyEvaluatorAdapter;
86
- }>;
87
- /**
88
- * Optional callback for the post-verdict path — fires after every
89
- * verification, regardless of permit/block, with the full
90
- * `VerifyResult`. Use for logging, dashboards, telemetry. Errors
91
- * thrown here are swallowed so user code can't break the middleware
92
- * response.
93
- */
94
- onResult?: (result: VerifyResult, req: NextRequest) => void | Promise<void>;
95
- /**
96
- * Accept legacy `KYA-Delegation`-header envelope form alongside the
97
- * canonical `_meta.proof.jws` body form. Default `false`.
98
- *
99
- * **When to enable** — customers whose agents pre-date Envelope-1
100
- * (#2537) and ship KYA-OS proofs as `{protected,payload,signature}`
101
- * JSON in a `KYA-Delegation` HTTP header. Post-Envelope-1 agents
102
- * ship compact JWS in the request body's `_meta.proof.jws` field;
103
- * those don't need this flag.
104
- *
105
- * Forwarded to the orchestrator's `VerifyRequestOpts.legacyEnvelopeFallback`.
106
- * Both transports (header + body) are honored when this is `true`;
107
- * the orchestrator's detection order is body first, then header
108
- * (`packages/checkpoint-wasm-runtime/src/engine/orchestrator/build-agent-request.ts`).
109
- *
110
- * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
111
- */
112
- legacyEnvelopeFallback?: boolean;
113
- /**
114
- * Read the request body when `content-type` is `application/json` so
115
- * the orchestrator can extract a KYA-OS envelope from
116
- * `_meta.proof.jws`. Default `true`.
117
- *
118
- * **When to disable** — streaming middlewares that can't tolerate
119
- * the `req.clone()` memory overhead (one full-body copy is buffered
120
- * during the read). For those, set `false` and route KYA-OS
121
- * envelopes through the `KYA-Delegation` header transport instead
122
- * (requires `legacyEnvelopeFallback: true`).
123
- *
124
- * The clone preserves `req.body` for downstream handlers — disabling
125
- * is a performance optimization, not a correctness fix.
126
- *
127
- * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
128
- */
129
- drainJsonBody?: boolean;
130
- /**
131
- * Engine-default behaviour knobs forwarded to every composed
132
- * `ContextSpec`. Defaults to `{ tier3Action: 'monitor' }` —
133
- * customer-onboarding-safe (tenant policy decides; engine doesn't
134
- * short-circuit known-agent UAs with an engine-default Block).
135
- *
136
- * Opt into `{ tier3Action: 'block' }` when the host wants the
137
- * calibrated engine-default block for KnownAiAgent / AiCrawler /
138
- * HeadlessBrowser classifications BEFORE the tenant policy seam.
139
- *
140
- * Added in `@kya-os/checkpoint-nextjs@1.2.0` (Engine-Tier3-Monitor-
141
- * Default, #2653 + this PR's plumbing follow-up).
142
- */
143
- engineConfig?: EngineConfig;
144
- /**
145
- * Project API key. Required for detections to land in the dashboard
146
- * — the engine verifies in-process via WASM, but the resulting
147
- * `VerifyResult` only reaches the dashboard's `detections` table
148
- * when this reporter is configured. Without it the verdict path
149
- * works locally but the onboarding "Verify connection" check fails
150
- * forever because no rows are ever written.
151
- *
152
- * Resolve from `process.env.CHECKPOINT_API_KEY` in the host app.
153
- *
154
- * Added in `@kya-os/checkpoint-nextjs@1.4.0`
155
- * (SDK-Detection-Reporter-1).
156
- */
157
- apiKey?: string;
158
- /**
159
- * Dashboard base URL. Defaults to `https://kya.vouched.id`.
160
- * Override for staging or self-hosted dashboards.
161
- */
162
- baseUrl?: string;
163
- /**
164
- * Surface reporter errors via `console.warn`. Defaults to `false`.
165
- * The reporter is fire-and-forget; enable during development to
166
- * confirm `apiKey` / `baseUrl` are routed correctly.
167
- *
168
- * Also wires the composed-policy shadow-divergence + fail-open
169
- * telemetry to `console.warn`/`console.error` (otherwise silent).
170
- */
171
- debug?: boolean;
172
- /**
173
- * Project id whose composed (/policy-compose) policy this middleware
174
- * enforces. When set, the project's policy is fetched from the dashboard
175
- * (`<dashboardUrl ?? baseUrl ?? default>/api/internal/policies/${projectId}`)
176
- * and — if it carries a deployed Cedar bundle with `engineEnforcementEnabled`
177
- * on — the kya-os-engine decision is enforced IN-PROCESS, byte-for-byte the
178
- * same as the DNS Gateway. Omit to run detection + the structured policy only
179
- * (fully back-compatible; purely additive).
180
- *
181
- * SHADOW-FIRST: with a deployed bundle but `engineEnforcementEnabled` off, the
182
- * engine decision is computed + logged on divergence but does NOT act.
183
- *
184
- * **Node vs Edge:** composed enforcement is default-on under the Node runtime
185
- * (`./node`). Under the Edge runtime (`./edge`) it additionally requires
186
- * `cedarWasmModule` to be wired (see below) — otherwise the seam stays inert.
187
- *
188
- * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
189
- */
190
- projectId?: string;
191
- /** Signed browser risk; configure explicit route scopes to enable consent step-up. */
192
- browserPosture?: BrowserPostureConfig;
193
- /**
194
- * Policy-fetch cache TTL in seconds. Defaults to 300 (5 minutes). How long
195
- * a fetched project policy is reused before the middleware refetches from
196
- * the dashboard — i.e. the worst-case delay before a dashboard policy
197
- * change takes effect on this host.
198
- *
199
- * `0` disables reuse entirely: every request fetches the policy (one
200
- * origin round-trip per request). Use for demo/example sites where instant
201
- * policy propagation matters more than latency; keep the default (or a
202
- * small positive value like 5) for production and benchmark hosts.
203
- */
204
- policyCacheTtlSeconds?: number;
205
- /**
206
- * Advanced / testing: inject a pre-built composed-policy context instead of
207
- * letting `withCheckpoint` construct one from `projectId` + `baseUrl` +
208
- * `apiKey`. Mirrors the `adapters` injection philosophy — production omits
209
- * this. When set, it takes precedence over `projectId`.
210
- */
211
- composedPolicyEnforcer?: ComposedPolicyContext;
212
- /**
213
- * EDGE runtime only. The cedar-web `WebAssembly.Module`, statically imported
214
- * by the host so composed-policy Cedar can compile at the edge:
215
- *
216
- * ```ts
217
- * import cedarWasmModule from
218
- * '@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-cedar-web/kya_os_engine_bg.wasm?module';
219
- * export default withCheckpoint({ projectId, cedarWasmModule });
220
- * ```
221
- *
222
- * The ~2 MB cedar binary is deliberately NOT bundled into the SDK — wiring it
223
- * is the consumer's explicit opt-in for edge composed enforcement (requires
224
- * `experiments.asyncWebAssembly` + a `.wasm` asset rule in `next.config`).
225
- * Without it the Edge seam stays inert (behaves exactly as 1.4.0); the Node
226
- * runtime ignores this field (it loads cedar via `createPolicyEvaluator`).
227
- *
228
- * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
229
- */
230
- cedarWasmModule?: WebAssembly.Module;
231
- }
232
-
233
- export type { CheckpointConfig as C };
@@ -1,233 +0,0 @@
1
- import { BrowserPostureConfig } from '@kya-os/checkpoint-shared/browser-posture';
2
- import { NextRequest } from 'next/server';
3
- import { DidResolverAdapter, StatusListCacheAdapter, ReputationOracleAdapter, PolicyEvaluatorAdapter } from '@kya-os/checkpoint-wasm-runtime/adapters';
4
- import { EnforcementMode, VerifyResult, EngineConfig } from '@kya-os/checkpoint-wasm-runtime/engine';
5
- import { ClientIpTrustPolicy, ChallengeEnvelopeMode, ChallengeWireInput, ChallengeContextFailureEvent } from '@kya-os/checkpoint-shared';
6
- import { ComposedPolicyContext } from './composed-policy.js';
7
-
8
- /**
9
- * Configuration for `withCheckpoint`.
10
- *
11
- * The new minimal shape Phase D's middleware needs. Legacy
12
- * `AgentShieldMiddlewareConfig` (from `./api-middleware`) remains
13
- * exported during the deprecation window — see D.4 cutover.
14
- */
15
- interface CheckpointConfig {
16
- /**
17
- * Selects the infrastructure allowed to vouch for client IP headers.
18
- * Defaults to direct peer/framework resolution; set `platform: 'vercel'`
19
- * for Vercel-hosted requests or `platform: 'trusted-proxy'` with an
20
- * explicit hop count for a configured proxy chain.
21
- */
22
- clientIpPolicy?: ClientIpTrustPolicy;
23
- /**
24
- * Tenant identifier — typically the customer's dashboard hostname
25
- * (e.g. `acme.checkpoint.example`). The PolicyEvaluator uses this
26
- * to look up tenant policy from the dashboard.
27
- */
28
- tenantHost: string;
29
- /** Exact org DID used to verify the consent credential's audience. */
30
- resourceOrgDid?: string;
31
- /** Explicit trusted delegation issuers; otherwise resolved from project policy. */
32
- trustedDelegationRoots?: string[];
33
- /**
34
- * `'enforce'` (default) blocks; `'observe'` passes everything
35
- * through with `X-Checkpoint-Would-Have-Been` headers. Per Phase 0.2.
36
- */
37
- enforcementMode?: EnforcementMode;
38
- /**
39
- * Challenge-emission envelope mode (draft-kya-http-02 §8.1 fetcher-200).
40
- * `negotiated` serves a body-readable HTTP 200 step-up response to
41
- * cooperative agents (fetchers that drop 4xx/5xx bodies), keeping the spec
42
- * 401/422 for everyone else. Defaults to `negotiated` (#3530). A cooperative-UX
43
- * bridge, NOT an access control.
44
- */
45
- delegationChallengeMode?: ChallengeEnvelopeMode;
46
- /**
47
- * Resolve a policy `Challenge` into complete registered wire context.
48
- * The callback performs any Authorization-Host registration asynchronously;
49
- * the synchronous engine renderer never fabricates a sid, consent URI, or proof.
50
- */
51
- resolveDelegationChallenge?: (context: {
52
- result: VerifyResult;
53
- request: NextRequest;
54
- }) => ChallengeWireInput | undefined | Promise<ChallengeWireInput | undefined>;
55
- /** Registration/resolution budget. Defaults to 3000 milliseconds. */
56
- delegationChallengeTimeoutMs?: number;
57
- /** Sanitized registration failure hook for metrics and operator warnings. */
58
- onDelegationChallengeFailure?: (event: ChallengeContextFailureEvent) => void;
59
- /**
60
- * Argus reputation oracle base URL. Omit to use the trust-by-default
61
- * baseline (reputation defaults to 1.0; orchestrator logs a one-shot
62
- * warning at first request).
63
- */
64
- argusUrl?: string;
65
- /**
66
- * Dashboard base URL for the PolicyEvaluator to fetch tenant policy
67
- * from. Omit to use the open-by-default tenant policy.
68
- */
69
- dashboardUrl?: string;
70
- /**
71
- * Returned to the PolicyEvaluator for anonymous requests (no agent
72
- * DID). Default 1.0 (trust-by-default).
73
- */
74
- reputationBaseline?: number;
75
- /**
76
- * Pre-built adapter instances. Production deployments use the
77
- * factory-built defaults from `@kya-os/checkpoint-wasm-runtime/adapters`;
78
- * tests use stubs. The factory composes any provided overrides over
79
- * defaults — partial overrides are supported.
80
- */
81
- adapters?: Partial<{
82
- didResolver: DidResolverAdapter;
83
- statusListCache: StatusListCacheAdapter;
84
- reputationOracle: ReputationOracleAdapter;
85
- policyEvaluator: PolicyEvaluatorAdapter;
86
- }>;
87
- /**
88
- * Optional callback for the post-verdict path — fires after every
89
- * verification, regardless of permit/block, with the full
90
- * `VerifyResult`. Use for logging, dashboards, telemetry. Errors
91
- * thrown here are swallowed so user code can't break the middleware
92
- * response.
93
- */
94
- onResult?: (result: VerifyResult, req: NextRequest) => void | Promise<void>;
95
- /**
96
- * Accept legacy `KYA-Delegation`-header envelope form alongside the
97
- * canonical `_meta.proof.jws` body form. Default `false`.
98
- *
99
- * **When to enable** — customers whose agents pre-date Envelope-1
100
- * (#2537) and ship KYA-OS proofs as `{protected,payload,signature}`
101
- * JSON in a `KYA-Delegation` HTTP header. Post-Envelope-1 agents
102
- * ship compact JWS in the request body's `_meta.proof.jws` field;
103
- * those don't need this flag.
104
- *
105
- * Forwarded to the orchestrator's `VerifyRequestOpts.legacyEnvelopeFallback`.
106
- * Both transports (header + body) are honored when this is `true`;
107
- * the orchestrator's detection order is body first, then header
108
- * (`packages/checkpoint-wasm-runtime/src/engine/orchestrator/build-agent-request.ts`).
109
- *
110
- * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
111
- */
112
- legacyEnvelopeFallback?: boolean;
113
- /**
114
- * Read the request body when `content-type` is `application/json` so
115
- * the orchestrator can extract a KYA-OS envelope from
116
- * `_meta.proof.jws`. Default `true`.
117
- *
118
- * **When to disable** — streaming middlewares that can't tolerate
119
- * the `req.clone()` memory overhead (one full-body copy is buffered
120
- * during the read). For those, set `false` and route KYA-OS
121
- * envelopes through the `KYA-Delegation` header transport instead
122
- * (requires `legacyEnvelopeFallback: true`).
123
- *
124
- * The clone preserves `req.body` for downstream handlers — disabling
125
- * is a performance optimization, not a correctness fix.
126
- *
127
- * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
128
- */
129
- drainJsonBody?: boolean;
130
- /**
131
- * Engine-default behaviour knobs forwarded to every composed
132
- * `ContextSpec`. Defaults to `{ tier3Action: 'monitor' }` —
133
- * customer-onboarding-safe (tenant policy decides; engine doesn't
134
- * short-circuit known-agent UAs with an engine-default Block).
135
- *
136
- * Opt into `{ tier3Action: 'block' }` when the host wants the
137
- * calibrated engine-default block for KnownAiAgent / AiCrawler /
138
- * HeadlessBrowser classifications BEFORE the tenant policy seam.
139
- *
140
- * Added in `@kya-os/checkpoint-nextjs@1.2.0` (Engine-Tier3-Monitor-
141
- * Default, #2653 + this PR's plumbing follow-up).
142
- */
143
- engineConfig?: EngineConfig;
144
- /**
145
- * Project API key. Required for detections to land in the dashboard
146
- * — the engine verifies in-process via WASM, but the resulting
147
- * `VerifyResult` only reaches the dashboard's `detections` table
148
- * when this reporter is configured. Without it the verdict path
149
- * works locally but the onboarding "Verify connection" check fails
150
- * forever because no rows are ever written.
151
- *
152
- * Resolve from `process.env.CHECKPOINT_API_KEY` in the host app.
153
- *
154
- * Added in `@kya-os/checkpoint-nextjs@1.4.0`
155
- * (SDK-Detection-Reporter-1).
156
- */
157
- apiKey?: string;
158
- /**
159
- * Dashboard base URL. Defaults to `https://kya.vouched.id`.
160
- * Override for staging or self-hosted dashboards.
161
- */
162
- baseUrl?: string;
163
- /**
164
- * Surface reporter errors via `console.warn`. Defaults to `false`.
165
- * The reporter is fire-and-forget; enable during development to
166
- * confirm `apiKey` / `baseUrl` are routed correctly.
167
- *
168
- * Also wires the composed-policy shadow-divergence + fail-open
169
- * telemetry to `console.warn`/`console.error` (otherwise silent).
170
- */
171
- debug?: boolean;
172
- /**
173
- * Project id whose composed (/policy-compose) policy this middleware
174
- * enforces. When set, the project's policy is fetched from the dashboard
175
- * (`<dashboardUrl ?? baseUrl ?? default>/api/internal/policies/${projectId}`)
176
- * and — if it carries a deployed Cedar bundle with `engineEnforcementEnabled`
177
- * on — the kya-os-engine decision is enforced IN-PROCESS, byte-for-byte the
178
- * same as the DNS Gateway. Omit to run detection + the structured policy only
179
- * (fully back-compatible; purely additive).
180
- *
181
- * SHADOW-FIRST: with a deployed bundle but `engineEnforcementEnabled` off, the
182
- * engine decision is computed + logged on divergence but does NOT act.
183
- *
184
- * **Node vs Edge:** composed enforcement is default-on under the Node runtime
185
- * (`./node`). Under the Edge runtime (`./edge`) it additionally requires
186
- * `cedarWasmModule` to be wired (see below) — otherwise the seam stays inert.
187
- *
188
- * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
189
- */
190
- projectId?: string;
191
- /** Signed browser risk; configure explicit route scopes to enable consent step-up. */
192
- browserPosture?: BrowserPostureConfig;
193
- /**
194
- * Policy-fetch cache TTL in seconds. Defaults to 300 (5 minutes). How long
195
- * a fetched project policy is reused before the middleware refetches from
196
- * the dashboard — i.e. the worst-case delay before a dashboard policy
197
- * change takes effect on this host.
198
- *
199
- * `0` disables reuse entirely: every request fetches the policy (one
200
- * origin round-trip per request). Use for demo/example sites where instant
201
- * policy propagation matters more than latency; keep the default (or a
202
- * small positive value like 5) for production and benchmark hosts.
203
- */
204
- policyCacheTtlSeconds?: number;
205
- /**
206
- * Advanced / testing: inject a pre-built composed-policy context instead of
207
- * letting `withCheckpoint` construct one from `projectId` + `baseUrl` +
208
- * `apiKey`. Mirrors the `adapters` injection philosophy — production omits
209
- * this. When set, it takes precedence over `projectId`.
210
- */
211
- composedPolicyEnforcer?: ComposedPolicyContext;
212
- /**
213
- * EDGE runtime only. The cedar-web `WebAssembly.Module`, statically imported
214
- * by the host so composed-policy Cedar can compile at the edge:
215
- *
216
- * ```ts
217
- * import cedarWasmModule from
218
- * '@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-cedar-web/kya_os_engine_bg.wasm?module';
219
- * export default withCheckpoint({ projectId, cedarWasmModule });
220
- * ```
221
- *
222
- * The ~2 MB cedar binary is deliberately NOT bundled into the SDK — wiring it
223
- * is the consumer's explicit opt-in for edge composed enforcement (requires
224
- * `experiments.asyncWebAssembly` + a `.wasm` asset rule in `next.config`).
225
- * Without it the Edge seam stays inert (behaves exactly as 1.4.0); the Node
226
- * runtime ignores this field (it loads cedar via `createPolicyEvaluator`).
227
- *
228
- * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
229
- */
230
- cedarWasmModule?: WebAssembly.Module;
231
- }
232
-
233
- export type { CheckpointConfig as C };
@@ -1,22 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server';
2
- import { N as NextJSMiddlewareConfig } from './types-Chgi5TFC.mjs';
3
- import '@kya-os/checkpoint-shared';
4
- import '@kya-os/checkpoint';
5
-
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`. Effectively dead code; kept
12
- * as a compile-time surface until next-minor cleanup. See `middleware.ts`
13
- * for the migration error message + canonical replacement recipe.
14
- */
15
-
16
- /**
17
- * Create an AgentShield middleware with automatic WASM initialization
18
- * This version handles initialization internally to avoid top-level await
19
- */
20
- declare function createAgentShieldMiddleware(config: NextJSMiddlewareConfig): (request: NextRequest) => Promise<NextResponse>;
21
-
22
- export { createAgentShieldMiddleware, createAgentShieldMiddleware as createMiddleware };
@@ -1,22 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server';
2
- import { N as NextJSMiddlewareConfig } from './types-Chgi5TFC.js';
3
- import '@kya-os/checkpoint-shared';
4
- import '@kya-os/checkpoint';
5
-
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`. Effectively dead code; kept
12
- * as a compile-time surface until next-minor cleanup. See `middleware.ts`
13
- * for the migration error message + canonical replacement recipe.
14
- */
15
-
16
- /**
17
- * Create an AgentShield middleware with automatic WASM initialization
18
- * This version handles initialization internally to avoid top-level await
19
- */
20
- declare function createAgentShieldMiddleware(config: NextJSMiddlewareConfig): (request: NextRequest) => Promise<NextResponse>;
21
-
22
- export { createAgentShieldMiddleware, createAgentShieldMiddleware as createMiddleware };
@@ -1,34 +0,0 @@
1
- 'use strict';
2
-
3
- var server = require('next/server');
4
-
5
- // src/create-middleware.ts
6
- var MIGRATION_ERROR = "@kya-os/checkpoint-nextjs's `createAgentShieldMiddleware` / `agentShield` were deleted in Phase D (engine consolidation). The 600-line TS pattern matcher that backed them is gone. Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs` (Node runtime) or `@kya-os/checkpoint-nextjs/edge` (Edge runtime). See packages/checkpoint-nextjs/CHANGELOG.md (1.0.0) for the recipe.";
7
- function createAgentShieldMiddleware(_config = {}) {
8
- throw new Error(MIGRATION_ERROR);
9
- }
10
-
11
- // src/create-middleware.ts
12
- var middlewareInstance = null;
13
- var isInitializing = false;
14
- var initPromise = null;
15
- function createAgentShieldMiddleware2(config) {
16
- return async function agentShieldMiddleware(request) {
17
- if (!middlewareInstance) {
18
- if (!isInitializing) {
19
- isInitializing = true;
20
- initPromise = (async () => {
21
- middlewareInstance = createAgentShieldMiddleware(config);
22
- return middlewareInstance;
23
- })();
24
- }
25
- if (initPromise) {
26
- middlewareInstance = await initPromise;
27
- }
28
- }
29
- return middlewareInstance ? middlewareInstance(request) : server.NextResponse.next();
30
- };
31
- }
32
-
33
- exports.createAgentShieldMiddleware = createAgentShieldMiddleware2;
34
- exports.createMiddleware = createAgentShieldMiddleware2;
@@ -1,31 +0,0 @@
1
- import { NextResponse } from 'next/server';
2
-
3
- // src/create-middleware.ts
4
- var MIGRATION_ERROR = "@kya-os/checkpoint-nextjs's `createAgentShieldMiddleware` / `agentShield` were deleted in Phase D (engine consolidation). The 600-line TS pattern matcher that backed them is gone. Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs` (Node runtime) or `@kya-os/checkpoint-nextjs/edge` (Edge runtime). See packages/checkpoint-nextjs/CHANGELOG.md (1.0.0) for the recipe.";
5
- function createAgentShieldMiddleware(_config = {}) {
6
- throw new Error(MIGRATION_ERROR);
7
- }
8
-
9
- // src/create-middleware.ts
10
- var middlewareInstance = null;
11
- var isInitializing = false;
12
- var initPromise = null;
13
- function createAgentShieldMiddleware2(config) {
14
- return async function agentShieldMiddleware(request) {
15
- if (!middlewareInstance) {
16
- if (!isInitializing) {
17
- isInitializing = true;
18
- initPromise = (async () => {
19
- middlewareInstance = createAgentShieldMiddleware(config);
20
- return middlewareInstance;
21
- })();
22
- }
23
- if (initPromise) {
24
- middlewareInstance = await initPromise;
25
- }
26
- }
27
- return middlewareInstance ? middlewareInstance(request) : NextResponse.next();
28
- };
29
- }
30
-
31
- export { createAgentShieldMiddleware2 as createAgentShieldMiddleware, createAgentShieldMiddleware2 as createMiddleware };