Core — veilgate
The Veilgate core engine — the redact() and rehydrate() API, the RedactResult shape, the reversible Vault, and the lower-level chunker, regex and policy exports.
veilgate is the core engine: chunker, regex fast-path, Jev adapter + mock,
priority-ordered policy engine, reversible vault, and the redact() / rehydrate() entry
points. 48 tests.
npm install veilgateredact(payload, options?)
type Payload = string | Record<string, unknown> | ChatMessage[];
interface RedactOptions {
policy?: Policy; // default: DEFAULT_POLICY ("balanced")
mode?: "mock" | "live"; // default: "mock"
format?: "text" | "json" | "chat"; // default: inferred from the payload
jev?: Partial<JevConfig>; // model, baseUrl, apiKey, budgets, pricing
client?: JevClient; // inject a live client or a test double
}Returns a Promise<RedactResult>:
interface RedactResult {
output: Payload; // same shape as the input, redactable spans replaced
decisions: Decision[]; // every decision, in pipeline order (regex first, then Jev)
vault: Vault; // reversible placeholder → original map
blocked: boolean; // true if any span produced a BLOCK — do not forward
stats: RedactStats; // spans, regexRedactions, jevSpans, jevCalls, actions{}
}import { redact } from "veilgate";
const r = await redact("deploy key AKIAIOSFODNN7EXAMPLE now");
r.output; // "deploy key [REDACTED_AWS_KEY_1] now"
r.stats.regexRedactions; // 1 (stripped locally, zero Jev cost)rehydrate(text, vault)
Replaces every stored placeholder with its original value, resolving nested placeholders (looping until stable), so round-trips are exact.
import { redact, rehydrate } from "veilgate";
const input = "email Alice Johnson, ssn 123-45-6789";
const r = await redact(input);
rehydrate(r.output, r.vault) === input; // trueThe vault
import { Vault } from "veilgate";
const v = new Vault();
const p = v.store("Alice", "PII_NAME"); // "[REDACTED_PII_NAME_1]"
v.get(p); // "Alice"
v.entries(); // [["[REDACTED_PII_NAME_1]", "Alice"]]Placeholders are typed and per-type incrementing: [REDACTED_<TYPE>_<n>].
Lower-level exports
For building on the pipeline directly:
| Export | Purpose |
|---|---|
chunk, inferFormat |
Split a payload into spans; detect its format |
scanText, luhnValid |
Run the regex fast-path; Luhn card validation |
evaluateSpans, DEFAULT_JEV_CONFIG |
The Jev adapter + its default config |
evaluate |
The policy engine (span detectors → decision) |
DEFAULT_POLICY, ACTION_PRIORITY |
The built-in balanced policy; action ordering |
estimateTokens, batchSpans |
Token estimation and batching for Jev calls |
VERSION |
The package version string |
DEFAULT_JEV_CONFIG:
{
model: "jev-1.13.0",
baseUrl: "https://api.typesafe.ai",
maxTokensPerCall: 6000,
inputPricePerMTok: 0.042,
}To change what gets redacted and how, pass a policy. See The policy model
and the ready-made presets in veilgate-policy.