@airwallex/node-sdk
Version:
Airwallex Node.js SDK
36 lines • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.maskSensitiveData = maskSensitiveData;
const DEFAULT_SENSITIVE_FIELDS = ['apiKey', 'token', 'x-api-key', 'authorization'];
function maskSensitiveData(data, options = {}) {
const { maskChar = '*', sensitiveFields = DEFAULT_SENSITIVE_FIELDS, maskLength = 6 } = options;
const mask = maskChar.repeat(maskLength);
function maskValue(value) {
if (value === null || value === undefined) {
return value;
}
return mask;
}
function processObject(input) {
if (input === null || typeof input !== 'object') {
return input;
}
if (Array.isArray(input)) {
return input.map((item) => processObject(item));
}
return Object.entries(input).reduce((acc, [key, value]) => {
if (sensitiveFields.includes(key)) {
acc[key] = maskValue(value);
}
else if (typeof value === 'object' && value !== null) {
acc[key] = processObject(value);
}
else {
acc[key] = value;
}
return acc;
}, {});
}
return processObject(data);
}
//# sourceMappingURL=maskHelper.js.map