@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,6 +1,6 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- let _kya_os_checkpoint_shared = require("@kya-os/checkpoint-shared");
3
- let next_server = require("next/server");
1
+ let next_server_js = require("next/server.js");
2
+ let _kya_os_checkpoint_shared_host_adapter = require("@kya-os/checkpoint-shared/host-adapter");
3
+ let _kya_os_checkpoint_shared_policy_enforcement = require("@kya-os/checkpoint-shared/policy/enforcement");
4
4
 
5
5
  //#region src/adapt.ts
6
6
  /**
@@ -31,37 +31,47 @@ let next_server = require("next/server");
31
31
  * deviation note confirmed the `X-Checkpoint-*` prefix is canon.
32
32
  */
33
33
  /**
34
+ * 503 (Retry-After, no-store) for an engine/pipeline fault. Never a 500 and
35
+ * never a pass-through: an unverifiable request is not allowed.
36
+ */
37
+ function failClosedResponse() {
38
+ return next_server_js.NextResponse.json(_kya_os_checkpoint_shared_policy_enforcement.FAIL_CLOSED_BODY, {
39
+ status: _kya_os_checkpoint_shared_policy_enforcement.FAIL_CLOSED_STATUS,
40
+ headers: _kya_os_checkpoint_shared_policy_enforcement.FAIL_CLOSED_HEADERS
41
+ });
42
+ }
43
+ /**
34
44
  * Convert the engine's transport-agnostic `RenderedResponse` into a
35
45
  * `NextResponse`. Sites-1's Playwright suite is the regression gate;
36
46
  * any drift here is caught downstream.
37
47
  */
38
48
  function adaptToNextResponse(rendered, req) {
39
- const clientAcceptsHtml = (0, _kya_os_checkpoint_shared.acceptsHtml)(req.headers);
40
- const verdictCookie = (0, _kya_os_checkpoint_shared.encodeVerdictCookie)(rendered);
41
- switch ((0, _kya_os_checkpoint_shared.classifyResponseShape)(rendered, clientAcceptsHtml)) {
49
+ const clientAcceptsHtml = (0, _kya_os_checkpoint_shared_host_adapter.acceptsHtml)(req.headers);
50
+ const verdictCookie = (0, _kya_os_checkpoint_shared_host_adapter.encodeVerdictCookie)(rendered);
51
+ switch ((0, _kya_os_checkpoint_shared_host_adapter.classifyResponseShape)(rendered, clientAcceptsHtml)) {
42
52
  case "pass-through": {
43
- const res = next_server.NextResponse.next();
53
+ const res = next_server_js.NextResponse.next();
44
54
  applyHeaders(res, rendered);
45
55
  setVerdictCookie(res, verdictCookie);
46
56
  return res;
47
57
  }
48
58
  case "redirect": {
49
59
  const target = new URL(rendered.headers.Location);
50
- const res = next_server.NextResponse.redirect(target);
60
+ const res = next_server_js.NextResponse.redirect(target);
51
61
  applyHeaders(res, rendered);
52
62
  setVerdictCookie(res, verdictCookie);
53
63
  return res;
54
64
  }
55
65
  case "html-block": {
56
- const blockedUrl = new URL(_kya_os_checkpoint_shared.BLOCKED_PATH, req.url);
57
- const res = next_server.NextResponse.rewrite(blockedUrl, { status: 200 });
66
+ const blockedUrl = new URL(_kya_os_checkpoint_shared_host_adapter.BLOCKED_PATH, req.url);
67
+ const res = next_server_js.NextResponse.rewrite(blockedUrl, { status: 200 });
58
68
  applyHeaders(res, rendered);
59
69
  setVerdictCookie(res, verdictCookie);
60
70
  return res;
61
71
  }
62
72
  case "json-block": {
63
73
  const body = rendered.body ?? {};
64
- const res = next_server.NextResponse.json(body, { status: rendered.status });
74
+ const res = next_server_js.NextResponse.json(body, { status: rendered.status });
65
75
  applyHeaders(res, rendered);
66
76
  setVerdictCookie(res, verdictCookie);
67
77
  return res;
@@ -70,7 +80,7 @@ function adaptToNextResponse(rendered, req) {
70
80
  }
71
81
  function setVerdictCookie(res, value) {
72
82
  res.cookies.set({
73
- name: _kya_os_checkpoint_shared.VERDICT_COOKIE_NAME,
83
+ name: _kya_os_checkpoint_shared_host_adapter.VERDICT_COOKIE_NAME,
74
84
  value,
75
85
  path: "/",
76
86
  sameSite: "lax",
@@ -83,4 +93,15 @@ function applyHeaders(res, rendered) {
83
93
  }
84
94
 
85
95
  //#endregion
86
- exports.adaptToNextResponse = adaptToNextResponse;
96
+ Object.defineProperty(exports, 'adaptToNextResponse', {
97
+ enumerable: true,
98
+ get: function () {
99
+ return adaptToNextResponse;
100
+ }
101
+ });
102
+ Object.defineProperty(exports, 'failClosedResponse', {
103
+ enumerable: true,
104
+ get: function () {
105
+ return failClosedResponse;
106
+ }
107
+ });
@@ -0,0 +1,222 @@
1
+ import { DetectionDetail, EnforcementAction, EngineInfo } from "@kya-os/checkpoint-shared";
2
+ //#region src/api-client.d.ts
3
+ /**
4
+ * API client configuration
5
+ */
6
+ interface CheckpointApiClientConfig {
7
+ /** API key for authentication */
8
+ apiKey: string;
9
+ /** API base URL (defaults to production) */
10
+ baseUrl?: string;
11
+ /**
12
+ * Use edge detection for lower latency (~30-50ms vs ~150ms) and better coverage.
13
+ * Edge detection can identify non-JS clients (curl, Python, Claude Code WebFetch)
14
+ * that the pixel cannot detect since they don't execute JavaScript.
15
+ * @default true
16
+ */
17
+ useEdge?: boolean;
18
+ /** Request timeout in milliseconds (default: 5000) */
19
+ timeout?: number;
20
+ /** Enable debug logging */
21
+ debug?: boolean;
22
+ }
23
+ /**
24
+ * Enforcement decision from the API
25
+ */
26
+ interface EnforcementDecision {
27
+ action: EnforcementAction;
28
+ reason: string;
29
+ isAgent: boolean;
30
+ confidence: number;
31
+ agentName?: string;
32
+ agentType?: string;
33
+ redirectUrl?: string;
34
+ message?: string;
35
+ metadata?: {
36
+ policyVersion?: string;
37
+ signatureVerified?: boolean;
38
+ denyListMatch?: {
39
+ clientDid?: string;
40
+ agentDid?: string;
41
+ clientName?: string;
42
+ reason?: string;
43
+ };
44
+ rateLimit?: {
45
+ limit?: number;
46
+ retryAfterSeconds?: number;
47
+ wouldBlock?: boolean;
48
+ skipped?: 'no_client_ip';
49
+ };
50
+ };
51
+ }
52
+ /**
53
+ * Detection detail (optional in response)
54
+ */
55
+ type ApiDetectionDetail = Omit<DetectionDetail, 'detectionClass' | 'verificationMethod' | 'reasons' | 'signals' | 'timestamp'> & {
56
+ agentName?: string;
57
+ /** Detection class: 'human', 'ai_agent', 'bot', 'incomplete_data' */
58
+ detectionClass?: string;
59
+ verificationMethod?: string;
60
+ reasons?: string[];
61
+ signals?: DetectionDetail['signals'];
62
+ timestamp?: DetectionDetail['timestamp'];
63
+ /** Detection engine used: 'wasm' or 'javascript-fallback' */
64
+ detectionMethod?: string;
65
+ detectionBasis?: string;
66
+ /**
67
+ * Ordered `detection/*` reason codes (KYA-1107 signal exposure; carried
68
+ * on every enforce detection payload alongside the populated `signals`
69
+ * list). Deliberately `string[]` rather than
70
+ * the registry union so an older SDK build tolerates codes added
71
+ * server-side later; the registry lives in
72
+ * `@kya-os/checkpoint-shared` (`DETECTION_REASON_CODES`).
73
+ */
74
+ reasonCodes?: string[];
75
+ };
76
+ /**
77
+ * Enforce API response
78
+ */
79
+ interface EnforceResponse {
80
+ success: boolean;
81
+ data?: {
82
+ decision: EnforcementDecision;
83
+ processingTimeMs: number;
84
+ requestId: string;
85
+ detection?: ApiDetectionDetail;
86
+ /**
87
+ * Self-identification of the engine that ran the detection (the gateway
88
+ * worker's `checkpoint-worker-wasm`). Absent when the gateway could not
89
+ * compute it.
90
+ */
91
+ engine?: EngineInfo;
92
+ };
93
+ error?: {
94
+ code: string;
95
+ message: string;
96
+ };
97
+ }
98
+ /**
99
+ * Request input for enforce API
100
+ */
101
+ interface EnforceInput {
102
+ /** HTTP headers from the incoming request */
103
+ headers?: Record<string, string>;
104
+ /** User-Agent header */
105
+ userAgent?: string;
106
+ /** Client IP address */
107
+ ipAddress?: string;
108
+ /** Request path */
109
+ path?: string;
110
+ /** Request URL */
111
+ url?: string;
112
+ /** HTTP method */
113
+ method?: string;
114
+ /** Request ID for tracing */
115
+ requestId?: string;
116
+ /** Options */
117
+ options?: {
118
+ /** Include full detection result */
119
+ includeDetectionResult?: boolean;
120
+ /** Cache TTL override */
121
+ cacheTTL?: number;
122
+ };
123
+ }
124
+ /**
125
+ * Input for logging a detection result
126
+ */
127
+ interface LogDetectionInput {
128
+ /** Detection result from Gateway */
129
+ detection: ApiDetectionDetail;
130
+ /** Request context */
131
+ context: {
132
+ userAgent?: string;
133
+ ipAddress?: string;
134
+ path?: string;
135
+ url?: string;
136
+ method?: string;
137
+ };
138
+ /** Source of the detection */
139
+ source?: 'gateway' | 'middleware';
140
+ /** The enforcement decision the caller received and acted on. */
141
+ enforcement?: {
142
+ action: EnforcementAction;
143
+ };
144
+ /** Self-identification of the engine that produced the detection. */
145
+ engine?: EngineInfo;
146
+ /** Self-identification of the reporting SDK: package, version and Next.js runtime. */
147
+ sdk?: {
148
+ name: string;
149
+ version: string;
150
+ runtime: 'node' | 'edge';
151
+ };
152
+ }
153
+ /**
154
+ * Checkpoint API Client
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const client = new CheckpointApiClient({
159
+ * apiKey: process.env.CHECKPOINT_API_KEY!,
160
+ * });
161
+ *
162
+ * const result = await client.enforce({
163
+ * headers: Object.fromEntries(request.headers),
164
+ * path: request.nextUrl.pathname,
165
+ * method: request.method,
166
+ * });
167
+ *
168
+ * if (result.decision.action === 'block') {
169
+ * return new Response('Access denied', { status: 403 });
170
+ * }
171
+ * ```
172
+ */
173
+ declare class CheckpointApiClient {
174
+ private apiKey;
175
+ private baseUrl;
176
+ private useEdge;
177
+ private timeout;
178
+ private debug;
179
+ constructor(config: CheckpointApiClientConfig);
180
+ /**
181
+ * Call the enforce API to check if a request should be allowed
182
+ */
183
+ enforce(input: EnforceInput): Promise<EnforceResponse>;
184
+ /**
185
+ * Quick check - returns just the action without full response parsing
186
+ * Useful for very fast middleware that just needs allow/block. On an API
187
+ * error the action is `block` (fail-closed) with `error` set.
188
+ */
189
+ quickCheck(input: EnforceInput): Promise<{
190
+ action: EnforcementAction;
191
+ error?: string;
192
+ }>;
193
+ /**
194
+ * Check if this client is using edge detection (Gateway Worker)
195
+ */
196
+ isUsingEdge(): boolean;
197
+ /**
198
+ * Log a detection result to the Checkpoint database.
199
+ * Use after Gateway Worker detection to persist results.
200
+ * Fire-and-forget - returns immediately without waiting for DB write.
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * // After receiving Gateway response
205
+ * if (client.isUsingEdge() && response.data?.detection) {
206
+ * client.logDetection({
207
+ * detection: response.data.detection,
208
+ * context: { userAgent, ipAddress, path, url, method }
209
+ * }).catch(err => console.error('Log failed:', err));
210
+ * }
211
+ * ```
212
+ */
213
+ logDetection(input: LogDetectionInput): Promise<void>;
214
+ }
215
+ declare function getCheckpointApiClient(config?: Partial<CheckpointApiClientConfig>): CheckpointApiClient;
216
+ /**
217
+ * Reset the singleton client (useful for testing)
218
+ */
219
+ declare function resetCheckpointApiClient(): void;
220
+ //#endregion
221
+ export { EnforceResponse as a, LogDetectionInput as c, EnforceInput as i, getCheckpointApiClient as l, CheckpointApiClient as n, EnforcementAction as o, CheckpointApiClientConfig as r, EnforcementDecision as s, ApiDetectionDetail as t, resetCheckpointApiClient as u };
222
+ //# sourceMappingURL=api-client-JHOrRUA_.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-client-JHOrRUA_.d.mts","names":[],"sources":["../src/api-client.ts"],"mappings":";;;;;UAiBiB;;EAEf;;EAEA;;;;;;;EAOA;;EAEA;;EAEA;;;;;UAgBe;EACf,QAAQ;EACR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IACE;IACA;IACA;MACE;MACA;MACA;MACA;;IAEF;MACE;MACA;MACA;MACA;;;;;;;KAQM,qBAAqB,KAC/B;EAGA;;EAEA;EACA;EACA;EACA,UAAU;EACV,YAAY;;EAEZ;EACA;;;;;;;;;EASA;;;;;UAMe;EACf;EACA;IACE,UAAU;IACV;IACA;IACA,YAAY;;;;;;IAMZ,SAAS;;EAEX;IACE;IACA;;;;;;UAOa;;EAEf,UAAU;;EAEV;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;IAEE;;IAEA;;;;;;UAOa;;EAEf,WAAW;;EAEX;IACE;IACA;IACA;IACA;IACA;;;EAGF;;EAEA;IAAgB,QAAQ;;;EAExB,SAAS;;EAET;IAAQ;IAAc;IAAiB;;;;;;;;;;;;;;;;;;;;;;;cA+B5B;UACH;UACA;UACA;UACA;UACA;EAEI,YAAA,QAAQ;;;;EAgBd,QAAQ,OAAO,eAAe,QAAQ;;;;;;EA4FtC,WAAW,OAAO,eAAe;IACrC,QAAQ;IACR;;;;;EAmBF;;;;;;;;;;;;;;;;;EAoBM,aAAa,OAAO,oBAAoB;;iBA2GhC,uBACd,SAAS,QAAQ,6BAChB;;;;iBAgBa"}
@@ -0,0 +1,222 @@
1
+ import { DetectionDetail, EnforcementAction, EngineInfo } from "@kya-os/checkpoint-shared";
2
+ //#region src/api-client.d.ts
3
+ /**
4
+ * API client configuration
5
+ */
6
+ interface CheckpointApiClientConfig {
7
+ /** API key for authentication */
8
+ apiKey: string;
9
+ /** API base URL (defaults to production) */
10
+ baseUrl?: string;
11
+ /**
12
+ * Use edge detection for lower latency (~30-50ms vs ~150ms) and better coverage.
13
+ * Edge detection can identify non-JS clients (curl, Python, Claude Code WebFetch)
14
+ * that the pixel cannot detect since they don't execute JavaScript.
15
+ * @default true
16
+ */
17
+ useEdge?: boolean;
18
+ /** Request timeout in milliseconds (default: 5000) */
19
+ timeout?: number;
20
+ /** Enable debug logging */
21
+ debug?: boolean;
22
+ }
23
+ /**
24
+ * Enforcement decision from the API
25
+ */
26
+ interface EnforcementDecision {
27
+ action: EnforcementAction;
28
+ reason: string;
29
+ isAgent: boolean;
30
+ confidence: number;
31
+ agentName?: string;
32
+ agentType?: string;
33
+ redirectUrl?: string;
34
+ message?: string;
35
+ metadata?: {
36
+ policyVersion?: string;
37
+ signatureVerified?: boolean;
38
+ denyListMatch?: {
39
+ clientDid?: string;
40
+ agentDid?: string;
41
+ clientName?: string;
42
+ reason?: string;
43
+ };
44
+ rateLimit?: {
45
+ limit?: number;
46
+ retryAfterSeconds?: number;
47
+ wouldBlock?: boolean;
48
+ skipped?: 'no_client_ip';
49
+ };
50
+ };
51
+ }
52
+ /**
53
+ * Detection detail (optional in response)
54
+ */
55
+ type ApiDetectionDetail = Omit<DetectionDetail, 'detectionClass' | 'verificationMethod' | 'reasons' | 'signals' | 'timestamp'> & {
56
+ agentName?: string;
57
+ /** Detection class: 'human', 'ai_agent', 'bot', 'incomplete_data' */
58
+ detectionClass?: string;
59
+ verificationMethod?: string;
60
+ reasons?: string[];
61
+ signals?: DetectionDetail['signals'];
62
+ timestamp?: DetectionDetail['timestamp'];
63
+ /** Detection engine used: 'wasm' or 'javascript-fallback' */
64
+ detectionMethod?: string;
65
+ detectionBasis?: string;
66
+ /**
67
+ * Ordered `detection/*` reason codes (KYA-1107 signal exposure; carried
68
+ * on every enforce detection payload alongside the populated `signals`
69
+ * list). Deliberately `string[]` rather than
70
+ * the registry union so an older SDK build tolerates codes added
71
+ * server-side later; the registry lives in
72
+ * `@kya-os/checkpoint-shared` (`DETECTION_REASON_CODES`).
73
+ */
74
+ reasonCodes?: string[];
75
+ };
76
+ /**
77
+ * Enforce API response
78
+ */
79
+ interface EnforceResponse {
80
+ success: boolean;
81
+ data?: {
82
+ decision: EnforcementDecision;
83
+ processingTimeMs: number;
84
+ requestId: string;
85
+ detection?: ApiDetectionDetail;
86
+ /**
87
+ * Self-identification of the engine that ran the detection (the gateway
88
+ * worker's `checkpoint-worker-wasm`). Absent when the gateway could not
89
+ * compute it.
90
+ */
91
+ engine?: EngineInfo;
92
+ };
93
+ error?: {
94
+ code: string;
95
+ message: string;
96
+ };
97
+ }
98
+ /**
99
+ * Request input for enforce API
100
+ */
101
+ interface EnforceInput {
102
+ /** HTTP headers from the incoming request */
103
+ headers?: Record<string, string>;
104
+ /** User-Agent header */
105
+ userAgent?: string;
106
+ /** Client IP address */
107
+ ipAddress?: string;
108
+ /** Request path */
109
+ path?: string;
110
+ /** Request URL */
111
+ url?: string;
112
+ /** HTTP method */
113
+ method?: string;
114
+ /** Request ID for tracing */
115
+ requestId?: string;
116
+ /** Options */
117
+ options?: {
118
+ /** Include full detection result */
119
+ includeDetectionResult?: boolean;
120
+ /** Cache TTL override */
121
+ cacheTTL?: number;
122
+ };
123
+ }
124
+ /**
125
+ * Input for logging a detection result
126
+ */
127
+ interface LogDetectionInput {
128
+ /** Detection result from Gateway */
129
+ detection: ApiDetectionDetail;
130
+ /** Request context */
131
+ context: {
132
+ userAgent?: string;
133
+ ipAddress?: string;
134
+ path?: string;
135
+ url?: string;
136
+ method?: string;
137
+ };
138
+ /** Source of the detection */
139
+ source?: 'gateway' | 'middleware';
140
+ /** The enforcement decision the caller received and acted on. */
141
+ enforcement?: {
142
+ action: EnforcementAction;
143
+ };
144
+ /** Self-identification of the engine that produced the detection. */
145
+ engine?: EngineInfo;
146
+ /** Self-identification of the reporting SDK: package, version and Next.js runtime. */
147
+ sdk?: {
148
+ name: string;
149
+ version: string;
150
+ runtime: 'node' | 'edge';
151
+ };
152
+ }
153
+ /**
154
+ * Checkpoint API Client
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const client = new CheckpointApiClient({
159
+ * apiKey: process.env.CHECKPOINT_API_KEY!,
160
+ * });
161
+ *
162
+ * const result = await client.enforce({
163
+ * headers: Object.fromEntries(request.headers),
164
+ * path: request.nextUrl.pathname,
165
+ * method: request.method,
166
+ * });
167
+ *
168
+ * if (result.decision.action === 'block') {
169
+ * return new Response('Access denied', { status: 403 });
170
+ * }
171
+ * ```
172
+ */
173
+ declare class CheckpointApiClient {
174
+ private apiKey;
175
+ private baseUrl;
176
+ private useEdge;
177
+ private timeout;
178
+ private debug;
179
+ constructor(config: CheckpointApiClientConfig);
180
+ /**
181
+ * Call the enforce API to check if a request should be allowed
182
+ */
183
+ enforce(input: EnforceInput): Promise<EnforceResponse>;
184
+ /**
185
+ * Quick check - returns just the action without full response parsing
186
+ * Useful for very fast middleware that just needs allow/block. On an API
187
+ * error the action is `block` (fail-closed) with `error` set.
188
+ */
189
+ quickCheck(input: EnforceInput): Promise<{
190
+ action: EnforcementAction;
191
+ error?: string;
192
+ }>;
193
+ /**
194
+ * Check if this client is using edge detection (Gateway Worker)
195
+ */
196
+ isUsingEdge(): boolean;
197
+ /**
198
+ * Log a detection result to the Checkpoint database.
199
+ * Use after Gateway Worker detection to persist results.
200
+ * Fire-and-forget - returns immediately without waiting for DB write.
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * // After receiving Gateway response
205
+ * if (client.isUsingEdge() && response.data?.detection) {
206
+ * client.logDetection({
207
+ * detection: response.data.detection,
208
+ * context: { userAgent, ipAddress, path, url, method }
209
+ * }).catch(err => console.error('Log failed:', err));
210
+ * }
211
+ * ```
212
+ */
213
+ logDetection(input: LogDetectionInput): Promise<void>;
214
+ }
215
+ declare function getCheckpointApiClient(config?: Partial<CheckpointApiClientConfig>): CheckpointApiClient;
216
+ /**
217
+ * Reset the singleton client (useful for testing)
218
+ */
219
+ declare function resetCheckpointApiClient(): void;
220
+ //#endregion
221
+ export { EnforceResponse as a, LogDetectionInput as c, EnforceInput as i, getCheckpointApiClient as l, CheckpointApiClient as n, EnforcementAction as o, CheckpointApiClientConfig as r, EnforcementDecision as s, ApiDetectionDetail as t, resetCheckpointApiClient as u };
222
+ //# sourceMappingURL=api-client-JHOrRUA_.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-client-JHOrRUA_.d.ts","names":[],"sources":["../src/api-client.ts"],"mappings":";;;;;UAiBiB;;EAEf;;EAEA;;;;;;;EAOA;;EAEA;;EAEA;;;;;UAgBe;EACf,QAAQ;EACR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IACE;IACA;IACA;MACE;MACA;MACA;MACA;;IAEF;MACE;MACA;MACA;MACA;;;;;;;KAQM,qBAAqB,KAC/B;EAGA;;EAEA;EACA;EACA;EACA,UAAU;EACV,YAAY;;EAEZ;EACA;;;;;;;;;EASA;;;;;UAMe;EACf;EACA;IACE,UAAU;IACV;IACA;IACA,YAAY;;;;;;IAMZ,SAAS;;EAEX;IACE;IACA;;;;;;UAOa;;EAEf,UAAU;;EAEV;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;IAEE;;IAEA;;;;;;UAOa;;EAEf,WAAW;;EAEX;IACE;IACA;IACA;IACA;IACA;;;EAGF;;EAEA;IAAgB,QAAQ;;;EAExB,SAAS;;EAET;IAAQ;IAAc;IAAiB;;;;;;;;;;;;;;;;;;;;;;;cA+B5B;UACH;UACA;UACA;UACA;UACA;EAEI,YAAA,QAAQ;;;;EAgBd,QAAQ,OAAO,eAAe,QAAQ;;;;;;EA4FtC,WAAW,OAAO,eAAe;IACrC,QAAQ;IACR;;;;;EAmBF;;;;;;;;;;;;;;;;;EAoBM,aAAa,OAAO,oBAAoB;;iBA2GhC,uBACd,SAAS,QAAQ,6BAChB;;;;iBAgBa"}