@graphcommerce/magento-cart 8.1.0-canary.9 → 9.0.0-canary.100

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 (31) hide show
  1. package/Api/CartItemCountChanged.graphql +1 -1
  2. package/CHANGELOG.md +245 -54
  3. package/Config.graphqls +17 -0
  4. package/components/ApolloCartError/ApolloCartErrorAlert.tsx +1 -46
  5. package/components/CartAddress/CartAddress.graphql +1 -0
  6. package/components/CartAgreementsForm/CartAgreementsForm.tsx +60 -33
  7. package/components/CartFab/CartFab.tsx +7 -1
  8. package/components/CartStartCheckout/CartStartCheckout.graphql +1 -1
  9. package/components/CartStartCheckout/CartStartCheckout.tsx +23 -7
  10. package/components/CartStartCheckout/CartStartCheckoutLinkOrButton.tsx +4 -2
  11. package/components/CartTotals/CartTotals.graphql +8 -4
  12. package/components/CartTotals/CartTotals.tsx +9 -6
  13. package/components/EmptyCart/EmptyCart.tsx +8 -4
  14. package/components/InlineAccount/InlineAccount.tsx +6 -6
  15. package/components/OrderSucces/OrderSuccesPage.graphql +1 -1
  16. package/hooks/index.ts +5 -3
  17. package/hooks/useCartPermissions.ts +21 -0
  18. package/hooks/useCartQuery.ts +24 -3
  19. package/hooks/useCheckoutPermissions.ts +21 -0
  20. package/hooks/useFormGqlMutationCart.ts +40 -3
  21. package/index.ts +4 -3
  22. package/link/{createCartErrorLink.ts → cartLink.ts} +60 -4
  23. package/link/isProtectedCartOperation.ts +5 -0
  24. package/package.json +16 -15
  25. package/plugins/MagentoCartGraphqlProvider.tsx +15 -3
  26. package/plugins/useSignInFormMergeCart.ts +8 -7
  27. package/typePolicies.ts +1 -0
  28. package/utils/cartPermissions.ts +23 -0
  29. package/utils/checkoutPermissions.ts +13 -0
  30. package/utils/index.ts +2 -0
  31. package/hooks/CurrentCartId.graphqls +0 -12
@@ -1,14 +1,16 @@
1
1
  import { useApolloClient } from '@graphcommerce/graphql'
2
- import type { useSignInForm } from '@graphcommerce/magento-customer'
3
- import type { MethodPlugin } from '@graphcommerce/next-config'
2
+ import type { useSignInForm as useSignInFormType } from '@graphcommerce/magento-customer'
3
+ import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
4
4
  import { cartLock, readCartId, useAssignCurrentCartId } from '../hooks'
5
5
  import { CustomerCartDocument } from '../hooks/CustomerCart.gql'
6
6
  import { MergeCartsDocument } from '../hooks/MergeCarts.gql'
7
7
 
8
- export const func = 'useSignInForm'
9
- export const exported = '@graphcommerce/magento-customer'
8
+ export const config: PluginConfig = {
9
+ type: 'function',
10
+ module: '@graphcommerce/magento-customer',
11
+ }
10
12
 
11
- const useSignInFormMergeCart: MethodPlugin<typeof useSignInForm> = (useSignInForm, options) => {
13
+ export const useSignInForm: FunctionPlugin<typeof useSignInFormType> = (useSignInForm, options) => {
12
14
  const client = useApolloClient()
13
15
  const assignCurrentCartId = useAssignCurrentCartId()
14
16
 
@@ -16,6 +18,7 @@ const useSignInFormMergeCart: MethodPlugin<typeof useSignInForm> = (useSignInFor
16
18
  ...options,
17
19
  onComplete: async (data, variables) => {
18
20
  await options.onComplete?.(data, variables)
21
+ if (data.errors) return
19
22
 
20
23
  cartLock(client.cache, true)
21
24
 
@@ -46,5 +49,3 @@ const useSignInFormMergeCart: MethodPlugin<typeof useSignInForm> = (useSignInFor
46
49
  },
47
50
  })
48
51
  }
49
-
50
- export const plugin = useSignInFormMergeCart
package/typePolicies.ts CHANGED
@@ -24,6 +24,7 @@ export const cartTypePolicies: StrictTypedTypePolicies = {
24
24
  return merged ? [merged] : []
25
25
  },
26
26
  },
27
+ items: { merge: (_, incoming) => incoming },
27
28
  prices: {
28
29
  merge: (existing: CartPrices[] | undefined, incoming: CartPrices[], options) =>
29
30
  options.mergeObjects(existing ?? {}, incoming),
@@ -0,0 +1,23 @@
1
+ import { storefrontConfig } from '@graphcommerce/next-ui'
2
+
3
+ function getCartPermissions(locale: string | undefined) {
4
+ return (
5
+ storefrontConfig(locale)?.permissions?.cart ??
6
+ import.meta.graphCommerce.permissions?.cart ??
7
+ 'ENABLED'
8
+ )
9
+ }
10
+
11
+ export function getCartDisabled(locale: string | undefined) {
12
+ return getCartPermissions(locale) === 'DISABLED'
13
+ }
14
+
15
+ export function getCartGuestEnabled(locale: string | undefined) {
16
+ return getCartPermissions(locale) === 'ENABLED'
17
+ }
18
+
19
+ export function getCartEnabledForUser(locale: string | undefined, loggedIn: () => boolean) {
20
+ if (getCartGuestEnabled(locale)) return true
21
+ if (getCartDisabled(locale)) return false
22
+ return !!loggedIn()
23
+ }
@@ -0,0 +1,13 @@
1
+ import { storefrontConfig } from '@graphcommerce/next-ui'
2
+
3
+ function getCheckoutPermission(locale: string | undefined) {
4
+ return (
5
+ storefrontConfig(locale)?.permissions?.checkout ??
6
+ import.meta.graphCommerce.permissions?.checkout ??
7
+ 'ENABLED'
8
+ )
9
+ }
10
+
11
+ export function getCheckoutIsDisabled(locale: string | undefined) {
12
+ return getCheckoutPermission(locale) === 'DISABLED'
13
+ }
package/utils/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './cartPermissions'
2
+ export * from './checkoutPermissions'
@@ -1,12 +0,0 @@
1
- extend type Query {
2
- currentCartId: CurrentCartId
3
- }
4
-
5
- type CurrentCartId {
6
- id: String
7
- locked: Boolean
8
- }
9
-
10
- input RegisterCartIdInput {
11
- cart_id: String!
12
- }