@frontegg/react 4.0.14 → 4.0.15-alpha.2201525149

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,7 +1,8 @@
1
- import React, { FC } from 'react';
1
+ import React, { FC, ReactNode } from 'react';
2
2
  export interface AuthorizationProps {
3
3
  requiredRoles?: string[];
4
4
  requiredPermissions?: string[];
5
5
  render?: (isAuthorized: boolean) => React.ReactNode | null;
6
+ children?: ReactNode;
6
7
  }
7
8
  export declare const AuthorizedContent: FC<AuthorizationProps>;
@@ -1,9 +1,10 @@
1
- import { FC } from 'react';
1
+ import { FC, ReactNode } from 'react';
2
2
  import { FronteggAppOptions } from '@frontegg/types';
3
3
  import { UseHistory } from './routerProxy';
4
4
  export declare type FronteggProviderProps = FronteggAppOptions & {
5
5
  appName?: string;
6
6
  history?: UseHistory;
7
+ children?: ReactNode;
7
8
  };
8
9
  declare type ConnectorProps = Omit<FronteggProviderProps, 'history'> & {
9
10
  history: {
package/index.js CHANGED
@@ -40,8 +40,7 @@ var useHistory = function () {
40
40
  var removeRedirectUrlFromQuery = function (query) {
41
41
  var q = new URLSearchParams(query);
42
42
  q.delete('redirectUrl');
43
- var cleanedQuery = q.toString();
44
- return cleanedQuery;
43
+ return q.toString();
45
44
  };
46
45
  var useQueryKeeper = function (_a) {
47
46
  var routes = _a.routes, history = _a.history;
@@ -103,13 +102,6 @@ var Connector = function (_a) {
103
102
  restApi.ContextHolder.setOnRedirectTo(onRedirectTo);
104
103
  var signUpUrl = app.store.getState().auth.routes.signUpUrl;
105
104
  useQueryKeeper({ routes: { signUpUrl: signUpUrl }, history: history });
106
- React.useEffect(function () { return function () {
107
- var _a, _b;
108
- try {
109
- (_b = (_a = app.store) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
110
- }
111
- catch (e) { }
112
- }; }, []);
113
105
  return React__default.createElement(reactHooks.FronteggStoreProvider, tslib.__assign({}, tslib.__assign(tslib.__assign({}, props), { app: app })));
114
106
  };
115
107
  var FronteggProvider = function (props) {
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/routerProxy.tsx","../src/queryKeeper.tsx","../src/FronteggProvider.tsx","../src/AuthorizedContent.tsx"],"sourcesContent":["import * as ReactRouterDom from 'react-router-dom';\n\nexport type Path = string;\n\ntype Location = {\n pathname: string;\n search: string;\n state: any;\n hash: string;\n key?: string;\n};\n\ntype LocationDescriptor = string | Location;\n\nexport type UseHistory = {\n push(path: Path, state?: any): void;\n push(location: LocationDescriptor): void;\n replace(path: Path, state?: any): void;\n replace(location: LocationDescriptor): void;\n};\n\nexport const BrowserRouter = ReactRouterDom.BrowserRouter;\n\nexport const useHistory = (): UseHistory => {\n // @ts-ignore\n const navigate = ReactRouterDom.useInRouterContext?.() ? ReactRouterDom.useNavigate?.() : null;\n const history = ReactRouterDom.useHistory?.();\n\n if (navigate) {\n const push = (path: Path, state?: any): void => {\n if (state) {\n navigate(path, { state });\n } else {\n navigate(path);\n }\n };\n\n const replace = (path: Path, state?: any): void => {\n navigate(path, { state, replace: true });\n };\n\n return { push, replace };\n }\n return history;\n};\n","import { useEffect, useRef } from 'react';\nimport { useLocation } from 'react-router-dom';\nimport { UseHistory } from './routerProxy';\n\ninterface useQueryKeeperProps {\n history: UseHistory;\n routes: {\n [key: string]: string;\n };\n}\n\nconst removeRedirectUrlFromQuery = (query: string) => {\n const q = new URLSearchParams(query);\n q.delete('redirectUrl');\n const cleanedQuery = q.toString();\n\n return cleanedQuery;\n};\n\nexport const useQueryKeeper = ({ routes, history }: useQueryKeeperProps): void => {\n const queryParams = useRef<string>();\n const prevPathname = useRef<string>();\n const { pathname, search } = useLocation();\n\n useEffect(() => {\n if (!!search) {\n queryParams.current = search;\n prevPathname.current = pathname;\n }\n }, []);\n\n useEffect(() => {\n const shouldKeepQuery = !!Object.values(routes).find((route) => route === prevPathname.current);\n\n if (!search && !!queryParams.current && shouldKeepQuery) {\n const query = removeRedirectUrlFromQuery(queryParams.current);\n history.push(pathname + `?${query}`);\n }\n\n prevPathname.current = pathname;\n }, [pathname, search, routes]);\n};\n","import React, { FC, useCallback, useEffect, useMemo } from 'react';\nimport { initialize } from '@frontegg/admin-portal';\nimport { FronteggAppOptions } from '@frontegg/types';\nimport { FronteggStoreProvider } from '@frontegg/react-hooks';\nimport { BrowserRouter, useHistory, UseHistory } from './routerProxy';\nimport { ContextHolder, RedirectOptions } from '@frontegg/rest-api';\nimport { AppHolder } from '@frontegg/admin-portal/AppHolder';\nimport { useQueryKeeper } from './queryKeeper';\n\nexport type FronteggProviderProps = FronteggAppOptions & {\n appName?: string;\n history?: UseHistory;\n};\ntype ConnectorProps = Omit<FronteggProviderProps, 'history'> & {\n history: {\n push: (path: string) => void;\n replace: (path: string) => void;\n };\n};\n\nexport const ConnectorHistory: FC<Omit<ConnectorProps, 'history'>> = (props) => {\n const history = useHistory();\n return <Connector history={history} {...props} />;\n};\n\nexport const Connector: FC<ConnectorProps> = ({ history, appName, ...props }) => {\n const isSSR = typeof window === 'undefined';\n\n // v6 or v5\n const baseName = props.basename ?? '';\n\n const onRedirectTo = useCallback((_path: string, opts?: RedirectOptions) => {\n let path = _path;\n // noinspection SuspiciousTypeOfGuard\n if (baseName && typeof baseName === 'string' && baseName.length > 0 && path.startsWith(baseName)) {\n path = path.substring(baseName.length);\n }\n if (opts?.preserveQueryParams) {\n path = `${path}${window.location.search}`;\n }\n if (opts?.refresh && !isSSR) {\n // @ts-ignore\n window.Cypress ? history.push(path) : (window.location.href = path);\n } else {\n opts?.replace ? history.replace(path) : history.push(path);\n }\n }, []);\n\n const app = useMemo(() => {\n try {\n return AppHolder.getInstance(appName ?? 'default');\n } catch (e) {\n return initialize(\n {\n ...props,\n basename: props.basename ?? baseName,\n contextOptions: {\n requestCredentials: 'include',\n ...props.contextOptions,\n },\n onRedirectTo,\n },\n appName ?? 'default'\n );\n }\n }, []);\n ContextHolder.setOnRedirectTo(onRedirectTo);\n\n const signUpUrl = app.store.getState().auth.routes.signUpUrl;\n useQueryKeeper({ routes: { signUpUrl }, history });\n\n useEffect(\n () => () => {\n try {\n (app.store as any)?.destroy?.();\n } catch (e) {}\n },\n []\n );\n return <FronteggStoreProvider {...({ ...props, app } as any)} />;\n};\n\nexport const FronteggProvider: FC<FronteggProviderProps> = (props) => {\n const history = useHistory();\n\n if (props.history || history) {\n return (\n <Connector history={props.history || history} {...props}>\n {props.children}\n </Connector>\n );\n }\n\n return (\n <BrowserRouter basename={props.basename}>\n <ConnectorHistory {...props}>{props.children}</ConnectorHistory>\n </BrowserRouter>\n );\n};\n","import React, { FC } from 'react';\nimport { useAuthUserOrNull } from '@frontegg/react-hooks';\nimport { User } from '@frontegg/redux-store';\n\nexport interface AuthorizationProps {\n requiredRoles?: string[];\n requiredPermissions?: string[];\n render?: (isAuthorized: boolean) => React.ReactNode | null;\n}\n\nexport const AuthorizedContent: FC<AuthorizationProps> = (props) => {\n let isAuthorized = true; // Initially\n const user = useAuthUserOrNull();\n\n if (!user?.superUser) {\n if (props.requiredPermissions) {\n isAuthorized = false; // Reset - we are going to check that the user has at least one matching permission\n for (const permission of props.requiredPermissions) {\n if (user?.permissions?.find(({ key }) => key === permission)) {\n isAuthorized = true;\n }\n }\n }\n\n if (props.requiredRoles) {\n isAuthorized = false; // Reset - we are going to check that the user has at least one matching role\n for (const role of props.requiredRoles) {\n if (user?.roles?.find(({ key }) => key === role)) {\n isAuthorized = true;\n }\n }\n }\n }\n if (typeof props.render === 'function') {\n return <>{props.render(isAuthorized)}</>;\n }\n\n return isAuthorized ? <>{props.children}</> : null;\n};\n"],"names":["ReactRouterDom.BrowserRouter","ReactRouterDom.useInRouterContext","ReactRouterDom.useNavigate","ReactRouterDom.useHistory","useRef","useLocation","useEffect","React","useCallback","useMemo","AppHolder","initialize","ContextHolder","FronteggStoreProvider","__assign","useAuthUserOrNull"],"mappings":";;;;;;;;;;;;;;;;AAqBO,IAAM,aAAa,GAAGA,4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GAAG,KAAK,UAAU;iBAAA,GAAG;oBAC5D,YAAY,GAAG,IAAI,CAAC;iBACrB;;YAHH,KAAyB,UAAyB,EAAzB,KAAA,KAAK,CAAC,mBAAmB,EAAzB,cAAyB,EAAzB,IAAyB;gBAA7C,IAAM,UAAU,SAAA;wBAAV,UAAU;aAIpB;SACF;QAED,IAAI,KAAK,CAAC,aAAa,EAAE;YACvB,YAAY,GAAG,KAAK,CAAC;oCACV,IAAI;gBACb,UAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,0CAAE,IAAI,CAAC,UAAC,EAAO;wBAAL,GAAG,SAAA;oBAAO,OAAA,GAAG,KAAK,IAAI;iBAAA,GAAG;oBAChD,YAAY,GAAG,IAAI,CAAC;iBACrB;;YAHH,KAAmB,UAAmB,EAAnB,KAAA,KAAK,CAAC,aAAa,EAAnB,cAAmB,EAAnB,IAAmB;gBAAjC,IAAM,IAAI,SAAA;wBAAJ,IAAI;aAId;SACF;KACF;IACD,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU,EAAE;QACtC,OAAOR,4DAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAI,CAAC;KAC1C;IAED,OAAO,YAAY,GAAGA,4DAAG,KAAK,CAAC,QAAQ,CAAI,GAAG,IAAI,CAAC;AACrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/routerProxy.tsx","../src/queryKeeper.tsx","../src/FronteggProvider.tsx","../src/AuthorizedContent.tsx"],"sourcesContent":["import * as ReactRouterDom from 'react-router-dom';\n\nexport type Path = string;\n\ntype Location = {\n pathname: string;\n search: string;\n state: any;\n hash: string;\n key?: string;\n};\n\ntype LocationDescriptor = string | Location;\n\nexport type UseHistory = {\n push(path: Path, state?: any): void;\n push(location: LocationDescriptor): void;\n replace(path: Path, state?: any): void;\n replace(location: LocationDescriptor): void;\n};\n\nexport const BrowserRouter = ReactRouterDom.BrowserRouter;\n\nexport const useHistory = (): UseHistory => {\n // @ts-ignore\n const navigate = ReactRouterDom.useInRouterContext?.() ? ReactRouterDom.useNavigate?.() : null;\n const history = ReactRouterDom.useHistory?.();\n\n if (navigate) {\n const push = (path: Path, state?: any): void => {\n if (state) {\n navigate(path, { state });\n } else {\n navigate(path);\n }\n };\n\n const replace = (path: Path, state?: any): void => {\n navigate(path, { state, replace: true });\n };\n\n return { push, replace };\n }\n return history;\n};\n","import { useEffect, useRef } from 'react';\nimport { useLocation } from 'react-router-dom';\nimport { UseHistory } from './routerProxy';\n\ninterface UseQueryKeeperProps {\n history: UseHistory;\n routes: {\n [key: string]: string;\n };\n}\n\nconst removeRedirectUrlFromQuery = (query: string) => {\n const q = new URLSearchParams(query);\n q.delete('redirectUrl');\n return q.toString();\n};\n\nexport const useQueryKeeper = ({ routes, history }: UseQueryKeeperProps): void => {\n const queryParams = useRef<string>();\n const prevPathname = useRef<string>();\n const { pathname, search } = useLocation();\n\n useEffect(() => {\n if (!!search) {\n queryParams.current = search;\n prevPathname.current = pathname;\n }\n }, []);\n\n useEffect(() => {\n const shouldKeepQuery = !!Object.values(routes).find((route) => route === prevPathname.current);\n\n if (!search && !!queryParams.current && shouldKeepQuery) {\n const query = removeRedirectUrlFromQuery(queryParams.current);\n history.push(pathname + `?${query}`);\n }\n\n prevPathname.current = pathname;\n }, [pathname, search, routes]);\n};\n","import React, { FC, ReactNode, useCallback, useMemo } from 'react';\nimport { initialize } from '@frontegg/admin-portal';\nimport { FronteggAppOptions } from '@frontegg/types';\nimport { FronteggStoreProvider } from '@frontegg/react-hooks';\nimport { BrowserRouter, useHistory, UseHistory } from './routerProxy';\nimport { ContextHolder, RedirectOptions } from '@frontegg/rest-api';\nimport { AppHolder } from '@frontegg/admin-portal/AppHolder';\nimport { useQueryKeeper } from './queryKeeper';\n\nexport type FronteggProviderProps = FronteggAppOptions & {\n appName?: string;\n history?: UseHistory;\n children?: ReactNode;\n};\ntype ConnectorProps = Omit<FronteggProviderProps, 'history'> & {\n history: {\n push: (path: string) => void;\n replace: (path: string) => void;\n };\n};\n\nexport const ConnectorHistory: FC<Omit<ConnectorProps, 'history'>> = (props) => {\n const history = useHistory();\n return <Connector history={history} {...props} />;\n};\n\nexport const Connector: FC<ConnectorProps> = ({ history, appName, ...props }) => {\n const isSSR = typeof window === 'undefined';\n\n // v6 or v5\n const baseName = props.basename ?? '';\n\n const onRedirectTo = useCallback((_path: string, opts?: RedirectOptions) => {\n let path = _path;\n // noinspection SuspiciousTypeOfGuard\n if (baseName && typeof baseName === 'string' && baseName.length > 0 && path.startsWith(baseName)) {\n path = path.substring(baseName.length);\n }\n if (opts?.preserveQueryParams) {\n path = `${path}${window.location.search}`;\n }\n if (opts?.refresh && !isSSR) {\n // @ts-ignore\n window.Cypress ? history.push(path) : (window.location.href = path);\n } else {\n opts?.replace ? history.replace(path) : history.push(path);\n }\n }, []);\n\n const app = useMemo(() => {\n try {\n return AppHolder.getInstance(appName ?? 'default');\n } catch (e) {\n return initialize(\n {\n ...props,\n basename: props.basename ?? baseName,\n contextOptions: {\n requestCredentials: 'include',\n ...props.contextOptions,\n },\n onRedirectTo,\n },\n appName ?? 'default'\n );\n }\n }, []);\n ContextHolder.setOnRedirectTo(onRedirectTo);\n\n const signUpUrl = app.store.getState().auth.routes.signUpUrl;\n useQueryKeeper({ routes: { signUpUrl }, history });\n\n return <FronteggStoreProvider {...({ ...props, app } as any)} />;\n};\n\nexport const FronteggProvider: FC<FronteggProviderProps> = (props) => {\n const history = useHistory();\n\n if (props.history || history) {\n return (\n <Connector history={props.history || history} {...props}>\n {props.children}\n </Connector>\n );\n }\n\n return (\n <BrowserRouter basename={props.basename}>\n <ConnectorHistory {...props}>{props.children}</ConnectorHistory>\n </BrowserRouter>\n );\n};\n","import React, { FC, ReactNode } from 'react';\nimport { useAuthUserOrNull } from '@frontegg/react-hooks';\n\nexport interface AuthorizationProps {\n requiredRoles?: string[];\n requiredPermissions?: string[];\n render?: (isAuthorized: boolean) => React.ReactNode | null;\n children?: ReactNode;\n}\n\nexport const AuthorizedContent: FC<AuthorizationProps> = (props) => {\n let isAuthorized = true; // Initially\n const user = useAuthUserOrNull();\n\n if (!user?.superUser) {\n if (props.requiredPermissions) {\n isAuthorized = false; // Reset - we are going to check that the user has at least one matching permission\n for (const permission of props.requiredPermissions) {\n if (user?.permissions?.find(({ key }) => key === permission)) {\n isAuthorized = true;\n }\n }\n }\n\n if (props.requiredRoles) {\n isAuthorized = false; // Reset - we are going to check that the user has at least one matching role\n for (const role of props.requiredRoles) {\n if (user?.roles?.find(({ key }) => key === role)) {\n isAuthorized = true;\n }\n }\n }\n }\n if (typeof props.render === 'function') {\n return <>{props.render(isAuthorized)}</>;\n }\n\n return isAuthorized ? <>{props.children}</> : null;\n};\n"],"names":["ReactRouterDom.BrowserRouter","ReactRouterDom.useInRouterContext","ReactRouterDom.useNavigate","ReactRouterDom.useHistory","useRef","useLocation","useEffect","React","useCallback","useMemo","AppHolder","initialize","ContextHolder","FronteggStoreProvider","__assign","useAuthUserOrNull"],"mappings":";;;;;;;;;;;;;;;;AAqBO,IAAM,aAAa,GAAGA,4BAA4B,CAAC;AAEnD,IAAM,UAAU,GAAG;;;IAExB,IAAM,QAAQ,GAAG,OAAAC,iCAAiC,+CAAjC,cAAc,WAA0BC,0BAA0B,+CAA1B,cAAc,IAAmB,IAAI,CAAC;IAC/F,IAAM,OAAO,SAAGC,yBAAyB,+CAAzB,cAAc,CAAe,CAAC;IAE9C,IAAI,QAAQ,EAAE;QACZ,IAAM,IAAI,GAAG,UAAC,IAAU,EAAE,KAAW;YACnC,IAAI,KAAK,EAAE;gBACT,QAAQ,CAAC,IAAI,EAAE,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;aAC3B;iBAAM;gBACL,QAAQ,CAAC,IAAI,CAAC,CAAC;aAChB;SACF,CAAC;QAEF,IAAM,OAAO,GAAG,UAAC,IAAU,EAAE,KAAW;YACtC,QAAQ,CAAC,IAAI,EAAE,EAAE,KAAK,OAA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AC1C;IAED,OAAO,YAAY,GAAGA,4DAAG,KAAK,CAAC,QAAQ,CAAI,GAAG,IAAI,CAAC;AACrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frontegg/react",
3
3
  "libName": "FronteggReact",
4
- "version": "4.0.14",
4
+ "version": "4.0.15-alpha.2201525149",
5
5
  "author": "Frontegg LTD",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
@@ -11,8 +11,8 @@
11
11
  "test": "jest --runInBand --passWithNoTests -c ../../scripts/jest.config.json --rootDir ."
12
12
  },
13
13
  "dependencies": {
14
- "@frontegg/admin-portal": "5.42.0",
15
- "@frontegg/react-hooks": "5.42.0"
14
+ "@frontegg/admin-portal": "5.43.0",
15
+ "@frontegg/react-hooks": "5.43.0"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "react": ">16.9.0",
package/queryKeeper.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { UseHistory } from './routerProxy';
2
- interface useQueryKeeperProps {
2
+ interface UseQueryKeeperProps {
3
3
  history: UseHistory;
4
4
  routes: {
5
5
  [key: string]: string;
6
6
  };
7
7
  }
8
- export declare const useQueryKeeper: ({ routes, history }: useQueryKeeperProps) => void;
8
+ export declare const useQueryKeeper: ({ routes, history }: UseQueryKeeperProps) => void;
9
9
  export {};