expf-sigma-node.js 3.0.3 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/public/sigma.js +176 -173
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expf-sigma-node.js",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "expf-sigma-node.js lets you manage features flags and remote config across web, server side applications. Deliver true Continuous Integration. Get builds out faster. Control who has access to new features.",
|
|
5
5
|
"main": "public/sigma.js",
|
|
6
6
|
"keywords": [
|
package/public/sigma.js
CHANGED
|
@@ -129,178 +129,6 @@ var SigmaUserData = class {
|
|
|
129
129
|
|
|
130
130
|
// src/modules/sigmaCache.js
|
|
131
131
|
var import_node_cache = __toESM(require("node-cache"));
|
|
132
|
-
var sigmaCache = new import_node_cache.default();
|
|
133
|
-
var SigmaCache = class {
|
|
134
|
-
constructor(postfix) {
|
|
135
|
-
this.postfix = "";
|
|
136
|
-
if (postfix)
|
|
137
|
-
this.postfix = "__" + postfix;
|
|
138
|
-
}
|
|
139
|
-
get(key) {
|
|
140
|
-
try {
|
|
141
|
-
return sigmaCache.get(key + this.postfix);
|
|
142
|
-
} catch (e) {
|
|
143
|
-
console.log(e);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
set(key, value) {
|
|
147
|
-
try {
|
|
148
|
-
sigmaCache.set(key + this.postfix, value);
|
|
149
|
-
return;
|
|
150
|
-
} catch (e) {
|
|
151
|
-
console.log(e);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
remove(key) {
|
|
155
|
-
try {
|
|
156
|
-
return sigmaCache.del(key + this.postfix);
|
|
157
|
-
} catch (e) {
|
|
158
|
-
console.log(e);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
parse(data) {
|
|
162
|
-
if (!this.get(data)) {
|
|
163
|
-
throw new Error(`${data} not found in cache`);
|
|
164
|
-
}
|
|
165
|
-
return JSON.parse(this.get(data));
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
// src/modules/sigmaGeoCache.js
|
|
170
|
-
var import_node_cache2 = __toESM(require("node-cache"));
|
|
171
|
-
var defaultGeoCacheTTL = 5 * 60;
|
|
172
|
-
var maxGeoCacheTTL = 120 * 60;
|
|
173
|
-
var minGeoCacheTTL = 1 * 60;
|
|
174
|
-
var sigmaGeoCache = new import_node_cache2.default();
|
|
175
|
-
var SigmaGeoCache = class {
|
|
176
|
-
constructor(postfix, geoCacheTTL) {
|
|
177
|
-
this.geoCacheTTL = geoCacheTTL || defaultGeoCacheTTL;
|
|
178
|
-
if (geoCacheTTL > maxGeoCacheTTL || geoCacheTTL < minGeoCacheTTL) {
|
|
179
|
-
this.geoCacheTTL = defaultGeoCacheTTL;
|
|
180
|
-
}
|
|
181
|
-
this.postfix = "";
|
|
182
|
-
if (postfix)
|
|
183
|
-
this.postfix = "__" + postfix;
|
|
184
|
-
}
|
|
185
|
-
get(key) {
|
|
186
|
-
try {
|
|
187
|
-
return sigmaGeoCache.get(key + this.postfix);
|
|
188
|
-
} catch (e) {
|
|
189
|
-
console.log(e);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
set(key, value) {
|
|
193
|
-
try {
|
|
194
|
-
return sigmaGeoCache.set(key + this.postfix, value, this.geoCacheTTL);
|
|
195
|
-
} catch (e) {
|
|
196
|
-
console.log(e);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
keys() {
|
|
200
|
-
return sigmaGeoCache.keys();
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
// src/helpers/checkBoolValue.js
|
|
205
|
-
function checkBoolValue(value) {
|
|
206
|
-
if (value)
|
|
207
|
-
return true;
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// src/helpers/checkForcedList.js
|
|
212
|
-
function checkForcedList(usersList, data) {
|
|
213
|
-
if (usersList.length) {
|
|
214
|
-
for (let id in usersList) {
|
|
215
|
-
if (usersList[id] == data) {
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// src/helpers/compareVersions.js
|
|
224
|
-
function compareVersions(versionA, versionB, strict = true) {
|
|
225
|
-
let resultCompare;
|
|
226
|
-
const versionsLength = Math.max(versionA.length, versionB.length);
|
|
227
|
-
versionA = (versionA + "").split(".");
|
|
228
|
-
versionB = (versionB + "").split(".");
|
|
229
|
-
for (let i = 0; i < versionsLength; i++) {
|
|
230
|
-
if (versionA[i] === void 0) {
|
|
231
|
-
versionA[i] = "0";
|
|
232
|
-
}
|
|
233
|
-
if (versionB[i] === void 0) {
|
|
234
|
-
versionB[i] = "0";
|
|
235
|
-
}
|
|
236
|
-
resultCompare = parseInt(versionA[i], 10) - parseInt(versionB[i], 10);
|
|
237
|
-
if (resultCompare !== 0) {
|
|
238
|
-
return resultCompare < 0 ? false : true;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (strict) {
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
if (!strict) {
|
|
245
|
-
return true;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// src/helpers/delay.js
|
|
250
|
-
function delay(ms) {
|
|
251
|
-
return new Promise((resolve) => setTimeout(() => resolve(void 0), ms));
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// src/helpers/digestHash.js
|
|
255
|
-
function digestHash(string) {
|
|
256
|
-
let hash = 0, i, chr;
|
|
257
|
-
if (string.length === 0)
|
|
258
|
-
return hash;
|
|
259
|
-
for (i = 0; i < string.length; i++) {
|
|
260
|
-
chr = string.charCodeAt(i);
|
|
261
|
-
hash = (hash << 5) - hash + chr;
|
|
262
|
-
hash |= 0;
|
|
263
|
-
}
|
|
264
|
-
return hash;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// src/helpers/doTypeConversion.js
|
|
268
|
-
function doTypeConversion(type, value) {
|
|
269
|
-
if (type === "string")
|
|
270
|
-
return value;
|
|
271
|
-
if (type === "bool") {
|
|
272
|
-
return value === "true" ? true : false;
|
|
273
|
-
}
|
|
274
|
-
if (type === "integer" || type === "number")
|
|
275
|
-
return parseFloat(value);
|
|
276
|
-
return value;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// src/helpers/generateRandomId.js
|
|
280
|
-
function generateRandomId() {
|
|
281
|
-
let text = "";
|
|
282
|
-
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
283
|
-
for (let i = 0; i < 80; i++)
|
|
284
|
-
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
285
|
-
return text;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// src/helpers/getUserGroup.js
|
|
289
|
-
function getUserGroup(salt, exposureRate, controlBucketPerc, forcedExp) {
|
|
290
|
-
let userInGroup = "a";
|
|
291
|
-
let currentDiapason = 0;
|
|
292
|
-
if (Math.abs(salt) / 100 <= parseFloat(exposureRate) * 100 || forcedExp) {
|
|
293
|
-
let bucket = Math.abs(salt) % 100;
|
|
294
|
-
for (let i = 0; i < controlBucketPerc.length; i++) {
|
|
295
|
-
currentDiapason += controlBucketPerc[i].weight * 100;
|
|
296
|
-
if (bucket <= currentDiapason) {
|
|
297
|
-
return userInGroup = controlBucketPerc[i].name;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return userInGroup;
|
|
301
|
-
}
|
|
302
|
-
return false;
|
|
303
|
-
}
|
|
304
132
|
|
|
305
133
|
// src/modules/sigmaHashes.js
|
|
306
134
|
var Hashes;
|
|
@@ -953,6 +781,181 @@ var zeta = 8540717056e4;
|
|
|
953
781
|
var SHA256 = new sigmaHashes_default.SHA256();
|
|
954
782
|
var MD5 = new sigmaHashes_default.MD5();
|
|
955
783
|
var expirationDate = 24 * 60 * 60 * 1e3;
|
|
784
|
+
var secondsIn24Hours = 24 * 60 * 60;
|
|
785
|
+
|
|
786
|
+
// src/modules/sigmaCache.js
|
|
787
|
+
var sigmaCache = new import_node_cache.default({ stdTTL: secondsIn24Hours });
|
|
788
|
+
var SigmaCache = class {
|
|
789
|
+
constructor(postfix) {
|
|
790
|
+
this.postfix = "";
|
|
791
|
+
if (postfix)
|
|
792
|
+
this.postfix = "__" + postfix;
|
|
793
|
+
}
|
|
794
|
+
get(key) {
|
|
795
|
+
try {
|
|
796
|
+
return sigmaCache.get(key + this.postfix);
|
|
797
|
+
} catch (e) {
|
|
798
|
+
console.log(e);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
set(key, value) {
|
|
802
|
+
try {
|
|
803
|
+
sigmaCache.set(key + this.postfix, value);
|
|
804
|
+
return;
|
|
805
|
+
} catch (e) {
|
|
806
|
+
console.log(e);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
remove(key) {
|
|
810
|
+
try {
|
|
811
|
+
return sigmaCache.del(key + this.postfix);
|
|
812
|
+
} catch (e) {
|
|
813
|
+
console.log(e);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
parse(data) {
|
|
817
|
+
if (!this.get(data)) {
|
|
818
|
+
throw new Error(`${data} not found in cache`);
|
|
819
|
+
}
|
|
820
|
+
return JSON.parse(this.get(data));
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
// src/modules/sigmaGeoCache.js
|
|
825
|
+
var import_node_cache2 = __toESM(require("node-cache"));
|
|
826
|
+
var defaultGeoCacheTTL = 5 * 60;
|
|
827
|
+
var maxGeoCacheTTL = 120 * 60;
|
|
828
|
+
var minGeoCacheTTL = 1 * 60;
|
|
829
|
+
var sigmaGeoCache = new import_node_cache2.default({ stdTTL: secondsIn24Hours });
|
|
830
|
+
var SigmaGeoCache = class {
|
|
831
|
+
constructor(postfix, geoCacheTTL) {
|
|
832
|
+
this.geoCacheTTL = geoCacheTTL || defaultGeoCacheTTL;
|
|
833
|
+
if (geoCacheTTL > maxGeoCacheTTL || geoCacheTTL < minGeoCacheTTL) {
|
|
834
|
+
this.geoCacheTTL = defaultGeoCacheTTL;
|
|
835
|
+
}
|
|
836
|
+
this.postfix = "";
|
|
837
|
+
if (postfix)
|
|
838
|
+
this.postfix = "__" + postfix;
|
|
839
|
+
}
|
|
840
|
+
get(key) {
|
|
841
|
+
try {
|
|
842
|
+
return sigmaGeoCache.get(key + this.postfix);
|
|
843
|
+
} catch (e) {
|
|
844
|
+
console.log(e);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
set(key, value) {
|
|
848
|
+
try {
|
|
849
|
+
return sigmaGeoCache.set(key + this.postfix, value, this.geoCacheTTL);
|
|
850
|
+
} catch (e) {
|
|
851
|
+
console.log(e);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
keys() {
|
|
855
|
+
return sigmaGeoCache.keys();
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
// src/helpers/checkBoolValue.js
|
|
860
|
+
function checkBoolValue(value) {
|
|
861
|
+
if (value)
|
|
862
|
+
return true;
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// src/helpers/checkForcedList.js
|
|
867
|
+
function checkForcedList(usersList, data) {
|
|
868
|
+
if (usersList.length) {
|
|
869
|
+
for (let id in usersList) {
|
|
870
|
+
if (usersList[id] == data) {
|
|
871
|
+
return true;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
return false;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// src/helpers/compareVersions.js
|
|
879
|
+
function compareVersions(versionA, versionB, strict = true) {
|
|
880
|
+
let resultCompare;
|
|
881
|
+
const versionsLength = Math.max(versionA.length, versionB.length);
|
|
882
|
+
versionA = (versionA + "").split(".");
|
|
883
|
+
versionB = (versionB + "").split(".");
|
|
884
|
+
for (let i = 0; i < versionsLength; i++) {
|
|
885
|
+
if (versionA[i] === void 0) {
|
|
886
|
+
versionA[i] = "0";
|
|
887
|
+
}
|
|
888
|
+
if (versionB[i] === void 0) {
|
|
889
|
+
versionB[i] = "0";
|
|
890
|
+
}
|
|
891
|
+
resultCompare = parseInt(versionA[i], 10) - parseInt(versionB[i], 10);
|
|
892
|
+
if (resultCompare !== 0) {
|
|
893
|
+
return resultCompare < 0 ? false : true;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
if (strict) {
|
|
897
|
+
return false;
|
|
898
|
+
}
|
|
899
|
+
if (!strict) {
|
|
900
|
+
return true;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// src/helpers/delay.js
|
|
905
|
+
function delay(ms) {
|
|
906
|
+
return new Promise((resolve) => setTimeout(() => resolve(void 0), ms));
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// src/helpers/digestHash.js
|
|
910
|
+
function digestHash(string) {
|
|
911
|
+
let hash = 0, i, chr;
|
|
912
|
+
if (string.length === 0)
|
|
913
|
+
return hash;
|
|
914
|
+
for (i = 0; i < string.length; i++) {
|
|
915
|
+
chr = string.charCodeAt(i);
|
|
916
|
+
hash = (hash << 5) - hash + chr;
|
|
917
|
+
hash |= 0;
|
|
918
|
+
}
|
|
919
|
+
return hash;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// src/helpers/doTypeConversion.js
|
|
923
|
+
function doTypeConversion(type, value) {
|
|
924
|
+
if (type === "string")
|
|
925
|
+
return value;
|
|
926
|
+
if (type === "bool") {
|
|
927
|
+
return value === "true" ? true : false;
|
|
928
|
+
}
|
|
929
|
+
if (type === "integer" || type === "number")
|
|
930
|
+
return parseFloat(value);
|
|
931
|
+
return value;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// src/helpers/generateRandomId.js
|
|
935
|
+
function generateRandomId() {
|
|
936
|
+
let text = "";
|
|
937
|
+
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
938
|
+
for (let i = 0; i < 80; i++)
|
|
939
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
940
|
+
return text;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
// src/helpers/getUserGroup.js
|
|
944
|
+
function getUserGroup(salt, exposureRate, controlBucketPerc, forcedExp) {
|
|
945
|
+
let userInGroup = "a";
|
|
946
|
+
let currentDiapason = 0;
|
|
947
|
+
if (Math.abs(salt) / 100 <= parseFloat(exposureRate) * 100 || forcedExp) {
|
|
948
|
+
let bucket = Math.abs(salt) % 100;
|
|
949
|
+
for (let i = 0; i < controlBucketPerc.length; i++) {
|
|
950
|
+
currentDiapason += controlBucketPerc[i].weight * 100;
|
|
951
|
+
if (bucket <= currentDiapason) {
|
|
952
|
+
return userInGroup = controlBucketPerc[i].name;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
return userInGroup;
|
|
956
|
+
}
|
|
957
|
+
return false;
|
|
958
|
+
}
|
|
956
959
|
|
|
957
960
|
// src/sigma.js
|
|
958
961
|
if (typeof import_node_fetch.default.default !== "undefined")
|
|
@@ -1161,7 +1164,7 @@ var Sigma = class {
|
|
|
1161
1164
|
const expName = this.getExperimentByFeatureFlag(cacheKey, flagName);
|
|
1162
1165
|
if (expName) {
|
|
1163
1166
|
const experimentByFlag = await this.getExperiment(expName).then((res) => res.getFeatureValue(flagName));
|
|
1164
|
-
if (experimentByFlag)
|
|
1167
|
+
if (experimentByFlag !== null)
|
|
1165
1168
|
return experimentByFlag;
|
|
1166
1169
|
}
|
|
1167
1170
|
for (let i = 0; i < cacheKey.feature_flags.length; i++) {
|