@ventlio/tanstack-query 0.5.14 → 0.6.1
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/helpers/index.d.ts +0 -1
- package/dist/index.mjs +158 -171
- package/dist/index.mjs.map +1 -1
- package/dist/queries/useDeleteRequest.d.ts +93 -39
- package/dist/queries/useGetRequest.d.ts +125 -12
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/queries/useDeleteRequest.js +39 -55
- package/dist/src/queries/useDeleteRequest.js.map +1 -1
- package/dist/src/queries/useGetInfiniteRequest.js +8 -3
- package/dist/src/queries/useGetInfiniteRequest.js.map +1 -1
- package/dist/src/queries/useGetRequest.js +98 -88
- package/dist/src/queries/useGetRequest.js.map +1 -1
- package/dist/src/queries/usePatchRequest.js +8 -12
- package/dist/src/queries/usePatchRequest.js.map +1 -1
- package/dist/src/queries/usePostRequest.js +10 -12
- package/dist/src/queries/usePostRequest.js.map +1 -1
- package/dist/types/index.d.ts +17 -1
- package/package.json +1 -1
- package/src/helpers/index.ts +0 -1
- package/src/queries/useDeleteRequest.ts +43 -68
- package/src/queries/useGetInfiniteRequest.ts +9 -3
- package/src/queries/useGetRequest.ts +167 -157
- package/src/queries/usePatchRequest.ts +10 -12
- package/src/queries/usePostRequest.ts +11 -13
- package/src/queries/usePutRequest.ts +10 -13
- package/src/types/index.ts +17 -1
- package/dist/helpers/scrollToTop.d.ts +0 -1
- package/dist/src/helpers/scrollToTop.js +0 -9
- package/dist/src/helpers/scrollToTop.js.map +0 -1
- package/src/helpers/scrollToTop.ts +0 -6
package/dist/helpers/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'url-search-params-polyfill';
|
|
2
|
-
import require$$0, { useState,
|
|
2
|
+
import require$$0, { useState, useMemo, useEffect, startTransition, useCallback } from 'react';
|
|
3
3
|
import { create } from 'zustand';
|
|
4
|
-
import { useQueryClient,
|
|
4
|
+
import { useQueryClient, useMutation, useInfiniteQuery, useQuery } from '@tanstack/react-query';
|
|
5
5
|
import lodashSet from 'lodash.set';
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
|
|
@@ -888,13 +888,6 @@ function result(object, path, defaultValue) {
|
|
|
888
888
|
return current;
|
|
889
889
|
}
|
|
890
890
|
|
|
891
|
-
const scrollToTop = () => {
|
|
892
|
-
window.scrollTo({
|
|
893
|
-
top: 0,
|
|
894
|
-
behavior: 'smooth',
|
|
895
|
-
});
|
|
896
|
-
};
|
|
897
|
-
|
|
898
891
|
function getDateInFuture(days) {
|
|
899
892
|
// Create a new Date object
|
|
900
893
|
const date = new Date();
|
|
@@ -1295,90 +1288,78 @@ function getAppFiles(body, fileSelectors = []) {
|
|
|
1295
1288
|
|
|
1296
1289
|
const useDeleteRequest = (deleteOptions) => {
|
|
1297
1290
|
const { baseUrl, headers } = deleteOptions ?? {};
|
|
1298
|
-
const
|
|
1299
|
-
const [options, setOptions] = useState();
|
|
1300
|
-
// const { middleware: middlewares } = useStore(bootStore);
|
|
1301
|
-
// const [middleware] = middlewares as unknown as MiddlewareFunction[];
|
|
1291
|
+
const { headerProvider } = useStore(bootStore);
|
|
1302
1292
|
const [requestPayload, setRequestPayload] = useState();
|
|
1303
|
-
const
|
|
1293
|
+
const isFutureMutationsPaused = usePauseFutureRequests((state) => state.isFutureMutationsPaused);
|
|
1304
1294
|
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
1305
|
-
const
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
const
|
|
1295
|
+
const storeHeaders = useHeaderStore((state) => state.headers);
|
|
1296
|
+
// Get headers from both the store and the headerProvider (if configured)
|
|
1297
|
+
const globalHeaders = useMemo(() => {
|
|
1298
|
+
const providerHeaders = headerProvider ? headerProvider() : undefined;
|
|
1299
|
+
return { ...providerHeaders, ...storeHeaders };
|
|
1300
|
+
}, [storeHeaders, headerProvider]);
|
|
1301
|
+
const sendRequest = async (path) => {
|
|
1309
1302
|
const requestOptions = {
|
|
1310
|
-
path
|
|
1303
|
+
path,
|
|
1311
1304
|
headers: { ...globalHeaders, ...headers },
|
|
1312
1305
|
baseURL: baseUrl ?? API_URL,
|
|
1313
1306
|
method: HttpMethod.DELETE,
|
|
1314
1307
|
timeout: TIMEOUT,
|
|
1315
1308
|
};
|
|
1316
|
-
// let deleteResponse: IRequestError | IRequestSuccess<TResponse>;
|
|
1317
|
-
// if (middleware) {
|
|
1318
|
-
// // perform global middleware
|
|
1319
|
-
// deleteResponse = await middleware(
|
|
1320
|
-
// async (middlewareOptions) =>
|
|
1321
|
-
// await makeRequest<TResponse>(
|
|
1322
|
-
// middlewareOptions ? { ...requestOptions, ...middlewareOptions } : requestOptions
|
|
1323
|
-
// ),
|
|
1324
|
-
// {
|
|
1325
|
-
// path: requestUrl,
|
|
1326
|
-
// baseUrl: baseUrl ?? API_URL,
|
|
1327
|
-
// }
|
|
1328
|
-
// );
|
|
1329
|
-
// } else {
|
|
1330
1309
|
const deleteResponse = await makeRequest(requestOptions);
|
|
1331
|
-
// }
|
|
1332
1310
|
if (deleteResponse.status) {
|
|
1333
|
-
|
|
1311
|
+
return deleteResponse;
|
|
1334
1312
|
}
|
|
1335
1313
|
else {
|
|
1336
|
-
|
|
1314
|
+
throw deleteResponse;
|
|
1337
1315
|
}
|
|
1338
1316
|
};
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
enabled: false,
|
|
1343
|
-
...options,
|
|
1317
|
+
// Use mutation instead of query for DELETE operations
|
|
1318
|
+
const mutation = useMutation({
|
|
1319
|
+
mutationFn: async ({ path }) => sendRequest(path),
|
|
1344
1320
|
});
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
// set enabled to be true for every delete
|
|
1354
|
-
internalDeleteOptions = internalDeleteOptions
|
|
1355
|
-
? { ...internalDeleteOptions, queryKey: [link, {}], enabled: true }
|
|
1356
|
-
: { queryKey: [link, {}], enabled: true };
|
|
1357
|
-
await setOptionsAsync(internalDeleteOptions);
|
|
1358
|
-
await updatedPathAsync(link);
|
|
1359
|
-
return query.data;
|
|
1321
|
+
/**
|
|
1322
|
+
* Perform a DELETE request to the specified path
|
|
1323
|
+
* @param path - The API path to send the DELETE request to
|
|
1324
|
+
* @param options - Optional mutation options (onSuccess, onError, etc.)
|
|
1325
|
+
*/
|
|
1326
|
+
const destroy = async (path, options) => {
|
|
1327
|
+
if (!isFutureMutationsPaused) {
|
|
1328
|
+
return mutation.mutateAsync({ path }, options);
|
|
1360
1329
|
}
|
|
1361
1330
|
else {
|
|
1362
|
-
setRequestPayload({
|
|
1331
|
+
setRequestPayload({ path, options });
|
|
1363
1332
|
return undefined;
|
|
1364
1333
|
}
|
|
1365
1334
|
};
|
|
1335
|
+
// Resume paused requests when mutations are unpaused
|
|
1366
1336
|
useEffect(() => {
|
|
1367
|
-
if (!
|
|
1368
|
-
destroy(requestPayload.
|
|
1337
|
+
if (!isFutureMutationsPaused && requestPayload) {
|
|
1338
|
+
destroy(requestPayload.path, requestPayload.options);
|
|
1369
1339
|
setRequestPayload(undefined);
|
|
1370
1340
|
}
|
|
1371
1341
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1372
|
-
}, [
|
|
1373
|
-
return {
|
|
1342
|
+
}, [isFutureMutationsPaused]);
|
|
1343
|
+
return {
|
|
1344
|
+
destroy,
|
|
1345
|
+
...mutation,
|
|
1346
|
+
isLoading: mutation.isPending || isFutureMutationsPaused,
|
|
1347
|
+
// For backward compatibility - mutations don't have initial loading state
|
|
1348
|
+
isInitialLoading: false,
|
|
1349
|
+
};
|
|
1374
1350
|
};
|
|
1375
1351
|
|
|
1376
1352
|
const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl, headers, }) => {
|
|
1377
1353
|
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
1378
|
-
const
|
|
1354
|
+
const { headerProvider } = useStore(bootStore);
|
|
1355
|
+
const storeHeaders = useHeaderStore((state) => state.headers);
|
|
1356
|
+
// Get headers from both the store and the headerProvider (if configured)
|
|
1357
|
+
const globalHeaders = useMemo(() => {
|
|
1358
|
+
const providerHeaders = headerProvider ? headerProvider() : undefined;
|
|
1359
|
+
return { ...providerHeaders, ...storeHeaders };
|
|
1360
|
+
}, [storeHeaders, headerProvider]);
|
|
1379
1361
|
const [requestPath, setRequestPath] = useState(path);
|
|
1380
1362
|
const [options, setOptions] = useState(queryOptions);
|
|
1381
|
-
useStore(bootStore);
|
|
1382
1363
|
const [requestPayload, setRequestPayload] = useState();
|
|
1383
1364
|
const isFutureQueriesPaused = usePauseFutureRequests((state) => state.isFutureQueriesPaused);
|
|
1384
1365
|
let queryClient = useQueryClient();
|
|
@@ -1488,24 +1469,28 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
|
|
|
1488
1469
|
*/
|
|
1489
1470
|
const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl, headers, paginationConfig, }) => {
|
|
1490
1471
|
const [requestPath, setRequestPath] = useState(path);
|
|
1491
|
-
const [options, setOptions] = useState(queryOptions);
|
|
1492
1472
|
const [page, setPage] = useState(1);
|
|
1493
1473
|
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
1494
|
-
const { middleware, pagination: globalPaginationConfig } = useStore(bootStore);
|
|
1495
|
-
const
|
|
1496
|
-
|
|
1474
|
+
const { middleware, pagination: globalPaginationConfig, headerProvider } = useStore(bootStore);
|
|
1475
|
+
const storeHeaders = useHeaderStore((state) => state.headers);
|
|
1476
|
+
// Get headers from both the store and the headerProvider (if configured)
|
|
1477
|
+
// headerProvider allows reading from cookies/localStorage synchronously
|
|
1478
|
+
const globalHeaders = useMemo(() => {
|
|
1479
|
+
const providerHeaders = headerProvider ? headerProvider() : undefined;
|
|
1480
|
+
// Merge: store headers take precedence over provider headers
|
|
1481
|
+
return { ...providerHeaders, ...storeHeaders };
|
|
1482
|
+
}, [storeHeaders, headerProvider]);
|
|
1497
1483
|
const isFutureQueriesPaused = usePauseFutureRequests((state) => state.isFutureQueriesPaused);
|
|
1498
|
-
|
|
1499
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1500
|
-
queryClient = useMemo(() => queryClient, []);
|
|
1484
|
+
const queryClient = useQueryClient();
|
|
1501
1485
|
// Merge global and local pagination config
|
|
1502
1486
|
const pagination = useMemo(() => ({
|
|
1503
1487
|
...globalPaginationConfig,
|
|
1504
1488
|
...paginationConfig,
|
|
1505
1489
|
}), [globalPaginationConfig, paginationConfig]);
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1490
|
+
/**
|
|
1491
|
+
* Core request function that makes the actual HTTP request
|
|
1492
|
+
*/
|
|
1493
|
+
const executeRequest = useCallback(async (requestUrl) => {
|
|
1509
1494
|
const requestOptions = {
|
|
1510
1495
|
path: requestUrl,
|
|
1511
1496
|
headers: { ...globalHeaders, ...headers },
|
|
@@ -1532,26 +1517,32 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
|
|
|
1532
1517
|
getResponse = await makeRequest(requestOptions);
|
|
1533
1518
|
}
|
|
1534
1519
|
if (getResponse.status) {
|
|
1535
|
-
|
|
1520
|
+
return getResponse;
|
|
1536
1521
|
}
|
|
1537
1522
|
else {
|
|
1538
|
-
|
|
1523
|
+
throw getResponse;
|
|
1539
1524
|
}
|
|
1540
|
-
};
|
|
1525
|
+
}, [globalHeaders, headers, baseUrl, API_URL, TIMEOUT, middleware]);
|
|
1526
|
+
// The declarative query - only runs when load is true
|
|
1541
1527
|
const query = useQuery({
|
|
1542
1528
|
queryKey: [requestPath, {}],
|
|
1543
|
-
queryFn: ({ queryKey }) =>
|
|
1544
|
-
|
|
1545
|
-
|
|
1529
|
+
queryFn: async ({ queryKey }) => {
|
|
1530
|
+
const [url] = queryKey;
|
|
1531
|
+
return executeRequest(url);
|
|
1532
|
+
},
|
|
1533
|
+
// Only enable when load is explicitly true AND queries aren't paused
|
|
1534
|
+
enabled: load === true && !isFutureQueriesPaused,
|
|
1535
|
+
...queryOptions,
|
|
1546
1536
|
});
|
|
1537
|
+
// Update request path when prop changes
|
|
1547
1538
|
useEffect(() => {
|
|
1548
|
-
if (path) {
|
|
1539
|
+
if (path && path !== requestPath) {
|
|
1549
1540
|
setRequestPath(path);
|
|
1550
1541
|
}
|
|
1551
|
-
}, [path]);
|
|
1542
|
+
}, [path, requestPath]);
|
|
1543
|
+
// Track query key for external reference
|
|
1552
1544
|
useEffect(() => {
|
|
1553
1545
|
if (keyTracker) {
|
|
1554
|
-
// set expiration time for the tracker
|
|
1555
1546
|
queryClient.setQueryDefaults([keyTracker], {
|
|
1556
1547
|
staleTime: Infinity,
|
|
1557
1548
|
});
|
|
@@ -1561,8 +1552,7 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
|
|
|
1561
1552
|
/**
|
|
1562
1553
|
* Extract pagination data from response using configured extractor
|
|
1563
1554
|
*/
|
|
1564
|
-
const getPaginationData = (response) => {
|
|
1565
|
-
// Use the configured pagination extractor or fall back to default
|
|
1555
|
+
const getPaginationData = useCallback((response) => {
|
|
1566
1556
|
const extractPagination = pagination.extractPagination ||
|
|
1567
1557
|
((res) => {
|
|
1568
1558
|
if ('pagination' in res.data) {
|
|
@@ -1571,90 +1561,90 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
|
|
|
1571
1561
|
return undefined;
|
|
1572
1562
|
});
|
|
1573
1563
|
return extractPagination(response);
|
|
1574
|
-
};
|
|
1564
|
+
}, [pagination.extractPagination]);
|
|
1565
|
+
/**
|
|
1566
|
+
* Construct a pagination URL using the configured builder
|
|
1567
|
+
*/
|
|
1568
|
+
const constructPaginationLink = useCallback((link, pageNumber) => {
|
|
1569
|
+
const buildPaginationUrl = pagination.buildPaginationUrl ||
|
|
1570
|
+
((url, targetPage) => {
|
|
1571
|
+
const [pathname, queryString] = url.split('?');
|
|
1572
|
+
const queryParams = new URLSearchParams(queryString || '');
|
|
1573
|
+
const pageParamName = pagination.pageParamName || 'page';
|
|
1574
|
+
queryParams.set(pageParamName, String(targetPage));
|
|
1575
|
+
return pathname + '?' + queryParams.toString();
|
|
1576
|
+
});
|
|
1577
|
+
return buildPaginationUrl(link, pageNumber);
|
|
1578
|
+
}, [pagination.buildPaginationUrl, pagination.pageParamName]);
|
|
1575
1579
|
/**
|
|
1576
1580
|
* Navigate to the next page if available
|
|
1577
1581
|
*/
|
|
1578
|
-
const nextPage = () => {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
+
const nextPage = useCallback(() => {
|
|
1583
|
+
const data = query.data;
|
|
1584
|
+
if (!data)
|
|
1585
|
+
return;
|
|
1586
|
+
const paginationData = getPaginationData(data);
|
|
1582
1587
|
if (!paginationData)
|
|
1583
1588
|
return;
|
|
1584
1589
|
if (paginationData.next_page !== paginationData.current_page &&
|
|
1585
1590
|
paginationData.next_page > paginationData.current_page) {
|
|
1586
|
-
|
|
1591
|
+
const newPath = constructPaginationLink(requestPath, paginationData.next_page);
|
|
1592
|
+
setRequestPath(newPath);
|
|
1593
|
+
setPage(paginationData.next_page);
|
|
1587
1594
|
}
|
|
1588
|
-
};
|
|
1595
|
+
}, [query.data, getPaginationData, constructPaginationLink, requestPath]);
|
|
1589
1596
|
/**
|
|
1590
1597
|
* Navigate to the previous page if available
|
|
1591
1598
|
*/
|
|
1592
|
-
const prevPage = () => {
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1599
|
+
const prevPage = useCallback(() => {
|
|
1600
|
+
const data = query.data;
|
|
1601
|
+
if (!data)
|
|
1602
|
+
return;
|
|
1603
|
+
const paginationData = getPaginationData(data);
|
|
1596
1604
|
if (!paginationData)
|
|
1597
1605
|
return;
|
|
1598
1606
|
if (paginationData.previous_page !== paginationData.current_page &&
|
|
1599
1607
|
paginationData.previous_page < paginationData.current_page) {
|
|
1600
|
-
|
|
1608
|
+
const newPath = constructPaginationLink(requestPath, paginationData.previous_page);
|
|
1609
|
+
setRequestPath(newPath);
|
|
1610
|
+
setPage(paginationData.previous_page);
|
|
1601
1611
|
}
|
|
1602
|
-
};
|
|
1612
|
+
}, [query.data, getPaginationData, constructPaginationLink, requestPath]);
|
|
1603
1613
|
/**
|
|
1604
|
-
*
|
|
1614
|
+
* Navigate to a specific page
|
|
1605
1615
|
*/
|
|
1606
|
-
const
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
const queryParams = new URLSearchParams(queryString || '');
|
|
1612
|
-
const pageParamName = pagination.pageParamName || 'page';
|
|
1613
|
-
const oldPage = Number(queryParams.get(pageParamName));
|
|
1614
|
-
queryParams.set(pageParamName, String(page));
|
|
1615
|
-
const newUrl = pathname + '?' + queryParams.toString();
|
|
1616
|
-
// only update page when pagination number changed
|
|
1617
|
-
if (oldPage !== pageNumber) {
|
|
1618
|
-
setPage(pageNumber);
|
|
1619
|
-
}
|
|
1620
|
-
return newUrl;
|
|
1621
|
-
});
|
|
1622
|
-
return buildPaginationUrl(link, pageNumber);
|
|
1623
|
-
};
|
|
1616
|
+
const gotoPage = useCallback((pageNumber) => {
|
|
1617
|
+
const newPath = constructPaginationLink(requestPath, pageNumber);
|
|
1618
|
+
setRequestPath(newPath);
|
|
1619
|
+
setPage(pageNumber);
|
|
1620
|
+
}, [constructPaginationLink, requestPath]);
|
|
1624
1621
|
/**
|
|
1625
|
-
*
|
|
1622
|
+
* Imperative GET request - fetches data from a dynamic URL
|
|
1623
|
+
* Uses queryClient.fetchQuery for proper caching and deduplication
|
|
1624
|
+
*
|
|
1625
|
+
* @param url - The URL to fetch from
|
|
1626
|
+
* @param fetchOptions - Optional query options (staleTime, gcTime, etc.)
|
|
1627
|
+
* @returns Promise resolving to the response data
|
|
1626
1628
|
*/
|
|
1627
|
-
const
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
setOptions(fetchOptions);
|
|
1629
|
+
const get = useCallback(async (url, fetchOptions) => {
|
|
1630
|
+
if (isFutureQueriesPaused) {
|
|
1631
|
+
throw new Error('Queries are currently paused');
|
|
1632
|
+
}
|
|
1633
|
+
// Use fetchQuery for imperative fetching - this properly handles caching
|
|
1634
|
+
const result = await queryClient.fetchQuery({
|
|
1635
|
+
queryKey: [url, {}],
|
|
1636
|
+
queryFn: () => executeRequest(url),
|
|
1637
|
+
staleTime: fetchOptions?.staleTime,
|
|
1638
|
+
gcTime: fetchOptions?.gcTime,
|
|
1638
1639
|
});
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
setRequestPayload({ link, fetchOptions });
|
|
1648
|
-
return undefined;
|
|
1649
|
-
}
|
|
1650
|
-
};
|
|
1651
|
-
useEffect(() => {
|
|
1652
|
-
if (!isFutureQueriesPaused && requestPayload) {
|
|
1653
|
-
get(requestPayload.link, requestPayload.fetchOptions);
|
|
1654
|
-
setRequestPayload(undefined);
|
|
1655
|
-
}
|
|
1656
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1657
|
-
}, [isFutureQueriesPaused]);
|
|
1640
|
+
return result;
|
|
1641
|
+
}, [queryClient, executeRequest, isFutureQueriesPaused]);
|
|
1642
|
+
/**
|
|
1643
|
+
* Refetch the current query with the existing path
|
|
1644
|
+
*/
|
|
1645
|
+
const refetch = useCallback(() => {
|
|
1646
|
+
return query.refetch();
|
|
1647
|
+
}, [query]);
|
|
1658
1648
|
return {
|
|
1659
1649
|
...query,
|
|
1660
1650
|
isLoading: query.isLoading || isFutureQueriesPaused,
|
|
@@ -1664,10 +1654,11 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
|
|
|
1664
1654
|
get,
|
|
1665
1655
|
gotoPage,
|
|
1666
1656
|
page,
|
|
1657
|
+
refetch,
|
|
1667
1658
|
queryKey: [requestPath, {}],
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
return
|
|
1659
|
+
getPaginationData: () => {
|
|
1660
|
+
const data = query.data;
|
|
1661
|
+
return data ? getPaginationData(data) : undefined;
|
|
1671
1662
|
},
|
|
1672
1663
|
};
|
|
1673
1664
|
};
|
|
@@ -1675,10 +1666,15 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
|
|
|
1675
1666
|
const usePatchRequest = ({ path, baseUrl, headers }) => {
|
|
1676
1667
|
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
1677
1668
|
const { uploadProgressPercent, onUploadProgress } = useUploadProgress();
|
|
1678
|
-
const
|
|
1669
|
+
const { headerProvider } = useStore(bootStore);
|
|
1670
|
+
const storeHeaders = useHeaderStore((state) => state.headers);
|
|
1671
|
+
// Get headers from both the store and the headerProvider (if configured)
|
|
1672
|
+
const globalHeaders = useMemo(() => {
|
|
1673
|
+
const providerHeaders = headerProvider ? headerProvider() : undefined;
|
|
1674
|
+
return { ...providerHeaders, ...storeHeaders };
|
|
1675
|
+
}, [storeHeaders, headerProvider]);
|
|
1679
1676
|
const [requestPayload, setRequestPayload] = useState();
|
|
1680
1677
|
const isFutureMutationsPaused = usePauseFutureRequests((state) => state.isFutureMutationsPaused);
|
|
1681
|
-
const { context } = useStore(bootStore);
|
|
1682
1678
|
const sendRequest = async (res, rej, data) => {
|
|
1683
1679
|
// get request headers
|
|
1684
1680
|
const requestOptions = {
|
|
@@ -1709,17 +1705,9 @@ const usePatchRequest = ({ path, baseUrl, headers }) => {
|
|
|
1709
1705
|
const patchResponse = await makeRequest(requestOptions);
|
|
1710
1706
|
// }
|
|
1711
1707
|
if (patchResponse.status) {
|
|
1712
|
-
// scroll to top after success
|
|
1713
|
-
if (context !== 'app') {
|
|
1714
|
-
scrollToTop();
|
|
1715
|
-
}
|
|
1716
1708
|
res(patchResponse);
|
|
1717
1709
|
}
|
|
1718
1710
|
else {
|
|
1719
|
-
// scroll to top after error
|
|
1720
|
-
if (context !== 'app') {
|
|
1721
|
-
scrollToTop();
|
|
1722
|
-
}
|
|
1723
1711
|
rej(patchResponse);
|
|
1724
1712
|
}
|
|
1725
1713
|
};
|
|
@@ -1751,8 +1739,15 @@ const usePatchRequest = ({ path, baseUrl, headers }) => {
|
|
|
1751
1739
|
|
|
1752
1740
|
const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelectors, }) => {
|
|
1753
1741
|
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
1754
|
-
const {
|
|
1755
|
-
const
|
|
1742
|
+
const { headerProvider } = useStore(bootStore);
|
|
1743
|
+
const storeHeaders = useHeaderStore((state) => state.headers);
|
|
1744
|
+
// Get headers from both the store and the headerProvider (if configured)
|
|
1745
|
+
// headerProvider allows reading from cookies/localStorage synchronously
|
|
1746
|
+
const globalHeaders = useMemo(() => {
|
|
1747
|
+
const providerHeaders = headerProvider ? headerProvider() : undefined;
|
|
1748
|
+
// Merge: store headers take precedence over provider headers
|
|
1749
|
+
return { ...providerHeaders, ...storeHeaders };
|
|
1750
|
+
}, [storeHeaders, headerProvider]);
|
|
1756
1751
|
const { isApp } = useReactNativeEnv();
|
|
1757
1752
|
const { uploadProgressPercent, onUploadProgress } = useUploadProgress();
|
|
1758
1753
|
const [requestPayload, setRequestPayload] = useState();
|
|
@@ -1794,17 +1789,9 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
|
|
|
1794
1789
|
const postResponse = await makeRequest(requestOptions);
|
|
1795
1790
|
// }
|
|
1796
1791
|
if (postResponse.status) {
|
|
1797
|
-
// scroll to top after success
|
|
1798
|
-
if (context !== 'app') {
|
|
1799
|
-
scrollToTop();
|
|
1800
|
-
}
|
|
1801
1792
|
res(postResponse);
|
|
1802
1793
|
}
|
|
1803
1794
|
else {
|
|
1804
|
-
// scroll to top after error
|
|
1805
|
-
if (context !== 'app') {
|
|
1806
|
-
scrollToTop();
|
|
1807
|
-
}
|
|
1808
1795
|
rej(postResponse);
|
|
1809
1796
|
}
|
|
1810
1797
|
};
|
|
@@ -1833,5 +1820,5 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
|
|
|
1833
1820
|
return { post, uploadProgressPercent, ...mutation, isLoading: mutation.isPending || isFutureMutationsPaused };
|
|
1834
1821
|
};
|
|
1835
1822
|
|
|
1836
|
-
export { ContentType, HttpMethod, axiosInstance, bootstrapQueryRequest, buildFormData, errorTransformer, executeMiddlewareChain, getDateInFuture, makeRequest, result,
|
|
1823
|
+
export { ContentType, HttpMethod, axiosInstance, bootstrapQueryRequest, buildFormData, errorTransformer, executeMiddlewareChain, getDateInFuture, makeRequest, result, successTransformer, useBaseUrlStore, useDeleteRequest, useEnvironmentVariables, useGetInfiniteRequest, useGetRequest, useHeaderStore, useKeyTrackerModel, usePatchRequest, usePauseFutureRequests, usePostRequest, useQueryHeaders, useQueryModel, useReactNativeEnv, useRefetchQuery, useUploadProgress };
|
|
1837
1824
|
//# sourceMappingURL=index.mjs.map
|