'use strict';
/**
- * Here are some sanitizers to replace data fields before logging.
- * Well, really, this just documents the expected format.
+ * Sanitizers replace data fields before logging.
+ * None are bundled, but here is an example of one.
*/
/**
- * template for sanitizers
- * @param {Object} data
- * @param {Boolean} sanitize
- * @returns {Boolean}
+ * Example sanitizer function.
+ * Sanitizers are called initially with `sanitize` false, to only determine
+ * whether the data object will be changed. If so, the sanitizer is then
+ * called again with `sanitize` true, but provided with a clone of the
+ * original data to update, to avoid leaking any applied changes back to the
+ * application.
+ * @param {object} data
+ * @param {boolean} sanitize
+ * @returns {boolean} whether sanitizer is applicable to data
*/
/* istanbul ignore next */
+/**
+ *
+ * @param {object} data data object to mogrify
+ * @param {boolean} sanitize mogrify if truue
+ * @returns {boolean} whether data would be mogrified
+ */
function _sanitizer(data, sanitize = true) {
let unclean = false;
- if (undefined) { // eslint-disable-line no-constant-condition
+ const sensitiveFieldLength = data?.sensitiveField?.length;
+ if (sensitiveFieldLength) {
unclean = true;
- }
- if (unclean && sanitize) {
- data;
+
+ if (sanitize) {
+ data.sensitiveField = '*'.repeat(sensitiveFieldLength);
+ }
}
return unclean;
}
-module.exports = {};
\ No newline at end of file
+module.exports = {};