flagsmith-nodejs 2.2.2 → 2.3.0
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/build/sdk/index.d.ts +5 -17
- package/build/sdk/index.js +2 -0
- package/build/sdk/types.d.ts +19 -1
- package/build/sdk/utils.d.ts +2 -2
- package/{es6-example → examples/api-proxy}/.babelrc +0 -0
- package/{es6-example → examples/api-proxy}/.eslintrc +0 -0
- package/examples/api-proxy/.idea/api-proxy.iml +12 -0
- package/examples/api-proxy/.idea/codeStyles/Project.xml +60 -0
- package/examples/api-proxy/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/examples/api-proxy/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/examples/api-proxy/.idea/modules.xml +8 -0
- package/examples/api-proxy/.idea/vcs.xml +6 -0
- package/examples/api-proxy/README.md +12 -0
- package/examples/api-proxy/package-lock.json +10895 -0
- package/examples/api-proxy/package.json +57 -0
- package/examples/api-proxy/src/api/index.js +42 -0
- package/{es6-example → examples/api-proxy}/src/index.js +0 -0
- package/examples/basic/.babelrc +3 -0
- package/examples/basic/.eslintrc +8 -0
- package/examples/basic/README.md +10 -0
- package/{es6-example → examples/basic}/package-lock.json +25 -39
- package/{es6-example → examples/basic}/package.json +1 -1
- package/examples/basic/src/api/index.js +33 -0
- package/{example/server → examples/basic/src}/index.js +4 -4
- package/examples/caching/.babelrc +3 -0
- package/examples/caching/.eslintrc +8 -0
- package/examples/caching/README.md +9 -0
- package/examples/caching/package-lock.json +10782 -0
- package/examples/caching/package.json +56 -0
- package/{example/server → examples/caching/src}/api/index.js +7 -11
- package/examples/caching/src/index.js +29 -0
- package/examples/custom-fetch-agent/.babelrc +3 -0
- package/examples/custom-fetch-agent/.eslintrc +8 -0
- package/examples/custom-fetch-agent/README.md +12 -0
- package/examples/custom-fetch-agent/package-lock.json +10782 -0
- package/examples/custom-fetch-agent/package.json +56 -0
- package/examples/custom-fetch-agent/src/api/index.js +34 -0
- package/examples/custom-fetch-agent/src/index.js +29 -0
- package/examples/local-evaluation/.babelrc +3 -0
- package/examples/local-evaluation/.eslintrc +8 -0
- package/examples/local-evaluation/README.md +18 -0
- package/examples/local-evaluation/package-lock.json +10782 -0
- package/examples/local-evaluation/package.json +56 -0
- package/{es6-example → examples/local-evaluation}/src/api/index.js +2 -13
- package/examples/local-evaluation/src/index.js +29 -0
- package/package.json +1 -1
- package/sdk/index.ts +8 -15
- package/sdk/types.ts +19 -2
- package/sdk/utils.ts +2 -2
- package/tests/sdk/flagsmith.test.ts +25 -10
- package/es6-example/README.md +0 -62
- package/example/LICENSE +0 -0
- package/example/Procfile +0 -1
- package/example/README.md +0 -15
- package/example/package-lock.json +0 -2387
- package/example/package.json +0 -27
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nodejs-es6-boilerplate",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Node.js boilerplate with ES6, ESLint, and Prettier",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"browserslist": [
|
|
7
|
+
"last 2 Chrome versions"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
+
"clean": "rm -rf build && mkdir build",
|
|
12
|
+
"build-babel": "babel -d ./build ./src -s",
|
|
13
|
+
"build": "npm run clean && npm run build-babel",
|
|
14
|
+
"dev": "nodemon --exec npm start --ignore ./build",
|
|
15
|
+
"node-cache": "^5.1.2",
|
|
16
|
+
"ssg-node-express": "4.16.4",
|
|
17
|
+
"start": "npm run build && node ./build/index.js",
|
|
18
|
+
"format": "prettier --write \"src/**/*.js\"",
|
|
19
|
+
"format:check": "prettier --list-different \"src/**/*.js\"",
|
|
20
|
+
"lint": "eslint \"src/**/*.js\"",
|
|
21
|
+
"lint:fix": "eslint --fix \"src/**/*.js\""
|
|
22
|
+
},
|
|
23
|
+
"repository": "github:vferdiansyah/nodejs-es6-boilerplate",
|
|
24
|
+
"keywords": [
|
|
25
|
+
"javascript",
|
|
26
|
+
"node",
|
|
27
|
+
"nodejs",
|
|
28
|
+
"es6",
|
|
29
|
+
"eslint",
|
|
30
|
+
"prettier",
|
|
31
|
+
"boilerplate"
|
|
32
|
+
],
|
|
33
|
+
"author": {
|
|
34
|
+
"name": "Veri Ferdiansyah",
|
|
35
|
+
"email": "veri.ferdi@gmail.com",
|
|
36
|
+
"url": "https://vferdiansyah.github.io"
|
|
37
|
+
},
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"bugs": "https://github.com/vferdiansyah/nodejs-es6-boilerplate/issues",
|
|
40
|
+
"homepage": "https://github.com/vferdiansyah/nodejs-es6-boilerplate#readme",
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@babel/cli": "^7.5.5",
|
|
43
|
+
"@babel/core": "^7.5.5",
|
|
44
|
+
"@babel/preset-env": "^7.5.5",
|
|
45
|
+
"eslint": "^6.2.1",
|
|
46
|
+
"eslint-config-prettier": "^6.1.0",
|
|
47
|
+
"eslint-plugin-prettier": "^3.1.0",
|
|
48
|
+
"express": "^4.18.1",
|
|
49
|
+
"nodemon": "^2.0.19",
|
|
50
|
+
"prettier": "^1.18.2"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"flagsmith-nodejs": "^2.2.2",
|
|
54
|
+
"https-proxy-agent": "^5.0.1",
|
|
55
|
+
"node-cache": "^5.1.2"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {Router} from 'express'
|
|
2
|
+
import Flagsmith from '../../../../build'
|
|
3
|
+
import HttpsProxyAgent from 'https-proxy-agent'
|
|
4
|
+
|
|
5
|
+
const environmentKey = 'NowEDzKzNJXZVTVanLVdMQ';
|
|
6
|
+
|
|
7
|
+
const flagsmith = new Flagsmith({
|
|
8
|
+
environmentKey,
|
|
9
|
+
agent: new HttpsProxyAgent({
|
|
10
|
+
host: "localhost",
|
|
11
|
+
protocol: "https",
|
|
12
|
+
port:8080,
|
|
13
|
+
headers: {
|
|
14
|
+
"Custom-Header": 1
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const api = () => {
|
|
20
|
+
const api = Router();
|
|
21
|
+
|
|
22
|
+
api.get('/', async (req, res) => {
|
|
23
|
+
const flags = await flagsmith.getEnvironmentFlags();
|
|
24
|
+
res.json(flags);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
api.get('/:user', async (req, res) => {
|
|
28
|
+
const flags = await flagsmith.getIdentityFlags(req.params.user, { checkout_v2: 1 });
|
|
29
|
+
const fontSize = flags.getFeatureValue('font_size');
|
|
30
|
+
const checkoutV2 = flags.isFeatureEnabled('checkout_v2');
|
|
31
|
+
res.json({ fontSize, checkoutV2 });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
api.get('/:user/segments', async (req, res) => {
|
|
35
|
+
const segments = await flagsmith.getIdentitySegments(req.params.user, { checkout_v2: 1 });
|
|
36
|
+
res.json(segments.map(v => v.name));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return api;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default api
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<img width="100%" src="https://github.com/Flagsmith/flagsmith/raw/main/static-files/hero.png"/>
|
|
2
|
+
|
|
3
|
+
# Flagsmith Node.js example with custom fetch agent
|
|
4
|
+
|
|
5
|
+
This is a simple Flagsmith Node.js example in local evaluation modes with a custom fetch agent. Using a custom fetch agent lets allows you to specify networking related options such as keep alive and socket timeout, read more on this [here](https://github.com/node-fetch/node-fetch#custom-agent).
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm i
|
|
9
|
+
npm run dev
|
|
10
|
+
```
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"flagsmith-nodejs": "^2.2.2
|
|
12
|
+
"flagsmith-nodejs": "^2.2.2",
|
|
13
13
|
"node-cache": "^5.1.2"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
@@ -2474,9 +2474,9 @@
|
|
|
2474
2474
|
}
|
|
2475
2475
|
},
|
|
2476
2476
|
"node_modules/flagsmith-nodejs": {
|
|
2477
|
-
"version": "2.2.2
|
|
2478
|
-
"resolved": "https://registry.npmjs.org/flagsmith-nodejs/-/flagsmith-nodejs-2.2.2
|
|
2479
|
-
"integrity": "sha512-
|
|
2477
|
+
"version": "2.2.2",
|
|
2478
|
+
"resolved": "https://registry.npmjs.org/flagsmith-nodejs/-/flagsmith-nodejs-2.2.2.tgz",
|
|
2479
|
+
"integrity": "sha512-T8RI5+H6GdHwXz7fOaQOE5Q6XJOeMLlSuSw4uDExQRkVzaO/6k0KFBYRRiTce//guRrkSSW1xqvcB8AuqYLkNA==",
|
|
2480
2480
|
"dependencies": {
|
|
2481
2481
|
"big-integer": "^1.6.51",
|
|
2482
2482
|
"md5": "^2.3.0",
|
|
@@ -3871,12 +3871,6 @@
|
|
|
3871
3871
|
"node": ">=6"
|
|
3872
3872
|
}
|
|
3873
3873
|
},
|
|
3874
|
-
"node_modules/json5/node_modules/minimist": {
|
|
3875
|
-
"version": "1.2.5",
|
|
3876
|
-
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
|
3877
|
-
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
|
3878
|
-
"dev": true
|
|
3879
|
-
},
|
|
3880
3874
|
"node_modules/kind-of": {
|
|
3881
3875
|
"version": "6.0.3",
|
|
3882
3876
|
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz",
|
|
@@ -3901,9 +3895,9 @@
|
|
|
3901
3895
|
}
|
|
3902
3896
|
},
|
|
3903
3897
|
"node_modules/lodash": {
|
|
3904
|
-
"version": "4.17.
|
|
3905
|
-
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.
|
|
3906
|
-
"integrity": "sha512-
|
|
3898
|
+
"version": "4.17.21",
|
|
3899
|
+
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
|
3900
|
+
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
|
3907
3901
|
"dev": true
|
|
3908
3902
|
},
|
|
3909
3903
|
"node_modules/loose-envify": {
|
|
@@ -4066,9 +4060,9 @@
|
|
|
4066
4060
|
}
|
|
4067
4061
|
},
|
|
4068
4062
|
"node_modules/minimist": {
|
|
4069
|
-
"version": "1.2.
|
|
4070
|
-
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.
|
|
4071
|
-
"integrity": "sha512-
|
|
4063
|
+
"version": "1.2.6",
|
|
4064
|
+
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
|
|
4065
|
+
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
|
|
4072
4066
|
"dev": true
|
|
4073
4067
|
},
|
|
4074
4068
|
"node_modules/mixin-deep": {
|
|
@@ -4651,9 +4645,9 @@
|
|
|
4651
4645
|
}
|
|
4652
4646
|
},
|
|
4653
4647
|
"node_modules/path-parse": {
|
|
4654
|
-
"version": "1.0.
|
|
4655
|
-
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.
|
|
4656
|
-
"integrity": "sha512-
|
|
4648
|
+
"version": "1.0.7",
|
|
4649
|
+
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
|
|
4650
|
+
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
|
|
4657
4651
|
"dev": true
|
|
4658
4652
|
},
|
|
4659
4653
|
"node_modules/path-to-regexp": {
|
|
@@ -8008,9 +8002,9 @@
|
|
|
8008
8002
|
}
|
|
8009
8003
|
},
|
|
8010
8004
|
"flagsmith-nodejs": {
|
|
8011
|
-
"version": "2.2.2
|
|
8012
|
-
"resolved": "https://registry.npmjs.org/flagsmith-nodejs/-/flagsmith-nodejs-2.2.2
|
|
8013
|
-
"integrity": "sha512-
|
|
8005
|
+
"version": "2.2.2",
|
|
8006
|
+
"resolved": "https://registry.npmjs.org/flagsmith-nodejs/-/flagsmith-nodejs-2.2.2.tgz",
|
|
8007
|
+
"integrity": "sha512-T8RI5+H6GdHwXz7fOaQOE5Q6XJOeMLlSuSw4uDExQRkVzaO/6k0KFBYRRiTce//guRrkSSW1xqvcB8AuqYLkNA==",
|
|
8014
8008
|
"requires": {
|
|
8015
8009
|
"big-integer": "^1.6.51",
|
|
8016
8010
|
"md5": "^2.3.0",
|
|
@@ -9107,14 +9101,6 @@
|
|
|
9107
9101
|
"dev": true,
|
|
9108
9102
|
"requires": {
|
|
9109
9103
|
"minimist": "^1.2.0"
|
|
9110
|
-
},
|
|
9111
|
-
"dependencies": {
|
|
9112
|
-
"minimist": {
|
|
9113
|
-
"version": "1.2.5",
|
|
9114
|
-
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
|
9115
|
-
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
|
9116
|
-
"dev": true
|
|
9117
|
-
}
|
|
9118
9104
|
}
|
|
9119
9105
|
},
|
|
9120
9106
|
"kind-of": {
|
|
@@ -9135,9 +9121,9 @@
|
|
|
9135
9121
|
}
|
|
9136
9122
|
},
|
|
9137
9123
|
"lodash": {
|
|
9138
|
-
"version": "4.17.
|
|
9139
|
-
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.
|
|
9140
|
-
"integrity": "sha512-
|
|
9124
|
+
"version": "4.17.21",
|
|
9125
|
+
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
|
9126
|
+
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
|
9141
9127
|
"dev": true
|
|
9142
9128
|
},
|
|
9143
9129
|
"loose-envify": {
|
|
@@ -9261,9 +9247,9 @@
|
|
|
9261
9247
|
}
|
|
9262
9248
|
},
|
|
9263
9249
|
"minimist": {
|
|
9264
|
-
"version": "1.2.
|
|
9265
|
-
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.
|
|
9266
|
-
"integrity": "sha512-
|
|
9250
|
+
"version": "1.2.6",
|
|
9251
|
+
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
|
|
9252
|
+
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
|
|
9267
9253
|
"dev": true
|
|
9268
9254
|
},
|
|
9269
9255
|
"mixin-deep": {
|
|
@@ -9707,9 +9693,9 @@
|
|
|
9707
9693
|
"dev": true
|
|
9708
9694
|
},
|
|
9709
9695
|
"path-parse": {
|
|
9710
|
-
"version": "1.0.
|
|
9711
|
-
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.
|
|
9712
|
-
"integrity": "sha512-
|
|
9696
|
+
"version": "1.0.7",
|
|
9697
|
+
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
|
|
9698
|
+
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
|
|
9713
9699
|
"dev": true
|
|
9714
9700
|
},
|
|
9715
9701
|
"path-to-regexp": {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {Router} from 'express'
|
|
2
|
+
import Flagsmith from '../../../../build'
|
|
3
|
+
|
|
4
|
+
const environmentKey = 'NowEDzKzNJXZVTVanLVdMQ';
|
|
5
|
+
|
|
6
|
+
const flagsmith = new Flagsmith({
|
|
7
|
+
environmentKey
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const api = () => {
|
|
11
|
+
const api = Router();
|
|
12
|
+
|
|
13
|
+
api.get('/', async (req, res) => {
|
|
14
|
+
const flags = await flagsmith.getEnvironmentFlags();
|
|
15
|
+
res.json(flags);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
api.get('/:user', async (req, res) => {
|
|
19
|
+
const flags = await flagsmith.getIdentityFlags(req.params.user, { checkout_v2: 1 });
|
|
20
|
+
const fontSize = flags.getFeatureValue('font_size');
|
|
21
|
+
const checkoutV2 = flags.isFeatureEnabled('checkout_v2');
|
|
22
|
+
res.json({ fontSize, checkoutV2 });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
api.get('/:user/segments', async (req, res) => {
|
|
26
|
+
const segments = await flagsmith.getIdentitySegments(req.params.user, { checkout_v2: 1 });
|
|
27
|
+
res.json(segments.map(v => v.name));
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return api;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default api
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import http from 'http'
|
|
2
|
+
import express from 'express'
|
|
3
|
+
import bodyParser from 'body-parser'
|
|
4
|
+
import api from './api'
|
|
4
5
|
const PORT = process.env.PORT || 3000;
|
|
5
6
|
const app = express();
|
|
6
|
-
const bodyParser = require('body-parser');
|
|
7
7
|
|
|
8
8
|
app.server = http.createServer(app);
|
|
9
9
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<img width="100%" src="https://github.com/Flagsmith/flagsmith/raw/main/static-files/hero.png"/>
|
|
2
|
+
|
|
3
|
+
# Flagsmith Node.js example with caching
|
|
4
|
+
|
|
5
|
+
This is a simple Flagsmith Node.js example that uses node-cache as a way to cache flags and identities with a TTL. This can also be used with other implementations such as Redis, see [here](https://docs.flagsmith.com/v1.0/clients/node#caching-data) for more information.
|
|
6
|
+
```shell
|
|
7
|
+
npm i
|
|
8
|
+
npm run dev
|
|
9
|
+
```
|