@kya-os/checkpoint-nextjs 1.9.0 → 1.11.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 (156) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/README.md +205 -31
  3. package/dist/adapt-BdQ9R7Iw.mjs +97 -0
  4. package/dist/adapt-BdQ9R7Iw.mjs.map +1 -0
  5. package/dist/adapt-CCSKGjVH.js +107 -0
  6. package/dist/api-client-JHOrRUA_.d.mts +222 -0
  7. package/dist/api-client-JHOrRUA_.d.mts.map +1 -0
  8. package/dist/api-client-JHOrRUA_.d.ts +222 -0
  9. package/dist/api-client-JHOrRUA_.d.ts.map +1 -0
  10. package/dist/api-client.d.mts +2 -213
  11. package/dist/api-client.d.ts +2 -213
  12. package/dist/api-client.js +221 -206
  13. package/dist/api-client.mjs +222 -202
  14. package/dist/api-client.mjs.map +1 -0
  15. package/dist/api-middleware-BWjokNis.d.mts +131 -0
  16. package/dist/api-middleware-BWjokNis.d.mts.map +1 -0
  17. package/dist/api-middleware-Bf3xmM9W.js +391 -0
  18. package/dist/api-middleware-C-ngFX_8.mjs +387 -0
  19. package/dist/api-middleware-C-ngFX_8.mjs.map +1 -0
  20. package/dist/api-middleware-DyLDqOYF.d.ts +131 -0
  21. package/dist/api-middleware-DyLDqOYF.d.ts.map +1 -0
  22. package/dist/api-middleware.d.mts +2 -166
  23. package/dist/api-middleware.d.ts +2 -166
  24. package/dist/api-middleware.js +3 -526
  25. package/dist/api-middleware.mjs +2 -521
  26. package/dist/cedar-wasm.d.mts +20 -0
  27. package/dist/cedar-wasm.d.mts.map +1 -0
  28. package/dist/cedar-wasm.d.ts +19 -0
  29. package/dist/cedar-wasm.d.ts.map +1 -0
  30. package/dist/cedar-wasm.js +24 -0
  31. package/dist/cedar-wasm.mjs +23 -0
  32. package/dist/cedar-wasm.mjs.map +1 -0
  33. package/dist/config-CPP1RV0f.d.mts +291 -0
  34. package/dist/config-CPP1RV0f.d.mts.map +1 -0
  35. package/dist/config-DVgOFxJs.d.ts +291 -0
  36. package/dist/config-DVgOFxJs.d.ts.map +1 -0
  37. package/dist/engine-wasm.d.mts +20 -0
  38. package/dist/engine-wasm.d.mts.map +1 -0
  39. package/dist/engine-wasm.d.ts +19 -0
  40. package/dist/engine-wasm.d.ts.map +1 -0
  41. package/dist/engine-wasm.js +24 -0
  42. package/dist/engine-wasm.mjs +23 -0
  43. package/dist/engine-wasm.mjs.map +1 -0
  44. package/dist/index-edge.d.mts +8 -0
  45. package/dist/index-edge.d.ts +8 -0
  46. package/dist/index-edge.js +14 -0
  47. package/dist/index-edge.mjs +7 -0
  48. package/dist/index.d.mts +8 -17
  49. package/dist/index.d.ts +8 -17
  50. package/dist/index.js +36 -1275
  51. package/dist/index.mjs +29 -1234
  52. package/dist/index.mjs.map +1 -0
  53. package/dist/middleware-bundler.d.mts +6 -12
  54. package/dist/middleware-bundler.d.mts.map +1 -0
  55. package/dist/middleware-bundler.d.ts +6 -12
  56. package/dist/middleware-bundler.d.ts.map +1 -0
  57. package/dist/middleware-bundler.js +12 -350
  58. package/dist/middleware-bundler.mjs +11 -347
  59. package/dist/middleware-bundler.mjs.map +1 -0
  60. package/dist/middleware-core-B0jf5_Hm.mjs +264 -0
  61. package/dist/middleware-core-B0jf5_Hm.mjs.map +1 -0
  62. package/dist/middleware-core-Bol44X9C.d.ts +17 -0
  63. package/dist/middleware-core-Bol44X9C.d.ts.map +1 -0
  64. package/dist/middleware-core-CMc-2QkU.js +274 -0
  65. package/dist/middleware-core-DycsbHUd.d.mts +17 -0
  66. package/dist/middleware-core-DycsbHUd.d.mts.map +1 -0
  67. package/dist/middleware-edge.d.mts +16 -14
  68. package/dist/middleware-edge.d.mts.map +1 -0
  69. package/dist/middleware-edge.d.ts +16 -14
  70. package/dist/middleware-edge.d.ts.map +1 -0
  71. package/dist/middleware-edge.js +94 -355
  72. package/dist/middleware-edge.mjs +90 -347
  73. package/dist/middleware-edge.mjs.map +1 -0
  74. package/dist/middleware-node-context-591KsiYg.js +39 -0
  75. package/dist/middleware-node-context-D_ZyUEcA.mjs +35 -0
  76. package/dist/middleware-node-context-D_ZyUEcA.mjs.map +1 -0
  77. package/dist/middleware-node.d.mts +10 -25
  78. package/dist/middleware-node.d.mts.map +1 -0
  79. package/dist/middleware-node.d.ts +10 -25
  80. package/dist/middleware-node.d.ts.map +1 -0
  81. package/dist/middleware-node.js +21 -351
  82. package/dist/middleware-node.mjs +19 -347
  83. package/dist/middleware-node.mjs.map +1 -0
  84. package/dist/posture-outcome-Ccujx_9V.d.mts +14 -0
  85. package/dist/posture-outcome-Ccujx_9V.d.mts.map +1 -0
  86. package/dist/posture-outcome-Ccujx_9V.d.ts +14 -0
  87. package/dist/posture-outcome-Ccujx_9V.d.ts.map +1 -0
  88. package/dist/posture-outcome-DQ4fdMfq.mjs +21 -0
  89. package/dist/posture-outcome-DQ4fdMfq.mjs.map +1 -0
  90. package/dist/posture-outcome-DddsJtL8.js +25 -0
  91. package/dist/public-api-CYsHrTQI.d.ts +5 -0
  92. package/dist/public-api-DkG7pRE0.d.mts +5 -0
  93. package/dist/rolldown-runtime-C24Yb2bl.js +33 -0
  94. package/dist/utils-Cnwg0VrY.mjs +88 -0
  95. package/dist/utils-Cnwg0VrY.mjs.map +1 -0
  96. package/dist/utils-dyFxqlFI.js +104 -0
  97. package/package.json +31 -66
  98. package/EDGE_RUNTIME_WASM_SETUP.md +0 -342
  99. package/bin/setup-edge-wasm.js +0 -513
  100. package/dist/adapt.d.mts +0 -39
  101. package/dist/adapt.d.ts +0 -39
  102. package/dist/adapt.js +0 -59
  103. package/dist/adapt.mjs +0 -57
  104. package/dist/composed-policy.d.mts +0 -115
  105. package/dist/composed-policy.d.ts +0 -115
  106. package/dist/composed-policy.js +0 -103
  107. package/dist/composed-policy.mjs +0 -97
  108. package/dist/config-CleTeeoW.d.mts +0 -233
  109. package/dist/config-XMOIkxFN.d.ts +0 -233
  110. package/dist/create-middleware.d.mts +0 -22
  111. package/dist/create-middleware.d.ts +0 -22
  112. package/dist/create-middleware.js +0 -34
  113. package/dist/create-middleware.mjs +0 -31
  114. package/dist/edge/index.d.mts +0 -112
  115. package/dist/edge/index.d.ts +0 -112
  116. package/dist/edge/index.js +0 -277
  117. package/dist/edge/index.mjs +0 -275
  118. package/dist/edge-runtime-loader.d.mts +0 -77
  119. package/dist/edge-runtime-loader.d.ts +0 -77
  120. package/dist/edge-runtime-loader.js +0 -242
  121. package/dist/edge-runtime-loader.mjs +0 -235
  122. package/dist/edge-wasm-middleware.d.mts +0 -62
  123. package/dist/edge-wasm-middleware.d.ts +0 -62
  124. package/dist/edge-wasm-middleware.js +0 -26
  125. package/dist/edge-wasm-middleware.mjs +0 -22
  126. package/dist/middleware.d.mts +0 -45
  127. package/dist/middleware.d.ts +0 -45
  128. package/dist/middleware.js +0 -19
  129. package/dist/middleware.mjs +0 -15
  130. package/dist/nodejs-wasm-loader.d.mts +0 -41
  131. package/dist/nodejs-wasm-loader.d.ts +0 -41
  132. package/dist/nodejs-wasm-loader.js +0 -36
  133. package/dist/nodejs-wasm-loader.mjs +0 -30
  134. package/dist/policy.d.mts +0 -162
  135. package/dist/policy.d.ts +0 -162
  136. package/dist/policy.js +0 -198
  137. package/dist/policy.mjs +0 -174
  138. package/dist/session-tracker.d.mts +0 -55
  139. package/dist/session-tracker.d.ts +0 -55
  140. package/dist/session-tracker.js +0 -172
  141. package/dist/session-tracker.mjs +0 -169
  142. package/dist/translate.d.mts +0 -63
  143. package/dist/translate.d.ts +0 -63
  144. package/dist/translate.js +0 -44
  145. package/dist/translate.mjs +0 -42
  146. package/dist/types-Chgi5TFC.d.mts +0 -105
  147. package/dist/types-Chgi5TFC.d.ts +0 -105
  148. package/dist/wasm-setup.d.mts +0 -46
  149. package/dist/wasm-setup.d.ts +0 -46
  150. package/dist/wasm-setup.js +0 -122
  151. package/dist/wasm-setup.mjs +0 -118
  152. package/wasm/agentshield_wasm.d.ts +0 -479
  153. package/wasm/agentshield_wasm.js +0 -1536
  154. package/wasm/agentshield_wasm_bg.wasm +0 -0
  155. package/wasm/package.json +0 -30
  156. package/wasm.d.ts +0 -21
@@ -0,0 +1,291 @@
1
+ import { BrowserPostureConfig } from "@kya-os/checkpoint-shared/browser-posture";
2
+ import { ComposedPolicyContext, RequestClaimStore } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
3
+ import { DidResolverAdapter, PolicyEvaluatorAdapter, ReputationOracleAdapter, StatusListCacheAdapter } from "@kya-os/checkpoint-wasm-runtime/adapters";
4
+ import { NextRequest } from "next/server.js";
5
+ import { ChallengeContextFailureEvent, ChallengeEnvelopeMode, ChallengeWireInput, ClientIpTrustPolicy } from "@kya-os/checkpoint-shared";
6
+ import { EnforcementMode, EngineConfig, VerifyResult } from "@kya-os/checkpoint-wasm-runtime/engine";
7
+ //#region src/config.d.ts
8
+ /**
9
+ * Configuration for `withCheckpoint`.
10
+ */
11
+ interface CheckpointConfig {
12
+ /**
13
+ * Selects the infrastructure allowed to vouch for observed client addresses.
14
+ * Vercel headers are honored only inside its managed runtime (`VERCEL=1`).
15
+ * NextRequest exposes no socket peer, so generic proxy and Cloudflare origin
16
+ * profiles cannot authenticate that boundary and return no address. Use a
17
+ * transport-aware ingress, such as the Express adapter, for those profiles.
18
+ */
19
+ clientIpPolicy?: ClientIpTrustPolicy;
20
+ /**
21
+ * Tenant identifier — typically the customer's dashboard hostname
22
+ * (e.g. `acme.checkpoint.example`). The PolicyEvaluator uses this
23
+ * to look up tenant policy from the dashboard.
24
+ */
25
+ tenantHost: string;
26
+ /** Exact org DID used to verify the consent credential's audience. */
27
+ resourceOrgDid?: string;
28
+ /** Explicit trusted delegation issuers; otherwise resolved from project policy. */
29
+ trustedDelegationRoots?: string[];
30
+ /**
31
+ * `'enforce'` (default) blocks; `'observe'` passes everything
32
+ * through with `X-Checkpoint-Would-Have-Been` headers. Per Phase 0.2.
33
+ *
34
+ * @default 'enforce'
35
+ */
36
+ enforcementMode?: EnforcementMode;
37
+ /**
38
+ * Challenge-emission envelope mode (draft-kya-http-02 §8.1 fetcher-200).
39
+ * `negotiated` serves a body-readable HTTP 200 step-up response to
40
+ * cooperative agents (fetchers that drop 4xx/5xx bodies), keeping the spec
41
+ * 401/422 for everyone else. Defaults to `negotiated` (#3530). A cooperative-UX
42
+ * bridge, NOT an access control.
43
+ *
44
+ * @default 'negotiated'
45
+ */
46
+ delegationChallengeMode?: ChallengeEnvelopeMode;
47
+ /**
48
+ * Resolve a policy `Challenge`, or a block consent can remedy, into registered wire context.
49
+ * The callback performs any Authorization-Host registration asynchronously;
50
+ * the synchronous engine renderer never fabricates a sid, consent URI, or proof.
51
+ */
52
+ resolveDelegationChallenge?: (context: {
53
+ result: VerifyResult;
54
+ request: NextRequest;
55
+ }) => ChallengeWireInput | undefined | Promise<ChallengeWireInput | undefined>;
56
+ /**
57
+ * Registration/resolution budget in milliseconds.
58
+ *
59
+ * @default 3000
60
+ */
61
+ delegationChallengeTimeoutMs?: number;
62
+ /** Sanitized registration failure hook for metrics and operator warnings. */
63
+ onDelegationChallengeFailure?: (event: ChallengeContextFailureEvent) => void;
64
+ /**
65
+ * Argus reputation oracle base URL. Omit to use the trust-by-default
66
+ * baseline (reputation defaults to 1.0; orchestrator logs a one-shot
67
+ * warning at first request).
68
+ */
69
+ argusUrl?: string;
70
+ /**
71
+ * Dashboard base URL for the composed policy fetch
72
+ * (`<dashboardUrl>/api/internal/policies/{projectId}`). Takes precedence over
73
+ * `baseUrl`; omit both to use the hosted dashboard.
74
+ */
75
+ dashboardUrl?: string;
76
+ /**
77
+ * Returned to the PolicyEvaluator for anonymous requests (no agent
78
+ * DID). Trust-by-default. Engine scale is `0.0` to `1.0`.
79
+ *
80
+ * @default 1.0
81
+ */
82
+ reputationBaseline?: number;
83
+ /**
84
+ * Pre-built adapter instances. Production deployments use the
85
+ * factory-built defaults from `@kya-os/checkpoint-wasm-runtime/adapters`;
86
+ * tests use stubs. The factory composes any provided overrides over
87
+ * defaults — partial overrides are supported.
88
+ */
89
+ adapters?: Partial<{
90
+ didResolver: DidResolverAdapter;
91
+ statusListCache: StatusListCacheAdapter;
92
+ reputationOracle: ReputationOracleAdapter;
93
+ policyEvaluator: PolicyEvaluatorAdapter;
94
+ }>;
95
+ /**
96
+ * Optional callback for the post-verdict path — fires after every
97
+ * verification, regardless of permit/block, with the full
98
+ * `VerifyResult`. Use for logging, dashboards, telemetry. Errors
99
+ * thrown here are swallowed so user code can't break the middleware
100
+ * response.
101
+ */
102
+ onResult?: (result: VerifyResult, req: NextRequest) => void | Promise<void>;
103
+ /**
104
+ * Accept legacy `KYA-Delegation`-header envelope form alongside the
105
+ * canonical `_meta.proof.jws` body form. Default `false`.
106
+ *
107
+ * **When to enable** — customers whose agents pre-date Envelope-1
108
+ * (#2537) and ship KYA-OS proofs as `{protected,payload,signature}`
109
+ * JSON in a `KYA-Delegation` HTTP header. Post-Envelope-1 agents
110
+ * ship compact JWS in the request body's `_meta.proof.jws` field;
111
+ * those don't need this flag.
112
+ *
113
+ * Forwarded to the orchestrator's `VerifyRequestOpts.legacyEnvelopeFallback`.
114
+ * Both transports (header + body) are honored when this is `true`;
115
+ * the orchestrator's detection order is body first, then header
116
+ * (`packages/checkpoint-wasm-runtime/src/engine/orchestrator/build-agent-request.ts`).
117
+ *
118
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
119
+ *
120
+ * @default false
121
+ */
122
+ legacyEnvelopeFallback?: boolean;
123
+ /**
124
+ * Read the request body when `content-type` is `application/json` so
125
+ * the orchestrator can extract a KYA-OS envelope from
126
+ * `_meta.proof.jws`. Default `true`.
127
+ *
128
+ * **When to disable** — streaming middlewares that can't tolerate
129
+ * the `req.clone()` memory overhead (one full-body copy is buffered
130
+ * during the read). For those, set `false` and route KYA-OS
131
+ * envelopes through the `KYA-Delegation` header transport instead
132
+ * (requires `legacyEnvelopeFallback: true`).
133
+ *
134
+ * The clone preserves `req.body` for downstream handlers — disabling
135
+ * is a performance optimization, not a correctness fix.
136
+ *
137
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
138
+ *
139
+ * @default true
140
+ */
141
+ drainJsonBody?: boolean;
142
+ /**
143
+ * Engine-default behaviour knobs forwarded to every composed
144
+ * `ContextSpec`. Defaults to `{ tier3Action: 'monitor' }` —
145
+ * customer-onboarding-safe (tenant policy decides; engine doesn't
146
+ * short-circuit known-agent UAs with an engine-default Block).
147
+ *
148
+ * Opt into `{ tier3Action: 'block' }` when the host wants the
149
+ * calibrated engine-default block for KnownAiAgent / AiCrawler /
150
+ * HeadlessBrowser classifications BEFORE the tenant policy seam.
151
+ *
152
+ * Added in `@kya-os/checkpoint-nextjs@1.2.0` (Engine-Tier3-Monitor-
153
+ * Default, #2653 + this PR's plumbing follow-up).
154
+ *
155
+ * @default { tier3Action: 'monitor' }
156
+ */
157
+ engineConfig?: EngineConfig;
158
+ /**
159
+ * Project API key. Required for detections to land in the dashboard
160
+ * — the engine verifies in-process via WASM, but the resulting
161
+ * `VerifyResult` only reaches the dashboard's `detections` table
162
+ * when this reporter is configured. Without it the verdict path
163
+ * works locally but the onboarding "Verify connection" check fails
164
+ * forever because no rows are ever written.
165
+ *
166
+ * Resolve from `process.env.CHECKPOINT_API_KEY` in the host app.
167
+ *
168
+ * Added in `@kya-os/checkpoint-nextjs@1.4.0`
169
+ * (SDK-Detection-Reporter-1).
170
+ */
171
+ apiKey?: string;
172
+ /**
173
+ * Dashboard base URL. Override for staging or self-hosted dashboards.
174
+ *
175
+ * @default 'https://kya.vouched.id'
176
+ */
177
+ baseUrl?: string;
178
+ /**
179
+ * Surface reporter errors via `console.warn`. Defaults to `false`.
180
+ * The reporter is fire-and-forget; enable during development to
181
+ * confirm `apiKey` / `baseUrl` are routed correctly.
182
+ *
183
+ * Also wires the composed-policy shadow-divergence + evaluation-error
184
+ * telemetry, and pipeline-failure logging (the 503 fail-closed path), to
185
+ * `console.warn`/`console.error` (otherwise silent).
186
+ *
187
+ * @default false
188
+ */
189
+ debug?: boolean;
190
+ /**
191
+ * Project id whose composed (/policy-compose) policy this middleware
192
+ * enforces. When set, the project's policy is fetched from the dashboard
193
+ * (`<dashboardUrl ?? baseUrl ?? default>/api/internal/policies/${projectId}`)
194
+ * and — if it carries a deployed Cedar bundle with `engineEnforcementEnabled`
195
+ * on — the kya-os-engine decision is enforced IN-PROCESS, byte-for-byte the
196
+ * same as the DNS Gateway. Omit to run detection + the structured policy only
197
+ * (fully back-compatible; purely additive).
198
+ *
199
+ * SHADOW-FIRST: with a deployed bundle but `engineEnforcementEnabled` off, the
200
+ * engine decision is computed + logged on divergence but does NOT act.
201
+ *
202
+ * **Node vs Edge:** composed enforcement is default-on under the Node runtime
203
+ * (`./node`). Under the Edge runtime (`./edge`) it additionally requires
204
+ * `cedarWasmModule` to be wired (see below) — otherwise the seam stays inert.
205
+ *
206
+ * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
207
+ */
208
+ projectId?: string;
209
+ /** Signed browser risk; configure explicit route scopes to enable consent step-up. */
210
+ browserPosture?: BrowserPostureConfig;
211
+ /**
212
+ * Where accepted signed requests are claimed, so each is used once. Defaults
213
+ * to the dashboard's shared ledger when `apiKey` and `projectId` are set,
214
+ * otherwise to a store in this process or isolate (with a one-time warning,
215
+ * since a deployment with several instances needs a shared store). Pass
216
+ * `createLocalRequestClaimStore()` to choose the in-process store explicitly.
217
+ */
218
+ requestClaimStore?: RequestClaimStore;
219
+ /**
220
+ * Policy-fetch cache TTL in seconds. Defaults to 300 (5 minutes). How long
221
+ * a fetched project policy is reused before the middleware refetches from
222
+ * the dashboard — i.e. the worst-case delay before a dashboard policy
223
+ * change takes effect on this host.
224
+ *
225
+ * `0` disables reuse entirely: every request fetches the policy (one
226
+ * origin round-trip per request). Use for demo/example sites where instant
227
+ * policy propagation matters more than latency; keep the default (or a
228
+ * small positive value like 5) for production and benchmark hosts.
229
+ *
230
+ * @default 300
231
+ */
232
+ policyCacheTtlSeconds?: number;
233
+ /**
234
+ * Advanced / testing: inject a pre-built composed-policy context instead of
235
+ * letting `withCheckpoint` construct one from `projectId` + `baseUrl` +
236
+ * `apiKey`. Mirrors the `adapters` injection philosophy — production omits
237
+ * this. When set, it takes precedence over `projectId`.
238
+ */
239
+ composedPolicyEnforcer?: ComposedPolicyContext;
240
+ /**
241
+ * EDGE runtime only. The Cedar build's `WebAssembly.Module`. Prefer passing
242
+ * it as `engineWasmModule` (see there); this field is kept so existing
243
+ * configs work. Passed alone it serves both roles, detection and policy, on
244
+ * one instance. Passed next to the engine-only build it runs as a second
245
+ * instance, and the Edge bundle carries the engine twice (`debug` logs a
246
+ * hint).
247
+ *
248
+ * Without a Cedar module the project's policy is still fetched and never
249
+ * skipped: with no Cedar policy nothing changes, a policy in shadow mode
250
+ * keeps the structured decision, and an enforcing policy answers every
251
+ * request 503 and logs which module is missing. The Node runtime ignores
252
+ * this field (it loads Cedar through `createPolicyEvaluator`).
253
+ *
254
+ * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
255
+ */
256
+ cedarWasmModule?: WebAssembly.Module;
257
+ /**
258
+ * EDGE runtime only, and required there unless `cedarWasmModule` is set.
259
+ * The module the engine runs on, statically imported by the host:
260
+ *
261
+ * ```ts
262
+ * // Detection only:
263
+ * import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
264
+ * // Detection and the project's Cedar policy, on one module:
265
+ * import engineWasmModule from '@kya-os/checkpoint-nextjs/cedar-wasm';
266
+ *
267
+ * export default withCheckpoint({ tenantHost, projectId, engineWasmModule });
268
+ * ```
269
+ *
270
+ * The Cedar build is the engine plus Cedar, so it replaces the engine-only
271
+ * build rather than adding to it; it is larger, which is why it is opt-in.
272
+ * A project whose Cedar policy is enforcing needs it on the Edge runtime.
273
+ *
274
+ * The Edge runtime does not let code compile WebAssembly from bytes, so the
275
+ * engine cannot fetch and compile its own binary there; the bundler has to
276
+ * hand it over as a compiled module. The Node runtime ignores this field.
277
+ */
278
+ engineWasmModule?: WebAssembly.Module;
279
+ }
280
+ /**
281
+ * `withCheckpoint` configuration for the Edge runtime (`./edge`): the engine
282
+ * needs a module, `engineWasmModule` or, on its own, `cedarWasmModule`.
283
+ */
284
+ type CheckpointEdgeConfig = CheckpointConfig & ({
285
+ engineWasmModule: WebAssembly.Module;
286
+ } | {
287
+ cedarWasmModule: WebAssembly.Module;
288
+ });
289
+ //#endregion
290
+ export { CheckpointEdgeConfig as n, CheckpointConfig as t };
291
+ //# sourceMappingURL=config-CPP1RV0f.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-CPP1RV0f.d.mts","names":[],"sources":["../src/config.ts"],"mappings":";;;;;;;;;;UAoCiB;;;;;;;;EAQf,iBAAiB;;;;;;EAMjB;;EAEA;;EAEA;;;;;;;EAQA,kBAAkB;;;;;;;;;;EAWlB,0BAA0B;;;;;;EAO1B,8BAA8B;IAC5B,QAAQ;IACR,SAAS;QACL,iCAAiC,QAAQ;;;;;;EAO/C;;EAGA,gCAAgC,OAAO;;;;;;EAOvC;;;;;;EAOA;;;;;;;EAQA;;;;;;;EAQA,WAAW;IACT,aAAa;IACb,iBAAiB;IACjB,kBAAkB;IAClB,iBAAiB;;;;;;;;;EAUnB,YAAY,QAAQ,cAAc,KAAK,uBAAuB;;;;;;;;;;;;;;;;;;;;EAqB9D;;;;;;;;;;;;;;;;;;;EAoBA;;;;;;;;;;;;;;;;EAiBA,eAAe;;;;;;;;;;;;;;EAef;;;;;;EAOA;;;;;;;;;;;;EAaA;;;;;;;;;;;;;;;;;;;EAoBA;;EAEA,iBAAiB;;;;;;;;EAQjB,oBAAoB;;;;;;;;;;;;;;EAepB;;;;;;;EAQA,yBAAyB;;;;;;;;;;;;;;;;;EAkBzB,kBAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;EAuB9B,mBAAmB,YAAY;;;;;;KAOrB,uBAAuB;EAC9B,kBAAkB,YAAY;;EAAa,iBAAiB,YAAY"}
@@ -0,0 +1,291 @@
1
+ import { ChallengeContextFailureEvent, ChallengeEnvelopeMode, ChallengeWireInput, ClientIpTrustPolicy } from "@kya-os/checkpoint-shared";
2
+ import { NextRequest } from "next/server.js";
3
+ import { BrowserPostureConfig } from "@kya-os/checkpoint-shared/browser-posture";
4
+ import { ComposedPolicyContext, RequestClaimStore } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
5
+ import { DidResolverAdapter, PolicyEvaluatorAdapter, ReputationOracleAdapter, StatusListCacheAdapter } from "@kya-os/checkpoint-wasm-runtime/adapters";
6
+ import { EnforcementMode, EngineConfig, VerifyResult } from "@kya-os/checkpoint-wasm-runtime/engine";
7
+ //#region src/config.d.ts
8
+ /**
9
+ * Configuration for `withCheckpoint`.
10
+ */
11
+ interface CheckpointConfig {
12
+ /**
13
+ * Selects the infrastructure allowed to vouch for observed client addresses.
14
+ * Vercel headers are honored only inside its managed runtime (`VERCEL=1`).
15
+ * NextRequest exposes no socket peer, so generic proxy and Cloudflare origin
16
+ * profiles cannot authenticate that boundary and return no address. Use a
17
+ * transport-aware ingress, such as the Express adapter, for those profiles.
18
+ */
19
+ clientIpPolicy?: ClientIpTrustPolicy;
20
+ /**
21
+ * Tenant identifier — typically the customer's dashboard hostname
22
+ * (e.g. `acme.checkpoint.example`). The PolicyEvaluator uses this
23
+ * to look up tenant policy from the dashboard.
24
+ */
25
+ tenantHost: string;
26
+ /** Exact org DID used to verify the consent credential's audience. */
27
+ resourceOrgDid?: string;
28
+ /** Explicit trusted delegation issuers; otherwise resolved from project policy. */
29
+ trustedDelegationRoots?: string[];
30
+ /**
31
+ * `'enforce'` (default) blocks; `'observe'` passes everything
32
+ * through with `X-Checkpoint-Would-Have-Been` headers. Per Phase 0.2.
33
+ *
34
+ * @default 'enforce'
35
+ */
36
+ enforcementMode?: EnforcementMode;
37
+ /**
38
+ * Challenge-emission envelope mode (draft-kya-http-02 §8.1 fetcher-200).
39
+ * `negotiated` serves a body-readable HTTP 200 step-up response to
40
+ * cooperative agents (fetchers that drop 4xx/5xx bodies), keeping the spec
41
+ * 401/422 for everyone else. Defaults to `negotiated` (#3530). A cooperative-UX
42
+ * bridge, NOT an access control.
43
+ *
44
+ * @default 'negotiated'
45
+ */
46
+ delegationChallengeMode?: ChallengeEnvelopeMode;
47
+ /**
48
+ * Resolve a policy `Challenge`, or a block consent can remedy, into registered wire context.
49
+ * The callback performs any Authorization-Host registration asynchronously;
50
+ * the synchronous engine renderer never fabricates a sid, consent URI, or proof.
51
+ */
52
+ resolveDelegationChallenge?: (context: {
53
+ result: VerifyResult;
54
+ request: NextRequest;
55
+ }) => ChallengeWireInput | undefined | Promise<ChallengeWireInput | undefined>;
56
+ /**
57
+ * Registration/resolution budget in milliseconds.
58
+ *
59
+ * @default 3000
60
+ */
61
+ delegationChallengeTimeoutMs?: number;
62
+ /** Sanitized registration failure hook for metrics and operator warnings. */
63
+ onDelegationChallengeFailure?: (event: ChallengeContextFailureEvent) => void;
64
+ /**
65
+ * Argus reputation oracle base URL. Omit to use the trust-by-default
66
+ * baseline (reputation defaults to 1.0; orchestrator logs a one-shot
67
+ * warning at first request).
68
+ */
69
+ argusUrl?: string;
70
+ /**
71
+ * Dashboard base URL for the composed policy fetch
72
+ * (`<dashboardUrl>/api/internal/policies/{projectId}`). Takes precedence over
73
+ * `baseUrl`; omit both to use the hosted dashboard.
74
+ */
75
+ dashboardUrl?: string;
76
+ /**
77
+ * Returned to the PolicyEvaluator for anonymous requests (no agent
78
+ * DID). Trust-by-default. Engine scale is `0.0` to `1.0`.
79
+ *
80
+ * @default 1.0
81
+ */
82
+ reputationBaseline?: number;
83
+ /**
84
+ * Pre-built adapter instances. Production deployments use the
85
+ * factory-built defaults from `@kya-os/checkpoint-wasm-runtime/adapters`;
86
+ * tests use stubs. The factory composes any provided overrides over
87
+ * defaults — partial overrides are supported.
88
+ */
89
+ adapters?: Partial<{
90
+ didResolver: DidResolverAdapter;
91
+ statusListCache: StatusListCacheAdapter;
92
+ reputationOracle: ReputationOracleAdapter;
93
+ policyEvaluator: PolicyEvaluatorAdapter;
94
+ }>;
95
+ /**
96
+ * Optional callback for the post-verdict path — fires after every
97
+ * verification, regardless of permit/block, with the full
98
+ * `VerifyResult`. Use for logging, dashboards, telemetry. Errors
99
+ * thrown here are swallowed so user code can't break the middleware
100
+ * response.
101
+ */
102
+ onResult?: (result: VerifyResult, req: NextRequest) => void | Promise<void>;
103
+ /**
104
+ * Accept legacy `KYA-Delegation`-header envelope form alongside the
105
+ * canonical `_meta.proof.jws` body form. Default `false`.
106
+ *
107
+ * **When to enable** — customers whose agents pre-date Envelope-1
108
+ * (#2537) and ship KYA-OS proofs as `{protected,payload,signature}`
109
+ * JSON in a `KYA-Delegation` HTTP header. Post-Envelope-1 agents
110
+ * ship compact JWS in the request body's `_meta.proof.jws` field;
111
+ * those don't need this flag.
112
+ *
113
+ * Forwarded to the orchestrator's `VerifyRequestOpts.legacyEnvelopeFallback`.
114
+ * Both transports (header + body) are honored when this is `true`;
115
+ * the orchestrator's detection order is body first, then header
116
+ * (`packages/checkpoint-wasm-runtime/src/engine/orchestrator/build-agent-request.ts`).
117
+ *
118
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
119
+ *
120
+ * @default false
121
+ */
122
+ legacyEnvelopeFallback?: boolean;
123
+ /**
124
+ * Read the request body when `content-type` is `application/json` so
125
+ * the orchestrator can extract a KYA-OS envelope from
126
+ * `_meta.proof.jws`. Default `true`.
127
+ *
128
+ * **When to disable** — streaming middlewares that can't tolerate
129
+ * the `req.clone()` memory overhead (one full-body copy is buffered
130
+ * during the read). For those, set `false` and route KYA-OS
131
+ * envelopes through the `KYA-Delegation` header transport instead
132
+ * (requires `legacyEnvelopeFallback: true`).
133
+ *
134
+ * The clone preserves `req.body` for downstream handlers — disabling
135
+ * is a performance optimization, not a correctness fix.
136
+ *
137
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
138
+ *
139
+ * @default true
140
+ */
141
+ drainJsonBody?: boolean;
142
+ /**
143
+ * Engine-default behaviour knobs forwarded to every composed
144
+ * `ContextSpec`. Defaults to `{ tier3Action: 'monitor' }` —
145
+ * customer-onboarding-safe (tenant policy decides; engine doesn't
146
+ * short-circuit known-agent UAs with an engine-default Block).
147
+ *
148
+ * Opt into `{ tier3Action: 'block' }` when the host wants the
149
+ * calibrated engine-default block for KnownAiAgent / AiCrawler /
150
+ * HeadlessBrowser classifications BEFORE the tenant policy seam.
151
+ *
152
+ * Added in `@kya-os/checkpoint-nextjs@1.2.0` (Engine-Tier3-Monitor-
153
+ * Default, #2653 + this PR's plumbing follow-up).
154
+ *
155
+ * @default { tier3Action: 'monitor' }
156
+ */
157
+ engineConfig?: EngineConfig;
158
+ /**
159
+ * Project API key. Required for detections to land in the dashboard
160
+ * — the engine verifies in-process via WASM, but the resulting
161
+ * `VerifyResult` only reaches the dashboard's `detections` table
162
+ * when this reporter is configured. Without it the verdict path
163
+ * works locally but the onboarding "Verify connection" check fails
164
+ * forever because no rows are ever written.
165
+ *
166
+ * Resolve from `process.env.CHECKPOINT_API_KEY` in the host app.
167
+ *
168
+ * Added in `@kya-os/checkpoint-nextjs@1.4.0`
169
+ * (SDK-Detection-Reporter-1).
170
+ */
171
+ apiKey?: string;
172
+ /**
173
+ * Dashboard base URL. Override for staging or self-hosted dashboards.
174
+ *
175
+ * @default 'https://kya.vouched.id'
176
+ */
177
+ baseUrl?: string;
178
+ /**
179
+ * Surface reporter errors via `console.warn`. Defaults to `false`.
180
+ * The reporter is fire-and-forget; enable during development to
181
+ * confirm `apiKey` / `baseUrl` are routed correctly.
182
+ *
183
+ * Also wires the composed-policy shadow-divergence + evaluation-error
184
+ * telemetry, and pipeline-failure logging (the 503 fail-closed path), to
185
+ * `console.warn`/`console.error` (otherwise silent).
186
+ *
187
+ * @default false
188
+ */
189
+ debug?: boolean;
190
+ /**
191
+ * Project id whose composed (/policy-compose) policy this middleware
192
+ * enforces. When set, the project's policy is fetched from the dashboard
193
+ * (`<dashboardUrl ?? baseUrl ?? default>/api/internal/policies/${projectId}`)
194
+ * and — if it carries a deployed Cedar bundle with `engineEnforcementEnabled`
195
+ * on — the kya-os-engine decision is enforced IN-PROCESS, byte-for-byte the
196
+ * same as the DNS Gateway. Omit to run detection + the structured policy only
197
+ * (fully back-compatible; purely additive).
198
+ *
199
+ * SHADOW-FIRST: with a deployed bundle but `engineEnforcementEnabled` off, the
200
+ * engine decision is computed + logged on divergence but does NOT act.
201
+ *
202
+ * **Node vs Edge:** composed enforcement is default-on under the Node runtime
203
+ * (`./node`). Under the Edge runtime (`./edge`) it additionally requires
204
+ * `cedarWasmModule` to be wired (see below) — otherwise the seam stays inert.
205
+ *
206
+ * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
207
+ */
208
+ projectId?: string;
209
+ /** Signed browser risk; configure explicit route scopes to enable consent step-up. */
210
+ browserPosture?: BrowserPostureConfig;
211
+ /**
212
+ * Where accepted signed requests are claimed, so each is used once. Defaults
213
+ * to the dashboard's shared ledger when `apiKey` and `projectId` are set,
214
+ * otherwise to a store in this process or isolate (with a one-time warning,
215
+ * since a deployment with several instances needs a shared store). Pass
216
+ * `createLocalRequestClaimStore()` to choose the in-process store explicitly.
217
+ */
218
+ requestClaimStore?: RequestClaimStore;
219
+ /**
220
+ * Policy-fetch cache TTL in seconds. Defaults to 300 (5 minutes). How long
221
+ * a fetched project policy is reused before the middleware refetches from
222
+ * the dashboard — i.e. the worst-case delay before a dashboard policy
223
+ * change takes effect on this host.
224
+ *
225
+ * `0` disables reuse entirely: every request fetches the policy (one
226
+ * origin round-trip per request). Use for demo/example sites where instant
227
+ * policy propagation matters more than latency; keep the default (or a
228
+ * small positive value like 5) for production and benchmark hosts.
229
+ *
230
+ * @default 300
231
+ */
232
+ policyCacheTtlSeconds?: number;
233
+ /**
234
+ * Advanced / testing: inject a pre-built composed-policy context instead of
235
+ * letting `withCheckpoint` construct one from `projectId` + `baseUrl` +
236
+ * `apiKey`. Mirrors the `adapters` injection philosophy — production omits
237
+ * this. When set, it takes precedence over `projectId`.
238
+ */
239
+ composedPolicyEnforcer?: ComposedPolicyContext;
240
+ /**
241
+ * EDGE runtime only. The Cedar build's `WebAssembly.Module`. Prefer passing
242
+ * it as `engineWasmModule` (see there); this field is kept so existing
243
+ * configs work. Passed alone it serves both roles, detection and policy, on
244
+ * one instance. Passed next to the engine-only build it runs as a second
245
+ * instance, and the Edge bundle carries the engine twice (`debug` logs a
246
+ * hint).
247
+ *
248
+ * Without a Cedar module the project's policy is still fetched and never
249
+ * skipped: with no Cedar policy nothing changes, a policy in shadow mode
250
+ * keeps the structured decision, and an enforcing policy answers every
251
+ * request 503 and logs which module is missing. The Node runtime ignores
252
+ * this field (it loads Cedar through `createPolicyEvaluator`).
253
+ *
254
+ * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
255
+ */
256
+ cedarWasmModule?: WebAssembly.Module;
257
+ /**
258
+ * EDGE runtime only, and required there unless `cedarWasmModule` is set.
259
+ * The module the engine runs on, statically imported by the host:
260
+ *
261
+ * ```ts
262
+ * // Detection only:
263
+ * import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
264
+ * // Detection and the project's Cedar policy, on one module:
265
+ * import engineWasmModule from '@kya-os/checkpoint-nextjs/cedar-wasm';
266
+ *
267
+ * export default withCheckpoint({ tenantHost, projectId, engineWasmModule });
268
+ * ```
269
+ *
270
+ * The Cedar build is the engine plus Cedar, so it replaces the engine-only
271
+ * build rather than adding to it; it is larger, which is why it is opt-in.
272
+ * A project whose Cedar policy is enforcing needs it on the Edge runtime.
273
+ *
274
+ * The Edge runtime does not let code compile WebAssembly from bytes, so the
275
+ * engine cannot fetch and compile its own binary there; the bundler has to
276
+ * hand it over as a compiled module. The Node runtime ignores this field.
277
+ */
278
+ engineWasmModule?: WebAssembly.Module;
279
+ }
280
+ /**
281
+ * `withCheckpoint` configuration for the Edge runtime (`./edge`): the engine
282
+ * needs a module, `engineWasmModule` or, on its own, `cedarWasmModule`.
283
+ */
284
+ type CheckpointEdgeConfig = CheckpointConfig & ({
285
+ engineWasmModule: WebAssembly.Module;
286
+ } | {
287
+ cedarWasmModule: WebAssembly.Module;
288
+ });
289
+ //#endregion
290
+ export { CheckpointEdgeConfig as n, CheckpointConfig as t };
291
+ //# sourceMappingURL=config-DVgOFxJs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-DVgOFxJs.d.ts","names":[],"sources":["../src/config.ts"],"mappings":";;;;;;;;;;UAoCiB;;;;;;;;EAQf,iBAAiB;;;;;;EAMjB;;EAEA;;EAEA;;;;;;;EAQA,kBAAkB;;;;;;;;;;EAWlB,0BAA0B;;;;;;EAO1B,8BAA8B;IAC5B,QAAQ;IACR,SAAS;QACL,iCAAiC,QAAQ;;;;;;EAO/C;;EAGA,gCAAgC,OAAO;;;;;;EAOvC;;;;;;EAOA;;;;;;;EAQA;;;;;;;EAQA,WAAW;IACT,aAAa;IACb,iBAAiB;IACjB,kBAAkB;IAClB,iBAAiB;;;;;;;;;EAUnB,YAAY,QAAQ,cAAc,KAAK,uBAAuB;;;;;;;;;;;;;;;;;;;;EAqB9D;;;;;;;;;;;;;;;;;;;EAoBA;;;;;;;;;;;;;;;;EAiBA,eAAe;;;;;;;;;;;;;;EAef;;;;;;EAOA;;;;;;;;;;;;EAaA;;;;;;;;;;;;;;;;;;;EAoBA;;EAEA,iBAAiB;;;;;;;;EAQjB,oBAAoB;;;;;;;;;;;;;;EAepB;;;;;;;EAQA,yBAAyB;;;;;;;;;;;;;;;;;EAkBzB,kBAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;EAuB9B,mBAAmB,YAAY;;;;;;KAOrB,uBAAuB;EAC9B,kBAAkB,YAAY;;EAAa,iBAAiB,YAAY"}
@@ -0,0 +1,20 @@
1
+ //#region src/engine-wasm.d.ts
2
+ /**
3
+ * The engine's compiled `WebAssembly.Module`, for `withCheckpoint`'s
4
+ * `engineWasmModule` on the Edge runtime:
5
+ *
6
+ * ```ts
7
+ * import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
8
+ * export default withCheckpoint({ tenantHost, engineWasmModule });
9
+ * ```
10
+ *
11
+ * `?module` is how Next.js imports a `.wasm` file as a compiled module, which
12
+ * the Edge runtime needs because it does not let code compile WebAssembly from
13
+ * bytes. Importing it through this package keeps the binary the same version
14
+ * as the engine glue this package loads, and works without a direct
15
+ * dependency on `@kya-os/checkpoint-wasm-runtime`.
16
+ */
17
+ declare const engineWasmModule: WebAssembly.Module;
18
+ //#endregion
19
+ export { engineWasmModule as default };
20
+ //# sourceMappingURL=engine-wasm.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine-wasm.d.mts","names":[],"sources":["../src/engine-wasm.ts"],"mappings":";;;;;;;;;;;;;;;;cAmBM,kBAAkB,YAAY"}
@@ -0,0 +1,19 @@
1
+ //#region src/engine-wasm.d.ts
2
+ /**
3
+ * The engine's compiled `WebAssembly.Module`, for `withCheckpoint`'s
4
+ * `engineWasmModule` on the Edge runtime:
5
+ *
6
+ * ```ts
7
+ * import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
8
+ * export default withCheckpoint({ tenantHost, engineWasmModule });
9
+ * ```
10
+ *
11
+ * `?module` is how Next.js imports a `.wasm` file as a compiled module, which
12
+ * the Edge runtime needs because it does not let code compile WebAssembly from
13
+ * bytes. Importing it through this package keeps the binary the same version
14
+ * as the engine glue this package loads, and works without a direct
15
+ * dependency on `@kya-os/checkpoint-wasm-runtime`.
16
+ */
17
+ declare const engineWasmModule: WebAssembly.Module;
18
+ export = engineWasmModule;
19
+ //# sourceMappingURL=engine-wasm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine-wasm.d.ts","names":[],"sources":["../src/engine-wasm.ts"],"mappings":";;;;;;;;;;;;;;;;cAmBM,kBAAkB,YAAY"}
@@ -0,0 +1,24 @@
1
+ const require_rolldown_runtime = require('./rolldown-runtime-C24Yb2bl.js');
2
+ let _kya_os_checkpoint_wasm_runtime_wasm_kya_os_engine_web_kya_os_engine_bg_wasm_module = require("@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-web/kya_os_engine_bg.wasm?module");
3
+ _kya_os_checkpoint_wasm_runtime_wasm_kya_os_engine_web_kya_os_engine_bg_wasm_module = require_rolldown_runtime.__toESM(_kya_os_checkpoint_wasm_runtime_wasm_kya_os_engine_web_kya_os_engine_bg_wasm_module);
4
+
5
+ //#region src/engine-wasm.ts
6
+ /**
7
+ * The engine's compiled `WebAssembly.Module`, for `withCheckpoint`'s
8
+ * `engineWasmModule` on the Edge runtime:
9
+ *
10
+ * ```ts
11
+ * import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
12
+ * export default withCheckpoint({ tenantHost, engineWasmModule });
13
+ * ```
14
+ *
15
+ * `?module` is how Next.js imports a `.wasm` file as a compiled module, which
16
+ * the Edge runtime needs because it does not let code compile WebAssembly from
17
+ * bytes. Importing it through this package keeps the binary the same version
18
+ * as the engine glue this package loads, and works without a direct
19
+ * dependency on `@kya-os/checkpoint-wasm-runtime`.
20
+ */
21
+ const engineWasmModule = _kya_os_checkpoint_wasm_runtime_wasm_kya_os_engine_web_kya_os_engine_bg_wasm_module.default;
22
+
23
+ //#endregion
24
+ module.exports = engineWasmModule;