import { b as EngineConfig, it as VerifyResult, y as EnforcementMode } from "./types-BVx5XvPN.mjs"; import { M as RequestClaimStore, R as PostureHandlerView, a as MakeComposedPolicyContextOptions, n as ComposedPolicyContext } from "./composed-policy-context-B7ziFk3g.mjs"; import { S as ResolutionWarmerEngine, t as EngineAdapterOverrides } from "./index-CK-B3y6a.mjs"; import { b as EngineRenderOptions } from "./edge-D5Fz0Z_e.mjs"; import { _ as RenderedResponse, g as IncomingHttpLike, v as VerifyRequestOpts, y as VendorKeyEdgeOptions } from "./verify-request-edge-DZlw_WV7.mjs"; import { f as ReporterContext } from "./index-CYz9wisx.mjs"; import { BrowserPostureConfig } from "@kya-os/checkpoint-shared/browser-posture"; import { ChallengeContextFailureEvent, ChallengeEnvelopeMode, ChallengeWireInput, ClientIpTrustPolicy, HeaderEntry } from "@kya-os/checkpoint-shared"; //#region src/pipeline/config.d.ts /** Configuration for `withCheckpoint`; `Req` is the framework's request type. */ interface CheckpointHostConfig { /** * Selects the infrastructure allowed to vouch for observed client * addresses. Each adapter documents which profiles it can authenticate. */ clientIpPolicy?: ClientIpTrustPolicy; /** * @deprecated No longer used; will be removed. Nothing reads it: the engine * makes the tenant decision, and a project's policy is keyed by `projectId`. */ tenantHost?: string; /** Exact org DID used to verify the consent credential's audience. */ resourceOrgDid?: string; /** Explicit trusted delegation issuers; otherwise resolved from project policy. */ trustedDelegationRoots?: string[]; /** * `'enforce'` (default) blocks; `'observe'` passes everything * through with `X-Checkpoint-Would-Have-Been` headers. Per Phase 0.2. * * When the project's policy cannot be read (the policy API is down or * refuses `apiKey`), observe mode serves the request on the engine's * decision, and enforce mode answers a retryable 503. * * @default 'enforce' */ enforcementMode?: EnforcementMode; /** * Challenge-emission envelope mode (draft-kya-http-02 §8.1 fetcher-200). * `negotiated` serves a body-readable HTTP 200 step-up response to * cooperative agents (fetchers that drop 4xx/5xx bodies), keeping the spec * 401/422 for everyone else. Defaults to `negotiated` (#3530). A cooperative-UX * bridge, NOT an access control. * * @default 'negotiated' */ delegationChallengeMode?: ChallengeEnvelopeMode; /** * Resolve a policy `Challenge`, or a block consent can remedy, into registered wire context. * The callback performs any Authorization-Host registration asynchronously; * the synchronous engine renderer never fabricates a sid, consent URI, or proof. */ resolveDelegationChallenge?: (context: { result: VerifyResult; request: Req; }) => ChallengeWireInput | undefined | Promise; /** * Registration/resolution budget in milliseconds. * * @default 3000 */ delegationChallengeTimeoutMs?: number; /** Sanitized registration failure hook for metrics and operator warnings. */ onDelegationChallengeFailure?: (event: ChallengeContextFailureEvent) => void; /** * Argus reputation oracle base URL. Omit to use the trust-by-default * baseline (reputation defaults to 1.0; orchestrator logs a one-shot * warning at first request). */ argusUrl?: string; /** * Dashboard base URL for the composed policy fetch * (`/api/internal/policies/{projectId}`). Takes precedence over * `baseUrl`; omit both to use the hosted dashboard. */ dashboardUrl?: string; /** * Pre-built adapter instances. Production deployments use the * factory-built defaults from `@kya-os/checkpoint-wasm-runtime/adapters`; * tests use stubs. The factory composes any provided overrides over * defaults — partial overrides are supported. */ adapters?: EngineAdapterOverrides; /** * Optional callback for the post-verdict path — fires after every * verification, regardless of permit/block, with the full * `VerifyResult`. Use for logging, dashboards, telemetry. Errors * thrown here are swallowed so user code can't break the middleware * response. */ onResult?: (result: VerifyResult, req: Req) => void | Promise; /** * Accept legacy `KYA-Delegation`-header envelope form alongside the * canonical `_meta.proof.jws` body form. Default `false`. * * **When to enable** — customers whose agents pre-date Envelope-1 * (#2537) and ship KYA-OS proofs as `{protected,payload,signature}` * JSON in a `KYA-Delegation` HTTP header. Post-Envelope-1 agents * ship compact JWS in the request body's `_meta.proof.jws` field; * those don't need this flag. * * Forwarded to the orchestrator's `VerifyRequestOpts.legacyEnvelopeFallback`. * Both transports (header + body) are honored when this is `true`; * the orchestrator's detection order is body first, then header * (`packages/checkpoint-wasm-runtime/src/engine/orchestrator/build-agent-request.ts`). * * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-express` * and `@kya-os/checkpoint-nextjs` 1.1.0. * * @default false */ legacyEnvelopeFallback?: boolean; /** * Engine-default behaviour knobs forwarded to every composed * `ContextSpec`. Defaults to `{ tier3Action: 'monitor' }` — * customer-onboarding-safe (tenant policy decides; engine doesn't * short-circuit known-agent UAs with an engine-default Block). * * Opt into `{ tier3Action: 'block' }` when the host wants the * calibrated engine-default block for KnownAiAgent / AiCrawler / * HeadlessBrowser classifications BEFORE the tenant policy seam. * The bench harness is the canonical opt-in consumer. * * Added in `@kya-os/checkpoint-express` and `@kya-os/checkpoint-nextjs` * 1.2.0 (Engine-Tier3-Monitor-Default, #2653 + its plumbing follow-up). * * @default { tier3Action: 'monitor' } */ engineConfig?: EngineConfig; /** * Project API key. Required for detections to land in the dashboard * — the engine verifies in-process via WASM, but the resulting * `VerifyResult` only reaches the dashboard's `detections` table * when this reporter is configured. Without it the verdict path * works locally but the onboarding "Verify connection" check fails * forever because no rows are ever written. It also authorizes the read of * the `projectId` policy. * * Resolve from `process.env.CHECKPOINT_API_KEY` in the host app. * * Added in `@kya-os/checkpoint-express` and `@kya-os/checkpoint-nextjs` * 1.4.0 (SDK-Detection-Reporter-1). */ apiKey?: string; /** * Dashboard base URL. Override for staging or self-hosted dashboards. * * @default 'https://kya.vouched.id' */ baseUrl?: string; /** * Surface reporter errors via `console.warn`. Defaults to `false`. * The reporter is fire-and-forget; enable during development to * confirm `apiKey` / `baseUrl` are routed correctly. * * Also wires the composed-policy shadow-divergence + evaluation-error * telemetry, and pipeline-failure logging (the 503 fail-closed path), to * `console.warn`/`console.error` (otherwise silent). * * @default false */ debug?: boolean; telemetryBatchSize?: number; telemetryFlushIntervalMs?: number; /** * Project id whose composed (/policy-compose) policy this middleware * enforces. When set, the project's policy is fetched from the dashboard * (`/api/internal/policies/${projectId}`) * and — if it carries a deployed Cedar bundle with `engineEnforcementEnabled` * on — the kya-os-engine decision is enforced IN-PROCESS, byte-for-byte the * same as the DNS Gateway. Omit to run detection + the structured policy only * (fully back-compatible; purely additive). * * SHADOW-FIRST: with a deployed bundle but `engineEnforcementEnabled` off, the * engine decision is computed + logged on divergence but does NOT act. * Get the project id from the dashboard (same place as `apiKey`). * * Needs `apiKey`: the policy API answers only a request carrying the * project's API key. With `projectId` and no `apiKey`, building the * middleware throws in enforce mode (Next.js answers every request 503 and * logs it), and in observe mode the policy is neither fetched nor applied * and one warning is logged at startup. With both set, a Node.js host reads * the policy when it starts, so a refused key is logged before the first * request. * * Added in `@kya-os/checkpoint-express` and `@kya-os/checkpoint-nextjs` * 1.5.0 (@Policy middleware-Cedar, #3076). */ projectId?: string; /** Signed browser risk; configure explicit route scopes to enable consent step-up. */ browserPosture?: BrowserPostureConfig; /** * Where accepted signed requests are claimed, so each is used once. Defaults * to the dashboard's shared ledger when `apiKey` and `projectId` are set, * otherwise to a store in this process or isolate (with a one-time warning, * since a deployment with several instances needs a shared store). Pass * `createLocalRequestClaimStore()` to choose the in-process store explicitly. */ requestClaimStore?: RequestClaimStore; /** * Policy-fetch cache TTL in seconds. Defaults to 300 (5 minutes). How long * a fetched project policy is reused before the middleware refetches from * the dashboard — i.e. the worst-case delay before a dashboard policy * change takes effect on this host. * * `0` disables reuse entirely: every request fetches the policy (one * origin round-trip per request). Use for demo/example sites where instant * policy propagation matters more than latency; keep the default (or a * small positive value like 5) for production and benchmark hosts. * * @default 300 */ policyCacheTtlSeconds?: number; /** * Advanced / testing: inject a pre-built composed-policy context instead of * letting `withCheckpoint` construct one from `projectId` + `baseUrl` + * `apiKey`. Mirrors the `adapters` injection philosophy — production omits * this. When set, it takes precedence over `projectId`. */ composedPolicyEnforcer?: ComposedPolicyContext; } //#endregion //#region src/engine/orchestrator/render-engine.d.ts /** Per-request host settings for {@link makeRenderDecision}'s renderer. */ type RenderDecisionOptions = EngineRenderOptions; /** The renderer the host adapters call. */ type RenderDecision = (result: VerifyResult, options?: RenderDecisionOptions) => RenderedResponse; //#endregion //#region src/engine/orchestrator/index.d.ts /** Render a `VerifyResult` as the kya-os/http answer, in the bundler-target engine. */ declare const renderDecisionAsResponse: RenderDecision; //#endregion //#region src/pipeline/pipeline.d.ts /** The engine an adapter runs: one `./orchestrator` build of this package. */ interface PipelineEngine { verifyRequest: (req: IncomingHttpLike, opts: VerifyRequestOpts & VendorKeyEdgeOptions) => Promise; renderDecisionAsResponse: typeof renderDecisionAsResponse; } /** The Cedar compiler a composed-policy context uses. */ type PolicyCompile = MakeComposedPolicyContextOptions['compile']; /** What an adapter supplies once, when it builds its middleware. */ interface PipelineHost { /** The SDK the detection reporter names, so the dashboard can version-gate it. */ sdk: { name: string; version: string; runtime: 'node' | 'edge'; }; /** * Loads the engine. A rejection is answered by the request that asked (the * adapter's 503), and the next request tries again. */ loadEngine: () => Promise; /** * The Cedar compiler for the project's composed policy. Called once, only * when the pipeline builds the composed-policy context itself (`projectId` * set, no `composedPolicyEnforcer` injected). */ policyCompiler: (config: Config) => PolicyCompile; /** Host-specific setup, run once after the configuration is checked; it may throw. */ start?: (config: Config) => void; /** * A persistent host's resolution engine (the orchestrator entry's * `resolutionEngine`). With it and a trusted-roots source, the engine's * DID document and status-list needs are answered from a background * warmer and the request path never fetches; without it they are fetched * inline. */ warmerEngine?: ResolutionWarmerEngine; } /** A request's headers, as the framework holds them. */ type CheckpointRequestHeaders = Headers | Record; /** What an adapter supplies per request. */ interface PipelineRequest { /** The framework's request, handed to `onResult` and `resolveDelegationChallenge`. */ request: Req; /** The request in the engine's shape. Called once, after the engine has loaded. */ translate: () => IncomingHttpLike | Promise; headers: CheckpointRequestHeaders; /** The full request path without its query: what verification saw. */ path: string; /** The client address the adapter's `clientIpPolicy` vouches for, if any. */ clientIp: () => string | null | undefined; /** The dashboard report's request context. Called only when reporting. */ reportContext: () => ReporterContext; /** Registers work that outlives the response (Edge, Workers). */ waitUntil?: (promise: Promise) => void; /** Called with the browser-posture outcome as soon as it is known, before `onResult`. */ onPostureOutcome?: (outcome: PostureHandlerView) => void; } /** What the pipeline hands back for the adapter to send. */ interface PipelineOutcome { rendered: ReturnType; result: VerifyResult; } /** One request through the pipeline. Throws on any fault; the adapter answers 503. */ type CheckpointPipeline = (input: PipelineRequest) => Promise; /** * Build the pipeline for one `withCheckpoint` call. Throws on an invalid * configuration. */ export declare function makeCheckpointPipeline>(config: Config, host: PipelineHost): CheckpointPipeline; /** * Log a pipeline fault the adapter is about to answer 503. An engine that * cannot load is an outage the operator has to see, so it is logged whatever * `debug` says; anything else only with `debug`. */ export declare function logPipelineFailure(error: unknown, debug: boolean | undefined): void; //#endregion export type { CheckpointHostConfig, CheckpointPipeline, CheckpointRequestHeaders, PipelineEngine, PipelineHost, PipelineOutcome, PipelineRequest, PolicyCompile }; //# sourceMappingURL=pipeline.d.mts.map