@frontegg/js 7.0.0-alpha.1 → 7.0.0-alpha.10

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.
@@ -1,4 +1,12 @@
1
1
  export declare class AdminPortal {
2
2
  static show(name?: string): void;
3
+ static showMultiApp(name?: string): void;
4
+ /**
5
+ * Open the hosted portal must be called synchronously with user interaction
6
+ *
7
+ * @param newTab - open the portal in a new tab = true
8
+ * @param name - the app name = 'default'
9
+ */
10
+ static openHosted(newTab?: boolean, name?: string): void;
3
11
  static hide(name?: string): void;
4
12
  }
@@ -11,6 +11,28 @@ export var AdminPortal = /*#__PURE__*/function () {
11
11
  var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
12
12
  AppHolder.getInstance(name).showAdminPortal();
13
13
  }
14
+ }, {
15
+ key: "showMultiApp",
16
+ value: function showMultiApp() {
17
+ var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
18
+ AppHolder.getInstance(name).showAdminPortal({
19
+ isMultiApp: true
20
+ });
21
+ }
22
+
23
+ /**
24
+ * Open the hosted portal must be called synchronously with user interaction
25
+ *
26
+ * @param newTab - open the portal in a new tab = true
27
+ * @param name - the app name = 'default'
28
+ */
29
+ }, {
30
+ key: "openHosted",
31
+ value: function openHosted() {
32
+ var newTab = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
33
+ var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
34
+ AppHolder.getInstance(name).openHostedAdminPortal(newTab);
35
+ }
14
36
  }, {
15
37
  key: "hide",
16
38
  value: function hide() {
@@ -1,5 +1,4 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
- import _extends from "@babel/runtime/helpers/esm/extends";
3
2
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
3
  import _createClass from "@babel/runtime/helpers/esm/createClass";
5
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
@@ -37,7 +36,7 @@ export var AdminPortalRenderer = /*#__PURE__*/function () {
37
36
  appName: name
38
37
  }, this, true, undefined, undefined, true);
39
38
  }
40
- this.options = _extends({
39
+ this.options = Object.assign({
41
40
  themeOptions: themeOptions,
42
41
  iframeRendering: true,
43
42
  metadata: {},
@@ -1,6 +1,7 @@
1
- import { EnhancedStore, EntitledToOptions, Entitlement } from '@frontegg/redux-store';
2
- import { FronteggAppOptions, FronteggCheckoutDialogOptions, LocalizationsOverrides, LoadEntitlementsCallback } from '@frontegg/types';
3
- import { IFeatureFlagsAttributes } from '@frontegg/rest-api';
1
+ import { EntitledToOptions, Entitlement, FronteggStore, IsSteppedUpOptions, StepUpOptions } from '@frontegg/redux-store';
2
+ import { FronteggAppOptions, FronteggCheckoutDialogOptions, LoadEntitlementsCallback, LocalizationsOverrides, ShowAdminPortalOptions, SwitchTenantOptions } from '@frontegg/types';
3
+ import { FetchClient, FronteggApiClient, IFeatureFlagsAttributes } from '@frontegg/rest-api';
4
+ import { CustomAttributes } from '@frontegg/entitlements-javascript-commons';
4
5
  declare type FronteggAppContainers = {
5
6
  adminPortalEl: HTMLElement;
6
7
  loginBoxEl: HTMLElement;
@@ -25,8 +26,10 @@ export declare class FronteggApp {
25
26
  loginBoxContainer?: HTMLElement;
26
27
  checkoutDialogContainer?: HTMLElement;
27
28
  loginBoxRenderer?: any;
28
- store: EnhancedStore;
29
+ store: FronteggStore;
29
30
  loadingListeners: (() => void)[];
31
+ fetchClient: FetchClient;
32
+ apiClient: FronteggApiClient;
30
33
  updateLocalizations?: (localizations: LocalizationsOverrides) => void;
31
34
  constructor(_options: FronteggAppOptions, name: string, iframeRendering?: boolean, allowMultipleRenderers?: boolean);
32
35
  /**
@@ -34,6 +37,7 @@ export declare class FronteggApp {
34
37
  * @param entitlementsOptions - entitlements options from frontegg options
35
38
  */
36
39
  private setEntitlementsOptions;
40
+ private setSessionContext;
37
41
  loadAdminBoxMetadata: () => Promise<void>;
38
42
  /**
39
43
  * Loading required information on first load, mainly for refresh token and initial data.
@@ -48,16 +52,27 @@ export declare class FronteggApp {
48
52
  * @param previewFeatureFlags
49
53
  */
50
54
  setFeatureFlagsForPreview: (previewFeatureFlags: IFeatureFlagsAttributes) => void;
55
+ /**
56
+ * @param flags keys to check
57
+ * @returns an array of feature flags on/off boolean values
58
+ */
59
+ queryFeatureFlags: (flags: string[]) => boolean[];
51
60
  initContainers(elements: FronteggAppContainers): Promise<void>;
52
61
  updateLocalizationsSetter: (localizationUpdateFn: (localizations: LocalizationsOverrides) => void) => void;
53
62
  updateMetadata(metadata: FronteggAppOptions['metadata']): void;
54
63
  addOnLoadedListener(listener: () => void): void;
55
64
  ready(listener: () => void): void;
56
- loginWithRedirect(): void;
65
+ loginWithRedirect(additionalParams?: Record<string, any>): void;
57
66
  logout(): void;
58
67
  loadScript(component: string): Promise<unknown>;
59
68
  loadLoginBox(): Promise<void>;
60
- showAdminPortal(): Promise<void>;
69
+ showAdminPortal(options?: ShowAdminPortalOptions): Promise<void>;
70
+ /**
71
+ * Open the hosted portal must be called synchronously with user interaction
72
+ *
73
+ * @param newTab - open the portal in a new tab = true
74
+ */
75
+ openHostedAdminPortal(newTab?: boolean): void;
61
76
  hideAdminPortal(): void;
62
77
  showCheckoutDialog(opts: FronteggCheckoutDialogOptions): Promise<void>;
63
78
  hideCheckoutDialog(): void;
@@ -66,28 +81,56 @@ export declare class FronteggApp {
66
81
  */
67
82
  private getEntitlementsFromStore;
68
83
  /**
69
- @param key
84
+ * @returns user store data
85
+ */
86
+ private getUserFromStore;
87
+ /**
88
+ * @param customAttributes consumer attributes
89
+ * @returns is entitled query data including: entitltments state, final attributes (consumer and frontegg) and API version to use
90
+ */
91
+ private getEntitlementsQueryData;
92
+ /**
93
+ @param key feature key
94
+ @param customAttributes user attributes
70
95
  @returns if the user is entitled to the given feature. Attaching the justification if not
71
96
  @throws when entitlement is not enabled via frontegg options
72
97
  */
73
- getFeatureEntitlements(key: string): Entitlement;
98
+ getFeatureEntitlements(key: string, customAttributes?: CustomAttributes): Entitlement;
74
99
  /**
75
- @param key
100
+ @param key permission key
101
+ @param customAttributes user attributes
76
102
  @returns if the user is entitled to the given permission. Attaching the justification if not
77
103
  @throws when entitlement is not enabled via frontegg options
78
104
  */
79
- getPermissionEntitlements(key: string): Entitlement;
105
+ getPermissionEntitlements(key: string, customAttributes?: CustomAttributes): Entitlement;
80
106
  /**
81
107
  @param options - including permission or feature key
108
+ @param customAttributes user attributes
82
109
  @returns if the user is entitled to the given permission or feature. Attaching the justification if not
83
110
  @throws when entitlement is not enabled via frontegg options
84
111
  */
85
- getEntitlements(options: EntitledToOptions): Entitlement;
112
+ getEntitlements(options: EntitledToOptions, customAttributes?: CustomAttributes): Entitlement;
86
113
  /**
87
114
  * Load entitlements
88
115
  * @param callback called on request completed with true if succeeded, false if failed
89
116
  */
90
117
  loadEntitlements(callback?: LoadEntitlementsCallback): void;
118
+ /**
119
+ * Redirects to the step up page with the max age param and set the redirect url in the local storage
120
+ * @param options.maxAge optional max age
121
+ */
122
+ stepUp(options?: StepUpOptions): void;
123
+ /**
124
+ * @param options.maxAge optional max age
125
+ * @return true when user is stepped up, false otherwise
126
+ */
127
+ isSteppedUp(options?: IsSteppedUpOptions): boolean;
128
+ /**
129
+ * Switch tenant
130
+ * @param payload.tenantId tenant id to switch for
131
+ * @param payload.callback optional callback to be called with true / false for success / failure tenant switching operation
132
+ */
133
+ switchTenant(payload: SwitchTenantOptions): void;
91
134
  close(): void;
92
135
  }
93
136
  export {};
@@ -1,23 +1,25 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
4
  import _createClass from "@babel/runtime/helpers/esm/createClass";
5
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
- import { createFronteggStore, getPermissionEntitlements as _getPermissionEntitlements, getFeatureEntitlements as _getFeatureEntitlements } from '@frontegg/redux-store';
6
+ import * as FronteggReduxStore from '@frontegg/redux-store';
7
+ import { createStore, getFeatureEntitlements as _getFeatureEntitlements, getPermissionEntitlements as _getPermissionEntitlements, isSteppedUp as _isSteppedUp, redirectByStepUpUrl } from '@frontegg/redux-store';
8
+ import * as FronteggTypes from '@frontegg/types';
7
9
  import { Metadata } from '@frontegg/types';
8
10
  import { formatName, restoreSearchParams } from '../utils';
9
11
  import { AppHolder } from '../AppHolder';
10
- import { fetch as FronteggFetch, ContextHolder } from '@frontegg/rest-api';
11
- import { RequestSource } from '@frontegg/rest-api';
12
12
  import * as FronteggRestApi from '@frontegg/rest-api';
13
- import * as FronteggTypes from '@frontegg/types';
13
+ import { ContextHolder, createApiClient, FetchClient, RequestSource } from '@frontegg/rest-api';
14
14
  import versions from '../version';
15
15
  import { mockFlagsList } from '../utils/mockFlagsList';
16
- import { loadGTM } from './utils';
16
+ import { getOverriddenMetadata, loadGTM } from './utils';
17
+ import * as ValtioVanilla from 'valtio/vanilla';
17
18
  export var FronteggApp = /*#__PURE__*/function () {
18
19
  function FronteggApp(_options, name) {
19
20
  var _this = this,
20
- _this$options$authOpt3;
21
+ _this$options$authOpt3,
22
+ _options$authOptions;
21
23
  var iframeRendering = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
22
24
  var allowMultipleRenderers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
23
25
  _classCallCheck(this, FronteggApp);
@@ -38,38 +40,43 @@ export var FronteggApp = /*#__PURE__*/function () {
38
40
  this.loginBoxRenderer = void 0;
39
41
  this.store = void 0;
40
42
  this.loadingListeners = [];
43
+ this.fetchClient = void 0;
44
+ this.apiClient = void 0;
41
45
  this.updateLocalizations = void 0;
42
46
  this.loadAdminBoxMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
43
- var Get, _data$rows$0$configur, _data$rows, _data$rows$, data;
47
+ var _data$rows$0$configur, _data$rows, _data$rows$, data, metadata;
44
48
  return _regeneratorRuntime.wrap(function _callee$(_context) {
45
49
  while (1) switch (_context.prev = _context.next) {
46
50
  case 0:
47
- Get = FronteggFetch.Get;
48
51
  if (_this.options.metadata) {
49
- _context.next = 12;
52
+ _context.next = 14;
50
53
  break;
51
54
  }
52
- _context.prev = 2;
53
- _context.next = 5;
54
- return Get("/metadata", {
55
+ _context.prev = 1;
56
+ _context.next = 4;
57
+ return _this.fetchClient.get('/metadata', {
55
58
  entityName: 'adminBox'
56
59
  });
57
- case 5:
60
+ case 4:
58
61
  data = _context.sent;
59
- _this.options.metadata = (_data$rows$0$configur = data == null ? void 0 : (_data$rows = data.rows) == null ? void 0 : (_data$rows$ = _data$rows[0]) == null ? void 0 : _data$rows$.configuration) != null ? _data$rows$0$configur : {};
60
- _context.next = 12;
62
+ metadata = (_data$rows$0$configur = data == null ? void 0 : (_data$rows = data.rows) == null ? void 0 : (_data$rows$ = _data$rows[0]) == null ? void 0 : _data$rows$.configuration) != null ? _data$rows$0$configur : {};
63
+ _context.next = 8;
64
+ return getOverriddenMetadata(metadata, _this.fetchClient);
65
+ case 8:
66
+ _this.options.metadata = _context.sent;
67
+ _context.next = 14;
61
68
  break;
62
- case 9:
63
- _context.prev = 9;
64
- _context.t0 = _context["catch"](2);
69
+ case 11:
70
+ _context.prev = 11;
71
+ _context.t0 = _context["catch"](1);
65
72
  console.error('failed to get admin portal metadata', _context.t0);
66
- case 12:
73
+ case 14:
67
74
  Metadata.set(_this.options.metadata, _this.name);
68
- case 13:
75
+ case 15:
69
76
  case "end":
70
77
  return _context.stop();
71
78
  }
72
- }, _callee, null, [[2, 9]]);
79
+ }, _callee, null, [[1, 11]]);
73
80
  }));
74
81
  this.requestAuthorize = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
75
82
  var _this$options$authOpt, _this$options$authOpt2;
@@ -79,14 +86,16 @@ export var FronteggApp = /*#__PURE__*/function () {
79
86
  case 0:
80
87
  shouldRequestHostedLoginAuthorize = (_this$options$authOpt = _this.options.authOptions) == null ? void 0 : (_this$options$authOpt2 = _this$options$authOpt.hostedLoginOptions) == null ? void 0 : _this$options$authOpt2.loadUserOnFirstLoad;
81
88
  if (!_this.options.builderMode && _this.options.framework !== 'nextjs') {
82
- if (_this.options.hostedLoginBox && !_this.options.customLoginBox && shouldRequestHostedLoginAuthorize) {
83
- _this.store.dispatch({
84
- type: 'auth/requestHostedLoginAuthorizeV2',
85
- payload: {
86
- shouldRedirectToLogin: false,
87
- firstTime: true
88
- }
89
- });
89
+ if (_this.options.hostedLoginBox && !_this.options.customLoginBox) {
90
+ if (shouldRequestHostedLoginAuthorize) {
91
+ _this.store.dispatch({
92
+ type: 'auth/requestHostedLoginAuthorizeV2',
93
+ payload: {
94
+ shouldRedirectToLogin: false,
95
+ firstTime: true
96
+ }
97
+ });
98
+ }
90
99
  } else {
91
100
  _this.store.dispatch({
92
101
  type: 'auth/requestAuthorize',
@@ -115,7 +124,7 @@ export var FronteggApp = /*#__PURE__*/function () {
115
124
  case 4:
116
125
  _context3.prev = 4;
117
126
  _context3.next = 7;
118
- return FronteggRestApi.loadFeatureFlags();
127
+ return _this.apiClient.featureFlags.loadFeatureFlags();
119
128
  case 7:
120
129
  flags = _context3.sent;
121
130
  if (_this.options.overrideFeatureFlags) {
@@ -135,7 +144,10 @@ export var FronteggApp = /*#__PURE__*/function () {
135
144
  }, _callee3, null, [[4, 12]]);
136
145
  }));
137
146
  this.setFeatureFlagsForPreview = function (previewFeatureFlags) {
138
- FronteggRestApi.FeatureFlags.set(_extends({}, mockFlagsList, previewFeatureFlags), _this.name);
147
+ FronteggRestApi.FeatureFlags.set(Object.assign({}, mockFlagsList, previewFeatureFlags), _this.name);
148
+ };
149
+ this.queryFeatureFlags = function (flags) {
150
+ return FronteggRestApi.FeatureFlags.getFeatureFlags(flags, _this.name);
139
151
  };
140
152
  this.updateLocalizationsSetter = function (localizationUpdateFn) {
141
153
  _this.updateLocalizations = localizationUpdateFn;
@@ -144,24 +156,42 @@ export var FronteggApp = /*#__PURE__*/function () {
144
156
  var _this$store$getState$;
145
157
  return (_this$store$getState$ = _this.store.getState().auth.user) == null ? void 0 : _this$store$getState$.entitlements;
146
158
  };
159
+ this.getUserFromStore = function () {
160
+ return _this.store.getState().auth.user;
161
+ };
162
+ this.getEntitlementsQueryData = function (customAttributes) {
163
+ var user = _this.getUserFromStore();
164
+ var entitlements = _this.getEntitlementsFromStore();
165
+ var attributes = {
166
+ custom: customAttributes,
167
+ jwt: user
168
+ };
169
+ return {
170
+ entitlements: entitlements,
171
+ attributes: attributes
172
+ };
173
+ };
147
174
  var appName = formatName(name);
148
175
  var customElementName = "frontegg-app-".concat(appName);
149
176
  this.iframeRendering = iframeRendering;
150
177
  this.name = appName;
151
- this.options = _extends({}, _options, {
152
- contextOptions: _extends({
178
+ this.options = Object.assign({}, _options, {
179
+ contextOptions: Object.assign({
153
180
  requestCredentials: 'include'
154
181
  }, _options.contextOptions)
155
182
  });
183
+ this.fetchClient = new FetchClient(this.name);
184
+ this.apiClient = createApiClient(this.name);
156
185
  if (this.options.cdnUrl) {
157
186
  this.cdnUrl = this.options.cdnUrl;
158
187
  }
159
188
  this.customElementName = customElementName;
160
- var authOptions = this.options.authOptions ? _extends({}, this.options.authOptions, {
189
+ var authOptions = this.options.authOptions ? Object.assign({}, this.options.authOptions, {
161
190
  hostedLoginBox: this.options.hostedLoginBox
162
191
  }) : {
163
192
  hostedLoginBox: this.options.hostedLoginBox
164
193
  };
194
+ authOptions.onRedirectTo = _options.onRedirectTo;
165
195
  authOptions.disableSilentRefresh = (_this$options$authOpt3 = this.options.authOptions) == null ? void 0 : _this$options$authOpt3.disableSilentRefresh;
166
196
  if (this.options.store) {
167
197
  this.store = this.options.store;
@@ -170,19 +200,32 @@ export var FronteggApp = /*#__PURE__*/function () {
170
200
  }
171
201
  } else {
172
202
  var _this$options$authOpt4, _this$options$auditsO;
173
- this.store = createFronteggStore({
203
+ this.store = createStore({
174
204
  context: this.options.contextOptions,
175
- appName: this.name
176
- }, this, this.options.previewMode, authOptions, {
177
- auth: (_this$options$authOpt4 = this.options.authOptions) != null ? _this$options$authOpt4 : {},
178
- audits: (_this$options$auditsO = this.options.auditsOptions) != null ? _this$options$auditsO : {}
179
- }, false, this.options.urlStrategy);
205
+ name: this.name,
206
+ builderMode: this.options.builderMode,
207
+ previewMode: this.options.previewMode,
208
+ storeHolder: this,
209
+ urlStrategy: this.options.urlStrategy,
210
+ initialState: {
211
+ auth: Object.assign({}, authOptions, (_this$options$authOpt4 = this.options.authOptions) != null ? _this$options$authOpt4 : {}),
212
+ auditLogs: Object.assign({}, (_this$options$auditsO = this.options.auditsOptions) != null ? _this$options$auditsO : {})
213
+ }
214
+ });
180
215
  }
181
216
  AppHolder.setInstance(appName, this);
217
+ var contextHolder = ContextHolder["for"](appName);
218
+ contextHolder.setAppName(appName);
182
219
  this.setEntitlementsOptions(_options.entitlementsOptions);
220
+ this.setSessionContext({
221
+ enableSessionPerTenant: (_options$authOptions = _options.authOptions) == null ? void 0 : _options$authOptions.enableSessionPerTenant
222
+ });
183
223
 
184
- // for feature flags (for entitlements)
185
- ContextHolder.setAppName(appName);
224
+ // pay attention: basename is used from the router base name, then if it's empty it will be the frontegg options basename
225
+ var basename = _options.basename;
226
+ if (basename) {
227
+ contextHolder.setBasename(basename);
228
+ }
186
229
  }
187
230
 
188
231
  /**
@@ -192,7 +235,12 @@ export var FronteggApp = /*#__PURE__*/function () {
192
235
  _createClass(FronteggApp, [{
193
236
  key: "setEntitlementsOptions",
194
237
  value: function setEntitlementsOptions(entitlementsOptions) {
195
- ContextHolder.setEntitlementsOptions(_extends({}, entitlementsOptions));
238
+ ContextHolder["for"](this.name).setEntitlementsOptions(Object.assign({}, entitlementsOptions));
239
+ }
240
+ }, {
241
+ key: "setSessionContext",
242
+ value: function setSessionContext(sessionContext) {
243
+ ContextHolder["for"](this.name).setSessionContext(Object.assign({}, sessionContext));
196
244
  }
197
245
  }, {
198
246
  key: "initContainers",
@@ -270,6 +318,7 @@ export var FronteggApp = /*#__PURE__*/function () {
270
318
  }, {
271
319
  key: "loginWithRedirect",
272
320
  value: function loginWithRedirect() {
321
+ var additionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
273
322
  this.store.dispatch({
274
323
  type: 'auth/setState',
275
324
  payload: {
@@ -277,7 +326,8 @@ export var FronteggApp = /*#__PURE__*/function () {
277
326
  }
278
327
  });
279
328
  this.store.dispatch({
280
- type: 'auth/requestHostedLoginAuthorize'
329
+ type: 'auth/requestHostedLoginAuthorize',
330
+ payload: additionalParams
281
331
  });
282
332
  }
283
333
  }, {
@@ -318,7 +368,9 @@ export var FronteggApp = /*#__PURE__*/function () {
318
368
  if (window["".concat(component, "Init")]) {
319
369
  resolve(window["".concat(component, "Init")]({
320
370
  FronteggRestApi: FronteggRestApi,
321
- FronteggTypes: FronteggTypes
371
+ FronteggTypes: FronteggTypes,
372
+ FronteggReduxStore: FronteggReduxStore,
373
+ ValtioVanilla: ValtioVanilla
322
374
  }));
323
375
  } else {
324
376
  resolve(window[component]);
@@ -371,31 +423,54 @@ export var FronteggApp = /*#__PURE__*/function () {
371
423
  }, {
372
424
  key: "showAdminPortal",
373
425
  value: function () {
374
- var _showAdminPortal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
375
- var FronteggAdminPortal;
426
+ var _showAdminPortal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(options) {
427
+ var _ref4, isMultiApp, _this$queryFeatureFla, _this$queryFeatureFla2, multiAppsFlag, FronteggAdminPortal;
376
428
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
377
429
  while (1) switch (_context6.prev = _context6.next) {
378
430
  case 0:
379
- FronteggRestApi.ContextHolder.setRequestSource(RequestSource.AdminPortal);
380
- _context6.next = 3;
431
+ _ref4 = options != null ? options : {
432
+ isMultiApp: false
433
+ }, isMultiApp = _ref4.isMultiApp;
434
+ _this$queryFeatureFla = this.queryFeatureFlags(['multi-apps-admin-portal']), _this$queryFeatureFla2 = _slicedToArray(_this$queryFeatureFla, 1), multiAppsFlag = _this$queryFeatureFla2[0];
435
+ ContextHolder["for"](this.name).setRequestSource(RequestSource.AdminPortal);
436
+ _context6.next = 5;
381
437
  return this.loadScript('FronteggAdminPortal');
382
- case 3:
438
+ case 5:
383
439
  FronteggAdminPortal = _context6.sent;
384
440
  this.adminPortalRenderer = FronteggAdminPortal.render(this.adminPortalEl, {
385
441
  injector: this,
386
- options: this.options
442
+ options: Object.assign({
443
+ isMultiApp: multiAppsFlag && isMultiApp
444
+ }, this.options)
387
445
  });
388
- case 5:
446
+ case 7:
389
447
  case "end":
390
448
  return _context6.stop();
391
449
  }
392
450
  }, _callee6, this);
393
451
  }));
394
- function showAdminPortal() {
452
+ function showAdminPortal(_x2) {
395
453
  return _showAdminPortal.apply(this, arguments);
396
454
  }
397
455
  return showAdminPortal;
398
456
  }()
457
+ /**
458
+ * Open the hosted portal must be called synchronously with user interaction
459
+ *
460
+ * @param newTab - open the portal in a new tab = true
461
+ */
462
+ }, {
463
+ key: "openHostedAdminPortal",
464
+ value: function openHostedAdminPortal() {
465
+ var newTab = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
466
+ var baseUrl = this.options.contextOptions.baseUrl;
467
+ var hostedPortalUrl = "".concat(baseUrl, "/oauth/portal");
468
+ if (newTab) {
469
+ window.open(hostedPortalUrl, '_blank');
470
+ return;
471
+ }
472
+ window.location.href = hostedPortalUrl;
473
+ }
399
474
  }, {
400
475
  key: "hideAdminPortal",
401
476
  value: function hideAdminPortal() {
@@ -405,7 +480,7 @@ export var FronteggApp = /*#__PURE__*/function () {
405
480
  (_this$adminPortalRend = this.adminPortalRenderer) == null ? void 0 : _this$adminPortalRend.unmount();
406
481
  // unmount is removing url search params, therefore we need to restore them after unmount
407
482
  restoreSearchParams(searchParams);
408
- FronteggRestApi.ContextHolder.setRequestSource(null);
483
+ ContextHolder["for"](this.name).setRequestSource(null);
409
484
  } catch (e) {
410
485
  console.error('Failed to unmount admin portal', e);
411
486
  }
@@ -422,7 +497,7 @@ export var FronteggApp = /*#__PURE__*/function () {
422
497
  return this.loadScript('FronteggAdminPortal');
423
498
  case 2:
424
499
  FronteggAdminPortal = _context7.sent;
425
- this.checkoutDialogRenderer = FronteggAdminPortal.renderCheckoutDialog(this.checkoutDialogEl, _extends({
500
+ this.checkoutDialogRenderer = FronteggAdminPortal.renderCheckoutDialog(this.checkoutDialogEl, Object.assign({
426
501
  injector: this
427
502
  }, opts, {
428
503
  options: this.options
@@ -433,7 +508,7 @@ export var FronteggApp = /*#__PURE__*/function () {
433
508
  }
434
509
  }, _callee7, this);
435
510
  }));
436
- function showCheckoutDialog(_x2) {
511
+ function showCheckoutDialog(_x3) {
437
512
  return _showCheckoutDialog.apply(this, arguments);
438
513
  }
439
514
  return showCheckoutDialog;
@@ -456,40 +531,47 @@ export var FronteggApp = /*#__PURE__*/function () {
456
531
  key: "getFeatureEntitlements",
457
532
  value:
458
533
  /**
459
- @param key
534
+ @param key feature key
535
+ @param customAttributes user attributes
460
536
  @returns if the user is entitled to the given feature. Attaching the justification if not
461
537
  @throws when entitlement is not enabled via frontegg options
462
538
  */
463
- function getFeatureEntitlements(key) {
464
- var entitlements = this.getEntitlementsFromStore();
465
- return _getFeatureEntitlements(entitlements, key);
539
+ function getFeatureEntitlements(key, customAttributes) {
540
+ var _this$getEntitlements = this.getEntitlementsQueryData(customAttributes),
541
+ entitlements = _this$getEntitlements.entitlements,
542
+ attributes = _this$getEntitlements.attributes;
543
+ return _getFeatureEntitlements(entitlements, key, attributes);
466
544
  }
467
545
 
468
546
  /**
469
- @param key
547
+ @param key permission key
548
+ @param customAttributes user attributes
470
549
  @returns if the user is entitled to the given permission. Attaching the justification if not
471
550
  @throws when entitlement is not enabled via frontegg options
472
551
  */
473
552
  }, {
474
553
  key: "getPermissionEntitlements",
475
- value: function getPermissionEntitlements(key) {
476
- var entitlements = this.getEntitlementsFromStore();
477
- return _getPermissionEntitlements(entitlements, key);
554
+ value: function getPermissionEntitlements(key, customAttributes) {
555
+ var _this$getEntitlements2 = this.getEntitlementsQueryData(customAttributes),
556
+ entitlements = _this$getEntitlements2.entitlements,
557
+ attributes = _this$getEntitlements2.attributes;
558
+ return _getPermissionEntitlements(entitlements, key, attributes);
478
559
  }
479
560
 
480
561
  /**
481
562
  @param options - including permission or feature key
563
+ @param customAttributes user attributes
482
564
  @returns if the user is entitled to the given permission or feature. Attaching the justification if not
483
565
  @throws when entitlement is not enabled via frontegg options
484
566
  */
485
567
  }, {
486
568
  key: "getEntitlements",
487
- value: function getEntitlements(options) {
569
+ value: function getEntitlements(options, customAttributes) {
488
570
  // we use permissionKey (options key) to decide if the user is using permission key or feature key
489
571
  if ('permissionKey' in options) {
490
- return this.getPermissionEntitlements(options.permissionKey);
572
+ return this.getPermissionEntitlements(options.permissionKey, customAttributes);
491
573
  }
492
- return this.getFeatureEntitlements(options.featureKey);
574
+ return this.getFeatureEntitlements(options.featureKey, customAttributes);
493
575
  }
494
576
 
495
577
  /**
@@ -506,6 +588,55 @@ export var FronteggApp = /*#__PURE__*/function () {
506
588
  }
507
589
  });
508
590
  }
591
+
592
+ /**
593
+ * Redirects to the step up page with the max age param and set the redirect url in the local storage
594
+ * @param options.maxAge optional max age
595
+ */
596
+ }, {
597
+ key: "stepUp",
598
+ value: function stepUp(options) {
599
+ var state = this.store.getState();
600
+ var _ref5 = (state == null ? void 0 : state.auth) || {},
601
+ hostedLoginBox = _ref5.hostedLoginBox,
602
+ stepUpUrl = _ref5.routes.stepUpUrl;
603
+ if (hostedLoginBox) {
604
+ this.store.dispatch({
605
+ type: 'auth/stepUpHostedLogin',
606
+ payload: options
607
+ });
608
+ return;
609
+ }
610
+ redirectByStepUpUrl(stepUpUrl, state.auth.onRedirectTo, options == null ? void 0 : options.maxAge);
611
+ }
612
+
613
+ /**
614
+ * @param options.maxAge optional max age
615
+ * @return true when user is stepped up, false otherwise
616
+ */
617
+ }, {
618
+ key: "isSteppedUp",
619
+ value: function isSteppedUp() {
620
+ var _this$store$getState;
621
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
622
+ var _ref6 = ((_this$store$getState = this.store.getState()) == null ? void 0 : _this$store$getState.auth) || {},
623
+ user = _ref6.user;
624
+ return _isSteppedUp(user, options);
625
+ }
626
+
627
+ /**
628
+ * Switch tenant
629
+ * @param payload.tenantId tenant id to switch for
630
+ * @param payload.callback optional callback to be called with true / false for success / failure tenant switching operation
631
+ */
632
+ }, {
633
+ key: "switchTenant",
634
+ value: function switchTenant(payload) {
635
+ this.store.dispatch({
636
+ type: 'auth/switchTenant',
637
+ payload: payload
638
+ });
639
+ }
509
640
  }, {
510
641
  key: "close",
511
642
  value: function close() {
@@ -1 +1,2 @@
1
1
  export * from './FronteggApp';
2
+ export { getOverriddenMetadata } from './utils';
@@ -1 +1,2 @@
1
- export * from './FronteggApp';
1
+ export * from './FronteggApp';
2
+ export { getOverriddenMetadata } from './utils';