@teamnovu/kit-shopware-composables 0.0.2 → 0.0.4

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 (142) hide show
  1. package/api-types/storeApiSchema.localhost.http +1 -1
  2. package/dist/helpers/checkout/index.d.ts +5 -0
  3. package/dist/helpers/checkout/useAddresses.d.ts +210 -0
  4. package/dist/helpers/checkout/useOrderDetails.d.ts +186 -0
  5. package/dist/helpers/checkout/useOrderPayment.d.ts +73 -0
  6. package/dist/helpers/checkout/usePaymentMethods.d.ts +155 -0
  7. package/dist/helpers/checkout/useShippingMethods.d.ts +173 -0
  8. package/dist/helpers/general/index.d.ts +2 -0
  9. package/dist/{usePagination.d.ts → helpers/general/usePagination.d.ts} +1 -1
  10. package/dist/{general → helpers/general}/useSeoUrl.d.ts +1 -1
  11. package/dist/helpers/index.d.ts +4 -0
  12. package/dist/helpers/product/index.d.ts +2 -0
  13. package/dist/helpers/product/useProductPrice.d.ts +61 -0
  14. package/dist/{products → helpers/product}/useProductVariantForOptions.d.ts +1 -1
  15. package/dist/helpers/user/index.d.ts +2 -0
  16. package/dist/helpers/user/useIsLoggedIn.d.ts +2 -0
  17. package/dist/helpers/user/useUser.d.ts +167 -0
  18. package/dist/index.d.ts +3 -188
  19. package/dist/index.mjs +871 -185
  20. package/dist/inject.d.ts +2 -2
  21. package/dist/keys.d.ts +35 -0
  22. package/dist/query/address/index.d.ts +3 -0
  23. package/dist/query/address/useCreateCustomerAddressMutation.d.ts +166 -0
  24. package/dist/query/address/useDeleteCustomerAddressMutation.d.ts +5 -0
  25. package/dist/query/address/useListAddressQuery.d.ts +48 -0
  26. package/dist/query/cart/index.d.ts +4 -0
  27. package/dist/query/cart/useAddLineItemMutation.d.ts +131 -0
  28. package/dist/query/cart/useReadCartQuery.d.ts +108 -0
  29. package/dist/query/cart/useRemoveLineItemMutation.d.ts +136 -0
  30. package/dist/query/cart/useUpdateLineItemMutation.d.ts +131 -0
  31. package/dist/query/checkout/index.d.ts +2 -0
  32. package/dist/query/checkout/useCheckout.d.ts +1 -0
  33. package/dist/query/checkout/useCreateOrderMutation.d.ts +281 -0
  34. package/dist/query/context/index.d.ts +2 -0
  35. package/dist/query/context/useReadContextQuery.d.ts +153 -0
  36. package/dist/query/context/useUpdateContextMutation.d.ts +60 -0
  37. package/dist/query/customer/index.d.ts +6 -0
  38. package/dist/query/customer/useChangeEmailMutation.d.ts +15 -0
  39. package/dist/query/customer/useChangeProfileMutation.d.ts +15 -0
  40. package/dist/query/customer/useLoginCustomerMutation.d.ts +30 -0
  41. package/dist/query/customer/useLogoutCustomerMutation.d.ts +15 -0
  42. package/dist/query/customer/useReadCustomerQuery.d.ts +220 -0
  43. package/dist/query/customer/useRegisterCustomerMutation.d.ts +266 -0
  44. package/dist/query/index.d.ts +10 -0
  45. package/dist/query/order/index.d.ts +1 -0
  46. package/dist/query/order/useReadOrderQuery.d.ts +44 -0
  47. package/dist/query/payment/index.d.ts +3 -0
  48. package/dist/query/payment/useHandlePaymentMutation.d.ts +15 -0
  49. package/dist/query/payment/useOrderSetPaymentMutation.d.ts +15 -0
  50. package/dist/query/payment/useReadPaymentMethodQuery.d.ts +31 -0
  51. package/dist/query/products/index.d.ts +3 -0
  52. package/dist/query/products/useReadCategoryListQuery.d.ts +48 -0
  53. package/dist/query/products/useReadCompactProductListingQuery.d.ts +35 -0
  54. package/dist/query/products/useReadCustomProductDetailQuery.d.ts +67 -0
  55. package/dist/query/shipping/index.d.ts +1 -0
  56. package/dist/query/shipping/useReadShippingMethodQuery.d.ts +55 -0
  57. package/dist/query/types/index.d.ts +2 -0
  58. package/dist/query/types/operations.d.ts +5 -0
  59. package/dist/query/types/query.d.ts +17 -0
  60. package/dist/util/index.d.ts +3 -0
  61. package/dist/util/unrefOptions.d.ts +4 -0
  62. package/dist/util/useOptimistic.d.ts +12 -0
  63. package/docs/index.md +457 -0
  64. package/docs/info.json +3 -0
  65. package/package.json +6 -2
  66. package/src/helpers/checkout/index.ts +5 -0
  67. package/src/helpers/checkout/useAddresses.ts +57 -0
  68. package/src/helpers/checkout/useOrderDetails.ts +94 -0
  69. package/src/helpers/checkout/useOrderPayment.ts +28 -0
  70. package/src/helpers/checkout/usePaymentMethods.ts +35 -0
  71. package/src/helpers/checkout/useShippingMethods.ts +35 -0
  72. package/src/helpers/general/index.ts +2 -0
  73. package/src/helpers/index.ts +4 -0
  74. package/src/helpers/product/index.ts +2 -0
  75. package/src/{products → helpers/product}/useProductPrice.ts +4 -45
  76. package/src/{products → helpers/product}/useProductVariantForOptions.ts +8 -2
  77. package/src/helpers/user/index.ts +2 -0
  78. package/src/helpers/user/useIsLoggedIn.ts +10 -0
  79. package/src/helpers/user/useUser.ts +53 -0
  80. package/src/index.ts +4 -21
  81. package/src/inject.ts +3 -3
  82. package/src/keys.ts +61 -0
  83. package/src/query/address/index.ts +3 -0
  84. package/src/query/address/useCreateCustomerAddressMutation.ts +32 -0
  85. package/src/query/address/useDeleteCustomerAddressMutation.ts +32 -0
  86. package/src/query/address/useListAddressQuery.ts +29 -0
  87. package/src/query/cart/index.ts +4 -0
  88. package/src/query/cart/useAddLineItemMutation.ts +45 -0
  89. package/src/query/cart/useReadCartQuery.ts +28 -0
  90. package/src/query/cart/useRemoveLineItemMutation.ts +32 -0
  91. package/src/query/cart/useUpdateLineItemMutation.ts +45 -0
  92. package/src/query/checkout/index.ts +2 -0
  93. package/src/query/checkout/useCheckout.ts +2 -0
  94. package/src/query/checkout/useCreateOrderMutation.ts +35 -0
  95. package/src/query/context/index.ts +2 -0
  96. package/src/query/context/useReadContextQuery.ts +19 -0
  97. package/src/query/context/useUpdateContextMutation.ts +36 -0
  98. package/src/query/customer/index.ts +6 -0
  99. package/src/query/customer/useChangeEmailMutation.ts +32 -0
  100. package/src/query/customer/useChangeProfileMutation.ts +32 -0
  101. package/src/query/customer/useLoginCustomerMutation.ts +42 -0
  102. package/src/query/customer/useLogoutCustomerMutation.ts +32 -0
  103. package/src/query/customer/useReadCustomerQuery.ts +27 -0
  104. package/src/query/customer/useRegisterCustomerMutation.ts +32 -0
  105. package/src/query/index.ts +10 -0
  106. package/src/query/order/index.ts +1 -0
  107. package/src/query/order/useReadOrderQuery.ts +33 -0
  108. package/src/query/payment/index.ts +3 -0
  109. package/src/query/payment/useHandlePaymentMutation.ts +27 -0
  110. package/src/query/payment/useOrderSetPaymentMutation.ts +32 -0
  111. package/src/query/payment/useReadPaymentMethodQuery.ts +30 -0
  112. package/src/query/products/index.ts +3 -0
  113. package/src/query/products/useReadCategoryListQuery.ts +28 -0
  114. package/src/query/products/useReadCompactProductListingQuery.ts +41 -0
  115. package/src/query/products/useReadCustomProductDetailQuery.ts +41 -0
  116. package/src/query/shipping/index.ts +1 -0
  117. package/src/query/shipping/useReadShippingMethodQuery.ts +29 -0
  118. package/src/query/types/index.ts +2 -0
  119. package/src/query/types/operations.ts +6 -0
  120. package/src/query/types/query.ts +39 -0
  121. package/src/util/index.ts +3 -0
  122. package/src/util/unrefOptions.ts +19 -0
  123. package/src/util/useOptimistic.ts +49 -0
  124. package/tsconfig.json +5 -2
  125. package/dist/context/useContextOptions.d.ts +0 -9
  126. package/dist/context/useContextUpdate.d.ts +0 -4
  127. package/dist/products/useCategoryQueryOptions.d.ts +0 -17
  128. package/dist/products/useProductListingQueryOptions.d.ts +0 -19
  129. package/dist/products/useProductListingQueryOptions.test.d.ts +0 -1
  130. package/dist/products/useProductPrice.d.ts +0 -48
  131. package/dist/products/useProductQueryOptions.d.ts +0 -19
  132. package/dist/types/query.d.ts +0 -7
  133. package/eslint.config.mjs +0 -84
  134. package/src/context/useContextOptions.ts +0 -16
  135. package/src/context/useContextUpdate.ts +0 -16
  136. package/src/products/useCategoryQueryOptions.ts +0 -25
  137. package/src/products/useProductListingQueryOptions.test.ts +0 -24
  138. package/src/products/useProductListingQueryOptions.ts +0 -28
  139. package/src/products/useProductQueryOptions.ts +0 -28
  140. package/src/types/query.ts +0 -18
  141. /package/src/{usePagination.ts → helpers/general/usePagination.ts} +0 -0
  142. /package/src/{general → helpers/general}/useSeoUrl.ts +0 -0
@@ -0,0 +1,35 @@
1
+ import { computed } from 'vue'
2
+ import { useReadShippingMethodQuery } from '../../query'
3
+ import { useReadContextQuery } from '../../query/context/useReadContextQuery'
4
+ import { useUpdateContextMutation } from '../../query/context/useUpdateContextMutation'
5
+
6
+ export function useShippingMethods() {
7
+ const contextQuery = useReadContextQuery()
8
+ const contextUpdateMutation = useUpdateContextMutation()
9
+ const shippingMethodsQuery = useReadShippingMethodQuery({
10
+ query: {
11
+ onlyActive: true,
12
+ },
13
+ })
14
+
15
+ const isSaving = computed(() => contextUpdateMutation.isPending.value)
16
+
17
+ const setShippingMethod = async (shippingMethodId: string) => {
18
+ return contextUpdateMutation.mutateAsync({
19
+ shippingMethodId,
20
+ })
21
+ }
22
+
23
+ const activeShippingMethod = computed(() => contextQuery.data?.value?.shippingMethod)
24
+ const shippingMethods = computed(() => shippingMethodsQuery.data?.value?.elements)
25
+
26
+ return {
27
+ contextUpdateMutation,
28
+ contextQuery,
29
+ shippingMethodsQuery,
30
+ activeShippingMethod,
31
+ setShippingMethod,
32
+ isSaving,
33
+ shippingMethods,
34
+ }
35
+ }
@@ -0,0 +1,2 @@
1
+ export * from './useSeoUrl'
2
+ export * from './usePagination'
@@ -0,0 +1,4 @@
1
+ export * from './checkout'
2
+ export * from './general'
3
+ export * from './product'
4
+ export * from './user'
@@ -0,0 +1,2 @@
1
+ export * from './useProductPrice'
2
+ export * from './useProductVariantForOptions'
@@ -1,64 +1,23 @@
1
1
  /**
2
2
  * Copied from:
3
- * https://github.com/shopware/frontends/blob/main/packages/composables/src/useProductPrice/useProductPrice.ts#L7
3
+ * https://github.com/shopware/frontends/blob/main/packages/composables/src/useProductPrice/useProductPrice.ts
4
4
  */
5
5
 
6
6
  import type { Schemas } from '#store-types'
7
- import type { TierPrice } from '@shopware/helpers'
8
7
  import { getProductTierPrices } from '@shopware/helpers'
9
8
  import type { ComputedRef, Ref } from 'vue'
10
9
  import { computed } from 'vue'
11
10
 
12
- export type UseProductPriceReturn = {
13
- /**
14
- * Whole calculated price object
15
- */
16
- price: ComputedRef<Schemas['CalculatedPrice'] | undefined>
17
- /**
18
- * Calculated price value for one selling unit
19
- */
20
- totalPrice: ComputedRef<number | undefined>
21
- /**
22
- * Current unit price value
23
- */
24
- unitPrice: ComputedRef<number | undefined>
25
- /**
26
- * Can be used if isListPrice is set to true
27
- */
28
- referencePrice: ComputedRef<
29
- Schemas['CalculatedPrice']['referencePrice'] | undefined
30
- >
31
- /**
32
- * determines if `price` contains the minimum tier price
33
- */
34
- displayFrom: ComputedRef<boolean>
35
- /**
36
- * cheapest price value for a variant if exists
37
- */
38
- displayFromVariants: ComputedRef<number | false | undefined>
39
- /**
40
- * array of TierPrice object
41
- */
42
- tierPrices: ComputedRef<TierPrice[]>
43
- /**
44
- * determines whether a discount price is set
45
- */
46
- isListPrice: ComputedRef<boolean>
47
- /**
48
- * price for products with regulation price
49
- */
50
- regulationPrice: ComputedRef<number | undefined>
51
- }
52
-
53
11
  /**
54
- * The purpose of the `useProductPrice` function is to abstract the logic to expose most useful helpers for price displaying.
12
+ * The purpose of the `useProductPrice` function is to abstract the logic
13
+ * to expose most useful helpers for price displaying.
55
14
  *
56
15
  * @public
57
16
  * @category Product
58
17
  */
59
18
  export function useProductPrice(
60
19
  product: Ref<Schemas['Product'] | undefined>,
61
- ): UseProductPriceReturn {
20
+ ) {
62
21
  const _cheapest: ComputedRef<
63
22
  Schemas['Product']['calculatedCheapestPrice'] | undefined
64
23
  > = computed(() => product.value?.calculatedCheapestPrice)
@@ -4,7 +4,10 @@ import { computed, unref } from 'vue'
4
4
 
5
5
  type DetailProduct<S extends Schemas> = S['CustomProductDetailResponse']['product']
6
6
 
7
- export function getProductVariantForOptions<S extends Schemas>(product: DetailProduct<S>, optionIds: string[]) {
7
+ export function getProductVariantForOptions<S extends Schemas>(
8
+ product: DetailProduct<S>,
9
+ optionIds: string[],
10
+ ) {
8
11
  const variants = product.extensions?.variants
9
12
 
10
13
  if (optionIds.length === 0) {
@@ -16,6 +19,9 @@ export function getProductVariantForOptions<S extends Schemas>(product: DetailPr
16
19
  return variants?.find(v => v.optionIds?.every(optId => optionIds.includes(optId)))
17
20
  }
18
21
 
19
- export function useProductVariantForOptions<S extends Schemas>(product: MaybeRef<DetailProduct<S>>, optionIds: MaybeRef<string[]>) {
22
+ export function useProductVariantForOptions<S extends Schemas>(
23
+ product: MaybeRef<DetailProduct<S>>,
24
+ optionIds: MaybeRef<string[]>,
25
+ ) {
20
26
  return computed(() => getProductVariantForOptions(unref(product), unref(optionIds)))
21
27
  }
@@ -0,0 +1,2 @@
1
+ export * from './useIsLoggedIn'
2
+ export * from './useUser'
@@ -0,0 +1,10 @@
1
+ import { computed } from 'vue'
2
+ import { useReadContextQuery } from '../../query/context/useReadContextQuery'
3
+
4
+ export function useIsLoggedIn() {
5
+ const { data: context } = useReadContextQuery()
6
+
7
+ return computed(() => !!context.value?.customer?.id
8
+ && !!context.value?.customer?.active
9
+ && !context.value?.customer?.guest)
10
+ }
@@ -0,0 +1,53 @@
1
+ import { computed } from 'vue'
2
+ import {
3
+ useReadCustomerQuery,
4
+ } from '../../query/customer'
5
+ import { Schemas } from '../../query/types'
6
+
7
+ export function useUser(criteria?: Schemas['Criteria']) {
8
+ // Create customer query
9
+ const customerQuery = useReadCustomerQuery(criteria ? { body: criteria } : undefined)
10
+
11
+ const user = computed(() => customerQuery.data?.value)
12
+
13
+ const isLoggedIn = computed(
14
+ () => !!user.value?.id && !!user.value.active && !user.value.guest,
15
+ )
16
+
17
+ const isCustomerSession = computed(
18
+ () => !!user.value?.id && !user.value.guest,
19
+ )
20
+
21
+ const isGuestSession = computed(() => !!user.value?.guest)
22
+
23
+ const defaultBillingAddressId = computed(
24
+ () => user.value?.defaultBillingAddressId || null,
25
+ )
26
+
27
+ const defaultShippingAddressId = computed(
28
+ () => user.value?.defaultShippingAddressId || null,
29
+ )
30
+
31
+ const userDefaultBillingAddress = computed(
32
+ () => user.value?.defaultBillingAddress || null,
33
+ )
34
+
35
+ const userDefaultShippingAddress = computed(
36
+ () => user.value?.defaultShippingAddress || null,
37
+ )
38
+
39
+ return {
40
+ // Computed properties
41
+ user,
42
+ isLoggedIn,
43
+ isCustomerSession,
44
+ isGuestSession,
45
+ defaultBillingAddressId,
46
+ defaultShippingAddressId,
47
+ userDefaultBillingAddress,
48
+ userDefaultShippingAddress,
49
+
50
+ // Expose queries and mutations directly
51
+ customerQuery,
52
+ }
53
+ }
package/src/index.ts CHANGED
@@ -1,24 +1,7 @@
1
- import type { Schemas as BaseSchemas, operations } from '#store-types'
2
- import { useContextOptions } from './context/useContextOptions'
3
- import { useContextUpdate } from './context/useContextUpdate'
4
- import { useCategoryQueryOptions } from './products/useCategoryQueryOptions'
5
- import { useProductListingQueryOptions } from './products/useProductListingQueryOptions'
6
- import { useProductQueryOptions } from './products/useProductQueryOptions'
7
- import { useProductVariantForOptions } from './products/useProductVariantForOptions'
1
+ import './query/types'
8
2
 
9
- export * from './general/useSeoUrl'
10
3
  export * from './inject'
11
4
  export * from './keys'
12
- export * from './products/useProductPrice'
13
- export * from './products/useProductVariantForOptions'
14
- export * from './usePagination'
15
- export * from './util/url'
16
-
17
- export default class ShopwareComposables<Operations extends operations, Schemas extends BaseSchemas> {
18
- useProductListingQueryOptions = useProductListingQueryOptions<Operations>
19
- useCategoryQueryOptions = useCategoryQueryOptions<Operations>
20
- useContextOptions = useContextOptions<Operations>
21
- useContextUpdate = useContextUpdate<Operations>
22
- useProductQueryOptions = useProductQueryOptions<Operations>
23
- useProductVariantForOptions = useProductVariantForOptions<Schemas>
24
- }
5
+ export * from './helpers'
6
+ export * from './query'
7
+ export * from './util'
package/src/inject.ts CHANGED
@@ -1,16 +1,16 @@
1
- import type { operations } from '#store-types'
2
1
  import type { ShopwareClient } from '@teamnovu/kit-shopware-api-client'
3
2
  import type { InjectionKey } from 'vue'
4
3
  import { inject } from 'vue'
4
+ import { Operations } from './query/types/operations'
5
5
 
6
6
  export const shopwareClientKey = Symbol('shopwareClient') as InjectionKey<ShopwareClient<never>>
7
7
 
8
- export function useShopwareQueryClient<Operations>() {
8
+ export function useShopwareQueryClient() {
9
9
  const client = inject(shopwareClientKey)
10
10
 
11
11
  if (!client) {
12
12
  throw new Error('Shopware client not provided!')
13
13
  }
14
14
 
15
- return client as ShopwareClient<operations & Operations>
15
+ return client as ShopwareClient<Operations>
16
16
  }
package/src/keys.ts CHANGED
@@ -40,3 +40,64 @@ export const productKeys = {
40
40
  },
41
41
  ] as const,
42
42
  }
43
+
44
+ export const cartKeys = {
45
+ get: () => ['cart'] as const,
46
+ }
47
+
48
+ export const customerKeys = {
49
+ get: () => ['customer'] as const,
50
+ }
51
+
52
+ export const addressKeys = {
53
+ all: () => ['address'] as const,
54
+ lists: () => [...addressKeys.all(), 'list'] as const,
55
+ list: (body: MaybeRef<unknown>) =>
56
+ [
57
+ ...addressKeys.all(),
58
+ 'list',
59
+ {
60
+ body,
61
+ },
62
+ ] as const,
63
+ }
64
+
65
+ export const shippingKeys = {
66
+ all: () => ['shippingMethod'] as const,
67
+ lists: () => [...shippingKeys.all(), 'list'] as const,
68
+ list: (body: MaybeRef<unknown>) =>
69
+ [
70
+ ...shippingKeys.all(),
71
+ 'list',
72
+ {
73
+ body,
74
+ },
75
+ ] as const,
76
+ }
77
+
78
+ export const paymentKeys = {
79
+ all: () => ['paymentMethod'] as const,
80
+ lists: () => [...paymentKeys.all(), 'list'] as const,
81
+ list: (body: MaybeRef<unknown>) =>
82
+ [
83
+ ...paymentKeys.all(),
84
+ 'list',
85
+ {
86
+ body,
87
+ },
88
+ ] as const,
89
+ }
90
+
91
+ export const orderKeys = {
92
+ all: () => ['order'] as const,
93
+ lists: () => [...orderKeys.all(), 'list'] as const,
94
+ details: () => [...orderKeys.all(), 'detail'] as const,
95
+ detail: (body: MaybeRef<unknown>) =>
96
+ [
97
+ ...orderKeys.all(),
98
+ 'detail',
99
+ {
100
+ body,
101
+ },
102
+ ] as const,
103
+ }
@@ -0,0 +1,3 @@
1
+ export * from './useListAddressQuery'
2
+ export * from './useCreateCustomerAddressMutation'
3
+ export * from './useDeleteCustomerAddressMutation'
@@ -0,0 +1,32 @@
1
+ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
2
+ import { unref } from 'vue'
3
+ import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
4
+ import { useShopwareQueryClient } from '../../inject'
5
+ import { addressKeys } from '../../keys'
6
+ import { unrefOptions } from '../../util/unrefOptions'
7
+
8
+ const createCustomerAddressOperation = 'createCustomerAddress post /account/address' satisfies OperationKey
9
+
10
+ export function useCreateCustomerAddressMutation(
11
+ mutationOptions?: UseMutationOptions<
12
+ OperationResponse<typeof createCustomerAddressOperation>,
13
+ unknown,
14
+ OperationOptions<typeof createCustomerAddressOperation>
15
+ >,
16
+ ) {
17
+ const client = useShopwareQueryClient()
18
+ const queryClient = useQueryClient()
19
+
20
+ return useMutation({
21
+ ...mutationOptions,
22
+ mutationFn: async (options: OperationOptions<typeof createCustomerAddressOperation>) => {
23
+ return client.query(createCustomerAddressOperation, unrefOptions(options))
24
+ },
25
+ onSuccess: (data, variables, context) => {
26
+ // Invalidate address list queries to refetch data
27
+ queryClient.invalidateQueries({ queryKey: addressKeys.lists() })
28
+
29
+ unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
30
+ },
31
+ })
32
+ }
@@ -0,0 +1,32 @@
1
+ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
2
+ import { unref } from 'vue'
3
+ import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
4
+ import { useShopwareQueryClient } from '../../inject'
5
+ import { addressKeys } from '../../keys'
6
+ import { unrefOptions } from '../../util/unrefOptions'
7
+
8
+ const deleteCustomerAddressOperation = 'deleteCustomerAddress delete /account/address/{addressId}' satisfies OperationKey
9
+
10
+ export function useDeleteCustomerAddressMutation(
11
+ mutationOptions?: UseMutationOptions<
12
+ OperationResponse<typeof deleteCustomerAddressOperation>,
13
+ unknown,
14
+ OperationOptions<typeof deleteCustomerAddressOperation>
15
+ >,
16
+ ) {
17
+ const client = useShopwareQueryClient()
18
+ const queryClient = useQueryClient()
19
+
20
+ return useMutation({
21
+ ...mutationOptions,
22
+ mutationFn: async (options: OperationOptions<typeof deleteCustomerAddressOperation>) => {
23
+ return client.query(deleteCustomerAddressOperation, unrefOptions(options))
24
+ },
25
+ onSuccess: (data, variables, context) => {
26
+ // Invalidate address list queries to refetch data
27
+ queryClient.invalidateQueries({ queryKey: addressKeys.lists() })
28
+
29
+ unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
30
+ },
31
+ })
32
+ }
@@ -0,0 +1,29 @@
1
+ import { queryOptions, useQuery } from '@tanstack/vue-query'
2
+ import { computed } from 'vue'
3
+ import { useShopwareQueryClient } from '../../inject'
4
+ import { addressKeys } from '../../keys'
5
+ import { unrefOptions } from '../../util/unrefOptions'
6
+ import type { OperationKey, OperationOptions } from '../types/query'
7
+
8
+ const listAddressOperation = 'listAddress post /account/list-address' satisfies OperationKey
9
+
10
+ export function useListAddressQueryOptions(
11
+ options?: OperationOptions<typeof listAddressOperation>,
12
+ ) {
13
+ const client = useShopwareQueryClient()
14
+ const queryKey = addressKeys.list(computed(() => unrefOptions(options)?.body))
15
+
16
+ return queryOptions({
17
+ queryKey,
18
+ queryFn: ({ signal }) => client.query(listAddressOperation, {
19
+ ...unrefOptions(options),
20
+ signal,
21
+ }),
22
+ })
23
+ }
24
+
25
+ export function useListAddressQuery(
26
+ options?: OperationOptions<typeof listAddressOperation>,
27
+ ) {
28
+ return useQuery(useListAddressQueryOptions(options))
29
+ }
@@ -0,0 +1,4 @@
1
+ export * from './useAddLineItemMutation'
2
+ export * from './useReadCartQuery'
3
+ export * from './useRemoveLineItemMutation'
4
+ export * from './useUpdateLineItemMutation'
@@ -0,0 +1,45 @@
1
+ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
2
+ import { unref } from 'vue'
3
+ import type { OperationBody, OperationKey, OperationResponse } from '../types/query'
4
+ import { useShopwareQueryClient } from '../../inject'
5
+ import { cartKeys } from '../../keys'
6
+
7
+ const addCartItemOperation = 'addLineItem post /checkout/cart/line-item' satisfies OperationKey
8
+
9
+ type LineItem = OperationBody<typeof addCartItemOperation>['items'][number]
10
+
11
+ type LineItemPayload =
12
+ Partial<Omit<LineItem, 'id' | 'quantity' | 'type'>> &
13
+ Required<Pick<LineItem, 'id' | 'quantity' | 'type'>>
14
+
15
+ type Body = Omit<
16
+ OperationBody<typeof addCartItemOperation>,
17
+ 'items'
18
+ > & {
19
+ items: LineItemPayload[]
20
+ }
21
+
22
+ export function useAddLineItemMutation(
23
+ mutationOptions: UseMutationOptions<
24
+ OperationResponse<typeof addCartItemOperation>,
25
+ unknown,
26
+ Body
27
+ >,
28
+ ) {
29
+ const client = useShopwareQueryClient()
30
+ const queryClient = useQueryClient()
31
+
32
+ return useMutation({
33
+ ...mutationOptions,
34
+ mutationFn: async (body: Body) => {
35
+ return client.query(addCartItemOperation, {
36
+ body: body as OperationBody<typeof addCartItemOperation>,
37
+ })
38
+ },
39
+ onSuccess: (newCart, variables, context) => {
40
+ queryClient.setQueryData(cartKeys.get(), newCart)
41
+ // queryClient.invalidateQueries({ queryKey: cartKeys.get() })
42
+ unref(unref(mutationOptions).onSuccess)?.(newCart, variables, context)
43
+ },
44
+ })
45
+ }
@@ -0,0 +1,28 @@
1
+ import { queryOptions, useQuery } from '@tanstack/vue-query'
2
+ import { useShopwareQueryClient } from '../../inject'
3
+ import { cartKeys } from '../../keys'
4
+ import { unrefOptions } from '../../util'
5
+ import type { OperationKey, OperationOptions } from '../types/query'
6
+
7
+ const readCartOperation = 'readCart get /checkout/cart' satisfies OperationKey
8
+
9
+ export function useReadCartQueryOptions(
10
+ options?: OperationOptions<typeof readCartOperation>,
11
+ ) {
12
+ const client = useShopwareQueryClient()
13
+ const queryKey = cartKeys.get()
14
+
15
+ return queryOptions({
16
+ queryKey,
17
+ queryFn: async ({ signal }) => {
18
+ return client.query(readCartOperation, {
19
+ ...unrefOptions(options),
20
+ signal,
21
+ })
22
+ },
23
+ })
24
+ }
25
+
26
+ export function useReadCartQuery() {
27
+ return useQuery(useReadCartQueryOptions())
28
+ }
@@ -0,0 +1,32 @@
1
+ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
2
+ import { unref } from 'vue'
3
+ import type { OperationBody, OperationKey, OperationResponse } from '../types/query'
4
+ import { useShopwareQueryClient } from '../../inject'
5
+ import { cartKeys } from '../../keys'
6
+
7
+ const removeCartItemOperation = 'removeLineItem post /checkout/cart/line-item/delete' satisfies OperationKey
8
+
9
+ export function useRemoveLineItemMutation(
10
+ mutationOptions?: UseMutationOptions<
11
+ OperationResponse<typeof removeCartItemOperation>,
12
+ unknown,
13
+ OperationBody<typeof removeCartItemOperation>
14
+ >,
15
+ ) {
16
+ const client = useShopwareQueryClient()
17
+ const queryClient = useQueryClient()
18
+
19
+ return useMutation({
20
+ ...mutationOptions,
21
+ mutationFn: async (body: OperationBody<typeof removeCartItemOperation>) => {
22
+ return client.query(removeCartItemOperation, {
23
+ body: body as OperationBody<typeof removeCartItemOperation>,
24
+ })
25
+ },
26
+ onSuccess: (newCart, variables, context) => {
27
+ queryClient.setQueryData(cartKeys.get(), newCart)
28
+ // queryClient.invalidateQueries({ queryKey: cartKeys.get() })
29
+ unref(unref(mutationOptions)?.onSuccess)?.(newCart, variables, context)
30
+ },
31
+ })
32
+ }
@@ -0,0 +1,45 @@
1
+ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
2
+ import { unref } from 'vue'
3
+ import { useShopwareQueryClient } from '../../inject'
4
+ import { cartKeys } from '../../keys'
5
+ import type { OperationBody, OperationKey, OperationResponse } from '../types/query'
6
+
7
+ const updateCartItemOperation = 'updateLineItem patch /checkout/cart/line-item' satisfies OperationKey
8
+
9
+ type LineItem = OperationBody<typeof updateCartItemOperation>['items'][number]
10
+
11
+ type LineItemPayload =
12
+ Partial<Omit<LineItem, 'id' | 'quantity' | 'type'>> &
13
+ Required<Pick<LineItem, 'id' | 'quantity' | 'type'>>
14
+
15
+ type Body = Omit<
16
+ OperationBody<typeof updateCartItemOperation>,
17
+ 'items'
18
+ > & {
19
+ items: LineItemPayload[]
20
+ }
21
+
22
+ export function useUpdateLineItemMutation(
23
+ mutationOptions?: UseMutationOptions<
24
+ OperationResponse<typeof updateCartItemOperation>,
25
+ unknown,
26
+ Body
27
+ >,
28
+ ) {
29
+ const client = useShopwareQueryClient()
30
+ const queryClient = useQueryClient()
31
+
32
+ return useMutation({
33
+ ...mutationOptions,
34
+ mutationFn: async (body: Body) => {
35
+ return client.query(updateCartItemOperation, {
36
+ body: body as OperationBody<typeof updateCartItemOperation>,
37
+ })
38
+ },
39
+ onSuccess: (newCart, variables, context) => {
40
+ queryClient.setQueryData(cartKeys.get(), newCart)
41
+ // queryClient.invalidateQueries({ queryKey: cartKeys.get() })
42
+ unref(unref(mutationOptions)?.onSuccess)?.(newCart, variables, context)
43
+ },
44
+ })
45
+ }
@@ -0,0 +1,2 @@
1
+ export * from './useCheckout'
2
+ export * from './useCreateOrderMutation'
@@ -0,0 +1,2 @@
1
+ export const useCheckout = () => {
2
+ }
@@ -0,0 +1,35 @@
1
+ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
2
+ import { unref } from 'vue'
3
+ import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
4
+ import { useShopwareQueryClient } from '../../inject'
5
+ import { cartKeys, orderKeys } from '../../keys'
6
+ import { unrefOptions } from '../../util/unrefOptions'
7
+
8
+ const createOrderOperation = 'createOrder post /checkout/order' satisfies OperationKey
9
+
10
+ export function useCreateOrderMutation(
11
+ mutationOptions?: UseMutationOptions<
12
+ OperationResponse<typeof createOrderOperation>,
13
+ unknown,
14
+ OperationOptions<typeof createOrderOperation>
15
+ >,
16
+ ) {
17
+ const client = useShopwareQueryClient()
18
+ const queryClient = useQueryClient()
19
+
20
+ return useMutation({
21
+ ...mutationOptions,
22
+ mutationFn: async (options?: OperationOptions<typeof createOrderOperation>) => {
23
+ return client.query(createOrderOperation, unrefOptions(options))
24
+ },
25
+ onSuccess: (data, variables, context) => {
26
+ // Clear cart after successful order creation
27
+ queryClient.invalidateQueries({ queryKey: cartKeys.get() })
28
+
29
+ // Invalidate order list to refetch data
30
+ queryClient.invalidateQueries({ queryKey: orderKeys.lists() })
31
+
32
+ unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
33
+ },
34
+ })
35
+ }
@@ -0,0 +1,2 @@
1
+ export * from './useReadContextQuery'
2
+ export * from './useUpdateContextMutation'
@@ -0,0 +1,19 @@
1
+ import { queryOptions, useQuery } from '@tanstack/vue-query'
2
+ import { useShopwareQueryClient } from '../../inject'
3
+ import { contextKeys } from '../../keys'
4
+ import type { OperationKey } from '../types/query'
5
+
6
+ const readContextOperation = 'readContext get /context' satisfies OperationKey
7
+
8
+ export function useReadContext() {
9
+ const client = useShopwareQueryClient()
10
+
11
+ return queryOptions({
12
+ queryKey: contextKeys.all(),
13
+ queryFn: ({ signal }) => client.query(readContextOperation, { signal }),
14
+ })
15
+ }
16
+
17
+ export function useReadContextQuery() {
18
+ return useQuery(useReadContext())
19
+ }