@instockng/api-client 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/backend-types.d.ts +10 -0
  2. package/dist/backend-types.js +10 -0
  3. package/dist/client.d.ts +20 -0
  4. package/dist/client.js +40 -0
  5. package/dist/fetchers/brands.d.ts +25 -0
  6. package/dist/fetchers/brands.js +26 -0
  7. package/dist/fetchers/carts.d.ts +2339 -0
  8. package/dist/fetchers/carts.js +167 -0
  9. package/dist/fetchers/delivery-zones.d.ts +28 -0
  10. package/{src/fetchers/delivery-zones.ts → dist/fetchers/delivery-zones.js} +9 -12
  11. package/{src/fetchers/index.ts → dist/fetchers/index.d.ts} +1 -1
  12. package/dist/fetchers/index.js +22 -0
  13. package/dist/fetchers/orders.d.ts +283 -0
  14. package/dist/fetchers/orders.js +44 -0
  15. package/dist/fetchers/products.d.ts +386 -0
  16. package/dist/fetchers/products.js +42 -0
  17. package/dist/hooks/admin/abandoned-carts.d.ts +535 -0
  18. package/dist/hooks/admin/abandoned-carts.js +79 -0
  19. package/dist/hooks/admin/brands.d.ts +79 -0
  20. package/dist/hooks/admin/brands.js +103 -0
  21. package/dist/hooks/admin/customers.d.ts +278 -0
  22. package/dist/hooks/admin/customers.js +25 -0
  23. package/dist/hooks/admin/delivery-zones.d.ts +270 -0
  24. package/dist/hooks/admin/delivery-zones.js +168 -0
  25. package/dist/hooks/admin/discount-codes.d.ts +299 -0
  26. package/dist/hooks/admin/discount-codes.js +157 -0
  27. package/{src/hooks/admin/index.ts → dist/hooks/admin/index.d.ts} +0 -1
  28. package/dist/hooks/admin/index.js +16 -0
  29. package/dist/hooks/admin/inventory.d.ts +224 -0
  30. package/dist/hooks/admin/inventory.js +102 -0
  31. package/dist/hooks/admin/orders.d.ts +1380 -0
  32. package/dist/hooks/admin/orders.js +169 -0
  33. package/dist/hooks/admin/products.d.ts +374 -0
  34. package/dist/hooks/admin/products.js +84 -0
  35. package/dist/hooks/admin/stats.d.ts +277 -0
  36. package/dist/hooks/admin/stats.js +24 -0
  37. package/dist/hooks/admin/variants.d.ts +115 -0
  38. package/dist/hooks/admin/variants.js +121 -0
  39. package/dist/hooks/admin/warehouses.d.ts +277 -0
  40. package/dist/hooks/admin/warehouses.js +103 -0
  41. package/dist/hooks/public/brands.d.ts +33 -0
  42. package/dist/hooks/public/brands.js +30 -0
  43. package/dist/hooks/public/carts.d.ts +2407 -0
  44. package/dist/hooks/public/carts.js +213 -0
  45. package/dist/hooks/public/delivery-zones.d.ts +34 -0
  46. package/{src/hooks/public/delivery-zones.ts → dist/hooks/public/delivery-zones.js} +6 -12
  47. package/{src/hooks/public/index.ts → dist/hooks/public/index.d.ts} +1 -1
  48. package/dist/hooks/public/index.js +10 -0
  49. package/dist/hooks/public/orders.d.ts +302 -0
  50. package/{src/hooks/public/orders.ts → dist/hooks/public/orders.js} +12 -28
  51. package/dist/hooks/public/products.d.ts +398 -0
  52. package/{src/hooks/public/products.ts → dist/hooks/public/products.js} +12 -22
  53. package/dist/hooks/use-query-unwrapped.d.ts +20 -0
  54. package/dist/hooks/use-query-unwrapped.js +22 -0
  55. package/dist/hooks/useApiConfig.d.ts +11 -0
  56. package/dist/hooks/useApiConfig.js +14 -0
  57. package/dist/index.d.ts +20 -0
  58. package/{src/index.ts → dist/index.js} +0 -17
  59. package/dist/provider.d.ts +33 -0
  60. package/dist/provider.js +52 -0
  61. package/dist/rpc-client.d.ts +9043 -0
  62. package/dist/rpc-client.js +78 -0
  63. package/{src/rpc-types.ts → dist/rpc-types.d.ts} +35 -80
  64. package/dist/rpc-types.js +7 -0
  65. package/{src/types.ts → dist/types.d.ts} +0 -6
  66. package/dist/types.js +16 -0
  67. package/dist/utils/query-keys.d.ts +106 -0
  68. package/dist/utils/query-keys.js +108 -0
  69. package/package.json +24 -13
  70. package/src/client.ts +0 -57
  71. package/src/fetchers/carts.ts +0 -202
  72. package/src/fetchers/orders.ts +0 -48
  73. package/src/fetchers/products.ts +0 -46
  74. package/src/hooks/admin/abandoned-carts.ts +0 -102
  75. package/src/hooks/admin/brands.ts +0 -134
  76. package/src/hooks/admin/customers.ts +0 -31
  77. package/src/hooks/admin/delivery-zones.ts +0 -236
  78. package/src/hooks/admin/discount-codes.ts +0 -222
  79. package/src/hooks/admin/inventory.ts +0 -137
  80. package/src/hooks/admin/orders.ts +0 -229
  81. package/src/hooks/admin/products.ts +0 -116
  82. package/src/hooks/admin/stats.ts +0 -30
  83. package/src/hooks/admin/variants.ts +0 -173
  84. package/src/hooks/admin/warehouses.ts +0 -143
  85. package/src/hooks/public/carts.ts +0 -298
  86. package/src/hooks/use-query-unwrapped.ts +0 -30
  87. package/src/hooks/useApiConfig.ts +0 -22
  88. package/src/provider.tsx +0 -89
  89. package/src/rpc-client.ts +0 -106
  90. package/src/utils/query-keys.ts +0 -121
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Backend RPC types - AUTO-GENERATED, DO NOT EDIT MANUALLY
3
+ *
4
+ * Generated from apps/backend/src/index.ts
5
+ * Run 'pnpm run generate-types' to regenerate this file
6
+ *
7
+ * These types provide end-to-end type safety between the backend API
8
+ * and the frontend hooks/fetchers.
9
+ */
10
+ export type { CartsRPC, OrdersRPC, ProductsRPC, DeliveryZonesRPC, BrandsRPC, AdminOrdersRPC, AdminBrandsRPC, AdminProductsRPC, AdminVariantsRPC, AdminWarehousesRPC, AdminInventoryRPC, AdminCustomersRPC, AdminStatsRPC, AdminAbandonedCartsRPC, AdminDiscountCodesRPC, AdminDeliveryZonesRPC, } from '../../../apps/backend/src/http-app';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Backend RPC types - AUTO-GENERATED, DO NOT EDIT MANUALLY
3
+ *
4
+ * Generated from apps/backend/src/index.ts
5
+ * Run 'pnpm run generate-types' to regenerate this file
6
+ *
7
+ * These types provide end-to-end type safety between the backend API
8
+ * and the frontend hooks/fetchers.
9
+ */
10
+ export {};
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Axios client configuration for OMS API
3
+ */
4
+ import { AxiosInstance, AxiosError } from 'axios';
5
+ export interface ApiClientConfig {
6
+ baseURL: string;
7
+ onError?: (error: AxiosError) => void;
8
+ }
9
+ /**
10
+ * Initialize the API client with configuration
11
+ */
12
+ export declare function initializeApiClient(config: ApiClientConfig): AxiosInstance;
13
+ /**
14
+ * Get the current API client instance
15
+ */
16
+ export declare function getApiClient(): AxiosInstance;
17
+ /**
18
+ * Reset the API client (mainly for testing)
19
+ */
20
+ export declare function resetApiClient(): void;
package/dist/client.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Axios client configuration for OMS API
3
+ */
4
+ import axios from 'axios';
5
+ let apiClient = null;
6
+ /**
7
+ * Initialize the API client with configuration
8
+ */
9
+ export function initializeApiClient(config) {
10
+ apiClient = axios.create({
11
+ baseURL: config.baseURL,
12
+ headers: {
13
+ 'Content-Type': 'application/json',
14
+ },
15
+ });
16
+ // Response interceptor for error handling
17
+ apiClient.interceptors.response.use((response) => response, (error) => {
18
+ // Call custom error handler if provided
19
+ if (config.onError) {
20
+ config.onError(error);
21
+ }
22
+ return Promise.reject(error);
23
+ });
24
+ return apiClient;
25
+ }
26
+ /**
27
+ * Get the current API client instance
28
+ */
29
+ export function getApiClient() {
30
+ if (!apiClient) {
31
+ throw new Error('API client not initialized. Make sure to wrap your app with ApiClientProvider.');
32
+ }
33
+ return apiClient;
34
+ }
35
+ /**
36
+ * Reset the API client (mainly for testing)
37
+ */
38
+ export function resetApiClient() {
39
+ apiClient = null;
40
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Brand 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
+ * Fetch brand configuration by slug
11
+ *
12
+ * @param slug - Brand slug (e.g., 'my-brand')
13
+ * @returns Brand with metaPixelId and other configuration
14
+ */
15
+ export declare function fetchBrandBySlug(slug: string): Promise<{
16
+ name: string;
17
+ id: string;
18
+ slug: string;
19
+ logoUrl: string;
20
+ siteUrl: string;
21
+ domain: string;
22
+ metaPixelId: string;
23
+ createdAt: string;
24
+ updatedAt: string;
25
+ }>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Brand 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
+ import { createRpcClients } from '../rpc-client';
10
+ const API_URL = 'https://oms-api.instock.ng';
11
+ /**
12
+ * Fetch brand configuration by slug
13
+ *
14
+ * @param slug - Brand slug (e.g., 'my-brand')
15
+ * @returns Brand with metaPixelId and other configuration
16
+ */
17
+ export async function fetchBrandBySlug(slug) {
18
+ const clients = createRpcClients(API_URL);
19
+ const res = await clients.brands[':slug'].$get({
20
+ param: { slug },
21
+ });
22
+ if (!res.ok) {
23
+ throw new Error(`Failed to fetch brand: ${res.statusText}`);
24
+ }
25
+ return res.json();
26
+ }