UNPKG

@splitsoftware/splitio-commons

Version:
64 lines (63 loc) 2.65 kB
import { hash } from '../utils/murmur3/murmur3'; var everythingAtTheEnd = /[^.]+$/; var DEFAULT_PREFIX = 'SPLITIO'; export function validatePrefix(prefix) { return prefix ? prefix + '.SPLITIO' : 'SPLITIO'; } var KeyBuilder = /** @class */ (function () { function KeyBuilder(prefix) { if (prefix === void 0) { prefix = DEFAULT_PREFIX; } this.prefix = prefix; } KeyBuilder.prototype.buildTrafficTypeKey = function (trafficType) { return "".concat(this.prefix, ".trafficType.").concat(trafficType); }; KeyBuilder.prototype.buildSetKey = function (set) { return "".concat(this.prefix, ".flagSet.").concat(set); }; KeyBuilder.prototype.buildDefinitionKey = function (definitionName) { return "".concat(this.prefix, ".split.").concat(definitionName); }; KeyBuilder.prototype.buildDefinitionsTillKey = function () { return "".concat(this.prefix, ".splits.till"); }; KeyBuilder.prototype.buildDefinitionKeyPrefix = function () { return "".concat(this.prefix, ".split."); }; KeyBuilder.prototype.buildRBSegmentKey = function (rbsegmentName) { return "".concat(this.prefix, ".rbsegment.").concat(rbsegmentName); }; KeyBuilder.prototype.buildRBSegmentsTillKey = function () { return "".concat(this.prefix, ".rbsegments.till"); }; KeyBuilder.prototype.buildRBSegmentKeyPrefix = function () { return "".concat(this.prefix, ".rbsegment."); }; KeyBuilder.prototype.buildSegmentNameKey = function (segmentName) { return "".concat(this.prefix, ".segment.").concat(segmentName); }; KeyBuilder.prototype.buildSegmentTillKey = function (segmentName) { return "".concat(this.prefix, ".segment.").concat(segmentName, ".till"); }; KeyBuilder.prototype.extractKey = function (builtKey) { var s = builtKey.match(everythingAtTheEnd); if (s && s.length) { return s[0]; } else { throw new Error('Invalid latency key provided'); } }; KeyBuilder.prototype.buildHashKey = function () { return "".concat(this.prefix, ".hash"); }; return KeyBuilder; }()); export { KeyBuilder }; /** * Generates a murmur32 hash based on the authorization key, the feature flags filter query, and version of SplitChanges API. * The hash is in hexadecimal format (8 characters max, 32 bits). */ export function getStorageHash(settings) { return hash("".concat(settings.core.authorizationKey, "::").concat(settings.sync.__splitFiltersValidation.queryString, "::").concat(settings.sync.flagSpecVersion)).toString(16); }