diff --git a/packages/admin-next/dashboard/src/hooks/api/auth.tsx b/packages/admin-next/dashboard/src/hooks/api/auth.tsx index 03d6f90b1e..b994c32f72 100644 --- a/packages/admin-next/dashboard/src/hooks/api/auth.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/auth.tsx @@ -1,10 +1,11 @@ import { UseMutationOptions, useMutation } from "@tanstack/react-query" +import { FetchError } from "@medusajs/js-sdk" import { sdk } from "../../lib/client" import { EmailPassReq } from "../../types/api-payloads" export const useSignInWithEmailPassword = ( - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (payload) => sdk.auth.login("user", "emailpass", payload), @@ -16,7 +17,7 @@ export const useSignInWithEmailPassword = ( } export const useSignUpWithEmailPass = ( - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (payload) => sdk.auth.register("user", "emailpass", payload), @@ -27,7 +28,7 @@ export const useSignUpWithEmailPass = ( }) } -export const useLogout = (options?: UseMutationOptions) => { +export const useLogout = (options?: UseMutationOptions) => { return useMutation({ mutationFn: () => sdk.auth.logout(), ...options, diff --git a/packages/admin-next/dashboard/src/hooks/api/claims.tsx b/packages/admin-next/dashboard/src/hooks/api/claims.tsx index cf39c8cd3f..d0b022525a 100644 --- a/packages/admin-next/dashboard/src/hooks/api/claims.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/claims.tsx @@ -1,4 +1,5 @@ import { HttpTypes } from "@medusajs/types" +import { FetchError } from "@medusajs/js-sdk" import { QueryKey, useMutation, @@ -22,7 +23,7 @@ export const useClaim = ( options?: Omit< UseQueryOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminClaimResponse, QueryKey >, @@ -43,7 +44,7 @@ export const useClaims = ( options?: Omit< UseQueryOptions< HttpTypes.AdminClaimListParams, - Error, + FetchError, HttpTypes.AdminClaimListResponse, QueryKey >, @@ -63,7 +64,7 @@ export const useCreateClaim = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminCreateClaim > ) => { @@ -92,7 +93,7 @@ export const useCreateClaim = ( export const useCancelClaim = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: () => sdk.admin.claim.cancel(id), @@ -121,7 +122,7 @@ export const useCancelClaim = ( export const useDeleteClaim = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: () => sdk.admin.claim.delete(id), @@ -151,7 +152,7 @@ export const useAddClaimItems = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminAddClaimItems > ) => { @@ -178,7 +179,7 @@ export const useUpdateClaimItems = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminUpdateClaimItem & { actionId: string } > ) => { @@ -207,7 +208,11 @@ export const useUpdateClaimItems = ( export const useRemoveClaimItem = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminReturnResponse, + FetchError, + string + > ) => { return useMutation({ mutationFn: (actionId: string) => @@ -232,7 +237,7 @@ export const useAddClaimInboundItems = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminAddClaimInboundItems > ) => { @@ -259,7 +264,7 @@ export const useUpdateClaimInboundItem = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminUpdateClaimInboundItem & { actionId: string } > ) => { @@ -288,7 +293,7 @@ export const useUpdateClaimInboundItem = ( export const useRemoveClaimInboundItem = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (actionId: string) => @@ -313,7 +318,7 @@ export const useAddClaimInboundShipping = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminClaimAddInboundShipping > ) => { @@ -340,7 +345,7 @@ export const useUpdateClaimInboundShipping = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminClaimUpdateInboundShipping > ) => { @@ -368,7 +373,7 @@ export const useUpdateClaimInboundShipping = ( export const useDeleteClaimInboundShipping = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (actionId: string) => @@ -393,7 +398,7 @@ export const useAddClaimOutboundItems = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminAddClaimOutboundItems > ) => { @@ -420,7 +425,7 @@ export const useUpdateClaimOutboundItems = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminUpdateClaimOutboundItem & { actionId: string } > ) => { @@ -449,7 +454,7 @@ export const useUpdateClaimOutboundItems = ( export const useRemoveClaimOutboundItem = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (actionId: string) => @@ -474,7 +479,7 @@ export const useAddClaimOutboundShipping = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminClaimAddOutboundShipping > ) => { @@ -501,7 +506,7 @@ export const useUpdateClaimOutboundShipping = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminClaimUpdateOutboundShipping > ) => { @@ -529,7 +534,7 @@ export const useUpdateClaimOutboundShipping = ( export const useDeleteClaimOutboundShipping = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (actionId: string) => @@ -554,7 +559,7 @@ export const useClaimConfirmRequest = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminClaimResponse, - Error, + FetchError, HttpTypes.AdminRequestClaim > ) => { @@ -587,7 +592,7 @@ export const useClaimConfirmRequest = ( export const useCancelClaimRequest = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: () => sdk.admin.claim.cancelRequest(id), diff --git a/packages/admin-next/dashboard/src/hooks/api/exchanges.tsx b/packages/admin-next/dashboard/src/hooks/api/exchanges.tsx index 7ad5c63bf1..7e759564eb 100644 --- a/packages/admin-next/dashboard/src/hooks/api/exchanges.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/exchanges.tsx @@ -6,7 +6,7 @@ import { useQuery, UseQueryOptions, } from "@tanstack/react-query" - +import { FetchError } from "@medusajs/js-sdk" import { sdk } from "../../lib/client" import { queryClient } from "../../lib/query-client" import { queryKeysFactory } from "../../lib/query-key-factory" @@ -22,7 +22,7 @@ export const useExchange = ( options?: Omit< UseQueryOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminExchangeResponse, QueryKey >, @@ -43,7 +43,7 @@ export const useExchanges = ( options?: Omit< UseQueryOptions< HttpTypes.AdminExchangeListParams, - Error, + FetchError, HttpTypes.AdminExchangeListResponse, QueryKey >, @@ -63,7 +63,7 @@ export const useCreateExchange = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminCreateExchange > ) => { @@ -92,7 +92,7 @@ export const useCreateExchange = ( export const useCancelExchange = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: () => sdk.admin.exchange.cancel(id), @@ -121,7 +121,10 @@ export const useCancelExchange = ( export const useDeleteExchange = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminExchangeDeleteResponse, + FetchError + > ) => { return useMutation({ mutationFn: () => sdk.admin.exchange.delete(id), @@ -151,7 +154,7 @@ export const useAddExchangeItems = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminAddExchangeItems > ) => { @@ -173,7 +176,7 @@ export const useUpdateExchangeItems = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminUpdateExchangeItem & { actionId: string } > ) => { @@ -197,7 +200,11 @@ export const useUpdateExchangeItems = ( export const useRemoveExchangeItem = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminReturnResponse, + FetchError, + string + > ) => { return useMutation({ mutationFn: (actionId: string) => @@ -217,7 +224,7 @@ export const useAddExchangeInboundItems = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminAddExchangeInboundItems > ) => { @@ -239,7 +246,7 @@ export const useUpdateExchangeInboundItem = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminUpdateExchangeInboundItem & { actionId: string } > ) => { @@ -263,7 +270,11 @@ export const useUpdateExchangeInboundItem = ( export const useRemoveExchangeInboundItem = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminExchangeResponse, + FetchError, + string + > ) => { return useMutation({ mutationFn: (actionId: string) => @@ -287,7 +298,7 @@ export const useAddExchangeInboundShipping = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminExchangeAddInboundShipping > ) => { @@ -309,7 +320,7 @@ export const useUpdateExchangeInboundShipping = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminExchangeUpdateInboundShipping > ) => { @@ -332,7 +343,11 @@ export const useUpdateExchangeInboundShipping = ( export const useDeleteExchangeInboundShipping = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminExchangeResponse, + FetchError, + string + > ) => { return useMutation({ mutationFn: (actionId: string) => @@ -352,7 +367,7 @@ export const useAddExchangeOutboundItems = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminAddExchangeOutboundItems > ) => { @@ -374,7 +389,7 @@ export const useUpdateExchangeOutboundItems = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminUpdateExchangeOutboundItem & { actionId: string } > ) => { @@ -398,7 +413,11 @@ export const useUpdateExchangeOutboundItems = ( export const useRemoveExchangeOutboundItem = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminExchangeResponse, + FetchError, + string + > ) => { return useMutation({ mutationFn: (actionId: string) => @@ -418,7 +437,7 @@ export const useAddExchangeOutboundShipping = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminExchangeAddOutboundShipping > ) => { @@ -440,7 +459,7 @@ export const useUpdateExchangeOutboundShipping = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminExchangeUpdateOutboundShipping > ) => { @@ -463,7 +482,11 @@ export const useUpdateExchangeOutboundShipping = ( export const useDeleteExchangeOutboundShipping = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminExchangeResponse, + FetchError, + string + > ) => { return useMutation({ mutationFn: (actionId: string) => @@ -483,7 +506,7 @@ export const useExchangeConfirmRequest = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminExchangeResponse, - Error, + FetchError, HttpTypes.AdminRequestExchange > ) => { @@ -516,7 +539,7 @@ export const useExchangeConfirmRequest = ( export const useCancelExchangeRequest = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: () => sdk.admin.exchange.cancelRequest(id), diff --git a/packages/admin-next/dashboard/src/hooks/api/fulfillment.tsx b/packages/admin-next/dashboard/src/hooks/api/fulfillment.tsx index eb393c8a9d..0ec6c8f480 100644 --- a/packages/admin-next/dashboard/src/hooks/api/fulfillment.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/fulfillment.tsx @@ -3,15 +3,16 @@ import { useMutation, UseMutationOptions } from "@tanstack/react-query" import { queryKeysFactory } from "../../lib/query-key-factory" import { HttpTypes } from "@medusajs/types" -import { client, sdk } from "../../lib/client" +import { sdk } from "../../lib/client" import { queryClient } from "../../lib/query-client" import { ordersQueryKeys } from "./orders" +import { FetchError } from "@medusajs/js-sdk" const FULFILLMENTS_QUERY_KEY = "fulfillments" as const export const fulfillmentsQueryKeys = queryKeysFactory(FULFILLMENTS_QUERY_KEY) export const useCreateFulfillment = ( - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (payload: any) => sdk.admin.fulfillment.create(payload), @@ -28,7 +29,7 @@ export const useCreateFulfillment = ( export const useCancelFulfillment = ( id: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: () => sdk.admin.fulfillment.cancel(id), @@ -47,7 +48,7 @@ export const useCreateFulfillmentShipment = ( fulfillmentId: string, options?: UseMutationOptions< { fulfillment: HttpTypes.AdminFulfillment }, - Error, + FetchError, HttpTypes.AdminCreateFulfillmentShipment > ) => { diff --git a/packages/admin-next/dashboard/src/hooks/api/invites.tsx b/packages/admin-next/dashboard/src/hooks/api/invites.tsx index d049716621..17a5f4e135 100644 --- a/packages/admin-next/dashboard/src/hooks/api/invites.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/invites.tsx @@ -13,6 +13,7 @@ import { import { sdk } from "../../lib/client" import { queryClient } from "../../lib/query-client" import { queryKeysFactory } from "../../lib/query-key-factory" +import { FetchError } from "@medusajs/js-sdk" const INVITES_QUERY_KEY = "invites" as const const invitesQueryKeys = queryKeysFactory(INVITES_QUERY_KEY) @@ -22,7 +23,7 @@ export const useInvite = ( options?: Omit< UseQueryOptions< { invite: HttpTypes.AdminInviteResponse }, - Error, + FetchError, { invite: HttpTypes.AdminInviteResponse }, QueryKey >, @@ -43,7 +44,7 @@ export const useInvites = ( options?: Omit< UseQueryOptions< PaginatedResponse<{ invites: HttpTypes.AdminInviteResponse[] }>, - Error, + FetchError, PaginatedResponse<{ invites: HttpTypes.AdminInviteResponse[] }>, QueryKey >, @@ -62,7 +63,7 @@ export const useInvites = ( export const useCreateInvite = ( options?: UseMutationOptions< { invite: AdminInviteResponse }, - Error, + FetchError, HttpTypes.AdminCreateInvite > ) => { @@ -78,7 +79,11 @@ export const useCreateInvite = ( export const useResendInvite = ( id: string, - options?: UseMutationOptions<{ invite: AdminInviteResponse }, Error, void> + options?: UseMutationOptions< + { invite: AdminInviteResponse }, + FetchError, + void + > ) => { return useMutation({ mutationFn: () => sdk.admin.invite.resend(id), @@ -93,7 +98,11 @@ export const useResendInvite = ( export const useDeleteInvite = ( id: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminInviteDeleteResponse, + FetchError, + void + > ) => { return useMutation({ mutationFn: () => sdk.admin.invite.delete(id), @@ -110,7 +119,7 @@ export const useAcceptInvite = ( inviteToken: string, options?: UseMutationOptions< { user: HttpTypes.AdminUserResponse }, - Error, + FetchError, HttpTypes.AdminAcceptInvite & { auth_token: string } > ) => { diff --git a/packages/admin-next/dashboard/src/hooks/api/notification.tsx b/packages/admin-next/dashboard/src/hooks/api/notification.tsx index 93e2f84e18..481faf5af0 100644 --- a/packages/admin-next/dashboard/src/hooks/api/notification.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/notification.tsx @@ -3,6 +3,7 @@ import { QueryKey, UseQueryOptions, useQuery } from "@tanstack/react-query" import { HttpTypes } from "@medusajs/types" import { sdk } from "../../lib/client" import { queryKeysFactory } from "../../lib/query-key-factory" +import { FetchError } from "@medusajs/js-sdk" const NOTIFICATION_QUERY_KEY = "notification" as const export const notificationQueryKeys = queryKeysFactory(NOTIFICATION_QUERY_KEY) @@ -13,7 +14,7 @@ export const useNotification = ( options?: Omit< UseQueryOptions< HttpTypes.AdminNotificationResponse, - Error, + FetchError, HttpTypes.AdminNotificationResponse, QueryKey >, @@ -34,7 +35,7 @@ export const useNotifications = ( options?: Omit< UseQueryOptions< HttpTypes.AdminNotificationListResponse, - Error, + FetchError, HttpTypes.AdminNotificationListResponse, QueryKey >, diff --git a/packages/admin-next/dashboard/src/hooks/api/order-edits.tsx b/packages/admin-next/dashboard/src/hooks/api/order-edits.tsx index d84b32f6c4..f6378db891 100644 --- a/packages/admin-next/dashboard/src/hooks/api/order-edits.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/order-edits.tsx @@ -5,12 +5,13 @@ import { HttpTypes } from "@medusajs/types" import { sdk } from "../../lib/client" import { queryClient } from "../../lib/query-client" import { ordersQueryKeys } from "./orders" +import { FetchError } from "@medusajs/js-sdk" export const useCreateOrderEdit = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminOrderEditPreviewResponse, - Error, + FetchError, HttpTypes.AdminInitiateOrderEditRequest > ) => { @@ -35,7 +36,7 @@ export const useRequestOrderEdit = ( id: string, options?: UseMutationOptions< HttpTypes.AdminOrderEditPreviewResponse, - Error, + FetchError, void > ) => { @@ -59,7 +60,7 @@ export const useConfirmOrderEdit = ( id: string, options?: UseMutationOptions< HttpTypes.AdminOrderEditPreviewResponse, - Error, + FetchError, void > ) => { @@ -81,7 +82,7 @@ export const useConfirmOrderEdit = ( export const useCancelOrderEdit = ( orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: () => sdk.admin.orderEdit.cancelRequest(orderId), @@ -103,7 +104,7 @@ export const useAddOrderEditItems = ( id: string, options?: UseMutationOptions< HttpTypes.AdminOrderEditPreviewResponse, - Error, + FetchError, HttpTypes.AdminAddOrderEditItems > ) => { @@ -127,7 +128,7 @@ export const useUpdateOrderEditOriginalItem = ( id: string, options?: UseMutationOptions< HttpTypes.AdminOrderEditPreviewResponse, - Error, + FetchError, HttpTypes.AdminUpdateOrderEditItem & { itemId: string } > ) => { @@ -155,7 +156,7 @@ export const useUpdateOrderEditAddedItem = ( id: string, options?: UseMutationOptions< HttpTypes.AdminOrderEditPreviewResponse, - Error, + FetchError, HttpTypes.AdminUpdateOrderEditItem & { actionId: string } > ) => { @@ -184,7 +185,7 @@ export const useRemoveOrderEditItem = ( id: string, options?: UseMutationOptions< HttpTypes.AdminOrderEditPreviewResponse, - Error, + FetchError, string > ) => { diff --git a/packages/admin-next/dashboard/src/hooks/api/orders.tsx b/packages/admin-next/dashboard/src/hooks/api/orders.tsx index 2e5a3e61f6..43ca8ade9b 100644 --- a/packages/admin-next/dashboard/src/hooks/api/orders.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/orders.tsx @@ -5,7 +5,7 @@ import { useQuery, UseQueryOptions, } from "@tanstack/react-query" - +import { FetchError } from "@medusajs/js-sdk" import { HttpTypes } from "@medusajs/types" import { sdk } from "../../lib/client" import { queryClient } from "../../lib/query-client" @@ -30,7 +30,7 @@ export const useOrder = ( id: string, query?: Record, options?: Omit< - UseQueryOptions, + UseQueryOptions, "queryFn" | "queryKey" > ) => { @@ -49,7 +49,7 @@ export const useOrderPreview = ( options?: Omit< UseQueryOptions< HttpTypes.AdminOrderPreviewResponse, - Error, + FetchError, HttpTypes.AdminOrderPreviewResponse, QueryKey >, @@ -68,7 +68,7 @@ export const useOrderPreview = ( export const useOrders = ( query?: Record, options?: Omit< - UseQueryOptions, + UseQueryOptions, "queryFn" | "queryKey" > ) => { @@ -85,7 +85,7 @@ export const useCreateOrderFulfillment = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminOrderResponse, - Error, + FetchError, HttpTypes.AdminCreateOrderFulfillment > ) => { @@ -114,7 +114,7 @@ export const useCreateOrderFulfillment = ( export const useCancelOrderFulfillment = ( orderId: string, fulfillmentId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (payload: { no_notification?: boolean }) => @@ -139,7 +139,7 @@ export const useCreateOrderShipment = ( fulfillmentId: string, options?: UseMutationOptions< { order: HttpTypes.AdminOrder }, - Error, + FetchError, HttpTypes.AdminCreateOrderShipment > ) => { @@ -163,7 +163,7 @@ export const useCreateOrderShipment = ( export const useCancelOrder = ( orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (id) => sdk.admin.order.cancel(id), diff --git a/packages/admin-next/dashboard/src/hooks/api/payment-collections.tsx b/packages/admin-next/dashboard/src/hooks/api/payment-collections.tsx index c8ca4b56a2..21c3746a6d 100644 --- a/packages/admin-next/dashboard/src/hooks/api/payment-collections.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/payment-collections.tsx @@ -15,7 +15,7 @@ export const useCreatePaymentCollection = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminPaymentCollectionResponse, - Error, + FetchError, HttpTypes.AdminCreatePaymentCollection > ) => { @@ -45,7 +45,7 @@ export const useMarkPaymentCollectionAsPaid = ( paymentCollectionId: string, options?: UseMutationOptions< HttpTypes.AdminPaymentCollectionResponse, - Error, + FetchError, HttpTypes.AdminMarkPaymentCollectionAsPaid > ) => { diff --git a/packages/admin-next/dashboard/src/hooks/api/payments.tsx b/packages/admin-next/dashboard/src/hooks/api/payments.tsx index b06d48369f..439299f780 100644 --- a/packages/admin-next/dashboard/src/hooks/api/payments.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/payments.tsx @@ -10,6 +10,7 @@ import { sdk } from "../../lib/client" import { queryClient } from "../../lib/query-client" import { queryKeysFactory } from "../../lib/query-key-factory" import { ordersQueryKeys } from "./orders" +import { FetchError } from "@medusajs/js-sdk" const PAYMENT_QUERY_KEY = "payment" as const export const paymentQueryKeys = queryKeysFactory(PAYMENT_QUERY_KEY) @@ -19,7 +20,7 @@ export const usePaymentProviders = ( options?: Omit< UseQueryOptions< HttpTypes.AdminGetPaymentProvidersParams, - Error, + FetchError, HttpTypes.AdminPaymentProviderListResponse, QueryKey >, @@ -41,7 +42,7 @@ export const usePayment = ( options?: Omit< UseQueryOptions< HttpTypes.AdminPaymentResponse, - Error, + FetchError, HttpTypes.AdminPaymentResponse, QueryKey >, @@ -62,7 +63,7 @@ export const useCapturePayment = ( paymentId: string, options?: UseMutationOptions< HttpTypes.AdminPaymentResponse, - Error, + FetchError, HttpTypes.AdminCapturePayment > ) => { @@ -88,7 +89,7 @@ export const useRefundPayment = ( paymentId: string, options?: UseMutationOptions< HttpTypes.AdminPaymentResponse, - Error, + FetchError, HttpTypes.AdminRefundPayment > ) => { diff --git a/packages/admin-next/dashboard/src/hooks/api/product-variants.tsx b/packages/admin-next/dashboard/src/hooks/api/product-variants.tsx index 965260fd65..359bc54db6 100644 --- a/packages/admin-next/dashboard/src/hooks/api/product-variants.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/product-variants.tsx @@ -1,6 +1,7 @@ import { QueryKey, useQuery, UseQueryOptions } from "@tanstack/react-query" import { sdk } from "../../lib/client" import { queryKeysFactory } from "../../lib/query-key-factory" +import { FetchError } from "@medusajs/js-sdk" const PRODUCT_VARIANT_QUERY_KEY = "product_variant" as const export const productVariantQueryKeys = queryKeysFactory( @@ -10,7 +11,7 @@ export const productVariantQueryKeys = queryKeysFactory( export const useVariants = ( query?: Record, options?: Omit< - UseQueryOptions, + UseQueryOptions, "queryFn" | "queryKey" > ) => { diff --git a/packages/admin-next/dashboard/src/hooks/api/products.tsx b/packages/admin-next/dashboard/src/hooks/api/products.tsx index 80fee0531e..2ee357a93a 100644 --- a/packages/admin-next/dashboard/src/hooks/api/products.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/products.tsx @@ -23,7 +23,7 @@ export const optionsQueryKeys = queryKeysFactory(OPTIONS_QUERY_KEY) export const useCreateProductOption = ( productId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (payload: HttpTypes.AdminCreateProductOption) => @@ -42,7 +42,7 @@ export const useCreateProductOption = ( export const useUpdateProductOption = ( productId: string, optionId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (payload: HttpTypes.AdminUpdateProductOption) => @@ -65,7 +65,7 @@ export const useUpdateProductOption = ( export const useDeleteProductOption = ( productId: string, optionId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: () => sdk.admin.product.deleteOption(productId, optionId), @@ -89,7 +89,7 @@ export const useProductVariant = ( variantId: string, query?: Record, options?: Omit< - UseQueryOptions, + UseQueryOptions, "queryFn" | "queryKey" > ) => { @@ -107,7 +107,7 @@ export const useProductVariants = ( productId: string, query?: Record, options?: Omit< - UseQueryOptions, + UseQueryOptions, "queryFn" | "queryKey" > ) => { @@ -122,7 +122,7 @@ export const useProductVariants = ( export const useCreateProductVariant = ( productId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (payload: HttpTypes.AdminCreateProductVariant) => @@ -141,7 +141,7 @@ export const useCreateProductVariant = ( export const useUpdateProductVariant = ( productId: string, variantId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: (payload: HttpTypes.AdminUpdateProductVariant) => @@ -163,7 +163,7 @@ export const useUpdateProductVariant = ( export const useUpdateProductVariantsBatch = ( productId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: ( @@ -187,7 +187,7 @@ export const useUpdateProductVariantsBatch = ( export const useProductVariantsInventoryItemsBatch = ( productId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: ( @@ -209,7 +209,7 @@ export const useProductVariantsInventoryItemsBatch = ( export const useDeleteVariant = ( productId: string, variantId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: () => sdk.admin.product.deleteVariant(productId, variantId), @@ -232,7 +232,7 @@ export const useProduct = ( id: string, query?: Record, options?: Omit< - UseQueryOptions, + UseQueryOptions, "queryFn" | "queryKey" > ) => { diff --git a/packages/admin-next/dashboard/src/hooks/api/refund-reasons.tsx b/packages/admin-next/dashboard/src/hooks/api/refund-reasons.tsx index 4465f47744..db889056f0 100644 --- a/packages/admin-next/dashboard/src/hooks/api/refund-reasons.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/refund-reasons.tsx @@ -2,6 +2,7 @@ import { HttpTypes } from "@medusajs/types" import { QueryKey, useQuery, UseQueryOptions } from "@tanstack/react-query" import { sdk } from "../../lib/client" import { queryKeysFactory } from "../../lib/query-key-factory" +import { FetchError } from "@medusajs/js-sdk" const REFUND_REASON_QUERY_KEY = "refund-reason" as const export const refundReasonQueryKeys = queryKeysFactory(REFUND_REASON_QUERY_KEY) @@ -11,7 +12,7 @@ export const useRefundReasons = ( options?: Omit< UseQueryOptions< HttpTypes.RefundReasonsResponse, - Error, + FetchError, HttpTypes.RefundReasonsResponse, QueryKey >, diff --git a/packages/admin-next/dashboard/src/hooks/api/regions.tsx b/packages/admin-next/dashboard/src/hooks/api/regions.tsx index f0e2865264..bc4133967c 100644 --- a/packages/admin-next/dashboard/src/hooks/api/regions.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/regions.tsx @@ -10,6 +10,7 @@ import { sdk } from "../../lib/client" import { queryClient } from "../../lib/query-client" import { queryKeysFactory } from "../../lib/query-key-factory" import { pricePreferencesQueryKeys } from "./price-preferences" +import { FetchError } from "@medusajs/js-sdk" const REGIONS_QUERY_KEY = "regions" as const export const regionsQueryKeys = queryKeysFactory(REGIONS_QUERY_KEY) @@ -20,7 +21,7 @@ export const useRegion = ( options?: Omit< UseQueryOptions< { region: HttpTypes.AdminRegion }, - Error, + FetchError, { region: HttpTypes.AdminRegion }, QueryKey >, @@ -41,7 +42,7 @@ export const useRegions = ( options?: Omit< UseQueryOptions< PaginatedResponse<{ regions: HttpTypes.AdminRegion[] }>, - Error, + FetchError, PaginatedResponse<{ regions: HttpTypes.AdminRegion[] }>, QueryKey >, @@ -60,7 +61,7 @@ export const useRegions = ( export const useCreateRegion = ( options?: UseMutationOptions< { region: HttpTypes.AdminRegion }, - Error, + FetchError, HttpTypes.AdminCreateRegion > ) => { @@ -86,7 +87,7 @@ export const useUpdateRegion = ( id: string, options?: UseMutationOptions< { region: HttpTypes.AdminRegion }, - Error, + FetchError, HttpTypes.AdminUpdateRegion > ) => { @@ -111,7 +112,11 @@ export const useUpdateRegion = ( export const useDeleteRegion = ( id: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminRegionDeleteResponse, + FetchError, + void + > ) => { return useMutation({ mutationFn: () => sdk.admin.region.delete(id), diff --git a/packages/admin-next/dashboard/src/hooks/api/return-reasons.tsx b/packages/admin-next/dashboard/src/hooks/api/return-reasons.tsx index 3db0c454fc..ee67cf9d53 100644 --- a/packages/admin-next/dashboard/src/hooks/api/return-reasons.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/return-reasons.tsx @@ -107,7 +107,7 @@ export const useDeleteReturnReason = ( id: string, options?: UseMutationOptions< HttpTypes.AdminReturnReasonDeleteResponse, - Error, + FetchError, void > ) => { diff --git a/packages/admin-next/dashboard/src/hooks/api/returns.tsx b/packages/admin-next/dashboard/src/hooks/api/returns.tsx index 001992d410..dc988621cb 100644 --- a/packages/admin-next/dashboard/src/hooks/api/returns.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/returns.tsx @@ -11,6 +11,7 @@ import { sdk } from "../../lib/client" import { queryClient } from "../../lib/query-client" import { queryKeysFactory } from "../../lib/query-key-factory" import { ordersQueryKeys } from "./orders" +import { FetchError } from "@medusajs/js-sdk" const RETURNS_QUERY_KEY = "returns" as const export const returnsQueryKeys = queryKeysFactory(RETURNS_QUERY_KEY) @@ -19,7 +20,7 @@ export const useReturn = ( id: string, query?: Record, options?: Omit< - UseQueryOptions, + UseQueryOptions, "queryFn" | "queryKey" > ) => { @@ -37,7 +38,7 @@ export const useReturns = ( options?: Omit< UseQueryOptions< HttpTypes.AdminReturnFilters, - Error, + FetchError, HttpTypes.AdminReturnsResponse, QueryKey >, @@ -57,7 +58,7 @@ export const useInitiateReturn = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminInitiateReturnRequest > ) => { @@ -85,7 +86,7 @@ export const useInitiateReturn = ( export const useCancelReturn = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: () => sdk.admin.return.cancel(id), @@ -120,7 +121,7 @@ export const useConfirmReturnRequest = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminConfirmReturnRequest > ) => { @@ -151,7 +152,7 @@ export const useConfirmReturnRequest = ( export const useCancelReturnRequest = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: () => sdk.admin.return.cancelRequest(id), @@ -182,7 +183,7 @@ export const useAddReturnItem = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminAddReturnItems > ) => { @@ -209,7 +210,7 @@ export const useUpdateReturnItem = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminUpdateReturnItems & { actionId: string } > ) => { @@ -238,7 +239,11 @@ export const useUpdateReturnItem = ( export const useRemoveReturnItem = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminReturnResponse, + FetchError, + string + > ) => { return useMutation({ mutationFn: (actionId: string) => @@ -263,7 +268,7 @@ export const useUpdateReturn = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminUpdateReturnRequest > ) => { @@ -291,7 +296,7 @@ export const useAddReturnShipping = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminAddReturnShipping > ) => { @@ -318,7 +323,7 @@ export const useUpdateReturnShipping = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminAddReturnShipping > ) => { @@ -346,7 +351,11 @@ export const useUpdateReturnShipping = ( export const useDeleteReturnShipping = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminReturnResponse, + FetchError, + string + > ) => { return useMutation({ mutationFn: (actionId: string) => @@ -375,7 +384,7 @@ export const useInitiateReceiveReturn = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminInitiateReceiveReturn > ) => { @@ -402,7 +411,7 @@ export const useAddReceiveItems = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminReceiveItems > ) => { @@ -429,7 +438,7 @@ export const useUpdateReceiveItem = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminUpdateReceiveItems & { actionId: string } > ) => { @@ -458,7 +467,11 @@ export const useUpdateReceiveItem = ( export const useRemoveReceiveItems = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminReturnResponse, + FetchError, + string + > ) => { return useMutation({ mutationFn: (actionId: string) => { @@ -484,7 +497,7 @@ export const useAddDismissItems = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminDismissItems > ) => { @@ -511,7 +524,7 @@ export const useUpdateDismissItem = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminUpdateDismissItems & { actionId: string } > ) => { @@ -540,7 +553,11 @@ export const useUpdateDismissItem = ( export const useRemoveDismissItem = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminReturnResponse, + FetchError, + string + > ) => { return useMutation({ mutationFn: (actionId: string) => { @@ -566,7 +583,7 @@ export const useConfirmReturnReceive = ( orderId: string, options?: UseMutationOptions< HttpTypes.AdminReturnResponse, - Error, + FetchError, HttpTypes.AdminConfirmReceiveReturn > ) => { @@ -597,7 +614,7 @@ export const useConfirmReturnReceive = ( export const useCancelReceiveReturn = ( id: string, orderId: string, - options?: UseMutationOptions + options?: UseMutationOptions ) => { return useMutation({ mutationFn: () => sdk.admin.return.cancelReceive(id), diff --git a/packages/admin-next/dashboard/src/hooks/api/sales-channels.tsx b/packages/admin-next/dashboard/src/hooks/api/sales-channels.tsx index 6fe9b6d666..16666c2420 100644 --- a/packages/admin-next/dashboard/src/hooks/api/sales-channels.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/sales-channels.tsx @@ -14,6 +14,7 @@ import { sdk } from "../../lib/client" import { queryClient } from "../../lib/query-client" import { queryKeysFactory } from "../../lib/query-key-factory" import { productsQueryKeys } from "./products" +import { FetchError } from "@medusajs/js-sdk" const SALES_CHANNELS_QUERY_KEY = "sales-channels" as const export const salesChannelsQueryKeys = queryKeysFactory(SALES_CHANNELS_QUERY_KEY) @@ -23,7 +24,7 @@ export const useSalesChannel = ( options?: Omit< UseQueryOptions< AdminSalesChannelResponse, - Error, + FetchError, AdminSalesChannelResponse, QueryKey >, @@ -44,7 +45,7 @@ export const useSalesChannels = ( options?: Omit< UseQueryOptions< AdminSalesChannelListResponse, - Error, + FetchError, AdminSalesChannelListResponse, QueryKey >, @@ -63,7 +64,7 @@ export const useSalesChannels = ( export const useCreateSalesChannel = ( options?: UseMutationOptions< AdminSalesChannelResponse, - Error, + FetchError, HttpTypes.AdminCreateSalesChannel > ) => { @@ -83,7 +84,7 @@ export const useUpdateSalesChannel = ( id: string, options?: UseMutationOptions< AdminSalesChannelResponse, - Error, + FetchError, HttpTypes.AdminUpdateSalesChannel > ) => { @@ -107,7 +108,7 @@ export const useDeleteSalesChannel = ( id: string, options?: UseMutationOptions< HttpTypes.AdminSalesChannelDeleteResponse, - Error, + FetchError, void > ) => { @@ -136,7 +137,7 @@ export const useSalesChannelRemoveProducts = ( id: string, options?: UseMutationOptions< AdminSalesChannelResponse, - Error, + FetchError, HttpTypes.AdminBatchLink["remove"] > ) => { @@ -173,7 +174,7 @@ export const useSalesChannelAddProducts = ( id: string, options?: UseMutationOptions< AdminSalesChannelResponse, - Error, + FetchError, HttpTypes.AdminBatchLink["add"] > ) => { diff --git a/packages/admin-next/dashboard/src/hooks/api/shipping-options.tsx b/packages/admin-next/dashboard/src/hooks/api/shipping-options.tsx index 0c7ba9414f..4297b2109d 100644 --- a/packages/admin-next/dashboard/src/hooks/api/shipping-options.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/shipping-options.tsx @@ -42,7 +42,7 @@ export const useShippingOptions = ( options?: Omit< UseQueryOptions< HttpTypes.AdminShippingOptionListResponse, - Error, + FetchError, HttpTypes.AdminShippingOptionListResponse, QueryKey >, diff --git a/packages/admin-next/dashboard/src/hooks/api/tax-rates.tsx b/packages/admin-next/dashboard/src/hooks/api/tax-rates.tsx index 823775c267..ac18bbddeb 100644 --- a/packages/admin-next/dashboard/src/hooks/api/tax-rates.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/tax-rates.tsx @@ -42,7 +42,7 @@ export const useTaxRates = ( options?: Omit< UseQueryOptions< HttpTypes.AdminTaxRateListResponse, - Error, + FetchError, HttpTypes.AdminTaxRateListResponse, QueryKey >, @@ -62,7 +62,7 @@ export const useUpdateTaxRate = ( id: string, options?: UseMutationOptions< HttpTypes.AdminTaxRateResponse, - Error, + FetchError, HttpTypes.AdminUpdateTaxRate > ) => { @@ -106,7 +106,7 @@ export const useDeleteTaxRate = ( id: string, options?: UseMutationOptions< HttpTypes.AdminTaxRateDeleteResponse, - Error, + FetchError, void > ) => { diff --git a/packages/admin-next/dashboard/src/lib/is-axios-error.ts b/packages/admin-next/dashboard/src/lib/is-axios-error.ts deleted file mode 100644 index 1d8cba11f8..0000000000 --- a/packages/admin-next/dashboard/src/lib/is-axios-error.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { AxiosError } from "axios" - -export const isAxiosError = (error: any): error is AxiosError => { - return error.isAxiosError -} diff --git a/packages/admin-next/dashboard/src/routes/login/login.tsx b/packages/admin-next/dashboard/src/routes/login/login.tsx index 0009e892dc..ec62128014 100644 --- a/packages/admin-next/dashboard/src/routes/login/login.tsx +++ b/packages/admin-next/dashboard/src/routes/login/login.tsx @@ -9,10 +9,10 @@ import { Divider } from "../../components/common/divider" import { Form } from "../../components/common/form" import { LogoBox } from "../../components/common/logo-box" import { useSignInWithEmailPassword } from "../../hooks/api/auth" -import { isAxiosError } from "../../lib/is-axios-error" import after from "virtual:medusa/widgets/login/after" import before from "virtual:medusa/widgets/login/before" +import { isFetchError } from "../../lib/is-fetch-error" const LoginSchema = z.object({ email: z.string().email(), @@ -45,8 +45,8 @@ export const Login = () => { navigate(from, { replace: true }) } catch (error) { - if (isAxiosError(error)) { - if (error.response?.status === 401) { + if (isFetchError(error)) { + if (error.status === 401) { form.setError("email", { type: "manual", }) diff --git a/packages/core/js-sdk/src/admin/order.ts b/packages/core/js-sdk/src/admin/order.ts index 49ddfe07a2..de45f15b6c 100644 --- a/packages/core/js-sdk/src/admin/order.ts +++ b/packages/core/js-sdk/src/admin/order.ts @@ -25,7 +25,7 @@ export class Order { async retrievePreview( id: string, - query?: SelectParams, + query?: HttpTypes.AdminOrderFilters, headers?: ClientHeaders ) { return await this.client.fetch(