expf-sigma-node.js 3.3.4 → 3.3.6
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 +66 -77
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expf-sigma-node.js",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.6",
|
|
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
|
@@ -1017,13 +1017,7 @@ var sigmaGeoCache = new import_node_cache2.default({
|
|
|
1017
1017
|
checkperiod: cacheCheckPeriod
|
|
1018
1018
|
});
|
|
1019
1019
|
var SigmaGeoCache = class {
|
|
1020
|
-
|
|
1021
|
-
minGeoCacheTTL = 1 * 60;
|
|
1022
|
-
constructor(postfix, geoCacheTTL) {
|
|
1023
|
-
this.geoCacheTTL = geoCacheTTL || defaultGeoCacheTTL;
|
|
1024
|
-
if (geoCacheTTL > this.maxGeoCacheTTL || geoCacheTTL < this.minGeoCacheTTL) {
|
|
1025
|
-
this.geoCacheTTL = defaultGeoCacheTTL;
|
|
1026
|
-
}
|
|
1020
|
+
constructor(postfix) {
|
|
1027
1021
|
this.postfix = "";
|
|
1028
1022
|
if (postfix)
|
|
1029
1023
|
this.postfix = "__" + postfix;
|
|
@@ -1037,7 +1031,7 @@ var SigmaGeoCache = class {
|
|
|
1037
1031
|
}
|
|
1038
1032
|
set(key, value) {
|
|
1039
1033
|
try {
|
|
1040
|
-
return sigmaGeoCache.set(key + this.postfix, value
|
|
1034
|
+
return sigmaGeoCache.set(key + this.postfix, value);
|
|
1041
1035
|
} catch (e) {
|
|
1042
1036
|
console.log(e);
|
|
1043
1037
|
}
|
|
@@ -1268,7 +1262,7 @@ function generateFilteredList(array, name) {
|
|
|
1268
1262
|
}
|
|
1269
1263
|
|
|
1270
1264
|
// package.json
|
|
1271
|
-
var version = "3.3.
|
|
1265
|
+
var version = "3.3.6";
|
|
1272
1266
|
|
|
1273
1267
|
// src/helpers/sdkVersion.js
|
|
1274
1268
|
var sdkVersion = version;
|
|
@@ -1323,7 +1317,6 @@ var Sigma = class {
|
|
|
1323
1317
|
this.api = options.api || defaultApi;
|
|
1324
1318
|
this.retries = options.retries || 2;
|
|
1325
1319
|
this.postfix = options.postfix || "";
|
|
1326
|
-
this.geoCacheTTL = options.geoCacheTTL || defaultGeoCacheTTL;
|
|
1327
1320
|
this.sigmaUserData = new SigmaUserData();
|
|
1328
1321
|
this.cache = new SigmaCache(this.postfix);
|
|
1329
1322
|
this.sigmaUserData.init({
|
|
@@ -1346,7 +1339,7 @@ var Sigma = class {
|
|
|
1346
1339
|
});
|
|
1347
1340
|
this.setSplitIdsToCache(this.userData);
|
|
1348
1341
|
this.makePrivateIdInCache();
|
|
1349
|
-
this.geoCache = new SigmaGeoCache(`${this.cache.get(sigmaPrivateId)}__${this.token}
|
|
1342
|
+
this.geoCache = new SigmaGeoCache(`${this.cache.get(sigmaPrivateId)}__${this.token}`);
|
|
1350
1343
|
}
|
|
1351
1344
|
setSplitIdsToCache(userData) {
|
|
1352
1345
|
for (let [key, value] of Object.entries(userData)) {
|
|
@@ -1463,14 +1456,20 @@ var Sigma = class {
|
|
|
1463
1456
|
console.error(errorMessages.APIRequestErrorConfig);
|
|
1464
1457
|
}
|
|
1465
1458
|
}
|
|
1459
|
+
this.recordLastUpdateInCache();
|
|
1460
|
+
}
|
|
1461
|
+
async saveToGeoCache() {
|
|
1466
1462
|
try {
|
|
1467
1463
|
await this.getUserGeoData();
|
|
1468
|
-
|
|
1464
|
+
this.geoCache.get(sigmaGeoData) ? this.sigmaUserData.setGeo(this.geoCache.parse(sigmaGeoData)) : this.sigmaUserData.setGeo("{}");
|
|
1465
|
+
} catch (error) {
|
|
1469
1466
|
if (!this.geoCache.get(sigmaGeoData)) {
|
|
1470
1467
|
this.geoCache.set(sigmaGeoData, JSON.stringify({ location: "none" }));
|
|
1471
1468
|
}
|
|
1469
|
+
errorMessages.APIRequestErrorGeoData.token = this.token;
|
|
1470
|
+
errorMessages.APIRequestErrorGeoData.userData = JSON.stringify(this.userData);
|
|
1471
|
+
console.error(error, errorMessages.APIRequestErrorGeoData);
|
|
1472
1472
|
}
|
|
1473
|
-
this.recordLastUpdateInCache();
|
|
1474
1473
|
}
|
|
1475
1474
|
hasExpireCache() {
|
|
1476
1475
|
const lastUpdate = Number(this.cache.get(sigmaDataFileLastUpdate));
|
|
@@ -1486,6 +1485,11 @@ var Sigma = class {
|
|
|
1486
1485
|
}
|
|
1487
1486
|
return true;
|
|
1488
1487
|
}
|
|
1488
|
+
updateGeoCache() {
|
|
1489
|
+
if (!this.geoCache.get(sigmaGeoData)) {
|
|
1490
|
+
this.saveToGeoCache();
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1489
1493
|
async getFlags() {
|
|
1490
1494
|
await this.updateCache();
|
|
1491
1495
|
const flags = this.cache.parse(sigmaDataFile);
|
|
@@ -1497,10 +1501,10 @@ var Sigma = class {
|
|
|
1497
1501
|
if (!flagName)
|
|
1498
1502
|
return null;
|
|
1499
1503
|
await this.updateCache();
|
|
1504
|
+
await this.updateGeoCache();
|
|
1500
1505
|
const cacheKey = this.cache.parse(sigmaDataFile);
|
|
1501
1506
|
if (!cacheKey.feature_flags)
|
|
1502
1507
|
return;
|
|
1503
|
-
this.sigmaUserData.setGeo(this.geoCache.parse(sigmaGeoData));
|
|
1504
1508
|
let flag = null;
|
|
1505
1509
|
const expName = this.getExperimentByFeatureFlag(cacheKey, flagName);
|
|
1506
1510
|
if (expName) {
|
|
@@ -1521,8 +1525,8 @@ var Sigma = class {
|
|
|
1521
1525
|
async getUserFeatureFlagsDetails() {
|
|
1522
1526
|
const featureFlags = [];
|
|
1523
1527
|
await this.updateCache();
|
|
1528
|
+
await this.updateGeoCache();
|
|
1524
1529
|
const sigmaDataLs = await this.cache.parse(sigmaDataFile);
|
|
1525
|
-
this.sigmaUserData.setGeo(this.geoCache.parse(sigmaGeoData));
|
|
1526
1530
|
if (sigmaDataLs.feature_flags.length > 0) {
|
|
1527
1531
|
for (const flag in sigmaDataLs.feature_flags) {
|
|
1528
1532
|
const ffName = sigmaDataLs.feature_flags[flag].name;
|
|
@@ -1663,7 +1667,7 @@ var Sigma = class {
|
|
|
1663
1667
|
userValue,
|
|
1664
1668
|
targets.conditions[index].value,
|
|
1665
1669
|
targets.conditions[index].condition_sign,
|
|
1666
|
-
this.sigmaUserData.user.
|
|
1670
|
+
this.sigmaUserData.user.date,
|
|
1667
1671
|
this.sigmaUserData.user.time
|
|
1668
1672
|
)
|
|
1669
1673
|
);
|
|
@@ -1689,6 +1693,7 @@ var Sigma = class {
|
|
|
1689
1693
|
if (!experimentName)
|
|
1690
1694
|
return null;
|
|
1691
1695
|
await this.updateCache();
|
|
1696
|
+
await this.updateGeoCache();
|
|
1692
1697
|
const sigmaDataLs = await this.cache.parse(sigmaDataFile);
|
|
1693
1698
|
this.sigmaUserData.setGeo(this.geoCache.parse(sigmaGeoData));
|
|
1694
1699
|
if (!sigmaDataLs.experiments)
|
|
@@ -1786,6 +1791,7 @@ var Sigma = class {
|
|
|
1786
1791
|
}
|
|
1787
1792
|
async getAllUserExperiments() {
|
|
1788
1793
|
await this.updateCache();
|
|
1794
|
+
await this.updateGeoCache();
|
|
1789
1795
|
const sigmaDataLs = this.cache.parse(sigmaDataFile);
|
|
1790
1796
|
if (!sigmaDataLs.experiments.length)
|
|
1791
1797
|
return null;
|
|
@@ -1876,7 +1882,7 @@ var Sigma = class {
|
|
|
1876
1882
|
userValue,
|
|
1877
1883
|
conditions[i].value,
|
|
1878
1884
|
conditions[i].condition_sign,
|
|
1879
|
-
this.sigmaUserData.user.
|
|
1885
|
+
this.sigmaUserData.user.date,
|
|
1880
1886
|
this.sigmaUserData.user.time
|
|
1881
1887
|
)
|
|
1882
1888
|
);
|
|
@@ -2110,25 +2116,12 @@ var Sigma = class {
|
|
|
2110
2116
|
console.warn(`Sigma warn: Experiment ${experimentId} has not group with index ${groupIndex}`);
|
|
2111
2117
|
return;
|
|
2112
2118
|
}
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
return;
|
|
2116
|
-
}
|
|
2117
|
-
if (splitById && this.userData[splitById] && !groupInExperiment.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2119
|
+
this.clearForcedList(experiment, splitById);
|
|
2120
|
+
if (this.userData[splitById] && !groupInExperiment.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2118
2121
|
groupInExperiment.forced_user_list.push(String(this.userData[splitById]));
|
|
2119
2122
|
}
|
|
2120
2123
|
} else if (!groupIndex) {
|
|
2121
|
-
|
|
2122
|
-
for (const group of experiment.groups) {
|
|
2123
|
-
if (splitById && group.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2124
|
-
isUserInForcedGroup = true;
|
|
2125
|
-
break;
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
if (isUserInForcedGroup) {
|
|
2129
|
-
console.warn(`Sigma warn: User is already group in experiment ${experimentId}. You need to exclude first then run method again`);
|
|
2130
|
-
return;
|
|
2131
|
-
}
|
|
2124
|
+
this.clearForcedList(experiment, splitById);
|
|
2132
2125
|
if (this.userData[splitById] && !experiment.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2133
2126
|
experiment.forced_user_list.push(String(this.userData[splitById]));
|
|
2134
2127
|
}
|
|
@@ -2136,68 +2129,64 @@ var Sigma = class {
|
|
|
2136
2129
|
if (!this.cache.get(sigmaForcedExperiments)) {
|
|
2137
2130
|
this.cache.set(sigmaForcedExperiments, JSON.stringify([{ experimentId, groupIndex }]));
|
|
2138
2131
|
} else {
|
|
2139
|
-
const forcedExperiments =
|
|
2140
|
-
|
|
2132
|
+
const forcedExperiments = this.cache.parse(sigmaForcedExperiments);
|
|
2133
|
+
const foundingForcedExperiment = forcedExperiments.find((el) => el.experimentId === experimentId);
|
|
2134
|
+
if (!foundingForcedExperiment) {
|
|
2141
2135
|
forcedExperiments.push({ experimentId, groupIndex });
|
|
2142
2136
|
this.cache.set(sigmaForcedExperiments, JSON.stringify(forcedExperiments));
|
|
2137
|
+
} else if (typeof groupIndex === "number" && groupIndex >= 0 && foundingForcedExperiment) {
|
|
2138
|
+
foundingForcedExperiment.groupIndex = groupIndex;
|
|
2139
|
+
this.cache.set(sigmaForcedExperiments, JSON.stringify(forcedExperiments));
|
|
2140
|
+
} else if (!groupIndex && foundingForcedExperiment) {
|
|
2141
|
+
foundingForcedExperiment.groupIndex = groupIndex;
|
|
2142
|
+
this.cache.set(sigmaForcedExperiments, JSON.stringify(forcedExperiments));
|
|
2143
2143
|
}
|
|
2144
2144
|
}
|
|
2145
2145
|
this.cache.set(sigmaDataFile, JSON.stringify(sigmaDataLs));
|
|
2146
2146
|
}
|
|
2147
|
-
|
|
2148
|
-
if (
|
|
2147
|
+
clearForcedList(experiment, splitById) {
|
|
2148
|
+
if (experiment.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2149
|
+
experiment.forced_user_list = experiment.forced_user_list.filter((el) => String(el) !== String(this.userData[splitById]));
|
|
2150
|
+
}
|
|
2151
|
+
for (const group of experiment.groups) {
|
|
2152
|
+
if (group.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2153
|
+
group.forced_user_list = group.forced_user_list.filter((el) => String(el) !== String(this.userData[splitById]));
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
async excludeForceUser(experimentId) {
|
|
2158
|
+
if (!experimentId || !this.cache.get(sigmaDataFile) || !this.cache.get(sigmaForcedExperiments))
|
|
2149
2159
|
return;
|
|
2150
2160
|
const sigmaDataLs = this.cache.parse(sigmaDataFile);
|
|
2151
2161
|
if (!sigmaDataLs || !sigmaDataLs.experiments)
|
|
2152
2162
|
return;
|
|
2153
2163
|
let experiment = sigmaDataLs.experiments.find((exp) => exp.name === experimentId);
|
|
2154
|
-
if (!experiment)
|
|
2155
|
-
|
|
2156
|
-
if (!Object.keys(this.userData).includes(experiment.split_by))
|
|
2164
|
+
if (!experiment) {
|
|
2165
|
+
console.warn(`Sigma warn: Experiment ${experimentId} not found`);
|
|
2157
2166
|
return;
|
|
2158
|
-
const splitById = Object.keys(this.userData).find((id) => id === experiment.split_by);
|
|
2159
|
-
if (experiment.forced_user_list.length && experiment.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2160
|
-
experiment.forced_user_list = experiment.forced_user_list.filter((el) => el !== String(this.userData[splitById]));
|
|
2161
2167
|
}
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
group.forced_user_list = group.forced_user_list.filter((el) => el !== String(this.userData[splitById]));
|
|
2166
|
-
}
|
|
2168
|
+
if (!Object.keys(this.userData).includes(experiment.split_by)) {
|
|
2169
|
+
console.warn(`Sigma warn: ${experiment.split_by} is missing in userData`);
|
|
2170
|
+
return;
|
|
2167
2171
|
}
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2172
|
+
let forcedExperiments = this.cache.parse(sigmaForcedExperiments);
|
|
2173
|
+
if (!forcedExperiments.find((el) => el.experimentId === experimentId))
|
|
2174
|
+
return;
|
|
2175
|
+
forcedExperiments = forcedExperiments.filter((el) => el.experimentId !== experimentId);
|
|
2176
|
+
if (forcedExperiments.length > 0) {
|
|
2177
|
+
this.cache.set(sigmaForcedExperiments, JSON.stringify(forcedExperiments));
|
|
2178
|
+
} else {
|
|
2179
|
+
this.cache.remove(sigmaForcedExperiments);
|
|
2176
2180
|
}
|
|
2177
|
-
this.cache.set(
|
|
2181
|
+
this.cache.set(sigmaHash, "");
|
|
2182
|
+
await this.saveToCache();
|
|
2178
2183
|
}
|
|
2179
|
-
excludeForceUserAll() {
|
|
2180
|
-
if (!this.cache.get(sigmaDataFile))
|
|
2181
|
-
return;
|
|
2182
|
-
const sigmaDataLs = this.cache.parse(sigmaDataFile);
|
|
2183
|
-
if (!sigmaDataLs || !sigmaDataLs.experiments)
|
|
2184
|
+
async excludeForceUserAll() {
|
|
2185
|
+
if (!this.cache.get(sigmaDataFile) || !this.cache.get(sigmaForcedExperiments))
|
|
2184
2186
|
return;
|
|
2185
|
-
for (const experiment of sigmaDataLs.experiments) {
|
|
2186
|
-
if (!Object.keys(this.userData).includes(experiment.split_by))
|
|
2187
|
-
continue;
|
|
2188
|
-
const splitById = Object.keys(this.userData).find((id) => id === experiment.split_by);
|
|
2189
|
-
if (experiment.forced_user_list.length && experiment.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2190
|
-
experiment.forced_user_list = experiment.forced_user_list.filter((el) => el !== String(this.userData[splitById]));
|
|
2191
|
-
}
|
|
2192
|
-
const groups = experiment.groups;
|
|
2193
|
-
for (const group of groups) {
|
|
2194
|
-
if (group.forced_user_list.length && group.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2195
|
-
group.forced_user_list = group.forced_user_list.filter((el) => el !== String(this.userData[splitById]));
|
|
2196
|
-
}
|
|
2197
|
-
}
|
|
2198
|
-
}
|
|
2199
2187
|
this.cache.remove(sigmaForcedExperiments);
|
|
2200
|
-
this.cache.set(
|
|
2188
|
+
this.cache.set(sigmaHash, "");
|
|
2189
|
+
await this.saveToCache();
|
|
2201
2190
|
}
|
|
2202
2191
|
checkForceExperiments() {
|
|
2203
2192
|
if (!this.cache.get(sigmaForcedExperiments))
|