UNPKG

@splitsoftware/splitio-commons

Version:
69 lines (68 loc) 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getStorageHash = exports.KeyBuilder = exports.validatePrefix = void 0; var murmur3_1 = require("../utils/murmur3/murmur3"); var everythingAtTheEnd = /[^.]+$/; var DEFAULT_PREFIX = 'SPLITIO'; function validatePrefix(prefix) { return prefix ? prefix + '.SPLITIO' : 'SPLITIO'; } exports.validatePrefix = validatePrefix; var KeyBuilder = /** @class */ (function () { function KeyBuilder(prefix) { if (prefix === void 0) { prefix = DEFAULT_PREFIX; } this.prefix = prefix; } KeyBuilder.prototype.buildTrafficTypeKey = function (trafficType) { return this.prefix + ".trafficType." + trafficType; }; KeyBuilder.prototype.buildFlagSetKey = function (flagSet) { return this.prefix + ".flagSet." + flagSet; }; KeyBuilder.prototype.buildSplitKey = function (splitName) { return this.prefix + ".split." + splitName; }; KeyBuilder.prototype.buildSplitsTillKey = function () { return this.prefix + ".splits.till"; }; KeyBuilder.prototype.buildSplitKeyPrefix = function () { return this.prefix + ".split."; }; KeyBuilder.prototype.buildRBSegmentKey = function (rbsegmentName) { return this.prefix + ".rbsegment." + rbsegmentName; }; KeyBuilder.prototype.buildRBSegmentsTillKey = function () { return this.prefix + ".rbsegments.till"; }; KeyBuilder.prototype.buildRBSegmentKeyPrefix = function () { return this.prefix + ".rbsegment."; }; KeyBuilder.prototype.buildSegmentNameKey = function (segmentName) { return this.prefix + ".segment." + segmentName; }; KeyBuilder.prototype.buildSegmentTillKey = function (segmentName) { return this.prefix + ".segment." + 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 this.prefix + ".hash"; }; return KeyBuilder; }()); exports.KeyBuilder = 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). */ function getStorageHash(settings) { return (0, murmur3_1.hash)(settings.core.authorizationKey + "::" + settings.sync.__splitFiltersValidation.queryString + "::" + settings.sync.flagSpecVersion).toString(16); } exports.getStorageHash = getStorageHash;