Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
6ad2ca7
feat: initial sdk rewrite
eder-zadrima Mar 8, 2022
37e8964
chore: refactor tests structure to account for sdk tests
eder-zadrima Mar 8, 2022
35ceaa0
feat: add flagsmith node.js SDK implementation
eder-zadrima Mar 10, 2022
d8bfea9
chore: minor refactoring
eder-zadrima Mar 10, 2022
d1c9631
docs: add JSDoc comments for the SDK
eder-zadrima Mar 10, 2022
3c7de37
docs: update example of SDK usage
eder-zadrima Mar 10, 2022
869107e
chore: add example to precommit linting
eder-zadrima Mar 10, 2022
2c9d554
chore: add gh action for tests
eder-zadrima Mar 10, 2022
3a11cbe
chore: trigger tests when pushed to main
eder-zadrima Mar 10, 2022
ffd8e1d
fix: retry logic for sdk
eder-zadrima Mar 10, 2022
5dba295
SDK Fixes
kyle-ssg Mar 14, 2022
89bc661
Throw on empty SDK key
kyle-ssg Mar 14, 2022
3eb2b1a
Minor
kyle-ssg Mar 14, 2022
cd487db
Update test, update updateEnvironment function names
kyle-ssg Mar 14, 2022
dce0afc
Log defaultFlagHandler on Feature does not exist error
kyle-ssg Mar 14, 2022
3de5c72
Merge pull request #24 from Flagsmith/sdk-rewrite-improvements
kyle-ssg Mar 15, 2022
9c4c1b4
Update example package.json readme
kyle-ssg Mar 15, 2022
eb474e6
Renamed BT to Flagsmith last remnants
dabeeeenster Mar 15, 2022
3f54c41
Use flagsmith 2.0.0-beta.1 in example
kyle-ssg Mar 15, 2022
c57ac4e
Merge remote-tracking branch 'origin/sdk-rewrite' into sdk-rewrite
kyle-ssg Mar 15, 2022
aebddc9
chore: fixes as per PR comments
eder-zadrima Mar 16, 2022
76f9d6c
chore: update exports for commonjs valid module
eder-zadrima Mar 16, 2022
f722f1d
chore: fix exporting issues
eder-zadrima Mar 17, 2022
9b55819
Fix setTrait Return Type
beeme1mr Apr 8, 2022
78b96e0
Fix traits logic
Apr 12, 2022
3d1987e
Merge pull request #27 from Flagsmith/fix/identity-flags-with-traits
kyle-ssg Apr 13, 2022
1c75677
Bump version
kyle-ssg Apr 13, 2022
bd66dcc
Merge pull request #26 from beeme1mr/fix-set-trait-typing
kyle-ssg Apr 13, 2022
7d33644
Prevent local eval race conditions, getIdentitySegments, add server k…
kyle-ssg Apr 16, 2022
ce8dde2
lint
kyle-ssg Apr 16, 2022
bf64da2
Adjust default flag handling
kyle-ssg Apr 27, 2022
a4a76c8
correct retries prop
kyle-ssg Apr 27, 2022
945192d
correct retries prop
kyle-ssg Apr 27, 2022
f95ad4c
added asdf
dabeeeenster May 17, 2022
6a8a31d
Version bump
dabeeeenster May 17, 2022
5f4aa26
Merge pull request #28 from Flagsmith/v2/get_identity_segments
kyle-ssg May 17, 2022
187b9db
bump 2.0.0-beta.5, build on prepublish
kyle-ssg May 17, 2022
c8e16ce
ES5 support, beta.6 bump
kyle-ssg May 18, 2022
af72ca3
ES5 compat for IdentityFeaturesList
kyle-ssg May 18, 2022
571b513
PR Feedback
kyle-ssg May 18, 2022
605a264
Resolve todo on mv test
kyle-ssg May 18, 2022
ad5b25b
Merge branch 'main' into sdk-rewrite
kyle-ssg May 18, 2022
5aca735
chore: update tests
eder-zadrima May 18, 2022
0fcebde
Merge branch 'sdk-rewrite' of https://github.com/Flagsmith/flagsmith-…
eder-zadrima May 18, 2022
298ab46
chore: remove redundant submodule
eder-zadrima May 18, 2022
707fbd9
chore: remove submodule files
eder-zadrima May 19, 2022
e121229
chore: fix tests running for submodule with test data
eder-zadrima May 19, 2022
7d92229
chore: wip on submodule
eder-zadrima May 19, 2022
32e0bb9
chore: clear old submodule
eder-zadrima May 19, 2022
7bbeea5
fix: get test data after clone
eder-zadrima May 19, 2022
e2c3c27
fix: checkout submodules on the action stage
eder-zadrima May 19, 2022
92fc1fe
chore: additional tests
eder-zadrima May 19, 2022
8db2de4
feat: add caching & tests
eder-zadrima May 20, 2022
d69e2a3
feat: add onEnvironmentChange callback
eder-zadrima May 21, 2022
255a977
chore: add test for local environment + identity flags
eder-zadrima May 21, 2022
de5a9f1
chore: fix race condition checking for environment flags
eder-zadrima May 21, 2022
60ffc15
chore: add misc tests
eder-zadrima May 21, 2022
ba0cdb5
chore: split sdk main test file
eder-zadrima May 21, 2022
fe39a33
bump 2.0.0-beta.7
kyle-ssg May 24, 2022
b63f461
chore: add test coverage
eder-zadrima May 25, 2022
78cb01c
feat: feature segments add
eder-zadrima May 26, 2022
0914942
Merge branch 'sdk-rewrite' of https://github.com/Flagsmith/flagsmith-…
eder-zadrima May 26, 2022
0a86930
fix: feature state priority calculation
eder-zadrima May 31, 2022
d944be5
chore: remove unused code
eder-zadrima May 31, 2022
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