expf-sigma-node.js 0.0.3 → 0.0.5

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 +25 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expf-sigma-node.js",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
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
@@ -5785,16 +5785,16 @@ var sigmaDataFile = "sigmaDataFile";
5785
5785
  var SHA256 = new import_jshashes.default.SHA256();
5786
5786
  var MD5 = new import_jshashes.default.MD5();
5787
5787
  var Sigma = class {
5788
- constructor(token, userData, api2, cacheTTL = 10, retries = 3) {
5788
+ constructor(token, userData, cacheTTL = 10, api2, retries = 3) {
5789
5789
  if (!token) {
5790
5790
  throw new Error("Please specify a token");
5791
5791
  }
5792
5792
  this.token = token;
5793
5793
  this.userData = userData || {};
5794
- this.api = api2 || `${defaultApi}/config.json`;
5795
- this.sigmaUserData = sigmaUserData;
5796
5794
  cacheTTL < 10 ? this.cacheTTL = 10 : this.cacheTTL = cacheTTL;
5795
+ this.api = api2 || `${defaultApi}/config.json`;
5797
5796
  this.retries = retries;
5797
+ this.sigmaUserData = sigmaUserData;
5798
5798
  this.sigmaUserData.init({
5799
5799
  userId: this.userData.userId || null,
5800
5800
  ip: this.userData.ip || null,
@@ -5804,10 +5804,11 @@ var Sigma = class {
5804
5804
  });
5805
5805
  if (!this.userData.userId) {
5806
5806
  this.setUserCookie();
5807
+ this.sigmaUserData.setUserId(cache.get(sigmaUserId));
5807
5808
  } else {
5808
5809
  cache.set(sigmaUserId, this.userData.userId);
5810
+ this.sigmaUserData.setUserId(this.userData.userId);
5809
5811
  }
5810
- this.sigmaUserData.setUserId(cache.get(sigmaUserId));
5811
5812
  }
5812
5813
  delay(ms) {
5813
5814
  new Promise((resolve) => setTimeout(() => resolve(void 0), ms));
@@ -5881,25 +5882,35 @@ var Sigma = class {
5881
5882
  cache.set("sigmaGeoData", JSON.stringify({ location: "none" }));
5882
5883
  console.error(error);
5883
5884
  }
5885
+ let data;
5884
5886
  try {
5885
- const data = await this.getDataFile(`${api2}`);
5886
- const hash = await SHA256.hex(JSON.stringify(data));
5887
- if (!localStorageHash || localStorageHash !== hash) {
5888
- cache.set("sigmaHash", hash);
5889
- cache.set(sigmaDataFile, JSON.stringify(data));
5890
- this.sigmaUserData.clearFlags();
5891
- }
5887
+ data = await this.getDataFile(`${api2}`);
5892
5888
  } catch (error) {
5893
5889
  if (!cache.get(sigmaDataFile)) {
5894
5890
  throw new Error(`
5895
- save data to cache: ${error},
5891
+ Get data: ${error},
5896
5892
  token: ${this.token},
5897
- url: ${defaultApi}/config
5893
+ url: ${defaultApi}/config.json
5898
5894
  `);
5899
5895
  } else {
5900
- console.error(`Get data config: ${error}`);
5896
+ console.error(`Get data config.json: ${error}`);
5897
+ return true;
5901
5898
  }
5902
5899
  }
5900
+ let hash;
5901
+ try {
5902
+ if (typeof data !== "object") {
5903
+ throw new Error(`typeof config.json is not an object`);
5904
+ }
5905
+ hash = await SHA256.hex(JSON.stringify(data));
5906
+ if (!localStorageHash || localStorageHash !== hash) {
5907
+ cache.set("sigmaHash", hash);
5908
+ cache.set(sigmaDataFile, JSON.stringify(data));
5909
+ this.sigmaUserData.clearFlags();
5910
+ }
5911
+ } catch (error) {
5912
+ throw new Error(`Save data to local storage`);
5913
+ }
5903
5914
  }
5904
5915
  setUserCookie() {
5905
5916
  let uin = cache.get(sigmaUserId);