Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Unit/Integration Tests

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
push:
branches:
- main
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout submodules # checkout rest
shell: bash
run: |
# If your submodules are configured to use SSH instead of HTTPS please uncomment the following line
git config --global url."https://github.com/".insteadOf "git@github.com:"
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
- uses: actions/setup-node@v1
with:
node-version: "15.x"
- name: cache node modules
uses: actions/cache@v1
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: |
npm-${{ hashFiles('package-lock.json') }}
npm-
- run: npm i -g npm@7.0.2
- run: npm install
- run: npm test
env:
CI: true
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@

.idea/*

node_modules/
node_modules/
build/

.tool-versions
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tests/engine/engine-tests/engine-test-data"]
path = tests/engine/engine-tests/engine-test-data
url = git@github.com:Flagsmith/engine-test-data.git
6 changes: 6 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
git add ./flagsmith-engine ./sdk ./tests ./example ./index.ts ./.github
npm run test
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ Please read [CONTRIBUTING.md](https://gist.github.com/kyle-ssg/c36a03aebe492e45c

If you encounter a bug or feature request we would like to hear about it. Before you submit an issue please search existing issues in order to prevent duplicates.

## Testing

To run the local tests you need to run following command beforehand:
```
git submodule add git@github.com:Flagsmith/engine-test-data.git tests/engine/engine-tests/engine-test-data/
```

## Get in touch

If you have any questions about our projects you can email <a href="mailto:support@flagsmith.com">support@flagsmith.com</a>.
Expand Down
6 changes: 0 additions & 6 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

## Getting Started

# Setup via cli

`npm i ssg-node -g`

`ssg-node PROJECT_NAME`

# Run

`$ npm start`
Expand Down
75 changes: 74 additions & 1 deletion example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "node-minimal",
"name": "flagsmith-nodejs-example",
"version": "0.1.1",
"description": "Node Express Boilerplate",
"description": "An example using the flagsmith nodejs library",
"main": "index.js",
"scripts": {
"start": "node --inspect ./server",
"start": "cd ../ && npm run build && cd ./example && node --inspect ./server",
"dev": "nodemon --exec npm start",
"test": "nodemon ./server/tests/"
},
Expand All @@ -15,6 +15,7 @@
"npm": "3.10.x"
},
"dependencies": {
"flagsmith-nodejs": "^2.0.0-beta.1",
"node-cache": "^5.1.2",
"ssg-node-express": "4.16.4",
"ssg-util": "0.0.3"
Expand Down
41 changes: 23 additions & 18 deletions example/server/api/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
const Router = require('express').Router;
const environmentID = 'uCDQzKWgejrutqSYYsKWen';
const flagsmith = require('../../../');
const NodeCache = require('node-cache');

flagsmith.init({
environmentID
// this is an example of a user-defined cache
/*cache: new NodeCache({
stdTTL: 5
})*/
const Flagsmith = require('../../../build');
const environmentKey = '';
if (!environmentKey) {
throw new Error(
'Please generate a Server Side SDK Key in environment settings to run the example'
);
}
const flagsmith = new Flagsmith({
environmentKey,
enableLocalEvaluation: true,
defaultFlagHandler: str => {
return { enabled: false, isDefault: true, value: null };
}
});

module.exports = () => {
const api = Router();

api.get('/', async (req, res) => {
const font_size = await flagsmith.getValue('font_size');
res.json({ font_size });
});

api.get('/flags', async (req, res) => {
const flags = await flagsmith.getFlags();
const flags = await flagsmith.getEnvironmentFlags();
res.json(flags);
});

api.get('/:user', async (req, res) => {
const font_size = await flagsmith.getValue('font_size', req.params.user);
res.json({ font_size });
const flags = await flagsmith.getIdentityFlags(req.params.user, { checkout_v2: 1 });
const fontSize = flags.getFeatureValue('font_size');
const checkoutV2 = flags.isFeatureEnabled('checkout_v2');
res.json({ fontSize, checkoutV2 });
});

api.get('/:user/segments', async (req, res) => {
const segments = await flagsmith.getIdentitySegments(req.params.user, { checkout_v2: 1 });
res.json(segments.map(v => v.name));
});

return api;
Expand Down
13 changes: 7 additions & 6 deletions example/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ app.server = http.createServer(app);
app.use(bodyParser.json());

// api router
app.use('/', api());
app.use('/api', api());

app.server.listen(PORT);
console.log('Server started on port ' + app.server.address().port);
console.log();
console.log('Go to http://localhost:' + PORT + '/');
console.log('To get an example feature state');
console.log('Go to http://localhost:' + PORT + '/api');
console.log('To get an example response for getFlags');
console.log();
console.log('Go to http://localhost:' + PORT + '/flagsmith_sample_user');
console.log('Go to http://localhost:' + PORT + '/api/flagsmith_sample_user');
console.log('To get an example feature state for a user');
console.log('Go to http://localhost:' + PORT + '/flags');
console.log('To get an example response for getFlags');
console.log();
console.log('Go to http://localhost:' + PORT + '/api/flagsmith_sample_user/segments');
console.log('To get the segments which the user belongs to');

module.exports = app;
Loading