@graphcommerce/googlerecaptcha 2.0.3 → 2.1.0
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 +45 -46
- package/README.md +18 -4
- package/components/GoogleRecaptchaProvider.tsx +20 -0
- package/components/GoogleRecaptchaV3Script.tsx +9 -6
- package/context/recaptchaContext.tsx +9 -0
- package/hooks/useGoogleRecaptcha.tsx +4 -0
- package/index.ts +3 -1
- package/link/recaptchaLink.ts +3 -1
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,94 +1,93 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1344](https://github.com/graphcommerce-org/graphcommerce/pull/1344) [`5ab19683c`](https://github.com/graphcommerce-org/graphcommerce/commit/5ab19683ca4e1ff78c21dbe09b73aeea43ef3b64) Thanks [@paales](https://github.com/paales)! - Added Google reCAPTCHA conditional loading to make it fully compatible, but load the reCAPTCHA only on pages with forms.
|
|
8
|
+
|
|
9
|
+
## 2.0.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1341](https://github.com/graphcommerce-org/graphcommerce/pull/1341) [`2e29c5852`](https://github.com/graphcommerce-org/graphcommerce/commit/2e29c585247d356e3027be92beb7815f2070c855) Thanks [@paales](https://github.com/paales)! - upgrade dependencies
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`2e29c5852`](https://github.com/graphcommerce-org/graphcommerce/commit/2e29c585247d356e3027be92beb7815f2070c855)]:
|
|
16
|
+
- @graphcommerce/graphql@3.0.5
|
|
17
|
+
|
|
18
|
+
## 2.0.4
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- [#1307](https://github.com/ho-nl/m2-pwa/pull/1307) [`bd10506d3`](https://github.com/ho-nl/m2-pwa/commit/bd10506d32fdbc91d01dadc29a12ebd1e0943655) Thanks [@paales](https://github.com/paales)! - All default exports are now named exports internally and all `index.tsx` are renamed to the component name.
|
|
23
|
+
|
|
24
|
+
* [#1307](https://github.com/ho-nl/m2-pwa/pull/1307) [`27cb1f2d8`](https://github.com/ho-nl/m2-pwa/commit/27cb1f2d8dbfb8f1b301ce56fb6a2b6c1fc6a5ef) Thanks [@paales](https://github.com/paales)! - upgrade dependencies
|
|
25
|
+
|
|
26
|
+
* Updated dependencies [[`bd10506d3`](https://github.com/ho-nl/m2-pwa/commit/bd10506d32fdbc91d01dadc29a12ebd1e0943655), [`27cb1f2d8`](https://github.com/ho-nl/m2-pwa/commit/27cb1f2d8dbfb8f1b301ce56fb6a2b6c1fc6a5ef)]:
|
|
27
|
+
- @graphcommerce/graphql@3.0.4
|
|
28
|
+
|
|
3
29
|
## 2.0.3
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
6
32
|
|
|
7
|
-
- [`973ff8645`](https://github.com/ho-nl/m2-pwa/commit/973ff86452a70ade9f4db13fdda6e963d7220e96)
|
|
8
|
-
Thanks [@paales](https://github.com/paales)! - made packages public
|
|
33
|
+
- [`973ff8645`](https://github.com/ho-nl/m2-pwa/commit/973ff86452a70ade9f4db13fdda6e963d7220e96) Thanks [@paales](https://github.com/paales)! - made packages public
|
|
9
34
|
|
|
10
|
-
- Updated dependencies
|
|
11
|
-
[[`973ff8645`](https://github.com/ho-nl/m2-pwa/commit/973ff86452a70ade9f4db13fdda6e963d7220e96)]:
|
|
35
|
+
- Updated dependencies [[`973ff8645`](https://github.com/ho-nl/m2-pwa/commit/973ff86452a70ade9f4db13fdda6e963d7220e96)]:
|
|
12
36
|
- @graphcommerce/graphql@3.0.3
|
|
13
37
|
|
|
14
38
|
## 2.0.2
|
|
15
39
|
|
|
16
40
|
### Patch Changes
|
|
17
41
|
|
|
18
|
-
- [#1276](https://github.com/ho-nl/m2-pwa/pull/1276)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* [
|
|
25
|
-
[`52a45bba4`](https://github.com/ho-nl/m2-pwa/commit/52a45bba4dc6dd6df3c81f5023df7d23ed8a534d)
|
|
26
|
-
Thanks [@paales](https://github.com/paales)! - Upgraded to
|
|
27
|
-
[NextJS 12.1](https://nextjs.org/blog/next-12-1)! This is just for compatibility, but we'll be
|
|
28
|
-
implementing
|
|
29
|
-
[On-demand Incremental Static Regeneration](https://nextjs.org/blog/next-12-1#on-demand-incremental-static-regeneration-beta)
|
|
30
|
-
soon.
|
|
31
|
-
|
|
32
|
-
This will greatly reduce the requirement to rebuid stuff and we'll add a management UI on the
|
|
33
|
-
frontend to be able to revalidate pages manually.
|
|
34
|
-
|
|
35
|
-
* Updated dependencies
|
|
36
|
-
[[`ce09388e0`](https://github.com/ho-nl/m2-pwa/commit/ce09388e0d7ef33aee660612340f6fbae15ceec2),
|
|
37
|
-
[`52a45bba4`](https://github.com/ho-nl/m2-pwa/commit/52a45bba4dc6dd6df3c81f5023df7d23ed8a534d)]:
|
|
42
|
+
- [#1276](https://github.com/ho-nl/m2-pwa/pull/1276) [`ce09388e0`](https://github.com/ho-nl/m2-pwa/commit/ce09388e0d7ef33aee660612340f6fbae15ceec2) Thanks [@paales](https://github.com/paales)! - We've moved lots of internal packages from `dependencies` to `peerDependencies`. The result of this is that there will be significantly less duplicate packages in the node_modules folders.
|
|
43
|
+
|
|
44
|
+
* [#1276](https://github.com/ho-nl/m2-pwa/pull/1276) [`52a45bba4`](https://github.com/ho-nl/m2-pwa/commit/52a45bba4dc6dd6df3c81f5023df7d23ed8a534d) Thanks [@paales](https://github.com/paales)! - Upgraded to [NextJS 12.1](https://nextjs.org/blog/next-12-1)! This is just for compatibility, but we'll be implementing [On-demand Incremental Static Regeneration](https://nextjs.org/blog/next-12-1#on-demand-incremental-static-regeneration-beta) soon.
|
|
45
|
+
|
|
46
|
+
This will greatly reduce the requirement to rebuid stuff and we'll add a management UI on the frontend to be able to revalidate pages manually.
|
|
47
|
+
|
|
48
|
+
* Updated dependencies [[`ce09388e0`](https://github.com/ho-nl/m2-pwa/commit/ce09388e0d7ef33aee660612340f6fbae15ceec2), [`52a45bba4`](https://github.com/ho-nl/m2-pwa/commit/52a45bba4dc6dd6df3c81f5023df7d23ed8a534d)]:
|
|
38
49
|
- @graphcommerce/graphql@3.0.2
|
|
39
50
|
|
|
40
51
|
## 2.0.1
|
|
41
52
|
|
|
42
53
|
### Patch Changes
|
|
43
54
|
|
|
44
|
-
- [`0cbaa878b`](https://github.com/ho-nl/m2-pwa/commit/0cbaa878b8a844d5abbeb1797b625a33130e6514)
|
|
45
|
-
|
|
46
|
-
so that the packages link to back to the website and repository
|
|
47
|
-
- Updated dependencies
|
|
48
|
-
[[`0cbaa878b`](https://github.com/ho-nl/m2-pwa/commit/0cbaa878b8a844d5abbeb1797b625a33130e6514)]:
|
|
55
|
+
- [`0cbaa878b`](https://github.com/ho-nl/m2-pwa/commit/0cbaa878b8a844d5abbeb1797b625a33130e6514) Thanks [@paales](https://github.com/paales)! - Added homepage and repository package.json files, so that the packages link to back to the website and repository
|
|
56
|
+
- Updated dependencies [[`0cbaa878b`](https://github.com/ho-nl/m2-pwa/commit/0cbaa878b8a844d5abbeb1797b625a33130e6514)]:
|
|
49
57
|
- @graphcommerce/graphql@3.0.1
|
|
50
58
|
|
|
51
59
|
## 2.0.0
|
|
52
60
|
|
|
53
61
|
### Major Changes
|
|
54
62
|
|
|
55
|
-
- [#1258](https://github.com/ho-nl/m2-pwa/pull/1258)
|
|
56
|
-
[`ad36382a4`](https://github.com/ho-nl/m2-pwa/commit/ad36382a4d55d83d9e47b7eb6a02671a2a631a05)
|
|
57
|
-
Thanks [@paales](https://github.com/paales)! - Upgraded to Material UI 5
|
|
63
|
+
- [#1258](https://github.com/ho-nl/m2-pwa/pull/1258) [`ad36382a4`](https://github.com/ho-nl/m2-pwa/commit/ad36382a4d55d83d9e47b7eb6a02671a2a631a05) Thanks [@paales](https://github.com/paales)! - Upgraded to Material UI 5
|
|
58
64
|
|
|
59
65
|
### Patch Changes
|
|
60
66
|
|
|
61
|
-
- Updated dependencies
|
|
62
|
-
[[`ad36382a4`](https://github.com/ho-nl/m2-pwa/commit/ad36382a4d55d83d9e47b7eb6a02671a2a631a05)]:
|
|
67
|
+
- Updated dependencies [[`ad36382a4`](https://github.com/ho-nl/m2-pwa/commit/ad36382a4d55d83d9e47b7eb6a02671a2a631a05)]:
|
|
63
68
|
- @graphcommerce/graphql@3.0.0
|
|
64
69
|
|
|
65
|
-
All notable changes to this project will be documented in this file. See
|
|
66
|
-
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
70
|
+
All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
67
71
|
|
|
68
72
|
## [1.1.8](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/googlerecaptcha@1.1.7...@graphcommerce/googlerecaptcha@1.1.8) (2021-12-20)
|
|
69
73
|
|
|
70
74
|
### Bug Fixes
|
|
71
75
|
|
|
72
|
-
- make sure we're not loading gogole properties when keys are not given
|
|
73
|
-
([8636715](https://github.com/ho-nl/m2-pwa/commit/8636715d61985e0919208ffb64354c3ebb43ed01))
|
|
76
|
+
- make sure we're not loading gogole properties when keys are not given ([8636715](https://github.com/ho-nl/m2-pwa/commit/8636715d61985e0919208ffb64354c3ebb43ed01))
|
|
74
77
|
|
|
75
78
|
## [1.1.2](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/googlerecaptcha@1.1.1...@graphcommerce/googlerecaptcha@1.1.2) (2021-11-12)
|
|
76
79
|
|
|
77
80
|
### Bug Fixes
|
|
78
81
|
|
|
79
|
-
- remove fragment
|
|
80
|
-
|
|
81
|
-
- remove hiding recaptcha from themeProvider, add to component
|
|
82
|
-
([6a49f77](https://github.com/ho-nl/m2-pwa/commit/6a49f77ef9fd22ea66e7acd1322c65ac6426fd3b))
|
|
82
|
+
- remove fragment ([3d8a964](https://github.com/ho-nl/m2-pwa/commit/3d8a964f3009f04b3ba09d54272a31b592e7a052))
|
|
83
|
+
- remove hiding recaptcha from themeProvider, add to component ([6a49f77](https://github.com/ho-nl/m2-pwa/commit/6a49f77ef9fd22ea66e7acd1322c65ac6426fd3b))
|
|
83
84
|
|
|
84
85
|
# 1.1.0 (2021-11-03)
|
|
85
86
|
|
|
86
87
|
### Bug Fixes
|
|
87
88
|
|
|
88
|
-
- make sure we're not throwing a warning on the production env.
|
|
89
|
-
([7ee4499](https://github.com/ho-nl/m2-pwa/commit/7ee449959509a13e684c19e2ff707e378d6b5c35))
|
|
89
|
+
- make sure we're not throwing a warning on the production env. ([7ee4499](https://github.com/ho-nl/m2-pwa/commit/7ee449959509a13e684c19e2ff707e378d6b5c35))
|
|
90
90
|
|
|
91
91
|
### Features
|
|
92
92
|
|
|
93
|
-
- google recaptcha v3 integration
|
|
94
|
-
([a9fcc16](https://github.com/ho-nl/m2-pwa/commit/a9fcc16f93951e61378c99a2e183e2d754da1d50))
|
|
93
|
+
- google recaptcha v3 integration ([a9fcc16](https://github.com/ho-nl/m2-pwa/commit/a9fcc16f93951e61378c99a2e183e2d754da1d50))
|
package/README.md
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
# @graphcommerce/googlerecaptcha
|
|
2
2
|
|
|
3
|
-
This package makes it easy to add Google Recaptcha v3 to GraphCommerce
|
|
3
|
+
This package makes it easy to add Google Recaptcha v3 to GraphCommerce. It
|
|
4
|
+
allows you to load the Recatcha script conditionally on the page so it isn't
|
|
5
|
+
initialized on all pages.
|
|
4
6
|
|
|
5
|
-
###
|
|
7
|
+
### Installation
|
|
6
8
|
|
|
7
9
|
1. Add `NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY` to your .env file.
|
|
8
10
|
[example](../../examples/magento-graphcms/.env.example)
|
|
9
|
-
2. Add `<
|
|
11
|
+
2. Add `<GoogleRecaptchaProvider/>` to your `pages/_app.tsx` file
|
|
10
12
|
[example](../../examples/magento-graphcms/pages/_app.tsx)
|
|
11
13
|
3. Add `recaptchaLink` to your Apollo Client.
|
|
12
|
-
[example](../../examples/magento-graphcms/lib/
|
|
14
|
+
[example](../../examples/magento-graphcms/lib/graphql/GraphQLProvider.tsx)
|
|
13
15
|
4. Add `X-Recaptcha` header to your `.meshrc.yml`.
|
|
14
16
|
[example](../../examples/magento-graphcms/.meshrc.yml)
|
|
17
|
+
|
|
18
|
+
### Usage
|
|
19
|
+
|
|
20
|
+
If you have a form that uses GoogleRecaptcha add `useGoogleRecaptcha()` in the
|
|
21
|
+
root of your component.
|
|
22
|
+
|
|
23
|
+
### Troubleshooting
|
|
24
|
+
|
|
25
|
+
`ReCaptcha validation failed, please try again`
|
|
26
|
+
: Magento is configured correctly and this is an error coming from Google
|
|
27
|
+
directly. You have misconfigured something on the Google side. Make sure the
|
|
28
|
+
domains are set up correctly, etc.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react'
|
|
2
|
+
import { RecaptchaContext, recaptchaContext } from '../context/recaptchaContext'
|
|
3
|
+
import { GoogleRecaptchaV3Script } from './GoogleRecaptchaV3Script'
|
|
4
|
+
|
|
5
|
+
export function GoogleRecaptchaProvider(props: { children: React.ReactNode; siteKey?: string }) {
|
|
6
|
+
const { children, siteKey = process.env.NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY } = props
|
|
7
|
+
const [enabled, setEnabled] = useState(false)
|
|
8
|
+
|
|
9
|
+
const context: RecaptchaContext = useMemo(
|
|
10
|
+
() => ({ enabled, siteKey, enable: () => setEnabled(true) }),
|
|
11
|
+
[enabled, siteKey],
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<recaptchaContext.Provider value={context}>
|
|
16
|
+
<GoogleRecaptchaV3Script />
|
|
17
|
+
{children}
|
|
18
|
+
</recaptchaContext.Provider>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
+
import { GlobalStyles } from '@mui/material'
|
|
1
2
|
import Script from 'next/script'
|
|
2
|
-
import
|
|
3
|
+
import { useContext } from 'react'
|
|
4
|
+
import { recaptchaContext } from '../context/recaptchaContext'
|
|
3
5
|
|
|
4
|
-
export
|
|
5
|
-
const siteKey =
|
|
6
|
+
export function GoogleRecaptchaV3Script() {
|
|
7
|
+
const { siteKey, enabled } = useContext(recaptchaContext)
|
|
6
8
|
|
|
7
|
-
if (process.env.NODE_ENV !== 'production' && !siteKey)
|
|
9
|
+
if (process.env.NODE_ENV !== 'production' && !siteKey && enabled)
|
|
8
10
|
console.warn(
|
|
9
11
|
'[@graphcommerce/googletagmanager]: NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY not found',
|
|
10
12
|
)
|
|
11
13
|
|
|
12
|
-
if (!siteKey) return null
|
|
14
|
+
if (!siteKey || !enabled) return null
|
|
13
15
|
|
|
14
16
|
return (
|
|
15
17
|
<>
|
|
16
18
|
<Script
|
|
19
|
+
key='google-recaptcha-v3'
|
|
17
20
|
strategy='lazyOnload'
|
|
18
21
|
src={`https://www.google.com/recaptcha/api.js?render=${siteKey}`}
|
|
19
22
|
/>
|
|
20
|
-
<
|
|
23
|
+
<GlobalStyles styles={{ '.grecaptcha-badge': { visibility: 'hidden' } }} />
|
|
21
24
|
</>
|
|
22
25
|
)
|
|
23
26
|
}
|
package/index.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './components/GoogleRecaptchaV3Script'
|
|
2
|
+
export * from './components/GoogleRecaptchaProvider'
|
|
2
3
|
export * from './link/recaptchaLink'
|
|
4
|
+
export * from './hooks/useGoogleRecaptcha'
|
package/link/recaptchaLink.ts
CHANGED
|
@@ -11,7 +11,9 @@ export const recaptchaLink = setContext(async (operation, context) => {
|
|
|
11
11
|
const recaptchaKey = process.env.NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY
|
|
12
12
|
if (!recaptchaKey || !globalThis.grecaptcha || !isMutation(operation)) return context
|
|
13
13
|
|
|
14
|
-
await new Promise<void>(
|
|
14
|
+
await new Promise<void>((resolve) => {
|
|
15
|
+
globalThis.grecaptcha?.ready(resolve)
|
|
16
|
+
})
|
|
15
17
|
|
|
16
18
|
const token = await globalThis.grecaptcha.execute(recaptchaKey, { action: 'submit' })
|
|
17
19
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/googlerecaptcha",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "2.0
|
|
5
|
+
"version": "2.1.0",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,18 +12,19 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@graphcommerce/eslint-config-pwa": "^4.
|
|
16
|
-
"@graphcommerce/prettier-config-pwa": "^4.0.
|
|
15
|
+
"@graphcommerce/eslint-config-pwa": "^4.1.1",
|
|
16
|
+
"@graphcommerce/prettier-config-pwa": "^4.0.3",
|
|
17
17
|
"@graphcommerce/typescript-config-pwa": "^4.0.2",
|
|
18
|
-
"@playwright/test": "^1.19.
|
|
19
|
-
"@types/grecaptcha": "^3.0.
|
|
18
|
+
"@playwright/test": "^1.19.2",
|
|
19
|
+
"@types/grecaptcha": "^3.0.4"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@graphcommerce/graphql": "^3.0.
|
|
22
|
+
"@graphcommerce/graphql": "^3.0.5"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"next": "^12.0.10",
|
|
26
26
|
"react": "^17.0.2",
|
|
27
|
-
"react-dom": "^17.0.2"
|
|
27
|
+
"react-dom": "^17.0.2",
|
|
28
|
+
"@mui/material": "^5.4.1"
|
|
28
29
|
}
|
|
29
30
|
}
|