@ventlio/tanstack-query 0.2.62 → 0.2.63-beta.2
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/config/bootstrapQueryRequest.js +1 -3
- package/dist/config/bootstrapQueryRequest.js.map +1 -1
- package/dist/config/useEnvironmentVariables.js +5 -7
- package/dist/config/useEnvironmentVariables.js.map +1 -1
- package/dist/config/useQueryConfig.js +3 -5
- package/dist/config/useQueryConfig.js.map +1 -1
- package/dist/config/useQueryHeaders.js +5 -7
- package/dist/config/useQueryHeaders.js.map +1 -1
- package/dist/config/useReactNativeEnv.d.ts +1 -0
- package/dist/config/useReactNativeEnv.js +8 -21
- package/dist/config/useReactNativeEnv.js.map +1 -1
- package/dist/helpers/scrollToTop.js +1 -3
- package/dist/helpers/scrollToTop.js.map +1 -1
- package/dist/helpers/timeFuncs.js +1 -3
- package/dist/helpers/timeFuncs.js.map +1 -1
- package/dist/index.js +19 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -26
- package/dist/index.mjs.map +1 -1
- package/dist/model/useKeyTrackerModel.js +3 -5
- package/dist/model/useKeyTrackerModel.js.map +1 -1
- package/dist/model/useQueryModel.js +3 -5
- package/dist/model/useQueryModel.js.map +1 -1
- package/dist/model/useRefetchQuery.js +3 -5
- package/dist/model/useRefetchQuery.js.map +1 -1
- package/dist/queries/useDeleteRequest.js +15 -17
- package/dist/queries/useDeleteRequest.js.map +1 -1
- package/dist/queries/useGetRequest.js +21 -23
- package/dist/queries/useGetRequest.js.map +1 -1
- package/dist/queries/usePatchRequest.js +15 -18
- package/dist/queries/usePatchRequest.js.map +1 -1
- package/dist/queries/usePostRequest.js +16 -19
- package/dist/queries/usePostRequest.js.map +1 -1
- package/dist/request/axios-instance.d.ts +3 -2
- package/dist/request/axios-instance.js +8 -8
- package/dist/request/buildFormData.js +1 -3
- package/dist/request/buildFormData.js.map +1 -1
- package/dist/request/make-request.js +17 -15
- package/dist/request/make-request.js.map +1 -1
- package/dist/request/request.enum.js +6 -6
- package/dist/request/transformer.js +1 -4
- package/dist/request/transformer.js.map +1 -1
- package/package.json +1 -1
- package/src/config/useEnvironmentVariables.ts +2 -2
- package/src/config/useReactNativeEnv.ts +5 -20
- package/src/request/axios-instance.ts +9 -8
- package/src/request/make-request.ts +8 -4
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const bootstrapQueryRequest = (queryClient, options) => {
|
|
4
2
|
// make query config doesn't expire
|
|
5
3
|
queryClient.setQueryDefaults(['config'], {
|
|
@@ -15,5 +13,5 @@ const bootstrapQueryRequest = (queryClient, options) => {
|
|
|
15
13
|
});
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
export { bootstrapQueryRequest };
|
|
19
17
|
//# sourceMappingURL=bootstrapQueryRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrapQueryRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bootstrapQueryRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var useReactNativeEnv = require('./useReactNativeEnv.js');
|
|
1
|
+
import { useReactNativeEnv } from './useReactNativeEnv.js';
|
|
4
2
|
|
|
5
3
|
const useEnvironmentVariables = () => {
|
|
6
|
-
const { appTimeout, appUrl } = useReactNativeEnv
|
|
7
|
-
const url = process.env.REACT_APP_API_URL
|
|
8
|
-
const timeout = process.env.REACT_APP_API_TIMEOUT
|
|
4
|
+
const { appTimeout, appUrl } = useReactNativeEnv();
|
|
5
|
+
const url = process.env.REACT_APP_API_URL ?? process.env.NEXT_PUBLIC_API_URL ?? appUrl;
|
|
6
|
+
const timeout = process.env.REACT_APP_API_TIMEOUT ?? process.env.NEXT_PUBLIC_API_TIMEOUT ?? appTimeout;
|
|
9
7
|
return {
|
|
10
8
|
API_URL: url,
|
|
11
9
|
TIMEOUT: Number(timeout),
|
|
12
10
|
};
|
|
13
11
|
};
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
export { useEnvironmentVariables };
|
|
16
14
|
//# sourceMappingURL=useEnvironmentVariables.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEnvironmentVariables.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useEnvironmentVariables.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var reactQuery = require('@tanstack/react-query');
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
4
2
|
|
|
5
3
|
const useQueryConfig = () => {
|
|
6
|
-
const queryClient =
|
|
4
|
+
const queryClient = useQueryClient();
|
|
7
5
|
const { headers = {} } = queryClient.getQueryData(['config']) ?? {};
|
|
8
6
|
return { headers };
|
|
9
7
|
};
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
export { useQueryConfig };
|
|
12
10
|
//# sourceMappingURL=useQueryConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueryConfig.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useQueryConfig.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var reactQuery = require('@tanstack/react-query');
|
|
4
|
-
var timeFuncs = require('../helpers/timeFuncs.js');
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { getDateInFuture } from '../helpers/timeFuncs.js';
|
|
5
3
|
|
|
6
4
|
const useQueryHeaders = () => {
|
|
7
|
-
const queryClient =
|
|
5
|
+
const queryClient = useQueryClient();
|
|
8
6
|
const getHeaders = () => {
|
|
9
7
|
const config = queryClient.getQueryData(['config']);
|
|
10
8
|
return config.headers;
|
|
@@ -20,11 +18,11 @@ const useQueryHeaders = () => {
|
|
|
20
18
|
const newConfig = { ...config, headers: newHeaders };
|
|
21
19
|
return newConfig;
|
|
22
20
|
}, {
|
|
23
|
-
updatedAt:
|
|
21
|
+
updatedAt: getDateInFuture(2),
|
|
24
22
|
});
|
|
25
23
|
};
|
|
26
24
|
return { setQueryHeaders, getHeaders };
|
|
27
25
|
};
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
export { useQueryHeaders };
|
|
30
28
|
//# sourceMappingURL=useQueryHeaders.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueryHeaders.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useQueryHeaders.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var reactQuery = require('@tanstack/react-query');
|
|
4
|
-
var react = require('react');
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
5
2
|
|
|
6
3
|
const useReactNativeEnv = () => {
|
|
7
|
-
const queryClient =
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (config?.options?.context === 'app') {
|
|
14
|
-
const API_URL = config.options.environments?.appBaseUrl;
|
|
15
|
-
const API_TIMEOUT = config.options.environments?.appTimeout;
|
|
16
|
-
setAppUrl(API_URL);
|
|
17
|
-
setAppTimeout(API_TIMEOUT);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
loadReactNativeEnvIfNeeded();
|
|
21
|
-
}, [queryClient]);
|
|
22
|
-
return { appUrl, appTimeout };
|
|
4
|
+
const queryClient = useQueryClient();
|
|
5
|
+
const config = queryClient.getQueryData(['config']);
|
|
6
|
+
const appUrl = config?.options?.environments?.appBaseUrl;
|
|
7
|
+
const appTimeout = config?.options?.environments?.appTimeout;
|
|
8
|
+
const isApp = config?.options?.context === 'app';
|
|
9
|
+
return { appUrl, appTimeout, isApp };
|
|
23
10
|
};
|
|
24
11
|
|
|
25
|
-
|
|
12
|
+
export { useReactNativeEnv };
|
|
26
13
|
//# sourceMappingURL=useReactNativeEnv.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReactNativeEnv.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useReactNativeEnv.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrollToTop.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scrollToTop.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
function getDateInFuture(days) {
|
|
4
2
|
// Create a new Date object
|
|
5
3
|
const date = new Date();
|
|
@@ -9,5 +7,5 @@ function getDateInFuture(days) {
|
|
|
9
7
|
return date.getTime();
|
|
10
8
|
}
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
export { getDateInFuture };
|
|
13
11
|
//# sourceMappingURL=timeFuncs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeFuncs.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"timeFuncs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,52 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var request_enum = require('./request/request.enum.js');
|
|
21
|
-
var transformer = require('./request/transformer.js');
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
exports.bootstrapQueryRequest = bootstrapQueryRequest.bootstrapQueryRequest;
|
|
26
|
-
exports.useEnvironmentVariables = useEnvironmentVariables.useEnvironmentVariables;
|
|
27
|
-
exports.useQueryConfig = useQueryConfig.useQueryConfig;
|
|
28
|
-
exports.useQueryHeaders = useQueryHeaders.useQueryHeaders;
|
|
29
|
-
exports.useReactNativeEnv = useReactNativeEnv.useReactNativeEnv;
|
|
30
|
-
exports.scrollToTop = scrollToTop.scrollToTop;
|
|
31
|
-
exports.getDateInFuture = timeFuncs.getDateInFuture;
|
|
32
|
-
exports.useKeyTrackerModel = useKeyTrackerModel.useKeyTrackerModel;
|
|
33
|
-
exports.useQueryModel = useQueryModel.useQueryModel;
|
|
34
|
-
exports.useRefetchQuery = useRefetchQuery.useRefetchQuery;
|
|
35
|
-
exports.useDeleteRequest = useDeleteRequest.useDeleteRequest;
|
|
36
|
-
exports.useGetRequest = useGetRequest.useGetRequest;
|
|
37
|
-
exports.usePatchRequest = usePatchRequest.usePatchRequest;
|
|
38
|
-
exports.usePostRequest = usePostRequest.usePostRequest;
|
|
39
|
-
exports.axiosInstance = axiosInstance.axiosInstance;
|
|
40
|
-
exports.buildFormData = buildFormData.buildFormData;
|
|
41
|
-
exports.makeRequest = makeRequest.makeRequest;
|
|
42
|
-
Object.defineProperty(exports, 'ContentType', {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function () { return request_enum.ContentType; }
|
|
45
|
-
});
|
|
46
|
-
Object.defineProperty(exports, 'HttpMethod', {
|
|
47
|
-
enumerable: true,
|
|
48
|
-
get: function () { return request_enum.HttpMethod; }
|
|
49
|
-
});
|
|
50
|
-
exports.errorTransformer = transformer.errorTransformer;
|
|
51
|
-
exports.successTransformer = transformer.successTransformer;
|
|
1
|
+
export { bootstrapQueryRequest } from './config/bootstrapQueryRequest.js';
|
|
2
|
+
export { useEnvironmentVariables } from './config/useEnvironmentVariables.js';
|
|
3
|
+
export { useQueryConfig } from './config/useQueryConfig.js';
|
|
4
|
+
export { useQueryHeaders } from './config/useQueryHeaders.js';
|
|
5
|
+
export { useReactNativeEnv } from './config/useReactNativeEnv.js';
|
|
6
|
+
export { scrollToTop } from './helpers/scrollToTop.js';
|
|
7
|
+
export { getDateInFuture } from './helpers/timeFuncs.js';
|
|
8
|
+
export { useKeyTrackerModel } from './model/useKeyTrackerModel.js';
|
|
9
|
+
export { useQueryModel } from './model/useQueryModel.js';
|
|
10
|
+
export { useRefetchQuery } from './model/useRefetchQuery.js';
|
|
11
|
+
export { useDeleteRequest } from './queries/useDeleteRequest.js';
|
|
12
|
+
export { useGetRequest } from './queries/useGetRequest.js';
|
|
13
|
+
export { usePatchRequest } from './queries/usePatchRequest.js';
|
|
14
|
+
export { usePostRequest } from './queries/usePostRequest.js';
|
|
15
|
+
export { axiosInstance } from './request/axios-instance.js';
|
|
16
|
+
export { buildFormData } from './request/buildFormData.js';
|
|
17
|
+
export { makeRequest } from './request/make-request.js';
|
|
18
|
+
export { ContentType, HttpMethod } from './request/request.enum.js';
|
|
19
|
+
export { errorTransformer, successTransformer } from './request/transformer.js';
|
|
52
20
|
//# sourceMappingURL=index.js.map
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useQueryClient, useQuery, useMutation } from '@tanstack/react-query';
|
|
2
|
-
import { useState,
|
|
3
|
-
import
|
|
2
|
+
import { useState, useMemo, useEffect, startTransition } from 'react';
|
|
3
|
+
import axios from 'axios';
|
|
4
4
|
|
|
5
5
|
const bootstrapQueryRequest = (queryClient, options) => {
|
|
6
6
|
// make query config doesn't expire
|
|
@@ -19,27 +19,17 @@ const bootstrapQueryRequest = (queryClient, options) => {
|
|
|
19
19
|
|
|
20
20
|
const useReactNativeEnv = () => {
|
|
21
21
|
const queryClient = useQueryClient();
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (config?.options?.context === 'app') {
|
|
28
|
-
const API_URL = config.options.environments?.appBaseUrl;
|
|
29
|
-
const API_TIMEOUT = config.options.environments?.appTimeout;
|
|
30
|
-
setAppUrl(API_URL);
|
|
31
|
-
setAppTimeout(API_TIMEOUT);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
loadReactNativeEnvIfNeeded();
|
|
35
|
-
}, [queryClient]);
|
|
36
|
-
return { appUrl, appTimeout };
|
|
22
|
+
const config = queryClient.getQueryData(['config']);
|
|
23
|
+
const appUrl = config?.options?.environments?.appBaseUrl;
|
|
24
|
+
const appTimeout = config?.options?.environments?.appTimeout;
|
|
25
|
+
const isApp = config?.options?.context === 'app';
|
|
26
|
+
return { appUrl, appTimeout, isApp };
|
|
37
27
|
};
|
|
38
28
|
|
|
39
29
|
const useEnvironmentVariables = () => {
|
|
40
30
|
const { appTimeout, appUrl } = useReactNativeEnv();
|
|
41
|
-
const url = process.env.REACT_APP_API_URL
|
|
42
|
-
const timeout = process.env.REACT_APP_API_TIMEOUT
|
|
31
|
+
const url = process.env.REACT_APP_API_URL ?? process.env.NEXT_PUBLIC_API_URL ?? appUrl;
|
|
32
|
+
const timeout = process.env.REACT_APP_API_TIMEOUT ?? process.env.NEXT_PUBLIC_API_TIMEOUT ?? appTimeout;
|
|
43
33
|
return {
|
|
44
34
|
API_URL: url,
|
|
45
35
|
TIMEOUT: Number(timeout),
|
|
@@ -124,10 +114,12 @@ const useRefetchQuery = async (queryKey) => {
|
|
|
124
114
|
return { refetchQuery };
|
|
125
115
|
};
|
|
126
116
|
|
|
127
|
-
const axiosInstance = (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
117
|
+
const axiosInstance = ({ baseURL, timeout, headers }) => {
|
|
118
|
+
return axios.create({
|
|
119
|
+
baseURL,
|
|
120
|
+
timeout,
|
|
121
|
+
headers,
|
|
122
|
+
});
|
|
131
123
|
};
|
|
132
124
|
|
|
133
125
|
const buildFormData = (body) => {
|
|
@@ -209,7 +201,7 @@ const successTransformer = (data) => {
|
|
|
209
201
|
|
|
210
202
|
async function makeRequest({ body, method = HttpMethod.GET, path, isFormData, headers = {}, baseURL, timeout, }) {
|
|
211
203
|
// configure body
|
|
212
|
-
body = isFormData ?
|
|
204
|
+
body = isFormData ? axios.toFormData(body) : body;
|
|
213
205
|
// configure request header
|
|
214
206
|
if (!isFormData) {
|
|
215
207
|
headers['Content-Type'] = ContentType.APPLICATION_JSON;
|
|
@@ -218,9 +210,13 @@ async function makeRequest({ body, method = HttpMethod.GET, path, isFormData, he
|
|
|
218
210
|
delete headers['Content-Type'];
|
|
219
211
|
}
|
|
220
212
|
try {
|
|
221
|
-
const axios = axiosInstance(
|
|
213
|
+
const axios = axiosInstance({ baseURL, headers, timeout });
|
|
222
214
|
// send request
|
|
223
|
-
const resp = await axios(
|
|
215
|
+
const resp = await axios({
|
|
216
|
+
url: path,
|
|
217
|
+
method,
|
|
218
|
+
data: body,
|
|
219
|
+
});
|
|
224
220
|
// get response json
|
|
225
221
|
const jsonResp = await resp.data;
|
|
226
222
|
// get response code
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var reactQuery = require('@tanstack/react-query');
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
4
2
|
|
|
5
3
|
const useKeyTrackerModel = (keyTracker) => {
|
|
6
|
-
const queryClient =
|
|
4
|
+
const queryClient = useQueryClient();
|
|
7
5
|
const getQueryKey = (innerKeyTracker) => {
|
|
8
6
|
const queryKey = queryClient.getQueryData([innerKeyTracker ?? keyTracker]);
|
|
9
7
|
return queryKey;
|
|
@@ -18,5 +16,5 @@ const useKeyTrackerModel = (keyTracker) => {
|
|
|
18
16
|
return { refetchQuery, getQueryKey };
|
|
19
17
|
};
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
export { useKeyTrackerModel };
|
|
22
20
|
//# sourceMappingURL=useKeyTrackerModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useKeyTrackerModel.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useKeyTrackerModel.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var reactQuery = require('@tanstack/react-query');
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
4
2
|
|
|
5
3
|
const useQueryModel = (queryKey, filters) => {
|
|
6
|
-
const queryClient =
|
|
4
|
+
const queryClient = useQueryClient();
|
|
7
5
|
return queryClient.getQueryData(queryKey, filters);
|
|
8
6
|
};
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
export { useQueryModel };
|
|
11
9
|
//# sourceMappingURL=useQueryModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueryModel.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useQueryModel.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var reactQuery = require('@tanstack/react-query');
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
4
2
|
|
|
5
3
|
const useRefetchQuery = async (queryKey) => {
|
|
6
|
-
const queryClient =
|
|
4
|
+
const queryClient = useQueryClient();
|
|
7
5
|
const refetchQuery = async (innerQueryKey) => {
|
|
8
6
|
await queryClient.refetchQueries({
|
|
9
7
|
queryKey,
|
|
@@ -14,5 +12,5 @@ const useRefetchQuery = async (queryKey) => {
|
|
|
14
12
|
return { refetchQuery };
|
|
15
13
|
};
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
export { useRefetchQuery };
|
|
18
16
|
//# sourceMappingURL=useRefetchQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRefetchQuery.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRefetchQuery.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var makeRequest = require('../request/make-request.js');
|
|
9
|
-
var request_enum = require('../request/request.enum.js');
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useEnvironmentVariables } from '../config/useEnvironmentVariables.js';
|
|
4
|
+
import { useQueryHeaders } from '../config/useQueryHeaders.js';
|
|
5
|
+
import 'axios';
|
|
6
|
+
import { makeRequest } from '../request/make-request.js';
|
|
7
|
+
import { HttpMethod } from '../request/request.enum.js';
|
|
10
8
|
|
|
11
9
|
const useDeleteRequest = (deleteOptions) => {
|
|
12
10
|
const { baseUrl, headers } = deleteOptions ?? {};
|
|
13
|
-
const [requestPath, updateDeletePath] =
|
|
14
|
-
const [options, setOptions] =
|
|
15
|
-
const { API_URL, TIMEOUT } = useEnvironmentVariables
|
|
16
|
-
const { getHeaders } = useQueryHeaders
|
|
11
|
+
const [requestPath, updateDeletePath] = useState('');
|
|
12
|
+
const [options, setOptions] = useState();
|
|
13
|
+
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
14
|
+
const { getHeaders } = useQueryHeaders();
|
|
17
15
|
const sendRequest = async (res, rej) => {
|
|
18
16
|
// get request headers
|
|
19
17
|
const globalHeaders = getHeaders();
|
|
20
|
-
const postResponse = await makeRequest
|
|
18
|
+
const postResponse = await makeRequest({
|
|
21
19
|
path: requestPath,
|
|
22
20
|
headers: { ...globalHeaders, ...headers },
|
|
23
|
-
method:
|
|
21
|
+
method: HttpMethod.DELETE,
|
|
24
22
|
baseURL: baseUrl ?? API_URL,
|
|
25
23
|
timeout: TIMEOUT,
|
|
26
24
|
});
|
|
@@ -31,7 +29,7 @@ const useDeleteRequest = (deleteOptions) => {
|
|
|
31
29
|
rej(postResponse);
|
|
32
30
|
}
|
|
33
31
|
};
|
|
34
|
-
const query =
|
|
32
|
+
const query = useQuery([requestPath, {}], () => new Promise((res, rej) => sendRequest(res, rej)), { enabled: false, ...options });
|
|
35
33
|
const updatedPathAsync = async (link) => {
|
|
36
34
|
return updateDeletePath(link);
|
|
37
35
|
};
|
|
@@ -49,5 +47,5 @@ const useDeleteRequest = (deleteOptions) => {
|
|
|
49
47
|
return { destroy, ...query };
|
|
50
48
|
};
|
|
51
49
|
|
|
52
|
-
|
|
50
|
+
export { useDeleteRequest };
|
|
53
51
|
//# sourceMappingURL=useDeleteRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeleteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDeleteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var makeRequest = require('../request/make-request.js');
|
|
9
|
-
require('../request/request.enum.js');
|
|
1
|
+
import { useQueryClient, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { useState, useMemo, useEffect, startTransition } from 'react';
|
|
3
|
+
import { useEnvironmentVariables } from '../config/useEnvironmentVariables.js';
|
|
4
|
+
import { useQueryHeaders } from '../config/useQueryHeaders.js';
|
|
5
|
+
import 'axios';
|
|
6
|
+
import { makeRequest } from '../request/make-request.js';
|
|
7
|
+
import '../request/request.enum.js';
|
|
10
8
|
|
|
11
9
|
const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl, headers, }) => {
|
|
12
|
-
const [requestPath, updatePath] =
|
|
13
|
-
const [options, setOptions] =
|
|
14
|
-
const [page, setPage] =
|
|
15
|
-
const { API_URL, TIMEOUT } = useEnvironmentVariables
|
|
16
|
-
const { getHeaders } = useQueryHeaders
|
|
17
|
-
let queryClient =
|
|
10
|
+
const [requestPath, updatePath] = useState(path);
|
|
11
|
+
const [options, setOptions] = useState(queryOptions);
|
|
12
|
+
const [page, setPage] = useState(1);
|
|
13
|
+
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
14
|
+
const { getHeaders } = useQueryHeaders();
|
|
15
|
+
let queryClient = useQueryClient();
|
|
18
16
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19
|
-
queryClient =
|
|
17
|
+
queryClient = useMemo(() => queryClient, []);
|
|
20
18
|
const sendRequest = async (res, rej) => {
|
|
21
19
|
// get request headers
|
|
22
20
|
const globalHeaders = getHeaders();
|
|
23
|
-
const getResponse = await makeRequest
|
|
21
|
+
const getResponse = await makeRequest({
|
|
24
22
|
path: requestPath,
|
|
25
23
|
headers: { ...globalHeaders, ...headers },
|
|
26
24
|
baseURL: baseUrl ?? API_URL,
|
|
@@ -33,16 +31,16 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
|
|
|
33
31
|
rej(getResponse);
|
|
34
32
|
}
|
|
35
33
|
};
|
|
36
|
-
const query =
|
|
34
|
+
const query = useQuery([requestPath, {}], () => new Promise((res, rej) => sendRequest(res, rej)), {
|
|
37
35
|
enabled: load,
|
|
38
36
|
...options,
|
|
39
37
|
});
|
|
40
|
-
|
|
38
|
+
useEffect(() => {
|
|
41
39
|
if (path) {
|
|
42
40
|
updatePath(path);
|
|
43
41
|
}
|
|
44
42
|
}, [path]);
|
|
45
|
-
|
|
43
|
+
useEffect(() => {
|
|
46
44
|
if (keyTracker) {
|
|
47
45
|
// set expiration time for the tracker
|
|
48
46
|
queryClient.setQueryDefaults([keyTracker], {
|
|
@@ -84,12 +82,12 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
|
|
|
84
82
|
updatePath(constructPaginationLink(requestPath, pageNumber));
|
|
85
83
|
};
|
|
86
84
|
const updatedPathAsync = async (link) => {
|
|
87
|
-
|
|
85
|
+
startTransition(() => {
|
|
88
86
|
updatePath(link);
|
|
89
87
|
});
|
|
90
88
|
};
|
|
91
89
|
const setOptionsAsync = async (fetchOptions) => {
|
|
92
|
-
|
|
90
|
+
startTransition(() => {
|
|
93
91
|
setOptions(fetchOptions);
|
|
94
92
|
});
|
|
95
93
|
};
|
|
@@ -110,5 +108,5 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
|
|
|
110
108
|
};
|
|
111
109
|
};
|
|
112
110
|
|
|
113
|
-
|
|
111
|
+
export { useGetRequest };
|
|
114
112
|
//# sourceMappingURL=useGetRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGetRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,41 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
require('axios');
|
|
9
|
-
var makeRequest = require('../request/make-request.js');
|
|
10
|
-
var request_enum = require('../request/request.enum.js');
|
|
1
|
+
import { useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { useEnvironmentVariables } from '../config/useEnvironmentVariables.js';
|
|
3
|
+
import { useQueryHeaders } from '../config/useQueryHeaders.js';
|
|
4
|
+
import { scrollToTop } from '../helpers/scrollToTop.js';
|
|
5
|
+
import 'axios';
|
|
6
|
+
import { makeRequest } from '../request/make-request.js';
|
|
7
|
+
import { HttpMethod } from '../request/request.enum.js';
|
|
11
8
|
|
|
12
9
|
const usePatchRequest = ({ path, baseUrl, headers }) => {
|
|
13
|
-
const { API_URL, TIMEOUT } = useEnvironmentVariables
|
|
14
|
-
const { getHeaders } = useQueryHeaders
|
|
10
|
+
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
11
|
+
const { getHeaders } = useQueryHeaders();
|
|
15
12
|
const sendRequest = async (res, rej, data) => {
|
|
16
13
|
// get request headers
|
|
17
14
|
const globalHeaders = getHeaders();
|
|
18
|
-
const patchResponse = await makeRequest
|
|
15
|
+
const patchResponse = await makeRequest({
|
|
19
16
|
path: path,
|
|
20
17
|
body: data,
|
|
21
|
-
method:
|
|
18
|
+
method: HttpMethod.PATCH,
|
|
22
19
|
headers: { ...globalHeaders, ...headers },
|
|
23
20
|
baseURL: baseUrl ?? API_URL,
|
|
24
21
|
timeout: TIMEOUT,
|
|
25
22
|
});
|
|
26
23
|
if (patchResponse.status) {
|
|
27
24
|
// scroll to top after success
|
|
28
|
-
scrollToTop
|
|
25
|
+
scrollToTop();
|
|
29
26
|
res(patchResponse);
|
|
30
27
|
}
|
|
31
28
|
else {
|
|
32
29
|
// scroll to top after error
|
|
33
|
-
scrollToTop
|
|
30
|
+
scrollToTop();
|
|
34
31
|
rej(patchResponse);
|
|
35
32
|
}
|
|
36
33
|
};
|
|
37
34
|
// register post mutation
|
|
38
|
-
const mutation =
|
|
35
|
+
const mutation = useMutation((dataData) => new Promise((res, rej) => {
|
|
39
36
|
return sendRequest(res, rej, dataData);
|
|
40
37
|
}));
|
|
41
38
|
const patch = async (data, options) => {
|
|
@@ -44,5 +41,5 @@ const usePatchRequest = ({ path, baseUrl, headers }) => {
|
|
|
44
41
|
return { patch, ...mutation };
|
|
45
42
|
};
|
|
46
43
|
|
|
47
|
-
|
|
44
|
+
export { usePatchRequest };
|
|
48
45
|
//# sourceMappingURL=usePatchRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePatchRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePatchRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
require('axios');
|
|
9
|
-
var makeRequest = require('../request/make-request.js');
|
|
10
|
-
var request_enum = require('../request/request.enum.js');
|
|
1
|
+
import { useQueryClient, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { useEnvironmentVariables } from '../config/useEnvironmentVariables.js';
|
|
3
|
+
import { useQueryHeaders } from '../config/useQueryHeaders.js';
|
|
4
|
+
import { scrollToTop } from '../helpers/scrollToTop.js';
|
|
5
|
+
import 'axios';
|
|
6
|
+
import { makeRequest } from '../request/make-request.js';
|
|
7
|
+
import { HttpMethod } from '../request/request.enum.js';
|
|
11
8
|
|
|
12
9
|
const usePostRequest = ({ path, isFormData = false, baseUrl, headers, }) => {
|
|
13
|
-
const { API_URL, TIMEOUT } = useEnvironmentVariables
|
|
14
|
-
const queryClient =
|
|
15
|
-
const { getHeaders } = useQueryHeaders
|
|
10
|
+
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
11
|
+
const queryClient = useQueryClient();
|
|
12
|
+
const { getHeaders } = useQueryHeaders();
|
|
16
13
|
const sendRequest = async (res, rej, postData) => {
|
|
17
14
|
// get request headers
|
|
18
15
|
const globalHeaders = getHeaders();
|
|
19
16
|
const config = queryClient.getQueryData(['config']);
|
|
20
|
-
const postResponse = await makeRequest
|
|
17
|
+
const postResponse = await makeRequest({
|
|
21
18
|
path,
|
|
22
19
|
body: postData,
|
|
23
|
-
method:
|
|
20
|
+
method: HttpMethod.POST,
|
|
24
21
|
isFormData,
|
|
25
22
|
headers: { ...globalHeaders, ...headers },
|
|
26
23
|
baseURL: baseUrl ?? API_URL,
|
|
@@ -29,25 +26,25 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, }) => {
|
|
|
29
26
|
if (postResponse.status) {
|
|
30
27
|
// scroll to top after success
|
|
31
28
|
if (config?.options?.context !== 'app') {
|
|
32
|
-
scrollToTop
|
|
29
|
+
scrollToTop();
|
|
33
30
|
}
|
|
34
31
|
res(postResponse);
|
|
35
32
|
}
|
|
36
33
|
else {
|
|
37
34
|
// scroll to top after error
|
|
38
35
|
if (config?.options?.context !== 'app') {
|
|
39
|
-
scrollToTop
|
|
36
|
+
scrollToTop();
|
|
40
37
|
}
|
|
41
38
|
rej(postResponse);
|
|
42
39
|
}
|
|
43
40
|
};
|
|
44
41
|
// register post mutation
|
|
45
|
-
const mutation =
|
|
42
|
+
const mutation = useMutation(async (postData) => new Promise((res, rej) => sendRequest(res, rej, postData)));
|
|
46
43
|
const post = async (data, options) => {
|
|
47
44
|
return mutation.mutateAsync(data, options);
|
|
48
45
|
};
|
|
49
46
|
return { post, ...mutation };
|
|
50
47
|
};
|
|
51
48
|
|
|
52
|
-
|
|
49
|
+
export { usePostRequest };
|
|
53
50
|
//# sourceMappingURL=usePostRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePostRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePostRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
import type { IMakeRequest } from './request.interface';
|
|
3
|
+
export declare const axiosInstance: ({ baseURL, timeout, headers }: Partial<IMakeRequest>) => AxiosInstance;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import axios from 'axios';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
const axiosInstance = ({ baseURL, timeout, headers }) => {
|
|
4
|
+
return axios.create({
|
|
5
|
+
baseURL,
|
|
6
|
+
timeout,
|
|
7
|
+
headers,
|
|
8
|
+
});
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export { axiosInstance };
|
|
12
12
|
//# sourceMappingURL=axios-instance.js.map
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const buildFormData = (body) => {
|
|
4
2
|
const formData = new FormData();
|
|
5
3
|
const handleArrayValue = (key, value) => {
|
|
@@ -42,5 +40,5 @@ const buildFormData = (body) => {
|
|
|
42
40
|
return formData;
|
|
43
41
|
};
|
|
44
42
|
|
|
45
|
-
|
|
43
|
+
export { buildFormData };
|
|
46
44
|
//# sourceMappingURL=buildFormData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormData.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildFormData.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,33 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { axiosInstance } from './axios-instance.js';
|
|
3
|
+
import { ContentType, HttpMethod } from './request.enum.js';
|
|
4
|
+
import { errorTransformer, successTransformer } from './transformer.js';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
var buildFormData = require('./buildFormData.js');
|
|
5
|
-
var request_enum = require('./request.enum.js');
|
|
6
|
-
var transformer = require('./transformer.js');
|
|
7
|
-
|
|
8
|
-
async function makeRequest({ body, method = request_enum.HttpMethod.GET, path, isFormData, headers = {}, baseURL, timeout, }) {
|
|
6
|
+
async function makeRequest({ body, method = HttpMethod.GET, path, isFormData, headers = {}, baseURL, timeout, }) {
|
|
9
7
|
// configure body
|
|
10
|
-
body = isFormData ?
|
|
8
|
+
body = isFormData ? axios.toFormData(body) : body;
|
|
11
9
|
// configure request header
|
|
12
10
|
if (!isFormData) {
|
|
13
|
-
headers['Content-Type'] =
|
|
11
|
+
headers['Content-Type'] = ContentType.APPLICATION_JSON;
|
|
14
12
|
}
|
|
15
13
|
else {
|
|
16
14
|
delete headers['Content-Type'];
|
|
17
15
|
}
|
|
18
16
|
try {
|
|
19
|
-
const axios = axiosInstance
|
|
17
|
+
const axios = axiosInstance({ baseURL, headers, timeout });
|
|
20
18
|
// send request
|
|
21
|
-
const resp = await axios(
|
|
19
|
+
const resp = await axios({
|
|
20
|
+
url: path,
|
|
21
|
+
method,
|
|
22
|
+
data: body,
|
|
23
|
+
});
|
|
22
24
|
// get response json
|
|
23
25
|
const jsonResp = await resp.data;
|
|
24
26
|
// get response code
|
|
25
27
|
const responseCode = resp.status;
|
|
26
28
|
if (responseCode > 299) {
|
|
27
29
|
// server returned an error
|
|
28
|
-
return
|
|
30
|
+
return errorTransformer({ ...jsonResp, statusCode: responseCode });
|
|
29
31
|
}
|
|
30
|
-
return
|
|
32
|
+
return successTransformer({
|
|
31
33
|
statusCode: responseCode,
|
|
32
34
|
...jsonResp,
|
|
33
35
|
status: resp.status,
|
|
@@ -35,7 +37,7 @@ async function makeRequest({ body, method = request_enum.HttpMethod.GET, path, i
|
|
|
35
37
|
}
|
|
36
38
|
catch (error) {
|
|
37
39
|
const errorData = error?.response?.data;
|
|
38
|
-
return
|
|
40
|
+
return errorTransformer({
|
|
39
41
|
statusCode: error.status,
|
|
40
42
|
message: error.message,
|
|
41
43
|
code: error.status || error.statusCode,
|
|
@@ -44,5 +46,5 @@ async function makeRequest({ body, method = request_enum.HttpMethod.GET, path, i
|
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
export { makeRequest };
|
|
48
50
|
//# sourceMappingURL=make-request.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-request.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"make-request.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.HttpMethod = void 0;
|
|
1
|
+
var HttpMethod;
|
|
4
2
|
(function (HttpMethod) {
|
|
5
3
|
HttpMethod["GET"] = "GET";
|
|
6
4
|
HttpMethod["POST"] = "POST";
|
|
7
5
|
HttpMethod["PUT"] = "PUT";
|
|
8
6
|
HttpMethod["PATCH"] = "PATCH";
|
|
9
7
|
HttpMethod["DELETE"] = "DELETE";
|
|
10
|
-
})(
|
|
11
|
-
|
|
8
|
+
})(HttpMethod || (HttpMethod = {}));
|
|
9
|
+
var ContentType;
|
|
12
10
|
(function (ContentType) {
|
|
13
11
|
ContentType["APPLICATION_JSON"] = "application/json";
|
|
14
12
|
ContentType["MULTIPART_FORM_DATA"] = "multipart/form-data";
|
|
15
|
-
})(
|
|
13
|
+
})(ContentType || (ContentType = {}));
|
|
14
|
+
|
|
15
|
+
export { ContentType, HttpMethod };
|
|
16
16
|
//# sourceMappingURL=request.enum.js.map
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
//
|
|
4
2
|
const errorTransformer = (data) => {
|
|
5
3
|
return {
|
|
@@ -21,6 +19,5 @@ const successTransformer = (data) => {
|
|
|
21
19
|
};
|
|
22
20
|
};
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
exports.successTransformer = successTransformer;
|
|
22
|
+
export { errorTransformer, successTransformer };
|
|
26
23
|
//# sourceMappingURL=transformer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transformer.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -3,8 +3,8 @@ import { useReactNativeEnv } from './useReactNativeEnv';
|
|
|
3
3
|
|
|
4
4
|
export const useEnvironmentVariables = (): IConfig => {
|
|
5
5
|
const { appTimeout, appUrl } = useReactNativeEnv();
|
|
6
|
-
const url = process.env.REACT_APP_API_URL
|
|
7
|
-
const timeout = process.env.REACT_APP_API_TIMEOUT
|
|
6
|
+
const url = process.env.REACT_APP_API_URL ?? process.env.NEXT_PUBLIC_API_URL ?? appUrl;
|
|
7
|
+
const timeout = process.env.REACT_APP_API_TIMEOUT ?? process.env.NEXT_PUBLIC_API_TIMEOUT ?? appTimeout;
|
|
8
8
|
|
|
9
9
|
return {
|
|
10
10
|
API_URL: url as string,
|
|
@@ -1,28 +1,13 @@
|
|
|
1
1
|
import { useQueryClient } from '@tanstack/react-query';
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
3
2
|
import type { TanstackQueryConfig } from '../types';
|
|
4
3
|
|
|
5
4
|
export const useReactNativeEnv = () => {
|
|
6
5
|
const queryClient = useQueryClient();
|
|
6
|
+
const config = queryClient.getQueryData<TanstackQueryConfig>(['config']);
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const appUrl: string | undefined = config?.options?.environments?.appBaseUrl;
|
|
9
|
+
const appTimeout: number | undefined = config?.options?.environments?.appTimeout;
|
|
10
|
+
const isApp = config?.options?.context === 'app';
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
const config = queryClient.getQueryData<TanstackQueryConfig>(['config']);
|
|
13
|
-
|
|
14
|
-
const loadReactNativeEnvIfNeeded = async () => {
|
|
15
|
-
if (config?.options?.context === 'app') {
|
|
16
|
-
const API_URL = config.options.environments?.appBaseUrl;
|
|
17
|
-
const API_TIMEOUT = config.options.environments?.appTimeout;
|
|
18
|
-
|
|
19
|
-
setAppUrl(API_URL);
|
|
20
|
-
setAppTimeout(API_TIMEOUT);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
loadReactNativeEnvIfNeeded();
|
|
25
|
-
}, [queryClient]);
|
|
26
|
-
|
|
27
|
-
return { appUrl, appTimeout };
|
|
12
|
+
return { appUrl, appTimeout, isApp };
|
|
28
13
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import type { IMakeRequest } from './request.interface';
|
|
3
4
|
|
|
4
|
-
export const axiosInstance = (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
export const axiosInstance = ({ baseURL, timeout, headers }: Partial<IMakeRequest>): AxiosInstance => {
|
|
6
|
+
return axios.create({
|
|
7
|
+
baseURL,
|
|
8
|
+
timeout,
|
|
9
|
+
headers,
|
|
10
|
+
});
|
|
10
11
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
1
2
|
import { axiosInstance } from './axios-instance';
|
|
2
3
|
|
|
3
|
-
import { buildFormData } from './buildFormData';
|
|
4
4
|
import { ContentType, HttpMethod } from './request.enum';
|
|
5
5
|
import type { IMakeRequest } from './request.interface';
|
|
6
6
|
import { errorTransformer, successTransformer } from './transformer';
|
|
@@ -15,7 +15,7 @@ export async function makeRequest<TResponse>({
|
|
|
15
15
|
timeout,
|
|
16
16
|
}: IMakeRequest) {
|
|
17
17
|
// configure body
|
|
18
|
-
body = isFormData ?
|
|
18
|
+
body = isFormData ? axios.toFormData(body as Record<string, any>) : body;
|
|
19
19
|
|
|
20
20
|
// configure request header
|
|
21
21
|
if (!isFormData) {
|
|
@@ -25,10 +25,14 @@ export async function makeRequest<TResponse>({
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
try {
|
|
28
|
-
const axios = axiosInstance(
|
|
28
|
+
const axios = axiosInstance({ baseURL, headers, timeout });
|
|
29
29
|
|
|
30
30
|
// send request
|
|
31
|
-
const resp = await axios(
|
|
31
|
+
const resp = await axios({
|
|
32
|
+
url: path,
|
|
33
|
+
method,
|
|
34
|
+
data: body,
|
|
35
|
+
});
|
|
32
36
|
|
|
33
37
|
// get response json
|
|
34
38
|
const jsonResp: any = await resp.data;
|