@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
package/src/fetchers/carts.ts
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cart fetcher functions
|
|
3
|
-
*
|
|
4
|
-
* These are the actual data-fetching functions used by hooks.
|
|
5
|
-
* They can also be imported directly in Server Components.
|
|
6
|
-
*
|
|
7
|
-
* API URL is hardcoded to https://oms-api.instock.ng
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { createRpcClients } from '../rpc-client';
|
|
11
|
-
|
|
12
|
-
const API_URL = 'https://oms-api.instock.ng';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Fetch a cart by ID
|
|
16
|
-
*
|
|
17
|
-
* @param cartId - Cart UUID
|
|
18
|
-
* @returns Cart with items, brand, and delivery zone
|
|
19
|
-
*/
|
|
20
|
-
export async function fetchCart(cartId: string) {
|
|
21
|
-
const clients = createRpcClients(API_URL);
|
|
22
|
-
const res = await clients.carts[':id'].$get({
|
|
23
|
-
param: { id: cartId },
|
|
24
|
-
});
|
|
25
|
-
if (!res.ok) {
|
|
26
|
-
throw new Error(`Failed to fetch cart: ${res.statusText}`);
|
|
27
|
-
}
|
|
28
|
-
return res.json();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Create a new cart
|
|
33
|
-
*
|
|
34
|
-
* @param brandSlug - Brand slug
|
|
35
|
-
* @returns Newly created cart
|
|
36
|
-
*/
|
|
37
|
-
export async function createCart(brandSlug: string) {
|
|
38
|
-
const clients = createRpcClients(API_URL);
|
|
39
|
-
const res = await clients.carts.index.$post({
|
|
40
|
-
json: { brandSlug },
|
|
41
|
-
});
|
|
42
|
-
if (!res.ok) {
|
|
43
|
-
throw new Error(`Failed to create cart: ${res.statusText}`);
|
|
44
|
-
}
|
|
45
|
-
return res.json();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Update a cart
|
|
50
|
-
*
|
|
51
|
-
* @param cartId - Cart UUID
|
|
52
|
-
* @param data - Cart update data (customer info, deliveryZoneId, etc.)
|
|
53
|
-
* @returns Updated cart
|
|
54
|
-
*/
|
|
55
|
-
export async function updateCart(
|
|
56
|
-
cartId: string,
|
|
57
|
-
data: {
|
|
58
|
-
customerPhone?: string | null;
|
|
59
|
-
customerEmail?: string | null;
|
|
60
|
-
customerFirstName?: string | null;
|
|
61
|
-
customerLastName?: string | null;
|
|
62
|
-
deliveryZoneId?: string | null;
|
|
63
|
-
ifUnmodifiedSince?: string;
|
|
64
|
-
}
|
|
65
|
-
) {
|
|
66
|
-
const clients = createRpcClients(API_URL);
|
|
67
|
-
const res = await clients.carts[':id'].$patch({
|
|
68
|
-
param: { id: cartId },
|
|
69
|
-
json: data,
|
|
70
|
-
});
|
|
71
|
-
if (!res.ok) {
|
|
72
|
-
throw new Error(`Failed to update cart: ${res.statusText}`);
|
|
73
|
-
}
|
|
74
|
-
return res.json();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Add an item to cart
|
|
79
|
-
*
|
|
80
|
-
* @param cartId - Cart UUID
|
|
81
|
-
* @param sku - Product variant SKU
|
|
82
|
-
* @param quantity - Quantity to add
|
|
83
|
-
* @returns Updated cart
|
|
84
|
-
*/
|
|
85
|
-
export async function addCartItem(cartId: string, sku: string, quantity: number) {
|
|
86
|
-
const clients = createRpcClients(API_URL);
|
|
87
|
-
const res = await clients.carts[':id'].items.$post({
|
|
88
|
-
param: { id: cartId },
|
|
89
|
-
json: { sku, quantity },
|
|
90
|
-
});
|
|
91
|
-
if (!res.ok) {
|
|
92
|
-
throw new Error(`Failed to add item to cart: ${res.statusText}`);
|
|
93
|
-
}
|
|
94
|
-
return res.json();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Update a cart item quantity
|
|
99
|
-
*
|
|
100
|
-
* @param cartId - Cart UUID
|
|
101
|
-
* @param itemId - Cart item UUID
|
|
102
|
-
* @param quantity - New quantity
|
|
103
|
-
* @returns Updated cart
|
|
104
|
-
*/
|
|
105
|
-
export async function updateCartItem(cartId: string, itemId: string, quantity: number) {
|
|
106
|
-
const clients = createRpcClients(API_URL);
|
|
107
|
-
const res = await clients.carts[':id'].items[':itemId'].$patch({
|
|
108
|
-
param: { id: cartId, itemId },
|
|
109
|
-
json: { quantity },
|
|
110
|
-
});
|
|
111
|
-
if (!res.ok) {
|
|
112
|
-
throw new Error(`Failed to update cart item: ${res.statusText}`);
|
|
113
|
-
}
|
|
114
|
-
return res.json();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Remove an item from cart
|
|
119
|
-
*
|
|
120
|
-
* @param cartId - Cart UUID
|
|
121
|
-
* @param itemId - Cart item UUID
|
|
122
|
-
* @returns Updated cart
|
|
123
|
-
*/
|
|
124
|
-
export async function removeCartItem(cartId: string, itemId: string) {
|
|
125
|
-
const clients = createRpcClients(API_URL);
|
|
126
|
-
const res = await clients.carts[':id'].items[':itemId'].$delete({
|
|
127
|
-
param: { id: cartId, itemId },
|
|
128
|
-
});
|
|
129
|
-
if (!res.ok) {
|
|
130
|
-
throw new Error(`Failed to remove cart item: ${res.statusText}`);
|
|
131
|
-
}
|
|
132
|
-
return res.json();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Apply a discount code to cart
|
|
137
|
-
*
|
|
138
|
-
* @param cartId - Cart UUID
|
|
139
|
-
* @param code - Discount code
|
|
140
|
-
* @returns Updated cart
|
|
141
|
-
*/
|
|
142
|
-
export async function applyDiscount(cartId: string, code: string) {
|
|
143
|
-
const clients = createRpcClients(API_URL);
|
|
144
|
-
const res = await clients.carts[':id']['apply-discount'].$post({
|
|
145
|
-
param: { id: cartId },
|
|
146
|
-
json: { code },
|
|
147
|
-
});
|
|
148
|
-
if (!res.ok) {
|
|
149
|
-
throw new Error(`Failed to apply discount: ${res.statusText}`);
|
|
150
|
-
}
|
|
151
|
-
return res.json();
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Remove discount from cart
|
|
156
|
-
*
|
|
157
|
-
* @param cartId - Cart UUID
|
|
158
|
-
* @returns Updated cart
|
|
159
|
-
*/
|
|
160
|
-
export async function removeDiscount(cartId: string) {
|
|
161
|
-
const clients = createRpcClients(API_URL);
|
|
162
|
-
const res = await clients.carts[':id']['remove-discount'].$post({
|
|
163
|
-
param: { id: cartId },
|
|
164
|
-
});
|
|
165
|
-
if (!res.ok) {
|
|
166
|
-
throw new Error(`Failed to remove discount: ${res.statusText}`);
|
|
167
|
-
}
|
|
168
|
-
return res.json();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Checkout a cart
|
|
173
|
-
*
|
|
174
|
-
* @param cartId - Cart UUID
|
|
175
|
-
* @param checkoutData - Checkout information (customer details, delivery, payment)
|
|
176
|
-
* @returns Created order
|
|
177
|
-
*/
|
|
178
|
-
export async function checkoutCart(
|
|
179
|
-
cartId: string,
|
|
180
|
-
checkoutData: {
|
|
181
|
-
firstName: string;
|
|
182
|
-
lastName: string;
|
|
183
|
-
phone?: string;
|
|
184
|
-
email?: string;
|
|
185
|
-
address: string;
|
|
186
|
-
city: string;
|
|
187
|
-
deliveryZoneId: string;
|
|
188
|
-
paymentMethod: 'cod' | 'online';
|
|
189
|
-
paystackReference?: string;
|
|
190
|
-
ifUnmodifiedSince?: string;
|
|
191
|
-
}
|
|
192
|
-
) {
|
|
193
|
-
const clients = createRpcClients(API_URL);
|
|
194
|
-
const res = await clients.carts[':id'].checkout.$post({
|
|
195
|
-
param: { id: cartId },
|
|
196
|
-
json: checkoutData,
|
|
197
|
-
});
|
|
198
|
-
if (!res.ok) {
|
|
199
|
-
throw new Error(`Failed to checkout cart: ${res.statusText}`);
|
|
200
|
-
}
|
|
201
|
-
return res.json();
|
|
202
|
-
}
|
package/src/fetchers/orders.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Order fetcher functions
|
|
3
|
-
*
|
|
4
|
-
* These are the actual data-fetching functions used by hooks.
|
|
5
|
-
* They can also be imported directly in Server Components.
|
|
6
|
-
*
|
|
7
|
-
* API URL is hardcoded to https://oms-api.instock.ng
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { createRpcClients } from '../rpc-client';
|
|
11
|
-
|
|
12
|
-
const API_URL = 'https://oms-api.instock.ng';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Fetch an order by ID and token
|
|
16
|
-
*
|
|
17
|
-
* @param orderId - Order UUID
|
|
18
|
-
* @param token - User action token
|
|
19
|
-
* @returns Order with items, delivery zone, and brand
|
|
20
|
-
*/
|
|
21
|
-
export async function fetchOrder(orderId: string, token: string) {
|
|
22
|
-
const clients = createRpcClients(API_URL);
|
|
23
|
-
const res = await clients.orders[':id'][':token'].$get({
|
|
24
|
-
param: { id: orderId, token },
|
|
25
|
-
});
|
|
26
|
-
if (!res.ok) {
|
|
27
|
-
throw new Error(`Failed to fetch order: ${res.statusText}`);
|
|
28
|
-
}
|
|
29
|
-
return res.json();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Confirm a prospect order
|
|
34
|
-
*
|
|
35
|
-
* @param orderId - Order UUID
|
|
36
|
-
* @param token - User action token
|
|
37
|
-
* @returns Confirmed order
|
|
38
|
-
*/
|
|
39
|
-
export async function confirmOrder(orderId: string, token: string) {
|
|
40
|
-
const clients = createRpcClients(API_URL);
|
|
41
|
-
const res = await clients.orders.confirm.$post({
|
|
42
|
-
json: { orderId, token },
|
|
43
|
-
});
|
|
44
|
-
if (!res.ok) {
|
|
45
|
-
throw new Error(`Failed to confirm order: ${res.statusText}`);
|
|
46
|
-
}
|
|
47
|
-
return res.json();
|
|
48
|
-
}
|
package/src/fetchers/products.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Product fetcher functions
|
|
3
|
-
*
|
|
4
|
-
* These are the actual data-fetching functions used by hooks.
|
|
5
|
-
* They can also be imported directly in Server Components.
|
|
6
|
-
*
|
|
7
|
-
* API URL is hardcoded to https://oms-api.instock.ng
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { createRpcClients } from '../rpc-client';
|
|
11
|
-
|
|
12
|
-
const API_URL = 'https://oms-api.instock.ng';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Fetch products by brand ID
|
|
16
|
-
*
|
|
17
|
-
* @param brandId - Brand UUID
|
|
18
|
-
* @returns Products for the brand with variants and availability
|
|
19
|
-
*/
|
|
20
|
-
export async function fetchProductsByBrand(brandId: string) {
|
|
21
|
-
const clients = createRpcClients(API_URL);
|
|
22
|
-
const res = await clients.products[':brandId'].$get({
|
|
23
|
-
param: { brandId },
|
|
24
|
-
});
|
|
25
|
-
if (!res.ok) {
|
|
26
|
-
throw new Error(`Failed to fetch products: ${res.statusText}`);
|
|
27
|
-
}
|
|
28
|
-
return res.json();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Fetch a single product by slug
|
|
33
|
-
*
|
|
34
|
-
* @param slug - Product slug (e.g., 'cotton-t-shirt')
|
|
35
|
-
* @returns Product with variants and availability
|
|
36
|
-
*/
|
|
37
|
-
export async function fetchProductBySlug(slug: string) {
|
|
38
|
-
const clients = createRpcClients(API_URL);
|
|
39
|
-
const res = await clients.products.product[':slug'].$get({
|
|
40
|
-
param: { slug },
|
|
41
|
-
});
|
|
42
|
-
if (!res.ok) {
|
|
43
|
-
throw new Error(`Failed to fetch product: ${res.statusText}`);
|
|
44
|
-
}
|
|
45
|
-
return res.json();
|
|
46
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe admin RPC hooks for abandoned cart 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 abandoned carts using admin RPC
|
|
13
|
-
*/
|
|
14
|
-
export function useListAbandonedCarts(
|
|
15
|
-
params?: { brandId?: string; hoursInactive?: number },
|
|
16
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['abandonedCarts']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
17
|
-
) {
|
|
18
|
-
const { baseURL, authToken } = useApiConfig();
|
|
19
|
-
|
|
20
|
-
return useQueryUnwrapped({
|
|
21
|
-
queryKey: queryKeys.admin.abandonedCarts.list(params),
|
|
22
|
-
queryFn: async () => {
|
|
23
|
-
const clients = createAdminRpcClients(baseURL);
|
|
24
|
-
const res = await clients.abandonedCarts.index.$get({ query: params as any }, authHeaders(authToken));
|
|
25
|
-
if (!res.ok) throw new Error(`Failed to fetch abandoned carts: ${res.statusText}`);
|
|
26
|
-
return res.json();
|
|
27
|
-
},
|
|
28
|
-
...options,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Hook to get abandoned cart statistics using admin RPC
|
|
34
|
-
*/
|
|
35
|
-
export function useGetAbandonedCartStats(
|
|
36
|
-
params?: { brandId?: string },
|
|
37
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['abandonedCarts']['stats']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
38
|
-
) {
|
|
39
|
-
const { baseURL, authToken } = useApiConfig();
|
|
40
|
-
|
|
41
|
-
return useQueryUnwrapped({
|
|
42
|
-
queryKey: queryKeys.admin.abandonedCarts.stats(params?.brandId),
|
|
43
|
-
queryFn: async () => {
|
|
44
|
-
const clients = createAdminRpcClients(baseURL);
|
|
45
|
-
const res = await clients.abandonedCarts.stats.$get({ query: params }, authHeaders(authToken));
|
|
46
|
-
if (!res.ok) throw new Error(`Failed to fetch abandoned cart stats: ${res.statusText}`);
|
|
47
|
-
return res.json();
|
|
48
|
-
},
|
|
49
|
-
...options,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Hook to get specific abandoned cart details using admin RPC
|
|
55
|
-
*/
|
|
56
|
-
export function useGetAbandonedCart(
|
|
57
|
-
cartId: string,
|
|
58
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['abandonedCarts'][':id']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
59
|
-
) {
|
|
60
|
-
const { baseURL, authToken } = useApiConfig();
|
|
61
|
-
|
|
62
|
-
return useQueryUnwrapped({
|
|
63
|
-
queryKey: queryKeys.admin.abandonedCarts.detail(cartId),
|
|
64
|
-
queryFn: async () => {
|
|
65
|
-
const clients = createAdminRpcClients(baseURL);
|
|
66
|
-
const res = await clients.abandonedCarts[':id'].$get(
|
|
67
|
-
{ param: { id: cartId } },
|
|
68
|
-
authHeaders(authToken)
|
|
69
|
-
);
|
|
70
|
-
if (!res.ok) throw new Error(`Failed to fetch abandoned cart: ${res.statusText}`);
|
|
71
|
-
return res.json();
|
|
72
|
-
},
|
|
73
|
-
...options,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Hook to clean up expired carts using admin RPC
|
|
79
|
-
*/
|
|
80
|
-
export function useCleanupExpiredCarts(
|
|
81
|
-
options?: UseMutationOptions<
|
|
82
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['abandonedCarts']['cleanup']['$post']>>['json']>>,
|
|
83
|
-
Error,
|
|
84
|
-
void
|
|
85
|
-
>
|
|
86
|
-
) {
|
|
87
|
-
const { baseURL, authToken } = useApiConfig();
|
|
88
|
-
const queryClient = useQueryClient();
|
|
89
|
-
|
|
90
|
-
return useMutation({
|
|
91
|
-
mutationFn: async () => {
|
|
92
|
-
const clients = createAdminRpcClients(baseURL);
|
|
93
|
-
const res = await clients.abandonedCarts.cleanup.$post({}, authHeaders(authToken));
|
|
94
|
-
if (!res.ok) throw new Error(`Failed to cleanup expired carts: ${res.statusText}`);
|
|
95
|
-
return res.json();
|
|
96
|
-
},
|
|
97
|
-
onSuccess: () => {
|
|
98
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.abandonedCarts.all });
|
|
99
|
-
},
|
|
100
|
-
...options,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe admin RPC hooks for brand management
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { useMutation, useQueryClient, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
6
|
-
import { useQueryUnwrapped } from '../use-query-unwrapped';
|
|
7
|
-
import { createAdminRpcClients, authHeaders } from '../../rpc-client';
|
|
8
|
-
import { queryKeys } from '../../utils/query-keys';
|
|
9
|
-
import { useApiConfig } from '../useApiConfig';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Hook to list all brands using admin RPC
|
|
13
|
-
*/
|
|
14
|
-
export function useListBrands(
|
|
15
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['brands']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
16
|
-
) {
|
|
17
|
-
const { baseURL, authToken } = useApiConfig();
|
|
18
|
-
|
|
19
|
-
return useQueryUnwrapped({
|
|
20
|
-
queryKey: queryKeys.admin.brands.list(),
|
|
21
|
-
queryFn: async () => {
|
|
22
|
-
const clients = createAdminRpcClients(baseURL);
|
|
23
|
-
const res = await clients.brands.index.$get({}, authHeaders(authToken));
|
|
24
|
-
if (!res.ok) throw new Error(`Failed to fetch brands: ${res.statusText}`);
|
|
25
|
-
return res.json();
|
|
26
|
-
},
|
|
27
|
-
...options,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Hook to get brand by ID using admin RPC
|
|
33
|
-
*/
|
|
34
|
-
export function useGetBrand(
|
|
35
|
-
brandId: string,
|
|
36
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['brands'][':id']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
37
|
-
) {
|
|
38
|
-
const { baseURL, authToken } = useApiConfig();
|
|
39
|
-
|
|
40
|
-
return useQueryUnwrapped({
|
|
41
|
-
queryKey: queryKeys.admin.brands.detail(brandId),
|
|
42
|
-
queryFn: async () => {
|
|
43
|
-
const clients = createAdminRpcClients(baseURL);
|
|
44
|
-
const res = await clients.brands[':id'].$get({ param: { id: brandId } }, authHeaders(authToken));
|
|
45
|
-
if (!res.ok) throw new Error(`Failed to fetch brand: ${res.statusText}`);
|
|
46
|
-
return res.json();
|
|
47
|
-
},
|
|
48
|
-
...options,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Hook to create a brand using admin RPC
|
|
54
|
-
*/
|
|
55
|
-
export function useCreateBrand(
|
|
56
|
-
options?: UseMutationOptions<
|
|
57
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['brands']['index']['$post']>>['json']>>,
|
|
58
|
-
Error,
|
|
59
|
-
any
|
|
60
|
-
>
|
|
61
|
-
) {
|
|
62
|
-
const { baseURL, authToken } = useApiConfig();
|
|
63
|
-
const queryClient = useQueryClient();
|
|
64
|
-
|
|
65
|
-
return useMutation({
|
|
66
|
-
mutationFn: async (data) => {
|
|
67
|
-
const clients = createAdminRpcClients(baseURL);
|
|
68
|
-
const res = await clients.brands.index.$post({ json: data }, authHeaders(authToken));
|
|
69
|
-
if (!res.ok) throw new Error(`Failed to create brand: ${res.statusText}`);
|
|
70
|
-
return res.json();
|
|
71
|
-
},
|
|
72
|
-
onSuccess: () => {
|
|
73
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.brands.all });
|
|
74
|
-
},
|
|
75
|
-
...options,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Hook to update a brand using admin RPC
|
|
81
|
-
*/
|
|
82
|
-
export function useUpdateBrand(
|
|
83
|
-
brandId: string,
|
|
84
|
-
options?: UseMutationOptions<
|
|
85
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['brands'][':id']['$patch']>>['json']>>,
|
|
86
|
-
Error,
|
|
87
|
-
any
|
|
88
|
-
>
|
|
89
|
-
) {
|
|
90
|
-
const { baseURL, authToken } = useApiConfig();
|
|
91
|
-
const queryClient = useQueryClient();
|
|
92
|
-
|
|
93
|
-
return useMutation({
|
|
94
|
-
mutationFn: async (data) => {
|
|
95
|
-
const clients = createAdminRpcClients(baseURL);
|
|
96
|
-
const res = await clients.brands[':id'].$patch({ json: data, param: { id: brandId } }, authHeaders(authToken));
|
|
97
|
-
if (!res.ok) throw new Error(`Failed to update brand: ${res.statusText}`);
|
|
98
|
-
return res.json();
|
|
99
|
-
},
|
|
100
|
-
onSuccess: () => {
|
|
101
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.brands.detail(brandId) });
|
|
102
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.brands.all });
|
|
103
|
-
},
|
|
104
|
-
...options,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Hook to delete a brand using admin RPC
|
|
110
|
-
*/
|
|
111
|
-
export function useDeleteBrand(
|
|
112
|
-
brandId: string,
|
|
113
|
-
options?: UseMutationOptions<
|
|
114
|
-
Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['brands'][':id']['$delete']>>['json']>>,
|
|
115
|
-
Error,
|
|
116
|
-
void
|
|
117
|
-
>
|
|
118
|
-
) {
|
|
119
|
-
const { baseURL, authToken } = useApiConfig();
|
|
120
|
-
const queryClient = useQueryClient();
|
|
121
|
-
|
|
122
|
-
return useMutation({
|
|
123
|
-
mutationFn: async () => {
|
|
124
|
-
const clients = createAdminRpcClients(baseURL);
|
|
125
|
-
const res = await clients.brands[':id'].$delete({ param: { id: brandId } }, authHeaders(authToken));
|
|
126
|
-
if (!res.ok) throw new Error(`Failed to delete brand: ${res.statusText}`);
|
|
127
|
-
return res.json();
|
|
128
|
-
},
|
|
129
|
-
onSuccess: () => {
|
|
130
|
-
queryClient.invalidateQueries({ queryKey: queryKeys.admin.brands.all });
|
|
131
|
-
},
|
|
132
|
-
...options,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe admin RPC hooks for customer management
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { UseQueryOptions } from '@tanstack/react-query';
|
|
6
|
-
import { useQueryUnwrapped } from '../use-query-unwrapped';
|
|
7
|
-
import { createAdminRpcClients, authHeaders } from '../../rpc-client';
|
|
8
|
-
import { queryKeys } from '../../utils/query-keys';
|
|
9
|
-
import { useApiConfig } from '../useApiConfig';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Hook to get customer order history by phone using admin RPC
|
|
13
|
-
*/
|
|
14
|
-
export function useGetCustomerHistory(
|
|
15
|
-
phone: string,
|
|
16
|
-
options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['customers']['history']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>
|
|
17
|
-
) {
|
|
18
|
-
const { baseURL, authToken } = useApiConfig();
|
|
19
|
-
|
|
20
|
-
return useQueryUnwrapped({
|
|
21
|
-
queryKey: queryKeys.admin.customers.history(phone),
|
|
22
|
-
queryFn: async () => {
|
|
23
|
-
const clients = createAdminRpcClients(baseURL);
|
|
24
|
-
const res = await clients.customers.history.$get({ query: { phone } }, authHeaders(authToken));
|
|
25
|
-
if (!res.ok) throw new Error(`Failed to fetch customer history: ${res.statusText}`);
|
|
26
|
-
return res.json();
|
|
27
|
-
},
|
|
28
|
-
enabled: !!phone,
|
|
29
|
-
...options,
|
|
30
|
-
});
|
|
31
|
-
}
|