@graphcommerce/magento-customer 10.0.0-canary.67 → 10.0.0-canary.72

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/components/AccountAddress/AccountAddress.tsx +4 -4
  3. package/components/AccountAddresses/AccountAddresses.tsx +6 -2
  4. package/components/AccountDeleteForm/AccountDeleteForm.tsx +14 -4
  5. package/components/AccountMenu/AccountMenu.tsx +2 -2
  6. package/components/AccountMenuItem/AccountMenuItem.tsx +19 -16
  7. package/components/ApolloCustomerError/useAuthorizationErrorMasked.ts +2 -2
  8. package/components/CancelOrder/CancelOrderForm.tsx +12 -19
  9. package/components/ConfirmCustomer/ConfirmCustomerForm.tsx +1 -5
  10. package/components/ContactForm/ContactForm.tsx +29 -26
  11. package/components/CreditMemo/CreditMemoCard.tsx +6 -6
  12. package/components/CreditMemo/CreditMemoDetails.tsx +12 -12
  13. package/components/CreditMemo/CreditMemoItems.tsx +5 -4
  14. package/components/CreditMemo/CreditMemoTotals.tsx +7 -8
  15. package/components/CustomerForms/useCustomerCreateForm.ts +2 -2
  16. package/components/CustomerForms/useCustomerUpdateForm.ts +2 -2
  17. package/components/EditAddressForm/EditAddressForm.tsx +0 -2
  18. package/components/ForgotPasswordForm/ForgotPasswordForm.tsx +0 -2
  19. package/components/Invoice/InvoiceCard.tsx +6 -6
  20. package/components/Invoice/InvoiceDetails.tsx +12 -12
  21. package/components/Invoice/InvoiceItems.tsx +5 -4
  22. package/components/Invoice/InvoiceTotals.tsx +7 -8
  23. package/components/NoOrdersFound/NoOrdersFound.tsx +2 -5
  24. package/components/Order/OrderCard/OrderCard.tsx +6 -7
  25. package/components/Order/OrderDetails/OrderDetails.tsx +9 -12
  26. package/components/Order/OrderItems/OrderItems.tsx +5 -4
  27. package/components/Order/OrderStateLabel/OrderStateLabelInline.tsx +12 -13
  28. package/components/Order/OrderTotals/OrderTotals.tsx +7 -8
  29. package/components/Shipment/ShipmentCard.tsx +6 -6
  30. package/components/Shipment/ShipmentDetails.tsx +12 -12
  31. package/components/Shipment/ShipmentItems.tsx +5 -4
  32. package/components/SignInForm/SignInForm.tsx +0 -2
  33. package/components/SignInForm/SignInFormInline.tsx +8 -5
  34. package/components/SignOutForm/signOut.ts +1 -1
  35. package/components/SignUpForm/SignUpForm.tsx +2 -2
  36. package/components/SignUpForm/SignUpFormInline.tsx +3 -1
  37. package/components/TrackingLink/TrackingLink.tsx +5 -5
  38. package/hooks/useCustomerQuery.ts +10 -9
  39. package/hooks/useCustomerSession.ts +1 -2
  40. package/hooks/useGuestQuery.ts +8 -7
  41. package/link/customerLink.ts +40 -31
  42. package/link/xMagentoCacheIdHeader.ts +22 -19
  43. package/package.json +16 -16
@@ -68,7 +68,9 @@ export function SignUpFormInline(props: SignUpFormInlineProps) {
68
68
  ) {
69
69
  return (
70
70
  <Alert>
71
- <Trans>Registration successful. Please check your inbox to confirm your email address ({email})</Trans>
71
+ <Trans>
72
+ Registration successful. Please check your inbox to confirm your email address ({email})
73
+ </Trans>
72
74
  </Alert>
73
75
  )
74
76
  }
@@ -1,4 +1,4 @@
1
- import { iconLocation, IconSvg } from '@graphcommerce/next-ui'
1
+ import { iconLocation, IconSvg, sxx } from '@graphcommerce/next-ui'
2
2
  import { Trans } from '@lingui/react/macro'
3
3
  import type { SxProps, Theme } from '@mui/material'
4
4
  import { Box, Link, Typography } from '@mui/material'
@@ -14,14 +14,14 @@ export function TrackingLink(props: TrackingLinkProps) {
14
14
  return (
15
15
  <Box
16
16
  className='TrackingLink-root'
17
- sx={[
17
+ sx={sxx(
18
18
  (theme) => ({
19
19
  display: 'flex',
20
20
  alignItems: 'center',
21
- color: theme.palette.primary.main,
21
+ color: theme.vars.palette.primary.main,
22
22
  }),
23
- ...(Array.isArray(sx) ? sx : [sx]),
24
- ]}
23
+ sx,
24
+ )}
25
25
  >
26
26
  {number && validUrl && (
27
27
  <Link
@@ -1,17 +1,18 @@
1
- import type {
2
- OperationVariables,
3
- QueryHookOptions,
4
- QueryResult,
5
- TypedDocumentNode,
6
- } from '@graphcommerce/graphql'
1
+ import type { OperationVariables, TypedDocumentNode } from '@graphcommerce/graphql'
7
2
  import { useQuery } from '@graphcommerce/graphql'
3
+ import type { useQuery as useQueryType } from '@apollo/client/react'
8
4
  import { useCustomerSession } from './useCustomerSession'
9
5
 
10
6
  /** Will only execute when the customer is signed in. */
11
7
  export function useCustomerQuery<Q, V extends OperationVariables>(
12
8
  document: TypedDocumentNode<Q, V>,
13
- options: QueryHookOptions<Q, V> = {},
14
- ): QueryResult<Q, V> {
9
+ options?: Omit<useQueryType.Options<Q, V>, 'query'>,
10
+ ) {
15
11
  const { loggedIn } = useCustomerSession()
16
- return useQuery(document, { ...options, ssr: false, skip: options.skip || !loggedIn })
12
+ return useQuery(document, {
13
+ ...options,
14
+ ssr: false,
15
+ returnPartialData: false,
16
+ skip: options?.skip || !loggedIn,
17
+ } as useQueryType.Options<Q, V>)
17
18
  }
@@ -1,4 +1,3 @@
1
- import type { QueryResult } from '@graphcommerce/graphql'
2
1
  import { useQuery } from '@graphcommerce/graphql'
3
2
  import type { CustomerTokenQuery, CustomerTokenQueryVariables } from './CustomerToken.gql'
4
3
  import { CustomerTokenDocument } from './CustomerToken.gql'
@@ -7,7 +6,7 @@ export type UseCustomerSessionOptions = Record<string, unknown>
7
6
 
8
7
  export type UseCustomerSessionReturn = {
9
8
  loggedIn: boolean
10
- query: QueryResult<CustomerTokenQuery, CustomerTokenQueryVariables>
9
+ query: useQuery.Result<CustomerTokenQuery, CustomerTokenQueryVariables>
11
10
  } & Partial<Omit<NonNullable<CustomerTokenQuery['customerToken']>, '__typename'>>
12
11
 
13
12
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -1,16 +1,17 @@
1
- import type {
2
- OperationVariables,
3
- QueryHookOptions,
4
- TypedDocumentNode,
5
- } from '@graphcommerce/graphql'
1
+ import type { OperationVariables, TypedDocumentNode } from '@graphcommerce/graphql'
6
2
  import { useQuery } from '@graphcommerce/graphql'
3
+ import type { useQuery as useQueryType } from '@apollo/client/react'
7
4
  import { useCustomerSession } from './useCustomerSession'
8
5
 
9
6
  /** Will only execute when the customer is not signed in. */
10
7
  export function useGuestQuery<Q, V extends OperationVariables>(
11
8
  document: TypedDocumentNode<Q, V>,
12
- queryOptions: QueryHookOptions<Q, V> = {},
9
+ queryOptions?: Omit<useQueryType.Options<Q, V>, 'query'>,
13
10
  ) {
14
11
  const { token } = useCustomerSession()
15
- return useQuery(document, { ...queryOptions, ssr: false, skip: queryOptions.skip || !!token })
12
+ return useQuery(document, {
13
+ ...queryOptions,
14
+ ssr: false,
15
+ skip: queryOptions?.skip || !!token,
16
+ } as useQueryType.Options<Q, V>)
16
17
  }
@@ -1,6 +1,12 @@
1
1
  import { globalApolloClient } from '@graphcommerce/graphql'
2
2
  import type { ApolloCache } from '@graphcommerce/graphql/apollo'
3
- import { ApolloLink, fromPromise, onError, setContext } from '@graphcommerce/graphql/apollo'
3
+ import {
4
+ ApolloLink,
5
+ CombinedGraphQLErrors,
6
+ ErrorLink,
7
+ SetContextLink,
8
+ } from '@graphcommerce/graphql/apollo'
9
+ import { from, switchMap } from '@graphcommerce/graphql/rxjs'
4
10
  import { magentoVersion } from '@graphcommerce/next-config/config'
5
11
  import type { GraphQLFormattedError } from 'graphql'
6
12
  import type { NextRouter } from 'next/router'
@@ -11,7 +17,7 @@ export type PushRouter = Pick<NextRouter, 'push' | 'events' | 'locale'>
11
17
 
12
18
  declare module '@apollo/client' {
13
19
  interface DefaultContext {
14
- cache?: ApolloCache<unknown>
20
+ cache?: ApolloCache
15
21
  headers?: Record<string, string>
16
22
  }
17
23
  }
@@ -45,31 +51,32 @@ export async function pushWithPromise(router: Pick<NextRouter, 'push' | 'events'
45
51
  })
46
52
  }
47
53
 
48
- const addTokenHeader = setContext((_, context) => {
49
- if (!context.headers) context.headers = {}
54
+ const addTokenHeader = new SetContextLink((prevContext) => {
55
+ const headers: Record<string, string> = { ...prevContext.headers }
50
56
 
51
57
  try {
52
- const query = context.cache?.readQuery({ query: CustomerTokenDocument })
58
+ const query = prevContext.cache?.readQuery({ query: CustomerTokenDocument })
53
59
 
54
60
  if (query?.customerToken?.token && query?.customerToken?.valid !== false) {
55
- context.headers.authorization = `Bearer ${query?.customerToken?.token}`
56
- return context
61
+ headers.authorization = `Bearer ${query?.customerToken?.token}`
57
62
  }
58
- return context
63
+ return { headers }
59
64
  } catch (error) {
60
- return context
65
+ return { headers }
61
66
  }
62
67
  })
63
68
 
64
69
  const customerErrorLink = (router: PushRouter) =>
65
- onError((context) => {
66
- const { graphQLErrors, operation, forward } = context
70
+ new ErrorLink(({ error, operation, forward }) => {
67
71
  const client = globalApolloClient.current
68
72
  if (!client) return undefined
69
73
 
74
+ // Check if this is a GraphQL error
75
+ if (!CombinedGraphQLErrors.is(error)) return undefined
76
+
70
77
  const oldHeaders = operation.getContext().headers
71
78
 
72
- const authError = graphQLErrors?.find(
79
+ const authError = error.errors.find(
73
80
  (err: GraphQLFormattedError) =>
74
81
  err.extensions?.category ===
75
82
  (magentoVersion >= 248 ? 'graphql-authentication' : 'graphql-authorization'),
@@ -99,25 +106,27 @@ const customerErrorLink = (router: PushRouter) =>
99
106
 
100
107
  const signInAgainPromise = pushWithPromise(router, '/account/signin')
101
108
 
102
- return fromPromise(signInAgainPromise).flatMap(() => {
103
- const tokenQuery = client.cache.readQuery({ query: CustomerTokenDocument })
104
-
105
- if (tokenQuery?.customerToken?.valid) {
106
- // Customer is reauthenticated, retrying request.
107
- operation.setContext({
108
- headers: {
109
- ...oldHeaders,
110
- authorization: `Bearer ${tokenQuery?.customerToken?.token}`,
111
- },
112
- })
113
- } else {
114
- // Customer has not reauthenticated, clearing all customer data.
115
- signOut(client)
116
- }
117
-
118
- // retry the request, returning the new observable
119
- return forward(operation)
120
- })
109
+ return from(signInAgainPromise).pipe(
110
+ switchMap(() => {
111
+ const tokenQuery = client.cache.readQuery({ query: CustomerTokenDocument })
112
+
113
+ if (tokenQuery?.customerToken?.valid) {
114
+ // Customer is reauthenticated, retrying request.
115
+ operation.setContext({
116
+ headers: {
117
+ ...oldHeaders,
118
+ authorization: `Bearer ${tokenQuery?.customerToken?.token}`,
119
+ },
120
+ })
121
+ } else {
122
+ // Customer has not reauthenticated, clearing all customer data.
123
+ signOut(client)
124
+ }
125
+
126
+ // retry the request, returning the new observable
127
+ return forward(operation)
128
+ }),
129
+ )
121
130
  })
122
131
 
123
132
  export const customerLink = (router: PushRouter) =>
@@ -1,5 +1,6 @@
1
1
  import type { DefaultContext } from '@graphcommerce/graphql'
2
2
  import { ApolloLink } from '@graphcommerce/graphql'
3
+ import { map } from '@graphcommerce/graphql/rxjs'
3
4
  import { CustomerTokenDocument } from '../hooks'
4
5
 
5
6
  export const xMagentoCacheIdHeader = new ApolloLink((operation, forward) => {
@@ -11,28 +12,30 @@ export const xMagentoCacheIdHeader = new ApolloLink((operation, forward) => {
11
12
  return { ...context, headers: { ...context.headers, 'x-magento-cache-id': xMagentoCacheId } }
12
13
  })
13
14
 
14
- return forward(operation).map((data) => {
15
- const { cache } = operation.getContext()
16
- if (!cache) return data
15
+ return forward(operation).pipe(
16
+ map((data) => {
17
+ const { cache } = operation.getContext()
18
+ if (!cache) return data
17
19
 
18
- const xMagentoCacheId = (
19
- data.extensions as { forwardedHeaders: Record<string, string> } | undefined
20
- )?.forwardedHeaders?.['x-magento-cache-id']
20
+ const xMagentoCacheId = (
21
+ data.extensions as { forwardedHeaders: Record<string, string> } | undefined
22
+ )?.forwardedHeaders?.['x-magento-cache-id']
21
23
 
22
- if (!xMagentoCacheId) return data
24
+ if (!xMagentoCacheId) return data
23
25
 
24
- const tokenResult = cache.readQuery({ query: CustomerTokenDocument })
26
+ const tokenResult = cache.readQuery({ query: CustomerTokenDocument })
25
27
 
26
- if (
27
- !tokenResult?.customerToken ||
28
- tokenResult.customerToken?.xMagentoCacheId === xMagentoCacheId
29
- )
30
- return data
28
+ if (
29
+ !tokenResult?.customerToken ||
30
+ tokenResult.customerToken?.xMagentoCacheId === xMagentoCacheId
31
+ )
32
+ return data
31
33
 
32
- cache.writeQuery({
33
- query: CustomerTokenDocument,
34
- data: { customerToken: { ...tokenResult.customerToken, xMagentoCacheId } },
35
- })
36
- return data
37
- })
34
+ cache.writeQuery({
35
+ query: CustomerTokenDocument,
36
+ data: { customerToken: { ...tokenResult.customerToken, xMagentoCacheId } },
37
+ })
38
+ return data
39
+ }),
40
+ )
38
41
  })
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": "10.0.0-canary.67",
5
+ "version": "10.0.0-canary.72",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -21,24 +21,24 @@
21
21
  "./plugins/magentoCustomerPrivateQueryContext": "./plugins/magentoCustomerPrivateQueryContext.ts"
22
22
  },
23
23
  "peerDependencies": {
24
- "@graphcommerce/ecommerce-ui": "^10.0.0-canary.67",
25
- "@graphcommerce/eslint-config-pwa": "^10.0.0-canary.67",
26
- "@graphcommerce/framer-next-pages": "^10.0.0-canary.67",
27
- "@graphcommerce/framer-utils": "^10.0.0-canary.67",
28
- "@graphcommerce/graphql": "^10.0.0-canary.67",
29
- "@graphcommerce/graphql-mesh": "^10.0.0-canary.67",
30
- "@graphcommerce/image": "^10.0.0-canary.67",
31
- "@graphcommerce/magento-graphql": "^10.0.0-canary.67",
32
- "@graphcommerce/magento-store": "^10.0.0-canary.67",
33
- "@graphcommerce/next-config": "^10.0.0-canary.67",
34
- "@graphcommerce/next-ui": "^10.0.0-canary.67",
35
- "@graphcommerce/prettier-config-pwa": "^10.0.0-canary.67",
36
- "@graphcommerce/react-hook-form": "^10.0.0-canary.67",
37
- "@graphcommerce/typescript-config-pwa": "^10.0.0-canary.67",
24
+ "@graphcommerce/ecommerce-ui": "^10.0.0-canary.72",
25
+ "@graphcommerce/eslint-config-pwa": "^10.0.0-canary.72",
26
+ "@graphcommerce/framer-next-pages": "^10.0.0-canary.72",
27
+ "@graphcommerce/framer-utils": "^10.0.0-canary.72",
28
+ "@graphcommerce/graphql": "^10.0.0-canary.72",
29
+ "@graphcommerce/graphql-mesh": "^10.0.0-canary.72",
30
+ "@graphcommerce/image": "^10.0.0-canary.72",
31
+ "@graphcommerce/magento-graphql": "^10.0.0-canary.72",
32
+ "@graphcommerce/magento-store": "^10.0.0-canary.72",
33
+ "@graphcommerce/next-config": "^10.0.0-canary.72",
34
+ "@graphcommerce/next-ui": "^10.0.0-canary.72",
35
+ "@graphcommerce/prettier-config-pwa": "^10.0.0-canary.72",
36
+ "@graphcommerce/react-hook-form": "^10.0.0-canary.72",
37
+ "@graphcommerce/typescript-config-pwa": "^10.0.0-canary.72",
38
38
  "@lingui/core": "^5",
39
39
  "@lingui/macro": "^5",
40
40
  "@lingui/react": "^5",
41
- "@mui/material": "^5.10.16",
41
+ "@mui/material": "^7.0.0",
42
42
  "framer-motion": "^11.0.0",
43
43
  "graphql": "^16.0.0",
44
44
  "next": "*",