expf-sigma-node.js 3.3.3 → 3.3.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 +112 -3
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.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
|
@@ -967,6 +967,7 @@ var statusSuccess = "success";
|
|
|
967
967
|
var statusFailed = "failed";
|
|
968
968
|
var status200 = 200;
|
|
969
969
|
var status400 = 400;
|
|
970
|
+
var sigmaForcedExperiments = "sigmaForcedExperiments";
|
|
970
971
|
|
|
971
972
|
// src/modules/sigmaCache.js
|
|
972
973
|
var sigmaCache = new import_node_cache.default({
|
|
@@ -1256,6 +1257,8 @@ function generateFilteredList(array, name) {
|
|
|
1256
1257
|
return item;
|
|
1257
1258
|
}
|
|
1258
1259
|
} else {
|
|
1260
|
+
if (!item.platform || item.platform === "all")
|
|
1261
|
+
return item;
|
|
1259
1262
|
if (item.platform === listName[index])
|
|
1260
1263
|
return item;
|
|
1261
1264
|
}
|
|
@@ -1265,7 +1268,7 @@ function generateFilteredList(array, name) {
|
|
|
1265
1268
|
}
|
|
1266
1269
|
|
|
1267
1270
|
// package.json
|
|
1268
|
-
var version = "3.3.
|
|
1271
|
+
var version = "3.3.5";
|
|
1269
1272
|
|
|
1270
1273
|
// src/helpers/sdkVersion.js
|
|
1271
1274
|
var sdkVersion = version;
|
|
@@ -1412,6 +1415,7 @@ var Sigma = class {
|
|
|
1412
1415
|
if (!localStorageHash || localStorageHash !== hash) {
|
|
1413
1416
|
this.cache.set(sigmaHash, hash);
|
|
1414
1417
|
this.cache.set(sigmaDataFile, JSON.stringify(data.data));
|
|
1418
|
+
this.checkForceExperiments();
|
|
1415
1419
|
}
|
|
1416
1420
|
return;
|
|
1417
1421
|
}
|
|
@@ -1659,7 +1663,7 @@ var Sigma = class {
|
|
|
1659
1663
|
userValue,
|
|
1660
1664
|
targets.conditions[index].value,
|
|
1661
1665
|
targets.conditions[index].condition_sign,
|
|
1662
|
-
this.sigmaUserData.user.
|
|
1666
|
+
this.sigmaUserData.user.date,
|
|
1663
1667
|
this.sigmaUserData.user.time
|
|
1664
1668
|
)
|
|
1665
1669
|
);
|
|
@@ -1872,7 +1876,7 @@ var Sigma = class {
|
|
|
1872
1876
|
userValue,
|
|
1873
1877
|
conditions[i].value,
|
|
1874
1878
|
conditions[i].condition_sign,
|
|
1875
|
-
this.sigmaUserData.user.
|
|
1879
|
+
this.sigmaUserData.user.date,
|
|
1876
1880
|
this.sigmaUserData.user.time
|
|
1877
1881
|
)
|
|
1878
1882
|
);
|
|
@@ -2082,6 +2086,111 @@ var Sigma = class {
|
|
|
2082
2086
|
}
|
|
2083
2087
|
};
|
|
2084
2088
|
}
|
|
2089
|
+
async includeForceUser(experimentId, groupIndex = null) {
|
|
2090
|
+
if (!experimentId)
|
|
2091
|
+
return;
|
|
2092
|
+
await this.updateCache();
|
|
2093
|
+
this.setForceUser(experimentId, groupIndex);
|
|
2094
|
+
}
|
|
2095
|
+
setForceUser(experimentId, groupIndex) {
|
|
2096
|
+
const sigmaDataLs = this.cache.parse(sigmaDataFile);
|
|
2097
|
+
if (!sigmaDataLs.experiments)
|
|
2098
|
+
return;
|
|
2099
|
+
const experiment = sigmaDataLs.experiments.find((exp) => exp.name === experimentId);
|
|
2100
|
+
if (!experiment)
|
|
2101
|
+
return;
|
|
2102
|
+
if (!Object.keys(this.userData).includes(experiment.split_by)) {
|
|
2103
|
+
console.warn(`Sigma warn: ${experiment.split_by} is missing in userData`);
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
const splitById = Object.keys(this.userData).find((id) => id === experiment.split_by);
|
|
2107
|
+
if (typeof groupIndex === "number" && groupIndex >= 0) {
|
|
2108
|
+
const groupInExperiment = experiment.groups[groupIndex];
|
|
2109
|
+
if (!groupInExperiment) {
|
|
2110
|
+
console.warn(`Sigma warn: Experiment ${experimentId} has not group with index ${groupIndex}`);
|
|
2111
|
+
return;
|
|
2112
|
+
}
|
|
2113
|
+
this.clearForcedList(experiment, splitById);
|
|
2114
|
+
if (this.userData[splitById] && !groupInExperiment.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2115
|
+
groupInExperiment.forced_user_list.push(String(this.userData[splitById]));
|
|
2116
|
+
}
|
|
2117
|
+
} else if (!groupIndex) {
|
|
2118
|
+
this.clearForcedList(experiment, splitById);
|
|
2119
|
+
if (this.userData[splitById] && !experiment.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2120
|
+
experiment.forced_user_list.push(String(this.userData[splitById]));
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
if (!this.cache.get(sigmaForcedExperiments)) {
|
|
2124
|
+
this.cache.set(sigmaForcedExperiments, JSON.stringify([{ experimentId, groupIndex }]));
|
|
2125
|
+
} else {
|
|
2126
|
+
const forcedExperiments = this.cache.parse(sigmaForcedExperiments);
|
|
2127
|
+
const foundingForcedExperiment = forcedExperiments.find((el) => el.experimentId === experimentId);
|
|
2128
|
+
if (!foundingForcedExperiment) {
|
|
2129
|
+
forcedExperiments.push({ experimentId, groupIndex });
|
|
2130
|
+
this.cache.set(sigmaForcedExperiments, JSON.stringify(forcedExperiments));
|
|
2131
|
+
} else if (typeof groupIndex === "number" && groupIndex >= 0 && foundingForcedExperiment) {
|
|
2132
|
+
foundingForcedExperiment.groupIndex = groupIndex;
|
|
2133
|
+
this.cache.set(sigmaForcedExperiments, JSON.stringify(forcedExperiments));
|
|
2134
|
+
} else if (!groupIndex && foundingForcedExperiment) {
|
|
2135
|
+
foundingForcedExperiment.groupIndex = groupIndex;
|
|
2136
|
+
this.cache.set(sigmaForcedExperiments, JSON.stringify(forcedExperiments));
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
this.cache.set(sigmaDataFile, JSON.stringify(sigmaDataLs));
|
|
2140
|
+
}
|
|
2141
|
+
clearForcedList(experiment, splitById) {
|
|
2142
|
+
if (experiment.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2143
|
+
experiment.forced_user_list = experiment.forced_user_list.filter((el) => String(el) !== String(this.userData[splitById]));
|
|
2144
|
+
}
|
|
2145
|
+
for (const group of experiment.groups) {
|
|
2146
|
+
if (group.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2147
|
+
group.forced_user_list = group.forced_user_list.filter((el) => String(el) !== String(this.userData[splitById]));
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
async excludeForceUser(experimentId) {
|
|
2152
|
+
if (!experimentId || !this.cache.get(sigmaDataFile) || !this.cache.get(sigmaForcedExperiments))
|
|
2153
|
+
return;
|
|
2154
|
+
const sigmaDataLs = this.cache.parse(sigmaDataFile);
|
|
2155
|
+
if (!sigmaDataLs || !sigmaDataLs.experiments)
|
|
2156
|
+
return;
|
|
2157
|
+
let experiment = sigmaDataLs.experiments.find((exp) => exp.name === experimentId);
|
|
2158
|
+
if (!experiment) {
|
|
2159
|
+
console.warn(`Sigma warn: Experiment ${experimentId} not found`);
|
|
2160
|
+
return;
|
|
2161
|
+
}
|
|
2162
|
+
if (!Object.keys(this.userData).includes(experiment.split_by)) {
|
|
2163
|
+
console.warn(`Sigma warn: ${experiment.split_by} is missing in userData`);
|
|
2164
|
+
return;
|
|
2165
|
+
}
|
|
2166
|
+
let forcedExperiments = this.cache.parse(sigmaForcedExperiments);
|
|
2167
|
+
if (!forcedExperiments.find((el) => el.experimentId === experimentId))
|
|
2168
|
+
return;
|
|
2169
|
+
forcedExperiments = forcedExperiments.filter((el) => el.experimentId !== experimentId);
|
|
2170
|
+
if (forcedExperiments.length > 0) {
|
|
2171
|
+
this.cache.set(sigmaForcedExperiments, JSON.stringify(forcedExperiments));
|
|
2172
|
+
} else {
|
|
2173
|
+
this.cache.remove(sigmaForcedExperiments);
|
|
2174
|
+
}
|
|
2175
|
+
this.cache.set(sigmaHash, "");
|
|
2176
|
+
await this.saveToCache();
|
|
2177
|
+
}
|
|
2178
|
+
async excludeForceUserAll() {
|
|
2179
|
+
if (!this.cache.get(sigmaDataFile) || !this.cache.get(sigmaForcedExperiments))
|
|
2180
|
+
return;
|
|
2181
|
+
this.cache.remove(sigmaForcedExperiments);
|
|
2182
|
+
this.cache.set(sigmaHash, "");
|
|
2183
|
+
await this.saveToCache();
|
|
2184
|
+
}
|
|
2185
|
+
checkForceExperiments() {
|
|
2186
|
+
if (!this.cache.get(sigmaForcedExperiments))
|
|
2187
|
+
return;
|
|
2188
|
+
const forcedExperiments = JSON.parse(this.cache.get(sigmaForcedExperiments));
|
|
2189
|
+
for (const forceExperiment of forcedExperiments) {
|
|
2190
|
+
this.setForceUser(forceExperiment.experimentId, forceExperiment.groupIndex);
|
|
2191
|
+
}
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2085
2194
|
};
|
|
2086
2195
|
var sigma_default = Sigma;
|
|
2087
2196
|
// Annotate the CommonJS export names for ESM import in node:
|