expf-sigma-node.js 1.1.4 → 1.1.6

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 +20 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expf-sigma-node.js",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
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
@@ -957,6 +957,7 @@ var Sigma = class {
957
957
  body,
958
958
  credentials: "same-origin",
959
959
  headers: {
960
+ "ip": this.userData.ip,
960
961
  "X-Real-IP": this.userData.ip,
961
962
  token: this.token,
962
963
  "user-id": this.userData.userId ? this.userData.userId : this.sigmaUserData.user.userId
@@ -983,6 +984,22 @@ var Sigma = class {
983
984
  throw new Error(`Get geo: ${error}`);
984
985
  }
985
986
  }
987
+ async setUserGeoData() {
988
+ let jsonUserGeoData = JSON.stringify({ location: "none" });
989
+ try {
990
+ if (this.userData.ip && !this.userData.geo) {
991
+ const userGeoData = await this.getUserGeoData();
992
+ if (!this.cache.get(sigmaGeoData) || userGeoData) {
993
+ jsonUserGeoData = JSON.stringify(userGeoData);
994
+ }
995
+ } else if (this.userData.geo) {
996
+ jsonUserGeoData = JSON.stringify(this.userData.geo);
997
+ }
998
+ } catch (error) {
999
+ console.log(error);
1000
+ }
1001
+ this.cache.set(sigmaGeoData, jsonUserGeoData);
1002
+ }
986
1003
  async saveToCache() {
987
1004
  const { api } = this;
988
1005
  const localStorageHash = this.cache.get("sigmaHash");
@@ -994,18 +1011,7 @@ var Sigma = class {
994
1011
  token: ${this.token}
995
1012
  `);
996
1013
  }
997
- try {
998
- if (!this.userData.geo) {
999
- const userGeoData = await this.getUserGeoData();
1000
- if (!this.cache.get(sigmaGeoData) || userGeoData) {
1001
- this.cache.set(sigmaGeoData, JSON.stringify(userGeoData));
1002
- }
1003
- } else {
1004
- this.cache.set(sigmaGeoData, JSON.stringify(this.userData.geo));
1005
- }
1006
- } catch (error) {
1007
- this.cache.set(sigmaGeoData, JSON.stringify({ location: "none" }));
1008
- }
1014
+ await this.setUserGeoData();
1009
1015
  let data;
1010
1016
  try {
1011
1017
  data = await this.getDataFile(`${api}/config.json`);
@@ -1045,7 +1051,8 @@ var Sigma = class {
1045
1051
  this.cache.get("sigmaDataFileLastUpdate")
1046
1052
  );
1047
1053
  const currentTime = Math.floor(Date.now() / 1e3);
1048
- if (currentTime > lastUpdate + this.cacheTTL || this.userData.geo) {
1054
+ const userGeoCache = this.cache.parse(sigmaGeoData);
1055
+ if (currentTime > lastUpdate + this.cacheTTL || Object.keys(userGeoCache).length !== 0 || Object.keys(this.userData.geo).length !== 0) {
1049
1056
  return true;
1050
1057
  }
1051
1058
  return false;