@frontegg/rest-api 3.1.78 → 3.1.79-alpha.9987430273
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BaseApiClient.d.ts +16 -0
- package/BaseApiClient.js +39 -0
- package/ContextHolder/index.d.ts +113 -28
- package/ContextHolder/index.js +163 -54
- package/FetchClient.d.ts +42 -0
- package/FetchClient.js +308 -0
- package/account-settings/index.d.ts +19 -7
- package/account-settings/index.js +23 -13
- package/applications/index.d.ts +49 -44
- package/applications/index.js +51 -37
- package/audits/index.d.ts +27 -15
- package/audits/index.js +27 -17
- package/auth/index.d.ts +817 -768
- package/auth/index.js +902 -721
- package/auth/secutiry-poilicy/index.d.ts +58 -102
- package/auth/secutiry-poilicy/index.js +122 -90
- package/auth/utils.d.ts +2 -2
- package/auth/utils.js +9 -8
- package/connectivity/index.d.ts +126 -27
- package/connectivity/index.js +147 -114
- package/directory/index.d.ts +31 -22
- package/directory/index.js +27 -15
- package/entitlements/index.d.ts +14 -8
- package/entitlements/index.js +12 -4
- package/feature-flags/index.d.ts +8 -2
- package/feature-flags/index.js +16 -8
- package/groups/index.d.ts +73 -49
- package/groups/index.js +64 -45
- package/impersonate/index.d.ts +15 -6
- package/impersonate/index.js +13 -5
- package/index.d.ts +154 -108
- package/index.js +109 -78
- package/interfaces.d.ts +10 -0
- package/metadata/index.d.ts +67 -7
- package/metadata/index.js +52 -32
- package/node/BaseApiClient.js +49 -0
- package/node/ContextHolder/index.js +163 -54
- package/node/FetchClient.js +326 -0
- package/node/account-settings/index.js +27 -16
- package/node/applications/index.js +51 -44
- package/node/audits/index.js +31 -20
- package/node/auth/index.js +768 -1035
- package/node/auth/secutiry-poilicy/index.js +125 -136
- package/node/auth/utils.js +9 -7
- package/node/connectivity/index.js +148 -187
- package/node/directory/index.js +29 -20
- package/node/entitlements/index.js +18 -5
- package/node/feature-flags/index.js +21 -9
- package/node/groups/index.js +65 -63
- package/node/impersonate/index.js +18 -5
- package/node/index.js +116 -71
- package/node/metadata/index.js +61 -52
- package/node/notifications/index.js +37 -27
- package/node/reports/index.js +78 -70
- package/node/roles/index.js +56 -51
- package/node/security-center/index.js +21 -9
- package/node/sub-tenants/index.js +90 -89
- package/node/subscriptions/index.js +69 -107
- package/node/subscriptions/invoices.js +25 -17
- package/node/subscriptions/managedSubscriptions.js +32 -27
- package/node/subscriptions/paymentMethods.js +27 -20
- package/node/subscriptions/paymentProviders.js +15 -6
- package/node/subscriptions/plans.js +17 -9
- package/node/subscriptions/providers/stripe/index.js +26 -21
- package/node/subscriptions/subscriptions.js +32 -27
- package/node/subscriptions/summaries.js +15 -6
- package/node/subscriptions/tenantConfiguration.js +17 -9
- package/node/subscriptions/vendorPublicConfigurations.js +15 -6
- package/node/teams/index.js +138 -148
- package/node/tenants/index.js +65 -60
- package/node/user-phone-numbers/index.js +32 -24
- package/node/users/index.js +58 -53
- package/node/vendor/index.js +17 -6
- package/notifications/index.d.ts +22 -16
- package/notifications/index.js +33 -22
- package/package.json +1 -1
- package/reports/index.d.ts +50 -44
- package/reports/index.js +75 -62
- package/roles/index.d.ts +44 -38
- package/roles/index.js +57 -41
- package/security-center/index.d.ts +14 -2
- package/security-center/index.js +15 -6
- package/sub-tenants/index.d.ts +57 -15
- package/sub-tenants/index.js +88 -68
- package/subscriptions/index.d.ts +56 -11
- package/subscriptions/index.js +58 -11
- package/subscriptions/invoices.d.ts +16 -13
- package/subscriptions/invoices.js +24 -14
- package/subscriptions/managedSubscriptions.d.ts +18 -15
- package/subscriptions/managedSubscriptions.js +33 -22
- package/subscriptions/paymentMethods.d.ts +16 -13
- package/subscriptions/paymentMethods.js +26 -17
- package/subscriptions/paymentProviders.d.ts +8 -5
- package/subscriptions/paymentProviders.js +11 -4
- package/subscriptions/plans.d.ts +11 -8
- package/subscriptions/plans.js +14 -6
- package/subscriptions/providers/stripe/index.d.ts +24 -21
- package/subscriptions/providers/stripe/index.js +27 -16
- package/subscriptions/subscriptions.d.ts +24 -21
- package/subscriptions/subscriptions.js +33 -22
- package/subscriptions/summaries.d.ts +7 -4
- package/subscriptions/summaries.js +10 -3
- package/subscriptions/tenantConfiguration.d.ts +6 -3
- package/subscriptions/tenantConfiguration.js +15 -7
- package/subscriptions/vendorPublicConfigurations.d.ts +5 -2
- package/subscriptions/vendorPublicConfigurations.js +11 -4
- package/teams/index.d.ts +37 -139
- package/teams/index.js +130 -99
- package/tenants/index.d.ts +25 -37
- package/tenants/index.js +62 -46
- package/user-phone-numbers/index.d.ts +32 -26
- package/user-phone-numbers/index.js +32 -19
- package/users/index.d.ts +21 -15
- package/users/index.js +60 -44
- package/vendor/index.d.ts +12 -6
- package/vendor/index.js +11 -4
- package/fetch.d.ts +0 -24
- package/fetch.js +0 -265
- package/node/fetch.js +0 -306
- package/node/subscriptions/providers/index.js +0 -18
- package/subscriptions/providers/index.d.ts +0 -1
- package/subscriptions/providers/index.js +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FetchClient } from './FetchClient';
|
|
2
|
+
import { RequestOptions, UserJwtOptions } from './interfaces';
|
|
3
|
+
export declare class BaseApiClient {
|
|
4
|
+
protected appName: string;
|
|
5
|
+
protected fetchClient: FetchClient;
|
|
6
|
+
protected constructor(appName: string);
|
|
7
|
+
protected get: <T>(url: string, params?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<T>;
|
|
8
|
+
protected post: <T>(url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<T>;
|
|
9
|
+
protected patch: <T>(url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<T>;
|
|
10
|
+
protected put: <T>(url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<T>;
|
|
11
|
+
protected delete: <T>(url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<T>;
|
|
12
|
+
protected postDownload: <T>(url: string, body?: any, params?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<T>;
|
|
13
|
+
protected extractHeadersFromOptions: (options?: UserJwtOptions) => {
|
|
14
|
+
Authorization?: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
package/BaseApiClient.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { FetchClient } from './FetchClient';
|
|
2
|
+
export class BaseApiClient {
|
|
3
|
+
constructor(appName) {
|
|
4
|
+
this.appName = void 0;
|
|
5
|
+
this.fetchClient = void 0;
|
|
6
|
+
|
|
7
|
+
this.get = async (url, params, opts) => {
|
|
8
|
+
return this.fetchClient.get(url, params, opts);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
this.post = async (url, body, opts) => {
|
|
12
|
+
return this.fetchClient.post(url, body, opts);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
this.patch = async (url, body, opts) => {
|
|
16
|
+
return this.fetchClient.patch(url, body, opts);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
this.put = async (url, body, opts) => {
|
|
20
|
+
return this.fetchClient.put(url, body, opts);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
this.delete = async (url, body, opts) => {
|
|
24
|
+
return this.fetchClient.delete(url, body, opts);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
this.postDownload = async (url, body, params, opts) => {
|
|
28
|
+
return this.fetchClient.postDownload(url, body, params, opts);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
this.extractHeadersFromOptions = (options = {}) => {
|
|
32
|
+
return this.fetchClient.extractHeadersFromOptions(options);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
this.appName = appName;
|
|
36
|
+
this.fetchClient = new FetchClient(appName);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
package/ContextHolder/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SessionContext, ContextOptions, RedirectOptions, RequestSource } from '../interfaces';
|
|
2
|
-
import { IUserProfile } from
|
|
2
|
+
import { IUserProfile } from '../users/interfaces';
|
|
3
3
|
/**
|
|
4
4
|
* Entitlements config from frontegg provider
|
|
5
5
|
*/
|
|
@@ -7,63 +7,148 @@ export interface EntitlementsOptions {
|
|
|
7
7
|
enabled?: boolean;
|
|
8
8
|
}
|
|
9
9
|
export declare class ContextHolder {
|
|
10
|
-
private static
|
|
10
|
+
private static _apps;
|
|
11
11
|
private context;
|
|
12
12
|
private accessToken;
|
|
13
13
|
private user;
|
|
14
14
|
private requestSource;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
onRedirectTo: (path: string, opts?: RedirectOptions) => void;
|
|
16
|
+
logout: (callback?: () => void) => void;
|
|
17
17
|
private entitlementsOptions;
|
|
18
18
|
private appName;
|
|
19
19
|
private sessionContext?;
|
|
20
20
|
private basename;
|
|
21
21
|
private constructor();
|
|
22
|
-
static
|
|
23
|
-
static
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
static
|
|
29
|
-
static
|
|
22
|
+
static default(): ContextHolder;
|
|
23
|
+
static for(appName: string): ContextHolder;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated - use ContextHolder.for(appName) / ContextHolder.default() instead
|
|
26
|
+
* @param appName
|
|
27
|
+
*/
|
|
28
|
+
static getInstance(appName?: string): ContextHolder;
|
|
29
|
+
static createInstance(appName?: string): ContextHolder;
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated - use ContextHolder.for(appName).setContext instead
|
|
32
|
+
*/
|
|
33
|
+
static setContext(context: ContextOptions, appName?: string): void;
|
|
34
|
+
setContext: (context: ContextOptions) => void;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated - use ContextHolder.for(appName).setAccessToken instead
|
|
37
|
+
*/
|
|
38
|
+
static setAccessToken(accessToken: string | null, appName?: string): void;
|
|
39
|
+
setAccessToken: (accessToken: string | null) => void;
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated - use ContextHolder.for(appName).setBasename instead
|
|
42
|
+
*/
|
|
43
|
+
static setBasename(basename: string | null, appName?: string): void;
|
|
44
|
+
setBasename(basename: string | null): void;
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated - use ContextHolder.for(appName).setUser instead
|
|
47
|
+
*/
|
|
48
|
+
static setUser(user: IUserProfile | null, appName?: string): void;
|
|
49
|
+
setUser: (user: IUserProfile | null) => void;
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated - use ContextHolder.for(appName).setRequestSource instead
|
|
52
|
+
*/
|
|
53
|
+
static setRequestSource(requestSource: RequestSource | null, appName?: string): void;
|
|
54
|
+
setRequestSource: (requestSource: RequestSource | null) => void;
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated - use ContextHolder.for(appName).setOnRedirectTo instead
|
|
57
|
+
*/
|
|
58
|
+
static setOnRedirectTo(onRedirectTo: (path: string, opts?: RedirectOptions) => void, appName?: string): void;
|
|
59
|
+
setOnRedirectTo: (onRedirectTo: (path: string, opts?: RedirectOptions | undefined) => void) => void;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated - use ContextHolder.for(appName).setLogout instead
|
|
62
|
+
*/
|
|
63
|
+
static setLogout(logout: (callback?: () => void) => void, logoutUrl: string, appName?: string): void;
|
|
64
|
+
setLogout: (logout: (callback?: (() => void) | undefined) => void) => void;
|
|
30
65
|
/**
|
|
31
66
|
* App name should also be set for entitlements
|
|
67
|
+
* @deprecated - use ContextHolder.for(appName).setEntitlementsOptions instead
|
|
32
68
|
* @param entitlementsOptions frontegg options entitlements config
|
|
69
|
+
* @param appName - app name
|
|
33
70
|
*/
|
|
34
|
-
static setEntitlementsOptions(entitlementsOptions: EntitlementsOptions): void;
|
|
71
|
+
static setEntitlementsOptions(entitlementsOptions: EntitlementsOptions, appName?: string): void;
|
|
72
|
+
setEntitlementsOptions: (entitlementsOptions: EntitlementsOptions) => void;
|
|
35
73
|
/**
|
|
74
|
+
* @deprecated - use ContextHolder.for(appName).setSessionContext instead
|
|
36
75
|
* @param sessionContext frontegg options SessionContext config
|
|
76
|
+
* @param appName - app name
|
|
77
|
+
*/
|
|
78
|
+
static setSessionContext(sessionContext: SessionContext, appName?: string): void;
|
|
79
|
+
setSessionContext: (sessionContext: SessionContext) => void;
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated - use ContextHolder.for(appName).setAppName instead
|
|
37
82
|
*/
|
|
38
|
-
static
|
|
83
|
+
static setAppName(appName: string): void;
|
|
84
|
+
setAppName: (appName: string) => void;
|
|
39
85
|
/**
|
|
40
|
-
* @
|
|
86
|
+
* @deprecated - use ContextHolder.for(appName).getContext instead
|
|
41
87
|
*/
|
|
42
|
-
static
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
88
|
+
static getContext(appName?: string): ContextOptions;
|
|
89
|
+
getContext: () => ContextOptions;
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated - use ContextHolder.for(appName).getAccessToken instead
|
|
92
|
+
*/
|
|
93
|
+
static getAccessToken(appName?: string): string | null;
|
|
94
|
+
getAccessToken: () => string | null;
|
|
95
|
+
/**
|
|
96
|
+
* @deprecated - use ContextHolder.for(appName).requestSource instead
|
|
97
|
+
*/
|
|
98
|
+
static getRequestSource(appName?: string): RequestSource | null;
|
|
99
|
+
getRequestSource: () => RequestSource | null;
|
|
47
100
|
static getBasename(): string | null;
|
|
48
|
-
static onRedirectTo(path: string, opts?: RedirectOptions): void;
|
|
49
|
-
static logout(callback?: () => void): void;
|
|
50
101
|
/**
|
|
102
|
+
* @deprecated - use ContextHolder.for(appName).getUser instead
|
|
103
|
+
*/
|
|
104
|
+
static getUser(appName?: string): IUserProfile | null;
|
|
105
|
+
getUser: () => IUserProfile | null;
|
|
106
|
+
/**
|
|
107
|
+
* @deprecated - use ContextHolder.for(appName).onRedirectTo instead
|
|
108
|
+
*/
|
|
109
|
+
static onRedirectTo(path: string, opts?: RedirectOptions, appName?: string): void;
|
|
110
|
+
/**
|
|
111
|
+
* @deprecated - use ContextHolder.for(appName).logout instead
|
|
112
|
+
*/
|
|
113
|
+
static logout(callback?: () => void, appName?: string): void;
|
|
114
|
+
/**
|
|
115
|
+
* @deprecated - use ContextHolder.for(appName).shouldLoadEntitlements instead
|
|
51
116
|
* @returns shouldLoadEntitlements. Default to false.
|
|
52
117
|
*/
|
|
53
|
-
static shouldLoadEntitlements(): boolean;
|
|
118
|
+
static shouldLoadEntitlements(appName?: string): boolean;
|
|
119
|
+
shouldLoadEntitlements: () => boolean;
|
|
54
120
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
121
|
+
* @deprecated - use ContextHolder.for(appName).isSessionPerTenantEnabled instead
|
|
122
|
+
* @returns isSessionPerTenantEnabled. Default to false.
|
|
123
|
+
*/
|
|
124
|
+
static isSessionPerTenantEnabled(appName?: string): boolean;
|
|
125
|
+
isSessionPerTenantEnabled: () => boolean;
|
|
58
126
|
/**
|
|
127
|
+
* @deprecated - use ContextHolder.for(appName).getAppName instead
|
|
59
128
|
* @returns app name value
|
|
60
129
|
*/
|
|
61
|
-
static getAppName(): string | null;
|
|
130
|
+
static getAppName(appName?: string): string | null;
|
|
131
|
+
getAppName: () => string | null;
|
|
62
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Frontegg context to be used in the application
|
|
135
|
+
*
|
|
136
|
+
* @deprecated use ContextHolder.for instead
|
|
137
|
+
*/
|
|
63
138
|
export declare const FronteggContext: {
|
|
64
139
|
getContext: () => ContextOptions;
|
|
65
140
|
getAccessToken: () => string | null;
|
|
141
|
+
setAccessToken: (accessToken: string | null) => void;
|
|
66
142
|
getUser: () => IUserProfile | null;
|
|
67
|
-
|
|
143
|
+
setUser: (user: IUserProfile | null) => void;
|
|
144
|
+
onRedirectTo: (path: string, opts?: RedirectOptions | undefined) => void;
|
|
145
|
+
setOnRedirectTo: (onRedirectTo: (path: string, opts?: RedirectOptions | undefined) => void) => void;
|
|
68
146
|
logout: (callback?: (() => void) | undefined) => void;
|
|
147
|
+
getRequestSource: () => RequestSource | null;
|
|
148
|
+
setRequestSource: (requestSource: RequestSource | null) => void;
|
|
149
|
+
isSessionPerTenantEnabled: () => boolean;
|
|
150
|
+
shouldLoadEntitlements: () => boolean;
|
|
151
|
+
getAppName: () => string | null;
|
|
152
|
+
setEntitlementsOptions: (entitlementsOptions: EntitlementsOptions) => void;
|
|
153
|
+
setSessionContext: (sessionContext: SessionContext) => void;
|
|
69
154
|
};
|
package/ContextHolder/index.js
CHANGED
|
@@ -13,119 +13,228 @@ export class ContextHolder {
|
|
|
13
13
|
this.appName = null;
|
|
14
14
|
this.sessionContext = void 0;
|
|
15
15
|
this.basename = null;
|
|
16
|
+
|
|
17
|
+
this.setContext = context => {
|
|
18
|
+
this.context = context;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
this.setAccessToken = accessToken => {
|
|
22
|
+
this.accessToken = accessToken;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
this.setUser = user => {
|
|
26
|
+
this.user = user;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
this.setRequestSource = requestSource => {
|
|
30
|
+
this.requestSource = requestSource;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
this.setOnRedirectTo = onRedirectTo => {
|
|
34
|
+
this.onRedirectTo = onRedirectTo;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
this.setLogout = logout => {
|
|
38
|
+
this.logout = logout;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
this.setEntitlementsOptions = entitlementsOptions => {
|
|
42
|
+
this.entitlementsOptions = entitlementsOptions;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
this.setSessionContext = sessionContext => {
|
|
46
|
+
this.sessionContext = sessionContext;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
this.setAppName = appName => {
|
|
50
|
+
this.appName = appName;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
this.getContext = () => {
|
|
54
|
+
var _this$context;
|
|
55
|
+
|
|
56
|
+
return (_this$context = this.context) != null ? _this$context : {
|
|
57
|
+
baseUrl: window.location.href,
|
|
58
|
+
tokenResolver: () => 'my-authentication-token',
|
|
59
|
+
logLevel: 'error'
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
this.getAccessToken = () => {
|
|
64
|
+
return this.accessToken;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
this.getRequestSource = () => {
|
|
68
|
+
return this.requestSource;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
this.getUser = () => {
|
|
72
|
+
return this.user;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
this.shouldLoadEntitlements = () => {
|
|
76
|
+
var _this$entitlementsOpt;
|
|
77
|
+
|
|
78
|
+
return ((_this$entitlementsOpt = this.entitlementsOptions) == null ? void 0 : _this$entitlementsOpt.enabled) || false;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
this.isSessionPerTenantEnabled = () => {
|
|
82
|
+
var _this$sessionContext;
|
|
83
|
+
|
|
84
|
+
return ((_this$sessionContext = this.sessionContext) == null ? void 0 : _this$sessionContext.enableSessionPerTenant) || false;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
this.getAppName = () => {
|
|
88
|
+
return this.appName;
|
|
89
|
+
};
|
|
16
90
|
}
|
|
17
91
|
|
|
18
|
-
static
|
|
19
|
-
|
|
20
|
-
|
|
92
|
+
static default() {
|
|
93
|
+
return ContextHolder.getInstance(DEFAULT_APP_NAME);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static for(appName) {
|
|
97
|
+
return ContextHolder.getInstance(appName);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static getInstance(appName = 'default') {
|
|
101
|
+
if (!ContextHolder._apps) {
|
|
102
|
+
ContextHolder._apps = {};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (ContextHolder._apps[appName]) {
|
|
106
|
+
return ContextHolder._apps[appName];
|
|
21
107
|
}
|
|
22
108
|
|
|
23
|
-
|
|
109
|
+
ContextHolder._apps[appName] = new ContextHolder();
|
|
110
|
+
return ContextHolder._apps[appName];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static createInstance(appName = 'default') {
|
|
114
|
+
ContextHolder._apps[appName] = new ContextHolder();
|
|
115
|
+
ContextHolder._apps[appName].appName = appName;
|
|
116
|
+
return ContextHolder._apps[appName];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static setContext(context, appName = 'default') {
|
|
120
|
+
ContextHolder.for(appName).context = context;
|
|
24
121
|
}
|
|
25
122
|
|
|
26
|
-
static
|
|
27
|
-
ContextHolder.
|
|
123
|
+
static setAccessToken(accessToken, appName = DEFAULT_APP_NAME) {
|
|
124
|
+
ContextHolder.for(appName).accessToken = accessToken;
|
|
28
125
|
}
|
|
29
126
|
|
|
30
|
-
static
|
|
31
|
-
ContextHolder.
|
|
127
|
+
static setBasename(basename, appName = DEFAULT_APP_NAME) {
|
|
128
|
+
ContextHolder.for(appName).basename = basename;
|
|
32
129
|
}
|
|
33
130
|
|
|
34
|
-
|
|
35
|
-
|
|
131
|
+
setBasename(basename) {
|
|
132
|
+
this.basename = basename;
|
|
36
133
|
}
|
|
37
134
|
|
|
38
|
-
static
|
|
39
|
-
ContextHolder.
|
|
135
|
+
static setUser(user, appName = 'default') {
|
|
136
|
+
ContextHolder.for(appName).user = user;
|
|
40
137
|
}
|
|
41
138
|
|
|
42
|
-
static setRequestSource(requestSource) {
|
|
43
|
-
ContextHolder.
|
|
139
|
+
static setRequestSource(requestSource, appName = 'default') {
|
|
140
|
+
ContextHolder.for(appName).requestSource = requestSource;
|
|
44
141
|
}
|
|
45
142
|
|
|
46
|
-
static setOnRedirectTo(onRedirectTo) {
|
|
47
|
-
ContextHolder.
|
|
143
|
+
static setOnRedirectTo(onRedirectTo, appName = 'default') {
|
|
144
|
+
ContextHolder.for(appName).onRedirectTo = onRedirectTo;
|
|
48
145
|
}
|
|
49
146
|
|
|
50
|
-
static setLogout(logout, logoutUrl) {
|
|
51
|
-
ContextHolder.
|
|
147
|
+
static setLogout(logout, logoutUrl, appName = 'default') {
|
|
148
|
+
const context = ContextHolder.for(appName);
|
|
149
|
+
|
|
150
|
+
context.logout = callback => {
|
|
52
151
|
if (!callback) {
|
|
53
|
-
|
|
152
|
+
context.onRedirectTo(logoutUrl, undefined);
|
|
54
153
|
} else {
|
|
55
154
|
logout(callback);
|
|
56
155
|
}
|
|
57
156
|
};
|
|
58
157
|
}
|
|
59
158
|
|
|
60
|
-
static setEntitlementsOptions(entitlementsOptions) {
|
|
61
|
-
ContextHolder.
|
|
159
|
+
static setEntitlementsOptions(entitlementsOptions, appName = 'default') {
|
|
160
|
+
ContextHolder.for(appName).entitlementsOptions = entitlementsOptions;
|
|
62
161
|
}
|
|
63
162
|
|
|
64
|
-
static setSessionContext(sessionContext) {
|
|
65
|
-
|
|
66
|
-
instance.sessionContext = sessionContext;
|
|
163
|
+
static setSessionContext(sessionContext, appName = 'default') {
|
|
164
|
+
ContextHolder.for(appName).sessionContext = sessionContext;
|
|
67
165
|
}
|
|
68
166
|
|
|
69
167
|
static setAppName(appName) {
|
|
70
|
-
ContextHolder.
|
|
168
|
+
ContextHolder.for(appName).appName = appName;
|
|
71
169
|
}
|
|
72
170
|
|
|
73
|
-
static getContext() {
|
|
74
|
-
var _ContextHolder$
|
|
171
|
+
static getContext(appName = 'default') {
|
|
172
|
+
var _ContextHolder$for$co;
|
|
75
173
|
|
|
76
|
-
return (_ContextHolder$
|
|
174
|
+
return (_ContextHolder$for$co = ContextHolder.for(appName).context) != null ? _ContextHolder$for$co : {
|
|
77
175
|
baseUrl: window.location.href,
|
|
78
176
|
tokenResolver: () => 'my-authentication-token',
|
|
79
177
|
logLevel: 'error'
|
|
80
178
|
};
|
|
81
179
|
}
|
|
82
180
|
|
|
83
|
-
static getAccessToken() {
|
|
84
|
-
return ContextHolder.
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
static getRequestSource() {
|
|
88
|
-
return ContextHolder.getInstance().requestSource;
|
|
181
|
+
static getAccessToken(appName = 'default') {
|
|
182
|
+
return ContextHolder.for(appName).accessToken;
|
|
89
183
|
}
|
|
90
184
|
|
|
91
|
-
static
|
|
92
|
-
return ContextHolder.
|
|
185
|
+
static getRequestSource(appName = 'default') {
|
|
186
|
+
return ContextHolder.for(appName).requestSource;
|
|
93
187
|
}
|
|
94
188
|
|
|
95
189
|
static getBasename() {
|
|
96
190
|
return ContextHolder.getInstance().basename;
|
|
97
191
|
}
|
|
98
192
|
|
|
99
|
-
static
|
|
100
|
-
return ContextHolder.
|
|
193
|
+
static getUser(appName = 'default') {
|
|
194
|
+
return ContextHolder.for(appName).user;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
static onRedirectTo(path, opts, appName = 'default') {
|
|
198
|
+
return ContextHolder.for(appName).onRedirectTo(path, opts);
|
|
101
199
|
}
|
|
102
200
|
|
|
103
|
-
static logout(callback) {
|
|
104
|
-
return ContextHolder.
|
|
201
|
+
static logout(callback, appName = 'default') {
|
|
202
|
+
return ContextHolder.for(appName).logout(callback);
|
|
105
203
|
}
|
|
106
204
|
|
|
107
|
-
static shouldLoadEntitlements() {
|
|
108
|
-
var _ContextHolder$
|
|
205
|
+
static shouldLoadEntitlements(appName = 'default') {
|
|
206
|
+
var _ContextHolder$for$en;
|
|
109
207
|
|
|
110
|
-
return ((_ContextHolder$
|
|
208
|
+
return ((_ContextHolder$for$en = ContextHolder.for(appName).entitlementsOptions) == null ? void 0 : _ContextHolder$for$en.enabled) || false;
|
|
111
209
|
}
|
|
112
210
|
|
|
113
|
-
static isSessionPerTenantEnabled() {
|
|
114
|
-
var _ContextHolder$
|
|
211
|
+
static isSessionPerTenantEnabled(appName = 'default') {
|
|
212
|
+
var _ContextHolder$for$se;
|
|
115
213
|
|
|
116
|
-
return ((_ContextHolder$
|
|
214
|
+
return ((_ContextHolder$for$se = ContextHolder.for(appName).sessionContext) == null ? void 0 : _ContextHolder$for$se.enableSessionPerTenant) || false;
|
|
117
215
|
}
|
|
118
216
|
|
|
119
|
-
static getAppName() {
|
|
120
|
-
return ContextHolder.
|
|
217
|
+
static getAppName(appName = 'default') {
|
|
218
|
+
return ContextHolder.for(appName).appName;
|
|
121
219
|
}
|
|
122
220
|
|
|
123
221
|
}
|
|
124
|
-
ContextHolder.
|
|
222
|
+
ContextHolder._apps = void 0;
|
|
223
|
+
const DEFAULT_APP_NAME = 'default';
|
|
125
224
|
export const FronteggContext = {
|
|
126
|
-
getContext: () => ContextHolder.getContext(),
|
|
127
|
-
getAccessToken: () => ContextHolder.getAccessToken(),
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
225
|
+
getContext: () => ContextHolder.getContext(DEFAULT_APP_NAME),
|
|
226
|
+
getAccessToken: () => ContextHolder.getAccessToken(DEFAULT_APP_NAME),
|
|
227
|
+
setAccessToken: accessToken => ContextHolder.setAccessToken(accessToken, DEFAULT_APP_NAME),
|
|
228
|
+
getUser: () => ContextHolder.getUser(DEFAULT_APP_NAME),
|
|
229
|
+
setUser: user => ContextHolder.setUser(user, DEFAULT_APP_NAME),
|
|
230
|
+
onRedirectTo: (path, opts) => ContextHolder.onRedirectTo(path, opts, DEFAULT_APP_NAME),
|
|
231
|
+
setOnRedirectTo: onRedirectTo => ContextHolder.setOnRedirectTo(onRedirectTo, DEFAULT_APP_NAME),
|
|
232
|
+
logout: callback => ContextHolder.logout(callback, DEFAULT_APP_NAME),
|
|
233
|
+
getRequestSource: () => ContextHolder.getRequestSource(DEFAULT_APP_NAME),
|
|
234
|
+
setRequestSource: requestSource => ContextHolder.setRequestSource(requestSource, DEFAULT_APP_NAME),
|
|
235
|
+
isSessionPerTenantEnabled: () => ContextHolder.isSessionPerTenantEnabled(DEFAULT_APP_NAME),
|
|
236
|
+
shouldLoadEntitlements: () => ContextHolder.shouldLoadEntitlements(DEFAULT_APP_NAME),
|
|
237
|
+
getAppName: () => ContextHolder.getAppName(DEFAULT_APP_NAME),
|
|
238
|
+
setEntitlementsOptions: entitlementsOptions => ContextHolder.setEntitlementsOptions(entitlementsOptions, DEFAULT_APP_NAME),
|
|
239
|
+
setSessionContext: sessionContext => ContextHolder.setSessionContext(sessionContext, DEFAULT_APP_NAME)
|
|
131
240
|
};
|
package/FetchClient.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ContextOptions, RequestOptions, UserJwtOptions } from './interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* FetchClient is a class that wrap around the fetch API to make requests.
|
|
4
|
+
* It is used by the BaseApiClient to make requests to the server
|
|
5
|
+
*/
|
|
6
|
+
export declare class FetchClient {
|
|
7
|
+
private appName;
|
|
8
|
+
constructor(appName: string);
|
|
9
|
+
private getFronteggContext;
|
|
10
|
+
private prepareUrl;
|
|
11
|
+
private buildQueryParams;
|
|
12
|
+
private getAdditionalQueryParams;
|
|
13
|
+
private getAdditionalHeaders;
|
|
14
|
+
private buildRequestHeaders;
|
|
15
|
+
sendRequest: (opts: RequestOptions) => Promise<any>;
|
|
16
|
+
get: (url: string, params?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
|
|
17
|
+
post: (url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
|
|
18
|
+
patch: (url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
|
|
19
|
+
put: (url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
|
|
20
|
+
delete: (url: string, body?: any, opts?: Pick<RequestOptions, "body" | "params" | "contentType" | "responseType" | "headers" | "credentials"> | undefined) => Promise<any>;
|
|
21
|
+
postDownload: (url: string, body?: any, params?: any, opts?: any) => Promise<any>;
|
|
22
|
+
extractHeadersFromOptions: (options?: UserJwtOptions) => {
|
|
23
|
+
Authorization?: string;
|
|
24
|
+
};
|
|
25
|
+
/** @deprecated use getContextBaseUrl instead */
|
|
26
|
+
static getBaseUrl: (context: ContextOptions, url: string, withFronteggPrefix?: boolean) => string;
|
|
27
|
+
/** @deprecated use getContextBaseUrl instead */
|
|
28
|
+
getBaseUrl: (context: ContextOptions, url: string, withFronteggPrefix?: boolean) => string;
|
|
29
|
+
getContextBaseUrl: (url: string, withFronteggPrefix?: boolean) => string;
|
|
30
|
+
static getMetadataHeaders: (context: ContextOptions) => Record<string, string>;
|
|
31
|
+
/** @deprecated - use getContextMetadataHeaders instead */
|
|
32
|
+
getMetadataHeaders: (context: ContextOptions) => Record<string, string>;
|
|
33
|
+
getContextMetadataHeaders: () => Record<string, string>;
|
|
34
|
+
static getScopedTenant: () => string | null;
|
|
35
|
+
}
|
|
36
|
+
declare const _default: FetchClient;
|
|
37
|
+
/**
|
|
38
|
+
* import FetchClient and use it to make requests to the server for specific application
|
|
39
|
+
* @param appName - the application name to make requests for
|
|
40
|
+
* @deprecated - use FetchClient directly
|
|
41
|
+
*/
|
|
42
|
+
export default _default;
|