@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
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
import { hc } from 'hono/client';
|
|
8
|
+
/**
|
|
9
|
+
* Create typed RPC clients for all public endpoints
|
|
10
|
+
*
|
|
11
|
+
* @param baseURL - Base URL for API requests (e.g., 'https://api.example.com')
|
|
12
|
+
* @returns Object with typed Hono RPC clients for each endpoint
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const clients = createRpcClients('https://api.example.com');
|
|
17
|
+
* const res = await clients.carts[':id'].$get({ param: { id: 'cart-123' } });
|
|
18
|
+
* const data = await res.json(); // Fully typed!
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function createRpcClients(baseURL) {
|
|
22
|
+
const fullBaseUrl = `${baseURL}/v1`;
|
|
23
|
+
return {
|
|
24
|
+
carts: hc(`${fullBaseUrl}/carts`),
|
|
25
|
+
orders: hc(`${fullBaseUrl}/orders`),
|
|
26
|
+
products: hc(`${fullBaseUrl}/products`),
|
|
27
|
+
deliveryZones: hc(`${fullBaseUrl}/delivery-zones`),
|
|
28
|
+
brands: hc(`${fullBaseUrl}/brands`),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create typed RPC clients for all admin endpoints
|
|
33
|
+
*
|
|
34
|
+
* @param baseURL - Base URL for API requests (e.g., 'https://api.example.com')
|
|
35
|
+
* @returns Object with typed Hono RPC clients for each admin endpoint
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const clients = createAdminRpcClients('https://api.example.com');
|
|
40
|
+
* const res = await clients.orders.index.$get({
|
|
41
|
+
* headers: { Authorization: `Bearer ${token}` }
|
|
42
|
+
* });
|
|
43
|
+
* const data = await res.json(); // Fully typed!
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function createAdminRpcClients(baseURL) {
|
|
47
|
+
const fullBaseUrl = `${baseURL}/v1/admin`;
|
|
48
|
+
return {
|
|
49
|
+
orders: hc(`${fullBaseUrl}/orders`),
|
|
50
|
+
brands: hc(`${fullBaseUrl}/brands`),
|
|
51
|
+
products: hc(`${fullBaseUrl}/products`),
|
|
52
|
+
variants: hc(`${fullBaseUrl}/variants`),
|
|
53
|
+
warehouses: hc(`${fullBaseUrl}/warehouses`),
|
|
54
|
+
inventory: hc(`${fullBaseUrl}/inventory`),
|
|
55
|
+
customers: hc(`${fullBaseUrl}/customers`),
|
|
56
|
+
stats: hc(`${fullBaseUrl}/stats`),
|
|
57
|
+
abandonedCarts: hc(`${fullBaseUrl}/abandoned-carts`),
|
|
58
|
+
discountCodes: hc(`${fullBaseUrl}/discount-codes`),
|
|
59
|
+
deliveryZones: hc(`${fullBaseUrl}/delivery-zones`),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Helper to create auth headers for admin RPC requests
|
|
64
|
+
*
|
|
65
|
+
* @param authToken - Clerk authentication token
|
|
66
|
+
* @returns Headers object with Authorization header
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const res = await client.brands.index.$get(
|
|
71
|
+
* {},
|
|
72
|
+
* authHeaders(token)
|
|
73
|
+
* );
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export function authHeaders(authToken) {
|
|
77
|
+
return { headers: { Authorization: `Bearer ${authToken}` } };
|
|
78
|
+
}
|
|
@@ -4,118 +4,73 @@
|
|
|
4
4
|
* The hooks already have proper Hono RPC type inference built-in.
|
|
5
5
|
* We extract the data types from UseQueryResult<T, E> to get the actual response types.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import type { UseQueryResult } from '@tanstack/react-query';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// since Hono RPC types include all possible HTTP responses. The hooks will throw on errors
|
|
13
|
-
// at runtime, but TypeScript doesn't know that. Consumers should use type guards like:
|
|
14
|
-
// `if (data && 'propertyName' in data) { ... }` to narrow the type.
|
|
15
|
-
type QueryData<T> = T extends UseQueryResult<infer D, any>
|
|
16
|
-
? NonNullable<D>
|
|
17
|
-
: never;
|
|
18
|
-
|
|
19
|
-
// Import all hooks for type extraction
|
|
20
|
-
import type {
|
|
21
|
-
useGetCart,
|
|
22
|
-
useGetOrder,
|
|
23
|
-
useGetProducts,
|
|
24
|
-
useGetDeliveryZones,
|
|
25
|
-
useCheckoutCart,
|
|
26
|
-
} from './hooks/public';
|
|
27
|
-
|
|
28
|
-
import type {
|
|
29
|
-
useListOrders,
|
|
30
|
-
useGetOrder as useGetAdminOrder,
|
|
31
|
-
useListBrands,
|
|
32
|
-
useListProducts,
|
|
33
|
-
useGetProduct,
|
|
34
|
-
useSearchVariants,
|
|
35
|
-
useListWarehouses,
|
|
36
|
-
useListInventory,
|
|
37
|
-
useGetCustomerHistory,
|
|
38
|
-
useGetStats,
|
|
39
|
-
useListAbandonedCarts,
|
|
40
|
-
useListDiscountCodes,
|
|
41
|
-
useGetDiscountCode,
|
|
42
|
-
useGetDiscountCodeAnalytics,
|
|
43
|
-
useListDeliveryZones as useListAdminDeliveryZones,
|
|
44
|
-
useListStates,
|
|
45
|
-
} from './hooks/admin';
|
|
46
|
-
|
|
47
|
-
// ============================================================================
|
|
48
|
-
// Admin API Response Types
|
|
49
|
-
// ============================================================================
|
|
50
|
-
|
|
8
|
+
type QueryData<T> = T extends UseQueryResult<infer D, any> ? NonNullable<D> : never;
|
|
9
|
+
import type { useGetCart, useGetOrder, useGetProducts, useGetDeliveryZones } from './hooks/public';
|
|
10
|
+
import type { useListOrders, useGetOrder as useGetAdminOrder, useListBrands, useListProducts, useGetProduct, useSearchVariants, useListWarehouses, useListInventory, useGetCustomerHistory, useGetStats, useListAbandonedCarts, useListDiscountCodes, useGetDiscountCode, useGetDiscountCodeAnalytics, useListDeliveryZones as useListAdminDeliveryZones, useListStates } from './hooks/admin';
|
|
51
11
|
export type AdminBrandsResponse = QueryData<ReturnType<typeof useListBrands>>;
|
|
52
12
|
export type Brand = AdminBrandsResponse extends Array<infer Item> ? Item : never;
|
|
53
|
-
|
|
54
13
|
export type AdminProductsResponse = QueryData<ReturnType<typeof useListProducts>>;
|
|
55
14
|
export type AdminProduct = AdminProductsResponse extends Array<infer Item> ? Item : never;
|
|
56
|
-
|
|
57
15
|
export type AdminProductFull = QueryData<ReturnType<typeof useGetProduct>>;
|
|
58
|
-
|
|
59
16
|
export type AdminOrdersResponse = QueryData<ReturnType<typeof useListOrders>>;
|
|
60
|
-
export type AdminOrder = AdminOrdersResponse extends {
|
|
61
|
-
|
|
17
|
+
export type AdminOrder = AdminOrdersResponse extends {
|
|
18
|
+
data: Array<infer Item>;
|
|
19
|
+
} ? Item : never;
|
|
62
20
|
export type AdminOrderFull = QueryData<ReturnType<typeof useGetAdminOrder>>;
|
|
63
|
-
|
|
64
21
|
export type AdminVariantsResponse = QueryData<ReturnType<typeof useSearchVariants>>;
|
|
65
22
|
export type Variant = AdminVariantsResponse extends Array<infer Item> ? Item : never;
|
|
66
|
-
|
|
67
23
|
export type AdminWarehousesResponse = QueryData<ReturnType<typeof useListWarehouses>>;
|
|
68
24
|
export type Warehouse = AdminWarehousesResponse extends Array<infer Item> ? Item : never;
|
|
69
|
-
|
|
70
25
|
export type AdminInventoryResponse = QueryData<ReturnType<typeof useListInventory>>;
|
|
71
26
|
export type InventoryItem = AdminInventoryResponse extends Array<infer Item> ? Item : never;
|
|
72
|
-
|
|
73
27
|
export type AdminCustomerHistoryResponse = QueryData<ReturnType<typeof useGetCustomerHistory>>;
|
|
74
|
-
export type Customer = AdminCustomerHistoryResponse extends {
|
|
75
|
-
|
|
76
|
-
|
|
28
|
+
export type Customer = AdminCustomerHistoryResponse extends {
|
|
29
|
+
customer: infer C;
|
|
30
|
+
} ? C : never;
|
|
31
|
+
export type CustomerOrder = AdminCustomerHistoryResponse extends {
|
|
32
|
+
orders: Array<infer Item>;
|
|
33
|
+
} ? Item : never;
|
|
77
34
|
export type AdminStatsResponse = QueryData<ReturnType<typeof useGetStats>>;
|
|
78
|
-
export type AdminStatsOverview = AdminStatsResponse extends {
|
|
79
|
-
|
|
80
|
-
|
|
35
|
+
export type AdminStatsOverview = AdminStatsResponse extends {
|
|
36
|
+
overview: infer O;
|
|
37
|
+
} ? O : never;
|
|
38
|
+
export type RecentOrder = AdminStatsResponse extends {
|
|
39
|
+
recentOrders: Array<infer Item>;
|
|
40
|
+
} ? Item : never;
|
|
81
41
|
export type AdminAbandonedCartsResponse = QueryData<ReturnType<typeof useListAbandonedCarts>>;
|
|
82
|
-
export type AbandonedCart = AdminAbandonedCartsResponse extends {
|
|
83
|
-
|
|
42
|
+
export type AbandonedCart = AdminAbandonedCartsResponse extends {
|
|
43
|
+
carts: Array<infer Item>;
|
|
44
|
+
} ? Item : never;
|
|
84
45
|
export type AdminDiscountCodesResponse = QueryData<ReturnType<typeof useListDiscountCodes>>;
|
|
85
|
-
export type DiscountCode = AdminDiscountCodesResponse extends {
|
|
86
|
-
|
|
46
|
+
export type DiscountCode = AdminDiscountCodesResponse extends {
|
|
47
|
+
data: Array<infer Item>;
|
|
48
|
+
} ? Item : never;
|
|
87
49
|
export type DiscountCodeFull = QueryData<ReturnType<typeof useGetDiscountCode>>;
|
|
88
|
-
|
|
89
50
|
export type DiscountCodeAnalytics = QueryData<ReturnType<typeof useGetDiscountCodeAnalytics>>;
|
|
90
|
-
|
|
91
|
-
// Admin Delivery Zones - returns flat array of zones
|
|
92
51
|
export type AdminDeliveryZonesResponse = QueryData<ReturnType<typeof useListAdminDeliveryZones>>;
|
|
93
|
-
export type AdminDeliveryZone = AdminDeliveryZonesResponse extends readonly (infer Item)[] ? Item :
|
|
94
|
-
AdminDeliveryZonesResponse extends (infer Item)[] ? Item : never;
|
|
95
|
-
|
|
96
|
-
// Admin States - returns array of states with nested deliveryZones
|
|
52
|
+
export type AdminDeliveryZone = AdminDeliveryZonesResponse extends readonly (infer Item)[] ? Item : AdminDeliveryZonesResponse extends (infer Item)[] ? Item : never;
|
|
97
53
|
export type AdminStatesResponse = QueryData<ReturnType<typeof useListStates>>;
|
|
98
54
|
export type AdminStateWithZones = AdminStatesResponse extends Array<infer Item> ? Item : never;
|
|
99
55
|
export type State = Omit<AdminStateWithZones, 'deliveryZones'>;
|
|
100
56
|
export type AdminState = State;
|
|
101
|
-
|
|
102
|
-
// ============================================================================
|
|
103
|
-
// Public API Response Types
|
|
104
|
-
// ============================================================================
|
|
105
|
-
|
|
106
57
|
export type PublicProductsResponse = QueryData<ReturnType<typeof useGetProducts>>;
|
|
107
58
|
export type PublicProduct = PublicProductsResponse extends Array<infer Item> ? Item : never;
|
|
108
59
|
export type Product = PublicProduct;
|
|
109
|
-
|
|
110
60
|
export type PublicDeliveryZonesResponse = QueryData<ReturnType<typeof useGetDeliveryZones>>;
|
|
111
61
|
export type PublicDeliveryZoneState = PublicDeliveryZonesResponse extends Array<infer Item> ? Item : never;
|
|
112
62
|
export type DeliveryZoneState = PublicDeliveryZoneState;
|
|
113
|
-
export type DeliveryZone = PublicDeliveryZoneState extends {
|
|
114
|
-
|
|
63
|
+
export type DeliveryZone = PublicDeliveryZoneState extends {
|
|
64
|
+
zones: Array<infer Zone>;
|
|
65
|
+
} ? Zone : never;
|
|
115
66
|
export type PublicCartResponse = QueryData<ReturnType<typeof useGetCart>>;
|
|
116
67
|
export type Cart = PublicCartResponse;
|
|
117
|
-
export type CartItem = PublicCartResponse extends {
|
|
118
|
-
|
|
68
|
+
export type CartItem = PublicCartResponse extends {
|
|
69
|
+
items: Array<infer Item>;
|
|
70
|
+
} ? Item : never;
|
|
119
71
|
export type PublicOrderResponse = QueryData<ReturnType<typeof useGetOrder>>;
|
|
120
72
|
export type Order = PublicOrderResponse;
|
|
121
|
-
export type OrderItem = Order extends {
|
|
73
|
+
export type OrderItem = Order extends {
|
|
74
|
+
items: Array<infer Item>;
|
|
75
|
+
} ? Item : never;
|
|
76
|
+
export {};
|
|
@@ -9,15 +9,9 @@
|
|
|
9
9
|
* const [selectedBrand, setSelectedBrand] = useState<Brand | null>(null)
|
|
10
10
|
* ```
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
// Re-export hooks so types and hooks can be imported together
|
|
14
12
|
export * from './hooks/public';
|
|
15
13
|
export * as admin from './hooks/admin';
|
|
16
|
-
|
|
17
|
-
// Re-export all RPC-derived types
|
|
18
14
|
export * from './rpc-types';
|
|
19
|
-
|
|
20
|
-
// Additional derived types for convenience
|
|
21
15
|
export type { PublicProduct as Product } from './rpc-types';
|
|
22
16
|
export type { PublicDeliveryZoneState as DeliveryZoneState } from './rpc-types';
|
|
23
17
|
export type { PublicCartResponse as CartResponse, PublicCartResponse as Cart } from './rpc-types';
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type exports for API client
|
|
3
|
+
*
|
|
4
|
+
* These types are derived directly from Hono RPC routes for end-to-end type safety.
|
|
5
|
+
*
|
|
6
|
+
* Usage in frontend:
|
|
7
|
+
* ```ts
|
|
8
|
+
* import type { Brand, InventoryItem } from '@oms/api-client'
|
|
9
|
+
* const [selectedBrand, setSelectedBrand] = useState<Brand | null>(null)
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
// Re-export hooks so types and hooks can be imported together
|
|
13
|
+
export * from './hooks/public';
|
|
14
|
+
export * as admin from './hooks/admin';
|
|
15
|
+
// Re-export all RPC-derived types
|
|
16
|
+
export * from './rpc-types';
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
export declare const queryKeys: {
|
|
10
|
+
public: {
|
|
11
|
+
all: readonly ["public"];
|
|
12
|
+
carts: {
|
|
13
|
+
all: readonly ["public", "carts"];
|
|
14
|
+
detail: (id: string) => readonly ["public", "carts", string];
|
|
15
|
+
};
|
|
16
|
+
orders: {
|
|
17
|
+
all: readonly ["public", "orders"];
|
|
18
|
+
detail: (id: string, token: string) => readonly ["public", "orders", string, string];
|
|
19
|
+
};
|
|
20
|
+
products: {
|
|
21
|
+
all: readonly ["public", "products"];
|
|
22
|
+
list: (brandId: string) => readonly ["public", "products", string];
|
|
23
|
+
detail: (productId: string) => readonly ["public", "products", string];
|
|
24
|
+
};
|
|
25
|
+
deliveryZones: {
|
|
26
|
+
all: readonly ["public", "delivery-zones"];
|
|
27
|
+
list: (brandId?: string) => readonly ["public", "delivery-zones", string];
|
|
28
|
+
};
|
|
29
|
+
brands: {
|
|
30
|
+
all: readonly ["public", "brands"];
|
|
31
|
+
detail: (slug: string) => readonly ["public", "brands", string];
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
admin: {
|
|
35
|
+
all: readonly ["admin"];
|
|
36
|
+
orders: {
|
|
37
|
+
all: readonly ["admin", "orders"];
|
|
38
|
+
list: () => readonly ["admin", "orders", "list"];
|
|
39
|
+
detail: (id: string) => readonly ["admin", "orders", string];
|
|
40
|
+
};
|
|
41
|
+
brands: {
|
|
42
|
+
all: readonly ["admin", "brands"];
|
|
43
|
+
list: () => readonly ["admin", "brands", "list"];
|
|
44
|
+
detail: (id: string) => readonly ["admin", "brands", string];
|
|
45
|
+
};
|
|
46
|
+
products: {
|
|
47
|
+
all: readonly ["admin", "products"];
|
|
48
|
+
list: (brandId?: string) => readonly ["admin", "products", "list", string];
|
|
49
|
+
detail: (id: string) => readonly ["admin", "products", string];
|
|
50
|
+
};
|
|
51
|
+
variants: {
|
|
52
|
+
all: readonly ["admin", "variants"];
|
|
53
|
+
list: () => readonly ["admin", "variants", "list"];
|
|
54
|
+
detail: (id: string) => readonly ["admin", "variants", string];
|
|
55
|
+
search: (params?: any) => readonly ["admin", "variants", "search", any];
|
|
56
|
+
byProduct: (productId: string) => readonly ["admin", "variants", "product", string];
|
|
57
|
+
inventory: (id: string) => readonly ["admin", "variants", string, "inventory"];
|
|
58
|
+
};
|
|
59
|
+
warehouses: {
|
|
60
|
+
all: readonly ["admin", "warehouses"];
|
|
61
|
+
list: () => readonly ["admin", "warehouses", "list"];
|
|
62
|
+
detail: (id: string) => readonly ["admin", "warehouses", string];
|
|
63
|
+
inventory: (id: string) => readonly ["admin", "warehouses", string, "inventory"];
|
|
64
|
+
};
|
|
65
|
+
inventory: {
|
|
66
|
+
all: readonly ["admin", "inventory"];
|
|
67
|
+
list: (params?: any) => readonly ["admin", "inventory", "list", any];
|
|
68
|
+
transactions: (params?: any) => readonly ["admin", "inventory", "transactions", any];
|
|
69
|
+
lowStock: (brandId?: string) => readonly ["admin", "inventory", "low-stock", string];
|
|
70
|
+
};
|
|
71
|
+
customers: {
|
|
72
|
+
all: readonly ["admin", "customers"];
|
|
73
|
+
history: (phone: string) => readonly ["admin", "customers", "history", string];
|
|
74
|
+
};
|
|
75
|
+
stats: {
|
|
76
|
+
all: readonly ["admin", "stats"];
|
|
77
|
+
overview: (brandId?: string) => readonly ["admin", "stats", "overview", string];
|
|
78
|
+
};
|
|
79
|
+
abandonedCarts: {
|
|
80
|
+
all: readonly ["admin", "abandoned-carts"];
|
|
81
|
+
list: (params?: any) => readonly ["admin", "abandoned-carts", "list", any];
|
|
82
|
+
detail: (id: string) => readonly ["admin", "abandoned-carts", string];
|
|
83
|
+
stats: (brandId?: string) => readonly ["admin", "abandoned-carts", "stats", string];
|
|
84
|
+
};
|
|
85
|
+
discountCodes: {
|
|
86
|
+
all: readonly ["admin", "discount-codes"];
|
|
87
|
+
list: (params?: any) => readonly ["admin", "discount-codes", "list", any];
|
|
88
|
+
detail: (id: string) => readonly ["admin", "discount-codes", string];
|
|
89
|
+
analytics: (id: string) => readonly ["admin", "discount-codes", string, "analytics"];
|
|
90
|
+
overviewStats: () => readonly ["admin", "discount-codes", "stats", "overview"];
|
|
91
|
+
};
|
|
92
|
+
deliveryZones: {
|
|
93
|
+
all: readonly ["admin", "delivery-zones"];
|
|
94
|
+
states: {
|
|
95
|
+
all: readonly ["admin", "delivery-zones", "states"];
|
|
96
|
+
list: () => readonly ["admin", "delivery-zones", "states", "list"];
|
|
97
|
+
detail: (id: string) => readonly ["admin", "delivery-zones", "states", string];
|
|
98
|
+
};
|
|
99
|
+
zones: {
|
|
100
|
+
all: readonly ["admin", "delivery-zones", "zones"];
|
|
101
|
+
list: (params?: any) => readonly ["admin", "delivery-zones", "zones", "list", any];
|
|
102
|
+
detail: (id: string) => readonly ["admin", "delivery-zones", "zones", string];
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
export const queryKeys = {
|
|
10
|
+
// Public API keys (RPC is now the default)
|
|
11
|
+
public: {
|
|
12
|
+
all: ['public'],
|
|
13
|
+
carts: {
|
|
14
|
+
all: ['public', 'carts'],
|
|
15
|
+
detail: (id) => ['public', 'carts', id],
|
|
16
|
+
},
|
|
17
|
+
orders: {
|
|
18
|
+
all: ['public', 'orders'],
|
|
19
|
+
detail: (id, token) => ['public', 'orders', id, token],
|
|
20
|
+
},
|
|
21
|
+
products: {
|
|
22
|
+
all: ['public', 'products'],
|
|
23
|
+
list: (brandId) => ['public', 'products', brandId],
|
|
24
|
+
detail: (productId) => ['public', 'products', productId],
|
|
25
|
+
},
|
|
26
|
+
deliveryZones: {
|
|
27
|
+
all: ['public', 'delivery-zones'],
|
|
28
|
+
list: (brandId) => ['public', 'delivery-zones', brandId],
|
|
29
|
+
},
|
|
30
|
+
brands: {
|
|
31
|
+
all: ['public', 'brands'],
|
|
32
|
+
detail: (slug) => ['public', 'brands', slug],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
// Admin API keys (RPC is now the default)
|
|
36
|
+
admin: {
|
|
37
|
+
all: ['admin'],
|
|
38
|
+
orders: {
|
|
39
|
+
all: ['admin', 'orders'],
|
|
40
|
+
list: () => ['admin', 'orders', 'list'],
|
|
41
|
+
detail: (id) => ['admin', 'orders', id],
|
|
42
|
+
},
|
|
43
|
+
brands: {
|
|
44
|
+
all: ['admin', 'brands'],
|
|
45
|
+
list: () => ['admin', 'brands', 'list'],
|
|
46
|
+
detail: (id) => ['admin', 'brands', id],
|
|
47
|
+
},
|
|
48
|
+
products: {
|
|
49
|
+
all: ['admin', 'products'],
|
|
50
|
+
list: (brandId) => ['admin', 'products', 'list', brandId],
|
|
51
|
+
detail: (id) => ['admin', 'products', id],
|
|
52
|
+
},
|
|
53
|
+
variants: {
|
|
54
|
+
all: ['admin', 'variants'],
|
|
55
|
+
list: () => ['admin', 'variants', 'list'],
|
|
56
|
+
detail: (id) => ['admin', 'variants', id],
|
|
57
|
+
search: (params) => ['admin', 'variants', 'search', params],
|
|
58
|
+
byProduct: (productId) => ['admin', 'variants', 'product', productId],
|
|
59
|
+
inventory: (id) => ['admin', 'variants', id, 'inventory'],
|
|
60
|
+
},
|
|
61
|
+
warehouses: {
|
|
62
|
+
all: ['admin', 'warehouses'],
|
|
63
|
+
list: () => ['admin', 'warehouses', 'list'],
|
|
64
|
+
detail: (id) => ['admin', 'warehouses', id],
|
|
65
|
+
inventory: (id) => ['admin', 'warehouses', id, 'inventory'],
|
|
66
|
+
},
|
|
67
|
+
inventory: {
|
|
68
|
+
all: ['admin', 'inventory'],
|
|
69
|
+
list: (params) => ['admin', 'inventory', 'list', params],
|
|
70
|
+
transactions: (params) => ['admin', 'inventory', 'transactions', params],
|
|
71
|
+
lowStock: (brandId) => ['admin', 'inventory', 'low-stock', brandId],
|
|
72
|
+
},
|
|
73
|
+
customers: {
|
|
74
|
+
all: ['admin', 'customers'],
|
|
75
|
+
history: (phone) => ['admin', 'customers', 'history', phone],
|
|
76
|
+
},
|
|
77
|
+
stats: {
|
|
78
|
+
all: ['admin', 'stats'],
|
|
79
|
+
overview: (brandId) => ['admin', 'stats', 'overview', brandId],
|
|
80
|
+
},
|
|
81
|
+
abandonedCarts: {
|
|
82
|
+
all: ['admin', 'abandoned-carts'],
|
|
83
|
+
list: (params) => ['admin', 'abandoned-carts', 'list', params],
|
|
84
|
+
detail: (id) => ['admin', 'abandoned-carts', id],
|
|
85
|
+
stats: (brandId) => ['admin', 'abandoned-carts', 'stats', brandId],
|
|
86
|
+
},
|
|
87
|
+
discountCodes: {
|
|
88
|
+
all: ['admin', 'discount-codes'],
|
|
89
|
+
list: (params) => ['admin', 'discount-codes', 'list', params],
|
|
90
|
+
detail: (id) => ['admin', 'discount-codes', id],
|
|
91
|
+
analytics: (id) => ['admin', 'discount-codes', id, 'analytics'],
|
|
92
|
+
overviewStats: () => ['admin', 'discount-codes', 'stats', 'overview'],
|
|
93
|
+
},
|
|
94
|
+
deliveryZones: {
|
|
95
|
+
all: ['admin', 'delivery-zones'],
|
|
96
|
+
states: {
|
|
97
|
+
all: ['admin', 'delivery-zones', 'states'],
|
|
98
|
+
list: () => ['admin', 'delivery-zones', 'states', 'list'],
|
|
99
|
+
detail: (id) => ['admin', 'delivery-zones', 'states', id],
|
|
100
|
+
},
|
|
101
|
+
zones: {
|
|
102
|
+
all: ['admin', 'delivery-zones', 'zones'],
|
|
103
|
+
list: (params) => ['admin', 'delivery-zones', 'zones', 'list', params],
|
|
104
|
+
detail: (id) => ['admin', 'delivery-zones', 'zones', id],
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
};
|
package/package.json
CHANGED
|
@@ -1,19 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instockng/api-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "React Query hooks for OMS API",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
|
-
".":
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./fetchers": {
|
|
13
|
+
"types": "./dist/fetchers/index.d.ts",
|
|
14
|
+
"import": "./dist/fetchers/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./admin": {
|
|
17
|
+
"types": "./dist/hooks/admin/index.d.ts",
|
|
18
|
+
"import": "./dist/hooks/admin/index.js"
|
|
19
|
+
}
|
|
12
20
|
},
|
|
13
21
|
"files": [
|
|
14
|
-
"
|
|
22
|
+
"dist",
|
|
15
23
|
"README.md"
|
|
16
24
|
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"type-check": "tsc --noEmit",
|
|
27
|
+
"build": "tsc --project tsconfig.build.json --noEmitOnError false",
|
|
28
|
+
"generate-types": "node scripts/generate-backend-types.mjs",
|
|
29
|
+
"prebuild": "pnpm run generate-types",
|
|
30
|
+
"prepublishOnly": "pnpm run generate-types"
|
|
31
|
+
},
|
|
17
32
|
"keywords": [
|
|
18
33
|
"api",
|
|
19
34
|
"react-query",
|
|
@@ -37,9 +52,5 @@
|
|
|
37
52
|
"axios": "^1.6.5",
|
|
38
53
|
"react": "^19.0.0",
|
|
39
54
|
"typescript": "^5.3.3"
|
|
40
|
-
},
|
|
41
|
-
"scripts": {
|
|
42
|
-
"type-check": "tsc --noEmit",
|
|
43
|
-
"build": "tsc --build"
|
|
44
55
|
}
|
|
45
|
-
}
|
|
56
|
+
}
|
package/src/client.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Axios client configuration for OMS API
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import axios, { AxiosInstance, AxiosError } from 'axios';
|
|
6
|
-
|
|
7
|
-
export interface ApiClientConfig {
|
|
8
|
-
baseURL: string;
|
|
9
|
-
onError?: (error: AxiosError) => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
let apiClient: AxiosInstance | null = null;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Initialize the API client with configuration
|
|
16
|
-
*/
|
|
17
|
-
export function initializeApiClient(config: ApiClientConfig): AxiosInstance {
|
|
18
|
-
apiClient = axios.create({
|
|
19
|
-
baseURL: config.baseURL,
|
|
20
|
-
headers: {
|
|
21
|
-
'Content-Type': 'application/json',
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// Response interceptor for error handling
|
|
26
|
-
apiClient.interceptors.response.use(
|
|
27
|
-
(response) => response,
|
|
28
|
-
(error: AxiosError) => {
|
|
29
|
-
// Call custom error handler if provided
|
|
30
|
-
if (config.onError) {
|
|
31
|
-
config.onError(error);
|
|
32
|
-
}
|
|
33
|
-
return Promise.reject(error);
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
return apiClient;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Get the current API client instance
|
|
42
|
-
*/
|
|
43
|
-
export function getApiClient(): AxiosInstance {
|
|
44
|
-
if (!apiClient) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
'API client not initialized. Make sure to wrap your app with ApiClientProvider.'
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
return apiClient;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Reset the API client (mainly for testing)
|
|
54
|
-
*/
|
|
55
|
-
export function resetApiClient(): void {
|
|
56
|
-
apiClient = null;
|
|
57
|
-
}
|