@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.
- package/CHANGELOG.md +30 -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.js +9 -6
- package/dist/adapt.mjs +9 -6
- package/dist/api-client.d.mts +9 -0
- package/dist/api-client.d.ts +9 -0
- package/dist/api-middleware.d.mts +5 -3
- package/dist/api-middleware.d.ts +5 -3
- package/dist/api-middleware.js +19 -32
- package/dist/api-middleware.mjs +20 -33
- package/dist/composed-policy.js +1 -0
- package/dist/composed-policy.mjs +2 -1
- package/dist/{config-DAwIA4DB.d.mts → config-CleTeeoW.d.mts} +32 -13
- package/dist/{config-DyU4l5er.d.ts → config-XMOIkxFN.d.ts} +32 -13
- package/dist/create-middleware.d.mts +1 -1
- package/dist/create-middleware.d.ts +1 -1
- package/dist/edge/index.d.mts +3 -1
- package/dist/edge/index.d.ts +3 -1
- package/dist/edge/index.js +5 -16
- package/dist/edge/index.mjs +5 -16
- package/dist/edge-runtime-loader.d.mts +3 -1
- package/dist/edge-runtime-loader.d.ts +3 -1
- package/dist/edge-runtime-loader.js +4 -16
- package/dist/edge-runtime-loader.mjs +5 -17
- package/dist/edge-wasm-middleware.d.mts +1 -1
- package/dist/edge-wasm-middleware.d.ts +1 -1
- package/dist/edge-wasm-middleware.js +1 -1
- package/dist/edge-wasm-middleware.mjs +1 -1
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +126 -85
- package/dist/index.mjs +128 -87
- package/dist/middleware-bundler.d.mts +13 -0
- package/dist/middleware-bundler.d.ts +13 -0
- package/dist/middleware-bundler.js +354 -0
- package/dist/middleware-bundler.mjs +352 -0
- package/dist/middleware-edge.d.mts +4 -40
- package/dist/middleware-edge.d.ts +4 -40
- package/dist/middleware-edge.js +148 -100
- package/dist/middleware-edge.mjs +151 -103
- package/dist/middleware-node.d.mts +15 -51
- package/dist/middleware-node.d.ts +15 -51
- package/dist/middleware-node.js +99 -56
- package/dist/middleware-node.mjs +102 -55
- package/dist/middleware.d.mts +1 -1
- package/dist/middleware.d.ts +1 -1
- package/dist/policy.js +6 -1
- package/dist/policy.mjs +6 -1
- package/dist/session-tracker.js +2 -0
- package/dist/session-tracker.mjs +2 -0
- package/dist/translate.d.mts +7 -4
- package/dist/translate.d.ts +7 -4
- package/dist/translate.js +9 -8
- package/dist/translate.mjs +9 -8
- package/dist/{types-D9RQvPNy.d.mts → types-Chgi5TFC.d.mts} +2 -2
- package/dist/{types-D9RQvPNy.d.ts → types-Chgi5TFC.d.ts} +2 -2
- package/package.json +17 -10
package/dist/translate.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
2
|
import { IncomingHttpLike } from '@kya-os/checkpoint-wasm-runtime/orchestrator';
|
|
3
|
+
import { ClientIpTrustPolicy } from '@kya-os/checkpoint-shared';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* D.2 — `NextRequest` → `IncomingHttpLike` translator.
|
|
@@ -12,15 +13,15 @@ import { IncomingHttpLike } from '@kya-os/checkpoint-wasm-runtime/orchestrator';
|
|
|
12
13
|
* Shared between the Node-runtime and Edge-runtime entries. Next.js
|
|
13
14
|
* `NextRequest` is the same shape in both runtimes — `req.headers` is
|
|
14
15
|
* a `Headers` instance, `req.body` is a `ReadableStream`, `req.ip` is
|
|
15
|
-
* a getter (only present in some deployment surfaces;
|
|
16
|
-
*
|
|
16
|
+
* a getter (only present in some deployment surfaces; forwarding headers
|
|
17
|
+
* are considered only when the caller selects a matching trust policy).
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Options controlling translator side effects.
|
|
21
22
|
*
|
|
22
23
|
* `drainJsonBody` (default `true`) controls whether the translator
|
|
23
|
-
* reads the request body so the orchestrator can extract
|
|
24
|
+
* reads the request body so the orchestrator can extract a KYA-OS
|
|
24
25
|
* envelope from `_meta.proof.jws` (the canonical spec-form transport).
|
|
25
26
|
*
|
|
26
27
|
* Trade-off — body draining consumes the request stream. We use
|
|
@@ -35,11 +36,13 @@ import { IncomingHttpLike } from '@kya-os/checkpoint-wasm-runtime/orchestrator';
|
|
|
35
36
|
interface NextRequestToHttpLikeOpts {
|
|
36
37
|
/**
|
|
37
38
|
* Read the request body when `content-type` is `application/json` so
|
|
38
|
-
* the orchestrator can extract
|
|
39
|
+
* the orchestrator can extract a KYA-OS envelope from
|
|
39
40
|
* `_meta.proof.jws`. Default `true`. Set `false` for streaming
|
|
40
41
|
* middlewares that can't tolerate the clone/read overhead.
|
|
41
42
|
*/
|
|
42
43
|
drainJsonBody?: boolean;
|
|
44
|
+
/** Deployment trust profile. Defaults to direct/peer-only fail-closed behavior. */
|
|
45
|
+
clientIpPolicy?: ClientIpTrustPolicy;
|
|
43
46
|
}
|
|
44
47
|
/**
|
|
45
48
|
* Translate a Next.js `NextRequest` into the orchestrator's
|
package/dist/translate.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var checkpointShared = require('@kya-os/checkpoint-shared');
|
|
4
|
+
|
|
3
5
|
// src/translate.ts
|
|
4
6
|
async function nextRequestToHttpLike(req, opts = {}) {
|
|
5
7
|
const url = new URL(req.url);
|
|
@@ -10,7 +12,7 @@ async function nextRequestToHttpLike(req, opts = {}) {
|
|
|
10
12
|
url: url.pathname + url.search,
|
|
11
13
|
headers: headersToRecord(req.headers),
|
|
12
14
|
body,
|
|
13
|
-
remoteAddress: extractRemoteAddress(req)
|
|
15
|
+
remoteAddress: extractRemoteAddress(req, opts.clientIpPolicy ?? { platform: "direct" })
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
18
|
async function tryDrainJsonBody(req, opts) {
|
|
@@ -30,14 +32,13 @@ function headersToRecord(headers) {
|
|
|
30
32
|
});
|
|
31
33
|
return out;
|
|
32
34
|
}
|
|
33
|
-
function extractRemoteAddress(req) {
|
|
34
|
-
const xff = req.headers.get("x-forwarded-for");
|
|
35
|
-
if (xff) {
|
|
36
|
-
const first = xff.split(",")[0]?.trim();
|
|
37
|
-
if (first) return first;
|
|
38
|
-
}
|
|
35
|
+
function extractRemoteAddress(req, policy) {
|
|
39
36
|
const maybeIp = req.ip;
|
|
40
|
-
return
|
|
37
|
+
return checkpointShared.resolveClientIp({
|
|
38
|
+
headers: req.headers,
|
|
39
|
+
frameworkAddress: maybeIp,
|
|
40
|
+
policy
|
|
41
|
+
}).ip ?? void 0;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
exports.nextRequestToHttpLike = nextRequestToHttpLike;
|
package/dist/translate.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { resolveClientIp } from '@kya-os/checkpoint-shared';
|
|
2
|
+
|
|
1
3
|
// src/translate.ts
|
|
2
4
|
async function nextRequestToHttpLike(req, opts = {}) {
|
|
3
5
|
const url = new URL(req.url);
|
|
@@ -8,7 +10,7 @@ async function nextRequestToHttpLike(req, opts = {}) {
|
|
|
8
10
|
url: url.pathname + url.search,
|
|
9
11
|
headers: headersToRecord(req.headers),
|
|
10
12
|
body,
|
|
11
|
-
remoteAddress: extractRemoteAddress(req)
|
|
13
|
+
remoteAddress: extractRemoteAddress(req, opts.clientIpPolicy ?? { platform: "direct" })
|
|
12
14
|
};
|
|
13
15
|
}
|
|
14
16
|
async function tryDrainJsonBody(req, opts) {
|
|
@@ -28,14 +30,13 @@ function headersToRecord(headers) {
|
|
|
28
30
|
});
|
|
29
31
|
return out;
|
|
30
32
|
}
|
|
31
|
-
function extractRemoteAddress(req) {
|
|
32
|
-
const xff = req.headers.get("x-forwarded-for");
|
|
33
|
-
if (xff) {
|
|
34
|
-
const first = xff.split(",")[0]?.trim();
|
|
35
|
-
if (first) return first;
|
|
36
|
-
}
|
|
33
|
+
function extractRemoteAddress(req, policy) {
|
|
37
34
|
const maybeIp = req.ip;
|
|
38
|
-
return
|
|
35
|
+
return resolveClientIp({
|
|
36
|
+
headers: req.headers,
|
|
37
|
+
frameworkAddress: maybeIp,
|
|
38
|
+
policy
|
|
39
|
+
}).ip ?? void 0;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
export { nextRequestToHttpLike };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { AgentShieldConfig, DetectionResult } from '@kya-os/checkpoint-shared';
|
|
3
|
-
import {
|
|
3
|
+
import { CheckpointEvents } from '@kya-os/checkpoint';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Next.js-specific type definitions
|
|
@@ -22,7 +22,7 @@ interface NextJSMiddlewareConfig extends Partial<AgentShieldConfig> {
|
|
|
22
22
|
/**
|
|
23
23
|
* Event handlers for detection events
|
|
24
24
|
*/
|
|
25
|
-
events?: Partial<
|
|
25
|
+
events?: Partial<CheckpointEvents>;
|
|
26
26
|
/**
|
|
27
27
|
* Path patterns to skip detection
|
|
28
28
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { AgentShieldConfig, DetectionResult } from '@kya-os/checkpoint-shared';
|
|
3
|
-
import {
|
|
3
|
+
import { CheckpointEvents } from '@kya-os/checkpoint';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Next.js-specific type definitions
|
|
@@ -22,7 +22,7 @@ interface NextJSMiddlewareConfig extends Partial<AgentShieldConfig> {
|
|
|
22
22
|
/**
|
|
23
23
|
* Event handlers for detection events
|
|
24
24
|
*/
|
|
25
|
-
events?: Partial<
|
|
25
|
+
events?: Partial<CheckpointEvents>;
|
|
26
26
|
/**
|
|
27
27
|
* Path patterns to skip detection
|
|
28
28
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kya-os/checkpoint-nextjs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Checkpoint Next.js middleware for AI agent detection (formerly @kya-os/agentshield-nextjs)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nextjs",
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
],
|
|
15
15
|
"license": "MIT OR Apache-2.0",
|
|
16
16
|
"author": "KnowThat.ai",
|
|
17
|
-
"homepage": "https://github.com/Know-That-Ai/
|
|
17
|
+
"homepage": "https://github.com/Know-That-Ai/checkpoint#readme",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "https://github.com/Know-That-Ai/
|
|
20
|
+
"url": "https://github.com/Know-That-Ai/checkpoint.git",
|
|
21
21
|
"directory": "packages/checkpoint-nextjs"
|
|
22
22
|
},
|
|
23
23
|
"bugs": {
|
|
24
|
-
"url": "https://github.com/Know-That-Ai/
|
|
24
|
+
"url": "https://github.com/Know-That-Ai/checkpoint/issues"
|
|
25
25
|
},
|
|
26
26
|
"main": "./dist/index.js",
|
|
27
27
|
"module": "./dist/index.mjs",
|
|
@@ -82,7 +82,12 @@
|
|
|
82
82
|
"import": "./dist/policy.mjs",
|
|
83
83
|
"require": "./dist/policy.js"
|
|
84
84
|
},
|
|
85
|
-
"./package.json": "./package.json"
|
|
85
|
+
"./package.json": "./package.json",
|
|
86
|
+
"./bundler": {
|
|
87
|
+
"types": "./dist/middleware-bundler.d.ts",
|
|
88
|
+
"import": "./dist/middleware-bundler.mjs",
|
|
89
|
+
"require": "./dist/middleware-bundler.js"
|
|
90
|
+
}
|
|
86
91
|
},
|
|
87
92
|
"files": [
|
|
88
93
|
"dist",
|
|
@@ -102,9 +107,9 @@
|
|
|
102
107
|
"@testing-library/react-hooks": "^8.0.1",
|
|
103
108
|
"@types/node": "^20.11.24",
|
|
104
109
|
"@types/react": "^18.2.61",
|
|
105
|
-
"@vitest/coverage-v8": "^
|
|
110
|
+
"@vitest/coverage-v8": "^3.2.6",
|
|
106
111
|
"jsdom": "^24.0.0",
|
|
107
|
-
"next": "^16.2.
|
|
112
|
+
"next": "^16.2.6",
|
|
108
113
|
"react": "^18.2.0",
|
|
109
114
|
"react-dom": "^18.2.0",
|
|
110
115
|
"rimraf": "^5.0.5",
|
|
@@ -112,7 +117,7 @@
|
|
|
112
117
|
"typescript": "^5.4.2",
|
|
113
118
|
"vite-plugin-top-level-await": "^1.6.0",
|
|
114
119
|
"vite-plugin-wasm": "^3.6.0",
|
|
115
|
-
"vitest": "^
|
|
120
|
+
"vitest": "^3.2.6"
|
|
116
121
|
},
|
|
117
122
|
"peerDependencies": {
|
|
118
123
|
"@upstash/redis": ">=1.0.0",
|
|
@@ -131,9 +136,10 @@
|
|
|
131
136
|
"dependencies": {
|
|
132
137
|
"@noble/ed25519": "^2.2.3",
|
|
133
138
|
"@noble/hashes": "^2.0.1",
|
|
139
|
+
"@vercel/functions": "^3.9.3",
|
|
140
|
+
"@kya-os/checkpoint-shared": "^1.3.0",
|
|
134
141
|
"@kya-os/checkpoint": "1.2.0",
|
|
135
|
-
"@kya-os/checkpoint-
|
|
136
|
-
"@kya-os/checkpoint-wasm-runtime": "^1.8.1"
|
|
142
|
+
"@kya-os/checkpoint-wasm-runtime": "^1.8.2"
|
|
137
143
|
},
|
|
138
144
|
"scripts": {
|
|
139
145
|
"build": "tsup",
|
|
@@ -142,6 +148,7 @@
|
|
|
142
148
|
"dev": "tsup --watch",
|
|
143
149
|
"clean": "rimraf dist .tsbuildinfo",
|
|
144
150
|
"test": "vitest run",
|
|
151
|
+
"test:unit": "vitest run",
|
|
145
152
|
"test:watch": "vitest",
|
|
146
153
|
"test:coverage": "vitest run --coverage",
|
|
147
154
|
"type-check": "tsc --noEmit",
|