@dawans/promptshield
Version:
Secure your LLM stack with enterprise-grade RulePacks for AI safety scanning
67 lines (66 loc) • 1.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScanResult = void 0;
/**
* Represents the result of a scan operation
*/
class ScanResult {
constructor(violations, metrics, timestamp = new Date()) {
this.violations = violations;
this.metrics = metrics;
this.timestamp = timestamp;
}
/**
* Gets violations filtered by severity
*/
getViolationsBySeverity(severity) {
return this.violations.filter((v) => severity.includes(v.severity));
}
/**
* Gets violations filtered by category
*/
getViolationsByCategory(categories) {
if (categories.length === 0)
return this.violations;
return this.violations.filter((v) => categories.includes(v.category));
}
/**
* Gets total violation count
*/
getTotalViolations() {
return this.violations.length;
}
/**
* Gets violation count by severity
*/
getViolationCountBySeverity() {
const counts = { low: 0, medium: 0, high: 0, critical: 0 };
this.violations.forEach((v) => {
if (v.severity in counts) {
counts[v.severity]++;
}
});
return counts;
}
/**
* Checks if scan failed based on severity threshold
*/
shouldFail(failOnSeverity) {
if (!failOnSeverity)
return false;
return this.violations.some((v) => v.severity === failOnSeverity);
}
/**
* Creates an empty scan result
*/
static empty() {
return new ScanResult([], {
objectsScanned: 0,
processingTime: 0,
memoryUsage: 0,
rulesApplied: 0,
streamingUsed: false,
});
}
}
exports.ScanResult = ScanResult;