@kya-os/checkpoint-nextjs 1.1.4 → 1.7.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 (43) hide show
  1. package/CHANGELOG.md +190 -0
  2. package/dist/composed-policy.d.mts +108 -0
  3. package/dist/composed-policy.d.ts +108 -0
  4. package/dist/composed-policy.js +91 -0
  5. package/dist/composed-policy.mjs +85 -0
  6. package/dist/config-_nfPN3E3.d.mts +205 -0
  7. package/dist/config-kxFihzR_.d.ts +205 -0
  8. package/dist/create-middleware.js +0 -2
  9. package/dist/create-middleware.mjs +0 -2
  10. package/dist/edge-runtime-loader.js +3 -1
  11. package/dist/edge-runtime-loader.mjs +3 -1
  12. package/dist/edge-wasm-middleware.d.mts +6 -6
  13. package/dist/edge-wasm-middleware.d.ts +6 -6
  14. package/dist/index.d.mts +6 -14
  15. package/dist/index.d.ts +6 -14
  16. package/dist/index.js +162 -9
  17. package/dist/index.mjs +163 -10
  18. package/dist/middleware-edge.d.mts +7 -3
  19. package/dist/middleware-edge.d.ts +7 -3
  20. package/dist/middleware-edge.js +159 -4
  21. package/dist/middleware-edge.mjs +156 -4
  22. package/dist/middleware-node.d.mts +39 -101
  23. package/dist/middleware-node.d.ts +39 -101
  24. package/dist/middleware-node.js +166 -4
  25. package/dist/middleware-node.mjs +163 -5
  26. package/dist/middleware.d.mts +10 -1
  27. package/dist/middleware.d.ts +10 -1
  28. package/dist/middleware.js +6 -0
  29. package/dist/middleware.mjs +6 -1
  30. package/dist/nodejs-wasm-loader.d.mts +3 -4
  31. package/dist/nodejs-wasm-loader.d.ts +3 -4
  32. package/dist/nodejs-wasm-loader.js +1 -1
  33. package/dist/nodejs-wasm-loader.mjs +1 -1
  34. package/dist/signature-verifier.js +2 -2
  35. package/dist/signature-verifier.mjs +2 -2
  36. package/dist/wasm-setup.js +1 -1
  37. package/dist/wasm-setup.mjs +1 -1
  38. package/package.json +8 -11
  39. package/dist/wasm-middleware.d.mts +0 -98
  40. package/dist/wasm-middleware.d.ts +0 -98
  41. package/dist/wasm-middleware.js +0 -125
  42. package/dist/wasm-middleware.mjs +0 -121
  43. package/templates/middleware-wasm-100.ts +0 -161
@@ -0,0 +1,205 @@
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 { ComposedPolicyContext } from './composed-policy.mjs';
5
+
6
+ /**
7
+ * `CheckpointConfig` — the `withCheckpoint` config contract for both the Node
8
+ * (`./node`) and Edge (`./edge`) middleware entries. Extracted from
9
+ * `middleware-node.ts` (a 190-line documented contract); both entries import it
10
+ * from here and re-export it so the public import paths
11
+ * (`@kya-os/checkpoint-nextjs`, `/node`, `/edge`) are unchanged.
12
+ */
13
+
14
+ /**
15
+ * Configuration for `withCheckpoint`.
16
+ *
17
+ * The new minimal shape Phase D's middleware needs. Legacy
18
+ * `AgentShieldMiddlewareConfig` (from `./api-middleware`) remains
19
+ * exported during the deprecation window — see D.4 cutover.
20
+ */
21
+ interface CheckpointConfig {
22
+ /**
23
+ * Tenant identifier — typically the customer's dashboard hostname
24
+ * (e.g. `acme.checkpoint.example`). The PolicyEvaluator uses this
25
+ * to look up tenant policy from the dashboard.
26
+ */
27
+ tenantHost: string;
28
+ /**
29
+ * `'enforce'` (default) blocks; `'observe'` passes everything
30
+ * through with `X-Checkpoint-Would-Have-Been` headers. Per Phase 0.2.
31
+ */
32
+ enforcementMode?: EnforcementMode;
33
+ /**
34
+ * Argus reputation oracle base URL. Omit to use the trust-by-default
35
+ * baseline (reputation defaults to 1.0; orchestrator logs a one-shot
36
+ * warning at first request).
37
+ */
38
+ argusUrl?: string;
39
+ /**
40
+ * Dashboard base URL for the PolicyEvaluator to fetch tenant policy
41
+ * from. Omit to use the open-by-default tenant policy.
42
+ */
43
+ dashboardUrl?: string;
44
+ /**
45
+ * Returned to the PolicyEvaluator for anonymous requests (no agent
46
+ * DID). Default 1.0 (trust-by-default).
47
+ */
48
+ reputationBaseline?: number;
49
+ /**
50
+ * Pre-built adapter instances. Production deployments use the
51
+ * factory-built defaults from `@kya-os/checkpoint-wasm-runtime/adapters`;
52
+ * tests use stubs. The factory composes any provided overrides over
53
+ * defaults — partial overrides are supported.
54
+ */
55
+ adapters?: Partial<{
56
+ didResolver: DidResolverAdapter;
57
+ statusListCache: StatusListCacheAdapter;
58
+ reputationOracle: ReputationOracleAdapter;
59
+ policyEvaluator: PolicyEvaluatorAdapter;
60
+ }>;
61
+ /**
62
+ * Optional callback for the post-verdict path — fires after every
63
+ * verification, regardless of permit/block, with the full
64
+ * `VerifyResult`. Use for logging, dashboards, telemetry. Errors
65
+ * thrown here are swallowed so user code can't break the middleware
66
+ * response.
67
+ */
68
+ onResult?: (result: VerifyResult, req: NextRequest) => void | Promise<void>;
69
+ /**
70
+ * Accept legacy `KYA-Delegation`-header envelope form alongside the
71
+ * canonical `_meta.proof.jws` body form. Default `false`.
72
+ *
73
+ * **When to enable** — customers whose agents pre-date Envelope-1
74
+ * (#2537) and ship MCP-I proofs as `{protected,payload,signature}`
75
+ * JSON in a `KYA-Delegation` HTTP header. Post-Envelope-1 agents
76
+ * ship compact JWS in the request body's `_meta.proof.jws` field;
77
+ * those don't need this flag.
78
+ *
79
+ * Forwarded to the orchestrator's `VerifyRequestOpts.legacyEnvelopeFallback`.
80
+ * Both transports (header + body) are honored when this is `true`;
81
+ * the orchestrator's detection order is body first, then header
82
+ * (`packages/checkpoint-wasm-runtime/src/engine/orchestrator/build-agent-request.ts`).
83
+ *
84
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
85
+ */
86
+ legacyEnvelopeFallback?: boolean;
87
+ /**
88
+ * Read the request body when `content-type` is `application/json` so
89
+ * the orchestrator can extract an MCP-I envelope from
90
+ * `_meta.proof.jws`. Default `true`.
91
+ *
92
+ * **When to disable** — streaming middlewares that can't tolerate
93
+ * the `req.clone()` memory overhead (one full-body copy is buffered
94
+ * during the read). For those, set `false` and route MCP-I
95
+ * envelopes through the `KYA-Delegation` header transport instead
96
+ * (requires `legacyEnvelopeFallback: true`).
97
+ *
98
+ * The clone preserves `req.body` for downstream handlers — disabling
99
+ * is a performance optimization, not a correctness fix.
100
+ *
101
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
102
+ */
103
+ drainJsonBody?: boolean;
104
+ /**
105
+ * Engine-default behaviour knobs forwarded to every composed
106
+ * `ContextSpec`. Defaults to `{ tier3Action: 'monitor' }` —
107
+ * customer-onboarding-safe (tenant policy decides; engine doesn't
108
+ * short-circuit known-agent UAs with an engine-default Block).
109
+ *
110
+ * Opt into `{ tier3Action: 'block' }` when the host wants the
111
+ * calibrated engine-default block for KnownAiAgent / AiCrawler /
112
+ * HeadlessBrowser classifications BEFORE the tenant policy seam.
113
+ *
114
+ * Added in `@kya-os/checkpoint-nextjs@1.2.0` (Engine-Tier3-Monitor-
115
+ * Default, #2653 + this PR's plumbing follow-up).
116
+ */
117
+ engineConfig?: EngineConfig;
118
+ /**
119
+ * Project API key. Required for detections to land in the dashboard
120
+ * — the engine verifies in-process via WASM, but the resulting
121
+ * `VerifyResult` only reaches the dashboard's `detections` table
122
+ * when this reporter is configured. Without it the verdict path
123
+ * works locally but the onboarding "Verify connection" check fails
124
+ * forever because no rows are ever written.
125
+ *
126
+ * Resolve from `process.env.CHECKPOINT_API_KEY` in the host app.
127
+ *
128
+ * Added in `@kya-os/checkpoint-nextjs@1.4.0`
129
+ * (SDK-Detection-Reporter-1).
130
+ */
131
+ apiKey?: string;
132
+ /**
133
+ * Dashboard base URL. Defaults to `https://kya.vouched.id`.
134
+ * Override for staging or self-hosted dashboards.
135
+ */
136
+ baseUrl?: string;
137
+ /**
138
+ * Surface reporter errors via `console.warn`. Defaults to `false`.
139
+ * The reporter is fire-and-forget; enable during development to
140
+ * confirm `apiKey` / `baseUrl` are routed correctly.
141
+ *
142
+ * Also wires the composed-policy shadow-divergence + fail-open
143
+ * telemetry to `console.warn`/`console.error` (otherwise silent).
144
+ */
145
+ debug?: boolean;
146
+ /**
147
+ * Project id whose composed (/policy-compose) policy this middleware
148
+ * enforces. When set, the project's policy is fetched from the dashboard
149
+ * (`<dashboardUrl ?? baseUrl ?? default>/api/internal/policies/${projectId}`)
150
+ * and — if it carries a deployed Cedar bundle with `engineEnforcementEnabled`
151
+ * on — the kya-os-engine decision is enforced IN-PROCESS, byte-for-byte the
152
+ * same as the DNS Gateway. Omit to run detection + the structured policy only
153
+ * (fully back-compatible; purely additive).
154
+ *
155
+ * SHADOW-FIRST: with a deployed bundle but `engineEnforcementEnabled` off, the
156
+ * engine decision is computed + logged on divergence but does NOT act.
157
+ *
158
+ * **Node vs Edge:** composed enforcement is default-on under the Node runtime
159
+ * (`./node`). Under the Edge runtime (`./edge`) it additionally requires
160
+ * `cedarWasmModule` to be wired (see below) — otherwise the seam stays inert.
161
+ *
162
+ * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
163
+ */
164
+ projectId?: string;
165
+ /**
166
+ * Policy-fetch cache TTL in seconds. Defaults to 300 (5 minutes). How long
167
+ * a fetched project policy is reused before the middleware refetches from
168
+ * the dashboard — i.e. the worst-case delay before a dashboard policy
169
+ * change takes effect on this host.
170
+ *
171
+ * `0` disables reuse entirely: every request fetches the policy (one
172
+ * origin round-trip per request). Use for demo/example sites where instant
173
+ * policy propagation matters more than latency; keep the default (or a
174
+ * small positive value like 5) for production and benchmark hosts.
175
+ */
176
+ policyCacheTtlSeconds?: number;
177
+ /**
178
+ * Advanced / testing: inject a pre-built composed-policy context instead of
179
+ * letting `withCheckpoint` construct one from `projectId` + `baseUrl` +
180
+ * `apiKey`. Mirrors the `adapters` injection philosophy — production omits
181
+ * this. When set, it takes precedence over `projectId`.
182
+ */
183
+ composedPolicyEnforcer?: ComposedPolicyContext;
184
+ /**
185
+ * EDGE runtime only. The cedar-web `WebAssembly.Module`, statically imported
186
+ * by the host so composed-policy Cedar can compile at the edge:
187
+ *
188
+ * ```ts
189
+ * import cedarWasmModule from
190
+ * '@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-cedar-web/kya_os_engine_bg.wasm?module';
191
+ * export default withCheckpoint({ projectId, cedarWasmModule });
192
+ * ```
193
+ *
194
+ * The ~2 MB cedar binary is deliberately NOT bundled into the SDK — wiring it
195
+ * is the consumer's explicit opt-in for edge composed enforcement (requires
196
+ * `experiments.asyncWebAssembly` + a `.wasm` asset rule in `next.config`).
197
+ * Without it the Edge seam stays inert (behaves exactly as 1.4.0); the Node
198
+ * runtime ignores this field (it loads cedar via `createPolicyEvaluator`).
199
+ *
200
+ * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
201
+ */
202
+ cedarWasmModule?: WebAssembly.Module;
203
+ }
204
+
205
+ export type { CheckpointConfig as C };
@@ -0,0 +1,205 @@
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 { ComposedPolicyContext } from './composed-policy.js';
5
+
6
+ /**
7
+ * `CheckpointConfig` — the `withCheckpoint` config contract for both the Node
8
+ * (`./node`) and Edge (`./edge`) middleware entries. Extracted from
9
+ * `middleware-node.ts` (a 190-line documented contract); both entries import it
10
+ * from here and re-export it so the public import paths
11
+ * (`@kya-os/checkpoint-nextjs`, `/node`, `/edge`) are unchanged.
12
+ */
13
+
14
+ /**
15
+ * Configuration for `withCheckpoint`.
16
+ *
17
+ * The new minimal shape Phase D's middleware needs. Legacy
18
+ * `AgentShieldMiddlewareConfig` (from `./api-middleware`) remains
19
+ * exported during the deprecation window — see D.4 cutover.
20
+ */
21
+ interface CheckpointConfig {
22
+ /**
23
+ * Tenant identifier — typically the customer's dashboard hostname
24
+ * (e.g. `acme.checkpoint.example`). The PolicyEvaluator uses this
25
+ * to look up tenant policy from the dashboard.
26
+ */
27
+ tenantHost: string;
28
+ /**
29
+ * `'enforce'` (default) blocks; `'observe'` passes everything
30
+ * through with `X-Checkpoint-Would-Have-Been` headers. Per Phase 0.2.
31
+ */
32
+ enforcementMode?: EnforcementMode;
33
+ /**
34
+ * Argus reputation oracle base URL. Omit to use the trust-by-default
35
+ * baseline (reputation defaults to 1.0; orchestrator logs a one-shot
36
+ * warning at first request).
37
+ */
38
+ argusUrl?: string;
39
+ /**
40
+ * Dashboard base URL for the PolicyEvaluator to fetch tenant policy
41
+ * from. Omit to use the open-by-default tenant policy.
42
+ */
43
+ dashboardUrl?: string;
44
+ /**
45
+ * Returned to the PolicyEvaluator for anonymous requests (no agent
46
+ * DID). Default 1.0 (trust-by-default).
47
+ */
48
+ reputationBaseline?: number;
49
+ /**
50
+ * Pre-built adapter instances. Production deployments use the
51
+ * factory-built defaults from `@kya-os/checkpoint-wasm-runtime/adapters`;
52
+ * tests use stubs. The factory composes any provided overrides over
53
+ * defaults — partial overrides are supported.
54
+ */
55
+ adapters?: Partial<{
56
+ didResolver: DidResolverAdapter;
57
+ statusListCache: StatusListCacheAdapter;
58
+ reputationOracle: ReputationOracleAdapter;
59
+ policyEvaluator: PolicyEvaluatorAdapter;
60
+ }>;
61
+ /**
62
+ * Optional callback for the post-verdict path — fires after every
63
+ * verification, regardless of permit/block, with the full
64
+ * `VerifyResult`. Use for logging, dashboards, telemetry. Errors
65
+ * thrown here are swallowed so user code can't break the middleware
66
+ * response.
67
+ */
68
+ onResult?: (result: VerifyResult, req: NextRequest) => void | Promise<void>;
69
+ /**
70
+ * Accept legacy `KYA-Delegation`-header envelope form alongside the
71
+ * canonical `_meta.proof.jws` body form. Default `false`.
72
+ *
73
+ * **When to enable** — customers whose agents pre-date Envelope-1
74
+ * (#2537) and ship MCP-I proofs as `{protected,payload,signature}`
75
+ * JSON in a `KYA-Delegation` HTTP header. Post-Envelope-1 agents
76
+ * ship compact JWS in the request body's `_meta.proof.jws` field;
77
+ * those don't need this flag.
78
+ *
79
+ * Forwarded to the orchestrator's `VerifyRequestOpts.legacyEnvelopeFallback`.
80
+ * Both transports (header + body) are honored when this is `true`;
81
+ * the orchestrator's detection order is body first, then header
82
+ * (`packages/checkpoint-wasm-runtime/src/engine/orchestrator/build-agent-request.ts`).
83
+ *
84
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
85
+ */
86
+ legacyEnvelopeFallback?: boolean;
87
+ /**
88
+ * Read the request body when `content-type` is `application/json` so
89
+ * the orchestrator can extract an MCP-I envelope from
90
+ * `_meta.proof.jws`. Default `true`.
91
+ *
92
+ * **When to disable** — streaming middlewares that can't tolerate
93
+ * the `req.clone()` memory overhead (one full-body copy is buffered
94
+ * during the read). For those, set `false` and route MCP-I
95
+ * envelopes through the `KYA-Delegation` header transport instead
96
+ * (requires `legacyEnvelopeFallback: true`).
97
+ *
98
+ * The clone preserves `req.body` for downstream handlers — disabling
99
+ * is a performance optimization, not a correctness fix.
100
+ *
101
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
102
+ */
103
+ drainJsonBody?: boolean;
104
+ /**
105
+ * Engine-default behaviour knobs forwarded to every composed
106
+ * `ContextSpec`. Defaults to `{ tier3Action: 'monitor' }` —
107
+ * customer-onboarding-safe (tenant policy decides; engine doesn't
108
+ * short-circuit known-agent UAs with an engine-default Block).
109
+ *
110
+ * Opt into `{ tier3Action: 'block' }` when the host wants the
111
+ * calibrated engine-default block for KnownAiAgent / AiCrawler /
112
+ * HeadlessBrowser classifications BEFORE the tenant policy seam.
113
+ *
114
+ * Added in `@kya-os/checkpoint-nextjs@1.2.0` (Engine-Tier3-Monitor-
115
+ * Default, #2653 + this PR's plumbing follow-up).
116
+ */
117
+ engineConfig?: EngineConfig;
118
+ /**
119
+ * Project API key. Required for detections to land in the dashboard
120
+ * — the engine verifies in-process via WASM, but the resulting
121
+ * `VerifyResult` only reaches the dashboard's `detections` table
122
+ * when this reporter is configured. Without it the verdict path
123
+ * works locally but the onboarding "Verify connection" check fails
124
+ * forever because no rows are ever written.
125
+ *
126
+ * Resolve from `process.env.CHECKPOINT_API_KEY` in the host app.
127
+ *
128
+ * Added in `@kya-os/checkpoint-nextjs@1.4.0`
129
+ * (SDK-Detection-Reporter-1).
130
+ */
131
+ apiKey?: string;
132
+ /**
133
+ * Dashboard base URL. Defaults to `https://kya.vouched.id`.
134
+ * Override for staging or self-hosted dashboards.
135
+ */
136
+ baseUrl?: string;
137
+ /**
138
+ * Surface reporter errors via `console.warn`. Defaults to `false`.
139
+ * The reporter is fire-and-forget; enable during development to
140
+ * confirm `apiKey` / `baseUrl` are routed correctly.
141
+ *
142
+ * Also wires the composed-policy shadow-divergence + fail-open
143
+ * telemetry to `console.warn`/`console.error` (otherwise silent).
144
+ */
145
+ debug?: boolean;
146
+ /**
147
+ * Project id whose composed (/policy-compose) policy this middleware
148
+ * enforces. When set, the project's policy is fetched from the dashboard
149
+ * (`<dashboardUrl ?? baseUrl ?? default>/api/internal/policies/${projectId}`)
150
+ * and — if it carries a deployed Cedar bundle with `engineEnforcementEnabled`
151
+ * on — the kya-os-engine decision is enforced IN-PROCESS, byte-for-byte the
152
+ * same as the DNS Gateway. Omit to run detection + the structured policy only
153
+ * (fully back-compatible; purely additive).
154
+ *
155
+ * SHADOW-FIRST: with a deployed bundle but `engineEnforcementEnabled` off, the
156
+ * engine decision is computed + logged on divergence but does NOT act.
157
+ *
158
+ * **Node vs Edge:** composed enforcement is default-on under the Node runtime
159
+ * (`./node`). Under the Edge runtime (`./edge`) it additionally requires
160
+ * `cedarWasmModule` to be wired (see below) — otherwise the seam stays inert.
161
+ *
162
+ * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
163
+ */
164
+ projectId?: string;
165
+ /**
166
+ * Policy-fetch cache TTL in seconds. Defaults to 300 (5 minutes). How long
167
+ * a fetched project policy is reused before the middleware refetches from
168
+ * the dashboard — i.e. the worst-case delay before a dashboard policy
169
+ * change takes effect on this host.
170
+ *
171
+ * `0` disables reuse entirely: every request fetches the policy (one
172
+ * origin round-trip per request). Use for demo/example sites where instant
173
+ * policy propagation matters more than latency; keep the default (or a
174
+ * small positive value like 5) for production and benchmark hosts.
175
+ */
176
+ policyCacheTtlSeconds?: number;
177
+ /**
178
+ * Advanced / testing: inject a pre-built composed-policy context instead of
179
+ * letting `withCheckpoint` construct one from `projectId` + `baseUrl` +
180
+ * `apiKey`. Mirrors the `adapters` injection philosophy — production omits
181
+ * this. When set, it takes precedence over `projectId`.
182
+ */
183
+ composedPolicyEnforcer?: ComposedPolicyContext;
184
+ /**
185
+ * EDGE runtime only. The cedar-web `WebAssembly.Module`, statically imported
186
+ * by the host so composed-policy Cedar can compile at the edge:
187
+ *
188
+ * ```ts
189
+ * import cedarWasmModule from
190
+ * '@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-cedar-web/kya_os_engine_bg.wasm?module';
191
+ * export default withCheckpoint({ projectId, cedarWasmModule });
192
+ * ```
193
+ *
194
+ * The ~2 MB cedar binary is deliberately NOT bundled into the SDK — wiring it
195
+ * is the consumer's explicit opt-in for edge composed enforcement (requires
196
+ * `experiments.asyncWebAssembly` + a `.wasm` asset rule in `next.config`).
197
+ * Without it the Edge seam stays inert (behaves exactly as 1.4.0); the Node
198
+ * runtime ignores this field (it loads cedar via `createPolicyEvaluator`).
199
+ *
200
+ * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
201
+ */
202
+ cedarWasmModule?: WebAssembly.Module;
203
+ }
204
+
205
+ export type { CheckpointConfig as C };
@@ -3,8 +3,6 @@
3
3
  var server = require('next/server');
4
4
 
5
5
  // src/create-middleware.ts
6
-
7
- // src/middleware.ts
8
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.";
9
7
  function createAgentShieldMiddleware(_config = {}) {
10
8
  throw new Error(MIGRATION_ERROR);
@@ -1,8 +1,6 @@
1
1
  import { NextResponse } from 'next/server';
2
2
 
3
3
  // src/create-middleware.ts
4
-
5
- // src/middleware.ts
6
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.";
7
5
  function createAgentShieldMiddleware(_config = {}) {
8
6
  throw new Error(MIGRATION_ERROR);
@@ -25,11 +25,13 @@ var SUSPICIOUS_HEADER_PREFIXES = ["x-openai-", "x-anthropic-", "x-ai-", "x-llm-"
25
25
  function escapeRegex(s) {
26
26
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
27
27
  }
28
+ var REGEX_SYNTAX_PATTERN = /(?:\\.|[()[\]{}|^$]|\.\*|\.\+|\.\?)/;
28
29
  var TOKEN_REGEX_CACHE = /* @__PURE__ */ new Map();
29
30
  function tokenRegex(token) {
30
31
  const cached = TOKEN_REGEX_CACHE.get(token);
31
32
  if (cached) return cached;
32
- const regex = new RegExp(`\\b${escapeRegex(token)}\\b`, "i");
33
+ const source = REGEX_SYNTAX_PATTERN.test(token) ? token : escapeRegex(token);
34
+ const regex = new RegExp(`(^|[^a-z0-9])${source}($|[^a-z0-9])`, "i");
33
35
  TOKEN_REGEX_CACHE.set(token, regex);
34
36
  return regex;
35
37
  }
@@ -23,11 +23,13 @@ var SUSPICIOUS_HEADER_PREFIXES = ["x-openai-", "x-anthropic-", "x-ai-", "x-llm-"
23
23
  function escapeRegex(s) {
24
24
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
25
25
  }
26
+ var REGEX_SYNTAX_PATTERN = /(?:\\.|[()[\]{}|^$]|\.\*|\.\+|\.\?)/;
26
27
  var TOKEN_REGEX_CACHE = /* @__PURE__ */ new Map();
27
28
  function tokenRegex(token) {
28
29
  const cached = TOKEN_REGEX_CACHE.get(token);
29
30
  if (cached) return cached;
30
- const regex = new RegExp(`\\b${escapeRegex(token)}\\b`, "i");
31
+ const source = REGEX_SYNTAX_PATTERN.test(token) ? token : escapeRegex(token);
32
+ const regex = new RegExp(`(^|[^a-z0-9])${source}($|[^a-z0-9])`, "i");
31
33
  TOKEN_REGEX_CACHE.set(token, regex);
32
34
  return regex;
33
35
  }
@@ -5,13 +5,13 @@ import { NextRequest, NextResponse } from 'next/server';
5
5
  * the retired `agentshield-wasm` Rust crate. This file shipped hand-
6
6
  * written wasm-bindgen glue code that loaded the legacy detector's
7
7
  * WASM binary; PR #2599's SSOT consolidation + PDM-1 #2560's engine
8
- * move + AgentDetector-Deletion-1 PR #2610's class-deprecation made
9
- * it structural dead weight.
8
+ * move + AgentDetector-Deletion-1 PR #2610's class-deprecation +
9
+ * AgentDetector-Deletion-2's class removal made it structural dead weight.
10
10
  *
11
- * Phase-D.9a converts the exports to throw-stubs (same precedent as
12
- * PR #2610's `createWasmAgentShieldMiddleware` deprecation). Phase-D.9b
13
- * (follow-up) deletes the underlying `agentshield-wasm` Rust crate
14
- * after migrating the production Cloudflare gateway worker.
11
+ * Phase-D.9a converts the exports to throw-stubs (same precedent the
12
+ * `createWasmAgentShieldMiddleware` removal used). Phase-D.9b (follow-up)
13
+ * deletes the underlying `agentshield-wasm` Rust crate after migrating
14
+ * the production Cloudflare gateway worker.
15
15
  *
16
16
  * Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge` —
17
17
  * engine-backed, runs the full kya-os-engine orchestrator including
@@ -5,13 +5,13 @@ import { NextRequest, NextResponse } from 'next/server';
5
5
  * the retired `agentshield-wasm` Rust crate. This file shipped hand-
6
6
  * written wasm-bindgen glue code that loaded the legacy detector's
7
7
  * WASM binary; PR #2599's SSOT consolidation + PDM-1 #2560's engine
8
- * move + AgentDetector-Deletion-1 PR #2610's class-deprecation made
9
- * it structural dead weight.
8
+ * move + AgentDetector-Deletion-1 PR #2610's class-deprecation +
9
+ * AgentDetector-Deletion-2's class removal made it structural dead weight.
10
10
  *
11
- * Phase-D.9a converts the exports to throw-stubs (same precedent as
12
- * PR #2610's `createWasmAgentShieldMiddleware` deprecation). Phase-D.9b
13
- * (follow-up) deletes the underlying `agentshield-wasm` Rust crate
14
- * after migrating the production Cloudflare gateway worker.
11
+ * Phase-D.9a converts the exports to throw-stubs (same precedent the
12
+ * `createWasmAgentShieldMiddleware` removal used). Phase-D.9b (follow-up)
13
+ * deletes the underlying `agentshield-wasm` Rust crate after migrating
14
+ * the production Cloudflare gateway worker.
15
15
  *
16
16
  * Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge` —
17
17
  * engine-backed, runs the full kya-os-engine orchestrator including
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { CheckpointConfig, withCheckpoint } from './middleware-node.mjs';
1
+ export { VERSION, withCheckpoint } from './middleware-node.mjs';
2
2
  export { createAgentShieldMiddleware, createAgentShieldMiddleware as createMiddleware } from './create-middleware.mjs';
3
3
  export { AgentDetectionEvent, AgentSession, AgentShieldMiddlewareConfig, CheckpointApiMiddlewareConfig, EnhancedMiddlewareConfig, StorageAdapter, StorageConfig, agentShieldMiddleware, createEnhancedAgentShieldMiddleware, withAgentShield, withCheckpointApi } from './api-middleware.mjs';
4
4
  export { createAgentShieldMiddleware as createAgentShieldMiddlewareBase } from './middleware.mjs';
@@ -6,20 +6,12 @@ export { EdgeSessionTracker, SessionData, SessionTrackingConfig, StatelessSessio
6
6
  export { AgentShieldClient, AgentShieldClientConfig, CheckpointApiClient, CheckpointApiClientConfig, EnforceInput, EnforceResponse, EnforcementDecision, LogDetectionInput, getAgentShieldClient, getCheckpointApiClient, resetAgentShieldClient, resetCheckpointApiClient } from './api-client.mjs';
7
7
  export { A as AgentShieldRequest, D as DetectionContext, N as NextJSMiddlewareConfig } from './types-D9RQvPNy.mjs';
8
8
  export { NextJSPolicyMiddlewareConfig, PolicyMiddlewareConfig, applyPolicy, buildBlockedResponse as buildPolicyBlockedResponse, buildRedirectResponse as buildPolicyRedirectResponse, createContextFromDetection, evaluatePolicyForDetection, getPolicy, handlePolicyDecision } from './policy.mjs';
9
+ export { C as CheckpointConfig } from './config-_nfPN3E3.mjs';
9
10
  export { DEFAULT_POLICY, ENFORCEMENT_ACTIONS, EnforcementAction, PolicyConfig, PolicyEvaluationContext, PolicyEvaluationResult, createEvaluationContext, evaluatePolicy } from '@kya-os/checkpoint-shared';
11
+ import '@kya-os/checkpoint-wasm-runtime/engine';
10
12
  import '@kya-os/checkpoint-wasm-runtime/adapters';
11
13
  import 'next/server';
12
- import '@kya-os/checkpoint-wasm-runtime/engine';
14
+ import '@kya-os/checkpoint-wasm-runtime/reporter';
15
+ import './composed-policy.mjs';
16
+ import '@kya-os/checkpoint-wasm-runtime/composed-policy';
13
17
  import '@kya-os/checkpoint';
14
-
15
- /**
16
- * @fileoverview Checkpoint Next.js Integration
17
- * @license MIT OR Apache-2.0
18
- */
19
-
20
- /**
21
- * Library version
22
- */
23
- declare const VERSION = "0.1.0";
24
-
25
- export { VERSION };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { CheckpointConfig, withCheckpoint } from './middleware-node.js';
1
+ export { VERSION, withCheckpoint } from './middleware-node.js';
2
2
  export { createAgentShieldMiddleware, createAgentShieldMiddleware as createMiddleware } from './create-middleware.js';
3
3
  export { AgentDetectionEvent, AgentSession, AgentShieldMiddlewareConfig, CheckpointApiMiddlewareConfig, EnhancedMiddlewareConfig, StorageAdapter, StorageConfig, agentShieldMiddleware, createEnhancedAgentShieldMiddleware, withAgentShield, withCheckpointApi } from './api-middleware.js';
4
4
  export { createAgentShieldMiddleware as createAgentShieldMiddlewareBase } from './middleware.js';
@@ -6,20 +6,12 @@ export { EdgeSessionTracker, SessionData, SessionTrackingConfig, StatelessSessio
6
6
  export { AgentShieldClient, AgentShieldClientConfig, CheckpointApiClient, CheckpointApiClientConfig, EnforceInput, EnforceResponse, EnforcementDecision, LogDetectionInput, getAgentShieldClient, getCheckpointApiClient, resetAgentShieldClient, resetCheckpointApiClient } from './api-client.js';
7
7
  export { A as AgentShieldRequest, D as DetectionContext, N as NextJSMiddlewareConfig } from './types-D9RQvPNy.js';
8
8
  export { NextJSPolicyMiddlewareConfig, PolicyMiddlewareConfig, applyPolicy, buildBlockedResponse as buildPolicyBlockedResponse, buildRedirectResponse as buildPolicyRedirectResponse, createContextFromDetection, evaluatePolicyForDetection, getPolicy, handlePolicyDecision } from './policy.js';
9
+ export { C as CheckpointConfig } from './config-kxFihzR_.js';
9
10
  export { DEFAULT_POLICY, ENFORCEMENT_ACTIONS, EnforcementAction, PolicyConfig, PolicyEvaluationContext, PolicyEvaluationResult, createEvaluationContext, evaluatePolicy } from '@kya-os/checkpoint-shared';
11
+ import '@kya-os/checkpoint-wasm-runtime/engine';
10
12
  import '@kya-os/checkpoint-wasm-runtime/adapters';
11
13
  import 'next/server';
12
- import '@kya-os/checkpoint-wasm-runtime/engine';
14
+ import '@kya-os/checkpoint-wasm-runtime/reporter';
15
+ import './composed-policy.js';
16
+ import '@kya-os/checkpoint-wasm-runtime/composed-policy';
13
17
  import '@kya-os/checkpoint';
14
-
15
- /**
16
- * @fileoverview Checkpoint Next.js Integration
17
- * @license MIT OR Apache-2.0
18
- */
19
-
20
- /**
21
- * Library version
22
- */
23
- declare const VERSION = "0.1.0";
24
-
25
- export { VERSION };