@frontegg/rest-api 3.1.78 → 3.1.79-alpha.10029056154

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.
Files changed (122) hide show
  1. package/BaseApiClient.d.ts +16 -0
  2. package/BaseApiClient.js +39 -0
  3. package/ContextHolder/index.d.ts +120 -29
  4. package/ContextHolder/index.js +169 -54
  5. package/FetchClient.d.ts +42 -0
  6. package/FetchClient.js +308 -0
  7. package/account-settings/index.d.ts +19 -7
  8. package/account-settings/index.js +23 -13
  9. package/applications/index.d.ts +49 -44
  10. package/applications/index.js +51 -37
  11. package/audits/index.d.ts +27 -15
  12. package/audits/index.js +27 -17
  13. package/auth/index.d.ts +817 -768
  14. package/auth/index.js +902 -721
  15. package/auth/secutiry-poilicy/index.d.ts +58 -102
  16. package/auth/secutiry-poilicy/index.js +122 -90
  17. package/auth/utils.d.ts +2 -2
  18. package/auth/utils.js +9 -8
  19. package/connectivity/index.d.ts +126 -27
  20. package/connectivity/index.js +147 -114
  21. package/directory/index.d.ts +31 -22
  22. package/directory/index.js +27 -15
  23. package/entitlements/index.d.ts +14 -8
  24. package/entitlements/index.js +12 -4
  25. package/feature-flags/index.d.ts +8 -2
  26. package/feature-flags/index.js +16 -8
  27. package/groups/index.d.ts +73 -49
  28. package/groups/index.js +64 -45
  29. package/impersonate/index.d.ts +15 -6
  30. package/impersonate/index.js +13 -5
  31. package/index.d.ts +156 -108
  32. package/index.js +109 -78
  33. package/interfaces.d.ts +10 -0
  34. package/metadata/index.d.ts +67 -7
  35. package/metadata/index.js +52 -32
  36. package/node/BaseApiClient.js +49 -0
  37. package/node/ContextHolder/index.js +169 -54
  38. package/node/FetchClient.js +326 -0
  39. package/node/account-settings/index.js +27 -16
  40. package/node/applications/index.js +51 -44
  41. package/node/audits/index.js +31 -20
  42. package/node/auth/index.js +768 -1035
  43. package/node/auth/secutiry-poilicy/index.js +125 -136
  44. package/node/auth/utils.js +9 -7
  45. package/node/connectivity/index.js +148 -187
  46. package/node/directory/index.js +29 -20
  47. package/node/entitlements/index.js +18 -5
  48. package/node/feature-flags/index.js +21 -9
  49. package/node/groups/index.js +65 -63
  50. package/node/impersonate/index.js +18 -5
  51. package/node/index.js +116 -71
  52. package/node/metadata/index.js +61 -52
  53. package/node/notifications/index.js +37 -27
  54. package/node/reports/index.js +78 -70
  55. package/node/roles/index.js +56 -51
  56. package/node/security-center/index.js +21 -9
  57. package/node/sub-tenants/index.js +90 -89
  58. package/node/subscriptions/index.js +69 -107
  59. package/node/subscriptions/invoices.js +25 -17
  60. package/node/subscriptions/managedSubscriptions.js +32 -27
  61. package/node/subscriptions/paymentMethods.js +27 -20
  62. package/node/subscriptions/paymentProviders.js +15 -6
  63. package/node/subscriptions/plans.js +17 -9
  64. package/node/subscriptions/providers/stripe/index.js +26 -21
  65. package/node/subscriptions/subscriptions.js +32 -27
  66. package/node/subscriptions/summaries.js +15 -6
  67. package/node/subscriptions/tenantConfiguration.js +17 -9
  68. package/node/subscriptions/vendorPublicConfigurations.js +15 -6
  69. package/node/teams/index.js +138 -148
  70. package/node/tenants/index.js +65 -60
  71. package/node/user-phone-numbers/index.js +32 -24
  72. package/node/users/index.js +58 -53
  73. package/node/vendor/index.js +17 -6
  74. package/notifications/index.d.ts +22 -16
  75. package/notifications/index.js +33 -22
  76. package/package.json +1 -1
  77. package/reports/index.d.ts +50 -44
  78. package/reports/index.js +75 -62
  79. package/roles/index.d.ts +44 -38
  80. package/roles/index.js +57 -41
  81. package/security-center/index.d.ts +14 -2
  82. package/security-center/index.js +15 -6
  83. package/sub-tenants/index.d.ts +57 -15
  84. package/sub-tenants/index.js +88 -68
  85. package/subscriptions/index.d.ts +56 -11
  86. package/subscriptions/index.js +58 -11
  87. package/subscriptions/invoices.d.ts +16 -13
  88. package/subscriptions/invoices.js +24 -14
  89. package/subscriptions/managedSubscriptions.d.ts +18 -15
  90. package/subscriptions/managedSubscriptions.js +33 -22
  91. package/subscriptions/paymentMethods.d.ts +16 -13
  92. package/subscriptions/paymentMethods.js +26 -17
  93. package/subscriptions/paymentProviders.d.ts +8 -5
  94. package/subscriptions/paymentProviders.js +11 -4
  95. package/subscriptions/plans.d.ts +11 -8
  96. package/subscriptions/plans.js +14 -6
  97. package/subscriptions/providers/stripe/index.d.ts +24 -21
  98. package/subscriptions/providers/stripe/index.js +27 -16
  99. package/subscriptions/subscriptions.d.ts +24 -21
  100. package/subscriptions/subscriptions.js +33 -22
  101. package/subscriptions/summaries.d.ts +7 -4
  102. package/subscriptions/summaries.js +10 -3
  103. package/subscriptions/tenantConfiguration.d.ts +6 -3
  104. package/subscriptions/tenantConfiguration.js +15 -7
  105. package/subscriptions/vendorPublicConfigurations.d.ts +5 -2
  106. package/subscriptions/vendorPublicConfigurations.js +11 -4
  107. package/teams/index.d.ts +37 -139
  108. package/teams/index.js +130 -99
  109. package/tenants/index.d.ts +25 -37
  110. package/tenants/index.js +62 -46
  111. package/user-phone-numbers/index.d.ts +32 -26
  112. package/user-phone-numbers/index.js +32 -19
  113. package/users/index.d.ts +21 -15
  114. package/users/index.js +60 -44
  115. package/vendor/index.d.ts +12 -6
  116. package/vendor/index.js +11 -4
  117. package/fetch.d.ts +0 -24
  118. package/fetch.js +0 -265
  119. package/node/fetch.js +0 -306
  120. package/node/subscriptions/providers/index.js +0 -18
  121. package/subscriptions/providers/index.d.ts +0 -1
  122. 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
+ }
@@ -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
+ }
@@ -1,5 +1,5 @@
1
1
  import { SessionContext, ContextOptions, RedirectOptions, RequestSource } from '../interfaces';
2
- import { IUserProfile } from "../users/interfaces";
2
+ import { IUserProfile } from '../users/interfaces';
3
3
  /**
4
4
  * Entitlements config from frontegg provider
5
5
  */
@@ -7,63 +7,154 @@ export interface EntitlementsOptions {
7
7
  enabled?: boolean;
8
8
  }
9
9
  export declare class ContextHolder {
10
- private static instance;
10
+ private static _apps;
11
11
  private context;
12
12
  private accessToken;
13
13
  private user;
14
14
  private requestSource;
15
- private onRedirectTo;
16
- private logout;
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 getInstance(): ContextHolder;
23
- static setContext(context: ContextOptions): void;
24
- static setAccessToken(accessToken: string | null): void;
25
- static setUser(user: IUserProfile | null): void;
26
- static setBasename(basename: string | null): void;
27
- static setRequestSource(requestSource: RequestSource | null): void;
28
- static setOnRedirectTo(onRedirectTo: (path: string, opts?: RedirectOptions) => void): void;
29
- static setLogout(logout: (callback?: () => void) => void, logoutUrl: string): void;
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).setUser instead
42
+ */
43
+ static setUser(user: IUserProfile | null, appName?: string): void;
44
+ setUser: (user: IUserProfile | null) => void;
45
+ /**
46
+ * @deprecated - use ContextHolder.for(appName).setRequestSource instead
47
+ */
48
+ static setRequestSource(requestSource: RequestSource | null, appName?: string): void;
49
+ setRequestSource: (requestSource: RequestSource | null) => void;
50
+ /**
51
+ * @deprecated - use ContextHolder.for(appName).setOnRedirectTo instead
52
+ */
53
+ static setOnRedirectTo(onRedirectTo: (path: string, opts?: RedirectOptions) => void, appName?: string): void;
54
+ setOnRedirectTo: (onRedirectTo: (path: string, opts?: RedirectOptions | undefined) => void) => void;
55
+ /**
56
+ * @deprecated - use ContextHolder.for(appName).setLogout instead
57
+ */
58
+ static setLogout(logout: (callback?: () => void) => void, logoutUrl: string, appName?: string): void;
59
+ setLogout: (logout: (callback?: (() => void) | undefined) => void) => void;
30
60
  /**
31
61
  * App name should also be set for entitlements
62
+ * @deprecated - use ContextHolder.for(appName).setEntitlementsOptions instead
32
63
  * @param entitlementsOptions frontegg options entitlements config
64
+ * @param appName - app name
33
65
  */
34
- static setEntitlementsOptions(entitlementsOptions: EntitlementsOptions): void;
66
+ static setEntitlementsOptions(entitlementsOptions: EntitlementsOptions, appName?: string): void;
67
+ setEntitlementsOptions: (entitlementsOptions: EntitlementsOptions) => void;
35
68
  /**
69
+ * @deprecated - use ContextHolder.for(appName).setSessionContext instead
36
70
  * @param sessionContext frontegg options SessionContext config
71
+ * @param appName - app name
72
+ */
73
+ static setSessionContext(sessionContext: SessionContext, appName?: string): void;
74
+ setSessionContext: (sessionContext: SessionContext) => void;
75
+ /**
76
+ * @deprecated - use ContextHolder.for(appName).setAppName instead
77
+ */
78
+ static setAppName(appName: string): void;
79
+ setAppName: (appName: string) => void;
80
+ /**
81
+ * @deprecated - use ContextHolder.for(appName).getContext instead
37
82
  */
38
- static setSessionContext(sessionContext: SessionContext): void;
83
+ static getContext(appName?: string): ContextOptions;
84
+ getContext: () => ContextOptions;
85
+ /**
86
+ * @deprecated - use ContextHolder.for(appName).getAccessToken instead
87
+ */
88
+ static getAccessToken(appName?: string): string | null;
89
+ getAccessToken: () => string | null;
90
+ /**
91
+ * @deprecated - use ContextHolder.for(appName).requestSource instead
92
+ */
93
+ static getRequestSource(appName?: string): RequestSource | null;
94
+ getRequestSource: () => RequestSource | null;
95
+ /**
96
+ * @deprecated - use ContextHolder.for(appName).getBasename instead
97
+ */
98
+ static getBasename(appName?: string): string | null;
99
+ getBasename(): string | null;
100
+ /**
101
+ * @deprecated - use ContextHolder.for(appName).setBasename instead
102
+ */
103
+ static setBasename(basename: string | null, appName?: string): void;
104
+ setBasename(basename: string | null): void;
39
105
  /**
40
- * @param appName for feature flags e.g.
106
+ * @deprecated - use ContextHolder.for(appName).getUser instead
41
107
  */
42
- static setAppName(appName: string | null): void;
43
- static getContext(): ContextOptions;
44
- static getAccessToken(): string | null;
45
- static getRequestSource(): RequestSource | null;
46
- static getUser(): IUserProfile | null;
47
- static getBasename(): string | null;
48
- static onRedirectTo(path: string, opts?: RedirectOptions): void;
49
- static logout(callback?: () => void): void;
108
+ static getUser(appName?: string): IUserProfile | null;
109
+ getUser: () => IUserProfile | null;
50
110
  /**
111
+ * @deprecated - use ContextHolder.for(appName).onRedirectTo instead
112
+ */
113
+ static onRedirectTo(path: string, opts?: RedirectOptions, appName?: string): void;
114
+ /**
115
+ * @deprecated - use ContextHolder.for(appName).logout instead
116
+ */
117
+ static logout(callback?: () => void, appName?: string): void;
118
+ /**
119
+ * @deprecated - use ContextHolder.for(appName).shouldLoadEntitlements instead
51
120
  * @returns shouldLoadEntitlements. Default to false.
52
121
  */
53
- static shouldLoadEntitlements(): boolean;
122
+ static shouldLoadEntitlements(appName?: string): boolean;
123
+ shouldLoadEntitlements: () => boolean;
54
124
  /**
55
- * @returns isSessionPerTenantEnabled. Default to false.
56
- */
57
- static isSessionPerTenantEnabled(): boolean;
125
+ * @deprecated - use ContextHolder.for(appName).isSessionPerTenantEnabled instead
126
+ * @returns isSessionPerTenantEnabled. Default to false.
127
+ */
128
+ static isSessionPerTenantEnabled(appName?: string): boolean;
129
+ isSessionPerTenantEnabled: () => boolean;
58
130
  /**
131
+ * @deprecated - use ContextHolder.for(appName).getAppName instead
59
132
  * @returns app name value
60
133
  */
61
- static getAppName(): string | null;
134
+ static getAppName(appName?: string): string | null;
135
+ getAppName: () => string | null;
62
136
  }
137
+ /**
138
+ * Frontegg context to be used in the application
139
+ *
140
+ * @deprecated use ContextHolder.for instead
141
+ */
63
142
  export declare const FronteggContext: {
64
143
  getContext: () => ContextOptions;
65
144
  getAccessToken: () => string | null;
145
+ setAccessToken: (accessToken: string | null) => void;
66
146
  getUser: () => IUserProfile | null;
67
- onRedirectTo: (path: string, opts: RedirectOptions) => void;
147
+ setUser: (user: IUserProfile | null) => void;
148
+ onRedirectTo: (path: string, opts?: RedirectOptions | undefined) => void;
149
+ setOnRedirectTo: (onRedirectTo: (path: string, opts?: RedirectOptions | undefined) => void) => void;
68
150
  logout: (callback?: (() => void) | undefined) => void;
151
+ getRequestSource: () => RequestSource | null;
152
+ setRequestSource: (requestSource: RequestSource | null) => void;
153
+ isSessionPerTenantEnabled: () => boolean;
154
+ shouldLoadEntitlements: () => boolean;
155
+ getAppName: () => string | null;
156
+ setEntitlementsOptions: (entitlementsOptions: EntitlementsOptions) => void;
157
+ setSessionContext: (sessionContext: SessionContext) => void;
158
+ getBasename: () => string | null;
159
+ setBasename: (basename: string | null) => void;
69
160
  };
@@ -13,119 +13,234 @@ 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
+ };
90
+ }
91
+
92
+ static default() {
93
+ return ContextHolder.getInstance(DEFAULT_APP_NAME);
94
+ }
95
+
96
+ static for(appName) {
97
+ return ContextHolder.getInstance(appName);
16
98
  }
17
99
 
18
- static getInstance() {
19
- if (!ContextHolder.instance) {
20
- ContextHolder.instance = new ContextHolder();
100
+ static getInstance(appName = 'default') {
101
+ if (!ContextHolder._apps) {
102
+ ContextHolder._apps = {};
21
103
  }
22
104
 
23
- return ContextHolder.instance;
105
+ if (ContextHolder._apps[appName]) {
106
+ return ContextHolder._apps[appName];
107
+ }
108
+
109
+ ContextHolder._apps[appName] = new ContextHolder();
110
+ return ContextHolder._apps[appName];
24
111
  }
25
112
 
26
- static setContext(context) {
27
- ContextHolder.getInstance().context = context;
113
+ static createInstance(appName = 'default') {
114
+ ContextHolder._apps[appName] = new ContextHolder();
115
+ ContextHolder._apps[appName].appName = appName;
116
+ return ContextHolder._apps[appName];
28
117
  }
29
118
 
30
- static setAccessToken(accessToken) {
31
- ContextHolder.getInstance().accessToken = accessToken;
119
+ static setContext(context, appName = 'default') {
120
+ ContextHolder.for(appName).context = context;
32
121
  }
33
122
 
34
- static setUser(user) {
35
- ContextHolder.getInstance().user = user;
123
+ static setAccessToken(accessToken, appName = DEFAULT_APP_NAME) {
124
+ ContextHolder.for(appName).accessToken = accessToken;
36
125
  }
37
126
 
38
- static setBasename(basename) {
39
- ContextHolder.getInstance().basename = basename;
127
+ static setUser(user, appName = 'default') {
128
+ ContextHolder.for(appName).user = user;
40
129
  }
41
130
 
42
- static setRequestSource(requestSource) {
43
- ContextHolder.getInstance().requestSource = requestSource;
131
+ static setRequestSource(requestSource, appName = 'default') {
132
+ ContextHolder.for(appName).requestSource = requestSource;
44
133
  }
45
134
 
46
- static setOnRedirectTo(onRedirectTo) {
47
- ContextHolder.getInstance().onRedirectTo = onRedirectTo;
135
+ static setOnRedirectTo(onRedirectTo, appName = 'default') {
136
+ ContextHolder.for(appName).onRedirectTo = onRedirectTo;
48
137
  }
49
138
 
50
- static setLogout(logout, logoutUrl) {
51
- ContextHolder.getInstance().logout = callback => {
139
+ static setLogout(logout, logoutUrl, appName = 'default') {
140
+ const context = ContextHolder.for(appName);
141
+
142
+ context.logout = callback => {
52
143
  if (!callback) {
53
- ContextHolder.onRedirectTo(logoutUrl);
144
+ context.onRedirectTo(logoutUrl, undefined);
54
145
  } else {
55
146
  logout(callback);
56
147
  }
57
148
  };
58
149
  }
59
150
 
60
- static setEntitlementsOptions(entitlementsOptions) {
61
- ContextHolder.getInstance().entitlementsOptions = entitlementsOptions;
151
+ static setEntitlementsOptions(entitlementsOptions, appName = 'default') {
152
+ ContextHolder.for(appName).entitlementsOptions = entitlementsOptions;
62
153
  }
63
154
 
64
- static setSessionContext(sessionContext) {
65
- const instance = ContextHolder.getInstance();
66
- instance.sessionContext = sessionContext;
155
+ static setSessionContext(sessionContext, appName = 'default') {
156
+ ContextHolder.for(appName).sessionContext = sessionContext;
67
157
  }
68
158
 
69
159
  static setAppName(appName) {
70
- ContextHolder.getInstance().appName = appName;
160
+ ContextHolder.for(appName).appName = appName;
71
161
  }
72
162
 
73
- static getContext() {
74
- var _ContextHolder$getIns;
163
+ static getContext(appName = 'default') {
164
+ var _ContextHolder$for$co;
75
165
 
76
- return (_ContextHolder$getIns = ContextHolder.getInstance().context) != null ? _ContextHolder$getIns : {
166
+ return (_ContextHolder$for$co = ContextHolder.for(appName).context) != null ? _ContextHolder$for$co : {
77
167
  baseUrl: window.location.href,
78
168
  tokenResolver: () => 'my-authentication-token',
79
169
  logLevel: 'error'
80
170
  };
81
171
  }
82
172
 
83
- static getAccessToken() {
84
- return ContextHolder.getInstance().accessToken;
173
+ static getAccessToken(appName = 'default') {
174
+ return ContextHolder.for(appName).accessToken;
175
+ }
176
+
177
+ static getRequestSource(appName = 'default') {
178
+ return ContextHolder.for(appName).requestSource;
179
+ }
180
+
181
+ static getBasename(appName = 'default') {
182
+ return ContextHolder.for(appName).basename;
183
+ }
184
+
185
+ getBasename() {
186
+ return this.basename;
85
187
  }
86
188
 
87
- static getRequestSource() {
88
- return ContextHolder.getInstance().requestSource;
189
+ static setBasename(basename, appName = DEFAULT_APP_NAME) {
190
+ ContextHolder.for(appName).basename = basename;
89
191
  }
90
192
 
91
- static getUser() {
92
- return ContextHolder.getInstance().user;
193
+ setBasename(basename) {
194
+ this.basename = basename;
93
195
  }
94
196
 
95
- static getBasename() {
96
- return ContextHolder.getInstance().basename;
197
+ static getUser(appName = 'default') {
198
+ return ContextHolder.for(appName).user;
97
199
  }
98
200
 
99
- static onRedirectTo(path, opts) {
100
- return ContextHolder.getInstance().onRedirectTo(path, opts);
201
+ static onRedirectTo(path, opts, appName = 'default') {
202
+ return ContextHolder.for(appName).onRedirectTo(path, opts);
101
203
  }
102
204
 
103
- static logout(callback) {
104
- return ContextHolder.getInstance().logout(callback);
205
+ static logout(callback, appName = 'default') {
206
+ return ContextHolder.for(appName).logout(callback);
105
207
  }
106
208
 
107
- static shouldLoadEntitlements() {
108
- var _ContextHolder$getIns2;
209
+ static shouldLoadEntitlements(appName = 'default') {
210
+ var _ContextHolder$for$en;
109
211
 
110
- return ((_ContextHolder$getIns2 = ContextHolder.getInstance().entitlementsOptions) == null ? void 0 : _ContextHolder$getIns2.enabled) || false;
212
+ return ((_ContextHolder$for$en = ContextHolder.for(appName).entitlementsOptions) == null ? void 0 : _ContextHolder$for$en.enabled) || false;
111
213
  }
112
214
 
113
- static isSessionPerTenantEnabled() {
114
- var _ContextHolder$getIns3;
215
+ static isSessionPerTenantEnabled(appName = 'default') {
216
+ var _ContextHolder$for$se;
115
217
 
116
- return ((_ContextHolder$getIns3 = ContextHolder.getInstance().sessionContext) == null ? void 0 : _ContextHolder$getIns3.enableSessionPerTenant) || false;
218
+ return ((_ContextHolder$for$se = ContextHolder.for(appName).sessionContext) == null ? void 0 : _ContextHolder$for$se.enableSessionPerTenant) || false;
117
219
  }
118
220
 
119
- static getAppName() {
120
- return ContextHolder.getInstance().appName;
221
+ static getAppName(appName = 'default') {
222
+ return ContextHolder.for(appName).appName;
121
223
  }
122
224
 
123
225
  }
124
- ContextHolder.instance = void 0;
226
+ ContextHolder._apps = void 0;
227
+ const DEFAULT_APP_NAME = 'default';
125
228
  export const FronteggContext = {
126
- getContext: () => ContextHolder.getContext(),
127
- getAccessToken: () => ContextHolder.getAccessToken(),
128
- getUser: () => ContextHolder.getUser(),
129
- onRedirectTo: (path, opts) => ContextHolder.onRedirectTo(path, opts),
130
- logout: callback => ContextHolder.logout(callback)
229
+ getContext: () => ContextHolder.getContext(DEFAULT_APP_NAME),
230
+ getAccessToken: () => ContextHolder.getAccessToken(DEFAULT_APP_NAME),
231
+ setAccessToken: accessToken => ContextHolder.setAccessToken(accessToken, DEFAULT_APP_NAME),
232
+ getUser: () => ContextHolder.getUser(DEFAULT_APP_NAME),
233
+ setUser: user => ContextHolder.setUser(user, DEFAULT_APP_NAME),
234
+ onRedirectTo: (path, opts) => ContextHolder.onRedirectTo(path, opts, DEFAULT_APP_NAME),
235
+ setOnRedirectTo: onRedirectTo => ContextHolder.setOnRedirectTo(onRedirectTo, DEFAULT_APP_NAME),
236
+ logout: callback => ContextHolder.logout(callback, DEFAULT_APP_NAME),
237
+ getRequestSource: () => ContextHolder.getRequestSource(DEFAULT_APP_NAME),
238
+ setRequestSource: requestSource => ContextHolder.setRequestSource(requestSource, DEFAULT_APP_NAME),
239
+ isSessionPerTenantEnabled: () => ContextHolder.isSessionPerTenantEnabled(DEFAULT_APP_NAME),
240
+ shouldLoadEntitlements: () => ContextHolder.shouldLoadEntitlements(DEFAULT_APP_NAME),
241
+ getAppName: () => ContextHolder.getAppName(DEFAULT_APP_NAME),
242
+ setEntitlementsOptions: entitlementsOptions => ContextHolder.setEntitlementsOptions(entitlementsOptions, DEFAULT_APP_NAME),
243
+ setSessionContext: sessionContext => ContextHolder.setSessionContext(sessionContext, DEFAULT_APP_NAME),
244
+ getBasename: () => ContextHolder.getBasename(DEFAULT_APP_NAME),
245
+ setBasename: basename => ContextHolder.setBasename(basename, DEFAULT_APP_NAME)
131
246
  };
@@ -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;