@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
@@ -1,63 +0,0 @@
1
- import { NextRequest } from 'next/server';
2
- import { IncomingHttpLike } from '@kya-os/checkpoint-wasm-runtime/orchestrator';
3
- import { ClientIpTrustPolicy } from '@kya-os/checkpoint-shared';
4
-
5
- /**
6
- * D.2 — `NextRequest` → `IncomingHttpLike` translator.
7
- *
8
- * The host wrapper's *only* job on the inbound path: take Next.js's
9
- * native request shape and produce the transport-agnostic
10
- * `IncomingHttpLike` Phase C's orchestrator consumes. Zero verification
11
- * logic, zero adapter calls, zero engine I/O.
12
- *
13
- * Shared between the Node-runtime and Edge-runtime entries. Next.js
14
- * `NextRequest` is the same shape in both runtimes — `req.headers` is
15
- * a `Headers` instance, `req.body` is a `ReadableStream`, `req.ip` is
16
- * a getter (only present in some deployment surfaces; forwarding headers
17
- * are considered only when the caller selects a matching trust policy).
18
- */
19
-
20
- /**
21
- * Options controlling translator side effects.
22
- *
23
- * `drainJsonBody` (default `true`) controls whether the translator
24
- * reads the request body so the orchestrator can extract a KYA-OS
25
- * envelope from `_meta.proof.jws` (the canonical spec-form transport).
26
- *
27
- * Trade-off — body draining consumes the request stream. We use
28
- * `req.clone().text()` so the original `req.body` stream is preserved
29
- * for downstream Next.js handlers. Cloning has memory overhead
30
- * proportional to the body size; for large request bodies (>1 MB) or
31
- * streaming-sensitive routes, set `drainJsonBody: false` and verify
32
- * envelopes via the `KYA-Delegation` header transport instead (the
33
- * legacy form, requires `legacyEnvelopeFallback: true` on
34
- * `withCheckpoint`).
35
- */
36
- interface NextRequestToHttpLikeOpts {
37
- /**
38
- * Read the request body when `content-type` is `application/json` so
39
- * the orchestrator can extract a KYA-OS envelope from
40
- * `_meta.proof.jws`. Default `true`. Set `false` for streaming
41
- * middlewares that can't tolerate the clone/read overhead.
42
- */
43
- drainJsonBody?: boolean;
44
- /** Deployment trust profile. Defaults to direct/peer-only fail-closed behavior. */
45
- clientIpPolicy?: ClientIpTrustPolicy;
46
- }
47
- /**
48
- * Translate a Next.js `NextRequest` into the orchestrator's
49
- * `IncomingHttpLike` shape.
50
- *
51
- * When `opts.drainJsonBody !== false` and the request is JSON, the
52
- * translator clones the request and reads the body into a string so
53
- * the orchestrator's `buildAgentRequest` can extract a
54
- * `_meta.proof.jws` envelope. The original `req.body` stream is
55
- * preserved for downstream handlers via `req.clone()`.
56
- *
57
- * When the body can't be read (drain disabled, non-JSON, or a stream
58
- * error) we pass `body: null` and the orchestrator routes to
59
- * PlainHttp — same behavior as the pre-1.1.0 default.
60
- */
61
- declare function nextRequestToHttpLike(req: NextRequest, opts?: NextRequestToHttpLikeOpts): Promise<IncomingHttpLike>;
62
-
63
- export { type NextRequestToHttpLikeOpts, nextRequestToHttpLike };
package/dist/translate.js DELETED
@@ -1,44 +0,0 @@
1
- 'use strict';
2
-
3
- var checkpointShared = require('@kya-os/checkpoint-shared');
4
-
5
- // src/translate.ts
6
- async function nextRequestToHttpLike(req, opts = {}) {
7
- const url = new URL(req.url);
8
- const body = await tryDrainJsonBody(req, opts);
9
- return {
10
- method: req.method,
11
- // Path + query only — orchestrator's URL parsing expects no scheme/host.
12
- url: url.pathname + url.search,
13
- headers: headersToRecord(req.headers),
14
- body,
15
- remoteAddress: extractRemoteAddress(req, opts.clientIpPolicy ?? { platform: "direct" })
16
- };
17
- }
18
- async function tryDrainJsonBody(req, opts) {
19
- if (opts.drainJsonBody === false) return null;
20
- const contentType = req.headers.get("content-type") ?? "";
21
- if (!contentType.toLowerCase().includes("application/json")) return null;
22
- try {
23
- return await req.clone().text();
24
- } catch {
25
- return null;
26
- }
27
- }
28
- function headersToRecord(headers) {
29
- const out = {};
30
- headers.forEach((value, key) => {
31
- out[key.toLowerCase()] = value;
32
- });
33
- return out;
34
- }
35
- function extractRemoteAddress(req, policy) {
36
- const maybeIp = req.ip;
37
- return checkpointShared.resolveClientIp({
38
- headers: req.headers,
39
- frameworkAddress: maybeIp,
40
- policy
41
- }).ip ?? void 0;
42
- }
43
-
44
- exports.nextRequestToHttpLike = nextRequestToHttpLike;
@@ -1,42 +0,0 @@
1
- import { resolveClientIp } from '@kya-os/checkpoint-shared';
2
-
3
- // src/translate.ts
4
- async function nextRequestToHttpLike(req, opts = {}) {
5
- const url = new URL(req.url);
6
- const body = await tryDrainJsonBody(req, opts);
7
- return {
8
- method: req.method,
9
- // Path + query only — orchestrator's URL parsing expects no scheme/host.
10
- url: url.pathname + url.search,
11
- headers: headersToRecord(req.headers),
12
- body,
13
- remoteAddress: extractRemoteAddress(req, opts.clientIpPolicy ?? { platform: "direct" })
14
- };
15
- }
16
- async function tryDrainJsonBody(req, opts) {
17
- if (opts.drainJsonBody === false) return null;
18
- const contentType = req.headers.get("content-type") ?? "";
19
- if (!contentType.toLowerCase().includes("application/json")) return null;
20
- try {
21
- return await req.clone().text();
22
- } catch {
23
- return null;
24
- }
25
- }
26
- function headersToRecord(headers) {
27
- const out = {};
28
- headers.forEach((value, key) => {
29
- out[key.toLowerCase()] = value;
30
- });
31
- return out;
32
- }
33
- function extractRemoteAddress(req, policy) {
34
- const maybeIp = req.ip;
35
- return resolveClientIp({
36
- headers: req.headers,
37
- frameworkAddress: maybeIp,
38
- policy
39
- }).ip ?? void 0;
40
- }
41
-
42
- export { nextRequestToHttpLike };
@@ -1,105 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server';
2
- import { AgentShieldConfig, DetectionResult } from '@kya-os/checkpoint-shared';
3
- import { CheckpointEvents } from '@kya-os/checkpoint';
4
-
5
- /**
6
- * Next.js-specific type definitions
7
- */
8
-
9
- /**
10
- * Next.js middleware configuration
11
- */
12
- interface NextJSMiddlewareConfig extends Partial<AgentShieldConfig> {
13
- /**
14
- * Action to take when an agent is detected
15
- */
16
- onAgentDetected?: 'block' | 'redirect' | 'rewrite' | 'allow' | 'log';
17
- /**
18
- * Custom handler for agent detection
19
- * @deprecated Use 'events' instead. Will be removed in v1.0.0
20
- */
21
- onDetection?: (req: NextRequest, result: DetectionResult) => NextResponse | Promise<NextResponse> | void | Promise<void>;
22
- /**
23
- * Event handlers for detection events
24
- */
25
- events?: Partial<CheckpointEvents>;
26
- /**
27
- * Path patterns to skip detection
28
- */
29
- skipPaths?: string[] | RegExp[];
30
- /**
31
- * Response when blocking agents
32
- */
33
- blockedResponse?: {
34
- status: number;
35
- message: string;
36
- headers?: Record<string, string>;
37
- };
38
- /**
39
- * Redirect URL when redirecting detected agents
40
- */
41
- redirectUrl?: string;
42
- /**
43
- * Rewrite URL when rewriting requests from detected agents
44
- */
45
- rewriteUrl?: string;
46
- /**
47
- * Confidence threshold for agent detection
48
- */
49
- confidenceThreshold?: number;
50
- /**
51
- * Enable WASM for enhanced detection
52
- */
53
- enableWasm?: boolean;
54
- /**
55
- * Session tracking configuration
56
- */
57
- sessionTracking?: {
58
- /**
59
- * Enable session tracking
60
- */
61
- enabled: boolean;
62
- /**
63
- * Cookie name for session storage
64
- * Default: '__agentshield_session'
65
- */
66
- cookieName?: string;
67
- /**
68
- * Cookie max age in seconds
69
- * Default: 3600 (1 hour)
70
- */
71
- cookieMaxAge?: number;
72
- /**
73
- * Encryption key for session data
74
- * Default: Uses CHECKPOINT_SECRET env var or default key
75
- */
76
- encryptionKey?: string;
77
- };
78
- }
79
- /**
80
- * Extended NextRequest with AgentShield data
81
- */
82
- interface AgentShieldRequest extends NextRequest {
83
- agentShield?: {
84
- result?: DetectionResult;
85
- skipped: boolean;
86
- session?: {
87
- id: string;
88
- agent: string;
89
- confidence: number;
90
- detectedAt: number;
91
- expires: number;
92
- };
93
- };
94
- }
95
- /**
96
- * Detection context for hooks
97
- */
98
- interface DetectionContext {
99
- result: DetectionResult;
100
- request: NextRequest;
101
- userAgent?: string;
102
- ip?: string;
103
- }
104
-
105
- export type { AgentShieldRequest as A, DetectionContext as D, NextJSMiddlewareConfig as N };
@@ -1,105 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server';
2
- import { AgentShieldConfig, DetectionResult } from '@kya-os/checkpoint-shared';
3
- import { CheckpointEvents } from '@kya-os/checkpoint';
4
-
5
- /**
6
- * Next.js-specific type definitions
7
- */
8
-
9
- /**
10
- * Next.js middleware configuration
11
- */
12
- interface NextJSMiddlewareConfig extends Partial<AgentShieldConfig> {
13
- /**
14
- * Action to take when an agent is detected
15
- */
16
- onAgentDetected?: 'block' | 'redirect' | 'rewrite' | 'allow' | 'log';
17
- /**
18
- * Custom handler for agent detection
19
- * @deprecated Use 'events' instead. Will be removed in v1.0.0
20
- */
21
- onDetection?: (req: NextRequest, result: DetectionResult) => NextResponse | Promise<NextResponse> | void | Promise<void>;
22
- /**
23
- * Event handlers for detection events
24
- */
25
- events?: Partial<CheckpointEvents>;
26
- /**
27
- * Path patterns to skip detection
28
- */
29
- skipPaths?: string[] | RegExp[];
30
- /**
31
- * Response when blocking agents
32
- */
33
- blockedResponse?: {
34
- status: number;
35
- message: string;
36
- headers?: Record<string, string>;
37
- };
38
- /**
39
- * Redirect URL when redirecting detected agents
40
- */
41
- redirectUrl?: string;
42
- /**
43
- * Rewrite URL when rewriting requests from detected agents
44
- */
45
- rewriteUrl?: string;
46
- /**
47
- * Confidence threshold for agent detection
48
- */
49
- confidenceThreshold?: number;
50
- /**
51
- * Enable WASM for enhanced detection
52
- */
53
- enableWasm?: boolean;
54
- /**
55
- * Session tracking configuration
56
- */
57
- sessionTracking?: {
58
- /**
59
- * Enable session tracking
60
- */
61
- enabled: boolean;
62
- /**
63
- * Cookie name for session storage
64
- * Default: '__agentshield_session'
65
- */
66
- cookieName?: string;
67
- /**
68
- * Cookie max age in seconds
69
- * Default: 3600 (1 hour)
70
- */
71
- cookieMaxAge?: number;
72
- /**
73
- * Encryption key for session data
74
- * Default: Uses CHECKPOINT_SECRET env var or default key
75
- */
76
- encryptionKey?: string;
77
- };
78
- }
79
- /**
80
- * Extended NextRequest with AgentShield data
81
- */
82
- interface AgentShieldRequest extends NextRequest {
83
- agentShield?: {
84
- result?: DetectionResult;
85
- skipped: boolean;
86
- session?: {
87
- id: string;
88
- agent: string;
89
- confidence: number;
90
- detectedAt: number;
91
- expires: number;
92
- };
93
- };
94
- }
95
- /**
96
- * Detection context for hooks
97
- */
98
- interface DetectionContext {
99
- result: DetectionResult;
100
- request: NextRequest;
101
- userAgent?: string;
102
- ip?: string;
103
- }
104
-
105
- export type { AgentShieldRequest as A, DetectionContext as D, NextJSMiddlewareConfig as N };
@@ -1,46 +0,0 @@
1
- /**
2
- * WASM Setup for AgentShield in Next.js Edge Runtime
3
- *
4
- * This module handles WASM initialization for cryptographic signature verification.
5
- * Designed to work without top-level await to avoid Next.js middleware issues.
6
- *
7
- * Usage in middleware.ts:
8
- * ```typescript
9
- * import { setupWasm } from '@kya-os/checkpoint-nextjs/wasm-setup';
10
- * import { createAgentShieldMiddleware } from '@kya-os/checkpoint-nextjs';
11
- *
12
- * export async function middleware(request: NextRequest) {
13
- * // Initialize WASM inside the middleware function
14
- * await setupWasm();
15
- *
16
- * const agentShieldMiddleware = createAgentShieldMiddleware({...});
17
- * return agentShieldMiddleware(request);
18
- * }
19
- * ```
20
- */
21
- /**
22
- * Initialize WASM module for AgentShield
23
- *
24
- * This function:
25
- * - Loads WASM in production/Edge Runtime for cryptographic verification
26
- * - Skips WASM in test environments (Jest) automatically
27
- * - Is safe to call multiple times (idempotent)
28
- * - Handles errors gracefully with fallback to pattern detection
29
- *
30
- * @returns Promise that resolves when initialization is complete
31
- */
32
- declare function setupWasm(): Promise<void>;
33
- /**
34
- * Check if WASM has been initialized
35
- *
36
- * @returns true if WASM setup has been attempted (success or failure)
37
- */
38
- declare function isWasmInitialized(): boolean;
39
- /**
40
- * Reset WASM initialization state (mainly for testing)
41
- *
42
- * @internal
43
- */
44
- declare function resetWasmState(): void;
45
-
46
- export { isWasmInitialized, resetWasmState, setupWasm };
@@ -1,46 +0,0 @@
1
- /**
2
- * WASM Setup for AgentShield in Next.js Edge Runtime
3
- *
4
- * This module handles WASM initialization for cryptographic signature verification.
5
- * Designed to work without top-level await to avoid Next.js middleware issues.
6
- *
7
- * Usage in middleware.ts:
8
- * ```typescript
9
- * import { setupWasm } from '@kya-os/checkpoint-nextjs/wasm-setup';
10
- * import { createAgentShieldMiddleware } from '@kya-os/checkpoint-nextjs';
11
- *
12
- * export async function middleware(request: NextRequest) {
13
- * // Initialize WASM inside the middleware function
14
- * await setupWasm();
15
- *
16
- * const agentShieldMiddleware = createAgentShieldMiddleware({...});
17
- * return agentShieldMiddleware(request);
18
- * }
19
- * ```
20
- */
21
- /**
22
- * Initialize WASM module for AgentShield
23
- *
24
- * This function:
25
- * - Loads WASM in production/Edge Runtime for cryptographic verification
26
- * - Skips WASM in test environments (Jest) automatically
27
- * - Is safe to call multiple times (idempotent)
28
- * - Handles errors gracefully with fallback to pattern detection
29
- *
30
- * @returns Promise that resolves when initialization is complete
31
- */
32
- declare function setupWasm(): Promise<void>;
33
- /**
34
- * Check if WASM has been initialized
35
- *
36
- * @returns true if WASM setup has been attempted (success or failure)
37
- */
38
- declare function isWasmInitialized(): boolean;
39
- /**
40
- * Reset WASM initialization state (mainly for testing)
41
- *
42
- * @internal
43
- */
44
- declare function resetWasmState(): void;
45
-
46
- export { isWasmInitialized, resetWasmState, setupWasm };
@@ -1,122 +0,0 @@
1
- 'use strict';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
6
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
7
- }) : x)(function(x) {
8
- if (typeof require !== "undefined") return require.apply(this, arguments);
9
- throw Error('Dynamic require of "' + x + '" is not supported');
10
- });
11
- var __esm = (fn, res) => function __init() {
12
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
13
- };
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
-
19
- // src/nodejs-wasm-loader.ts
20
- var nodejs_wasm_loader_exports = {};
21
- __export(nodejs_wasm_loader_exports, {
22
- __resetNodejsWasmWarningForTests: () => __resetNodejsWasmWarningForTests,
23
- getWasmModule: () => getWasmModule,
24
- isNodejsRuntime: () => isNodejsRuntime,
25
- isWasmInitialized: () => isWasmInitialized,
26
- loadWasmNodejs: () => loadWasmNodejs
27
- });
28
- function warnNodejsWasmDeprecated() {
29
- if (_nodejsWasmWarned) return;
30
- _nodejsWasmWarned = true;
31
- if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
32
- console.warn(`[Checkpoint] ${MIGRATION_ERROR}`);
33
- }
34
- function __resetNodejsWasmWarningForTests() {
35
- _nodejsWasmWarned = false;
36
- }
37
- async function loadWasmNodejs() {
38
- warnNodejsWasmDeprecated();
39
- throw new Error(MIGRATION_ERROR);
40
- }
41
- function isNodejsRuntime() {
42
- warnNodejsWasmDeprecated();
43
- throw new Error(MIGRATION_ERROR);
44
- }
45
- function getWasmModule() {
46
- warnNodejsWasmDeprecated();
47
- throw new Error(MIGRATION_ERROR);
48
- }
49
- function isWasmInitialized() {
50
- warnNodejsWasmDeprecated();
51
- throw new Error(MIGRATION_ERROR);
52
- }
53
- var MIGRATION_ERROR, _nodejsWasmWarned;
54
- var init_nodejs_wasm_loader = __esm({
55
- "src/nodejs-wasm-loader.ts"() {
56
- MIGRATION_ERROR = "`@kya-os/checkpoint-nextjs`'s `loadWasmNodejs` / `isNodejsRuntime` / `getWasmModule` / `isWasmInitialized` were deprecated in Phase-D.9a (legacy `agentshield-wasm` Rust crate retirement). The legacy detection class they fed was removed in AgentDetector-Deletion-2. Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs` \u2014 engine-backed via the Rust `kya-os-engine` crate, with automatic WASM loading via `@kya-os/checkpoint-wasm-runtime`. See packages/checkpoint-nextjs/README.md for the canonical recipe.";
57
- _nodejsWasmWarned = false;
58
- }
59
- });
60
-
61
- // src/wasm-setup.ts
62
- var wasmInitialized = false;
63
- var initPromise = null;
64
- var initAttempted = false;
65
- async function setupWasm() {
66
- if (wasmInitialized) {
67
- return;
68
- }
69
- if (initPromise) {
70
- return initPromise;
71
- }
72
- initPromise = doSetupWasm();
73
- return initPromise;
74
- }
75
- async function doSetupWasm() {
76
- if (initAttempted) {
77
- return;
78
- }
79
- initAttempted = true;
80
- try {
81
- if (typeof process !== "undefined" && process.env.NODE_ENV === "test") {
82
- wasmInitialized = true;
83
- return;
84
- }
85
- const isNodejs = typeof process !== "undefined" && typeof __require !== "undefined" && process.env.NEXT_RUNTIME === "nodejs";
86
- if (isNodejs) {
87
- try {
88
- const { loadWasmNodejs: loadWasmNodejs2 } = await Promise.resolve().then(() => (init_nodejs_wasm_loader(), nodejs_wasm_loader_exports));
89
- const loaded = await loadWasmNodejs2();
90
- wasmInitialized = true;
91
- if (loaded) {
92
- console.log("\u{1F680} AgentShield: Running with full WASM support (Node.js runtime)");
93
- } else {
94
- console.log("\u{1F4CA} AgentShield: Using pattern detection (WASM not found)");
95
- }
96
- return;
97
- } catch (error) {
98
- console.warn("\u26A0\uFE0F AgentShield: Node.js WASM loader failed:", error);
99
- }
100
- }
101
- wasmInitialized = true;
102
- if (process.env.NEXT_RUNTIME === "edge") {
103
- console.log(
104
- "\u26A1 AgentShield: Edge Runtime detected - using pattern detection (85% confidence)"
105
- );
106
- console.log("\u2705 AgentShield: Ready for AI agent detection");
107
- }
108
- } catch (error) {
109
- wasmInitialized = true;
110
- }
111
- }
112
- function isWasmInitialized2() {
113
- return wasmInitialized;
114
- }
115
- function resetWasmState() {
116
- wasmInitialized = false;
117
- initPromise = null;
118
- }
119
-
120
- exports.isWasmInitialized = isWasmInitialized2;
121
- exports.resetWasmState = resetWasmState;
122
- exports.setupWasm = setupWasm;
@@ -1,118 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
4
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
5
- }) : x)(function(x) {
6
- if (typeof require !== "undefined") return require.apply(this, arguments);
7
- throw Error('Dynamic require of "' + x + '" is not supported');
8
- });
9
- var __esm = (fn, res) => function __init() {
10
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
- };
12
- var __export = (target, all) => {
13
- for (var name in all)
14
- __defProp(target, name, { get: all[name], enumerable: true });
15
- };
16
-
17
- // src/nodejs-wasm-loader.ts
18
- var nodejs_wasm_loader_exports = {};
19
- __export(nodejs_wasm_loader_exports, {
20
- __resetNodejsWasmWarningForTests: () => __resetNodejsWasmWarningForTests,
21
- getWasmModule: () => getWasmModule,
22
- isNodejsRuntime: () => isNodejsRuntime,
23
- isWasmInitialized: () => isWasmInitialized,
24
- loadWasmNodejs: () => loadWasmNodejs
25
- });
26
- function warnNodejsWasmDeprecated() {
27
- if (_nodejsWasmWarned) return;
28
- _nodejsWasmWarned = true;
29
- if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
30
- console.warn(`[Checkpoint] ${MIGRATION_ERROR}`);
31
- }
32
- function __resetNodejsWasmWarningForTests() {
33
- _nodejsWasmWarned = false;
34
- }
35
- async function loadWasmNodejs() {
36
- warnNodejsWasmDeprecated();
37
- throw new Error(MIGRATION_ERROR);
38
- }
39
- function isNodejsRuntime() {
40
- warnNodejsWasmDeprecated();
41
- throw new Error(MIGRATION_ERROR);
42
- }
43
- function getWasmModule() {
44
- warnNodejsWasmDeprecated();
45
- throw new Error(MIGRATION_ERROR);
46
- }
47
- function isWasmInitialized() {
48
- warnNodejsWasmDeprecated();
49
- throw new Error(MIGRATION_ERROR);
50
- }
51
- var MIGRATION_ERROR, _nodejsWasmWarned;
52
- var init_nodejs_wasm_loader = __esm({
53
- "src/nodejs-wasm-loader.ts"() {
54
- MIGRATION_ERROR = "`@kya-os/checkpoint-nextjs`'s `loadWasmNodejs` / `isNodejsRuntime` / `getWasmModule` / `isWasmInitialized` were deprecated in Phase-D.9a (legacy `agentshield-wasm` Rust crate retirement). The legacy detection class they fed was removed in AgentDetector-Deletion-2. Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs` \u2014 engine-backed via the Rust `kya-os-engine` crate, with automatic WASM loading via `@kya-os/checkpoint-wasm-runtime`. See packages/checkpoint-nextjs/README.md for the canonical recipe.";
55
- _nodejsWasmWarned = false;
56
- }
57
- });
58
-
59
- // src/wasm-setup.ts
60
- var wasmInitialized = false;
61
- var initPromise = null;
62
- var initAttempted = false;
63
- async function setupWasm() {
64
- if (wasmInitialized) {
65
- return;
66
- }
67
- if (initPromise) {
68
- return initPromise;
69
- }
70
- initPromise = doSetupWasm();
71
- return initPromise;
72
- }
73
- async function doSetupWasm() {
74
- if (initAttempted) {
75
- return;
76
- }
77
- initAttempted = true;
78
- try {
79
- if (typeof process !== "undefined" && process.env.NODE_ENV === "test") {
80
- wasmInitialized = true;
81
- return;
82
- }
83
- const isNodejs = typeof process !== "undefined" && typeof __require !== "undefined" && process.env.NEXT_RUNTIME === "nodejs";
84
- if (isNodejs) {
85
- try {
86
- const { loadWasmNodejs: loadWasmNodejs2 } = await Promise.resolve().then(() => (init_nodejs_wasm_loader(), nodejs_wasm_loader_exports));
87
- const loaded = await loadWasmNodejs2();
88
- wasmInitialized = true;
89
- if (loaded) {
90
- console.log("\u{1F680} AgentShield: Running with full WASM support (Node.js runtime)");
91
- } else {
92
- console.log("\u{1F4CA} AgentShield: Using pattern detection (WASM not found)");
93
- }
94
- return;
95
- } catch (error) {
96
- console.warn("\u26A0\uFE0F AgentShield: Node.js WASM loader failed:", error);
97
- }
98
- }
99
- wasmInitialized = true;
100
- if (process.env.NEXT_RUNTIME === "edge") {
101
- console.log(
102
- "\u26A1 AgentShield: Edge Runtime detected - using pattern detection (85% confidence)"
103
- );
104
- console.log("\u2705 AgentShield: Ready for AI agent detection");
105
- }
106
- } catch (error) {
107
- wasmInitialized = true;
108
- }
109
- }
110
- function isWasmInitialized2() {
111
- return wasmInitialized;
112
- }
113
- function resetWasmState() {
114
- wasmInitialized = false;
115
- initPromise = null;
116
- }
117
-
118
- export { isWasmInitialized2 as isWasmInitialized, resetWasmState, setupWasm };