@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,236 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe admin RPC hooks for delivery zone and state 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
|
-
// ============ STATES ============
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Hook to list all states using admin RPC
|
|
15
|
-
*/
|
|
16
|
-
export function useListStates(
|
|
17
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['deliveryZones']['states']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
18
|
-
) {
|
|
19
|
-
const { baseURL, authToken } = useApiConfig();
|
|
20
|
-
|
|
21
|
-
return useQueryUnwrapped({
|
|
22
|
-
queryKey: queryKeys.admin.deliveryZones.states.list(),
|
|
23
|
-
queryFn: async () => {
|
|
24
|
-
const clients = createAdminRpcClients(baseURL);
|
|
25
|
-
const res = await clients.deliveryZones.states.$get({}, authHeaders(authToken));
|
|
26
|
-
if (!res.ok) throw new Error(`Failed to fetch states: ${res.statusText}`);
|
|
27
|
-
return res.json();
|
|
28
|
-
},
|
|
29
|
-
...options,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Hook to create a state using admin RPC
|
|
35
|
-
*/
|
|
36
|
-
export function useCreateState(
|
|
37
|
-
options?: UseMutationOptions<
|
|
38
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['deliveryZones']['states']['$post']>>['json']>>,
|
|
39
|
-
Error,
|
|
40
|
-
any
|
|
41
|
-
>
|
|
42
|
-
) {
|
|
43
|
-
const { baseURL, authToken } = useApiConfig();
|
|
44
|
-
const queryClient = useQueryClient();
|
|
45
|
-
|
|
46
|
-
return useMutation({
|
|
47
|
-
mutationFn: async (data) => {
|
|
48
|
-
const clients = createAdminRpcClients(baseURL);
|
|
49
|
-
const res = await clients.deliveryZones.states.$post({ json: data }, authHeaders(authToken));
|
|
50
|
-
if (!res.ok) throw new Error(`Failed to create state: ${res.statusText}`);
|
|
51
|
-
return res.json();
|
|
52
|
-
},
|
|
53
|
-
onSuccess: () => {
|
|
54
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.states.all });
|
|
55
|
-
},
|
|
56
|
-
...options,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Hook to update a state using admin RPC
|
|
62
|
-
*/
|
|
63
|
-
export function useUpdateState(
|
|
64
|
-
stateId: string,
|
|
65
|
-
options?: UseMutationOptions<
|
|
66
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['deliveryZones']['states'][':id']['$patch']>>['json']>>,
|
|
67
|
-
Error,
|
|
68
|
-
any
|
|
69
|
-
>
|
|
70
|
-
) {
|
|
71
|
-
const { baseURL, authToken } = useApiConfig();
|
|
72
|
-
const queryClient = useQueryClient();
|
|
73
|
-
|
|
74
|
-
return useMutation({
|
|
75
|
-
mutationFn: async (data) => {
|
|
76
|
-
const clients = createAdminRpcClients(baseURL);
|
|
77
|
-
const res = await clients.deliveryZones.states[':id'].$patch(
|
|
78
|
-
{ json: data, param: { id: stateId } },
|
|
79
|
-
authHeaders(authToken)
|
|
80
|
-
);
|
|
81
|
-
if (!res.ok) throw new Error(`Failed to update state: ${res.statusText}`);
|
|
82
|
-
return res.json();
|
|
83
|
-
},
|
|
84
|
-
onSuccess: () => {
|
|
85
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.states.detail(stateId) });
|
|
86
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.states.all });
|
|
87
|
-
},
|
|
88
|
-
...options,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Hook to delete a state using admin RPC
|
|
94
|
-
*/
|
|
95
|
-
export function useDeleteState(
|
|
96
|
-
stateId: string,
|
|
97
|
-
options?: UseMutationOptions<
|
|
98
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['deliveryZones']['states'][':id']['$delete']>>['json']>>,
|
|
99
|
-
Error,
|
|
100
|
-
void
|
|
101
|
-
>
|
|
102
|
-
) {
|
|
103
|
-
const { baseURL, authToken } = useApiConfig();
|
|
104
|
-
const queryClient = useQueryClient();
|
|
105
|
-
|
|
106
|
-
return useMutation({
|
|
107
|
-
mutationFn: async () => {
|
|
108
|
-
const clients = createAdminRpcClients(baseURL);
|
|
109
|
-
const res = await clients.deliveryZones.states[':id'].$delete(
|
|
110
|
-
{ param: { id: stateId } },
|
|
111
|
-
authHeaders(authToken)
|
|
112
|
-
);
|
|
113
|
-
if (!res.ok) throw new Error(`Failed to delete state: ${res.statusText}`);
|
|
114
|
-
return res.json();
|
|
115
|
-
},
|
|
116
|
-
onSuccess: () => {
|
|
117
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.states.all });
|
|
118
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.zones.all });
|
|
119
|
-
},
|
|
120
|
-
...options,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// ============ DELIVERY ZONES ============
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Hook to list delivery zones using admin RPC
|
|
128
|
-
*/
|
|
129
|
-
export function useListDeliveryZones(
|
|
130
|
-
params?: { stateId?: string; brandId?: string },
|
|
131
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['deliveryZones']['zones']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
132
|
-
) {
|
|
133
|
-
const { baseURL, authToken } = useApiConfig();
|
|
134
|
-
|
|
135
|
-
return useQueryUnwrapped({
|
|
136
|
-
queryKey: queryKeys.admin.deliveryZones.zones.list(params),
|
|
137
|
-
queryFn: async () => {
|
|
138
|
-
const clients = createAdminRpcClients(baseURL);
|
|
139
|
-
const res = await clients.deliveryZones.zones.$get({ query: params as any }, authHeaders(authToken));
|
|
140
|
-
if (!res.ok) throw new Error(`Failed to fetch delivery zones: ${res.statusText}`);
|
|
141
|
-
return res.json();
|
|
142
|
-
},
|
|
143
|
-
...options,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Hook to create a delivery zone using admin RPC
|
|
149
|
-
*/
|
|
150
|
-
export function useCreateDeliveryZone(
|
|
151
|
-
options?: UseMutationOptions<
|
|
152
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['deliveryZones']['zones']['$post']>>['json']>>,
|
|
153
|
-
Error,
|
|
154
|
-
any
|
|
155
|
-
>
|
|
156
|
-
) {
|
|
157
|
-
const { baseURL, authToken } = useApiConfig();
|
|
158
|
-
const queryClient = useQueryClient();
|
|
159
|
-
|
|
160
|
-
return useMutation({
|
|
161
|
-
mutationFn: async (data) => {
|
|
162
|
-
const clients = createAdminRpcClients(baseURL);
|
|
163
|
-
const res = await clients.deliveryZones.zones.$post({ json: data }, authHeaders(authToken));
|
|
164
|
-
if (!res.ok) throw new Error(`Failed to create delivery zone: ${res.statusText}`);
|
|
165
|
-
return res.json();
|
|
166
|
-
},
|
|
167
|
-
onSuccess: () => {
|
|
168
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.zones.all });
|
|
169
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.states.all });
|
|
170
|
-
},
|
|
171
|
-
...options,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Hook to update a delivery zone using admin RPC
|
|
177
|
-
*/
|
|
178
|
-
export function useUpdateDeliveryZone(
|
|
179
|
-
zoneId: string,
|
|
180
|
-
options?: UseMutationOptions<
|
|
181
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['deliveryZones']['zones'][':id']['$patch']>>['json']>>,
|
|
182
|
-
Error,
|
|
183
|
-
any
|
|
184
|
-
>
|
|
185
|
-
) {
|
|
186
|
-
const { baseURL, authToken } = useApiConfig();
|
|
187
|
-
const queryClient = useQueryClient();
|
|
188
|
-
|
|
189
|
-
return useMutation({
|
|
190
|
-
mutationFn: async (data) => {
|
|
191
|
-
const clients = createAdminRpcClients(baseURL);
|
|
192
|
-
const res = await clients.deliveryZones.zones[':id'].$patch(
|
|
193
|
-
{ json: data, param: { id: zoneId } },
|
|
194
|
-
authHeaders(authToken)
|
|
195
|
-
);
|
|
196
|
-
if (!res.ok) throw new Error(`Failed to update delivery zone: ${res.statusText}`);
|
|
197
|
-
return res.json();
|
|
198
|
-
},
|
|
199
|
-
onSuccess: () => {
|
|
200
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.zones.detail(zoneId) });
|
|
201
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.zones.all });
|
|
202
|
-
},
|
|
203
|
-
...options,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Hook to delete a delivery zone using admin RPC
|
|
209
|
-
*/
|
|
210
|
-
export function useDeleteDeliveryZone(
|
|
211
|
-
zoneId: string,
|
|
212
|
-
options?: UseMutationOptions<
|
|
213
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['deliveryZones']['zones'][':id']['$delete']>>['json']>>,
|
|
214
|
-
Error,
|
|
215
|
-
void
|
|
216
|
-
>
|
|
217
|
-
) {
|
|
218
|
-
const { baseURL, authToken } = useApiConfig();
|
|
219
|
-
const queryClient = useQueryClient();
|
|
220
|
-
|
|
221
|
-
return useMutation({
|
|
222
|
-
mutationFn: async () => {
|
|
223
|
-
const clients = createAdminRpcClients(baseURL);
|
|
224
|
-
const res = await clients.deliveryZones.zones[':id'].$delete(
|
|
225
|
-
{ param: { id: zoneId } },
|
|
226
|
-
authHeaders(authToken)
|
|
227
|
-
);
|
|
228
|
-
if (!res.ok) throw new Error(`Failed to delete delivery zone: ${res.statusText}`);
|
|
229
|
-
return res.json();
|
|
230
|
-
},
|
|
231
|
-
onSuccess: () => {
|
|
232
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.zones.all });
|
|
233
|
-
},
|
|
234
|
-
...options,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe admin RPC hooks for discount code 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 discount codes using admin RPC
|
|
13
|
-
*/
|
|
14
|
-
export function useListDiscountCodes(
|
|
15
|
-
params?: {
|
|
16
|
-
page?: number;
|
|
17
|
-
limit?: number;
|
|
18
|
-
category?: string;
|
|
19
|
-
brandId?: string;
|
|
20
|
-
isActive?: string;
|
|
21
|
-
search?: string;
|
|
22
|
-
},
|
|
23
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
24
|
-
) {
|
|
25
|
-
const { baseURL, authToken } = useApiConfig();
|
|
26
|
-
|
|
27
|
-
return useQueryUnwrapped({
|
|
28
|
-
queryKey: queryKeys.admin.discountCodes.list(params),
|
|
29
|
-
queryFn: async () => {
|
|
30
|
-
const clients = createAdminRpcClients(baseURL);
|
|
31
|
-
const res = await clients.discountCodes.index.$get({ query: params as any }, authHeaders(authToken));
|
|
32
|
-
if (!res.ok) throw new Error(`Failed to fetch discount codes: ${res.statusText}`);
|
|
33
|
-
return res.json();
|
|
34
|
-
},
|
|
35
|
-
...options,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Hook to get discount code by ID using admin RPC
|
|
41
|
-
*/
|
|
42
|
-
export function useGetDiscountCode(
|
|
43
|
-
codeId: string,
|
|
44
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes'][':id']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
45
|
-
) {
|
|
46
|
-
const { baseURL, authToken } = useApiConfig();
|
|
47
|
-
|
|
48
|
-
return useQueryUnwrapped({
|
|
49
|
-
queryKey: queryKeys.admin.discountCodes.detail(codeId),
|
|
50
|
-
queryFn: async () => {
|
|
51
|
-
const clients = createAdminRpcClients(baseURL);
|
|
52
|
-
const res = await clients.discountCodes[':id'].$get(
|
|
53
|
-
{ param: { id: codeId } },
|
|
54
|
-
authHeaders(authToken)
|
|
55
|
-
);
|
|
56
|
-
if (!res.ok) throw new Error(`Failed to fetch discount code: ${res.statusText}`);
|
|
57
|
-
return res.json();
|
|
58
|
-
},
|
|
59
|
-
...options,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Hook to create a discount code using admin RPC
|
|
65
|
-
*/
|
|
66
|
-
export function useCreateDiscountCode(
|
|
67
|
-
options?: UseMutationOptions<
|
|
68
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes']['index']['$post']>>['json']>>,
|
|
69
|
-
Error,
|
|
70
|
-
any
|
|
71
|
-
>
|
|
72
|
-
) {
|
|
73
|
-
const { baseURL, authToken } = useApiConfig();
|
|
74
|
-
const queryClient = useQueryClient();
|
|
75
|
-
|
|
76
|
-
return useMutation({
|
|
77
|
-
mutationFn: async (data) => {
|
|
78
|
-
const clients = createAdminRpcClients(baseURL);
|
|
79
|
-
const res = await clients.discountCodes.index.$post({ json: data }, authHeaders(authToken));
|
|
80
|
-
if (!res.ok) throw new Error(`Failed to create discount code: ${res.statusText}`);
|
|
81
|
-
return res.json();
|
|
82
|
-
},
|
|
83
|
-
onSuccess: () => {
|
|
84
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.discountCodes.all });
|
|
85
|
-
},
|
|
86
|
-
...options,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Hook to update a discount code using admin RPC
|
|
92
|
-
*/
|
|
93
|
-
export function useUpdateDiscountCode(
|
|
94
|
-
codeId: string,
|
|
95
|
-
options?: UseMutationOptions<
|
|
96
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes'][':id']['$patch']>>['json']>>,
|
|
97
|
-
Error,
|
|
98
|
-
any
|
|
99
|
-
>
|
|
100
|
-
) {
|
|
101
|
-
const { baseURL, authToken } = useApiConfig();
|
|
102
|
-
const queryClient = useQueryClient();
|
|
103
|
-
|
|
104
|
-
return useMutation({
|
|
105
|
-
mutationFn: async (data) => {
|
|
106
|
-
const clients = createAdminRpcClients(baseURL);
|
|
107
|
-
const res = await clients.discountCodes[':id'].$patch(
|
|
108
|
-
{ json: data, param: { id: codeId } },
|
|
109
|
-
authHeaders(authToken)
|
|
110
|
-
);
|
|
111
|
-
if (!res.ok) throw new Error(`Failed to update discount code: ${res.statusText}`);
|
|
112
|
-
return res.json();
|
|
113
|
-
},
|
|
114
|
-
onSuccess: () => {
|
|
115
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.discountCodes.detail(codeId) });
|
|
116
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.discountCodes.all });
|
|
117
|
-
},
|
|
118
|
-
...options,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Hook to delete a discount code using admin RPC
|
|
124
|
-
*/
|
|
125
|
-
export function useDeleteDiscountCode(
|
|
126
|
-
codeId: string,
|
|
127
|
-
options?: UseMutationOptions<
|
|
128
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes'][':id']['$delete']>>['json']>>,
|
|
129
|
-
Error,
|
|
130
|
-
void
|
|
131
|
-
>
|
|
132
|
-
) {
|
|
133
|
-
const { baseURL, authToken } = useApiConfig();
|
|
134
|
-
const queryClient = useQueryClient();
|
|
135
|
-
|
|
136
|
-
return useMutation({
|
|
137
|
-
mutationFn: async () => {
|
|
138
|
-
const clients = createAdminRpcClients(baseURL);
|
|
139
|
-
const res = await clients.discountCodes[':id'].$delete(
|
|
140
|
-
{ param: { id: codeId } },
|
|
141
|
-
authHeaders(authToken)
|
|
142
|
-
);
|
|
143
|
-
if (!res.ok) throw new Error(`Failed to delete discount code: ${res.statusText}`);
|
|
144
|
-
return res.json();
|
|
145
|
-
},
|
|
146
|
-
onSuccess: () => {
|
|
147
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.discountCodes.all });
|
|
148
|
-
},
|
|
149
|
-
...options,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Hook to get discount code analytics using admin RPC
|
|
155
|
-
*/
|
|
156
|
-
export function useGetDiscountCodeAnalytics(
|
|
157
|
-
codeId: string,
|
|
158
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes'][':id']['analytics']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
159
|
-
) {
|
|
160
|
-
const { baseURL, authToken } = useApiConfig();
|
|
161
|
-
|
|
162
|
-
return useQueryUnwrapped({
|
|
163
|
-
queryKey: queryKeys.admin.discountCodes.analytics(codeId),
|
|
164
|
-
queryFn: async () => {
|
|
165
|
-
const clients = createAdminRpcClients(baseURL);
|
|
166
|
-
const res = await clients.discountCodes[':id'].analytics.$get(
|
|
167
|
-
{ param: { id: codeId } },
|
|
168
|
-
authHeaders(authToken)
|
|
169
|
-
);
|
|
170
|
-
if (!res.ok) throw new Error(`Failed to fetch discount code analytics: ${res.statusText}`);
|
|
171
|
-
return res.json();
|
|
172
|
-
},
|
|
173
|
-
...options,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Hook to bulk generate discount codes using admin RPC
|
|
179
|
-
*/
|
|
180
|
-
export function useBulkGenerateDiscountCodes(
|
|
181
|
-
options?: UseMutationOptions<
|
|
182
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes']['bulk-generate']['$post']>>['json']>>,
|
|
183
|
-
Error,
|
|
184
|
-
any
|
|
185
|
-
>
|
|
186
|
-
) {
|
|
187
|
-
const { baseURL, authToken } = useApiConfig();
|
|
188
|
-
const queryClient = useQueryClient();
|
|
189
|
-
|
|
190
|
-
return useMutation({
|
|
191
|
-
mutationFn: async (data) => {
|
|
192
|
-
const clients = createAdminRpcClients(baseURL);
|
|
193
|
-
const res = await clients.discountCodes['bulk-generate'].$post({ json: data }, authHeaders(authToken));
|
|
194
|
-
if (!res.ok) throw new Error(`Failed to bulk generate discount codes: ${res.statusText}`);
|
|
195
|
-
return res.json();
|
|
196
|
-
},
|
|
197
|
-
onSuccess: () => {
|
|
198
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.discountCodes.all });
|
|
199
|
-
},
|
|
200
|
-
...options,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Hook to get discount code overview stats using admin RPC
|
|
206
|
-
*/
|
|
207
|
-
export function useGetDiscountCodeOverviewStats(
|
|
208
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes']['stats']['overview']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
209
|
-
) {
|
|
210
|
-
const { baseURL, authToken } = useApiConfig();
|
|
211
|
-
|
|
212
|
-
return useQueryUnwrapped({
|
|
213
|
-
queryKey: queryKeys.admin.discountCodes.overviewStats(),
|
|
214
|
-
queryFn: async () => {
|
|
215
|
-
const clients = createAdminRpcClients(baseURL);
|
|
216
|
-
const res = await clients.discountCodes.stats.overview.$get({}, authHeaders(authToken));
|
|
217
|
-
if (!res.ok) throw new Error(`Failed to fetch discount code overview stats: ${res.statusText}`);
|
|
218
|
-
return res.json();
|
|
219
|
-
},
|
|
220
|
-
...options,
|
|
221
|
-
});
|
|
222
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe admin RPC hooks for inventory 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 get inventory overview using admin RPC
|
|
13
|
-
*/
|
|
14
|
-
export function useListInventory(
|
|
15
|
-
params?: { brandId?: string; warehouseId?: string; productId?: string },
|
|
16
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['inventory']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
17
|
-
) {
|
|
18
|
-
const { baseURL, authToken } = useApiConfig();
|
|
19
|
-
|
|
20
|
-
return useQueryUnwrapped({
|
|
21
|
-
queryKey: queryKeys.admin.inventory.list(params),
|
|
22
|
-
queryFn: async () => {
|
|
23
|
-
const clients = createAdminRpcClients(baseURL);
|
|
24
|
-
const res = await clients.inventory.index.$get({ query: params as any }, authHeaders(authToken));
|
|
25
|
-
if (!res.ok) throw new Error(`Failed to fetch inventory: ${res.statusText}`);
|
|
26
|
-
return res.json();
|
|
27
|
-
},
|
|
28
|
-
...options,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Hook to adjust inventory using admin RPC
|
|
34
|
-
*/
|
|
35
|
-
export function useAdjustInventory(
|
|
36
|
-
options?: UseMutationOptions<
|
|
37
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['inventory']['adjust']['$post']>>['json']>>,
|
|
38
|
-
Error,
|
|
39
|
-
any
|
|
40
|
-
>
|
|
41
|
-
) {
|
|
42
|
-
const { baseURL, authToken } = useApiConfig();
|
|
43
|
-
const queryClient = useQueryClient();
|
|
44
|
-
|
|
45
|
-
return useMutation({
|
|
46
|
-
mutationFn: async (data) => {
|
|
47
|
-
const clients = createAdminRpcClients(baseURL);
|
|
48
|
-
const res = await clients.inventory.adjust.$post({ json: data }, authHeaders(authToken));
|
|
49
|
-
if (!res.ok) throw new Error(`Failed to adjust inventory: ${res.statusText}`);
|
|
50
|
-
return res.json();
|
|
51
|
-
},
|
|
52
|
-
onSuccess: () => {
|
|
53
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.inventory.all });
|
|
54
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.variants.all });
|
|
55
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.warehouses.all });
|
|
56
|
-
},
|
|
57
|
-
...options,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Hook to transfer inventory between warehouses using admin RPC
|
|
63
|
-
*/
|
|
64
|
-
export function useTransferInventory(
|
|
65
|
-
options?: UseMutationOptions<
|
|
66
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['inventory']['transfer']['$post']>>['json']>>,
|
|
67
|
-
Error,
|
|
68
|
-
any
|
|
69
|
-
>
|
|
70
|
-
) {
|
|
71
|
-
const { baseURL, authToken } = useApiConfig();
|
|
72
|
-
const queryClient = useQueryClient();
|
|
73
|
-
|
|
74
|
-
return useMutation({
|
|
75
|
-
mutationFn: async (data) => {
|
|
76
|
-
const clients = createAdminRpcClients(baseURL);
|
|
77
|
-
const res = await clients.inventory.transfer.$post({ json: data }, authHeaders(authToken));
|
|
78
|
-
if (!res.ok) throw new Error(`Failed to transfer inventory: ${res.statusText}`);
|
|
79
|
-
return res.json();
|
|
80
|
-
},
|
|
81
|
-
onSuccess: () => {
|
|
82
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.inventory.all });
|
|
83
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.warehouses.all });
|
|
84
|
-
},
|
|
85
|
-
...options,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Hook to get inventory transaction history using admin RPC
|
|
91
|
-
*/
|
|
92
|
-
export function useGetInventoryTransactions(
|
|
93
|
-
params?: {
|
|
94
|
-
variantId?: string;
|
|
95
|
-
warehouseId?: string;
|
|
96
|
-
type?: string;
|
|
97
|
-
startDate?: string;
|
|
98
|
-
endDate?: string;
|
|
99
|
-
page?: number;
|
|
100
|
-
limit?: number;
|
|
101
|
-
},
|
|
102
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['inventory']['transactions']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
103
|
-
) {
|
|
104
|
-
const { baseURL, authToken } = useApiConfig();
|
|
105
|
-
|
|
106
|
-
return useQueryUnwrapped({
|
|
107
|
-
queryKey: queryKeys.admin.inventory.transactions(params),
|
|
108
|
-
queryFn: async () => {
|
|
109
|
-
const clients = createAdminRpcClients(baseURL);
|
|
110
|
-
const res = await clients.inventory.transactions.$get({ query: params as any }, authHeaders(authToken));
|
|
111
|
-
if (!res.ok) throw new Error(`Failed to fetch inventory transactions: ${res.statusText}`);
|
|
112
|
-
return res.json();
|
|
113
|
-
},
|
|
114
|
-
...options,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Hook to get low stock alerts using admin RPC
|
|
120
|
-
*/
|
|
121
|
-
export function useGetLowStockVariants(
|
|
122
|
-
params?: { brandId?: string },
|
|
123
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['inventory']['low-stock']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
124
|
-
) {
|
|
125
|
-
const { baseURL, authToken } = useApiConfig();
|
|
126
|
-
|
|
127
|
-
return useQueryUnwrapped({
|
|
128
|
-
queryKey: queryKeys.admin.inventory.lowStock(params?.brandId),
|
|
129
|
-
queryFn: async () => {
|
|
130
|
-
const clients = createAdminRpcClients(baseURL);
|
|
131
|
-
const res = await clients.inventory['low-stock'].$get({ query: params as any }, authHeaders(authToken));
|
|
132
|
-
if (!res.ok) throw new Error(`Failed to fetch low stock alerts: ${res.statusText}`);
|
|
133
|
-
return res.json();
|
|
134
|
-
},
|
|
135
|
-
...options,
|
|
136
|
-
});
|
|
137
|
-
}
|