@instockng/api-client 1.0.4 → 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.
@@ -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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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, authToken } = useApiConfig();
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(authToken));
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();
@@ -10,12 +10,13 @@ import { useApiConfig } from '../useApiConfig';
10
10
  * Hook to get inventory overview using admin RPC
11
11
  */
12
12
  export function useListInventory(params, options) {
13
- const { baseURL, authToken } = useApiConfig();
13
+ const { baseURL, getAuthToken } = useApiConfig();
14
14
  return useQueryUnwrapped({
15
15
  queryKey: queryKeys.admin.inventory.list(params),
16
16
  queryFn: async () => {
17
+ const token = await getAuthToken();
17
18
  const clients = createAdminRpcClients(baseURL);
18
- const res = await clients.inventory.index.$get({ query: params }, authHeaders(authToken));
19
+ const res = await clients.inventory.index.$get({ query: params }, authHeaders(token));
19
20
  if (!res.ok)
20
21
  throw new Error(`Failed to fetch inventory: ${res.statusText}`);
21
22
  return res.json();
@@ -27,12 +28,13 @@ export function useListInventory(params, options) {
27
28
  * Hook to adjust inventory using admin RPC
28
29
  */
29
30
  export function useAdjustInventory(options) {
30
- const { baseURL, authToken } = useApiConfig();
31
+ const { baseURL, getAuthToken } = useApiConfig();
31
32
  const queryClient = useQueryClient();
32
33
  return useMutation({
33
34
  mutationFn: async (data) => {
35
+ const token = await getAuthToken();
34
36
  const clients = createAdminRpcClients(baseURL);
35
- const res = await clients.inventory.adjust.$post({ json: data }, authHeaders(authToken));
37
+ const res = await clients.inventory.adjust.$post({ json: data }, authHeaders(token));
36
38
  if (!res.ok)
37
39
  throw new Error(`Failed to adjust inventory: ${res.statusText}`);
38
40
  return res.json();
@@ -49,12 +51,13 @@ export function useAdjustInventory(options) {
49
51
  * Hook to transfer inventory between warehouses using admin RPC
50
52
  */
51
53
  export function useTransferInventory(options) {
52
- const { baseURL, authToken } = useApiConfig();
54
+ const { baseURL, getAuthToken } = useApiConfig();
53
55
  const queryClient = useQueryClient();
54
56
  return useMutation({
55
57
  mutationFn: async (data) => {
58
+ const token = await getAuthToken();
56
59
  const clients = createAdminRpcClients(baseURL);
57
- const res = await clients.inventory.transfer.$post({ json: data }, authHeaders(authToken));
60
+ const res = await clients.inventory.transfer.$post({ json: data }, authHeaders(token));
58
61
  if (!res.ok)
59
62
  throw new Error(`Failed to transfer inventory: ${res.statusText}`);
60
63
  return res.json();
@@ -70,12 +73,13 @@ export function useTransferInventory(options) {
70
73
  * Hook to get inventory transaction history using admin RPC
71
74
  */
72
75
  export function useGetInventoryTransactions(params, options) {
73
- const { baseURL, authToken } = useApiConfig();
76
+ const { baseURL, getAuthToken } = useApiConfig();
74
77
  return useQueryUnwrapped({
75
78
  queryKey: queryKeys.admin.inventory.transactions(params),
76
79
  queryFn: async () => {
80
+ const token = await getAuthToken();
77
81
  const clients = createAdminRpcClients(baseURL);
78
- const res = await clients.inventory.transactions.$get({ query: params }, authHeaders(authToken));
82
+ const res = await clients.inventory.transactions.$get({ query: params }, authHeaders(token));
79
83
  if (!res.ok)
80
84
  throw new Error(`Failed to fetch inventory transactions: ${res.statusText}`);
81
85
  return res.json();
@@ -87,12 +91,13 @@ export function useGetInventoryTransactions(params, options) {
87
91
  * Hook to get low stock alerts using admin RPC
88
92
  */
89
93
  export function useGetLowStockVariants(params, options) {
90
- const { baseURL, authToken } = useApiConfig();
94
+ const { baseURL, getAuthToken } = useApiConfig();
91
95
  return useQueryUnwrapped({
92
96
  queryKey: queryKeys.admin.inventory.lowStock(params?.brandId),
93
97
  queryFn: async () => {
98
+ const token = await getAuthToken();
94
99
  const clients = createAdminRpcClients(baseURL);
95
- const res = await clients.inventory['low-stock'].$get({ query: params }, authHeaders(authToken));
100
+ const res = await clients.inventory['low-stock'].$get({ query: params }, authHeaders(token));
96
101
  if (!res.ok)
97
102
  throw new Error(`Failed to fetch low stock alerts: ${res.statusText}`);
98
103
  return res.json();
@@ -20,12 +20,13 @@ import { useApiConfig } from '../useApiConfig';
20
20
  * ```
21
21
  */
22
22
  export function useListOrders(options) {
23
- const { baseURL, authToken } = useApiConfig();
23
+ const { baseURL, getAuthToken } = useApiConfig();
24
24
  return useQueryUnwrapped({
25
25
  queryKey: queryKeys.admin.orders.list(),
26
26
  queryFn: async () => {
27
+ const token = await getAuthToken();
27
28
  const clients = createAdminRpcClients(baseURL);
28
- const res = await clients.orders.index.$get({}, authHeaders(authToken));
29
+ const res = await clients.orders.index.$get({}, authHeaders(token));
29
30
  if (!res.ok) {
30
31
  throw new Error(`Failed to fetch orders: ${res.statusText}`);
31
32
  }
@@ -46,12 +47,13 @@ export function useListOrders(options) {
46
47
  * ```
47
48
  */
48
49
  export function useGetOrder(orderId, options) {
49
- const { baseURL, authToken } = useApiConfig();
50
+ const { baseURL, getAuthToken } = useApiConfig();
50
51
  return useQueryUnwrapped({
51
52
  queryKey: queryKeys.admin.orders.detail(orderId),
52
53
  queryFn: async () => {
54
+ const token = await getAuthToken();
53
55
  const clients = createAdminRpcClients(baseURL);
54
- const res = await clients.orders[':id'].$get({ param: { id: orderId } }, authHeaders(authToken));
56
+ const res = await clients.orders[':id'].$get({ param: { id: orderId } }, authHeaders(token));
55
57
  if (!res.ok) {
56
58
  throw new Error(`Failed to fetch order: ${res.statusText}`);
57
59
  }
@@ -76,12 +78,13 @@ export function useGetOrder(orderId, options) {
76
78
  * ```
77
79
  */
78
80
  export function useCreateOrder(options) {
79
- const { baseURL, authToken } = useApiConfig();
81
+ const { baseURL, getAuthToken } = useApiConfig();
80
82
  const queryClient = useQueryClient();
81
83
  return useMutation({
82
84
  mutationFn: async (data) => {
85
+ const token = await getAuthToken();
83
86
  const clients = createAdminRpcClients(baseURL);
84
- const res = await clients.orders.index.$post({ json: data }, authHeaders(authToken));
87
+ const res = await clients.orders.index.$post({ json: data }, authHeaders(token));
85
88
  if (!res.ok) {
86
89
  throw new Error(`Failed to create order: ${res.statusText}`);
87
90
  }
@@ -100,12 +103,13 @@ export function useCreateOrder(options) {
100
103
  * @param options - React Query mutation options
101
104
  */
102
105
  export function useUpdateOrder(orderId, options) {
103
- const { baseURL, authToken } = useApiConfig();
106
+ const { baseURL, getAuthToken } = useApiConfig();
104
107
  const queryClient = useQueryClient();
105
108
  return useMutation({
106
109
  mutationFn: async (data) => {
110
+ const token = await getAuthToken();
107
111
  const clients = createAdminRpcClients(baseURL);
108
- const res = await clients.orders[':id'].$patch({ param: { id: orderId }, json: data }, authHeaders(authToken));
112
+ const res = await clients.orders[':id'].$patch({ param: { id: orderId }, json: data }, authHeaders(token));
109
113
  if (!res.ok) {
110
114
  throw new Error(`Failed to update order: ${res.statusText}`);
111
115
  }
@@ -125,12 +129,13 @@ export function useUpdateOrder(orderId, options) {
125
129
  * @param options - React Query mutation options
126
130
  */
127
131
  export function useUpdateOrderStatus(orderId, options) {
128
- const { baseURL, authToken } = useApiConfig();
132
+ const { baseURL, getAuthToken } = useApiConfig();
129
133
  const queryClient = useQueryClient();
130
134
  return useMutation({
131
135
  mutationFn: async (data) => {
136
+ const token = await getAuthToken();
132
137
  const clients = createAdminRpcClients(baseURL);
133
- const res = await clients.orders[':id'].status.$patch({ param: { id: orderId }, json: data }, authHeaders(authToken));
138
+ const res = await clients.orders[':id'].status.$patch({ param: { id: orderId }, json: data }, authHeaders(token));
134
139
  if (!res.ok) {
135
140
  throw new Error(`Failed to update order status: ${res.statusText}`);
136
141
  }
@@ -150,12 +155,13 @@ export function useUpdateOrderStatus(orderId, options) {
150
155
  * @param options - React Query mutation options
151
156
  */
152
157
  export function useDeleteOrder(orderId, options) {
153
- const { baseURL, authToken } = useApiConfig();
158
+ const { baseURL, getAuthToken } = useApiConfig();
154
159
  const queryClient = useQueryClient();
155
160
  return useMutation({
156
161
  mutationFn: async () => {
162
+ const token = await getAuthToken();
157
163
  const clients = createAdminRpcClients(baseURL);
158
- const res = await clients.orders[':id'].$delete({ param: { id: orderId } }, authHeaders(authToken));
164
+ const res = await clients.orders[':id'].$delete({ param: { id: orderId } }, authHeaders(token));
159
165
  if (!res.ok) {
160
166
  throw new Error(`Failed to delete order: ${res.statusText}`);
161
167
  }
@@ -7,12 +7,13 @@ import { createAdminRpcClients, authHeaders } from '../../rpc-client';
7
7
  import { queryKeys } from '../../utils/query-keys';
8
8
  import { useApiConfig } from '../useApiConfig';
9
9
  export function useListProducts(brandId, options) {
10
- const { baseURL, authToken } = useApiConfig();
10
+ const { baseURL, getAuthToken } = useApiConfig();
11
11
  return useQueryUnwrapped({
12
12
  queryKey: queryKeys.admin.products.list(brandId),
13
13
  queryFn: async () => {
14
+ const token = await getAuthToken();
14
15
  const clients = createAdminRpcClients(baseURL);
15
- const res = await clients.products.index.$get(brandId ? { query: { brandId } } : {}, authHeaders(authToken));
16
+ const res = await clients.products.index.$get(brandId ? { query: { brandId } } : {}, authHeaders(token));
16
17
  if (!res.ok)
17
18
  throw new Error(`Failed to fetch products: ${res.statusText}`);
18
19
  return res.json();
@@ -21,12 +22,13 @@ export function useListProducts(brandId, options) {
21
22
  });
22
23
  }
23
24
  export function useGetProduct(productId, options) {
24
- const { baseURL, authToken } = useApiConfig();
25
+ const { baseURL, getAuthToken } = useApiConfig();
25
26
  return useQueryUnwrapped({
26
27
  queryKey: queryKeys.admin.products.detail(productId),
27
28
  queryFn: async () => {
29
+ const token = await getAuthToken();
28
30
  const clients = createAdminRpcClients(baseURL);
29
- const res = await clients.products[':id'].$get({ param: { id: productId } }, authHeaders(authToken));
31
+ const res = await clients.products[':id'].$get({ param: { id: productId } }, authHeaders(token));
30
32
  if (!res.ok)
31
33
  throw new Error(`Failed to fetch product: ${res.statusText}`);
32
34
  return res.json();
@@ -35,12 +37,13 @@ export function useGetProduct(productId, options) {
35
37
  });
36
38
  }
37
39
  export function useCreateProduct(options) {
38
- const { baseURL, authToken } = useApiConfig();
40
+ const { baseURL, getAuthToken } = useApiConfig();
39
41
  const queryClient = useQueryClient();
40
42
  return useMutation({
41
43
  mutationFn: async (data) => {
44
+ const token = await getAuthToken();
42
45
  const clients = createAdminRpcClients(baseURL);
43
- const res = await clients.products.index.$post({ json: data }, authHeaders(authToken));
46
+ const res = await clients.products.index.$post({ json: data }, authHeaders(token));
44
47
  if (!res.ok)
45
48
  throw new Error(`Failed to create product: ${res.statusText}`);
46
49
  return res.json();
@@ -50,12 +53,13 @@ export function useCreateProduct(options) {
50
53
  });
51
54
  }
52
55
  export function useUpdateProduct(productId, options) {
53
- const { baseURL, authToken } = useApiConfig();
56
+ const { baseURL, getAuthToken } = useApiConfig();
54
57
  const queryClient = useQueryClient();
55
58
  return useMutation({
56
59
  mutationFn: async (data) => {
60
+ const token = await getAuthToken();
57
61
  const clients = createAdminRpcClients(baseURL);
58
- const res = await clients.products[':id'].$patch({ param: { id: productId }, json: data }, authHeaders(authToken));
62
+ const res = await clients.products[':id'].$patch({ param: { id: productId }, json: data }, authHeaders(token));
59
63
  if (!res.ok)
60
64
  throw new Error(`Failed to update product: ${res.statusText}`);
61
65
  return res.json();
@@ -68,12 +72,13 @@ export function useUpdateProduct(productId, options) {
68
72
  });
69
73
  }
70
74
  export function useDeleteProduct(productId, options) {
71
- const { baseURL, authToken } = useApiConfig();
75
+ const { baseURL, getAuthToken } = useApiConfig();
72
76
  const queryClient = useQueryClient();
73
77
  return useMutation({
74
78
  mutationFn: async () => {
79
+ const token = await getAuthToken();
75
80
  const clients = createAdminRpcClients(baseURL);
76
- const res = await clients.products[':id'].$delete({ param: { id: productId } }, authHeaders(authToken));
81
+ const res = await clients.products[':id'].$delete({ param: { id: productId } }, authHeaders(token));
77
82
  if (!res.ok)
78
83
  throw new Error(`Failed to delete product: ${res.statusText}`);
79
84
  return res.json();
@@ -9,12 +9,13 @@ import { useApiConfig } from '../useApiConfig';
9
9
  * Hook to get dashboard statistics using admin RPC
10
10
  */
11
11
  export function useGetStats(params, options) {
12
- const { baseURL, authToken } = useApiConfig();
12
+ const { baseURL, getAuthToken } = useApiConfig();
13
13
  return useQueryUnwrapped({
14
14
  queryKey: queryKeys.admin.stats.overview(params?.brandId),
15
15
  queryFn: async () => {
16
+ const token = await getAuthToken();
16
17
  const clients = createAdminRpcClients(baseURL);
17
- const res = await clients.stats.index.$get({ query: params }, authHeaders(authToken));
18
+ const res = await clients.stats.index.$get({ query: params }, authHeaders(token));
18
19
  if (!res.ok)
19
20
  throw new Error(`Failed to fetch statistics: ${res.statusText}`);
20
21
  return res.json();
@@ -10,12 +10,13 @@ import { useApiConfig } from '../useApiConfig';
10
10
  * Hook to search variants across all products using admin RPC
11
11
  */
12
12
  export function useSearchVariants(params, options) {
13
- const { baseURL, authToken } = useApiConfig();
13
+ const { baseURL, getAuthToken } = useApiConfig();
14
14
  return useQueryUnwrapped({
15
15
  queryKey: queryKeys.admin.variants.search(params),
16
16
  queryFn: async () => {
17
+ const token = await getAuthToken();
17
18
  const clients = createAdminRpcClients(baseURL);
18
- const res = await clients.variants.index.$get({ query: params }, authHeaders(authToken));
19
+ const res = await clients.variants.index.$get({ query: params }, authHeaders(token));
19
20
  if (!res.ok)
20
21
  throw new Error(`Failed to search variants: ${res.statusText}`);
21
22
  return res.json();
@@ -27,12 +28,13 @@ export function useSearchVariants(params, options) {
27
28
  * Hook to list variants for a specific product using admin RPC
28
29
  */
29
30
  export function useListProductVariants(productId, options) {
30
- const { baseURL, authToken } = useApiConfig();
31
+ const { baseURL, getAuthToken } = useApiConfig();
31
32
  return useQueryUnwrapped({
32
33
  queryKey: queryKeys.admin.variants.byProduct(productId),
33
34
  queryFn: async () => {
35
+ const token = await getAuthToken();
34
36
  const clients = createAdminRpcClients(baseURL);
35
- const res = await clients.variants.products[':productId'].variants.$get({ param: { productId } }, authHeaders(authToken));
37
+ const res = await clients.variants.products[':productId'].variants.$get({ param: { productId } }, authHeaders(token));
36
38
  if (!res.ok)
37
39
  throw new Error(`Failed to fetch product variants: ${res.statusText}`);
38
40
  return res.json();
@@ -44,12 +46,13 @@ export function useListProductVariants(productId, options) {
44
46
  * Hook to create a variant for a product using admin RPC
45
47
  */
46
48
  export function useCreateVariant(productId, options) {
47
- const { baseURL, authToken } = useApiConfig();
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.variants.products[':productId'].variants.$post({ json: data, param: { productId } }, authHeaders(authToken));
55
+ const res = await clients.variants.products[':productId'].variants.$post({ json: data, param: { productId } }, authHeaders(token));
53
56
  if (!res.ok)
54
57
  throw new Error(`Failed to create variant: ${res.statusText}`);
55
58
  return res.json();
@@ -65,12 +68,13 @@ export function useCreateVariant(productId, options) {
65
68
  * Hook to update a variant using admin RPC
66
69
  */
67
70
  export function useUpdateVariant(variantId, options) {
68
- const { baseURL, authToken } = useApiConfig();
71
+ const { baseURL, getAuthToken } = useApiConfig();
69
72
  const queryClient = useQueryClient();
70
73
  return useMutation({
71
74
  mutationFn: async (data) => {
75
+ const token = await getAuthToken();
72
76
  const clients = createAdminRpcClients(baseURL);
73
- const res = await clients.variants[':id'].$patch({ json: data, param: { id: variantId } }, authHeaders(authToken));
77
+ const res = await clients.variants[':id'].$patch({ json: data, param: { id: variantId } }, authHeaders(token));
74
78
  if (!res.ok)
75
79
  throw new Error(`Failed to update variant: ${res.statusText}`);
76
80
  return res.json();
@@ -86,12 +90,13 @@ export function useUpdateVariant(variantId, options) {
86
90
  * Hook to get variant inventory across all warehouses using admin RPC
87
91
  */
88
92
  export function useGetVariantInventory(variantId, options) {
89
- const { baseURL, authToken } = useApiConfig();
93
+ const { baseURL, getAuthToken } = useApiConfig();
90
94
  return useQueryUnwrapped({
91
95
  queryKey: queryKeys.admin.variants.inventory(variantId),
92
96
  queryFn: async () => {
97
+ const token = await getAuthToken();
93
98
  const clients = createAdminRpcClients(baseURL);
94
- const res = await clients.variants[':id'].inventory.$get({ param: { id: variantId } }, authHeaders(authToken));
99
+ const res = await clients.variants[':id'].inventory.$get({ param: { id: variantId } }, authHeaders(token));
95
100
  if (!res.ok)
96
101
  throw new Error(`Failed to fetch variant inventory: ${res.statusText}`);
97
102
  return res.json();
@@ -103,12 +108,13 @@ export function useGetVariantInventory(variantId, options) {
103
108
  * Hook to delete a variant using admin RPC
104
109
  */
105
110
  export function useDeleteVariant(variantId, options) {
106
- const { baseURL, authToken } = useApiConfig();
111
+ const { baseURL, getAuthToken } = useApiConfig();
107
112
  const queryClient = useQueryClient();
108
113
  return useMutation({
109
114
  mutationFn: async () => {
115
+ const token = await getAuthToken();
110
116
  const clients = createAdminRpcClients(baseURL);
111
- const res = await clients.variants[':id'].$delete({ param: { id: variantId } }, authHeaders(authToken));
117
+ const res = await clients.variants[':id'].$delete({ param: { id: variantId } }, authHeaders(token));
112
118
  if (!res.ok)
113
119
  throw new Error(`Failed to delete variant: ${res.statusText}`);
114
120
  return res.json();
@@ -10,12 +10,13 @@ import { useApiConfig } from '../useApiConfig';
10
10
  * Hook to list all warehouses using admin RPC
11
11
  */
12
12
  export function useListWarehouses(options) {
13
- const { baseURL, authToken } = useApiConfig();
13
+ const { baseURL, getAuthToken } = useApiConfig();
14
14
  return useQueryUnwrapped({
15
15
  queryKey: queryKeys.admin.warehouses.list(),
16
16
  queryFn: async () => {
17
+ const token = await getAuthToken();
17
18
  const clients = createAdminRpcClients(baseURL);
18
- const res = await clients.warehouses.index.$get({}, authHeaders(authToken));
19
+ const res = await clients.warehouses.index.$get({}, authHeaders(token));
19
20
  if (!res.ok)
20
21
  throw new Error(`Failed to fetch warehouses: ${res.statusText}`);
21
22
  return res.json();
@@ -27,12 +28,13 @@ export function useListWarehouses(options) {
27
28
  * Hook to create a warehouse using admin RPC
28
29
  */
29
30
  export function useCreateWarehouse(options) {
30
- const { baseURL, authToken } = useApiConfig();
31
+ const { baseURL, getAuthToken } = useApiConfig();
31
32
  const queryClient = useQueryClient();
32
33
  return useMutation({
33
34
  mutationFn: async (data) => {
35
+ const token = await getAuthToken();
34
36
  const clients = createAdminRpcClients(baseURL);
35
- const res = await clients.warehouses.index.$post({ json: data }, authHeaders(authToken));
37
+ const res = await clients.warehouses.index.$post({ json: data }, authHeaders(token));
36
38
  if (!res.ok)
37
39
  throw new Error(`Failed to create warehouse: ${res.statusText}`);
38
40
  return res.json();
@@ -47,12 +49,13 @@ export function useCreateWarehouse(options) {
47
49
  * Hook to update a warehouse using admin RPC
48
50
  */
49
51
  export function useUpdateWarehouse(warehouseId, options) {
50
- const { baseURL, authToken } = useApiConfig();
52
+ const { baseURL, getAuthToken } = useApiConfig();
51
53
  const queryClient = useQueryClient();
52
54
  return useMutation({
53
55
  mutationFn: async (data) => {
56
+ const token = await getAuthToken();
54
57
  const clients = createAdminRpcClients(baseURL);
55
- const res = await clients.warehouses[':id'].$patch({ json: data, param: { id: warehouseId } }, authHeaders(authToken));
58
+ const res = await clients.warehouses[':id'].$patch({ json: data, param: { id: warehouseId } }, authHeaders(token));
56
59
  if (!res.ok)
57
60
  throw new Error(`Failed to update warehouse: ${res.statusText}`);
58
61
  return res.json();
@@ -68,12 +71,13 @@ export function useUpdateWarehouse(warehouseId, options) {
68
71
  * Hook to get warehouse inventory using admin RPC
69
72
  */
70
73
  export function useGetWarehouseInventory(warehouseId, options) {
71
- const { baseURL, authToken } = useApiConfig();
74
+ const { baseURL, getAuthToken } = useApiConfig();
72
75
  return useQueryUnwrapped({
73
76
  queryKey: queryKeys.admin.warehouses.inventory(warehouseId),
74
77
  queryFn: async () => {
78
+ const token = await getAuthToken();
75
79
  const clients = createAdminRpcClients(baseURL);
76
- const res = await clients.warehouses[':id'].inventory.$get({ param: { id: warehouseId } }, authHeaders(authToken));
80
+ const res = await clients.warehouses[':id'].inventory.$get({ param: { id: warehouseId } }, authHeaders(token));
77
81
  if (!res.ok)
78
82
  throw new Error(`Failed to fetch warehouse inventory: ${res.statusText}`);
79
83
  return res.json();
@@ -85,12 +89,13 @@ export function useGetWarehouseInventory(warehouseId, options) {
85
89
  * Hook to delete a warehouse using admin RPC
86
90
  */
87
91
  export function useDeleteWarehouse(warehouseId, options) {
88
- const { baseURL, authToken } = useApiConfig();
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.warehouses[':id'].$delete({ param: { id: warehouseId } }, authHeaders(authToken));
98
+ const res = await clients.warehouses[':id'].$delete({ param: { id: warehouseId } }, authHeaders(token));
94
99
  if (!res.ok)
95
100
  throw new Error(`Failed to delete warehouse: ${res.statusText}`);
96
101
  return res.json();
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * Hook to access API configuration from context
3
3
  */
4
+ import { type AuthTokenGetter } from '../provider';
4
5
  export interface ApiConfig {
5
6
  baseURL: string;
6
- authToken: string;
7
+ getAuthToken: AuthTokenGetter;
7
8
  }
8
9
  /**
9
10
  * Get API configuration from context
@@ -6,9 +6,9 @@ import { useApiClientContext } from '../provider';
6
6
  * Get API configuration from context
7
7
  */
8
8
  export function useApiConfig() {
9
- const { baseURL, authToken } = useApiClientContext();
9
+ const { baseURL, getAuthToken } = useApiClientContext();
10
10
  return {
11
11
  baseURL,
12
- authToken: authToken || '',
12
+ getAuthToken,
13
13
  };
14
14
  }
@@ -4,14 +4,15 @@
4
4
  import { ReactNode } from 'react';
5
5
  import { QueryClient } from '@tanstack/react-query';
6
6
  import { AxiosError } from 'axios';
7
+ export type AuthTokenGetter = () => Promise<string>;
7
8
  interface ApiClientContextValue {
8
9
  baseURL: string;
9
- authToken?: string;
10
+ getAuthToken: AuthTokenGetter;
10
11
  }
11
12
  export interface ApiClientProviderProps {
12
13
  children: ReactNode;
13
14
  baseURL?: string;
14
- authToken?: string;
15
+ getAuthToken: AuthTokenGetter;
15
16
  onError?: (error: AxiosError) => void;
16
17
  queryClient?: QueryClient;
17
18
  }
@@ -20,12 +21,14 @@ export interface ApiClientProviderProps {
20
21
  *
21
22
  * @example
22
23
  * ```tsx
23
- * <ApiClientProvider>
24
+ * const { getToken } = useAuth();
25
+ *
26
+ * <ApiClientProvider getAuthToken={getToken}>
24
27
  * <App />
25
28
  * </ApiClientProvider>
26
29
  * ```
27
30
  */
28
- export declare function ApiClientProvider({ children, baseURL, authToken, onError, queryClient: externalQueryClient }: ApiClientProviderProps): import("react/jsx-runtime").JSX.Element;
31
+ export declare function ApiClientProvider({ children, baseURL, getAuthToken, onError, queryClient: externalQueryClient }: ApiClientProviderProps): import("react/jsx-runtime").JSX.Element;
29
32
  /**
30
33
  * Hook to access API client context
31
34
  */
@@ -11,12 +11,14 @@ const ApiClientContext = createContext(null);
11
11
  *
12
12
  * @example
13
13
  * ```tsx
14
- * <ApiClientProvider>
14
+ * const { getToken } = useAuth();
15
+ *
16
+ * <ApiClientProvider getAuthToken={getToken}>
15
17
  * <App />
16
18
  * </ApiClientProvider>
17
19
  * ```
18
20
  */
19
- export function ApiClientProvider({ children, baseURL = 'https://oms-api.instock.ng', authToken, onError, queryClient: externalQueryClient }) {
21
+ export function ApiClientProvider({ children, baseURL = 'https://oms-api.instock.ng', getAuthToken, onError, queryClient: externalQueryClient }) {
20
22
  // Initialize client synchronously on first render
21
23
  const config = {
22
24
  baseURL,
@@ -38,7 +40,7 @@ export function ApiClientProvider({ children, baseURL = 'https://oms-api.instock
38
40
  },
39
41
  },
40
42
  }), [externalQueryClient]);
41
- return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(ApiClientContext.Provider, { value: { baseURL, authToken }, children: children }) }));
43
+ return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(ApiClientContext.Provider, { value: { baseURL, getAuthToken }, children: children }) }));
42
44
  }
43
45
  /**
44
46
  * Hook to access API client context
@@ -9,6 +9,7 @@
9
9
  * const [selectedBrand, setSelectedBrand] = useState<Brand | null>(null)
10
10
  * ```
11
11
  */
12
+ import type { AdminOrderFull, PublicCartResponse } from './rpc-types';
12
13
  export * from './hooks/public';
13
14
  export * as admin from './hooks/admin';
14
15
  export * from './rpc-types';
@@ -31,3 +32,6 @@ export type { Customer } from './rpc-types';
31
32
  export type { CustomerOrder } from './rpc-types';
32
33
  export type { AdminDeliveryZone } from './rpc-types';
33
34
  export type { AdminState } from './rpc-types';
35
+ export type OrderStatus = AdminOrderFull['status'];
36
+ export type ProspectReason = NonNullable<AdminOrderFull['prospectReason']>;
37
+ export type PaymentMethod = PublicCartResponse['availablePaymentMethods'][number];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instockng/api-client",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "React Query hooks for OMS API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",