Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@frontegg/client

Package Overview
Dependencies
Maintainers
2
Versions
184
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@frontegg/client - npm Package Compare versions

Comparing version 5.1.1-alpha.1 to 6.0.0-alpha.1

dist/src/clients/identity/token-resolvers/access-token-services/cache-services/cache-access-token.service-abstract.d.ts

33

dist/src/clients/identity/token-resolvers/access-token-resolver.js

@@ -8,3 +8,2 @@ "use strict";

const token_resolver_1 = require("./token-resolver");
const cache_1 = require("../../../cache");
const access_token_services_1 = require("./access-token-services");

@@ -14,2 +13,3 @@ const authenticator_1 = require("../../../authenticator");

const frontegg_context_1 = require("../../../components/frontegg-context");
const cache_1 = require("../../../components/cache");
class AccessTokenResolver extends token_resolver_1.TokenResolver {

@@ -39,3 +39,3 @@ constructor() {

...(entityWithRoles || ((options === null || options === void 0 ? void 0 : options.withRolesAndPermissions) ? await this.getEntity(entity) : {})),
...entity
...entity,
};

@@ -46,3 +46,3 @@ }

await this.authenticator.init(FRONTEGG_CLIENT_ID || process.env.FRONTEGG_CLIENT_ID || '', FRONTEGG_API_KEY || process.env.FRONTEGG_API_KEY || '');
this.initAccessTokenServices();
await this.initAccessTokenServices();
}

@@ -65,26 +65,11 @@ getEntity(entity) {

}
initAccessTokenServices() {
var _a, _b;
async initAccessTokenServices() {
if (this.accessTokenServices.length) {
return;
}
const accessTokensOptions = frontegg_context_1.FronteggContext.getOptions().accessTokensOptions;
if (((_a = accessTokensOptions === null || accessTokensOptions === void 0 ? void 0 : accessTokensOptions.cache) === null || _a === void 0 ? void 0 : _a.type) === 'ioredis') {
this.accessTokenServices = [
new access_token_services_1.CacheTenantAccessTokenService(new cache_1.IORedisCacheManager(accessTokensOptions.cache.options), new cache_1.IORedisCacheManager(accessTokensOptions.cache.options), new access_token_services_1.TenantAccessTokenService(this.httpClient)),
new access_token_services_1.CacheUserAccessTokenService(new cache_1.IORedisCacheManager(accessTokensOptions.cache.options), new cache_1.IORedisCacheManager(accessTokensOptions.cache.options), new access_token_services_1.UserAccessTokenService(this.httpClient)),
];
}
else if (((_b = accessTokensOptions === null || accessTokensOptions === void 0 ? void 0 : accessTokensOptions.cache) === null || _b === void 0 ? void 0 : _b.type) === 'redis') {
this.accessTokenServices = [
new access_token_services_1.CacheTenantAccessTokenService(new cache_1.RedisCacheManager(accessTokensOptions.cache.options), new cache_1.RedisCacheManager(accessTokensOptions.cache.options), new access_token_services_1.TenantAccessTokenService(this.httpClient)),
new access_token_services_1.CacheUserAccessTokenService(new cache_1.RedisCacheManager(accessTokensOptions.cache.options), new cache_1.RedisCacheManager(accessTokensOptions.cache.options), new access_token_services_1.UserAccessTokenService(this.httpClient)),
];
}
else {
this.accessTokenServices = [
new access_token_services_1.CacheTenantAccessTokenService(new cache_1.LocalCacheManager(), new cache_1.LocalCacheManager(), new access_token_services_1.TenantAccessTokenService(this.httpClient)),
new access_token_services_1.CacheUserAccessTokenService(new cache_1.LocalCacheManager(), new cache_1.LocalCacheManager(), new access_token_services_1.UserAccessTokenService(this.httpClient)),
];
}
const cache = await cache_1.FronteggCache.getInstance();
this.accessTokenServices = [
new access_token_services_1.CacheTenantAccessTokenService(cache, new access_token_services_1.TenantAccessTokenService(this.httpClient)),
new access_token_services_1.CacheUserAccessTokenService(cache, new access_token_services_1.UserAccessTokenService(this.httpClient)),
];
}

@@ -91,0 +76,0 @@ }

@@ -1,11 +0,8 @@

import { ICacheManager } from '../../../../../cache/cache.manager.interface';
import { IEmptyAccessToken, IEntityWithRoles, ITenantAccessToken } from '../../../types';
import { ICacheManager } from '../../../../../components/cache/managers/cache.manager.interface';
import { ITenantAccessToken } from '../../../types';
import { AccessTokenService } from '../services/access-token.service';
import { CacheAccessTokenService } from './cache-access-token.service';
export declare class CacheTenantAccessTokenService extends CacheAccessTokenService<ITenantAccessToken> {
readonly entityCacheManager: ICacheManager<IEntityWithRoles | IEmptyAccessToken>;
readonly activeAccessTokensCacheManager: ICacheManager<string[]>;
readonly tenantAccessTokenService: AccessTokenService<ITenantAccessToken>;
constructor(entityCacheManager: ICacheManager<IEntityWithRoles | IEmptyAccessToken>, activeAccessTokensCacheManager: ICacheManager<string[]>, tenantAccessTokenService: AccessTokenService<ITenantAccessToken>);
import { CacheAccessTokenServiceAbstract } from './cache-access-token.service-abstract';
export declare class CacheTenantAccessTokenService extends CacheAccessTokenServiceAbstract<ITenantAccessToken> {
constructor(cacheManager: ICacheManager<any>, tenantAccessTokenService: AccessTokenService<ITenantAccessToken>);
protected getCachePrefix(): string;
}

@@ -5,12 +5,9 @@ "use strict";

const types_1 = require("../../../types");
const cache_access_token_service_1 = require("./cache-access-token.service");
class CacheTenantAccessTokenService extends cache_access_token_service_1.CacheAccessTokenService {
constructor(entityCacheManager, activeAccessTokensCacheManager, tenantAccessTokenService) {
super(entityCacheManager, activeAccessTokensCacheManager, tenantAccessTokenService, types_1.tokenTypes.TenantAccessToken);
this.entityCacheManager = entityCacheManager;
this.activeAccessTokensCacheManager = activeAccessTokensCacheManager;
this.tenantAccessTokenService = tenantAccessTokenService;
const cache_access_token_service_abstract_1 = require("./cache-access-token.service-abstract");
class CacheTenantAccessTokenService extends cache_access_token_service_abstract_1.CacheAccessTokenServiceAbstract {
constructor(cacheManager, tenantAccessTokenService) {
super(cacheManager, tenantAccessTokenService, types_1.tokenTypes.TenantAccessToken);
}
getCachePrefix() {
return 'frontegg_sdk_v1_user_access_tokens';
return 'frontegg_sdk_v1_user_access_tokens_';
}

@@ -17,0 +14,0 @@ }

@@ -1,11 +0,9 @@

import { ICacheManager } from '../../../../../cache/cache.manager.interface';
import { IEmptyAccessToken, IEntityWithRoles, IUserAccessToken } from '../../../types';
import { ICacheManager } from '../../../../../components/cache/managers/cache.manager.interface';
import { IUserAccessToken } from '../../../types';
import { AccessTokenService } from '../services/access-token.service';
import { CacheAccessTokenService } from './cache-access-token.service';
export declare class CacheUserAccessTokenService extends CacheAccessTokenService<IUserAccessToken> {
readonly entityCacheManager: ICacheManager<IEntityWithRoles | IEmptyAccessToken>;
readonly activeAccessTokensCacheManager: ICacheManager<string[]>;
import { CacheAccessTokenServiceAbstract } from './cache-access-token.service-abstract';
export declare class CacheUserAccessTokenService extends CacheAccessTokenServiceAbstract<IUserAccessToken> {
readonly userAccessTokenService: AccessTokenService<IUserAccessToken>;
constructor(entityCacheManager: ICacheManager<IEntityWithRoles | IEmptyAccessToken>, activeAccessTokensCacheManager: ICacheManager<string[]>, userAccessTokenService: AccessTokenService<IUserAccessToken>);
constructor(cacheManager: ICacheManager<any>, userAccessTokenService: AccessTokenService<IUserAccessToken>);
protected getCachePrefix(): string;
}

@@ -5,12 +5,10 @@ "use strict";

const types_1 = require("../../../types");
const cache_access_token_service_1 = require("./cache-access-token.service");
class CacheUserAccessTokenService extends cache_access_token_service_1.CacheAccessTokenService {
constructor(entityCacheManager, activeAccessTokensCacheManager, userAccessTokenService) {
super(entityCacheManager, activeAccessTokensCacheManager, userAccessTokenService, types_1.tokenTypes.UserAccessToken);
this.entityCacheManager = entityCacheManager;
this.activeAccessTokensCacheManager = activeAccessTokensCacheManager;
const cache_access_token_service_abstract_1 = require("./cache-access-token.service-abstract");
class CacheUserAccessTokenService extends cache_access_token_service_abstract_1.CacheAccessTokenServiceAbstract {
constructor(cacheManager, userAccessTokenService) {
super(cacheManager, userAccessTokenService, types_1.tokenTypes.UserAccessToken);
this.userAccessTokenService = userAccessTokenService;
}
getCachePrefix() {
return 'frontegg_sdk_v1_tenant_access_tokens';
return 'frontegg_sdk_v1_tenant_access_tokens_';
}

@@ -17,0 +15,0 @@ }

import { IFronteggContext, IFronteggOptions } from './types';
export declare class FronteggContext {
static getInstance(): FronteggContext;
static init(context: IFronteggContext, options?: IFronteggOptions): void;
static init(context: IFronteggContext, givenOptions?: Partial<IFronteggOptions>): void;
static getContext(): IFronteggContext;

@@ -12,5 +12,6 @@ static getOptions(): IFronteggOptions;

private validateOptions;
private validateAccessTokensOptions;
private validateCacheOptions;
private validateIORedisOptions;
private validateRedisOptions;
private static prepareOptions;
}

@@ -5,2 +5,7 @@ "use strict";

const package_loader_1 = require("../../utils/package-loader");
const DEFAULT_OPTIONS = {
cache: {
type: 'local',
},
};
class FronteggContext {

@@ -13,6 +18,7 @@ static getInstance() {

}
static init(context, options) {
static init(context, givenOptions) {
const options = FronteggContext.prepareOptions(givenOptions);
FronteggContext.getInstance().validateOptions(options);
FronteggContext.getInstance().options = options;
FronteggContext.getInstance().context = context;
FronteggContext.getInstance().validateOptions(options);
FronteggContext.getInstance().options = options !== null && options !== void 0 ? options : {};
}

@@ -26,23 +32,20 @@ static getContext() {

static getOptions() {
return FronteggContext.getInstance().options || {};
return FronteggContext.getInstance().options;
}
constructor() {
this.context = null;
this.options = {};
this.options = DEFAULT_OPTIONS;
}
validateOptions(options) {
if (options === null || options === void 0 ? void 0 : options.accessTokensOptions) {
this.validateAccessTokensOptions(options.accessTokensOptions);
if (options.cache) {
this.validateCacheOptions(options.cache);
}
}
validateAccessTokensOptions(accessTokensOptions) {
if (!accessTokensOptions.cache) {
throw new Error(`'cache' is missing from access tokens options`);
validateCacheOptions(cache) {
if (cache.type === 'ioredis') {
this.validateIORedisOptions(cache.options);
}
if (accessTokensOptions.cache.type === 'ioredis') {
this.validateIORedisOptions(accessTokensOptions.cache.options);
else if (cache.type === 'redis') {
this.validateRedisOptions(cache.options);
}
else if (accessTokensOptions.cache.type === 'redis') {
this.validateRedisOptions(accessTokensOptions.cache.options);
}
}

@@ -67,4 +70,10 @@ validateIORedisOptions(redisOptions) {

}
static prepareOptions(options) {
return {
...DEFAULT_OPTIONS,
...(options || {}),
};
}
}
exports.FronteggContext = FronteggContext;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import { IIORedisCacheOptions, IRedisCacheOptions } from '../../cache/types';
import { IIORedisOptions, IRedisOptions } from '../cache/managers';
export interface IFronteggContext {

@@ -7,21 +7,18 @@ FRONTEGG_CLIENT_ID: string;

export interface IFronteggOptions {
cache?: IAccessTokensLocalCache | IAccessTokensIORedisCache | IAccessTokensRedisCache;
accessTokensOptions?: IAccessTokensOptions;
cache: IFronteggCacheOptions;
}
export interface IAccessTokensOptions {
cache: IAccessTokensLocalCache | IAccessTokensIORedisCache | IAccessTokensRedisCache;
}
export interface IAccessTokensCache {
export interface IBaseCacheOptions {
type: 'ioredis' | 'local' | 'redis';
}
export interface IAccessTokensLocalCache extends IAccessTokensCache {
export interface ILocalCacheOptions extends IBaseCacheOptions {
type: 'local';
}
export interface IAccessTokensIORedisCache extends IAccessTokensCache {
export interface IIORedisCacheOptions extends IBaseCacheOptions {
type: 'ioredis';
options: IIORedisCacheOptions;
options: IIORedisOptions;
}
export interface IAccessTokensRedisCache extends IAccessTokensCache {
export interface IRedisCacheOptions extends IBaseCacheOptions, IRedisOptions {
type: 'redis';
options: IRedisCacheOptions;
options: IRedisOptions;
}
export type IFronteggCacheOptions = ILocalCacheOptions | IIORedisCacheOptions | IRedisCacheOptions;
export declare class PackageUtils {
static loadPackage(name: string): unknown;
static loadPackage<T = unknown>(name: string): T;
}

@@ -0,1 +1,23 @@

# [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)

@@ -2,0 +24,0 @@

{
"name": "@frontegg/client",
"version": "5.1.1-alpha.1",
"version": "6.0.0-alpha.1",
"description": "Frontegg Javascript Library for backend node servers",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -62,2 +62,44 @@ <br />

### 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

@@ -85,3 +127,3 @@

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:

@@ -91,57 +133,4 @@ - ioredis

#### Use ioredis as your cache
When initializing your context, pass an access tokens options object with your ioredis parameters
For details on cache configuration, refer to <a href="#redis-cache">Redis cache</a> section.
```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,
},
);
```
### Clients

@@ -160,3 +149,3 @@

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

@@ -302,3 +291,3 @@

```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>' });
```

@@ -305,0 +294,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc