@teamnovu/kit-shopware-composables 0.0.7 → 0.0.8

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 (51) hide show
  1. package/dist/helpers/checkout/useCheckoutAddresses.d.ts +6 -16
  2. package/dist/helpers/checkout/useOrderDetails.d.ts +7 -163
  3. package/dist/helpers/checkout/useOrderPayment.d.ts +4 -37
  4. package/dist/helpers/checkout/usePaymentMethods.d.ts +7 -19
  5. package/dist/helpers/checkout/useShippingMethods.d.ts +7 -19
  6. package/dist/helpers/types/schema.d.ts +5 -0
  7. package/dist/index.mjs +684 -575
  8. package/dist/query/address/useCreateCustomerAddressMutation.d.ts +1 -162
  9. package/dist/query/address/useUpdateCustomerAddressMutation.d.ts +1 -162
  10. package/dist/query/cart/useAddLineItemMutation.d.ts +1 -122
  11. package/dist/query/cart/useRemoveLineItemMutation.d.ts +5 -126
  12. package/dist/query/cart/useUpdateLineItemMutation.d.ts +1 -122
  13. package/dist/query/checkout/useCreateOrderMutation.d.ts +2 -278
  14. package/dist/query/context/useUpdateContextMutation.d.ts +5 -15
  15. package/dist/query/customer/index.d.ts +7 -0
  16. package/dist/query/customer/useChangeEmailMutation.d.ts +1 -11
  17. package/dist/query/customer/useChangePasswordMutation.d.ts +6 -0
  18. package/dist/query/customer/useChangeProfileMutation.d.ts +1 -11
  19. package/dist/query/customer/useDefaultBillingAddressMutation.d.ts +6 -0
  20. package/dist/query/customer/useDefaultShippingAddressMutation.d.ts +6 -0
  21. package/dist/query/customer/useDeleteCustomerMutation.d.ts +6 -0
  22. package/dist/query/customer/useLoginCustomerMutation.d.ts +5 -15
  23. package/dist/query/customer/useLogoutCustomerMutation.d.ts +1 -11
  24. package/dist/query/customer/useRecoveryPasswordMutation.d.ts +6 -0
  25. package/dist/query/customer/useRegisterConfirmMutation.d.ts +21 -0
  26. package/dist/query/customer/useRegisterCustomerMutation.d.ts +1 -262
  27. package/dist/query/customer/useSendRecoveryMailMutation.d.ts +6 -0
  28. package/dist/query/payment/useHandlePaymentMutation.d.ts +1 -11
  29. package/dist/query/payment/useOrderSetPaymentMutation.d.ts +1 -11
  30. package/dist/query/types/query.d.ts +2 -2
  31. package/dist/util/index.d.ts +1 -0
  32. package/dist/util/isAsynchronous.d.ts +3 -0
  33. package/package.json +2 -2
  34. package/src/helpers/checkout/useOrderDetails.ts +8 -8
  35. package/src/helpers/checkout/useOrderPayment.ts +6 -10
  36. package/src/helpers/types/schema.ts +11 -0
  37. package/src/query/checkout/useCreateOrderMutation.ts +2 -2
  38. package/src/query/customer/index.ts +7 -0
  39. package/src/query/customer/useChangeEmailMutation.ts +2 -1
  40. package/src/query/customer/useChangePasswordMutation.ts +28 -0
  41. package/src/query/customer/useChangeProfileMutation.ts +5 -2
  42. package/src/query/customer/useDefaultBillingAddressMutation.ts +35 -0
  43. package/src/query/customer/useDefaultShippingAddressMutation.ts +35 -0
  44. package/src/query/customer/useDeleteCustomerMutation.ts +36 -0
  45. package/src/query/customer/useRecoveryPasswordMutation.ts +28 -0
  46. package/src/query/customer/useRegisterConfirmMutation.ts +37 -0
  47. package/src/query/customer/useSendRecoveryMailMutation.ts +28 -0
  48. package/src/query/types/operations.ts +0 -1
  49. package/src/query/types/query.ts +2 -2
  50. package/src/util/index.ts +1 -0
  51. package/src/util/isAsynchronous.ts +8 -0
@@ -0,0 +1,35 @@
1
+ import { useMutation, type UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
2
+ import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
3
+ import { unref } from 'vue'
4
+ import { useShopwareQueryClient } from '../../inject'
5
+ import { contextKeys, customerKeys } from '../../keys'
6
+ import { unrefOptions } from '../../util/unrefOptions'
7
+ import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
8
+
9
+ const defaultShippingAddressOperation = 'defaultShippingAddress patch /account/address/default-shipping/{addressId}' satisfies OperationKey
10
+
11
+ export function useDefaultShippingAddressMutation(
12
+ mutationOptions?: UseMutationOptions<
13
+ OperationResponse<typeof defaultShippingAddressOperation>,
14
+ ShopwareApiError | Error,
15
+ OperationOptions<typeof defaultShippingAddressOperation>
16
+ >,
17
+ ) {
18
+ const client = useShopwareQueryClient()
19
+ const queryClient = useQueryClient()
20
+
21
+ return useMutation({
22
+ ...mutationOptions,
23
+ mutationFn: async (options: OperationOptions<typeof defaultShippingAddressOperation>) => {
24
+ return client.query(defaultShippingAddressOperation, unrefOptions(options))
25
+ },
26
+ onSuccess: async (data, variables, context) => {
27
+ await Promise.all([
28
+ queryClient.invalidateQueries({ queryKey: customerKeys.all() }),
29
+ queryClient.invalidateQueries({ queryKey: contextKeys.all() }),
30
+ ])
31
+
32
+ await unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
33
+ },
34
+ })
35
+ }
@@ -0,0 +1,36 @@
1
+ import { useMutation, type UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
2
+ import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
3
+ import { unref } from 'vue'
4
+ import { useShopwareQueryClient } from '../../inject'
5
+ import { cartKeys, contextKeys, customerKeys } from '../../keys'
6
+ import { unrefOptions } from '../../util/unrefOptions'
7
+ import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
8
+
9
+ const deleteCustomerOperation = 'deleteCustomer delete /account/customer' satisfies OperationKey
10
+
11
+ export function useDeleteCustomerMutation(
12
+ mutationOptions?: UseMutationOptions<
13
+ OperationResponse<typeof deleteCustomerOperation>,
14
+ ShopwareApiError | Error,
15
+ OperationOptions<typeof deleteCustomerOperation>
16
+ >,
17
+ ) {
18
+ const client = useShopwareQueryClient()
19
+ const queryClient = useQueryClient()
20
+
21
+ return useMutation({
22
+ ...mutationOptions,
23
+ mutationFn: async (options?: OperationOptions<typeof deleteCustomerOperation>) => {
24
+ return client.query(deleteCustomerOperation, unrefOptions(options))
25
+ },
26
+ onSuccess: async (data, variables, context) => {
27
+ await Promise.all([
28
+ queryClient.resetQueries({ queryKey: customerKeys.all() }),
29
+ queryClient.resetQueries({ queryKey: contextKeys.all() }),
30
+ queryClient.resetQueries({ queryKey: cartKeys.get() }),
31
+ ])
32
+
33
+ await unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
34
+ },
35
+ })
36
+ }
@@ -0,0 +1,28 @@
1
+ import { useMutation, type UseMutationOptions } from '@tanstack/vue-query'
2
+ import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
3
+ import { unref } from 'vue'
4
+ import { useShopwareQueryClient } from '../../inject'
5
+ import { unrefOptions } from '../../util/unrefOptions'
6
+ import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
7
+
8
+ const recoveryPasswordOperation = 'recoveryPassword post /account/recovery-password-confirm' satisfies OperationKey
9
+
10
+ export function useRecoveryPasswordMutation(
11
+ mutationOptions?: UseMutationOptions<
12
+ OperationResponse<typeof recoveryPasswordOperation>,
13
+ ShopwareApiError | Error,
14
+ OperationOptions<typeof recoveryPasswordOperation>
15
+ >,
16
+ ) {
17
+ const client = useShopwareQueryClient()
18
+
19
+ return useMutation({
20
+ ...mutationOptions,
21
+ mutationFn: async (options: OperationOptions<typeof recoveryPasswordOperation>) => {
22
+ return client.query(recoveryPasswordOperation, unrefOptions(options))
23
+ },
24
+ onSuccess: async (data, variables, context) => {
25
+ await unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
26
+ },
27
+ })
28
+ }
@@ -0,0 +1,37 @@
1
+ import { useMutation, type UseMutationOptions } from '@tanstack/vue-query'
2
+ import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
3
+ import { unref } from 'vue'
4
+ import { useShopwareQueryClient } from '../../inject'
5
+ import type { OperationBody, OperationKey, OperationResponse } from '../types/query'
6
+
7
+ const registerConfirmOperation = 'registerConfirm post /account/register-confirm' satisfies OperationKey
8
+
9
+ export function useRegisterConfirmMutation(
10
+ mutationOptions?: UseMutationOptions<
11
+ OperationResponse<typeof registerConfirmOperation>,
12
+ ShopwareApiError | Error,
13
+ OperationBody<typeof registerConfirmOperation>
14
+ >,
15
+ ) {
16
+ const client = useShopwareQueryClient()
17
+
18
+ return useMutation({
19
+ ...mutationOptions,
20
+ mutationFn: async (body: OperationBody<typeof registerConfirmOperation>) => {
21
+ const response = await client.queryRaw(registerConfirmOperation, {
22
+ body,
23
+ })
24
+
25
+ const contextToken = response.headers.get('sw-context-token')
26
+
27
+ if (contextToken) {
28
+ client.setContextToken(contextToken)
29
+ }
30
+
31
+ return response.json() as Promise<never>
32
+ },
33
+ onSuccess: async (newCustomer, variables, context) => {
34
+ await unref(unref(mutationOptions)?.onSuccess)?.(newCustomer, variables, context)
35
+ },
36
+ })
37
+ }
@@ -0,0 +1,28 @@
1
+ import { useMutation, type UseMutationOptions } from '@tanstack/vue-query'
2
+ import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
3
+ import { unref } from 'vue'
4
+ import { useShopwareQueryClient } from '../../inject'
5
+ import { unrefOptions } from '../../util/unrefOptions'
6
+ import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
7
+
8
+ const sendRecoveryMailOperation = 'sendRecoveryMail post /account/recovery-password' satisfies OperationKey
9
+
10
+ export function useSendRecoveryMailMutation(
11
+ mutationOptions?: UseMutationOptions<
12
+ OperationResponse<typeof sendRecoveryMailOperation>,
13
+ ShopwareApiError | Error,
14
+ OperationOptions<typeof sendRecoveryMailOperation>
15
+ >,
16
+ ) {
17
+ const client = useShopwareQueryClient()
18
+
19
+ return useMutation({
20
+ ...mutationOptions,
21
+ mutationFn: async (options: OperationOptions<typeof sendRecoveryMailOperation>) => {
22
+ return client.query(sendRecoveryMailOperation, unrefOptions(options))
23
+ },
24
+ onSuccess: async (data, variables, context) => {
25
+ await unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
26
+ },
27
+ })
28
+ }
@@ -3,4 +3,3 @@ import type { operations as OriginalOperations, Schemas as OriginalSchemas } fro
3
3
 
4
4
  export interface Operations extends ShopwareApi.Operations, OriginalOperations {}
5
5
  export interface Schemas extends ShopwareApi.Schemas, OriginalSchemas {}
6
-
@@ -1,5 +1,6 @@
1
1
  import type { QueryKey, UseQueryOptions } from '@tanstack/vue-query'
2
2
  import type {
3
+ BrandedResponse,
3
4
  OperationProp,
4
5
  OperationOptions as RawOperationOptions,
5
6
  } from '@teamnovu/kit-shopware-api-client'
@@ -18,8 +19,7 @@ export type ShallowUnwrapRefs<T> = {
18
19
  export type OperationKey = keyof Operations
19
20
  export type OperationBody<K extends OperationKey> =
20
21
  OperationProp<Operations, K, 'body'>
21
- export type OperationResponse<K extends OperationKey> =
22
- OperationProp<Operations, K, 'response'>
22
+ export type OperationResponse<K extends OperationKey> = BrandedResponse<Operations, K>
23
23
 
24
24
  export type OperationOptions<
25
25
  K extends OperationKey,
package/src/util/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './unrefOptions'
2
2
  export * from './url'
3
3
  export * from './useOptimistic'
4
+ export * from './isAsynchronous'
@@ -0,0 +1,8 @@
1
+ import { unref, type MaybeRef } from 'vue'
2
+ import type { Schemas } from '../query/types/operations'
3
+
4
+ export const isAsynchronousOrder = (order: MaybeRef<Schemas['Order'] | null | undefined>) => {
5
+ const activeTransaction = unref(order)?.transactions?.find(t => t.paymentMethod?.active)
6
+ // @ts-expect-error - This property does not seem to be declared in the typescript types
7
+ return activeTransaction?.paymentMethod?.asynchronous && activeTransaction?.paymentMethod?.afterOrderEnabled
8
+ }