@kya-os/checkpoint-nextjs 1.9.0 → 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 +77 -0
- 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 +78 -51
- package/dist/adapt.mjs +77 -48
- package/dist/adapt.mjs.map +1 -0
- package/dist/api-client.d.mts +150 -159
- package/dist/api-client.d.mts.map +1 -0
- package/dist/api-client.d.ts +150 -159
- 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 -131
- package/dist/api-middleware.d.mts.map +1 -0
- package/dist/api-middleware.d.ts +117 -131
- package/dist/api-middleware.d.ts.map +1 -0
- package/dist/api-middleware.js +8 -527
- package/dist/api-middleware.mjs +3 -521
- 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 -89
- package/dist/composed-policy.mjs +121 -86
- 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 -88
- package/dist/edge/index.d.mts.map +1 -0
- package/dist/edge/index.d.ts +64 -88
- package/dist/edge/index.d.ts.map +1 -0
- package/dist/edge/index.js +349 -264
- package/dist/edge/index.mjs +348 -261
- package/dist/edge/index.mjs.map +1 -0
- package/dist/edge-runtime-loader.d.mts +37 -65
- package/dist/edge-runtime-loader.d.mts.map +1 -0
- package/dist/edge-runtime-loader.d.ts +37 -65
- package/dist/edge-runtime-loader.d.ts.map +1 -0
- package/dist/edge-runtime-loader.js +268 -213
- package/dist/edge-runtime-loader.mjs +267 -210
- 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 -1265
- package/dist/index.mjs +16 -1234
- package/dist/index.mjs.map +1 -0
- package/dist/middleware-bundler.d.mts +6 -12
- package/dist/middleware-bundler.d.mts.map +1 -0
- package/dist/middleware-bundler.d.ts +6 -12
- package/dist/middleware-bundler.d.ts.map +1 -0
- package/dist/middleware-bundler.js +12 -350
- package/dist/middleware-bundler.mjs +11 -347
- 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 -14
- package/dist/middleware-edge.d.mts.map +1 -0
- package/dist/middleware-edge.d.ts +8 -14
- package/dist/middleware-edge.d.ts.map +1 -0
- package/dist/middleware-edge.js +41 -355
- package/dist/middleware-edge.mjs +39 -347
- 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 -27
- package/dist/middleware-node.d.ts +3 -27
- package/dist/middleware-node.js +13 -351
- package/dist/middleware-node.mjs +11 -347
- 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 -165
- package/dist/policy.mjs +183 -152
- 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 -165
- package/dist/session-tracker.mjs +140 -162
- package/dist/session-tracker.mjs.map +1 -0
- package/dist/translate.d.mts +17 -32
- package/dist/translate.d.mts.map +1 -0
- package/dist/translate.d.ts +17 -32
- package/dist/translate.d.ts.map +1 -0
- package/dist/translate.js +69 -34
- package/dist/translate.mjs +68 -31
- 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 +8 -8
- package/dist/config-CleTeeoW.d.mts +0 -233
- package/dist/config-XMOIkxFN.d.ts +0 -233
- package/dist/types-Chgi5TFC.d.mts +0 -105
- package/dist/types-Chgi5TFC.d.ts +0 -105
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @kya-os/checkpoint-nextjs
|
|
2
2
|
|
|
3
|
+
## 1.10.0
|
|
4
|
+
|
|
5
|
+
Picks up the Zod 4 flip through its dependency ranges, plus two behaviour
|
|
6
|
+
changes and a build-tooling swap.
|
|
7
|
+
|
|
8
|
+
### Changed
|
|
9
|
+
|
|
10
|
+
- Dependency ranges move to the Zod 4 family: `@kya-os/checkpoint-shared`
|
|
11
|
+
`^1.3.0` to `^1.4.0`, `@kya-os/checkpoint-wasm-runtime` `^1.8.2` to
|
|
12
|
+
`^1.9.0`, and `@kya-os/checkpoint` `1.2.0` to `1.3.0` (an exact pin, not a
|
|
13
|
+
range). See `@kya-os/checkpoint-shared` 1.4.0 for the validation and
|
|
14
|
+
error-shape changes that come with it. This package's own public surface
|
|
15
|
+
re-exports no Zod object, so nothing Zod-shaped reaches a consumer's
|
|
16
|
+
`.d.ts` from here.
|
|
17
|
+
- Built with `tsdown` instead of `tsup` (#5131). Entrypoints, export
|
|
18
|
+
conditions, and emitted formats are unchanged; this is a toolchain swap,
|
|
19
|
+
but it does regenerate every file in `dist`.
|
|
20
|
+
- A2A Agent Card verification now counts as a verified identity in policy
|
|
21
|
+
context (#4987). `createContextFromDetection` adds
|
|
22
|
+
`verificationMethod === 'a2a'` to the set that marks a request verified,
|
|
23
|
+
alongside `signature`, `tier1_rfc9421`, `kya-http`, and
|
|
24
|
+
`kya-http-delegated`. The engine that emits `'a2a'` ships in
|
|
25
|
+
`@kya-os/checkpoint-wasm-runtime`, and the range above resolves 1.9.0,
|
|
26
|
+
which predates that engine build, so this branch stays inert until a
|
|
27
|
+
wasm-runtime carrying the A2A verifier is published. Behaviour against
|
|
28
|
+
1.9.0 is unchanged.
|
|
29
|
+
- The API middleware now sets `source: 'middleware'` explicitly on the
|
|
30
|
+
detection it logs (#5018). Previously it inherited `logDetection`'s
|
|
31
|
+
default of `'gateway'`, which describes the transport rather than the
|
|
32
|
+
installation, so Next.js API-middleware detections were attributed to the
|
|
33
|
+
gateway in the dashboard. Projects on this path will see their detections
|
|
34
|
+
move from the gateway source to the middleware source.
|
|
35
|
+
|
|
36
|
+
### Documentation
|
|
37
|
+
|
|
38
|
+
- `@default` annotations added across the config surface, and the
|
|
39
|
+
self-justifying comment sweep in #4976 removed stale inline notes. No
|
|
40
|
+
runtime change.
|
|
41
|
+
|
|
42
|
+
### Known issue, pre-existing
|
|
43
|
+
|
|
44
|
+
`require('@kya-os/checkpoint-nextjs/edge')` fails under CommonJS with
|
|
45
|
+
`Package subpath './policy-edge' is not defined by "exports"`. This package
|
|
46
|
+
declares a `require` condition for `./edge`, but that file transitively
|
|
47
|
+
requires `@kya-os/checkpoint-wasm-runtime/policy-edge`, which declares only
|
|
48
|
+
`types`, `edge-runtime`, and `import`. Published 1.9.0 fails the same way, so
|
|
49
|
+
this release does not introduce or worsen it. Bundled Next.js builds resolve
|
|
50
|
+
through the `edge-runtime` condition and are unaffected.
|
|
51
|
+
|
|
3
52
|
## 1.9.0
|
|
4
53
|
|
|
5
54
|
- Add the `@kya-os/checkpoint-nextjs/bundler` entry for applications that bundle the WASM runtime, including the first-party browser integrity lab.
|
|
@@ -9,6 +58,34 @@
|
|
|
9
58
|
Vercel and trusted-proxy forwarding require an explicit profile.
|
|
10
59
|
- Authenticated server-to-server body addresses are normalized only after the
|
|
11
60
|
caller has passed the endpoint authentication boundary.
|
|
61
|
+
- Browser posture verification (#4940). New `browserPosture` option on
|
|
62
|
+
`withCheckpoint`: `{ origin, keyId, publicKey, protectedRoutes, sessionCookieName? }`.
|
|
63
|
+
The ES256 posture token from the beacon's `__Host-checkpoint_posture_<projectId>`
|
|
64
|
+
cookie is verified locally against the pinned public key (exact HTTPS origin,
|
|
65
|
+
`keyId`, `projectId`, 120s lifetime, SHA-256 binding to the beacon session
|
|
66
|
+
cookie) and projected into Cedar as `context.integrity`. The default step-up
|
|
67
|
+
rule challenges only the listed protected routes (exact path, or subtree with
|
|
68
|
+
a trailing `/*`; longest match wins; scopes nonempty and unique) when the
|
|
69
|
+
verified verdict is `agent-driven` and the request carries no verified
|
|
70
|
+
delegation (`attested-bearer` or `delegated`) covering every listed scope.
|
|
71
|
+
- An `agent-driven` verified posture promotes a Human or IncompleteData result to
|
|
72
|
+
`Browser agent (unsigned)` (`ai_agent`, `verificationMethod: 'behavioral'`,
|
|
73
|
+
confidence bounded to 50..85). Posture never supplies identity and never
|
|
74
|
+
creates a Permit.
|
|
75
|
+
- New `resourceOrgDid` and `trustedDelegationRoots` config options: pin the
|
|
76
|
+
consent credential audience and the trusted delegation issuers instead of
|
|
77
|
+
resolving them from project policy.
|
|
78
|
+
- Startup validation: `browserPosture` requires `projectId`, an exact HTTPS
|
|
79
|
+
`origin`, `keyId`, and a public P-256 key (no private scalar); invalid or
|
|
80
|
+
duplicate `protectedRoutes` paths throw. Configuring `protectedRoutes`
|
|
81
|
+
without `resolveDelegationChallenge` throws. Use
|
|
82
|
+
`createBrowserIntegrityChallengeResolver` from
|
|
83
|
+
`@kya-os/checkpoint-wasm-runtime/composed-policy`; a challenge whose
|
|
84
|
+
registered scopes do not cover the required scopes renders 503 rather than a
|
|
85
|
+
fabricated consent link.
|
|
86
|
+
- Applies to the in-process `withCheckpoint` middleware (node, edge, bundler).
|
|
87
|
+
`withCheckpointApi` does not verify posture locally.
|
|
88
|
+
- Entries added after publication. See `docs/runbooks/browser-integrity.md`.
|
|
12
89
|
|
|
13
90
|
## 1.8.0 — fetcher-200 envelope active by default (#3530)
|
|
14
91
|
|
package/dist/adapt.d.mts
CHANGED
|
@@ -1,39 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* D.3 — `RenderedResponse` → `NextResponse` adapter.
|
|
6
|
-
*
|
|
7
|
-
* The host wrapper's *only* job on the outbound path: take the
|
|
8
|
-
* transport-agnostic `RenderedResponse` Phase C's
|
|
9
|
-
* `renderDecisionAsResponse` produces and translate it to a
|
|
10
|
-
* `NextResponse`. Zero verdict decisions, zero engine I/O.
|
|
11
|
-
*
|
|
12
|
-
* Shared between the Node-runtime and Edge-runtime entries. The
|
|
13
|
-
* branching here is identical in both — Next.js `NextResponse` has the
|
|
14
|
-
* same API surface across runtimes; only the underlying response
|
|
15
|
-
* primitive differs (Node http.ServerResponse vs Edge `Response`).
|
|
16
|
-
*
|
|
17
|
-
* Architectural pins per architect § 4.3 / § 4.4:
|
|
18
|
-
*
|
|
19
|
-
* 1. **Verdict-cookie format is contract.** Sites-1's Sonner toast
|
|
20
|
-
* depends on `__checkpoint_verdict=%7B%22verdict%22%3A%22<v>%22...
|
|
21
|
-
* %7D` (single URL-encoded JSON). Byte-format pinned by adapt.test.
|
|
22
|
-
*
|
|
23
|
-
* 2. **HTML-accepting clients → `/blocked` rewrite at status 200**
|
|
24
|
-
* (so the page renders with the verdict cookie set; Sonner picks
|
|
25
|
-
* up the cookie and shows the toast). Non-HTML clients → JSON 4xx.
|
|
26
|
-
*
|
|
27
|
-
* 3. **`X-Checkpoint-Engine` carries `result.engineInfo.name`** —
|
|
28
|
-
* `checkpoint-engine-wasm` after Phase D ships. Brian's Sites-2
|
|
29
|
-
* deviation note confirmed the `X-Checkpoint-*` prefix is canon.
|
|
30
|
-
*/
|
|
31
|
-
|
|
1
|
+
import { RenderedResponse } from "@kya-os/checkpoint-wasm-runtime/orchestrator";
|
|
2
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
3
|
+
//#region src/adapt.d.ts
|
|
32
4
|
/**
|
|
33
5
|
* Convert the engine's transport-agnostic `RenderedResponse` into a
|
|
34
6
|
* `NextResponse`. Sites-1's Playwright suite is the regression gate;
|
|
35
7
|
* any drift here is caught downstream.
|
|
36
8
|
*/
|
|
37
|
-
declare function adaptToNextResponse(rendered: RenderedResponse, req: NextRequest): NextResponse;
|
|
38
|
-
|
|
39
|
-
|
|
9
|
+
export declare function adaptToNextResponse(rendered: RenderedResponse, req: NextRequest): NextResponse;
|
|
10
|
+
//#endregion
|
|
11
|
+
//# sourceMappingURL=adapt.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapt.d.mts","names":[],"sources":["../src/adapt.ts"],"mappings":";;;;;;;;wBA4CgB,oBAAoB,UAAU,kBAAkB,KAAK,cAAc"}
|
package/dist/adapt.d.ts
CHANGED
|
@@ -1,39 +1,11 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from
|
|
2
|
-
import { RenderedResponse } from
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* D.3 — `RenderedResponse` → `NextResponse` adapter.
|
|
6
|
-
*
|
|
7
|
-
* The host wrapper's *only* job on the outbound path: take the
|
|
8
|
-
* transport-agnostic `RenderedResponse` Phase C's
|
|
9
|
-
* `renderDecisionAsResponse` produces and translate it to a
|
|
10
|
-
* `NextResponse`. Zero verdict decisions, zero engine I/O.
|
|
11
|
-
*
|
|
12
|
-
* Shared between the Node-runtime and Edge-runtime entries. The
|
|
13
|
-
* branching here is identical in both — Next.js `NextResponse` has the
|
|
14
|
-
* same API surface across runtimes; only the underlying response
|
|
15
|
-
* primitive differs (Node http.ServerResponse vs Edge `Response`).
|
|
16
|
-
*
|
|
17
|
-
* Architectural pins per architect § 4.3 / § 4.4:
|
|
18
|
-
*
|
|
19
|
-
* 1. **Verdict-cookie format is contract.** Sites-1's Sonner toast
|
|
20
|
-
* depends on `__checkpoint_verdict=%7B%22verdict%22%3A%22<v>%22...
|
|
21
|
-
* %7D` (single URL-encoded JSON). Byte-format pinned by adapt.test.
|
|
22
|
-
*
|
|
23
|
-
* 2. **HTML-accepting clients → `/blocked` rewrite at status 200**
|
|
24
|
-
* (so the page renders with the verdict cookie set; Sonner picks
|
|
25
|
-
* up the cookie and shows the toast). Non-HTML clients → JSON 4xx.
|
|
26
|
-
*
|
|
27
|
-
* 3. **`X-Checkpoint-Engine` carries `result.engineInfo.name`** —
|
|
28
|
-
* `checkpoint-engine-wasm` after Phase D ships. Brian's Sites-2
|
|
29
|
-
* deviation note confirmed the `X-Checkpoint-*` prefix is canon.
|
|
30
|
-
*/
|
|
31
|
-
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { RenderedResponse } from "@kya-os/checkpoint-wasm-runtime/orchestrator";
|
|
3
|
+
//#region src/adapt.d.ts
|
|
32
4
|
/**
|
|
33
5
|
* Convert the engine's transport-agnostic `RenderedResponse` into a
|
|
34
6
|
* `NextResponse`. Sites-1's Playwright suite is the regression gate;
|
|
35
7
|
* any drift here is caught downstream.
|
|
36
8
|
*/
|
|
37
|
-
declare function adaptToNextResponse(rendered: RenderedResponse, req: NextRequest): NextResponse;
|
|
38
|
-
|
|
39
|
-
|
|
9
|
+
export declare function adaptToNextResponse(rendered: RenderedResponse, req: NextRequest): NextResponse;
|
|
10
|
+
//#endregion
|
|
11
|
+
//# sourceMappingURL=adapt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapt.d.ts","names":[],"sources":["../src/adapt.ts"],"mappings":";;;;;;;;wBA4CgB,oBAAoB,UAAU,kBAAkB,KAAK,cAAc"}
|
package/dist/adapt.js
CHANGED
|
@@ -1,59 +1,86 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _kya_os_checkpoint_shared = require("@kya-os/checkpoint-shared");
|
|
3
|
+
let next_server = require("next/server");
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
//#region src/adapt.ts
|
|
6
|
+
/**
|
|
7
|
+
* D.3 — `RenderedResponse` → `NextResponse` adapter.
|
|
8
|
+
*
|
|
9
|
+
* The host wrapper's *only* job on the outbound path: take the
|
|
10
|
+
* transport-agnostic `RenderedResponse` Phase C's
|
|
11
|
+
* `renderDecisionAsResponse` produces and translate it to a
|
|
12
|
+
* `NextResponse`. Zero verdict decisions, zero engine I/O.
|
|
13
|
+
*
|
|
14
|
+
* Shared between the Node-runtime and Edge-runtime entries. The
|
|
15
|
+
* branching here is identical in both — Next.js `NextResponse` has the
|
|
16
|
+
* same API surface across runtimes; only the underlying response
|
|
17
|
+
* primitive differs (Node http.ServerResponse vs Edge `Response`).
|
|
18
|
+
*
|
|
19
|
+
* Architectural pins per architect § 4.3 / § 4.4:
|
|
20
|
+
*
|
|
21
|
+
* 1. **Verdict-cookie format is contract.** Sites-1's Sonner toast
|
|
22
|
+
* depends on `__checkpoint_verdict=%7B%22verdict%22%3A%22<v>%22...
|
|
23
|
+
* %7D` (single URL-encoded JSON). Byte-format pinned by adapt.test.
|
|
24
|
+
*
|
|
25
|
+
* 2. **HTML-accepting clients → `/blocked` rewrite at status 200**
|
|
26
|
+
* (so the page renders with the verdict cookie set; Sonner picks
|
|
27
|
+
* up the cookie and shows the toast). Non-HTML clients → JSON 4xx.
|
|
28
|
+
*
|
|
29
|
+
* 3. **`X-Checkpoint-Engine` carries `result.engineInfo.name`** —
|
|
30
|
+
* `checkpoint-engine-wasm` after Phase D ships. Brian's Sites-2
|
|
31
|
+
* deviation note confirmed the `X-Checkpoint-*` prefix is canon.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Convert the engine's transport-agnostic `RenderedResponse` into a
|
|
35
|
+
* `NextResponse`. Sites-1's Playwright suite is the regression gate;
|
|
36
|
+
* any drift here is caught downstream.
|
|
37
|
+
*/
|
|
7
38
|
function adaptToNextResponse(rendered, req) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
39
|
+
const clientAcceptsHtml = (0, _kya_os_checkpoint_shared.acceptsHtml)(req.headers);
|
|
40
|
+
const verdictCookie = (0, _kya_os_checkpoint_shared.encodeVerdictCookie)(rendered);
|
|
41
|
+
switch ((0, _kya_os_checkpoint_shared.classifyResponseShape)(rendered, clientAcceptsHtml)) {
|
|
42
|
+
case "pass-through": {
|
|
43
|
+
const res = next_server.NextResponse.next();
|
|
44
|
+
applyHeaders(res, rendered);
|
|
45
|
+
setVerdictCookie(res, verdictCookie);
|
|
46
|
+
return res;
|
|
47
|
+
}
|
|
48
|
+
case "redirect": {
|
|
49
|
+
const target = new URL(rendered.headers.Location);
|
|
50
|
+
const res = next_server.NextResponse.redirect(target);
|
|
51
|
+
applyHeaders(res, rendered);
|
|
52
|
+
setVerdictCookie(res, verdictCookie);
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
case "html-block": {
|
|
56
|
+
const blockedUrl = new URL(_kya_os_checkpoint_shared.BLOCKED_PATH, req.url);
|
|
57
|
+
const res = next_server.NextResponse.rewrite(blockedUrl, { status: 200 });
|
|
58
|
+
applyHeaders(res, rendered);
|
|
59
|
+
setVerdictCookie(res, verdictCookie);
|
|
60
|
+
return res;
|
|
61
|
+
}
|
|
62
|
+
case "json-block": {
|
|
63
|
+
const body = rendered.body ?? {};
|
|
64
|
+
const res = next_server.NextResponse.json(body, { status: rendered.status });
|
|
65
|
+
applyHeaders(res, rendered);
|
|
66
|
+
setVerdictCookie(res, verdictCookie);
|
|
67
|
+
return res;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
40
70
|
}
|
|
41
71
|
function setVerdictCookie(res, value) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
res.cookies.set({
|
|
73
|
+
name: _kya_os_checkpoint_shared.VERDICT_COOKIE_NAME,
|
|
74
|
+
value,
|
|
75
|
+
path: "/",
|
|
76
|
+
sameSite: "lax",
|
|
77
|
+
httpOnly: false
|
|
78
|
+
});
|
|
49
79
|
}
|
|
50
80
|
function applyHeaders(res, rendered) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
for (const [key, value] of rendered.headerEntries ?? []) {
|
|
55
|
-
res.headers.append(key, value);
|
|
56
|
-
}
|
|
81
|
+
for (const [key, value] of Object.entries(rendered.headers)) res.headers.set(key, value);
|
|
82
|
+
for (const [key, value] of rendered.headerEntries ?? []) res.headers.append(key, value);
|
|
57
83
|
}
|
|
58
84
|
|
|
59
|
-
|
|
85
|
+
//#endregion
|
|
86
|
+
exports.adaptToNextResponse = adaptToNextResponse;
|
package/dist/adapt.mjs
CHANGED
|
@@ -1,57 +1,86 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { BLOCKED_PATH, VERDICT_COOKIE_NAME, acceptsHtml, classifyResponseShape, encodeVerdictCookie } from "@kya-os/checkpoint-shared";
|
|
2
|
+
import { NextResponse } from "next/server";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
//#region src/adapt.ts
|
|
5
|
+
/**
|
|
6
|
+
* D.3 — `RenderedResponse` → `NextResponse` adapter.
|
|
7
|
+
*
|
|
8
|
+
* The host wrapper's *only* job on the outbound path: take the
|
|
9
|
+
* transport-agnostic `RenderedResponse` Phase C's
|
|
10
|
+
* `renderDecisionAsResponse` produces and translate it to a
|
|
11
|
+
* `NextResponse`. Zero verdict decisions, zero engine I/O.
|
|
12
|
+
*
|
|
13
|
+
* Shared between the Node-runtime and Edge-runtime entries. The
|
|
14
|
+
* branching here is identical in both — Next.js `NextResponse` has the
|
|
15
|
+
* same API surface across runtimes; only the underlying response
|
|
16
|
+
* primitive differs (Node http.ServerResponse vs Edge `Response`).
|
|
17
|
+
*
|
|
18
|
+
* Architectural pins per architect § 4.3 / § 4.4:
|
|
19
|
+
*
|
|
20
|
+
* 1. **Verdict-cookie format is contract.** Sites-1's Sonner toast
|
|
21
|
+
* depends on `__checkpoint_verdict=%7B%22verdict%22%3A%22<v>%22...
|
|
22
|
+
* %7D` (single URL-encoded JSON). Byte-format pinned by adapt.test.
|
|
23
|
+
*
|
|
24
|
+
* 2. **HTML-accepting clients → `/blocked` rewrite at status 200**
|
|
25
|
+
* (so the page renders with the verdict cookie set; Sonner picks
|
|
26
|
+
* up the cookie and shows the toast). Non-HTML clients → JSON 4xx.
|
|
27
|
+
*
|
|
28
|
+
* 3. **`X-Checkpoint-Engine` carries `result.engineInfo.name`** —
|
|
29
|
+
* `checkpoint-engine-wasm` after Phase D ships. Brian's Sites-2
|
|
30
|
+
* deviation note confirmed the `X-Checkpoint-*` prefix is canon.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Convert the engine's transport-agnostic `RenderedResponse` into a
|
|
34
|
+
* `NextResponse`. Sites-1's Playwright suite is the regression gate;
|
|
35
|
+
* any drift here is caught downstream.
|
|
36
|
+
*/
|
|
5
37
|
function adaptToNextResponse(rendered, req) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
+
const clientAcceptsHtml = acceptsHtml(req.headers);
|
|
39
|
+
const verdictCookie = encodeVerdictCookie(rendered);
|
|
40
|
+
switch (classifyResponseShape(rendered, clientAcceptsHtml)) {
|
|
41
|
+
case "pass-through": {
|
|
42
|
+
const res = NextResponse.next();
|
|
43
|
+
applyHeaders(res, rendered);
|
|
44
|
+
setVerdictCookie(res, verdictCookie);
|
|
45
|
+
return res;
|
|
46
|
+
}
|
|
47
|
+
case "redirect": {
|
|
48
|
+
const target = new URL(rendered.headers.Location);
|
|
49
|
+
const res = NextResponse.redirect(target);
|
|
50
|
+
applyHeaders(res, rendered);
|
|
51
|
+
setVerdictCookie(res, verdictCookie);
|
|
52
|
+
return res;
|
|
53
|
+
}
|
|
54
|
+
case "html-block": {
|
|
55
|
+
const blockedUrl = new URL(BLOCKED_PATH, req.url);
|
|
56
|
+
const res = NextResponse.rewrite(blockedUrl, { status: 200 });
|
|
57
|
+
applyHeaders(res, rendered);
|
|
58
|
+
setVerdictCookie(res, verdictCookie);
|
|
59
|
+
return res;
|
|
60
|
+
}
|
|
61
|
+
case "json-block": {
|
|
62
|
+
const body = rendered.body ?? {};
|
|
63
|
+
const res = NextResponse.json(body, { status: rendered.status });
|
|
64
|
+
applyHeaders(res, rendered);
|
|
65
|
+
setVerdictCookie(res, verdictCookie);
|
|
66
|
+
return res;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
38
69
|
}
|
|
39
70
|
function setVerdictCookie(res, value) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
71
|
+
res.cookies.set({
|
|
72
|
+
name: VERDICT_COOKIE_NAME,
|
|
73
|
+
value,
|
|
74
|
+
path: "/",
|
|
75
|
+
sameSite: "lax",
|
|
76
|
+
httpOnly: false
|
|
77
|
+
});
|
|
47
78
|
}
|
|
48
79
|
function applyHeaders(res, rendered) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
for (const [key, value] of rendered.headerEntries ?? []) {
|
|
53
|
-
res.headers.append(key, value);
|
|
54
|
-
}
|
|
80
|
+
for (const [key, value] of Object.entries(rendered.headers)) res.headers.set(key, value);
|
|
81
|
+
for (const [key, value] of rendered.headerEntries ?? []) res.headers.append(key, value);
|
|
55
82
|
}
|
|
56
83
|
|
|
84
|
+
//#endregion
|
|
57
85
|
export { adaptToNextResponse };
|
|
86
|
+
//# sourceMappingURL=adapt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapt.mjs","names":[],"sources":["../src/adapt.ts"],"sourcesContent":["/**\n * D.3 — `RenderedResponse` → `NextResponse` adapter.\n *\n * The host wrapper's *only* job on the outbound path: take the\n * transport-agnostic `RenderedResponse` Phase C's\n * `renderDecisionAsResponse` produces and translate it to a\n * `NextResponse`. Zero verdict decisions, zero engine I/O.\n *\n * Shared between the Node-runtime and Edge-runtime entries. The\n * branching here is identical in both — Next.js `NextResponse` has the\n * same API surface across runtimes; only the underlying response\n * primitive differs (Node http.ServerResponse vs Edge `Response`).\n *\n * Architectural pins per architect § 4.3 / § 4.4:\n *\n * 1. **Verdict-cookie format is contract.** Sites-1's Sonner toast\n * depends on `__checkpoint_verdict=%7B%22verdict%22%3A%22<v>%22...\n * %7D` (single URL-encoded JSON). Byte-format pinned by adapt.test.\n *\n * 2. **HTML-accepting clients → `/blocked` rewrite at status 200**\n * (so the page renders with the verdict cookie set; Sonner picks\n * up the cookie and shows the toast). Non-HTML clients → JSON 4xx.\n *\n * 3. **`X-Checkpoint-Engine` carries `result.engineInfo.name`** —\n * `checkpoint-engine-wasm` after Phase D ships. Brian's Sites-2\n * deviation note confirmed the `X-Checkpoint-*` prefix is canon.\n */\n\nimport { type NextRequest, NextResponse } from 'next/server';\n\nimport type { RenderedResponse } from '@kya-os/checkpoint-wasm-runtime/orchestrator';\nimport {\n VERDICT_COOKIE_NAME,\n BLOCKED_PATH,\n encodeVerdictCookie,\n acceptsHtml,\n classifyResponseShape,\n} from '@kya-os/checkpoint-shared';\n\n/**\n * Convert the engine's transport-agnostic `RenderedResponse` into a\n * `NextResponse`. Sites-1's Playwright suite is the regression gate;\n * any drift here is caught downstream.\n */\nexport function adaptToNextResponse(rendered: RenderedResponse, req: NextRequest): NextResponse {\n const clientAcceptsHtml = acceptsHtml(req.headers);\n const verdictCookie = encodeVerdictCookie(rendered);\n const shape = classifyResponseShape(rendered, clientAcceptsHtml);\n\n switch (shape) {\n case 'pass-through': {\n // Permit OR Observe-mode any-verdict.\n const res = NextResponse.next();\n applyHeaders(res, rendered);\n setVerdictCookie(res, verdictCookie);\n return res;\n }\n\n case 'redirect': {\n // Decision::Redirect → 302 + Location.\n const target = new URL(rendered.headers.Location!);\n const res = NextResponse.redirect(target);\n applyHeaders(res, rendered);\n setVerdictCookie(res, verdictCookie);\n return res;\n }\n\n case 'html-block': {\n // Sites-1 contract: HTML clients (browsers) need a renderable page\n // to show the rejection UI. The verdict cookie carries the reason;\n // the /blocked route reads it and renders the toast.\n const blockedUrl = new URL(BLOCKED_PATH, req.url);\n const res = NextResponse.rewrite(blockedUrl, { status: 200 });\n applyHeaders(res, rendered);\n setVerdictCookie(res, verdictCookie);\n return res;\n }\n\n case 'json-block': {\n // The orchestrator's RenderedResponse already supplies the correct\n // status (401/403/422/...); we just need to materialise the body.\n // application/problem+json (Instruct) uses the Content-Type from\n // rendered.headers; defaults to application/json for everything else.\n const body = rendered.body ?? {};\n const res = NextResponse.json(body, { status: rendered.status as number });\n applyHeaders(res, rendered);\n setVerdictCookie(res, verdictCookie);\n return res;\n }\n }\n}\n\n// -----------------------------------------------------------------------------\n// Helpers — Next.js-specific glue. The framework-agnostic primitives\n// (encodeVerdictCookie, acceptsHtml, classifyResponseShape,\n// VERDICT_COOKIE_NAME, BLOCKED_PATH) live in `@kya-os/checkpoint-shared`\n// so checkpoint-express + future host wrappers produce byte-identical\n// cookies and route HTML/JSON branching the same way.\n// -----------------------------------------------------------------------------\n\nfunction setVerdictCookie(res: NextResponse, value: string): void {\n // Path / SameSite / HttpOnly chosen for the Sonner-bridge use case:\n // path=/ so any route can read it, SameSite=Lax so first-party\n // navigations carry it, HttpOnly=false so the client-side toast JS\n // can read it (it's verdict UX, not a session token).\n res.cookies.set({\n name: VERDICT_COOKIE_NAME,\n value,\n path: '/',\n sameSite: 'lax',\n httpOnly: false,\n });\n}\n\nfunction applyHeaders(res: NextResponse, rendered: RenderedResponse): void {\n // NextResponse.next() / rewrite() / json() return responses with\n // some default headers; orchestrator headers (X-Checkpoint-*, Location)\n // override. We don't strip pre-existing headers — only set new ones.\n for (const [key, value] of Object.entries(rendered.headers)) {\n res.headers.set(key, value);\n }\n for (const [key, value] of rendered.headerEntries ?? []) {\n res.headers.append(key, value);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,oBAAoB,UAA4B,KAAgC;CAC9F,MAAM,oBAAoB,YAAY,IAAI,OAAO;CACjD,MAAM,gBAAgB,oBAAoB,QAAQ;CAGlD,QAFc,sBAAsB,UAAU,iBAElC,GAAZ;EACE,KAAK,gBAAgB;GAEnB,MAAM,MAAM,aAAa,KAAK;GAC9B,aAAa,KAAK,QAAQ;GAC1B,iBAAiB,KAAK,aAAa;GACnC,OAAO;EACT;EAEA,KAAK,YAAY;GAEf,MAAM,SAAS,IAAI,IAAI,SAAS,QAAQ,QAAS;GACjD,MAAM,MAAM,aAAa,SAAS,MAAM;GACxC,aAAa,KAAK,QAAQ;GAC1B,iBAAiB,KAAK,aAAa;GACnC,OAAO;EACT;EAEA,KAAK,cAAc;GAIjB,MAAM,aAAa,IAAI,IAAI,cAAc,IAAI,GAAG;GAChD,MAAM,MAAM,aAAa,QAAQ,YAAY,EAAE,QAAQ,IAAI,CAAC;GAC5D,aAAa,KAAK,QAAQ;GAC1B,iBAAiB,KAAK,aAAa;GACnC,OAAO;EACT;EAEA,KAAK,cAAc;GAKjB,MAAM,OAAO,SAAS,QAAQ,CAAC;GAC/B,MAAM,MAAM,aAAa,KAAK,MAAM,EAAE,QAAQ,SAAS,OAAiB,CAAC;GACzE,aAAa,KAAK,QAAQ;GAC1B,iBAAiB,KAAK,aAAa;GACnC,OAAO;EACT;CACF;AACF;AAUA,SAAS,iBAAiB,KAAmB,OAAqB;CAKhE,IAAI,QAAQ,IAAI;EACd,MAAM;EACN;EACA,MAAM;EACN,UAAU;EACV,UAAU;CACZ,CAAC;AACH;AAEA,SAAS,aAAa,KAAmB,UAAkC;CAIzE,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,OAAO,GACxD,IAAI,QAAQ,IAAI,KAAK,KAAK;CAE5B,KAAK,MAAM,CAAC,KAAK,UAAU,SAAS,iBAAiB,CAAC,GACpD,IAAI,QAAQ,OAAO,KAAK,KAAK;AAEjC"}
|