@@ -36,103 +36,103 @@ namespace ShopHooks {
3636 return context ;
3737 }
3838
39- const clientDecorator = < T = CallableFunction > ( func : ( client : ShopAPIClient ) => T ) : T => {
39+ export const useShopClient = ( ) => {
4040 const { shopApiDomain, shopApiCSRFCookieName, shopApiTimeout } = useShopContext ( ) ;
41- return func ( new ShopAPIClient ( shopApiDomain , shopApiCSRFCookieName , shopApiTimeout ) ) ;
41+ return new ShopAPIClient ( shopApiDomain , shopApiCSRFCookieName , shopApiTimeout ) ;
4242 }
4343
44- export const useUserStatus = ( ) =>
44+ export const useUserStatus = ( client : ShopAPIClient ) =>
4545 useSuspenseQuery ( {
4646 queryKey : QUERY_KEYS . USER ,
47- queryFn : clientDecorator ( ShopAPIs . retrieveUserInfo ) ,
47+ queryFn : ShopAPIs . retrieveUserInfo ( client ) ,
4848 retry : 3 ,
4949 } ) ;
5050
51- export const useSignInWithEmailMutation = ( ) =>
51+ export const useSignInWithEmailMutation = ( client : ShopAPIClient ) =>
5252 useMutation ( {
5353 mutationKey : MUTATION_KEYS . USER_SIGN_IN_EMAIL ,
54- mutationFn : clientDecorator ( ShopAPIs . signInWithEmail ) ,
54+ mutationFn : ShopAPIs . signInWithEmail ( client ) ,
5555 meta : { invalidates : [ QUERY_KEYS . BASE ] } ,
5656 } ) ;
5757
58- export const useSignInWithSNSMutation = ( ) =>
58+ export const useSignInWithSNSMutation = ( client : ShopAPIClient ) =>
5959 useMutation ( {
6060 mutationKey : MUTATION_KEYS . USER_SIGN_IN_SNS ,
61- mutationFn : clientDecorator ( ShopAPIs . signInWithSNS ) ,
61+ mutationFn : ShopAPIs . signInWithSNS ( client ) ,
6262 meta : { invalidates : [ QUERY_KEYS . BASE ] } ,
6363 } ) ;
6464
65- export const useSignOutMutation = ( ) =>
65+ export const useSignOutMutation = ( client : ShopAPIClient ) =>
6666 useMutation ( {
6767 mutationKey : MUTATION_KEYS . USER_SIGN_OUT ,
68- mutationFn : clientDecorator ( ShopAPIs . signOut ) ,
68+ mutationFn : ShopAPIs . signOut ( client ) ,
6969 meta : { invalidates : [ QUERY_KEYS . BASE ] } ,
7070 } ) ;
7171
72- export const useProducts = ( qs ?: ShopSchemas . ProductListQueryParams ) =>
72+ export const useProducts = ( client : ShopAPIClient , qs ?: ShopSchemas . ProductListQueryParams ) =>
7373 useSuspenseQuery ( {
7474 queryKey : QUERY_KEYS . PRODUCT_LIST ,
75- queryFn : ( ) => clientDecorator ( ShopAPIs . listProducts ) ( qs ) ,
75+ queryFn : ( ) => ShopAPIs . listProducts ( client ) ( qs ) ,
7676 } ) ;
7777
78- export const useCart = ( ) =>
78+ export const useCart = ( client : ShopAPIClient ) =>
7979 useSuspenseQuery ( {
8080 queryKey : QUERY_KEYS . CART_INFO ,
81- queryFn : clientDecorator ( ShopAPIs . retrieveCart ) ,
81+ queryFn : ShopAPIs . retrieveCart ( client ) ,
8282 } ) ;
8383
84- export const useAddItemToCartMutation = ( ) =>
84+ export const useAddItemToCartMutation = ( client : ShopAPIClient ) =>
8585 useMutation ( {
8686 mutationKey : MUTATION_KEYS . CART_ITEM_APPEND ,
87- mutationFn : clientDecorator ( ShopAPIs . appendItemToCart ) ,
87+ mutationFn : ShopAPIs . appendItemToCart ( client ) ,
8888 meta : { invalidates : [ QUERY_KEYS . CART_INFO ] } ,
8989 } ) ;
9090
91- export const useRemoveItemFromCartMutation = ( ) =>
91+ export const useRemoveItemFromCartMutation = ( client : ShopAPIClient ) =>
9292 useMutation ( {
9393 mutationKey : MUTATION_KEYS . CART_ITEM_REMOVE ,
94- mutationFn : clientDecorator ( ShopAPIs . removeItemFromCart ) ,
94+ mutationFn : ShopAPIs . removeItemFromCart ( client ) ,
9595 meta : { invalidates : [ QUERY_KEYS . CART_INFO ] } ,
9696 } ) ;
9797
98- export const usePrepareOneItemOrderMutation = ( ) =>
98+ export const usePrepareOneItemOrderMutation = ( client : ShopAPIClient ) =>
9999 useMutation ( {
100100 mutationKey : MUTATION_KEYS . ONE_ITEM_ORDER_START ,
101- mutationFn : clientDecorator ( ShopAPIs . prepareOneItemOrder ) ,
101+ mutationFn : ShopAPIs . prepareOneItemOrder ( client ) ,
102102 meta : { invalidates : [ QUERY_KEYS . CART_INFO , QUERY_KEYS . ORDER_LIST ] } ,
103103 } ) ;
104104
105- export const usePrepareCartOrderMutation = ( ) =>
105+ export const usePrepareCartOrderMutation = ( client : ShopAPIClient ) =>
106106 useMutation ( {
107107 mutationKey : MUTATION_KEYS . CART_ORDER_START ,
108- mutationFn : clientDecorator ( ShopAPIs . prepareCartOrder ) ,
108+ mutationFn : ShopAPIs . prepareCartOrder ( client ) ,
109109 meta : { invalidates : [ QUERY_KEYS . CART_INFO , QUERY_KEYS . ORDER_LIST ] } ,
110110 } ) ;
111111
112- export const useOrders = ( ) =>
112+ export const useOrders = ( client : ShopAPIClient ) =>
113113 useSuspenseQuery ( {
114114 queryKey : QUERY_KEYS . ORDER_LIST ,
115- queryFn : clientDecorator ( ShopAPIs . listOrders ) ,
115+ queryFn : ShopAPIs . listOrders ( client ) ,
116116 } ) ;
117117
118- export const useOneItemRefundMutation = ( ) =>
118+ export const useOneItemRefundMutation = ( client : ShopAPIClient ) =>
119119 useMutation ( {
120120 mutationKey : MUTATION_KEYS . ONE_ITEM_REFUND ,
121- mutationFn : clientDecorator ( ShopAPIs . refundOneItemFromOrder ) ,
121+ mutationFn : ShopAPIs . refundOneItemFromOrder ( client ) ,
122122 meta : { invalidates : [ QUERY_KEYS . ORDER_LIST ] } ,
123123 } ) ;
124124
125- export const useOrderRefundMutation = ( ) =>
125+ export const useOrderRefundMutation = ( client : ShopAPIClient ) =>
126126 useMutation ( {
127127 mutationKey : MUTATION_KEYS . ALL_ORDER_REFUND ,
128- mutationFn : clientDecorator ( ShopAPIs . refundAllItemsInOrder ) ,
128+ mutationFn : ShopAPIs . refundAllItemsInOrder ( client ) ,
129129 meta : { invalidates : [ QUERY_KEYS . ORDER_LIST ] } ,
130130 } ) ;
131131
132- export const useOptionsOfOneItemInOrderPatchMutation = ( ) =>
132+ export const useOptionsOfOneItemInOrderPatchMutation = ( client : ShopAPIClient ) =>
133133 useMutation ( {
134134 mutationKey : MUTATION_KEYS . CART_ITEM_APPEND ,
135- mutationFn : clientDecorator ( ShopAPIs . patchOrderOptions ) ,
135+ mutationFn : ShopAPIs . patchOrderOptions ( client ) ,
136136 meta : { invalidates : [ QUERY_KEYS . ORDER_LIST ] } ,
137137 } ) ;
138138}
0 commit comments