expf-sigma-node.js 1.0.0 → 1.1.1

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 +24 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expf-sigma-node.js",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
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
@@ -68,7 +68,10 @@ var SigmaUserData = class {
68
68
  email,
69
69
  appVersion,
70
70
  custom,
71
- deviceCategory
71
+ deviceCategory,
72
+ os,
73
+ browser,
74
+ geo
72
75
  }) {
73
76
  this.user.userId = userId;
74
77
  this.user.ip = ip;
@@ -78,8 +81,9 @@ var SigmaUserData = class {
78
81
  this.user.time = new Date().getTime() / (1e3 * 60 * 60);
79
82
  this.user.date = Math.floor(new Date().getTime() / (1e3 * 60 * 60 * 24));
80
83
  this.user.deviceCategory = deviceCategory;
81
- }
82
- getUserNavigator() {
84
+ this.user.os = os;
85
+ this.user.browser = browser;
86
+ this.user.geo = geo;
83
87
  }
84
88
  setUserId(userId) {
85
89
  this.user.userId = userId;
@@ -877,6 +881,7 @@ var defaultApi = "https://api.expf.ru/api/v1";
877
881
  var sigmaUserId = "sigmaUserId";
878
882
  var sigmaDataFile = "sigmaDataFile";
879
883
  var sigmaExperiments = "sigmaExperiments";
884
+ var sigmaGeoData = "sigmaGeoData";
880
885
  var SHA256 = new sigmaHashes_default.SHA256();
881
886
  var MD5 = new sigmaHashes_default.MD5();
882
887
  var max_decimal_64 = 18446744073709552e3;
@@ -893,7 +898,7 @@ var Sigma = class {
893
898
  this.token = token;
894
899
  this.userData = userData || {};
895
900
  cacheTTL < 10 ? this.cacheTTL = 10 : this.cacheTTL = cacheTTL;
896
- this.api = options.api || `${defaultApi}/config.json`;
901
+ this.api = options.api || `${defaultApi}`;
897
902
  this.retries = options.retries || 3;
898
903
  this.sigmaUserData = new SigmaUserData();
899
904
  this.postfix = options.postfix || "";
@@ -905,7 +910,10 @@ var Sigma = class {
905
910
  email: this.userData.email || null,
906
911
  appVersion: this.userData.appVersion || null,
907
912
  custom: this.userData.custom || null,
908
- deviceCategory: this.userData.deviceCategory || null
913
+ deviceCategory: this.userData.deviceCategory || null,
914
+ browser: this.userData.browser || null,
915
+ os: this.userData.os || null,
916
+ geo: this.userData.geo || null
909
917
  });
910
918
  this.cache.set(sigmaUserId, this.userData.userId);
911
919
  this.setUserCookie();
@@ -968,8 +976,7 @@ var Sigma = class {
968
976
  }
969
977
  async getUserGeoData() {
970
978
  try {
971
- const data = await this.getDataFile(`${defaultApi}/geo`);
972
- this.sigmaUserData.setIp(data.ip);
979
+ const data = await this.getDataFile(`${this.api}/geo`);
973
980
  return data;
974
981
  } catch (error) {
975
982
  throw new Error(error);
@@ -987,24 +994,27 @@ var Sigma = class {
987
994
  `);
988
995
  }
989
996
  try {
990
- const userGeoData = await this.getUserGeoData();
991
- if (!this.cache.get("sigmaGeoData") || this.cache.get("sigmaGeoData", { location: "none" }) && userGeoData) {
992
- this.cache.set("sigmaGeoData", JSON.stringify(userGeoData));
993
- this.sigmaUserData.clearFlags();
997
+ if (!this.userData.geo) {
998
+ const userGeoData = await this.getUserGeoData();
999
+ if (!this.cache.get(sigmaGeoData) || this.cache.get(sigmaGeoData, { location: "none" }) && userGeoData) {
1000
+ this.cache.set(sigmaGeoData, JSON.stringify(userGeoData));
1001
+ }
1002
+ } else {
1003
+ this.cache.set(sigmaGeoData, JSON.stringify(this.userData.geo));
994
1004
  }
995
1005
  } catch (error) {
996
- this.cache.set("sigmaGeoData", JSON.stringify({ location: "none" }));
1006
+ this.cache.set(sigmaGeoData, JSON.stringify({ location: "none" }));
997
1007
  console.error(error);
998
1008
  }
999
1009
  let data;
1000
1010
  try {
1001
- data = await this.getDataFile(`${api}`);
1011
+ data = await this.getDataFile(`${api}/config.json`);
1002
1012
  } catch (error) {
1003
1013
  if (!this.cache.get(sigmaDataFile)) {
1004
1014
  throw new Error(`
1005
1015
  Get data: ${error},
1006
1016
  token: ${this.token},
1007
- url: ${defaultApi}/config.json
1017
+ url: ${this.api}/config.json
1008
1018
  `);
1009
1019
  } else {
1010
1020
  console.error(`Get data config.json: ${error}`);