@kya-os/checkpoint-wasm-runtime 1.5.1 → 1.6.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 (43) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/dist/engine-edge.d.mts +52 -16
  3. package/dist/engine-edge.d.ts +52 -16
  4. package/dist/engine-edge.js +11 -4
  5. package/dist/engine-edge.mjs +11 -4
  6. package/dist/index.d.mts +118 -1
  7. package/dist/index.d.ts +118 -1
  8. package/dist/orchestrator-edge.js +29 -13
  9. package/dist/orchestrator-edge.mjs +29 -13
  10. package/dist/orchestrator-node.js +18 -9
  11. package/dist/orchestrator-node.mjs +18 -9
  12. package/dist/orchestrator.d.mts +52 -16
  13. package/dist/orchestrator.d.ts +52 -16
  14. package/dist/orchestrator.js +29 -13
  15. package/dist/orchestrator.mjs +29 -13
  16. package/dist/policy.d.mts +148 -0
  17. package/dist/policy.d.ts +148 -0
  18. package/dist/policy.js +52 -0
  19. package/dist/policy.mjs +53 -0
  20. package/dist/reporter.d.mts +102 -0
  21. package/dist/reporter.d.ts +102 -0
  22. package/dist/reporter.js +125 -0
  23. package/dist/reporter.mjs +122 -0
  24. package/package.json +15 -5
  25. package/wasm/kya-os-engine/kya_os_engine_bg.wasm +0 -0
  26. package/wasm/kya-os-engine-bundler/kya_os_engine_bg.wasm +0 -0
  27. package/wasm/kya-os-engine-cedar/README.md +26 -0
  28. package/wasm/kya-os-engine-cedar/kya_os_engine.d.ts +77 -0
  29. package/wasm/kya-os-engine-cedar/kya_os_engine.js +636 -0
  30. package/wasm/kya-os-engine-cedar/kya_os_engine_bg.wasm +0 -0
  31. package/wasm/kya-os-engine-cedar/kya_os_engine_bg.wasm.d.ts +11 -0
  32. package/wasm/kya-os-engine-cedar/package.json +29 -0
  33. package/wasm/kya-os-engine-cedar-web/README.md +26 -0
  34. package/wasm/kya-os-engine-cedar-web/kya_os_engine.d.ts +117 -0
  35. package/wasm/kya-os-engine-cedar-web/kya_os_engine.js +694 -0
  36. package/wasm/kya-os-engine-cedar-web/kya_os_engine_bg.wasm +0 -0
  37. package/wasm/kya-os-engine-cedar-web/kya_os_engine_bg.wasm.d.ts +11 -0
  38. package/wasm/kya-os-engine-cedar-web/package.json +31 -0
  39. package/wasm/kya-os-engine-web/kya_os_engine_bg.wasm +0 -0
  40. package/wasm/agentshield_wasm.d.ts +0 -485
  41. package/wasm/agentshield_wasm.js +0 -1551
  42. package/wasm/agentshield_wasm_bg.wasm +0 -0
  43. package/wasm/agentshield_wasm_bg.wasm.d.ts +0 -97
@@ -0,0 +1,148 @@
1
+ import { D as Decision } from './types-C3RniIOM.mjs';
2
+ export { B as BlockReason } from './types-C3RniIOM.mjs';
3
+ import '@kya-os/checkpoint-shared';
4
+
5
+ /**
6
+ * Cedar policy-evaluator bridge — Node fallback.
7
+ *
8
+ * Surfaces the `PolicyEvaluator` class exported by the cedar-enabled
9
+ * `kya-os-engine` WASM artifact (built by
10
+ * `rust/scripts/build-engine-cedar-wasm.sh`, gated on the Rust
11
+ * `wasm,cedar` features). A JS host (the gateway) compiles a tenant
12
+ * policy bundle once and authorizes many requests against it in-process,
13
+ * with no round-trip to a separate policy service.
14
+ *
15
+ * The cedar artifact is a SEPARATE, larger binary than the lean
16
+ * detection artifact — it pulls in `cedar-policy`. Detection-only
17
+ * consumers load `./engine` (the lean `verify()` glue); only callers that
18
+ * need in-process authorization reach for this bridge.
19
+ *
20
+ * ## Lazy loading
21
+ *
22
+ * The cedar `--target nodejs` glue instantiates the ~2 MB cedar WASM the
23
+ * moment it is `require`d (it `fs.readFileSync`s its `.wasm` sibling at
24
+ * module load). To keep the separate-artifact promise — detection-only
25
+ * consumers must NOT pay cedar's memory/startup — the glue is loaded
26
+ * LAZILY: nothing happens on `import`; the artifact is `require`d (and
27
+ * memoised) only on the first {@link createPolicyEvaluator} call. This is
28
+ * also why cedar lives behind the dedicated `./policy` subpath and is NOT
29
+ * re-exported from the `./node` barrel.
30
+ *
31
+ * `createRequire(__filename)` resolves the glue at call time in both
32
+ * builds — native `require` under CJS, the tsup `shims` / `createRequire`
33
+ * banner under ESM. The glue stays external (regex
34
+ * `wasm/kya-os-engine-cedar/` in tsup's `commonOpts.external`), so its
35
+ * `__dirname` resolves against `node_modules/.../wasm/kya-os-engine-cedar/`
36
+ * where the `.wasm` lives, and `"type": "commonjs"` on the artifact's
37
+ * package.json keeps Node from throwing `ERR_REQUIRE_ESM`.
38
+ *
39
+ * Direct .wasm path (for callers building their own loaders):
40
+ * `@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-cedar/kya_os_engine_bg.wasm`
41
+ */
42
+
43
+ /**
44
+ * Owned, plain-data request the host hands to
45
+ * {@link PolicyEvaluatorRuntime.authorize}. Mirrors the Rust
46
+ * `AuthorizeInput` (`rust/crates/kya-os-engine/src/policy/authorize.rs`);
47
+ * keys are camelCase across the wasm-bindgen boundary, matching every
48
+ * other engine wire type.
49
+ *
50
+ * The evaluator is **synchronous over pre-resolved facts** (H-1 Kickoff
51
+ * § 4.5): the host pre-fetches the agent's delegation chain, reputation,
52
+ * etc. and ships the results here — no JS callbacks cross the boundary.
53
+ *
54
+ * `agentDid` and `reputation` are optional (omit or pass `undefined` for
55
+ * an anonymous or reputation-less request); `grantedScopes` defaults to an
56
+ * empty list when omitted.
57
+ */
58
+ interface AuthorizeInput {
59
+ /** Agent DID if identity has been established, otherwise omitted. */
60
+ agentDid?: string;
61
+ /** The action being requested (e.g., `"book_flight"`). */
62
+ action: string;
63
+ /** The resource being acted on (e.g., `"travel_api"`). */
64
+ resource: string;
65
+ /** Scopes granted by the agent's delegation chain. Defaults to `[]`. */
66
+ grantedScopes?: string[];
67
+ /** Agent's reputation score in `[0.0, 1.0]`, if computed. */
68
+ reputation?: number;
69
+ /** Tenant identifier. */
70
+ tenantId: string;
71
+ }
72
+ /**
73
+ * Structural type of the WASM `PolicyEvaluator` class the cedar glue
74
+ * exports. Pinned here so this bridge type-checks against the artifact's
75
+ * `.d.ts` (`constructor(policy_text: string)`, `authorize(input): any`,
76
+ * `free()`).
77
+ */
78
+ interface WasmPolicyEvaluator {
79
+ authorize(input: AuthorizeInput): unknown;
80
+ free(): void;
81
+ }
82
+ /**
83
+ * Host-facing wrapper around one compiled Cedar policy bundle.
84
+ *
85
+ * Construction compiles the bundle once; every {@link authorize} call
86
+ * evaluates a single owned request against it without re-parsing policy
87
+ * text (the compile-once / evaluate-many contract the engine upholds,
88
+ * carried across the boundary).
89
+ */
90
+ declare class PolicyEvaluatorRuntime {
91
+ private readonly inner;
92
+ /**
93
+ * @param inner - The compiled WASM `PolicyEvaluator` handle. Built in
94
+ * {@link createPolicyEvaluator}; reused by every {@link authorize}
95
+ * call for the lifetime of this wrapper.
96
+ */
97
+ constructor(inner: WasmPolicyEvaluator);
98
+ /**
99
+ * Authorize one owned request against the compiled policy bundle.
100
+ *
101
+ * The evaluator owns the fail-closed posture — a request it cannot
102
+ * marshal into Cedar, or one matching no `permit`, comes back as a
103
+ * {@link Decision} `Block` (not a thrown error). Authorization
104
+ * *verdicts* never throw; they surface inside the returned value.
105
+ *
106
+ * @throws {Error} only for boundary faults the WASM glue rejects: a
107
+ * malformed `input` that fails `AuthorizeInput` deserialisation, or a
108
+ * failure serialising the resulting `Decision`.
109
+ */
110
+ authorize(input: AuthorizeInput): Decision;
111
+ /**
112
+ * Release the compiled bundle's WASM memory. Call when the evaluator is
113
+ * no longer needed; after this the wrapper must not be reused.
114
+ */
115
+ free(): void;
116
+ }
117
+ /**
118
+ * Compile a Cedar policy bundle into a reusable in-process evaluator.
119
+ *
120
+ * Mirrors `createNodeDetector`'s WASM loading: routes through the cedar
121
+ * `--target nodejs` glue, which self-loads its `.wasm` sibling via CJS
122
+ * `__dirname` + `require('fs')`. The returned {@link PolicyEvaluatorRuntime}
123
+ * holds one compiled bundle and authorizes many requests against it.
124
+ *
125
+ * @param policyText - The tenant's Cedar policy bundle as source text.
126
+ * @throws {Error} if `policyText` is not syntactically valid Cedar — a
127
+ * malformed bundle is an infrastructure fault surfaced here at
128
+ * construction, never as a per-request deny.
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * import { createPolicyEvaluator } from '@kya-os/checkpoint-wasm-runtime/policy';
133
+ *
134
+ * const evaluator = createPolicyEvaluator('permit(principal, action, resource);');
135
+ * const decision = evaluator.authorize({
136
+ * action: 'book_flight',
137
+ * resource: 'travel_api',
138
+ * tenantId: 'tenant-a',
139
+ * grantedScopes: ['book_flight'],
140
+ * });
141
+ * if (decision.kind === 'Permit') {
142
+ * // proceed
143
+ * }
144
+ * ```
145
+ */
146
+ declare function createPolicyEvaluator(policyText: string): PolicyEvaluatorRuntime;
147
+
148
+ export { type AuthorizeInput, Decision, PolicyEvaluatorRuntime, createPolicyEvaluator };
@@ -0,0 +1,148 @@
1
+ import { D as Decision } from './types-C3RniIOM.js';
2
+ export { B as BlockReason } from './types-C3RniIOM.js';
3
+ import '@kya-os/checkpoint-shared';
4
+
5
+ /**
6
+ * Cedar policy-evaluator bridge — Node fallback.
7
+ *
8
+ * Surfaces the `PolicyEvaluator` class exported by the cedar-enabled
9
+ * `kya-os-engine` WASM artifact (built by
10
+ * `rust/scripts/build-engine-cedar-wasm.sh`, gated on the Rust
11
+ * `wasm,cedar` features). A JS host (the gateway) compiles a tenant
12
+ * policy bundle once and authorizes many requests against it in-process,
13
+ * with no round-trip to a separate policy service.
14
+ *
15
+ * The cedar artifact is a SEPARATE, larger binary than the lean
16
+ * detection artifact — it pulls in `cedar-policy`. Detection-only
17
+ * consumers load `./engine` (the lean `verify()` glue); only callers that
18
+ * need in-process authorization reach for this bridge.
19
+ *
20
+ * ## Lazy loading
21
+ *
22
+ * The cedar `--target nodejs` glue instantiates the ~2 MB cedar WASM the
23
+ * moment it is `require`d (it `fs.readFileSync`s its `.wasm` sibling at
24
+ * module load). To keep the separate-artifact promise — detection-only
25
+ * consumers must NOT pay cedar's memory/startup — the glue is loaded
26
+ * LAZILY: nothing happens on `import`; the artifact is `require`d (and
27
+ * memoised) only on the first {@link createPolicyEvaluator} call. This is
28
+ * also why cedar lives behind the dedicated `./policy` subpath and is NOT
29
+ * re-exported from the `./node` barrel.
30
+ *
31
+ * `createRequire(__filename)` resolves the glue at call time in both
32
+ * builds — native `require` under CJS, the tsup `shims` / `createRequire`
33
+ * banner under ESM. The glue stays external (regex
34
+ * `wasm/kya-os-engine-cedar/` in tsup's `commonOpts.external`), so its
35
+ * `__dirname` resolves against `node_modules/.../wasm/kya-os-engine-cedar/`
36
+ * where the `.wasm` lives, and `"type": "commonjs"` on the artifact's
37
+ * package.json keeps Node from throwing `ERR_REQUIRE_ESM`.
38
+ *
39
+ * Direct .wasm path (for callers building their own loaders):
40
+ * `@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-cedar/kya_os_engine_bg.wasm`
41
+ */
42
+
43
+ /**
44
+ * Owned, plain-data request the host hands to
45
+ * {@link PolicyEvaluatorRuntime.authorize}. Mirrors the Rust
46
+ * `AuthorizeInput` (`rust/crates/kya-os-engine/src/policy/authorize.rs`);
47
+ * keys are camelCase across the wasm-bindgen boundary, matching every
48
+ * other engine wire type.
49
+ *
50
+ * The evaluator is **synchronous over pre-resolved facts** (H-1 Kickoff
51
+ * § 4.5): the host pre-fetches the agent's delegation chain, reputation,
52
+ * etc. and ships the results here — no JS callbacks cross the boundary.
53
+ *
54
+ * `agentDid` and `reputation` are optional (omit or pass `undefined` for
55
+ * an anonymous or reputation-less request); `grantedScopes` defaults to an
56
+ * empty list when omitted.
57
+ */
58
+ interface AuthorizeInput {
59
+ /** Agent DID if identity has been established, otherwise omitted. */
60
+ agentDid?: string;
61
+ /** The action being requested (e.g., `"book_flight"`). */
62
+ action: string;
63
+ /** The resource being acted on (e.g., `"travel_api"`). */
64
+ resource: string;
65
+ /** Scopes granted by the agent's delegation chain. Defaults to `[]`. */
66
+ grantedScopes?: string[];
67
+ /** Agent's reputation score in `[0.0, 1.0]`, if computed. */
68
+ reputation?: number;
69
+ /** Tenant identifier. */
70
+ tenantId: string;
71
+ }
72
+ /**
73
+ * Structural type of the WASM `PolicyEvaluator` class the cedar glue
74
+ * exports. Pinned here so this bridge type-checks against the artifact's
75
+ * `.d.ts` (`constructor(policy_text: string)`, `authorize(input): any`,
76
+ * `free()`).
77
+ */
78
+ interface WasmPolicyEvaluator {
79
+ authorize(input: AuthorizeInput): unknown;
80
+ free(): void;
81
+ }
82
+ /**
83
+ * Host-facing wrapper around one compiled Cedar policy bundle.
84
+ *
85
+ * Construction compiles the bundle once; every {@link authorize} call
86
+ * evaluates a single owned request against it without re-parsing policy
87
+ * text (the compile-once / evaluate-many contract the engine upholds,
88
+ * carried across the boundary).
89
+ */
90
+ declare class PolicyEvaluatorRuntime {
91
+ private readonly inner;
92
+ /**
93
+ * @param inner - The compiled WASM `PolicyEvaluator` handle. Built in
94
+ * {@link createPolicyEvaluator}; reused by every {@link authorize}
95
+ * call for the lifetime of this wrapper.
96
+ */
97
+ constructor(inner: WasmPolicyEvaluator);
98
+ /**
99
+ * Authorize one owned request against the compiled policy bundle.
100
+ *
101
+ * The evaluator owns the fail-closed posture — a request it cannot
102
+ * marshal into Cedar, or one matching no `permit`, comes back as a
103
+ * {@link Decision} `Block` (not a thrown error). Authorization
104
+ * *verdicts* never throw; they surface inside the returned value.
105
+ *
106
+ * @throws {Error} only for boundary faults the WASM glue rejects: a
107
+ * malformed `input` that fails `AuthorizeInput` deserialisation, or a
108
+ * failure serialising the resulting `Decision`.
109
+ */
110
+ authorize(input: AuthorizeInput): Decision;
111
+ /**
112
+ * Release the compiled bundle's WASM memory. Call when the evaluator is
113
+ * no longer needed; after this the wrapper must not be reused.
114
+ */
115
+ free(): void;
116
+ }
117
+ /**
118
+ * Compile a Cedar policy bundle into a reusable in-process evaluator.
119
+ *
120
+ * Mirrors `createNodeDetector`'s WASM loading: routes through the cedar
121
+ * `--target nodejs` glue, which self-loads its `.wasm` sibling via CJS
122
+ * `__dirname` + `require('fs')`. The returned {@link PolicyEvaluatorRuntime}
123
+ * holds one compiled bundle and authorizes many requests against it.
124
+ *
125
+ * @param policyText - The tenant's Cedar policy bundle as source text.
126
+ * @throws {Error} if `policyText` is not syntactically valid Cedar — a
127
+ * malformed bundle is an infrastructure fault surfaced here at
128
+ * construction, never as a per-request deny.
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * import { createPolicyEvaluator } from '@kya-os/checkpoint-wasm-runtime/policy';
133
+ *
134
+ * const evaluator = createPolicyEvaluator('permit(principal, action, resource);');
135
+ * const decision = evaluator.authorize({
136
+ * action: 'book_flight',
137
+ * resource: 'travel_api',
138
+ * tenantId: 'tenant-a',
139
+ * grantedScopes: ['book_flight'],
140
+ * });
141
+ * if (decision.kind === 'Permit') {
142
+ * // proceed
143
+ * }
144
+ * ```
145
+ */
146
+ declare function createPolicyEvaluator(policyText: string): PolicyEvaluatorRuntime;
147
+
148
+ export { type AuthorizeInput, Decision, PolicyEvaluatorRuntime, createPolicyEvaluator };
package/dist/policy.js ADDED
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ var module$1 = require('module');
4
+
5
+ // src/policy-evaluator.ts
6
+ var cedarRequire = module$1.createRequire(__filename);
7
+ var cedarModule;
8
+ function loadCedarModule() {
9
+ cedarModule ??= cedarRequire(
10
+ "@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-cedar/kya_os_engine.js"
11
+ );
12
+ return cedarModule;
13
+ }
14
+ var PolicyEvaluatorRuntime = class {
15
+ /**
16
+ * @param inner - The compiled WASM `PolicyEvaluator` handle. Built in
17
+ * {@link createPolicyEvaluator}; reused by every {@link authorize}
18
+ * call for the lifetime of this wrapper.
19
+ */
20
+ constructor(inner) {
21
+ this.inner = inner;
22
+ }
23
+ /**
24
+ * Authorize one owned request against the compiled policy bundle.
25
+ *
26
+ * The evaluator owns the fail-closed posture — a request it cannot
27
+ * marshal into Cedar, or one matching no `permit`, comes back as a
28
+ * {@link Decision} `Block` (not a thrown error). Authorization
29
+ * *verdicts* never throw; they surface inside the returned value.
30
+ *
31
+ * @throws {Error} only for boundary faults the WASM glue rejects: a
32
+ * malformed `input` that fails `AuthorizeInput` deserialisation, or a
33
+ * failure serialising the resulting `Decision`.
34
+ */
35
+ authorize(input) {
36
+ return this.inner.authorize(input);
37
+ }
38
+ /**
39
+ * Release the compiled bundle's WASM memory. Call when the evaluator is
40
+ * no longer needed; after this the wrapper must not be reused.
41
+ */
42
+ free() {
43
+ this.inner.free();
44
+ }
45
+ };
46
+ function createPolicyEvaluator(policyText) {
47
+ const { PolicyEvaluator } = loadCedarModule();
48
+ return new PolicyEvaluatorRuntime(new PolicyEvaluator(policyText));
49
+ }
50
+
51
+ exports.PolicyEvaluatorRuntime = PolicyEvaluatorRuntime;
52
+ exports.createPolicyEvaluator = createPolicyEvaluator;
@@ -0,0 +1,53 @@
1
+ import { createRequire } from 'module';
2
+ import 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ createRequire(import.meta.url);
6
+ var getFilename = () => fileURLToPath(import.meta.url);
7
+ var __filename$1 = /* @__PURE__ */ getFilename();
8
+ var cedarRequire = createRequire(__filename$1);
9
+ var cedarModule;
10
+ function loadCedarModule() {
11
+ cedarModule ??= cedarRequire(
12
+ "@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-cedar/kya_os_engine.js"
13
+ );
14
+ return cedarModule;
15
+ }
16
+ var PolicyEvaluatorRuntime = class {
17
+ /**
18
+ * @param inner - The compiled WASM `PolicyEvaluator` handle. Built in
19
+ * {@link createPolicyEvaluator}; reused by every {@link authorize}
20
+ * call for the lifetime of this wrapper.
21
+ */
22
+ constructor(inner) {
23
+ this.inner = inner;
24
+ }
25
+ /**
26
+ * Authorize one owned request against the compiled policy bundle.
27
+ *
28
+ * The evaluator owns the fail-closed posture — a request it cannot
29
+ * marshal into Cedar, or one matching no `permit`, comes back as a
30
+ * {@link Decision} `Block` (not a thrown error). Authorization
31
+ * *verdicts* never throw; they surface inside the returned value.
32
+ *
33
+ * @throws {Error} only for boundary faults the WASM glue rejects: a
34
+ * malformed `input` that fails `AuthorizeInput` deserialisation, or a
35
+ * failure serialising the resulting `Decision`.
36
+ */
37
+ authorize(input) {
38
+ return this.inner.authorize(input);
39
+ }
40
+ /**
41
+ * Release the compiled bundle's WASM memory. Call when the evaluator is
42
+ * no longer needed; after this the wrapper must not be reused.
43
+ */
44
+ free() {
45
+ this.inner.free();
46
+ }
47
+ };
48
+ function createPolicyEvaluator(policyText) {
49
+ const { PolicyEvaluator } = loadCedarModule();
50
+ return new PolicyEvaluatorRuntime(new PolicyEvaluator(policyText));
51
+ }
52
+
53
+ export { PolicyEvaluatorRuntime, createPolicyEvaluator };
@@ -0,0 +1,102 @@
1
+ import { V as VerifyResult, f as EngineInfo } from './types-C3RniIOM.mjs';
2
+ import '@kya-os/checkpoint-shared';
3
+
4
+ /**
5
+ * Detection reporter — fire-and-forget POST to the dashboard's
6
+ * `/api/v1/log-detection` ingest endpoint.
7
+ *
8
+ * The engine-backed middlewares (`withCheckpoint` in `checkpoint-express`
9
+ * and `checkpoint-nextjs`) run verification locally via WASM. Without
10
+ * this reporter the verdict path works in-process but nothing flows
11
+ * back to the dashboard — the onboarding "Verify" check fails forever
12
+ * because the `detections` table never sees a row.
13
+ *
14
+ * Mirrors the contract of the legacy `CheckpointApiClient.logDetection`
15
+ * (see `checkpoint-nextjs/src/api-client.ts`) so the server-side
16
+ * ingest at `/api/v1/log-detection` accepts both paths identically.
17
+ *
18
+ * Subpath: `@kya-os/checkpoint-wasm-runtime/reporter`.
19
+ *
20
+ * @license MIT OR Apache-2.0
21
+ */
22
+
23
+ /**
24
+ * Request context the middleware extracts from its framework-native
25
+ * request object. Shape matches the `ContextSchema` accepted by
26
+ * `/api/v1/log-detection`.
27
+ */
28
+ interface ReporterContext {
29
+ userAgent?: string;
30
+ ipAddress?: string;
31
+ path?: string;
32
+ url?: string;
33
+ method?: string;
34
+ }
35
+ /**
36
+ * Configuration for the detection reporter.
37
+ */
38
+ interface DetectionReporterConfig {
39
+ /**
40
+ * Project API key. Resolved server-side at the ingest endpoint into
41
+ * the project association used to insert the detection row. Required.
42
+ */
43
+ apiKey: string;
44
+ /**
45
+ * Dashboard base URL. Defaults to `https://kya.vouched.id`. Override
46
+ * for staging environments or self-hosted dashboards.
47
+ */
48
+ baseUrl?: string;
49
+ /**
50
+ * Per-request timeout in milliseconds. Defaults to 5000ms. The POST
51
+ * is fire-and-forget — a timeout aborts the request but never blocks
52
+ * the verdict path.
53
+ */
54
+ timeoutMs?: number;
55
+ /**
56
+ * Emit `console.warn` on reporter failures. Defaults to `false` —
57
+ * fire-and-forget means silent by design. Enable during development
58
+ * to surface mis-configured `apiKey` / `baseUrl`.
59
+ */
60
+ debug?: boolean;
61
+ }
62
+ /**
63
+ * Self-catching reporter promise. Call after every `verifyRequest`
64
+ * decision. Callers that can extend request lifetime (for example,
65
+ * NextFetchEvent.waitUntil) should attach this promise; callers that
66
+ * cannot may still ignore it safely because errors are swallowed
67
+ * (unless `debug: true`).
68
+ */
69
+ type DetectionReporter = (result: VerifyResult, ctx: ReporterContext) => Promise<void>;
70
+ /**
71
+ * Build a fire-and-forget reporter bound to a single project API key.
72
+ *
73
+ * The returned function is safe to call from any verdict path — it
74
+ * never throws, never awaits the network round-trip, and never affects
75
+ * the response.
76
+ */
77
+ declare function makeDetectionReporter(config: DetectionReporterConfig): DetectionReporter;
78
+ /**
79
+ * Translate the engine's `VerifyResult` into the request body shape
80
+ * accepted by `/api/v1/log-detection`. Exported for tests + for
81
+ * advanced consumers wiring a custom transport.
82
+ */
83
+ declare function buildLogDetectionPayload(result: VerifyResult, ctx: ReporterContext): {
84
+ detection: {
85
+ isAgent: boolean;
86
+ confidence: number;
87
+ agentName: string | undefined;
88
+ agentType: string | undefined;
89
+ detectionClass: string | undefined;
90
+ verificationMethod: "signature" | "pattern" | "behavioral" | "network" | "mcp_i_handshake" | "none" | "error" | undefined;
91
+ reasons: string[];
92
+ };
93
+ context: ReporterContext;
94
+ source: "middleware";
95
+ enforcement: {
96
+ action: string;
97
+ reason?: string;
98
+ };
99
+ engine: EngineInfo | undefined;
100
+ };
101
+
102
+ export { type DetectionReporter, type DetectionReporterConfig, type ReporterContext, buildLogDetectionPayload, makeDetectionReporter };
@@ -0,0 +1,102 @@
1
+ import { V as VerifyResult, f as EngineInfo } from './types-C3RniIOM.js';
2
+ import '@kya-os/checkpoint-shared';
3
+
4
+ /**
5
+ * Detection reporter — fire-and-forget POST to the dashboard's
6
+ * `/api/v1/log-detection` ingest endpoint.
7
+ *
8
+ * The engine-backed middlewares (`withCheckpoint` in `checkpoint-express`
9
+ * and `checkpoint-nextjs`) run verification locally via WASM. Without
10
+ * this reporter the verdict path works in-process but nothing flows
11
+ * back to the dashboard — the onboarding "Verify" check fails forever
12
+ * because the `detections` table never sees a row.
13
+ *
14
+ * Mirrors the contract of the legacy `CheckpointApiClient.logDetection`
15
+ * (see `checkpoint-nextjs/src/api-client.ts`) so the server-side
16
+ * ingest at `/api/v1/log-detection` accepts both paths identically.
17
+ *
18
+ * Subpath: `@kya-os/checkpoint-wasm-runtime/reporter`.
19
+ *
20
+ * @license MIT OR Apache-2.0
21
+ */
22
+
23
+ /**
24
+ * Request context the middleware extracts from its framework-native
25
+ * request object. Shape matches the `ContextSchema` accepted by
26
+ * `/api/v1/log-detection`.
27
+ */
28
+ interface ReporterContext {
29
+ userAgent?: string;
30
+ ipAddress?: string;
31
+ path?: string;
32
+ url?: string;
33
+ method?: string;
34
+ }
35
+ /**
36
+ * Configuration for the detection reporter.
37
+ */
38
+ interface DetectionReporterConfig {
39
+ /**
40
+ * Project API key. Resolved server-side at the ingest endpoint into
41
+ * the project association used to insert the detection row. Required.
42
+ */
43
+ apiKey: string;
44
+ /**
45
+ * Dashboard base URL. Defaults to `https://kya.vouched.id`. Override
46
+ * for staging environments or self-hosted dashboards.
47
+ */
48
+ baseUrl?: string;
49
+ /**
50
+ * Per-request timeout in milliseconds. Defaults to 5000ms. The POST
51
+ * is fire-and-forget — a timeout aborts the request but never blocks
52
+ * the verdict path.
53
+ */
54
+ timeoutMs?: number;
55
+ /**
56
+ * Emit `console.warn` on reporter failures. Defaults to `false` —
57
+ * fire-and-forget means silent by design. Enable during development
58
+ * to surface mis-configured `apiKey` / `baseUrl`.
59
+ */
60
+ debug?: boolean;
61
+ }
62
+ /**
63
+ * Self-catching reporter promise. Call after every `verifyRequest`
64
+ * decision. Callers that can extend request lifetime (for example,
65
+ * NextFetchEvent.waitUntil) should attach this promise; callers that
66
+ * cannot may still ignore it safely because errors are swallowed
67
+ * (unless `debug: true`).
68
+ */
69
+ type DetectionReporter = (result: VerifyResult, ctx: ReporterContext) => Promise<void>;
70
+ /**
71
+ * Build a fire-and-forget reporter bound to a single project API key.
72
+ *
73
+ * The returned function is safe to call from any verdict path — it
74
+ * never throws, never awaits the network round-trip, and never affects
75
+ * the response.
76
+ */
77
+ declare function makeDetectionReporter(config: DetectionReporterConfig): DetectionReporter;
78
+ /**
79
+ * Translate the engine's `VerifyResult` into the request body shape
80
+ * accepted by `/api/v1/log-detection`. Exported for tests + for
81
+ * advanced consumers wiring a custom transport.
82
+ */
83
+ declare function buildLogDetectionPayload(result: VerifyResult, ctx: ReporterContext): {
84
+ detection: {
85
+ isAgent: boolean;
86
+ confidence: number;
87
+ agentName: string | undefined;
88
+ agentType: string | undefined;
89
+ detectionClass: string | undefined;
90
+ verificationMethod: "signature" | "pattern" | "behavioral" | "network" | "mcp_i_handshake" | "none" | "error" | undefined;
91
+ reasons: string[];
92
+ };
93
+ context: ReporterContext;
94
+ source: "middleware";
95
+ enforcement: {
96
+ action: string;
97
+ reason?: string;
98
+ };
99
+ engine: EngineInfo | undefined;
100
+ };
101
+
102
+ export { type DetectionReporter, type DetectionReporterConfig, type ReporterContext, buildLogDetectionPayload, makeDetectionReporter };