expf-sigma-node.js 3.2.3 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/sigma.js +27 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expf-sigma-node.js",
3
- "version": "3.2.3",
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 });
@@ -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 || null,
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;
@@ -1432,7 +1433,6 @@ var Sigma = class {
1432
1433
  return null;
1433
1434
  }
1434
1435
  await this.updateCache();
1435
- await this.setUserGeoData();
1436
1436
  const sigmaDataLs = await this.cache.parse(sigmaDataFile);
1437
1437
  if (!sigmaDataLs.experiments) {
1438
1438
  throw new Error("Experiments not found in cache");