@kya-os/checkpoint-nextjs 1.7.1 → 1.9.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 (59) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/EDGE_RUNTIME_WASM_SETUP.md +11 -11
  3. package/README.md +144 -251
  4. package/bin/setup-edge-wasm.js +9 -1
  5. package/dist/adapt.js +9 -6
  6. package/dist/adapt.mjs +9 -6
  7. package/dist/api-client.d.mts +9 -0
  8. package/dist/api-client.d.ts +9 -0
  9. package/dist/api-middleware.d.mts +5 -3
  10. package/dist/api-middleware.d.ts +5 -3
  11. package/dist/api-middleware.js +19 -32
  12. package/dist/api-middleware.mjs +20 -33
  13. package/dist/composed-policy.js +1 -0
  14. package/dist/composed-policy.mjs +2 -1
  15. package/dist/{config-DAwIA4DB.d.mts → config-CleTeeoW.d.mts} +32 -13
  16. package/dist/{config-DyU4l5er.d.ts → config-XMOIkxFN.d.ts} +32 -13
  17. package/dist/create-middleware.d.mts +1 -1
  18. package/dist/create-middleware.d.ts +1 -1
  19. package/dist/edge/index.d.mts +3 -1
  20. package/dist/edge/index.d.ts +3 -1
  21. package/dist/edge/index.js +5 -16
  22. package/dist/edge/index.mjs +5 -16
  23. package/dist/edge-runtime-loader.d.mts +3 -1
  24. package/dist/edge-runtime-loader.d.ts +3 -1
  25. package/dist/edge-runtime-loader.js +4 -16
  26. package/dist/edge-runtime-loader.mjs +5 -17
  27. package/dist/edge-wasm-middleware.d.mts +1 -1
  28. package/dist/edge-wasm-middleware.d.ts +1 -1
  29. package/dist/edge-wasm-middleware.js +1 -1
  30. package/dist/edge-wasm-middleware.mjs +1 -1
  31. package/dist/index.d.mts +6 -6
  32. package/dist/index.d.ts +6 -6
  33. package/dist/index.js +126 -85
  34. package/dist/index.mjs +128 -87
  35. package/dist/middleware-bundler.d.mts +13 -0
  36. package/dist/middleware-bundler.d.ts +13 -0
  37. package/dist/middleware-bundler.js +354 -0
  38. package/dist/middleware-bundler.mjs +352 -0
  39. package/dist/middleware-edge.d.mts +4 -40
  40. package/dist/middleware-edge.d.ts +4 -40
  41. package/dist/middleware-edge.js +148 -100
  42. package/dist/middleware-edge.mjs +151 -103
  43. package/dist/middleware-node.d.mts +15 -51
  44. package/dist/middleware-node.d.ts +15 -51
  45. package/dist/middleware-node.js +99 -56
  46. package/dist/middleware-node.mjs +102 -55
  47. package/dist/middleware.d.mts +1 -1
  48. package/dist/middleware.d.ts +1 -1
  49. package/dist/policy.js +6 -1
  50. package/dist/policy.mjs +6 -1
  51. package/dist/session-tracker.js +2 -0
  52. package/dist/session-tracker.mjs +2 -0
  53. package/dist/translate.d.mts +7 -4
  54. package/dist/translate.d.ts +7 -4
  55. package/dist/translate.js +9 -8
  56. package/dist/translate.mjs +9 -8
  57. package/dist/{types-D9RQvPNy.d.mts → types-Chgi5TFC.d.mts} +2 -2
  58. package/dist/{types-D9RQvPNy.d.ts → types-Chgi5TFC.d.ts} +2 -2
  59. package/package.json +17 -10
@@ -1,5 +1,5 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { DetectionDetail } from '@kya-os/checkpoint-shared';
2
+ import { ClientIpTrustPolicy, DetectionDetail } from '@kya-os/checkpoint-shared';
3
3
  export { DetectionDetail } from '@kya-os/checkpoint-shared';
4
4
 
5
5
  /**
@@ -30,6 +30,8 @@ export { DetectionDetail } from '@kya-os/checkpoint-shared';
30
30
  * Edge middleware configuration
31
31
  */
32
32
  interface EdgeMiddlewareConfig {
33
+ /** Explicit deployment/proxy trust profile for client-IP resolution. */
34
+ clientIpPolicy?: ClientIpTrustPolicy;
33
35
  /**
34
36
  * Pre-compiled WebAssembly.Module for Edge Runtime
35
37
  * Use static import: `import wasmModule from '@kya-os/checkpoint-wasm-runtime/wasm?module'`
@@ -1,5 +1,5 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { DetectionDetail } from '@kya-os/checkpoint-shared';
2
+ import { ClientIpTrustPolicy, DetectionDetail } from '@kya-os/checkpoint-shared';
3
3
  export { DetectionDetail } from '@kya-os/checkpoint-shared';
4
4
 
5
5
  /**
@@ -30,6 +30,8 @@ export { DetectionDetail } from '@kya-os/checkpoint-shared';
30
30
  * Edge middleware configuration
31
31
  */
32
32
  interface EdgeMiddlewareConfig {
33
+ /** Explicit deployment/proxy trust profile for client-IP resolution. */
34
+ clientIpPolicy?: ClientIpTrustPolicy;
33
35
  /**
34
36
  * Pre-compiled WebAssembly.Module for Edge Runtime
35
37
  * Use static import: `import wasmModule from '@kya-os/checkpoint-wasm-runtime/wasm?module'`
@@ -1,23 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var server = require('next/server');
4
+ var checkpointShared = require('@kya-os/checkpoint-shared');
4
5
 
5
6
  // src/edge/index.ts
6
-
7
- // src/utils.ts
8
- function getClientIp(request) {
9
- const forwardedFor = request.headers.get("x-forwarded-for");
10
- if (forwardedFor) {
11
- const ip = forwardedFor.split(",")[0]?.trim();
12
- if (ip) return ip;
13
- }
14
- const realIp = request.headers.get("x-real-ip");
15
- if (realIp) return realIp;
16
- const cfIp = request.headers.get("cf-connecting-ip");
17
- if (cfIp) return cfIp;
18
- const clientIp = request.headers.get("x-client-ip");
19
- if (clientIp) return clientIp;
20
- return void 0;
7
+ function getClientIp(request, policy = { platform: "direct" }) {
8
+ const frameworkAddress = request.ip;
9
+ return checkpointShared.resolveClientIp({ headers: request.headers, frameworkAddress, policy }).ip ?? void 0;
21
10
  }
22
11
 
23
12
  // src/local-detection-gate.ts
@@ -185,7 +174,7 @@ function createEdgeMiddleware(config = {}) {
185
174
  const url = new URL(request.url);
186
175
  const input = {
187
176
  userAgent: request.headers.get("user-agent") || void 0,
188
- ipAddress: getClientIp(request),
177
+ ipAddress: getClientIp(request, config.clientIpPolicy),
189
178
  headers: Object.fromEntries(request.headers.entries()),
190
179
  url: url.pathname + url.search,
191
180
  method: request.method
@@ -1,21 +1,10 @@
1
1
  import { NextResponse } from 'next/server';
2
+ import { resolveClientIp } from '@kya-os/checkpoint-shared';
2
3
 
3
4
  // src/edge/index.ts
4
-
5
- // src/utils.ts
6
- function getClientIp(request) {
7
- const forwardedFor = request.headers.get("x-forwarded-for");
8
- if (forwardedFor) {
9
- const ip = forwardedFor.split(",")[0]?.trim();
10
- if (ip) return ip;
11
- }
12
- const realIp = request.headers.get("x-real-ip");
13
- if (realIp) return realIp;
14
- const cfIp = request.headers.get("cf-connecting-ip");
15
- if (cfIp) return cfIp;
16
- const clientIp = request.headers.get("x-client-ip");
17
- if (clientIp) return clientIp;
18
- return void 0;
5
+ function getClientIp(request, policy = { platform: "direct" }) {
6
+ const frameworkAddress = request.ip;
7
+ return resolveClientIp({ headers: request.headers, frameworkAddress, policy }).ip ?? void 0;
19
8
  }
20
9
 
21
10
  // src/local-detection-gate.ts
@@ -183,7 +172,7 @@ function createEdgeMiddleware(config = {}) {
183
172
  const url = new URL(request.url);
184
173
  const input = {
185
174
  userAgent: request.headers.get("user-agent") || void 0,
186
- ipAddress: getClientIp(request),
175
+ ipAddress: getClientIp(request, config.clientIpPolicy),
187
176
  headers: Object.fromEntries(request.headers.entries()),
188
177
  url: url.pathname + url.search,
189
178
  method: request.method
@@ -1,4 +1,4 @@
1
- import { DetectionDetail } from '@kya-os/checkpoint-shared';
1
+ import { ClientIpTrustPolicy, DetectionDetail } from '@kya-os/checkpoint-shared';
2
2
  import { NextRequest } from 'next/server';
3
3
 
4
4
  /**
@@ -38,6 +38,8 @@ type EdgeRuntimeDetectionDetail = DetectionDetail & {
38
38
  interface EdgeCheckpointConfig {
39
39
  wasmModule?: WebAssembly.Module;
40
40
  enableWasm?: boolean;
41
+ /** Explicit deployment/proxy trust profile for client-IP resolution. */
42
+ clientIpPolicy?: ClientIpTrustPolicy;
41
43
  onAgentDetected?: (result: EdgeRuntimeDetectionDetail) => void;
42
44
  blockAgents?: boolean;
43
45
  allowedAgents?: string[];
@@ -1,4 +1,4 @@
1
- import { DetectionDetail } from '@kya-os/checkpoint-shared';
1
+ import { ClientIpTrustPolicy, DetectionDetail } from '@kya-os/checkpoint-shared';
2
2
  import { NextRequest } from 'next/server';
3
3
 
4
4
  /**
@@ -38,6 +38,8 @@ type EdgeRuntimeDetectionDetail = DetectionDetail & {
38
38
  interface EdgeCheckpointConfig {
39
39
  wasmModule?: WebAssembly.Module;
40
40
  enableWasm?: boolean;
41
+ /** Explicit deployment/proxy trust profile for client-IP resolution. */
42
+ clientIpPolicy?: ClientIpTrustPolicy;
41
43
  onAgentDetected?: (result: EdgeRuntimeDetectionDetail) => void;
42
44
  blockAgents?: boolean;
43
45
  allowedAgents?: string[];
@@ -3,21 +3,9 @@
3
3
  var checkpointShared = require('@kya-os/checkpoint-shared');
4
4
 
5
5
  // src/edge-runtime-loader.ts
6
-
7
- // src/utils.ts
8
- function getClientIp(request) {
9
- const forwardedFor = request.headers.get("x-forwarded-for");
10
- if (forwardedFor) {
11
- const ip = forwardedFor.split(",")[0]?.trim();
12
- if (ip) return ip;
13
- }
14
- const realIp = request.headers.get("x-real-ip");
15
- if (realIp) return realIp;
16
- const cfIp = request.headers.get("cf-connecting-ip");
17
- if (cfIp) return cfIp;
18
- const clientIp = request.headers.get("x-client-ip");
19
- if (clientIp) return clientIp;
20
- return void 0;
6
+ function getClientIp(request, policy = { platform: "direct" }) {
7
+ const frameworkAddress = request.ip;
8
+ return checkpointShared.resolveClientIp({ headers: request.headers, frameworkAddress, policy }).ip ?? void 0;
21
9
  }
22
10
 
23
11
  // src/edge-runtime-loader.ts
@@ -132,7 +120,7 @@ var EdgeRuntimeCheckpoint = class {
132
120
  }
133
121
  const metadata = {
134
122
  userAgent: request.headers.get("user-agent") || "",
135
- ipAddress: getClientIp(request) || "",
123
+ ipAddress: getClientIp(request, this.config.clientIpPolicy) || "",
136
124
  headers: Object.fromEntries(request.headers.entries())
137
125
  };
138
126
  if (this.wasmInstance && this.config.enableWasm !== false) {
@@ -1,21 +1,9 @@
1
- import { KNOWN_AGENT_PATTERNS } from '@kya-os/checkpoint-shared';
1
+ import { resolveClientIp, KNOWN_AGENT_PATTERNS } from '@kya-os/checkpoint-shared';
2
2
 
3
3
  // src/edge-runtime-loader.ts
4
-
5
- // src/utils.ts
6
- function getClientIp(request) {
7
- const forwardedFor = request.headers.get("x-forwarded-for");
8
- if (forwardedFor) {
9
- const ip = forwardedFor.split(",")[0]?.trim();
10
- if (ip) return ip;
11
- }
12
- const realIp = request.headers.get("x-real-ip");
13
- if (realIp) return realIp;
14
- const cfIp = request.headers.get("cf-connecting-ip");
15
- if (cfIp) return cfIp;
16
- const clientIp = request.headers.get("x-client-ip");
17
- if (clientIp) return clientIp;
18
- return void 0;
4
+ function getClientIp(request, policy = { platform: "direct" }) {
5
+ const frameworkAddress = request.ip;
6
+ return resolveClientIp({ headers: request.headers, frameworkAddress, policy }).ip ?? void 0;
19
7
  }
20
8
 
21
9
  // src/edge-runtime-loader.ts
@@ -130,7 +118,7 @@ var EdgeRuntimeCheckpoint = class {
130
118
  }
131
119
  const metadata = {
132
120
  userAgent: request.headers.get("user-agent") || "",
133
- ipAddress: getClientIp(request) || "",
121
+ ipAddress: getClientIp(request, this.config.clientIpPolicy) || "",
134
122
  headers: Object.fromEntries(request.headers.entries())
135
123
  };
136
124
  if (this.wasmInstance && this.config.enableWasm !== false) {
@@ -15,7 +15,7 @@ import { NextRequest, NextResponse } from 'next/server';
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
18
- * MCP-I envelope verification. See `packages/checkpoint-nextjs/README.md`
18
+ * KYA-OS envelope verification. See `packages/checkpoint-nextjs/README.md`
19
19
  * for the canonical recipe.
20
20
  */
21
21
 
@@ -15,7 +15,7 @@ import { NextRequest, NextResponse } from 'next/server';
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
18
- * MCP-I envelope verification. See `packages/checkpoint-nextjs/README.md`
18
+ * KYA-OS envelope verification. See `packages/checkpoint-nextjs/README.md`
19
19
  * for the canonical recipe.
20
20
  */
21
21
 
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  // src/edge-wasm-middleware.ts
4
- var MIGRATION_ERROR = "`@kya-os/checkpoint-nextjs/edge-wasm-middleware` was deprecated in Phase-D.9a (legacy `agentshield-wasm` Rust crate retirement). Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge` \u2014 engine-backed via the Rust `kya-os-engine` crate (PDM-1 #2560), runs the full orchestrator including MCP-I envelope verification. See packages/checkpoint-nextjs/README.md for the canonical recipe.";
4
+ var MIGRATION_ERROR = "`@kya-os/checkpoint-nextjs/edge-wasm-middleware` was deprecated in Phase-D.9a (legacy `agentshield-wasm` Rust crate retirement). Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge` \u2014 engine-backed via the Rust `kya-os-engine` crate (PDM-1 #2560), runs the full orchestrator including KYA-OS envelope verification. See packages/checkpoint-nextjs/README.md for the canonical recipe.";
5
5
  var _edgeWasmWarned = false;
6
6
  function warnEdgeWasmDeprecated() {
7
7
  if (_edgeWasmWarned) return;
@@ -1,5 +1,5 @@
1
1
  // src/edge-wasm-middleware.ts
2
- var MIGRATION_ERROR = "`@kya-os/checkpoint-nextjs/edge-wasm-middleware` was deprecated in Phase-D.9a (legacy `agentshield-wasm` Rust crate retirement). Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge` \u2014 engine-backed via the Rust `kya-os-engine` crate (PDM-1 #2560), runs the full orchestrator including MCP-I envelope verification. See packages/checkpoint-nextjs/README.md for the canonical recipe.";
2
+ var MIGRATION_ERROR = "`@kya-os/checkpoint-nextjs/edge-wasm-middleware` was deprecated in Phase-D.9a (legacy `agentshield-wasm` Rust crate retirement). Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge` \u2014 engine-backed via the Rust `kya-os-engine` crate (PDM-1 #2560), runs the full orchestrator including KYA-OS envelope verification. See packages/checkpoint-nextjs/README.md for the canonical recipe.";
3
3
  var _edgeWasmWarned = false;
4
4
  function warnEdgeWasmDeprecated() {
5
5
  if (_edgeWasmWarned) return;
package/dist/index.d.mts CHANGED
@@ -4,14 +4,14 @@ export { AgentDetectionEvent, AgentSession, AgentShieldMiddlewareConfig, Checkpo
4
4
  export { createAgentShieldMiddleware as createAgentShieldMiddlewareBase } from './middleware.mjs';
5
5
  export { EdgeSessionTracker, SessionData, SessionTrackingConfig, StatelessSessionChecker } from './session-tracker.mjs';
6
6
  export { AgentShieldClient, AgentShieldClientConfig, CheckpointApiClient, CheckpointApiClientConfig, EnforceInput, EnforceResponse, EnforcementDecision, LogDetectionInput, getAgentShieldClient, getCheckpointApiClient, resetAgentShieldClient, resetCheckpointApiClient } from './api-client.mjs';
7
- export { A as AgentShieldRequest, D as DetectionContext, N as NextJSMiddlewareConfig } from './types-D9RQvPNy.mjs';
7
+ export { A as AgentShieldRequest, D as DetectionContext, N as NextJSMiddlewareConfig } from './types-Chgi5TFC.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-DAwIA4DB.mjs';
9
+ export { C as CheckpointConfig } from './config-CleTeeoW.mjs';
10
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';
12
- import '@kya-os/checkpoint-wasm-runtime/adapters';
13
11
  import 'next/server';
14
- import '@kya-os/checkpoint-wasm-runtime/reporter';
12
+ import '@kya-os/checkpoint';
13
+ import '@kya-os/checkpoint-shared/browser-posture';
14
+ import '@kya-os/checkpoint-wasm-runtime/adapters';
15
+ import '@kya-os/checkpoint-wasm-runtime/engine';
15
16
  import './composed-policy.mjs';
16
17
  import '@kya-os/checkpoint-wasm-runtime/composed-policy';
17
- import '@kya-os/checkpoint';
package/dist/index.d.ts CHANGED
@@ -4,14 +4,14 @@ export { AgentDetectionEvent, AgentSession, AgentShieldMiddlewareConfig, Checkpo
4
4
  export { createAgentShieldMiddleware as createAgentShieldMiddlewareBase } from './middleware.js';
5
5
  export { EdgeSessionTracker, SessionData, SessionTrackingConfig, StatelessSessionChecker } from './session-tracker.js';
6
6
  export { AgentShieldClient, AgentShieldClientConfig, CheckpointApiClient, CheckpointApiClientConfig, EnforceInput, EnforceResponse, EnforcementDecision, LogDetectionInput, getAgentShieldClient, getCheckpointApiClient, resetAgentShieldClient, resetCheckpointApiClient } from './api-client.js';
7
- export { A as AgentShieldRequest, D as DetectionContext, N as NextJSMiddlewareConfig } from './types-D9RQvPNy.js';
7
+ export { A as AgentShieldRequest, D as DetectionContext, N as NextJSMiddlewareConfig } from './types-Chgi5TFC.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-DyU4l5er.js';
9
+ export { C as CheckpointConfig } from './config-XMOIkxFN.js';
10
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';
12
- import '@kya-os/checkpoint-wasm-runtime/adapters';
13
11
  import 'next/server';
14
- import '@kya-os/checkpoint-wasm-runtime/reporter';
12
+ import '@kya-os/checkpoint';
13
+ import '@kya-os/checkpoint-shared/browser-posture';
14
+ import '@kya-os/checkpoint-wasm-runtime/adapters';
15
+ import '@kya-os/checkpoint-wasm-runtime/engine';
15
16
  import './composed-policy.js';
16
17
  import '@kya-os/checkpoint-wasm-runtime/composed-policy';
17
- import '@kya-os/checkpoint';