repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

extensions/leaks/src/types.ts

Raw
export type CustomRegexInput = {
	pattern?: unknown;
	label?: unknown;
	[key: string]: unknown;
};

export type LeaksSettings = {
	regex: CustomRegexInput[];
};

export type WarningRecord = {
	code: string;
	message: string;
	severity: "warning" | "error";
};

export type SpanLabel = {
	tag: string;
	priority: number;
	source: "dotenv" | "env" | "structure" | "custom" | "builtin" | "generic";
};

export type SecretSpan = {
	start: number;
	end: number;
	value: string;
	labels: SpanLabel[];
	kind:
		| "structure"
		| "exact"
		| "custom"
		| "builtin"
		| "generic"
		| "private-key"
		| "jwt";
	confidence: number;
	wholeSpan: boolean;
};

export type RedactionOrigin = "context" | "provider" | "diagnostic";

export type RedactionRecord = {
	path: string;
	labels: string[];
	placeholders: string[];
};

export type AmbiguityRecord = {
	path: string;
	family: string;
};

export type RedactionResult = {
	text: string;
	count: number;
	labels: string[];
	placeholders: string[];
	redactions: RedactionRecord[];
	ambiguities: AmbiguityRecord[];
};

export type DeepRedactionResult<T = unknown> = {
	value: T;
	changed: boolean;
	count: number;
	redactions: RedactionRecord[];
	ambiguities: AmbiguityRecord[];
};

export type EngineStats = {
	active: true;
	builtInRuleCount: number;
	customRegexCount: number;
	regexWarningCount: number;
	warningCount: number;
	invalidRegexCount: number;
	learnedCount: number;
	mappingCount: number;
	persistenceEnabled: boolean;
	lastProviderRedactionCount: number;
	totalProviderRedactionCount: number;
	totalProtectedRedactionCount: number;
	lastProviderAmbiguityCount: number;
	recentLabels: string[];
	latestTags: string[];
	warnings: WarningRecord[];
};

export type Detector = (text: string) => SecretSpan[];