@frontegg/react 4.0.18-alpha.2404258317 → 4.0.18-alpha.2420085164
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/CheckoutDialog.d.ts +1 -0
- package/index.js +12 -3
- package/index.js.map +1 -1
- package/package.json +1 -1
package/CheckoutDialog.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -161,6 +161,7 @@ var useCheckoutDialog = function (plan) {
|
|
|
161
161
|
error: null,
|
|
162
162
|
success: false,
|
|
163
163
|
}), _b = _a[0], open = _b.open, error = _b.error, success = _b.success, setState = _a[1];
|
|
164
|
+
var loading = reactHooks.useCheckout().loading;
|
|
164
165
|
var handleError = React.useCallback(function (error) {
|
|
165
166
|
setState({
|
|
166
167
|
open: true,
|
|
@@ -170,7 +171,7 @@ var useCheckoutDialog = function (plan) {
|
|
|
170
171
|
}, []);
|
|
171
172
|
var handleSuccess = React.useCallback(function () {
|
|
172
173
|
setState({
|
|
173
|
-
open:
|
|
174
|
+
open: false,
|
|
174
175
|
success: true,
|
|
175
176
|
error: null,
|
|
176
177
|
});
|
|
@@ -202,13 +203,21 @@ var useCheckoutDialog = function (plan) {
|
|
|
202
203
|
adminPortal.CheckoutDialog.hide();
|
|
203
204
|
}
|
|
204
205
|
}, [open]);
|
|
205
|
-
return {
|
|
206
|
+
return React.useMemo(function () { return ({
|
|
206
207
|
open: open,
|
|
207
208
|
showDialog: showDialog,
|
|
208
209
|
hideDialog: hideDialog,
|
|
209
210
|
error: error,
|
|
210
211
|
success: success,
|
|
211
|
-
|
|
212
|
+
loading: loading,
|
|
213
|
+
}); }, [
|
|
214
|
+
open,
|
|
215
|
+
showDialog,
|
|
216
|
+
hideDialog,
|
|
217
|
+
error,
|
|
218
|
+
success,
|
|
219
|
+
loading,
|
|
220
|
+
]);
|
|
212
221
|
};
|
|
213
222
|
|
|
214
223
|
Object.keys(reactHooks).forEach(function (k) {
|
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';\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","import { useCallback, useEffect, useState } from 'react';\nimport { CheckoutDialog } from '@frontegg/admin-portal';\n\ninterface CheckoutDialogState {\n open: boolean;\n error: string | null;\n success: boolean;\n}\n\nexport interface CheckoutDialogHook {\n showDialog: () => void;\n hideDialog: () => void;\n open: boolean;\n error: string | null;\n success: boolean;\n}\n\nexport const useCheckoutDialog = (plan: string): 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: true,\n success: true,\n error: null,\n });\n }, []);\n\n const showDialog = useCallback(() => {\n setState({\n open: true,\n success: false,\n error: null,\n });\n }, []);\n\n const hideDialog = useCallback(() => {\n setState({\n open: false,\n error: null,\n success: false,\n });\n }, []);\n\n useEffect(() => {\n if (open) {\n CheckoutDialog.show({\n plan,\n onClose: hideDialog,\n onError: handleError,\n onSuccess: handleSuccess,\n });\n } else {\n CheckoutDialog.hide();\n }\n }, [open]);\n\n return {\n open,\n showDialog,\n hideDialog,\n error,\n 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":";;;;;;;;;;;;;;;;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,OAAA,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;SAC1C,CAAC;QAEF,OAAO,EAAE,IAAI,MAAA,EAA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X,OAAO;QACL,IAAI,MAAA;QACJ,UAAU,YAAA;QACV,UAAU,YAAA;QACV,KAAK,OAAA;QACL,OAAO,SAAA;KACR,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';\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","import { useCallback, useEffect, useMemo, useState } from 'react';\nimport { CheckoutDialog } from '@frontegg/admin-portal';\nimport { useCheckout } from '@frontegg/react-hooks';\n\ninterface CheckoutDialogState {\n open: boolean;\n error: string | null;\n success: boolean;\n}\n\nexport interface CheckoutDialogHook {\n showDialog: () => void;\n hideDialog: () => void;\n open: boolean;\n error: string | null;\n success: boolean;\n loading: boolean;\n}\n\nexport const useCheckoutDialog = (plan: string): CheckoutDialogHook => {\n const [{ open, error, success }, setState] = useState<CheckoutDialogState>({\n open: false,\n error: null,\n success: false,\n });\n const { loading } = useCheckout();\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 setState({\n open: true,\n success: false,\n error: null,\n });\n }, []);\n\n const hideDialog = useCallback(() => {\n setState({\n open: false,\n error: null,\n success: false,\n });\n }, []);\n\n useEffect(() => {\n if (open) {\n CheckoutDialog.show({\n plan,\n onClose: hideDialog,\n onError: handleError,\n onSuccess: handleSuccess,\n });\n } else {\n CheckoutDialog.hide();\n }\n }, [open]);\n\n return useMemo(() => ({\n open,\n showDialog,\n hideDialog,\n error,\n success,\n loading,\n }), [\n open,\n showDialog,\n hideDialog,\n error,\n success,\n loading,\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","useCheckout","CheckoutDialog"],"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,K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