expf-sigma-node.js 3.3.3 → 3.3.4
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 +127 -1
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.4",
|
|
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.4";
|
|
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
|
}
|
|
@@ -2082,6 +2086,128 @@ 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
|
+
if (splitById && experiment.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2114
|
+
console.warn(`Sigma warn: User is already in experiment ${experimentId}. You need to exclude first then run method again`);
|
|
2115
|
+
return;
|
|
2116
|
+
}
|
|
2117
|
+
if (splitById && this.userData[splitById] && !groupInExperiment.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2118
|
+
groupInExperiment.forced_user_list.push(String(this.userData[splitById]));
|
|
2119
|
+
}
|
|
2120
|
+
} else if (!groupIndex) {
|
|
2121
|
+
let isUserInForcedGroup = false;
|
|
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
|
+
}
|
|
2132
|
+
if (this.userData[splitById] && !experiment.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2133
|
+
experiment.forced_user_list.push(String(this.userData[splitById]));
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
if (!this.cache.get(sigmaForcedExperiments)) {
|
|
2137
|
+
this.cache.set(sigmaForcedExperiments, JSON.stringify([{ experimentId, groupIndex }]));
|
|
2138
|
+
} else {
|
|
2139
|
+
const forcedExperiments = JSON.parse(this.cache.get(sigmaForcedExperiments));
|
|
2140
|
+
if (!forcedExperiments.find((el) => el.experimentId === experimentId)) {
|
|
2141
|
+
forcedExperiments.push({ experimentId, groupIndex });
|
|
2142
|
+
this.cache.set(sigmaForcedExperiments, JSON.stringify(forcedExperiments));
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
this.cache.set(sigmaDataFile, JSON.stringify(sigmaDataLs));
|
|
2146
|
+
}
|
|
2147
|
+
excludeForceUser(experimentId) {
|
|
2148
|
+
if (!experimentId || !this.cache.get(sigmaDataFile))
|
|
2149
|
+
return;
|
|
2150
|
+
const sigmaDataLs = this.cache.parse(sigmaDataFile);
|
|
2151
|
+
if (!sigmaDataLs || !sigmaDataLs.experiments)
|
|
2152
|
+
return;
|
|
2153
|
+
let experiment = sigmaDataLs.experiments.find((exp) => exp.name === experimentId);
|
|
2154
|
+
if (!experiment)
|
|
2155
|
+
return;
|
|
2156
|
+
if (!Object.keys(this.userData).includes(experiment.split_by))
|
|
2157
|
+
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
|
+
}
|
|
2162
|
+
const groups = experiment.groups;
|
|
2163
|
+
for (const group of groups) {
|
|
2164
|
+
if (group.forced_user_list.length && group.forced_user_list.includes(String(this.userData[splitById]))) {
|
|
2165
|
+
group.forced_user_list = group.forced_user_list.filter((el) => el !== String(this.userData[splitById]));
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
if (this.cache.get(sigmaForcedExperiments)) {
|
|
2169
|
+
let forcedExperiments = JSON.parse(this.cache.get(sigmaForcedExperiments));
|
|
2170
|
+
forcedExperiments = forcedExperiments.filter((el) => el.experimentId !== experimentId);
|
|
2171
|
+
if (forcedExperiments.length > 0) {
|
|
2172
|
+
this.cache.set(sigmaForcedExperiments, JSON.stringify(forcedExperiments));
|
|
2173
|
+
} else {
|
|
2174
|
+
this.cache.remove(sigmaForcedExperiments);
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
this.cache.set(sigmaDataFile, JSON.stringify(sigmaDataLs));
|
|
2178
|
+
}
|
|
2179
|
+
excludeForceUserAll() {
|
|
2180
|
+
if (!this.cache.get(sigmaDataFile))
|
|
2181
|
+
return;
|
|
2182
|
+
const sigmaDataLs = this.cache.parse(sigmaDataFile);
|
|
2183
|
+
if (!sigmaDataLs || !sigmaDataLs.experiments)
|
|
2184
|
+
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
|
+
this.cache.remove(sigmaForcedExperiments);
|
|
2200
|
+
this.cache.set(sigmaDataFile, JSON.stringify(sigmaDataLs));
|
|
2201
|
+
}
|
|
2202
|
+
checkForceExperiments() {
|
|
2203
|
+
if (!this.cache.get(sigmaForcedExperiments))
|
|
2204
|
+
return;
|
|
2205
|
+
const forcedExperiments = JSON.parse(this.cache.get(sigmaForcedExperiments));
|
|
2206
|
+
for (const forceExperiment of forcedExperiments) {
|
|
2207
|
+
this.setForceUser(forceExperiment.experimentId, forceExperiment.groupIndex);
|
|
2208
|
+
}
|
|
2209
|
+
return;
|
|
2210
|
+
}
|
|
2085
2211
|
};
|
|
2086
2212
|
var sigma_default = Sigma;
|
|
2087
2213
|
// Annotate the CommonJS export names for ESM import in node:
|