@instockng/api-client 1.0.0 → 1.0.2
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/dist/backend-types.d.ts +10 -0
- package/dist/backend-types.js +10 -0
- package/dist/client.d.ts +20 -0
- package/dist/client.js +40 -0
- package/dist/fetchers/brands.d.ts +25 -0
- package/dist/fetchers/brands.js +26 -0
- package/dist/fetchers/carts.d.ts +2339 -0
- package/dist/fetchers/carts.js +167 -0
- package/dist/fetchers/delivery-zones.d.ts +28 -0
- package/{src/fetchers/delivery-zones.ts → dist/fetchers/delivery-zones.js} +9 -12
- package/{src/fetchers/index.ts → dist/fetchers/index.d.ts} +1 -1
- package/dist/fetchers/index.js +22 -0
- package/dist/fetchers/orders.d.ts +283 -0
- package/dist/fetchers/orders.js +44 -0
- package/dist/fetchers/products.d.ts +386 -0
- package/dist/fetchers/products.js +42 -0
- package/dist/hooks/admin/abandoned-carts.d.ts +535 -0
- package/dist/hooks/admin/abandoned-carts.js +79 -0
- package/dist/hooks/admin/brands.d.ts +79 -0
- package/dist/hooks/admin/brands.js +103 -0
- package/dist/hooks/admin/customers.d.ts +278 -0
- package/dist/hooks/admin/customers.js +25 -0
- package/dist/hooks/admin/delivery-zones.d.ts +270 -0
- package/dist/hooks/admin/delivery-zones.js +168 -0
- package/dist/hooks/admin/discount-codes.d.ts +299 -0
- package/dist/hooks/admin/discount-codes.js +157 -0
- package/{src/hooks/admin/index.ts → dist/hooks/admin/index.d.ts} +0 -1
- package/dist/hooks/admin/index.js +16 -0
- package/dist/hooks/admin/inventory.d.ts +224 -0
- package/dist/hooks/admin/inventory.js +102 -0
- package/dist/hooks/admin/orders.d.ts +1380 -0
- package/dist/hooks/admin/orders.js +169 -0
- package/dist/hooks/admin/products.d.ts +374 -0
- package/dist/hooks/admin/products.js +84 -0
- package/dist/hooks/admin/stats.d.ts +277 -0
- package/dist/hooks/admin/stats.js +24 -0
- package/dist/hooks/admin/variants.d.ts +115 -0
- package/dist/hooks/admin/variants.js +121 -0
- package/dist/hooks/admin/warehouses.d.ts +277 -0
- package/dist/hooks/admin/warehouses.js +103 -0
- package/dist/hooks/public/brands.d.ts +33 -0
- package/dist/hooks/public/brands.js +30 -0
- package/dist/hooks/public/carts.d.ts +2407 -0
- package/dist/hooks/public/carts.js +213 -0
- package/dist/hooks/public/delivery-zones.d.ts +34 -0
- package/{src/hooks/public/delivery-zones.ts → dist/hooks/public/delivery-zones.js} +6 -12
- package/{src/hooks/public/index.ts → dist/hooks/public/index.d.ts} +1 -1
- package/dist/hooks/public/index.js +10 -0
- package/dist/hooks/public/orders.d.ts +302 -0
- package/{src/hooks/public/orders.ts → dist/hooks/public/orders.js} +12 -28
- package/dist/hooks/public/products.d.ts +398 -0
- package/{src/hooks/public/products.ts → dist/hooks/public/products.js} +12 -22
- package/dist/hooks/use-query-unwrapped.d.ts +20 -0
- package/dist/hooks/use-query-unwrapped.js +22 -0
- package/dist/hooks/useApiConfig.d.ts +11 -0
- package/dist/hooks/useApiConfig.js +14 -0
- package/dist/index.d.ts +20 -0
- package/{src/index.ts → dist/index.js} +0 -17
- package/dist/provider.d.ts +33 -0
- package/dist/provider.js +52 -0
- package/dist/rpc-client.d.ts +9043 -0
- package/dist/rpc-client.js +78 -0
- package/{src/rpc-types.ts → dist/rpc-types.d.ts} +35 -80
- package/dist/rpc-types.js +7 -0
- package/{src/types.ts → dist/types.d.ts} +0 -6
- package/dist/types.js +16 -0
- package/dist/utils/query-keys.d.ts +106 -0
- package/dist/utils/query-keys.js +108 -0
- package/package.json +24 -13
- package/src/client.ts +0 -57
- package/src/fetchers/carts.ts +0 -202
- package/src/fetchers/orders.ts +0 -48
- package/src/fetchers/products.ts +0 -46
- package/src/hooks/admin/abandoned-carts.ts +0 -102
- package/src/hooks/admin/brands.ts +0 -134
- package/src/hooks/admin/customers.ts +0 -31
- package/src/hooks/admin/delivery-zones.ts +0 -236
- package/src/hooks/admin/discount-codes.ts +0 -222
- package/src/hooks/admin/inventory.ts +0 -137
- package/src/hooks/admin/orders.ts +0 -229
- package/src/hooks/admin/products.ts +0 -116
- package/src/hooks/admin/stats.ts +0 -30
- package/src/hooks/admin/variants.ts +0 -173
- package/src/hooks/admin/warehouses.ts +0 -143
- package/src/hooks/public/carts.ts +0 -298
- package/src/hooks/use-query-unwrapped.ts +0 -30
- package/src/hooks/useApiConfig.ts +0 -22
- package/src/provider.tsx +0 -89
- package/src/rpc-client.ts +0 -106
- package/src/utils/query-keys.ts +0 -121
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe admin RPC hooks for order management
|
|
3
|
-
*
|
|
4
|
-
* These hooks use Hono RPC client with types directly from the backend,
|
|
5
|
-
* providing end-to-end type safety without code generation.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { useMutation, useQueryClient, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
9
|
-
import { useQueryUnwrapped } from '../use-query-unwrapped';
|
|
10
|
-
import { createAdminRpcClients, authHeaders } from '../../rpc-client';
|
|
11
|
-
import { queryKeys } from '../../utils/query-keys';
|
|
12
|
-
import { useApiConfig } from '../useApiConfig';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Hook to list all orders with pagination using admin RPC
|
|
16
|
-
*
|
|
17
|
-
* @param options - React Query options
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```tsx
|
|
21
|
-
* const { data: orders, isLoading } = useListOrders();
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export function useListOrders(
|
|
25
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['orders']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
26
|
-
) {
|
|
27
|
-
const { baseURL, authToken } = useApiConfig();
|
|
28
|
-
|
|
29
|
-
return useQueryUnwrapped({
|
|
30
|
-
queryKey: queryKeys.admin.orders.list(),
|
|
31
|
-
queryFn: async () => {
|
|
32
|
-
const clients = createAdminRpcClients(baseURL);
|
|
33
|
-
const res = await clients.orders.index.$get({}, authHeaders(authToken));
|
|
34
|
-
if (!res.ok) {
|
|
35
|
-
throw new Error(`Failed to fetch orders: ${res.statusText}`);
|
|
36
|
-
}
|
|
37
|
-
return res.json();
|
|
38
|
-
},
|
|
39
|
-
...options,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Hook to get order by ID using admin RPC
|
|
45
|
-
*
|
|
46
|
-
* @param orderId - Order UUID
|
|
47
|
-
* @param options - React Query options
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```tsx
|
|
51
|
-
* const { data: order } = useGetOrder('order-123');
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export function useGetOrder(
|
|
55
|
-
orderId: string,
|
|
56
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['orders'][':id']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
57
|
-
) {
|
|
58
|
-
const { baseURL, authToken } = useApiConfig();
|
|
59
|
-
|
|
60
|
-
return useQueryUnwrapped({
|
|
61
|
-
queryKey: queryKeys.admin.orders.detail(orderId),
|
|
62
|
-
queryFn: async () => {
|
|
63
|
-
const clients = createAdminRpcClients(baseURL);
|
|
64
|
-
const res = await clients.orders[':id'].$get(
|
|
65
|
-
{ param: { id: orderId } },
|
|
66
|
-
authHeaders(authToken)
|
|
67
|
-
);
|
|
68
|
-
if (!res.ok) {
|
|
69
|
-
throw new Error(`Failed to fetch order: ${res.statusText}`);
|
|
70
|
-
}
|
|
71
|
-
return res.json();
|
|
72
|
-
},
|
|
73
|
-
...options,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Hook to create a new order using admin RPC
|
|
79
|
-
*
|
|
80
|
-
* @param options - React Query mutation options
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```tsx
|
|
84
|
-
* const createOrder = useCreateOrder();
|
|
85
|
-
* createOrder.mutate({
|
|
86
|
-
* brandSlug: 'my-brand',
|
|
87
|
-
* items: [{ sku: 'SKU-001', quantity: 2 }],
|
|
88
|
-
* // ... other order fields
|
|
89
|
-
* });
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
export function useCreateOrder(
|
|
93
|
-
options?: UseMutationOptions<
|
|
94
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['orders']['index']['$post']>>['json']>>,
|
|
95
|
-
Error,
|
|
96
|
-
any // Type will be inferred from backend
|
|
97
|
-
>
|
|
98
|
-
) {
|
|
99
|
-
const { baseURL, authToken } = useApiConfig();
|
|
100
|
-
const queryClient = useQueryClient();
|
|
101
|
-
|
|
102
|
-
return useMutation({
|
|
103
|
-
mutationFn: async (data) => {
|
|
104
|
-
const clients = createAdminRpcClients(baseURL);
|
|
105
|
-
const res = await clients.orders.index.$post(
|
|
106
|
-
{ json: data },
|
|
107
|
-
authHeaders(authToken)
|
|
108
|
-
);
|
|
109
|
-
if (!res.ok) {
|
|
110
|
-
throw new Error(`Failed to create order: ${res.statusText}`);
|
|
111
|
-
}
|
|
112
|
-
return res.json();
|
|
113
|
-
},
|
|
114
|
-
onSuccess: () => {
|
|
115
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.orders.all });
|
|
116
|
-
},
|
|
117
|
-
...options,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Hook to update an order using admin RPC
|
|
123
|
-
*
|
|
124
|
-
* @param orderId - Order UUID
|
|
125
|
-
* @param options - React Query mutation options
|
|
126
|
-
*/
|
|
127
|
-
export function useUpdateOrder(
|
|
128
|
-
orderId: string,
|
|
129
|
-
options?: UseMutationOptions<
|
|
130
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['orders'][':id']['$patch']>>['json']>>,
|
|
131
|
-
Error,
|
|
132
|
-
any
|
|
133
|
-
>
|
|
134
|
-
) {
|
|
135
|
-
const { baseURL, authToken } = useApiConfig();
|
|
136
|
-
const queryClient = useQueryClient();
|
|
137
|
-
|
|
138
|
-
return useMutation({
|
|
139
|
-
mutationFn: async (data) => {
|
|
140
|
-
const clients = createAdminRpcClients(baseURL);
|
|
141
|
-
const res = await clients.orders[':id'].$patch(
|
|
142
|
-
{ param: { id: orderId }, json: data },
|
|
143
|
-
authHeaders(authToken)
|
|
144
|
-
);
|
|
145
|
-
if (!res.ok) {
|
|
146
|
-
throw new Error(`Failed to update order: ${res.statusText}`);
|
|
147
|
-
}
|
|
148
|
-
return res.json();
|
|
149
|
-
},
|
|
150
|
-
onSuccess: () => {
|
|
151
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.orders.detail(orderId) });
|
|
152
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.orders.all });
|
|
153
|
-
},
|
|
154
|
-
...options,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Hook to update order status using admin RPC
|
|
160
|
-
*
|
|
161
|
-
* @param orderId - Order UUID
|
|
162
|
-
* @param options - React Query mutation options
|
|
163
|
-
*/
|
|
164
|
-
export function useUpdateOrderStatus(
|
|
165
|
-
orderId: string,
|
|
166
|
-
options?: UseMutationOptions<
|
|
167
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['orders'][':id']['status']['$patch']>>['json']>>,
|
|
168
|
-
Error,
|
|
169
|
-
any
|
|
170
|
-
>
|
|
171
|
-
) {
|
|
172
|
-
const { baseURL, authToken } = useApiConfig();
|
|
173
|
-
const queryClient = useQueryClient();
|
|
174
|
-
|
|
175
|
-
return useMutation({
|
|
176
|
-
mutationFn: async (data) => {
|
|
177
|
-
const clients = createAdminRpcClients(baseURL);
|
|
178
|
-
const res = await clients.orders[':id'].status.$patch(
|
|
179
|
-
{ param: { id: orderId }, json: data },
|
|
180
|
-
authHeaders(authToken)
|
|
181
|
-
);
|
|
182
|
-
if (!res.ok) {
|
|
183
|
-
throw new Error(`Failed to update order status: ${res.statusText}`);
|
|
184
|
-
}
|
|
185
|
-
return res.json();
|
|
186
|
-
},
|
|
187
|
-
onSuccess: () => {
|
|
188
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.orders.detail(orderId) });
|
|
189
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.orders.all });
|
|
190
|
-
},
|
|
191
|
-
...options,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Hook to delete an order using admin RPC
|
|
197
|
-
*
|
|
198
|
-
* @param orderId - Order UUID
|
|
199
|
-
* @param options - React Query mutation options
|
|
200
|
-
*/
|
|
201
|
-
export function useDeleteOrder(
|
|
202
|
-
orderId: string,
|
|
203
|
-
options?: UseMutationOptions<
|
|
204
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['orders'][':id']['$delete']>>['json']>>,
|
|
205
|
-
Error,
|
|
206
|
-
void
|
|
207
|
-
>
|
|
208
|
-
) {
|
|
209
|
-
const { baseURL, authToken } = useApiConfig();
|
|
210
|
-
const queryClient = useQueryClient();
|
|
211
|
-
|
|
212
|
-
return useMutation({
|
|
213
|
-
mutationFn: async () => {
|
|
214
|
-
const clients = createAdminRpcClients(baseURL);
|
|
215
|
-
const res = await clients.orders[':id'].$delete(
|
|
216
|
-
{ param: { id: orderId } },
|
|
217
|
-
authHeaders(authToken)
|
|
218
|
-
);
|
|
219
|
-
if (!res.ok) {
|
|
220
|
-
throw new Error(`Failed to delete order: ${res.statusText}`);
|
|
221
|
-
}
|
|
222
|
-
return res.json();
|
|
223
|
-
},
|
|
224
|
-
onSuccess: () => {
|
|
225
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.orders.all });
|
|
226
|
-
},
|
|
227
|
-
...options,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe admin RPC hooks for product management
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { useMutation, useQueryClient, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
6
|
-
import { useQueryUnwrapped } from '../use-query-unwrapped';
|
|
7
|
-
import { createAdminRpcClients, authHeaders } from '../../rpc-client';
|
|
8
|
-
import { queryKeys } from '../../utils/query-keys';
|
|
9
|
-
import { useApiConfig } from '../useApiConfig';
|
|
10
|
-
|
|
11
|
-
export function useListProducts(
|
|
12
|
-
brandId?: string,
|
|
13
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['products']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
14
|
-
) {
|
|
15
|
-
const { baseURL, authToken } = useApiConfig();
|
|
16
|
-
|
|
17
|
-
return useQueryUnwrapped({
|
|
18
|
-
queryKey: queryKeys.admin.products.list(brandId),
|
|
19
|
-
queryFn: async () => {
|
|
20
|
-
const clients = createAdminRpcClients(baseURL);
|
|
21
|
-
const res = await clients.products.index.$get(
|
|
22
|
-
brandId ? { query: { brandId } } : {},
|
|
23
|
-
authHeaders(authToken)
|
|
24
|
-
);
|
|
25
|
-
if (!res.ok) throw new Error(`Failed to fetch products: ${res.statusText}`);
|
|
26
|
-
return res.json();
|
|
27
|
-
},
|
|
28
|
-
...options,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function useGetProduct(
|
|
33
|
-
productId: string,
|
|
34
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['products'][':id']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
35
|
-
) {
|
|
36
|
-
const { baseURL, authToken } = useApiConfig();
|
|
37
|
-
|
|
38
|
-
return useQueryUnwrapped({
|
|
39
|
-
queryKey: queryKeys.admin.products.detail(productId),
|
|
40
|
-
queryFn: async () => {
|
|
41
|
-
const clients = createAdminRpcClients(baseURL);
|
|
42
|
-
const res = await clients.products[':id'].$get(
|
|
43
|
-
{ param: { id: productId } },
|
|
44
|
-
authHeaders(authToken)
|
|
45
|
-
);
|
|
46
|
-
if (!res.ok) throw new Error(`Failed to fetch product: ${res.statusText}`);
|
|
47
|
-
return res.json();
|
|
48
|
-
},
|
|
49
|
-
...options,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function useCreateProduct(
|
|
54
|
-
options?: UseMutationOptions<any, Error, any>
|
|
55
|
-
) {
|
|
56
|
-
const { baseURL, authToken } = useApiConfig();
|
|
57
|
-
const queryClient = useQueryClient();
|
|
58
|
-
return useMutation({
|
|
59
|
-
mutationFn: async (data) => {
|
|
60
|
-
const clients = createAdminRpcClients(baseURL);
|
|
61
|
-
const res = await clients.products.index.$post(
|
|
62
|
-
{ json: data },
|
|
63
|
-
authHeaders(authToken)
|
|
64
|
-
);
|
|
65
|
-
if (!res.ok) throw new Error(`Failed to create product: ${res.statusText}`);
|
|
66
|
-
return res.json();
|
|
67
|
-
},
|
|
68
|
-
onSuccess: () => queryClient.invalidateQueries({ queryKey: queryKeys.admin.products.all }),
|
|
69
|
-
...options,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function useUpdateProduct(
|
|
74
|
-
productId: string,
|
|
75
|
-
options?: UseMutationOptions<any, Error, any>
|
|
76
|
-
) {
|
|
77
|
-
const { baseURL, authToken } = useApiConfig();
|
|
78
|
-
const queryClient = useQueryClient();
|
|
79
|
-
return useMutation({
|
|
80
|
-
mutationFn: async (data) => {
|
|
81
|
-
const clients = createAdminRpcClients(baseURL);
|
|
82
|
-
const res = await clients.products[':id'].$patch(
|
|
83
|
-
{ param: { id: productId }, json: data },
|
|
84
|
-
authHeaders(authToken)
|
|
85
|
-
);
|
|
86
|
-
if (!res.ok) throw new Error(`Failed to update product: ${res.statusText}`);
|
|
87
|
-
return res.json();
|
|
88
|
-
},
|
|
89
|
-
onSuccess: () => {
|
|
90
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.products.detail(productId) });
|
|
91
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.products.all });
|
|
92
|
-
},
|
|
93
|
-
...options,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function useDeleteProduct(
|
|
98
|
-
productId: string,
|
|
99
|
-
options?: UseMutationOptions<any, Error, void>
|
|
100
|
-
) {
|
|
101
|
-
const { baseURL, authToken } = useApiConfig();
|
|
102
|
-
const queryClient = useQueryClient();
|
|
103
|
-
return useMutation({
|
|
104
|
-
mutationFn: async () => {
|
|
105
|
-
const clients = createAdminRpcClients(baseURL);
|
|
106
|
-
const res = await clients.products[':id'].$delete(
|
|
107
|
-
{ param: { id: productId } },
|
|
108
|
-
authHeaders(authToken)
|
|
109
|
-
);
|
|
110
|
-
if (!res.ok) throw new Error(`Failed to delete product: ${res.statusText}`);
|
|
111
|
-
return res.json();
|
|
112
|
-
},
|
|
113
|
-
onSuccess: () => queryClient.invalidateQueries({ queryKey: queryKeys.admin.products.all }),
|
|
114
|
-
...options,
|
|
115
|
-
});
|
|
116
|
-
}
|
package/src/hooks/admin/stats.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe admin RPC hooks for statistics
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { UseQueryOptions } from '@tanstack/react-query';
|
|
6
|
-
import { useQueryUnwrapped } from '../use-query-unwrapped';
|
|
7
|
-
import { createAdminRpcClients, authHeaders } from '../../rpc-client';
|
|
8
|
-
import { queryKeys } from '../../utils/query-keys';
|
|
9
|
-
import { useApiConfig } from '../useApiConfig';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Hook to get dashboard statistics using admin RPC
|
|
13
|
-
*/
|
|
14
|
-
export function useGetStats(
|
|
15
|
-
params?: { brandId?: string },
|
|
16
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['stats']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
17
|
-
) {
|
|
18
|
-
const { baseURL, authToken } = useApiConfig();
|
|
19
|
-
|
|
20
|
-
return useQueryUnwrapped({
|
|
21
|
-
queryKey: queryKeys.admin.stats.overview(params?.brandId),
|
|
22
|
-
queryFn: async () => {
|
|
23
|
-
const clients = createAdminRpcClients(baseURL);
|
|
24
|
-
const res = await clients.stats.index.$get({ query: params as any }, authHeaders(authToken));
|
|
25
|
-
if (!res.ok) throw new Error(`Failed to fetch statistics: ${res.statusText}`);
|
|
26
|
-
return res.json();
|
|
27
|
-
},
|
|
28
|
-
...options,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe admin RPC hooks for variant management
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { useMutation, useQueryClient, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
6
|
-
import { useQueryUnwrapped } from '../use-query-unwrapped';
|
|
7
|
-
import { createAdminRpcClients, authHeaders } from '../../rpc-client';
|
|
8
|
-
import { queryKeys } from '../../utils/query-keys';
|
|
9
|
-
import { useApiConfig } from '../useApiConfig';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Hook to search variants across all products using admin RPC
|
|
13
|
-
*/
|
|
14
|
-
export function useSearchVariants(
|
|
15
|
-
params?: { brandId?: string; search?: string },
|
|
16
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['variants']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
17
|
-
) {
|
|
18
|
-
const { baseURL, authToken } = useApiConfig();
|
|
19
|
-
|
|
20
|
-
return useQueryUnwrapped({
|
|
21
|
-
queryKey: queryKeys.admin.variants.search(params),
|
|
22
|
-
queryFn: async () => {
|
|
23
|
-
const clients = createAdminRpcClients(baseURL);
|
|
24
|
-
const res = await clients.variants.index.$get({ query: params as any }, authHeaders(authToken));
|
|
25
|
-
if (!res.ok) throw new Error(`Failed to search variants: ${res.statusText}`);
|
|
26
|
-
return res.json();
|
|
27
|
-
},
|
|
28
|
-
...options,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Hook to list variants for a specific product using admin RPC
|
|
34
|
-
*/
|
|
35
|
-
export function useListProductVariants(
|
|
36
|
-
productId: string,
|
|
37
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['variants']['products'][':productId']['variants']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
38
|
-
) {
|
|
39
|
-
const { baseURL, authToken } = useApiConfig();
|
|
40
|
-
|
|
41
|
-
return useQueryUnwrapped({
|
|
42
|
-
queryKey: queryKeys.admin.variants.byProduct(productId),
|
|
43
|
-
queryFn: async () => {
|
|
44
|
-
const clients = createAdminRpcClients(baseURL);
|
|
45
|
-
const res = await clients.variants.products[':productId'].variants.$get(
|
|
46
|
-
{ param: { productId } },
|
|
47
|
-
authHeaders(authToken)
|
|
48
|
-
);
|
|
49
|
-
if (!res.ok) throw new Error(`Failed to fetch product variants: ${res.statusText}`);
|
|
50
|
-
return res.json();
|
|
51
|
-
},
|
|
52
|
-
...options,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Hook to create a variant for a product using admin RPC
|
|
58
|
-
*/
|
|
59
|
-
export function useCreateVariant(
|
|
60
|
-
productId: string,
|
|
61
|
-
options?: UseMutationOptions<
|
|
62
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['variants']['products'][':productId']['variants']['$post']>>['json']>>,
|
|
63
|
-
Error,
|
|
64
|
-
any
|
|
65
|
-
>
|
|
66
|
-
) {
|
|
67
|
-
const { baseURL, authToken } = useApiConfig();
|
|
68
|
-
const queryClient = useQueryClient();
|
|
69
|
-
|
|
70
|
-
return useMutation({
|
|
71
|
-
mutationFn: async (data) => {
|
|
72
|
-
const clients = createAdminRpcClients(baseURL);
|
|
73
|
-
const res = await clients.variants.products[':productId'].variants.$post(
|
|
74
|
-
{ json: data, param: { productId } },
|
|
75
|
-
authHeaders(authToken)
|
|
76
|
-
);
|
|
77
|
-
if (!res.ok) throw new Error(`Failed to create variant: ${res.statusText}`);
|
|
78
|
-
return res.json();
|
|
79
|
-
},
|
|
80
|
-
onSuccess: () => {
|
|
81
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.variants.all });
|
|
82
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.products.detail(productId) });
|
|
83
|
-
},
|
|
84
|
-
...options,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Hook to update a variant using admin RPC
|
|
90
|
-
*/
|
|
91
|
-
export function useUpdateVariant(
|
|
92
|
-
variantId: string,
|
|
93
|
-
options?: UseMutationOptions<
|
|
94
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['variants'][':id']['$patch']>>['json']>>,
|
|
95
|
-
Error,
|
|
96
|
-
any
|
|
97
|
-
>
|
|
98
|
-
) {
|
|
99
|
-
const { baseURL, authToken } = useApiConfig();
|
|
100
|
-
const queryClient = useQueryClient();
|
|
101
|
-
|
|
102
|
-
return useMutation({
|
|
103
|
-
mutationFn: async (data) => {
|
|
104
|
-
const clients = createAdminRpcClients(baseURL);
|
|
105
|
-
const res = await clients.variants[':id'].$patch(
|
|
106
|
-
{ json: data, param: { id: variantId } },
|
|
107
|
-
authHeaders(authToken)
|
|
108
|
-
);
|
|
109
|
-
if (!res.ok) throw new Error(`Failed to update variant: ${res.statusText}`);
|
|
110
|
-
return res.json();
|
|
111
|
-
},
|
|
112
|
-
onSuccess: () => {
|
|
113
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.variants.detail(variantId) });
|
|
114
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.variants.all });
|
|
115
|
-
},
|
|
116
|
-
...options,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Hook to get variant inventory across all warehouses using admin RPC
|
|
122
|
-
*/
|
|
123
|
-
export function useGetVariantInventory(
|
|
124
|
-
variantId: string,
|
|
125
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['variants'][':id']['inventory']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
126
|
-
) {
|
|
127
|
-
const { baseURL, authToken } = useApiConfig();
|
|
128
|
-
|
|
129
|
-
return useQueryUnwrapped({
|
|
130
|
-
queryKey: queryKeys.admin.variants.inventory(variantId),
|
|
131
|
-
queryFn: async () => {
|
|
132
|
-
const clients = createAdminRpcClients(baseURL);
|
|
133
|
-
const res = await clients.variants[':id'].inventory.$get(
|
|
134
|
-
{ param: { id: variantId } },
|
|
135
|
-
authHeaders(authToken)
|
|
136
|
-
);
|
|
137
|
-
if (!res.ok) throw new Error(`Failed to fetch variant inventory: ${res.statusText}`);
|
|
138
|
-
return res.json();
|
|
139
|
-
},
|
|
140
|
-
...options,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Hook to delete a variant using admin RPC
|
|
146
|
-
*/
|
|
147
|
-
export function useDeleteVariant(
|
|
148
|
-
variantId: string,
|
|
149
|
-
options?: UseMutationOptions<
|
|
150
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['variants'][':id']['$delete']>>['json']>>,
|
|
151
|
-
Error,
|
|
152
|
-
void
|
|
153
|
-
>
|
|
154
|
-
) {
|
|
155
|
-
const { baseURL, authToken } = useApiConfig();
|
|
156
|
-
const queryClient = useQueryClient();
|
|
157
|
-
|
|
158
|
-
return useMutation({
|
|
159
|
-
mutationFn: async () => {
|
|
160
|
-
const clients = createAdminRpcClients(baseURL);
|
|
161
|
-
const res = await clients.variants[':id'].$delete(
|
|
162
|
-
{ param: { id: variantId } },
|
|
163
|
-
authHeaders(authToken)
|
|
164
|
-
);
|
|
165
|
-
if (!res.ok) throw new Error(`Failed to delete variant: ${res.statusText}`);
|
|
166
|
-
return res.json();
|
|
167
|
-
},
|
|
168
|
-
onSuccess: () => {
|
|
169
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.variants.all });
|
|
170
|
-
},
|
|
171
|
-
...options,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe admin RPC hooks for warehouse management
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { useMutation, useQueryClient, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
6
|
-
import { useQueryUnwrapped } from '../use-query-unwrapped';
|
|
7
|
-
import { createAdminRpcClients, authHeaders } from '../../rpc-client';
|
|
8
|
-
import { queryKeys } from '../../utils/query-keys';
|
|
9
|
-
import { useApiConfig } from '../useApiConfig';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Hook to list all warehouses using admin RPC
|
|
13
|
-
*/
|
|
14
|
-
export function useListWarehouses(
|
|
15
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['warehouses']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
16
|
-
) {
|
|
17
|
-
const { baseURL, authToken } = useApiConfig();
|
|
18
|
-
|
|
19
|
-
return useQueryUnwrapped({
|
|
20
|
-
queryKey: queryKeys.admin.warehouses.list(),
|
|
21
|
-
queryFn: async () => {
|
|
22
|
-
const clients = createAdminRpcClients(baseURL);
|
|
23
|
-
const res = await clients.warehouses.index.$get({}, authHeaders(authToken));
|
|
24
|
-
if (!res.ok) throw new Error(`Failed to fetch warehouses: ${res.statusText}`);
|
|
25
|
-
return res.json();
|
|
26
|
-
},
|
|
27
|
-
...options,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Hook to create a warehouse using admin RPC
|
|
33
|
-
*/
|
|
34
|
-
export function useCreateWarehouse(
|
|
35
|
-
options?: UseMutationOptions<
|
|
36
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['warehouses']['index']['$post']>>['json']>>,
|
|
37
|
-
Error,
|
|
38
|
-
any
|
|
39
|
-
>
|
|
40
|
-
) {
|
|
41
|
-
const { baseURL, authToken } = useApiConfig();
|
|
42
|
-
const queryClient = useQueryClient();
|
|
43
|
-
|
|
44
|
-
return useMutation({
|
|
45
|
-
mutationFn: async (data) => {
|
|
46
|
-
const clients = createAdminRpcClients(baseURL);
|
|
47
|
-
const res = await clients.warehouses.index.$post({ json: data }, authHeaders(authToken));
|
|
48
|
-
if (!res.ok) throw new Error(`Failed to create warehouse: ${res.statusText}`);
|
|
49
|
-
return res.json();
|
|
50
|
-
},
|
|
51
|
-
onSuccess: () => {
|
|
52
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.warehouses.all });
|
|
53
|
-
},
|
|
54
|
-
...options,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Hook to update a warehouse using admin RPC
|
|
60
|
-
*/
|
|
61
|
-
export function useUpdateWarehouse(
|
|
62
|
-
warehouseId: string,
|
|
63
|
-
options?: UseMutationOptions<
|
|
64
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['warehouses'][':id']['$patch']>>['json']>>,
|
|
65
|
-
Error,
|
|
66
|
-
any
|
|
67
|
-
>
|
|
68
|
-
) {
|
|
69
|
-
const { baseURL, authToken } = useApiConfig();
|
|
70
|
-
const queryClient = useQueryClient();
|
|
71
|
-
|
|
72
|
-
return useMutation({
|
|
73
|
-
mutationFn: async (data) => {
|
|
74
|
-
const clients = createAdminRpcClients(baseURL);
|
|
75
|
-
const res = await clients.warehouses[':id'].$patch(
|
|
76
|
-
{ json: data, param: { id: warehouseId } },
|
|
77
|
-
authHeaders(authToken)
|
|
78
|
-
);
|
|
79
|
-
if (!res.ok) throw new Error(`Failed to update warehouse: ${res.statusText}`);
|
|
80
|
-
return res.json();
|
|
81
|
-
},
|
|
82
|
-
onSuccess: () => {
|
|
83
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.warehouses.detail(warehouseId) });
|
|
84
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.warehouses.all });
|
|
85
|
-
},
|
|
86
|
-
...options,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Hook to get warehouse inventory using admin RPC
|
|
92
|
-
*/
|
|
93
|
-
export function useGetWarehouseInventory(
|
|
94
|
-
warehouseId: string,
|
|
95
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['warehouses'][':id']['inventory']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
96
|
-
) {
|
|
97
|
-
const { baseURL, authToken } = useApiConfig();
|
|
98
|
-
|
|
99
|
-
return useQueryUnwrapped({
|
|
100
|
-
queryKey: queryKeys.admin.warehouses.inventory(warehouseId),
|
|
101
|
-
queryFn: async () => {
|
|
102
|
-
const clients = createAdminRpcClients(baseURL);
|
|
103
|
-
const res = await clients.warehouses[':id'].inventory.$get(
|
|
104
|
-
{ param: { id: warehouseId } },
|
|
105
|
-
authHeaders(authToken)
|
|
106
|
-
);
|
|
107
|
-
if (!res.ok) throw new Error(`Failed to fetch warehouse inventory: ${res.statusText}`);
|
|
108
|
-
return res.json();
|
|
109
|
-
},
|
|
110
|
-
...options,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Hook to delete a warehouse using admin RPC
|
|
116
|
-
*/
|
|
117
|
-
export function useDeleteWarehouse(
|
|
118
|
-
warehouseId: string,
|
|
119
|
-
options?: UseMutationOptions<
|
|
120
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['warehouses'][':id']['$delete']>>['json']>>,
|
|
121
|
-
Error,
|
|
122
|
-
void
|
|
123
|
-
>
|
|
124
|
-
) {
|
|
125
|
-
const { baseURL, authToken } = useApiConfig();
|
|
126
|
-
const queryClient = useQueryClient();
|
|
127
|
-
|
|
128
|
-
return useMutation({
|
|
129
|
-
mutationFn: async () => {
|
|
130
|
-
const clients = createAdminRpcClients(baseURL);
|
|
131
|
-
const res = await clients.warehouses[':id'].$delete(
|
|
132
|
-
{ param: { id: warehouseId } },
|
|
133
|
-
authHeaders(authToken)
|
|
134
|
-
);
|
|
135
|
-
if (!res.ok) throw new Error(`Failed to delete warehouse: ${res.statusText}`);
|
|
136
|
-
return res.json();
|
|
137
|
-
},
|
|
138
|
-
onSuccess: () => {
|
|
139
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.warehouses.all });
|
|
140
|
-
},
|
|
141
|
-
...options,
|
|
142
|
-
});
|
|
143
|
-
}
|