2021-11-08 15:52:42 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { curry } = require('lodash/fp');
|
|
|
|
|
2022-12-08 17:17:11 +01:00
|
|
|
const { pipeAsync } = require('../async');
|
2021-11-08 15:52:42 +01:00
|
|
|
const traverseEntity = require('../traverse-entity');
|
|
|
|
|
|
|
|
const { removePassword, removePrivate } = require('./visitors');
|
|
|
|
|
|
|
|
const sanitizePasswords = curry((schema, entity) => {
|
|
|
|
return traverseEntity(removePassword, { schema }, entity);
|
|
|
|
});
|
|
|
|
|
|
|
|
const sanitizePrivates = curry((schema, entity) => {
|
|
|
|
return traverseEntity(removePrivate, { schema }, entity);
|
|
|
|
});
|
|
|
|
|
|
|
|
const defaultSanitizeOutput = curry((schema, entity) => {
|
|
|
|
return pipeAsync(sanitizePrivates(schema), sanitizePasswords(schema))(entity);
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
sanitizePasswords,
|
|
|
|
sanitizePrivates,
|
|
|
|
defaultSanitizeOutput,
|
|
|
|
};
|