@instockng/api-client 1.0.5 → 1.0.7
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/apps/backend/src/lib/meta-capi.d.ts +1 -1
- package/dist/apps/backend/src/lib/meta-capi.js +1 -1
- package/dist/apps/backend/src/lib/order-recovery.d.ts +86 -0
- package/dist/apps/backend/src/lib/order-recovery.js +7 -2
- package/dist/apps/backend/src/notifications/producers/meta-capi-producer.d.ts +7 -0
- package/dist/apps/backend/src/notifications/producers/meta-capi-producer.js +41 -0
- package/dist/apps/backend/src/routes/admin/orders.d.ts +310 -20
- package/dist/apps/backend/src/routes/admin/orders.js +26 -2
- package/dist/apps/backend/src/routes/public/orders.d.ts +288 -6
- package/dist/apps/backend/src/routes/public/orders.js +1 -1
- package/dist/apps/backend/src/validators/order.d.ts +6 -37
- package/dist/apps/backend/src/validators/order.js +6 -7
- package/dist/enum-types.d.ts +8 -0
- package/dist/enum-types.js +5 -0
- package/dist/fetchers/carts.js +5 -0
- package/dist/fetchers/orders.d.ts +258 -1
- package/dist/hooks/admin/abandoned-carts.js +12 -8
- package/dist/hooks/admin/brands.js +15 -10
- package/dist/hooks/admin/customers.js +3 -2
- package/dist/hooks/admin/delivery-zones.js +24 -16
- package/dist/hooks/admin/discount-codes.js +24 -16
- package/dist/hooks/admin/inventory.js +15 -10
- package/dist/hooks/admin/orders.d.ts +285 -3
- package/dist/hooks/admin/orders.js +24 -15
- package/dist/hooks/admin/products.js +15 -10
- package/dist/hooks/admin/stats.js +3 -2
- package/dist/hooks/admin/variants.js +18 -12
- package/dist/hooks/admin/warehouses.js +15 -10
- package/dist/hooks/public/orders.d.ts +258 -1
- package/dist/hooks/useApiConfig.d.ts +2 -1
- package/dist/hooks/useApiConfig.js +2 -2
- package/dist/packages/api-client/src/enum-types.d.ts +8 -0
- package/dist/packages/api-client/src/enum-types.js +5 -0
- package/dist/packages/api-client/src/fetchers/carts.js +5 -0
- package/dist/packages/api-client/src/fetchers/orders.d.ts +258 -1
- package/dist/packages/api-client/src/hooks/admin/orders.d.ts +285 -3
- package/dist/packages/api-client/src/hooks/admin/orders.js +7 -4
- package/dist/packages/api-client/src/hooks/public/orders.d.ts +258 -1
- package/dist/packages/api-client/src/rpc-client.d.ts +891 -319
- package/dist/packages/api-client/src/types.d.ts +1 -4
- package/dist/packages/api-client/src/utils/query-keys.d.ts +1 -1
- package/dist/packages/api-client/src/utils/query-keys.js +1 -1
- package/dist/provider.d.ts +7 -4
- package/dist/provider.js +5 -3
- package/dist/rpc-client.d.ts +891 -319
- package/dist/types.d.ts +1 -0
- package/dist/utils/query-keys.d.ts +1 -1
- package/dist/utils/query-keys.js +1 -1
- package/package.json +1 -1
|
@@ -280,4 +280,261 @@ export declare function fetchOrder(orderId: string, token: string): Promise<{
|
|
|
280
280
|
* @param token - User action token
|
|
281
281
|
* @returns Confirmed order
|
|
282
282
|
*/
|
|
283
|
-
export declare function confirmOrder(orderId: string, token: string): Promise<
|
|
283
|
+
export declare function confirmOrder(orderId: string, token: string): Promise<{
|
|
284
|
+
subtotal: number;
|
|
285
|
+
deliveryCharge: number;
|
|
286
|
+
totalPrice: number;
|
|
287
|
+
discountAmount: number;
|
|
288
|
+
createdAt: string;
|
|
289
|
+
updatedAt: string;
|
|
290
|
+
deletedAt: string;
|
|
291
|
+
prospectSince: string;
|
|
292
|
+
lastRecoveryAttemptAt: string;
|
|
293
|
+
brand: {
|
|
294
|
+
createdAt: string;
|
|
295
|
+
updatedAt: string;
|
|
296
|
+
deletedAt: string;
|
|
297
|
+
name: string;
|
|
298
|
+
id: string;
|
|
299
|
+
slug: string;
|
|
300
|
+
logoUrl: string | null;
|
|
301
|
+
siteUrl: string;
|
|
302
|
+
domain: string;
|
|
303
|
+
metaPixelId: string | null;
|
|
304
|
+
};
|
|
305
|
+
deliveryZone: {
|
|
306
|
+
deliveryCost: number;
|
|
307
|
+
freeShippingThreshold: number;
|
|
308
|
+
createdAt: string;
|
|
309
|
+
updatedAt: string;
|
|
310
|
+
deletedAt: string;
|
|
311
|
+
state: {
|
|
312
|
+
createdAt: string;
|
|
313
|
+
updatedAt: string;
|
|
314
|
+
deletedAt: string;
|
|
315
|
+
name: string;
|
|
316
|
+
id: string;
|
|
317
|
+
isActive: boolean;
|
|
318
|
+
};
|
|
319
|
+
name: string;
|
|
320
|
+
id: string;
|
|
321
|
+
brandId: string | null;
|
|
322
|
+
stateId: string;
|
|
323
|
+
allowCOD: boolean;
|
|
324
|
+
allowOnline: boolean;
|
|
325
|
+
waybillOnly: boolean;
|
|
326
|
+
estimatedDays: number | null;
|
|
327
|
+
isActive: boolean;
|
|
328
|
+
};
|
|
329
|
+
items: {
|
|
330
|
+
priceAtPurchase: number;
|
|
331
|
+
variant: {
|
|
332
|
+
price: number;
|
|
333
|
+
createdAt: string;
|
|
334
|
+
updatedAt: string;
|
|
335
|
+
deletedAt: string;
|
|
336
|
+
product: {
|
|
337
|
+
createdAt: string;
|
|
338
|
+
updatedAt: string;
|
|
339
|
+
deletedAt: string;
|
|
340
|
+
name: string;
|
|
341
|
+
id: string;
|
|
342
|
+
slug: string;
|
|
343
|
+
brandId: string;
|
|
344
|
+
isActive: boolean;
|
|
345
|
+
description: string | null;
|
|
346
|
+
thumbnailUrl: string | null;
|
|
347
|
+
quantityDiscounts: string | number | boolean | {
|
|
348
|
+
[x: string]: string | number | boolean | /*elided*/ any | {
|
|
349
|
+
[x: number]: string | number | boolean | /*elided*/ any | /*elided*/ any;
|
|
350
|
+
length: number;
|
|
351
|
+
toString: never;
|
|
352
|
+
toLocaleString: never;
|
|
353
|
+
pop: never;
|
|
354
|
+
push: never;
|
|
355
|
+
concat: never;
|
|
356
|
+
join: never;
|
|
357
|
+
reverse: never;
|
|
358
|
+
shift: never;
|
|
359
|
+
slice: never;
|
|
360
|
+
sort: never;
|
|
361
|
+
splice: never;
|
|
362
|
+
unshift: never;
|
|
363
|
+
indexOf: never;
|
|
364
|
+
lastIndexOf: never;
|
|
365
|
+
every: never;
|
|
366
|
+
some: never;
|
|
367
|
+
forEach: never;
|
|
368
|
+
map: never;
|
|
369
|
+
filter: never;
|
|
370
|
+
reduce: never;
|
|
371
|
+
reduceRight: never;
|
|
372
|
+
find: never;
|
|
373
|
+
findIndex: never;
|
|
374
|
+
fill: never;
|
|
375
|
+
copyWithin: never;
|
|
376
|
+
entries: never;
|
|
377
|
+
keys: never;
|
|
378
|
+
values: never;
|
|
379
|
+
includes: never;
|
|
380
|
+
flatMap: never;
|
|
381
|
+
flat: never;
|
|
382
|
+
[Symbol.iterator]: never;
|
|
383
|
+
readonly [Symbol.unscopables]: {
|
|
384
|
+
[x: number]: boolean;
|
|
385
|
+
length?: boolean;
|
|
386
|
+
toString?: boolean;
|
|
387
|
+
toLocaleString?: boolean;
|
|
388
|
+
pop?: boolean;
|
|
389
|
+
push?: boolean;
|
|
390
|
+
concat?: boolean;
|
|
391
|
+
join?: boolean;
|
|
392
|
+
reverse?: boolean;
|
|
393
|
+
shift?: boolean;
|
|
394
|
+
slice?: boolean;
|
|
395
|
+
sort?: boolean;
|
|
396
|
+
splice?: boolean;
|
|
397
|
+
unshift?: boolean;
|
|
398
|
+
indexOf?: boolean;
|
|
399
|
+
lastIndexOf?: boolean;
|
|
400
|
+
every?: boolean;
|
|
401
|
+
some?: boolean;
|
|
402
|
+
forEach?: boolean;
|
|
403
|
+
map?: boolean;
|
|
404
|
+
filter?: boolean;
|
|
405
|
+
reduce?: boolean;
|
|
406
|
+
reduceRight?: boolean;
|
|
407
|
+
find?: boolean;
|
|
408
|
+
findIndex?: boolean;
|
|
409
|
+
fill?: boolean;
|
|
410
|
+
copyWithin?: boolean;
|
|
411
|
+
entries?: boolean;
|
|
412
|
+
keys?: boolean;
|
|
413
|
+
values?: boolean;
|
|
414
|
+
includes?: boolean;
|
|
415
|
+
flatMap?: boolean;
|
|
416
|
+
flat?: boolean;
|
|
417
|
+
};
|
|
418
|
+
};
|
|
419
|
+
} | {
|
|
420
|
+
[x: number]: string | number | boolean | {
|
|
421
|
+
[x: string]: string | number | boolean | /*elided*/ any | /*elided*/ any;
|
|
422
|
+
} | /*elided*/ any;
|
|
423
|
+
length: number;
|
|
424
|
+
toString: never;
|
|
425
|
+
toLocaleString: never;
|
|
426
|
+
pop: never;
|
|
427
|
+
push: never;
|
|
428
|
+
concat: never;
|
|
429
|
+
join: never;
|
|
430
|
+
reverse: never;
|
|
431
|
+
shift: never;
|
|
432
|
+
slice: never;
|
|
433
|
+
sort: never;
|
|
434
|
+
splice: never;
|
|
435
|
+
unshift: never;
|
|
436
|
+
indexOf: never;
|
|
437
|
+
lastIndexOf: never;
|
|
438
|
+
every: never;
|
|
439
|
+
some: never;
|
|
440
|
+
forEach: never;
|
|
441
|
+
map: never;
|
|
442
|
+
filter: never;
|
|
443
|
+
reduce: never;
|
|
444
|
+
reduceRight: never;
|
|
445
|
+
find: never;
|
|
446
|
+
findIndex: never;
|
|
447
|
+
fill: never;
|
|
448
|
+
copyWithin: never;
|
|
449
|
+
entries: never;
|
|
450
|
+
keys: never;
|
|
451
|
+
values: never;
|
|
452
|
+
includes: never;
|
|
453
|
+
flatMap: never;
|
|
454
|
+
flat: never;
|
|
455
|
+
[Symbol.iterator]: never;
|
|
456
|
+
readonly [Symbol.unscopables]: {
|
|
457
|
+
[x: number]: boolean;
|
|
458
|
+
length?: boolean;
|
|
459
|
+
toString?: boolean;
|
|
460
|
+
toLocaleString?: boolean;
|
|
461
|
+
pop?: boolean;
|
|
462
|
+
push?: boolean;
|
|
463
|
+
concat?: boolean;
|
|
464
|
+
join?: boolean;
|
|
465
|
+
reverse?: boolean;
|
|
466
|
+
shift?: boolean;
|
|
467
|
+
slice?: boolean;
|
|
468
|
+
sort?: boolean;
|
|
469
|
+
splice?: boolean;
|
|
470
|
+
unshift?: boolean;
|
|
471
|
+
indexOf?: boolean;
|
|
472
|
+
lastIndexOf?: boolean;
|
|
473
|
+
every?: boolean;
|
|
474
|
+
some?: boolean;
|
|
475
|
+
forEach?: boolean;
|
|
476
|
+
map?: boolean;
|
|
477
|
+
filter?: boolean;
|
|
478
|
+
reduce?: boolean;
|
|
479
|
+
reduceRight?: boolean;
|
|
480
|
+
find?: boolean;
|
|
481
|
+
findIndex?: boolean;
|
|
482
|
+
fill?: boolean;
|
|
483
|
+
copyWithin?: boolean;
|
|
484
|
+
entries?: boolean;
|
|
485
|
+
keys?: boolean;
|
|
486
|
+
values?: boolean;
|
|
487
|
+
includes?: boolean;
|
|
488
|
+
flatMap?: boolean;
|
|
489
|
+
flat?: boolean;
|
|
490
|
+
};
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
name: string | null;
|
|
494
|
+
id: string;
|
|
495
|
+
isActive: boolean;
|
|
496
|
+
thumbnailUrl: string | null;
|
|
497
|
+
productId: string;
|
|
498
|
+
sku: string;
|
|
499
|
+
trackInventory: boolean;
|
|
500
|
+
lowStockThreshold: number | null;
|
|
501
|
+
};
|
|
502
|
+
warehouse: {
|
|
503
|
+
createdAt: string;
|
|
504
|
+
updatedAt: string;
|
|
505
|
+
deletedAt: string;
|
|
506
|
+
name: string;
|
|
507
|
+
id: string;
|
|
508
|
+
isActive: boolean;
|
|
509
|
+
address: string | null;
|
|
510
|
+
city: string | null;
|
|
511
|
+
state: string | null;
|
|
512
|
+
};
|
|
513
|
+
id: string;
|
|
514
|
+
orderId: string;
|
|
515
|
+
variantId: string;
|
|
516
|
+
warehouseId: string | null;
|
|
517
|
+
quantity: number;
|
|
518
|
+
}[];
|
|
519
|
+
id: string;
|
|
520
|
+
email: string | null;
|
|
521
|
+
brandId: string;
|
|
522
|
+
deliveryZoneId: string;
|
|
523
|
+
recoveryAttempts: number;
|
|
524
|
+
recoveryDiscountCodeId: string | null;
|
|
525
|
+
wasRecovered: boolean;
|
|
526
|
+
estimatedDays: number | null;
|
|
527
|
+
orderNumber: number;
|
|
528
|
+
firstName: string;
|
|
529
|
+
lastName: string;
|
|
530
|
+
phone: string;
|
|
531
|
+
address: string;
|
|
532
|
+
city: string;
|
|
533
|
+
discountCodeId: string | null;
|
|
534
|
+
paymentMethod: import("@prisma/client").$Enums.PaymentMethod;
|
|
535
|
+
paystackReference: string | null;
|
|
536
|
+
status: import("@prisma/client").$Enums.OrderStatus;
|
|
537
|
+
cancellationReason: string | null;
|
|
538
|
+
prospectReason: import("@prisma/client").$Enums.ProspectReason | null;
|
|
539
|
+
userActionToken: string;
|
|
540
|
+
}>;
|
|
@@ -10,12 +10,13 @@ import { useApiConfig } from '../useApiConfig';
|
|
|
10
10
|
* Hook to list abandoned carts using admin RPC
|
|
11
11
|
*/
|
|
12
12
|
export function useListAbandonedCarts(params, options) {
|
|
13
|
-
const { baseURL,
|
|
13
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
14
14
|
return useQueryUnwrapped({
|
|
15
15
|
queryKey: queryKeys.admin.abandonedCarts.list(params),
|
|
16
16
|
queryFn: async () => {
|
|
17
|
+
const token = await getAuthToken();
|
|
17
18
|
const clients = createAdminRpcClients(baseURL);
|
|
18
|
-
const res = await clients.abandonedCarts.index.$get({ query: params }, authHeaders(
|
|
19
|
+
const res = await clients.abandonedCarts.index.$get({ query: params }, authHeaders(token));
|
|
19
20
|
if (!res.ok)
|
|
20
21
|
throw new Error(`Failed to fetch abandoned carts: ${res.statusText}`);
|
|
21
22
|
return res.json();
|
|
@@ -27,12 +28,13 @@ export function useListAbandonedCarts(params, options) {
|
|
|
27
28
|
* Hook to get abandoned cart statistics using admin RPC
|
|
28
29
|
*/
|
|
29
30
|
export function useGetAbandonedCartStats(params, options) {
|
|
30
|
-
const { baseURL,
|
|
31
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
31
32
|
return useQueryUnwrapped({
|
|
32
33
|
queryKey: queryKeys.admin.abandonedCarts.stats(params?.brandId),
|
|
33
34
|
queryFn: async () => {
|
|
35
|
+
const token = await getAuthToken();
|
|
34
36
|
const clients = createAdminRpcClients(baseURL);
|
|
35
|
-
const res = await clients.abandonedCarts.stats.$get({ query: params }, authHeaders(
|
|
37
|
+
const res = await clients.abandonedCarts.stats.$get({ query: params }, authHeaders(token));
|
|
36
38
|
if (!res.ok)
|
|
37
39
|
throw new Error(`Failed to fetch abandoned cart stats: ${res.statusText}`);
|
|
38
40
|
return res.json();
|
|
@@ -44,12 +46,13 @@ export function useGetAbandonedCartStats(params, options) {
|
|
|
44
46
|
* Hook to get specific abandoned cart details using admin RPC
|
|
45
47
|
*/
|
|
46
48
|
export function useGetAbandonedCart(cartId, options) {
|
|
47
|
-
const { baseURL,
|
|
49
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
48
50
|
return useQueryUnwrapped({
|
|
49
51
|
queryKey: queryKeys.admin.abandonedCarts.detail(cartId),
|
|
50
52
|
queryFn: async () => {
|
|
53
|
+
const token = await getAuthToken();
|
|
51
54
|
const clients = createAdminRpcClients(baseURL);
|
|
52
|
-
const res = await clients.abandonedCarts[':id'].$get({ param: { id: cartId } }, authHeaders(
|
|
55
|
+
const res = await clients.abandonedCarts[':id'].$get({ param: { id: cartId } }, authHeaders(token));
|
|
53
56
|
if (!res.ok)
|
|
54
57
|
throw new Error(`Failed to fetch abandoned cart: ${res.statusText}`);
|
|
55
58
|
return res.json();
|
|
@@ -61,12 +64,13 @@ export function useGetAbandonedCart(cartId, options) {
|
|
|
61
64
|
* Hook to clean up expired carts using admin RPC
|
|
62
65
|
*/
|
|
63
66
|
export function useCleanupExpiredCarts(options) {
|
|
64
|
-
const { baseURL,
|
|
67
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
65
68
|
const queryClient = useQueryClient();
|
|
66
69
|
return useMutation({
|
|
67
70
|
mutationFn: async () => {
|
|
71
|
+
const token = await getAuthToken();
|
|
68
72
|
const clients = createAdminRpcClients(baseURL);
|
|
69
|
-
const res = await clients.abandonedCarts.cleanup.$post({}, authHeaders(
|
|
73
|
+
const res = await clients.abandonedCarts.cleanup.$post({}, authHeaders(token));
|
|
70
74
|
if (!res.ok)
|
|
71
75
|
throw new Error(`Failed to cleanup expired carts: ${res.statusText}`);
|
|
72
76
|
return res.json();
|
|
@@ -10,12 +10,13 @@ import { useApiConfig } from '../useApiConfig';
|
|
|
10
10
|
* Hook to list all brands using admin RPC
|
|
11
11
|
*/
|
|
12
12
|
export function useListBrands(options) {
|
|
13
|
-
const { baseURL,
|
|
13
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
14
14
|
return useQueryUnwrapped({
|
|
15
15
|
queryKey: queryKeys.admin.brands.list(),
|
|
16
16
|
queryFn: async () => {
|
|
17
|
+
const token = await getAuthToken();
|
|
17
18
|
const clients = createAdminRpcClients(baseURL);
|
|
18
|
-
const res = await clients.brands.index.$get({}, authHeaders(
|
|
19
|
+
const res = await clients.brands.index.$get({}, authHeaders(token));
|
|
19
20
|
if (!res.ok)
|
|
20
21
|
throw new Error(`Failed to fetch brands: ${res.statusText}`);
|
|
21
22
|
return res.json();
|
|
@@ -27,12 +28,13 @@ export function useListBrands(options) {
|
|
|
27
28
|
* Hook to get brand by ID using admin RPC
|
|
28
29
|
*/
|
|
29
30
|
export function useGetBrand(brandId, options) {
|
|
30
|
-
const { baseURL,
|
|
31
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
31
32
|
return useQueryUnwrapped({
|
|
32
33
|
queryKey: queryKeys.admin.brands.detail(brandId),
|
|
33
34
|
queryFn: async () => {
|
|
35
|
+
const token = await getAuthToken();
|
|
34
36
|
const clients = createAdminRpcClients(baseURL);
|
|
35
|
-
const res = await clients.brands[':id'].$get({ param: { id: brandId } }, authHeaders(
|
|
37
|
+
const res = await clients.brands[':id'].$get({ param: { id: brandId } }, authHeaders(token));
|
|
36
38
|
if (!res.ok)
|
|
37
39
|
throw new Error(`Failed to fetch brand: ${res.statusText}`);
|
|
38
40
|
return res.json();
|
|
@@ -44,12 +46,13 @@ export function useGetBrand(brandId, options) {
|
|
|
44
46
|
* Hook to create a brand using admin RPC
|
|
45
47
|
*/
|
|
46
48
|
export function useCreateBrand(options) {
|
|
47
|
-
const { baseURL,
|
|
49
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
48
50
|
const queryClient = useQueryClient();
|
|
49
51
|
return useMutation({
|
|
50
52
|
mutationFn: async (data) => {
|
|
53
|
+
const token = await getAuthToken();
|
|
51
54
|
const clients = createAdminRpcClients(baseURL);
|
|
52
|
-
const res = await clients.brands.index.$post({ json: data }, authHeaders(
|
|
55
|
+
const res = await clients.brands.index.$post({ json: data }, authHeaders(token));
|
|
53
56
|
if (!res.ok)
|
|
54
57
|
throw new Error(`Failed to create brand: ${res.statusText}`);
|
|
55
58
|
return res.json();
|
|
@@ -64,12 +67,13 @@ export function useCreateBrand(options) {
|
|
|
64
67
|
* Hook to update a brand using admin RPC
|
|
65
68
|
*/
|
|
66
69
|
export function useUpdateBrand(brandId, options) {
|
|
67
|
-
const { baseURL,
|
|
70
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
68
71
|
const queryClient = useQueryClient();
|
|
69
72
|
return useMutation({
|
|
70
73
|
mutationFn: async (data) => {
|
|
74
|
+
const token = await getAuthToken();
|
|
71
75
|
const clients = createAdminRpcClients(baseURL);
|
|
72
|
-
const res = await clients.brands[':id'].$patch({ json: data, param: { id: brandId } }, authHeaders(
|
|
76
|
+
const res = await clients.brands[':id'].$patch({ json: data, param: { id: brandId } }, authHeaders(token));
|
|
73
77
|
if (!res.ok)
|
|
74
78
|
throw new Error(`Failed to update brand: ${res.statusText}`);
|
|
75
79
|
return res.json();
|
|
@@ -85,12 +89,13 @@ export function useUpdateBrand(brandId, options) {
|
|
|
85
89
|
* Hook to delete a brand using admin RPC
|
|
86
90
|
*/
|
|
87
91
|
export function useDeleteBrand(brandId, options) {
|
|
88
|
-
const { baseURL,
|
|
92
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
89
93
|
const queryClient = useQueryClient();
|
|
90
94
|
return useMutation({
|
|
91
95
|
mutationFn: async () => {
|
|
96
|
+
const token = await getAuthToken();
|
|
92
97
|
const clients = createAdminRpcClients(baseURL);
|
|
93
|
-
const res = await clients.brands[':id'].$delete({ param: { id: brandId } }, authHeaders(
|
|
98
|
+
const res = await clients.brands[':id'].$delete({ param: { id: brandId } }, authHeaders(token));
|
|
94
99
|
if (!res.ok)
|
|
95
100
|
throw new Error(`Failed to delete brand: ${res.statusText}`);
|
|
96
101
|
return res.json();
|
|
@@ -9,12 +9,13 @@ import { useApiConfig } from '../useApiConfig';
|
|
|
9
9
|
* Hook to get customer order history by phone using admin RPC
|
|
10
10
|
*/
|
|
11
11
|
export function useGetCustomerHistory(phone, options) {
|
|
12
|
-
const { baseURL,
|
|
12
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
13
13
|
return useQueryUnwrapped({
|
|
14
14
|
queryKey: queryKeys.admin.customers.history(phone),
|
|
15
15
|
queryFn: async () => {
|
|
16
|
+
const token = await getAuthToken();
|
|
16
17
|
const clients = createAdminRpcClients(baseURL);
|
|
17
|
-
const res = await clients.customers.history.$get({ query: { phone } }, authHeaders(
|
|
18
|
+
const res = await clients.customers.history.$get({ query: { phone } }, authHeaders(token));
|
|
18
19
|
if (!res.ok)
|
|
19
20
|
throw new Error(`Failed to fetch customer history: ${res.statusText}`);
|
|
20
21
|
return res.json();
|
|
@@ -11,12 +11,13 @@ import { useApiConfig } from '../useApiConfig';
|
|
|
11
11
|
* Hook to list all states using admin RPC
|
|
12
12
|
*/
|
|
13
13
|
export function useListStates(options) {
|
|
14
|
-
const { baseURL,
|
|
14
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
15
15
|
return useQueryUnwrapped({
|
|
16
16
|
queryKey: queryKeys.admin.deliveryZones.states.list(),
|
|
17
17
|
queryFn: async () => {
|
|
18
|
+
const token = await getAuthToken();
|
|
18
19
|
const clients = createAdminRpcClients(baseURL);
|
|
19
|
-
const res = await clients.deliveryZones.states.$get({}, authHeaders(
|
|
20
|
+
const res = await clients.deliveryZones.states.$get({}, authHeaders(token));
|
|
20
21
|
if (!res.ok)
|
|
21
22
|
throw new Error(`Failed to fetch states: ${res.statusText}`);
|
|
22
23
|
return res.json();
|
|
@@ -28,12 +29,13 @@ export function useListStates(options) {
|
|
|
28
29
|
* Hook to create a state using admin RPC
|
|
29
30
|
*/
|
|
30
31
|
export function useCreateState(options) {
|
|
31
|
-
const { baseURL,
|
|
32
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
32
33
|
const queryClient = useQueryClient();
|
|
33
34
|
return useMutation({
|
|
34
35
|
mutationFn: async (data) => {
|
|
36
|
+
const token = await getAuthToken();
|
|
35
37
|
const clients = createAdminRpcClients(baseURL);
|
|
36
|
-
const res = await clients.deliveryZones.states.$post({ json: data }, authHeaders(
|
|
38
|
+
const res = await clients.deliveryZones.states.$post({ json: data }, authHeaders(token));
|
|
37
39
|
if (!res.ok)
|
|
38
40
|
throw new Error(`Failed to create state: ${res.statusText}`);
|
|
39
41
|
return res.json();
|
|
@@ -48,12 +50,13 @@ export function useCreateState(options) {
|
|
|
48
50
|
* Hook to update a state using admin RPC
|
|
49
51
|
*/
|
|
50
52
|
export function useUpdateState(stateId, options) {
|
|
51
|
-
const { baseURL,
|
|
53
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
52
54
|
const queryClient = useQueryClient();
|
|
53
55
|
return useMutation({
|
|
54
56
|
mutationFn: async (data) => {
|
|
57
|
+
const token = await getAuthToken();
|
|
55
58
|
const clients = createAdminRpcClients(baseURL);
|
|
56
|
-
const res = await clients.deliveryZones.states[':id'].$patch({ json: data, param: { id: stateId } }, authHeaders(
|
|
59
|
+
const res = await clients.deliveryZones.states[':id'].$patch({ json: data, param: { id: stateId } }, authHeaders(token));
|
|
57
60
|
if (!res.ok)
|
|
58
61
|
throw new Error(`Failed to update state: ${res.statusText}`);
|
|
59
62
|
return res.json();
|
|
@@ -69,12 +72,13 @@ export function useUpdateState(stateId, options) {
|
|
|
69
72
|
* Hook to delete a state using admin RPC
|
|
70
73
|
*/
|
|
71
74
|
export function useDeleteState(stateId, options) {
|
|
72
|
-
const { baseURL,
|
|
75
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
73
76
|
const queryClient = useQueryClient();
|
|
74
77
|
return useMutation({
|
|
75
78
|
mutationFn: async () => {
|
|
79
|
+
const token = await getAuthToken();
|
|
76
80
|
const clients = createAdminRpcClients(baseURL);
|
|
77
|
-
const res = await clients.deliveryZones.states[':id'].$delete({ param: { id: stateId } }, authHeaders(
|
|
81
|
+
const res = await clients.deliveryZones.states[':id'].$delete({ param: { id: stateId } }, authHeaders(token));
|
|
78
82
|
if (!res.ok)
|
|
79
83
|
throw new Error(`Failed to delete state: ${res.statusText}`);
|
|
80
84
|
return res.json();
|
|
@@ -91,12 +95,13 @@ export function useDeleteState(stateId, options) {
|
|
|
91
95
|
* Hook to list delivery zones using admin RPC
|
|
92
96
|
*/
|
|
93
97
|
export function useListDeliveryZones(params, options) {
|
|
94
|
-
const { baseURL,
|
|
98
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
95
99
|
return useQueryUnwrapped({
|
|
96
100
|
queryKey: queryKeys.admin.deliveryZones.zones.list(params),
|
|
97
101
|
queryFn: async () => {
|
|
102
|
+
const token = await getAuthToken();
|
|
98
103
|
const clients = createAdminRpcClients(baseURL);
|
|
99
|
-
const res = await clients.deliveryZones.zones.$get({ query: params }, authHeaders(
|
|
104
|
+
const res = await clients.deliveryZones.zones.$get({ query: params }, authHeaders(token));
|
|
100
105
|
if (!res.ok)
|
|
101
106
|
throw new Error(`Failed to fetch delivery zones: ${res.statusText}`);
|
|
102
107
|
return res.json();
|
|
@@ -108,12 +113,13 @@ export function useListDeliveryZones(params, options) {
|
|
|
108
113
|
* Hook to create a delivery zone using admin RPC
|
|
109
114
|
*/
|
|
110
115
|
export function useCreateDeliveryZone(options) {
|
|
111
|
-
const { baseURL,
|
|
116
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
112
117
|
const queryClient = useQueryClient();
|
|
113
118
|
return useMutation({
|
|
114
119
|
mutationFn: async (data) => {
|
|
120
|
+
const token = await getAuthToken();
|
|
115
121
|
const clients = createAdminRpcClients(baseURL);
|
|
116
|
-
const res = await clients.deliveryZones.zones.$post({ json: data }, authHeaders(
|
|
122
|
+
const res = await clients.deliveryZones.zones.$post({ json: data }, authHeaders(token));
|
|
117
123
|
if (!res.ok)
|
|
118
124
|
throw new Error(`Failed to create delivery zone: ${res.statusText}`);
|
|
119
125
|
return res.json();
|
|
@@ -129,12 +135,13 @@ export function useCreateDeliveryZone(options) {
|
|
|
129
135
|
* Hook to update a delivery zone using admin RPC
|
|
130
136
|
*/
|
|
131
137
|
export function useUpdateDeliveryZone(zoneId, options) {
|
|
132
|
-
const { baseURL,
|
|
138
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
133
139
|
const queryClient = useQueryClient();
|
|
134
140
|
return useMutation({
|
|
135
141
|
mutationFn: async (data) => {
|
|
142
|
+
const token = await getAuthToken();
|
|
136
143
|
const clients = createAdminRpcClients(baseURL);
|
|
137
|
-
const res = await clients.deliveryZones.zones[':id'].$patch({ json: data, param: { id: zoneId } }, authHeaders(
|
|
144
|
+
const res = await clients.deliveryZones.zones[':id'].$patch({ json: data, param: { id: zoneId } }, authHeaders(token));
|
|
138
145
|
if (!res.ok)
|
|
139
146
|
throw new Error(`Failed to update delivery zone: ${res.statusText}`);
|
|
140
147
|
return res.json();
|
|
@@ -150,12 +157,13 @@ export function useUpdateDeliveryZone(zoneId, options) {
|
|
|
150
157
|
* Hook to delete a delivery zone using admin RPC
|
|
151
158
|
*/
|
|
152
159
|
export function useDeleteDeliveryZone(zoneId, options) {
|
|
153
|
-
const { baseURL,
|
|
160
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
154
161
|
const queryClient = useQueryClient();
|
|
155
162
|
return useMutation({
|
|
156
163
|
mutationFn: async () => {
|
|
164
|
+
const token = await getAuthToken();
|
|
157
165
|
const clients = createAdminRpcClients(baseURL);
|
|
158
|
-
const res = await clients.deliveryZones.zones[':id'].$delete({ param: { id: zoneId } }, authHeaders(
|
|
166
|
+
const res = await clients.deliveryZones.zones[':id'].$delete({ param: { id: zoneId } }, authHeaders(token));
|
|
159
167
|
if (!res.ok)
|
|
160
168
|
throw new Error(`Failed to delete delivery zone: ${res.statusText}`);
|
|
161
169
|
return res.json();
|
|
@@ -10,12 +10,13 @@ import { useApiConfig } from '../useApiConfig';
|
|
|
10
10
|
* Hook to list discount codes using admin RPC
|
|
11
11
|
*/
|
|
12
12
|
export function useListDiscountCodes(params, options) {
|
|
13
|
-
const { baseURL,
|
|
13
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
14
14
|
return useQueryUnwrapped({
|
|
15
15
|
queryKey: queryKeys.admin.discountCodes.list(params),
|
|
16
16
|
queryFn: async () => {
|
|
17
|
+
const token = await getAuthToken();
|
|
17
18
|
const clients = createAdminRpcClients(baseURL);
|
|
18
|
-
const res = await clients.discountCodes.index.$get({ query: params }, authHeaders(
|
|
19
|
+
const res = await clients.discountCodes.index.$get({ query: params }, authHeaders(token));
|
|
19
20
|
if (!res.ok)
|
|
20
21
|
throw new Error(`Failed to fetch discount codes: ${res.statusText}`);
|
|
21
22
|
return res.json();
|
|
@@ -27,12 +28,13 @@ export function useListDiscountCodes(params, options) {
|
|
|
27
28
|
* Hook to get discount code by ID using admin RPC
|
|
28
29
|
*/
|
|
29
30
|
export function useGetDiscountCode(codeId, options) {
|
|
30
|
-
const { baseURL,
|
|
31
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
31
32
|
return useQueryUnwrapped({
|
|
32
33
|
queryKey: queryKeys.admin.discountCodes.detail(codeId),
|
|
33
34
|
queryFn: async () => {
|
|
35
|
+
const token = await getAuthToken();
|
|
34
36
|
const clients = createAdminRpcClients(baseURL);
|
|
35
|
-
const res = await clients.discountCodes[':id'].$get({ param: { id: codeId } }, authHeaders(
|
|
37
|
+
const res = await clients.discountCodes[':id'].$get({ param: { id: codeId } }, authHeaders(token));
|
|
36
38
|
if (!res.ok)
|
|
37
39
|
throw new Error(`Failed to fetch discount code: ${res.statusText}`);
|
|
38
40
|
return res.json();
|
|
@@ -44,12 +46,13 @@ export function useGetDiscountCode(codeId, options) {
|
|
|
44
46
|
* Hook to create a discount code using admin RPC
|
|
45
47
|
*/
|
|
46
48
|
export function useCreateDiscountCode(options) {
|
|
47
|
-
const { baseURL,
|
|
49
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
48
50
|
const queryClient = useQueryClient();
|
|
49
51
|
return useMutation({
|
|
50
52
|
mutationFn: async (data) => {
|
|
53
|
+
const token = await getAuthToken();
|
|
51
54
|
const clients = createAdminRpcClients(baseURL);
|
|
52
|
-
const res = await clients.discountCodes.index.$post({ json: data }, authHeaders(
|
|
55
|
+
const res = await clients.discountCodes.index.$post({ json: data }, authHeaders(token));
|
|
53
56
|
if (!res.ok)
|
|
54
57
|
throw new Error(`Failed to create discount code: ${res.statusText}`);
|
|
55
58
|
return res.json();
|
|
@@ -64,12 +67,13 @@ export function useCreateDiscountCode(options) {
|
|
|
64
67
|
* Hook to update a discount code using admin RPC
|
|
65
68
|
*/
|
|
66
69
|
export function useUpdateDiscountCode(codeId, options) {
|
|
67
|
-
const { baseURL,
|
|
70
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
68
71
|
const queryClient = useQueryClient();
|
|
69
72
|
return useMutation({
|
|
70
73
|
mutationFn: async (data) => {
|
|
74
|
+
const token = await getAuthToken();
|
|
71
75
|
const clients = createAdminRpcClients(baseURL);
|
|
72
|
-
const res = await clients.discountCodes[':id'].$patch({ json: data, param: { id: codeId } }, authHeaders(
|
|
76
|
+
const res = await clients.discountCodes[':id'].$patch({ json: data, param: { id: codeId } }, authHeaders(token));
|
|
73
77
|
if (!res.ok)
|
|
74
78
|
throw new Error(`Failed to update discount code: ${res.statusText}`);
|
|
75
79
|
return res.json();
|
|
@@ -85,12 +89,13 @@ export function useUpdateDiscountCode(codeId, options) {
|
|
|
85
89
|
* Hook to delete a discount code using admin RPC
|
|
86
90
|
*/
|
|
87
91
|
export function useDeleteDiscountCode(codeId, options) {
|
|
88
|
-
const { baseURL,
|
|
92
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
89
93
|
const queryClient = useQueryClient();
|
|
90
94
|
return useMutation({
|
|
91
95
|
mutationFn: async () => {
|
|
96
|
+
const token = await getAuthToken();
|
|
92
97
|
const clients = createAdminRpcClients(baseURL);
|
|
93
|
-
const res = await clients.discountCodes[':id'].$delete({ param: { id: codeId } }, authHeaders(
|
|
98
|
+
const res = await clients.discountCodes[':id'].$delete({ param: { id: codeId } }, authHeaders(token));
|
|
94
99
|
if (!res.ok)
|
|
95
100
|
throw new Error(`Failed to delete discount code: ${res.statusText}`);
|
|
96
101
|
return res.json();
|
|
@@ -105,12 +110,13 @@ export function useDeleteDiscountCode(codeId, options) {
|
|
|
105
110
|
* Hook to get discount code analytics using admin RPC
|
|
106
111
|
*/
|
|
107
112
|
export function useGetDiscountCodeAnalytics(codeId, options) {
|
|
108
|
-
const { baseURL,
|
|
113
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
109
114
|
return useQueryUnwrapped({
|
|
110
115
|
queryKey: queryKeys.admin.discountCodes.analytics(codeId),
|
|
111
116
|
queryFn: async () => {
|
|
117
|
+
const token = await getAuthToken();
|
|
112
118
|
const clients = createAdminRpcClients(baseURL);
|
|
113
|
-
const res = await clients.discountCodes[':id'].analytics.$get({ param: { id: codeId } }, authHeaders(
|
|
119
|
+
const res = await clients.discountCodes[':id'].analytics.$get({ param: { id: codeId } }, authHeaders(token));
|
|
114
120
|
if (!res.ok)
|
|
115
121
|
throw new Error(`Failed to fetch discount code analytics: ${res.statusText}`);
|
|
116
122
|
return res.json();
|
|
@@ -122,12 +128,13 @@ export function useGetDiscountCodeAnalytics(codeId, options) {
|
|
|
122
128
|
* Hook to bulk generate discount codes using admin RPC
|
|
123
129
|
*/
|
|
124
130
|
export function useBulkGenerateDiscountCodes(options) {
|
|
125
|
-
const { baseURL,
|
|
131
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
126
132
|
const queryClient = useQueryClient();
|
|
127
133
|
return useMutation({
|
|
128
134
|
mutationFn: async (data) => {
|
|
135
|
+
const token = await getAuthToken();
|
|
129
136
|
const clients = createAdminRpcClients(baseURL);
|
|
130
|
-
const res = await clients.discountCodes['bulk-generate'].$post({ json: data }, authHeaders(
|
|
137
|
+
const res = await clients.discountCodes['bulk-generate'].$post({ json: data }, authHeaders(token));
|
|
131
138
|
if (!res.ok)
|
|
132
139
|
throw new Error(`Failed to bulk generate discount codes: ${res.statusText}`);
|
|
133
140
|
return res.json();
|
|
@@ -142,12 +149,13 @@ export function useBulkGenerateDiscountCodes(options) {
|
|
|
142
149
|
* Hook to get discount code overview stats using admin RPC
|
|
143
150
|
*/
|
|
144
151
|
export function useGetDiscountCodeOverviewStats(options) {
|
|
145
|
-
const { baseURL,
|
|
152
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
146
153
|
return useQueryUnwrapped({
|
|
147
154
|
queryKey: queryKeys.admin.discountCodes.overviewStats(),
|
|
148
155
|
queryFn: async () => {
|
|
156
|
+
const token = await getAuthToken();
|
|
149
157
|
const clients = createAdminRpcClients(baseURL);
|
|
150
|
-
const res = await clients.discountCodes.stats.overview.$get({}, authHeaders(
|
|
158
|
+
const res = await clients.discountCodes.stats.overview.$get({}, authHeaders(token));
|
|
151
159
|
if (!res.ok)
|
|
152
160
|
throw new Error(`Failed to fetch discount code overview stats: ${res.statusText}`);
|
|
153
161
|
return res.json();
|