UNPKG

@splitsoftware/splitio-commons

Version:
38 lines (37 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sanitizeValue = void 0; var sanitize_1 = require("./sanitize"); var constants_1 = require("../../logger/constants"); function parseValue(log, key, attributeName, attributes) { var value = undefined; if (attributeName) { if (attributes) { value = attributes[attributeName]; log.debug(constants_1.ENGINE_VALUE, [attributeName, value]); } else { log.warn(constants_1.ENGINE_VALUE_NO_ATTRIBUTES, [attributeName]); } } else { value = key; } return value; } /** * Defines value to be matched (key / attribute). */ function sanitizeValue(log, key, matcherDto, attributes) { var attributeName = matcherDto.attribute; var valueToMatch = parseValue(log, key, attributeName, attributes); var sanitizedValue = (0, sanitize_1.sanitize)(log, matcherDto.type, valueToMatch, matcherDto.dataType, attributes); if (sanitizedValue !== undefined) { return sanitizedValue; } else { log.warn(constants_1.ENGINE_VALUE_INVALID, [valueToMatch + (attributeName ? ' for attribute ' + attributeName : '')]); return; } } exports.sanitizeValue = sanitizeValue;