@devcycle/bucketing
Advanced tools
Comparing version 1.0.54 to 1.0.55
{ | ||
"name": "@devcycle/bucketing", | ||
"version": "1.0.54", | ||
"version": "1.0.55", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@devcycle/bucketing-test-data": "^1.0.43" | ||
"@devcycle/bucketing-test-data": "^1.0.44" | ||
}, | ||
@@ -11,3 +11,3 @@ "main": "./src/index.js", | ||
"dependencies": { | ||
"@devcycle/types": "1.0.55", | ||
"@devcycle/types": "1.0.56", | ||
"class-transformer": "0.5.1", | ||
@@ -14,0 +14,0 @@ "@nestjs/class-validator": "^0.13.4", |
'use strict'; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -18,15 +7,15 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.generateBucketedConfig = exports.generateKnownVariableKeys = exports.getSegmentedFeatureDataFromConfig = exports.bucketForSegmentedFeature = exports.doesUserPassRollout = exports.getCurrentRolloutPercentage = exports.decideTargetVariation = exports.generateBoundedHash = exports.generateBoundedHashes = void 0; | ||
var orderBy_1 = __importDefault(require("lodash/orderBy")); | ||
var pick_1 = __importDefault(require("lodash/pick")); | ||
var last_1 = __importDefault(require("lodash/last")); | ||
var first_1 = __importDefault(require("lodash/first")); | ||
var murmurhash_1 = __importDefault(require("murmurhash")); | ||
var segmentation_1 = require("./segmentation"); | ||
const orderBy_1 = __importDefault(require("lodash/orderBy")); | ||
const pick_1 = __importDefault(require("lodash/pick")); | ||
const last_1 = __importDefault(require("lodash/last")); | ||
const first_1 = __importDefault(require("lodash/first")); | ||
const murmurhash_1 = __importDefault(require("murmurhash")); | ||
const segmentation_1 = require("./segmentation"); | ||
// Max value of an unsigned 32-bit integer, which is what murmurhash returns | ||
var MAX_HASH_VALUE = 4294967295; | ||
var baseSeed = 1; | ||
var generateBoundedHashes = function (user_id, target_id) { | ||
const MAX_HASH_VALUE = 4294967295; | ||
const baseSeed = 1; | ||
const generateBoundedHashes = (user_id, target_id) => { | ||
// The seed provided to murmurhash must be a number | ||
// So we first hash the target_id with a constant seed | ||
var targetHash = murmurhash_1.default.v3(target_id, baseSeed); | ||
const targetHash = murmurhash_1.default.v3(target_id, baseSeed); | ||
return { | ||
@@ -38,4 +27,4 @@ rolloutHash: (0, exports.generateBoundedHash)(user_id + '_rollout', targetHash), | ||
exports.generateBoundedHashes = generateBoundedHashes; | ||
var generateBoundedHash = function (input, hashSeed) { | ||
var hash = murmurhash_1.default.v3(input, hashSeed); | ||
const generateBoundedHash = (input, hashSeed) => { | ||
const hash = murmurhash_1.default.v3(input, hashSeed); | ||
return hash / MAX_HASH_VALUE; | ||
@@ -50,9 +39,7 @@ }; | ||
*/ | ||
var decideTargetVariation = function (_a) { | ||
var target = _a.target, boundedHash = _a.boundedHash; | ||
var variations = (0, orderBy_1.default)(target.distribution, '_variation', ['desc']); | ||
var distributionIndex = 0; | ||
var previousDistributionIndex = 0; | ||
for (var _i = 0, variations_1 = variations; _i < variations_1.length; _i++) { | ||
var variation = variations_1[_i]; | ||
const decideTargetVariation = ({ target, boundedHash }) => { | ||
const variations = (0, orderBy_1.default)(target.distribution, '_variation', ['desc']); | ||
let distributionIndex = 0; | ||
const previousDistributionIndex = 0; | ||
for (const variation of variations) { | ||
distributionIndex += variation.percentage; | ||
@@ -66,6 +53,6 @@ if (boundedHash >= previousDistributionIndex && boundedHash < distributionIndex) { | ||
exports.decideTargetVariation = decideTargetVariation; | ||
var getCurrentRolloutPercentage = function (rollout, currentDate) { | ||
const getCurrentRolloutPercentage = (rollout, currentDate) => { | ||
var _a, _b; | ||
var start = rollout.startPercentage; | ||
var startDate = rollout.startDate; | ||
const start = rollout.startPercentage; | ||
const startDate = rollout.startDate; | ||
if (rollout.type === 'schedule') { | ||
@@ -77,5 +64,5 @@ return currentDate >= startDate ? 1 : 0; | ||
} | ||
var _currentStage = (0, last_1.default)((_a = rollout.stages) === null || _a === void 0 ? void 0 : _a.filter(function (stage) { return stage.date <= currentDate; })); | ||
var nextStage = (0, first_1.default)((_b = rollout.stages) === null || _b === void 0 ? void 0 : _b.filter(function (stage) { return stage.date > currentDate; })); | ||
var currentStage = _currentStage || (startDate < currentDate ? { | ||
const _currentStage = (0, last_1.default)((_a = rollout.stages) === null || _a === void 0 ? void 0 : _a.filter((stage) => stage.date <= currentDate)); | ||
const nextStage = (0, first_1.default)((_b = rollout.stages) === null || _b === void 0 ? void 0 : _b.filter((stage) => stage.date > currentDate)); | ||
const currentStage = _currentStage || (startDate < currentDate ? { | ||
percentage: start, | ||
@@ -90,3 +77,3 @@ date: startDate | ||
} | ||
var currentDatePercentage = (currentDate.getTime() - currentStage.date.getTime()) / | ||
const currentDatePercentage = (currentDate.getTime() - currentStage.date.getTime()) / | ||
(nextStage.date.getTime() - currentStage.date.getTime()); | ||
@@ -100,24 +87,21 @@ if (currentDatePercentage === 0) { | ||
exports.getCurrentRolloutPercentage = getCurrentRolloutPercentage; | ||
var doesUserPassRollout = function (_a) { | ||
var rollout = _a.rollout, boundedHash = _a.boundedHash; | ||
const doesUserPassRollout = ({ rollout, boundedHash }) => { | ||
if (!rollout) { | ||
return true; | ||
} | ||
var rolloutPercentage = (0, exports.getCurrentRolloutPercentage)(rollout, new Date()); | ||
const rolloutPercentage = (0, exports.getCurrentRolloutPercentage)(rollout, new Date()); | ||
return !!rolloutPercentage && (boundedHash <= rolloutPercentage); | ||
}; | ||
exports.doesUserPassRollout = doesUserPassRollout; | ||
var bucketForSegmentedFeature = function (_a) { | ||
var boundedHash = _a.boundedHash, target = _a.target; | ||
return (0, exports.decideTargetVariation)({ target: target, boundedHash: boundedHash }); | ||
const bucketForSegmentedFeature = ({ boundedHash, target }) => { | ||
return (0, exports.decideTargetVariation)({ target, boundedHash }); | ||
}; | ||
exports.bucketForSegmentedFeature = bucketForSegmentedFeature; | ||
var getSegmentedFeatureDataFromConfig = function (_a) { | ||
var config = _a.config, user = _a.user; | ||
var initialValue = []; | ||
return config.features.reduce(function (accumulator, feature) { | ||
const getSegmentedFeatureDataFromConfig = ({ config, user }) => { | ||
const initialValue = []; | ||
return config.features.reduce((accumulator, feature) => { | ||
var _a, _b, _c; | ||
// Returns the first target for which the user passes segmentation | ||
var isOptInEnabled = ((_a = feature.settings) === null || _a === void 0 ? void 0 : _a['optInEnabled']) && ((_c = (_b = config.project.settings) === null || _b === void 0 ? void 0 : _b['optIn']) === null || _c === void 0 ? void 0 : _c['enabled']); | ||
var segmentedFeatureTarget = feature.configuration.targets.find(function (target) { | ||
const isOptInEnabled = ((_a = feature.settings) === null || _a === void 0 ? void 0 : _a['optInEnabled']) && ((_c = (_b = config.project.settings) === null || _b === void 0 ? void 0 : _b['optIn']) === null || _c === void 0 ? void 0 : _c['enabled']); | ||
const segmentedFeatureTarget = feature.configuration.targets.find((target) => { | ||
return (0, segmentation_1.evaluateOperator)({ | ||
@@ -132,3 +116,3 @@ operator: target._audience.filters, | ||
accumulator.push({ | ||
feature: feature, | ||
feature, | ||
target: segmentedFeatureTarget | ||
@@ -141,7 +125,5 @@ }); | ||
exports.getSegmentedFeatureDataFromConfig = getSegmentedFeatureDataFromConfig; | ||
var generateKnownVariableKeys = function (_a) { | ||
var variableHashes = _a.variableHashes, variableMap = _a.variableMap; | ||
var knownVariableKeys = []; | ||
for (var _i = 0, _b = Object.entries(variableHashes); _i < _b.length; _i++) { | ||
var _c = _b[_i], key = _c[0], hash = _c[1]; | ||
const generateKnownVariableKeys = ({ variableHashes, variableMap }) => { | ||
const knownVariableKeys = []; | ||
for (const [key, hash] of Object.entries(variableHashes)) { | ||
if (!(variableMap === null || variableMap === void 0 ? void 0 : variableMap[key])) { | ||
@@ -154,37 +136,37 @@ knownVariableKeys.push(hash); | ||
exports.generateKnownVariableKeys = generateKnownVariableKeys; | ||
var generateBucketedConfig = function (_a) { | ||
var config = _a.config, user = _a.user; | ||
var variableMap = {}; | ||
var featureKeyMap = {}; | ||
var featureVariationMap = {}; | ||
var segmentedFeatures = (0, exports.getSegmentedFeatureDataFromConfig)({ config: config, user: user }); | ||
segmentedFeatures.forEach(function (_a) { | ||
var feature = _a.feature, target = _a.target; | ||
var _id = feature._id, key = feature.key, type = feature.type, variations = feature.variations, settings = feature.settings; | ||
var _b = (0, exports.generateBoundedHashes)(user.user_id, target._id), rolloutHash = _b.rolloutHash, bucketingHash = _b.bucketingHash; | ||
const generateBucketedConfig = ({ config, user }) => { | ||
const variableMap = {}; | ||
const featureKeyMap = {}; | ||
const featureVariationMap = {}; | ||
const segmentedFeatures = (0, exports.getSegmentedFeatureDataFromConfig)({ config, user }); | ||
segmentedFeatures.forEach(({ feature, target }) => { | ||
const { _id, key, type, variations, settings } = feature; | ||
const { rolloutHash, bucketingHash } = (0, exports.generateBoundedHashes)(user.user_id, target._id); | ||
if (target.rollout && !(0, exports.doesUserPassRollout)({ boundedHash: rolloutHash, rollout: target.rollout })) { | ||
return; | ||
} | ||
var variation_id = (0, exports.bucketForSegmentedFeature)({ boundedHash: bucketingHash, target: target }); | ||
var variation = variations.find(function (v) { return v._id === variation_id; }); | ||
const variation_id = (0, exports.bucketForSegmentedFeature)({ boundedHash: bucketingHash, target }); | ||
const variation = variations.find((v) => v._id === variation_id); | ||
if (!variation) { | ||
throw new Error("Config missing variation: ".concat(variation_id)); | ||
throw new Error(`Config missing variation: ${variation_id}`); | ||
} | ||
featureKeyMap[key] = { | ||
_id: _id, | ||
key: key, | ||
type: type, | ||
_id, | ||
key, | ||
type, | ||
_variation: variation_id, | ||
variationName: variation.name, | ||
variationKey: variation.key, | ||
settings: settings | ||
settings | ||
}; | ||
featureVariationMap[_id] = variation_id; | ||
variation.variables.forEach(function (_a) { | ||
var _var = _a._var, value = _a.value; | ||
var variable = config.variables.find(function (v) { return v._id === _var; }); | ||
variation.variables.forEach(({ _var, value }) => { | ||
const variable = config.variables.find((v) => v._id === _var); | ||
if (!variable) { | ||
throw new Error("Config missing variable: ".concat(_var)); | ||
throw new Error(`Config missing variable: ${_var}`); | ||
} | ||
variableMap[variable.key] = __assign(__assign({}, variable), { value: value }); | ||
variableMap[variable.key] = { | ||
...variable, | ||
value, | ||
}; | ||
}); | ||
@@ -196,3 +178,3 @@ }); | ||
features: featureKeyMap, | ||
featureVariationMap: featureVariationMap, | ||
featureVariationMap, | ||
// Return empty object for now, until we switch to WASM bucketing logic | ||
@@ -202,3 +184,3 @@ variableVariationMap: {}, | ||
variableHashes: config.variableHashes, | ||
variableMap: variableMap | ||
variableMap | ||
}), | ||
@@ -205,0 +187,0 @@ variables: variableMap |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -18,10 +7,10 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.parseUserAgent = exports.getFilterValues = exports.checkCustomData = exports.checkVersionFilters = exports.checkBooleanFilter = exports.checkStringsFilter = exports.checkNumbersFilter = exports.checkNumberFilter = exports.checkVersionFilter = exports.checkVersionValue = exports.convertToSemanticVersion = exports.evaluateOperator = void 0; | ||
var isArray_1 = __importDefault(require("lodash/isArray")); | ||
var isNumber_1 = __importDefault(require("lodash/isNumber")); | ||
var isString_1 = __importDefault(require("lodash/isString")); | ||
var isBoolean_1 = __importDefault(require("lodash/isBoolean")); | ||
var includes_1 = __importDefault(require("lodash/includes")); | ||
var find_1 = __importDefault(require("lodash/find")); | ||
var versionCompare_1 = require("./versionCompare"); | ||
var ua_parser_js_1 = __importDefault(require("ua-parser-js")); | ||
const isArray_1 = __importDefault(require("lodash/isArray")); | ||
const isNumber_1 = __importDefault(require("lodash/isNumber")); | ||
const isString_1 = __importDefault(require("lodash/isString")); | ||
const isBoolean_1 = __importDefault(require("lodash/isBoolean")); | ||
const includes_1 = __importDefault(require("lodash/includes")); | ||
const find_1 = __importDefault(require("lodash/find")); | ||
const versionCompare_1 = require("./versionCompare"); | ||
const ua_parser_js_1 = __importDefault(require("ua-parser-js")); | ||
// TODO add support for OR/XOR as well as recursive filters | ||
@@ -35,15 +24,14 @@ /** | ||
*/ | ||
var evaluateOperator = function (_a) { | ||
var operator = _a.operator, data = _a.data, featureId = _a.featureId, isOptInEnabled = _a.isOptInEnabled; | ||
const evaluateOperator = ({ operator, data, featureId, isOptInEnabled }) => { | ||
if (!operator.filters.length) | ||
return false; | ||
var doesUserPassFilter = function (filter) { | ||
const doesUserPassFilter = (filter) => { | ||
if (filter.type === 'all') | ||
return true; | ||
if (filter.type === 'optIn') { | ||
var optIns = data.optIns; | ||
const optIns = data.optIns; | ||
return isOptInEnabled && !!(optIns === null || optIns === void 0 ? void 0 : optIns[featureId]); | ||
} | ||
if (!filter.subType || !filterFunctionsBySubtype[filter.subType]) { | ||
throw new Error("Invalid filter subType: ".concat(filter.subType)); | ||
throw new Error(`Invalid filter subType: ${filter.subType}`); | ||
} | ||
@@ -60,18 +48,21 @@ return filterFunctionsBySubtype[filter.subType](data, filter); | ||
exports.evaluateOperator = evaluateOperator; | ||
var filterFunctionsBySubtype = { | ||
country: function (data, filter) { return (0, exports.checkStringsFilter)(data.country, filter); }, | ||
email: function (data, filter) { return (0, exports.checkStringsFilter)(data.email, filter); }, | ||
ip: function (data, filter) { return (0, exports.checkStringsFilter)(data.ip, filter); }, | ||
user_id: function (data, filter) { return (0, exports.checkStringsFilter)(data.user_id, filter); }, | ||
appVersion: function (data, filter) { return (0, exports.checkVersionFilters)(data.appVersion, filter); }, | ||
platformVersion: function (data, filter) { return (0, exports.checkVersionFilters)(data.platformVersion, filter); }, | ||
deviceModel: function (data, filter) { return (0, exports.checkStringsFilter)(data.deviceModel, filter); }, | ||
platform: function (data, filter) { return (0, exports.checkStringsFilter)(data.platform, filter); }, | ||
customData: function (data, filter) { | ||
var combinedCustomData = __assign(__assign({}, data.customData), data.privateCustomData); | ||
const filterFunctionsBySubtype = { | ||
country: (data, filter) => (0, exports.checkStringsFilter)(data.country, filter), | ||
email: (data, filter) => (0, exports.checkStringsFilter)(data.email, filter), | ||
ip: (data, filter) => (0, exports.checkStringsFilter)(data.ip, filter), | ||
user_id: (data, filter) => (0, exports.checkStringsFilter)(data.user_id, filter), | ||
appVersion: (data, filter) => (0, exports.checkVersionFilters)(data.appVersion, filter), | ||
platformVersion: (data, filter) => (0, exports.checkVersionFilters)(data.platformVersion, filter), | ||
deviceModel: (data, filter) => (0, exports.checkStringsFilter)(data.deviceModel, filter), | ||
platform: (data, filter) => (0, exports.checkStringsFilter)(data.platform, filter), | ||
customData: (data, filter) => { | ||
const combinedCustomData = { | ||
...data.customData, | ||
...data.privateCustomData | ||
}; | ||
return (0, exports.checkCustomData)(combinedCustomData, filter); | ||
} | ||
}; | ||
var convertToSemanticVersion = function (version) { | ||
var splitVersion = version.split('.'); | ||
const convertToSemanticVersion = (version) => { | ||
const splitVersion = version.split('.'); | ||
if (splitVersion.length < 2) { | ||
@@ -83,3 +74,3 @@ splitVersion.push('0'); | ||
} | ||
splitVersion.forEach(function (value, index) { | ||
splitVersion.forEach((value, index) => { | ||
if (value === '') { | ||
@@ -92,5 +83,5 @@ splitVersion[index] = '0'; | ||
exports.convertToSemanticVersion = convertToSemanticVersion; | ||
var checkVersionValue = function (filterVersion, version, operator) { | ||
const checkVersionValue = (filterVersion, version, operator) => { | ||
if ((filterVersion === null || filterVersion === void 0 ? void 0 : filterVersion.length) > 0) { | ||
var result = (0, versionCompare_1.versionCompare)(version, filterVersion, { zeroExtend: true }); | ||
const result = (0, versionCompare_1.versionCompare)(version, filterVersion, { zeroExtend: true }); | ||
if (isNaN(result)) { | ||
@@ -112,5 +103,5 @@ return false; | ||
exports.checkVersionValue = checkVersionValue; | ||
var checkVersionFilter = function (version, filterVersions, operator) { | ||
var parsedOperator = operator; | ||
var parsedVersion = version; | ||
const checkVersionFilter = (version, filterVersions, operator) => { | ||
let parsedOperator = operator; | ||
let parsedVersion = version; | ||
if (!parsedVersion) { | ||
@@ -122,4 +113,4 @@ return false; | ||
} | ||
var filterVersionsTemp = filterVersions.filter(function (val) { return typeof val === 'string'; }); | ||
var not = false; | ||
let filterVersionsTemp = filterVersions.filter((val) => typeof val === 'string'); | ||
let not = false; | ||
if (parsedOperator === '!=') { | ||
@@ -129,4 +120,3 @@ parsedOperator = '='; | ||
} | ||
for (var _i = 0, filterVersionsTemp_1 = filterVersionsTemp; _i < filterVersionsTemp_1.length; _i++) { | ||
var v = filterVersionsTemp_1[_i]; | ||
for (const v of filterVersionsTemp) { | ||
if (typeof v !== 'string') { | ||
@@ -139,13 +129,13 @@ return false; | ||
// eg. 1.2.3a-b6 becomes 1.2.3 | ||
var regex1_1 = new RegExp(/[^(\d|.|\-)]/g); | ||
var regex2_1 = new RegExp(/-.*/g); | ||
parsedVersion = parsedVersion.replace(regex1_1, '').replace(regex2_1, ''); | ||
filterVersionsTemp = filterVersionsTemp.map(function (filterVersion) { return filterVersion.replace(regex1_1, '').replace(regex2_1, ''); }); | ||
const regex1 = new RegExp(/[^(\d|.|\-)]/g); | ||
const regex2 = new RegExp(/-.*/g); | ||
parsedVersion = parsedVersion.replace(regex1, '').replace(regex2, ''); | ||
filterVersionsTemp = filterVersionsTemp.map((filterVersion) => filterVersion.replace(regex1, '').replace(regex2, '')); | ||
} | ||
parsedVersion = (0, exports.convertToSemanticVersion)(parsedVersion); | ||
var passed = filterVersionsTemp.some(function (v) { return (0, exports.checkVersionValue)(v, parsedVersion, operator); }); | ||
const passed = filterVersionsTemp.some((v) => (0, exports.checkVersionValue)(v, parsedVersion, operator)); | ||
return (!not) ? passed : !passed; | ||
}; | ||
exports.checkVersionFilter = checkVersionFilter; | ||
var checkNumberFilter = function (num, filterNums, operator) { | ||
const checkNumberFilter = (num, filterNums, operator) => { | ||
if ((0, isString_1.default)(operator)) { | ||
@@ -163,3 +153,3 @@ switch (operator) { | ||
if ((0, isNumber_1.default)(num) && !isNaN(num)) { | ||
return filterNums.some(function (filterNum) { | ||
return filterNums.some((filterNum) => { | ||
if (!((0, isNumber_1.default)(filterNum) && !isNaN(filterNum))) { | ||
@@ -188,12 +178,12 @@ return false; | ||
exports.checkNumberFilter = checkNumberFilter; | ||
var checkNumbersFilter = function (number, filter) { | ||
var parsedNumber = (0, isString_1.default)(number) ? Number(number) : number; | ||
var operator = filter.comparator; | ||
var values = (0, exports.getFilterValues)(filter); | ||
const checkNumbersFilter = (number, filter) => { | ||
const parsedNumber = (0, isString_1.default)(number) ? Number(number) : number; | ||
const operator = filter.comparator; | ||
const values = (0, exports.getFilterValues)(filter); | ||
return (0, exports.checkNumberFilter)(parsedNumber, values, operator); | ||
}; | ||
exports.checkNumbersFilter = checkNumbersFilter; | ||
var checkStringsFilter = function (string, filter) { | ||
var operator = filter.comparator; | ||
var values = (0, exports.getFilterValues)(filter); | ||
const checkStringsFilter = (string, filter) => { | ||
const operator = filter.comparator; | ||
const values = (0, exports.getFilterValues)(filter); | ||
switch (operator) { | ||
@@ -209,5 +199,5 @@ case '=': | ||
case 'contain': | ||
return (!!values && (0, isString_1.default)(string) && !!(0, find_1.default)(values, function (value) { return (0, includes_1.default)(string, value); })); | ||
return (!!values && (0, isString_1.default)(string) && !!(0, find_1.default)(values, (value) => (0, includes_1.default)(string, value))); | ||
case '!contain': | ||
return (!!values && (!(0, isString_1.default)(string) || !(0, find_1.default)(values, function (value) { return (0, includes_1.default)(string, value); }))); | ||
return (!!values && (!(0, isString_1.default)(string) || !(0, find_1.default)(values, (value) => (0, includes_1.default)(string, value)))); | ||
} | ||
@@ -217,5 +207,5 @@ return (0, isString_1.default)(string); | ||
exports.checkStringsFilter = checkStringsFilter; | ||
var checkBooleanFilter = function (bool, filter) { | ||
var operator = filter.comparator; | ||
var values = (0, exports.getFilterValues)(filter); | ||
const checkBooleanFilter = (bool, filter) => { | ||
const operator = filter.comparator; | ||
const values = (0, exports.getFilterValues)(filter); | ||
switch (operator) { | ||
@@ -236,6 +226,6 @@ case 'contain': | ||
exports.checkBooleanFilter = checkBooleanFilter; | ||
var checkVersionFilters = function (appVersion, filter) { | ||
var parsedAppVersion = appVersion; | ||
var operator = filter.comparator; | ||
var values = (0, exports.getFilterValues)(filter); | ||
const checkVersionFilters = (appVersion, filter) => { | ||
const parsedAppVersion = appVersion; | ||
const operator = filter.comparator; | ||
const values = (0, exports.getFilterValues)(filter); | ||
// dont need to do semver if they're looking for an exact match. Adds support for non semver versions. | ||
@@ -250,9 +240,9 @@ if (operator === '=') { | ||
exports.checkVersionFilters = checkVersionFilters; | ||
var checkCustomData = function (data, filter) { | ||
var values = (0, exports.getFilterValues)(filter); | ||
var operator = filter.comparator; | ||
const checkCustomData = (data, filter) => { | ||
const values = (0, exports.getFilterValues)(filter); | ||
const operator = filter.comparator; | ||
if (filter.dataKey && (0, isString_1.default)(filter.dataKey)) { | ||
var customData = data || {}; | ||
var firstValue = values && values[0]; | ||
var dataValue = customData[filter.dataKey]; | ||
const customData = data || {}; | ||
const firstValue = values && values[0]; | ||
const dataValue = customData[filter.dataKey]; | ||
if (operator === 'exist') { | ||
@@ -305,5 +295,5 @@ return checkValueExists(dataValue); | ||
// exports.checkListAudienceFields = checkListAudienceFields | ||
var getFilterValues = function (filter) { | ||
var values = (0, isArray_1.default)(filter.values) | ||
? filter.values.filter(function (val) { return !(val === null || val === undefined); }) | ||
const getFilterValues = (filter) => { | ||
const values = (0, isArray_1.default)(filter.values) | ||
? filter.values.filter((val) => !(val === null || val === undefined)) | ||
: null; | ||
@@ -318,5 +308,5 @@ if (values && values.length > 0) { | ||
exports.getFilterValues = getFilterValues; | ||
var parseUserAgent = function (uaString) { | ||
const parseUserAgent = (uaString) => { | ||
// Note: Anything that is not in this map will return Desktop | ||
var DEVICES_MAP = { | ||
const DEVICES_MAP = { | ||
'mobile': 'Mobile', | ||
@@ -326,3 +316,3 @@ 'tablet': 'Tablet' | ||
// Note: Anything that is not in this map will return Other | ||
var BROWSER_MAP = { | ||
const BROWSER_MAP = { | ||
'Chrome': 'Chrome', | ||
@@ -342,3 +332,3 @@ 'Chrome Headless': 'Chrome', | ||
} | ||
var parser = new ua_parser_js_1.default(uaString); | ||
const parser = new ua_parser_js_1.default(uaString); | ||
return { | ||
@@ -345,0 +335,0 @@ browser: BROWSER_MAP[parser.getBrowser().name || ''] || 'Other', |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.versionCompare = void 0; | ||
var versionCompare = function (v1, v2, options) { | ||
var lexicographical = options === null || options === void 0 ? void 0 : options.lexicographical, zeroExtend = options === null || options === void 0 ? void 0 : options.zeroExtend; | ||
var v1parts = v1.split('.'), v2parts = v2.split('.'); | ||
var isValidPart = function (x) { | ||
const versionCompare = (v1, v2, options) => { | ||
const lexicographical = options === null || options === void 0 ? void 0 : options.lexicographical, zeroExtend = options === null || options === void 0 ? void 0 : options.zeroExtend; | ||
const v1parts = v1.split('.'), v2parts = v2.split('.'); | ||
const isValidPart = (x) => { | ||
return (lexicographical ? /^\d+[A-Za-z]*$/ : /^\d+$/).test(x); | ||
@@ -19,4 +19,4 @@ }; | ||
} | ||
var v1PartsFinal = v1parts; | ||
var v2PartsFinal = v2parts; | ||
let v1PartsFinal = v1parts; | ||
let v2PartsFinal = v2parts; | ||
if (!lexicographical) { | ||
@@ -26,3 +26,3 @@ v1PartsFinal = v1parts.map(Number); | ||
} | ||
for (var i = 0; i < v1PartsFinal.length; ++i) { | ||
for (let i = 0; i < v1PartsFinal.length; ++i) { | ||
if (v2PartsFinal.length === i) { | ||
@@ -29,0 +29,0 @@ return 1; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
47814
651
+ Added@devcycle/types@1.0.56(transitive)
- Removed@devcycle/types@1.0.55(transitive)
Updated@devcycle/types@1.0.56