@frontegg/js 6.10.1 → 6.12.0

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,8 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
5
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
2
6
  import { createFronteggStore } from '@frontegg/redux-store';
3
7
  import { Metadata } from '@frontegg/types';
4
8
  import { formatName } from '../utils';
@@ -7,15 +11,23 @@ import { fetch as FronteggFetch } from '@frontegg/rest-api';
7
11
  import * as FronteggRestApi from '@frontegg/rest-api';
8
12
  import * as FronteggTypes from '@frontegg/types';
9
13
  import versions from '../version';
10
- export class FronteggApp {
11
- constructor(_options, name, iframeRendering = false) {
12
- var _this$options$authOpt, _this$options$store, _this$options$authOpt2, _this$options$auditsO;
14
+ export var FronteggApp = /*#__PURE__*/function () {
15
+ function FronteggApp(_options, name) {
16
+ var _this = this,
17
+ _this$options$authOpt,
18
+ _this$options$store,
19
+ _this$options$authOpt2,
20
+ _this$options$auditsO;
21
+
22
+ var iframeRendering = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
23
+
24
+ _classCallCheck(this, FronteggApp);
13
25
 
14
26
  this.name = void 0;
15
27
  this.iframeRendering = void 0;
16
28
  this.options = void 0;
17
29
  this.loading = true;
18
- this.cdnUrl = `https://assets.frontegg.com/admin-box/${versions.cdnVersion}`;
30
+ this.cdnUrl = "https://assets.frontegg.com/admin-box/".concat(versions.cdnVersion);
19
31
  this.customElementName = '';
20
32
  this.adminPortalEl = void 0;
21
33
  this.adminPortalRenderer = void 0;
@@ -30,51 +42,99 @@ export class FronteggApp {
30
42
  this.flags = {};
31
43
  this.loadingListeners = [];
32
44
  this.updateLocalizations = void 0;
33
-
34
- this.loadAdminBoxMetadata = async () => {
35
- const {
36
- Get
37
- } = FronteggFetch;
38
-
39
- if (!this.options.metadata) {
40
- try {
41
- var _data$rows$0$configur, _data$rows, _data$rows$;
42
-
43
- const data = await Get(`/metadata`, {
44
- entityName: 'adminBox'
45
- });
46
- 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 : {};
47
- } catch (e) {
48
- console.error('failed to get admin portal metadata', e);
45
+ this.loadAdminBoxMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
46
+ var Get, _data$rows$0$configur, _data$rows, _data$rows$, data;
47
+
48
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
49
+ while (1) {
50
+ switch (_context.prev = _context.next) {
51
+ case 0:
52
+ Get = FronteggFetch.Get;
53
+
54
+ if (_this.options.metadata) {
55
+ _context.next = 12;
56
+ break;
57
+ }
58
+
59
+ _context.prev = 2;
60
+ _context.next = 5;
61
+ return Get("/metadata", {
62
+ entityName: 'adminBox'
63
+ });
64
+
65
+ case 5:
66
+ data = _context.sent;
67
+ _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 : {};
68
+ _context.next = 12;
69
+ break;
70
+
71
+ case 9:
72
+ _context.prev = 9;
73
+ _context.t0 = _context["catch"](2);
74
+ console.error('failed to get admin portal metadata', _context.t0);
75
+
76
+ case 12:
77
+ Metadata.set(_this.options.metadata, _this.name);
78
+
79
+ case 13:
80
+ case "end":
81
+ return _context.stop();
82
+ }
49
83
  }
50
- }
51
-
52
- Metadata.set(this.options.metadata, this.name);
53
- };
54
-
55
- this.requestAuthorize = async () => {
56
- if (!this.options.hostedLoginBox && !this.options.builderMode && this.options.framework !== 'nextjs') {
57
- this.store.dispatch({
58
- type: 'auth/requestAuthorize',
59
- payload: true
60
- });
61
- }
62
- };
63
-
64
- this.loadFeatureFlags = async () => {
65
- try {
66
- this.flags = await FronteggRestApi.loadFeatureFlags();
67
- } catch (e) {
68
- console.error('failed to get admin portal feature flags', e);
69
- }
70
- };
84
+ }, _callee, null, [[2, 9]]);
85
+ }));
86
+ this.requestAuthorize = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
87
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
88
+ while (1) {
89
+ switch (_context2.prev = _context2.next) {
90
+ case 0:
91
+ if (!_this.options.hostedLoginBox && !_this.options.builderMode && _this.options.framework !== 'nextjs') {
92
+ _this.store.dispatch({
93
+ type: 'auth/requestAuthorize',
94
+ payload: true
95
+ });
96
+ }
97
+
98
+ case 1:
99
+ case "end":
100
+ return _context2.stop();
101
+ }
102
+ }
103
+ }, _callee2);
104
+ }));
105
+ this.loadFeatureFlags = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
106
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
107
+ while (1) {
108
+ switch (_context3.prev = _context3.next) {
109
+ case 0:
110
+ _context3.prev = 0;
111
+ _context3.next = 3;
112
+ return FronteggRestApi.loadFeatureFlags();
113
+
114
+ case 3:
115
+ _this.flags = _context3.sent;
116
+ _context3.next = 9;
117
+ break;
118
+
119
+ case 6:
120
+ _context3.prev = 6;
121
+ _context3.t0 = _context3["catch"](0);
122
+ console.error('failed to get admin portal feature flags', _context3.t0);
123
+
124
+ case 9:
125
+ case "end":
126
+ return _context3.stop();
127
+ }
128
+ }
129
+ }, _callee3, null, [[0, 6]]);
130
+ }));
71
131
 
72
- this.updateLocalizationsSetter = localizationUpdateFn => {
73
- this.updateLocalizations = localizationUpdateFn;
132
+ this.updateLocalizationsSetter = function (localizationUpdateFn) {
133
+ _this.updateLocalizations = localizationUpdateFn;
74
134
  };
75
135
 
76
- let appName = formatName(name);
77
- let customElementName = `frontegg-app-${appName}`;
136
+ var appName = formatName(name);
137
+ var customElementName = "frontegg-app-".concat(appName);
78
138
  this.iframeRendering = iframeRendering;
79
139
  this.name = appName;
80
140
  this.options = _extends({}, _options, {
@@ -88,7 +148,7 @@ export class FronteggApp {
88
148
  }
89
149
 
90
150
  this.customElementName = customElementName;
91
- const authOptions = this.options.authOptions ? _extends({}, this.options.authOptions, {
151
+ var authOptions = this.options.authOptions ? _extends({}, this.options.authOptions, {
92
152
  hostedLoginBox: this.options.hostedLoginBox
93
153
  }) : {
94
154
  hostedLoginBox: this.options.hostedLoginBox
@@ -103,140 +163,270 @@ export class FronteggApp {
103
163
  AppHolder.setInstance(appName, this);
104
164
  }
105
165
 
106
- async initContainers(elements) {
107
- this.adminPortalEl = elements.adminPortalEl;
108
- this.loginBoxEl = elements.loginBoxEl;
109
- this.checkoutDialogEl = elements.checkoutDialogEl;
110
- this.adminPortalContainer = elements.adminPortalContainer;
111
- this.loginBoxContainer = elements.loginBoxContainer;
112
- this.checkoutDialogContainer = elements.checkoutDialogContainer;
113
-
114
- try {
115
- document.body.classList.add('frontegg-loading');
116
- } catch (e) {}
117
-
118
- await Promise.all([this.loadAdminBoxMetadata(), this.requestAuthorize(), this.loadFeatureFlags()]);
119
-
120
- if (!this.options.previewMode && !this.options.customLoginBox) {
121
- this.loadLoginBox();
122
- }
123
-
124
- this.loadScript('FronteggAdminPortal');
125
- }
166
+ _createClass(FronteggApp, [{
167
+ key: "initContainers",
168
+ value: function () {
169
+ var _initContainers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(elements) {
170
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
171
+ while (1) {
172
+ switch (_context4.prev = _context4.next) {
173
+ case 0:
174
+ this.adminPortalEl = elements.adminPortalEl;
175
+ this.loginBoxEl = elements.loginBoxEl;
176
+ this.checkoutDialogEl = elements.checkoutDialogEl;
177
+ this.adminPortalContainer = elements.adminPortalContainer;
178
+ this.loginBoxContainer = elements.loginBoxContainer;
179
+ this.checkoutDialogContainer = elements.checkoutDialogContainer;
180
+
181
+ try {
182
+ document.body.classList.add('frontegg-loading');
183
+ } catch (e) {}
184
+
185
+ _context4.next = 9;
186
+ return Promise.all([this.loadAdminBoxMetadata(), this.requestAuthorize(), this.loadFeatureFlags()]);
187
+
188
+ case 9:
189
+ if (!this.options.previewMode && !this.options.customLoginBox) {
190
+ this.loadLoginBox();
191
+ }
192
+
193
+ this.loadScript('FronteggAdminPortal');
194
+
195
+ case 11:
196
+ case "end":
197
+ return _context4.stop();
198
+ }
199
+ }
200
+ }, _callee4, this);
201
+ }));
202
+
203
+ function initContainers(_x) {
204
+ return _initContainers.apply(this, arguments);
205
+ }
126
206
 
127
- updateMetadata(metadata) {
128
- Metadata.set(metadata, this.name);
207
+ return initContainers;
208
+ }()
209
+ }, {
210
+ key: "updateMetadata",
211
+ value: function updateMetadata(metadata) {
212
+ Metadata.set(metadata, this.name);
129
213
 
130
- if (metadata != null && metadata.localizations) {
131
- var _this$updateLocalizat;
214
+ if (metadata != null && metadata.localizations) {
215
+ var _this$updateLocalizat;
132
216
 
133
- (_this$updateLocalizat = this.updateLocalizations) == null ? void 0 : _this$updateLocalizat.call(this, metadata.localizations);
217
+ (_this$updateLocalizat = this.updateLocalizations) == null ? void 0 : _this$updateLocalizat.call(this, metadata.localizations);
218
+ }
134
219
  }
135
- }
220
+ }, {
221
+ key: "addOnLoadedListener",
222
+ value: function addOnLoadedListener(listener) {
223
+ if (!this.loading) {
224
+ listener();
225
+ return;
226
+ }
136
227
 
137
- addOnLoadedListener(listener) {
138
- if (!this.loading) {
139
- listener();
140
- return;
228
+ this.loadingListeners.push(listener);
141
229
  }
142
-
143
- this.loadingListeners.push(listener);
144
- }
145
-
146
- loadScript(component) {
147
- return new Promise((resolve, reject) => {
148
- // TODO: prevent this behavior if development
149
- if (window[component]) {
150
- resolve(window[component]);
151
- return;
230
+ }, {
231
+ key: "ready",
232
+ value: function ready(listener) {
233
+ if (this.loading) {
234
+ listener();
235
+ } else {
236
+ this.addOnLoadedListener(listener);
152
237
  }
153
-
154
-
155
-
156
- const entries = {
157
- FronteggLoginBox: 'login-box/index.js',
158
- FronteggAdminPortal: 'admin-portal/index.js'
159
- };
160
- const script = document.createElement('script');
161
- script.src = `${this.cdnUrl}/${entries[component]}`;
162
- script.setAttribute('id', `${component}Script`);
163
- script.setAttribute('cdn-url', this.cdnUrl);
164
-
165
- script.onload = () => {
166
- if (window[`${component}Init`]) {
167
- resolve(window[`${component}Init`]({
168
- FronteggRestApi,
169
- FronteggTypes
170
- }));
171
- } else {
238
+ }
239
+ }, {
240
+ key: "loginWithRedirect",
241
+ value: function loginWithRedirect() {
242
+ this.store.dispatch({
243
+ type: 'auth/setState',
244
+ payload: {
245
+ isLoading: true
246
+ }
247
+ });
248
+ this.store.dispatch({
249
+ type: 'auth/requestHostedLoginAuthorize'
250
+ });
251
+ }
252
+ }, {
253
+ key: "loadScript",
254
+ value: function loadScript(component) {
255
+ var _this2 = this;
256
+
257
+ return new Promise(function (resolve, reject) {
258
+ // TODO: prevent this behavior if development
259
+ if (window[component]) {
172
260
  resolve(window[component]);
261
+ return;
173
262
  }
174
- };
175
-
176
- script.onerror = e => {
177
- console.log('Profile page error', e);
178
- reject(e);
179
- };
263
+
264
+
265
+
266
+ var entries = {
267
+ FronteggLoginBox: 'login-box/index.js',
268
+ FronteggAdminPortal: 'admin-portal/index.js'
269
+ };
270
+ var script = document.createElement('script');
271
+ script.src = "".concat(_this2.cdnUrl, "/").concat(entries[component]);
272
+ script.setAttribute('id', "".concat(component, "Script"));
273
+ script.setAttribute('cdn-url', _this2.cdnUrl);
274
+
275
+ script.onload = function () {
276
+ if (window["".concat(component, "Init")]) {
277
+ resolve(window["".concat(component, "Init")]({
278
+ FronteggRestApi: FronteggRestApi,
279
+ FronteggTypes: FronteggTypes
280
+ }));
281
+ } else {
282
+ resolve(window[component]);
283
+ }
284
+ };
285
+
286
+ script.onerror = function (e) {
287
+ console.log('Profile page error', e);
288
+ reject(e);
289
+ };
290
+
291
+ document.body.append(script);
292
+ });
293
+ }
294
+ }, {
295
+ key: "loadLoginBox",
296
+ value: function () {
297
+ var _loadLoginBox = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
298
+ var FronteggLoginBox;
299
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
300
+ while (1) {
301
+ switch (_context5.prev = _context5.next) {
302
+ case 0:
303
+ _context5.next = 2;
304
+ return this.loadScript('FronteggLoginBox');
305
+
306
+ case 2:
307
+ FronteggLoginBox = _context5.sent;
308
+ FronteggLoginBox.render(this.loginBoxEl, {
309
+ injector: this,
310
+ options: this.options
311
+ });
312
+ this.loading = false;
313
+ this.loadingListeners.forEach(function (listener) {
314
+ try {
315
+ listener();
316
+ } catch (e) {}
317
+ });
318
+ this.loadingListeners = [];
319
+
320
+ case 7:
321
+ case "end":
322
+ return _context5.stop();
323
+ }
324
+ }
325
+ }, _callee5, this);
326
+ }));
327
+
328
+ function loadLoginBox() {
329
+ return _loadLoginBox.apply(this, arguments);
330
+ }
180
331
 
181
- document.body.append(script);
182
- });
183
- }
332
+ return loadLoginBox;
333
+ }()
334
+ }, {
335
+ key: "showAdminPortal",
336
+ value: function () {
337
+ var _showAdminPortal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
338
+ var FronteggAdminPortal;
339
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
340
+ while (1) {
341
+ switch (_context6.prev = _context6.next) {
342
+ case 0:
343
+ _context6.next = 2;
344
+ return this.loadScript('FronteggAdminPortal');
345
+
346
+ case 2:
347
+ FronteggAdminPortal = _context6.sent;
348
+ this.adminPortalRenderer = FronteggAdminPortal.render(this.adminPortalEl, {
349
+ injector: this,
350
+ options: this.options
351
+ });
352
+
353
+ case 4:
354
+ case "end":
355
+ return _context6.stop();
356
+ }
357
+ }
358
+ }, _callee6, this);
359
+ }));
360
+
361
+ function showAdminPortal() {
362
+ return _showAdminPortal.apply(this, arguments);
363
+ }
184
364
 
185
- async loadLoginBox() {
186
- const FronteggLoginBox = await this.loadScript('FronteggLoginBox');
187
- FronteggLoginBox.render(this.loginBoxEl, {
188
- injector: this,
189
- options: this.options
190
- });
191
- this.loading = false;
192
- this.loadingListeners.forEach(listener => {
365
+ return showAdminPortal;
366
+ }()
367
+ }, {
368
+ key: "hideAdminPortal",
369
+ value: function hideAdminPortal() {
193
370
  try {
194
- listener();
195
- } catch (e) {}
196
- });
197
- this.loadingListeners = [];
198
- }
199
-
200
- async showAdminPortal() {
201
- const FronteggAdminPortal = await this.loadScript('FronteggAdminPortal');
202
- this.adminPortalRenderer = FronteggAdminPortal.render(this.adminPortalEl, {
203
- injector: this,
204
- options: this.options
205
- });
206
- }
207
-
208
- hideAdminPortal() {
209
- try {
210
- var _this$adminPortalRend;
371
+ var _this$adminPortalRend;
211
372
 
212
- (_this$adminPortalRend = this.adminPortalRenderer) == null ? void 0 : _this$adminPortalRend.unmount();
213
- } catch (e) {
214
- console.error('Failed to unmount admin portal', e);
373
+ (_this$adminPortalRend = this.adminPortalRenderer) == null ? void 0 : _this$adminPortalRend.unmount();
374
+ } catch (e) {
375
+ console.error('Failed to unmount admin portal', e);
376
+ }
215
377
  }
216
- }
217
-
218
- async showCheckoutDialog(opts) {
219
- const FronteggAdminPortal = await this.loadScript('FronteggAdminPortal');
220
- this.checkoutDialogRenderer = FronteggAdminPortal.renderCheckoutDialog(this.checkoutDialogEl, _extends({
221
- injector: this
222
- }, opts, {
223
- options: this.options
224
- }));
225
- }
378
+ }, {
379
+ key: "showCheckoutDialog",
380
+ value: function () {
381
+ var _showCheckoutDialog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(opts) {
382
+ var FronteggAdminPortal;
383
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
384
+ while (1) {
385
+ switch (_context7.prev = _context7.next) {
386
+ case 0:
387
+ _context7.next = 2;
388
+ return this.loadScript('FronteggAdminPortal');
389
+
390
+ case 2:
391
+ FronteggAdminPortal = _context7.sent;
392
+ this.checkoutDialogRenderer = FronteggAdminPortal.renderCheckoutDialog(this.checkoutDialogEl, _extends({
393
+ injector: this
394
+ }, opts, {
395
+ options: this.options
396
+ }));
397
+
398
+ case 4:
399
+ case "end":
400
+ return _context7.stop();
401
+ }
402
+ }
403
+ }, _callee7, this);
404
+ }));
405
+
406
+ function showCheckoutDialog(_x2) {
407
+ return _showCheckoutDialog.apply(this, arguments);
408
+ }
226
409
 
227
- hideCheckoutDialog() {
228
- try {
229
- var _this$checkoutDialogR;
410
+ return showCheckoutDialog;
411
+ }()
412
+ }, {
413
+ key: "hideCheckoutDialog",
414
+ value: function hideCheckoutDialog() {
415
+ try {
416
+ var _this$checkoutDialogR;
230
417
 
231
- (_this$checkoutDialogR = this.checkoutDialogRenderer) == null ? void 0 : _this$checkoutDialogR.unmount();
232
- } catch (e) {
233
- console.error('Failed to unmount checkout dialog', e);
418
+ (_this$checkoutDialogR = this.checkoutDialogRenderer) == null ? void 0 : _this$checkoutDialogR.unmount();
419
+ } catch (e) {
420
+ console.error('Failed to unmount checkout dialog', e);
421
+ }
234
422
  }
235
- }
236
-
237
- close() {
238
- this.hideAdminPortal();
239
- this.hideCheckoutDialog();
240
- }
423
+ }, {
424
+ key: "close",
425
+ value: function close() {
426
+ this.hideAdminPortal();
427
+ this.hideCheckoutDialog();
428
+ }
429
+ }]);
241
430
 
242
- }
431
+ return FronteggApp;
432
+ }();
@@ -1,31 +1,42 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
2
4
  import { authActions } from '@frontegg/redux-store';
3
5
  import { AppHolder } from '../AppHolder';
4
6
  import { ContextHolder } from '@frontegg/rest-api';
5
- export class HostedLogin {
6
- static setAuthentication(isAuthenticated, accessToken, user, appName = 'default') {
7
- const app = AppHolder.getInstance(appName);
7
+ export var HostedLogin = /*#__PURE__*/function () {
8
+ function HostedLogin() {
9
+ _classCallCheck(this, HostedLogin);
10
+ }
11
+
12
+ _createClass(HostedLogin, null, [{
13
+ key: "setAuthentication",
14
+ value: function setAuthentication(isAuthenticated, accessToken, user) {
15
+ var appName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'default';
16
+ var app = AppHolder.getInstance(appName);
8
17
 
9
- if (isAuthenticated && accessToken) {
10
- ContextHolder.setAccessToken(accessToken);
11
- ContextHolder.setUser(_extends({}, user, {
12
- accessToken
13
- }));
14
- app.store.dispatch(authActions.setState({
15
- isLoading: false,
16
- isAuthenticated,
17
- user
18
- }));
19
- app.store.dispatch(authActions.loadTenants());
20
- } else {
21
- ContextHolder.setAccessToken(null);
22
- ContextHolder.setUser(null);
23
- app.store.dispatch(authActions.setState({
24
- isLoading: false,
25
- isAuthenticated: false,
26
- user: null
27
- }));
18
+ if (isAuthenticated && accessToken) {
19
+ ContextHolder.setAccessToken(accessToken);
20
+ ContextHolder.setUser(_extends({}, user, {
21
+ accessToken: accessToken
22
+ }));
23
+ app.store.dispatch(authActions.setState({
24
+ isLoading: false,
25
+ isAuthenticated: isAuthenticated,
26
+ user: user
27
+ }));
28
+ app.store.dispatch(authActions.loadTenants());
29
+ } else {
30
+ ContextHolder.setAccessToken(null);
31
+ ContextHolder.setUser(null);
32
+ app.store.dispatch(authActions.setState({
33
+ isLoading: false,
34
+ isAuthenticated: false,
35
+ user: null
36
+ }));
37
+ }
28
38
  }
29
- }
39
+ }]);
30
40
 
31
- }
41
+ return HostedLogin;
42
+ }();