@shopana/ga
Version:
Type-safe Google Analytics 4 (GA4) tracking library for React and Next.js with ecommerce support, event batching, and SSR compatibility
46 lines • 1.41 kB
JavaScript
const SENSITIVE_KEYS = /password|token|secret|card|ssn|bearer|api[_-]?key|auth|credential|private[_-]?key|access[_-]?token|refresh[_-]?token|session[_-]?id|authorization/i;
export function sanitizeParameters(input = {}) {
const result = {};
for (const [key, value] of Object.entries(input)) {
if (SENSITIVE_KEYS.test(key)) {
continue;
}
const sanitized = sanitizeValue(value);
if (typeof sanitized !== 'undefined') {
result[key] = sanitized;
}
}
return result;
}
function sanitizeValue(value) {
if (value instanceof Date) {
return value.toISOString();
}
if (Array.isArray(value)) {
const cleaned = value
.map(sanitizeValue)
.filter((item) => typeof item !== 'undefined');
return cleaned;
}
if (typeof value === 'number') {
return Number.isFinite(value) ? value : undefined;
}
if (isPrimitive(value)) {
return value;
}
return undefined;
}
function isPrimitive(value) {
return (value === null ||
typeof value === 'string' ||
typeof value === 'boolean' ||
typeof value === 'number' ||
typeof value === 'undefined');
}
export function normalizeError(error) {
if (error instanceof Error) {
return error;
}
return new Error(String(error));
}
//# sourceMappingURL=sanitize.js.map