@graphcommerce/magento-customer 4.11.6 → 4.12.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 CHANGED
@@ -1,5 +1,32 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1670](https://github.com/graphcommerce-org/graphcommerce/pull/1670) [`8a34f8081`](https://github.com/graphcommerce-org/graphcommerce/commit/8a34f808186274a6fe1d4f309472f1a9c6d00efd) Thanks [@Jessevdpoel](https://github.com/Jessevdpoel)! - Added cache resetting when token expires and logging in with a different account than cached.
8
+
9
+ ### Patch Changes
10
+
11
+ - [#1675](https://github.com/graphcommerce-org/graphcommerce/pull/1675) [`1b1504c9b`](https://github.com/graphcommerce-org/graphcommerce/commit/1b1504c9b0e51f2787bce91e1ff1940f540411d6) Thanks [@paales](https://github.com/paales)! - Added crosssel functionality
12
+
13
+ - Updated dependencies [[`9e630670f`](https://github.com/graphcommerce-org/graphcommerce/commit/9e630670ff6c952ab7b938d890b5509804985cf3), [`cf3518499`](https://github.com/graphcommerce-org/graphcommerce/commit/cf351849999ad6fe73ce2bb258098a7dd301d517), [`2e9fa5984`](https://github.com/graphcommerce-org/graphcommerce/commit/2e9fa5984a07ff14fc1b3a4f62189a26e8e3ecdd), [`adf13069a`](https://github.com/graphcommerce-org/graphcommerce/commit/adf13069af6460c960276b402237371c12fc6dec), [`1b1504c9b`](https://github.com/graphcommerce-org/graphcommerce/commit/1b1504c9b0e51f2787bce91e1ff1940f540411d6), [`8a34f8081`](https://github.com/graphcommerce-org/graphcommerce/commit/8a34f808186274a6fe1d4f309472f1a9c6d00efd), [`6c2e27b1b`](https://github.com/graphcommerce-org/graphcommerce/commit/6c2e27b1be4aaa888e65a2bd69eaeb467a54a023), [`3dde492ad`](https://github.com/graphcommerce-org/graphcommerce/commit/3dde492ad3a49d96481eeb7453fb305d0017b1a5)]:
14
+ - @graphcommerce/next-ui@4.28.1
15
+ - @graphcommerce/graphql@3.5.0
16
+ - @graphcommerce/framer-utils@3.2.1
17
+ - @graphcommerce/ecommerce-ui@1.5.4
18
+ - @graphcommerce/magento-store@4.3.2
19
+ - @graphcommerce/magento-graphql@3.1.9
20
+ - @graphcommerce/image@3.1.10
21
+
22
+ ## 4.11.7
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [[`1f2e14ba8`](https://github.com/graphcommerce-org/graphcommerce/commit/1f2e14ba8b674b87257a123e8cb215157890eb22), [`fc32b9ab3`](https://github.com/graphcommerce-org/graphcommerce/commit/fc32b9ab3818eb99c546a89e7f42045a6fbfba81)]:
27
+ - @graphcommerce/react-hook-form@3.3.5
28
+ - @graphcommerce/ecommerce-ui@1.5.3
29
+
3
30
  ## 4.11.6
4
31
 
5
32
  ### Patch Changes
@@ -0,0 +1,38 @@
1
+ import { useApolloClient } from '@graphcommerce/graphql'
2
+ import { CustomerTokenDocument } from '@graphcommerce/magento-customer'
3
+ import { Button } from '@mui/material'
4
+
5
+ export function SessionDebugger() {
6
+ const client = useApolloClient()
7
+
8
+ return (
9
+ <div style={{ position: 'fixed', bottom: 0, right: 0, zIndex: 1, opacity: 0.3 }}>
10
+ <Button
11
+ type='button'
12
+ variant='text'
13
+ size='small'
14
+ onClick={() => {
15
+ const currentToken = client.readQuery({ query: CustomerTokenDocument })
16
+ if (!currentToken?.customerToken?.token) {
17
+ console.log('No customerToken available, nothing to break')
18
+ } else {
19
+ console.log(`Changing current token to a random one)`)
20
+
21
+ client.writeQuery({
22
+ query: CustomerTokenDocument,
23
+ data: {
24
+ customerToken: {
25
+ ...currentToken?.customerToken,
26
+ valid: false,
27
+ },
28
+ },
29
+ broadcast: true,
30
+ })
31
+ }
32
+ }}
33
+ >
34
+ break magento token
35
+ </Button>
36
+ </div>
37
+ )
38
+ }
@@ -1,9 +1,11 @@
1
+ import { useApolloClient } from '@graphcommerce/graphql'
1
2
  import { graphqlErrorByCategory } from '@graphcommerce/magento-graphql'
2
3
  import { Button, FormRow, FormActions } from '@graphcommerce/next-ui'
3
4
  import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
4
5
  import { Trans } from '@lingui/react'
5
6
  import { Box, FormControl, Link, SxProps, TextField, Theme } from '@mui/material'
6
7
  import PageLink from 'next/link'
8
+ import { CustomerDocument } from '../../hooks'
7
9
  import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert'
8
10
  import { SignInDocument } from './SignIn.gql'
9
11
 
@@ -11,9 +13,20 @@ type SignInFormProps = { email: string; sx?: SxProps<Theme> }
11
13
 
12
14
  export function SignInForm(props: SignInFormProps) {
13
15
  const { email, sx } = props
16
+
17
+ const client = useApolloClient()
14
18
  const form = useFormGqlMutation(
15
19
  SignInDocument,
16
- { defaultValues: { email }, onBeforeSubmit: (values) => ({ ...values, email }) },
20
+ {
21
+ defaultValues: { email },
22
+ onBeforeSubmit: async (values) => {
23
+ const oldEmail = client.cache.readQuery({ query: CustomerDocument })
24
+ if (oldEmail?.customer?.email !== email) {
25
+ await client.resetStore()
26
+ }
27
+ return { ...values, email }
28
+ },
29
+ },
17
30
  { errorPolicy: 'all' },
18
31
  )
19
32
 
@@ -19,8 +19,7 @@ export function SignOutForm(props: SignOutFormProps) {
19
19
  {
20
20
  onComplete: async () => {
21
21
  await client.clearStore()
22
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
23
- router.push('/')
22
+ await router.push('/')
24
23
  },
25
24
  },
26
25
  { errorPolicy: 'all' },
@@ -41,7 +41,9 @@ export function WaitForCustomer(props: WaitForCustomerProps) {
41
41
 
42
42
  const session = useCustomerSession()
43
43
  const queries = Array.isArray(waitFor) ? waitFor : [waitFor]
44
- const error = mergeErrors(queries.map((query) => query.error).filter(nonNullable))
44
+ const error = mergeErrors(
45
+ queries.map((query) => (typeof query === 'boolean' ? null : query.error)).filter(nonNullable),
46
+ )
45
47
 
46
48
  return (
47
49
  <WaitForQueries
@@ -16,13 +16,28 @@ export type UseCustomerSessionReturn =
16
16
  query: QueryResult<CustomerTokenQuery, CustomerTokenQueryVariables>
17
17
  } & Partial<Omit<NonNullable<CustomerTokenQuery['customerToken']>, '__typename'>>
18
18
 
19
- export function useCustomerSession(
20
- options: UseCustomerSessionOptions = {},
21
- ): UseCustomerSessionReturn {
19
+ export function useCustomerSession(options: UseCustomerSessionOptions = {}) {
20
+ /**
21
+ * We current always assume the initial render is during hydration.
22
+ *
23
+ * How can we determine we're not actually hydrating? Classically you could just use some global
24
+ * state to track this because when the initial render is done, we're not hydrating anymore.
25
+ *
26
+ * However, <Suspense/> can be used to defer the rendering to a later moment. This means that the
27
+ * useCustomerSession hook is called later and we're still in the hydration phase for this
28
+ * component while other components are rendering for the second time.
29
+ */
22
30
  const { hydration = false } = options
23
31
  const [hydrating, setHydrating] = useState(!hydration)
24
32
 
25
- useIsomorphicLayoutEffect(() => startTransition(() => setHydrating(false)), [])
33
+ /**
34
+ * After the initital render we are definitely sure we're not hydrating anymore so we can flip the
35
+ * switch and rerender.
36
+ */
37
+ useIsomorphicLayoutEffect(() => {
38
+ if (!hydrating) return
39
+ startTransition(() => setHydrating(false))
40
+ }, [hydrating])
26
41
 
27
42
  const skip = hydrating
28
43
 
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.11.6",
5
+ "version": "4.12.0",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -19,15 +19,15 @@
19
19
  "type-fest": "^2.12.2"
20
20
  },
21
21
  "dependencies": {
22
- "@graphcommerce/ecommerce-ui": "1.5.2",
23
- "@graphcommerce/framer-utils": "3.2.0",
24
- "@graphcommerce/graphql": "3.4.8",
22
+ "@graphcommerce/ecommerce-ui": "1.5.4",
23
+ "@graphcommerce/framer-utils": "3.2.1",
24
+ "@graphcommerce/graphql": "3.5.0",
25
25
  "@graphcommerce/graphql-mesh": "4.2.0",
26
- "@graphcommerce/image": "3.1.9",
27
- "@graphcommerce/magento-graphql": "3.1.8",
28
- "@graphcommerce/magento-store": "4.3.1",
29
- "@graphcommerce/next-ui": "4.28.0",
30
- "@graphcommerce/react-hook-form": "3.3.4"
26
+ "@graphcommerce/image": "3.1.10",
27
+ "@graphcommerce/magento-graphql": "3.1.9",
28
+ "@graphcommerce/magento-store": "4.3.2",
29
+ "@graphcommerce/next-ui": "4.28.1",
30
+ "@graphcommerce/react-hook-form": "3.3.5"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@lingui/react": "^3.13.2",