28 lines
1.2 KiB
JavaScript
28 lines
1.2 KiB
JavaScript
export function publicBillingSettings(value = {}) {
|
|
// Safe for the PUBLIC customer portal. Never return stripe_sk or other keys.
|
|
return Object.fromEntries(['iban', 'bank_name', 'account_holder', 'observations', 'stripe_enabled']
|
|
.filter(k => Object.hasOwn(value, k)).map(k => [k, value[k]]));
|
|
}
|
|
|
|
const secretKey = /password|secret|token|api[_-]?key|stripe[_-]?[sp]k|signature|pdf_base64|contract_pdf_url|pdf_raw_data/i;
|
|
export function redact(value) {
|
|
if (Array.isArray(value)) return value.map(redact);
|
|
if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value)
|
|
.filter(([key]) => !secretKey.test(key)).map(([key, val]) => [key, redact(val)]));
|
|
return value;
|
|
}
|
|
|
|
export function normalizeOrigin(value) {
|
|
const url = new URL(value);
|
|
if (url.protocol !== 'https:' || url.username || url.password || url.pathname !== '/' || url.search || url.hash)
|
|
throw new Error('INTEGRA_MCP_PUBLIC_ORIGIN debe ser un origen HTTPS sin ruta, por ejemplo https://tu-backend.es');
|
|
return url.origin;
|
|
}
|
|
|
|
export function safeRedirect(value) {
|
|
try {
|
|
const u = new URL(value);
|
|
return !u.username && !u.password && !u.hash && u.protocol === 'https:';
|
|
} catch { return false; }
|
|
}
|