expf-sigma-node.js 0.0.4 → 0.0.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.
- package/package.json +1 -1
- package/public/sigma.js +37 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expf-sigma-node.js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.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
|
@@ -5795,6 +5795,7 @@ var Sigma = class {
|
|
|
5795
5795
|
this.api = api2 || `${defaultApi}/config.json`;
|
|
5796
5796
|
this.retries = retries;
|
|
5797
5797
|
this.sigmaUserData = sigmaUserData;
|
|
5798
|
+
this.userData.userId = this.validateUserDataUserId(this.userData.userId);
|
|
5798
5799
|
this.sigmaUserData.init({
|
|
5799
5800
|
userId: this.userData.userId || null,
|
|
5800
5801
|
ip: this.userData.ip || null,
|
|
@@ -5802,13 +5803,24 @@ var Sigma = class {
|
|
|
5802
5803
|
appVersion: this.userData.appVersion || null,
|
|
5803
5804
|
custom: this.userData.custom || null
|
|
5804
5805
|
});
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5806
|
+
cache.set(sigmaUserId, this.userData.userId);
|
|
5807
|
+
this.setUserCookie();
|
|
5808
|
+
}
|
|
5809
|
+
validateUserDataUserId(userId) {
|
|
5810
|
+
let hasMakeId = false;
|
|
5811
|
+
if (typeof userId === "undefined") {
|
|
5812
|
+
hasMakeId = true;
|
|
5813
|
+
}
|
|
5814
|
+
userId = String(userId).trim();
|
|
5815
|
+
if (userId.length === 0) {
|
|
5816
|
+
hasMakeId = true;
|
|
5811
5817
|
}
|
|
5818
|
+
if (hasMakeId && cache.get(sigmaUserId)) {
|
|
5819
|
+
userId = cache.get(sigmaUserId);
|
|
5820
|
+
} else if (hasMakeId) {
|
|
5821
|
+
userId = this.makeIdCookie();
|
|
5822
|
+
}
|
|
5823
|
+
return userId;
|
|
5812
5824
|
}
|
|
5813
5825
|
delay(ms) {
|
|
5814
5826
|
new Promise((resolve) => setTimeout(() => resolve(void 0), ms));
|
|
@@ -5882,25 +5894,35 @@ var Sigma = class {
|
|
|
5882
5894
|
cache.set("sigmaGeoData", JSON.stringify({ location: "none" }));
|
|
5883
5895
|
console.error(error);
|
|
5884
5896
|
}
|
|
5897
|
+
let data;
|
|
5885
5898
|
try {
|
|
5886
|
-
|
|
5887
|
-
const hash = await SHA256.hex(JSON.stringify(data));
|
|
5888
|
-
if (!localStorageHash || localStorageHash !== hash) {
|
|
5889
|
-
cache.set("sigmaHash", hash);
|
|
5890
|
-
cache.set(sigmaDataFile, JSON.stringify(data));
|
|
5891
|
-
this.sigmaUserData.clearFlags();
|
|
5892
|
-
}
|
|
5899
|
+
data = await this.getDataFile(`${api2}`);
|
|
5893
5900
|
} catch (error) {
|
|
5894
5901
|
if (!cache.get(sigmaDataFile)) {
|
|
5895
5902
|
throw new Error(`
|
|
5896
|
-
|
|
5903
|
+
Get data: ${error},
|
|
5897
5904
|
token: ${this.token},
|
|
5898
5905
|
url: ${defaultApi}/config.json
|
|
5899
5906
|
`);
|
|
5900
5907
|
} else {
|
|
5901
|
-
console.error(`Get data config: ${error}`);
|
|
5908
|
+
console.error(`Get data config.json: ${error}`);
|
|
5909
|
+
return true;
|
|
5902
5910
|
}
|
|
5903
5911
|
}
|
|
5912
|
+
let hash;
|
|
5913
|
+
try {
|
|
5914
|
+
if (typeof data !== "object") {
|
|
5915
|
+
throw new Error(`typeof config.json is not an object`);
|
|
5916
|
+
}
|
|
5917
|
+
hash = await SHA256.hex(JSON.stringify(data));
|
|
5918
|
+
if (!localStorageHash || localStorageHash !== hash) {
|
|
5919
|
+
cache.set("sigmaHash", hash);
|
|
5920
|
+
cache.set(sigmaDataFile, JSON.stringify(data));
|
|
5921
|
+
this.sigmaUserData.clearFlags();
|
|
5922
|
+
}
|
|
5923
|
+
} catch (error) {
|
|
5924
|
+
throw new Error(`Save data to local storage`);
|
|
5925
|
+
}
|
|
5904
5926
|
}
|
|
5905
5927
|
setUserCookie() {
|
|
5906
5928
|
let uin = cache.get(sigmaUserId);
|