@graphcommerce/magento-customer 10.0.0-canary.68 → 10.0.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,143 @@
1
1
  # Change Log
2
2
 
3
+ ## 10.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#2546](https://github.com/graphcommerce-org/graphcommerce/pull/2546) [`ed9332a`](https://github.com/graphcommerce-org/graphcommerce/commit/ed9332a7f78966d932041d9a7725641edc92b28d) - ## GraphCommerce 10 - Turbopack Support
8
+
9
+ This major release brings full Turbopack compatibility, dramatically improving development speed.
10
+
11
+ ### 🚀 Turbopack-Compatible Interceptor System
12
+
13
+ The entire plugin/interceptor system has been rewritten to work with Turbopack:
14
+
15
+ - **No more Webpack plugins** - Removed `InterceptorPlugin` webpack plugin entirely
16
+ - **File-based interception** - Original files are moved to `.original.tsx` and replaced with interceptor content
17
+ - **Direct imports** - Interceptors import from `.original` files instead of embedding source
18
+ - **New CLI commands**:
19
+ - `graphcommerce codegen-interceptors` - Generate interceptor files
20
+ - `graphcommerce cleanup-interceptors` - Reset interceptor system, restore original files
21
+ - **Stable file hashing** - Deterministic interceptor generation for better caching
22
+
23
+ ### ⚙️ Treeshakable Configuration System
24
+
25
+ Replaced Webpack `DefinePlugin`-based `import.meta.graphCommerce` with a new generated configuration system:
26
+
27
+ - **New `codegen-config-values` command** - Generates TypeScript files with precise typing
28
+ - **Schema-driven** - Dynamically introspects Zod schemas to determine all available properties
29
+ - **Fully treeshakable** - Unused config values are eliminated from the bundle
30
+ - **Type-safe** - Uses `Get<GraphCommerceConfig, 'path'>` for nested property access
31
+ - **Separate files for nested objects** - Optimal treeshaking for complex configurations
32
+
33
+ ### 🔧 withGraphCommerce Changes
34
+
35
+ - **Removed** `InterceptorPlugin` - No longer needed with file-based interception
36
+ - **Removed** `DefinePlugin` for `import.meta.graphCommerce` - Replaced with generated config
37
+ - **Removed** `@mui/*` alias rewrites - No longer required
38
+ - **Added** Turbopack loader rules for `.yaml`, `.yml`, and `.po` files
39
+ - **Added** `serverExternalPackages` for all `@whatwg-node/*` packages
40
+ - **Added** `optimizePackageImports` for better bundle optimization
41
+ - **Added** `images.qualities: [52, 75]` for Next.js image optimization
42
+
43
+ ### 📦 Lingui Configuration
44
+
45
+ - **Renamed** `lingui.config.js` → `lingui.config.ts` with TypeScript support
46
+ - **Updated** `@graphcommerce/lingui-next/config` to TypeScript with proper exports
47
+ - **Simplified** formatter options
48
+
49
+ ### ⚛️ React 19 & Next.js 16 Compatibility
50
+
51
+ - Updated `RefObject<T>` types for React 19 (now includes `null` by default)
52
+ - Replaced deprecated `React.VFC` with `React.FC`
53
+ - Fixed `useRef` calls to require explicit initial values
54
+ - Updated `MutableRefObject` usage in `framer-scroller`
55
+
56
+ ### 📋 ESLint 9 Flat Config
57
+
58
+ - Migrated from legacy `.eslintrc` to new flat config format (`eslint.config.mjs`)
59
+ - Updated `@typescript-eslint/*` packages to v8
60
+ - Fixed AST selector for `SxProps` rule (`typeParameters` → `typeArguments`)
61
+
62
+ ### 🔄 Apollo Client
63
+
64
+ - Fixed deprecated `name` option → `clientAwareness: { name: 'ssr' }`
65
+ - Updated error handling types to accept `ApolloError | null | undefined`
66
+
67
+ ### ⚠️ Breaking Changes
68
+
69
+ - **Node.js 24.x not supported** - Restricted to `>=20 <24.0.0` due to [nodejs/undici#4290](https://github.com/nodejs/undici/issues/4290)
70
+ - **Interceptor files changed** - Original components now at `.original.tsx`
71
+ - **Config access changed** - Use generated config values instead of `import.meta.graphCommerce`
72
+ - **ESLint config format** - Must use flat config (`eslint.config.mjs`)
73
+ - **Lingui config** - Rename `lingui.config.js` to `lingui.config.ts`
74
+
75
+ ### 🗑️ Removed
76
+
77
+ - `InterceptorPlugin` webpack plugin
78
+ - `configToImportMeta` utility
79
+ - Webpack `DefinePlugin` usage for config
80
+ - `@mui/*` modern alias rewrites
81
+ - Debug plugins (`CircularDependencyPlugin`, `DuplicatesPlugin`) ([@paales](https://github.com/paales))
82
+
83
+ - [#2557](https://github.com/graphcommerce-org/graphcommerce/pull/2557) [`ceaadd8`](https://github.com/graphcommerce-org/graphcommerce/commit/ceaadd87f0648982a068a3b07b1fa149c9127f49) - ## Material UI v5 → v7 Migration
84
+
85
+ This release upgrades Material UI from v5 to v7 with full CSS variables support. ([@paales](https://github.com/paales))
86
+
87
+ - [#2565](https://github.com/graphcommerce-org/graphcommerce/pull/2565) [`c96dfcd`](https://github.com/graphcommerce-org/graphcommerce/commit/c96dfcdca981baca387c270ad9e2b9515cdd00cc) - Updated to Apollo Client 4 ([@paales](https://github.com/paales))
88
+
89
+ ### Minor Changes
90
+
91
+ - [#2499](https://github.com/graphcommerce-org/graphcommerce/pull/2499) [`20703bc`](https://github.com/graphcommerce-org/graphcommerce/commit/20703bc5c453fb7ee61eb4350e207e84a749bf5e) - Magento 2.4.7: Implemented the `customer_account_create` and `customer_account_edit` forms using the `attributeForm` query for the registration page and customer information form. The forms respect the settings configured in the 'Customer Configuration section'. It allows configuration for `prefix`, `middlename`, `suffix`,`dob`, `gender` and other fields. This also makes the frontend compatible with Adobe Commerce's Customer Attributes module. ([@paales](https://github.com/paales))
92
+
93
+ - [#2499](https://github.com/graphcommerce-org/graphcommerce/pull/2499) [`30f9371`](https://github.com/graphcommerce-org/graphcommerce/commit/30f9371503959b990c65058a88be6f61b4859140) - Added support for viewing Invoices/Shipments and Credit Memo's ([@paales](https://github.com/paales))
94
+
95
+ ### Patch Changes
96
+
97
+ - [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`0cb3ace`](https://github.com/graphcommerce-org/graphcommerce/commit/0cb3aceb09967493ecdd5040446447ff32cc3f43) - Created a AccountDashboardQueryFragment instead of only a query to allow for adding customerDownloadableProducts to the dashboard query ([@paales](https://github.com/paales))
98
+
99
+ - [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`427833d`](https://github.com/graphcommerce-org/graphcommerce/commit/427833d3fa46ec6096853bdc3dfd81321df6e63b) - Forward address field props ([@paales](https://github.com/paales))
100
+
101
+ - [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`c1f04dc`](https://github.com/graphcommerce-org/graphcommerce/commit/c1f04dcb4ddd621361e6c930fb42afae0aabe9f9) - Migrate to default OrderItem resolver and remove useOrderCardItemImages as OrderItem now returns a product. Add a custom resolver for 2.4.5 and 2.4.6 that implements the functionality for older versions. ([@paales](https://github.com/paales))
102
+
103
+ - [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`c1f04dc`](https://github.com/graphcommerce-org/graphcommerce/commit/c1f04dcb4ddd621361e6c930fb42afae0aabe9f9) - Created a refactored the AccountOrders page and refactored the OrderCard. ([@paales](https://github.com/paales))
104
+
105
+ - [#2540](https://github.com/graphcommerce-org/graphcommerce/pull/2540) [`36e2bac`](https://github.com/graphcommerce-org/graphcommerce/commit/36e2bacb4fe765ce1fcd24dc36736e90bb17a7dc) - Add billingAddress permission (EDITABLE | READONLY) that controls whether the end user can update their billing address in the account section and checkout. ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
106
+
107
+ - [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`db56933`](https://github.com/graphcommerce-org/graphcommerce/commit/db569336dddd3e955ff0b5b00cafa25079f1adee) - Implemented order sorting for account overview and account list and implement custom resolver for Magento 2.4.5 (which is slow but works). ([@paales](https://github.com/paales))
108
+
109
+ - [#2499](https://github.com/graphcommerce-org/graphcommerce/pull/2499) [`6cb4815`](https://github.com/graphcommerce-org/graphcommerce/commit/6cb4815a0faf4cc2f60c13d9384e3a96b6bdb2bb) - Deleting an account will now require reauthentication and moved the menu item to the Authentication section ([@paales](https://github.com/paales))
110
+
111
+ - [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`db56933`](https://github.com/graphcommerce-org/graphcommerce/commit/db569336dddd3e955ff0b5b00cafa25079f1adee) - Use OrderStateLabel in my account instead of OrderStateLabelInline and deprecate that one. ([@paales](https://github.com/paales))
112
+
113
+ - [#2524](https://github.com/graphcommerce-org/graphcommerce/pull/2524) [`dcc46aa`](https://github.com/graphcommerce-org/graphcommerce/commit/dcc46aae34f5eda6a633f472289ac4488ac96492) - Solve issue where the user is getting a 400 error when logging in because the password is not being sent. The password field was disabled before the form was submitted, causing the password not to be sent. ([@paales](https://github.com/paales))
114
+
115
+ - [#2553](https://github.com/graphcommerce-org/graphcommerce/pull/2553) [`66ba029`](https://github.com/graphcommerce-org/graphcommerce/commit/66ba029d2cc9dee6f8ff8c92a628d4fc0cf4d309) - Unset token when on magento 248 to prevent repeated graphql-authentication errors ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
116
+
117
+ - [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`dc387da`](https://github.com/graphcommerce-org/graphcommerce/commit/dc387da4c32585c251fe9dec90aa010e2a435df5) - OrderTotals/OrderDetails now only renders addres information if available ([@paales](https://github.com/paales))
118
+
119
+ - [#2529](https://github.com/graphcommerce-org/graphcommerce/pull/2529) [`b331f4d`](https://github.com/graphcommerce-org/graphcommerce/commit/b331f4d060c1385569fbbe1592ac245832de55bc) - Remove all usages of the NoSsr component as the GraphQL layer already handles this. ([@paales](https://github.com/paales))
120
+
121
+ - [`5ca6fb9`](https://github.com/graphcommerce-org/graphcommerce/commit/5ca6fb94f6f275210c77493d05bad7c1620ff5a3) - When a user reorders their cart without interacting with their cart previously a new cart wouldn't be created. ([@paales](https://github.com/paales))
122
+
123
+ - [#2499](https://github.com/graphcommerce-org/graphcommerce/pull/2499) [`2409514`](https://github.com/graphcommerce-org/graphcommerce/commit/240951428ac0bdc11649f4190b6d51c004680b34) - Order/Invoice/CreditMemo and Shipment views ([@paales](https://github.com/paales))
124
+
125
+ - [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`183d8dd`](https://github.com/graphcommerce-org/graphcommerce/commit/183d8ddef6059f07ffe585b0f05a51731b12b371) - Remove odd nonNullable that is also available in @graphcommmerce/next-ui ([@paales](https://github.com/paales))
126
+
127
+ - [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`623e993`](https://github.com/graphcommerce-org/graphcommerce/commit/623e993579b05e053d2d2f29684649cd4f4586de) - `<WaitForCustomer />` now accepts all props of the FullPageMessage ([@paales](https://github.com/paales))
128
+
129
+ ## 10.0.0-canary.72
130
+
131
+ ## 10.0.0-canary.71
132
+
133
+ ## 10.0.0-canary.70
134
+
135
+ ### Major Changes
136
+
137
+ - [#2565](https://github.com/graphcommerce-org/graphcommerce/pull/2565) [`c96dfcd`](https://github.com/graphcommerce-org/graphcommerce/commit/c96dfcdca981baca387c270ad9e2b9515cdd00cc) - Updated to Apollo Client 4 ([@paales](https://github.com/paales))
138
+
139
+ ## 10.0.0-canary.69
140
+
3
141
  ## 10.0.0-canary.68
4
142
 
5
143
  ### Major Changes
@@ -1,9 +1,9 @@
1
- import type { ApolloError } from '@graphcommerce/graphql'
2
1
  import { graphqlErrorByCategory } from '@graphcommerce/magento-graphql'
2
+ import type { ErrorLike } from '@apollo/client'
3
3
  import { t } from '@lingui/core/macro'
4
4
  import { useCustomerSession } from '../../hooks/useCustomerSession'
5
5
 
6
- export function useAuthorizationErrorMasked(error?: ApolloError | null) {
6
+ export function useAuthorizationErrorMasked(error?: ErrorLike | null) {
7
7
  const { token } = useCustomerSession()
8
8
 
9
9
  return graphqlErrorByCategory({
@@ -7,12 +7,13 @@ import {
7
7
  import { Button, Form, FormRow, MessageSnackbar } from '@graphcommerce/next-ui'
8
8
  import { FormPersist, useFormGqlMutation } from '@graphcommerce/react-hook-form'
9
9
  import { Trans } from '@lingui/react/macro'
10
+ import { useEffect } from 'react'
10
11
  import type { CustomerQuery } from '../../hooks'
11
12
  import { CustomerDocument, useCustomerQuery } from '../../hooks'
12
13
  import type { ContactUsMutationVariables } from './ContactUsMutation.gql'
13
14
  import { ContactUsDocument } from './ContactUsMutation.gql'
14
15
 
15
- function findTelephone(data: CustomerQuery): string | undefined {
16
+ function findTelephone(data: Partial<CustomerQuery>): string | undefined {
16
17
  const { customer } = data
17
18
  if (!customer) return undefined
18
19
 
@@ -48,31 +49,33 @@ export function ContactForm() {
48
49
 
49
50
  const { control, formState, error, handleSubmit, setValue, getValues } = form
50
51
 
51
- useCustomerQuery(CustomerDocument, {
52
- onCompleted: (data) => {
53
- if (!data.customer) return
54
-
55
- const telephone = findTelephone(data)
56
-
57
- if (!getValues('input.telephone') && telephone) {
58
- setValue('input.telephone', telephone)
59
- }
60
-
61
- if (!getValues('input.email') && data.customer?.email) {
62
- setValue('input.email', data.customer?.email)
63
- }
64
-
65
- if (!getValues('input.name') && data.customer) {
66
- setValue(
67
- 'input.name',
68
- `${data.customer?.firstname ?? ''} ${data.customer?.middlename ?? ''} ${data.customer?.lastname ?? ''}`.replaceAll(
69
- ' ',
70
- ' ',
71
- ),
72
- )
73
- }
74
- },
75
- })
52
+ const customerQuery = useCustomerQuery(CustomerDocument)
53
+
54
+ // Handle customer data when it's loaded
55
+ useEffect(() => {
56
+ const data = customerQuery.data
57
+ if (!data?.customer) return
58
+
59
+ const telephone = findTelephone(data)
60
+
61
+ if (!getValues('input.telephone') && telephone) {
62
+ setValue('input.telephone', telephone)
63
+ }
64
+
65
+ if (!getValues('input.email') && data.customer?.email) {
66
+ setValue('input.email', data.customer?.email)
67
+ }
68
+
69
+ if (!getValues('input.name') && data.customer) {
70
+ setValue(
71
+ 'input.name',
72
+ `${data.customer?.firstname ?? ''} ${data.customer?.middlename ?? ''} ${data.customer?.lastname ?? ''}`.replaceAll(
73
+ ' ',
74
+ ' ',
75
+ ),
76
+ )
77
+ }
78
+ }, [customerQuery.data, getValues, setValue])
76
79
 
77
80
  const submit = handleSubmit(() => {})
78
81
 
@@ -6,7 +6,7 @@ import {
6
6
  type UseAttributesFormConfig,
7
7
  } from '@graphcommerce/magento-store'
8
8
  import { useFormGqlMutation, type UseFormGraphQlOptions } from '@graphcommerce/react-hook-form'
9
- import type { MutationHookOptions } from '@apollo/client'
9
+ import type { useMutation } from '@apollo/client/react'
10
10
  import {
11
11
  UseCustomerCreateFormDocument,
12
12
  type UseCustomerCreateFormMutation,
@@ -46,7 +46,7 @@ export function useCustomerCreateForm(
46
46
  UseCustomerCreateFormMutation,
47
47
  CreateCustomerFormValues
48
48
  >,
49
- mutationOptions?: MutationHookOptions<UseCustomerCreateFormMutation, CreateCustomerFormValues>,
49
+ mutationOptions?: useMutation.Options<UseCustomerCreateFormMutation, CreateCustomerFormValues>,
50
50
  ) {
51
51
  const attributes = useAttributesForm({
52
52
  formCode: 'customer_account_create',
@@ -7,7 +7,7 @@ import {
7
7
  type UseAttributesFormConfig,
8
8
  } from '@graphcommerce/magento-store'
9
9
  import { useFormGqlMutation, type UseFormGraphQlOptions } from '@graphcommerce/react-hook-form'
10
- import type { MutationHookOptions } from '@apollo/client'
10
+ import type { useMutation } from '@apollo/client/react'
11
11
  import type { OmitDeep } from 'type-fest'
12
12
  import type { CustomerInfoFragment } from '../../hooks'
13
13
  import {
@@ -93,7 +93,7 @@ export function useCustomerUpdateForm(
93
93
  UseCustomerUpdateFormMutation,
94
94
  UpdateCustomerFormValues
95
95
  >,
96
- mutationOptions?: MutationHookOptions<UseCustomerUpdateFormMutation, UpdateCustomerFormValues>,
96
+ mutationOptions?: useMutation.Options<UseCustomerUpdateFormMutation, UpdateCustomerFormValues>,
97
97
  ) {
98
98
  const { customer, ...attributeFormConfig } = config
99
99
  const attributes = useAttributesForm({
@@ -1,7 +1,7 @@
1
1
  import type { ApolloClient } from '@graphcommerce/graphql'
2
2
  import { removeCssFlag } from '@graphcommerce/next-ui'
3
3
 
4
- export function signOut(client: ApolloClient<object>) {
4
+ export function signOut(client: ApolloClient) {
5
5
  removeCssFlag('private-query')
6
6
  globalThis?.sessionStorage?.clear()
7
7
  client.cache.evict({ fieldName: 'currentCartId' })
@@ -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.68",
5
+ "version": "10.0.0",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -21,20 +21,20 @@
21
21
  "./plugins/magentoCustomerPrivateQueryContext": "./plugins/magentoCustomerPrivateQueryContext.ts"
22
22
  },
23
23
  "peerDependencies": {
24
- "@graphcommerce/ecommerce-ui": "^10.0.0-canary.68",
25
- "@graphcommerce/eslint-config-pwa": "^10.0.0-canary.68",
26
- "@graphcommerce/framer-next-pages": "^10.0.0-canary.68",
27
- "@graphcommerce/framer-utils": "^10.0.0-canary.68",
28
- "@graphcommerce/graphql": "^10.0.0-canary.68",
29
- "@graphcommerce/graphql-mesh": "^10.0.0-canary.68",
30
- "@graphcommerce/image": "^10.0.0-canary.68",
31
- "@graphcommerce/magento-graphql": "^10.0.0-canary.68",
32
- "@graphcommerce/magento-store": "^10.0.0-canary.68",
33
- "@graphcommerce/next-config": "^10.0.0-canary.68",
34
- "@graphcommerce/next-ui": "^10.0.0-canary.68",
35
- "@graphcommerce/prettier-config-pwa": "^10.0.0-canary.68",
36
- "@graphcommerce/react-hook-form": "^10.0.0-canary.68",
37
- "@graphcommerce/typescript-config-pwa": "^10.0.0-canary.68",
24
+ "@graphcommerce/ecommerce-ui": "^10.0.0",
25
+ "@graphcommerce/eslint-config-pwa": "^10.0.0",
26
+ "@graphcommerce/framer-next-pages": "^10.0.0",
27
+ "@graphcommerce/framer-utils": "^10.0.0",
28
+ "@graphcommerce/graphql": "^10.0.0",
29
+ "@graphcommerce/graphql-mesh": "^10.0.0",
30
+ "@graphcommerce/image": "^10.0.0",
31
+ "@graphcommerce/magento-graphql": "^10.0.0",
32
+ "@graphcommerce/magento-store": "^10.0.0",
33
+ "@graphcommerce/next-config": "^10.0.0",
34
+ "@graphcommerce/next-ui": "^10.0.0",
35
+ "@graphcommerce/prettier-config-pwa": "^10.0.0",
36
+ "@graphcommerce/react-hook-form": "^10.0.0",
37
+ "@graphcommerce/typescript-config-pwa": "^10.0.0",
38
38
  "@lingui/core": "^5",
39
39
  "@lingui/macro": "^5",
40
40
  "@lingui/react": "^5",