flagsmith-nodejs 2.0.2 → 2.1.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/README.md +1 -1
- package/build/flagsmith-engine/index.d.ts +7 -0
- package/build/flagsmith-engine/index.js +15 -1
- package/build/index.d.ts +2 -1
- package/build/index.js +15 -3
- package/build/sdk/index.d.ts +5 -0
- package/build/sdk/index.js +19 -1
- package/build/sdk/types.d.ts +3 -3
- package/es6-example/.babelrc +3 -0
- package/es6-example/.eslintrc +8 -0
- package/es6-example/README.md +62 -0
- package/es6-example/package-lock.json +10585 -0
- package/es6-example/package.json +55 -0
- package/es6-example/src/api/index.js +50 -0
- package/es6-example/src/index.js +29 -0
- package/example/package-lock.json +1573 -21
- package/example/package.json +4 -1
- package/example/server/api/index.js +6 -3
- package/example/server/index.js +1 -1
- package/flagsmith-engine/index.ts +8 -0
- package/index.ts +19 -2
- package/package.json +3 -2
- package/sdk/analytics.ts +2 -2
- package/sdk/index.ts +12 -0
- package/sdk/models.ts +1 -1
- package/sdk/types.ts +4 -4
- package/tests/sdk/analytics.test.ts +10 -10
- package/tests/sdk/utils.ts +2 -1
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
"node-cache": "^5.1.2"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {Router} from 'express'
|
|
2
|
+
import Flagsmith from '../../../build'
|
|
3
|
+
|
|
4
|
+
const environmentKey = '';
|
|
5
|
+
import nodecache from "node-cache";
|
|
6
|
+
|
|
7
|
+
if (!environmentKey) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
'Please generate a Server Side SDK Key in environment settings to run the example'
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
const flagsmith = new Flagsmith({
|
|
13
|
+
environmentKey,
|
|
14
|
+
enableLocalEvaluation: true,
|
|
15
|
+
cache: new nodecache({
|
|
16
|
+
stdTTL: 10,
|
|
17
|
+
checkperiod: 10,
|
|
18
|
+
}),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// solicitor
|
|
23
|
+
|
|
24
|
+
// read only
|
|
25
|
+
// sra authorisation date
|
|
26
|
+
|
|
27
|
+
const api = () => {
|
|
28
|
+
const api = Router();
|
|
29
|
+
|
|
30
|
+
api.get('/', async (req, res) => {
|
|
31
|
+
const flags = await flagsmith.getEnvironmentFlags();
|
|
32
|
+
res.json(flags);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
api.get('/:user', async (req, res) => {
|
|
36
|
+
const flags = await flagsmith.getIdentityFlags(req.params.user, { checkout_v2: 1 });
|
|
37
|
+
const fontSize = flags.getFeatureValue('font_size');
|
|
38
|
+
const checkoutV2 = flags.isFeatureEnabled('checkout_v2');
|
|
39
|
+
res.json({ fontSize, checkoutV2 });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
api.get('/:user/segments', async (req, res) => {
|
|
43
|
+
const segments = await flagsmith.getIdentitySegments(req.params.user, { checkout_v2: 1 });
|
|
44
|
+
res.json(segments.map(v => v.name));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return api;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default api
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import http from 'http'
|
|
2
|
+
import express from 'express'
|
|
3
|
+
import bodyParser from 'body-parser'
|
|
4
|
+
import api from './api'
|
|
5
|
+
const PORT = process.env.PORT || 3000;
|
|
6
|
+
const app = express();
|
|
7
|
+
|
|
8
|
+
app.server = http.createServer(app);
|
|
9
|
+
|
|
10
|
+
//Apply middleware
|
|
11
|
+
// parse various different custom JSON types as JSON
|
|
12
|
+
app.use(bodyParser.json());
|
|
13
|
+
|
|
14
|
+
// api router
|
|
15
|
+
app.use('/api', api());
|
|
16
|
+
|
|
17
|
+
app.server.listen(PORT);
|
|
18
|
+
console.log('Server started on port ' + PORT);
|
|
19
|
+
console.log();
|
|
20
|
+
console.log('Go to http://localhost:' + PORT + '/api');
|
|
21
|
+
console.log('To get an example response for getFlags');
|
|
22
|
+
console.log();
|
|
23
|
+
console.log('Go to http://localhost:' + PORT + '/api/flagsmith_sample_user');
|
|
24
|
+
console.log('To get an example feature state for a user');
|
|
25
|
+
console.log();
|
|
26
|
+
console.log('Go to http://localhost:' + PORT + '/api/flagsmith_sample_user/segments');
|
|
27
|
+
console.log('To get the segments which the user belongs to');
|
|
28
|
+
|
|
29
|
+
module.exports = app;
|