@kya-os/checkpoint-nextjs 1.7.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +107 -0
- package/EDGE_RUNTIME_WASM_SETUP.md +11 -11
- package/README.md +144 -251
- package/bin/setup-edge-wasm.js +9 -1
- package/dist/adapt.d.mts +6 -34
- package/dist/adapt.d.mts.map +1 -0
- package/dist/adapt.d.ts +6 -34
- package/dist/adapt.d.ts.map +1 -0
- package/dist/adapt.js +79 -49
- package/dist/adapt.mjs +78 -46
- package/dist/adapt.mjs.map +1 -0
- package/dist/api-client.d.mts +150 -150
- package/dist/api-client.d.mts.map +1 -0
- package/dist/api-client.d.ts +150 -150
- package/dist/api-client.d.ts.map +1 -0
- package/dist/api-client.js +218 -204
- package/dist/api-client.mjs +217 -201
- package/dist/api-client.mjs.map +1 -0
- package/dist/api-middleware-CDSh3TSE.js +379 -0
- package/dist/api-middleware-CMDRoQik.mjs +357 -0
- package/dist/api-middleware-CMDRoQik.mjs.map +1 -0
- package/dist/api-middleware.d.mts +117 -129
- package/dist/api-middleware.d.mts.map +1 -0
- package/dist/api-middleware.d.ts +117 -129
- package/dist/api-middleware.d.ts.map +1 -0
- package/dist/api-middleware.js +8 -540
- package/dist/api-middleware.mjs +3 -534
- package/dist/composed-policy-BCaNiVHv.d.mts +98 -0
- package/dist/composed-policy-BCaNiVHv.d.mts.map +1 -0
- package/dist/composed-policy-zzJYNFTb.d.ts +98 -0
- package/dist/composed-policy-zzJYNFTb.d.ts.map +1 -0
- package/dist/composed-policy.d.mts +2 -115
- package/dist/composed-policy.d.ts +2 -115
- package/dist/composed-policy.js +122 -88
- package/dist/composed-policy.mjs +121 -85
- package/dist/composed-policy.mjs.map +1 -0
- package/dist/config-CbAg2mze.d.ts +255 -0
- package/dist/config-CbAg2mze.d.ts.map +1 -0
- package/dist/config-Doe0Tn53.d.mts +255 -0
- package/dist/config-Doe0Tn53.d.mts.map +1 -0
- package/dist/create-middleware.d.mts +7 -18
- package/dist/create-middleware.d.mts.map +1 -0
- package/dist/create-middleware.d.ts +7 -18
- package/dist/create-middleware.d.ts.map +1 -0
- package/dist/create-middleware.js +36 -31
- package/dist/create-middleware.mjs +35 -28
- package/dist/create-middleware.mjs.map +1 -0
- package/dist/edge/index.d.mts +64 -86
- package/dist/edge/index.d.mts.map +1 -0
- package/dist/edge/index.d.ts +64 -86
- package/dist/edge/index.d.ts.map +1 -0
- package/dist/edge/index.js +349 -275
- package/dist/edge/index.mjs +348 -272
- package/dist/edge/index.mjs.map +1 -0
- package/dist/edge-runtime-loader.d.mts +37 -63
- package/dist/edge-runtime-loader.d.mts.map +1 -0
- package/dist/edge-runtime-loader.d.ts +37 -63
- package/dist/edge-runtime-loader.d.ts.map +1 -0
- package/dist/edge-runtime-loader.js +268 -225
- package/dist/edge-runtime-loader.mjs +267 -222
- package/dist/edge-runtime-loader.mjs.map +1 -0
- package/dist/edge-wasm-middleware.d.mts +27 -46
- package/dist/edge-wasm-middleware.d.mts.map +1 -0
- package/dist/edge-wasm-middleware.d.ts +27 -46
- package/dist/edge-wasm-middleware.d.ts.map +1 -0
- package/dist/edge-wasm-middleware.js +26 -15
- package/dist/edge-wasm-middleware.mjs +25 -12
- package/dist/edge-wasm-middleware.mjs.map +1 -0
- package/dist/index.d.mts +10 -17
- package/dist/index.d.ts +10 -17
- package/dist/index.js +55 -1224
- package/dist/index.mjs +16 -1193
- package/dist/index.mjs.map +1 -0
- package/dist/middleware-bundler.d.mts +7 -0
- package/dist/middleware-bundler.d.mts.map +1 -0
- package/dist/middleware-bundler.d.ts +7 -0
- package/dist/middleware-bundler.d.ts.map +1 -0
- package/dist/middleware-bundler.js +16 -0
- package/dist/middleware-bundler.mjs +16 -0
- package/dist/middleware-bundler.mjs.map +1 -0
- package/dist/middleware-core-BYQP9FND.mjs +165 -0
- package/dist/middleware-core-BYQP9FND.mjs.map +1 -0
- package/dist/middleware-core-D6TijE6P.js +175 -0
- package/dist/middleware-edge.d.mts +8 -50
- package/dist/middleware-edge.d.mts.map +1 -0
- package/dist/middleware-edge.d.ts +8 -50
- package/dist/middleware-edge.d.ts.map +1 -0
- package/dist/middleware-edge.js +41 -307
- package/dist/middleware-edge.mjs +39 -299
- package/dist/middleware-edge.mjs.map +1 -0
- package/dist/middleware-node-CE4GevYs.d.ts +20 -0
- package/dist/middleware-node-CE4GevYs.d.ts.map +1 -0
- package/dist/middleware-node-DtyOuPta.d.mts +20 -0
- package/dist/middleware-node-DtyOuPta.d.mts.map +1 -0
- package/dist/middleware-node-context-BqPbf-fI.mjs +34 -0
- package/dist/middleware-node-context-BqPbf-fI.mjs.map +1 -0
- package/dist/middleware-node-context-rgnc7UNR.js +38 -0
- package/dist/middleware-node.d.mts +3 -63
- package/dist/middleware-node.d.ts +3 -63
- package/dist/middleware-node.js +13 -308
- package/dist/middleware-node.mjs +12 -301
- package/dist/middleware-node.mjs.map +1 -0
- package/dist/middleware.d.mts +8 -28
- package/dist/middleware.d.mts.map +1 -0
- package/dist/middleware.d.ts +8 -28
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +43 -9
- package/dist/middleware.mjs +42 -6
- package/dist/middleware.mjs.map +1 -0
- package/dist/nodejs-wasm-loader.d.mts +8 -7
- package/dist/nodejs-wasm-loader.d.mts.map +1 -0
- package/dist/nodejs-wasm-loader.d.ts +8 -7
- package/dist/nodejs-wasm-loader.d.ts.map +1 -0
- package/dist/nodejs-wasm-loader.js +53 -19
- package/dist/nodejs-wasm-loader.mjs +52 -16
- package/dist/nodejs-wasm-loader.mjs.map +1 -0
- package/dist/policy.d.mts +86 -110
- package/dist/policy.d.mts.map +1 -0
- package/dist/policy.d.ts +86 -110
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +203 -160
- package/dist/policy.mjs +183 -147
- package/dist/policy.mjs.map +1 -0
- package/dist/session-tracker.d.mts +42 -47
- package/dist/session-tracker.d.mts.map +1 -0
- package/dist/session-tracker.d.ts +42 -47
- package/dist/session-tracker.d.ts.map +1 -0
- package/dist/session-tracker.js +141 -163
- package/dist/session-tracker.mjs +140 -160
- package/dist/session-tracker.mjs.map +1 -0
- package/dist/translate.d.mts +18 -30
- package/dist/translate.d.mts.map +1 -0
- package/dist/translate.d.ts +18 -30
- package/dist/translate.d.ts.map +1 -0
- package/dist/translate.js +70 -34
- package/dist/translate.mjs +70 -32
- package/dist/translate.mjs.map +1 -0
- package/dist/types-C0SkqLMM.d.mts +102 -0
- package/dist/types-C0SkqLMM.d.mts.map +1 -0
- package/dist/types-C7DNSCTO.d.ts +102 -0
- package/dist/types-C7DNSCTO.d.ts.map +1 -0
- package/dist/utils-Cj4XNhIY.mjs +35 -0
- package/dist/utils-Cj4XNhIY.mjs.map +1 -0
- package/dist/utils-DAisnYnI.js +45 -0
- package/dist/wasm-setup.d.mts +6 -5
- package/dist/wasm-setup.d.mts.map +1 -0
- package/dist/wasm-setup.d.ts +6 -5
- package/dist/wasm-setup.d.ts.map +1 -0
- package/dist/wasm-setup.js +82 -113
- package/dist/wasm-setup.mjs +85 -108
- package/dist/wasm-setup.mjs.map +1 -0
- package/package.json +22 -15
- package/dist/config-DAwIA4DB.d.mts +0 -214
- package/dist/config-DyU4l5er.d.ts +0 -214
- package/dist/types-D9RQvPNy.d.mts +0 -105
- package/dist/types-D9RQvPNy.d.ts +0 -105
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { NextRequest } from 'next/server';
|
|
2
|
-
import { DidResolverAdapter, StatusListCacheAdapter, ReputationOracleAdapter, PolicyEvaluatorAdapter } from '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
3
|
-
import { EnforcementMode, VerifyResult, EngineConfig } from '@kya-os/checkpoint-wasm-runtime/engine';
|
|
4
|
-
import { ChallengeEnvelopeMode } from '@kya-os/checkpoint-shared';
|
|
5
|
-
import { ComposedPolicyContext } from './composed-policy.mjs';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* `CheckpointConfig` — the `withCheckpoint` config contract for both the Node
|
|
9
|
-
* (`./node`) and Edge (`./edge`) middleware entries. Extracted from
|
|
10
|
-
* `middleware-node.ts` (a 190-line documented contract); both entries import it
|
|
11
|
-
* from here and re-export it so the public import paths
|
|
12
|
-
* (`@kya-os/checkpoint-nextjs`, `/node`, `/edge`) are unchanged.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Configuration for `withCheckpoint`.
|
|
17
|
-
*
|
|
18
|
-
* The new minimal shape Phase D's middleware needs. Legacy
|
|
19
|
-
* `AgentShieldMiddlewareConfig` (from `./api-middleware`) remains
|
|
20
|
-
* exported during the deprecation window — see D.4 cutover.
|
|
21
|
-
*/
|
|
22
|
-
interface CheckpointConfig {
|
|
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
|
-
/**
|
|
30
|
-
* `'enforce'` (default) blocks; `'observe'` passes everything
|
|
31
|
-
* through with `X-Checkpoint-Would-Have-Been` headers. Per Phase 0.2.
|
|
32
|
-
*/
|
|
33
|
-
enforcementMode?: EnforcementMode;
|
|
34
|
-
/**
|
|
35
|
-
* Challenge-emission envelope mode (draft-kya-http-02 §8.1 fetcher-200).
|
|
36
|
-
* `negotiated` serves a body-readable HTTP 200 step-up response to
|
|
37
|
-
* cooperative agents (fetchers that drop 4xx/5xx bodies), keeping the spec
|
|
38
|
-
* 401/422 for everyone else. Defaults to `spec-401`. A cooperative-UX
|
|
39
|
-
* bridge, NOT an access control.
|
|
40
|
-
*/
|
|
41
|
-
delegationChallengeMode?: ChallengeEnvelopeMode;
|
|
42
|
-
/**
|
|
43
|
-
* Argus reputation oracle base URL. Omit to use the trust-by-default
|
|
44
|
-
* baseline (reputation defaults to 1.0; orchestrator logs a one-shot
|
|
45
|
-
* warning at first request).
|
|
46
|
-
*/
|
|
47
|
-
argusUrl?: string;
|
|
48
|
-
/**
|
|
49
|
-
* Dashboard base URL for the PolicyEvaluator to fetch tenant policy
|
|
50
|
-
* from. Omit to use the open-by-default tenant policy.
|
|
51
|
-
*/
|
|
52
|
-
dashboardUrl?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Returned to the PolicyEvaluator for anonymous requests (no agent
|
|
55
|
-
* DID). Default 1.0 (trust-by-default).
|
|
56
|
-
*/
|
|
57
|
-
reputationBaseline?: number;
|
|
58
|
-
/**
|
|
59
|
-
* Pre-built adapter instances. Production deployments use the
|
|
60
|
-
* factory-built defaults from `@kya-os/checkpoint-wasm-runtime/adapters`;
|
|
61
|
-
* tests use stubs. The factory composes any provided overrides over
|
|
62
|
-
* defaults — partial overrides are supported.
|
|
63
|
-
*/
|
|
64
|
-
adapters?: Partial<{
|
|
65
|
-
didResolver: DidResolverAdapter;
|
|
66
|
-
statusListCache: StatusListCacheAdapter;
|
|
67
|
-
reputationOracle: ReputationOracleAdapter;
|
|
68
|
-
policyEvaluator: PolicyEvaluatorAdapter;
|
|
69
|
-
}>;
|
|
70
|
-
/**
|
|
71
|
-
* Optional callback for the post-verdict path — fires after every
|
|
72
|
-
* verification, regardless of permit/block, with the full
|
|
73
|
-
* `VerifyResult`. Use for logging, dashboards, telemetry. Errors
|
|
74
|
-
* thrown here are swallowed so user code can't break the middleware
|
|
75
|
-
* response.
|
|
76
|
-
*/
|
|
77
|
-
onResult?: (result: VerifyResult, req: NextRequest) => void | Promise<void>;
|
|
78
|
-
/**
|
|
79
|
-
* Accept legacy `KYA-Delegation`-header envelope form alongside the
|
|
80
|
-
* canonical `_meta.proof.jws` body form. Default `false`.
|
|
81
|
-
*
|
|
82
|
-
* **When to enable** — customers whose agents pre-date Envelope-1
|
|
83
|
-
* (#2537) and ship MCP-I proofs as `{protected,payload,signature}`
|
|
84
|
-
* JSON in a `KYA-Delegation` HTTP header. Post-Envelope-1 agents
|
|
85
|
-
* ship compact JWS in the request body's `_meta.proof.jws` field;
|
|
86
|
-
* those don't need this flag.
|
|
87
|
-
*
|
|
88
|
-
* Forwarded to the orchestrator's `VerifyRequestOpts.legacyEnvelopeFallback`.
|
|
89
|
-
* Both transports (header + body) are honored when this is `true`;
|
|
90
|
-
* the orchestrator's detection order is body first, then header
|
|
91
|
-
* (`packages/checkpoint-wasm-runtime/src/engine/orchestrator/build-agent-request.ts`).
|
|
92
|
-
*
|
|
93
|
-
* SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
|
|
94
|
-
*/
|
|
95
|
-
legacyEnvelopeFallback?: boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Read the request body when `content-type` is `application/json` so
|
|
98
|
-
* the orchestrator can extract an MCP-I envelope from
|
|
99
|
-
* `_meta.proof.jws`. Default `true`.
|
|
100
|
-
*
|
|
101
|
-
* **When to disable** — streaming middlewares that can't tolerate
|
|
102
|
-
* the `req.clone()` memory overhead (one full-body copy is buffered
|
|
103
|
-
* during the read). For those, set `false` and route MCP-I
|
|
104
|
-
* envelopes through the `KYA-Delegation` header transport instead
|
|
105
|
-
* (requires `legacyEnvelopeFallback: true`).
|
|
106
|
-
*
|
|
107
|
-
* The clone preserves `req.body` for downstream handlers — disabling
|
|
108
|
-
* is a performance optimization, not a correctness fix.
|
|
109
|
-
*
|
|
110
|
-
* SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
|
|
111
|
-
*/
|
|
112
|
-
drainJsonBody?: boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Engine-default behaviour knobs forwarded to every composed
|
|
115
|
-
* `ContextSpec`. Defaults to `{ tier3Action: 'monitor' }` —
|
|
116
|
-
* customer-onboarding-safe (tenant policy decides; engine doesn't
|
|
117
|
-
* short-circuit known-agent UAs with an engine-default Block).
|
|
118
|
-
*
|
|
119
|
-
* Opt into `{ tier3Action: 'block' }` when the host wants the
|
|
120
|
-
* calibrated engine-default block for KnownAiAgent / AiCrawler /
|
|
121
|
-
* HeadlessBrowser classifications BEFORE the tenant policy seam.
|
|
122
|
-
*
|
|
123
|
-
* Added in `@kya-os/checkpoint-nextjs@1.2.0` (Engine-Tier3-Monitor-
|
|
124
|
-
* Default, #2653 + this PR's plumbing follow-up).
|
|
125
|
-
*/
|
|
126
|
-
engineConfig?: EngineConfig;
|
|
127
|
-
/**
|
|
128
|
-
* Project API key. Required for detections to land in the dashboard
|
|
129
|
-
* — the engine verifies in-process via WASM, but the resulting
|
|
130
|
-
* `VerifyResult` only reaches the dashboard's `detections` table
|
|
131
|
-
* when this reporter is configured. Without it the verdict path
|
|
132
|
-
* works locally but the onboarding "Verify connection" check fails
|
|
133
|
-
* forever because no rows are ever written.
|
|
134
|
-
*
|
|
135
|
-
* Resolve from `process.env.CHECKPOINT_API_KEY` in the host app.
|
|
136
|
-
*
|
|
137
|
-
* Added in `@kya-os/checkpoint-nextjs@1.4.0`
|
|
138
|
-
* (SDK-Detection-Reporter-1).
|
|
139
|
-
*/
|
|
140
|
-
apiKey?: string;
|
|
141
|
-
/**
|
|
142
|
-
* Dashboard base URL. Defaults to `https://kya.vouched.id`.
|
|
143
|
-
* Override for staging or self-hosted dashboards.
|
|
144
|
-
*/
|
|
145
|
-
baseUrl?: string;
|
|
146
|
-
/**
|
|
147
|
-
* Surface reporter errors via `console.warn`. Defaults to `false`.
|
|
148
|
-
* The reporter is fire-and-forget; enable during development to
|
|
149
|
-
* confirm `apiKey` / `baseUrl` are routed correctly.
|
|
150
|
-
*
|
|
151
|
-
* Also wires the composed-policy shadow-divergence + fail-open
|
|
152
|
-
* telemetry to `console.warn`/`console.error` (otherwise silent).
|
|
153
|
-
*/
|
|
154
|
-
debug?: boolean;
|
|
155
|
-
/**
|
|
156
|
-
* Project id whose composed (/policy-compose) policy this middleware
|
|
157
|
-
* enforces. When set, the project's policy is fetched from the dashboard
|
|
158
|
-
* (`<dashboardUrl ?? baseUrl ?? default>/api/internal/policies/${projectId}`)
|
|
159
|
-
* and — if it carries a deployed Cedar bundle with `engineEnforcementEnabled`
|
|
160
|
-
* on — the kya-os-engine decision is enforced IN-PROCESS, byte-for-byte the
|
|
161
|
-
* same as the DNS Gateway. Omit to run detection + the structured policy only
|
|
162
|
-
* (fully back-compatible; purely additive).
|
|
163
|
-
*
|
|
164
|
-
* SHADOW-FIRST: with a deployed bundle but `engineEnforcementEnabled` off, the
|
|
165
|
-
* engine decision is computed + logged on divergence but does NOT act.
|
|
166
|
-
*
|
|
167
|
-
* **Node vs Edge:** composed enforcement is default-on under the Node runtime
|
|
168
|
-
* (`./node`). Under the Edge runtime (`./edge`) it additionally requires
|
|
169
|
-
* `cedarWasmModule` to be wired (see below) — otherwise the seam stays inert.
|
|
170
|
-
*
|
|
171
|
-
* Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
|
|
172
|
-
*/
|
|
173
|
-
projectId?: string;
|
|
174
|
-
/**
|
|
175
|
-
* Policy-fetch cache TTL in seconds. Defaults to 300 (5 minutes). How long
|
|
176
|
-
* a fetched project policy is reused before the middleware refetches from
|
|
177
|
-
* the dashboard — i.e. the worst-case delay before a dashboard policy
|
|
178
|
-
* change takes effect on this host.
|
|
179
|
-
*
|
|
180
|
-
* `0` disables reuse entirely: every request fetches the policy (one
|
|
181
|
-
* origin round-trip per request). Use for demo/example sites where instant
|
|
182
|
-
* policy propagation matters more than latency; keep the default (or a
|
|
183
|
-
* small positive value like 5) for production and benchmark hosts.
|
|
184
|
-
*/
|
|
185
|
-
policyCacheTtlSeconds?: number;
|
|
186
|
-
/**
|
|
187
|
-
* Advanced / testing: inject a pre-built composed-policy context instead of
|
|
188
|
-
* letting `withCheckpoint` construct one from `projectId` + `baseUrl` +
|
|
189
|
-
* `apiKey`. Mirrors the `adapters` injection philosophy — production omits
|
|
190
|
-
* this. When set, it takes precedence over `projectId`.
|
|
191
|
-
*/
|
|
192
|
-
composedPolicyEnforcer?: ComposedPolicyContext;
|
|
193
|
-
/**
|
|
194
|
-
* EDGE runtime only. The cedar-web `WebAssembly.Module`, statically imported
|
|
195
|
-
* by the host so composed-policy Cedar can compile at the edge:
|
|
196
|
-
*
|
|
197
|
-
* ```ts
|
|
198
|
-
* import cedarWasmModule from
|
|
199
|
-
* '@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-cedar-web/kya_os_engine_bg.wasm?module';
|
|
200
|
-
* export default withCheckpoint({ projectId, cedarWasmModule });
|
|
201
|
-
* ```
|
|
202
|
-
*
|
|
203
|
-
* The ~2 MB cedar binary is deliberately NOT bundled into the SDK — wiring it
|
|
204
|
-
* is the consumer's explicit opt-in for edge composed enforcement (requires
|
|
205
|
-
* `experiments.asyncWebAssembly` + a `.wasm` asset rule in `next.config`).
|
|
206
|
-
* Without it the Edge seam stays inert (behaves exactly as 1.4.0); the Node
|
|
207
|
-
* runtime ignores this field (it loads cedar via `createPolicyEvaluator`).
|
|
208
|
-
*
|
|
209
|
-
* Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
|
|
210
|
-
*/
|
|
211
|
-
cedarWasmModule?: WebAssembly.Module;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export type { CheckpointConfig as C };
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { NextRequest } from 'next/server';
|
|
2
|
-
import { DidResolverAdapter, StatusListCacheAdapter, ReputationOracleAdapter, PolicyEvaluatorAdapter } from '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
3
|
-
import { EnforcementMode, VerifyResult, EngineConfig } from '@kya-os/checkpoint-wasm-runtime/engine';
|
|
4
|
-
import { ChallengeEnvelopeMode } from '@kya-os/checkpoint-shared';
|
|
5
|
-
import { ComposedPolicyContext } from './composed-policy.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* `CheckpointConfig` — the `withCheckpoint` config contract for both the Node
|
|
9
|
-
* (`./node`) and Edge (`./edge`) middleware entries. Extracted from
|
|
10
|
-
* `middleware-node.ts` (a 190-line documented contract); both entries import it
|
|
11
|
-
* from here and re-export it so the public import paths
|
|
12
|
-
* (`@kya-os/checkpoint-nextjs`, `/node`, `/edge`) are unchanged.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Configuration for `withCheckpoint`.
|
|
17
|
-
*
|
|
18
|
-
* The new minimal shape Phase D's middleware needs. Legacy
|
|
19
|
-
* `AgentShieldMiddlewareConfig` (from `./api-middleware`) remains
|
|
20
|
-
* exported during the deprecation window — see D.4 cutover.
|
|
21
|
-
*/
|
|
22
|
-
interface CheckpointConfig {
|
|
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
|
-
/**
|
|
30
|
-
* `'enforce'` (default) blocks; `'observe'` passes everything
|
|
31
|
-
* through with `X-Checkpoint-Would-Have-Been` headers. Per Phase 0.2.
|
|
32
|
-
*/
|
|
33
|
-
enforcementMode?: EnforcementMode;
|
|
34
|
-
/**
|
|
35
|
-
* Challenge-emission envelope mode (draft-kya-http-02 §8.1 fetcher-200).
|
|
36
|
-
* `negotiated` serves a body-readable HTTP 200 step-up response to
|
|
37
|
-
* cooperative agents (fetchers that drop 4xx/5xx bodies), keeping the spec
|
|
38
|
-
* 401/422 for everyone else. Defaults to `spec-401`. A cooperative-UX
|
|
39
|
-
* bridge, NOT an access control.
|
|
40
|
-
*/
|
|
41
|
-
delegationChallengeMode?: ChallengeEnvelopeMode;
|
|
42
|
-
/**
|
|
43
|
-
* Argus reputation oracle base URL. Omit to use the trust-by-default
|
|
44
|
-
* baseline (reputation defaults to 1.0; orchestrator logs a one-shot
|
|
45
|
-
* warning at first request).
|
|
46
|
-
*/
|
|
47
|
-
argusUrl?: string;
|
|
48
|
-
/**
|
|
49
|
-
* Dashboard base URL for the PolicyEvaluator to fetch tenant policy
|
|
50
|
-
* from. Omit to use the open-by-default tenant policy.
|
|
51
|
-
*/
|
|
52
|
-
dashboardUrl?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Returned to the PolicyEvaluator for anonymous requests (no agent
|
|
55
|
-
* DID). Default 1.0 (trust-by-default).
|
|
56
|
-
*/
|
|
57
|
-
reputationBaseline?: number;
|
|
58
|
-
/**
|
|
59
|
-
* Pre-built adapter instances. Production deployments use the
|
|
60
|
-
* factory-built defaults from `@kya-os/checkpoint-wasm-runtime/adapters`;
|
|
61
|
-
* tests use stubs. The factory composes any provided overrides over
|
|
62
|
-
* defaults — partial overrides are supported.
|
|
63
|
-
*/
|
|
64
|
-
adapters?: Partial<{
|
|
65
|
-
didResolver: DidResolverAdapter;
|
|
66
|
-
statusListCache: StatusListCacheAdapter;
|
|
67
|
-
reputationOracle: ReputationOracleAdapter;
|
|
68
|
-
policyEvaluator: PolicyEvaluatorAdapter;
|
|
69
|
-
}>;
|
|
70
|
-
/**
|
|
71
|
-
* Optional callback for the post-verdict path — fires after every
|
|
72
|
-
* verification, regardless of permit/block, with the full
|
|
73
|
-
* `VerifyResult`. Use for logging, dashboards, telemetry. Errors
|
|
74
|
-
* thrown here are swallowed so user code can't break the middleware
|
|
75
|
-
* response.
|
|
76
|
-
*/
|
|
77
|
-
onResult?: (result: VerifyResult, req: NextRequest) => void | Promise<void>;
|
|
78
|
-
/**
|
|
79
|
-
* Accept legacy `KYA-Delegation`-header envelope form alongside the
|
|
80
|
-
* canonical `_meta.proof.jws` body form. Default `false`.
|
|
81
|
-
*
|
|
82
|
-
* **When to enable** — customers whose agents pre-date Envelope-1
|
|
83
|
-
* (#2537) and ship MCP-I proofs as `{protected,payload,signature}`
|
|
84
|
-
* JSON in a `KYA-Delegation` HTTP header. Post-Envelope-1 agents
|
|
85
|
-
* ship compact JWS in the request body's `_meta.proof.jws` field;
|
|
86
|
-
* those don't need this flag.
|
|
87
|
-
*
|
|
88
|
-
* Forwarded to the orchestrator's `VerifyRequestOpts.legacyEnvelopeFallback`.
|
|
89
|
-
* Both transports (header + body) are honored when this is `true`;
|
|
90
|
-
* the orchestrator's detection order is body first, then header
|
|
91
|
-
* (`packages/checkpoint-wasm-runtime/src/engine/orchestrator/build-agent-request.ts`).
|
|
92
|
-
*
|
|
93
|
-
* SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
|
|
94
|
-
*/
|
|
95
|
-
legacyEnvelopeFallback?: boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Read the request body when `content-type` is `application/json` so
|
|
98
|
-
* the orchestrator can extract an MCP-I envelope from
|
|
99
|
-
* `_meta.proof.jws`. Default `true`.
|
|
100
|
-
*
|
|
101
|
-
* **When to disable** — streaming middlewares that can't tolerate
|
|
102
|
-
* the `req.clone()` memory overhead (one full-body copy is buffered
|
|
103
|
-
* during the read). For those, set `false` and route MCP-I
|
|
104
|
-
* envelopes through the `KYA-Delegation` header transport instead
|
|
105
|
-
* (requires `legacyEnvelopeFallback: true`).
|
|
106
|
-
*
|
|
107
|
-
* The clone preserves `req.body` for downstream handlers — disabling
|
|
108
|
-
* is a performance optimization, not a correctness fix.
|
|
109
|
-
*
|
|
110
|
-
* SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
|
|
111
|
-
*/
|
|
112
|
-
drainJsonBody?: boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Engine-default behaviour knobs forwarded to every composed
|
|
115
|
-
* `ContextSpec`. Defaults to `{ tier3Action: 'monitor' }` —
|
|
116
|
-
* customer-onboarding-safe (tenant policy decides; engine doesn't
|
|
117
|
-
* short-circuit known-agent UAs with an engine-default Block).
|
|
118
|
-
*
|
|
119
|
-
* Opt into `{ tier3Action: 'block' }` when the host wants the
|
|
120
|
-
* calibrated engine-default block for KnownAiAgent / AiCrawler /
|
|
121
|
-
* HeadlessBrowser classifications BEFORE the tenant policy seam.
|
|
122
|
-
*
|
|
123
|
-
* Added in `@kya-os/checkpoint-nextjs@1.2.0` (Engine-Tier3-Monitor-
|
|
124
|
-
* Default, #2653 + this PR's plumbing follow-up).
|
|
125
|
-
*/
|
|
126
|
-
engineConfig?: EngineConfig;
|
|
127
|
-
/**
|
|
128
|
-
* Project API key. Required for detections to land in the dashboard
|
|
129
|
-
* — the engine verifies in-process via WASM, but the resulting
|
|
130
|
-
* `VerifyResult` only reaches the dashboard's `detections` table
|
|
131
|
-
* when this reporter is configured. Without it the verdict path
|
|
132
|
-
* works locally but the onboarding "Verify connection" check fails
|
|
133
|
-
* forever because no rows are ever written.
|
|
134
|
-
*
|
|
135
|
-
* Resolve from `process.env.CHECKPOINT_API_KEY` in the host app.
|
|
136
|
-
*
|
|
137
|
-
* Added in `@kya-os/checkpoint-nextjs@1.4.0`
|
|
138
|
-
* (SDK-Detection-Reporter-1).
|
|
139
|
-
*/
|
|
140
|
-
apiKey?: string;
|
|
141
|
-
/**
|
|
142
|
-
* Dashboard base URL. Defaults to `https://kya.vouched.id`.
|
|
143
|
-
* Override for staging or self-hosted dashboards.
|
|
144
|
-
*/
|
|
145
|
-
baseUrl?: string;
|
|
146
|
-
/**
|
|
147
|
-
* Surface reporter errors via `console.warn`. Defaults to `false`.
|
|
148
|
-
* The reporter is fire-and-forget; enable during development to
|
|
149
|
-
* confirm `apiKey` / `baseUrl` are routed correctly.
|
|
150
|
-
*
|
|
151
|
-
* Also wires the composed-policy shadow-divergence + fail-open
|
|
152
|
-
* telemetry to `console.warn`/`console.error` (otherwise silent).
|
|
153
|
-
*/
|
|
154
|
-
debug?: boolean;
|
|
155
|
-
/**
|
|
156
|
-
* Project id whose composed (/policy-compose) policy this middleware
|
|
157
|
-
* enforces. When set, the project's policy is fetched from the dashboard
|
|
158
|
-
* (`<dashboardUrl ?? baseUrl ?? default>/api/internal/policies/${projectId}`)
|
|
159
|
-
* and — if it carries a deployed Cedar bundle with `engineEnforcementEnabled`
|
|
160
|
-
* on — the kya-os-engine decision is enforced IN-PROCESS, byte-for-byte the
|
|
161
|
-
* same as the DNS Gateway. Omit to run detection + the structured policy only
|
|
162
|
-
* (fully back-compatible; purely additive).
|
|
163
|
-
*
|
|
164
|
-
* SHADOW-FIRST: with a deployed bundle but `engineEnforcementEnabled` off, the
|
|
165
|
-
* engine decision is computed + logged on divergence but does NOT act.
|
|
166
|
-
*
|
|
167
|
-
* **Node vs Edge:** composed enforcement is default-on under the Node runtime
|
|
168
|
-
* (`./node`). Under the Edge runtime (`./edge`) it additionally requires
|
|
169
|
-
* `cedarWasmModule` to be wired (see below) — otherwise the seam stays inert.
|
|
170
|
-
*
|
|
171
|
-
* Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
|
|
172
|
-
*/
|
|
173
|
-
projectId?: string;
|
|
174
|
-
/**
|
|
175
|
-
* Policy-fetch cache TTL in seconds. Defaults to 300 (5 minutes). How long
|
|
176
|
-
* a fetched project policy is reused before the middleware refetches from
|
|
177
|
-
* the dashboard — i.e. the worst-case delay before a dashboard policy
|
|
178
|
-
* change takes effect on this host.
|
|
179
|
-
*
|
|
180
|
-
* `0` disables reuse entirely: every request fetches the policy (one
|
|
181
|
-
* origin round-trip per request). Use for demo/example sites where instant
|
|
182
|
-
* policy propagation matters more than latency; keep the default (or a
|
|
183
|
-
* small positive value like 5) for production and benchmark hosts.
|
|
184
|
-
*/
|
|
185
|
-
policyCacheTtlSeconds?: number;
|
|
186
|
-
/**
|
|
187
|
-
* Advanced / testing: inject a pre-built composed-policy context instead of
|
|
188
|
-
* letting `withCheckpoint` construct one from `projectId` + `baseUrl` +
|
|
189
|
-
* `apiKey`. Mirrors the `adapters` injection philosophy — production omits
|
|
190
|
-
* this. When set, it takes precedence over `projectId`.
|
|
191
|
-
*/
|
|
192
|
-
composedPolicyEnforcer?: ComposedPolicyContext;
|
|
193
|
-
/**
|
|
194
|
-
* EDGE runtime only. The cedar-web `WebAssembly.Module`, statically imported
|
|
195
|
-
* by the host so composed-policy Cedar can compile at the edge:
|
|
196
|
-
*
|
|
197
|
-
* ```ts
|
|
198
|
-
* import cedarWasmModule from
|
|
199
|
-
* '@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-cedar-web/kya_os_engine_bg.wasm?module';
|
|
200
|
-
* export default withCheckpoint({ projectId, cedarWasmModule });
|
|
201
|
-
* ```
|
|
202
|
-
*
|
|
203
|
-
* The ~2 MB cedar binary is deliberately NOT bundled into the SDK — wiring it
|
|
204
|
-
* is the consumer's explicit opt-in for edge composed enforcement (requires
|
|
205
|
-
* `experiments.asyncWebAssembly` + a `.wasm` asset rule in `next.config`).
|
|
206
|
-
* Without it the Edge seam stays inert (behaves exactly as 1.4.0); the Node
|
|
207
|
-
* runtime ignores this field (it loads cedar via `createPolicyEvaluator`).
|
|
208
|
-
*
|
|
209
|
-
* Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
|
|
210
|
-
*/
|
|
211
|
-
cedarWasmModule?: WebAssembly.Module;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export type { CheckpointConfig as C };
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { AgentShieldConfig, DetectionResult } from '@kya-os/checkpoint-shared';
|
|
3
|
-
import { AgentShieldEvents } from '@kya-os/checkpoint';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Next.js-specific type definitions
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Next.js middleware configuration
|
|
11
|
-
*/
|
|
12
|
-
interface NextJSMiddlewareConfig extends Partial<AgentShieldConfig> {
|
|
13
|
-
/**
|
|
14
|
-
* Action to take when an agent is detected
|
|
15
|
-
*/
|
|
16
|
-
onAgentDetected?: 'block' | 'redirect' | 'rewrite' | 'allow' | 'log';
|
|
17
|
-
/**
|
|
18
|
-
* Custom handler for agent detection
|
|
19
|
-
* @deprecated Use 'events' instead. Will be removed in v1.0.0
|
|
20
|
-
*/
|
|
21
|
-
onDetection?: (req: NextRequest, result: DetectionResult) => NextResponse | Promise<NextResponse> | void | Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Event handlers for detection events
|
|
24
|
-
*/
|
|
25
|
-
events?: Partial<AgentShieldEvents>;
|
|
26
|
-
/**
|
|
27
|
-
* Path patterns to skip detection
|
|
28
|
-
*/
|
|
29
|
-
skipPaths?: string[] | RegExp[];
|
|
30
|
-
/**
|
|
31
|
-
* Response when blocking agents
|
|
32
|
-
*/
|
|
33
|
-
blockedResponse?: {
|
|
34
|
-
status: number;
|
|
35
|
-
message: string;
|
|
36
|
-
headers?: Record<string, string>;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Redirect URL when redirecting detected agents
|
|
40
|
-
*/
|
|
41
|
-
redirectUrl?: string;
|
|
42
|
-
/**
|
|
43
|
-
* Rewrite URL when rewriting requests from detected agents
|
|
44
|
-
*/
|
|
45
|
-
rewriteUrl?: string;
|
|
46
|
-
/**
|
|
47
|
-
* Confidence threshold for agent detection
|
|
48
|
-
*/
|
|
49
|
-
confidenceThreshold?: number;
|
|
50
|
-
/**
|
|
51
|
-
* Enable WASM for enhanced detection
|
|
52
|
-
*/
|
|
53
|
-
enableWasm?: boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Session tracking configuration
|
|
56
|
-
*/
|
|
57
|
-
sessionTracking?: {
|
|
58
|
-
/**
|
|
59
|
-
* Enable session tracking
|
|
60
|
-
*/
|
|
61
|
-
enabled: boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Cookie name for session storage
|
|
64
|
-
* Default: '__agentshield_session'
|
|
65
|
-
*/
|
|
66
|
-
cookieName?: string;
|
|
67
|
-
/**
|
|
68
|
-
* Cookie max age in seconds
|
|
69
|
-
* Default: 3600 (1 hour)
|
|
70
|
-
*/
|
|
71
|
-
cookieMaxAge?: number;
|
|
72
|
-
/**
|
|
73
|
-
* Encryption key for session data
|
|
74
|
-
* Default: Uses CHECKPOINT_SECRET env var or default key
|
|
75
|
-
*/
|
|
76
|
-
encryptionKey?: string;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Extended NextRequest with AgentShield data
|
|
81
|
-
*/
|
|
82
|
-
interface AgentShieldRequest extends NextRequest {
|
|
83
|
-
agentShield?: {
|
|
84
|
-
result?: DetectionResult;
|
|
85
|
-
skipped: boolean;
|
|
86
|
-
session?: {
|
|
87
|
-
id: string;
|
|
88
|
-
agent: string;
|
|
89
|
-
confidence: number;
|
|
90
|
-
detectedAt: number;
|
|
91
|
-
expires: number;
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Detection context for hooks
|
|
97
|
-
*/
|
|
98
|
-
interface DetectionContext {
|
|
99
|
-
result: DetectionResult;
|
|
100
|
-
request: NextRequest;
|
|
101
|
-
userAgent?: string;
|
|
102
|
-
ip?: string;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export type { AgentShieldRequest as A, DetectionContext as D, NextJSMiddlewareConfig as N };
|
package/dist/types-D9RQvPNy.d.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { AgentShieldConfig, DetectionResult } from '@kya-os/checkpoint-shared';
|
|
3
|
-
import { AgentShieldEvents } from '@kya-os/checkpoint';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Next.js-specific type definitions
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Next.js middleware configuration
|
|
11
|
-
*/
|
|
12
|
-
interface NextJSMiddlewareConfig extends Partial<AgentShieldConfig> {
|
|
13
|
-
/**
|
|
14
|
-
* Action to take when an agent is detected
|
|
15
|
-
*/
|
|
16
|
-
onAgentDetected?: 'block' | 'redirect' | 'rewrite' | 'allow' | 'log';
|
|
17
|
-
/**
|
|
18
|
-
* Custom handler for agent detection
|
|
19
|
-
* @deprecated Use 'events' instead. Will be removed in v1.0.0
|
|
20
|
-
*/
|
|
21
|
-
onDetection?: (req: NextRequest, result: DetectionResult) => NextResponse | Promise<NextResponse> | void | Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Event handlers for detection events
|
|
24
|
-
*/
|
|
25
|
-
events?: Partial<AgentShieldEvents>;
|
|
26
|
-
/**
|
|
27
|
-
* Path patterns to skip detection
|
|
28
|
-
*/
|
|
29
|
-
skipPaths?: string[] | RegExp[];
|
|
30
|
-
/**
|
|
31
|
-
* Response when blocking agents
|
|
32
|
-
*/
|
|
33
|
-
blockedResponse?: {
|
|
34
|
-
status: number;
|
|
35
|
-
message: string;
|
|
36
|
-
headers?: Record<string, string>;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Redirect URL when redirecting detected agents
|
|
40
|
-
*/
|
|
41
|
-
redirectUrl?: string;
|
|
42
|
-
/**
|
|
43
|
-
* Rewrite URL when rewriting requests from detected agents
|
|
44
|
-
*/
|
|
45
|
-
rewriteUrl?: string;
|
|
46
|
-
/**
|
|
47
|
-
* Confidence threshold for agent detection
|
|
48
|
-
*/
|
|
49
|
-
confidenceThreshold?: number;
|
|
50
|
-
/**
|
|
51
|
-
* Enable WASM for enhanced detection
|
|
52
|
-
*/
|
|
53
|
-
enableWasm?: boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Session tracking configuration
|
|
56
|
-
*/
|
|
57
|
-
sessionTracking?: {
|
|
58
|
-
/**
|
|
59
|
-
* Enable session tracking
|
|
60
|
-
*/
|
|
61
|
-
enabled: boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Cookie name for session storage
|
|
64
|
-
* Default: '__agentshield_session'
|
|
65
|
-
*/
|
|
66
|
-
cookieName?: string;
|
|
67
|
-
/**
|
|
68
|
-
* Cookie max age in seconds
|
|
69
|
-
* Default: 3600 (1 hour)
|
|
70
|
-
*/
|
|
71
|
-
cookieMaxAge?: number;
|
|
72
|
-
/**
|
|
73
|
-
* Encryption key for session data
|
|
74
|
-
* Default: Uses CHECKPOINT_SECRET env var or default key
|
|
75
|
-
*/
|
|
76
|
-
encryptionKey?: string;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Extended NextRequest with AgentShield data
|
|
81
|
-
*/
|
|
82
|
-
interface AgentShieldRequest extends NextRequest {
|
|
83
|
-
agentShield?: {
|
|
84
|
-
result?: DetectionResult;
|
|
85
|
-
skipped: boolean;
|
|
86
|
-
session?: {
|
|
87
|
-
id: string;
|
|
88
|
-
agent: string;
|
|
89
|
-
confidence: number;
|
|
90
|
-
detectedAt: number;
|
|
91
|
-
expires: number;
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Detection context for hooks
|
|
97
|
-
*/
|
|
98
|
-
interface DetectionContext {
|
|
99
|
-
result: DetectionResult;
|
|
100
|
-
request: NextRequest;
|
|
101
|
-
userAgent?: string;
|
|
102
|
-
ip?: string;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export type { AgentShieldRequest as A, DetectionContext as D, NextJSMiddlewareConfig as N };
|