@frontegg/react 5.0.12 → 5.0.13-alpha.3612311487

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Change Log
2
2
 
3
+ ## [5.0.13](https://github.com/frontegg/frontegg-react/compare/v5.0.12...v5.0.13) (2022-12-4)
4
+
5
+ - FR-9852 - copy invite link fix
6
+ - FR-9858 - fix - appearance and settings should be optional for invite user customization
7
+
8
+ - FR-9852 - Support copy invite link for dynamic base URL as well (mainly for Next.js)
9
+ - FR-9742 - login with mfa
10
+ - FR-9520 - FR-9504 - fonts improvements
11
+
12
+
3
13
  ## [5.0.12](https://github.com/frontegg/frontegg-react/compare/v5.0.11...v5.0.12) (2022-11-28)
4
14
 
5
15
  - FR-9750 - change api according to the new names security tabs
package/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export * from './CheckoutDialog';
4
4
  export { AdminPortal, CheckoutDialog } from '@frontegg/js';
5
5
  export * from '@frontegg/react-hooks';
6
6
  export * from '@frontegg/types';
7
+ export { ContextHolder } from '@frontegg/rest-api';
package/index.js CHANGED
@@ -234,6 +234,12 @@ Object.defineProperty(exports, 'CheckoutDialog', {
234
234
  return js.CheckoutDialog;
235
235
  }
236
236
  });
237
+ Object.defineProperty(exports, 'ContextHolder', {
238
+ enumerable: true,
239
+ get: function () {
240
+ return restApi.ContextHolder;
241
+ }
242
+ });
237
243
  exports.AuthorizedContent = AuthorizedContent;
238
244
  exports.Connector = Connector;
239
245
  exports.ConnectorHistory = ConnectorHistory;
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","../src/CheckoutDialog.tsx"],"sourcesContent":["import * as ReactRouterDom from 'react-router-dom';\nimport { FC } from 'react';\nimport { BrowserRouterProps } 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: FC<BrowserRouterProps> = (ReactRouterDom.BrowserRouter as unknown) as FC<\n BrowserRouterProps\n>;\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/js';\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/js/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","import { useCallback, useMemo, useState } from 'react';\nimport { CheckoutDialog } from '@frontegg/js';\n\ninterface CheckoutDialogState {\n open: boolean;\n error: string | null;\n success: boolean;\n}\n\nexport interface CheckoutDialogHook {\n showDialog: (plan: string) => void;\n hideDialog: () => void;\n open: boolean;\n error: string | null;\n success: boolean;\n}\n\nexport const useCheckoutDialog = (appName = 'default'): CheckoutDialogHook => {\n const [{ open, error, success }, setState] = useState<CheckoutDialogState>({\n open: false,\n error: null,\n success: false,\n });\n\n const handleError = useCallback((error: string) => {\n setState({\n open: true,\n success: false,\n error,\n });\n }, []);\n\n const handleSuccess = useCallback(() => {\n setState({\n open: false,\n success: true,\n error: null,\n });\n }, []);\n\n const showDialog = useCallback(\n (plan: string) => {\n CheckoutDialog.show(\n {\n plan,\n onClose: hideDialog,\n onError: handleError,\n onSuccess: handleSuccess,\n },\n appName\n );\n setState({\n open: true,\n success: false,\n error: null,\n });\n },\n [appName]\n );\n\n const hideDialog = useCallback(() => {\n CheckoutDialog.hide(appName);\n setState({\n open: false,\n error: null,\n success: false,\n });\n }, [appName]);\n\n return useMemo(\n () => ({\n open,\n showDialog,\n hideDialog,\n error,\n success,\n }),\n [open, showDialog, hideDialog, error, success]\n );\n};\n"],"names":["ReactRouterDom.BrowserRouter","ReactRouterDom.useInRouterContext","ReactRouterDom.useNavigate","ReactRouterDom.useHistory","useRef","useLocation","useEffect","React","useCallback","useMemo","AppHolder","initialize","ContextHolder","FronteggStoreProvider","__assign","useAuthUserOrNull","useState","CheckoutDialog"],"mappings":";;;;;;;;;;;;;;;;AAuBO,IAAM,aAAa,GAA4BA,4BAErD,CAAC;AAEK,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,OAAA,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;SAC1C,CAAC;QAEF,OAAO,EAAE,IAAI,MAAA,EAAE,OAAO,SAAA,EAAE,CAAC;KAC1B;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;;ACrCD,IAAM,0BAA0B,GAAG,UAAC,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IAAC,EACF,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAC/C,CAAC;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/routerProxy.tsx","../src/queryKeeper.tsx","../src/FronteggProvider.tsx","../src/AuthorizedContent.tsx","../src/CheckoutDialog.tsx"],"sourcesContent":["import * as ReactRouterDom from 'react-router-dom';\nimport { FC } from 'react';\nimport { BrowserRouterProps } 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: FC<BrowserRouterProps> = (ReactRouterDom.BrowserRouter as unknown) as FC<\n BrowserRouterProps\n>;\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/js';\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/js/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","import { useCallback, useMemo, useState } from 'react';\nimport { CheckoutDialog } from '@frontegg/js';\n\ninterface CheckoutDialogState {\n open: boolean;\n error: string | null;\n success: boolean;\n}\n\nexport interface CheckoutDialogHook {\n showDialog: (plan: string) => void;\n hideDialog: () => void;\n open: boolean;\n error: string | null;\n success: boolean;\n}\n\nexport const useCheckoutDialog = (appName = 'default'): CheckoutDialogHook => {\n const [{ open, error, success }, setState] = useState<CheckoutDialogState>({\n open: false,\n error: null,\n success: false,\n });\n\n const handleError = useCallback((error: string) => {\n setState({\n open: true,\n success: false,\n error,\n });\n }, []);\n\n const handleSuccess = useCallback(() => {\n setState({\n open: false,\n success: true,\n error: null,\n });\n }, []);\n\n const showDialog = useCallback(\n (plan: string) => {\n CheckoutDialog.show(\n {\n plan,\n onClose: hideDialog,\n onError: handleError,\n onSuccess: handleSuccess,\n },\n appName\n );\n setState({\n open: true,\n success: false,\n error: null,\n });\n },\n [appName]\n );\n\n const hideDialog = useCallback(() => {\n CheckoutDialog.hide(appName);\n setState({\n open: false,\n error: null,\n success: false,\n });\n }, [appName]);\n\n return useMemo(\n () => ({\n open,\n showDialog,\n hideDialog,\n error,\n success,\n }),\n [open, showDialog, hideDialog, error, success]\n );\n};\n"],"names":["ReactRouterDom.BrowserRouter","ReactRouterDom.useInRouterContext","ReactRouterDom.useNavigate","ReactRouterDom.useHistory","useRef","useLocation","useEffect","React","useCallback","useMemo","AppHolder","initialize","ContextHolder","FronteggStoreProvider","__assign","useAuthUserOrNull","useState","CheckoutDialog"],"mappings":";;;;;;;;;;;;;;;;AAuBO,IAAM,aAAa,GAA4BA,4BAErD,CAAC;AAEK,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;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AU,GAAGT,iBAAW,CAAC;QAC7BS,iBAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7B,QAAQ,CAAC;YACP,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;KACJ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAOR,aAAO,CACZ,cAAM,QAAC;QACL,IAAI,MAAA;QACJ,UAAU,YAAA;QACV,UAAU,YAAA;QACV,KAAK,OAAA;QACL,OAAO,SAAA;KACR,IAAC,EACF,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAC/C,CAAC;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frontegg/react",
3
3
  "libName": "FronteggReact",
4
- "version": "5.0.12",
4
+ "version": "5.0.13-alpha.3612311487",
5
5
  "author": "Frontegg LTD",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
@@ -10,8 +10,8 @@
10
10
  "build:watch": "rm -rf dist && mkdir dist && rollup -w -c ./rollup.config.js"
11
11
  },
12
12
  "dependencies": {
13
- "@frontegg/js": "6.46.0",
14
- "@frontegg/react-hooks": "6.46.0"
13
+ "@frontegg/js": "6.48.0",
14
+ "@frontegg/react-hooks": "6.48.0"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "react": ">16.9.0",