@graphcommerce/magento-customer 4.6.3 → 4.7.2
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 +41 -0
- package/components/ApolloCustomerError/ApolloCustomerErrorFullPage.tsx +2 -2
- package/components/SignOutForm/SignOutForm.tsx +3 -1
- package/hooks/useCustomerQuery.ts +29 -4
- package/hooks/useCustomerSession.ts +20 -4
- package/link/createCustomerTokenLink.ts +2 -2
- package/link/onAuthenticationError.ts +2 -2
- package/package.json +13 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 4.7.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1552](https://github.com/graphcommerce-org/graphcommerce/pull/1552) [`18054c441`](https://github.com/graphcommerce-org/graphcommerce/commit/18054c441962ba750bed3acc39ab46c8d3a341ce) Thanks [@paales](https://github.com/paales)! - Updated to Next.js v12.2.2 and other packages and made compatible
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`18054c441`](https://github.com/graphcommerce-org/graphcommerce/commit/18054c441962ba750bed3acc39ab46c8d3a341ce), [`c5c539c44`](https://github.com/graphcommerce-org/graphcommerce/commit/c5c539c44eeac524cd62ce649e132d2e00333794), [`6f69bc54c`](https://github.com/graphcommerce-org/graphcommerce/commit/6f69bc54c6e0224452817c532ae58d9c332b61ea), [`21886d6fa`](https://github.com/graphcommerce-org/graphcommerce/commit/21886d6fa64a48d9e932bfaf8d138c9b13c36e43)]:
|
|
10
|
+
- @graphcommerce/graphql@3.4.1
|
|
11
|
+
- @graphcommerce/graphql-mesh@4.1.5
|
|
12
|
+
- @graphcommerce/next-ui@4.13.1
|
|
13
|
+
- @graphcommerce/ecommerce-ui@1.1.2
|
|
14
|
+
- @graphcommerce/magento-graphql@3.1.1
|
|
15
|
+
- @graphcommerce/magento-store@4.2.17
|
|
16
|
+
|
|
17
|
+
## 4.7.1
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`8d8fda262`](https://github.com/graphcommerce-org/graphcommerce/commit/8d8fda2623e561cb43441110c67ffa34b692668a), [`d41cff721`](https://github.com/graphcommerce-org/graphcommerce/commit/d41cff7211230561ceeb7786cf75790efd6377cd), [`cefa7b365`](https://github.com/graphcommerce-org/graphcommerce/commit/cefa7b3652b55108d2178927e3c5d98a111cf373)]:
|
|
22
|
+
- @graphcommerce/next-ui@4.13.0
|
|
23
|
+
- @graphcommerce/magento-store@4.2.16
|
|
24
|
+
- @graphcommerce/ecommerce-ui@1.1.1
|
|
25
|
+
|
|
26
|
+
## 4.7.0
|
|
27
|
+
|
|
28
|
+
### Minor Changes
|
|
29
|
+
|
|
30
|
+
- [#1544](https://github.com/graphcommerce-org/graphcommerce/pull/1544) [`5f927ebdc`](https://github.com/graphcommerce-org/graphcommerce/commit/5f927ebdc6f0331833e02b96e4f169bfe475ac6b) Thanks [@mikekeehnen](https://github.com/mikekeehnen)! - Fixed hydration errors on account, cart and wishlist
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- [#1545](https://github.com/graphcommerce-org/graphcommerce/pull/1545) [`c87a28e7d`](https://github.com/graphcommerce-org/graphcommerce/commit/c87a28e7dad87bffd0bd125ad5fdca65aaa389cc) Thanks [@paales](https://github.com/paales)! - Faster hydration with useLayoutEffect
|
|
35
|
+
|
|
36
|
+
- Updated dependencies [[`5f927ebdc`](https://github.com/graphcommerce-org/graphcommerce/commit/5f927ebdc6f0331833e02b96e4f169bfe475ac6b), [`c756f42e5`](https://github.com/graphcommerce-org/graphcommerce/commit/c756f42e503761a497e4a5a7a02d02141df231c3)]:
|
|
37
|
+
- @graphcommerce/ecommerce-ui@1.1.0
|
|
38
|
+
- @graphcommerce/graphql@3.4.0
|
|
39
|
+
- @graphcommerce/magento-graphql@3.1.0
|
|
40
|
+
- @graphcommerce/react-hook-form@3.3.0
|
|
41
|
+
- @graphcommerce/next-ui@4.12.0
|
|
42
|
+
- @graphcommerce/magento-store@4.2.15
|
|
43
|
+
|
|
3
44
|
## 4.6.3
|
|
4
45
|
|
|
5
46
|
### Patch Changes
|
|
@@ -16,7 +16,7 @@ export type ApolloCustomerErrorFullPageProps = {
|
|
|
16
16
|
|
|
17
17
|
export function ApolloCustomerErrorFullPage(props: ApolloCustomerErrorFullPageProps) {
|
|
18
18
|
const { error, icon, altButton, button, ...alertProps } = props
|
|
19
|
-
const [newError, unauthorized] = useAuthorizationErrorMasked()
|
|
19
|
+
const [newError, unauthorized] = useAuthorizationErrorMasked(error)
|
|
20
20
|
const { token } = useCustomerSession()
|
|
21
21
|
|
|
22
22
|
return (
|
|
@@ -28,7 +28,7 @@ export function ApolloCustomerErrorFullPage(props: ApolloCustomerErrorFullPagePr
|
|
|
28
28
|
unauthorized ? (
|
|
29
29
|
<PageLink href='/account/signin' passHref>
|
|
30
30
|
<Button variant='contained' color='primary' size='large'>
|
|
31
|
-
{token ? <Trans id='Sign in' /> : <Trans id='
|
|
31
|
+
{token ? <Trans id='Sign in' /> : <Trans id='Sign in or create an account!' />}
|
|
32
32
|
</Button>
|
|
33
33
|
</PageLink>
|
|
34
34
|
) : (
|
|
@@ -5,7 +5,9 @@ import React from 'react'
|
|
|
5
5
|
import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert'
|
|
6
6
|
import { SignOutFormDocument } from './SignOutForm.gql'
|
|
7
7
|
|
|
8
|
-
type SignOutFormProps = {
|
|
8
|
+
type SignOutFormProps = {
|
|
9
|
+
button: (props: { formState: FormState<Record<string, unknown>> }) => React.ReactNode
|
|
10
|
+
}
|
|
9
11
|
|
|
10
12
|
export function SignOutForm(props: SignOutFormProps) {
|
|
11
13
|
const { button } = props
|
|
@@ -1,11 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useQuery,
|
|
3
|
+
TypedDocumentNode,
|
|
4
|
+
QueryHookOptions,
|
|
5
|
+
QueryResult,
|
|
6
|
+
ApolloError,
|
|
7
|
+
} from '@graphcommerce/graphql'
|
|
8
|
+
import { GraphQLError } from 'graphql'
|
|
2
9
|
import { useCustomerSession } from './useCustomerSession'
|
|
3
10
|
|
|
11
|
+
const notLoggedInError = new ApolloError({
|
|
12
|
+
graphQLErrors: [
|
|
13
|
+
new GraphQLError('Not authorized', {
|
|
14
|
+
extensions: { category: 'graphql-authorization' },
|
|
15
|
+
}),
|
|
16
|
+
],
|
|
17
|
+
})
|
|
18
|
+
|
|
4
19
|
/** Will only execute when the customer is signed in. */
|
|
5
20
|
export function useCustomerQuery<Q, V>(
|
|
6
21
|
document: TypedDocumentNode<Q, V>,
|
|
7
22
|
queryOptions: QueryHookOptions<Q, V> = {},
|
|
8
|
-
) {
|
|
9
|
-
const { loggedIn } = useCustomerSession()
|
|
10
|
-
|
|
23
|
+
): QueryResult<Q, V> {
|
|
24
|
+
const { loggedIn, called } = useCustomerSession()
|
|
25
|
+
|
|
26
|
+
const result = useQuery(document, {
|
|
27
|
+
...queryOptions,
|
|
28
|
+
ssr: false,
|
|
29
|
+
skip: !loggedIn,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
...result,
|
|
34
|
+
error: called && !loggedIn ? notLoggedInError : result.error,
|
|
35
|
+
}
|
|
11
36
|
}
|
|
@@ -1,19 +1,35 @@
|
|
|
1
|
+
import { useIsomorphicLayoutEffect } from '@graphcommerce/framer-utils'
|
|
1
2
|
import { useQuery } from '@graphcommerce/graphql'
|
|
3
|
+
import { useState } from 'react'
|
|
2
4
|
import { CustomerTokenDocument, CustomerTokenQuery } from './CustomerToken.gql'
|
|
3
5
|
|
|
4
|
-
type TokenResponse = Omit<NonNullable<CustomerTokenQuery['customerToken']>, '__typename'>
|
|
6
|
+
type TokenResponse = Omit<NonNullable<CustomerTokenQuery['customerToken']>, '__typename'> & {
|
|
7
|
+
called: boolean
|
|
8
|
+
}
|
|
5
9
|
|
|
6
10
|
export type UseCustomerSessionReturn =
|
|
7
11
|
| Partial<TokenResponse> & { loggedIn: boolean; requireAuth: boolean }
|
|
8
12
|
|
|
9
13
|
export function useCustomerSession(): UseCustomerSessionReturn {
|
|
10
|
-
const
|
|
11
|
-
|
|
14
|
+
const [skip, setSkip] = useState(true)
|
|
15
|
+
|
|
16
|
+
const { called, data } = useQuery(CustomerTokenDocument, {
|
|
17
|
+
ssr: false,
|
|
18
|
+
fetchPolicy: 'cache-only',
|
|
19
|
+
skip,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const token = data?.customerToken
|
|
23
|
+
|
|
24
|
+
useIsomorphicLayoutEffect(() => {
|
|
25
|
+
if (skip) setSkip(false)
|
|
26
|
+
}, [skip])
|
|
12
27
|
|
|
13
|
-
if (!token) return { loggedIn: false, requireAuth: true }
|
|
28
|
+
if (!token) return { called, loggedIn: false, requireAuth: true }
|
|
14
29
|
|
|
15
30
|
return {
|
|
16
31
|
...token,
|
|
32
|
+
called,
|
|
17
33
|
loggedIn: Boolean(token?.token && token.valid),
|
|
18
34
|
requireAuth: Boolean(!token || !token.valid),
|
|
19
35
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
setContext,
|
|
7
7
|
} from '@graphcommerce/graphql'
|
|
8
8
|
import { CustomerTokenDocument } from '../hooks'
|
|
9
|
-
import {
|
|
9
|
+
import { onAuthorizationError } from './onAuthenticationError'
|
|
10
10
|
|
|
11
11
|
export const addTokenHeader = setContext((_, context: ClientContext) => {
|
|
12
12
|
if (!context.headers) context.headers = {}
|
|
@@ -22,7 +22,7 @@ export const addTokenHeader = setContext((_, context: ClientContext) => {
|
|
|
22
22
|
}
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
export const customerTokenLink = ApolloLink.from([addTokenHeader,
|
|
25
|
+
export const customerTokenLink = ApolloLink.from([addTokenHeader, onAuthorizationError])
|
|
26
26
|
|
|
27
27
|
/** Not really required anymore, you can use customerTokenLink directly */
|
|
28
28
|
export const createCustomerTokenLink = (_: ApolloCache<NormalizedCacheObject>) => customerTokenLink
|
|
@@ -22,14 +22,14 @@ function invalidateToken(cache: InMemoryCache) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export const
|
|
25
|
+
export const onAuthorizationError = onError(({ graphQLErrors, operation }) => {
|
|
26
26
|
const { cache } = operation.getContext()
|
|
27
27
|
if (graphQLErrors) {
|
|
28
28
|
for (const err of graphQLErrors) {
|
|
29
29
|
if (err.extensions?.category === 'graphql-authorization') {
|
|
30
30
|
// Modify the operation context with a new token
|
|
31
31
|
invalidateToken(cache as InMemoryCache)
|
|
32
|
-
break
|
|
32
|
+
break
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/magento-customer",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "4.
|
|
5
|
+
"version": "4.7.2",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,21 +12,22 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@graphcommerce/eslint-config-pwa": "^4.1.
|
|
15
|
+
"@graphcommerce/eslint-config-pwa": "^4.1.9",
|
|
16
16
|
"@graphcommerce/prettier-config-pwa": "^4.0.6",
|
|
17
|
-
"@graphcommerce/typescript-config-pwa": "^4.0.
|
|
17
|
+
"@graphcommerce/typescript-config-pwa": "^4.0.4",
|
|
18
18
|
"@playwright/test": "^1.21.1",
|
|
19
19
|
"type-fest": "^2.12.2"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@graphcommerce/ecommerce-ui": "1.
|
|
23
|
-
"@graphcommerce/
|
|
24
|
-
"@graphcommerce/graphql
|
|
22
|
+
"@graphcommerce/ecommerce-ui": "1.1.2",
|
|
23
|
+
"@graphcommerce/framer-utils": "3.1.4",
|
|
24
|
+
"@graphcommerce/graphql": "3.4.1",
|
|
25
|
+
"@graphcommerce/graphql-mesh": "4.1.5",
|
|
25
26
|
"@graphcommerce/image": "3.1.7",
|
|
26
|
-
"@graphcommerce/magento-graphql": "3.
|
|
27
|
-
"@graphcommerce/magento-store": "4.2.
|
|
28
|
-
"@graphcommerce/next-ui": "4.
|
|
29
|
-
"@graphcommerce/react-hook-form": "3.
|
|
27
|
+
"@graphcommerce/magento-graphql": "3.1.1",
|
|
28
|
+
"@graphcommerce/magento-store": "4.2.17",
|
|
29
|
+
"@graphcommerce/next-ui": "4.13.1",
|
|
30
|
+
"@graphcommerce/react-hook-form": "3.3.0"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
33
|
"@lingui/react": "^3.13.2",
|
|
@@ -35,6 +36,7 @@
|
|
|
35
36
|
"framer-motion": "^6.2.4",
|
|
36
37
|
"next": "^12.1.2",
|
|
37
38
|
"react": "^18.0.0",
|
|
38
|
-
"react-dom": "^18.0.0"
|
|
39
|
+
"react-dom": "^18.0.0",
|
|
40
|
+
"graphql": "16.5.0"
|
|
39
41
|
}
|
|
40
42
|
}
|