@graphcommerce/magento-cart 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 +136 -0
- package/hooks/useAssignCurrentCartId.ts +3 -3
- package/hooks/useCartQuery.ts +32 -17
- package/hooks/useCurrentCartId.ts +2 -3
- package/hooks/useFormGqlMutationCart.ts +9 -5
- package/link/cartLink.ts +42 -36
- package/package.json +15 -15
- package/plugins/useSignInFormMergeCart.ts +6 -6
- package/test/fillCartAgreementsForm.ts +1 -4
- package/typePolicies.ts +2 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,141 @@
|
|
|
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
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`cf44b1f`](https://github.com/graphcommerce-org/graphcommerce/commit/cf44b1f723b7f2073a21abd6821768427cb95315) - Added hideTotals to MultiCartStartCheckout ([@paales](https://github.com/paales))
|
|
92
|
+
|
|
93
|
+
- [`d7ad6a3`](https://github.com/graphcommerce-org/graphcommerce/commit/d7ad6a32acdd0c9540656feae9fbb1d5f5f3dbf9) - Additional export for GetCartTotals ([@paales](https://github.com/paales))
|
|
94
|
+
|
|
95
|
+
- [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`af4463d`](https://github.com/graphcommerce-org/graphcommerce/commit/af4463dcbc6903241c8804ffba2f43b2b8e1a00b) - When running a cart mutation and the cartId is already passed to the form we use that value instead of retrieving the current cart again. ([@paales](https://github.com/paales))
|
|
96
|
+
|
|
97
|
+
- [#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))
|
|
98
|
+
|
|
99
|
+
- [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`415f9fb`](https://github.com/graphcommerce-org/graphcommerce/commit/415f9fb50454fb20cb533235969dd9ab4ffc134b) - Allow setting the cartId in the form for useFormGqlMutationCart by setting the cartId in the form AND allow setting the cartId for a whole context by wrapping with CartIdProvider ([@paales](https://github.com/paales))
|
|
100
|
+
|
|
101
|
+
- [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`4e3f3f2`](https://github.com/graphcommerce-org/graphcommerce/commit/4e3f3f2df58638ba8ffc68ee9f274cdd6c45d6d4) - Allow setting the redirect value in the AddProductsToCartForm as a form value. ([@paales](https://github.com/paales))
|
|
102
|
+
|
|
103
|
+
- [#2537](https://github.com/graphcommerce-org/graphcommerce/pull/2537) [`1f37f05`](https://github.com/graphcommerce-org/graphcommerce/commit/1f37f05200e3015bf36d450bffff40c5d551ec54) - Forwarded ref to AddProductsToCartButton ([@paales](https://github.com/paales))
|
|
104
|
+
|
|
105
|
+
- [#2479](https://github.com/graphcommerce-org/graphcommerce/pull/2479) [`ae5e72c`](https://github.com/graphcommerce-org/graphcommerce/commit/ae5e72ccf1c8218ace3cca1c4e52ec8d46821a27) - Solve issue where the total of the cart was zero due to discount or store credit the user couldn't proceed to the checkout. We now check for items and errors instead of the total. ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
|
|
106
|
+
|
|
107
|
+
- [#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))
|
|
108
|
+
|
|
109
|
+
- [#2521](https://github.com/graphcommerce-org/graphcommerce/pull/2521) [`6847259`](https://github.com/graphcommerce-org/graphcommerce/commit/6847259715b0cebcc3f7415ed06cc38814663811) - Solve typescript issue were product types were added incorrectly. ([@paales](https://github.com/paales))
|
|
110
|
+
|
|
111
|
+
- [#2499](https://github.com/graphcommerce-org/graphcommerce/pull/2499) [`35fdadd`](https://github.com/graphcommerce-org/graphcommerce/commit/35fdadd8896619a2c84e91e39279f5928c0c9007) - Removed deprecated fields from AddProductsToCartForm ([@paales](https://github.com/paales))
|
|
112
|
+
|
|
113
|
+
- [#2485](https://github.com/graphcommerce-org/graphcommerce/pull/2485) [`6533728`](https://github.com/graphcommerce-org/graphcommerce/commit/65337280c6f4291cf4354e6ed9659f03388ca8d4) - When ordering a virtual product the checkout would still reference a Track & Trace ([@paales](https://github.com/paales))
|
|
114
|
+
|
|
115
|
+
- [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`af4463d`](https://github.com/graphcommerce-org/graphcommerce/commit/af4463dcbc6903241c8804ffba2f43b2b8e1a00b) - Solve issue where if the onBeforeSubmit would return false, it would still error if submitted while the cart is locked. ([@paales](https://github.com/paales))
|
|
116
|
+
|
|
117
|
+
- [#2499](https://github.com/graphcommerce-org/graphcommerce/pull/2499) [`b26f573`](https://github.com/graphcommerce-org/graphcommerce/commit/b26f57307ab1d08f628183dd86e487ec9aa1e5cf) - Moved all functionality from the @graphcommerce/magento-cart-billing-address package to the @graphcommerce/magento-cart package. All occurences of @graphcommerce/magento-cart-billing-address should be removed for your codebase. ([@paales](https://github.com/paales))
|
|
118
|
+
|
|
119
|
+
- [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`1a06135`](https://github.com/graphcommerce-org/graphcommerce/commit/1a061357f4ccb430dd13194f755815474e140520) - Allow awaitable async requests for onStart on checkout button ([@paales](https://github.com/paales))
|
|
120
|
+
|
|
121
|
+
- [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`4cde990`](https://github.com/graphcommerce-org/graphcommerce/commit/4cde990dbeecdba8a00d0e34a1095fb14d8a0ad6) - When the cart totals are updated via a mutation, make sure to also fetch the id when the query is used so that automatically updates. ([@paales](https://github.com/paales))
|
|
122
|
+
|
|
123
|
+
- [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`7ae2909`](https://github.com/graphcommerce-org/graphcommerce/commit/7ae2909d57e58f00f18acb198028c601ccd857c5) - CartTotals now accepts a readOnly prop to handle plugins showing information based on that prop ([@paales](https://github.com/paales))
|
|
124
|
+
|
|
125
|
+
- [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`b6f76b6`](https://github.com/graphcommerce-org/graphcommerce/commit/b6f76b61f235d3336d8d296f1bed61c9f5daf325) - Solve issue where available_payment_methods would give an apollo client error that it couldn’t be properly merged ([@paales](https://github.com/paales))
|
|
126
|
+
|
|
127
|
+
## 10.0.0-canary.72
|
|
128
|
+
|
|
129
|
+
## 10.0.0-canary.71
|
|
130
|
+
|
|
131
|
+
## 10.0.0-canary.70
|
|
132
|
+
|
|
133
|
+
### Major Changes
|
|
134
|
+
|
|
135
|
+
- [#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))
|
|
136
|
+
|
|
137
|
+
## 10.0.0-canary.69
|
|
138
|
+
|
|
3
139
|
## 10.0.0-canary.68
|
|
4
140
|
|
|
5
141
|
### Major Changes
|
|
@@ -6,7 +6,7 @@ import { CurrentCartIdDocument } from './CurrentCartId.gql'
|
|
|
6
6
|
|
|
7
7
|
export const CART_ID_COOKIE = 'cart'
|
|
8
8
|
|
|
9
|
-
export function writeCartId(cache: ApolloCache
|
|
9
|
+
export function writeCartId(cache: ApolloCache, id: string | null = null) {
|
|
10
10
|
cache.writeQuery({
|
|
11
11
|
query: CurrentCartIdDocument,
|
|
12
12
|
data: { currentCartId: { __typename: 'CurrentCartId', locked: false, id } },
|
|
@@ -14,11 +14,11 @@ export function writeCartId(cache: ApolloCache<object>, id: string | null = null
|
|
|
14
14
|
})
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function readCartId(cache: ApolloCache
|
|
17
|
+
export function readCartId(cache: ApolloCache) {
|
|
18
18
|
return cache.readQuery({ query: CurrentCartIdDocument })?.currentCartId
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function cartLock(cache: ApolloCache
|
|
21
|
+
export function cartLock(cache: ApolloCache, locked: boolean) {
|
|
22
22
|
const currentCartId = cache.readQuery({ query: CurrentCartIdDocument })?.currentCartId
|
|
23
23
|
if (currentCartId?.id && currentCartId.locked !== locked) {
|
|
24
24
|
cache.writeQuery({
|
package/hooks/useCartQuery.ts
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
OperationVariables,
|
|
3
|
+
TypedDocumentNode,
|
|
4
|
+
WatchQueryFetchPolicy,
|
|
5
|
+
} from '@graphcommerce/graphql'
|
|
6
|
+
import { useQuery } from '@graphcommerce/graphql'
|
|
7
|
+
import { CombinedGraphQLErrors } from '@apollo/client/errors'
|
|
8
|
+
import type { useQuery as useQueryType } from '@apollo/client/react'
|
|
3
9
|
import { GraphQLError } from 'graphql'
|
|
4
10
|
import { useRouter } from 'next/router'
|
|
5
11
|
import { useCartShouldLoginToContinue } from './useCartPermissions'
|
|
6
12
|
import { useCurrentCartId } from './useCurrentCartId'
|
|
7
13
|
|
|
14
|
+
type CartQueryOptions<Q, V extends OperationVariables> = Omit<
|
|
15
|
+
useQueryType.Options<Q, V>,
|
|
16
|
+
'variables'
|
|
17
|
+
> & {
|
|
18
|
+
variables?: Omit<V, 'cartId'>
|
|
19
|
+
}
|
|
20
|
+
|
|
8
21
|
/**
|
|
9
22
|
* Requires the query to have a `$cartId: String!` argument. It will automatically inject the
|
|
10
23
|
* currently active cart_id.
|
|
@@ -15,12 +28,10 @@ import { useCurrentCartId } from './useCurrentCartId'
|
|
|
15
28
|
* const { data } = useCartQuery(CartFabQueryDocument)
|
|
16
29
|
* ```
|
|
17
30
|
*/
|
|
18
|
-
export function useCartQuery<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
) {
|
|
22
|
-
const { ...queryOptions } = options
|
|
23
|
-
|
|
31
|
+
export function useCartQuery<
|
|
32
|
+
Q,
|
|
33
|
+
V extends OperationVariables & { cartId: string; [index: string]: unknown },
|
|
34
|
+
>(document: TypedDocumentNode<Q, V>, options?: CartQueryOptions<Q, V>) {
|
|
24
35
|
const router = useRouter()
|
|
25
36
|
const { currentCartId, locked } = useCurrentCartId()
|
|
26
37
|
|
|
@@ -29,23 +40,27 @@ export function useCartQuery<Q, V extends { cartId: string; [index: string]: unk
|
|
|
29
40
|
const cartId = usingUrl ? urlCartId : currentCartId
|
|
30
41
|
const shouldLoginToContinue = useCartShouldLoginToContinue()
|
|
31
42
|
|
|
32
|
-
|
|
43
|
+
let fetchPolicy: WatchQueryFetchPolicy | undefined = options?.fetchPolicy
|
|
44
|
+
let returnPartialData: boolean | undefined = options?.returnPartialData
|
|
33
45
|
|
|
34
|
-
if (usingUrl
|
|
35
|
-
|
|
46
|
+
if (usingUrl || locked) fetchPolicy = 'cache-only'
|
|
47
|
+
if (usingUrl && typeof returnPartialData === 'undefined') returnPartialData = true
|
|
36
48
|
|
|
37
|
-
|
|
49
|
+
const variables = { cartId, ...options?.variables } as V
|
|
38
50
|
|
|
39
51
|
const query = useQuery(document, {
|
|
40
|
-
...
|
|
41
|
-
|
|
52
|
+
...options,
|
|
53
|
+
fetchPolicy,
|
|
54
|
+
returnPartialData,
|
|
55
|
+
variables,
|
|
56
|
+
skip: options?.skip || !cartId || shouldLoginToContinue,
|
|
42
57
|
})
|
|
43
58
|
|
|
44
|
-
if (shouldLoginToContinue && !
|
|
59
|
+
if (shouldLoginToContinue && !options?.skip) {
|
|
45
60
|
return {
|
|
46
61
|
...query,
|
|
47
|
-
error: new
|
|
48
|
-
|
|
62
|
+
error: new CombinedGraphQLErrors({
|
|
63
|
+
errors: [
|
|
49
64
|
new GraphQLError('Action can not be performed by the current user', {
|
|
50
65
|
extensions: { category: 'graphql-authorization' },
|
|
51
66
|
}),
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { QueryHookOptions } from '@graphcommerce/graphql'
|
|
2
1
|
import { useQuery } from '@graphcommerce/graphql'
|
|
3
2
|
import type { CurrentCartIdQuery, CurrentCartIdQueryVariables } from './CurrentCartId.gql'
|
|
4
3
|
import { CurrentCartIdDocument } from './CurrentCartId.gql'
|
|
@@ -6,8 +5,8 @@ import { CurrentCartIdDocument } from './CurrentCartId.gql'
|
|
|
6
5
|
export function useCurrentCartId<
|
|
7
6
|
Q extends CurrentCartIdQuery,
|
|
8
7
|
V extends CurrentCartIdQueryVariables,
|
|
9
|
-
>(options:
|
|
10
|
-
const queryResults = useQuery<Q, V>(CurrentCartIdDocument, options)
|
|
8
|
+
>(options: Partial<useQuery.Options<Q, V>> = {}) {
|
|
9
|
+
const queryResults = useQuery<Q, V>(CurrentCartIdDocument, options as useQuery.Options<Q, V>)
|
|
11
10
|
|
|
12
11
|
return {
|
|
13
12
|
currentCartId: queryResults.data?.currentCartId?.id || '',
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
CombinedGraphQLErrors,
|
|
3
|
+
TypedDocumentNode,
|
|
4
|
+
useApolloClient,
|
|
5
|
+
useMutation,
|
|
6
|
+
} from '@graphcommerce/graphql'
|
|
3
7
|
import type {
|
|
4
8
|
UseFormGqlMutationReturn,
|
|
5
9
|
UseFormGraphQlOptions,
|
|
@@ -18,7 +22,7 @@ export function useFormGqlMutationCart<
|
|
|
18
22
|
>(
|
|
19
23
|
document: TypedDocumentNode<Q, V>,
|
|
20
24
|
options: UseFormGraphQlOptions<Q, V> & { submitWhileLocked?: boolean } = {},
|
|
21
|
-
operationOptions?:
|
|
25
|
+
operationOptions?: useMutation.Options<NoInfer<Q>, NoInfer<V>>,
|
|
22
26
|
): UseFormGqlMutationReturn<Q, V> {
|
|
23
27
|
const cartIdCreate = useCartIdCreate()
|
|
24
28
|
const cartIdFromContext = useCartIdContext()
|
|
@@ -63,8 +67,8 @@ export function useFormGqlMutationCart<
|
|
|
63
67
|
if (shouldLoginToContinue && result.formState.isSubmitted && shouldBlockOperation) {
|
|
64
68
|
return {
|
|
65
69
|
...result,
|
|
66
|
-
error: new
|
|
67
|
-
|
|
70
|
+
error: new CombinedGraphQLErrors({
|
|
71
|
+
errors: [
|
|
68
72
|
new GraphQLError('Action can not be performed by the current user', {
|
|
69
73
|
extensions: { category: 'graphql-authorization' },
|
|
70
74
|
}),
|
package/link/cartLink.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { globalApolloClient } from '@graphcommerce/graphql'
|
|
2
|
+
import { ApolloLink, CombinedGraphQLErrors, ErrorLink } from '@graphcommerce/graphql/apollo'
|
|
3
|
+
import { filter, from, of, switchMap } from '@graphcommerce/graphql/rxjs'
|
|
4
4
|
import { CustomerTokenDocument, getCustomerAccountCanSignIn } from '@graphcommerce/magento-customer'
|
|
5
5
|
import type { PushRouter } from '@graphcommerce/magento-customer/link/customerLink'
|
|
6
6
|
import { pushWithPromise } from '@graphcommerce/magento-customer/link/customerLink'
|
|
@@ -14,8 +14,8 @@ import { CreateEmptyCartDocument } from '../hooks/CreateEmptyCart.gql'
|
|
|
14
14
|
import { getCartEnabledForUser } from '../utils'
|
|
15
15
|
import { isProtectedCartOperation } from './isProtectedCartOperation'
|
|
16
16
|
|
|
17
|
-
type CartOperation = Operation & { variables: { cartId: string } }
|
|
18
|
-
function isCartOperation(operation: Operation): operation is CartOperation {
|
|
17
|
+
type CartOperation = ApolloLink.Operation & { variables: { cartId: string } }
|
|
18
|
+
function isCartOperation(operation: ApolloLink.Operation): operation is CartOperation {
|
|
19
19
|
return typeof operation.variables.cartId === 'string'
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -24,13 +24,16 @@ function errorIsIncluded(errorPath: readonly (string | number)[] | undefined, ke
|
|
|
24
24
|
return keys.some((value) => value === error)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const cartErrorLink =
|
|
27
|
+
const cartErrorLink = new ErrorLink(({ error, operation, forward }) => {
|
|
28
28
|
if (!globalApolloClient.current) return undefined
|
|
29
29
|
|
|
30
30
|
const client = globalApolloClient.current
|
|
31
31
|
const { cache } = client
|
|
32
32
|
|
|
33
|
-
if
|
|
33
|
+
// Check if this is a GraphQL error
|
|
34
|
+
if (!CombinedGraphQLErrors.is(error)) return undefined
|
|
35
|
+
|
|
36
|
+
if (!isCartOperation(operation)) return undefined
|
|
34
37
|
|
|
35
38
|
const isErrorCategory = (err: GraphQLFormattedError, category: ErrorCategory) =>
|
|
36
39
|
err.extensions?.category === category
|
|
@@ -54,7 +57,7 @@ const cartErrorLink = onError(({ graphQLErrors, operation, forward }) => {
|
|
|
54
57
|
// 'applyCouponToCart',
|
|
55
58
|
// 'removeCouponFromCart'
|
|
56
59
|
])
|
|
57
|
-
const cartErr =
|
|
60
|
+
const cartErr = error.errors.find((err) => isNoSuchEntityError(err))
|
|
58
61
|
|
|
59
62
|
if (!cartErr) return undefined
|
|
60
63
|
|
|
@@ -63,9 +66,9 @@ const cartErrorLink = onError(({ graphQLErrors, operation, forward }) => {
|
|
|
63
66
|
if (urlParams.get('cart_id')) return forward(operation)
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
return from(client?.mutate({ mutation: CreateEmptyCartDocument })).pipe(
|
|
70
|
+
filter((value) => Boolean(value)),
|
|
71
|
+
switchMap((cartData) => {
|
|
69
72
|
const cartId = cartData.data?.createEmptyCart
|
|
70
73
|
if (!cartId) return forward(operation)
|
|
71
74
|
|
|
@@ -74,7 +77,8 @@ const cartErrorLink = onError(({ graphQLErrors, operation, forward }) => {
|
|
|
74
77
|
|
|
75
78
|
// retry the request, returning the new observable
|
|
76
79
|
return forward(operation)
|
|
77
|
-
})
|
|
80
|
+
}),
|
|
81
|
+
)
|
|
78
82
|
})
|
|
79
83
|
|
|
80
84
|
const cartPermissionLink = (router: PushRouter) =>
|
|
@@ -82,7 +86,7 @@ const cartPermissionLink = (router: PushRouter) =>
|
|
|
82
86
|
const { locale } = router
|
|
83
87
|
const { cache } = operation.getContext()
|
|
84
88
|
|
|
85
|
-
if (!isProtectedCartOperation(operation.operationName)) return forward(operation)
|
|
89
|
+
if (!isProtectedCartOperation(operation.operationName ?? '')) return forward(operation)
|
|
86
90
|
|
|
87
91
|
const check = () => Boolean(cache?.readQuery({ query: CustomerTokenDocument }))
|
|
88
92
|
if (getCartEnabledForUser(locale, check)) return forward(operation)
|
|
@@ -95,33 +99,35 @@ const cartPermissionLink = (router: PushRouter) =>
|
|
|
95
99
|
const oldHeaders = operation.getContext().headers
|
|
96
100
|
const signInAgainPromise = pushWithPromise(router, '/account/signin')
|
|
97
101
|
|
|
98
|
-
return
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
return from(signInAgainPromise).pipe(
|
|
103
|
+
switchMap(() => {
|
|
104
|
+
const tokenQuery = cache?.readQuery({ query: CustomerTokenDocument })
|
|
105
|
+
|
|
106
|
+
if (tokenQuery?.customerToken?.valid) {
|
|
107
|
+
// Customer is authenticated, retrying request.
|
|
108
|
+
operation.setContext({
|
|
109
|
+
headers: {
|
|
110
|
+
...oldHeaders,
|
|
111
|
+
authorization: `Bearer ${tokenQuery?.customerToken?.token}`,
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
return forward(operation)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return of({
|
|
118
|
+
data: null,
|
|
119
|
+
errors: [
|
|
120
|
+
new GraphQLError(t`Please login to add products to your cart`, {
|
|
121
|
+
extensions: { category: 'graphql-authorization' },
|
|
122
|
+
}),
|
|
123
|
+
],
|
|
108
124
|
})
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return Observable.of({
|
|
113
|
-
data: null,
|
|
114
|
-
errors: [
|
|
115
|
-
new GraphQLError(t`Please login to add products to your cart`, {
|
|
116
|
-
extensions: { category: 'graphql-authorization' },
|
|
117
|
-
}),
|
|
118
|
-
],
|
|
119
|
-
})
|
|
120
|
-
})
|
|
125
|
+
}),
|
|
126
|
+
)
|
|
121
127
|
})
|
|
122
128
|
|
|
123
129
|
export const cartLink = (router: PushRouter) => {
|
|
124
|
-
const links = [cartErrorLink]
|
|
130
|
+
const links: ApolloLink[] = [cartErrorLink]
|
|
125
131
|
|
|
126
132
|
if (!(permissions?.cart === 'ENABLED')) {
|
|
127
133
|
links.push(cartPermissionLink(router))
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/magento-cart",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "10.0.0
|
|
5
|
+
"version": "10.0.0",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -20,20 +20,20 @@
|
|
|
20
20
|
"./plugins/useSignInFormMergeCart": "./plugins/useSignInFormMergeCart.ts"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@graphcommerce/ecommerce-ui": "^10.0.0
|
|
24
|
-
"@graphcommerce/eslint-config-pwa": "^10.0.0
|
|
25
|
-
"@graphcommerce/framer-next-pages": "^10.0.0
|
|
26
|
-
"@graphcommerce/framer-scroller": "^10.0.0
|
|
27
|
-
"@graphcommerce/framer-utils": "^10.0.0
|
|
28
|
-
"@graphcommerce/graphql": "^10.0.0
|
|
29
|
-
"@graphcommerce/image": "^10.0.0
|
|
30
|
-
"@graphcommerce/magento-customer": "^10.0.0
|
|
31
|
-
"@graphcommerce/magento-graphql": "^10.0.0
|
|
32
|
-
"@graphcommerce/magento-store": "^10.0.0
|
|
33
|
-
"@graphcommerce/next-ui": "^10.0.0
|
|
34
|
-
"@graphcommerce/prettier-config-pwa": "^10.0.0
|
|
35
|
-
"@graphcommerce/react-hook-form": "^10.0.0
|
|
36
|
-
"@graphcommerce/typescript-config-pwa": "^10.0.0
|
|
23
|
+
"@graphcommerce/ecommerce-ui": "^10.0.0",
|
|
24
|
+
"@graphcommerce/eslint-config-pwa": "^10.0.0",
|
|
25
|
+
"@graphcommerce/framer-next-pages": "^10.0.0",
|
|
26
|
+
"@graphcommerce/framer-scroller": "^10.0.0",
|
|
27
|
+
"@graphcommerce/framer-utils": "^10.0.0",
|
|
28
|
+
"@graphcommerce/graphql": "^10.0.0",
|
|
29
|
+
"@graphcommerce/image": "^10.0.0",
|
|
30
|
+
"@graphcommerce/magento-customer": "^10.0.0",
|
|
31
|
+
"@graphcommerce/magento-graphql": "^10.0.0",
|
|
32
|
+
"@graphcommerce/magento-store": "^10.0.0",
|
|
33
|
+
"@graphcommerce/next-ui": "^10.0.0",
|
|
34
|
+
"@graphcommerce/prettier-config-pwa": "^10.0.0",
|
|
35
|
+
"@graphcommerce/react-hook-form": "^10.0.0",
|
|
36
|
+
"@graphcommerce/typescript-config-pwa": "^10.0.0",
|
|
37
37
|
"@lingui/core": "^5",
|
|
38
38
|
"@lingui/macro": "^5",
|
|
39
39
|
"@lingui/react": "^5",
|
|
@@ -22,12 +22,12 @@ export const useSignInForm: FunctionPlugin<typeof useSignInFormType> = (useSignI
|
|
|
22
22
|
|
|
23
23
|
cartLock(client.cache, true)
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
25
|
+
const customerCartResult = await client.query({
|
|
26
|
+
query: CustomerCartDocument,
|
|
27
|
+
fetchPolicy: 'network-only',
|
|
28
|
+
})
|
|
29
|
+
const destinationCartId = customerCartResult.data?.customerCart?.id
|
|
30
|
+
if (!destinationCartId) return
|
|
31
31
|
|
|
32
32
|
try {
|
|
33
33
|
const sourceCartId = readCartId(client.cache)?.id
|
|
@@ -3,10 +3,7 @@ import type { ApolloClient, NormalizedCacheObject } from '@graphcommerce/graphql
|
|
|
3
3
|
import type { Page } from '@playwright/test'
|
|
4
4
|
import { CartAgreementsDocument } from '../components/CartAgreementsForm/CartAgreements.gql'
|
|
5
5
|
|
|
6
|
-
export async function fillCartAgreementsForm(
|
|
7
|
-
page: Page,
|
|
8
|
-
client: ApolloClient<NormalizedCacheObject>,
|
|
9
|
-
) {
|
|
6
|
+
export async function fillCartAgreementsForm(page: Page, client: ApolloClient) {
|
|
10
7
|
const res = (await client.query({ query: CartAgreementsDocument })).data
|
|
11
8
|
|
|
12
9
|
for await (const agreement of res.checkoutAgreements ?? []) {
|
package/typePolicies.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ApolloCache,
|
|
3
|
-
NormalizedCacheObject,
|
|
4
|
-
StrictTypedTypePolicies,
|
|
5
|
-
} from '@graphcommerce/graphql'
|
|
1
|
+
import type { ApolloCache, StrictTypedTypePolicies } from '@graphcommerce/graphql'
|
|
6
2
|
import type { CartPrices, QuerycartArgs, ShippingCartAddress } from '@graphcommerce/graphql-mesh'
|
|
7
3
|
import { CartFabDocument } from './components/CartFab/CartFab.gql'
|
|
8
4
|
import { readCartId, writeCartId } from './hooks'
|
|
@@ -57,10 +53,7 @@ export const cartTypePolicies: StrictTypedTypePolicies = {
|
|
|
57
53
|
},
|
|
58
54
|
}
|
|
59
55
|
|
|
60
|
-
export const migrateCart = (
|
|
61
|
-
oldCache: ApolloCache<NormalizedCacheObject>,
|
|
62
|
-
newCache: ApolloCache<NormalizedCacheObject>,
|
|
63
|
-
) => {
|
|
56
|
+
export const migrateCart = (oldCache: ApolloCache, newCache: ApolloCache) => {
|
|
64
57
|
const cartId = readCartId(oldCache)?.id
|
|
65
58
|
|
|
66
59
|
if (cartId) {
|