Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
85db523
feat(cache): decoupled cache managers from AccessTokens
arturwolny-frontegg Jul 13, 2023
9051f01
build(sdk): npm audit fix
arturwolny-frontegg Jul 14, 2023
7d04440
fix(cache): Bringing back the ICacheManager generic to the class level
arturwolny-frontegg Jul 17, 2023
3bbe939
refactor(sdk): removed irrelevant accessTokenOptions; refactored cach…
arturwolny-frontegg Jul 19, 2023
579d601
build(sdk): updated lock file
arturwolny-frontegg Jul 21, 2023
e30ee78
refactor(sdk): ran lint fix
arturwolny-frontegg Jul 22, 2023
756dfb9
refactor(sdk): removed irrelevant process warning
arturwolny-frontegg Jul 30, 2023
e226bac
docs(sdk): removed examples of Redis cache configuration in access to…
arturwolny-frontegg Jul 30, 2023
fcc357c
refactor(sdk): formatted code
arturwolny-frontegg Jul 30, 2023
1404bfe
Merge pull request #154 from frontegg/FR-12681-redis-cache-refactor
arturwolny-frontegg Jul 31, 2023
5b17898
chore(release): 6.0.0-alpha.1 [skip ci]
semantic-release-bot Jul 31, 2023
4b416f8
feat(cache): Adjusted cache to support collections/sets and maps/hash…
arturwolny-frontegg Jul 17, 2023
dfb138e
feat(entitlements): Introduced the entitlements cache based of genera…
arturwolny-frontegg Jul 30, 2023
83be07d
refactor(entitlements): adjust the entitlements cache with refactored…
arturwolny-frontegg Aug 1, 2023
0eec25e
refactor(sdk): reformatting applied
arturwolny-frontegg Aug 1, 2023
3ec0c67
ci(sdk): fixed tests in CI
arturwolny-frontegg Aug 1, 2023
5c3bbf3
feature(entitlements): leader election for entitlements client cache …
arturwolny-frontegg Aug 14, 2023
3ec695b
feature(entitlements): CR fixes
arturwolny-frontegg Aug 28, 2023
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
103 changes: 46 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,48 @@ FronteggContext.init({
});
```

### Redis cache
Some parts of SDK can facilitate the Redis cache for the sake of performance. To set up the cache, pass additional options
to `FronteggContext.init(..)` call.
If no cache is configured, then data is cached locally, in NodeJS process memory.

#### Redis cache with `ioredis` library
```javascript
const { FronteggContext } = require('@frontegg/client');

FronteggContext.init({
FRONTEGG_CLIENT_ID: '<YOUR_CLIENT_ID>',
FRONTEGG_API_KEY: '<YOUR_API_KEY>',
}, {
cache: {
type: 'ioredis',
options: {
host: 'localhost',
port: 6379,
password: '',
db: 10,
}
}
});
```

#### Redis cache with `redis` library
```javascript
const { FronteggContext } = require('@frontegg/client');

FronteggContext.init({
FRONTEGG_CLIENT_ID: '<YOUR_CLIENT_ID>',
FRONTEGG_API_KEY: '<YOUR_API_KEY>',
}, {
cache: {
type: 'redis',
options: {
url: 'redis[s]://[[username][:password]@][host][:port][/db-number]',
}
}
});
```

### Middleware

Use Frontegg's "withAuthentication" auth guard to protect your routes.
Expand All @@ -81,65 +123,12 @@ Head over to the <a href="https://docs.frontegg.com/docs/using-frontegg-sdk">Doc
### Access tokens

When using M2M authentication, access tokens will be cached by the SDK.
By default access tokens will be cached locally, however you can use two other kinds of cache:
By default, access tokens will be cached locally, however you can use two other kinds of cache:

- ioredis
- redis

#### Use ioredis as your cache
When initializing your context, pass an access tokens options object with your ioredis parameters

```javascript
const { FronteggContext } = require('@frontegg/client');

const accessTokensOptions = {
cache: {
type: 'ioredis',
options: {
host: 'localhost',
port: 6379,
password: '',
db: 10,
},
},
};

FronteggContext.init(
{
FRONTEGG_CLIENT_ID: '<YOUR_CLIENT_ID>',
FRONTEGG_API_KEY: '<YOUR_API_KEY>',
},
{
accessTokensOptions,
},
);
```

#### Use redis as your cache
When initializing your context, pass an access tokens options object with your redis parameters

```javascript
const { FronteggContext } = require('@frontegg/client');

const accessTokensOptions = {
cache: {
type: 'redis',
options: {
url: 'redis[s]://[[username][:password]@][host][:port][/db-number]',
},
},
};

FronteggContext.init(
{
FRONTEGG_CLIENT_ID: '<YOUR_CLIENT_ID>',
FRONTEGG_API_KEY: '<YOUR_API_KEY>',
},
{
accessTokensOptions,
},
);
```
For details on cache configuration, refer to <a href="#redis-cache">Redis cache</a> section.

### Clients

Expand All @@ -154,7 +143,7 @@ const { AuditsClient } = require('@frontegg/client');
const audits = new AuditsClient();

// initialize the module
await audits.init('MY-CLIENT-ID', 'MY-AUDITS-KEY');
await audits.init('<YOUR_CLIENT_ID>', '<YOUR_API_KEY>');
```

#### Sending audits
Expand Down Expand Up @@ -295,7 +284,7 @@ const { IdentityClient } = require('@frontegg/client');
Then, initialize the client

```javascript
const identityClient = new IdentityClient({ FRONTEGG_CLIENT_ID: 'your-client-id', FRONTEGG_API_KEY: 'your-api-key' });
const identityClient = new IdentityClient({ FRONTEGG_CLIENT_ID: '<YOUR_CLIENT_ID>', FRONTEGG_API_KEY: '<YOUR_API_KEY>' });
```

And use this client to validate
Expand Down
7 changes: 7 additions & 0 deletions ci/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "3"
services:
redis:
image: redis
restart: always
ports:
- 36279:6379
12 changes: 12 additions & 0 deletions ci/run-test-suite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -e

docker compose -p nodejs-sdk-tests up -d --wait

npm run --prefix ../ test:jest --coverage
RESULT=$@

docker compose -p nodejs-sdk-tests down

exit $RESULT
22 changes: 22 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# [6.0.0-alpha.1](https://github.com/frontegg/nodejs-sdk/compare/5.1.1-alpha.1...6.0.0-alpha.1) (2023-07-31)


### Code Refactoring

* **sdk:** removed irrelevant accessTokenOptions; refactored cache manager implementations ([3bbe939](https://github.com/frontegg/nodejs-sdk/commit/3bbe93926e52eda261db11bb6fbdd65671074e4e))


### Bug Fixes

* **cache:** Bringing back the ICacheManager generic to the class level ([7d04440](https://github.com/frontegg/nodejs-sdk/commit/7d04440ab94e66d0155032597d42ec8b17c4b1da))


### Features

* **cache:** decoupled cache managers from AccessTokens ([85db523](https://github.com/frontegg/nodejs-sdk/commit/85db5230d7530e2e61dcea8e79174148e9cb1f6f))


### BREAKING CHANGES

* **sdk:** removed accessTokenOptions from FronteggContext configuration

## [5.1.1-alpha.1](https://github.com/frontegg/nodejs-sdk/compare/5.1.0...5.1.1-alpha.1) (2023-07-30)


Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
lines: 18,
},
},
setupFilesAfterEnv: ['jest-extended/all'],
reporters: [
'default',
[
Expand Down
125 changes: 122 additions & 3 deletions package-lock.json

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

Loading