@instockng/api-client 1.0.3 → 1.0.5

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 (170) hide show
  1. package/dist/apps/backend/src/generated/zod/index.d.ts +1114 -0
  2. package/dist/apps/backend/src/generated/zod/index.js +670 -0
  3. package/dist/apps/backend/src/http-app.d.ts +40 -0
  4. package/dist/apps/backend/src/http-app.js +106 -0
  5. package/dist/apps/backend/src/lib/brand-response.d.ts +14 -0
  6. package/dist/apps/backend/src/lib/brand-response.js +8 -0
  7. package/dist/apps/backend/src/lib/cart-helpers.d.ts +280 -0
  8. package/dist/apps/backend/src/lib/cart-helpers.js +93 -0
  9. package/dist/apps/backend/src/lib/cart-recovery.d.ts +30 -0
  10. package/dist/apps/backend/src/lib/cart-recovery.js +147 -0
  11. package/dist/apps/backend/src/lib/cart-response.d.ts +121 -0
  12. package/dist/apps/backend/src/lib/cart-response.js +150 -0
  13. package/dist/apps/backend/src/lib/clerk.d.ts +18 -0
  14. package/dist/apps/backend/src/lib/clerk.js +167 -0
  15. package/dist/apps/backend/src/lib/delivery-zone-response.d.ts +62 -0
  16. package/dist/apps/backend/src/lib/delivery-zone-response.js +24 -0
  17. package/dist/apps/backend/src/lib/discount-code-response.d.ts +42 -0
  18. package/dist/apps/backend/src/lib/discount-code-response.js +19 -0
  19. package/dist/apps/backend/src/lib/discount.d.ts +20 -0
  20. package/dist/apps/backend/src/lib/discount.js +35 -0
  21. package/dist/apps/backend/src/lib/inventory.d.ts +26 -0
  22. package/dist/apps/backend/src/lib/inventory.js +160 -0
  23. package/dist/apps/backend/src/lib/meta-capi.d.ts +48 -0
  24. package/dist/apps/backend/src/lib/meta-capi.js +120 -0
  25. package/dist/apps/backend/src/lib/openapi.d.ts +36 -0
  26. package/dist/apps/backend/src/lib/openapi.js +69 -0
  27. package/dist/apps/backend/src/lib/order-recovery.d.ts +367 -0
  28. package/dist/apps/backend/src/lib/order-recovery.js +373 -0
  29. package/dist/apps/backend/src/lib/order-response.d.ts +136 -0
  30. package/dist/apps/backend/src/lib/order-response.js +61 -0
  31. package/dist/apps/backend/src/lib/pricing.d.ts +39 -0
  32. package/dist/apps/backend/src/lib/pricing.js +62 -0
  33. package/dist/apps/backend/src/lib/prisma.d.ts +9 -0
  34. package/dist/apps/backend/src/lib/prisma.js +30 -0
  35. package/dist/apps/backend/src/lib/product-response.d.ts +82 -0
  36. package/dist/apps/backend/src/lib/product-response.js +29 -0
  37. package/dist/apps/backend/src/lib/utils.d.ts +32 -0
  38. package/dist/apps/backend/src/lib/utils.js +63 -0
  39. package/dist/apps/backend/src/middleware/clerk-auth.d.ts +8 -0
  40. package/dist/apps/backend/src/middleware/clerk-auth.js +89 -0
  41. package/dist/apps/backend/src/middleware/cors.d.ts +8 -0
  42. package/dist/apps/backend/src/middleware/cors.js +11 -0
  43. package/dist/apps/backend/src/notifications/producers/meta-capi-producer.d.ts +55 -0
  44. package/dist/apps/backend/src/notifications/producers/meta-capi-producer.js +125 -0
  45. package/dist/apps/backend/src/notifications/producers/order-notification.d.ts +9 -0
  46. package/dist/apps/backend/src/notifications/producers/order-notification.js +18 -0
  47. package/dist/apps/backend/src/notifications/producers/prospect-recovery-notification.d.ts +10 -0
  48. package/dist/apps/backend/src/notifications/producers/prospect-recovery-notification.js +11 -0
  49. package/dist/apps/backend/src/routes/admin/abandoned-carts.d.ts +605 -0
  50. package/dist/apps/backend/src/routes/admin/abandoned-carts.js +194 -0
  51. package/dist/apps/backend/src/routes/admin/brands.d.ts +175 -0
  52. package/dist/apps/backend/src/routes/admin/brands.js +118 -0
  53. package/dist/apps/backend/src/routes/admin/customers.d.ts +306 -0
  54. package/dist/apps/backend/src/routes/admin/customers.js +39 -0
  55. package/dist/apps/backend/src/routes/admin/delivery-zones.d.ts +438 -0
  56. package/dist/apps/backend/src/routes/admin/delivery-zones.js +300 -0
  57. package/dist/apps/backend/src/routes/admin/discount-codes.d.ts +478 -0
  58. package/dist/apps/backend/src/routes/admin/discount-codes.js +418 -0
  59. package/dist/apps/backend/src/routes/admin/inventory.d.ts +273 -0
  60. package/dist/apps/backend/src/routes/admin/inventory.js +189 -0
  61. package/dist/apps/backend/src/routes/admin/orders.d.ts +1478 -0
  62. package/dist/apps/backend/src/routes/admin/orders.js +503 -0
  63. package/dist/apps/backend/src/routes/admin/products.d.ts +860 -0
  64. package/dist/apps/backend/src/routes/admin/products.js +107 -0
  65. package/dist/apps/backend/src/routes/admin/stats.d.ts +288 -0
  66. package/dist/apps/backend/src/routes/admin/stats.js +55 -0
  67. package/dist/apps/backend/src/routes/admin/variants.d.ts +239 -0
  68. package/dist/apps/backend/src/routes/admin/variants.js +173 -0
  69. package/dist/apps/backend/src/routes/admin/warehouses.d.ts +373 -0
  70. package/dist/apps/backend/src/routes/admin/warehouses.js +123 -0
  71. package/dist/apps/backend/src/routes/public/brands.d.ts +40 -0
  72. package/dist/apps/backend/src/routes/public/brands.js +38 -0
  73. package/dist/apps/backend/src/routes/public/carts.d.ts +2655 -0
  74. package/dist/apps/backend/src/routes/public/carts.js +631 -0
  75. package/dist/apps/backend/src/routes/public/delivery-zones.d.ts +35 -0
  76. package/dist/apps/backend/src/routes/public/delivery-zones.js +62 -0
  77. package/dist/apps/backend/src/routes/public/orders.d.ts +323 -0
  78. package/dist/apps/backend/src/routes/public/orders.js +160 -0
  79. package/dist/apps/backend/src/routes/public/products.d.ts +449 -0
  80. package/dist/apps/backend/src/routes/public/products.js +133 -0
  81. package/dist/apps/backend/src/types/index.d.ts +42 -0
  82. package/dist/apps/backend/src/types/index.js +2 -0
  83. package/dist/apps/backend/src/validators/brand.d.ts +17 -0
  84. package/dist/apps/backend/src/validators/brand.js +15 -0
  85. package/dist/apps/backend/src/validators/delivery-zone.d.ts +31 -0
  86. package/dist/apps/backend/src/validators/delivery-zone.js +51 -0
  87. package/dist/apps/backend/src/validators/discount-code.d.ts +74 -0
  88. package/dist/apps/backend/src/validators/discount-code.js +50 -0
  89. package/dist/apps/backend/src/validators/inventory.d.ts +20 -0
  90. package/dist/apps/backend/src/validators/inventory.js +15 -0
  91. package/dist/apps/backend/src/validators/order.d.ts +87 -0
  92. package/dist/apps/backend/src/validators/order.js +61 -0
  93. package/dist/apps/backend/src/validators/product.d.ts +18 -0
  94. package/dist/apps/backend/src/validators/product.js +19 -0
  95. package/dist/apps/backend/src/validators/variant.d.ts +19 -0
  96. package/dist/apps/backend/src/validators/variant.js +19 -0
  97. package/dist/apps/backend/src/validators/warehouse.d.ts +15 -0
  98. package/dist/apps/backend/src/validators/warehouse.js +15 -0
  99. package/dist/fetchers/carts.d.ts +746 -754
  100. package/dist/hooks/public/carts.d.ts +694 -702
  101. package/dist/packages/api-client/src/backend-types.d.ts +10 -0
  102. package/dist/packages/api-client/src/backend-types.js +10 -0
  103. package/dist/packages/api-client/src/client.d.ts +20 -0
  104. package/dist/packages/api-client/src/client.js +40 -0
  105. package/dist/packages/api-client/src/fetchers/brands.d.ts +25 -0
  106. package/dist/packages/api-client/src/fetchers/brands.js +26 -0
  107. package/dist/packages/api-client/src/fetchers/carts.d.ts +2335 -0
  108. package/dist/packages/api-client/src/fetchers/carts.js +169 -0
  109. package/dist/packages/api-client/src/fetchers/delivery-zones.d.ts +28 -0
  110. package/dist/packages/api-client/src/fetchers/delivery-zones.js +26 -0
  111. package/dist/packages/api-client/src/fetchers/index.d.ts +22 -0
  112. package/dist/packages/api-client/src/fetchers/index.js +22 -0
  113. package/dist/packages/api-client/src/fetchers/orders.d.ts +283 -0
  114. package/dist/packages/api-client/src/fetchers/orders.js +44 -0
  115. package/dist/packages/api-client/src/fetchers/products.d.ts +386 -0
  116. package/dist/packages/api-client/src/fetchers/products.js +42 -0
  117. package/dist/packages/api-client/src/hooks/admin/abandoned-carts.d.ts +535 -0
  118. package/dist/packages/api-client/src/hooks/admin/abandoned-carts.js +83 -0
  119. package/dist/packages/api-client/src/hooks/admin/brands.d.ts +79 -0
  120. package/dist/packages/api-client/src/hooks/admin/brands.js +108 -0
  121. package/dist/packages/api-client/src/hooks/admin/customers.d.ts +278 -0
  122. package/dist/packages/api-client/src/hooks/admin/customers.js +26 -0
  123. package/dist/packages/api-client/src/hooks/admin/delivery-zones.d.ts +270 -0
  124. package/dist/packages/api-client/src/hooks/admin/delivery-zones.js +176 -0
  125. package/dist/packages/api-client/src/hooks/admin/discount-codes.d.ts +299 -0
  126. package/dist/packages/api-client/src/hooks/admin/discount-codes.js +165 -0
  127. package/dist/packages/api-client/src/hooks/admin/index.d.ts +16 -0
  128. package/dist/packages/api-client/src/hooks/admin/index.js +16 -0
  129. package/dist/packages/api-client/src/hooks/admin/inventory.d.ts +224 -0
  130. package/dist/packages/api-client/src/hooks/admin/inventory.js +107 -0
  131. package/dist/packages/api-client/src/hooks/admin/orders.d.ts +1380 -0
  132. package/dist/packages/api-client/src/hooks/admin/orders.js +175 -0
  133. package/dist/packages/api-client/src/hooks/admin/products.d.ts +374 -0
  134. package/dist/packages/api-client/src/hooks/admin/products.js +89 -0
  135. package/dist/packages/api-client/src/hooks/admin/stats.d.ts +277 -0
  136. package/dist/packages/api-client/src/hooks/admin/stats.js +25 -0
  137. package/dist/packages/api-client/src/hooks/admin/variants.d.ts +115 -0
  138. package/dist/packages/api-client/src/hooks/admin/variants.js +127 -0
  139. package/dist/packages/api-client/src/hooks/admin/warehouses.d.ts +277 -0
  140. package/dist/packages/api-client/src/hooks/admin/warehouses.js +108 -0
  141. package/dist/packages/api-client/src/hooks/public/brands.d.ts +33 -0
  142. package/dist/packages/api-client/src/hooks/public/brands.js +30 -0
  143. package/dist/packages/api-client/src/hooks/public/carts.d.ts +2405 -0
  144. package/dist/packages/api-client/src/hooks/public/carts.js +213 -0
  145. package/dist/packages/api-client/src/hooks/public/delivery-zones.d.ts +34 -0
  146. package/dist/packages/api-client/src/hooks/public/delivery-zones.js +28 -0
  147. package/dist/packages/api-client/src/hooks/public/index.d.ts +10 -0
  148. package/dist/packages/api-client/src/hooks/public/index.js +10 -0
  149. package/dist/packages/api-client/src/hooks/public/orders.d.ts +302 -0
  150. package/dist/packages/api-client/src/hooks/public/orders.js +50 -0
  151. package/dist/packages/api-client/src/hooks/public/products.d.ts +398 -0
  152. package/dist/packages/api-client/src/hooks/public/products.js +47 -0
  153. package/dist/packages/api-client/src/hooks/use-query-unwrapped.d.ts +20 -0
  154. package/dist/packages/api-client/src/hooks/use-query-unwrapped.js +22 -0
  155. package/dist/packages/api-client/src/hooks/useApiConfig.d.ts +12 -0
  156. package/dist/packages/api-client/src/hooks/useApiConfig.js +14 -0
  157. package/dist/packages/api-client/src/index.d.ts +20 -0
  158. package/dist/packages/api-client/src/index.js +25 -0
  159. package/dist/packages/api-client/src/provider.d.ts +36 -0
  160. package/dist/packages/api-client/src/provider.js +54 -0
  161. package/dist/packages/api-client/src/rpc-client.d.ts +9035 -0
  162. package/dist/packages/api-client/src/rpc-client.js +78 -0
  163. package/dist/packages/api-client/src/rpc-types.d.ts +76 -0
  164. package/dist/packages/api-client/src/rpc-types.js +7 -0
  165. package/dist/packages/api-client/src/types.d.ts +37 -0
  166. package/dist/packages/api-client/src/types.js +16 -0
  167. package/dist/packages/api-client/src/utils/query-keys.d.ts +106 -0
  168. package/dist/packages/api-client/src/utils/query-keys.js +108 -0
  169. package/dist/rpc-client.d.ts +685 -693
  170. package/package.json +10 -9
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Type-safe admin RPC hooks for delivery zone and state management
3
+ */
4
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
5
+ import { useQueryUnwrapped } from '../use-query-unwrapped';
6
+ import { createAdminRpcClients, authHeaders } from '../../rpc-client';
7
+ import { queryKeys } from '../../utils/query-keys';
8
+ import { useApiConfig } from '../useApiConfig';
9
+ // ============ STATES ============
10
+ /**
11
+ * Hook to list all states using admin RPC
12
+ */
13
+ export function useListStates(options) {
14
+ const { baseURL, getAuthToken } = useApiConfig();
15
+ return useQueryUnwrapped({
16
+ queryKey: queryKeys.admin.deliveryZones.states.list(),
17
+ queryFn: async () => {
18
+ const token = await getAuthToken();
19
+ const clients = createAdminRpcClients(baseURL);
20
+ const res = await clients.deliveryZones.states.$get({}, authHeaders(token));
21
+ if (!res.ok)
22
+ throw new Error(`Failed to fetch states: ${res.statusText}`);
23
+ return res.json();
24
+ },
25
+ ...options,
26
+ });
27
+ }
28
+ /**
29
+ * Hook to create a state using admin RPC
30
+ */
31
+ export function useCreateState(options) {
32
+ const { baseURL, getAuthToken } = useApiConfig();
33
+ const queryClient = useQueryClient();
34
+ return useMutation({
35
+ mutationFn: async (data) => {
36
+ const token = await getAuthToken();
37
+ const clients = createAdminRpcClients(baseURL);
38
+ const res = await clients.deliveryZones.states.$post({ json: data }, authHeaders(token));
39
+ if (!res.ok)
40
+ throw new Error(`Failed to create state: ${res.statusText}`);
41
+ return res.json();
42
+ },
43
+ onSuccess: () => {
44
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.states.all });
45
+ },
46
+ ...options,
47
+ });
48
+ }
49
+ /**
50
+ * Hook to update a state using admin RPC
51
+ */
52
+ export function useUpdateState(stateId, options) {
53
+ const { baseURL, getAuthToken } = useApiConfig();
54
+ const queryClient = useQueryClient();
55
+ return useMutation({
56
+ mutationFn: async (data) => {
57
+ const token = await getAuthToken();
58
+ const clients = createAdminRpcClients(baseURL);
59
+ const res = await clients.deliveryZones.states[':id'].$patch({ json: data, param: { id: stateId } }, authHeaders(token));
60
+ if (!res.ok)
61
+ throw new Error(`Failed to update state: ${res.statusText}`);
62
+ return res.json();
63
+ },
64
+ onSuccess: () => {
65
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.states.detail(stateId) });
66
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.states.all });
67
+ },
68
+ ...options,
69
+ });
70
+ }
71
+ /**
72
+ * Hook to delete a state using admin RPC
73
+ */
74
+ export function useDeleteState(stateId, options) {
75
+ const { baseURL, getAuthToken } = useApiConfig();
76
+ const queryClient = useQueryClient();
77
+ return useMutation({
78
+ mutationFn: async () => {
79
+ const token = await getAuthToken();
80
+ const clients = createAdminRpcClients(baseURL);
81
+ const res = await clients.deliveryZones.states[':id'].$delete({ param: { id: stateId } }, authHeaders(token));
82
+ if (!res.ok)
83
+ throw new Error(`Failed to delete state: ${res.statusText}`);
84
+ return res.json();
85
+ },
86
+ onSuccess: () => {
87
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.states.all });
88
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.zones.all });
89
+ },
90
+ ...options,
91
+ });
92
+ }
93
+ // ============ DELIVERY ZONES ============
94
+ /**
95
+ * Hook to list delivery zones using admin RPC
96
+ */
97
+ export function useListDeliveryZones(params, options) {
98
+ const { baseURL, getAuthToken } = useApiConfig();
99
+ return useQueryUnwrapped({
100
+ queryKey: queryKeys.admin.deliveryZones.zones.list(params),
101
+ queryFn: async () => {
102
+ const token = await getAuthToken();
103
+ const clients = createAdminRpcClients(baseURL);
104
+ const res = await clients.deliveryZones.zones.$get({ query: params }, authHeaders(token));
105
+ if (!res.ok)
106
+ throw new Error(`Failed to fetch delivery zones: ${res.statusText}`);
107
+ return res.json();
108
+ },
109
+ ...options,
110
+ });
111
+ }
112
+ /**
113
+ * Hook to create a delivery zone using admin RPC
114
+ */
115
+ export function useCreateDeliveryZone(options) {
116
+ const { baseURL, getAuthToken } = useApiConfig();
117
+ const queryClient = useQueryClient();
118
+ return useMutation({
119
+ mutationFn: async (data) => {
120
+ const token = await getAuthToken();
121
+ const clients = createAdminRpcClients(baseURL);
122
+ const res = await clients.deliveryZones.zones.$post({ json: data }, authHeaders(token));
123
+ if (!res.ok)
124
+ throw new Error(`Failed to create delivery zone: ${res.statusText}`);
125
+ return res.json();
126
+ },
127
+ onSuccess: () => {
128
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.zones.all });
129
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.states.all });
130
+ },
131
+ ...options,
132
+ });
133
+ }
134
+ /**
135
+ * Hook to update a delivery zone using admin RPC
136
+ */
137
+ export function useUpdateDeliveryZone(zoneId, options) {
138
+ const { baseURL, getAuthToken } = useApiConfig();
139
+ const queryClient = useQueryClient();
140
+ return useMutation({
141
+ mutationFn: async (data) => {
142
+ const token = await getAuthToken();
143
+ const clients = createAdminRpcClients(baseURL);
144
+ const res = await clients.deliveryZones.zones[':id'].$patch({ json: data, param: { id: zoneId } }, authHeaders(token));
145
+ if (!res.ok)
146
+ throw new Error(`Failed to update delivery zone: ${res.statusText}`);
147
+ return res.json();
148
+ },
149
+ onSuccess: () => {
150
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.zones.detail(zoneId) });
151
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.zones.all });
152
+ },
153
+ ...options,
154
+ });
155
+ }
156
+ /**
157
+ * Hook to delete a delivery zone using admin RPC
158
+ */
159
+ export function useDeleteDeliveryZone(zoneId, options) {
160
+ const { baseURL, getAuthToken } = useApiConfig();
161
+ const queryClient = useQueryClient();
162
+ return useMutation({
163
+ mutationFn: async () => {
164
+ const token = await getAuthToken();
165
+ const clients = createAdminRpcClients(baseURL);
166
+ const res = await clients.deliveryZones.zones[':id'].$delete({ param: { id: zoneId } }, authHeaders(token));
167
+ if (!res.ok)
168
+ throw new Error(`Failed to delete delivery zone: ${res.statusText}`);
169
+ return res.json();
170
+ },
171
+ onSuccess: () => {
172
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.deliveryZones.zones.all });
173
+ },
174
+ ...options,
175
+ });
176
+ }
@@ -0,0 +1,299 @@
1
+ /**
2
+ * Type-safe admin RPC hooks for discount code management
3
+ */
4
+ import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
5
+ import { createAdminRpcClients } from '../../rpc-client';
6
+ /**
7
+ * Hook to list discount codes using admin RPC
8
+ */
9
+ export declare function useListDiscountCodes(params?: {
10
+ page?: number;
11
+ limit?: number;
12
+ category?: string;
13
+ brandId?: string;
14
+ isActive?: string;
15
+ search?: string;
16
+ }, options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<{
17
+ data: {
18
+ value: number;
19
+ minPurchase: number;
20
+ maxDiscount: number;
21
+ createdAt: string;
22
+ updatedAt: string;
23
+ deletedAt: string;
24
+ brand: {
25
+ createdAt: string;
26
+ updatedAt: string;
27
+ deletedAt: string;
28
+ name: string;
29
+ id: string;
30
+ slug: string;
31
+ logoUrl: string | null;
32
+ siteUrl: string;
33
+ domain: string;
34
+ metaPixelId: string | null;
35
+ };
36
+ isExpired: boolean;
37
+ usagePercentage: number;
38
+ id: string;
39
+ brandId: string | null;
40
+ isActive: boolean;
41
+ code: string;
42
+ type: string;
43
+ usageLimit: number | null;
44
+ usageCount: number;
45
+ perCustomerLimit: number | null;
46
+ validFrom: string;
47
+ validUntil: string;
48
+ isAutoApply: boolean;
49
+ description: string | null;
50
+ category: string;
51
+ createdBy: string | null;
52
+ }[];
53
+ pagination: {
54
+ page: number;
55
+ limit: number;
56
+ total: number;
57
+ totalPages: number;
58
+ };
59
+ }, Error>;
60
+ /**
61
+ * Hook to get discount code by ID using admin RPC
62
+ */
63
+ export declare function useGetDiscountCode(codeId: string, options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes'][':id']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<{
64
+ _count: {
65
+ usageLog: number;
66
+ orders: number;
67
+ };
68
+ value: number;
69
+ minPurchase: number;
70
+ maxDiscount: number;
71
+ createdAt: string;
72
+ updatedAt: string;
73
+ deletedAt: string;
74
+ brand: {
75
+ createdAt: string;
76
+ updatedAt: string;
77
+ deletedAt: string;
78
+ name: string;
79
+ id: string;
80
+ slug: string;
81
+ logoUrl: string | null;
82
+ siteUrl: string;
83
+ domain: string;
84
+ metaPixelId: string | null;
85
+ };
86
+ isExpired: boolean;
87
+ usagePercentage: number;
88
+ id: string;
89
+ brandId: string | null;
90
+ isActive: boolean;
91
+ code: string;
92
+ type: string;
93
+ usageLimit: number | null;
94
+ usageCount: number;
95
+ perCustomerLimit: number | null;
96
+ validFrom: string;
97
+ validUntil: string;
98
+ isAutoApply: boolean;
99
+ description: string | null;
100
+ category: string;
101
+ createdBy: string | null;
102
+ }, Error>;
103
+ /**
104
+ * Hook to create a discount code using admin RPC
105
+ */
106
+ export declare function useCreateDiscountCode(options?: UseMutationOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes']['index']['$post']>>['json']>>, Error, any>): import("@tanstack/react-query").UseMutationResult<{
107
+ error: {
108
+ code: string;
109
+ message: string;
110
+ };
111
+ } | {
112
+ error: {
113
+ code: string;
114
+ message: string;
115
+ };
116
+ } | {
117
+ value: number;
118
+ minPurchase: number;
119
+ maxDiscount: number;
120
+ createdAt: string;
121
+ updatedAt: string;
122
+ deletedAt: string;
123
+ brand: {
124
+ createdAt: string;
125
+ updatedAt: string;
126
+ deletedAt: string;
127
+ name: string;
128
+ id: string;
129
+ slug: string;
130
+ logoUrl: string | null;
131
+ siteUrl: string;
132
+ domain: string;
133
+ metaPixelId: string | null;
134
+ };
135
+ isExpired: boolean;
136
+ usagePercentage: number;
137
+ id: string;
138
+ brandId: string | null;
139
+ isActive: boolean;
140
+ code: string;
141
+ type: string;
142
+ usageLimit: number | null;
143
+ usageCount: number;
144
+ perCustomerLimit: number | null;
145
+ validFrom: string;
146
+ validUntil: string;
147
+ isAutoApply: boolean;
148
+ description: string | null;
149
+ category: string;
150
+ createdBy: string | null;
151
+ } | {
152
+ error: {
153
+ code: string;
154
+ message: any;
155
+ };
156
+ }, Error, any, unknown>;
157
+ /**
158
+ * Hook to update a discount code using admin RPC
159
+ */
160
+ export declare function useUpdateDiscountCode(codeId: string, options?: UseMutationOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes'][':id']['$patch']>>['json']>>, Error, any>): import("@tanstack/react-query").UseMutationResult<{
161
+ value: number;
162
+ minPurchase: number;
163
+ maxDiscount: number;
164
+ createdAt: string;
165
+ updatedAt: string;
166
+ deletedAt: string;
167
+ brand: {
168
+ createdAt: string;
169
+ updatedAt: string;
170
+ deletedAt: string;
171
+ name: string;
172
+ id: string;
173
+ slug: string;
174
+ logoUrl: string | null;
175
+ siteUrl: string;
176
+ domain: string;
177
+ metaPixelId: string | null;
178
+ };
179
+ isExpired: boolean;
180
+ usagePercentage: number;
181
+ id: string;
182
+ brandId: string | null;
183
+ isActive: boolean;
184
+ code: string;
185
+ type: string;
186
+ usageLimit: number | null;
187
+ usageCount: number;
188
+ perCustomerLimit: number | null;
189
+ validFrom: string;
190
+ validUntil: string;
191
+ isAutoApply: boolean;
192
+ description: string | null;
193
+ category: string;
194
+ createdBy: string | null;
195
+ } | {
196
+ error: {
197
+ code: string;
198
+ message: string;
199
+ };
200
+ } | {
201
+ error: {
202
+ code: string;
203
+ message: string;
204
+ };
205
+ } | {
206
+ error: {
207
+ code: string;
208
+ message: any;
209
+ };
210
+ }, Error, any, unknown>;
211
+ /**
212
+ * Hook to delete a discount code using admin RPC
213
+ */
214
+ export declare function useDeleteDiscountCode(codeId: string, options?: UseMutationOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes'][':id']['$delete']>>['json']>>, Error, void>): import("@tanstack/react-query").UseMutationResult<unknown, Error, void, unknown>;
215
+ /**
216
+ * Hook to get discount code analytics using admin RPC
217
+ */
218
+ export declare function useGetDiscountCodeAnalytics(codeId: string, options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes'][':id']['analytics']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<{
219
+ totalUses: number;
220
+ usagePercentage: number;
221
+ totalDiscountGiven: number;
222
+ totalRevenue: number;
223
+ averageOrderValue: number;
224
+ averageDiscount: number;
225
+ uniqueCustomers: number;
226
+ usageByDate: import("hono/utils/types").JSONValue[];
227
+ topCustomers: import("hono/utils/types").JSONValue[];
228
+ recentUsages: {
229
+ id: string;
230
+ orderId: string;
231
+ customerPhone: string;
232
+ usedAt: string;
233
+ discountAmount: string;
234
+ orderTotal: string;
235
+ order: {
236
+ id: string;
237
+ phone: string;
238
+ };
239
+ }[];
240
+ value: number;
241
+ minPurchase: number;
242
+ maxDiscount: number;
243
+ createdAt: string;
244
+ updatedAt: string;
245
+ deletedAt: string;
246
+ brand: {
247
+ createdAt: string;
248
+ updatedAt: string;
249
+ deletedAt: string;
250
+ name: string;
251
+ id: string;
252
+ slug: string;
253
+ logoUrl: string | null;
254
+ siteUrl: string;
255
+ domain: string;
256
+ metaPixelId: string | null;
257
+ };
258
+ isExpired: boolean;
259
+ id: string;
260
+ brandId: string | null;
261
+ isActive: boolean;
262
+ code: string;
263
+ type: string;
264
+ usageLimit: number | null;
265
+ usageCount: number;
266
+ perCustomerLimit: number | null;
267
+ validFrom: string;
268
+ validUntil: string;
269
+ isAutoApply: boolean;
270
+ description: string | null;
271
+ category: string;
272
+ createdBy: string | null;
273
+ }, Error>;
274
+ /**
275
+ * Hook to bulk generate discount codes using admin RPC
276
+ */
277
+ export declare function useBulkGenerateDiscountCodes(options?: UseMutationOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes']['bulk-generate']['$post']>>['json']>>, Error, any>): import("@tanstack/react-query").UseMutationResult<{
278
+ codes: string[];
279
+ count: number;
280
+ } | {
281
+ error: {
282
+ code: string;
283
+ message: any;
284
+ };
285
+ }, Error, any, unknown>;
286
+ /**
287
+ * Hook to get discount code overview stats using admin RPC
288
+ */
289
+ export declare function useGetDiscountCodeOverviewStats(options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['discountCodes']['stats']['overview']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<{
290
+ totalCodes: number;
291
+ activeCodes: number;
292
+ totalUsage: number;
293
+ totalDiscountGiven: string | number;
294
+ totalRevenue: string | number;
295
+ codesByCategory: {
296
+ category: string;
297
+ _count: number;
298
+ }[];
299
+ }, Error>;
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Type-safe admin RPC hooks for discount code management
3
+ */
4
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
5
+ import { useQueryUnwrapped } from '../use-query-unwrapped';
6
+ import { createAdminRpcClients, authHeaders } from '../../rpc-client';
7
+ import { queryKeys } from '../../utils/query-keys';
8
+ import { useApiConfig } from '../useApiConfig';
9
+ /**
10
+ * Hook to list discount codes using admin RPC
11
+ */
12
+ export function useListDiscountCodes(params, options) {
13
+ const { baseURL, getAuthToken } = useApiConfig();
14
+ return useQueryUnwrapped({
15
+ queryKey: queryKeys.admin.discountCodes.list(params),
16
+ queryFn: async () => {
17
+ const token = await getAuthToken();
18
+ const clients = createAdminRpcClients(baseURL);
19
+ const res = await clients.discountCodes.index.$get({ query: params }, authHeaders(token));
20
+ if (!res.ok)
21
+ throw new Error(`Failed to fetch discount codes: ${res.statusText}`);
22
+ return res.json();
23
+ },
24
+ ...options,
25
+ });
26
+ }
27
+ /**
28
+ * Hook to get discount code by ID using admin RPC
29
+ */
30
+ export function useGetDiscountCode(codeId, options) {
31
+ const { baseURL, getAuthToken } = useApiConfig();
32
+ return useQueryUnwrapped({
33
+ queryKey: queryKeys.admin.discountCodes.detail(codeId),
34
+ queryFn: async () => {
35
+ const token = await getAuthToken();
36
+ const clients = createAdminRpcClients(baseURL);
37
+ const res = await clients.discountCodes[':id'].$get({ param: { id: codeId } }, authHeaders(token));
38
+ if (!res.ok)
39
+ throw new Error(`Failed to fetch discount code: ${res.statusText}`);
40
+ return res.json();
41
+ },
42
+ ...options,
43
+ });
44
+ }
45
+ /**
46
+ * Hook to create a discount code using admin RPC
47
+ */
48
+ export function useCreateDiscountCode(options) {
49
+ const { baseURL, getAuthToken } = useApiConfig();
50
+ const queryClient = useQueryClient();
51
+ return useMutation({
52
+ mutationFn: async (data) => {
53
+ const token = await getAuthToken();
54
+ const clients = createAdminRpcClients(baseURL);
55
+ const res = await clients.discountCodes.index.$post({ json: data }, authHeaders(token));
56
+ if (!res.ok)
57
+ throw new Error(`Failed to create discount code: ${res.statusText}`);
58
+ return res.json();
59
+ },
60
+ onSuccess: () => {
61
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.discountCodes.all });
62
+ },
63
+ ...options,
64
+ });
65
+ }
66
+ /**
67
+ * Hook to update a discount code using admin RPC
68
+ */
69
+ export function useUpdateDiscountCode(codeId, options) {
70
+ const { baseURL, getAuthToken } = useApiConfig();
71
+ const queryClient = useQueryClient();
72
+ return useMutation({
73
+ mutationFn: async (data) => {
74
+ const token = await getAuthToken();
75
+ const clients = createAdminRpcClients(baseURL);
76
+ const res = await clients.discountCodes[':id'].$patch({ json: data, param: { id: codeId } }, authHeaders(token));
77
+ if (!res.ok)
78
+ throw new Error(`Failed to update discount code: ${res.statusText}`);
79
+ return res.json();
80
+ },
81
+ onSuccess: () => {
82
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.discountCodes.detail(codeId) });
83
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.discountCodes.all });
84
+ },
85
+ ...options,
86
+ });
87
+ }
88
+ /**
89
+ * Hook to delete a discount code using admin RPC
90
+ */
91
+ export function useDeleteDiscountCode(codeId, options) {
92
+ const { baseURL, getAuthToken } = useApiConfig();
93
+ const queryClient = useQueryClient();
94
+ return useMutation({
95
+ mutationFn: async () => {
96
+ const token = await getAuthToken();
97
+ const clients = createAdminRpcClients(baseURL);
98
+ const res = await clients.discountCodes[':id'].$delete({ param: { id: codeId } }, authHeaders(token));
99
+ if (!res.ok)
100
+ throw new Error(`Failed to delete discount code: ${res.statusText}`);
101
+ return res.json();
102
+ },
103
+ onSuccess: () => {
104
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.discountCodes.all });
105
+ },
106
+ ...options,
107
+ });
108
+ }
109
+ /**
110
+ * Hook to get discount code analytics using admin RPC
111
+ */
112
+ export function useGetDiscountCodeAnalytics(codeId, options) {
113
+ const { baseURL, getAuthToken } = useApiConfig();
114
+ return useQueryUnwrapped({
115
+ queryKey: queryKeys.admin.discountCodes.analytics(codeId),
116
+ queryFn: async () => {
117
+ const token = await getAuthToken();
118
+ const clients = createAdminRpcClients(baseURL);
119
+ const res = await clients.discountCodes[':id'].analytics.$get({ param: { id: codeId } }, authHeaders(token));
120
+ if (!res.ok)
121
+ throw new Error(`Failed to fetch discount code analytics: ${res.statusText}`);
122
+ return res.json();
123
+ },
124
+ ...options,
125
+ });
126
+ }
127
+ /**
128
+ * Hook to bulk generate discount codes using admin RPC
129
+ */
130
+ export function useBulkGenerateDiscountCodes(options) {
131
+ const { baseURL, getAuthToken } = useApiConfig();
132
+ const queryClient = useQueryClient();
133
+ return useMutation({
134
+ mutationFn: async (data) => {
135
+ const token = await getAuthToken();
136
+ const clients = createAdminRpcClients(baseURL);
137
+ const res = await clients.discountCodes['bulk-generate'].$post({ json: data }, authHeaders(token));
138
+ if (!res.ok)
139
+ throw new Error(`Failed to bulk generate discount codes: ${res.statusText}`);
140
+ return res.json();
141
+ },
142
+ onSuccess: () => {
143
+ queryClient.invalidateQueries({ queryKey: queryKeys.admin.discountCodes.all });
144
+ },
145
+ ...options,
146
+ });
147
+ }
148
+ /**
149
+ * Hook to get discount code overview stats using admin RPC
150
+ */
151
+ export function useGetDiscountCodeOverviewStats(options) {
152
+ const { baseURL, getAuthToken } = useApiConfig();
153
+ return useQueryUnwrapped({
154
+ queryKey: queryKeys.admin.discountCodes.overviewStats(),
155
+ queryFn: async () => {
156
+ const token = await getAuthToken();
157
+ const clients = createAdminRpcClients(baseURL);
158
+ const res = await clients.discountCodes.stats.overview.$get({}, authHeaders(token));
159
+ if (!res.ok)
160
+ throw new Error(`Failed to fetch discount code overview stats: ${res.statusText}`);
161
+ return res.json();
162
+ },
163
+ ...options,
164
+ });
165
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Type-safe admin RPC hooks
3
+ *
4
+ * Export all admin RPC hooks for use in admin dashboards
5
+ */
6
+ export * from './orders';
7
+ export * from './brands';
8
+ export * from './products';
9
+ export * from './variants';
10
+ export * from './warehouses';
11
+ export * from './inventory';
12
+ export * from './customers';
13
+ export * from './stats';
14
+ export * from './abandoned-carts';
15
+ export * from './discount-codes';
16
+ export * from './delivery-zones';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Type-safe admin RPC hooks
3
+ *
4
+ * Export all admin RPC hooks for use in admin dashboards
5
+ */
6
+ export * from './orders';
7
+ export * from './brands';
8
+ export * from './products';
9
+ export * from './variants';
10
+ export * from './warehouses';
11
+ export * from './inventory';
12
+ export * from './customers';
13
+ export * from './stats';
14
+ export * from './abandoned-carts';
15
+ export * from './discount-codes';
16
+ export * from './delivery-zones';