@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
30 lines (29 loc) • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.shouldApplyRollout = exports.getTreatment = void 0;
var constants_1 = require("../../logger/constants");
var murmur3_1 = require("../../utils/murmur3/murmur3");
/**
* Get the treatment name given a key, a seed, and the percentage of each treatment.
*/
function getTreatment(log, key, seed, treatments) {
var _bucket = (0, murmur3_1.bucket)(key, seed);
var treatment = treatments.getTreatmentFor(_bucket);
log.debug(constants_1.ENGINE_BUCKET, [_bucket, key, seed, treatment]);
return treatment;
}
exports.getTreatment = getTreatment;
/**
* Evaluates the traffic allocation to see if we should apply rollout conditions or not.
*/
function shouldApplyRollout(trafficAllocation, key, trafficAllocationSeed) {
// For rollout, if traffic allocation for splits is 100%, we don't need to filter it because everything should evaluate the rollout.
if (trafficAllocation < 100) {
var _bucket = (0, murmur3_1.bucket)(key, trafficAllocationSeed);
if (_bucket > trafficAllocation) {
return false;
}
}
return true;
}
exports.shouldApplyRollout = shouldApplyRollout;