expf-sigma-node.js 3.1.0 → 3.2.1
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 +102 -52
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expf-sigma-node.js",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
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
|
@@ -32,6 +32,7 @@ var import_node_fetch = __toESM(require("node-fetch"));
|
|
|
32
32
|
|
|
33
33
|
// src/modules/sigmaUserData.js
|
|
34
34
|
var SigmaUserData = class {
|
|
35
|
+
platform = "all";
|
|
35
36
|
constructor() {
|
|
36
37
|
this.user = {
|
|
37
38
|
userId: null,
|
|
@@ -901,6 +902,70 @@ function compareVersions(versionA, versionB, strict = true) {
|
|
|
901
902
|
}
|
|
902
903
|
}
|
|
903
904
|
|
|
905
|
+
// src/helpers/conditionOperation.js
|
|
906
|
+
function conditionOperation(userValue, conditionValues, operation) {
|
|
907
|
+
!operation ? operation = "=" : operation;
|
|
908
|
+
if (userValue === null || typeof userValue === "undefined" || !conditionValues)
|
|
909
|
+
return false;
|
|
910
|
+
userValue = String(userValue);
|
|
911
|
+
if (!Array.isArray(conditionValues))
|
|
912
|
+
conditionValues = String(conditionValues);
|
|
913
|
+
switch (operation.trim()) {
|
|
914
|
+
case "equal":
|
|
915
|
+
return userValue.toLowerCase().trim() == conditionValues.toLowerCase().trim();
|
|
916
|
+
case "not equal":
|
|
917
|
+
return userValue.toLowerCase().trim() != conditionValues.toLowerCase().trim();
|
|
918
|
+
case "greater":
|
|
919
|
+
return compareVersions(userValue.trim(), conditionValues.trim());
|
|
920
|
+
case "less":
|
|
921
|
+
return compareVersions(conditionValues.trim(), userValue.trim());
|
|
922
|
+
case "greater equal":
|
|
923
|
+
return compareVersions(userValue.trim(), conditionValues.trim(), false);
|
|
924
|
+
case "less equal":
|
|
925
|
+
return compareVersions(conditionValues.trim(), userValue.trim(), false);
|
|
926
|
+
case "any of":
|
|
927
|
+
return conditionValues.includes(userValue);
|
|
928
|
+
case "none of":
|
|
929
|
+
return !conditionValues.includes(userValue);
|
|
930
|
+
case "contains any of":
|
|
931
|
+
for (let i = 0; i < conditionValues.length; i++) {
|
|
932
|
+
if (userValue.includes(conditionValues[i])) {
|
|
933
|
+
return true;
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
return false;
|
|
937
|
+
case "contains none of":
|
|
938
|
+
for (let i = 0; i < conditionValues.length; i++) {
|
|
939
|
+
if (userValue.includes(conditionValues[i])) {
|
|
940
|
+
return false;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
return true;
|
|
944
|
+
case "on date":
|
|
945
|
+
return Math.floor(
|
|
946
|
+
new Date(conditionValues.trim()).getTime() / (1e3 * 60 * 60 * 24)
|
|
947
|
+
) == this.sigmaUserData.user.date;
|
|
948
|
+
case "after time":
|
|
949
|
+
return new Date(conditionValues.trim()).getTime() / (1e3 * 60 * 60) < this.sigmaUserData.user.time;
|
|
950
|
+
case "before time":
|
|
951
|
+
return new Date(conditionValues.trim()).getTime() / (1e3 * 60 * 60) > this.sigmaUserData.user.time;
|
|
952
|
+
case "starts with":
|
|
953
|
+
return userValue.startsWith(conditionValues);
|
|
954
|
+
case "not starts with":
|
|
955
|
+
return !userValue.startsWith(conditionValues);
|
|
956
|
+
case "ends with":
|
|
957
|
+
return userValue.endsWith(conditionValues);
|
|
958
|
+
case "not ends with":
|
|
959
|
+
return !userValue.endsWith(conditionValues);
|
|
960
|
+
case "contains":
|
|
961
|
+
return userValue.includes(conditionValues);
|
|
962
|
+
case "not contains":
|
|
963
|
+
return !userValue.includes(conditionValues);
|
|
964
|
+
default:
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
904
969
|
// src/helpers/delay.js
|
|
905
970
|
function delay(ms) {
|
|
906
971
|
return new Promise((resolve) => setTimeout(() => resolve(void 0), ms));
|
|
@@ -957,6 +1022,40 @@ function getUserGroup(salt, exposureRate, controlBucket, forcedExp) {
|
|
|
957
1022
|
return false;
|
|
958
1023
|
}
|
|
959
1024
|
|
|
1025
|
+
// src/helpers/filterByPlatform.js
|
|
1026
|
+
function filterByPlatform(config, platformName) {
|
|
1027
|
+
if (!Object.keys(config).length)
|
|
1028
|
+
return;
|
|
1029
|
+
if (!platformName)
|
|
1030
|
+
return config;
|
|
1031
|
+
let filteredConfig = { ...config };
|
|
1032
|
+
const { feature_flags, experiments } = filteredConfig;
|
|
1033
|
+
filteredConfig.feature_flags = generateFilteredList(feature_flags, platformName);
|
|
1034
|
+
filteredConfig.experiments = generateFilteredList(experiments, platformName);
|
|
1035
|
+
return filteredConfig;
|
|
1036
|
+
}
|
|
1037
|
+
function generateFilteredList(array, name) {
|
|
1038
|
+
if (!array.length)
|
|
1039
|
+
return [];
|
|
1040
|
+
let listName = null;
|
|
1041
|
+
if (Array.isArray(name)) {
|
|
1042
|
+
listName = [...name];
|
|
1043
|
+
} else if (typeof name === "string") {
|
|
1044
|
+
listName = [name];
|
|
1045
|
+
}
|
|
1046
|
+
if (listName.find((n) => n === "all"))
|
|
1047
|
+
return array;
|
|
1048
|
+
array = array.filter((item) => {
|
|
1049
|
+
for (let index in listName) {
|
|
1050
|
+
if (!item.platform)
|
|
1051
|
+
return item;
|
|
1052
|
+
if (item.platform === listName[index])
|
|
1053
|
+
return item;
|
|
1054
|
+
}
|
|
1055
|
+
});
|
|
1056
|
+
return array;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
960
1059
|
// src/sigma.js
|
|
961
1060
|
if (typeof import_node_fetch.default.default !== "undefined")
|
|
962
1061
|
import_node_fetch.default.default;
|
|
@@ -1118,6 +1217,7 @@ var Sigma = class {
|
|
|
1118
1217
|
if (typeof data !== "object") {
|
|
1119
1218
|
throw new Error(`typeof config.json is not an object`);
|
|
1120
1219
|
}
|
|
1220
|
+
data = filterByPlatform(data, this.userData.platform || this.sigmaUserData.platform);
|
|
1121
1221
|
hash = await SHA256.hex(JSON.stringify(data));
|
|
1122
1222
|
if (!localStorageHash || localStorageHash !== hash) {
|
|
1123
1223
|
this.cache.set(sigmaHash, hash);
|
|
@@ -1206,56 +1306,6 @@ var Sigma = class {
|
|
|
1206
1306
|
}
|
|
1207
1307
|
return flagValue;
|
|
1208
1308
|
}
|
|
1209
|
-
conditionOperation(userValue, conditionValues, operation) {
|
|
1210
|
-
!operation ? operation = "=" : operation;
|
|
1211
|
-
if (userValue === null || typeof userValue === "undefined" || !conditionValues)
|
|
1212
|
-
return false;
|
|
1213
|
-
userValue = String(userValue);
|
|
1214
|
-
if (!Array.isArray(conditionValues))
|
|
1215
|
-
conditionValues = String(conditionValues);
|
|
1216
|
-
switch (operation.trim()) {
|
|
1217
|
-
case "equal":
|
|
1218
|
-
return userValue.toLowerCase().trim() == conditionValues.toLowerCase().trim();
|
|
1219
|
-
case "not equal":
|
|
1220
|
-
return userValue.toLowerCase().trim() != conditionValues.toLowerCase().trim();
|
|
1221
|
-
case "greater":
|
|
1222
|
-
return compareVersions(userValue.trim(), conditionValues.trim());
|
|
1223
|
-
case "less":
|
|
1224
|
-
return compareVersions(conditionValues.trim(), userValue.trim());
|
|
1225
|
-
case "greater equal":
|
|
1226
|
-
return compareVersions(userValue.trim(), conditionValues.trim(), false);
|
|
1227
|
-
case "less equal":
|
|
1228
|
-
return compareVersions(conditionValues.trim(), userValue.trim(), false);
|
|
1229
|
-
case "any of":
|
|
1230
|
-
return conditionValues.includes(userValue);
|
|
1231
|
-
case "none of":
|
|
1232
|
-
return !conditionValues.includes(userValue);
|
|
1233
|
-
case "contains any of":
|
|
1234
|
-
for (let i = 0; i < conditionValues.length; i++) {
|
|
1235
|
-
if (userValue.includes(conditionValues[i])) {
|
|
1236
|
-
return true;
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
return false;
|
|
1240
|
-
case "contains none of":
|
|
1241
|
-
for (let i = 0; i < conditionValues.length; i++) {
|
|
1242
|
-
if (userValue.includes(conditionValues[i])) {
|
|
1243
|
-
return false;
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
return true;
|
|
1247
|
-
case "on date":
|
|
1248
|
-
return Math.floor(
|
|
1249
|
-
new Date(conditionValues.trim()).getTime() / (1e3 * 60 * 60 * 24)
|
|
1250
|
-
) == this.sigmaUserData.user.date;
|
|
1251
|
-
case "after time":
|
|
1252
|
-
return new Date(conditionValues.trim()).getTime() / (1e3 * 60 * 60) < this.sigmaUserData.user.time;
|
|
1253
|
-
case "before time":
|
|
1254
|
-
return new Date(conditionValues.trim()).getTime() / (1e3 * 60 * 60) > this.sigmaUserData.user.time;
|
|
1255
|
-
default:
|
|
1256
|
-
return false;
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
1309
|
getUserParamValue(paramKey, privateFlag = null, isConditionSignForHash = false) {
|
|
1260
1310
|
if (!paramKey)
|
|
1261
1311
|
return false;
|
|
@@ -1349,7 +1399,7 @@ var Sigma = class {
|
|
|
1349
1399
|
this.checkConditionSignForHash(targets.conditions[index].condition_sign)
|
|
1350
1400
|
);
|
|
1351
1401
|
results.push(
|
|
1352
|
-
|
|
1402
|
+
conditionOperation(
|
|
1353
1403
|
userValue,
|
|
1354
1404
|
targets.conditions[index].value,
|
|
1355
1405
|
targets.conditions[index].condition_sign
|
|
@@ -1561,7 +1611,7 @@ var Sigma = class {
|
|
|
1561
1611
|
this.checkConditionSignForHash(conditions[i].condition_sign)
|
|
1562
1612
|
);
|
|
1563
1613
|
results.push(
|
|
1564
|
-
|
|
1614
|
+
conditionOperation(
|
|
1565
1615
|
userValue,
|
|
1566
1616
|
conditions[i].value,
|
|
1567
1617
|
conditions[i].condition_sign
|