@graphcommerce/googlerecaptcha 2.1.23 → 2.2.0-canary.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # Change Log
2
2
 
3
- ## 2.1.23
3
+ ## 2.2.0-canary.3
4
4
 
5
- ## 2.1.22
5
+ ### Minor Changes
6
+
7
+ - [#1733](https://github.com/graphcommerce-org/graphcommerce/pull/1733) [`493506480`](https://github.com/graphcommerce-org/graphcommerce/commit/4935064809501682ec4df55ea47e022550dcd336) - Google Recaptcha now uses the new plugin system. Whenever the @graphcommerce/ecommerce-ui ApolloErrorAlert, ApolloErrorFullPage and ApolloErrorSnackbar components are rendered it will activate the Google Recaptcha plugins. ([@paales](https://github.com/paales))
8
+
9
+ ## 2.1.22-canary.2
10
+
11
+ ## 2.1.22-canary.1
12
+
13
+ ## 2.1.22-canary.0
6
14
 
7
15
  ## 2.1.21
8
16
 
package/README.md CHANGED
@@ -8,17 +8,14 @@ initialized on all pages.
8
8
 
9
9
  1. Add `NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY` to your .env file.
10
10
  [example](../../examples/magento-graphcms/.env.example)
11
- 2. Add `<GoogleRecaptchaProvider/>` to your `pages/_app.tsx` file
12
- [example](../../examples/magento-graphcms/pages/_app.tsx)
13
- 3. Add `recaptchaLink` to your Apollo Client.
14
- [example](../../examples/magento-graphcms/lib/graphql/GraphQLProvider.tsx)
15
- 4. Add `X-Recaptcha` header to your `.meshrc.yml`.
11
+ 2. Add `X-Recaptcha` header to your `.meshrc.yml`.
16
12
  [example](../../examples/magento-graphcms/.meshrc.yml)
17
13
 
18
14
  ### Usage
19
15
 
20
- If you have a form that uses GoogleRecaptcha add `useGoogleRecaptcha()` in the
21
- root of your component.
16
+ If you have a form that uses GoogleRecaptcha make sure you are using one of
17
+ ApolloErrorAlert, ApolloErrorFullPage and ApolloErrorSnackbar components. This
18
+ will activate the Google Recaptcha plugins.
22
19
 
23
20
  ### Troubleshooting
24
21
 
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.1.23",
5
+ "version": "2.2.0-canary.3",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -19,7 +19,7 @@
19
19
  "@types/grecaptcha": "^3.0.4"
20
20
  },
21
21
  "dependencies": {
22
- "@graphcommerce/graphql": "4.30.2"
22
+ "@graphcommerce/graphql": "4.31.0-canary.3"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "next": "^12.1.2",
@@ -0,0 +1,14 @@
1
+ import type { ApolloErrorAlertProps } from '@graphcommerce/ecommerce-ui'
2
+ import type { PluginProps } from '@graphcommerce/next-config'
3
+ import { useGoogleRecaptcha } from '../hooks/useGoogleRecaptcha'
4
+
5
+ export const component = 'ApolloErrorAlert'
6
+ export const exported = '@graphcommerce/ecommerce-ui'
7
+
8
+ function GrecaptchaApolloErrorAlert(props: PluginProps<ApolloErrorAlertProps>) {
9
+ const { Prev } = props
10
+ useGoogleRecaptcha()
11
+ return <Prev {...props} />
12
+ }
13
+
14
+ export const Plugin = GrecaptchaApolloErrorAlert
@@ -0,0 +1,14 @@
1
+ import type { ApolloErrorFullPageProps } from '@graphcommerce/ecommerce-ui'
2
+ import type { PluginProps } from '@graphcommerce/next-config'
3
+ import { useGoogleRecaptcha } from '../hooks/useGoogleRecaptcha'
4
+
5
+ export const component = 'ApolloErrorFullPage'
6
+ export const exported = '@graphcommerce/ecommerce-ui'
7
+
8
+ function GrecaptchaApolloErrorFullPage(props: PluginProps<ApolloErrorFullPageProps>) {
9
+ const { Prev } = props
10
+ useGoogleRecaptcha()
11
+ return <Prev {...props} />
12
+ }
13
+
14
+ export const Plugin = GrecaptchaApolloErrorFullPage
@@ -0,0 +1,14 @@
1
+ import type { ApolloErrorSnackbarProps } from '@graphcommerce/ecommerce-ui'
2
+ import type { PluginProps } from '@graphcommerce/next-config'
3
+ import { useGoogleRecaptcha } from '../hooks/useGoogleRecaptcha'
4
+
5
+ export const component = 'ApolloErrorSnackbar'
6
+ export const exported = '@graphcommerce/ecommerce-ui'
7
+
8
+ function GrecaptchaApolloErrorSnackbar(props: PluginProps<ApolloErrorSnackbarProps>) {
9
+ const { Prev } = props
10
+ useGoogleRecaptcha()
11
+ return <Prev {...props} />
12
+ }
13
+
14
+ export const Plugin = GrecaptchaApolloErrorSnackbar
@@ -0,0 +1,61 @@
1
+ import { GraphQLProviderProps } from '@graphcommerce/graphql'
2
+ import type { PluginProps } from '@graphcommerce/next-config'
3
+ import { GlobalStyles } from '@mui/material'
4
+ import Script from 'next/script'
5
+ import { useState, useMemo } from 'react'
6
+ import { recaptchaContext, RecaptchaContext } from '../context/recaptchaContext'
7
+ import { recaptchaLink } from '../link/recaptchaLink'
8
+
9
+ export const component = 'GraphQLProvider'
10
+ export const exported = '@graphcommerce/graphql'
11
+
12
+ let warned = false
13
+
14
+ function GrecaptchaGraphQLProvider(props: PluginProps<GraphQLProviderProps>) {
15
+ const { Prev, links = [], ...prev } = props
16
+
17
+ const [enabled, setEnabled] = useState(false)
18
+ const context: RecaptchaContext = useMemo(
19
+ () => ({
20
+ enabled,
21
+ siteKey: process.env.NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY,
22
+ enable: () => setEnabled(true),
23
+ }),
24
+ [enabled],
25
+ )
26
+
27
+ if (process.env.NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY) {
28
+ return (
29
+ <recaptchaContext.Provider value={context}>
30
+ {enabled && (
31
+ <>
32
+ <Script
33
+ key='@graphcommerce/grecaptcha'
34
+ strategy='lazyOnload'
35
+ src={`https://www.google.com/recaptcha/api.js?render=${process.env.NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY}`}
36
+ />
37
+ <GlobalStyles styles={{ '.grecaptcha-badge': { visibility: 'hidden' } }} />
38
+ </>
39
+ )}
40
+ <Prev
41
+ {...prev}
42
+ // Add recaptcha headers to the request.
43
+ links={[...links, recaptchaLink]}
44
+ />
45
+ </recaptchaContext.Provider>
46
+ )
47
+ }
48
+
49
+ if (process.env.NODE_ENV !== 'production') {
50
+ if (!warned) {
51
+ console.info(
52
+ '[@graphcommerce/googlerecaptcha]: process.env.NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY not found',
53
+ )
54
+ warned = true
55
+ }
56
+ }
57
+
58
+ return <Prev {...props} />
59
+ }
60
+
61
+ export const Plugin = GrecaptchaGraphQLProvider