@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.
Files changed (90) hide show
  1. package/dist/backend-types.d.ts +10 -0
  2. package/dist/backend-types.js +10 -0
  3. package/dist/client.d.ts +20 -0
  4. package/dist/client.js +40 -0
  5. package/dist/fetchers/brands.d.ts +25 -0
  6. package/dist/fetchers/brands.js +26 -0
  7. package/dist/fetchers/carts.d.ts +2339 -0
  8. package/dist/fetchers/carts.js +167 -0
  9. package/dist/fetchers/delivery-zones.d.ts +28 -0
  10. package/{src/fetchers/delivery-zones.ts → dist/fetchers/delivery-zones.js} +9 -12
  11. package/{src/fetchers/index.ts → dist/fetchers/index.d.ts} +1 -1
  12. package/dist/fetchers/index.js +22 -0
  13. package/dist/fetchers/orders.d.ts +283 -0
  14. package/dist/fetchers/orders.js +44 -0
  15. package/dist/fetchers/products.d.ts +386 -0
  16. package/dist/fetchers/products.js +42 -0
  17. package/dist/hooks/admin/abandoned-carts.d.ts +535 -0
  18. package/dist/hooks/admin/abandoned-carts.js +79 -0
  19. package/dist/hooks/admin/brands.d.ts +79 -0
  20. package/dist/hooks/admin/brands.js +103 -0
  21. package/dist/hooks/admin/customers.d.ts +278 -0
  22. package/dist/hooks/admin/customers.js +25 -0
  23. package/dist/hooks/admin/delivery-zones.d.ts +270 -0
  24. package/dist/hooks/admin/delivery-zones.js +168 -0
  25. package/dist/hooks/admin/discount-codes.d.ts +299 -0
  26. package/dist/hooks/admin/discount-codes.js +157 -0
  27. package/{src/hooks/admin/index.ts → dist/hooks/admin/index.d.ts} +0 -1
  28. package/dist/hooks/admin/index.js +16 -0
  29. package/dist/hooks/admin/inventory.d.ts +224 -0
  30. package/dist/hooks/admin/inventory.js +102 -0
  31. package/dist/hooks/admin/orders.d.ts +1380 -0
  32. package/dist/hooks/admin/orders.js +169 -0
  33. package/dist/hooks/admin/products.d.ts +374 -0
  34. package/dist/hooks/admin/products.js +84 -0
  35. package/dist/hooks/admin/stats.d.ts +277 -0
  36. package/dist/hooks/admin/stats.js +24 -0
  37. package/dist/hooks/admin/variants.d.ts +115 -0
  38. package/dist/hooks/admin/variants.js +121 -0
  39. package/dist/hooks/admin/warehouses.d.ts +277 -0
  40. package/dist/hooks/admin/warehouses.js +103 -0
  41. package/dist/hooks/public/brands.d.ts +33 -0
  42. package/dist/hooks/public/brands.js +30 -0
  43. package/dist/hooks/public/carts.d.ts +2407 -0
  44. package/dist/hooks/public/carts.js +213 -0
  45. package/dist/hooks/public/delivery-zones.d.ts +34 -0
  46. package/{src/hooks/public/delivery-zones.ts → dist/hooks/public/delivery-zones.js} +6 -12
  47. package/{src/hooks/public/index.ts → dist/hooks/public/index.d.ts} +1 -1
  48. package/dist/hooks/public/index.js +10 -0
  49. package/dist/hooks/public/orders.d.ts +302 -0
  50. package/{src/hooks/public/orders.ts → dist/hooks/public/orders.js} +12 -28
  51. package/dist/hooks/public/products.d.ts +398 -0
  52. package/{src/hooks/public/products.ts → dist/hooks/public/products.js} +12 -22
  53. package/dist/hooks/use-query-unwrapped.d.ts +20 -0
  54. package/dist/hooks/use-query-unwrapped.js +22 -0
  55. package/dist/hooks/useApiConfig.d.ts +11 -0
  56. package/dist/hooks/useApiConfig.js +14 -0
  57. package/dist/index.d.ts +20 -0
  58. package/{src/index.ts → dist/index.js} +0 -17
  59. package/dist/provider.d.ts +33 -0
  60. package/dist/provider.js +52 -0
  61. package/dist/rpc-client.d.ts +9043 -0
  62. package/dist/rpc-client.js +78 -0
  63. package/{src/rpc-types.ts → dist/rpc-types.d.ts} +35 -80
  64. package/dist/rpc-types.js +7 -0
  65. package/{src/types.ts → dist/types.d.ts} +0 -6
  66. package/dist/types.js +16 -0
  67. package/dist/utils/query-keys.d.ts +106 -0
  68. package/dist/utils/query-keys.js +108 -0
  69. package/package.json +24 -13
  70. package/src/client.ts +0 -57
  71. package/src/fetchers/carts.ts +0 -202
  72. package/src/fetchers/orders.ts +0 -48
  73. package/src/fetchers/products.ts +0 -46
  74. package/src/hooks/admin/abandoned-carts.ts +0 -102
  75. package/src/hooks/admin/brands.ts +0 -134
  76. package/src/hooks/admin/customers.ts +0 -31
  77. package/src/hooks/admin/delivery-zones.ts +0 -236
  78. package/src/hooks/admin/discount-codes.ts +0 -222
  79. package/src/hooks/admin/inventory.ts +0 -137
  80. package/src/hooks/admin/orders.ts +0 -229
  81. package/src/hooks/admin/products.ts +0 -116
  82. package/src/hooks/admin/stats.ts +0 -30
  83. package/src/hooks/admin/variants.ts +0 -173
  84. package/src/hooks/admin/warehouses.ts +0 -143
  85. package/src/hooks/public/carts.ts +0 -298
  86. package/src/hooks/use-query-unwrapped.ts +0 -30
  87. package/src/hooks/useApiConfig.ts +0 -22
  88. package/src/provider.tsx +0 -89
  89. package/src/rpc-client.ts +0 -106
  90. package/src/utils/query-keys.ts +0 -121
@@ -0,0 +1,277 @@
1
+ /**
2
+ * Type-safe admin RPC hooks for statistics
3
+ */
4
+ import { UseQueryOptions } from '@tanstack/react-query';
5
+ import { createAdminRpcClients } from '../../rpc-client';
6
+ /**
7
+ * Hook to get dashboard statistics using admin RPC
8
+ */
9
+ export declare function useGetStats(params?: {
10
+ brandId?: string;
11
+ }, options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['stats']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<{
12
+ overview: {
13
+ totalOrders: number;
14
+ pendingOrders: number;
15
+ shippedOrders: number;
16
+ deliveredOrders: number;
17
+ totalRevenue: number;
18
+ };
19
+ recentOrders: {
20
+ subtotal: number;
21
+ deliveryCharge: number;
22
+ totalPrice: number;
23
+ discountAmount: number;
24
+ createdAt: string;
25
+ updatedAt: string;
26
+ deletedAt: string;
27
+ prospectSince: string;
28
+ lastRecoveryAttemptAt: string;
29
+ brand: {
30
+ createdAt: string;
31
+ updatedAt: string;
32
+ deletedAt: string;
33
+ name: string;
34
+ id: string;
35
+ slug: string;
36
+ logoUrl: string | null;
37
+ siteUrl: string;
38
+ domain: string;
39
+ metaPixelId: string | null;
40
+ };
41
+ deliveryZone: {
42
+ deliveryCost: number;
43
+ freeShippingThreshold: number;
44
+ createdAt: string;
45
+ updatedAt: string;
46
+ deletedAt: string;
47
+ state: {
48
+ createdAt: string;
49
+ updatedAt: string;
50
+ deletedAt: string;
51
+ name: string;
52
+ id: string;
53
+ isActive: boolean;
54
+ };
55
+ name: string;
56
+ id: string;
57
+ brandId: string | null;
58
+ stateId: string;
59
+ allowCOD: boolean;
60
+ allowOnline: boolean;
61
+ waybillOnly: boolean;
62
+ estimatedDays: number | null;
63
+ isActive: boolean;
64
+ };
65
+ items: {
66
+ priceAtPurchase: number;
67
+ variant: {
68
+ price: number;
69
+ createdAt: string;
70
+ updatedAt: string;
71
+ deletedAt: string;
72
+ product: {
73
+ createdAt: string;
74
+ updatedAt: string;
75
+ deletedAt: string;
76
+ name: string;
77
+ id: string;
78
+ slug: string;
79
+ brandId: string;
80
+ isActive: boolean;
81
+ description: string | null;
82
+ thumbnailUrl: string | null;
83
+ quantityDiscounts: string | number | boolean | {
84
+ [x: string]: string | number | boolean | /*elided*/ any | {
85
+ [x: number]: string | number | boolean | /*elided*/ any | /*elided*/ any;
86
+ length: number;
87
+ toString: never;
88
+ toLocaleString: never;
89
+ pop: never;
90
+ push: never;
91
+ concat: never;
92
+ join: never;
93
+ reverse: never;
94
+ shift: never;
95
+ slice: never;
96
+ sort: never;
97
+ splice: never;
98
+ unshift: never;
99
+ indexOf: never;
100
+ lastIndexOf: never;
101
+ every: never;
102
+ some: never;
103
+ forEach: never;
104
+ map: never;
105
+ filter: never;
106
+ reduce: never;
107
+ reduceRight: never;
108
+ find: never;
109
+ findIndex: never;
110
+ fill: never;
111
+ copyWithin: never;
112
+ entries: never;
113
+ keys: never;
114
+ values: never;
115
+ includes: never;
116
+ flatMap: never;
117
+ flat: never;
118
+ [Symbol.iterator]: never;
119
+ readonly [Symbol.unscopables]: {
120
+ [x: number]: boolean;
121
+ length?: boolean;
122
+ toString?: boolean;
123
+ toLocaleString?: boolean;
124
+ pop?: boolean;
125
+ push?: boolean;
126
+ concat?: boolean;
127
+ join?: boolean;
128
+ reverse?: boolean;
129
+ shift?: boolean;
130
+ slice?: boolean;
131
+ sort?: boolean;
132
+ splice?: boolean;
133
+ unshift?: boolean;
134
+ indexOf?: boolean;
135
+ lastIndexOf?: boolean;
136
+ every?: boolean;
137
+ some?: boolean;
138
+ forEach?: boolean;
139
+ map?: boolean;
140
+ filter?: boolean;
141
+ reduce?: boolean;
142
+ reduceRight?: boolean;
143
+ find?: boolean;
144
+ findIndex?: boolean;
145
+ fill?: boolean;
146
+ copyWithin?: boolean;
147
+ entries?: boolean;
148
+ keys?: boolean;
149
+ values?: boolean;
150
+ includes?: boolean;
151
+ flatMap?: boolean;
152
+ flat?: boolean;
153
+ };
154
+ };
155
+ } | {
156
+ [x: number]: string | number | boolean | {
157
+ [x: string]: string | number | boolean | /*elided*/ any | /*elided*/ any;
158
+ } | /*elided*/ any;
159
+ length: number;
160
+ toString: never;
161
+ toLocaleString: never;
162
+ pop: never;
163
+ push: never;
164
+ concat: never;
165
+ join: never;
166
+ reverse: never;
167
+ shift: never;
168
+ slice: never;
169
+ sort: never;
170
+ splice: never;
171
+ unshift: never;
172
+ indexOf: never;
173
+ lastIndexOf: never;
174
+ every: never;
175
+ some: never;
176
+ forEach: never;
177
+ map: never;
178
+ filter: never;
179
+ reduce: never;
180
+ reduceRight: never;
181
+ find: never;
182
+ findIndex: never;
183
+ fill: never;
184
+ copyWithin: never;
185
+ entries: never;
186
+ keys: never;
187
+ values: never;
188
+ includes: never;
189
+ flatMap: never;
190
+ flat: never;
191
+ [Symbol.iterator]: never;
192
+ readonly [Symbol.unscopables]: {
193
+ [x: number]: boolean;
194
+ length?: boolean;
195
+ toString?: boolean;
196
+ toLocaleString?: boolean;
197
+ pop?: boolean;
198
+ push?: boolean;
199
+ concat?: boolean;
200
+ join?: boolean;
201
+ reverse?: boolean;
202
+ shift?: boolean;
203
+ slice?: boolean;
204
+ sort?: boolean;
205
+ splice?: boolean;
206
+ unshift?: boolean;
207
+ indexOf?: boolean;
208
+ lastIndexOf?: boolean;
209
+ every?: boolean;
210
+ some?: boolean;
211
+ forEach?: boolean;
212
+ map?: boolean;
213
+ filter?: boolean;
214
+ reduce?: boolean;
215
+ reduceRight?: boolean;
216
+ find?: boolean;
217
+ findIndex?: boolean;
218
+ fill?: boolean;
219
+ copyWithin?: boolean;
220
+ entries?: boolean;
221
+ keys?: boolean;
222
+ values?: boolean;
223
+ includes?: boolean;
224
+ flatMap?: boolean;
225
+ flat?: boolean;
226
+ };
227
+ };
228
+ };
229
+ name: string | null;
230
+ id: string;
231
+ isActive: boolean;
232
+ thumbnailUrl: string | null;
233
+ productId: string;
234
+ sku: string;
235
+ trackInventory: boolean;
236
+ lowStockThreshold: number | null;
237
+ };
238
+ warehouse: {
239
+ createdAt: string;
240
+ updatedAt: string;
241
+ deletedAt: string;
242
+ name: string;
243
+ id: string;
244
+ isActive: boolean;
245
+ address: string | null;
246
+ city: string | null;
247
+ state: string | null;
248
+ };
249
+ id: string;
250
+ orderId: string;
251
+ variantId: string;
252
+ warehouseId: string | null;
253
+ quantity: number;
254
+ }[];
255
+ id: string;
256
+ email: string | null;
257
+ brandId: string;
258
+ deliveryZoneId: string;
259
+ recoveryAttempts: number;
260
+ recoveryDiscountCodeId: string | null;
261
+ wasRecovered: boolean;
262
+ estimatedDays: number | null;
263
+ orderNumber: number;
264
+ firstName: string;
265
+ lastName: string;
266
+ phone: string;
267
+ address: string;
268
+ city: string;
269
+ discountCodeId: string | null;
270
+ paymentMethod: import("@prisma/client").$Enums.PaymentMethod;
271
+ paystackReference: string | null;
272
+ status: import("@prisma/client").$Enums.OrderStatus;
273
+ cancellationReason: string | null;
274
+ prospectReason: import("@prisma/client").$Enums.ProspectReason | null;
275
+ userActionToken: string;
276
+ }[];
277
+ }, Error>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Type-safe admin RPC hooks for statistics
3
+ */
4
+ import { useQueryUnwrapped } from '../use-query-unwrapped';
5
+ import { createAdminRpcClients, authHeaders } from '../../rpc-client';
6
+ import { queryKeys } from '../../utils/query-keys';
7
+ import { useApiConfig } from '../useApiConfig';
8
+ /**
9
+ * Hook to get dashboard statistics using admin RPC
10
+ */
11
+ export function useGetStats(params, options) {
12
+ const { baseURL, authToken } = useApiConfig();
13
+ return useQueryUnwrapped({
14
+ queryKey: queryKeys.admin.stats.overview(params?.brandId),
15
+ queryFn: async () => {
16
+ const clients = createAdminRpcClients(baseURL);
17
+ const res = await clients.stats.index.$get({ query: params }, authHeaders(authToken));
18
+ if (!res.ok)
19
+ throw new Error(`Failed to fetch statistics: ${res.statusText}`);
20
+ return res.json();
21
+ },
22
+ ...options,
23
+ });
24
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Type-safe admin RPC hooks for variant management
3
+ */
4
+ import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
5
+ import { createAdminRpcClients } from '../../rpc-client';
6
+ /**
7
+ * Hook to search variants across all products using admin RPC
8
+ */
9
+ export declare function useSearchVariants(params?: {
10
+ brandId?: string;
11
+ search?: string;
12
+ }, options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['variants']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<{
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ price: number;
16
+ deletedAt: string;
17
+ name: string | null;
18
+ id: string;
19
+ isActive: boolean;
20
+ thumbnailUrl: string | null;
21
+ productId: string;
22
+ sku: string;
23
+ trackInventory: boolean;
24
+ lowStockThreshold: number | null;
25
+ }[], Error>;
26
+ /**
27
+ * Hook to list variants for a specific product using admin RPC
28
+ */
29
+ export declare function useListProductVariants(productId: string, options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['variants']['products'][':productId']['variants']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<{
30
+ createdAt: string;
31
+ updatedAt: string;
32
+ price: number;
33
+ deletedAt: string;
34
+ name: string | null;
35
+ id: string;
36
+ isActive: boolean;
37
+ thumbnailUrl: string | null;
38
+ productId: string;
39
+ sku: string;
40
+ trackInventory: boolean;
41
+ lowStockThreshold: number | null;
42
+ }[], Error>;
43
+ /**
44
+ * Hook to create a variant for a product using admin RPC
45
+ */
46
+ export declare function useCreateVariant(productId: string, options?: UseMutationOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['variants']['products'][':productId']['variants']['$post']>>['json']>>, Error, any>): import("@tanstack/react-query").UseMutationResult<{
47
+ createdAt: string;
48
+ updatedAt: string;
49
+ price: number;
50
+ deletedAt: string;
51
+ name: string | null;
52
+ id: string;
53
+ isActive: boolean;
54
+ thumbnailUrl: string | null;
55
+ productId: string;
56
+ sku: string;
57
+ trackInventory: boolean;
58
+ lowStockThreshold: number | null;
59
+ } | {
60
+ error: {
61
+ code: string;
62
+ message: string;
63
+ };
64
+ }, Error, any, unknown>;
65
+ /**
66
+ * Hook to update a variant using admin RPC
67
+ */
68
+ export declare function useUpdateVariant(variantId: string, options?: UseMutationOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['variants'][':id']['$patch']>>['json']>>, Error, any>): import("@tanstack/react-query").UseMutationResult<{
69
+ createdAt: string;
70
+ updatedAt: string;
71
+ price: number;
72
+ deletedAt: string;
73
+ name: string | null;
74
+ id: string;
75
+ isActive: boolean;
76
+ thumbnailUrl: string | null;
77
+ productId: string;
78
+ sku: string;
79
+ trackInventory: boolean;
80
+ lowStockThreshold: number | null;
81
+ } | {
82
+ error: {
83
+ code: string;
84
+ message: string;
85
+ };
86
+ }, Error, any, unknown>;
87
+ /**
88
+ * Hook to get variant inventory across all warehouses using admin RPC
89
+ */
90
+ export declare function useGetVariantInventory(variantId: string, options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['variants'][':id']['inventory']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<{
91
+ variant: {
92
+ createdAt: string;
93
+ updatedAt: string;
94
+ price: number;
95
+ deletedAt: string;
96
+ name: string | null;
97
+ id: string;
98
+ isActive: boolean;
99
+ thumbnailUrl: string | null;
100
+ productId: string;
101
+ sku: string;
102
+ trackInventory: boolean;
103
+ lowStockThreshold: number | null;
104
+ };
105
+ totalInventory: number;
106
+ warehouses: {
107
+ warehouseId: string;
108
+ warehouseName: string;
109
+ inventoryCount: number;
110
+ }[];
111
+ }, Error>;
112
+ /**
113
+ * Hook to delete a variant using admin RPC
114
+ */
115
+ export declare function useDeleteVariant(variantId: string, options?: UseMutationOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['variants'][':id']['$delete']>>['json']>>, Error, void>): import("@tanstack/react-query").UseMutationResult<unknown, Error, void, unknown>;
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Type-safe admin RPC hooks for variant management
3
+ */
4
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
5
+ import { useQueryUnwrapped } from '../use-query-unwrapped';
6
+ import { createAdminRpcClients, authHeaders } from '../../rpc-client';
7
+ import { queryKeys } from '../../utils/query-keys';
8
+ import { useApiConfig } from '../useApiConfig';
9
+ /**
10
+ * Hook to search variants across all products using admin RPC
11
+ */
12
+ export function useSearchVariants(params, options) {
13
+ const { baseURL, authToken } = useApiConfig();
14
+ return useQueryUnwrapped({
15
+ queryKey: queryKeys.admin.variants.search(params),
16
+ queryFn: async () => {
17
+ const clients = createAdminRpcClients(baseURL);
18
+ const res = await clients.variants.index.$get({ query: params }, authHeaders(authToken));
19
+ if (!res.ok)
20
+ throw new Error(`Failed to search variants: ${res.statusText}`);
21
+ return res.json();
22
+ },
23
+ ...options,
24
+ });
25
+ }
26
+ /**
27
+ * Hook to list variants for a specific product using admin RPC
28
+ */
29
+ export function useListProductVariants(productId, options) {
30
+ const { baseURL, authToken } = useApiConfig();
31
+ return useQueryUnwrapped({
32
+ queryKey: queryKeys.admin.variants.byProduct(productId),
33
+ queryFn: async () => {
34
+ const clients = createAdminRpcClients(baseURL);
35
+ const res = await clients.variants.products[':productId'].variants.$get({ param: { productId } }, authHeaders(authToken));
36
+ if (!res.ok)
37
+ throw new Error(`Failed to fetch product variants: ${res.statusText}`);
38
+ return res.json();
39
+ },
40
+ ...options,
41
+ });
42
+ }
43
+ /**
44
+ * Hook to create a variant for a product using admin RPC
45
+ */
46
+ export function useCreateVariant(productId, options) {
47
+ const { baseURL, authToken } = useApiConfig();
48
+ const queryClient = useQueryClient();
49
+ return useMutation({
50
+ mutationFn: async (data) => {
51
+ const clients = createAdminRpcClients(baseURL);
52
+ const res = await clients.variants.products[':productId'].variants.$post({ json: data, param: { productId } }, authHeaders(authToken));
53
+ if (!res.ok)
54
+ throw new Error(`Failed to create variant: ${res.statusText}`);
55
+ return res.json();
56
+ },
57
+ onSuccess: () => {
58
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.variants.all });
59
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.products.detail(productId) });
60
+ },
61
+ ...options,
62
+ });
63
+ }
64
+ /**
65
+ * Hook to update a variant using admin RPC
66
+ */
67
+ export function useUpdateVariant(variantId, options) {
68
+ const { baseURL, authToken } = useApiConfig();
69
+ const queryClient = useQueryClient();
70
+ return useMutation({
71
+ mutationFn: async (data) => {
72
+ const clients = createAdminRpcClients(baseURL);
73
+ const res = await clients.variants[':id'].$patch({ json: data, param: { id: variantId } }, authHeaders(authToken));
74
+ if (!res.ok)
75
+ throw new Error(`Failed to update variant: ${res.statusText}`);
76
+ return res.json();
77
+ },
78
+ onSuccess: () => {
79
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.variants.detail(variantId) });
80
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.variants.all });
81
+ },
82
+ ...options,
83
+ });
84
+ }
85
+ /**
86
+ * Hook to get variant inventory across all warehouses using admin RPC
87
+ */
88
+ export function useGetVariantInventory(variantId, options) {
89
+ const { baseURL, authToken } = useApiConfig();
90
+ return useQueryUnwrapped({
91
+ queryKey: queryKeys.admin.variants.inventory(variantId),
92
+ queryFn: async () => {
93
+ const clients = createAdminRpcClients(baseURL);
94
+ const res = await clients.variants[':id'].inventory.$get({ param: { id: variantId } }, authHeaders(authToken));
95
+ if (!res.ok)
96
+ throw new Error(`Failed to fetch variant inventory: ${res.statusText}`);
97
+ return res.json();
98
+ },
99
+ ...options,
100
+ });
101
+ }
102
+ /**
103
+ * Hook to delete a variant using admin RPC
104
+ */
105
+ export function useDeleteVariant(variantId, options) {
106
+ const { baseURL, authToken } = useApiConfig();
107
+ const queryClient = useQueryClient();
108
+ return useMutation({
109
+ mutationFn: async () => {
110
+ const clients = createAdminRpcClients(baseURL);
111
+ const res = await clients.variants[':id'].$delete({ param: { id: variantId } }, authHeaders(authToken));
112
+ if (!res.ok)
113
+ throw new Error(`Failed to delete variant: ${res.statusText}`);
114
+ return res.json();
115
+ },
116
+ onSuccess: () => {
117
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.variants.all });
118
+ },
119
+ ...options,
120
+ });
121
+ }