@kya-os/checkpoint-nextjs 1.10.0 → 1.12.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 (214) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/README.md +217 -35
  3. package/dist/{adapt.mjs → adapt-BvqYgrAk.mjs} +15 -4
  4. package/dist/adapt-BvqYgrAk.mjs.map +1 -0
  5. package/dist/{adapt.js → adapt-DUEIfZnx.js} +34 -13
  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 -204
  11. package/dist/api-client.d.ts +2 -204
  12. package/dist/api-client.js +19 -18
  13. package/dist/api-client.mjs +20 -16
  14. package/dist/api-client.mjs.map +1 -1
  15. package/dist/api-middleware-BtsYJU5u.d.mts +131 -0
  16. package/dist/api-middleware-BtsYJU5u.d.mts.map +1 -0
  17. package/dist/{api-middleware-CMDRoQik.mjs → api-middleware-DvmkJ_Li.mjs} +68 -38
  18. package/dist/api-middleware-DvmkJ_Li.mjs.map +1 -0
  19. package/dist/api-middleware-DyLDqOYF.d.ts +131 -0
  20. package/dist/api-middleware-DyLDqOYF.d.ts.map +1 -0
  21. package/dist/{api-middleware-CDSh3TSE.js → api-middleware-beNlXd5P.js} +75 -63
  22. package/dist/api-middleware.d.mts +2 -152
  23. package/dist/api-middleware.d.ts +2 -152
  24. package/dist/api-middleware.js +1 -5
  25. package/dist/api-middleware.mjs +2 -3
  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-D7h2w_it.d.mts +89 -0
  34. package/dist/config-D7h2w_it.d.mts.map +1 -0
  35. package/dist/config-DkXvl4nH.d.ts +89 -0
  36. package/dist/config-DkXvl4nH.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 -10
  49. package/dist/index.d.ts +8 -10
  50. package/dist/index.js +20 -49
  51. package/dist/index.mjs +21 -8
  52. package/dist/index.mjs.map +1 -1
  53. package/dist/middleware-bundler.d.mts +1 -1
  54. package/dist/middleware-bundler.d.mts.map +1 -1
  55. package/dist/middleware-bundler.d.ts +1 -1
  56. package/dist/middleware-bundler.d.ts.map +1 -1
  57. package/dist/middleware-bundler.js +5 -5
  58. package/dist/middleware-bundler.mjs +5 -5
  59. package/dist/middleware-bundler.mjs.map +1 -1
  60. package/dist/middleware-core-B1GuspOY.js +169 -0
  61. package/dist/middleware-core-BmW2kH8J.d.ts +14 -0
  62. package/dist/middleware-core-BmW2kH8J.d.ts.map +1 -0
  63. package/dist/middleware-core-CnPUoD2v.d.mts +14 -0
  64. package/dist/middleware-core-CnPUoD2v.d.mts.map +1 -0
  65. package/dist/middleware-core-WZeMSRqx.mjs +159 -0
  66. package/dist/middleware-core-WZeMSRqx.mjs.map +1 -0
  67. package/dist/middleware-edge.d.mts +11 -3
  68. package/dist/middleware-edge.d.mts.map +1 -1
  69. package/dist/middleware-edge.d.ts +11 -3
  70. package/dist/middleware-edge.d.ts.map +1 -1
  71. package/dist/middleware-edge.js +68 -29
  72. package/dist/middleware-edge.mjs +68 -31
  73. package/dist/middleware-edge.mjs.map +1 -1
  74. package/dist/middleware-node-context-BvqrL2Ra.mjs +16 -0
  75. package/dist/middleware-node-context-BvqrL2Ra.mjs.map +1 -0
  76. package/dist/middleware-node-context-TRMTgp3y.js +20 -0
  77. package/dist/middleware-node.d.mts +12 -3
  78. package/dist/middleware-node.d.mts.map +1 -0
  79. package/dist/middleware-node.d.ts +12 -3
  80. package/dist/middleware-node.d.ts.map +1 -0
  81. package/dist/middleware-node.js +14 -6
  82. package/dist/middleware-node.mjs +14 -6
  83. package/dist/middleware-node.mjs.map +1 -1
  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-Cw7Zj290.d.ts +5 -0
  92. package/dist/public-api-DgCw1uo6.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 +27 -62
  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 -11
  101. package/dist/adapt.d.mts.map +0 -1
  102. package/dist/adapt.d.ts +0 -11
  103. package/dist/adapt.d.ts.map +0 -1
  104. package/dist/adapt.mjs.map +0 -1
  105. package/dist/api-client.d.mts.map +0 -1
  106. package/dist/api-client.d.ts.map +0 -1
  107. package/dist/api-middleware-CMDRoQik.mjs.map +0 -1
  108. package/dist/api-middleware.d.mts.map +0 -1
  109. package/dist/api-middleware.d.ts.map +0 -1
  110. package/dist/composed-policy-BCaNiVHv.d.mts +0 -98
  111. package/dist/composed-policy-BCaNiVHv.d.mts.map +0 -1
  112. package/dist/composed-policy-zzJYNFTb.d.ts +0 -98
  113. package/dist/composed-policy-zzJYNFTb.d.ts.map +0 -1
  114. package/dist/composed-policy.d.mts +0 -2
  115. package/dist/composed-policy.d.ts +0 -2
  116. package/dist/composed-policy.js +0 -136
  117. package/dist/composed-policy.mjs +0 -132
  118. package/dist/composed-policy.mjs.map +0 -1
  119. package/dist/config-CbAg2mze.d.ts +0 -255
  120. package/dist/config-CbAg2mze.d.ts.map +0 -1
  121. package/dist/config-Doe0Tn53.d.mts +0 -255
  122. package/dist/config-Doe0Tn53.d.mts.map +0 -1
  123. package/dist/create-middleware.d.mts +0 -11
  124. package/dist/create-middleware.d.mts.map +0 -1
  125. package/dist/create-middleware.d.ts +0 -11
  126. package/dist/create-middleware.d.ts.map +0 -1
  127. package/dist/create-middleware.js +0 -39
  128. package/dist/create-middleware.mjs +0 -38
  129. package/dist/create-middleware.mjs.map +0 -1
  130. package/dist/edge/index.d.mts +0 -88
  131. package/dist/edge/index.d.mts.map +0 -1
  132. package/dist/edge/index.d.ts +0 -88
  133. package/dist/edge/index.d.ts.map +0 -1
  134. package/dist/edge/index.js +0 -362
  135. package/dist/edge/index.mjs +0 -362
  136. package/dist/edge/index.mjs.map +0 -1
  137. package/dist/edge-runtime-loader.d.mts +0 -49
  138. package/dist/edge-runtime-loader.d.mts.map +0 -1
  139. package/dist/edge-runtime-loader.d.ts +0 -49
  140. package/dist/edge-runtime-loader.d.ts.map +0 -1
  141. package/dist/edge-runtime-loader.js +0 -297
  142. package/dist/edge-runtime-loader.mjs +0 -292
  143. package/dist/edge-runtime-loader.mjs.map +0 -1
  144. package/dist/edge-wasm-middleware.d.mts +0 -43
  145. package/dist/edge-wasm-middleware.d.mts.map +0 -1
  146. package/dist/edge-wasm-middleware.d.ts +0 -43
  147. package/dist/edge-wasm-middleware.d.ts.map +0 -1
  148. package/dist/edge-wasm-middleware.js +0 -37
  149. package/dist/edge-wasm-middleware.mjs +0 -35
  150. package/dist/edge-wasm-middleware.mjs.map +0 -1
  151. package/dist/middleware-core-BYQP9FND.mjs +0 -165
  152. package/dist/middleware-core-BYQP9FND.mjs.map +0 -1
  153. package/dist/middleware-core-D6TijE6P.js +0 -175
  154. package/dist/middleware-node-CE4GevYs.d.ts +0 -20
  155. package/dist/middleware-node-CE4GevYs.d.ts.map +0 -1
  156. package/dist/middleware-node-DtyOuPta.d.mts +0 -20
  157. package/dist/middleware-node-DtyOuPta.d.mts.map +0 -1
  158. package/dist/middleware-node-context-BqPbf-fI.mjs +0 -34
  159. package/dist/middleware-node-context-BqPbf-fI.mjs.map +0 -1
  160. package/dist/middleware-node-context-rgnc7UNR.js +0 -38
  161. package/dist/middleware.d.mts +0 -25
  162. package/dist/middleware.d.mts.map +0 -1
  163. package/dist/middleware.d.ts +0 -25
  164. package/dist/middleware.d.ts.map +0 -1
  165. package/dist/middleware.js +0 -53
  166. package/dist/middleware.mjs +0 -51
  167. package/dist/middleware.mjs.map +0 -1
  168. package/dist/nodejs-wasm-loader.d.mts +0 -42
  169. package/dist/nodejs-wasm-loader.d.mts.map +0 -1
  170. package/dist/nodejs-wasm-loader.d.ts +0 -42
  171. package/dist/nodejs-wasm-loader.d.ts.map +0 -1
  172. package/dist/nodejs-wasm-loader.js +0 -70
  173. package/dist/nodejs-wasm-loader.mjs +0 -66
  174. package/dist/nodejs-wasm-loader.mjs.map +0 -1
  175. package/dist/policy.d.mts +0 -138
  176. package/dist/policy.d.mts.map +0 -1
  177. package/dist/policy.d.ts +0 -138
  178. package/dist/policy.d.ts.map +0 -1
  179. package/dist/policy.js +0 -236
  180. package/dist/policy.mjs +0 -205
  181. package/dist/policy.mjs.map +0 -1
  182. package/dist/session-tracker.d.mts +0 -50
  183. package/dist/session-tracker.d.mts.map +0 -1
  184. package/dist/session-tracker.d.ts +0 -50
  185. package/dist/session-tracker.d.ts.map +0 -1
  186. package/dist/session-tracker.js +0 -148
  187. package/dist/session-tracker.mjs +0 -147
  188. package/dist/session-tracker.mjs.map +0 -1
  189. package/dist/translate.d.mts +0 -48
  190. package/dist/translate.d.mts.map +0 -1
  191. package/dist/translate.d.ts +0 -48
  192. package/dist/translate.d.ts.map +0 -1
  193. package/dist/translate.js +0 -79
  194. package/dist/translate.mjs +0 -79
  195. package/dist/translate.mjs.map +0 -1
  196. package/dist/types-C0SkqLMM.d.mts +0 -102
  197. package/dist/types-C0SkqLMM.d.mts.map +0 -1
  198. package/dist/types-C7DNSCTO.d.ts +0 -102
  199. package/dist/types-C7DNSCTO.d.ts.map +0 -1
  200. package/dist/utils-Cj4XNhIY.mjs +0 -35
  201. package/dist/utils-Cj4XNhIY.mjs.map +0 -1
  202. package/dist/utils-DAisnYnI.js +0 -45
  203. package/dist/wasm-setup.d.mts +0 -47
  204. package/dist/wasm-setup.d.mts.map +0 -1
  205. package/dist/wasm-setup.d.ts +0 -47
  206. package/dist/wasm-setup.d.ts.map +0 -1
  207. package/dist/wasm-setup.js +0 -91
  208. package/dist/wasm-setup.mjs +0 -95
  209. package/dist/wasm-setup.mjs.map +0 -1
  210. package/wasm/agentshield_wasm.d.ts +0 -479
  211. package/wasm/agentshield_wasm.js +0 -1536
  212. package/wasm/agentshield_wasm_bg.wasm +0 -0
  213. package/wasm/package.json +0 -30
  214. package/wasm.d.ts +0 -21
@@ -1,44 +1,81 @@
1
- import { DEFAULT_DASHBOARD_URL, consoleComposedPolicyLogger, makeComposedPolicyContext } from "./composed-policy.mjs";
2
- import { n as makeNextMiddleware } from "./middleware-core-BYQP9FND.mjs";
3
- import { PolicyFetcher } from "@kya-os/checkpoint-shared";
1
+ import { n as makeNextMiddleware } from "./middleware-core-WZeMSRqx.mjs";
2
+ import { t as getCheckpointPostureOutcome } from "./posture-outcome-DQ4fdMfq.mjs";
4
3
  import { initEngineEdge, renderDecisionAsResponse, verifyRequestEdge } from "@kya-os/checkpoint-wasm-runtime/orchestrator/edge";
5
- import { evaluatePolicy as evaluatePolicy$1, initPolicyEvaluatorEdge } from "@kya-os/checkpoint-wasm-runtime/policy-edge";
4
+ import { evaluatePolicy, initPolicyEvaluatorEdge, isCedarModule } from "@kya-os/checkpoint-wasm-runtime/policy-edge";
6
5
 
7
6
  //#region src/middleware-edge.ts
8
- /** Edge host: eagerly initialize its engine and opt into Cedar only when wired. */
7
+ /**
8
+ * Edge host: the engine runs on the module the host passes. The Cedar build
9
+ * (`./cedar-wasm`) is the engine plus Cedar, so passed as `engineWasmModule`
10
+ * (or alone as `cedarWasmModule`) one instance serves detection and policy.
11
+ */
9
12
  function withCheckpoint(config) {
10
- initEngineEdge();
11
- return makeNextMiddleware(verifyRequestEdge, renderDecisionAsResponse, config, {
13
+ return makeNextMiddleware(config, {
12
14
  runtime: "edge",
13
- buildComposedContext
15
+ loadEngine: async () => {
16
+ await initEngineEdge(engineModule(config));
17
+ return {
18
+ verifyRequest: verifyRequestEdge,
19
+ renderDecisionAsResponse
20
+ };
21
+ },
22
+ policyCompiler: edgePolicyCompiler,
23
+ start: checkModules
14
24
  });
15
25
  }
26
+ /** The module the engine runs on: `engineWasmModule`, else the Cedar build. */
27
+ function engineModule(config) {
28
+ return config.engineWasmModule ?? config.cedarWasmModule;
29
+ }
30
+ /** The Cedar build, whichever field it was passed in. */
31
+ function cedarModule(config) {
32
+ if (config.cedarWasmModule) return config.cedarWasmModule;
33
+ return isCedarModule(config.engineWasmModule) ? config.engineWasmModule : void 0;
34
+ }
35
+ function checkModules(config) {
36
+ if (!engineModule(config)) throw new Error("withCheckpoint on the Edge runtime needs engineWasmModule: import it from '@kya-os/checkpoint-nextjs/engine-wasm' (detection), or from '@kya-os/checkpoint-nextjs/cedar-wasm' (detection and Cedar policy), and pass it in the config");
37
+ if (config.debug && config.engineWasmModule && config.cedarWasmModule && !isCedarModule(config.engineWasmModule)) console.warn("[checkpoint] engineWasmModule and cedarWasmModule are two different builds, so the Edge bundle carries the engine twice. The Cedar build is the engine too: pass '@kya-os/checkpoint-nextjs/cedar-wasm' as engineWasmModule alone to run detection and Cedar on one module.");
38
+ }
16
39
  /**
17
- * Build the EDGE-runtime composed-policy context. Unlike Node, edge composed
18
- * enforcement is CONSUMER-OPT-IN: it requires `cedarWasmModule` to be wired so
19
- * the ~2 MB cedar binary is never forced into every consumer's Edge Middleware
20
- * bundle, and so the unproven `new URL('…cedar…')` fallback fetch is never
21
- * reached. Without it the seam stays inert — edge behaves exactly as 1.4.0.
22
- * When wired, the cedar-web module is registered once via
23
- * `initPolicyEvaluatorEdge`, and the async `evaluatePolicy` compiler is injected
24
- * into the shared core (its single-flight cache absorbs the async compile).
40
+ * A project has a Cedar policy, but this Edge middleware has no Cedar module to
41
+ * evaluate it with.
25
42
  */
26
- function buildComposedContext(config) {
27
- if (config.composedPolicyEnforcer) return config.composedPolicyEnforcer;
28
- if (!config.projectId || !config.cedarWasmModule) return null;
29
- initPolicyEvaluatorEdge(config.cedarWasmModule);
30
- return makeComposedPolicyContext({
31
- projectId: config.projectId,
32
- fetcher: new PolicyFetcher({
33
- apiBaseUrl: config.dashboardUrl ?? config.baseUrl ?? "https://kya.vouched.id",
34
- apiKey: config.apiKey,
35
- cacheTtlSeconds: config.policyCacheTtlSeconds
36
- }),
37
- compile: (language, source) => evaluatePolicy$1(language, source),
38
- logger: config.debug ? consoleComposedPolicyLogger : void 0
39
- });
43
+ var CedarWasmModuleMissingError = class extends Error {
44
+ constructor(projectId) {
45
+ super(`Project ${projectId} has a Cedar policy, but withCheckpoint on the Edge runtime has no Cedar module to evaluate it: import it from '@kya-os/checkpoint-nextjs/cedar-wasm' and pass it as engineWasmModule, in place of the engine-only build, so one module runs detection and Cedar. Requests are answered 503 while the policy is enforcing.`);
46
+ this.name = "CedarWasmModuleMissingError";
47
+ }
48
+ };
49
+ /**
50
+ * The EDGE-runtime Cedar compiler for the project's composed policy. The Cedar
51
+ * build is opt-in on the Edge runtime (it is larger than the engine-only
52
+ * build), so Edge bundles that never evaluate Cedar don't carry it. When the
53
+ * host passes it, as `engineWasmModule` or `cedarWasmModule`, it is registered
54
+ * via `initPolicyEvaluatorEdge`, wasm-runtime evaluates policy on the engine's
55
+ * own instance when the engine runs on it, and the async `evaluatePolicy`
56
+ * compiler is used.
57
+ *
58
+ * Without it a project's policy is still fetched and is never skipped: the
59
+ * compiler throws `CedarWasmModuleMissingError`, so a project with no Cedar
60
+ * policy is unaffected, a policy in shadow mode keeps the structured decision,
61
+ * and an enforcing policy answers 503, as any composed-policy fault does.
62
+ */
63
+ function edgePolicyCompiler(config) {
64
+ const projectId = config.projectId ?? "";
65
+ const cedarWasmModule = cedarModule(config);
66
+ if (cedarWasmModule) initPolicyEvaluatorEdge(cedarWasmModule);
67
+ let reportedMissingModule = false;
68
+ return async (language, source) => {
69
+ if (cedarWasmModule) return evaluatePolicy(language, source);
70
+ const error = new CedarWasmModuleMissingError(projectId);
71
+ if (!reportedMissingModule) {
72
+ reportedMissingModule = true;
73
+ console.error(`[checkpoint] ${error.message}`);
74
+ }
75
+ throw error;
76
+ };
40
77
  }
41
78
 
42
79
  //#endregion
43
- export { initEngineEdge, initPolicyEvaluatorEdge, withCheckpoint };
80
+ export { CedarWasmModuleMissingError, getCheckpointPostureOutcome, initEngineEdge, initPolicyEvaluatorEdge, withCheckpoint };
44
81
  //# sourceMappingURL=middleware-edge.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware-edge.mjs","names":["evaluatePolicy"],"sources":["../src/middleware-edge.ts"],"sourcesContent":["/** Edge host: eagerly initialize its engine and opt into Cedar only when wired. */\nimport {\n initEngineEdge,\n renderDecisionAsResponse,\n verifyRequestEdge,\n} from '@kya-os/checkpoint-wasm-runtime/orchestrator/edge';\nimport {\n evaluatePolicy,\n initPolicyEvaluatorEdge,\n} from '@kya-os/checkpoint-wasm-runtime/policy-edge';\nimport { PolicyFetcher } from '@kya-os/checkpoint-shared';\nimport {\n makeComposedPolicyContext,\n consoleComposedPolicyLogger,\n DEFAULT_DASHBOARD_URL,\n type ComposedPolicyContext,\n} from './composed-policy';\nimport { makeNextMiddleware } from './middleware-core';\nimport type { CheckpointConfig } from './config';\nexport type { CheckpointConfig } from './config';\n\nexport function withCheckpoint(config: CheckpointConfig) {\n // The first request awaits this same idempotent initialization promise.\n void initEngineEdge();\n return makeNextMiddleware(verifyRequestEdge, renderDecisionAsResponse, config, {\n runtime: 'edge',\n buildComposedContext,\n });\n}\n\n/**\n * Build the EDGE-runtime composed-policy context. Unlike Node, edge composed\n * enforcement is CONSUMER-OPT-IN: it requires `cedarWasmModule` to be wired so\n * the ~2 MB cedar binary is never forced into every consumer's Edge Middleware\n * bundle, and so the unproven `new URL('…cedar…')` fallback fetch is never\n * reached. Without it the seam stays inert — edge behaves exactly as 1.4.0.\n * When wired, the cedar-web module is registered once via\n * `initPolicyEvaluatorEdge`, and the async `evaluatePolicy` compiler is injected\n * into the shared core (its single-flight cache absorbs the async compile).\n */\nfunction buildComposedContext(config: CheckpointConfig): ComposedPolicyContext | null {\n if (config.composedPolicyEnforcer) return config.composedPolicyEnforcer;\n if (!config.projectId || !config.cedarWasmModule) return null;\n initPolicyEvaluatorEdge(config.cedarWasmModule);\n return makeComposedPolicyContext({\n projectId: config.projectId,\n fetcher: new PolicyFetcher({\n apiBaseUrl: config.dashboardUrl ?? config.baseUrl ?? DEFAULT_DASHBOARD_URL,\n apiKey: config.apiKey,\n cacheTtlSeconds: config.policyCacheTtlSeconds,\n }),\n compile: (language, source) => evaluatePolicy(language, source),\n logger: config.debug ? consoleComposedPolicyLogger : undefined,\n });\n}\n\n// Allow hosts to initialize their WASM modules explicitly at startup.\nexport { initEngineEdge, initPolicyEvaluatorEdge };\n"],"mappings":";;;;;;;;AAqBA,SAAgB,eAAe,QAA0B;CAEvD,AAAK,eAAe;CACpB,OAAO,mBAAmB,mBAAmB,0BAA0B,QAAQ;EAC7E,SAAS;EACT;CACF,CAAC;AACH;;;;;;;;;;;AAYA,SAAS,qBAAqB,QAAwD;CACpF,IAAI,OAAO,wBAAwB,OAAO,OAAO;CACjD,IAAI,CAAC,OAAO,aAAa,CAAC,OAAO,iBAAiB,OAAO;CACzD,wBAAwB,OAAO,eAAe;CAC9C,OAAO,0BAA0B;EAC/B,WAAW,OAAO;EAClB,SAAS,IAAI,cAAc;GACzB,YAAY,OAAO,gBAAgB,OAAO;GAC1C,QAAQ,OAAO;GACf,iBAAiB,OAAO;EAC1B,CAAC;EACD,UAAU,UAAU,WAAWA,iBAAe,UAAU,MAAM;EAC9D,QAAQ,OAAO,QAAQ,8BAA8B;CACvD,CAAC;AACH"}
1
+ {"version":3,"file":"middleware-edge.mjs","names":[],"sources":["../src/middleware-edge.ts"],"sourcesContent":["/**\n * Edge host: the engine runs on the module the host passes. The Cedar build\n * (`./cedar-wasm`) is the engine plus Cedar, so passed as `engineWasmModule`\n * (or alone as `cedarWasmModule`) one instance serves detection and policy.\n */\nimport {\n initEngineEdge,\n renderDecisionAsResponse,\n verifyRequestEdge,\n} from '@kya-os/checkpoint-wasm-runtime/orchestrator/edge';\nimport {\n evaluatePolicy,\n initPolicyEvaluatorEdge,\n isCedarModule,\n} from '@kya-os/checkpoint-wasm-runtime/policy-edge';\nimport type { PolicyCompile } from '@kya-os/checkpoint-wasm-runtime/pipeline';\nimport { makeNextMiddleware } from './middleware-core';\nimport type { CheckpointConfig, CheckpointEdgeConfig } from './config';\nexport type { CheckpointConfig, CheckpointEdgeConfig } from './config';\nexport {\n getCheckpointPostureOutcome,\n type CheckpointPostureOptions,\n type CheckpointPostureOutcome,\n} from './posture-outcome';\n\nexport function withCheckpoint(config: CheckpointEdgeConfig) {\n return makeNextMiddleware(config, {\n runtime: 'edge',\n // Every attempt passes the module: after a failed init wasm-runtime\n // forgets the module it was given, and an init without one tries to\n // compile bytes, which the Edge runtime cannot do. A failed load is\n // retried by the next request; once loaded, this resolves at once.\n loadEngine: async () => {\n await initEngineEdge(engineModule(config));\n return { verifyRequest: verifyRequestEdge, renderDecisionAsResponse };\n },\n policyCompiler: edgePolicyCompiler,\n start: checkModules,\n });\n}\n\n/** The module the engine runs on: `engineWasmModule`, else the Cedar build. */\nfunction engineModule(config: CheckpointConfig): WebAssembly.Module | undefined {\n return config.engineWasmModule ?? config.cedarWasmModule;\n}\n\n/** The Cedar build, whichever field it was passed in. */\nfunction cedarModule(config: CheckpointConfig): WebAssembly.Module | undefined {\n if (config.cedarWasmModule) return config.cedarWasmModule;\n return isCedarModule(config.engineWasmModule) ? config.engineWasmModule : undefined;\n}\n\nfunction checkModules(config: CheckpointConfig): void {\n // `config` is typed, but the `.` entry's types are the Node build's, where\n // both modules are optional, so check here.\n if (!engineModule(config)) {\n throw new Error(\n 'withCheckpoint on the Edge runtime needs engineWasmModule: import it from ' +\n \"'@kya-os/checkpoint-nextjs/engine-wasm' (detection), or from \" +\n \"'@kya-os/checkpoint-nextjs/cedar-wasm' (detection and Cedar policy), and pass it in the config\"\n );\n }\n if (\n config.debug &&\n config.engineWasmModule &&\n config.cedarWasmModule &&\n !isCedarModule(config.engineWasmModule)\n ) {\n console.warn(\n '[checkpoint] engineWasmModule and cedarWasmModule are two different builds, so the Edge ' +\n 'bundle carries the engine twice. The Cedar build is the engine too: pass ' +\n \"'@kya-os/checkpoint-nextjs/cedar-wasm' as engineWasmModule alone to run detection and \" +\n 'Cedar on one module.'\n );\n }\n}\n\n/**\n * A project has a Cedar policy, but this Edge middleware has no Cedar module to\n * evaluate it with.\n */\nexport class CedarWasmModuleMissingError extends Error {\n constructor(projectId: string) {\n super(\n `Project ${projectId} has a Cedar policy, but withCheckpoint on the Edge runtime has no ` +\n \"Cedar module to evaluate it: import it from '@kya-os/checkpoint-nextjs/cedar-wasm' and \" +\n 'pass it as engineWasmModule, in place of the engine-only build, so one module runs ' +\n 'detection and Cedar. Requests are answered 503 while the policy is enforcing.'\n );\n this.name = 'CedarWasmModuleMissingError';\n }\n}\n\n/**\n * The EDGE-runtime Cedar compiler for the project's composed policy. The Cedar\n * build is opt-in on the Edge runtime (it is larger than the engine-only\n * build), so Edge bundles that never evaluate Cedar don't carry it. When the\n * host passes it, as `engineWasmModule` or `cedarWasmModule`, it is registered\n * via `initPolicyEvaluatorEdge`, wasm-runtime evaluates policy on the engine's\n * own instance when the engine runs on it, and the async `evaluatePolicy`\n * compiler is used.\n *\n * Without it a project's policy is still fetched and is never skipped: the\n * compiler throws `CedarWasmModuleMissingError`, so a project with no Cedar\n * policy is unaffected, a policy in shadow mode keeps the structured decision,\n * and an enforcing policy answers 503, as any composed-policy fault does.\n */\nfunction edgePolicyCompiler(config: CheckpointConfig): PolicyCompile {\n const projectId = config.projectId ?? '';\n const cedarWasmModule = cedarModule(config);\n if (cedarWasmModule) initPolicyEvaluatorEdge(cedarWasmModule);\n let reportedMissingModule = false;\n return async (language, source) => {\n if (cedarWasmModule) return evaluatePolicy(language, source);\n const error = new CedarWasmModuleMissingError(projectId);\n if (!reportedMissingModule) {\n reportedMissingModule = true;\n console.error(`[checkpoint] ${error.message}`);\n }\n throw error;\n };\n}\n\n// Allow hosts to initialize their WASM modules explicitly at startup.\nexport { initEngineEdge, initPolicyEvaluatorEdge };\n"],"mappings":";;;;;;;;;;;AAyBA,SAAgB,eAAe,QAA8B;CAC3D,OAAO,mBAAmB,QAAQ;EAChC,SAAS;EAKT,YAAY,YAAY;GACtB,MAAM,eAAe,aAAa,MAAM,CAAC;GACzC,OAAO;IAAE,eAAe;IAAmB;GAAyB;EACtE;EACA,gBAAgB;EAChB,OAAO;CACT,CAAC;AACH;;AAGA,SAAS,aAAa,QAA0D;CAC9E,OAAO,OAAO,oBAAoB,OAAO;AAC3C;;AAGA,SAAS,YAAY,QAA0D;CAC7E,IAAI,OAAO,iBAAiB,OAAO,OAAO;CAC1C,OAAO,cAAc,OAAO,gBAAgB,IAAI,OAAO,mBAAmB;AAC5E;AAEA,SAAS,aAAa,QAAgC;CAGpD,IAAI,CAAC,aAAa,MAAM,GACtB,MAAM,IAAI,MACR,uOAGF;CAEF,IACE,OAAO,SACP,OAAO,oBACP,OAAO,mBACP,CAAC,cAAc,OAAO,gBAAgB,GAEtC,QAAQ,KACN,6QAIF;AAEJ;;;;;AAMA,IAAa,8BAAb,cAAiD,MAAM;CACrD,YAAY,WAAmB;EAC7B,MACE,WAAW,UAAU,2TAIvB;EACA,KAAK,OAAO;CACd;AACF;;;;;;;;;;;;;;;AAgBA,SAAS,mBAAmB,QAAyC;CACnE,MAAM,YAAY,OAAO,aAAa;CACtC,MAAM,kBAAkB,YAAY,MAAM;CAC1C,IAAI,iBAAiB,wBAAwB,eAAe;CAC5D,IAAI,wBAAwB;CAC5B,OAAO,OAAO,UAAU,WAAW;EACjC,IAAI,iBAAiB,OAAO,eAAe,UAAU,MAAM;EAC3D,MAAM,QAAQ,IAAI,4BAA4B,SAAS;EACvD,IAAI,CAAC,uBAAuB;GAC1B,wBAAwB;GACxB,QAAQ,MAAM,gBAAgB,MAAM,SAAS;EAC/C;EACA,MAAM;CACR;AACF"}
@@ -0,0 +1,16 @@
1
+ //#region src/middleware-node-context.ts
2
+ /**
3
+ * The Node-runtime Cedar compiler for the project's composed policy: the SYNC
4
+ * `createPolicyEvaluator`, whose cedar-nodejs glue loads lazily on first use
5
+ * (no init handshake, never bundled into the edge build).
6
+ */
7
+ function nodePolicyCompiler() {
8
+ return async (_language, source) => {
9
+ const { createPolicyEvaluator } = await import("@kya-os/checkpoint-wasm-runtime/policy");
10
+ return createPolicyEvaluator(source);
11
+ };
12
+ }
13
+
14
+ //#endregion
15
+ export { nodePolicyCompiler as t };
16
+ //# sourceMappingURL=middleware-node-context-BvqrL2Ra.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware-node-context-BvqrL2Ra.mjs","names":[],"sources":["../src/middleware-node-context.ts"],"sourcesContent":["import type { PolicyCompile } from '@kya-os/checkpoint-wasm-runtime/pipeline';\n\n/**\n * The Node-runtime Cedar compiler for the project's composed policy: the SYNC\n * `createPolicyEvaluator`, whose cedar-nodejs glue loads lazily on first use\n * (no init handshake, never bundled into the edge build).\n */\nexport function nodePolicyCompiler(): PolicyCompile {\n // Load the Node policy compiler only on first use. This module is imported\n // exclusively by the Node and bundler hosts, never by the Edge pipeline.\n return async (_language, source) => {\n const { createPolicyEvaluator } = await import('@kya-os/checkpoint-wasm-runtime/policy');\n return createPolicyEvaluator(source);\n };\n}\n"],"mappings":";;;;;;AAOA,SAAgB,qBAAoC;CAGlD,OAAO,OAAO,WAAW,WAAW;EAClC,MAAM,EAAE,0BAA0B,MAAM,OAAO;EAC/C,OAAO,sBAAsB,MAAM;CACrC;AACF"}
@@ -0,0 +1,20 @@
1
+ //#region src/middleware-node-context.ts
2
+ /**
3
+ * The Node-runtime Cedar compiler for the project's composed policy: the SYNC
4
+ * `createPolicyEvaluator`, whose cedar-nodejs glue loads lazily on first use
5
+ * (no init handshake, never bundled into the edge build).
6
+ */
7
+ function nodePolicyCompiler() {
8
+ return async (_language, source) => {
9
+ const { createPolicyEvaluator } = await import("@kya-os/checkpoint-wasm-runtime/policy");
10
+ return createPolicyEvaluator(source);
11
+ };
12
+ }
13
+
14
+ //#endregion
15
+ Object.defineProperty(exports, 'nodePolicyCompiler', {
16
+ enumerable: true,
17
+ get: function () {
18
+ return nodePolicyCompiler;
19
+ }
20
+ });
@@ -1,3 +1,12 @@
1
- import { t as CheckpointConfig } from "./config-Doe0Tn53.mjs";
2
- import { n as VERSION, t as withCheckpoint } from "./middleware-node-DtyOuPta.mjs";
3
- export { type CheckpointConfig, VERSION, withCheckpoint };
1
+ import { t as CheckpointConfig } from "./config-D7h2w_it.mjs";
2
+ import { t as VERSION } from "./middleware-core-CnPUoD2v.mjs";
3
+ //#region src/middleware-node.d.ts
4
+ /**
5
+ * `withCheckpoint` on the Node.js runtime, bundled (`proxy.ts`, `middleware.ts`)
6
+ * or not. The engine's Node build loads its `.wasm` through `new URL(...,
7
+ * import.meta.url)`, which bundlers follow and copy.
8
+ */
9
+ export declare function withCheckpoint(config: CheckpointConfig): (req: import("next/server").NextRequest, event?: Pick<import("next/server").NextFetchEvent, "waitUntil">) => Promise<import("next/server").NextResponse>;
10
+ //#endregion
11
+ export { type CheckpointConfig, VERSION };
12
+ //# sourceMappingURL=middleware-node.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware-node.d.mts","names":[],"sources":["../src/middleware-node.ts"],"mappings":";;;;;;;;wBAUgB,eAAe,QAAQ,oBAAgB,2BAAA,aAAA,QAAA,2BAAA,iCAAA,8BAAA"}
@@ -1,3 +1,12 @@
1
- import { t as CheckpointConfig } from "./config-CbAg2mze.js";
2
- import { n as VERSION, t as withCheckpoint } from "./middleware-node-CE4GevYs.js";
3
- export { type CheckpointConfig, VERSION, withCheckpoint };
1
+ import { t as CheckpointConfig } from "./config-DkXvl4nH.js";
2
+ import { t as VERSION } from "./middleware-core-BmW2kH8J.js";
3
+ //#region src/middleware-node.d.ts
4
+ /**
5
+ * `withCheckpoint` on the Node.js runtime, bundled (`proxy.ts`, `middleware.ts`)
6
+ * or not. The engine's Node build loads its `.wasm` through `new URL(...,
7
+ * import.meta.url)`, which bundlers follow and copy.
8
+ */
9
+ export declare function withCheckpoint(config: CheckpointConfig): (req: import("next/server").NextRequest, event?: Pick<import("next/server").NextFetchEvent, "waitUntil">) => Promise<import("next/server").NextResponse>;
10
+ //#endregion
11
+ export { type CheckpointConfig, VERSION };
12
+ //# sourceMappingURL=middleware-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware-node.d.ts","names":[],"sources":["../src/middleware-node.ts"],"mappings":";;;;;;;;wBAUgB,eAAe,QAAQ,oBAAgB,2BAAA,aAAA,QAAA,2BAAA,iCAAA,8BAAA"}
@@ -1,14 +1,22 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_middleware_core = require('./middleware-core-D6TijE6P.js');
3
- const require_middleware_node_context = require('./middleware-node-context-rgnc7UNR.js');
4
- let _kya_os_checkpoint_wasm_runtime_orchestrator = require("@kya-os/checkpoint-wasm-runtime/orchestrator");
2
+ const require_middleware_core = require('./middleware-core-B1GuspOY.js');
3
+ const require_middleware_node_context = require('./middleware-node-context-TRMTgp3y.js');
5
4
 
6
5
  //#region src/middleware-node.ts
7
- /** Node host with native filesystem WASM loading. */
6
+ /**
7
+ * `withCheckpoint` on the Node.js runtime, bundled (`proxy.ts`, `middleware.ts`)
8
+ * or not. The engine's Node build loads its `.wasm` through `new URL(...,
9
+ * import.meta.url)`, which bundlers follow and copy.
10
+ */
8
11
  function withCheckpoint(config) {
9
- return require_middleware_core.makeNextMiddleware(_kya_os_checkpoint_wasm_runtime_orchestrator.verifyRequest, _kya_os_checkpoint_wasm_runtime_orchestrator.renderDecisionAsResponse, config, {
12
+ return require_middleware_core.makeNextMiddleware(config, {
10
13
  runtime: "node",
11
- buildComposedContext: require_middleware_node_context.buildComposedContext
14
+ loadEngine: async () => {
15
+ const orchestrator = await import("@kya-os/checkpoint-wasm-runtime/orchestrator/node");
16
+ await orchestrator.initEngine();
17
+ return orchestrator;
18
+ },
19
+ policyCompiler: require_middleware_node_context.nodePolicyCompiler
12
20
  });
13
21
  }
14
22
 
@@ -1,13 +1,21 @@
1
- import { n as makeNextMiddleware, t as VERSION } from "./middleware-core-BYQP9FND.mjs";
2
- import { t as buildComposedContext } from "./middleware-node-context-BqPbf-fI.mjs";
3
- import { renderDecisionAsResponse, verifyRequest } from "@kya-os/checkpoint-wasm-runtime/orchestrator";
1
+ import { n as makeNextMiddleware, t as VERSION } from "./middleware-core-WZeMSRqx.mjs";
2
+ import { t as nodePolicyCompiler } from "./middleware-node-context-BvqrL2Ra.mjs";
4
3
 
5
4
  //#region src/middleware-node.ts
6
- /** Node host with native filesystem WASM loading. */
5
+ /**
6
+ * `withCheckpoint` on the Node.js runtime, bundled (`proxy.ts`, `middleware.ts`)
7
+ * or not. The engine's Node build loads its `.wasm` through `new URL(...,
8
+ * import.meta.url)`, which bundlers follow and copy.
9
+ */
7
10
  function withCheckpoint(config) {
8
- return makeNextMiddleware(verifyRequest, renderDecisionAsResponse, config, {
11
+ return makeNextMiddleware(config, {
9
12
  runtime: "node",
10
- buildComposedContext
13
+ loadEngine: async () => {
14
+ const orchestrator = await import("@kya-os/checkpoint-wasm-runtime/orchestrator/node");
15
+ await orchestrator.initEngine();
16
+ return orchestrator;
17
+ },
18
+ policyCompiler: nodePolicyCompiler
11
19
  });
12
20
  }
13
21
 
@@ -1 +1 @@
1
- {"version":3,"file":"middleware-node.mjs","names":[],"sources":["../src/middleware-node.ts"],"sourcesContent":["import {\n verifyRequest,\n renderDecisionAsResponse,\n} from '@kya-os/checkpoint-wasm-runtime/orchestrator';\nimport { makeNextMiddleware } from './middleware-core';\nimport { buildComposedContext } from './middleware-node-context';\nimport type { CheckpointConfig } from './config';\nexport type { CheckpointConfig } from './config';\n\n/** Node host with native filesystem WASM loading. */\nexport function withCheckpoint(config: CheckpointConfig) {\n return makeNextMiddleware(verifyRequest, renderDecisionAsResponse, config, {\n runtime: 'node',\n buildComposedContext,\n });\n}\n\nexport { VERSION } from './middleware-core';\n"],"mappings":";;;;;;AAUA,SAAgB,eAAe,QAA0B;CACvD,OAAO,mBAAmB,eAAe,0BAA0B,QAAQ;EACzE,SAAS;EACT;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"middleware-node.mjs","names":[],"sources":["../src/middleware-node.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/**\n * `withCheckpoint` on the Node.js runtime, bundled (`proxy.ts`, `middleware.ts`)\n * or not. The engine's Node build loads its `.wasm` through `new URL(...,\n * import.meta.url)`, which bundlers follow and copy.\n */\nexport function withCheckpoint(config: CheckpointConfig) {\n return makeNextMiddleware(config, {\n runtime: 'node',\n // Pinned to the Node build whatever conditions a bundler resolves with.\n // Importing it does not read the `.wasm`; `initEngine` does, so a missing\n // or unreadable engine fails here, where it is logged and answered 503,\n // and the next request retries, instead of failing this module.\n loadEngine: async () => {\n const orchestrator = await import('@kya-os/checkpoint-wasm-runtime/orchestrator/node');\n await orchestrator.initEngine();\n return orchestrator;\n },\n policyCompiler: nodePolicyCompiler,\n });\n}\n\nexport { VERSION } from './middleware-core';\n"],"mappings":";;;;;;;;;AAUA,SAAgB,eAAe,QAA0B;CACvD,OAAO,mBAAmB,QAAQ;EAChC,SAAS;EAKT,YAAY,YAAY;GACtB,MAAM,eAAe,MAAM,OAAO;GAClC,MAAM,aAAa,WAAW;GAC9B,OAAO;EACT;EACA,gBAAgB;CAClB,CAAC;AACH"}
@@ -0,0 +1,14 @@
1
+ import { BrowserPostureConfig } from "@kya-os/checkpoint-shared/browser-posture";
2
+ import { PostureHandlerView } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
3
+ //#region src/posture-outcome.d.ts
4
+ type CheckpointPostureOutcome = PostureHandlerView;
5
+ interface CheckpointPostureOptions {
6
+ browserPosture: BrowserPostureConfig;
7
+ projectId: string;
8
+ }
9
+ declare function getCheckpointPostureOutcome(input: Request | Headers | {
10
+ headers: Headers;
11
+ }, options: CheckpointPostureOptions): Promise<CheckpointPostureOutcome>;
12
+ //#endregion
13
+ export { CheckpointPostureOutcome as n, getCheckpointPostureOutcome as r, CheckpointPostureOptions as t };
14
+ //# sourceMappingURL=posture-outcome-Ccujx_9V.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"posture-outcome-Ccujx_9V.d.mts","names":[],"sources":["../src/posture-outcome.ts"],"mappings":";;;KAWY,2BAA2B;UAEtB;EACf,gBAAgB;EAChB;;iBASoB,4BACpB,OAAO,UAAU;EAAY,SAAS;GACtC,SAAS,2BACR,QAAQ"}
@@ -0,0 +1,14 @@
1
+ import { BrowserPostureConfig } from "@kya-os/checkpoint-shared/browser-posture";
2
+ import { PostureHandlerView } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
3
+ //#region src/posture-outcome.d.ts
4
+ type CheckpointPostureOutcome = PostureHandlerView;
5
+ interface CheckpointPostureOptions {
6
+ browserPosture: BrowserPostureConfig;
7
+ projectId: string;
8
+ }
9
+ declare function getCheckpointPostureOutcome(input: Request | Headers | {
10
+ headers: Headers;
11
+ }, options: CheckpointPostureOptions): Promise<CheckpointPostureOutcome>;
12
+ //#endregion
13
+ export { CheckpointPostureOutcome as n, getCheckpointPostureOutcome as r, CheckpointPostureOptions as t };
14
+ //# sourceMappingURL=posture-outcome-Ccujx_9V.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"posture-outcome-Ccujx_9V.d.ts","names":[],"sources":["../src/posture-outcome.ts"],"mappings":";;;KAWY,2BAA2B;UAEtB;EACf,gBAAgB;EAChB;;iBASoB,4BACpB,OAAO,UAAU;EAAY,SAAS;GACtC,SAAS,2BACR,QAAQ"}
@@ -0,0 +1,21 @@
1
+ import { postureOutcomeFromRequest, postureRequestFromHeaders, validateBrowserPostureConfig } from "@kya-os/checkpoint-shared/browser-posture";
2
+ import { postureOutcomeView } from "@kya-os/checkpoint-wasm-runtime/composed-policy";
3
+
4
+ //#region src/posture-outcome.ts
5
+ function hasGet(input) {
6
+ return typeof input.get === "function";
7
+ }
8
+ const validatedProjects = /* @__PURE__ */ new WeakMap();
9
+ async function getCheckpointPostureOutcome(input, options) {
10
+ if (!options.browserPosture) throw new Error("getCheckpointPostureOutcome requires the browserPosture config");
11
+ if (validatedProjects.get(options.browserPosture) !== options.projectId) {
12
+ validateBrowserPostureConfig(options.browserPosture, options.projectId);
13
+ validatedProjects.set(options.browserPosture, options.projectId);
14
+ }
15
+ const headers = hasGet(input) ? input : input.headers;
16
+ return postureOutcomeView(await postureOutcomeFromRequest(postureRequestFromHeaders((name) => headers.get(name)), options.browserPosture, options.projectId));
17
+ }
18
+
19
+ //#endregion
20
+ export { getCheckpointPostureOutcome as t };
21
+ //# sourceMappingURL=posture-outcome-DQ4fdMfq.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"posture-outcome-DQ4fdMfq.mjs","names":[],"sources":["../src/posture-outcome.ts"],"sourcesContent":["import {\n postureOutcomeFromRequest,\n postureRequestFromHeaders,\n validateBrowserPostureConfig,\n type BrowserPostureConfig,\n} from '@kya-os/checkpoint-shared/browser-posture';\nimport {\n postureOutcomeView,\n type PostureHandlerView,\n} from '@kya-os/checkpoint-wasm-runtime/composed-policy';\n\nexport type CheckpointPostureOutcome = PostureHandlerView;\n\nexport interface CheckpointPostureOptions {\n browserPosture: BrowserPostureConfig;\n projectId: string;\n}\n\nfunction hasGet(input: Request | Headers | { headers: Headers }): input is Headers {\n return typeof (input as Headers).get === 'function';\n}\n\nconst validatedProjects = new WeakMap<BrowserPostureConfig, string>();\n\nexport async function getCheckpointPostureOutcome(\n input: Request | Headers | { headers: Headers },\n options: CheckpointPostureOptions\n): Promise<CheckpointPostureOutcome> {\n if (!options.browserPosture) {\n throw new Error('getCheckpointPostureOutcome requires the browserPosture config');\n }\n if (validatedProjects.get(options.browserPosture) !== options.projectId) {\n validateBrowserPostureConfig(options.browserPosture, options.projectId);\n validatedProjects.set(options.browserPosture, options.projectId);\n }\n const headers = hasGet(input) ? input : input.headers;\n return postureOutcomeView(\n await postureOutcomeFromRequest(\n postureRequestFromHeaders((name) => headers.get(name)),\n options.browserPosture,\n options.projectId\n )\n );\n}\n"],"mappings":";;;;AAkBA,SAAS,OAAO,OAAmE;CACjF,OAAO,OAAQ,MAAkB,QAAQ;AAC3C;AAEA,MAAM,oCAAoB,IAAI,QAAsC;AAEpE,eAAsB,4BACpB,OACA,SACmC;CACnC,IAAI,CAAC,QAAQ,gBACX,MAAM,IAAI,MAAM,gEAAgE;CAElF,IAAI,kBAAkB,IAAI,QAAQ,cAAc,MAAM,QAAQ,WAAW;EACvE,6BAA6B,QAAQ,gBAAgB,QAAQ,SAAS;EACtE,kBAAkB,IAAI,QAAQ,gBAAgB,QAAQ,SAAS;CACjE;CACA,MAAM,UAAU,OAAO,KAAK,IAAI,QAAQ,MAAM;CAC9C,OAAO,mBACL,MAAM,0BACJ,2BAA2B,SAAS,QAAQ,IAAI,IAAI,CAAC,GACrD,QAAQ,gBACR,QAAQ,SACV,CACF;AACF"}
@@ -0,0 +1,25 @@
1
+ let _kya_os_checkpoint_shared_browser_posture = require("@kya-os/checkpoint-shared/browser-posture");
2
+ let _kya_os_checkpoint_wasm_runtime_composed_policy = require("@kya-os/checkpoint-wasm-runtime/composed-policy");
3
+
4
+ //#region src/posture-outcome.ts
5
+ function hasGet(input) {
6
+ return typeof input.get === "function";
7
+ }
8
+ const validatedProjects = /* @__PURE__ */ new WeakMap();
9
+ async function getCheckpointPostureOutcome(input, options) {
10
+ if (!options.browserPosture) throw new Error("getCheckpointPostureOutcome requires the browserPosture config");
11
+ if (validatedProjects.get(options.browserPosture) !== options.projectId) {
12
+ (0, _kya_os_checkpoint_shared_browser_posture.validateBrowserPostureConfig)(options.browserPosture, options.projectId);
13
+ validatedProjects.set(options.browserPosture, options.projectId);
14
+ }
15
+ const headers = hasGet(input) ? input : input.headers;
16
+ return (0, _kya_os_checkpoint_wasm_runtime_composed_policy.postureOutcomeView)(await (0, _kya_os_checkpoint_shared_browser_posture.postureOutcomeFromRequest)((0, _kya_os_checkpoint_shared_browser_posture.postureRequestFromHeaders)((name) => headers.get(name)), options.browserPosture, options.projectId));
17
+ }
18
+
19
+ //#endregion
20
+ Object.defineProperty(exports, 'getCheckpointPostureOutcome', {
21
+ enumerable: true,
22
+ get: function () {
23
+ return getCheckpointPostureOutcome;
24
+ }
25
+ });
@@ -0,0 +1,5 @@
1
+ import "./api-client-JHOrRUA_.js";
2
+ import "./api-middleware-DyLDqOYF.js";
3
+ import "./config-DkXvl4nH.js";
4
+ import "./posture-outcome-Ccujx_9V.js";
5
+ import "./middleware-core-BmW2kH8J.js";
@@ -0,0 +1,5 @@
1
+ import "./api-client-JHOrRUA_.mjs";
2
+ import "./api-middleware-BtsYJU5u.mjs";
3
+ import "./config-D7h2w_it.mjs";
4
+ import "./posture-outcome-Ccujx_9V.mjs";
5
+ import "./middleware-core-CnPUoD2v.mjs";
@@ -0,0 +1,33 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ Object.defineProperty(exports, '__toESM', {
29
+ enumerable: true,
30
+ get: function () {
31
+ return __toESM;
32
+ }
33
+ });
@@ -0,0 +1,88 @@
1
+ import { resolveObservedClientAddress } from "@kya-os/checkpoint-shared/client-ip";
2
+
3
+ //#region src/utils.ts
4
+ /**
5
+ * Extract client IP address from a NextRequest.
6
+ * In Next.js 15+, the `ip` property was removed from NextRequest.
7
+ * Forwarded values require an authenticated deployment boundary. NextRequest
8
+ * exposes no socket peer, so arbitrary proxy profiles remain unavailable.
9
+ *
10
+ * @param request - The NextRequest object
11
+ * @returns The client IP address or undefined if not available
12
+ */
13
+ function getClientIp(request, policy = { platform: "direct" }) {
14
+ const frameworkAddress = request.ip;
15
+ const onVercel = typeof process !== "undefined" && process.env?.VERCEL === "1";
16
+ const effectivePolicy = policy.platform === "vercel" && !onVercel ? { platform: "direct" } : policy;
17
+ const resolution = resolveObservedClientAddress({
18
+ headers: request.headers,
19
+ frameworkAddress,
20
+ vercelRuntime: onVercel,
21
+ policy: effectivePolicy
22
+ });
23
+ return resolution.trusted ? resolution.ip : void 0;
24
+ }
25
+ /**
26
+ * Safely extract the hostname from a URL string.
27
+ * Returns a friendly fallback when parsing fails so UX copy doesn't leak
28
+ * "undefined" or similar to end users.
29
+ */
30
+ function safeHostname(url) {
31
+ try {
32
+ return new URL(url).hostname;
33
+ } catch {
34
+ return "this site";
35
+ }
36
+ }
37
+ const DROPPED_HEADERS = [
38
+ "cookie",
39
+ "authorization",
40
+ "proxy-authorization",
41
+ "x-api-key",
42
+ "x-vercel-protection-bypass",
43
+ "cf-access-jwt-assertion",
44
+ "cf-access-client-secret"
45
+ ];
46
+ const CREDENTIAL_HEADER = /^(?!kya-|x-bot-token$)(?:.*-)?(?:authorization|auth|token|secret|password|api-?key|apikey|subscription-key|credential)s?(?:-.*)?$/;
47
+ const BEACON_COOKIE = "_as_beacon_session=";
48
+ const DELEGATION_BEARER = /^bearer\s+[\w-]+\.([\w-]+)\.[\w-]+$/i;
49
+ function isRecord(value) {
50
+ return typeof value === "object" && value !== null && !Array.isArray(value);
51
+ }
52
+ function hasDelegationType(type) {
53
+ return Array.isArray(type) && type.includes("DelegationCredential");
54
+ }
55
+ function isDelegationBearer(authorization) {
56
+ for (const candidate of (authorization ?? "").split(",")) {
57
+ const match = DELEGATION_BEARER.exec(candidate.trim());
58
+ if (!match) continue;
59
+ if (match[1].length > 16384) return true;
60
+ let claims;
61
+ try {
62
+ claims = JSON.parse(atob(match[1].replace(/-/g, "+").replace(/_/g, "/")));
63
+ } catch {
64
+ continue;
65
+ }
66
+ if (!isRecord(claims)) continue;
67
+ if (hasDelegationType(claims.type)) return true;
68
+ const vc = claims.vc;
69
+ if (!isRecord(vc)) continue;
70
+ if (hasDelegationType(vc.type)) return true;
71
+ const subject = vc.credentialSubject;
72
+ if (isRecord(subject) && isRecord(subject.delegation)) return true;
73
+ }
74
+ return false;
75
+ }
76
+ function relayHeaders(input) {
77
+ const headers = new Headers(input);
78
+ const relayed = Object.fromEntries([...headers].filter(([name]) => !DROPPED_HEADERS.includes(name) && !CREDENTIAL_HEADER.test(name)));
79
+ const beacon = (headers.get("cookie") ?? "").split(";").map((part) => part.trim()).filter((part) => part.startsWith(BEACON_COOKIE));
80
+ if (beacon.length) relayed.cookie = beacon.join("; ");
81
+ const authorization = headers.get("authorization");
82
+ if (isDelegationBearer(authorization)) relayed.authorization = authorization;
83
+ return relayed;
84
+ }
85
+
86
+ //#endregion
87
+ export { relayHeaders as n, safeHostname as r, getClientIp as t };
88
+ //# sourceMappingURL=utils-Cnwg0VrY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-Cnwg0VrY.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Utility functions for @kya-os/checkpoint-nextjs\n */\n\nimport type { NextRequest } from 'next/server.js';\nimport {\n resolveObservedClientAddress,\n type ClientIpTrustPolicy,\n} from '@kya-os/checkpoint-shared/client-ip';\n\n/**\n * Extract client IP address from a NextRequest.\n * In Next.js 15+, the `ip` property was removed from NextRequest.\n * Forwarded values require an authenticated deployment boundary. NextRequest\n * exposes no socket peer, so arbitrary proxy profiles remain unavailable.\n *\n * @param request - The NextRequest object\n * @returns The client IP address or undefined if not available\n */\nexport function getClientIp(\n request: NextRequest,\n policy: ClientIpTrustPolicy = { platform: 'direct' }\n): string | undefined {\n const frameworkAddress = (request as unknown as { ip?: string }).ip;\n const onVercel = typeof process !== 'undefined' && process.env?.VERCEL === '1';\n const effectivePolicy: ClientIpTrustPolicy =\n policy.platform === 'vercel' && !onVercel ? { platform: 'direct' } : policy;\n const resolution = resolveObservedClientAddress({\n headers: request.headers,\n frameworkAddress,\n vercelRuntime: onVercel,\n policy: effectivePolicy,\n });\n return resolution.trusted ? resolution.ip : undefined;\n}\n\n/**\n * Safely extract the hostname from a URL string.\n * Returns a friendly fallback when parsing fails so UX copy doesn't leak\n * \"undefined\" or similar to end users.\n */\nexport function safeHostname(url: string): string {\n try {\n return new URL(url).hostname;\n } catch {\n return 'this site';\n }\n}\n\nconst DROPPED_HEADERS = [\n 'cookie',\n 'authorization',\n 'proxy-authorization',\n 'x-api-key',\n 'x-vercel-protection-bypass',\n 'cf-access-jwt-assertion',\n 'cf-access-client-secret',\n];\nconst CREDENTIAL_HEADER =\n /^(?!kya-|x-bot-token$)(?:.*-)?(?:authorization|auth|token|secret|password|api-?key|apikey|subscription-key|credential)s?(?:-.*)?$/;\nconst BEACON_COOKIE = '_as_beacon_session=';\nconst DELEGATION_BEARER = /^bearer\\s+[\\w-]+\\.([\\w-]+)\\.[\\w-]+$/i;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction hasDelegationType(type: unknown): boolean {\n return Array.isArray(type) && type.includes('DelegationCredential');\n}\n\nfunction isDelegationBearer(authorization: string | null): authorization is string {\n for (const candidate of (authorization ?? '').split(',')) {\n const match = DELEGATION_BEARER.exec(candidate.trim());\n if (!match) continue;\n\n // Match the engine's conservative routing: oversized compact bearers must\n // reach it so it can fail closed without decoding an untrusted payload.\n if (match[1].length > 16 * 1024) return true;\n\n let claims: unknown;\n try {\n claims = JSON.parse(atob(match[1].replace(/-/g, '+').replace(/_/g, '/')));\n } catch {\n continue;\n }\n if (!isRecord(claims)) continue;\n if (hasDelegationType(claims.type)) return true;\n const vc = claims.vc;\n if (!isRecord(vc)) continue;\n if (hasDelegationType(vc.type)) return true;\n const subject = vc.credentialSubject;\n if (isRecord(subject) && isRecord(subject.delegation)) return true;\n }\n return false;\n}\n\nexport function relayHeaders(input: Record<string, string>): Record<string, string> {\n const headers = new Headers(input);\n const relayed = Object.fromEntries(\n [...headers].filter(\n ([name]) => !DROPPED_HEADERS.includes(name) && !CREDENTIAL_HEADER.test(name)\n )\n );\n const beacon = (headers.get('cookie') ?? '')\n .split(';')\n .map((part) => part.trim())\n .filter((part) => part.startsWith(BEACON_COOKIE));\n if (beacon.length) relayed.cookie = beacon.join('; ');\n const authorization = headers.get('authorization');\n if (isDelegationBearer(authorization)) relayed.authorization = authorization;\n return relayed;\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,YACd,SACA,SAA8B,EAAE,UAAU,SAAS,GAC/B;CACpB,MAAM,mBAAoB,QAAuC;CACjE,MAAM,WAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,WAAW;CAC3E,MAAM,kBACJ,OAAO,aAAa,YAAY,CAAC,WAAW,EAAE,UAAU,SAAS,IAAI;CACvE,MAAM,aAAa,6BAA6B;EAC9C,SAAS,QAAQ;EACjB;EACA,eAAe;EACf,QAAQ;CACV,CAAC;CACD,OAAO,WAAW,UAAU,WAAW,KAAK;AAC9C;;;;;;AAOA,SAAgB,aAAa,KAAqB;CAChD,IAAI;EACF,OAAO,IAAI,IAAI,GAAG,CAAC,CAAC;CACtB,QAAQ;EACN,OAAO;CACT;AACF;AAEA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAM,oBACJ;AACF,MAAM,gBAAgB;AACtB,MAAM,oBAAoB;AAE1B,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,kBAAkB,MAAwB;CACjD,OAAO,MAAM,QAAQ,IAAI,KAAK,KAAK,SAAS,sBAAsB;AACpE;AAEA,SAAS,mBAAmB,eAAuD;CACjF,KAAK,MAAM,cAAc,iBAAiB,GAAE,CAAE,MAAM,GAAG,GAAG;EACxD,MAAM,QAAQ,kBAAkB,KAAK,UAAU,KAAK,CAAC;EACrD,IAAI,CAAC,OAAO;EAIZ,IAAI,MAAM,EAAE,CAAC,SAAS,OAAW,OAAO;EAExC,IAAI;EACJ,IAAI;GACF,SAAS,KAAK,MAAM,KAAK,MAAM,EAAE,CAAC,QAAQ,MAAM,GAAG,CAAC,CAAC,QAAQ,MAAM,GAAG,CAAC,CAAC;EAC1E,QAAQ;GACN;EACF;EACA,IAAI,CAAC,SAAS,MAAM,GAAG;EACvB,IAAI,kBAAkB,OAAO,IAAI,GAAG,OAAO;EAC3C,MAAM,KAAK,OAAO;EAClB,IAAI,CAAC,SAAS,EAAE,GAAG;EACnB,IAAI,kBAAkB,GAAG,IAAI,GAAG,OAAO;EACvC,MAAM,UAAU,GAAG;EACnB,IAAI,SAAS,OAAO,KAAK,SAAS,QAAQ,UAAU,GAAG,OAAO;CAChE;CACA,OAAO;AACT;AAEA,SAAgB,aAAa,OAAuD;CAClF,MAAM,UAAU,IAAI,QAAQ,KAAK;CACjC,MAAM,UAAU,OAAO,YACrB,CAAC,GAAG,OAAO,CAAC,CAAC,QACV,CAAC,UAAU,CAAC,gBAAgB,SAAS,IAAI,KAAK,CAAC,kBAAkB,KAAK,IAAI,CAC7E,CACF;CACA,MAAM,UAAU,QAAQ,IAAI,QAAQ,KAAK,GAAE,CACxC,MAAM,GAAG,CAAC,CACV,KAAK,SAAS,KAAK,KAAK,CAAC,CAAC,CAC1B,QAAQ,SAAS,KAAK,WAAW,aAAa,CAAC;CAClD,IAAI,OAAO,QAAQ,QAAQ,SAAS,OAAO,KAAK,IAAI;CACpD,MAAM,gBAAgB,QAAQ,IAAI,eAAe;CACjD,IAAI,mBAAmB,aAAa,GAAG,QAAQ,gBAAgB;CAC/D,OAAO;AACT"}