@graphcommerce/magento-cart 9.0.0-canary.114 → 9.0.0-canary.116
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 +4 -0
- package/Config.graphqls +7 -0
- package/components/CartAddressSingleLine/CartAddressSingleLine.tsx +1 -0
- package/hooks/useCartQuery.ts +2 -7
- package/hooks/useMergeCustomerCart.ts +1 -0
- package/index.ts +0 -1
- package/package.json +15 -15
- package/plugins/CartDebuggerPlugin.tsx +42 -0
- package/typePolicies.ts +8 -6
- package/utils/cartPermissions.ts +4 -0
- package/components/CartDebugger/CartDebugger.tsx +0 -30
package/CHANGELOG.md
CHANGED
package/Config.graphqls
CHANGED
|
@@ -5,6 +5,7 @@ import type { CartAddressFragment } from '../CartAddress/CartAddress.gql'
|
|
|
5
5
|
|
|
6
6
|
export type CartAddressSingleLineProps = CartAddressFragment & { locale?: CountryCodeEnum }
|
|
7
7
|
|
|
8
|
+
/** @public */
|
|
8
9
|
export function CartAddressSingleLine(props: CartAddressSingleLineProps) {
|
|
9
10
|
const { locale } = props
|
|
10
11
|
return <AddressSingleLine {...props} country_code={locale} />
|
package/hooks/useCartQuery.ts
CHANGED
|
@@ -17,14 +17,9 @@ import { useCurrentCartId } from './useCurrentCartId'
|
|
|
17
17
|
*/
|
|
18
18
|
export function useCartQuery<Q, V extends { cartId: string; [index: string]: unknown }>(
|
|
19
19
|
document: TypedDocumentNode<Q, V>,
|
|
20
|
-
options: QueryHookOptions<Q, Omit<V, 'cartId'>>
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Not used anymore, when the cart_id is in the URL, it will always be used.
|
|
23
|
-
*/
|
|
24
|
-
allowUrl?: boolean
|
|
25
|
-
} = {},
|
|
20
|
+
options: QueryHookOptions<Q, Omit<V, 'cartId'>> = {},
|
|
26
21
|
) {
|
|
27
|
-
const {
|
|
22
|
+
const { ...queryOptions } = options
|
|
28
23
|
|
|
29
24
|
const router = useRouter()
|
|
30
25
|
const { currentCartId, locked } = useCurrentCartId()
|
package/index.ts
CHANGED
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": "9.0.0-canary.
|
|
5
|
+
"version": "9.0.0-canary.116",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,20 +12,20 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@graphcommerce/ecommerce-ui": "^9.0.0-canary.
|
|
16
|
-
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.
|
|
17
|
-
"@graphcommerce/framer-next-pages": "^9.0.0-canary.
|
|
18
|
-
"@graphcommerce/framer-scroller": "^9.0.0-canary.
|
|
19
|
-
"@graphcommerce/framer-utils": "^9.0.0-canary.
|
|
20
|
-
"@graphcommerce/graphql": "^9.0.0-canary.
|
|
21
|
-
"@graphcommerce/image": "^9.0.0-canary.
|
|
22
|
-
"@graphcommerce/magento-customer": "^9.0.0-canary.
|
|
23
|
-
"@graphcommerce/magento-graphql": "^9.0.0-canary.
|
|
24
|
-
"@graphcommerce/magento-store": "^9.0.0-canary.
|
|
25
|
-
"@graphcommerce/next-ui": "^9.0.0-canary.
|
|
26
|
-
"@graphcommerce/prettier-config-pwa": "^9.0.0-canary.
|
|
27
|
-
"@graphcommerce/react-hook-form": "^9.0.0-canary.
|
|
28
|
-
"@graphcommerce/typescript-config-pwa": "^9.0.0-canary.
|
|
15
|
+
"@graphcommerce/ecommerce-ui": "^9.0.0-canary.116",
|
|
16
|
+
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.116",
|
|
17
|
+
"@graphcommerce/framer-next-pages": "^9.0.0-canary.116",
|
|
18
|
+
"@graphcommerce/framer-scroller": "^9.0.0-canary.116",
|
|
19
|
+
"@graphcommerce/framer-utils": "^9.0.0-canary.116",
|
|
20
|
+
"@graphcommerce/graphql": "^9.0.0-canary.116",
|
|
21
|
+
"@graphcommerce/image": "^9.0.0-canary.116",
|
|
22
|
+
"@graphcommerce/magento-customer": "^9.0.0-canary.116",
|
|
23
|
+
"@graphcommerce/magento-graphql": "^9.0.0-canary.116",
|
|
24
|
+
"@graphcommerce/magento-store": "^9.0.0-canary.116",
|
|
25
|
+
"@graphcommerce/next-ui": "^9.0.0-canary.116",
|
|
26
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.0-canary.116",
|
|
27
|
+
"@graphcommerce/react-hook-form": "^9.0.0-canary.116",
|
|
28
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.0-canary.116",
|
|
29
29
|
"@lingui/core": "^4.2.1",
|
|
30
30
|
"@lingui/macro": "^4.2.1",
|
|
31
31
|
"@lingui/react": "^4.2.1",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { PagesProps } from '@graphcommerce/framer-next-pages'
|
|
2
|
+
import { useApolloClient } from '@graphcommerce/graphql/apollo'
|
|
3
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
4
|
+
import { Button } from '@mui/material'
|
|
5
|
+
import { readCartId, writeCartId } from '../hooks/useAssignCurrentCartId'
|
|
6
|
+
|
|
7
|
+
export const config: PluginConfig = {
|
|
8
|
+
type: 'component',
|
|
9
|
+
module: '@graphcommerce/framer-next-pages',
|
|
10
|
+
ifConfig: 'debug.cart',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function FramerNextPages(props: PluginProps<PagesProps>) {
|
|
14
|
+
const { Prev, ...rest } = props
|
|
15
|
+
const client = useApolloClient()
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<>
|
|
19
|
+
<Prev {...rest} />
|
|
20
|
+
<div style={{ position: 'fixed', bottom: 20, right: 0, zIndex: 1, opacity: 0.3 }}>
|
|
21
|
+
<Button
|
|
22
|
+
type='button'
|
|
23
|
+
variant='text'
|
|
24
|
+
size='small'
|
|
25
|
+
onClick={() => {
|
|
26
|
+
const currentCartId = readCartId(client.cache)
|
|
27
|
+
if (!currentCartId) {
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.log('No customerToken available, nothing to break')
|
|
30
|
+
} else {
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.log('Changing current token to a random one')
|
|
33
|
+
writeCartId(client.cache, `${Math.random().toString(36).slice(2)}random-cardId`)
|
|
34
|
+
}
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
break cart token
|
|
38
|
+
</Button>
|
|
39
|
+
</div>
|
|
40
|
+
</>
|
|
41
|
+
)
|
|
42
|
+
}
|
package/typePolicies.ts
CHANGED
|
@@ -67,11 +67,13 @@ export const migrateCart = (
|
|
|
67
67
|
|
|
68
68
|
// We have special handling for the CartFab because it tries to load data only from the cache.
|
|
69
69
|
const cartFab = oldCache.readQuery({ query: CartFabDocument })
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
if (cartFab) {
|
|
71
|
+
newCache.writeQuery({
|
|
72
|
+
query: CartFabDocument,
|
|
73
|
+
data: cartFab,
|
|
74
|
+
variables: { cartId },
|
|
75
|
+
broadcast: true,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
76
78
|
}
|
|
77
79
|
}
|
package/utils/cartPermissions.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { storefrontConfig } from '@graphcommerce/next-ui'
|
|
2
2
|
|
|
3
|
+
/** @public */
|
|
3
4
|
function getCartPermissions(locale: string | undefined) {
|
|
4
5
|
return (
|
|
5
6
|
storefrontConfig(locale)?.permissions?.cart ??
|
|
@@ -8,14 +9,17 @@ function getCartPermissions(locale: string | undefined) {
|
|
|
8
9
|
)
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
/** @public */
|
|
11
13
|
export function getCartDisabled(locale: string | undefined) {
|
|
12
14
|
return getCartPermissions(locale) === 'DISABLED'
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
/** @public */
|
|
15
18
|
export function getCartGuestEnabled(locale: string | undefined) {
|
|
16
19
|
return getCartPermissions(locale) === 'ENABLED'
|
|
17
20
|
}
|
|
18
21
|
|
|
22
|
+
/** @public */
|
|
19
23
|
export function getCartEnabledForUser(locale: string | undefined, loggedIn: () => boolean) {
|
|
20
24
|
if (getCartGuestEnabled(locale)) return true
|
|
21
25
|
if (getCartDisabled(locale)) return false
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { useApolloClient } from '@graphcommerce/graphql'
|
|
2
|
-
import { Button } from '@mui/material'
|
|
3
|
-
import { readCartId, writeCartId } from '../../hooks'
|
|
4
|
-
|
|
5
|
-
export function CartDebugger() {
|
|
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 currentCartId = readCartId(client.cache)
|
|
16
|
-
if (!currentCartId) {
|
|
17
|
-
// eslint-disable-next-line no-console
|
|
18
|
-
console.log('No customerToken available, nothing to break')
|
|
19
|
-
} else {
|
|
20
|
-
// eslint-disable-next-line no-console
|
|
21
|
-
console.log('Changing current token to a random one')
|
|
22
|
-
writeCartId(client.cache, `${Math.random().toString(36).slice(2)}random-cardId`)
|
|
23
|
-
}
|
|
24
|
-
}}
|
|
25
|
-
>
|
|
26
|
-
break cart
|
|
27
|
-
</Button>
|
|
28
|
-
</div>
|
|
29
|
-
)
|
|
30
|
-
}
|