// src/trace/redact.ts
var DEFAULT_REDACTION_RULES = [
  { id: "email", pattern: /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi },
  { id: "ssn", pattern: /\b\d{3}-\d{2}-\d{4}\b/g },
  { id: "credit-card", pattern: /\b(?:\d[ -]*?){13,16}\b/g },
  { id: "phone-us", pattern: /\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g },
  { id: "ipv4", pattern: /\b(?:\d{1,3}\.){3}\d{1,3}\b/g },
  { id: "aws-access-key", pattern: /\bAKIA[0-9A-Z]{16}\b/g },
  { id: "bearer", pattern: /\bBearer\s+[A-Za-z0-9._~+/=-]{10,}/gi },
  { id: "sk-key", pattern: /\bsk-[A-Za-z0-9_-]{10,}\b/g },
  {
    id: "private-key-block",
    pattern: /-----BEGIN (?:RSA |EC |OPENSSH |DSA )?PRIVATE KEY-----[\s\S]*?-----END[^-]*-----/g
  }
];
var REDACTION_VERSION = "1.0.0";
function redactString(input, rules = DEFAULT_REDACTION_RULES) {
  const byRule = {};
  let redactionCount = 0;
  let output = input;
  for (const rule of rules) {
    let hits = 0;
    output = output.replace(rule.pattern, () => {
      hits++;
      return rule.replacement ?? `[redacted:${rule.id}]`;
    });
    if (hits > 0) {
      byRule[rule.id] = hits;
      redactionCount += hits;
    }
  }
  return { output, report: { redactionCount, byRule } };
}
function redactValue(value, rules = DEFAULT_REDACTION_RULES, report = { redactionCount: 0, byRule: {} }) {
  if (typeof value === "string") {
    const { output, report: r } = redactString(value, rules);
    report.redactionCount += r.redactionCount;
    for (const [k, v] of Object.entries(r.byRule)) {
      report.byRule[k] = (report.byRule[k] ?? 0) + v;
    }
    return { value: output, report };
  }
  if (Array.isArray(value)) {
    return {
      value: value.map((v) => redactValue(v, rules, report).value),
      report
    };
  }
  if (value !== null && typeof value === "object") {
    const next = {};
    for (const [k, v] of Object.entries(value)) {
      next[k] = redactValue(v, rules, report).value;
    }
    return { value: next, report };
  }
  return { value, report };
}

export {
  DEFAULT_REDACTION_RULES,
  REDACTION_VERSION,
  redactString,
  redactValue
};
//# sourceMappingURL=chunk-GGE4NNQT.js.map