import { c as BlockReason, it as VerifyResult, x as EngineInfo } from "./types-BVx5XvPN.mjs"; import "./policy-evaluator-Cn476P-M.mjs"; import { ReportedIdentity } from "@kya-os/checkpoint-shared"; import { ClientAddressShadow } from "@kya-os/checkpoint-shared/client-ip"; //#region src/reporter/index.d.ts declare const DEFAULT_TELEMETRY_BATCH_SIZE = 200; declare const MAX_TELEMETRY_BATCH_SIZE = 500; declare const DEFAULT_TELEMETRY_FLUSH_INTERVAL_MS = 2000; declare const REPORT_QUEUE_CAPACITY = 10000; declare const REPORT_MAX_IN_FLIGHT = 4; declare const REPORT_GZIP_MIN_CHARS = 1024; declare const REPORT_GZIP_BACKOFF_MS: number; /** * Request context the middleware extracts from its framework-native * request object. Shape matches the `ContextSchema` accepted by * `/api/v1/log-detection`. */ interface ReporterContext { userAgent?: string; ipAddress?: string; path?: string; url?: string; method?: string; /** * Shadow measurement of the trusted-proxy rule decided on 2026-10-28 * (`compareForwardedChainShadow`): agreement and shapes only, never an * address. Removed with that function once the engine resolves the client * address. */ clientAddressShadow?: ClientAddressShadow; } /** * SDK self-identification — the producing middleware package + its installed * version + runtime. The engine WASM reports the SAME `engine.name` * (`checkpoint-engine-wasm`) for Express, Next.js-node, AND Next.js-edge, so * detections cannot otherwise tell them apart OR know the SDK version. The host * wrapper binds this once (from its own `VERSION` constant + entry file), so the * dashboard can gate "composed policy enforces here" on the actual installed SDK * — including showing Next.js-edge as opt-in (it enforces only when the host * wires `cedarWasmModule`, which detections can't observe). * * Carried TOP-LEVEL in the payload (not inside `engine`) so it survives the * engine-field drop in {@link sanitizeEngineInfo}. */ interface ReporterSdkInfo { /** npm package name, e.g. `@kya-os/checkpoint-express`. */ name: string; /** Installed SDK semver, e.g. `1.5.1`. */ version: string; /** Host runtime — `'edge'` composed enforcement is opt-in (cedarWasmModule). */ runtime: 'node' | 'edge'; } /** * Configuration for the detection reporter. */ interface DetectionReporterConfig { /** * Project API key. Resolved server-side at the ingest endpoint into * the project association used to insert the detection row. Required. */ apiKey: string; /** * Dashboard base URL. Defaults to `https://kya.vouched.id`. Override * for staging environments or self-hosted dashboards. */ baseUrl?: string; /** * Per-attempt timeout in milliseconds. Defaults to 5000ms. The POST * is fire-and-forget — a timeout aborts the attempt, which is then * retried like a network error, and never blocks the verdict path. */ timeoutMs?: number; /** * Log retry attempts, network failures, server errors and dropped engine * fields. Defaults to `false`. Other HTTP failures can still warn. * API key rejections warn once per key and endpoint in each process, even with debug off. */ debug?: boolean; /** * SDK self-identification — bound once by the host wrapper. Omit for the * legacy/anonymous path (the dashboard then can't version-gate this runtime * and treats it honestly as unknown). See {@link ReporterSdkInfo}. */ sdk?: ReporterSdkInfo; telemetryBatchSize?: number; telemetryFlushIntervalMs?: number; } interface DetectionReporter { (result: VerifyResult, ctx: ReporterContext): Promise; flush: () => Promise; } declare function flushDetectionReports(): Promise; interface ReportSenderConfig { apiKey: string; baseUrl?: string; timeoutMs?: number; debug?: boolean; telemetryBatchSize?: number; telemetryFlushIntervalMs?: number; runtime?: 'node' | 'edge'; } interface ReportSender { send: (payload: Record) => Promise; flush: () => Promise; } declare function makeReportSender(config: ReportSenderConfig): ReportSender; declare function makeDetectionReporter(config: DetectionReporterConfig): DetectionReporter; /** * Translate the engine's `VerifyResult` into the request body shape * accepted by `/api/v1/log-detection`. Exported for tests + for * advanced consumers wiring a custom transport. */ declare function buildLogDetectionPayload(result: VerifyResult, ctx: ReporterContext, sdk?: ReporterSdkInfo): { identity?: { agent?: { did?: string | undefined; oauthClientId?: string | undefined; clientInfoName?: string | undefined; clientInfoVersion?: string | undefined; } | undefined; principal?: { did?: string | undefined; sub?: string | undefined; email?: string | undefined; } | undefined; delegation?: { result: "verified" | "failed" | "not_presented"; verifiedBy: "reporter" | "gateway" | "checkpoint"; jti?: string | undefined; sid?: string | undefined; iss?: string | undefined; aud?: string | undefined; capabilities?: string[] | undefined; exp?: number | undefined; } | undefined; } | undefined; engineSteps?: { name: string; verdict: "pass" | "fail" | "skip"; latencyMicros: number; reason?: string | undefined; }[] | undefined; context: ReporterContext; source: "middleware"; enforcement: { composedBlobHash?: string | undefined; signals?: { signalType: "behavioral" | "pattern" | "network" | "signature" | "fingerprint"; confidence: number; weight: number; source: string; explanation: string; metadata?: Record | undefined; }[] | undefined; blockReason?: BlockReason | undefined; action: string; reason?: string; policyId?: string; }; engine: EngineInfo | undefined; sdk: ReporterSdkInfo | undefined; postureOutcome?: { status: "verified" | "absent" | "rejected"; reason?: "malformed" | "unknown-key" | "bad-signature" | "invalid-claims" | "project-mismatch" | "origin-mismatch" | "audience-mismatch" | "expired" | "not-yet-valid" | "binding-mismatch" | "session-missing" | undefined; } | undefined; browserIntegrity?: { projectId: string; sessionId: string; verdict: "human" | "agent-driven" | "insufficient"; score: number | null; scorerVersion: number; reasons: string[]; issuedAt: number; expiresAt: number; source: "verified-posture"; } | undefined; detection: { isAgent: boolean; confidence: number; agentName: string | undefined; agentType: string | undefined; detectionClass: string | undefined; verificationMethod: "behavioral" | "pattern" | "network" | "signature" | "error" | "kyaos_handshake" | "mcp_i_handshake" | "kya-http" | "kya-http-delegated" | "tier1_rfc9421" | "a2a" | "none" | undefined; reasons: string[]; shadowMetadata: Record | undefined; detectionBasis: string | undefined; }; }; /** * Build the `identity` wire block (`ReportedIdentitySchema` in * `@kya-os/checkpoint-shared`) from the engine's verdict. Thin passthrough: every * fact here already left the WASM boundary on `detectionDetail.metadata`; this * function only decides which of three shapes the ALREADY-DECIDED engine verdict maps * to (flow-lab-customer-delegation-timeline plan, D15 / E4 / E5): * * 1. `metadata.kya_session_id` present AND `decision.kind === 'Permit'` -> the engine * verified a presented delegation. `result: SID_ATTRIBUTABLE_RESULT` ('verified'), * carrying the sid. The engine never stamps a sid on a reject or a demotion, so * this branch alone is what makes "verified" trustworthy: the security rule is * never decode the bearer here to get a sid; only the engine's verified output * can supply one. The added `decision.kind === 'Permit'` gate is defense in depth: * the engine only ever pairs a stamped sid with a Permit decision (see * `kya_verified_detail` / `bearer_verified_detail` in `rust/crates/kya-os-engine/src/api.rs`), * so requiring both here guards against a future engine change surfacing a sid * outside that pairing, matching D15's "the server has to hold the line" * principle applied client-side too. * 2. No sid, but `metadata.kya_error_code` is a registry `kyaos/*` code (via * `readKyaErrorCode`) -> a kya credential was presented and the engine explicitly * rejected it. `result: 'failed'`, no sid (E4). * 3. Neither -> nothing kya-shaped was presented, OR the engine demoted the request * (identity-pending / a cold trusted root never resolves to a registry code: * `readKyaErrorCode` already filters `kyaos/identity-pending` out because it is * not a member of `KYA_HTTP_ERROR`). Falls through to branch 4. * 4. (KYA-1099 W1) `result.bearerDelegationIdentity` is set — the orchestrator itself * observed a standalone bearer delegation (`verify-request-edge.ts`). This is the * branch that fires for a plain bearer delegation with no `sid` claim (ordinary * Bouncer-issued delegations, not kya-http/2 registered sessions): `result: * 'verified' | 'failed'` from the orchestrator's decision, carrying `jti` — the * join key into `delegations.id` that branches 1-3 never carry. Only reached when neither 1 nor 2 already produced a `delegation` (a sid * claim, when present, still wins — the engine-verified sid is the stronger * signal). Omit entirely (branch 5) when nothing was presented at all. * * `identity.agent.did` rides along whenever the engine attributed a leaf DID * (branches 1-3), or, absent that, whenever branch 4's bearer delegation carried one * — independent of which delegation branch fired. * * Returns `undefined` (never `{}`) when there is nothing to report, so callers can * `...(identity ? { identity } : {})` and keep the wire lean for every non-KYA-OS * request (the overwhelming majority). */ declare function buildReportedIdentity(result: VerifyResult): ReportedIdentity | undefined; //#endregion export { makeDetectionReporter as _, MAX_TELEMETRY_BATCH_SIZE as a, REPORT_MAX_IN_FLIGHT as c, ReportSenderConfig as d, ReporterContext as f, flushDetectionReports as g, buildReportedIdentity as h, DetectionReporterConfig as i, REPORT_QUEUE_CAPACITY as l, buildLogDetectionPayload as m, DEFAULT_TELEMETRY_FLUSH_INTERVAL_MS as n, REPORT_GZIP_BACKOFF_MS as o, ReporterSdkInfo as p, DetectionReporter as r, REPORT_GZIP_MIN_CHARS as s, DEFAULT_TELEMETRY_BATCH_SIZE as t, ReportSender as u, makeReportSender as v }; //# sourceMappingURL=index-CYz9wisx.d.mts.map