@ventlio/tanstack-query 0.2.33 → 0.2.35

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/README.md CHANGED
@@ -10,6 +10,8 @@ But we were not discouraged. So, we set out to find a solution which led to the
10
10
 
11
11
  ---
12
12
 
13
+ > Please note that this package is still being developed and may not function as expected. We are working to refine its implementation structure to meet a functional standard. The documentation may not align with the current implementation, so if you encounter any difficulties while setting up the package, please raise an issue in the GitHub repository. We appreciate your patience and understanding as we work to improve this package.
14
+
13
15
  ## Install
14
16
 
15
17
  > You must install @tanstack/react-query and axios first to use this package
@@ -28,10 +30,22 @@ $ npm install @ventlio/tanstack-query
28
30
  $ yarn add @ventlio/tanstack-query
29
31
  ```
30
32
 
33
+
31
34
  ## Getting Started
32
35
 
33
36
  Follow the below instructions to have the package running on your project
34
37
 
38
+ ### Set the environment variables
39
+ ```env
40
+ # For ReactJS
41
+ REACT_APP_API_URL='https://build.ventlio.com'
42
+ REACT_APP_API_TIMEOUT=300000
43
+
44
+ # For NextJS
45
+ NEXT_PUBLIC_API_URL='https://build.ventlio.com'
46
+ NEXT_PUBLIC_API_TIMEOUT=300000
47
+
48
+ ```
35
49
  ```js
36
50
  import { QueryClient } from '@tanstack/react-query';
37
51
  import { TanstackQueryConfig } from '@ventlio/tanstack-query';
@@ -44,8 +58,6 @@ queryClient.setQueryData <
44
58
  TanstackQueryConfig >
45
59
  (['config'],
46
60
  {
47
- baseURL: 'https://pokeapi.co/api/v2',
48
- timeout: 10000,
49
61
  headers: {
50
62
  Authorization: `Bearer Hello`,
51
63
  },
@@ -78,9 +90,7 @@ import {
78
90
  } from '@ventlio/tanstack-query';
79
91
 
80
92
  function LoginPage() {
81
- const { baseURL, setQueryBaseUrl } = useQueryBaseURL();
82
93
  const { headers, setQueryHeaders } = useQueryHeaders();
83
- const { timeout, setQueryTimeout } = useQueryTimeout();
84
94
 
85
95
  useEffect(() => {
86
96
  // after user has logged in successfully set the authorization header token
@@ -0,0 +1,2 @@
1
+ import type { QueryClient } from '@tanstack/react-query';
2
+ export declare const bootstrapQueryRequest: (queryClient: QueryClient) => void;
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const bootstrapQueryRequest = (queryClient) => {
4
+ // make query config doesn't expire
5
+ queryClient.setQueryDefaults(['config'], {
6
+ staleTime: Infinity,
7
+ cacheTime: Infinity,
8
+ });
9
+ // set default query confg
10
+ queryClient.setQueryData(['config'], {
11
+ headers: {
12
+ Authorization: ``,
13
+ },
14
+ });
15
+ };
16
+
17
+ exports.bootstrapQueryRequest = bootstrapQueryRequest;
18
+ //# sourceMappingURL=bootstrapQueryRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrapQueryRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
@@ -1,3 +1,4 @@
1
+ export * from './bootstrapQueryRequest';
1
2
  export * from './config.interface';
2
3
  export * from './useEnvironmentVariables';
3
4
  export * from './useQueryConfig';
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var reactQuery = require('@tanstack/react-query');
4
+ var timeFuncs = require('../helpers/timeFuncs.js');
4
5
 
5
6
  const useQueryHeaders = () => {
6
7
  const queryClient = reactQuery.useQueryClient();
@@ -18,7 +19,9 @@ const useQueryHeaders = () => {
18
19
  queryClient.setQueryData(['config'], (config) => {
19
20
  const newConfig = { ...config, headers: newHeaders };
20
21
  return newConfig;
21
- }, {});
22
+ }, {
23
+ updatedAt: timeFuncs.getDateInFuture(2),
24
+ });
22
25
  };
23
26
  return { setQueryHeaders, getHeaders };
24
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useQueryHeaders.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"useQueryHeaders.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1,2 @@
1
1
  export * from './scrollToTop';
2
+ export * from './timeFuncs';
@@ -0,0 +1 @@
1
+ export declare function getDateInFuture(days: number): number;
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ function getDateInFuture(days) {
4
+ // Create a new Date object
5
+ const date = new Date();
6
+ // Add the specified number of days to the date
7
+ date.setDate(date.getDate() + days);
8
+ // Get the Unix timestamp of the date (in milliseconds)
9
+ return date.getTime();
10
+ }
11
+
12
+ exports.getDateInFuture = getDateInFuture;
13
+ //# sourceMappingURL=timeFuncs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeFuncs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ var bootstrapQueryRequest = require('./config/bootstrapQueryRequest.js');
3
4
  var useEnvironmentVariables = require('./config/useEnvironmentVariables.js');
4
5
  var useQueryConfig = require('./config/useQueryConfig.js');
5
6
  var useQueryHeaders = require('./config/useQueryHeaders.js');
6
7
  var scrollToTop = require('./helpers/scrollToTop.js');
8
+ var timeFuncs = require('./helpers/timeFuncs.js');
7
9
  var useKeyTrackerModel = require('./model/useKeyTrackerModel.js');
8
10
  var useQueryModel = require('./model/useQueryModel.js');
9
11
  var useRefetchQuery = require('./model/useRefetchQuery.js');
@@ -19,10 +21,12 @@ var transformer = require('./request/transformer.js');
19
21
 
20
22
 
21
23
 
24
+ exports.bootstrapQueryRequest = bootstrapQueryRequest.bootstrapQueryRequest;
22
25
  exports.useEnvironmentVariables = useEnvironmentVariables.useEnvironmentVariables;
23
26
  exports.useQueryConfig = useQueryConfig.useQueryConfig;
24
27
  exports.useQueryHeaders = useQueryHeaders.useQueryHeaders;
25
28
  exports.scrollToTop = scrollToTop.scrollToTop;
29
+ exports.getDateInFuture = timeFuncs.getDateInFuture;
26
30
  exports.useKeyTrackerModel = useKeyTrackerModel.useKeyTrackerModel;
27
31
  exports.useQueryModel = useQueryModel.useQueryModel;
28
32
  exports.useRefetchQuery = useRefetchQuery.useRefetchQuery;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -2,6 +2,20 @@ import { useQueryClient, useQuery, useMutation } from '@tanstack/react-query';
2
2
  import { useState, useMemo, useEffect, startTransition } from 'react';
3
3
  import axios from 'axios';
4
4
 
5
+ const bootstrapQueryRequest = (queryClient) => {
6
+ // make query config doesn't expire
7
+ queryClient.setQueryDefaults(['config'], {
8
+ staleTime: Infinity,
9
+ cacheTime: Infinity,
10
+ });
11
+ // set default query confg
12
+ queryClient.setQueryData(['config'], {
13
+ headers: {
14
+ Authorization: ``,
15
+ },
16
+ });
17
+ };
18
+
5
19
  const useEnvironmentVariables = () => {
6
20
  const url = process.env.REACT_APP_API_URL || process.env.NEXT_PUBLIC_API_URL;
7
21
  const timeout = process.env.REACT_APP_API_TIMEOUT || process.env.NEXT_PUBLIC_API_TIMEOUT;
@@ -17,6 +31,22 @@ const useQueryConfig = () => {
17
31
  return { headers };
18
32
  };
19
33
 
34
+ const scrollToTop = () => {
35
+ window.scrollTo({
36
+ top: 0,
37
+ behavior: 'smooth',
38
+ });
39
+ };
40
+
41
+ function getDateInFuture(days) {
42
+ // Create a new Date object
43
+ const date = new Date();
44
+ // Add the specified number of days to the date
45
+ date.setDate(date.getDate() + days);
46
+ // Get the Unix timestamp of the date (in milliseconds)
47
+ return date.getTime();
48
+ }
49
+
20
50
  const useQueryHeaders = () => {
21
51
  const queryClient = useQueryClient();
22
52
  const getHeaders = () => {
@@ -33,18 +63,13 @@ const useQueryHeaders = () => {
33
63
  queryClient.setQueryData(['config'], (config) => {
34
64
  const newConfig = { ...config, headers: newHeaders };
35
65
  return newConfig;
36
- }, {});
66
+ }, {
67
+ updatedAt: getDateInFuture(2),
68
+ });
37
69
  };
38
70
  return { setQueryHeaders, getHeaders };
39
71
  };
40
72
 
41
- const scrollToTop = () => {
42
- window.scrollTo({
43
- top: 0,
44
- behavior: 'smooth',
45
- });
46
- };
47
-
48
73
  const useKeyTrackerModel = (keyTracker) => {
49
74
  const queryClient = useQueryClient();
50
75
  const [data, setData] = useState();
@@ -404,5 +429,5 @@ const usePostRequest = ({ path, isFormData = false, }) => {
404
429
  return { post, ...mutation };
405
430
  };
406
431
 
407
- export { ContentType, HttpMethod, axiosInstance, buildFormData, errorTransformer, makeRequest, scrollToTop, successTransformer, useDeleteRequest, useEnvironmentVariables, useGetRequest, useKeyTrackerModel, usePatchRequest, usePostRequest, useQueryConfig, useQueryHeaders, useQueryModel, useRefetchQuery };
432
+ export { ContentType, HttpMethod, axiosInstance, bootstrapQueryRequest, buildFormData, errorTransformer, getDateInFuture, makeRequest, scrollToTop, successTransformer, useDeleteRequest, useEnvironmentVariables, useGetRequest, useKeyTrackerModel, usePatchRequest, usePostRequest, useQueryConfig, useQueryHeaders, useQueryModel, useRefetchQuery };
408
433
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ventlio/tanstack-query",
3
- "version": "0.2.33",
3
+ "version": "0.2.35",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "contributors": [
@@ -0,0 +1,17 @@
1
+ import type { QueryClient } from '@tanstack/react-query';
2
+ import type { TanstackQueryConfig } from '../types';
3
+
4
+ export const bootstrapQueryRequest = (queryClient: QueryClient): void => {
5
+ // make query config doesn't expire
6
+ queryClient.setQueryDefaults(['config'], {
7
+ staleTime: Infinity,
8
+ cacheTime: Infinity,
9
+ });
10
+
11
+ // set default query confg
12
+ queryClient.setQueryData<TanstackQueryConfig>(['config'], {
13
+ headers: {
14
+ Authorization: ``,
15
+ },
16
+ });
17
+ };
@@ -1,3 +1,4 @@
1
+ export * from './bootstrapQueryRequest';
1
2
  export * from './config.interface';
2
3
  export * from './useEnvironmentVariables';
3
4
  export * from './useQueryConfig';
@@ -1,4 +1,5 @@
1
1
  import { useQueryClient } from '@tanstack/react-query';
2
+ import { getDateInFuture } from '../helpers';
2
3
  import type { IUseQueryHeaders, TanstackQueryConfig } from '../types';
3
4
 
4
5
  export const useQueryHeaders = (): IUseQueryHeaders => {
@@ -23,7 +24,9 @@ export const useQueryHeaders = (): IUseQueryHeaders => {
23
24
  const newConfig = { ...config, headers: newHeaders };
24
25
  return newConfig;
25
26
  },
26
- {}
27
+ {
28
+ updatedAt: getDateInFuture(2),
29
+ }
27
30
  );
28
31
  };
29
32
 
@@ -1 +1,2 @@
1
1
  export * from './scrollToTop';
2
+ export * from './timeFuncs';
@@ -0,0 +1,10 @@
1
+ export function getDateInFuture(days: number) {
2
+ // Create a new Date object
3
+ const date = new Date();
4
+
5
+ // Add the specified number of days to the date
6
+ date.setDate(date.getDate() + days);
7
+
8
+ // Get the Unix timestamp of the date (in milliseconds)
9
+ return date.getTime();
10
+ }