Files
Rental-operations-platform/src/lib/demo/redaction.ts
T
2026-06-25 20:08:39 -04:00

33 lines
867 B
TypeScript

const sensitiveKeys = new Set([
'fullname',
'name',
'workemail',
'email',
'company',
'market',
'message',
'phone',
'fieldvalue',
'serverresponse',
]);
export function redactSensitive(value: unknown): unknown {
if (Array.isArray(value)) return value.map(redactSensitive);
if (!value || typeof value !== 'object') return value;
return Object.fromEntries(
Object.entries(value).map(([key, child]) => [
key,
sensitiveKeys.has(key.toLowerCase()) ? '[REDACTED]' : redactSensitive(child),
]),
);
}
export function containsSensitiveKey(value: unknown): boolean {
if (Array.isArray(value)) return value.some(containsSensitiveKey);
if (!value || typeof value !== 'object') return false;
return Object.entries(value).some(
([key, child]) => sensitiveKeys.has(key.toLowerCase()) || containsSensitiveKey(child),
);
}