expf-sigma-node.js 3.1.0 → 3.2.0
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 +36 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expf-sigma-node.js",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
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,
|
|
@@ -957,6 +958,40 @@ function getUserGroup(salt, exposureRate, controlBucket, forcedExp) {
|
|
|
957
958
|
return false;
|
|
958
959
|
}
|
|
959
960
|
|
|
961
|
+
// src/helpers/filterByPlatform.js
|
|
962
|
+
function filterByPlatform(config, platformName) {
|
|
963
|
+
if (!Object.keys(config).length)
|
|
964
|
+
return;
|
|
965
|
+
if (!platformName)
|
|
966
|
+
return config;
|
|
967
|
+
let filteredConfig = { ...config };
|
|
968
|
+
const { feature_flags, experiments } = filteredConfig;
|
|
969
|
+
filteredConfig.feature_flags = generateFilteredList(feature_flags, platformName);
|
|
970
|
+
filteredConfig.experiments = generateFilteredList(experiments, platformName);
|
|
971
|
+
return filteredConfig;
|
|
972
|
+
}
|
|
973
|
+
function generateFilteredList(array, name) {
|
|
974
|
+
if (!array.length)
|
|
975
|
+
return [];
|
|
976
|
+
let listName = null;
|
|
977
|
+
if (Array.isArray(name)) {
|
|
978
|
+
listName = [...name];
|
|
979
|
+
} else if (typeof name === "string") {
|
|
980
|
+
listName = [name];
|
|
981
|
+
}
|
|
982
|
+
if (listName.find((n) => n === "all"))
|
|
983
|
+
return array;
|
|
984
|
+
array = array.filter((item) => {
|
|
985
|
+
for (let index in listName) {
|
|
986
|
+
if (!item.platform)
|
|
987
|
+
return item;
|
|
988
|
+
if (item.platform === listName[index])
|
|
989
|
+
return item;
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
return array;
|
|
993
|
+
}
|
|
994
|
+
|
|
960
995
|
// src/sigma.js
|
|
961
996
|
if (typeof import_node_fetch.default.default !== "undefined")
|
|
962
997
|
import_node_fetch.default.default;
|
|
@@ -1118,6 +1153,7 @@ var Sigma = class {
|
|
|
1118
1153
|
if (typeof data !== "object") {
|
|
1119
1154
|
throw new Error(`typeof config.json is not an object`);
|
|
1120
1155
|
}
|
|
1156
|
+
data = filterByPlatform(data, this.userData.platform || this.sigmaUserData.platform);
|
|
1121
1157
|
hash = await SHA256.hex(JSON.stringify(data));
|
|
1122
1158
|
if (!localStorageHash || localStorageHash !== hash) {
|
|
1123
1159
|
this.cache.set(sigmaHash, hash);
|