expf-sigma-node.js 3.0.0 → 3.0.2
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 +26 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expf-sigma-node.js",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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
|
@@ -148,6 +148,13 @@ var SigmaCache = class {
|
|
|
148
148
|
console.log(e);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
+
remove(key) {
|
|
152
|
+
try {
|
|
153
|
+
return sigmaCache.del(key + this.postfix);
|
|
154
|
+
} catch (e) {
|
|
155
|
+
console.log(e);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
151
158
|
parse(data) {
|
|
152
159
|
if (!this.get(data)) {
|
|
153
160
|
throw new Error(`${data} not found in cache`);
|
|
@@ -266,8 +273,8 @@ function doTypeConversion(type, value) {
|
|
|
266
273
|
return value;
|
|
267
274
|
}
|
|
268
275
|
|
|
269
|
-
// src/helpers/
|
|
270
|
-
function
|
|
276
|
+
// src/helpers/generateRandomId.js
|
|
277
|
+
function generateRandomId() {
|
|
271
278
|
let text = "";
|
|
272
279
|
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
273
280
|
for (let i = 0; i < 80; i++)
|
|
@@ -932,6 +939,7 @@ var defaultApi = "https://api.expf.ru/api/v1";
|
|
|
932
939
|
var sigmaUserId = "sigmaUserId";
|
|
933
940
|
var sigmaProfileId = "sigmaProfileId";
|
|
934
941
|
var sigmaDeviceId = "sigmaDeviceId";
|
|
942
|
+
var sigmaPrivateId = "sigmaPrivateId";
|
|
935
943
|
var sigmaHash = "sigmaHash";
|
|
936
944
|
var sigmaDataFileLastUpdate = "sigmaDataFileLastUpdate";
|
|
937
945
|
var sigmaDataFile = "sigmaDataFile";
|
|
@@ -981,40 +989,33 @@ var Sigma = class {
|
|
|
981
989
|
});
|
|
982
990
|
this.geoCache = new SigmaGeoCache(this.token, options.geoCacheTTL);
|
|
983
991
|
this.setSplitIdsToCache(this.userData);
|
|
992
|
+
this.makePrivateIdInCache();
|
|
984
993
|
}
|
|
985
994
|
setSplitIdsToCache(userData) {
|
|
986
995
|
for (let [key, value] of Object.entries(userData)) {
|
|
987
996
|
switch (key) {
|
|
988
997
|
case "userId":
|
|
989
|
-
if (value)
|
|
998
|
+
if (value && String(value).trim().length > 0)
|
|
990
999
|
this.cache.set(sigmaUserId, String(value).trim());
|
|
991
1000
|
break;
|
|
992
1001
|
case "profileId":
|
|
993
|
-
if (value)
|
|
1002
|
+
if (value && String(value).trim().length > 0)
|
|
994
1003
|
this.cache.set(sigmaProfileId, String(value).trim());
|
|
995
1004
|
break;
|
|
996
1005
|
case "deviceId":
|
|
997
|
-
if (value)
|
|
1006
|
+
if (value && String(value).trim().length > 0)
|
|
998
1007
|
this.cache.set(sigmaDeviceId, String(value).trim());
|
|
999
1008
|
break;
|
|
1000
1009
|
}
|
|
1001
1010
|
}
|
|
1002
1011
|
}
|
|
1003
|
-
|
|
1004
|
-
let
|
|
1005
|
-
if (
|
|
1006
|
-
|
|
1012
|
+
makePrivateIdInCache() {
|
|
1013
|
+
let privateId = this.cache.get(sigmaPrivateId);
|
|
1014
|
+
if (!privateId) {
|
|
1015
|
+
privateId = generateRandomId();
|
|
1016
|
+
this.cache.set(sigmaPrivateId, privateId);
|
|
1007
1017
|
}
|
|
1008
|
-
|
|
1009
|
-
if (userId.length === 0) {
|
|
1010
|
-
hasMakeId = true;
|
|
1011
|
-
}
|
|
1012
|
-
if (hasMakeId && this.cache.get(sigmaUserId)) {
|
|
1013
|
-
userId = this.cache.get(sigmaUserId);
|
|
1014
|
-
} else if (hasMakeId) {
|
|
1015
|
-
userId = makeIdCookie();
|
|
1016
|
-
}
|
|
1017
|
-
return userId;
|
|
1018
|
+
return privateId;
|
|
1018
1019
|
}
|
|
1019
1020
|
retryFetch(url, fetchOptions, retries = 3, timeout) {
|
|
1020
1021
|
return new Promise((resolve, reject) => {
|
|
@@ -1042,7 +1043,7 @@ var Sigma = class {
|
|
|
1042
1043
|
"ip": this.userData.ip,
|
|
1043
1044
|
"X-Real-IP": this.userData.ip,
|
|
1044
1045
|
token: this.token,
|
|
1045
|
-
"user-id": this.
|
|
1046
|
+
"user-id": this.cache.get(sigmaPrivateId)
|
|
1046
1047
|
}
|
|
1047
1048
|
};
|
|
1048
1049
|
if (method !== "GET") {
|
|
@@ -1309,6 +1310,9 @@ var Sigma = class {
|
|
|
1309
1310
|
if (!experiment)
|
|
1310
1311
|
return;
|
|
1311
1312
|
let id = null;
|
|
1313
|
+
if (!experiment.split_by) {
|
|
1314
|
+
experiment.split_by = "userId";
|
|
1315
|
+
}
|
|
1312
1316
|
switch (experiment.split_by) {
|
|
1313
1317
|
case "userId":
|
|
1314
1318
|
id = this.cache.get(sigmaUserId) || null;
|
|
@@ -1492,6 +1496,8 @@ var Sigma = class {
|
|
|
1492
1496
|
if (result.length > 0) {
|
|
1493
1497
|
this.cache.set(sigmaExperiments, result.slice(0, -1));
|
|
1494
1498
|
return result.slice(0, -1);
|
|
1499
|
+
} else {
|
|
1500
|
+
this.cache.remove(sigmaExperiments);
|
|
1495
1501
|
}
|
|
1496
1502
|
return null;
|
|
1497
1503
|
}
|