next-recaptcha-v3 1.0.4 → 1.0.5
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/README.md +1 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/useReCaptcha.d.ts +1 -1
- package/package.json +12 -12
- package/lib/cjs/ReCaptcha.js +0 -37
- package/lib/cjs/ReCaptcha.js.map +0 -1
- package/lib/cjs/ReCaptchaProvider.js +0 -99
- package/lib/cjs/ReCaptchaProvider.js.map +0 -1
- package/lib/cjs/index.js +0 -22
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/recaptcha.types.js +0 -5
- package/lib/cjs/recaptcha.types.js.map +0 -1
- package/lib/cjs/useReCaptcha.js +0 -43
- package/lib/cjs/useReCaptcha.js.map +0 -1
- package/lib/cjs/utils.js +0 -19
- package/lib/cjs/utils.js.map +0 -1
- package/lib/cjs/withReCaptcha.js +0 -26
- package/lib/cjs/withReCaptcha.js.map +0 -1
package/README.md
CHANGED
package/lib/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/utils.ts","../src/ReCaptchaProvider.tsx","../src/useReCaptcha.tsx","../src/ReCaptcha.tsx","../src/withReCaptcha.tsx"],"sourcesContent":["/**\r\n * Function to generate the src for the script tag\r\n * Refs: https://developers.google.com/recaptcha/docs/loading\r\n */\r\nexport const getRecaptchaScriptSrc = ({\r\n reCaptchaKey,\r\n language,\r\n useRecaptchaNet = false,\r\n useEnterprise = false,\r\n}: {\r\n reCaptchaKey?: string;\r\n language?: string;\r\n useRecaptchaNet?: boolean;\r\n useEnterprise?: boolean;\r\n} = {}): string => {\r\n const hostName = useRecaptchaNet ? \"recaptcha.net\" : \"google.com\";\r\n const script = useEnterprise ? \"enterprise.js\" : \"api.js\";\r\n\r\n let src = `https://www.${hostName}/recaptcha/${script}?`;\r\n if (reCaptchaKey) src += `render=${reCaptchaKey}`;\r\n if (language) src += `&hl=${language}`;\r\n\r\n return src;\r\n};\r\n","import React, {\r\n useMemo,\r\n useState,\r\n useEffect,\r\n useCallback,\r\n useContext,\r\n createContext,\r\n useDebugValue,\r\n} from \"react\";\r\nimport Script, { ScriptProps } from \"next/script\";\r\nimport type { IReCaptcha } from \"./recaptcha.types\";\r\nimport { getRecaptchaScriptSrc } from \"./utils\";\r\n\r\ninterface ReCaptchaContextProps {\r\n /** reCAPTCHA_site_key */\r\n readonly reCaptchaKey: string | null;\r\n /** Global ReCaptcha object */\r\n readonly grecaptcha: IReCaptcha | null;\r\n /** Is ReCaptcha script loaded */\r\n readonly loaded: boolean;\r\n /** Is ReCaptcha failed to load */\r\n readonly error: boolean;\r\n}\r\n\r\nconst ReCaptchaContext = createContext<ReCaptchaContextProps>({\r\n reCaptchaKey: null,\r\n grecaptcha: null,\r\n loaded: false,\r\n error: false,\r\n});\r\n\r\nconst useReCaptchaContext = () => {\r\n const values = useContext(ReCaptchaContext);\r\n useDebugValue(`grecaptcha available: ${values?.loaded ? \"Yes\" : \"No\"}`);\r\n useDebugValue(`ReCaptcha Script: ${values?.loaded ? \"Loaded\" : \"Not Loaded\"}`);\r\n useDebugValue(`Failed to load Script: ${values?.error ? \"Yes\" : \"No\"}`);\r\n return values;\r\n};\r\n\r\ninterface ReCaptchaProviderProps extends Partial<Omit<ScriptProps, \"onLoad\">> {\r\n reCaptchaKey?: string;\r\n language?: string;\r\n useRecaptchaNet?: boolean;\r\n useEnterprise?: boolean;\r\n children?: React.ReactNode;\r\n onLoad?: (grecaptcha: IReCaptcha, e: any) => void;\r\n}\r\n\r\nconst ReCaptchaProvider: React.FC<ReCaptchaProviderProps> = ({\r\n reCaptchaKey: passedReCaptchaKey,\r\n\r\n useEnterprise = false,\r\n useRecaptchaNet = false,\r\n language,\r\n children,\r\n\r\n id = \"google-recaptcha-v3\",\r\n strategy = \"afterInteractive\",\r\n\r\n src: passedSrc,\r\n onLoad: passedOnLoad,\r\n onError: passedOnError,\r\n\r\n ...props\r\n}) => {\r\n const [grecaptcha, setGreCaptcha] = useState<IReCaptcha | null>(null);\r\n const [loaded, setLoaded] = useState(false);\r\n const [error, setError] = useState(false);\r\n\r\n const reCaptchaKey = passedReCaptchaKey || process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY || null;\r\n\r\n const src =\r\n passedSrc ||\r\n getRecaptchaScriptSrc({ reCaptchaKey, language, useRecaptchaNet, useEnterprise }) ||\r\n null;\r\n\r\n // Reset state when script src is changed\r\n useEffect(() => {\r\n setLoaded(false);\r\n setError(false);\r\n }, [src]);\r\n\r\n // Handle script load\r\n const onLoad = useCallback(\r\n (e?: any) => {\r\n const grecaptcha = useEnterprise ? window?.grecaptcha?.enterprise : window?.grecaptcha;\r\n\r\n if (grecaptcha) {\r\n grecaptcha.ready(() => {\r\n setGreCaptcha(grecaptcha);\r\n setLoaded(true);\r\n passedOnLoad?.(grecaptcha, e);\r\n });\r\n }\r\n },\r\n [passedOnLoad, useEnterprise],\r\n );\r\n\r\n // Run 'onLoad' function once just in case if grecaptcha is already globally available in window\r\n useEffect(() => onLoad(), [onLoad]);\r\n\r\n // Handle script error\r\n const onError = useCallback(\r\n (e: any) => {\r\n setError(true);\r\n passedOnError?.(e);\r\n },\r\n [passedOnError],\r\n );\r\n\r\n // Prevent unnecessary rerenders\r\n const value = useMemo(\r\n () => ({ reCaptchaKey, grecaptcha, loaded, error }),\r\n [reCaptchaKey, grecaptcha, loaded, error],\r\n );\r\n\r\n return (\r\n <ReCaptchaContext.Provider value={value}>\r\n {children}\r\n <Script id={id} src={src} strategy={strategy} onLoad={onLoad} onError={onError} {...props} />\r\n </ReCaptchaContext.Provider>\r\n );\r\n};\r\n\r\nexport { ReCaptchaContext, useReCaptchaContext, ReCaptchaProvider };\r\nexport type { ReCaptchaContextProps, ReCaptchaProviderProps };\r\n","import { useCallback } from \"react\";\r\nimport { useReCaptchaContext } from \"./ReCaptchaProvider\";\r\nimport type { ReCaptchaContextProps } from \"./ReCaptchaProvider\";\r\n\r\nexport interface useReCaptchaProps extends ReCaptchaContextProps {\r\n executeRecaptcha: (action: string) => Promise<string>;\r\n}\r\n\r\n/** React Hook to generate ReCaptcha token\r\n * @example\r\n * const { executeRecaptcha } = useReCaptcha()\r\n */\r\nconst useReCaptcha = (passedReCaptchaKey?: string): useReCaptchaProps => {\r\n const { grecaptcha, reCaptchaKey, ...contextProps } = useReCaptchaContext();\r\n\r\n const siteKey = passedReCaptchaKey || reCaptchaKey;\r\n\r\n const executeRecaptcha = useCallback(\r\n async (action: string) => {\r\n if (typeof grecaptcha?.execute !== \"function\") {\r\n throw new Error(\"Recaptcha has not been loaded\");\r\n }\r\n\r\n const result = await grecaptcha.execute(siteKey, { action });\r\n\r\n return result;\r\n },\r\n [grecaptcha, siteKey],\r\n );\r\n\r\n return { ...contextProps, grecaptcha, reCaptchaKey: siteKey, executeRecaptcha };\r\n};\r\n\r\nexport { useReCaptcha };\r\n","import { useEffect } from \"react\";\r\nimport { useReCaptcha } from \"./useReCaptcha\";\r\n\r\ninterface ReCaptchaProps {\r\n onValidate: (token: string) => void;\r\n action: string;\r\n validate?: boolean;\r\n reCaptchaKey?: string;\r\n}\r\n\r\n/** React Component to generate ReCaptcha token\r\n * @example\r\n * <ReCaptcha action='form-submit' onValidate={handleToken} />\r\n */\r\nconst ReCaptcha: React.FC<ReCaptchaProps> = ({\r\n action,\r\n onValidate,\r\n validate = true,\r\n reCaptchaKey,\r\n}) => {\r\n const { executeRecaptcha } = useReCaptcha(reCaptchaKey);\r\n\r\n useEffect(() => {\r\n if (!validate) return;\r\n if (typeof executeRecaptcha !== \"function\") return;\r\n if (typeof onValidate !== \"function\") return;\r\n\r\n const handleExecuteRecaptcha = async () => {\r\n const token = await executeRecaptcha(action);\r\n onValidate(token);\r\n };\r\n\r\n handleExecuteRecaptcha();\r\n }, [action, onValidate, validate, executeRecaptcha]);\r\n\r\n return null;\r\n};\r\n\r\nexport { ReCaptcha };\r\nexport type { ReCaptchaProps };\r\n","import React from \"react\";\r\nimport { useReCaptcha } from \"./useReCaptcha\";\r\nimport type { useReCaptchaProps } from \"./useReCaptcha\";\r\n\r\ninterface WithReCaptchaProps extends useReCaptchaProps {}\r\n\r\n/** React HOC to generate ReCaptcha token\r\n * @example\r\n * withReCaptcha(MyComponent)\r\n */\r\nfunction withReCaptcha<T extends WithReCaptchaProps = WithReCaptchaProps>(\r\n WrappedComponent: React.ComponentType<T>,\r\n) {\r\n // Try to create a nice displayName for React Dev Tools.\r\n const displayName = WrappedComponent.displayName || WrappedComponent.name || \"Component\";\r\n\r\n // Creating the inner component. The calculated Props type here is the where the magic happens.\r\n const ComponentWithReCaptca = (props: Omit<T, keyof WithReCaptchaProps>) => {\r\n const reCaptchaProps = useReCaptcha();\r\n\r\n // Pass current token and function to generate it to the component\r\n return <WrappedComponent {...reCaptchaProps} {...(props as T)} />;\r\n };\r\n\r\n ComponentWithReCaptca.displayName = `withReCaptcha(${displayName})`;\r\n\r\n return ComponentWithReCaptca;\r\n}\r\n\r\nexport { withReCaptcha };\r\nexport type { WithReCaptchaProps };\r\n"],"names":["ReCaptchaContext","createContext","reCaptchaKey","grecaptcha","loaded","error","useReCaptchaContext","values","useContext","useDebugValue","ReCaptchaProvider","_a","passedReCaptchaKey","useEnterprise","useRecaptchaNet","language","children","id","strategy","src","passedSrc","onLoad","passedOnLoad","onError","passedOnError","props","__rest","setGreCaptcha","useState","setLoaded","setError","process","env","NEXT_PUBLIC_RECAPTCHA_SITE_KEY","getRecaptchaScriptSrc","useEffect","useCallback","e","window","enterprise","ready","value","useMemo","React","Provider","createElement","Script","Object","assign","useReCaptcha","contextProps","siteKey","executeRecaptcha","action","__awaiter","execute","Error","ReCaptcha","onValidate","validate","token","withReCaptcha","WrappedComponent","displayName","name","ComponentWithReCaptca","reCaptchaProps"],"mappings":"kxBAIO,MCoBDA,EAAmBC,EAAqC,CAC5DC,aAAc,KACdC,WAAY,KACZC,QAAQ,EACRC,OAAO,IAGHC,E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eD,EAAiBE,MAAQ,YAGvEC,EAAyBxC,IAC7B,MAAMyC,EAAiBjB,IAGvB,OAAON,gBAACmB,EAAgBf,OAAAC,OAAA,GAAKkB,EAAqBzC,GAAe,EAKnE,OAFAwC,EAAsBF,YAAc,iBAAiBA,KAE9CE,CACT"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/utils.ts","../src/ReCaptchaProvider.tsx","../src/useReCaptcha.tsx","../src/ReCaptcha.tsx","../src/withReCaptcha.tsx"],"sourcesContent":["/**\r\n * Function to generate the src for the script tag\r\n * Refs: https://developers.google.com/recaptcha/docs/loading\r\n */\r\nexport const getRecaptchaScriptSrc = ({\r\n reCaptchaKey,\r\n language,\r\n useRecaptchaNet = false,\r\n useEnterprise = false,\r\n}: {\r\n reCaptchaKey?: string;\r\n language?: string;\r\n useRecaptchaNet?: boolean;\r\n useEnterprise?: boolean;\r\n} = {}): string => {\r\n const hostName = useRecaptchaNet ? \"recaptcha.net\" : \"google.com\";\r\n const script = useEnterprise ? \"enterprise.js\" : \"api.js\";\r\n\r\n let src = `https://www.${hostName}/recaptcha/${script}?`;\r\n if (reCaptchaKey) src += `render=${reCaptchaKey}`;\r\n if (language) src += `&hl=${language}`;\r\n\r\n return src;\r\n};\r\n","import React, {\r\n useMemo,\r\n useState,\r\n useEffect,\r\n useCallback,\r\n useContext,\r\n createContext,\r\n useDebugValue,\r\n} from \"react\";\r\nimport Script, { ScriptProps } from \"next/script\";\r\nimport type { IReCaptcha } from \"./recaptcha.types\";\r\nimport { getRecaptchaScriptSrc } from \"./utils\";\r\n\r\ninterface ReCaptchaContextProps {\r\n /** reCAPTCHA_site_key */\r\n readonly reCaptchaKey: string | null;\r\n /** Global ReCaptcha object */\r\n readonly grecaptcha: IReCaptcha | null;\r\n /** Is ReCaptcha script loaded */\r\n readonly loaded: boolean;\r\n /** Is ReCaptcha failed to load */\r\n readonly error: boolean;\r\n}\r\n\r\nconst ReCaptchaContext = createContext<ReCaptchaContextProps>({\r\n reCaptchaKey: null,\r\n grecaptcha: null,\r\n loaded: false,\r\n error: false,\r\n});\r\n\r\nconst useReCaptchaContext = () => {\r\n const values = useContext(ReCaptchaContext);\r\n useDebugValue(`grecaptcha available: ${values?.loaded ? \"Yes\" : \"No\"}`);\r\n useDebugValue(`ReCaptcha Script: ${values?.loaded ? \"Loaded\" : \"Not Loaded\"}`);\r\n useDebugValue(`Failed to load Script: ${values?.error ? \"Yes\" : \"No\"}`);\r\n return values;\r\n};\r\n\r\ninterface ReCaptchaProviderProps extends Partial<Omit<ScriptProps, \"onLoad\">> {\r\n reCaptchaKey?: string;\r\n language?: string;\r\n useRecaptchaNet?: boolean;\r\n useEnterprise?: boolean;\r\n children?: React.ReactNode;\r\n onLoad?: (grecaptcha: IReCaptcha, e: any) => void;\r\n}\r\n\r\nconst ReCaptchaProvider: React.FC<ReCaptchaProviderProps> = ({\r\n reCaptchaKey: passedReCaptchaKey,\r\n\r\n useEnterprise = false,\r\n useRecaptchaNet = false,\r\n language,\r\n children,\r\n\r\n id = \"google-recaptcha-v3\",\r\n strategy = \"afterInteractive\",\r\n\r\n src: passedSrc,\r\n onLoad: passedOnLoad,\r\n onError: passedOnError,\r\n\r\n ...props\r\n}) => {\r\n const [grecaptcha, setGreCaptcha] = useState<IReCaptcha | null>(null);\r\n const [loaded, setLoaded] = useState(false);\r\n const [error, setError] = useState(false);\r\n\r\n const reCaptchaKey = passedReCaptchaKey || process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY || null;\r\n\r\n const src =\r\n passedSrc ||\r\n getRecaptchaScriptSrc({ reCaptchaKey, language, useRecaptchaNet, useEnterprise }) ||\r\n null;\r\n\r\n // Reset state when script src is changed\r\n useEffect(() => {\r\n setLoaded(false);\r\n setError(false);\r\n }, [src]);\r\n\r\n // Handle script load\r\n const onLoad = useCallback(\r\n (e?: any) => {\r\n const grecaptcha = useEnterprise ? window?.grecaptcha?.enterprise : window?.grecaptcha;\r\n\r\n if (grecaptcha) {\r\n grecaptcha.ready(() => {\r\n setGreCaptcha(grecaptcha);\r\n setLoaded(true);\r\n passedOnLoad?.(grecaptcha, e);\r\n });\r\n }\r\n },\r\n [passedOnLoad, useEnterprise],\r\n );\r\n\r\n // Run 'onLoad' function once just in case if grecaptcha is already globally available in window\r\n useEffect(() => onLoad(), [onLoad]);\r\n\r\n // Handle script error\r\n const onError = useCallback(\r\n (e: any) => {\r\n setError(true);\r\n passedOnError?.(e);\r\n },\r\n [passedOnError],\r\n );\r\n\r\n // Prevent unnecessary rerenders\r\n const value = useMemo(\r\n () => ({ reCaptchaKey, grecaptcha, loaded, error }),\r\n [reCaptchaKey, grecaptcha, loaded, error],\r\n );\r\n\r\n return (\r\n <ReCaptchaContext.Provider value={value}>\r\n {children}\r\n <Script id={id} src={src} strategy={strategy} onLoad={onLoad} onError={onError} {...props} />\r\n </ReCaptchaContext.Provider>\r\n );\r\n};\r\n\r\nexport { ReCaptchaContext, useReCaptchaContext, ReCaptchaProvider };\r\nexport type { ReCaptchaContextProps, ReCaptchaProviderProps };\r\n","import { useCallback } from \"react\";\r\nimport { useReCaptchaContext } from \"./ReCaptchaProvider\";\r\nimport type { ReCaptchaContextProps } from \"./ReCaptchaProvider\";\r\n\r\nexport interface useReCaptchaProps extends ReCaptchaContextProps {\r\n executeRecaptcha: (action: string) => Promise<string>;\r\n}\r\n\r\n/** React Hook to generate ReCaptcha token\r\n * @example\r\n * const { executeRecaptcha } = useReCaptcha()\r\n */\r\nconst useReCaptcha = (reCaptchaKey?: string): useReCaptchaProps => {\r\n const { grecaptcha, reCaptchaKey: contextReCaptchaKey, ...contextProps } = useReCaptchaContext();\r\n\r\n const siteKey = reCaptchaKey || contextReCaptchaKey;\r\n\r\n const executeRecaptcha = useCallback(\r\n async (action: string) => {\r\n if (typeof grecaptcha?.execute !== \"function\") {\r\n throw new Error(\"Recaptcha has not been loaded\");\r\n }\r\n\r\n const result = await grecaptcha.execute(siteKey, { action });\r\n\r\n return result;\r\n },\r\n [grecaptcha, siteKey],\r\n );\r\n\r\n return { ...contextProps, grecaptcha, reCaptchaKey: siteKey, executeRecaptcha };\r\n};\r\n\r\nexport { useReCaptcha };\r\n","import { useEffect } from \"react\";\r\nimport { useReCaptcha } from \"./useReCaptcha\";\r\n\r\ninterface ReCaptchaProps {\r\n onValidate: (token: string) => void;\r\n action: string;\r\n validate?: boolean;\r\n reCaptchaKey?: string;\r\n}\r\n\r\n/** React Component to generate ReCaptcha token\r\n * @example\r\n * <ReCaptcha action='form-submit' onValidate={handleToken} />\r\n */\r\nconst ReCaptcha: React.FC<ReCaptchaProps> = ({\r\n action,\r\n onValidate,\r\n validate = true,\r\n reCaptchaKey,\r\n}) => {\r\n const { executeRecaptcha } = useReCaptcha(reCaptchaKey);\r\n\r\n useEffect(() => {\r\n if (!validate) return;\r\n if (typeof executeRecaptcha !== \"function\") return;\r\n if (typeof onValidate !== \"function\") return;\r\n\r\n const handleExecuteRecaptcha = async () => {\r\n const token = await executeRecaptcha(action);\r\n onValidate(token);\r\n };\r\n\r\n handleExecuteRecaptcha();\r\n }, [action, onValidate, validate, executeRecaptcha]);\r\n\r\n return null;\r\n};\r\n\r\nexport { ReCaptcha };\r\nexport type { ReCaptchaProps };\r\n","import React from \"react\";\r\nimport { useReCaptcha } from \"./useReCaptcha\";\r\nimport type { useReCaptchaProps } from \"./useReCaptcha\";\r\n\r\ninterface WithReCaptchaProps extends useReCaptchaProps {}\r\n\r\n/** React HOC to generate ReCaptcha token\r\n * @example\r\n * withReCaptcha(MyComponent)\r\n */\r\nfunction withReCaptcha<T extends WithReCaptchaProps = WithReCaptchaProps>(\r\n WrappedComponent: React.ComponentType<T>,\r\n) {\r\n // Try to create a nice displayName for React Dev Tools.\r\n const displayName = WrappedComponent.displayName || WrappedComponent.name || \"Component\";\r\n\r\n // Creating the inner component. The calculated Props type here is the where the magic happens.\r\n const ComponentWithReCaptca = (props: Omit<T, keyof WithReCaptchaProps>) => {\r\n const reCaptchaProps = useReCaptcha();\r\n\r\n // Pass current token and function to generate it to the component\r\n return <WrappedComponent {...reCaptchaProps} {...(props as T)} />;\r\n };\r\n\r\n ComponentWithReCaptca.displayName = `withReCaptcha(${displayName})`;\r\n\r\n return ComponentWithReCaptca;\r\n}\r\n\r\nexport { withReCaptcha };\r\nexport type { WithReCaptchaProps };\r\n"],"names":["ReCaptchaContext","createContext","reCaptchaKey","grecaptcha","loaded","error","useReCaptchaContext","values","useContext","useDebugValue","ReCaptchaProvider","_a","passedReCaptchaKey","useEnterprise","useRecaptchaNet","language","children","id","strategy","src","passedSrc","onLoad","passedOnLoad","onError","passedOnError","props","__rest","setGreCaptcha","useState","setLoaded","setError","process","env","NEXT_PUBLIC_RECAPTCHA_SITE_KEY","getRecaptchaScriptSrc","useEffect","useCallback","e","window","enterprise","ready","value","useMemo","React","Provider","createElement","Script","Object","assign","useReCaptcha","contextReCaptchaKey","contextProps","siteKey","executeRecaptcha","action","__awaiter","execute","Error","ReCaptcha","onValidate","validate","token","withReCaptcha","WrappedComponent","displayName","name","ComponentWithReCaptca","reCaptchaProps"],"mappings":"kxBAIO,MCoBDA,EAAmBC,EAAqC,CAC5DC,aAAc,KACdC,WAAY,KACZC,QAAQ,EACRC,OAAO,IAGHC,EAAsB,KAC1B,MAAMC,EAASC,EAAWR,GAI1B,OAHAS,EAAc,2BAAyBF,aAAM,EAANA,EAAQH,QAAS,MAAQ,OAChEK,EAAc,uBAAqBF,aAAM,EAANA,EAAQH,QAAS,SAAW,eAC/DK,EAAc,4BAA0BF,aAAM,EAANA,EAAQF,OAAQ,MAAQ,OACzDE,CAAM,EAYTG,EAAuDC,IAAA,IAC3DT,aAAcU,EAAkBC,cAEhCA,GAAgB,EAAKC,gBACrBA,GAAkB,EAAKC,SACvBA,EAAQC,SACRA,EAAQC,GAERA,EAAK,sBAAqBC,SAC1BA,EAAW,mBAEXC,IAAKC,EACLC,OAAQC,EACRC,QAASC,GAAab,EAEnBc,EAAKC,EAAAf,EAfmD,mHAiB3D,MAAOR,EAAYwB,GAA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wBC,EAApDzB,EAAAf,EAAA,CAAA,aAAA,iBAEAyC,EAAUlD,GAAgBgD,EAE1BG,EAAmBjB,GAChBkB,GAAkBC,OAAA,OAAA,OAAA,GAAA,YACvB,GAAmC,mBAAxBpD,aAAU,EAAVA,EAAYqD,SACrB,MAAM,IAAIC,MAAM,iCAKlB,aAFqBtD,EAAWqD,QAAQJ,EAAS,CAAEE,UAGpD,KACD,CAACnD,EAAYiD,IAGf,OAAYL,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EAAAG,IAAchD,aAAYD,aAAckD,EAASC,oBAAmB,EChB5EK,EAAsC,EAC1CJ,SACAK,aACAC,YAAW,EACX1D,mBAEA,MAAMmD,iBAAEA,GAAqBJ,EAAa/C,GAe1C,OAbAiC,GAAU,KACR,IAAKyB,EAAU,OACf,GAAgC,mBAArBP,EAAiC,OAC5C,GAA0B,mBAAfM,EAA2B,OAEIJ,OAAA,OAAA,OAAA,GAAA,YACxC,MAAMM,QAAcR,EAAiBC,GACrCK,EAAWE,EACb,GAEwB,GACvB,CAACP,EAAQK,EAAYC,EAAUP,IAE3B,IAAI,ECzBb,SAASS,EACPC,GAGA,MAAMC,EAAcD,EAAiBC,aAAeD,EAAiBE,MAAQ,YAGvEC,EAAyBzC,IAC7B,MAAM0C,EAAiBlB,IAGvB,OAAON,gBAACoB,EAAgBhB,OAAAC,OAAA,GAAKmB,EAAqB1C,GAAe,EAKnE,OAFAyC,EAAsBF,YAAc,iBAAiBA,KAE9CE,CACT"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/ReCaptchaProvider.tsx","../src/useReCaptcha.tsx","../src/ReCaptcha.tsx","../src/withReCaptcha.tsx"],"sourcesContent":["/**\r\n * Function to generate the src for the script tag\r\n * Refs: https://developers.google.com/recaptcha/docs/loading\r\n */\r\nexport const getRecaptchaScriptSrc = ({\r\n reCaptchaKey,\r\n language,\r\n useRecaptchaNet = false,\r\n useEnterprise = false,\r\n}: {\r\n reCaptchaKey?: string;\r\n language?: string;\r\n useRecaptchaNet?: boolean;\r\n useEnterprise?: boolean;\r\n} = {}): string => {\r\n const hostName = useRecaptchaNet ? \"recaptcha.net\" : \"google.com\";\r\n const script = useEnterprise ? \"enterprise.js\" : \"api.js\";\r\n\r\n let src = `https://www.${hostName}/recaptcha/${script}?`;\r\n if (reCaptchaKey) src += `render=${reCaptchaKey}`;\r\n if (language) src += `&hl=${language}`;\r\n\r\n return src;\r\n};\r\n","import React, {\r\n useMemo,\r\n useState,\r\n useEffect,\r\n useCallback,\r\n useContext,\r\n createContext,\r\n useDebugValue,\r\n} from \"react\";\r\nimport Script, { ScriptProps } from \"next/script\";\r\nimport type { IReCaptcha } from \"./recaptcha.types\";\r\nimport { getRecaptchaScriptSrc } from \"./utils\";\r\n\r\ninterface ReCaptchaContextProps {\r\n /** reCAPTCHA_site_key */\r\n readonly reCaptchaKey: string | null;\r\n /** Global ReCaptcha object */\r\n readonly grecaptcha: IReCaptcha | null;\r\n /** Is ReCaptcha script loaded */\r\n readonly loaded: boolean;\r\n /** Is ReCaptcha failed to load */\r\n readonly error: boolean;\r\n}\r\n\r\nconst ReCaptchaContext = createContext<ReCaptchaContextProps>({\r\n reCaptchaKey: null,\r\n grecaptcha: null,\r\n loaded: false,\r\n error: false,\r\n});\r\n\r\nconst useReCaptchaContext = () => {\r\n const values = useContext(ReCaptchaContext);\r\n useDebugValue(`grecaptcha available: ${values?.loaded ? \"Yes\" : \"No\"}`);\r\n useDebugValue(`ReCaptcha Script: ${values?.loaded ? \"Loaded\" : \"Not Loaded\"}`);\r\n useDebugValue(`Failed to load Script: ${values?.error ? \"Yes\" : \"No\"}`);\r\n return values;\r\n};\r\n\r\ninterface ReCaptchaProviderProps extends Partial<Omit<ScriptProps, \"onLoad\">> {\r\n reCaptchaKey?: string;\r\n language?: string;\r\n useRecaptchaNet?: boolean;\r\n useEnterprise?: boolean;\r\n children?: React.ReactNode;\r\n onLoad?: (grecaptcha: IReCaptcha, e: any) => void;\r\n}\r\n\r\nconst ReCaptchaProvider: React.FC<ReCaptchaProviderProps> = ({\r\n reCaptchaKey: passedReCaptchaKey,\r\n\r\n useEnterprise = false,\r\n useRecaptchaNet = false,\r\n language,\r\n children,\r\n\r\n id = \"google-recaptcha-v3\",\r\n strategy = \"afterInteractive\",\r\n\r\n src: passedSrc,\r\n onLoad: passedOnLoad,\r\n onError: passedOnError,\r\n\r\n ...props\r\n}) => {\r\n const [grecaptcha, setGreCaptcha] = useState<IReCaptcha | null>(null);\r\n const [loaded, setLoaded] = useState(false);\r\n const [error, setError] = useState(false);\r\n\r\n const reCaptchaKey = passedReCaptchaKey || process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY || null;\r\n\r\n const src =\r\n passedSrc ||\r\n getRecaptchaScriptSrc({ reCaptchaKey, language, useRecaptchaNet, useEnterprise }) ||\r\n null;\r\n\r\n // Reset state when script src is changed\r\n useEffect(() => {\r\n setLoaded(false);\r\n setError(false);\r\n }, [src]);\r\n\r\n // Handle script load\r\n const onLoad = useCallback(\r\n (e?: any) => {\r\n const grecaptcha = useEnterprise ? window?.grecaptcha?.enterprise : window?.grecaptcha;\r\n\r\n if (grecaptcha) {\r\n grecaptcha.ready(() => {\r\n setGreCaptcha(grecaptcha);\r\n setLoaded(true);\r\n passedOnLoad?.(grecaptcha, e);\r\n });\r\n }\r\n },\r\n [passedOnLoad, useEnterprise],\r\n );\r\n\r\n // Run 'onLoad' function once just in case if grecaptcha is already globally available in window\r\n useEffect(() => onLoad(), [onLoad]);\r\n\r\n // Handle script error\r\n const onError = useCallback(\r\n (e: any) => {\r\n setError(true);\r\n passedOnError?.(e);\r\n },\r\n [passedOnError],\r\n );\r\n\r\n // Prevent unnecessary rerenders\r\n const value = useMemo(\r\n () => ({ reCaptchaKey, grecaptcha, loaded, error }),\r\n [reCaptchaKey, grecaptcha, loaded, error],\r\n );\r\n\r\n return (\r\n <ReCaptchaContext.Provider value={value}>\r\n {children}\r\n <Script id={id} src={src} strategy={strategy} onLoad={onLoad} onError={onError} {...props} />\r\n </ReCaptchaContext.Provider>\r\n );\r\n};\r\n\r\nexport { ReCaptchaContext, useReCaptchaContext, ReCaptchaProvider };\r\nexport type { ReCaptchaContextProps, ReCaptchaProviderProps };\r\n","import { useCallback } from \"react\";\r\nimport { useReCaptchaContext } from \"./ReCaptchaProvider\";\r\nimport type { ReCaptchaContextProps } from \"./ReCaptchaProvider\";\r\n\r\nexport interface useReCaptchaProps extends ReCaptchaContextProps {\r\n executeRecaptcha: (action: string) => Promise<string>;\r\n}\r\n\r\n/** React Hook to generate ReCaptcha token\r\n * @example\r\n * const { executeRecaptcha } = useReCaptcha()\r\n */\r\nconst useReCaptcha = (passedReCaptchaKey?: string): useReCaptchaProps => {\r\n const { grecaptcha, reCaptchaKey, ...contextProps } = useReCaptchaContext();\r\n\r\n const siteKey = passedReCaptchaKey || reCaptchaKey;\r\n\r\n const executeRecaptcha = useCallback(\r\n async (action: string) => {\r\n if (typeof grecaptcha?.execute !== \"function\") {\r\n throw new Error(\"Recaptcha has not been loaded\");\r\n }\r\n\r\n const result = await grecaptcha.execute(siteKey, { action });\r\n\r\n return result;\r\n },\r\n [grecaptcha, siteKey],\r\n );\r\n\r\n return { ...contextProps, grecaptcha, reCaptchaKey: siteKey, executeRecaptcha };\r\n};\r\n\r\nexport { useReCaptcha };\r\n","import { useEffect } from \"react\";\r\nimport { useReCaptcha } from \"./useReCaptcha\";\r\n\r\ninterface ReCaptchaProps {\r\n onValidate: (token: string) => void;\r\n action: string;\r\n validate?: boolean;\r\n reCaptchaKey?: string;\r\n}\r\n\r\n/** React Component to generate ReCaptcha token\r\n * @example\r\n * <ReCaptcha action='form-submit' onValidate={handleToken} />\r\n */\r\nconst ReCaptcha: React.FC<ReCaptchaProps> = ({\r\n action,\r\n onValidate,\r\n validate = true,\r\n reCaptchaKey,\r\n}) => {\r\n const { executeRecaptcha } = useReCaptcha(reCaptchaKey);\r\n\r\n useEffect(() => {\r\n if (!validate) return;\r\n if (typeof executeRecaptcha !== \"function\") return;\r\n if (typeof onValidate !== \"function\") return;\r\n\r\n const handleExecuteRecaptcha = async () => {\r\n const token = await executeRecaptcha(action);\r\n onValidate(token);\r\n };\r\n\r\n handleExecuteRecaptcha();\r\n }, [action, onValidate, validate, executeRecaptcha]);\r\n\r\n return null;\r\n};\r\n\r\nexport { ReCaptcha };\r\nexport type { ReCaptchaProps };\r\n","import React from \"react\";\r\nimport { useReCaptcha } from \"./useReCaptcha\";\r\nimport type { useReCaptchaProps } from \"./useReCaptcha\";\r\n\r\ninterface WithReCaptchaProps extends useReCaptchaProps {}\r\n\r\n/** React HOC to generate ReCaptcha token\r\n * @example\r\n * withReCaptcha(MyComponent)\r\n */\r\nfunction withReCaptcha<T extends WithReCaptchaProps = WithReCaptchaProps>(\r\n WrappedComponent: React.ComponentType<T>,\r\n) {\r\n // Try to create a nice displayName for React Dev Tools.\r\n const displayName = WrappedComponent.displayName || WrappedComponent.name || \"Component\";\r\n\r\n // Creating the inner component. The calculated Props type here is the where the magic happens.\r\n const ComponentWithReCaptca = (props: Omit<T, keyof WithReCaptchaProps>) => {\r\n const reCaptchaProps = useReCaptcha();\r\n\r\n // Pass current token and function to generate it to the component\r\n return <WrappedComponent {...reCaptchaProps} {...(props as T)} />;\r\n };\r\n\r\n ComponentWithReCaptca.displayName = `withReCaptcha(${displayName})`;\r\n\r\n return ComponentWithReCaptca;\r\n}\r\n\r\nexport { withReCaptcha };\r\nexport type { WithReCaptchaProps };\r\n"],"names":["ReCaptchaContext","createContext","reCaptchaKey","grecaptcha","loaded","error","useReCaptchaContext","values","useContext","useDebugValue","useReCaptcha","passedReCaptchaKey","_a","contextProps","__rest","siteKey","executeRecaptcha","useCallback","action","__awaiter","execute","Error","Object","assign","onValidate","validate","useEffect","token","useEnterprise","useRecaptchaNet","language","children","id","strategy","src","passedSrc","onLoad","passedOnLoad","onError","passedOnError","props","setGreCaptcha","useState","setLoaded","setError","process","env","NEXT_PUBLIC_RECAPTCHA_SITE_KEY","getRecaptchaScriptSrc","e","window","enterprise","ready","value","useMemo","React","Provider","createElement","Script","WrappedComponent","displayName","name","ComponentWithReCaptca","reCaptchaProps"],"mappings":"8zBAIO,MCoBDA,EAAmBC,EAAAA,cAAqC,CAC5DC,aAAc,KACdC,WAAY,KACZC,QAAQ,EACRC,OAAO,IAGHC,EAAsB,KAC1B,MAAMC,EAASC,aAAWR,GAI1B,OAHAS,EAAaA,cAAC,2BAAyBF,aAAM,EAANA,EAAQH,QAAS,MAAQ,OAChEK,EAAaA,cAAC,uBAAqBF,aAAM,EAANA,EAAQH,QAAS,SAAW,eAC/DK,EAAaA,cAAC,4BAA0BF,aAAM,EAANA,EAAQF,OAAQ,MAAQ,OACzDE,CAAM,ECxBTG,EAAgBC,IACpB,MAAMC,EAAgDN,KAAhDH,WAAEA,EAAUD,aAAEA,GAAYU,EAAKC,EAA/BC,EAAAF,EAAA,CAAA,aAAA,iBAEAG,EAAUJ,GAAsBT,EAEhCc,EAAmBC,eAChBC,GAAkBC,OAAA,OAAA,OAAA,GAAA,YACvB,GAAmC,mBAAxBhB,aAAU,EAAVA,EAAYiB,SACrB,MAAM,IAAIC,MAAM,iCAKlB,aAFqBlB,EAAWiB,QAAQL,EAAS,CAAEG,UAGpD,KACD,CAACf,EAAYY,IAGf,OAAYO,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EAAAV,IAAcV,aAAYD,aAAca,EAASC,oBAAmB,oBChBtC,EAC1CE,SACAM,aACAC,YAAW,EACXvB,mBAEA,MAAMc,iBAAEA,GAAqBN,EAAaR,GAe1C,OAbAwB,EAAAA,WAAU,KACR,IAAKD,EAAU,OACf,GAAgC,mBAArBT,EAAiC,OAC5C,GAA0B,mBAAfQ,EAA2B,OAEIL,OAAA,OAAA,OAAA,GAAA,YACxC,MAAMQ,QAAcX,EAAiBE,GACrCM,EAAWG,EACb,GAEwB,GACvB,CAACT,EAAQM,EAAYC,EAAUT,IA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pD,eAAcC,aAAYC,SAAQC,WAC3C,CAACH,EAAcC,EAAYC,EAAQC,IAGrC,OACEkD,EAAAA,sBAACvD,EAAiBwD,SAAS,CAAAH,MAAOA,GAC/BtB,EACDwB,UAACE,cAAAC,EAAAA,QAAOpC,OAAAC,OAAA,CAAAS,GAAIA,EAAIE,IAAKA,EAAKD,SAAUA,EAAUG,OAAQA,EAAQE,QAASA,GAAaE,IAEtF,6EG/GJ,SACEmB,GAGA,MAAMC,EAAcD,EAAiBC,aAAeD,EAAiBE,MAAQ,YAGvEC,EAAyBtB,IAC7B,MAAMuB,EAAiBrD,IAGvB,OAAO6C,wBAACI,EAAgBrC,OAAAC,OAAA,GAAKwC,EAAqBvB,GAAe,EAKnE,OAFAsB,EAAsBF,YAAc,iBAAiBA,KAE9CE,CACT"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/ReCaptchaProvider.tsx","../src/useReCaptcha.tsx","../src/ReCaptcha.tsx","../src/withReCaptcha.tsx"],"sourcesContent":["/**\r\n * Function to generate the src for the script tag\r\n * Refs: https://developers.google.com/recaptcha/docs/loading\r\n */\r\nexport const getRecaptchaScriptSrc = ({\r\n reCaptchaKey,\r\n language,\r\n useRecaptchaNet = false,\r\n useEnterprise = false,\r\n}: {\r\n reCaptchaKey?: string;\r\n language?: string;\r\n useRecaptchaNet?: boolean;\r\n useEnterprise?: boolean;\r\n} = {}): string => {\r\n const hostName = useRecaptchaNet ? \"recaptcha.net\" : \"google.com\";\r\n const script = useEnterprise ? \"enterprise.js\" : \"api.js\";\r\n\r\n let src = `https://www.${hostName}/recaptcha/${script}?`;\r\n if (reCaptchaKey) src += `render=${reCaptchaKey}`;\r\n if (language) src += `&hl=${language}`;\r\n\r\n return src;\r\n};\r\n","import React, {\r\n useMemo,\r\n useState,\r\n useEffect,\r\n useCallback,\r\n useContext,\r\n createContext,\r\n useDebugValue,\r\n} from \"react\";\r\nimport Script, { ScriptProps } from \"next/script\";\r\nimport type { IReCaptcha } from \"./recaptcha.types\";\r\nimport { getRecaptchaScriptSrc } from \"./utils\";\r\n\r\ninterface ReCaptchaContextProps {\r\n /** reCAPTCHA_site_key */\r\n readonly reCaptchaKey: string | null;\r\n /** Global ReCaptcha object */\r\n readonly grecaptcha: IReCaptcha | null;\r\n /** Is ReCaptcha script loaded */\r\n readonly loaded: boolean;\r\n /** Is ReCaptcha failed to load */\r\n readonly error: boolean;\r\n}\r\n\r\nconst ReCaptchaContext = createContext<ReCaptchaContextProps>({\r\n reCaptchaKey: null,\r\n grecaptcha: null,\r\n loaded: false,\r\n error: false,\r\n});\r\n\r\nconst useReCaptchaContext = () => {\r\n const values = useContext(ReCaptchaContext);\r\n useDebugValue(`grecaptcha available: ${values?.loaded ? \"Yes\" : \"No\"}`);\r\n useDebugValue(`ReCaptcha Script: ${values?.loaded ? \"Loaded\" : \"Not Loaded\"}`);\r\n useDebugValue(`Failed to load Script: ${values?.error ? \"Yes\" : \"No\"}`);\r\n return values;\r\n};\r\n\r\ninterface ReCaptchaProviderProps extends Partial<Omit<ScriptProps, \"onLoad\">> {\r\n reCaptchaKey?: string;\r\n language?: string;\r\n useRecaptchaNet?: boolean;\r\n useEnterprise?: boolean;\r\n children?: React.ReactNode;\r\n onLoad?: (grecaptcha: IReCaptcha, e: any) => void;\r\n}\r\n\r\nconst ReCaptchaProvider: React.FC<ReCaptchaProviderProps> = ({\r\n reCaptchaKey: passedReCaptchaKey,\r\n\r\n useEnterprise = false,\r\n useRecaptchaNet = false,\r\n language,\r\n children,\r\n\r\n id = \"google-recaptcha-v3\",\r\n strategy = \"afterInteractive\",\r\n\r\n src: passedSrc,\r\n onLoad: passedOnLoad,\r\n onError: passedOnError,\r\n\r\n ...props\r\n}) => {\r\n const [grecaptcha, setGreCaptcha] = useState<IReCaptcha | null>(null);\r\n const [loaded, setLoaded] = useState(false);\r\n const [error, setError] = useState(false);\r\n\r\n const reCaptchaKey = passedReCaptchaKey || process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY || null;\r\n\r\n const src =\r\n passedSrc ||\r\n getRecaptchaScriptSrc({ reCaptchaKey, language, useRecaptchaNet, useEnterprise }) ||\r\n null;\r\n\r\n // Reset state when script src is changed\r\n useEffect(() => {\r\n setLoaded(false);\r\n setError(false);\r\n }, [src]);\r\n\r\n // Handle script load\r\n const onLoad = useCallback(\r\n (e?: any) => {\r\n const grecaptcha = useEnterprise ? window?.grecaptcha?.enterprise : window?.grecaptcha;\r\n\r\n if (grecaptcha) {\r\n grecaptcha.ready(() => {\r\n setGreCaptcha(grecaptcha);\r\n setLoaded(true);\r\n passedOnLoad?.(grecaptcha, e);\r\n });\r\n }\r\n },\r\n [passedOnLoad, useEnterprise],\r\n );\r\n\r\n // Run 'onLoad' function once just in case if grecaptcha is already globally available in window\r\n useEffect(() => onLoad(), [onLoad]);\r\n\r\n // Handle script error\r\n const onError = useCallback(\r\n (e: any) => {\r\n setError(true);\r\n passedOnError?.(e);\r\n },\r\n [passedOnError],\r\n );\r\n\r\n // Prevent unnecessary rerenders\r\n const value = useMemo(\r\n () => ({ reCaptchaKey, grecaptcha, loaded, error }),\r\n [reCaptchaKey, grecaptcha, loaded, error],\r\n );\r\n\r\n return (\r\n <ReCaptchaContext.Provider value={value}>\r\n {children}\r\n <Script id={id} src={src} strategy={strategy} onLoad={onLoad} onError={onError} {...props} />\r\n </ReCaptchaContext.Provider>\r\n );\r\n};\r\n\r\nexport { ReCaptchaContext, useReCaptchaContext, ReCaptchaProvider };\r\nexport type { ReCaptchaContextProps, ReCaptchaProviderProps };\r\n","import { useCallback } from \"react\";\r\nimport { useReCaptchaContext } from \"./ReCaptchaProvider\";\r\nimport type { ReCaptchaContextProps } from \"./ReCaptchaProvider\";\r\n\r\nexport interface useReCaptchaProps extends ReCaptchaContextProps {\r\n executeRecaptcha: (action: string) => Promise<string>;\r\n}\r\n\r\n/** React Hook to generate ReCaptcha token\r\n * @example\r\n * const { executeRecaptcha } = useReCaptcha()\r\n */\r\nconst useReCaptcha = (reCaptchaKey?: string): useReCaptchaProps => {\r\n const { grecaptcha, reCaptchaKey: contextReCaptchaKey, ...contextProps } = useReCaptchaContext();\r\n\r\n const siteKey = reCaptchaKey || contextReCaptchaKey;\r\n\r\n const executeRecaptcha = useCallback(\r\n async (action: string) => {\r\n if (typeof grecaptcha?.execute !== \"function\") {\r\n throw new Error(\"Recaptcha has not been loaded\");\r\n }\r\n\r\n const result = await grecaptcha.execute(siteKey, { action });\r\n\r\n return result;\r\n },\r\n [grecaptcha, siteKey],\r\n );\r\n\r\n return { ...contextProps, grecaptcha, reCaptchaKey: siteKey, executeRecaptcha };\r\n};\r\n\r\nexport { useReCaptcha };\r\n","import { useEffect } from \"react\";\r\nimport { useReCaptcha } from \"./useReCaptcha\";\r\n\r\ninterface ReCaptchaProps {\r\n onValidate: (token: string) => void;\r\n action: string;\r\n validate?: boolean;\r\n reCaptchaKey?: string;\r\n}\r\n\r\n/** React Component to generate ReCaptcha token\r\n * @example\r\n * <ReCaptcha action='form-submit' onValidate={handleToken} />\r\n */\r\nconst ReCaptcha: React.FC<ReCaptchaProps> = ({\r\n action,\r\n onValidate,\r\n validate = true,\r\n reCaptchaKey,\r\n}) => {\r\n const { executeRecaptcha } = useReCaptcha(reCaptchaKey);\r\n\r\n useEffect(() => {\r\n if (!validate) return;\r\n if (typeof executeRecaptcha !== \"function\") return;\r\n if (typeof onValidate !== \"function\") return;\r\n\r\n const handleExecuteRecaptcha = async () => {\r\n const token = await executeRecaptcha(action);\r\n onValidate(token);\r\n };\r\n\r\n handleExecuteRecaptcha();\r\n }, [action, onValidate, validate, executeRecaptcha]);\r\n\r\n return null;\r\n};\r\n\r\nexport { ReCaptcha };\r\nexport type { ReCaptchaProps };\r\n","import React from \"react\";\r\nimport { useReCaptcha } from \"./useReCaptcha\";\r\nimport type { useReCaptchaProps } from \"./useReCaptcha\";\r\n\r\ninterface WithReCaptchaProps extends useReCaptchaProps {}\r\n\r\n/** React HOC to generate ReCaptcha token\r\n * @example\r\n * withReCaptcha(MyComponent)\r\n */\r\nfunction withReCaptcha<T extends WithReCaptchaProps = WithReCaptchaProps>(\r\n WrappedComponent: React.ComponentType<T>,\r\n) {\r\n // Try to create a nice displayName for React Dev Tools.\r\n const displayName = WrappedComponent.displayName || WrappedComponent.name || \"Component\";\r\n\r\n // Creating the inner component. The calculated Props type here is the where the magic happens.\r\n const ComponentWithReCaptca = (props: Omit<T, keyof WithReCaptchaProps>) => {\r\n const reCaptchaProps = useReCaptcha();\r\n\r\n // Pass current token and function to generate it to the component\r\n return <WrappedComponent {...reCaptchaProps} {...(props as T)} />;\r\n };\r\n\r\n ComponentWithReCaptca.displayName = `withReCaptcha(${displayName})`;\r\n\r\n return ComponentWithReCaptca;\r\n}\r\n\r\nexport { withReCaptcha };\r\nexport type { WithReCaptchaProps };\r\n"],"names":["ReCaptchaContext","createContext","reCaptchaKey","grecaptcha","loaded","error","useReCaptchaContext","values","useContext","useDebugValue","useReCaptcha","_a","contextReCaptchaKey","contextProps","__rest","siteKey","executeRecaptcha","useCallback","action","__awaiter","execute","Error","Object","assign","onValidate","validate","useEffect","token","passedReCaptchaKey","useEnterprise","useRecaptchaNet","language","children","id","strategy","src","passedSrc","onLoad","passedOnLoad","onError","passedOnError","props","setGreCaptcha","useState","setLoaded","setError","process","env","NEXT_PUBLIC_RECAPTCHA_SITE_KEY","getRecaptchaScriptSrc","e","window","enterprise","ready","value","useMemo","React","Provider","createElement","Script","WrappedComponent","displayName","name","ComponentWithReCaptca","reCaptchaProps"],"mappings":"8zBAIO,MCoBDA,EAAmBC,EAAAA,cAAqC,CAC5DC,aAAc,KACdC,WAAY,KACZC,QAAQ,EACRC,OAAO,IAGHC,EAAsB,KAC1B,MAAMC,EAASC,aAAWR,GAI1B,OAHAS,EAAaA,cAAC,2BAAyBF,aAAM,EAANA,EAAQH,QAAS,MAAQ,OAChEK,EAAaA,cAAC,uBAAqBF,aAAM,EAANA,EAAQH,QAAS,SAAW,eAC/DK,EAAaA,cAAC,4BAA0BF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AFAsB,EAAsBF,YAAc,iBAAiBA,KAE9CE,CACT"}
|
package/lib/useReCaptcha.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export interface useReCaptchaProps extends ReCaptchaContextProps {
|
|
|
6
6
|
* @example
|
|
7
7
|
* const { executeRecaptcha } = useReCaptcha()
|
|
8
8
|
*/
|
|
9
|
-
declare const useReCaptcha: (
|
|
9
|
+
declare const useReCaptcha: (reCaptchaKey?: string) => useReCaptchaProps;
|
|
10
10
|
export { useReCaptcha };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-recaptcha-v3",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "🤖 Next.js hook to add Google ReCaptcha to your application",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Roman Zhuravlov",
|
|
@@ -39,31 +39,31 @@
|
|
|
39
39
|
"react-dom": ">=16.8.0"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
42
|
+
"node": ">=14.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"next": "^12.3.
|
|
45
|
+
"next": "^12.3.1",
|
|
46
46
|
"react": "^18.2.0",
|
|
47
47
|
"react-dom": "^18.2.0",
|
|
48
48
|
"@rollup/plugin-commonjs": "^22.0.2",
|
|
49
49
|
"@rollup/plugin-node-resolve": "^14.1.0",
|
|
50
|
-
"@types/node": "^18.
|
|
51
|
-
"@types/react": "^18.0.
|
|
50
|
+
"@types/node": "^18.8.2",
|
|
51
|
+
"@types/react": "^18.0.21",
|
|
52
52
|
"@types/react-dom": "^18.0.6",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
54
|
-
"@typescript-eslint/parser": "^5.
|
|
55
|
-
"eslint": "^8.
|
|
56
|
-
"eslint-config-next": "^12.3.
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^5.39.0",
|
|
54
|
+
"@typescript-eslint/parser": "^5.39.0",
|
|
55
|
+
"eslint": "^8.24.0",
|
|
56
|
+
"eslint-config-next": "^12.3.1",
|
|
57
57
|
"eslint-config-prettier": "^8.5.0",
|
|
58
58
|
"husky": "^8.0.1",
|
|
59
59
|
"lint-staged": "^13.0.3",
|
|
60
60
|
"prettier": "^2.7.1",
|
|
61
61
|
"pretty-quick": "^3.1.3",
|
|
62
|
-
"rollup": "^2.79.
|
|
62
|
+
"rollup": "^2.79.1",
|
|
63
63
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
64
64
|
"rollup-plugin-terser": "^7.0.2",
|
|
65
|
-
"rollup-plugin-typescript2": "^0.34.
|
|
66
|
-
"typescript": "^4.8.
|
|
65
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
66
|
+
"typescript": "^4.8.4"
|
|
67
67
|
},
|
|
68
68
|
"lint-staged": {
|
|
69
69
|
"**/*.{js,jsx,ts,tsx}": [
|
package/lib/cjs/ReCaptcha.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ReCaptcha = void 0;
|
|
13
|
-
const react_1 = require("react");
|
|
14
|
-
const useReCaptcha_1 = require("./useReCaptcha");
|
|
15
|
-
/** React Component to generate ReCaptcha token
|
|
16
|
-
* @example
|
|
17
|
-
* <ReCaptcha action='form-submit' onValidate={handleToken} />
|
|
18
|
-
*/
|
|
19
|
-
const ReCaptcha = ({ action, onValidate, validate = true, reCaptchaKey, }) => {
|
|
20
|
-
const { executeRecaptcha } = (0, useReCaptcha_1.useReCaptcha)(reCaptchaKey);
|
|
21
|
-
(0, react_1.useEffect)(() => {
|
|
22
|
-
if (!validate)
|
|
23
|
-
return;
|
|
24
|
-
if (typeof executeRecaptcha !== "function")
|
|
25
|
-
return;
|
|
26
|
-
if (typeof onValidate !== "function")
|
|
27
|
-
return;
|
|
28
|
-
const handleExecuteRecaptcha = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
-
const token = yield executeRecaptcha(action);
|
|
30
|
-
onValidate(token);
|
|
31
|
-
});
|
|
32
|
-
handleExecuteRecaptcha();
|
|
33
|
-
}, [action, onValidate, validate, executeRecaptcha]);
|
|
34
|
-
return null;
|
|
35
|
-
};
|
|
36
|
-
exports.ReCaptcha = ReCaptcha;
|
|
37
|
-
//# sourceMappingURL=ReCaptcha.js.map
|
package/lib/cjs/ReCaptcha.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ReCaptcha.js","sourceRoot":"","sources":["../../src/ReCaptcha.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAkC;AAClC,iDAA8C;AAS9C;;;GAGG;AACH,MAAM,SAAS,GAA6B,CAAC,EAC3C,MAAM,EACN,UAAU,EACV,QAAQ,GAAG,IAAI,EACf,YAAY,GACb,EAAE,EAAE;IACH,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAA,2BAAY,EAAC,YAAY,CAAC,CAAC;IAExD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,QAAQ;YAAE,OAAO;QACtB,IAAI,OAAO,gBAAgB,KAAK,UAAU;YAAE,OAAO;QACnD,IAAI,OAAO,UAAU,KAAK,UAAU;YAAE,OAAO;QAE7C,MAAM,sBAAsB,GAAG,GAAS,EAAE;YACxC,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,MAAM,CAAC,CAAC;YAC7C,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC,CAAA,CAAC;QAEF,sBAAsB,EAAE,CAAC;IAC3B,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAErD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEO,8BAAS"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
-
var t = {};
|
|
27
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
-
t[p] = s[p];
|
|
29
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
-
t[p[i]] = s[p[i]];
|
|
33
|
-
}
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.ReCaptchaProvider = exports.useReCaptchaContext = exports.ReCaptchaContext = void 0;
|
|
41
|
-
const react_1 = __importStar(require("react"));
|
|
42
|
-
const script_1 = __importDefault(require("next/script"));
|
|
43
|
-
const utils_1 = require("./utils");
|
|
44
|
-
const ReCaptchaContext = (0, react_1.createContext)({
|
|
45
|
-
reCaptchaKey: null,
|
|
46
|
-
grecaptcha: null,
|
|
47
|
-
loaded: false,
|
|
48
|
-
error: false,
|
|
49
|
-
});
|
|
50
|
-
exports.ReCaptchaContext = ReCaptchaContext;
|
|
51
|
-
const useReCaptchaContext = () => {
|
|
52
|
-
const values = (0, react_1.useContext)(ReCaptchaContext);
|
|
53
|
-
(0, react_1.useDebugValue)(`grecaptcha available: ${(values === null || values === void 0 ? void 0 : values.loaded) ? "Yes" : "No"}`);
|
|
54
|
-
(0, react_1.useDebugValue)(`ReCaptcha Script: ${(values === null || values === void 0 ? void 0 : values.loaded) ? "Loaded" : "Not Loaded"}`);
|
|
55
|
-
(0, react_1.useDebugValue)(`Failed to load Script: ${(values === null || values === void 0 ? void 0 : values.error) ? "Yes" : "No"}`);
|
|
56
|
-
return values;
|
|
57
|
-
};
|
|
58
|
-
exports.useReCaptchaContext = useReCaptchaContext;
|
|
59
|
-
const ReCaptchaProvider = (_a) => {
|
|
60
|
-
var { reCaptchaKey: passedReCaptchaKey, useEnterprise = false, useRecaptchaNet = false, language, children, id = "google-recaptcha-v3", strategy = "afterInteractive", src: passedSrc, onLoad: passedOnLoad, onError: passedOnError } = _a, props = __rest(_a, ["reCaptchaKey", "useEnterprise", "useRecaptchaNet", "language", "children", "id", "strategy", "src", "onLoad", "onError"]);
|
|
61
|
-
const [grecaptcha, setGreCaptcha] = (0, react_1.useState)(null);
|
|
62
|
-
const [loaded, setLoaded] = (0, react_1.useState)(false);
|
|
63
|
-
const [error, setError] = (0, react_1.useState)(false);
|
|
64
|
-
const reCaptchaKey = passedReCaptchaKey || process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY || null;
|
|
65
|
-
const src = passedSrc ||
|
|
66
|
-
(0, utils_1.getRecaptchaScriptSrc)({ reCaptchaKey, language, useRecaptchaNet, useEnterprise }) ||
|
|
67
|
-
null;
|
|
68
|
-
// Reset state when script src is changed
|
|
69
|
-
(0, react_1.useEffect)(() => {
|
|
70
|
-
setLoaded(false);
|
|
71
|
-
setError(false);
|
|
72
|
-
}, [src]);
|
|
73
|
-
// Handle script load
|
|
74
|
-
const onLoad = (0, react_1.useCallback)((e) => {
|
|
75
|
-
var _a;
|
|
76
|
-
const grecaptcha = useEnterprise ? (_a = window === null || window === void 0 ? void 0 : window.grecaptcha) === null || _a === void 0 ? void 0 : _a.enterprise : window === null || window === void 0 ? void 0 : window.grecaptcha;
|
|
77
|
-
if (grecaptcha) {
|
|
78
|
-
grecaptcha.ready(() => {
|
|
79
|
-
setGreCaptcha(grecaptcha);
|
|
80
|
-
setLoaded(true);
|
|
81
|
-
passedOnLoad === null || passedOnLoad === void 0 ? void 0 : passedOnLoad(grecaptcha, e);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}, [passedOnLoad, useEnterprise]);
|
|
85
|
-
// Run 'onLoad' function once just in case if grecaptcha is already globally available in window
|
|
86
|
-
(0, react_1.useEffect)(() => onLoad(), [onLoad]);
|
|
87
|
-
// Handle script error
|
|
88
|
-
const onError = (0, react_1.useCallback)((e) => {
|
|
89
|
-
setError(true);
|
|
90
|
-
passedOnError === null || passedOnError === void 0 ? void 0 : passedOnError(e);
|
|
91
|
-
}, [passedOnError]);
|
|
92
|
-
// Prevent unnecessary rerenders
|
|
93
|
-
const value = (0, react_1.useMemo)(() => ({ reCaptchaKey, grecaptcha, loaded, error }), [reCaptchaKey, grecaptcha, loaded, error]);
|
|
94
|
-
return (react_1.default.createElement(ReCaptchaContext.Provider, { value: value },
|
|
95
|
-
children,
|
|
96
|
-
react_1.default.createElement(script_1.default, Object.assign({ id: id, src: src, strategy: strategy, onLoad: onLoad, onError: onError }, props))));
|
|
97
|
-
};
|
|
98
|
-
exports.ReCaptchaProvider = ReCaptchaProvider;
|
|
99
|
-
//# sourceMappingURL=ReCaptchaProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ReCaptchaProvider.js","sourceRoot":"","sources":["../../src/ReCaptchaProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAQe;AACf,yDAAkD;AAElD,mCAAgD;AAahD,MAAM,gBAAgB,GAAG,IAAA,qBAAa,EAAwB;IAC5D,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,IAAI;IAChB,MAAM,EAAE,KAAK;IACb,KAAK,EAAE,KAAK;CACb,CAAC,CAAC;AA+FM,4CAAgB;AA7FzB,MAAM,mBAAmB,GAAG,GAAG,EAAE;IAC/B,MAAM,MAAM,GAAG,IAAA,kBAAU,EAAC,gBAAgB,CAAC,CAAC;IAC5C,IAAA,qBAAa,EAAC,yBAAyB,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,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,CAAC,CAC1C,CAAC;IAEF,OAAO,CACL,8BAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK;QACpC,QAAQ;QACT,8BAAC,gBAAM,kBAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,IAAM,KAAK,EAAI,CACnE,CAC7B,CAAC;AACJ,CAAC,CAAC;AAE8C,8CAAiB"}
|
package/lib/cjs/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./recaptcha.types"), exports);
|
|
18
|
-
__exportStar(require("./ReCaptcha"), exports);
|
|
19
|
-
__exportStar(require("./ReCaptchaProvider"), exports);
|
|
20
|
-
__exportStar(require("./useReCaptcha"), exports);
|
|
21
|
-
__exportStar(require("./withReCaptcha"), exports);
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,8CAA4B;AAC5B,sDAAoC;AACpC,iDAA+B;AAC/B,kDAAgC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recaptcha.types.js","sourceRoot":"","sources":["../../src/recaptcha.types.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,kEAAkE"}
|
package/lib/cjs/useReCaptcha.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.useReCaptcha = void 0;
|
|
24
|
-
const react_1 = require("react");
|
|
25
|
-
const ReCaptchaProvider_1 = require("./ReCaptchaProvider");
|
|
26
|
-
/** React Hook to generate ReCaptcha token
|
|
27
|
-
* @example
|
|
28
|
-
* const { executeRecaptcha } = useReCaptcha()
|
|
29
|
-
*/
|
|
30
|
-
const useReCaptcha = (passedReCaptchaKey) => {
|
|
31
|
-
const _a = (0, ReCaptchaProvider_1.useReCaptchaContext)(), { grecaptcha, reCaptchaKey } = _a, contextProps = __rest(_a, ["grecaptcha", "reCaptchaKey"]);
|
|
32
|
-
const siteKey = passedReCaptchaKey || reCaptchaKey;
|
|
33
|
-
const executeRecaptcha = (0, react_1.useCallback)((action) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
if (typeof (grecaptcha === null || grecaptcha === void 0 ? void 0 : grecaptcha.execute) !== "function") {
|
|
35
|
-
throw new Error("Recaptcha has not been loaded");
|
|
36
|
-
}
|
|
37
|
-
const result = yield grecaptcha.execute(siteKey, { action });
|
|
38
|
-
return result;
|
|
39
|
-
}), [grecaptcha, siteKey]);
|
|
40
|
-
return Object.assign(Object.assign({}, contextProps), { grecaptcha, reCaptchaKey: siteKey, executeRecaptcha });
|
|
41
|
-
};
|
|
42
|
-
exports.useReCaptcha = useReCaptcha;
|
|
43
|
-
//# sourceMappingURL=useReCaptcha.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useReCaptcha.js","sourceRoot":"","sources":["../../src/useReCaptcha.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAoC;AACpC,2DAA0D;AAO1D;;;GAGG;AACH,MAAM,YAAY,GAAG,CAAC,kBAA2B,EAAqB,EAAE;IACtE,MAAM,KAAgD,IAAA,uCAAmB,GAAE,EAArE,EAAE,UAAU,EAAE,YAAY,OAA2C,EAAtC,YAAY,cAA3C,8BAA6C,CAAwB,CAAC;IAE5E,MAAM,OAAO,GAAG,kBAAkB,IAAI,YAAY,CAAC;IAEnD,MAAM,gBAAgB,GAAG,IAAA,mBAAW,EAClC,CAAO,MAAc,EAAE,EAAE;QACvB,IAAI,OAAO,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,CAAA,KAAK,UAAU,EAAE;YAC7C,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SAClD;QAED,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAE7D,OAAO,MAAM,CAAC;IAChB,CAAC,CAAA,EACD,CAAC,UAAU,EAAE,OAAO,CAAC,CACtB,CAAC;IAEF,uCAAY,YAAY,KAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,gBAAgB,IAAG;AAClF,CAAC,CAAC;AAEO,oCAAY"}
|
package/lib/cjs/utils.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRecaptchaScriptSrc = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Function to generate the src for the script tag
|
|
6
|
-
* Refs: https://developers.google.com/recaptcha/docs/loading
|
|
7
|
-
*/
|
|
8
|
-
const getRecaptchaScriptSrc = ({ reCaptchaKey, language, useRecaptchaNet = false, useEnterprise = false, } = {}) => {
|
|
9
|
-
const hostName = useRecaptchaNet ? "recaptcha.net" : "google.com";
|
|
10
|
-
const script = useEnterprise ? "enterprise.js" : "api.js";
|
|
11
|
-
let src = `https://www.${hostName}/recaptcha/${script}?`;
|
|
12
|
-
if (reCaptchaKey)
|
|
13
|
-
src += `render=${reCaptchaKey}`;
|
|
14
|
-
if (language)
|
|
15
|
-
src += `&hl=${language}`;
|
|
16
|
-
return src;
|
|
17
|
-
};
|
|
18
|
-
exports.getRecaptchaScriptSrc = getRecaptchaScriptSrc;
|
|
19
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/cjs/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,qBAAqB,GAAG,CAAC,EACpC,YAAY,EACZ,QAAQ,EACR,eAAe,GAAG,KAAK,EACvB,aAAa,GAAG,KAAK,MAMnB,EAAE,EAAU,EAAE;IAChB,MAAM,QAAQ,GAAG,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC;IAClE,MAAM,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC;IAE1D,IAAI,GAAG,GAAG,eAAe,QAAQ,cAAc,MAAM,GAAG,CAAC;IACzD,IAAI,YAAY;QAAE,GAAG,IAAI,UAAU,YAAY,EAAE,CAAC;IAClD,IAAI,QAAQ;QAAE,GAAG,IAAI,OAAO,QAAQ,EAAE,CAAC;IAEvC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAnBW,QAAA,qBAAqB,yBAmBhC"}
|
package/lib/cjs/withReCaptcha.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.withReCaptcha = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const useReCaptcha_1 = require("./useReCaptcha");
|
|
9
|
-
/** React HOC to generate ReCaptcha token
|
|
10
|
-
* @example
|
|
11
|
-
* withReCaptcha(MyComponent)
|
|
12
|
-
*/
|
|
13
|
-
function withReCaptcha(WrappedComponent) {
|
|
14
|
-
// Try to create a nice displayName for React Dev Tools.
|
|
15
|
-
const displayName = WrappedComponent.displayName || WrappedComponent.name || "Component";
|
|
16
|
-
// Creating the inner component. The calculated Props type here is the where the magic happens.
|
|
17
|
-
const ComponentWithReCaptca = (props) => {
|
|
18
|
-
const reCaptchaProps = (0, useReCaptcha_1.useReCaptcha)();
|
|
19
|
-
// Pass current token and function to generate it to the component
|
|
20
|
-
return react_1.default.createElement(WrappedComponent, Object.assign({}, reCaptchaProps, props));
|
|
21
|
-
};
|
|
22
|
-
ComponentWithReCaptca.displayName = `withReCaptcha(${displayName})`;
|
|
23
|
-
return ComponentWithReCaptca;
|
|
24
|
-
}
|
|
25
|
-
exports.withReCaptcha = withReCaptcha;
|
|
26
|
-
//# sourceMappingURL=withReCaptcha.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withReCaptcha.js","sourceRoot":"","sources":["../../src/withReCaptcha.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,iDAA8C;AAK9C;;;GAGG;AACH,SAAS,aAAa,CACpB,gBAAwC;IAExC,wDAAwD;IACxD,MAAM,WAAW,GAAG,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,IAAI,IAAI,WAAW,CAAC;IAEzF,+FAA+F;IAC/F,MAAM,qBAAqB,GAAG,CAAC,KAAwC,EAAE,EAAE;QACzE,MAAM,cAAc,GAAG,IAAA,2BAAY,GAAE,CAAC;QAEtC,kEAAkE;QAClE,OAAO,8BAAC,gBAAgB,oBAAK,cAAc,EAAO,KAAW,EAAI,CAAC;IACpE,CAAC,CAAC;IAEF,qBAAqB,CAAC,WAAW,GAAG,iBAAiB,WAAW,GAAG,CAAC;IAEpE,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAEQ,sCAAa"}
|