@instockng/api-client 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/enum-types.d.ts +8 -0
- package/dist/enum-types.js +5 -0
- package/dist/fetchers/carts.js +5 -0
- package/dist/hooks/admin/abandoned-carts.js +12 -8
- package/dist/hooks/admin/brands.js +15 -10
- package/dist/hooks/admin/customers.js +3 -2
- package/dist/hooks/admin/delivery-zones.js +24 -16
- package/dist/hooks/admin/discount-codes.js +24 -16
- package/dist/hooks/admin/inventory.js +15 -10
- package/dist/hooks/admin/orders.js +18 -12
- package/dist/hooks/admin/products.js +15 -10
- package/dist/hooks/admin/stats.js +3 -2
- package/dist/hooks/admin/variants.js +18 -12
- package/dist/hooks/admin/warehouses.js +15 -10
- package/dist/hooks/useApiConfig.d.ts +2 -1
- package/dist/hooks/useApiConfig.js +2 -2
- package/dist/provider.d.ts +7 -4
- package/dist/provider.js +5 -3
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/dist/apps/backend/src/generated/zod/index.d.ts +0 -1114
- package/dist/apps/backend/src/generated/zod/index.js +0 -670
- package/dist/apps/backend/src/http-app.d.ts +0 -40
- package/dist/apps/backend/src/http-app.js +0 -106
- package/dist/apps/backend/src/lib/brand-response.d.ts +0 -14
- package/dist/apps/backend/src/lib/brand-response.js +0 -8
- package/dist/apps/backend/src/lib/cart-helpers.d.ts +0 -280
- package/dist/apps/backend/src/lib/cart-helpers.js +0 -93
- package/dist/apps/backend/src/lib/cart-recovery.d.ts +0 -30
- package/dist/apps/backend/src/lib/cart-recovery.js +0 -147
- package/dist/apps/backend/src/lib/cart-response.d.ts +0 -121
- package/dist/apps/backend/src/lib/cart-response.js +0 -150
- package/dist/apps/backend/src/lib/clerk.d.ts +0 -18
- package/dist/apps/backend/src/lib/clerk.js +0 -167
- package/dist/apps/backend/src/lib/delivery-zone-response.d.ts +0 -62
- package/dist/apps/backend/src/lib/delivery-zone-response.js +0 -24
- package/dist/apps/backend/src/lib/discount-code-response.d.ts +0 -42
- package/dist/apps/backend/src/lib/discount-code-response.js +0 -19
- package/dist/apps/backend/src/lib/discount.d.ts +0 -20
- package/dist/apps/backend/src/lib/discount.js +0 -35
- package/dist/apps/backend/src/lib/inventory.d.ts +0 -26
- package/dist/apps/backend/src/lib/inventory.js +0 -160
- package/dist/apps/backend/src/lib/meta-capi.d.ts +0 -48
- package/dist/apps/backend/src/lib/meta-capi.js +0 -120
- package/dist/apps/backend/src/lib/openapi.d.ts +0 -36
- package/dist/apps/backend/src/lib/openapi.js +0 -69
- package/dist/apps/backend/src/lib/order-recovery.d.ts +0 -367
- package/dist/apps/backend/src/lib/order-recovery.js +0 -373
- package/dist/apps/backend/src/lib/order-response.d.ts +0 -136
- package/dist/apps/backend/src/lib/order-response.js +0 -61
- package/dist/apps/backend/src/lib/pricing.d.ts +0 -39
- package/dist/apps/backend/src/lib/pricing.js +0 -62
- package/dist/apps/backend/src/lib/prisma.d.ts +0 -9
- package/dist/apps/backend/src/lib/prisma.js +0 -30
- package/dist/apps/backend/src/lib/product-response.d.ts +0 -82
- package/dist/apps/backend/src/lib/product-response.js +0 -29
- package/dist/apps/backend/src/lib/utils.d.ts +0 -32
- package/dist/apps/backend/src/lib/utils.js +0 -63
- package/dist/apps/backend/src/middleware/clerk-auth.d.ts +0 -8
- package/dist/apps/backend/src/middleware/clerk-auth.js +0 -89
- package/dist/apps/backend/src/middleware/cors.d.ts +0 -8
- package/dist/apps/backend/src/middleware/cors.js +0 -11
- package/dist/apps/backend/src/notifications/producers/meta-capi-producer.d.ts +0 -55
- package/dist/apps/backend/src/notifications/producers/meta-capi-producer.js +0 -125
- package/dist/apps/backend/src/notifications/producers/order-notification.d.ts +0 -9
- package/dist/apps/backend/src/notifications/producers/order-notification.js +0 -18
- package/dist/apps/backend/src/notifications/producers/prospect-recovery-notification.d.ts +0 -10
- package/dist/apps/backend/src/notifications/producers/prospect-recovery-notification.js +0 -11
- package/dist/apps/backend/src/routes/admin/abandoned-carts.d.ts +0 -605
- package/dist/apps/backend/src/routes/admin/abandoned-carts.js +0 -194
- package/dist/apps/backend/src/routes/admin/brands.d.ts +0 -175
- package/dist/apps/backend/src/routes/admin/brands.js +0 -118
- package/dist/apps/backend/src/routes/admin/customers.d.ts +0 -306
- package/dist/apps/backend/src/routes/admin/customers.js +0 -39
- package/dist/apps/backend/src/routes/admin/delivery-zones.d.ts +0 -438
- package/dist/apps/backend/src/routes/admin/delivery-zones.js +0 -300
- package/dist/apps/backend/src/routes/admin/discount-codes.d.ts +0 -478
- package/dist/apps/backend/src/routes/admin/discount-codes.js +0 -418
- package/dist/apps/backend/src/routes/admin/inventory.d.ts +0 -273
- package/dist/apps/backend/src/routes/admin/inventory.js +0 -189
- package/dist/apps/backend/src/routes/admin/orders.d.ts +0 -1478
- package/dist/apps/backend/src/routes/admin/orders.js +0 -503
- package/dist/apps/backend/src/routes/admin/products.d.ts +0 -860
- package/dist/apps/backend/src/routes/admin/products.js +0 -107
- package/dist/apps/backend/src/routes/admin/stats.d.ts +0 -288
- package/dist/apps/backend/src/routes/admin/stats.js +0 -55
- package/dist/apps/backend/src/routes/admin/variants.d.ts +0 -239
- package/dist/apps/backend/src/routes/admin/variants.js +0 -173
- package/dist/apps/backend/src/routes/admin/warehouses.d.ts +0 -373
- package/dist/apps/backend/src/routes/admin/warehouses.js +0 -123
- package/dist/apps/backend/src/routes/public/brands.d.ts +0 -40
- package/dist/apps/backend/src/routes/public/brands.js +0 -38
- package/dist/apps/backend/src/routes/public/carts.d.ts +0 -2655
- package/dist/apps/backend/src/routes/public/carts.js +0 -631
- package/dist/apps/backend/src/routes/public/delivery-zones.d.ts +0 -35
- package/dist/apps/backend/src/routes/public/delivery-zones.js +0 -62
- package/dist/apps/backend/src/routes/public/orders.d.ts +0 -323
- package/dist/apps/backend/src/routes/public/orders.js +0 -160
- package/dist/apps/backend/src/routes/public/products.d.ts +0 -449
- package/dist/apps/backend/src/routes/public/products.js +0 -133
- package/dist/apps/backend/src/types/index.d.ts +0 -42
- package/dist/apps/backend/src/types/index.js +0 -2
- package/dist/apps/backend/src/validators/brand.d.ts +0 -17
- package/dist/apps/backend/src/validators/brand.js +0 -15
- package/dist/apps/backend/src/validators/delivery-zone.d.ts +0 -31
- package/dist/apps/backend/src/validators/delivery-zone.js +0 -51
- package/dist/apps/backend/src/validators/discount-code.d.ts +0 -74
- package/dist/apps/backend/src/validators/discount-code.js +0 -50
- package/dist/apps/backend/src/validators/inventory.d.ts +0 -20
- package/dist/apps/backend/src/validators/inventory.js +0 -15
- package/dist/apps/backend/src/validators/order.d.ts +0 -87
- package/dist/apps/backend/src/validators/order.js +0 -61
- package/dist/apps/backend/src/validators/product.d.ts +0 -18
- package/dist/apps/backend/src/validators/product.js +0 -19
- package/dist/apps/backend/src/validators/variant.d.ts +0 -19
- package/dist/apps/backend/src/validators/variant.js +0 -19
- package/dist/apps/backend/src/validators/warehouse.d.ts +0 -15
- package/dist/apps/backend/src/validators/warehouse.js +0 -15
- package/dist/packages/api-client/src/backend-types.d.ts +0 -10
- package/dist/packages/api-client/src/backend-types.js +0 -10
- package/dist/packages/api-client/src/client.d.ts +0 -20
- package/dist/packages/api-client/src/client.js +0 -40
- package/dist/packages/api-client/src/fetchers/brands.d.ts +0 -25
- package/dist/packages/api-client/src/fetchers/brands.js +0 -26
- package/dist/packages/api-client/src/fetchers/carts.d.ts +0 -2335
- package/dist/packages/api-client/src/fetchers/carts.js +0 -169
- package/dist/packages/api-client/src/fetchers/delivery-zones.d.ts +0 -28
- package/dist/packages/api-client/src/fetchers/delivery-zones.js +0 -26
- package/dist/packages/api-client/src/fetchers/index.d.ts +0 -22
- package/dist/packages/api-client/src/fetchers/index.js +0 -22
- package/dist/packages/api-client/src/fetchers/orders.d.ts +0 -283
- package/dist/packages/api-client/src/fetchers/orders.js +0 -44
- package/dist/packages/api-client/src/fetchers/products.d.ts +0 -386
- package/dist/packages/api-client/src/fetchers/products.js +0 -42
- package/dist/packages/api-client/src/hooks/admin/abandoned-carts.d.ts +0 -535
- package/dist/packages/api-client/src/hooks/admin/abandoned-carts.js +0 -83
- package/dist/packages/api-client/src/hooks/admin/brands.d.ts +0 -79
- package/dist/packages/api-client/src/hooks/admin/brands.js +0 -108
- package/dist/packages/api-client/src/hooks/admin/customers.d.ts +0 -278
- package/dist/packages/api-client/src/hooks/admin/customers.js +0 -26
- package/dist/packages/api-client/src/hooks/admin/delivery-zones.d.ts +0 -270
- package/dist/packages/api-client/src/hooks/admin/delivery-zones.js +0 -176
- package/dist/packages/api-client/src/hooks/admin/discount-codes.d.ts +0 -299
- package/dist/packages/api-client/src/hooks/admin/discount-codes.js +0 -165
- package/dist/packages/api-client/src/hooks/admin/index.d.ts +0 -16
- package/dist/packages/api-client/src/hooks/admin/index.js +0 -16
- package/dist/packages/api-client/src/hooks/admin/inventory.d.ts +0 -224
- package/dist/packages/api-client/src/hooks/admin/inventory.js +0 -107
- package/dist/packages/api-client/src/hooks/admin/orders.d.ts +0 -1380
- package/dist/packages/api-client/src/hooks/admin/orders.js +0 -175
- package/dist/packages/api-client/src/hooks/admin/products.d.ts +0 -374
- package/dist/packages/api-client/src/hooks/admin/products.js +0 -89
- package/dist/packages/api-client/src/hooks/admin/stats.d.ts +0 -277
- package/dist/packages/api-client/src/hooks/admin/stats.js +0 -25
- package/dist/packages/api-client/src/hooks/admin/variants.d.ts +0 -115
- package/dist/packages/api-client/src/hooks/admin/variants.js +0 -127
- package/dist/packages/api-client/src/hooks/admin/warehouses.d.ts +0 -277
- package/dist/packages/api-client/src/hooks/admin/warehouses.js +0 -108
- package/dist/packages/api-client/src/hooks/public/brands.d.ts +0 -33
- package/dist/packages/api-client/src/hooks/public/brands.js +0 -30
- package/dist/packages/api-client/src/hooks/public/carts.d.ts +0 -2405
- package/dist/packages/api-client/src/hooks/public/carts.js +0 -213
- package/dist/packages/api-client/src/hooks/public/delivery-zones.d.ts +0 -34
- package/dist/packages/api-client/src/hooks/public/delivery-zones.js +0 -28
- package/dist/packages/api-client/src/hooks/public/index.d.ts +0 -10
- package/dist/packages/api-client/src/hooks/public/index.js +0 -10
- package/dist/packages/api-client/src/hooks/public/orders.d.ts +0 -302
- package/dist/packages/api-client/src/hooks/public/orders.js +0 -50
- package/dist/packages/api-client/src/hooks/public/products.d.ts +0 -398
- package/dist/packages/api-client/src/hooks/public/products.js +0 -47
- package/dist/packages/api-client/src/hooks/use-query-unwrapped.d.ts +0 -20
- package/dist/packages/api-client/src/hooks/use-query-unwrapped.js +0 -22
- package/dist/packages/api-client/src/hooks/useApiConfig.d.ts +0 -12
- package/dist/packages/api-client/src/hooks/useApiConfig.js +0 -14
- package/dist/packages/api-client/src/index.d.ts +0 -20
- package/dist/packages/api-client/src/index.js +0 -25
- package/dist/packages/api-client/src/provider.d.ts +0 -36
- package/dist/packages/api-client/src/provider.js +0 -54
- package/dist/packages/api-client/src/rpc-client.d.ts +0 -9035
- package/dist/packages/api-client/src/rpc-client.js +0 -78
- package/dist/packages/api-client/src/rpc-types.d.ts +0 -76
- package/dist/packages/api-client/src/rpc-types.js +0 -7
- package/dist/packages/api-client/src/types.d.ts +0 -37
- package/dist/packages/api-client/src/types.js +0 -16
- package/dist/packages/api-client/src/utils/query-keys.d.ts +0 -106
- package/dist/packages/api-client/src/utils/query-keys.js +0 -108
|
@@ -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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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
|
-
|
|
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,
|
|
9
|
+
const { baseURL, getAuthToken } = useApiClientContext();
|
|
10
10
|
return {
|
|
11
11
|
baseURL,
|
|
12
|
-
|
|
12
|
+
getAuthToken,
|
|
13
13
|
};
|
|
14
14
|
}
|
package/dist/provider.d.ts
CHANGED
|
@@ -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
|
-
|
|
10
|
+
getAuthToken: AuthTokenGetter;
|
|
10
11
|
}
|
|
11
12
|
export interface ApiClientProviderProps {
|
|
12
13
|
children: ReactNode;
|
|
13
14
|
baseURL?: string;
|
|
14
|
-
|
|
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
|
-
*
|
|
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,
|
|
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
|
*/
|
package/dist/provider.js
CHANGED
|
@@ -11,12 +11,14 @@ const ApiClientContext = createContext(null);
|
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```tsx
|
|
14
|
-
*
|
|
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',
|
|
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,
|
|
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
|
package/dist/types.d.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
export * from './hooks/public';
|
|
13
13
|
export * as admin from './hooks/admin';
|
|
14
14
|
export * from './rpc-types';
|
|
15
|
+
export type { OrderStatus, ProspectReason, PaymentMethod } from './enum-types';
|
|
15
16
|
export type { PublicProduct as Product } from './rpc-types';
|
|
16
17
|
export type { PublicDeliveryZoneState as DeliveryZoneState } from './rpc-types';
|
|
17
18
|
export type { PublicCartResponse as CartResponse, PublicCartResponse as Cart } from './rpc-types';
|