expf-sigma-node.js 3.4.0 → 3.4.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/sigma.js +18 -52
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expf-sigma-node.js",
3
- "version": "3.4.0",
3
+ "version": "3.4.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
@@ -918,13 +918,9 @@ var sigmaHashes_default = Hashes;
918
918
 
919
919
  // src/helpers/constants.js
920
920
  var defaultApi = "https://api.expf.ru/api/v1";
921
- var sigmaUserId = "sigmaUserId";
922
- var sigmaProfileId = "sigmaProfileId";
923
- var sigmaDeviceId = "sigmaDeviceId";
924
921
  var sigmaPrivateId = "sigmaPrivateId";
925
922
  var sigmaHash = "sigmaHash";
926
923
  var sigmaDataFileLastUpdate = "sigmaDataFileLastUpdate";
927
- var sigmaExpiration = "sigmaExpiration";
928
924
  var sigmaDataFile = "sigmaDataFile";
929
925
  var sigmaExperiments = "sigmaExperiments";
930
926
  var sigmaHoldouts = "sigmaHoldouts";
@@ -933,7 +929,6 @@ var max_decimal_64 = 18446744073709552e3;
933
929
  var zeta = 8540717056e4;
934
930
  var SHA256 = new sigmaHashes_default.SHA256();
935
931
  var MD5 = new sigmaHashes_default.MD5();
936
- var expirationDate = 24 * 60 * 60 * 1e3;
937
932
  var secondsIn24Hours = 24 * 60 * 60;
938
933
  var defaultGeoCacheTTL = 5 * 60;
939
934
  var cacheStandardTimeToLive = 3600;
@@ -1271,7 +1266,7 @@ function generateFilteredList(array, name) {
1271
1266
  }
1272
1267
 
1273
1268
  // package.json
1274
- var version = "3.4.0";
1269
+ var version = "3.4.2";
1275
1270
 
1276
1271
  // src/helpers/sdkVersion.js
1277
1272
  var sdkVersion = version;
@@ -1346,28 +1341,9 @@ var Sigma = class {
1346
1341
  pathname: this.userData.pathname || null,
1347
1342
  ua: this.userData.ua || void 0
1348
1343
  });
1349
- this.setSplitIdsToCache(this.userData);
1350
1344
  this.makePrivateIdInCache();
1351
1345
  this.geoCache = new SigmaGeoCache(`${this.cache.get(sigmaPrivateId)}__${this.token}`);
1352
1346
  }
1353
- setSplitIdsToCache(userData) {
1354
- for (let [key, value] of Object.entries(userData)) {
1355
- if (!value || !String(value).trim().length)
1356
- continue;
1357
- switch (key) {
1358
- case "userId":
1359
- this.cache.set(sigmaUserId, String(value).trim());
1360
- this.cache.set(sigmaExpiration, new Date().getTime() + expirationDate);
1361
- break;
1362
- case "profileId":
1363
- this.cache.set(sigmaProfileId, String(value).trim());
1364
- break;
1365
- case "deviceId":
1366
- this.cache.set(sigmaDeviceId, String(value).trim());
1367
- break;
1368
- }
1369
- }
1370
- }
1371
1347
  makePrivateIdInCache() {
1372
1348
  if (!this.cache.get(sigmaPrivateId)) {
1373
1349
  this.cache.set(sigmaPrivateId, generateRandomId());
@@ -1380,7 +1356,7 @@ var Sigma = class {
1380
1356
  statusCode: "",
1381
1357
  data: null
1382
1358
  };
1383
- const controller = new AbortController();
1359
+ const controller = typeof AbortController !== "undefined" ? new AbortController() : null;
1384
1360
  try {
1385
1361
  data = await (0, import_node_fetch.default)(url, {
1386
1362
  headers: {
@@ -1391,13 +1367,14 @@ var Sigma = class {
1391
1367
  "sdk-name": sdkName,
1392
1368
  "sdk-version": sdkVersion
1393
1369
  },
1394
- signal: controller.signal
1370
+ ...controller && { signal: controller.signal }
1395
1371
  });
1396
1372
  sigmaData.status = data.status === status200 ? statusSuccess : statusFailed;
1397
1373
  sigmaData.statusCode = data.status;
1398
1374
  sigmaData.data = data.status === status200 ? await data.json() : null;
1399
1375
  } catch {
1400
- controller.abort();
1376
+ if (controller)
1377
+ controller.abort();
1401
1378
  sigmaData.status = statusFailed;
1402
1379
  sigmaData.statusCode = status400;
1403
1380
  sigmaData.data = null;
@@ -1635,19 +1612,15 @@ var Sigma = class {
1635
1612
  }
1636
1613
  switchSplitById(splitBy) {
1637
1614
  let id = null;
1638
- const cacheSigmaExpiration = this.cache.get(sigmaExpiration);
1639
1615
  switch (splitBy) {
1640
1616
  case "userId":
1641
- id = this.cache.get(sigmaUserId) || null;
1642
- if (typeof cacheSigmaExpiration !== "undefined" && new Date().getTime() >= Number(cacheSigmaExpiration)) {
1643
- id = null;
1644
- }
1617
+ id = this.userData.userId ? String(this.userData.userId).trim() : null;
1645
1618
  break;
1646
1619
  case "profileId":
1647
- id = this.cache.get(sigmaProfileId) || null;
1620
+ id = this.userData.profileId ? String(this.userData.profileId).trim() : null;
1648
1621
  break;
1649
1622
  case "deviceId":
1650
- id = this.cache.get(sigmaDeviceId) || null;
1623
+ id = this.userData.deviceId ? String(this.userData.deviceId).trim() : null;
1651
1624
  break;
1652
1625
  }
1653
1626
  return id;
@@ -2026,10 +1999,6 @@ var Sigma = class {
2026
1999
  const data = await this.cache.get(sigmaHash);
2027
2000
  return data;
2028
2001
  }
2029
- async getCacheUserId() {
2030
- const data = await this.cache.get(sigmaUserId);
2031
- return data;
2032
- }
2033
2002
  checkConditionsStatement(ruleStatement, items) {
2034
2003
  let isSuccessRule = false;
2035
2004
  if (ruleStatement == "OR") {
@@ -2048,14 +2017,11 @@ var Sigma = class {
2048
2017
  }
2049
2018
  }
2050
2019
  clearUserProperties() {
2051
- this.clearCacheByKeys([
2052
- sigmaUserId,
2053
- sigmaDeviceId,
2054
- sigmaProfileId,
2055
- sigmaExpiration,
2056
- sigmaExperiments
2057
- ]);
2020
+ this.userData.userId = void 0;
2021
+ this.userData.profileId = void 0;
2022
+ this.userData.deviceId = void 0;
2058
2023
  this.sigmaUserData.removeInjectedProperties();
2024
+ this.clearCacheByKeys([sigmaExperiments]);
2059
2025
  }
2060
2026
  overwriteGeoCache(key, value) {
2061
2027
  const geoCache = this.geoCache.parse(sigmaGeoData);
@@ -2066,17 +2032,17 @@ var Sigma = class {
2066
2032
  return {
2067
2033
  setUserId: (userId) => {
2068
2034
  this.sigmaUserData.setUserId(userId);
2069
- this.cache.set(sigmaUserId, userId);
2035
+ this.userData.userId = userId;
2070
2036
  return this.editUserProperties();
2071
2037
  },
2072
2038
  setDeviceId: (deviceId) => {
2073
2039
  this.sigmaUserData.setDeviceId(deviceId);
2074
- this.cache.set(sigmaDeviceId, deviceId);
2040
+ this.userData.deviceId = deviceId;
2075
2041
  return this.editUserProperties();
2076
2042
  },
2077
2043
  setProfileId: (profileId) => {
2078
2044
  this.sigmaUserData.setProfileId(profileId);
2079
- this.cache.set(sigmaProfileId, profileId);
2045
+ this.userData.profileId = profileId;
2080
2046
  return this.editUserProperties();
2081
2047
  },
2082
2048
  setEmail: (email) => {
@@ -2134,17 +2100,17 @@ var Sigma = class {
2134
2100
  },
2135
2101
  removeUserId: () => {
2136
2102
  this.sigmaUserData.removeUserId();
2137
- this.cache.remove(sigmaUserId);
2103
+ this.userData.userId = void 0;
2138
2104
  return this.editUserProperties();
2139
2105
  },
2140
2106
  removeDeviceId: () => {
2141
2107
  this.sigmaUserData.removeDeviceId();
2142
- this.cache.remove(sigmaDeviceId);
2108
+ this.userData.deviceId = void 0;
2143
2109
  return this.editUserProperties();
2144
2110
  },
2145
2111
  removeProfileId: () => {
2146
2112
  this.sigmaUserData.removeProfileId();
2147
- this.cache.remove(sigmaProfileId);
2113
+ this.userData.profileId = void 0;
2148
2114
  return this.editUserProperties();
2149
2115
  },
2150
2116
  removeAppVersion: () => {