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

@frontegg/rest-api

Package Overview
Dependencies
Maintainers
3
Versions
621
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@frontegg/rest-api - npm Package Compare versions

Comparing version 3.1.74-alpha.9436935127 to 3.1.74-alpha.9437859720

18

auth/index.js

@@ -11,3 +11,2 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";

import { urls } from "../constants";
import { getFronteggContext } from '../ContextHolder';
import { jwtDecode } from "../jwt";

@@ -21,2 +20,3 @@ import { LOAD_AUTHORIZATION_FF } from './interfaces';

import { EntitlementsApi } from '../entitlements';
import { ContextHolder } from '../ContextHolder';
export class AuthenticationApi extends BaseApiClient {

@@ -33,3 +33,3 @@ constructor(appName) {

const contextHolder = getFronteggContext(this.appName);
const contextHolder = ContextHolder.for(this.appName);
contextHolder.setAccessToken(loginResponse.accessToken);

@@ -41,3 +41,3 @@ const me = await this.getMeAndEntitlements();

getFronteggContext(this.appName).setUser(user);
contextHolder.setUser(user);
return user;

@@ -53,3 +53,3 @@ };

const contextHolder = getFronteggContext(this.appName);
const contextHolder = ContextHolder.for(this.appName);
contextHolder.setAccessToken(loginResponse.accessToken);

@@ -61,3 +61,3 @@ const [me, tenants] = await Promise.all([this.getMeAndEntitlements(), this.tenantsApi.getTenants()]);

getFronteggContext(this.appName).setUser(user);
contextHolder.setUser(user);
return {

@@ -80,3 +80,3 @@ user,

const contextHolder = getFronteggContext(this.appName);
const contextHolder = ContextHolder.for(this.appName);
contextHolder.setAccessToken(accessToken);

@@ -101,3 +101,3 @@ const [me, currentUserTenants] = await Promise.all([this.getMeAndEntitlements(), getCurrentUserTenantsFunction(this.appName)()]);

this.generateLoginResponseFromOAuthResponse = async oauthResponse => {
const contextHolder = getFronteggContext(this.appName);
const contextHolder = ContextHolder.for(this.appName);
contextHolder.setAccessToken(oauthResponse.id_token);

@@ -120,3 +120,3 @@ const me = await this.getMeAndEntitlements();

this.generateLoginResponseFromOAuthResponseV2 = async oauthResponse => {
const contextHolder = getFronteggContext(this.appName);
const contextHolder = ContextHolder.for(this.appName);
contextHolder.setAccessToken(oauthResponse.id_token);

@@ -916,3 +916,3 @@ const [me, currentUserTenants] = await Promise.all([this.getMeAndEntitlements(), getCurrentUserTenantsFunction(this.appName)()]);

shouldLoadEntitlements() {
if (!getFronteggContext(this.appName).shouldLoadEntitlements()) {
if (!ContextHolder.for(this.appName).shouldLoadEntitlements()) {
return false;

@@ -919,0 +919,0 @@ }

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

import { getFronteggContext } from '../ContextHolder';
import { ContextHolder } from '../ContextHolder';
import { USE_CURRENT_USER_TENANTS_V1_ENDPOINT_FF } from './constants';

@@ -25,3 +25,3 @@ import { FeatureFlags } from '../feature-flags';

export function getTabTenantFromSessionStorage(appName) {
if (!getFronteggContext(appName).isSessionPerTenantEnabled()) {
if (!ContextHolder.for(appName).isSessionPerTenantEnabled()) {
return null;

@@ -36,3 +36,3 @@ }

if (getFronteggContext(appName).isSessionPerTenantEnabled()) {
if (ContextHolder.for(appName).isSessionPerTenantEnabled()) {
return usersApi.getCurrentUserTenantsV1;

@@ -39,0 +39,0 @@ }

@@ -15,4 +15,4 @@ import { SessionContext, ContextOptions, RedirectOptions, RequestSource } from '../interfaces';

private requestSource;
private onRedirectTo;
private logout;
onRedirectTo: (path: string, opts?: RedirectOptions) => void;
logout: (callback?: () => void) => void;
private entitlementsOptions;

@@ -22,30 +22,43 @@ private appName;

private constructor();
static default(): ContextHolder;
static for(appName: string): ContextHolder;
/**
* @deprecated - use ContextHolder.for(appName) / ContextHolder.default() instead
* @param appName
*/
static getInstance(appName?: string): ContextHolder;
static createInstance(appName?: string): ContextHolder;
/**
* @deprecated - use getFronteggContext(appName).setContext instead
* @deprecated - use ContextHolder.for(appName).setContext instead
*/
static setContext(context: ContextOptions, appName?: string): void;
setContext(context: ContextOptions): void;
/**
* @deprecated - use getFronteggContext(appName).setAccessToken instead
* @deprecated - use ContextHolder.for(appName).setAccessToken instead
*/
static setAccessToken(accessToken: string | null, appName?: string): void;
setAccessToken(accessToken: string | null): void;
/**
* @deprecated - use getFronteggContext(appName).setUser instead
* @deprecated - use ContextHolder.for(appName).setUser instead
*/
static setUser(user: IUserProfile | null, appName?: string): void;
setUser(user: IUserProfile | null): void;
/**
* @deprecated - use getFronteggContext(appName).setRequestSource instead
* @deprecated - use ContextHolder.for(appName).setRequestSource instead
*/
static setRequestSource(requestSource: RequestSource | null, appName?: string): void;
setRequestSource(requestSource: RequestSource | null): void;
/**
* @deprecated - use getFronteggContext(appName).setOnRedirectTo instead
* @deprecated - use ContextHolder.for(appName).setOnRedirectTo instead
*/
static setOnRedirectTo(onRedirectTo: (path: string, opts?: RedirectOptions) => void, appName?: string): void;
setOnRedirectTo(onRedirectTo: (path: string, opts?: RedirectOptions) => void): void;
/**
* @deprecated - use getFronteggContext(appName).setLogout instead
* @deprecated - use ContextHolder.for(appName).setLogout instead
*/
static setLogout(logout: (callback?: () => void) => void, logoutUrl: string, appName?: string): void;
setLogout(logout: (callback?: () => void) => void): void;
/**
* App name should also be set for entitlements
* @deprecated - use getFronteggContext(appName).setEntitlementsOptions instead
* @deprecated - use ContextHolder.for(appName).setEntitlementsOptions instead
* @param entitlementsOptions frontegg options entitlements config

@@ -55,4 +68,5 @@ * @param appName - app name

static setEntitlementsOptions(entitlementsOptions: EntitlementsOptions, appName?: string): void;
setEntitlementsOptions(entitlementsOptions: EntitlementsOptions): void;
/**
* @deprecated - use getFronteggContext(appName).setSessionContext instead
* @deprecated - use ContextHolder.for(appName).setSessionContext instead
* @param sessionContext frontegg options SessionContext config

@@ -62,42 +76,54 @@ * @param appName - app name

static setSessionContext(sessionContext: SessionContext, appName?: string): void;
setSessionContext(sessionContext: SessionContext): void;
/**
* @deprecated - use getFronteggContext(appName).setAppName instead
* @deprecated - use ContextHolder.for(appName).setAppName instead
*/
static setAppName(appName: string): void;
setAppName(appName: string): void;
/**
* @deprecated - use ContextHolder.for(appName).getContext instead
*/
static getContext(appName?: string): ContextOptions;
getContext(): ContextOptions;
/**
* @deprecated - use getFronteggContext(appName) instead
* @deprecated - use ContextHolder.for(appName).getAccessToken instead
*/
static getAccessToken(appName?: string): string | null;
getAccessToken(): string | null;
/**
* @deprecated - use getFronteggContext(appName).requestSource instead
* @deprecated - use ContextHolder.for(appName).requestSource instead
*/
static getRequestSource(appName?: string): RequestSource | null;
getRequestSource(): RequestSource | null;
/**
* @deprecated - use getFronteggContext(appName).getUser instead
* @deprecated - use ContextHolder.for(appName).getUser instead
*/
static getUser(appName?: string): IUserProfile | null;
getUser(): IUserProfile | null;
/**
* @deprecated - use getFronteggContext(appName).onRedirectTo instead
* @deprecated - use ContextHolder.for(appName).onRedirectTo instead
*/
static onRedirectTo(path: string, opts?: RedirectOptions, appName?: string): void;
/**
* @deprecated - use getFronteggContext(appName)/logout instead
* @deprecated - use ContextHolder.for(appName).logout instead
*/
static logout(callback?: () => void, appName?: string): void;
/**
* @deprecated - use getFronteggContext(appName).shouldLoadEntitlements instead
* @deprecated - use ContextHolder.for(appName).shouldLoadEntitlements instead
* @returns shouldLoadEntitlements. Default to false.
*/
static shouldLoadEntitlements(appName?: string): boolean;
shouldLoadEntitlements(): boolean;
/**
* @deprecated - use getFronteggContext(appName).isSessionPerTenantEnabled instead
* @deprecated - use ContextHolder.for(appName).isSessionPerTenantEnabled instead
* @returns isSessionPerTenantEnabled. Default to false.
*/
static isSessionPerTenantEnabled(appName?: string): boolean;
isSessionPerTenantEnabled(): boolean;
/**
* @deprecated - use getFronteggContext(appName).getAppName instead
* @deprecated - use ContextHolder.for(appName).getAppName instead
* @returns app name value
*/
static getAppName(appName?: string): string | null;
getAppName(): string | null;
}

@@ -107,3 +133,3 @@ /**

*
* @deprecated use getFronteggContext instead
* @deprecated use ContextHolder.for instead
*/

@@ -113,9 +139,2 @@ export declare const FronteggContext: {

getAccessToken: () => string | null;
getUser: () => IUserProfile | null;
onRedirectTo: (path: string, opts: RedirectOptions) => void;
logout: (callback?: (() => void) | undefined) => void;
};
export declare const getFronteggContext: (appName?: string) => {
getContext: () => ContextOptions;
getAccessToken: () => string | null;
setAccessToken: (accessToken: string | null) => void;

@@ -128,4 +147,8 @@ getUser: () => IUserProfile | null;

getRequestSource: () => RequestSource | null;
setRequestSource: (requestSource: RequestSource | null) => void;
isSessionPerTenantEnabled: () => boolean;
shouldLoadEntitlements: () => boolean;
getAppName: () => string | null;
setEntitlementsOptions: (entitlementsOptions: EntitlementsOptions) => void;
setSessionContext: (sessionContext: SessionContext) => void;
};

@@ -17,3 +17,15 @@ export class ContextHolder {

static default() {
return ContextHolder.getInstance(DEFAULT_APP_NAME);
}
static for(appName) {
return ContextHolder.getInstance(appName);
}
static getInstance(appName = 'default') {
if (!ContextHolder._apps) {
ContextHolder._apps = {};
}
if (ContextHolder._apps[appName]) {

@@ -27,26 +39,54 @@ return ContextHolder._apps[appName];

static createInstance(appName = 'default') {
ContextHolder._apps[appName] = new ContextHolder();
ContextHolder._apps[appName].appName = appName;
return ContextHolder._apps[appName];
}
static setContext(context, appName = 'default') {
ContextHolder.getInstance(appName).context = context;
ContextHolder.for(appName).context = context;
}
setContext(context) {
this.context = context;
}
static setAccessToken(accessToken, appName = 'default') {
ContextHolder.getInstance(appName).accessToken = accessToken;
ContextHolder.for(appName).accessToken = accessToken;
}
setAccessToken(accessToken) {
this.accessToken = accessToken;
}
static setUser(user, appName = 'default') {
ContextHolder.getInstance(appName).user = user;
ContextHolder.for(appName).user = user;
}
setUser(user) {
this.user = user;
}
static setRequestSource(requestSource, appName = 'default') {
ContextHolder.getInstance(appName).requestSource = requestSource;
ContextHolder.for(appName).requestSource = requestSource;
}
setRequestSource(requestSource) {
this.requestSource = requestSource;
}
static setOnRedirectTo(onRedirectTo, appName = 'default') {
ContextHolder.getInstance(appName).onRedirectTo = onRedirectTo;
ContextHolder.for(appName).onRedirectTo = onRedirectTo;
}
setOnRedirectTo(onRedirectTo) {
this.onRedirectTo = onRedirectTo;
}
static setLogout(logout, logoutUrl, appName = 'default') {
ContextHolder.getInstance(appName).logout = callback => {
const context = ContextHolder.for(appName);
context.logout = callback => {
if (!callback) {
ContextHolder.onRedirectTo(logoutUrl, undefined, appName);
context.onRedirectTo(logoutUrl, undefined);
} else {

@@ -58,18 +98,34 @@ logout(callback);

setLogout(logout) {
this.logout = logout;
}
static setEntitlementsOptions(entitlementsOptions, appName = 'default') {
ContextHolder.getInstance(appName).entitlementsOptions = entitlementsOptions;
ContextHolder.for(appName).entitlementsOptions = entitlementsOptions;
}
setEntitlementsOptions(entitlementsOptions) {
this.entitlementsOptions = entitlementsOptions;
}
static setSessionContext(sessionContext, appName = 'default') {
ContextHolder.getInstance(appName).sessionContext = sessionContext;
ContextHolder.for(appName).sessionContext = sessionContext;
}
setSessionContext(sessionContext) {
this.sessionContext = sessionContext;
}
static setAppName(appName) {
ContextHolder.getInstance(appName).appName = appName;
ContextHolder.for(appName).appName = appName;
}
setAppName(appName) {
this.appName = appName;
}
static getContext(appName = 'default') {
var _ContextHolder$getIns;
var _ContextHolder$for$co;
return (_ContextHolder$getIns = ContextHolder.getInstance(appName).context) != null ? _ContextHolder$getIns : {
return (_ContextHolder$for$co = ContextHolder.for(appName).context) != null ? _ContextHolder$for$co : {
baseUrl: window.location.href,

@@ -81,59 +137,95 @@ tokenResolver: () => 'my-authentication-token',

getContext() {
var _this$context;
return (_this$context = this.context) != null ? _this$context : {
baseUrl: window.location.href,
tokenResolver: () => 'my-authentication-token',
logLevel: 'error'
};
}
static getAccessToken(appName = 'default') {
return ContextHolder.getInstance(appName).accessToken;
return ContextHolder.for(appName).accessToken;
}
getAccessToken() {
return this.accessToken;
}
static getRequestSource(appName = 'default') {
return ContextHolder.getInstance(appName).requestSource;
return ContextHolder.for(appName).requestSource;
}
getRequestSource() {
return this.requestSource;
}
static getUser(appName = 'default') {
return ContextHolder.getInstance(appName).user;
return ContextHolder.for(appName).user;
}
getUser() {
return this.user;
}
static onRedirectTo(path, opts, appName = 'default') {
return ContextHolder.getInstance(appName).onRedirectTo(path, opts);
return ContextHolder.for(appName).onRedirectTo(path, opts);
}
static logout(callback, appName = 'default') {
return ContextHolder.getInstance(appName).logout(callback);
return ContextHolder.for(appName).logout(callback);
}
static shouldLoadEntitlements(appName = 'default') {
var _ContextHolder$getIns2;
var _ContextHolder$for$en;
return ((_ContextHolder$getIns2 = ContextHolder.getInstance(appName).entitlementsOptions) == null ? void 0 : _ContextHolder$getIns2.enabled) || false;
return ((_ContextHolder$for$en = ContextHolder.for(appName).entitlementsOptions) == null ? void 0 : _ContextHolder$for$en.enabled) || false;
}
shouldLoadEntitlements() {
var _this$entitlementsOpt;
return ((_this$entitlementsOpt = this.entitlementsOptions) == null ? void 0 : _this$entitlementsOpt.enabled) || false;
}
static isSessionPerTenantEnabled(appName = 'default') {
var _ContextHolder$getIns3;
var _ContextHolder$for$se;
return ((_ContextHolder$getIns3 = ContextHolder.getInstance(appName).sessionContext) == null ? void 0 : _ContextHolder$getIns3.enableSessionPerTenant) || false;
return ((_ContextHolder$for$se = ContextHolder.for(appName).sessionContext) == null ? void 0 : _ContextHolder$for$se.enableSessionPerTenant) || false;
}
isSessionPerTenantEnabled() {
var _this$sessionContext;
return ((_this$sessionContext = this.sessionContext) == null ? void 0 : _this$sessionContext.enableSessionPerTenant) || false;
}
static getAppName(appName = 'default') {
return ContextHolder.getInstance(appName).appName;
return ContextHolder.for(appName).appName;
}
getAppName() {
return this.appName;
}
}
ContextHolder._apps = void 0;
const DEFAULT_APP_NAME = 'default';
export const FronteggContext = {
getContext: () => ContextHolder.getContext(),
getAccessToken: () => ContextHolder.getAccessToken(),
getUser: () => ContextHolder.getUser(),
onRedirectTo: (path, opts) => ContextHolder.onRedirectTo(path, opts),
logout: callback => ContextHolder.logout(callback)
};
export const getFronteggContext = (appName = 'default') => ({
getContext: () => ContextHolder.getContext(appName),
getAccessToken: () => ContextHolder.getAccessToken(appName),
setAccessToken: accessToken => ContextHolder.setAccessToken(accessToken, appName),
getUser: () => ContextHolder.getUser(appName),
setUser: user => ContextHolder.setUser(user, appName),
onRedirectTo: (path, opts) => ContextHolder.onRedirectTo(path, opts, appName),
setOnRedirectTo: onRedirectTo => ContextHolder.setOnRedirectTo(onRedirectTo, appName),
logout: callback => ContextHolder.logout(callback, appName),
getRequestSource: () => ContextHolder.getRequestSource(appName),
isSessionPerTenantEnabled: () => ContextHolder.isSessionPerTenantEnabled(appName),
shouldLoadEntitlements: () => ContextHolder.shouldLoadEntitlements(appName)
});
getContext: () => ContextHolder.getContext(DEFAULT_APP_NAME),
getAccessToken: () => ContextHolder.getAccessToken(DEFAULT_APP_NAME),
setAccessToken: accessToken => ContextHolder.setAccessToken(accessToken, DEFAULT_APP_NAME),
getUser: () => ContextHolder.getUser(DEFAULT_APP_NAME),
setUser: user => ContextHolder.setUser(user, DEFAULT_APP_NAME),
onRedirectTo: (path, opts) => ContextHolder.onRedirectTo(path, opts, DEFAULT_APP_NAME),
setOnRedirectTo: onRedirectTo => ContextHolder.setOnRedirectTo(onRedirectTo, DEFAULT_APP_NAME),
logout: callback => ContextHolder.logout(callback, DEFAULT_APP_NAME),
getRequestSource: () => ContextHolder.getRequestSource(DEFAULT_APP_NAME),
setRequestSource: requestSource => ContextHolder.setRequestSource(requestSource, DEFAULT_APP_NAME),
isSessionPerTenantEnabled: () => ContextHolder.isSessionPerTenantEnabled(DEFAULT_APP_NAME),
shouldLoadEntitlements: () => ContextHolder.shouldLoadEntitlements(DEFAULT_APP_NAME),
getAppName: () => ContextHolder.getAppName(DEFAULT_APP_NAME),
setEntitlementsOptions: entitlementsOptions => ContextHolder.setEntitlementsOptions(entitlementsOptions, DEFAULT_APP_NAME),
setSessionContext: sessionContext => ContextHolder.setSessionContext(sessionContext, DEFAULT_APP_NAME)
};
import _extends from "@babel/runtime/helpers/esm/extends";
import { getFronteggContext } from './ContextHolder';
import { ContextHolder } from './ContextHolder';
import { FronteggApiError } from './error';

@@ -11,3 +11,3 @@ import { GENERIC_ERROR_MESSAGE } from './constants';

this.getFronteggContext = () => {
return getFronteggContext(this.appName);
return ContextHolder.for(this.appName);
};

@@ -125,3 +125,3 @@

const context = getFronteggContext(this.appName).getContext();
const context = this.getFronteggContext().getContext();
const headers = await this.buildRequestHeaders(opts.contentType);

@@ -128,0 +128,0 @@ const url = await this.prepareUrl(opts.url, opts.params);

@@ -5,3 +5,3 @@ import { AuthStrategyEnum, MachineToMachineAuthStrategy, SocialLoginProviders } from './auth';

import fetch, { FetchClient } from './FetchClient';
import { ContextHolder, FronteggContext, getFronteggContext } from './ContextHolder';
import { ContextHolder, FronteggContext } from './ContextHolder';
import { AuthenticationApi } from './auth';

@@ -111,3 +111,3 @@ import { UsersApi } from './users';

declare const createApiClient: (appName: string) => FronteggApiClient;
export { fetch, FetchClient, ContextHolder, FronteggContext, getFronteggContext, api, createApiClient, FronteggApiError, AuthStrategyEnum, SocialLoginProviders, ISubscriptionCancellationPolicy, ISubscriptionStatus, PaymentMethodType, ProviderType, MachineToMachineAuthStrategy, };
export { fetch, FetchClient, ContextHolder, FronteggContext, api, createApiClient, FronteggApiError, AuthStrategyEnum, SocialLoginProviders, ISubscriptionCancellationPolicy, ISubscriptionStatus, PaymentMethodType, ProviderType, MachineToMachineAuthStrategy, };
declare const _default: {

@@ -120,9 +120,2 @@ fetch: FetchClient;

getAccessToken: () => string | null;
getUser: () => import("./users/interfaces").IGetUsersV2Response | null;
onRedirectTo: (path: string, opts: import("./interfaces").RedirectOptions) => void;
logout: (callback?: (() => void) | undefined) => void;
};
getFronteggContext: (appName?: string) => {
getContext: () => import("./interfaces").ContextOptions;
getAccessToken: () => string | null;
setAccessToken: (accessToken: string | null) => void;

@@ -135,4 +128,8 @@ getUser: () => import("./users/interfaces").IGetUsersV2Response | null;

getRequestSource: () => import("./interfaces").RequestSource | null;
setRequestSource: (requestSource: import("./interfaces").RequestSource | null) => void;
isSessionPerTenantEnabled: () => boolean;
shouldLoadEntitlements: () => boolean;
getAppName: () => string | null;
setEntitlementsOptions: (entitlementsOptions: import("./ContextHolder").EntitlementsOptions) => void;
setSessionContext: (sessionContext: import("./interfaces").SessionContext) => void;
};

@@ -139,0 +136,0 @@ api: {

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

/** @license Frontegg v3.1.74-alpha.9436935127
/** @license Frontegg v3.1.74-alpha.9437859720
*

@@ -10,3 +10,3 @@ * This source code is licensed under the MIT license found in the

import fetch, { FetchClient } from './FetchClient';
import { ContextHolder, FronteggContext, getFronteggContext } from './ContextHolder';
import { ContextHolder, FronteggContext } from './ContextHolder';
import DefaultAuthenticationApi, { AuthenticationApi } from './auth';

@@ -112,3 +112,3 @@ import DefaultUsersApi, { UsersApi } from './users';

export { fetch, FetchClient, ContextHolder, FronteggContext, getFronteggContext, api, createApiClient, FronteggApiError, AuthStrategyEnum, SocialLoginProviders, ISubscriptionCancellationPolicy, ISubscriptionStatus, PaymentMethodType, ProviderType, MachineToMachineAuthStrategy };
export { fetch, FetchClient, ContextHolder, FronteggContext, api, createApiClient, FronteggApiError, AuthStrategyEnum, SocialLoginProviders, ISubscriptionCancellationPolicy, ISubscriptionStatus, PaymentMethodType, ProviderType, MachineToMachineAuthStrategy };
export default {

@@ -119,3 +119,2 @@ fetch,

FronteggContext,
getFronteggContext,
api,

@@ -122,0 +121,0 @@ createApiClient,

@@ -87,4 +87,2 @@ "use strict";

var _ContextHolder = require("../ContextHolder");
var _jwt = require("../jwt");

@@ -104,2 +102,4 @@

var _ContextHolder = require("../ContextHolder");
const _excluded = ["type"],

@@ -120,3 +120,4 @@ _excluded2 = ["type"],

const contextHolder = (0, _ContextHolder.getFronteggContext)(this.appName);
const contextHolder = _ContextHolder.ContextHolder.for(this.appName);
contextHolder.setAccessToken(loginResponse.accessToken);

@@ -126,3 +127,3 @@ const me = await this.getMeAndEntitlements();

const user = (0, _extends2.default)({}, loginResponse, decodedContent, me);
(0, _ContextHolder.getFronteggContext)(this.appName).setUser(user);
contextHolder.setUser(user);
return user;

@@ -138,3 +139,4 @@ };

const contextHolder = (0, _ContextHolder.getFronteggContext)(this.appName);
const contextHolder = _ContextHolder.ContextHolder.for(this.appName);
contextHolder.setAccessToken(loginResponse.accessToken);

@@ -144,3 +146,3 @@ const [me, tenants] = await Promise.all([this.getMeAndEntitlements(), this.tenantsApi.getTenants()]);

const user = (0, _extends2.default)({}, loginResponse, decodedContent, me);
(0, _ContextHolder.getFronteggContext)(this.appName).setUser(user);
contextHolder.setUser(user);
return {

@@ -163,3 +165,4 @@ user,

const contextHolder = (0, _ContextHolder.getFronteggContext)(this.appName);
const contextHolder = _ContextHolder.ContextHolder.for(this.appName);
contextHolder.setAccessToken(accessToken);

@@ -183,3 +186,4 @@ const [me, currentUserTenants] = await Promise.all([this.getMeAndEntitlements(), (0, _utils.getCurrentUserTenantsFunction)(this.appName)()]);

this.generateLoginResponseFromOAuthResponse = async oauthResponse => {
const contextHolder = (0, _ContextHolder.getFronteggContext)(this.appName);
const contextHolder = _ContextHolder.ContextHolder.for(this.appName);
contextHolder.setAccessToken(oauthResponse.id_token);

@@ -200,3 +204,4 @@ const me = await this.getMeAndEntitlements();

this.generateLoginResponseFromOAuthResponseV2 = async oauthResponse => {
const contextHolder = (0, _ContextHolder.getFronteggContext)(this.appName);
const contextHolder = _ContextHolder.ContextHolder.for(this.appName);
contextHolder.setAccessToken(oauthResponse.id_token);

@@ -992,3 +997,3 @@ const [me, currentUserTenants] = await Promise.all([this.getMeAndEntitlements(), (0, _utils.getCurrentUserTenantsFunction)(this.appName)()]);

shouldLoadEntitlements() {
if (!(0, _ContextHolder.getFronteggContext)(this.appName).shouldLoadEntitlements()) {
if (!_ContextHolder.ContextHolder.for(this.appName).shouldLoadEntitlements()) {
return false;

@@ -995,0 +1000,0 @@ }

@@ -43,3 +43,3 @@ "use strict";

function getTabTenantFromSessionStorage(appName) {
if (!(0, _ContextHolder.getFronteggContext)(appName).isSessionPerTenantEnabled()) {
if (!_ContextHolder.ContextHolder.for(appName).isSessionPerTenantEnabled()) {
return null;

@@ -56,3 +56,3 @@ }

if ((0, _ContextHolder.getFronteggContext)(appName).isSessionPerTenantEnabled()) {
if (_ContextHolder.ContextHolder.for(appName).isSessionPerTenantEnabled()) {
return usersApi.getCurrentUserTenantsV1;

@@ -59,0 +59,0 @@ }

@@ -6,3 +6,3 @@ "use strict";

});
exports.getFronteggContext = exports.FronteggContext = exports.ContextHolder = void 0;
exports.FronteggContext = exports.ContextHolder = void 0;

@@ -25,3 +25,15 @@ class ContextHolder {

static default() {
return ContextHolder.getInstance(DEFAULT_APP_NAME);
}
static for(appName) {
return ContextHolder.getInstance(appName);
}
static getInstance(appName = 'default') {
if (!ContextHolder._apps) {
ContextHolder._apps = {};
}
if (ContextHolder._apps[appName]) {

@@ -35,26 +47,54 @@ return ContextHolder._apps[appName];

static createInstance(appName = 'default') {
ContextHolder._apps[appName] = new ContextHolder();
ContextHolder._apps[appName].appName = appName;
return ContextHolder._apps[appName];
}
static setContext(context, appName = 'default') {
ContextHolder.getInstance(appName).context = context;
ContextHolder.for(appName).context = context;
}
setContext(context) {
this.context = context;
}
static setAccessToken(accessToken, appName = 'default') {
ContextHolder.getInstance(appName).accessToken = accessToken;
ContextHolder.for(appName).accessToken = accessToken;
}
setAccessToken(accessToken) {
this.accessToken = accessToken;
}
static setUser(user, appName = 'default') {
ContextHolder.getInstance(appName).user = user;
ContextHolder.for(appName).user = user;
}
setUser(user) {
this.user = user;
}
static setRequestSource(requestSource, appName = 'default') {
ContextHolder.getInstance(appName).requestSource = requestSource;
ContextHolder.for(appName).requestSource = requestSource;
}
setRequestSource(requestSource) {
this.requestSource = requestSource;
}
static setOnRedirectTo(onRedirectTo, appName = 'default') {
ContextHolder.getInstance(appName).onRedirectTo = onRedirectTo;
ContextHolder.for(appName).onRedirectTo = onRedirectTo;
}
setOnRedirectTo(onRedirectTo) {
this.onRedirectTo = onRedirectTo;
}
static setLogout(logout, logoutUrl, appName = 'default') {
ContextHolder.getInstance(appName).logout = callback => {
const context = ContextHolder.for(appName);
context.logout = callback => {
if (!callback) {
ContextHolder.onRedirectTo(logoutUrl, undefined, appName);
context.onRedirectTo(logoutUrl, undefined);
} else {

@@ -66,18 +106,34 @@ logout(callback);

setLogout(logout) {
this.logout = logout;
}
static setEntitlementsOptions(entitlementsOptions, appName = 'default') {
ContextHolder.getInstance(appName).entitlementsOptions = entitlementsOptions;
ContextHolder.for(appName).entitlementsOptions = entitlementsOptions;
}
setEntitlementsOptions(entitlementsOptions) {
this.entitlementsOptions = entitlementsOptions;
}
static setSessionContext(sessionContext, appName = 'default') {
ContextHolder.getInstance(appName).sessionContext = sessionContext;
ContextHolder.for(appName).sessionContext = sessionContext;
}
setSessionContext(sessionContext) {
this.sessionContext = sessionContext;
}
static setAppName(appName) {
ContextHolder.getInstance(appName).appName = appName;
ContextHolder.for(appName).appName = appName;
}
setAppName(appName) {
this.appName = appName;
}
static getContext(appName = 'default') {
var _ContextHolder$getIns;
var _ContextHolder$for$co;
return (_ContextHolder$getIns = ContextHolder.getInstance(appName).context) != null ? _ContextHolder$getIns : {
return (_ContextHolder$for$co = ContextHolder.for(appName).context) != null ? _ContextHolder$for$co : {
baseUrl: window.location.href,

@@ -89,38 +145,76 @@ tokenResolver: () => 'my-authentication-token',

getContext() {
var _this$context;
return (_this$context = this.context) != null ? _this$context : {
baseUrl: window.location.href,
tokenResolver: () => 'my-authentication-token',
logLevel: 'error'
};
}
static getAccessToken(appName = 'default') {
return ContextHolder.getInstance(appName).accessToken;
return ContextHolder.for(appName).accessToken;
}
getAccessToken() {
return this.accessToken;
}
static getRequestSource(appName = 'default') {
return ContextHolder.getInstance(appName).requestSource;
return ContextHolder.for(appName).requestSource;
}
getRequestSource() {
return this.requestSource;
}
static getUser(appName = 'default') {
return ContextHolder.getInstance(appName).user;
return ContextHolder.for(appName).user;
}
getUser() {
return this.user;
}
static onRedirectTo(path, opts, appName = 'default') {
return ContextHolder.getInstance(appName).onRedirectTo(path, opts);
return ContextHolder.for(appName).onRedirectTo(path, opts);
}
static logout(callback, appName = 'default') {
return ContextHolder.getInstance(appName).logout(callback);
return ContextHolder.for(appName).logout(callback);
}
static shouldLoadEntitlements(appName = 'default') {
var _ContextHolder$getIns2;
var _ContextHolder$for$en;
return ((_ContextHolder$getIns2 = ContextHolder.getInstance(appName).entitlementsOptions) == null ? void 0 : _ContextHolder$getIns2.enabled) || false;
return ((_ContextHolder$for$en = ContextHolder.for(appName).entitlementsOptions) == null ? void 0 : _ContextHolder$for$en.enabled) || false;
}
shouldLoadEntitlements() {
var _this$entitlementsOpt;
return ((_this$entitlementsOpt = this.entitlementsOptions) == null ? void 0 : _this$entitlementsOpt.enabled) || false;
}
static isSessionPerTenantEnabled(appName = 'default') {
var _ContextHolder$getIns3;
var _ContextHolder$for$se;
return ((_ContextHolder$getIns3 = ContextHolder.getInstance(appName).sessionContext) == null ? void 0 : _ContextHolder$getIns3.enableSessionPerTenant) || false;
return ((_ContextHolder$for$se = ContextHolder.for(appName).sessionContext) == null ? void 0 : _ContextHolder$for$se.enableSessionPerTenant) || false;
}
isSessionPerTenantEnabled() {
var _this$sessionContext;
return ((_this$sessionContext = this.sessionContext) == null ? void 0 : _this$sessionContext.enableSessionPerTenant) || false;
}
static getAppName(appName = 'default') {
return ContextHolder.getInstance(appName).appName;
return ContextHolder.for(appName).appName;
}
getAppName() {
return this.appName;
}
}

@@ -130,25 +224,20 @@

ContextHolder._apps = void 0;
const DEFAULT_APP_NAME = 'default';
const FronteggContext = {
getContext: () => ContextHolder.getContext(),
getAccessToken: () => ContextHolder.getAccessToken(),
getUser: () => ContextHolder.getUser(),
onRedirectTo: (path, opts) => ContextHolder.onRedirectTo(path, opts),
logout: callback => ContextHolder.logout(callback)
getContext: () => ContextHolder.getContext(DEFAULT_APP_NAME),
getAccessToken: () => ContextHolder.getAccessToken(DEFAULT_APP_NAME),
setAccessToken: accessToken => ContextHolder.setAccessToken(accessToken, DEFAULT_APP_NAME),
getUser: () => ContextHolder.getUser(DEFAULT_APP_NAME),
setUser: user => ContextHolder.setUser(user, DEFAULT_APP_NAME),
onRedirectTo: (path, opts) => ContextHolder.onRedirectTo(path, opts, DEFAULT_APP_NAME),
setOnRedirectTo: onRedirectTo => ContextHolder.setOnRedirectTo(onRedirectTo, DEFAULT_APP_NAME),
logout: callback => ContextHolder.logout(callback, DEFAULT_APP_NAME),
getRequestSource: () => ContextHolder.getRequestSource(DEFAULT_APP_NAME),
setRequestSource: requestSource => ContextHolder.setRequestSource(requestSource, DEFAULT_APP_NAME),
isSessionPerTenantEnabled: () => ContextHolder.isSessionPerTenantEnabled(DEFAULT_APP_NAME),
shouldLoadEntitlements: () => ContextHolder.shouldLoadEntitlements(DEFAULT_APP_NAME),
getAppName: () => ContextHolder.getAppName(DEFAULT_APP_NAME),
setEntitlementsOptions: entitlementsOptions => ContextHolder.setEntitlementsOptions(entitlementsOptions, DEFAULT_APP_NAME),
setSessionContext: sessionContext => ContextHolder.setSessionContext(sessionContext, DEFAULT_APP_NAME)
};
exports.FronteggContext = FronteggContext;
const getFronteggContext = (appName = 'default') => ({
getContext: () => ContextHolder.getContext(appName),
getAccessToken: () => ContextHolder.getAccessToken(appName),
setAccessToken: accessToken => ContextHolder.setAccessToken(accessToken, appName),
getUser: () => ContextHolder.getUser(appName),
setUser: user => ContextHolder.setUser(user, appName),
onRedirectTo: (path, opts) => ContextHolder.onRedirectTo(path, opts, appName),
setOnRedirectTo: onRedirectTo => ContextHolder.setOnRedirectTo(onRedirectTo, appName),
logout: callback => ContextHolder.logout(callback, appName),
getRequestSource: () => ContextHolder.getRequestSource(appName),
isSessionPerTenantEnabled: () => ContextHolder.isSessionPerTenantEnabled(appName),
shouldLoadEntitlements: () => ContextHolder.shouldLoadEntitlements(appName)
});
exports.getFronteggContext = getFronteggContext;
exports.FronteggContext = FronteggContext;

@@ -25,3 +25,3 @@ "use strict";

this.getFronteggContext = () => {
return (0, _ContextHolder.getFronteggContext)(this.appName);
return _ContextHolder.ContextHolder.for(this.appName);
};

@@ -139,3 +139,3 @@

const context = (0, _ContextHolder.getFronteggContext)(this.appName).getContext();
const context = this.getFronteggContext().getContext();
const headers = await this.buildRequestHeaders(opts.contentType);

@@ -142,0 +142,0 @@ const url = await this.prepareUrl(opts.url, opts.params);

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

/** @license Frontegg v3.1.74-alpha.9436935127
/** @license Frontegg v3.1.74-alpha.9437859720
*

@@ -30,4 +30,3 @@ * This source code is licensed under the MIT license found in the

ContextHolder: true,
FronteggContext: true,
getFronteggContext: true
FronteggContext: true
};

@@ -119,8 +118,2 @@ Object.defineProperty(exports, "AuthStrategyEnum", {

});
Object.defineProperty(exports, "getFronteggContext", {
enumerable: true,
get: function () {
return _ContextHolder.getFronteggContext;
}
});
Object.defineProperty(exports, "getTabTenantFromSessionStorage", {

@@ -634,3 +627,2 @@ enumerable: true,

FronteggContext: _ContextHolder.FronteggContext,
getFronteggContext: _ContextHolder.getFronteggContext,
api,

@@ -637,0 +629,0 @@ createApiClient,

@@ -25,3 +25,3 @@ "use strict";

this.switchTenant = async body => {
if ((0, _ContextHolder.getFronteggContext)(this.appName).isSessionPerTenantEnabled()) {
if (_ContextHolder.ContextHolder.for(this.appName).isSessionPerTenantEnabled()) {
(0, _utils.setTabTenantInSessionStorage)(body.tenantId);

@@ -28,0 +28,0 @@ }

{
"name": "@frontegg/rest-api",
"version": "3.1.74-alpha.9436935127",
"version": "3.1.74-alpha.9437859720",
"main": "./node/index.js",

@@ -5,0 +5,0 @@ "license": "MIT",

import _extends from "@babel/runtime/helpers/esm/extends";
import { urls } from '../constants';
import { setTabTenantInSessionStorage } from '../auth/utils';
import { getFronteggContext } from '../ContextHolder';
import { ContextHolder } from '../ContextHolder';
import { BaseApiClient } from '../BaseApiClient';

@@ -11,3 +11,3 @@ export class TenantsApi extends BaseApiClient {

this.switchTenant = async body => {
if (getFronteggContext(this.appName).isSessionPerTenantEnabled()) {
if (ContextHolder.for(this.appName).isSessionPerTenantEnabled()) {
setTabTenantInSessionStorage(body.tenantId);

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

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