Skip to content
Draft
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
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
62 changes: 62 additions & 0 deletions package-lock.json

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

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"build:watch": "rm -rf dist && tsc --watch",
"lint": "eslint --ignore-path .eslintignore --ext .js,.ts .",
"format": "prettier --write \"**/*.+(js|ts|json)\"",
"test": "npm run build && jest",
"test:coverage": "npm test -- --coverage",
"test:jest": "npm run build && jest --runInBand",
"test": "(cd ci; ./run-test-suite.sh)",
"test:coverage": "npm test",
"test:watch": "npm run build && jest --watch",
"dev": "tsc --watch"
},
Expand All @@ -22,6 +23,7 @@
"license": "ISC",
"homepage": "https://github.com/frontegg/nodejs-sdk",
"dependencies": {
"@frontegg/entitlements-javascript-commons": "^1.0.0-alpha.12",
"@slack/web-api": "^6.7.2",
"axios": "^0.27.2",
"jsonwebtoken": "^9.0.0",
Expand All @@ -41,6 +43,8 @@
}
},
"devDependencies": {
"@fast-check/jest": "^1.7.3",
"@frontegg/entitlements-service-types": "^0.29.0",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@types/axios-mock-adapter": "^1.10.0",
Expand All @@ -58,6 +62,7 @@
"ioredis": "^5.2.5",
"ioredis-mock": "^8.2.2",
"jest": "^28.1.3",
"jest-extended": "^4.0.2",
"jest-junit": "^14.0.1",
"jest-mock-extended": "^3.0.4",
"prettier": "^2.7.1",
Expand Down
9 changes: 0 additions & 9 deletions src/cache/cache.manager.interface.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/cache/index.ts

This file was deleted.

40 changes: 0 additions & 40 deletions src/cache/ioredis-cache.manager.spec.ts

This file was deleted.

Loading