@instockng/api-client 1.0.36 → 1.0.39

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 (35) hide show
  1. package/dist/backend-types.d.ts +1 -1
  2. package/dist/fetchers/brands.js +1 -1
  3. package/dist/fetchers/carts.d.ts +586 -1
  4. package/dist/fetchers/carts.js +19 -3
  5. package/dist/fetchers/delivery-zones.js +1 -1
  6. package/dist/fetchers/orders.d.ts +82 -0
  7. package/dist/fetchers/orders.js +38 -1
  8. package/dist/fetchers/products.js +1 -1
  9. package/dist/hooks/admin/abandoned-carts.d.ts +8 -0
  10. package/dist/hooks/admin/brands.d.ts +4 -0
  11. package/dist/hooks/admin/customers.d.ts +27 -0
  12. package/dist/hooks/admin/delivery-zones.d.ts +4 -0
  13. package/dist/hooks/admin/discount-codes.d.ts +5 -0
  14. package/dist/hooks/admin/dispatch-riders.d.ts +59 -0
  15. package/dist/hooks/admin/dispatch-riders.js +92 -0
  16. package/dist/hooks/admin/index.d.ts +1 -0
  17. package/dist/hooks/admin/index.js +1 -0
  18. package/dist/hooks/admin/orders.d.ts +191 -0
  19. package/dist/hooks/admin/orders.js +93 -0
  20. package/dist/hooks/admin/products.d.ts +6 -0
  21. package/dist/hooks/admin/stats.d.ts +34 -0
  22. package/dist/hooks/admin/stats.js +20 -0
  23. package/dist/hooks/admin/variants.d.ts +10 -0
  24. package/dist/hooks/admin/warehouses.d.ts +2 -0
  25. package/dist/hooks/public/carts.d.ts +585 -1
  26. package/dist/hooks/public/carts.js +20 -2
  27. package/dist/hooks/public/orders.d.ts +86 -1
  28. package/dist/hooks/public/orders.js +23 -1
  29. package/dist/provider.js +1 -1
  30. package/dist/rpc-client.d.ts +5456 -1769
  31. package/dist/rpc-client.js +1 -0
  32. package/dist/rpc-types.d.ts +9 -0
  33. package/dist/utils/query-keys.d.ts +7 -0
  34. package/dist/utils/query-keys.js +7 -0
  35. package/package.json +7 -8
@@ -7,7 +7,7 @@
7
7
  import { useMutation, useQueryClient } from '@tanstack/react-query';
8
8
  import { useQueryUnwrapped } from '../use-query-unwrapped';
9
9
  import { queryKeys } from '../../utils/query-keys';
10
- import { fetchCart, updateCart, createCart, addCartItem, updateCartItem, removeCartItem, applyDiscount, removeDiscount, checkoutCart, initiateCheckout, fetchCartRecommendations, } from '../../fetchers/carts';
10
+ import { fetchCart, updateCart, createCart, addCartItem, updateCartItem, removeCartItem, applyDiscount, removeDiscount, checkoutCart, initiateCheckout, fetchCartRecommendations, fetchCartUpsellAddons, } from '../../fetchers/carts';
11
11
  /**
12
12
  * Hook to get cart by ID using RPC
13
13
  *
@@ -128,13 +128,17 @@ export function useRemoveDiscount(cartId, options) {
128
128
  export function useAddCartItem(cartId, options) {
129
129
  const queryClient = useQueryClient();
130
130
  return useMutation({
131
- mutationFn: (data) => addCartItem(cartId, data.sku, data.quantity, data.fbc, data.fbp, data.ttp, data.ttclid),
131
+ mutationFn: (data) => addCartItem(cartId, data.sku, data.quantity, data.fbc, data.fbp, data.ttp, data.ttclid, data.fromUpsell, data.upsellDiscountPercent),
132
132
  onSuccess: (_, variables) => {
133
133
  queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
134
134
  // Refresh recommendations only if cart is not visible (refreshRecommendations flag is true)
135
135
  if (variables.refreshRecommendations) {
136
136
  queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.recommendations(cartId) });
137
137
  }
138
+ // Refresh upsell addons when item is added from upsell
139
+ if (variables.fromUpsell) {
140
+ queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.upsellAddons(cartId) });
141
+ }
138
142
  },
139
143
  ...options,
140
144
  });
@@ -256,3 +260,17 @@ export function useGetCartRecommendations(cartId, limit, options) {
256
260
  ...options,
257
261
  });
258
262
  }
263
+ /**
264
+ * Hook to get discounted upsell add-ons for a cart
265
+ *
266
+ * @param cartId - Cart UUID
267
+ * @param options - React Query options
268
+ */
269
+ export function useGetCartUpsellAddons(cartId, options) {
270
+ return useQueryUnwrapped({
271
+ queryKey: cartId ? queryKeys.public.carts.upsellAddons(cartId) : ['public', 'carts', 'upsell-addons'],
272
+ queryFn: () => fetchCartUpsellAddons(cartId),
273
+ enabled: !!cartId,
274
+ ...options,
275
+ });
276
+ }
@@ -5,7 +5,7 @@
5
5
  * providing end-to-end type safety without code generation.
6
6
  */
7
7
  import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
8
- import { fetchOrder, confirmOrder, fetchOrderRecommendations } from '../../fetchers/orders';
8
+ import { fetchOrder, confirmOrder, confirmDelivery, updateDeliveryAddress, fetchOrderRecommendations } from '../../fetchers/orders';
9
9
  /**
10
10
  * Hook to get order by ID and token using RPC
11
11
  *
@@ -21,16 +21,30 @@ import { fetchOrder, confirmOrder, fetchOrderRecommendations } from '../../fetch
21
21
  */
22
22
  export declare function useGetOrder(orderId: string, token: string, options?: Omit<UseQueryOptions<Awaited<ReturnType<typeof fetchOrder>>, Error>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<{
23
23
  canConfirm: boolean;
24
+ canConfirmDelivery: boolean;
25
+ canUpdateAddress: boolean;
24
26
  confirmationMessage: string;
25
27
  subtotal: number;
28
+ totalCost: number;
29
+ totalProfit: number;
30
+ profitMargin: number;
26
31
  deliveryCharge: number;
27
32
  totalPrice: number;
28
33
  discountAmount: number;
34
+ amountPaid: number;
35
+ flutterwaveAccountBank: string;
36
+ flutterwaveAccountNumber: string;
37
+ flutterwaveAccountExpiry: string;
29
38
  createdAt: string;
30
39
  updatedAt: string;
31
40
  deletedAt: string;
32
41
  prospectSince: string;
33
42
  lastRecoveryAttemptAt: string;
43
+ shippedAt: string;
44
+ deliveryConfirmationSentAt: string;
45
+ deliveryConfirmedAt: string;
46
+ deliveryConfirmationAttempts: number;
47
+ needsManualCall: boolean;
34
48
  brand: {
35
49
  id: string;
36
50
  name: string;
@@ -42,6 +56,7 @@ export declare function useGetOrder(orderId: string, token: string, options?: Om
42
56
  tiktokPixelId: string;
43
57
  paystackPublicKey: string;
44
58
  freeShippingThreshold: number;
59
+ upsellDiscountPercent: number;
45
60
  createdAt: string;
46
61
  updatedAt: string;
47
62
  deletedAt: string;
@@ -74,6 +89,8 @@ export declare function useGetOrder(orderId: string, token: string, options?: Om
74
89
  };
75
90
  items: {
76
91
  priceAtPurchase: number;
92
+ costAtPurchase: number;
93
+ itemProfit: number;
77
94
  variant: {
78
95
  price: number;
79
96
  createdAt: string;
@@ -533,6 +550,7 @@ export declare function useGetOrder(orderId: string, token: string, options?: Om
533
550
  productId: string;
534
551
  thumbnailUrl: string | null;
535
552
  sku: string;
553
+ costPrice: string;
536
554
  compareAtPrice: string;
537
555
  trackInventory: boolean;
538
556
  lowStockThreshold: number | null;
@@ -573,8 +591,19 @@ export declare function useGetOrder(orderId: string, token: string, options?: Om
573
591
  paystackReference: string | null;
574
592
  status: import("@prisma/client").$Enums.OrderStatus;
575
593
  cancellationReason: string | null;
594
+ shippingMethod: string | null;
595
+ dispatchRiderId: string | null;
596
+ fezTrackingNumber: string | null;
597
+ flutterwaveOrderRef: string | null;
598
+ flutterwaveCustomerId: string | null;
576
599
  prospectReason: import("@prisma/client").$Enums.ProspectReason | null;
577
600
  userActionToken: string;
601
+ labelPrintedAt: string;
602
+ dispatchRider?: {
603
+ id: string;
604
+ name: string;
605
+ phone: string;
606
+ };
578
607
  }, Error>;
579
608
  /**
580
609
  * Hook to confirm a prospect order using RPC
@@ -595,14 +624,26 @@ export declare function useConfirmOrder(options?: UseMutationOptions<Awaited<Ret
595
624
  token: string;
596
625
  }>): import("@tanstack/react-query").UseMutationResult<{
597
626
  subtotal: number;
627
+ totalCost: number;
628
+ totalProfit: number;
629
+ profitMargin: number;
598
630
  deliveryCharge: number;
599
631
  totalPrice: number;
600
632
  discountAmount: number;
633
+ amountPaid: number;
634
+ flutterwaveAccountBank: string;
635
+ flutterwaveAccountNumber: string;
636
+ flutterwaveAccountExpiry: string;
601
637
  createdAt: string;
602
638
  updatedAt: string;
603
639
  deletedAt: string;
604
640
  prospectSince: string;
605
641
  lastRecoveryAttemptAt: string;
642
+ shippedAt: string;
643
+ deliveryConfirmationSentAt: string;
644
+ deliveryConfirmedAt: string;
645
+ deliveryConfirmationAttempts: number;
646
+ needsManualCall: boolean;
606
647
  brand: {
607
648
  id: string;
608
649
  name: string;
@@ -614,6 +655,7 @@ export declare function useConfirmOrder(options?: UseMutationOptions<Awaited<Ret
614
655
  tiktokPixelId: string;
615
656
  paystackPublicKey: string;
616
657
  freeShippingThreshold: number;
658
+ upsellDiscountPercent: number;
617
659
  createdAt: string;
618
660
  updatedAt: string;
619
661
  deletedAt: string;
@@ -646,6 +688,8 @@ export declare function useConfirmOrder(options?: UseMutationOptions<Awaited<Ret
646
688
  };
647
689
  items: {
648
690
  priceAtPurchase: number;
691
+ costAtPurchase: number;
692
+ itemProfit: number;
649
693
  variant: {
650
694
  price: number;
651
695
  createdAt: string;
@@ -1105,6 +1149,7 @@ export declare function useConfirmOrder(options?: UseMutationOptions<Awaited<Ret
1105
1149
  productId: string;
1106
1150
  thumbnailUrl: string | null;
1107
1151
  sku: string;
1152
+ costPrice: string;
1108
1153
  compareAtPrice: string;
1109
1154
  trackInventory: boolean;
1110
1155
  lowStockThreshold: number | null;
@@ -1145,12 +1190,49 @@ export declare function useConfirmOrder(options?: UseMutationOptions<Awaited<Ret
1145
1190
  paystackReference: string | null;
1146
1191
  status: import("@prisma/client").$Enums.OrderStatus;
1147
1192
  cancellationReason: string | null;
1193
+ shippingMethod: string | null;
1194
+ dispatchRiderId: string | null;
1195
+ fezTrackingNumber: string | null;
1196
+ flutterwaveOrderRef: string | null;
1197
+ flutterwaveCustomerId: string | null;
1148
1198
  prospectReason: import("@prisma/client").$Enums.ProspectReason | null;
1149
1199
  userActionToken: string;
1200
+ labelPrintedAt: string;
1201
+ dispatchRider?: {
1202
+ id: string;
1203
+ name: string;
1204
+ phone: string;
1205
+ };
1150
1206
  }, Error, {
1151
1207
  orderId: string;
1152
1208
  token: string;
1153
1209
  }, unknown>;
1210
+ /**
1211
+ * Hook to confirm delivery details for an order
1212
+ */
1213
+ export declare function useConfirmDelivery(options?: UseMutationOptions<Awaited<ReturnType<typeof confirmDelivery>>, Error, {
1214
+ orderId: string;
1215
+ token: string;
1216
+ }>): import("@tanstack/react-query").UseMutationResult<any, Error, {
1217
+ orderId: string;
1218
+ token: string;
1219
+ }, unknown>;
1220
+ /**
1221
+ * Hook to update delivery address for an order
1222
+ */
1223
+ export declare function useUpdateDeliveryAddress(options?: UseMutationOptions<Awaited<ReturnType<typeof updateDeliveryAddress>>, Error, {
1224
+ orderId: string;
1225
+ token: string;
1226
+ address?: string;
1227
+ city?: string;
1228
+ phone?: string;
1229
+ }>): import("@tanstack/react-query").UseMutationResult<any, Error, {
1230
+ orderId: string;
1231
+ token: string;
1232
+ address?: string;
1233
+ city?: string;
1234
+ phone?: string;
1235
+ }, unknown>;
1154
1236
  /**
1155
1237
  * Hook to get order recommendations for post-purchase upsell
1156
1238
  *
@@ -1331,6 +1413,7 @@ export declare function useGetOrderRecommendations(orderId: string | null | unde
1331
1413
  tiktokPixelId: string;
1332
1414
  paystackPublicKey: string;
1333
1415
  freeShippingThreshold: number;
1416
+ upsellDiscountPercent: number;
1334
1417
  createdAt: string;
1335
1418
  updatedAt: string;
1336
1419
  deletedAt: string;
@@ -1339,9 +1422,11 @@ export declare function useGetOrderRecommendations(orderId: string | null | unde
1339
1422
  createdAt: string;
1340
1423
  updatedAt: string;
1341
1424
  price: number;
1425
+ costPrice: number;
1342
1426
  compareAtPrice: number;
1343
1427
  deletedAt: string;
1344
1428
  thumbnailUrl: string;
1429
+ rawThumbnailUrl: string;
1345
1430
  originalPrice: number;
1346
1431
  id: string;
1347
1432
  name: string | null;
@@ -7,7 +7,7 @@
7
7
  import { useMutation } from '@tanstack/react-query';
8
8
  import { useQueryUnwrapped } from '../use-query-unwrapped';
9
9
  import { queryKeys } from '../../utils/query-keys';
10
- import { fetchOrder, confirmOrder, fetchOrderRecommendations } from '../../fetchers/orders';
10
+ import { fetchOrder, confirmOrder, confirmDelivery, updateDeliveryAddress, fetchOrderRecommendations } from '../../fetchers/orders';
11
11
  /**
12
12
  * Hook to get order by ID and token using RPC
13
13
  *
@@ -48,6 +48,28 @@ export function useConfirmOrder(options) {
48
48
  ...options,
49
49
  });
50
50
  }
51
+ /**
52
+ * Hook to confirm delivery details for an order
53
+ */
54
+ export function useConfirmDelivery(options) {
55
+ return useMutation({
56
+ mutationFn: (data) => confirmDelivery(data.orderId, data.token),
57
+ ...options,
58
+ });
59
+ }
60
+ /**
61
+ * Hook to update delivery address for an order
62
+ */
63
+ export function useUpdateDeliveryAddress(options) {
64
+ return useMutation({
65
+ mutationFn: (data) => updateDeliveryAddress(data.orderId, data.token, {
66
+ address: data.address,
67
+ city: data.city,
68
+ phone: data.phone,
69
+ }),
70
+ ...options,
71
+ });
72
+ }
51
73
  /**
52
74
  * Hook to get order recommendations for post-purchase upsell
53
75
  *
package/dist/provider.js CHANGED
@@ -18,7 +18,7 @@ const ApiClientContext = createContext(null);
18
18
  * </ApiClientProvider>
19
19
  * ```
20
20
  */
21
- export function ApiClientProvider({ children, baseURL = 'https://oms-api.instock.com.ng', getAuthToken, onError, queryClient: externalQueryClient }) {
21
+ export function ApiClientProvider({ children, baseURL = 'https://oms-api.instock.ng', getAuthToken, onError, queryClient: externalQueryClient }) {
22
22
  // Initialize client synchronously on first render
23
23
  const config = {
24
24
  baseURL,