@frontegg/react 6.0.1-alpha.0 → 6.0.1-alpha.1

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/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.0.1-alpha.0
1
+ /** @license Frontegg v6.0.1-alpha.1
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@frontegg/react",
3
- "version": "6.0.1-alpha.0",
3
+ "version": "6.0.1-alpha.1",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
7
7
  "@babel/runtime": "^7.17.2",
8
- "@frontegg/js": "6.0.1-alpha.0",
9
- "@frontegg/react-hooks": "6.0.1-alpha.0"
8
+ "@frontegg/js": "6.0.1-alpha.1",
9
+ "@frontegg/react-hooks": "6.0.1-alpha.1"
10
10
  },
11
11
  "peerDependencies": {
12
12
  "react": ">16.9.0",
@@ -15,6 +15,6 @@
15
15
  },
16
16
  "sideEffects": false,
17
17
  "private": false,
18
- "module": "./index.js",
18
+ "module": "./node/index.js",
19
19
  "types": "./index.d.ts"
20
20
  }
@@ -1,48 +0,0 @@
1
- import React from 'react';
2
- import { useAuthUserOrNull } from '@frontegg/react-hooks';
3
- import { Fragment as _Fragment } from "react/jsx-runtime";
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- export const AuthorizedContent = props => {
6
- let isAuthorized = true;
7
- const user = useAuthUserOrNull();
8
-
9
- if (!(user != null && user.superUser)) {
10
- if (props.requiredPermissions) {
11
- isAuthorized = false;
12
-
13
- for (const permission of props.requiredPermissions) {
14
- var _user$permissions;
15
-
16
- if (user != null && (_user$permissions = user.permissions) != null && _user$permissions.find(({
17
- key
18
- }) => key === permission)) {
19
- isAuthorized = true;
20
- }
21
- }
22
- }
23
-
24
- if (props.requiredRoles) {
25
- isAuthorized = false;
26
-
27
- for (const role of props.requiredRoles) {
28
- var _user$roles;
29
-
30
- if (user != null && (_user$roles = user.roles) != null && _user$roles.find(({
31
- key
32
- }) => key === role)) {
33
- isAuthorized = true;
34
- }
35
- }
36
- }
37
- }
38
-
39
- if (typeof props.render === 'function') {
40
- return _jsx(_Fragment, {
41
- children: props.render(isAuthorized)
42
- });
43
- }
44
-
45
- return isAuthorized ? _jsx(_Fragment, {
46
- children: props.children
47
- }) : null;
48
- };
package/CheckoutDialog.js DELETED
@@ -1,55 +0,0 @@
1
- import { useCallback, useMemo, useState } from 'react';
2
- import { CheckoutDialog } from '@frontegg/js';
3
- export const useCheckoutDialog = () => {
4
- const [{
5
- open,
6
- error,
7
- success
8
- }, setState] = useState({
9
- open: false,
10
- error: null,
11
- success: false
12
- });
13
- const handleError = useCallback(error => {
14
- setState({
15
- open: true,
16
- success: false,
17
- error
18
- });
19
- }, []);
20
- const handleSuccess = useCallback(() => {
21
- setState({
22
- open: false,
23
- success: true,
24
- error: null
25
- });
26
- }, []);
27
- const showDialog = useCallback(plan => {
28
- CheckoutDialog.show({
29
- plan,
30
- onClose: hideDialog,
31
- onError: handleError,
32
- onSuccess: handleSuccess
33
- });
34
- setState({
35
- open: true,
36
- success: false,
37
- error: null
38
- });
39
- }, []);
40
- const hideDialog = useCallback(() => {
41
- CheckoutDialog.hide();
42
- setState({
43
- open: false,
44
- error: null,
45
- success: false
46
- });
47
- }, []);
48
- return useMemo(() => ({
49
- open,
50
- showDialog,
51
- hideDialog,
52
- error,
53
- success
54
- }), [open, showDialog, hideDialog, error, success]);
55
- };
@@ -1,89 +0,0 @@
1
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
- import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["history", "appName"];
4
- import React, { useCallback, useMemo } from 'react';
5
- import { AppHolder, initialize } from '@frontegg/js';
6
- import { FronteggStoreProvider } from '@frontegg/react-hooks';
7
- import { BrowserRouter, useHistory } from './routerProxy';
8
- import { ContextHolder } from '@frontegg/rest-api';
9
- import { useQueryKeeper } from './queryKeeper';
10
- import { jsx as _jsx } from "react/jsx-runtime";
11
- export const ConnectorHistory = props => {
12
- const history = useHistory();
13
- return _jsx(Connector, _extends({
14
- history: history
15
- }, props));
16
- };
17
- export const Connector = _ref => {
18
- var _props$basename;
19
-
20
- let {
21
- history,
22
- appName
23
- } = _ref,
24
- props = _objectWithoutPropertiesLoose(_ref, _excluded);
25
-
26
- const isSSR = typeof window === 'undefined';
27
- const baseName = (_props$basename = props.basename) != null ? _props$basename : '';
28
- const onRedirectTo = useCallback((_path, opts) => {
29
- let path = _path;
30
-
31
- if (baseName && typeof baseName === 'string' && baseName.length > 0 && path.startsWith(baseName)) {
32
- path = path.substring(baseName.length);
33
- }
34
-
35
- if (opts != null && opts.preserveQueryParams) {
36
- path = `${path}${window.location.search}`;
37
- }
38
-
39
- if (opts != null && opts.refresh && !isSSR) {
40
- window.Cypress ? history.push(path) : window.location.href = path;
41
- } else {
42
- opts != null && opts.replace ? history.replace(path) : history.push(path);
43
- }
44
- }, []);
45
- const app = useMemo(() => {
46
- try {
47
- return AppHolder.getInstance(appName != null ? appName : 'default');
48
- } catch (e) {
49
- var _props$basename2;
50
-
51
- return initialize(_extends({}, props, {
52
- basename: (_props$basename2 = props.basename) != null ? _props$basename2 : baseName,
53
- contextOptions: _extends({
54
- requestCredentials: 'include'
55
- }, props.contextOptions),
56
- onRedirectTo
57
- }), appName != null ? appName : 'default');
58
- }
59
- }, []);
60
- ContextHolder.setOnRedirectTo(onRedirectTo);
61
- const signUpUrl = app.store.getState().auth.routes.signUpUrl;
62
- useQueryKeeper({
63
- routes: {
64
- signUpUrl
65
- },
66
- history
67
- });
68
- return _jsx(FronteggStoreProvider, _extends({}, _extends({}, props, {
69
- app
70
- })));
71
- };
72
- export const FronteggProvider = props => {
73
- const history = useHistory();
74
-
75
- if (props.history || history) {
76
- return _jsx(Connector, _extends({
77
- history: props.history || history
78
- }, props, {
79
- children: props.children
80
- }));
81
- }
82
-
83
- return _jsx(BrowserRouter, {
84
- basename: props.basename,
85
- children: _jsx(ConnectorHistory, _extends({}, props, {
86
- children: props.children
87
- }))
88
- });
89
- };
package/index.js DELETED
@@ -1,11 +0,0 @@
1
- /** @license Frontegg v6.0.1-alpha.0
2
- *
3
- * This source code is licensed under the MIT license found in the
4
- * LICENSE file in the root directory of this source tree.
5
- */
6
- export * from './FronteggProvider';
7
- export * from './AuthorizedContent';
8
- export * from './CheckoutDialog';
9
- export { AdminPortal, CheckoutDialog } from '@frontegg/js';
10
- export * from '@frontegg/react-hooks';
11
- export * from '@frontegg/types';
package/queryKeeper.js DELETED
@@ -1,36 +0,0 @@
1
- import { useEffect, useRef } from 'react';
2
- import { useLocation } from 'react-router-dom';
3
-
4
- const removeRedirectUrlFromQuery = query => {
5
- const q = new URLSearchParams(query);
6
- q.delete('redirectUrl');
7
- return q.toString();
8
- };
9
-
10
- export const useQueryKeeper = ({
11
- routes,
12
- history
13
- }) => {
14
- const queryParams = useRef();
15
- const prevPathname = useRef();
16
- const {
17
- pathname,
18
- search
19
- } = useLocation();
20
- useEffect(() => {
21
- if (!!search) {
22
- queryParams.current = search;
23
- prevPathname.current = pathname;
24
- }
25
- }, []);
26
- useEffect(() => {
27
- const shouldKeepQuery = !!Object.values(routes).find(route => route === prevPathname.current);
28
-
29
- if (!search && !!queryParams.current && shouldKeepQuery) {
30
- const query = removeRedirectUrlFromQuery(queryParams.current);
31
- history.push(pathname + `?${query}`);
32
- }
33
-
34
- prevPathname.current = pathname;
35
- }, [pathname, search, routes]);
36
- };
package/routerProxy.js DELETED
@@ -1,34 +0,0 @@
1
- import * as ReactRouterDom from 'react-router-dom';
2
- export const BrowserRouter = ReactRouterDom.BrowserRouter;
3
- export const useHistory = () => {
4
- var _ReactRouterDom$useIn, _ReactRouterDom$useNa, _ReactRouterDom$useHi;
5
-
6
- const navigate = (_ReactRouterDom$useIn = ReactRouterDom.useInRouterContext) != null && _ReactRouterDom$useIn.call(ReactRouterDom) ? (_ReactRouterDom$useNa = ReactRouterDom.useNavigate) == null ? void 0 : _ReactRouterDom$useNa.call(ReactRouterDom) : null;
7
- const history = (_ReactRouterDom$useHi = ReactRouterDom.useHistory) == null ? void 0 : _ReactRouterDom$useHi.call(ReactRouterDom);
8
-
9
- if (navigate) {
10
- const push = (path, state) => {
11
- if (state) {
12
- navigate(path, {
13
- state
14
- });
15
- } else {
16
- navigate(path);
17
- }
18
- };
19
-
20
- const replace = (path, state) => {
21
- navigate(path, {
22
- state,
23
- replace: true
24
- });
25
- };
26
-
27
- return {
28
- push,
29
- replace
30
- };
31
- }
32
-
33
- return history;
34
- };