UNPKG

@splitsoftware/splitio-commons

Version:
69 lines (68 loc) 2.91 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 "".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; }()); 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)("".concat(settings.core.authorizationKey, "::").concat(settings.sync.__splitFiltersValidation.queryString, "::").concat(settings.sync.flagSpecVersion)).toString(16); } exports.getStorageHash = getStorageHash;