expf-sigma-node.js 0.1.0 → 0.1.2
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 +8 -2
- package/public/sigma.js +26 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expf-sigma-node.js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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": [
|
|
@@ -17,7 +17,10 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"release": "np",
|
|
19
19
|
"build": "esbuild --bundle ./src/sigma.js --platform=node --format=cjs --outdir=public",
|
|
20
|
-
"dev": "esbuild --bundle ./src/sigma.js --platform=node --format=cjs --outdir=public --watch"
|
|
20
|
+
"dev": "esbuild --bundle ./src/sigma.js --platform=node --format=cjs --outdir=public --watch",
|
|
21
|
+
"lint": "eslint ./src/sigma.js",
|
|
22
|
+
"lint:all": "eslint \"**/*.js\"",
|
|
23
|
+
"test": "jest"
|
|
21
24
|
},
|
|
22
25
|
"dependencies": {
|
|
23
26
|
"node-fetch": "^2.1.2"
|
|
@@ -27,6 +30,7 @@
|
|
|
27
30
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
28
31
|
"@babel/preset-env": "^7.16.4",
|
|
29
32
|
"babel-eslint": "^10.1.0",
|
|
33
|
+
"babel-jest": "^29.2.2",
|
|
30
34
|
"babel-loader": "^8.2.3",
|
|
31
35
|
"babel-plugin-add-module-exports": "^1.0.4",
|
|
32
36
|
"clean-webpack-plugin": "^4.0.0",
|
|
@@ -36,6 +40,8 @@
|
|
|
36
40
|
"eslint-plugin-jest": "^23.8.2",
|
|
37
41
|
"eslint-plugin-node": "^11.1.0",
|
|
38
42
|
"eslint-plugin-prettier": "^3.1.3",
|
|
43
|
+
"jest": "^29.2.2",
|
|
44
|
+
"jest-environment-jsdom": "^29.2.1",
|
|
39
45
|
"js-cookie": "^3.0.1",
|
|
40
46
|
"jshashes": "^1.0.8",
|
|
41
47
|
"node-cache": "^5.1.2",
|
package/public/sigma.js
CHANGED
|
@@ -5620,11 +5620,14 @@ var SigmaUserData = class {
|
|
|
5620
5620
|
getUserNavigator() {
|
|
5621
5621
|
const userNavigator = browser_detect_es5_default();
|
|
5622
5622
|
const { user } = this;
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
user.
|
|
5623
|
+
let userOs;
|
|
5624
|
+
if (userNavigator.os) {
|
|
5625
|
+
userOs = userNavigator.os.split(" ");
|
|
5626
|
+
}
|
|
5627
|
+
user.browser.name = userNavigator.name ? userNavigator.name : void 0;
|
|
5628
|
+
user.browser.version = userNavigator.version ? userNavigator.version : void 0;
|
|
5629
|
+
user.os.name = userOs ? userOs[0] : void 0;
|
|
5630
|
+
user.os.version = userOs ? userOs[1] : void 0;
|
|
5628
5631
|
}
|
|
5629
5632
|
setUserId(userId) {
|
|
5630
5633
|
this.user.userId = userId;
|
|
@@ -5980,6 +5983,7 @@ var Sigma = class {
|
|
|
5980
5983
|
async getUserGeoData() {
|
|
5981
5984
|
try {
|
|
5982
5985
|
const data = await this.getDataFile(`${defaultApi}/geo`);
|
|
5986
|
+
this.sigmaUserData.setIp(data.ip);
|
|
5983
5987
|
return data;
|
|
5984
5988
|
} catch (error) {
|
|
5985
5989
|
throw new Error(error);
|
|
@@ -6076,7 +6080,7 @@ var Sigma = class {
|
|
|
6076
6080
|
}
|
|
6077
6081
|
async checkFlag(flagName) {
|
|
6078
6082
|
if (!flagName) {
|
|
6079
|
-
return
|
|
6083
|
+
return null;
|
|
6080
6084
|
}
|
|
6081
6085
|
await this.updateCache();
|
|
6082
6086
|
const cacheKey = this.cache.parse("sigmaDataFile");
|
|
@@ -6092,7 +6096,7 @@ var Sigma = class {
|
|
|
6092
6096
|
}
|
|
6093
6097
|
}
|
|
6094
6098
|
if (!flag)
|
|
6095
|
-
return
|
|
6099
|
+
return null;
|
|
6096
6100
|
return this.findingSpotCondition(flag, this.sigmaUserData);
|
|
6097
6101
|
}
|
|
6098
6102
|
getFlag(key) {
|
|
@@ -6143,14 +6147,14 @@ var Sigma = class {
|
|
|
6143
6147
|
return !conditionValues.includes(userValue);
|
|
6144
6148
|
case "contains any of":
|
|
6145
6149
|
for (let i = 0; i < conditionValues.length; i++) {
|
|
6146
|
-
if (String(conditionValues[i])
|
|
6150
|
+
if (String(userValue).includes(conditionValues[i])) {
|
|
6147
6151
|
return true;
|
|
6148
6152
|
}
|
|
6149
6153
|
}
|
|
6150
6154
|
return false;
|
|
6151
6155
|
case "contains none of":
|
|
6152
6156
|
for (let i = 0; i < conditionValues.length; i++) {
|
|
6153
|
-
if (String(conditionValues[i])
|
|
6157
|
+
if (String(userValue).includes(conditionValues[i])) {
|
|
6154
6158
|
return false;
|
|
6155
6159
|
}
|
|
6156
6160
|
}
|
|
@@ -6228,7 +6232,7 @@ var Sigma = class {
|
|
|
6228
6232
|
}
|
|
6229
6233
|
async getExperiment(experimentName) {
|
|
6230
6234
|
if (!experimentName) {
|
|
6231
|
-
return
|
|
6235
|
+
return null;
|
|
6232
6236
|
}
|
|
6233
6237
|
await this.updateCache();
|
|
6234
6238
|
const sigmaDataLs = await this.cache.parse(sigmaDataFile);
|
|
@@ -6268,7 +6272,7 @@ var Sigma = class {
|
|
|
6268
6272
|
}
|
|
6269
6273
|
const getParamValue = (paramName) => {
|
|
6270
6274
|
if (!paramName || !experiment) {
|
|
6271
|
-
return
|
|
6275
|
+
return null;
|
|
6272
6276
|
}
|
|
6273
6277
|
const groupName = this.cache.get(localStorageGroupName);
|
|
6274
6278
|
let params = null;
|
|
@@ -6279,7 +6283,7 @@ var Sigma = class {
|
|
|
6279
6283
|
}
|
|
6280
6284
|
}
|
|
6281
6285
|
if (!params) {
|
|
6282
|
-
return
|
|
6286
|
+
return null;
|
|
6283
6287
|
}
|
|
6284
6288
|
let paramValue = null;
|
|
6285
6289
|
for (let item in params.values) {
|
|
@@ -6288,13 +6292,13 @@ var Sigma = class {
|
|
|
6288
6292
|
}
|
|
6289
6293
|
}
|
|
6290
6294
|
if (!paramValue) {
|
|
6291
|
-
return
|
|
6295
|
+
return null;
|
|
6292
6296
|
}
|
|
6293
6297
|
return paramValue;
|
|
6294
6298
|
};
|
|
6295
6299
|
const getFeatureValue = (flagName) => {
|
|
6296
6300
|
if (!flagName || !experiment) {
|
|
6297
|
-
return
|
|
6301
|
+
return null;
|
|
6298
6302
|
}
|
|
6299
6303
|
const groupName = this.cache.get(localStorageGroupName);
|
|
6300
6304
|
let flagExperiment = null;
|
|
@@ -6305,7 +6309,7 @@ var Sigma = class {
|
|
|
6305
6309
|
}
|
|
6306
6310
|
}
|
|
6307
6311
|
if (!flagExperiment)
|
|
6308
|
-
return
|
|
6312
|
+
return null;
|
|
6309
6313
|
let flag = null;
|
|
6310
6314
|
for (let i = 0; i < flagExperiment.groups.length; i++) {
|
|
6311
6315
|
if (flagExperiment.groups[i]["group"] === groupName) {
|
|
@@ -6314,8 +6318,8 @@ var Sigma = class {
|
|
|
6314
6318
|
}
|
|
6315
6319
|
}
|
|
6316
6320
|
if (!flag)
|
|
6317
|
-
return
|
|
6318
|
-
return this.findingSpotCondition(flag);
|
|
6321
|
+
return null;
|
|
6322
|
+
return this.findingSpotCondition(flag, false, experiment);
|
|
6319
6323
|
};
|
|
6320
6324
|
return {
|
|
6321
6325
|
getParamValue,
|
|
@@ -6372,7 +6376,7 @@ var Sigma = class {
|
|
|
6372
6376
|
}
|
|
6373
6377
|
return groupName;
|
|
6374
6378
|
}
|
|
6375
|
-
findingSpotCondition(flag, saveToUser) {
|
|
6379
|
+
findingSpotCondition(flag, saveToUser = false, exp = null) {
|
|
6376
6380
|
let flagRules = flag.rules;
|
|
6377
6381
|
let flagDefaultResult = null;
|
|
6378
6382
|
for (let defaultRule in flagRules) {
|
|
@@ -6397,7 +6401,10 @@ var Sigma = class {
|
|
|
6397
6401
|
const conditions = flagRules[rule].conditions;
|
|
6398
6402
|
let results = [];
|
|
6399
6403
|
for (let i in conditions) {
|
|
6400
|
-
let userValue = this.getUserParamValue(
|
|
6404
|
+
let userValue = this.getUserParamValue(
|
|
6405
|
+
conditions[i].name,
|
|
6406
|
+
exp ? exp.is_private : flag.is_private
|
|
6407
|
+
);
|
|
6401
6408
|
results.push(
|
|
6402
6409
|
this.conditionOperation(
|
|
6403
6410
|
userValue,
|