@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
@@ -1,298 +0,0 @@
1
- /**
2
- * Type-safe RPC hooks for cart operations
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 { queryKeys } from '../../utils/query-keys';
11
- import {
12
- fetchCart,
13
- updateCart,
14
- createCart,
15
- addCartItem,
16
- updateCartItem,
17
- removeCartItem,
18
- applyDiscount,
19
- removeDiscount,
20
- checkoutCart,
21
- } from '../../fetchers/carts';
22
-
23
- /**
24
- * Hook to get cart by ID using RPC
25
- *
26
- * @param cartId - Cart UUID
27
- * @param options - React Query options
28
- *
29
- * @example
30
- * ```tsx
31
- * const { data: cart, isLoading } = useGetCart('cart-123');
32
- * console.log(cart?.cart.brand.name); // Fully typed!
33
- * ```
34
- */
35
- export function useGetCart(
36
- cartId: string,
37
- options?: Omit<UseQueryOptions<Awaited<ReturnType<typeof fetchCart>>, Error>, 'queryKey' | 'queryFn'>
38
- ) {
39
- return useQueryUnwrapped({
40
- queryKey: queryKeys.public.carts.detail(cartId),
41
- queryFn: () => fetchCart(cartId),
42
- ...options,
43
- });
44
- }
45
-
46
- /**
47
- * Hook to update cart using RPC
48
- *
49
- * @param cartId - Cart UUID
50
- * @param options - React Query mutation options
51
- *
52
- * @example
53
- * ```tsx
54
- * const updateCart = useUpdateCart('cart-123');
55
- * updateCart.mutate({
56
- * customerEmail: 'user@example.com',
57
- * deliveryZoneId: 'zone-123'
58
- * });
59
- * ```
60
- */
61
- export function useUpdateCart(
62
- cartId: string,
63
- options?: UseMutationOptions<
64
- Awaited<ReturnType<typeof updateCart>>,
65
- Error,
66
- Parameters<typeof updateCart>[1]
67
- >
68
- ) {
69
- const queryClient = useQueryClient();
70
-
71
- return useMutation({
72
- mutationFn: (data) => updateCart(cartId, data),
73
- onSuccess: () => {
74
- queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
75
- },
76
- ...options,
77
- });
78
- }
79
-
80
- /**
81
- * Hook to create a new cart using RPC
82
- *
83
- * @param options - React Query mutation options
84
- *
85
- * @example
86
- * ```tsx
87
- * const createCart = useCreateCart();
88
- * createCart.mutate('my-brand');
89
- * ```
90
- */
91
- export function useCreateCart(
92
- options?: UseMutationOptions<
93
- Awaited<ReturnType<typeof createCart>>,
94
- Error,
95
- string
96
- >
97
- ) {
98
- return useMutation({
99
- mutationFn: (brandSlug: string) => createCart(brandSlug),
100
- ...options,
101
- });
102
- }
103
-
104
- /**
105
- * Hook to apply discount code to cart using RPC
106
- *
107
- * @param cartId - Cart UUID
108
- * @param options - React Query mutation options
109
- *
110
- * @example
111
- * ```tsx
112
- * const applyDiscount = useApplyDiscount('cart-123');
113
- * applyDiscount.mutate({ code: 'SAVE10' });
114
- * ```
115
- */
116
- export function useApplyDiscount(
117
- cartId: string,
118
- options?: UseMutationOptions<
119
- Awaited<ReturnType<typeof applyDiscount>>,
120
- Error,
121
- { code: string }
122
- >
123
- ) {
124
- const queryClient = useQueryClient();
125
-
126
- return useMutation({
127
- mutationFn: (data) => applyDiscount(cartId, data.code),
128
- onSuccess: () => {
129
- queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
130
- },
131
- ...options,
132
- });
133
- }
134
-
135
- /**
136
- * Hook to remove discount code from cart using RPC
137
- *
138
- * @param cartId - Cart UUID
139
- * @param options - React Query mutation options
140
- *
141
- * @example
142
- * ```tsx
143
- * const removeDiscount = useRemoveDiscount('cart-123');
144
- * removeDiscount.mutate();
145
- * ```
146
- */
147
- export function useRemoveDiscount(
148
- cartId: string,
149
- options?: UseMutationOptions<
150
- Awaited<ReturnType<typeof removeDiscount>>,
151
- Error,
152
- void
153
- >
154
- ) {
155
- const queryClient = useQueryClient();
156
-
157
- return useMutation({
158
- mutationFn: () => removeDiscount(cartId),
159
- onSuccess: () => {
160
- queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
161
- },
162
- ...options,
163
- });
164
- }
165
-
166
- /**
167
- * Hook to add item to cart using RPC
168
- *
169
- * @param cartId - Cart UUID
170
- * @param options - React Query mutation options
171
- *
172
- * @example
173
- * ```tsx
174
- * const addItem = useAddCartItem('cart-123');
175
- * addItem.mutate({ sku: 'PROD-001', quantity: 2 });
176
- * ```
177
- */
178
- export function useAddCartItem(
179
- cartId: string,
180
- options?: UseMutationOptions<
181
- Awaited<ReturnType<typeof addCartItem>>,
182
- Error,
183
- { sku: string; quantity: number }
184
- >
185
- ) {
186
- const queryClient = useQueryClient();
187
-
188
- return useMutation({
189
- mutationFn: (data) => addCartItem(cartId, data.sku, data.quantity),
190
- onSuccess: () => {
191
- queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
192
- },
193
- ...options,
194
- });
195
- }
196
-
197
- /**
198
- * Hook to update cart item quantity using RPC
199
- *
200
- * @param cartId - Cart UUID
201
- * @param options - React Query mutation options
202
- *
203
- * @example
204
- * ```tsx
205
- * const updateItem = useUpdateCartItem('cart-123');
206
- * updateItem.mutate({ itemId: 'item-456', quantity: 3 });
207
- * ```
208
- */
209
- export function useUpdateCartItem(
210
- cartId: string,
211
- options?: UseMutationOptions<
212
- Awaited<ReturnType<typeof updateCartItem>>,
213
- Error,
214
- { itemId: string; quantity: number }
215
- >
216
- ) {
217
- const queryClient = useQueryClient();
218
-
219
- return useMutation({
220
- mutationFn: ({ itemId, quantity }) => updateCartItem(cartId, itemId, quantity),
221
- onSuccess: () => {
222
- queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
223
- },
224
- ...options,
225
- });
226
- }
227
-
228
- /**
229
- * Hook to remove item from cart using RPC
230
- *
231
- * @param cartId - Cart UUID
232
- * @param options - React Query mutation options
233
- *
234
- * @example
235
- * ```tsx
236
- * const removeItem = useRemoveCartItem('cart-123');
237
- * removeItem.mutate('item-456'); // Pass itemId in mutate call
238
- * ```
239
- */
240
- export function useRemoveCartItem(
241
- cartId: string,
242
- options?: UseMutationOptions<
243
- Awaited<ReturnType<typeof removeCartItem>>,
244
- Error,
245
- string
246
- >
247
- ) {
248
- const queryClient = useQueryClient();
249
-
250
- return useMutation({
251
- mutationFn: (itemId: string) => removeCartItem(cartId, itemId),
252
- onSuccess: () => {
253
- queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
254
- },
255
- ...options,
256
- });
257
- }
258
-
259
- /**
260
- * Hook to checkout a cart and create an order using RPC
261
- *
262
- * @param cartId - Cart UUID
263
- * @param options - React Query mutation options
264
- *
265
- * @example
266
- * ```tsx
267
- * const checkout = useCheckoutCart('cart-123');
268
- * checkout.mutate({
269
- * firstName: 'John',
270
- * lastName: 'Doe',
271
- * email: 'john@example.com',
272
- * phone: '+1234567890',
273
- * address: '123 Main St',
274
- * city: 'New York',
275
- * deliveryZoneId: 'zone-123',
276
- * paymentMethod: 'cod'
277
- * });
278
- * ```
279
- */
280
- export function useCheckoutCart(
281
- cartId: string,
282
- options?: UseMutationOptions<
283
- Awaited<ReturnType<typeof checkoutCart>>,
284
- Error,
285
- Parameters<typeof checkoutCart>[1]
286
- >
287
- ) {
288
- const queryClient = useQueryClient();
289
-
290
- return useMutation({
291
- mutationFn: (data) => checkoutCart(cartId, data),
292
- onSuccess: () => {
293
- // Invalidate cart query since it's now converted to an order
294
- queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
295
- },
296
- ...options,
297
- });
298
- }
@@ -1,30 +0,0 @@
1
- import { useQuery, type UseQueryOptions, type UseQueryResult } from '@tanstack/react-query';
2
-
3
- /**
4
- * Wrapper around useQuery that narrows the data type to exclude error responses
5
- *
6
- * Since our hooks throw on HTTP errors (via `if (!res.ok) throw new Error(...)`),
7
- * the data will never actually be an error response at runtime. This wrapper
8
- * tells TypeScript that truth.
9
- *
10
- * @example
11
- * ```ts
12
- * // Instead of:
13
- * return useQuery({ ... }) // Returns UseQueryResult<Data | { error: ... }, Error>
14
- *
15
- * // Use:
16
- * return useQueryUnwrapped({ ... }) // Returns UseQueryResult<Data, Error>
17
- * ```
18
- */
19
- export function useQueryUnwrapped<
20
- TData,
21
- TError = Error,
22
- TQueryKey extends readonly unknown[] = readonly unknown[]
23
- >(
24
- options: UseQueryOptions<TData, TError, TData, TQueryKey>
25
- ): UseQueryResult<Exclude<TData, { error: any }>, TError> {
26
- const result = useQuery(options);
27
-
28
- // Cast the data to exclude error types since we throw on errors
29
- return result as UseQueryResult<Exclude<TData, { error: any }>, TError>;
30
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Hook to access API configuration from context
3
- */
4
-
5
- import { useApiClientContext } from '../provider';
6
-
7
- export interface ApiConfig {
8
- baseURL: string;
9
- authToken: string;
10
- }
11
-
12
- /**
13
- * Get API configuration from context
14
- */
15
- export function useApiConfig(): ApiConfig {
16
- const { baseURL, authToken } = useApiClientContext();
17
-
18
- return {
19
- baseURL,
20
- authToken: authToken || '',
21
- };
22
- }
package/src/provider.tsx DELETED
@@ -1,89 +0,0 @@
1
- /**
2
- * React context provider for API client configuration
3
- */
4
-
5
- import { createContext, useContext, useEffect, ReactNode, useMemo } from 'react';
6
- import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
7
- import { AxiosError } from 'axios';
8
- import { initializeApiClient, ApiClientConfig } from './client';
9
-
10
- interface ApiClientContextValue {
11
- baseURL: string;
12
- authToken?: string;
13
- }
14
-
15
- const ApiClientContext = createContext<ApiClientContextValue | null>(null);
16
-
17
- export interface ApiClientProviderProps {
18
- children: ReactNode;
19
- baseURL?: string;
20
- authToken?: string;
21
- onError?: (error: AxiosError) => void;
22
- queryClient?: QueryClient;
23
- }
24
-
25
- /**
26
- * Provider component that initializes the API client and React Query
27
- *
28
- * @example
29
- * ```tsx
30
- * <ApiClientProvider>
31
- * <App />
32
- * </ApiClientProvider>
33
- * ```
34
- */
35
- export function ApiClientProvider({
36
- children,
37
- baseURL = 'https://oms-api.instock.ng',
38
- authToken,
39
- onError,
40
- queryClient: externalQueryClient
41
- }: ApiClientProviderProps) {
42
- // Initialize client synchronously on first render
43
- const config: ApiClientConfig = {
44
- baseURL,
45
- onError,
46
- };
47
-
48
- initializeApiClient(config);
49
-
50
- // Update client when config changes
51
- useEffect(() => {
52
- initializeApiClient(config);
53
- }, [baseURL, onError]);
54
-
55
- // Create a default query client if one isn't provided
56
- const queryClient = useMemo(
57
- () =>
58
- externalQueryClient ||
59
- new QueryClient({
60
- defaultOptions: {
61
- queries: {
62
- retry: 1,
63
- refetchOnWindowFocus: false,
64
- staleTime: 5000,
65
- },
66
- },
67
- }),
68
- [externalQueryClient]
69
- );
70
-
71
- return (
72
- <QueryClientProvider client={queryClient}>
73
- <ApiClientContext.Provider value={{ baseURL, authToken }}>
74
- {children}
75
- </ApiClientContext.Provider>
76
- </QueryClientProvider>
77
- );
78
- }
79
-
80
- /**
81
- * Hook to access API client context
82
- */
83
- export function useApiClientContext() {
84
- const context = useContext(ApiClientContext);
85
- if (!context) {
86
- throw new Error('useApiClientContext must be used within ApiClientProvider');
87
- }
88
- return context;
89
- }
package/src/rpc-client.ts DELETED
@@ -1,106 +0,0 @@
1
- /**
2
- * Hono RPC client for type-safe API access
3
- *
4
- * This creates typed RPC clients that import backend types directly.
5
- * The clients are used by RPC hooks to provide end-to-end type safety.
6
- */
7
-
8
- import { hc } from 'hono/client';
9
- import type {
10
- CartsRPC,
11
- OrdersRPC,
12
- ProductsRPC,
13
- DeliveryZonesRPC,
14
- AdminOrdersRPC,
15
- AdminBrandsRPC,
16
- AdminProductsRPC,
17
- AdminVariantsRPC,
18
- AdminWarehousesRPC,
19
- AdminInventoryRPC,
20
- AdminCustomersRPC,
21
- AdminStatsRPC,
22
- AdminAbandonedCartsRPC,
23
- AdminDiscountCodesRPC,
24
- AdminDeliveryZonesRPC,
25
- } from 'backend';
26
-
27
- /**
28
- * Create typed RPC clients for all public endpoints
29
- *
30
- * @param baseURL - Base URL for API requests (e.g., 'https://api.example.com')
31
- * @returns Object with typed Hono RPC clients for each endpoint
32
- *
33
- * @example
34
- * ```ts
35
- * const clients = createRpcClients('https://api.example.com');
36
- * const res = await clients.carts[':id'].$get({ param: { id: 'cart-123' } });
37
- * const data = await res.json(); // Fully typed!
38
- * ```
39
- */
40
- export function createRpcClients(baseURL: string) {
41
- const fullBaseUrl = `${baseURL}/v1`;
42
-
43
- return {
44
- carts: hc<CartsRPC>(`${fullBaseUrl}/carts`),
45
- orders: hc<OrdersRPC>(`${fullBaseUrl}/orders`),
46
- products: hc<ProductsRPC>(`${fullBaseUrl}/products`),
47
- deliveryZones: hc<DeliveryZonesRPC>(`${fullBaseUrl}/delivery-zones`),
48
- };
49
- }
50
-
51
- /**
52
- * Create typed RPC clients for all admin endpoints
53
- *
54
- * @param baseURL - Base URL for API requests (e.g., 'https://api.example.com')
55
- * @returns Object with typed Hono RPC clients for each admin endpoint
56
- *
57
- * @example
58
- * ```ts
59
- * const clients = createAdminRpcClients('https://api.example.com');
60
- * const res = await clients.orders.index.$get({
61
- * headers: { Authorization: `Bearer ${token}` }
62
- * });
63
- * const data = await res.json(); // Fully typed!
64
- * ```
65
- */
66
- export function createAdminRpcClients(baseURL: string) {
67
- const fullBaseUrl = `${baseURL}/v1/admin`;
68
-
69
- return {
70
- orders: hc<AdminOrdersRPC>(`${fullBaseUrl}/orders`),
71
- brands: hc<AdminBrandsRPC>(`${fullBaseUrl}/brands`),
72
- products: hc<AdminProductsRPC>(`${fullBaseUrl}/products`),
73
- variants: hc<AdminVariantsRPC>(`${fullBaseUrl}/variants`),
74
- warehouses: hc<AdminWarehousesRPC>(`${fullBaseUrl}/warehouses`),
75
- inventory: hc<AdminInventoryRPC>(`${fullBaseUrl}/inventory`),
76
- customers: hc<AdminCustomersRPC>(`${fullBaseUrl}/customers`),
77
- stats: hc<AdminStatsRPC>(`${fullBaseUrl}/stats`),
78
- abandonedCarts: hc<AdminAbandonedCartsRPC>(`${fullBaseUrl}/abandoned-carts`),
79
- discountCodes: hc<AdminDiscountCodesRPC>(`${fullBaseUrl}/discount-codes`),
80
- deliveryZones: hc<AdminDeliveryZonesRPC>(`${fullBaseUrl}/delivery-zones`),
81
- };
82
- }
83
-
84
- /**
85
- * Helper to create auth headers for admin RPC requests
86
- *
87
- * @param authToken - Clerk authentication token
88
- * @returns Headers object with Authorization header
89
- *
90
- * @example
91
- * ```ts
92
- * const res = await client.brands.index.$get(
93
- * {},
94
- * authHeaders(token)
95
- * );
96
- * ```
97
- */
98
- export function authHeaders(authToken: string) {
99
- return { headers: { Authorization: `Bearer ${authToken}` } };
100
- }
101
-
102
- /**
103
- * Type of the RPC clients for use in hooks
104
- */
105
- export type RpcClients = ReturnType<typeof createRpcClients>;
106
- export type AdminRpcClients = ReturnType<typeof createAdminRpcClients>;
@@ -1,121 +0,0 @@
1
- /**
2
- * Query key factories for React Query
3
- *
4
- * This provides a centralized way to manage query keys,
5
- * making it easier to invalidate and refetch queries.
6
- *
7
- * @see https://tkdodo.eu/blog/effective-react-query-keys
8
- */
9
-
10
- export const queryKeys = {
11
- // Public API keys (RPC is now the default)
12
- public: {
13
- all: ['public'] as const,
14
-
15
- carts: {
16
- all: ['public', 'carts'] as const,
17
- detail: (id: string) => ['public', 'carts', id] as const,
18
- },
19
-
20
- orders: {
21
- all: ['public', 'orders'] as const,
22
- detail: (id: string, token: string) => ['public', 'orders', id, token] as const,
23
- },
24
-
25
- products: {
26
- all: ['public', 'products'] as const,
27
- list: (brandId: string) => ['public', 'products', brandId] as const,
28
- detail: (productId: string) => ['public', 'products', productId] as const,
29
- },
30
-
31
- deliveryZones: {
32
- all: ['public', 'delivery-zones'] as const,
33
- list: (brandId?: string) => ['public', 'delivery-zones', brandId] as const,
34
- },
35
- },
36
-
37
- // Admin API keys (RPC is now the default)
38
- admin: {
39
- all: ['admin'] as const,
40
-
41
- orders: {
42
- all: ['admin', 'orders'] as const,
43
- list: () => ['admin', 'orders', 'list'] as const,
44
- detail: (id: string) => ['admin', 'orders', id] as const,
45
- },
46
-
47
- brands: {
48
- all: ['admin', 'brands'] as const,
49
- list: () => ['admin', 'brands', 'list'] as const,
50
- detail: (id: string) => ['admin', 'brands', id] as const,
51
- },
52
-
53
- products: {
54
- all: ['admin', 'products'] as const,
55
- list: (brandId?: string) => ['admin', 'products', 'list', brandId] as const,
56
- detail: (id: string) => ['admin', 'products', id] as const,
57
- },
58
-
59
- variants: {
60
- all: ['admin', 'variants'] as const,
61
- list: () => ['admin', 'variants', 'list'] as const,
62
- detail: (id: string) => ['admin', 'variants', id] as const,
63
- search: (params?: any) => ['admin', 'variants', 'search', params] as const,
64
- byProduct: (productId: string) => ['admin', 'variants', 'product', productId] as const,
65
- inventory: (id: string) => ['admin', 'variants', id, 'inventory'] as const,
66
- },
67
-
68
- warehouses: {
69
- all: ['admin', 'warehouses'] as const,
70
- list: () => ['admin', 'warehouses', 'list'] as const,
71
- detail: (id: string) => ['admin', 'warehouses', id] as const,
72
- inventory: (id: string) => ['admin', 'warehouses', id, 'inventory'] as const,
73
- },
74
-
75
- inventory: {
76
- all: ['admin', 'inventory'] as const,
77
- list: (params?: any) => ['admin', 'inventory', 'list', params] as const,
78
- transactions: (params?: any) => ['admin', 'inventory', 'transactions', params] as const,
79
- lowStock: (brandId?: string) => ['admin', 'inventory', 'low-stock', brandId] as const,
80
- },
81
-
82
- customers: {
83
- all: ['admin', 'customers'] as const,
84
- history: (phone: string) => ['admin', 'customers', 'history', phone] as const,
85
- },
86
-
87
- stats: {
88
- all: ['admin', 'stats'] as const,
89
- overview: (brandId?: string) => ['admin', 'stats', 'overview', brandId] as const,
90
- },
91
-
92
- abandonedCarts: {
93
- all: ['admin', 'abandoned-carts'] as const,
94
- list: (params?: any) => ['admin', 'abandoned-carts', 'list', params] as const,
95
- detail: (id: string) => ['admin', 'abandoned-carts', id] as const,
96
- stats: (brandId?: string) => ['admin', 'abandoned-carts', 'stats', brandId] as const,
97
- },
98
-
99
- discountCodes: {
100
- all: ['admin', 'discount-codes'] as const,
101
- list: (params?: any) => ['admin', 'discount-codes', 'list', params] as const,
102
- detail: (id: string) => ['admin', 'discount-codes', id] as const,
103
- analytics: (id: string) => ['admin', 'discount-codes', id, 'analytics'] as const,
104
- overviewStats: () => ['admin', 'discount-codes', 'stats', 'overview'] as const,
105
- },
106
-
107
- deliveryZones: {
108
- all: ['admin', 'delivery-zones'] as const,
109
- states: {
110
- all: ['admin', 'delivery-zones', 'states'] as const,
111
- list: () => ['admin', 'delivery-zones', 'states', 'list'] as const,
112
- detail: (id: string) => ['admin', 'delivery-zones', 'states', id] as const,
113
- },
114
- zones: {
115
- all: ['admin', 'delivery-zones', 'zones'] as const,
116
- list: (params?: any) => ['admin', 'delivery-zones', 'zones', 'list', params] as const,
117
- detail: (id: string) => ['admin', 'delivery-zones', 'zones', id] as const,
118
- },
119
- },
120
- },
121
- };