@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.
- package/api-types/storeApiSchema.localhost.http +1 -1
- package/dist/helpers/checkout/index.d.ts +5 -0
- package/dist/helpers/checkout/useAddresses.d.ts +210 -0
- package/dist/helpers/checkout/useOrderDetails.d.ts +186 -0
- package/dist/helpers/checkout/useOrderPayment.d.ts +73 -0
- package/dist/helpers/checkout/usePaymentMethods.d.ts +155 -0
- package/dist/helpers/checkout/useShippingMethods.d.ts +173 -0
- package/dist/helpers/general/index.d.ts +2 -0
- package/dist/{usePagination.d.ts → helpers/general/usePagination.d.ts} +1 -1
- package/dist/{general → helpers/general}/useSeoUrl.d.ts +1 -1
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/product/index.d.ts +2 -0
- package/dist/helpers/product/useProductPrice.d.ts +61 -0
- package/dist/{products → helpers/product}/useProductVariantForOptions.d.ts +1 -1
- package/dist/helpers/user/index.d.ts +2 -0
- package/dist/helpers/user/useIsLoggedIn.d.ts +2 -0
- package/dist/helpers/user/useUser.d.ts +167 -0
- package/dist/index.d.ts +3 -188
- package/dist/index.mjs +871 -185
- package/dist/inject.d.ts +2 -2
- package/dist/keys.d.ts +35 -0
- package/dist/query/address/index.d.ts +3 -0
- package/dist/query/address/useCreateCustomerAddressMutation.d.ts +166 -0
- package/dist/query/address/useDeleteCustomerAddressMutation.d.ts +5 -0
- package/dist/query/address/useListAddressQuery.d.ts +48 -0
- package/dist/query/cart/index.d.ts +4 -0
- package/dist/query/cart/useAddLineItemMutation.d.ts +131 -0
- package/dist/query/cart/useReadCartQuery.d.ts +108 -0
- package/dist/query/cart/useRemoveLineItemMutation.d.ts +136 -0
- package/dist/query/cart/useUpdateLineItemMutation.d.ts +131 -0
- package/dist/query/checkout/index.d.ts +2 -0
- package/dist/query/checkout/useCheckout.d.ts +1 -0
- package/dist/query/checkout/useCreateOrderMutation.d.ts +281 -0
- package/dist/query/context/index.d.ts +2 -0
- package/dist/query/context/useReadContextQuery.d.ts +153 -0
- package/dist/query/context/useUpdateContextMutation.d.ts +60 -0
- package/dist/query/customer/index.d.ts +6 -0
- package/dist/query/customer/useChangeEmailMutation.d.ts +15 -0
- package/dist/query/customer/useChangeProfileMutation.d.ts +15 -0
- package/dist/query/customer/useLoginCustomerMutation.d.ts +30 -0
- package/dist/query/customer/useLogoutCustomerMutation.d.ts +15 -0
- package/dist/query/customer/useReadCustomerQuery.d.ts +220 -0
- package/dist/query/customer/useRegisterCustomerMutation.d.ts +266 -0
- package/dist/query/index.d.ts +10 -0
- package/dist/query/order/index.d.ts +1 -0
- package/dist/query/order/useReadOrderQuery.d.ts +44 -0
- package/dist/query/payment/index.d.ts +3 -0
- package/dist/query/payment/useHandlePaymentMutation.d.ts +15 -0
- package/dist/query/payment/useOrderSetPaymentMutation.d.ts +15 -0
- package/dist/query/payment/useReadPaymentMethodQuery.d.ts +31 -0
- package/dist/query/products/index.d.ts +3 -0
- package/dist/query/products/useReadCategoryListQuery.d.ts +48 -0
- package/dist/query/products/useReadCompactProductListingQuery.d.ts +35 -0
- package/dist/query/products/useReadCustomProductDetailQuery.d.ts +67 -0
- package/dist/query/shipping/index.d.ts +1 -0
- package/dist/query/shipping/useReadShippingMethodQuery.d.ts +55 -0
- package/dist/query/types/index.d.ts +2 -0
- package/dist/query/types/operations.d.ts +5 -0
- package/dist/query/types/query.d.ts +17 -0
- package/dist/util/index.d.ts +3 -0
- package/dist/util/unrefOptions.d.ts +4 -0
- package/dist/util/useOptimistic.d.ts +12 -0
- package/docs/index.md +457 -0
- package/docs/info.json +3 -0
- package/package.json +6 -2
- package/src/helpers/checkout/index.ts +5 -0
- package/src/helpers/checkout/useAddresses.ts +57 -0
- package/src/helpers/checkout/useOrderDetails.ts +94 -0
- package/src/helpers/checkout/useOrderPayment.ts +28 -0
- package/src/helpers/checkout/usePaymentMethods.ts +35 -0
- package/src/helpers/checkout/useShippingMethods.ts +35 -0
- package/src/helpers/general/index.ts +2 -0
- package/src/helpers/index.ts +4 -0
- package/src/helpers/product/index.ts +2 -0
- package/src/{products → helpers/product}/useProductPrice.ts +4 -45
- package/src/{products → helpers/product}/useProductVariantForOptions.ts +8 -2
- package/src/helpers/user/index.ts +2 -0
- package/src/helpers/user/useIsLoggedIn.ts +10 -0
- package/src/helpers/user/useUser.ts +53 -0
- package/src/index.ts +4 -21
- package/src/inject.ts +3 -3
- package/src/keys.ts +61 -0
- package/src/query/address/index.ts +3 -0
- package/src/query/address/useCreateCustomerAddressMutation.ts +32 -0
- package/src/query/address/useDeleteCustomerAddressMutation.ts +32 -0
- package/src/query/address/useListAddressQuery.ts +29 -0
- package/src/query/cart/index.ts +4 -0
- package/src/query/cart/useAddLineItemMutation.ts +45 -0
- package/src/query/cart/useReadCartQuery.ts +28 -0
- package/src/query/cart/useRemoveLineItemMutation.ts +32 -0
- package/src/query/cart/useUpdateLineItemMutation.ts +45 -0
- package/src/query/checkout/index.ts +2 -0
- package/src/query/checkout/useCheckout.ts +2 -0
- package/src/query/checkout/useCreateOrderMutation.ts +35 -0
- package/src/query/context/index.ts +2 -0
- package/src/query/context/useReadContextQuery.ts +19 -0
- package/src/query/context/useUpdateContextMutation.ts +36 -0
- package/src/query/customer/index.ts +6 -0
- package/src/query/customer/useChangeEmailMutation.ts +32 -0
- package/src/query/customer/useChangeProfileMutation.ts +32 -0
- package/src/query/customer/useLoginCustomerMutation.ts +42 -0
- package/src/query/customer/useLogoutCustomerMutation.ts +32 -0
- package/src/query/customer/useReadCustomerQuery.ts +27 -0
- package/src/query/customer/useRegisterCustomerMutation.ts +32 -0
- package/src/query/index.ts +10 -0
- package/src/query/order/index.ts +1 -0
- package/src/query/order/useReadOrderQuery.ts +33 -0
- package/src/query/payment/index.ts +3 -0
- package/src/query/payment/useHandlePaymentMutation.ts +27 -0
- package/src/query/payment/useOrderSetPaymentMutation.ts +32 -0
- package/src/query/payment/useReadPaymentMethodQuery.ts +30 -0
- package/src/query/products/index.ts +3 -0
- package/src/query/products/useReadCategoryListQuery.ts +28 -0
- package/src/query/products/useReadCompactProductListingQuery.ts +41 -0
- package/src/query/products/useReadCustomProductDetailQuery.ts +41 -0
- package/src/query/shipping/index.ts +1 -0
- package/src/query/shipping/useReadShippingMethodQuery.ts +29 -0
- package/src/query/types/index.ts +2 -0
- package/src/query/types/operations.ts +6 -0
- package/src/query/types/query.ts +39 -0
- package/src/util/index.ts +3 -0
- package/src/util/unrefOptions.ts +19 -0
- package/src/util/useOptimistic.ts +49 -0
- package/tsconfig.json +5 -2
- package/dist/context/useContextOptions.d.ts +0 -9
- package/dist/context/useContextUpdate.d.ts +0 -4
- package/dist/products/useCategoryQueryOptions.d.ts +0 -17
- package/dist/products/useProductListingQueryOptions.d.ts +0 -19
- package/dist/products/useProductListingQueryOptions.test.d.ts +0 -1
- package/dist/products/useProductPrice.d.ts +0 -48
- package/dist/products/useProductQueryOptions.d.ts +0 -19
- package/dist/types/query.d.ts +0 -7
- package/eslint.config.mjs +0 -84
- package/src/context/useContextOptions.ts +0 -16
- package/src/context/useContextUpdate.ts +0 -16
- package/src/products/useCategoryQueryOptions.ts +0 -25
- package/src/products/useProductListingQueryOptions.test.ts +0 -24
- package/src/products/useProductListingQueryOptions.ts +0 -28
- package/src/products/useProductQueryOptions.ts +0 -28
- package/src/types/query.ts +0 -18
- /package/src/{usePagination.ts → helpers/general/usePagination.ts} +0 -0
- /package/src/{general → helpers/general}/useSeoUrl.ts +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import { unref } from 'vue'
|
|
3
|
+
import { useShopwareQueryClient } from '../../inject'
|
|
4
|
+
import { contextKeys } from '../../keys'
|
|
5
|
+
import type { OperationBody, OperationKey, OperationResponse } from '../types/query'
|
|
6
|
+
|
|
7
|
+
const updateContextOperation = 'updateContext patch /context' satisfies OperationKey
|
|
8
|
+
|
|
9
|
+
export function useUpdateContextMutation(
|
|
10
|
+
mutationOptions?: UseMutationOptions<
|
|
11
|
+
OperationResponse<typeof updateContextOperation>,
|
|
12
|
+
unknown,
|
|
13
|
+
OperationBody<typeof updateContextOperation>
|
|
14
|
+
>,
|
|
15
|
+
) {
|
|
16
|
+
const client = useShopwareQueryClient()
|
|
17
|
+
const queryClient = useQueryClient()
|
|
18
|
+
|
|
19
|
+
return useMutation({
|
|
20
|
+
...mutationOptions,
|
|
21
|
+
mutationFn: async (body: OperationBody<typeof updateContextOperation>) => {
|
|
22
|
+
// Prevent race condition by cancelling the query before the mutation is executed
|
|
23
|
+
queryClient.cancelQueries({ queryKey: contextKeys.all() })
|
|
24
|
+
|
|
25
|
+
return client.query(updateContextOperation, {
|
|
26
|
+
body,
|
|
27
|
+
})
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
onSuccess: (newContext, variables, context) => {
|
|
31
|
+
queryClient.invalidateQueries({ queryKey: contextKeys.all() })
|
|
32
|
+
|
|
33
|
+
unref(unref(mutationOptions)?.onSuccess)?.(newContext, variables, context)
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
}
|
|
@@ -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 { customerKeys } from '../../keys'
|
|
6
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
7
|
+
|
|
8
|
+
const changeEmailOperation = 'changeEmail post /account/change-email' satisfies OperationKey
|
|
9
|
+
|
|
10
|
+
export function useChangeEmailMutation(
|
|
11
|
+
mutationOptions?: UseMutationOptions<
|
|
12
|
+
OperationResponse<typeof changeEmailOperation>,
|
|
13
|
+
unknown,
|
|
14
|
+
OperationOptions<typeof changeEmailOperation>
|
|
15
|
+
>,
|
|
16
|
+
) {
|
|
17
|
+
const client = useShopwareQueryClient()
|
|
18
|
+
const queryClient = useQueryClient()
|
|
19
|
+
|
|
20
|
+
return useMutation({
|
|
21
|
+
...mutationOptions,
|
|
22
|
+
mutationFn: async (options: OperationOptions<typeof changeEmailOperation>) => {
|
|
23
|
+
return client.query(changeEmailOperation, unrefOptions(options))
|
|
24
|
+
},
|
|
25
|
+
onSuccess: (data, variables, context) => {
|
|
26
|
+
queryClient.invalidateQueries({ queryKey: customerKeys.get() })
|
|
27
|
+
|
|
28
|
+
unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
29
|
+
},
|
|
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 { customerKeys } from '../../keys'
|
|
6
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
7
|
+
|
|
8
|
+
const changeProfileOperation = 'changeProfile post /account/change-profile' satisfies OperationKey
|
|
9
|
+
|
|
10
|
+
export function useChangeProfileMutation(
|
|
11
|
+
mutationOptions?: UseMutationOptions<
|
|
12
|
+
OperationResponse<typeof changeProfileOperation>,
|
|
13
|
+
unknown,
|
|
14
|
+
OperationOptions<typeof changeProfileOperation>
|
|
15
|
+
>,
|
|
16
|
+
) {
|
|
17
|
+
const client = useShopwareQueryClient()
|
|
18
|
+
const queryClient = useQueryClient()
|
|
19
|
+
|
|
20
|
+
return useMutation({
|
|
21
|
+
...mutationOptions,
|
|
22
|
+
mutationFn: async (options: OperationOptions<typeof changeProfileOperation>) => {
|
|
23
|
+
return client.query(changeProfileOperation, unrefOptions(options))
|
|
24
|
+
},
|
|
25
|
+
onSuccess: (data, variables, context) => {
|
|
26
|
+
queryClient.invalidateQueries({ queryKey: customerKeys.get() })
|
|
27
|
+
|
|
28
|
+
unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
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 { contextKeys, cartKeys, customerKeys } from '../../keys'
|
|
6
|
+
|
|
7
|
+
const loginCustomerOperation = 'loginCustomer post /account/login' satisfies OperationKey
|
|
8
|
+
|
|
9
|
+
export function useLoginCustomerMutation(
|
|
10
|
+
mutationOptions?: UseMutationOptions<
|
|
11
|
+
OperationResponse<typeof loginCustomerOperation>,
|
|
12
|
+
unknown,
|
|
13
|
+
OperationBody<typeof loginCustomerOperation>
|
|
14
|
+
>,
|
|
15
|
+
) {
|
|
16
|
+
const client = useShopwareQueryClient()
|
|
17
|
+
const queryClient = useQueryClient()
|
|
18
|
+
|
|
19
|
+
return useMutation({
|
|
20
|
+
...mutationOptions,
|
|
21
|
+
mutationFn: async (body: OperationBody<typeof loginCustomerOperation>) => {
|
|
22
|
+
const response = await client.queryRaw(loginCustomerOperation, {
|
|
23
|
+
body,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const contextToken = response.headers.get('sw-context-token')
|
|
27
|
+
|
|
28
|
+
if (contextToken) {
|
|
29
|
+
client.setContextToken(contextToken)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return response.json()
|
|
33
|
+
},
|
|
34
|
+
onSuccess: (newCustomer, variables, context) => {
|
|
35
|
+
queryClient.invalidateQueries({ queryKey: contextKeys.all() })
|
|
36
|
+
queryClient.invalidateQueries({ queryKey: cartKeys.get() })
|
|
37
|
+
queryClient.invalidateQueries({ queryKey: customerKeys.get() })
|
|
38
|
+
|
|
39
|
+
unref(unref(mutationOptions)?.onSuccess)?.(newCustomer, variables, context)
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
}
|
|
@@ -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 { customerKeys } from '../../keys'
|
|
6
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
7
|
+
|
|
8
|
+
const logoutOperation = 'logoutCustomer post /account/logout' satisfies OperationKey
|
|
9
|
+
|
|
10
|
+
export function useLogoutCustomerMutation(
|
|
11
|
+
mutationOptions?: UseMutationOptions<
|
|
12
|
+
OperationResponse<typeof logoutOperation>,
|
|
13
|
+
unknown,
|
|
14
|
+
OperationOptions<typeof logoutOperation>
|
|
15
|
+
>,
|
|
16
|
+
) {
|
|
17
|
+
const client = useShopwareQueryClient()
|
|
18
|
+
const queryClient = useQueryClient()
|
|
19
|
+
|
|
20
|
+
return useMutation({
|
|
21
|
+
...mutationOptions,
|
|
22
|
+
mutationFn: async (options?: OperationOptions<typeof logoutOperation>) => {
|
|
23
|
+
return client.query(logoutOperation, unrefOptions(options))
|
|
24
|
+
},
|
|
25
|
+
onSuccess: (data, variables, context) => {
|
|
26
|
+
queryClient.removeQueries({ queryKey: customerKeys.get() })
|
|
27
|
+
|
|
28
|
+
unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/vue-query'
|
|
2
|
+
import { useShopwareQueryClient } from '../../inject'
|
|
3
|
+
import { customerKeys } from '../../keys'
|
|
4
|
+
import { unrefOptions } from '../../util'
|
|
5
|
+
import type { OperationKey, OperationOptions } from '../types/query'
|
|
6
|
+
|
|
7
|
+
const readCustomer = 'readCustomer post /account/customer' satisfies OperationKey
|
|
8
|
+
|
|
9
|
+
export function useReadCustomerQueryOptions(
|
|
10
|
+
options?: OperationOptions<typeof readCustomer>,
|
|
11
|
+
) {
|
|
12
|
+
const client = useShopwareQueryClient()
|
|
13
|
+
const queryKey = customerKeys.get()
|
|
14
|
+
|
|
15
|
+
return queryOptions({
|
|
16
|
+
queryKey,
|
|
17
|
+
queryFn: async () => {
|
|
18
|
+
return client.query(readCustomer, unrefOptions(options))
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function useReadCustomerQuery(
|
|
24
|
+
options?: OperationOptions<typeof readCustomer>,
|
|
25
|
+
) {
|
|
26
|
+
return useQuery(useReadCustomerQueryOptions(options))
|
|
27
|
+
}
|
|
@@ -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 { customerKeys } from '../../keys'
|
|
6
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
7
|
+
|
|
8
|
+
const registerOperation = 'register post /account/register' satisfies OperationKey
|
|
9
|
+
|
|
10
|
+
export function useRegisterCustomerMutation(
|
|
11
|
+
mutationOptions?: UseMutationOptions<
|
|
12
|
+
OperationResponse<typeof registerOperation>,
|
|
13
|
+
unknown,
|
|
14
|
+
OperationOptions<typeof registerOperation>
|
|
15
|
+
>,
|
|
16
|
+
) {
|
|
17
|
+
const client = useShopwareQueryClient()
|
|
18
|
+
const queryClient = useQueryClient()
|
|
19
|
+
|
|
20
|
+
return useMutation({
|
|
21
|
+
...mutationOptions,
|
|
22
|
+
mutationFn: async (options: OperationOptions<typeof registerOperation>) => {
|
|
23
|
+
return client.query(registerOperation, unrefOptions(options))
|
|
24
|
+
},
|
|
25
|
+
onSuccess: (data, variables, context) => {
|
|
26
|
+
queryClient.invalidateQueries({ queryKey: customerKeys.get() })
|
|
27
|
+
|
|
28
|
+
unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './address'
|
|
2
|
+
export * from './cart'
|
|
3
|
+
export * from './checkout'
|
|
4
|
+
export * from './context'
|
|
5
|
+
export * from './customer'
|
|
6
|
+
export * from './order'
|
|
7
|
+
export * from './payment'
|
|
8
|
+
export * from './products'
|
|
9
|
+
export * from './shipping'
|
|
10
|
+
export * from './types'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useReadOrderQuery'
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/vue-query'
|
|
2
|
+
import { useShopwareQueryClient } from '../../inject'
|
|
3
|
+
import { orderKeys } from '../../keys'
|
|
4
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
5
|
+
import type { OperationKey, OperationOptions } from '../types/query'
|
|
6
|
+
|
|
7
|
+
const readOrderOperation = 'readOrder post /order' satisfies OperationKey
|
|
8
|
+
|
|
9
|
+
export function useReadOrderQueryOptions(
|
|
10
|
+
options?: OperationOptions<typeof readOrderOperation>,
|
|
11
|
+
) {
|
|
12
|
+
const client = useShopwareQueryClient()
|
|
13
|
+
const queryKey = orderKeys.detail(options)
|
|
14
|
+
|
|
15
|
+
return queryOptions({
|
|
16
|
+
queryKey,
|
|
17
|
+
queryFn: async ({ signal }) => {
|
|
18
|
+
const opts = unrefOptions(options)
|
|
19
|
+
return client.query(readOrderOperation, {
|
|
20
|
+
...opts,
|
|
21
|
+
signal,
|
|
22
|
+
})
|
|
23
|
+
},
|
|
24
|
+
enabled: !!options,
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useReadOrderQuery(
|
|
29
|
+
options?: OperationOptions<typeof readOrderOperation>,
|
|
30
|
+
) {
|
|
31
|
+
return useQuery(useReadOrderQueryOptions(options))
|
|
32
|
+
}
|
|
33
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useMutation, UseMutationOptions } 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 { unrefOptions } from '../../util/unrefOptions'
|
|
6
|
+
|
|
7
|
+
const handlePaymentOperation = 'handlePaymentMethod post /handle-payment' satisfies OperationKey
|
|
8
|
+
|
|
9
|
+
export function useHandlePaymentMutation(
|
|
10
|
+
mutationOptions?: UseMutationOptions<
|
|
11
|
+
OperationResponse<typeof handlePaymentOperation>,
|
|
12
|
+
unknown,
|
|
13
|
+
OperationOptions<typeof handlePaymentOperation>
|
|
14
|
+
>,
|
|
15
|
+
) {
|
|
16
|
+
const client = useShopwareQueryClient()
|
|
17
|
+
|
|
18
|
+
return useMutation({
|
|
19
|
+
...mutationOptions,
|
|
20
|
+
mutationFn: async (options: OperationOptions<typeof handlePaymentOperation>) => {
|
|
21
|
+
return client.query(handlePaymentOperation, unrefOptions(options))
|
|
22
|
+
},
|
|
23
|
+
onSuccess: (data, variables, context) => {
|
|
24
|
+
unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
}
|
|
@@ -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 { orderKeys } from '../../keys'
|
|
6
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
7
|
+
|
|
8
|
+
const orderSetPaymentOperation = 'orderSetPayment post /order/payment' satisfies OperationKey
|
|
9
|
+
|
|
10
|
+
export function useOrderSetPaymentMutation(
|
|
11
|
+
mutationOptions?: UseMutationOptions<
|
|
12
|
+
OperationResponse<typeof orderSetPaymentOperation>,
|
|
13
|
+
unknown,
|
|
14
|
+
OperationOptions<typeof orderSetPaymentOperation>
|
|
15
|
+
>,
|
|
16
|
+
) {
|
|
17
|
+
const client = useShopwareQueryClient()
|
|
18
|
+
const queryClient = useQueryClient()
|
|
19
|
+
|
|
20
|
+
return useMutation({
|
|
21
|
+
...mutationOptions,
|
|
22
|
+
mutationFn: async (options: OperationOptions<typeof orderSetPaymentOperation>) => {
|
|
23
|
+
return client.query(orderSetPaymentOperation, unrefOptions(options))
|
|
24
|
+
},
|
|
25
|
+
onSuccess: (data, variables, context) => {
|
|
26
|
+
// Invalidate order queries to refetch updated payment information
|
|
27
|
+
queryClient.invalidateQueries({ queryKey: orderKeys.all() })
|
|
28
|
+
|
|
29
|
+
unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/vue-query'
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import { useShopwareQueryClient } from '../../inject'
|
|
4
|
+
import { paymentKeys } from '../../keys'
|
|
5
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
6
|
+
import type { OperationKey, OperationOptions } from '../types/query'
|
|
7
|
+
|
|
8
|
+
export const readPaymentMethodOperation = 'readPaymentMethod post /payment-method' satisfies OperationKey
|
|
9
|
+
|
|
10
|
+
export function useReadPaymentMethodQueryOptions(
|
|
11
|
+
options?: OperationOptions<typeof readPaymentMethodOperation>,
|
|
12
|
+
) {
|
|
13
|
+
const client = useShopwareQueryClient()
|
|
14
|
+
const queryKey = paymentKeys.list(computed(() => unrefOptions(options)?.body))
|
|
15
|
+
|
|
16
|
+
return queryOptions({
|
|
17
|
+
queryKey,
|
|
18
|
+
queryFn: ({ signal }) =>
|
|
19
|
+
client.query(readPaymentMethodOperation, {
|
|
20
|
+
...unrefOptions(options),
|
|
21
|
+
signal,
|
|
22
|
+
}),
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function useReadPaymentMethodQuery(
|
|
27
|
+
options?: OperationOptions<typeof readPaymentMethodOperation>,
|
|
28
|
+
) {
|
|
29
|
+
return useQuery(useReadPaymentMethodQueryOptions(options))
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/vue-query'
|
|
2
|
+
import { useShopwareQueryClient } from '../../inject'
|
|
3
|
+
import { categoryKeys } from '../../keys'
|
|
4
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
5
|
+
import type { OperationKey, OperationOptions } from '../types/query'
|
|
6
|
+
|
|
7
|
+
const readCategoryListOperation = 'readCategoryList post /category' satisfies OperationKey
|
|
8
|
+
|
|
9
|
+
export const useReadCategoryListQueryOptions = function useReadCategoryListQueryOptions(
|
|
10
|
+
options?: OperationOptions<typeof readCategoryListOperation>,
|
|
11
|
+
) {
|
|
12
|
+
const client = useShopwareQueryClient()
|
|
13
|
+
const queryKey = categoryKeys.list(options)
|
|
14
|
+
|
|
15
|
+
return queryOptions({
|
|
16
|
+
queryKey,
|
|
17
|
+
queryFn: async ({ signal }) => {
|
|
18
|
+
return client.query(readCategoryListOperation, {
|
|
19
|
+
...unrefOptions(options),
|
|
20
|
+
signal,
|
|
21
|
+
})
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function useReadCategoryListQuery(options?: OperationOptions<typeof readCategoryListOperation>) {
|
|
27
|
+
return useQuery(useReadCategoryListQueryOptions(options))
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/vue-query'
|
|
2
|
+
import type { MaybeRef } from 'vue'
|
|
3
|
+
import { unref } from 'vue'
|
|
4
|
+
import { useShopwareQueryClient } from '../../inject'
|
|
5
|
+
import { productKeys } from '../../keys'
|
|
6
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
7
|
+
import { relativizeSeoUrl } from '../../util/url'
|
|
8
|
+
import type { OperationKey, OperationOptions } from '../types/query'
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @stylistic/max-len
|
|
11
|
+
const readListingOperation = 'readCompactProductListing post /novu/headless/product-listing/{seoUrl}' satisfies OperationKey
|
|
12
|
+
|
|
13
|
+
export function useReadCompactProductListingQueryOptions(
|
|
14
|
+
seoUrl: MaybeRef<string>,
|
|
15
|
+
options?: OperationOptions<typeof readListingOperation, 'params'>,
|
|
16
|
+
) {
|
|
17
|
+
const client = useShopwareQueryClient()
|
|
18
|
+
const queryKey = productKeys.list(seoUrl, options)
|
|
19
|
+
|
|
20
|
+
return queryOptions({
|
|
21
|
+
queryKey,
|
|
22
|
+
queryFn: async ({ signal }) => {
|
|
23
|
+
const opts = unrefOptions(options)
|
|
24
|
+
return client.query(readListingOperation, {
|
|
25
|
+
...opts,
|
|
26
|
+
params: {
|
|
27
|
+
...opts.params,
|
|
28
|
+
seoUrl: relativizeSeoUrl(unref(seoUrl)),
|
|
29
|
+
},
|
|
30
|
+
signal,
|
|
31
|
+
})
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function useReadCompactProductListingQuery(
|
|
37
|
+
seoUrl: MaybeRef<string>,
|
|
38
|
+
options?: OperationOptions<typeof readListingOperation, 'params'>,
|
|
39
|
+
) {
|
|
40
|
+
return useQuery(useReadCompactProductListingQueryOptions(seoUrl, options))
|
|
41
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/vue-query'
|
|
2
|
+
import type { MaybeRef } from 'vue'
|
|
3
|
+
import { unref } from 'vue'
|
|
4
|
+
import { useShopwareQueryClient } from '../../inject'
|
|
5
|
+
import { productKeys } from '../../keys'
|
|
6
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
7
|
+
import { relativizeSeoUrl } from '../../util/url'
|
|
8
|
+
import type { OperationKey, OperationOptions } from '../types/query'
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @stylistic/max-len
|
|
11
|
+
const readCustomProductDetailOperation = 'readCustomProductDetail post /novu/headless/product/{seoUrl}' satisfies OperationKey
|
|
12
|
+
|
|
13
|
+
export function useReadCustomProductDetailOptions(
|
|
14
|
+
seoUrl: MaybeRef<string>,
|
|
15
|
+
body?: OperationOptions<typeof readCustomProductDetailOperation, 'params'>,
|
|
16
|
+
) {
|
|
17
|
+
const client = useShopwareQueryClient()
|
|
18
|
+
const queryKey = productKeys.detail(seoUrl, body)
|
|
19
|
+
|
|
20
|
+
return queryOptions({
|
|
21
|
+
queryKey,
|
|
22
|
+
queryFn: async ({ signal }) => {
|
|
23
|
+
const opts = unrefOptions(body)
|
|
24
|
+
return client.query(readCustomProductDetailOperation, {
|
|
25
|
+
...opts,
|
|
26
|
+
params: {
|
|
27
|
+
...opts.params,
|
|
28
|
+
seoUrl: relativizeSeoUrl(unref(seoUrl)),
|
|
29
|
+
},
|
|
30
|
+
signal,
|
|
31
|
+
})
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function useReadCustomProductDetailQuery(
|
|
37
|
+
seoUrl: MaybeRef<string>,
|
|
38
|
+
body?: OperationOptions<typeof readCustomProductDetailOperation, 'params'>,
|
|
39
|
+
) {
|
|
40
|
+
return useQuery(useReadCustomProductDetailOptions(seoUrl, body))
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useReadShippingMethodQuery'
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/vue-query'
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import { useShopwareQueryClient } from '../../inject'
|
|
4
|
+
import { shippingKeys } from '../../keys'
|
|
5
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
6
|
+
import type { OperationKey, OperationOptions } from '../types/query'
|
|
7
|
+
|
|
8
|
+
export const readShippingMethodOperation = 'readShippingMethod post /shipping-method' satisfies OperationKey
|
|
9
|
+
|
|
10
|
+
export function useReadShippingMethodQueryOptions(
|
|
11
|
+
options?: OperationOptions<typeof readShippingMethodOperation>,
|
|
12
|
+
) {
|
|
13
|
+
const client = useShopwareQueryClient()
|
|
14
|
+
const queryKey = shippingKeys.list(computed(() => unrefOptions(options)?.body))
|
|
15
|
+
|
|
16
|
+
return queryOptions({
|
|
17
|
+
queryKey,
|
|
18
|
+
queryFn: ({ signal }) => client.query(readShippingMethodOperation, {
|
|
19
|
+
...unrefOptions(options),
|
|
20
|
+
signal,
|
|
21
|
+
}),
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function useReadShippingMethodQuery(
|
|
26
|
+
options?: OperationOptions<typeof readShippingMethodOperation>,
|
|
27
|
+
) {
|
|
28
|
+
return useQuery(useReadShippingMethodQueryOptions(options))
|
|
29
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { operations, Schemas as OriginalSchemas } from '#store-types'
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
4
|
+
export interface Operations extends operations {}
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
6
|
+
export interface Schemas extends OriginalSchemas {}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { operations } from '#store-types'
|
|
2
|
+
import type { QueryKey, UseQueryOptions } from '@tanstack/vue-query'
|
|
3
|
+
import type {
|
|
4
|
+
OperationProp,
|
|
5
|
+
OperationOptions as RawOperationOptions,
|
|
6
|
+
} from '@teamnovu/kit-shopware-api-client'
|
|
7
|
+
import { MaybeRef, UnwrapRef } from 'vue'
|
|
8
|
+
import { Operations } from './operations'
|
|
9
|
+
|
|
10
|
+
export type PartialProps<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
|
11
|
+
|
|
12
|
+
export type ShallowMaybeRefs<T> = {
|
|
13
|
+
[K in keyof T]: MaybeRef<T[K]>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type ShallowUnwrapRefs<T> = {
|
|
17
|
+
[K in keyof T]: UnwrapRef<T[K]>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type OperationKey = keyof operations
|
|
21
|
+
export type OperationBody<K extends OperationKey> =
|
|
22
|
+
OperationProp<Operations, K, 'body'>
|
|
23
|
+
export type OperationResponse<K extends OperationKey> =
|
|
24
|
+
OperationProp<Operations, K, 'response'>
|
|
25
|
+
|
|
26
|
+
export type OperationOptions<
|
|
27
|
+
K extends OperationKey,
|
|
28
|
+
OmitKeys extends keyof RawOperationOptions<Operations, K> = never,
|
|
29
|
+
> =
|
|
30
|
+
MaybeRef<ShallowMaybeRefs<PartialProps<RawOperationOptions<Operations, K>, OmitKeys>>>
|
|
31
|
+
|
|
32
|
+
export type Options<K extends OperationKey, QK extends QueryKey = QueryKey> =
|
|
33
|
+
UseQueryOptions<
|
|
34
|
+
OperationResponse<K>,
|
|
35
|
+
Error,
|
|
36
|
+
OperationResponse<K>,
|
|
37
|
+
OperationResponse<K>,
|
|
38
|
+
QK
|
|
39
|
+
>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { unref, UnwrapRef } from 'vue'
|
|
2
|
+
import { OperationOptions as RawOperationOptions } from '@teamnovu/kit-shopware-api-client'
|
|
3
|
+
import { OperationOptions, PartialProps } from '../query/types/query'
|
|
4
|
+
import { Operations } from '../query/types'
|
|
5
|
+
|
|
6
|
+
export function unrefOptions<
|
|
7
|
+
K extends keyof Operations,
|
|
8
|
+
OmitKeys extends keyof RawOperationOptions<Operations, K> = never,
|
|
9
|
+
>(
|
|
10
|
+
options: OperationOptions<K, OmitKeys> | undefined,
|
|
11
|
+
) {
|
|
12
|
+
const opts = unref(options)
|
|
13
|
+
|
|
14
|
+
return Object.fromEntries(
|
|
15
|
+
Object.entries(opts ?? {}).map(
|
|
16
|
+
([key, value]) => [key, unref(value) as UnwrapRef<typeof value>],
|
|
17
|
+
),
|
|
18
|
+
) as PartialProps<RawOperationOptions<Operations, K>, OmitKeys>
|
|
19
|
+
}
|