"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.redactConnectionString = exports.shouldRedactCommand = void 0;
exports.redact = redact;
const regexes_1 = require("./regexes");
const utils_1 = require("./utils");
const secrets_1 = require("./secrets");
function redact(message, secrets = undefined) {
    if ((0, utils_1.isPlainObject)(message)) {
        const newMessage = Object.fromEntries(Object.entries(message).map(([key, value]) => [
            key,
            redact(value, secrets),
        ]));
        return Object.setPrototypeOf(newMessage, Object.getPrototypeOf(message));
    }
    if (Array.isArray(message)) {
        return message.map((msg) => redact(msg, secrets));
    }
    if (typeof message !== 'string') {
        return message;
    }
    if (secrets) {
        message = (0, secrets_1.redactSecretsOnString)(message, secrets);
    }
    for (const [regex, replacement] of regexes_1.regexes) {
        message = message.replace(regex, replacement);
    }
    return message;
}
var should_redact_command_1 = require("./should-redact-command");
Object.defineProperty(exports, "shouldRedactCommand", { enumerable: true, get: function () { return should_redact_command_1.shouldRedactCommand; } });
var redact_connection_string_1 = require("./redact-connection-string");
Object.defineProperty(exports, "redactConnectionString", { enumerable: true, get: function () { return redact_connection_string_1.redactConnectionString; } });
exports.default = redact;
//# sourceMappingURL=index.js.map