Comparing version 2.3.7 to 3.0.0
{ | ||
"name": "rox-base", | ||
"version": "2.3.7", | ||
"version": "3.0.0", | ||
"description": "Rollout.io ROX JS SDK Base", | ||
@@ -38,6 +38,5 @@ "author": "Rollout.io <support@rollout.io>", | ||
"ROX": { | ||
"api_version": "1.5.0" | ||
"api_version": "1.6.0" | ||
}, | ||
"main": "src/index.js", | ||
"module": "src/index.js", | ||
"main": "dist/rox-base.js", | ||
"devDependencies": { | ||
@@ -44,0 +43,0 @@ "axios": "^0.18.0", |
@@ -12,5 +12,3 @@ import { RoxxParser } from '../parsers'; | ||
if (types.indexOf(valueType) === -1) { | ||
throw new Error( | ||
`RoxConfiguration initialized with wrong type '${valueType}'` | ||
); | ||
throw new Error(`RoxConfiguration initialized with wrong type '${valueType}'`); | ||
} | ||
@@ -68,4 +66,10 @@ | ||
let mergedContext = Context.Actions.getMergedContextWithGlobal(context); | ||
let value = parser.evaluateExpression(this.condition, mergedContext); | ||
value ? this._value = value : this._value = this.defaultValue; | ||
let value = parser.evaluateExpression(this.condition, {}, mergedContext); | ||
if (this._type !== typeof value || value === undefined) { | ||
this._value = this._defaultValue; | ||
} else { | ||
this._value = value; | ||
} | ||
} | ||
@@ -72,0 +76,0 @@ return this._value; |
@@ -12,2 +12,3 @@ import { invokeImpression } from '../lib/ImpressionHandler'; | ||
this._frozen = false; | ||
this._freezable = true; | ||
} | ||
@@ -47,2 +48,7 @@ | ||
/* abstract */ | ||
getInternalValue() { | ||
throw Error('not implemented'); | ||
} | ||
set name(name) { | ||
@@ -71,8 +77,16 @@ this._name = name; | ||
defaultValue: this.defaultValue, | ||
originalValue: this.getActiveValue(true, true), | ||
originalValue: this._originalValue(), | ||
overridingValue: this.overridenValue, | ||
value: this.getValue.length === 1 ? this.getValue(true) : this.getValue(null, true) | ||
value: this._freezable ? this.getValue(true) : this.getValue(null, true) | ||
}; | ||
} | ||
_originalValue() { | ||
const dontInvokeFlagImpression = true; | ||
const dontInvokeFreeze = true; | ||
return this._freezable | ||
? this.getActiveValue({ dontInvokeFlagImpression, dontInvokeFreeze }) | ||
: this.getActiveValue({ dontInvokeFlagImpression, dontInvokeFreeze }, null); | ||
} | ||
_flagImpression(value, context) { | ||
@@ -79,0 +93,0 @@ invokeImpression(value, this, context); |
@@ -69,3 +69,3 @@ import { BugsnagReporter, RoxLogger, ClassRegister, ConfigurationFetcher } from './'; | ||
.getDefaultCustomProperties(this.deviceProperties) | ||
.map(CustomPropertyRepository.set.bind(CustomPropertyRepository)); | ||
.map(CustomPropertyRepository.setIfNotExists.bind(CustomPropertyRepository)); | ||
} catch (e) { | ||
@@ -72,0 +72,0 @@ const message = 'Oh uh! An error occured during setup.'; |
@@ -210,5 +210,7 @@ import { fetchRemoteConfiguration } from './RequestConfiguration'; | ||
const signed_date = new Date(response.signed_date); | ||
if (!signed_date || signed_date > +new Date()) { | ||
return false; | ||
return Promise.resolve(false); | ||
} | ||
return this.crypto.then(crypto => crypto.verify(data, signature_v0)); | ||
@@ -215,0 +217,0 @@ } |
import TargetGroupRepository from '../repositories/TargetGroupRepository'; | ||
import CustomPropertyRepository from '../repositories/CustomPropertyRepository'; | ||
import FlagsRepository from '../repositories/RoxFlagRepository'; | ||
import ExperimentRepository from '../repositories/ExperimentsRepository'; | ||
import RoxxParser from '../parsers/RoxxParser'; | ||
import md5 from 'md5'; | ||
function _versionCompare (v1, v2, options = {zeroExtend: true, lexicographical: true }) { | ||
function _versionCompare(v1, v2, options = { zeroExtend: true, lexicographical: true }) { | ||
var lexicographical = options && options.lexicographical, | ||
@@ -12,3 +14,3 @@ zeroExtend = options && options.zeroExtend, | ||
function isValidPart (x) { | ||
function isValidPart(x) { | ||
return (lexicographical ? /[0-9A-Za-z_-]+$/ : /^\d+$/).test(x); | ||
@@ -52,10 +54,5 @@ } | ||
const getBucket = (seed) => { | ||
const getBucket = seed => { | ||
var hash = md5(seed, { asBytes: true }); | ||
hash = | ||
((hash[0] & 0xff) | | ||
((hash[1] & 0xff) << 8) | | ||
((hash[2] & 0xff) << 16) | | ||
((hash[3] & 0xff) << 24)) >>> | ||
0; | ||
hash = ((hash[0] & 0xff) | ((hash[1] & 0xff) << 8) | ((hash[2] & 0xff) << 16) | ((hash[3] & 0xff) << 24)) >>> 0; | ||
@@ -66,3 +63,3 @@ var bucket = hash / (Math.pow(2, 32) - 1); | ||
export const isUndefined = (op) => op === undefined; | ||
export const isUndefined = op => op === undefined; | ||
export const now = () => Date.now(); | ||
@@ -73,4 +70,5 @@ export const and = (op1, op2) => op1 && op2; | ||
export const eq = (op1, op2) => (isUndefined(op1) ? false : op1) === (isUndefined(op2) ? false : op2); | ||
export const not = (op) => !op; | ||
export const ifThen = (conditionExpression, trueExpression, falseExpression) => conditionExpression ? trueExpression : falseExpression; | ||
export const not = op => !op; | ||
export const ifThen = (conditionExpression, trueExpression, falseExpression) => | ||
conditionExpression ? trueExpression : falseExpression; | ||
@@ -185,6 +183,26 @@ export const lt = (op1, op2) => { | ||
export const isInTargetGroup = (targetGroup, context = {}) => { | ||
export const flagValue = (flagName, context = {}, internalContext = {}) => { | ||
const flag = FlagsRepository.flagWithName(flagName); | ||
if (flag) { | ||
return flag.getInternalValue(internalContext, context); | ||
} | ||
const exp = ExperimentRepository.experimentForFlagName(flagName); | ||
if (exp && exp.deploymentConfiguration) { | ||
const expressionValue = new RoxxParser().evaluateExpression( | ||
exp.deploymentConfiguration.condition, | ||
internalContext, | ||
context | ||
); | ||
return expressionValue || 'false'; | ||
} | ||
return 'false'; | ||
}; | ||
export const isInTargetGroup = (targetGroup, context = {}, callContext = {}) => { | ||
const tg = TargetGroupRepository.targetGroupWithName(targetGroup); | ||
if(tg) { | ||
return new RoxxParser().evaluateExpression(tg.condition, context); | ||
if (tg) { | ||
return new RoxxParser().evaluateExpression(tg.condition, callContext, context); | ||
} else { | ||
@@ -208,3 +226,2 @@ return false; | ||
export const operatorsWithContext = [isInTargetGroup, property]; | ||
export const operatorsWithContext = [isInTargetGroup, flagValue, property]; |
@@ -47,7 +47,12 @@ import LRUCache from 'lru-cache'; | ||
*/ | ||
_modifyArgsHook({ operator, args, context }) { | ||
_modifyArgsHook({ operator, args, context, callContext }) { | ||
var argsWithContext = args; | ||
if (context && RoxxOperatorsMap.operatorsWithContext.includes(operator)) { | ||
return [...args, context]; // insert context as a last arg | ||
argsWithContext = [...args, context]; // insert context | ||
} | ||
return args; | ||
if (callContext) { | ||
return [...argsWithContext, callContext]; | ||
} | ||
return argsWithContext; | ||
} | ||
@@ -76,3 +81,3 @@ | ||
*/ | ||
evaluateExpression(expr, context = {}) { | ||
evaluateExpression(expr, callContext = {}, context = {}) { | ||
var stack = []; | ||
@@ -91,3 +96,3 @@ var tokens = this.compileExpression(expr); | ||
var args = this._argsArrayForOperator(operator, stack); | ||
args = this._modifyArgsHook({ operator, args, context }); | ||
args = this._modifyArgsHook({ operator, args, context, callContext }); | ||
var value = operator.apply(this, args); | ||
@@ -94,0 +99,0 @@ stack.push(value); |
@@ -18,2 +18,9 @@ class CustomPropertyRepository { | ||
setIfNotExists(property) { | ||
if (this.has(property)) { | ||
return; | ||
} | ||
this.set(property); | ||
} | ||
clear() { | ||
@@ -20,0 +27,0 @@ this.store.clear(); |
@@ -23,4 +23,8 @@ class ExperimentsRepository { | ||
experimentForFlagName(flagName) { | ||
return this.experiments.find(e => e.flags && e.flags.some(f => f.name === flagName)); | ||
} | ||
experimentForFlag(flag) { | ||
return this.experiments.find(e => e.flags && e.flags.some(f => f.name === flag.name)); | ||
return this.experimentForFlagName(flag.name); | ||
} | ||
@@ -27,0 +31,0 @@ } |
@@ -18,3 +18,3 @@ class RoxFlagRepository { | ||
get flags() { | ||
return Object.keys(this.map).map(t => this.map[t]) | ||
return Object.keys(this.map).map(t => this.map[t]); | ||
} | ||
@@ -21,0 +21,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
1280438
4
56
11220