import { fileURLToPath as __fileURLToPath } from 'url';
import { dirname as __pathDirname } from 'path';
const __filename = __fileURLToPath(import.meta.url);
const __dirname = __pathDirname(__filename);
import { SENSITIVE_PATTERNS } from "../security/input-sanitizer.js";
const PRIVACY_PATTERNS = {
  // Permissive: Only critical secrets
  permissive: [],
  // Standard: Secrets + PII basics
  standard: [
    // Email addresses
    /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
    // Phone numbers (various formats)
    /\b(?:\+?1[-.\s]?)?(?:\(?\d{3}\)?[-.\s]?)?\d{3}[-.\s]?\d{4}\b/g,
    // SSN-like patterns
    /\b\d{3}[-.\s]?\d{2}[-.\s]?\d{4}\b/g,
    // IP addresses (v4)
    /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/g
  ],
  // Strict: All standard + additional PII
  strict: [
    // Credit card-like numbers (13-19 digits, optionally separated)
    /\b(?:\d{4}[-.\s]?){3,4}\d{1,4}\b/g,
    // Date of birth patterns (various formats)
    /\b(?:0?[1-9]|1[0-2])[-/](?:0?[1-9]|[12][0-9]|3[01])[-/](?:19|20)\d{2}\b/g,
    // AWS-style keys
    /\b(?:AKIA|ABIA|ACCA|ASIA)[A-Z0-9]{16}\b/g,
    // Private key markers
    /-----BEGIN (?:RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----/g,
    // JWT tokens
    /\beyJ[A-Za-z0-9_-]*\.eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*/g,
    // URLs with credentials
    /(?:https?|ftp):\/\/[^\s:@]+:[^\s:@]+@[^\s]+/gi,
    // MAC addresses
    /\b(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}\b/g,
    // UUID-like patterns that might be sensitive
    /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi
  ]
};
class PrivacyFilter {
  config;
  patterns;
  constructor(config) {
    this.config = config;
    this.patterns = this.buildPatternList();
  }
  /**
   * Build the complete list of patterns based on privacy mode
   */
  buildPatternList() {
    const patterns = [];
    patterns.push(...SENSITIVE_PATTERNS);
    switch (this.config.mode) {
      case "strict":
        patterns.push(...PRIVACY_PATTERNS.strict);
        patterns.push(...PRIVACY_PATTERNS.standard);
        break;
      case "standard":
        patterns.push(...PRIVACY_PATTERNS.standard);
        break;
      case "permissive":
        break;
    }
    return patterns;
  }
  /**
   * Filter sensitive patterns from content
   * @param content The content to filter
   * @returns Filtered content and count of redactions
   */
  filter(content) {
    if (!content) {
      return { filtered: "", redactedCount: 0 };
    }
    let filtered = content;
    let redactedCount = 0;
    for (const pattern of this.patterns) {
      pattern.lastIndex = 0;
      const matches = content.match(pattern);
      if (matches) {
        redactedCount += matches.length;
      }
      filtered = filtered.replace(pattern, "[REDACTED]");
    }
    return { filtered, redactedCount };
  }
  /**
   * Check if content contains sensitive data without modifying it
   * @param content The content to check
   * @returns True if sensitive data is detected
   */
  containsSensitive(content) {
    if (!content) return false;
    for (const pattern of this.patterns) {
      pattern.lastIndex = 0;
      if (pattern.test(content)) {
        return true;
      }
    }
    return false;
  }
  /**
   * Get the current privacy mode
   */
  getMode() {
    return this.config.mode;
  }
  /**
   * Update the privacy mode and rebuild patterns
   */
  setMode(mode) {
    this.config.mode = mode;
    this.patterns = this.buildPatternList();
  }
  /**
   * Get the count of active patterns
   */
  getPatternCount() {
    return this.patterns.length;
  }
}
function createPrivacyFilter(mode = "standard") {
  return new PrivacyFilter({ mode });
}
export {
  PrivacyFilter,
  createPrivacyFilter
};
//# sourceMappingURL=privacy-filter.js.map
