@kya-os/checkpoint-nextjs 1.11.0 → 1.13.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 (79) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +16 -8
  3. package/dist/{adapt-BdQ9R7Iw.mjs → adapt-BGEyLf44.mjs} +13 -3
  4. package/dist/adapt-BGEyLf44.mjs.map +1 -0
  5. package/dist/{adapt-CCSKGjVH.js → adapt-D2-OBY9M.js} +17 -1
  6. package/dist/{api-middleware-BWjokNis.d.mts → api-middleware-BtsYJU5u.d.mts} +2 -2
  7. package/dist/{api-middleware-BWjokNis.d.mts.map → api-middleware-BtsYJU5u.d.mts.map} +1 -1
  8. package/dist/{api-middleware-C-ngFX_8.mjs → api-middleware-DcUgTDv5.mjs} +4 -4
  9. package/dist/{api-middleware-C-ngFX_8.mjs.map → api-middleware-DcUgTDv5.mjs.map} +1 -1
  10. package/dist/{api-middleware-Bf3xmM9W.js → api-middleware-LhLqOapx.js} +3 -3
  11. package/dist/api-middleware.d.mts +1 -1
  12. package/dist/api-middleware.js +1 -1
  13. package/dist/api-middleware.mjs +1 -1
  14. package/dist/cedar-wasm.d.mts +1 -1
  15. package/dist/cedar-wasm.d.ts +1 -1
  16. package/dist/cedar-wasm.js +1 -1
  17. package/dist/cedar-wasm.mjs +1 -1
  18. package/dist/cedar-wasm.mjs.map +1 -1
  19. package/dist/config-CXS_-rRv.d.ts +95 -0
  20. package/dist/config-CXS_-rRv.d.ts.map +1 -0
  21. package/dist/config-DQ-VuHlJ.d.mts +95 -0
  22. package/dist/config-DQ-VuHlJ.d.mts.map +1 -0
  23. package/dist/engine-wasm.d.mts +1 -1
  24. package/dist/engine-wasm.d.ts +1 -1
  25. package/dist/engine-wasm.js +1 -1
  26. package/dist/engine-wasm.mjs +1 -1
  27. package/dist/engine-wasm.mjs.map +1 -1
  28. package/dist/index-edge.d.mts +4 -4
  29. package/dist/index-edge.d.ts +3 -3
  30. package/dist/index-edge.js +2 -2
  31. package/dist/index-edge.mjs +2 -2
  32. package/dist/index.d.mts +4 -4
  33. package/dist/index.d.ts +3 -3
  34. package/dist/index.js +2 -2
  35. package/dist/index.mjs +2 -2
  36. package/dist/middleware-bundler.d.mts +1 -1
  37. package/dist/middleware-bundler.d.ts +1 -1
  38. package/dist/middleware-bundler.js +3 -3
  39. package/dist/middleware-bundler.mjs +3 -3
  40. package/dist/middleware-bundler.mjs.map +1 -1
  41. package/dist/middleware-core-0s8y7UNN.js +203 -0
  42. package/dist/{middleware-core-Bol44X9C.d.ts → middleware-core-Cxb9Jh0a.d.mts} +4 -7
  43. package/dist/middleware-core-Cxb9Jh0a.d.mts.map +1 -0
  44. package/dist/middleware-core-DN_FLlaV.mjs +193 -0
  45. package/dist/middleware-core-DN_FLlaV.mjs.map +1 -0
  46. package/dist/{middleware-core-DycsbHUd.d.mts → middleware-core-DaNMjsib.d.ts} +4 -7
  47. package/dist/middleware-core-DaNMjsib.d.ts.map +1 -0
  48. package/dist/middleware-edge.d.mts +1 -1
  49. package/dist/middleware-edge.d.mts.map +1 -1
  50. package/dist/middleware-edge.d.ts +1 -1
  51. package/dist/middleware-edge.d.ts.map +1 -1
  52. package/dist/middleware-edge.js +21 -35
  53. package/dist/middleware-edge.mjs +21 -35
  54. package/dist/middleware-edge.mjs.map +1 -1
  55. package/dist/middleware-node-context-BvqrL2Ra.mjs +16 -0
  56. package/dist/middleware-node-context-BvqrL2Ra.mjs.map +1 -0
  57. package/dist/middleware-node-context-TRMTgp3y.js +20 -0
  58. package/dist/middleware-node.d.mts +2 -2
  59. package/dist/middleware-node.d.ts +2 -2
  60. package/dist/middleware-node.js +3 -3
  61. package/dist/middleware-node.mjs +3 -3
  62. package/dist/middleware-node.mjs.map +1 -1
  63. package/dist/public-api-BZ5Ahk6X.d.mts +5 -0
  64. package/dist/{public-api-CYsHrTQI.d.ts → public-api-DnTh8YEz.d.ts} +2 -2
  65. package/package.json +3 -3
  66. package/dist/adapt-BdQ9R7Iw.mjs.map +0 -1
  67. package/dist/config-CPP1RV0f.d.mts +0 -291
  68. package/dist/config-CPP1RV0f.d.mts.map +0 -1
  69. package/dist/config-DVgOFxJs.d.ts +0 -291
  70. package/dist/config-DVgOFxJs.d.ts.map +0 -1
  71. package/dist/middleware-core-B0jf5_Hm.mjs +0 -264
  72. package/dist/middleware-core-B0jf5_Hm.mjs.map +0 -1
  73. package/dist/middleware-core-Bol44X9C.d.ts.map +0 -1
  74. package/dist/middleware-core-CMc-2QkU.js +0 -274
  75. package/dist/middleware-core-DycsbHUd.d.mts.map +0 -1
  76. package/dist/middleware-node-context-591KsiYg.js +0 -39
  77. package/dist/middleware-node-context-D_ZyUEcA.mjs +0 -35
  78. package/dist/middleware-node-context-D_ZyUEcA.mjs.map +0 -1
  79. package/dist/public-api-DkG7pRE0.d.mts +0 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-CXS_-rRv.d.ts","names":[],"sources":["../src/config.ts"],"mappings":";;;;;;;;;UAkBiB,yBAAyB,qBAAqB;;;;;;;;EAQ7D,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;EA0BjB;;;;;;;;;;;;;;;;;EAkBA,kBAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;EAuB9B,mBAAmB,YAAY;;;;;;KAOrB,uBAAuB;EAC9B,kBAAkB,YAAY;;EAAa,iBAAiB,YAAY"}
@@ -0,0 +1,95 @@
1
+ import { CheckpointHostConfig } from "@kya-os/checkpoint-wasm-runtime/pipeline";
2
+ import { NextRequest } from "next/server.js";
3
+ import { ClientIpTrustPolicy } from "@kya-os/checkpoint-shared";
4
+ //#region src/config.d.ts
5
+ /**
6
+ * Configuration for `withCheckpoint`. Every field is optional; on the Edge
7
+ * runtime `withCheckpoint` also needs a compiled engine module
8
+ * (`CheckpointEdgeConfig`).
9
+ */
10
+ interface CheckpointConfig extends CheckpointHostConfig<NextRequest> {
11
+ /**
12
+ * Selects the infrastructure allowed to vouch for observed client addresses.
13
+ * Vercel headers are honored only inside its managed runtime (`VERCEL=1`).
14
+ * NextRequest exposes no socket peer, so generic proxy and Cloudflare origin
15
+ * profiles cannot authenticate that boundary and return no address. Use a
16
+ * transport-aware ingress, such as the Express adapter, for those profiles.
17
+ */
18
+ clientIpPolicy?: ClientIpTrustPolicy;
19
+ /**
20
+ * Read the request body when `content-type` is `application/json` so
21
+ * the orchestrator can extract a KYA-OS envelope from
22
+ * `_meta.proof.jws`, and read the exact bytes of a request that carries
23
+ * a kya-http/2 signature so its `Content-Digest` can be checked. A signed
24
+ * body over 1 MiB is answered with 413 (in observe mode it passes through
25
+ * and is reported as a would-have-been Block). Default `true`.
26
+ *
27
+ * **When to disable** — streaming middlewares that can't tolerate
28
+ * the `req.clone()` memory overhead (one full-body copy is buffered
29
+ * during the read). For those, set `false` and route KYA-OS
30
+ * envelopes through the `KYA-Delegation` header transport instead
31
+ * (requires `legacyEnvelopeFallback: true`). With draining off, a
32
+ * kya-http/2 request whose `Content-Length` or `Transfer-Encoding`
33
+ * declares a body is refused (403 `kyaos/profile-violation`), because
34
+ * the body cannot be bound to its signature.
35
+ *
36
+ * The clone preserves `req.body` for downstream handlers — disabling
37
+ * is a performance optimization, not a correctness fix.
38
+ *
39
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
40
+ *
41
+ * @default true
42
+ */
43
+ drainJsonBody?: boolean;
44
+ /**
45
+ * EDGE runtime only. The Cedar build's `WebAssembly.Module`. Prefer passing
46
+ * it as `engineWasmModule` (see there); this field is kept so existing
47
+ * configs work. Passed alone it serves both roles, detection and policy, on
48
+ * one instance. Passed next to the engine-only build it runs as a second
49
+ * instance, and the Edge bundle carries the engine twice (`debug` logs a
50
+ * hint).
51
+ *
52
+ * Without a Cedar module the project's policy is still fetched and never
53
+ * skipped: with no Cedar policy nothing changes, a policy in shadow mode
54
+ * keeps the structured decision, and an enforcing policy answers every
55
+ * request 503 and logs which module is missing. The Node runtime ignores
56
+ * this field (it loads Cedar through `createPolicyEvaluator`).
57
+ *
58
+ * Added in `@kya-os/checkpoint-nextjs@1.5.0` (@Policy middleware-Cedar, #3076).
59
+ */
60
+ cedarWasmModule?: WebAssembly.Module;
61
+ /**
62
+ * EDGE runtime only, and required there unless `cedarWasmModule` is set.
63
+ * The module the engine runs on, statically imported by the host:
64
+ *
65
+ * ```ts
66
+ * // Detection only:
67
+ * import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
68
+ * // Detection and the project's Cedar policy, on one module:
69
+ * import engineWasmModule from '@kya-os/checkpoint-nextjs/cedar-wasm';
70
+ *
71
+ * export default withCheckpoint({ projectId, engineWasmModule });
72
+ * ```
73
+ *
74
+ * The Cedar build is the engine plus Cedar, so it replaces the engine-only
75
+ * build rather than adding to it; it is larger, which is why it is opt-in.
76
+ * A project whose Cedar policy is enforcing needs it on the Edge runtime.
77
+ *
78
+ * The Edge runtime does not let code compile WebAssembly from bytes, so the
79
+ * engine cannot fetch and compile its own binary there; the bundler has to
80
+ * hand it over as a compiled module. The Node runtime ignores this field.
81
+ */
82
+ engineWasmModule?: WebAssembly.Module;
83
+ }
84
+ /**
85
+ * `withCheckpoint` configuration for the Edge runtime (`./edge`): the engine
86
+ * needs a module, `engineWasmModule` or, on its own, `cedarWasmModule`.
87
+ */
88
+ type CheckpointEdgeConfig = CheckpointConfig & ({
89
+ engineWasmModule: WebAssembly.Module;
90
+ } | {
91
+ cedarWasmModule: WebAssembly.Module;
92
+ });
93
+ //#endregion
94
+ export { CheckpointEdgeConfig as n, CheckpointConfig as t };
95
+ //# sourceMappingURL=config-DQ-VuHlJ.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-DQ-VuHlJ.d.mts","names":[],"sources":["../src/config.ts"],"mappings":";;;;;;;;;UAkBiB,yBAAyB,qBAAqB;;;;;;;;EAQ7D,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;EA0BjB;;;;;;;;;;;;;;;;;EAkBA,kBAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;EAuB9B,mBAAmB,YAAY;;;;;;KAOrB,uBAAuB;EAC9B,kBAAkB,YAAY;;EAAa,iBAAiB,YAAY"}
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * ```ts
7
7
  * import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
8
- * export default withCheckpoint({ tenantHost, engineWasmModule });
8
+ * export default withCheckpoint({ engineWasmModule });
9
9
  * ```
10
10
  *
11
11
  * `?module` is how Next.js imports a `.wasm` file as a compiled module, which
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * ```ts
7
7
  * import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
8
- * export default withCheckpoint({ tenantHost, engineWasmModule });
8
+ * export default withCheckpoint({ engineWasmModule });
9
9
  * ```
10
10
  *
11
11
  * `?module` is how Next.js imports a `.wasm` file as a compiled module, which
@@ -9,7 +9,7 @@ _kya_os_checkpoint_wasm_runtime_wasm_kya_os_engine_web_kya_os_engine_bg_wasm_mod
9
9
  *
10
10
  * ```ts
11
11
  * import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
12
- * export default withCheckpoint({ tenantHost, engineWasmModule });
12
+ * export default withCheckpoint({ engineWasmModule });
13
13
  * ```
14
14
  *
15
15
  * `?module` is how Next.js imports a `.wasm` file as a compiled module, which
@@ -7,7 +7,7 @@ import compiled from "@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-web/kya
7
7
  *
8
8
  * ```ts
9
9
  * import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
10
- * export default withCheckpoint({ tenantHost, engineWasmModule });
10
+ * export default withCheckpoint({ engineWasmModule });
11
11
  * ```
12
12
  *
13
13
  * `?module` is how Next.js imports a `.wasm` file as a compiled module, which
@@ -1 +1 @@
1
- {"version":3,"file":"engine-wasm.mjs","names":[],"sources":["../src/engine-wasm.ts"],"sourcesContent":["/**\n * The engine's compiled `WebAssembly.Module`, for `withCheckpoint`'s\n * `engineWasmModule` on the Edge runtime:\n *\n * ```ts\n * import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';\n * export default withCheckpoint({ tenantHost, engineWasmModule });\n * ```\n *\n * `?module` is how Next.js imports a `.wasm` file as a compiled module, which\n * the Edge runtime needs because it does not let code compile WebAssembly from\n * bytes. Importing it through this package keeps the binary the same version\n * as the engine glue this package loads, and works without a direct\n * dependency on `@kya-os/checkpoint-wasm-runtime`.\n */\n\nimport compiled from '@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-web/kya_os_engine_bg.wasm?module';\n\n// Typed here so the published declaration names no `?module` specifier.\nconst engineWasmModule: WebAssembly.Module = compiled;\nexport default engineWasmModule;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAM,mBAAuC"}
1
+ {"version":3,"file":"engine-wasm.mjs","names":[],"sources":["../src/engine-wasm.ts"],"sourcesContent":["/**\n * The engine's compiled `WebAssembly.Module`, for `withCheckpoint`'s\n * `engineWasmModule` on the Edge runtime:\n *\n * ```ts\n * import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';\n * export default withCheckpoint({ engineWasmModule });\n * ```\n *\n * `?module` is how Next.js imports a `.wasm` file as a compiled module, which\n * the Edge runtime needs because it does not let code compile WebAssembly from\n * bytes. Importing it through this package keeps the binary the same version\n * as the engine glue this package loads, and works without a direct\n * dependency on `@kya-os/checkpoint-wasm-runtime`.\n */\n\nimport compiled from '@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-web/kya_os_engine_bg.wasm?module';\n\n// Typed here so the published declaration names no `?module` specifier.\nconst engineWasmModule: WebAssembly.Module = compiled;\nexport default engineWasmModule;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAM,mBAAuC"}
@@ -1,8 +1,8 @@
1
1
  import { a as EnforceResponse, c as LogDetectionInput, i as EnforceInput, l as getCheckpointApiClient, n as CheckpointApiClient, o as EnforcementAction, r as CheckpointApiClientConfig, s as EnforcementDecision, u as resetCheckpointApiClient } from "./api-client-JHOrRUA_.mjs";
2
- import { n as withCheckpointApi, t as CheckpointApiMiddlewareConfig } from "./api-middleware-BWjokNis.mjs";
3
- import { t as CheckpointConfig } from "./config-CPP1RV0f.mjs";
2
+ import { n as withCheckpointApi, t as CheckpointApiMiddlewareConfig } from "./api-middleware-BtsYJU5u.mjs";
3
+ import { t as CheckpointConfig } from "./config-DQ-VuHlJ.mjs";
4
4
  import { n as CheckpointPostureOutcome, r as getCheckpointPostureOutcome, t as CheckpointPostureOptions } from "./posture-outcome-Ccujx_9V.mjs";
5
5
  import { withCheckpoint } from "./middleware-edge.mjs";
6
- import { t as VERSION } from "./middleware-core-DycsbHUd.mjs";
7
- import "./public-api-DkG7pRE0.mjs";
6
+ import { t as VERSION } from "./middleware-core-Cxb9Jh0a.mjs";
7
+ import "./public-api-BZ5Ahk6X.mjs";
8
8
  export { CheckpointApiClient, type CheckpointApiClientConfig, type CheckpointApiMiddlewareConfig, type CheckpointConfig, type CheckpointPostureOptions, type CheckpointPostureOutcome, type EnforceInput, type EnforceResponse, type EnforcementAction, type EnforcementDecision, type LogDetectionInput, VERSION, getCheckpointApiClient, getCheckpointPostureOutcome, resetCheckpointApiClient, withCheckpoint, withCheckpointApi };
@@ -1,8 +1,8 @@
1
1
  import { a as EnforceResponse, c as LogDetectionInput, i as EnforceInput, l as getCheckpointApiClient, n as CheckpointApiClient, o as EnforcementAction, r as CheckpointApiClientConfig, s as EnforcementDecision, u as resetCheckpointApiClient } from "./api-client-JHOrRUA_.js";
2
2
  import { n as withCheckpointApi, t as CheckpointApiMiddlewareConfig } from "./api-middleware-DyLDqOYF.js";
3
- import { t as CheckpointConfig } from "./config-DVgOFxJs.js";
3
+ import { t as CheckpointConfig } from "./config-CXS_-rRv.js";
4
4
  import { n as CheckpointPostureOutcome, r as getCheckpointPostureOutcome, t as CheckpointPostureOptions } from "./posture-outcome-Ccujx_9V.js";
5
5
  import { withCheckpoint } from "./middleware-edge.js";
6
- import { t as VERSION } from "./middleware-core-Bol44X9C.js";
7
- import "./public-api-CYsHrTQI.js";
6
+ import { t as VERSION } from "./middleware-core-DaNMjsib.js";
7
+ import "./public-api-DnTh8YEz.js";
8
8
  export { CheckpointApiClient, type CheckpointApiClientConfig, type CheckpointApiMiddlewareConfig, type CheckpointConfig, type CheckpointPostureOptions, type CheckpointPostureOutcome, type EnforceInput, type EnforceResponse, type EnforcementAction, type EnforcementDecision, type LogDetectionInput, VERSION, getCheckpointApiClient, getCheckpointPostureOutcome, resetCheckpointApiClient, withCheckpoint, withCheckpointApi };
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_middleware_core = require('./middleware-core-CMc-2QkU.js');
2
+ const require_middleware_core = require('./middleware-core-0s8y7UNN.js');
3
3
  const require_posture_outcome = require('./posture-outcome-DddsJtL8.js');
4
4
  const require_api_client = require('./api-client.js');
5
- const require_api_middleware = require('./api-middleware-Bf3xmM9W.js');
5
+ const require_api_middleware = require('./api-middleware-LhLqOapx.js');
6
6
  const require_middleware_edge = require('./middleware-edge.js');
7
7
 
8
8
  exports.CheckpointApiClient = require_api_client.CheckpointApiClient;
@@ -1,7 +1,7 @@
1
- import { t as VERSION } from "./middleware-core-B0jf5_Hm.mjs";
1
+ import { t as VERSION } from "./middleware-core-DN_FLlaV.mjs";
2
2
  import { t as getCheckpointPostureOutcome } from "./posture-outcome-DQ4fdMfq.mjs";
3
3
  import { CheckpointApiClient, getCheckpointApiClient, resetCheckpointApiClient } from "./api-client.mjs";
4
- import { t as withCheckpointApi } from "./api-middleware-C-ngFX_8.mjs";
4
+ import { t as withCheckpointApi } from "./api-middleware-DcUgTDv5.mjs";
5
5
  import { withCheckpoint } from "./middleware-edge.mjs";
6
6
 
7
7
  export { CheckpointApiClient, VERSION, getCheckpointApiClient, getCheckpointPostureOutcome, resetCheckpointApiClient, withCheckpoint, withCheckpointApi };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { a as EnforceResponse, c as LogDetectionInput, i as EnforceInput, l as getCheckpointApiClient, n as CheckpointApiClient, o as EnforcementAction, r as CheckpointApiClientConfig, s as EnforcementDecision, u as resetCheckpointApiClient } from "./api-client-JHOrRUA_.mjs";
2
- import { n as withCheckpointApi, t as CheckpointApiMiddlewareConfig } from "./api-middleware-BWjokNis.mjs";
3
- import { t as CheckpointConfig } from "./config-CPP1RV0f.mjs";
2
+ import { n as withCheckpointApi, t as CheckpointApiMiddlewareConfig } from "./api-middleware-BtsYJU5u.mjs";
3
+ import { t as CheckpointConfig } from "./config-DQ-VuHlJ.mjs";
4
4
  import { n as CheckpointPostureOutcome, r as getCheckpointPostureOutcome, t as CheckpointPostureOptions } from "./posture-outcome-Ccujx_9V.mjs";
5
- import { t as VERSION } from "./middleware-core-DycsbHUd.mjs";
6
- import "./public-api-DkG7pRE0.mjs";
5
+ import { t as VERSION } from "./middleware-core-Cxb9Jh0a.mjs";
6
+ import "./public-api-BZ5Ahk6X.mjs";
7
7
  import { withCheckpoint } from "./middleware-node.mjs";
8
8
  export { CheckpointApiClient, type CheckpointApiClientConfig, type CheckpointApiMiddlewareConfig, type CheckpointConfig, type CheckpointPostureOptions, type CheckpointPostureOutcome, type EnforceInput, type EnforceResponse, type EnforcementAction, type EnforcementDecision, type LogDetectionInput, VERSION, getCheckpointApiClient, getCheckpointPostureOutcome, resetCheckpointApiClient, withCheckpoint, withCheckpointApi };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { a as EnforceResponse, c as LogDetectionInput, i as EnforceInput, l as getCheckpointApiClient, n as CheckpointApiClient, o as EnforcementAction, r as CheckpointApiClientConfig, s as EnforcementDecision, u as resetCheckpointApiClient } from "./api-client-JHOrRUA_.js";
2
2
  import { n as withCheckpointApi, t as CheckpointApiMiddlewareConfig } from "./api-middleware-DyLDqOYF.js";
3
- import { t as CheckpointConfig } from "./config-DVgOFxJs.js";
3
+ import { t as CheckpointConfig } from "./config-CXS_-rRv.js";
4
4
  import { n as CheckpointPostureOutcome, r as getCheckpointPostureOutcome, t as CheckpointPostureOptions } from "./posture-outcome-Ccujx_9V.js";
5
- import { t as VERSION } from "./middleware-core-Bol44X9C.js";
6
- import "./public-api-CYsHrTQI.js";
5
+ import { t as VERSION } from "./middleware-core-DaNMjsib.js";
6
+ import "./public-api-DnTh8YEz.js";
7
7
  import { withCheckpoint } from "./middleware-node.js";
8
8
  export { CheckpointApiClient, type CheckpointApiClientConfig, type CheckpointApiMiddlewareConfig, type CheckpointConfig, type CheckpointPostureOptions, type CheckpointPostureOutcome, type EnforceInput, type EnforceResponse, type EnforcementAction, type EnforcementDecision, type LogDetectionInput, VERSION, getCheckpointApiClient, getCheckpointPostureOutcome, resetCheckpointApiClient, withCheckpoint, withCheckpointApi };
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_middleware_core = require('./middleware-core-CMc-2QkU.js');
2
+ const require_middleware_core = require('./middleware-core-0s8y7UNN.js');
3
3
  const require_middleware_node = require('./middleware-node.js');
4
4
  const require_posture_outcome = require('./posture-outcome-DddsJtL8.js');
5
5
  const require_api_client = require('./api-client.js');
6
- const require_api_middleware = require('./api-middleware-Bf3xmM9W.js');
6
+ const require_api_middleware = require('./api-middleware-LhLqOapx.js');
7
7
 
8
8
  //#region src/index.ts
9
9
  /**
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { t as VERSION } from "./middleware-core-B0jf5_Hm.mjs";
1
+ import { t as VERSION } from "./middleware-core-DN_FLlaV.mjs";
2
2
  import { withCheckpoint } from "./middleware-node.mjs";
3
3
  import { t as getCheckpointPostureOutcome } from "./posture-outcome-DQ4fdMfq.mjs";
4
4
  import { CheckpointApiClient, getCheckpointApiClient, resetCheckpointApiClient } from "./api-client.mjs";
5
- import { t as withCheckpointApi } from "./api-middleware-C-ngFX_8.mjs";
5
+ import { t as withCheckpointApi } from "./api-middleware-DcUgTDv5.mjs";
6
6
 
7
7
  //#region src/index.ts
8
8
  /**
@@ -1,4 +1,4 @@
1
- import { t as CheckpointConfig } from "./config-CPP1RV0f.mjs";
1
+ import { t as CheckpointConfig } from "./config-DQ-VuHlJ.mjs";
2
2
  //#region src/middleware-bundler.d.ts
3
3
  /** Next.js server bundlers import the WASM asset rather than relocating a Node fs read. */
4
4
  export declare function withCheckpoint(config: CheckpointConfig): (req: import("next/server").NextRequest, event?: Pick<import("next/server").NextFetchEvent, "waitUntil">) => Promise<import("next/server").NextResponse>;
@@ -1,4 +1,4 @@
1
- import { t as CheckpointConfig } from "./config-DVgOFxJs.js";
1
+ import { t as CheckpointConfig } from "./config-CXS_-rRv.js";
2
2
  //#region src/middleware-bundler.d.ts
3
3
  /** Next.js server bundlers import the WASM asset rather than relocating a Node fs read. */
4
4
  export declare function withCheckpoint(config: CheckpointConfig): (req: import("next/server").NextRequest, event?: Pick<import("next/server").NextFetchEvent, "waitUntil">) => Promise<import("next/server").NextResponse>;
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_middleware_core = require('./middleware-core-CMc-2QkU.js');
3
- const require_middleware_node_context = require('./middleware-node-context-591KsiYg.js');
2
+ const require_middleware_core = require('./middleware-core-0s8y7UNN.js');
3
+ const require_middleware_node_context = require('./middleware-node-context-TRMTgp3y.js');
4
4
 
5
5
  //#region src/middleware-bundler.ts
6
6
  /** Next.js server bundlers import the WASM asset rather than relocating a Node fs read. */
@@ -8,7 +8,7 @@ function withCheckpoint(config) {
8
8
  return require_middleware_core.makeNextMiddleware(config, {
9
9
  runtime: "node",
10
10
  loadEngine: () => import("@kya-os/checkpoint-wasm-runtime/orchestrator/bundler"),
11
- buildComposedContext: require_middleware_node_context.buildComposedContext
11
+ policyCompiler: require_middleware_node_context.nodePolicyCompiler
12
12
  });
13
13
  }
14
14
 
@@ -1,5 +1,5 @@
1
- import { n as makeNextMiddleware } from "./middleware-core-B0jf5_Hm.mjs";
2
- import { t as buildComposedContext } from "./middleware-node-context-D_ZyUEcA.mjs";
1
+ import { n as makeNextMiddleware } from "./middleware-core-DN_FLlaV.mjs";
2
+ import { t as nodePolicyCompiler } from "./middleware-node-context-BvqrL2Ra.mjs";
3
3
 
4
4
  //#region src/middleware-bundler.ts
5
5
  /** Next.js server bundlers import the WASM asset rather than relocating a Node fs read. */
@@ -7,7 +7,7 @@ function withCheckpoint(config) {
7
7
  return makeNextMiddleware(config, {
8
8
  runtime: "node",
9
9
  loadEngine: () => import("@kya-os/checkpoint-wasm-runtime/orchestrator/bundler"),
10
- buildComposedContext
10
+ policyCompiler: nodePolicyCompiler
11
11
  });
12
12
  }
13
13
 
@@ -1 +1 @@
1
- {"version":3,"file":"middleware-bundler.mjs","names":[],"sources":["../src/middleware-bundler.ts"],"sourcesContent":["import { makeNextMiddleware } from './middleware-core';\nimport { buildComposedContext } from './middleware-node-context';\nimport type { CheckpointConfig } from './config';\nexport type { CheckpointConfig } from './config';\n\n/** Next.js server bundlers import the WASM asset rather than relocating a Node fs read. */\nexport function withCheckpoint(config: CheckpointConfig) {\n return makeNextMiddleware(config, {\n runtime: 'node',\n // Imported on first use: a failure to load the engine is then answered 503\n // per request instead of failing this module.\n loadEngine: () => import('@kya-os/checkpoint-wasm-runtime/orchestrator/bundler'),\n buildComposedContext,\n });\n}\n"],"mappings":";;;;;AAMA,SAAgB,eAAe,QAA0B;CACvD,OAAO,mBAAmB,QAAQ;EAChC,SAAS;EAGT,kBAAkB,OAAO;EACzB;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"middleware-bundler.mjs","names":[],"sources":["../src/middleware-bundler.ts"],"sourcesContent":["import { makeNextMiddleware } from './middleware-core';\nimport { nodePolicyCompiler } from './middleware-node-context';\nimport type { CheckpointConfig } from './config';\nexport type { CheckpointConfig } from './config';\n\n/** Next.js server bundlers import the WASM asset rather than relocating a Node fs read. */\nexport function withCheckpoint(config: CheckpointConfig) {\n return makeNextMiddleware(config, {\n runtime: 'node',\n // Imported on first use: a failure to load the engine is then answered 503\n // per request instead of failing this module.\n loadEngine: () => import('@kya-os/checkpoint-wasm-runtime/orchestrator/bundler'),\n policyCompiler: nodePolicyCompiler,\n });\n}\n"],"mappings":";;;;;AAMA,SAAgB,eAAe,QAA0B;CACvD,OAAO,mBAAmB,QAAQ;EAChC,SAAS;EAGT,kBAAkB,OAAO;EACzB,gBAAgB;CAClB,CAAC;AACH"}
@@ -0,0 +1,203 @@
1
+ const require_adapt = require('./adapt-D2-OBY9M.js');
2
+ const require_utils = require('./utils-dyFxqlFI.js');
3
+ let _kya_os_checkpoint_wasm_runtime_pipeline = require("@kya-os/checkpoint-wasm-runtime/pipeline");
4
+ let _vercel_functions = require("@vercel/functions");
5
+ let _kya_os_checkpoint_shared_kya_http = require("@kya-os/checkpoint-shared/kya-http");
6
+
7
+ //#region src/translate.ts
8
+ /**
9
+ * Translate a Next.js `NextRequest` into the orchestrator's
10
+ * `IncomingHttpLike` shape.
11
+ *
12
+ * When `opts.drainJsonBody !== false` the translator reads a clone of
13
+ * the request body: JSON as a string so `buildAgentRequest` can extract
14
+ * a `_meta.proof.jws` envelope, and the body of a kya-http/2 signed
15
+ * request as its exact bytes (`rawBody`) for the `Content-Digest` check.
16
+ * The original `req.body` stream is preserved for downstream handlers.
17
+ *
18
+ * When the body can't be read (drain disabled, non-JSON unsigned, or a
19
+ * stream error) we pass `body: null` and the orchestrator routes to
20
+ * PlainHttp — same behavior as the pre-1.1.0 default. A kya-http/2
21
+ * request whose `Content-Length` or `Transfer-Encoding` declares a body
22
+ * the engine never received is refused by the orchestrator.
23
+ */
24
+ async function translateNextRequest(req, opts = {}) {
25
+ const url = new URL(req.url);
26
+ const { body, rawBody, signedBodyTooLarge } = await tryDrainBody(req, opts);
27
+ return {
28
+ httpLike: {
29
+ method: req.method,
30
+ url: url.pathname + url.search,
31
+ headers: headersToRecord(req.headers),
32
+ body,
33
+ ...rawBody ? { rawBody } : {},
34
+ remoteAddress: require_utils.getClientIp(req, opts.clientIpPolicy)
35
+ },
36
+ signedBodyTooLarge
37
+ };
38
+ }
39
+ /**
40
+ * Read the request body when the caller has opted in (default). Returns
41
+ * `body: null` on any failure — the orchestrator handles `null` as "no
42
+ * body present" (→ PlainHttp).
43
+ *
44
+ * Clone-first means the original `req.body` ReadableStream stays
45
+ * unconsumed and downstream handlers can re-read it. Without the
46
+ * clone, calling `req.text()` in middleware would block any route
47
+ * handler that needs the body.
48
+ */
49
+ async function tryDrainBody(req, opts) {
50
+ if (opts.drainJsonBody === false) return {
51
+ body: null,
52
+ signedBodyTooLarge: false
53
+ };
54
+ const isJson = (req.headers.get("content-type") ?? "").toLowerCase().includes("application/json");
55
+ if ((0, _kya_os_checkpoint_shared_kya_http.requestPresentsKyaSignature)(req.headers)) {
56
+ const read = await (0, _kya_os_checkpoint_shared_kya_http.readBodyBounded)(req, _kya_os_checkpoint_shared_kya_http.KYA_SIGNED_BODY_MAX_BYTES);
57
+ if ("failure" in read) return {
58
+ body: null,
59
+ signedBodyTooLarge: read.failure === "too-large"
60
+ };
61
+ return {
62
+ body: isJson ? new TextDecoder().decode(read.bytes) : null,
63
+ rawBody: read.bytes,
64
+ signedBodyTooLarge: false
65
+ };
66
+ }
67
+ if (!isJson) return {
68
+ body: null,
69
+ signedBodyTooLarge: false
70
+ };
71
+ try {
72
+ return {
73
+ body: await req.clone().text(),
74
+ signedBodyTooLarge: false
75
+ };
76
+ } catch {
77
+ return {
78
+ body: null,
79
+ signedBodyTooLarge: false
80
+ };
81
+ }
82
+ }
83
+ /**
84
+ * Convert a `Headers` instance into a lowercase-keyed plain object.
85
+ * HTTP header names are case-insensitive (RFC 9110 § 5.1); the
86
+ * orchestrator does case-sensitive lookups, so we normalise to
87
+ * lowercase here. Multi-value headers (Set-Cookie, Accept) are
88
+ * surfaced as their `Headers.get()` view — a single string with
89
+ * comma-joined values, matching what other host adapters produce.
90
+ */
91
+ function headersToRecord(headers) {
92
+ const out = {};
93
+ headers.forEach((value, key) => {
94
+ out[key.toLowerCase()] = value;
95
+ });
96
+ return out;
97
+ }
98
+
99
+ //#endregion
100
+ //#region src/middleware-core.ts
101
+ /**
102
+ * The Next.js side of the shared request pipeline
103
+ * (`@kya-os/checkpoint-wasm-runtime/pipeline`). Node, bundler and Edge hosts
104
+ * inject their engine and Cedar compiler; runtime-specific WASM initialization
105
+ * stays in each host entry. Public withCheckpoint exports live there too.
106
+ */
107
+ /** npm package name this SDK self-reports to the detection reporter. */
108
+ const SDK_NAME = "@kya-os/checkpoint-nextjs";
109
+ /**
110
+ * Installed SDK version, self-reported to the detection reporter so the
111
+ * dashboard can version-gate "composed policy enforces here". MUST equal
112
+ * `package.json` version — pinned by a unit test (the old hardcoded `0.1.0` had
113
+ * drifted). Re-exported as `VERSION` from the package index.
114
+ */
115
+ const VERSION = "1.13.0";
116
+ /**
117
+ * Build the Checkpoint middleware. Returns a function `(req) => NextResponse`
118
+ * suitable for `export default withCheckpoint({...})` in `middleware.ts`.
119
+ *
120
+ * Every verification decision flows through the Rust `kya-os-engine`
121
+ * via WASM. The TS layer translates request shape, runs the shared
122
+ * pipeline, and translates the verdict to `NextResponse`. No
123
+ * verification logic lives in this file.
124
+ *
125
+ * It never throws. An error in the configuration or in loading the engine
126
+ * would otherwise fail the middleware module, and a Next.js middleware that
127
+ * fails to load can let requests through unchecked. Every such error is
128
+ * answered 503 instead (fail closed) and logged.
129
+ */
130
+ function makeNextMiddleware(config, host) {
131
+ try {
132
+ return makeMiddleware(config, host);
133
+ } catch (error) {
134
+ return async function misconfiguredCheckpointMiddleware() {
135
+ console.error("[checkpoint] withCheckpoint is misconfigured; responding 503:", error);
136
+ return require_adapt.failClosedResponse();
137
+ };
138
+ }
139
+ }
140
+ function makeMiddleware(config, host) {
141
+ const pipeline = (0, _kya_os_checkpoint_wasm_runtime_pipeline.makeCheckpointPipeline)(config, {
142
+ sdk: {
143
+ name: SDK_NAME,
144
+ version: VERSION,
145
+ runtime: host.runtime
146
+ },
147
+ loadEngine: host.loadEngine,
148
+ policyCompiler: host.policyCompiler,
149
+ start: host.start
150
+ });
151
+ const translateOpts = {
152
+ drainJsonBody: config.drainJsonBody,
153
+ clientIpPolicy: config.clientIpPolicy
154
+ };
155
+ return async function checkpointMiddleware(req, event) {
156
+ const waitUntil = event ? (promise) => event.waitUntil(promise) : _vercel_functions.waitUntil;
157
+ try {
158
+ const { httpLike, signedBodyTooLarge } = await translateNextRequest(req, translateOpts);
159
+ if (signedBodyTooLarge && config.enforcementMode !== "observe") return require_adapt.signedBodyTooLargeResponse();
160
+ const { rendered } = await pipeline({
161
+ request: req,
162
+ translate: () => httpLike,
163
+ headers: req.headers,
164
+ path: req.nextUrl.pathname,
165
+ clientIp: () => require_utils.getClientIp(req, config.clientIpPolicy),
166
+ reportContext: () => extractReporterContext(req, config.clientIpPolicy),
167
+ waitUntil
168
+ });
169
+ return require_adapt.adaptToNextResponse(rendered, req);
170
+ } catch (err) {
171
+ (0, _kya_os_checkpoint_wasm_runtime_pipeline.logPipelineFailure)(err, config.debug);
172
+ return require_adapt.failClosedResponse();
173
+ }
174
+ };
175
+ }
176
+ /**
177
+ * Pull the request context the dashboard's `/api/v1/log-detection`
178
+ * endpoint expects out of a `NextRequest`. Works under both Node and
179
+ * Edge runtimes — no runtime-specific APIs.
180
+ */
181
+ function extractReporterContext(req, policy) {
182
+ return {
183
+ userAgent: req.headers.get("user-agent") ?? void 0,
184
+ ipAddress: require_utils.getClientIp(req, policy),
185
+ path: req.nextUrl.pathname,
186
+ url: req.nextUrl.href,
187
+ method: req.method
188
+ };
189
+ }
190
+
191
+ //#endregion
192
+ Object.defineProperty(exports, 'VERSION', {
193
+ enumerable: true,
194
+ get: function () {
195
+ return VERSION;
196
+ }
197
+ });
198
+ Object.defineProperty(exports, 'makeNextMiddleware', {
199
+ enumerable: true,
200
+ get: function () {
201
+ return makeNextMiddleware;
202
+ }
203
+ });
@@ -1,9 +1,6 @@
1
- import "./config-DVgOFxJs.js";
1
+ import "./config-DQ-VuHlJ.mjs";
2
+ import "@kya-os/checkpoint-wasm-runtime/pipeline";
2
3
  import { NextRequest, NextResponse } from "next/server.js";
3
- import "@kya-os/checkpoint-wasm-runtime/orchestrator/edge";
4
- import { ComposedPolicyContext } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
5
- import { VerifyResult } from "@kya-os/checkpoint-wasm-runtime/engine";
6
- import "@kya-os/checkpoint-wasm-runtime/orchestrator";
7
4
  //#region src/middleware-core.d.ts
8
5
  /**
9
6
  * Installed SDK version, self-reported to the detection reporter so the
@@ -11,7 +8,7 @@ import "@kya-os/checkpoint-wasm-runtime/orchestrator";
11
8
  * `package.json` version — pinned by a unit test (the old hardcoded `0.1.0` had
12
9
  * drifted). Re-exported as `VERSION` from the package index.
13
10
  */
14
- declare const VERSION = "1.11.0";
11
+ declare const VERSION = "1.13.0";
15
12
  //#endregion
16
13
  export { VERSION as t };
17
- //# sourceMappingURL=middleware-core-Bol44X9C.d.ts.map
14
+ //# sourceMappingURL=middleware-core-Cxb9Jh0a.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware-core-Cxb9Jh0a.d.mts","names":[],"sources":["../src/middleware-core.ts"],"mappings":";;;;;;;;;;cA4Da"}