expf-sigma-node.js 3.2.2 → 3.2.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 +37 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expf-sigma-node.js",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.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
|
@@ -783,6 +783,7 @@ var SHA256 = new sigmaHashes_default.SHA256();
|
|
|
783
783
|
var MD5 = new sigmaHashes_default.MD5();
|
|
784
784
|
var expirationDate = 24 * 60 * 60 * 1e3;
|
|
785
785
|
var secondsIn24Hours = 24 * 60 * 60;
|
|
786
|
+
var sigmaGeoData = "sigmaGeoData";
|
|
786
787
|
|
|
787
788
|
// src/modules/sigmaCache.js
|
|
788
789
|
var sigmaCache = new import_node_cache.default({ stdTTL: secondsIn24Hours });
|
|
@@ -903,7 +904,7 @@ function compareVersions(versionA, versionB, strict = true) {
|
|
|
903
904
|
}
|
|
904
905
|
|
|
905
906
|
// src/helpers/conditionOperation.js
|
|
906
|
-
function conditionOperation(userValue, conditionValues, operation) {
|
|
907
|
+
function conditionOperation(userValue, conditionValues, operation, date, time) {
|
|
907
908
|
!operation ? operation = "=" : operation;
|
|
908
909
|
if (userValue === null || typeof userValue === "undefined" || !conditionValues)
|
|
909
910
|
return false;
|
|
@@ -944,11 +945,11 @@ function conditionOperation(userValue, conditionValues, operation) {
|
|
|
944
945
|
case "on date":
|
|
945
946
|
return Math.floor(
|
|
946
947
|
new Date(conditionValues.trim()).getTime() / (1e3 * 60 * 60 * 24)
|
|
947
|
-
) ==
|
|
948
|
+
) == date;
|
|
948
949
|
case "after time":
|
|
949
|
-
return new Date(conditionValues.trim()).getTime() / (1e3 * 60 * 60) <
|
|
950
|
+
return new Date(conditionValues.trim()).getTime() / (1e3 * 60 * 60) < time;
|
|
950
951
|
case "before time":
|
|
951
|
-
return new Date(conditionValues.trim()).getTime() / (1e3 * 60 * 60) >
|
|
952
|
+
return new Date(conditionValues.trim()).getTime() / (1e3 * 60 * 60) > time;
|
|
952
953
|
case "starts with":
|
|
953
954
|
return userValue.startsWith(conditionValues);
|
|
954
955
|
case "not starts with":
|
|
@@ -1079,6 +1080,7 @@ var Sigma = class {
|
|
|
1079
1080
|
this.sigmaUserData = new SigmaUserData();
|
|
1080
1081
|
this.postfix = options.postfix || "";
|
|
1081
1082
|
this.cache = new SigmaCache(this.postfix);
|
|
1083
|
+
this.geoCache = new SigmaGeoCache(`${this.userData.ip}__${this.token}`, options.geoCacheTTL);
|
|
1082
1084
|
this.sigmaUserData.init({
|
|
1083
1085
|
userId: this.userData.userId || null,
|
|
1084
1086
|
profileId: this.userData.profileId || null,
|
|
@@ -1090,13 +1092,12 @@ var Sigma = class {
|
|
|
1090
1092
|
deviceCategory: this.userData.deviceCategory || null,
|
|
1091
1093
|
browser: this.userData.browser || { version: null, name: null },
|
|
1092
1094
|
os: this.userData.os || { version: null, name: null },
|
|
1093
|
-
geo: this.userData.geo ||
|
|
1095
|
+
geo: this.userData.ip ? this.geoCache.get(sigmaGeoData) : this.userData.geo || this.sigmaUserData.user.geo,
|
|
1094
1096
|
domain: this.userData.domain || null,
|
|
1095
1097
|
url: this.userData.url || null,
|
|
1096
1098
|
query: this.userData.query || null,
|
|
1097
1099
|
pathname: this.userData.pathname || null
|
|
1098
1100
|
});
|
|
1099
|
-
this.geoCache = new SigmaGeoCache(this.token, options.geoCacheTTL);
|
|
1100
1101
|
this.setSplitIdsToCache(this.userData);
|
|
1101
1102
|
this.makePrivateIdInCache();
|
|
1102
1103
|
}
|
|
@@ -1177,32 +1178,9 @@ var Sigma = class {
|
|
|
1177
1178
|
throw new Error(`Get geo: ${error}`);
|
|
1178
1179
|
}
|
|
1179
1180
|
}
|
|
1180
|
-
async setUserGeoData() {
|
|
1181
|
-
if (!this.userData.ip)
|
|
1182
|
-
return;
|
|
1183
|
-
const geoKey = `${this.userData.ip}__${this.token}`;
|
|
1184
|
-
const foundingGeoKey = this.geoCache.keys().find((k) => k === geoKey);
|
|
1185
|
-
if (foundingGeoKey) {
|
|
1186
|
-
const userGeoData = this.geoCache.get(this.userData.ip);
|
|
1187
|
-
this.sigmaUserData.setGeo(userGeoData);
|
|
1188
|
-
return;
|
|
1189
|
-
} else {
|
|
1190
|
-
const userGeoData = await this.getUserGeoData();
|
|
1191
|
-
this.geoCache.set(this.userData.ip, userGeoData);
|
|
1192
|
-
this.sigmaUserData.setGeo(userGeoData);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
1181
|
async saveToCache() {
|
|
1196
1182
|
const { api } = this;
|
|
1197
1183
|
const localStorageHash = this.cache.get(sigmaHash);
|
|
1198
|
-
try {
|
|
1199
|
-
const timeRecord = Math.floor(Date.now() / 1e3);
|
|
1200
|
-
this.cache.set(sigmaDataFileLastUpdate, timeRecord);
|
|
1201
|
-
} catch (error) {
|
|
1202
|
-
throw new Error(`save last update to cache: ${error},
|
|
1203
|
-
token: ${this.token}
|
|
1204
|
-
`);
|
|
1205
|
-
}
|
|
1206
1184
|
let data;
|
|
1207
1185
|
try {
|
|
1208
1186
|
data = await this.getDataFile(`${api}/config.json`);
|
|
@@ -1229,6 +1207,30 @@ var Sigma = class {
|
|
|
1229
1207
|
} catch (error) {
|
|
1230
1208
|
throw new Error(`Save data to local storage`);
|
|
1231
1209
|
}
|
|
1210
|
+
try {
|
|
1211
|
+
if (this.userData.ip) {
|
|
1212
|
+
const userGeoData = await this.getUserGeoData();
|
|
1213
|
+
this.geoCache.set(sigmaGeoData, JSON.stringify(userGeoData));
|
|
1214
|
+
this.sigmaUserData.setGeo(userGeoData);
|
|
1215
|
+
} else if (this.userData.geo) {
|
|
1216
|
+
this.geoCache.set(sigmaGeoData, JSON.stringify(this.userData.geo));
|
|
1217
|
+
this.sigmaUserData.setGeo(this.userData.geo);
|
|
1218
|
+
} else {
|
|
1219
|
+
this.geoCache.set(sigmaGeoData, JSON.stringify({ location: "none" }));
|
|
1220
|
+
this.sigmaUserData.setGeo({ location: "none" });
|
|
1221
|
+
}
|
|
1222
|
+
} catch {
|
|
1223
|
+
this.geoCache.set(sigmaGeoData, JSON.stringify({ location: "none" }));
|
|
1224
|
+
this.sigmaUserData.setGeo({ location: "none" });
|
|
1225
|
+
}
|
|
1226
|
+
try {
|
|
1227
|
+
const timeRecord = Math.floor(Date.now() / 1e3);
|
|
1228
|
+
this.cache.set(sigmaDataFileLastUpdate, timeRecord);
|
|
1229
|
+
} catch (error) {
|
|
1230
|
+
throw new Error(`save last update to cache: ${error},
|
|
1231
|
+
token: ${this.token}
|
|
1232
|
+
`);
|
|
1233
|
+
}
|
|
1232
1234
|
}
|
|
1233
1235
|
hasExpireCache() {
|
|
1234
1236
|
const lastUpdate = parseInt(
|
|
@@ -1258,7 +1260,6 @@ var Sigma = class {
|
|
|
1258
1260
|
return null;
|
|
1259
1261
|
}
|
|
1260
1262
|
await this.updateCache();
|
|
1261
|
-
await this.setUserGeoData();
|
|
1262
1263
|
const cacheKey = this.cache.parse(sigmaDataFile);
|
|
1263
1264
|
if (!cacheKey.feature_flags)
|
|
1264
1265
|
return;
|
|
@@ -1404,7 +1405,9 @@ var Sigma = class {
|
|
|
1404
1405
|
conditionOperation(
|
|
1405
1406
|
userValue,
|
|
1406
1407
|
targets.conditions[index].value,
|
|
1407
|
-
targets.conditions[index].condition_sign
|
|
1408
|
+
targets.conditions[index].condition_sign,
|
|
1409
|
+
this.sigmaUserData.user.data,
|
|
1410
|
+
this.sigmaUserData.user.time
|
|
1408
1411
|
)
|
|
1409
1412
|
);
|
|
1410
1413
|
}
|
|
@@ -1430,7 +1433,6 @@ var Sigma = class {
|
|
|
1430
1433
|
return null;
|
|
1431
1434
|
}
|
|
1432
1435
|
await this.updateCache();
|
|
1433
|
-
await this.setUserGeoData();
|
|
1434
1436
|
const sigmaDataLs = await this.cache.parse(sigmaDataFile);
|
|
1435
1437
|
if (!sigmaDataLs.experiments) {
|
|
1436
1438
|
throw new Error("Experiments not found in cache");
|
|
@@ -1616,7 +1618,9 @@ var Sigma = class {
|
|
|
1616
1618
|
conditionOperation(
|
|
1617
1619
|
userValue,
|
|
1618
1620
|
conditions[i].value,
|
|
1619
|
-
conditions[i].condition_sign
|
|
1621
|
+
conditions[i].condition_sign,
|
|
1622
|
+
this.sigmaUserData.user.data,
|
|
1623
|
+
this.sigmaUserData.user.time
|
|
1620
1624
|
)
|
|
1621
1625
|
);
|
|
1622
1626
|
}
|