@acrool/react-fetcher 0.0.7-alpha.3 → 0.0.8-alpha.0
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/acrool-react-fetcher.es.js +31 -21
- package/dist/acrool-react-fetcher.es.js.map +1 -1
- package/dist/fetchers/createGraphQLFetcher/createGraphQLFetcher.d.ts +3 -2
- package/dist/fetchers/createGraphQLFetcher/types.d.ts +3 -0
- package/dist/fetchers/createRestFulFetcher/createRestFulFetcher.d.ts +3 -3
- package/dist/fetchers/createRestFulFetcher/types.d.ts +5 -0
- package/dist/fetchers/types.d.ts +1 -1
- package/package.json +1 -1
- package/dist/fetchers/config.d.ts +0 -1
|
@@ -9,7 +9,6 @@ function r$1(e2) {
|
|
|
9
9
|
}, e2);
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
const fetcherLeastTime = 400;
|
|
13
12
|
const isFile$1 = (input) => "File" in window && input instanceof File;
|
|
14
13
|
const isBlob$1 = (input) => "Blob" in window && input instanceof Blob;
|
|
15
14
|
const getVariablesFileMap = (originVariables, parentKey = ["variables"]) => {
|
|
@@ -36,11 +35,17 @@ const getVariablesFileMap = (originVariables, parentKey = ["variables"]) => {
|
|
|
36
35
|
};
|
|
37
36
|
}, { variables: {}, map: [], values: [] });
|
|
38
37
|
};
|
|
39
|
-
const createGraphQLFetcher = (axiosInstance, query) => {
|
|
38
|
+
const createGraphQLFetcher = (axiosInstance, query, options) => {
|
|
40
39
|
return async (args) => {
|
|
41
40
|
let data = void 0;
|
|
42
41
|
let contentType = void 0;
|
|
43
|
-
|
|
42
|
+
let fetchOptions = {};
|
|
43
|
+
let headers = {};
|
|
44
|
+
if (args == null ? void 0 : args.fetchOptions) {
|
|
45
|
+
const { headers: tmpHeader, ...tmpFetchOptions } = args.fetchOptions;
|
|
46
|
+
fetchOptions = tmpFetchOptions;
|
|
47
|
+
headers = tmpHeader;
|
|
48
|
+
}
|
|
44
49
|
const variables = args == null ? void 0 : args.variables;
|
|
45
50
|
let isMultipartFormData = false;
|
|
46
51
|
if (variables) {
|
|
@@ -74,18 +79,17 @@ const createGraphQLFetcher = (axiosInstance, query) => {
|
|
|
74
79
|
data = JSON.stringify({ query, variables });
|
|
75
80
|
}
|
|
76
81
|
const endpoint = "";
|
|
77
|
-
const headers = {
|
|
78
|
-
"Content-Type": contentType,
|
|
79
|
-
"Apollo-Require-Preflight": "true",
|
|
80
|
-
"X-Requested-With": "XMLHttpRequest",
|
|
81
|
-
...options == null ? void 0 : options.headers
|
|
82
|
-
};
|
|
83
82
|
const [res] = await Promise.all([
|
|
84
83
|
axiosInstance.post(endpoint, data, {
|
|
85
|
-
|
|
86
|
-
headers
|
|
84
|
+
fetchOptions,
|
|
85
|
+
headers: {
|
|
86
|
+
...headers,
|
|
87
|
+
"Content-Type": contentType,
|
|
88
|
+
"Apollo-Require-Preflight": "true",
|
|
89
|
+
"X-Requested-With": "XMLHttpRequest"
|
|
90
|
+
}
|
|
87
91
|
}),
|
|
88
|
-
r$1((
|
|
92
|
+
r$1((fetchOptions == null ? void 0 : fetchOptions.leastTime) ?? (options == null ? void 0 : options.fetcherLeastTime) ?? 100)
|
|
89
93
|
]);
|
|
90
94
|
return res.data.data;
|
|
91
95
|
};
|
|
@@ -127,28 +131,34 @@ const getDataWithContentType = (contentType, data = {}) => {
|
|
|
127
131
|
const getContentTypeWithMethod = (method) => {
|
|
128
132
|
return ERequestContentType.json;
|
|
129
133
|
};
|
|
130
|
-
const createRestFulFetcher = (axiosInstance, document2,
|
|
134
|
+
const createRestFulFetcher = (axiosInstance, document2, options) => {
|
|
131
135
|
return async (args) => {
|
|
132
|
-
var _a;
|
|
133
136
|
const method = (document2 == null ? void 0 : document2.method) || "";
|
|
134
|
-
|
|
137
|
+
let fetchOptions = {};
|
|
138
|
+
let headers = {};
|
|
139
|
+
if (args == null ? void 0 : args.fetchOptions) {
|
|
140
|
+
const { headers: tmpHeader, ...tmpFetchOptions } = args.fetchOptions;
|
|
141
|
+
fetchOptions = tmpFetchOptions;
|
|
142
|
+
headers = tmpHeader;
|
|
143
|
+
}
|
|
135
144
|
const body = typeof args === "object" && args !== null && "body" in args ? args.body : void 0;
|
|
136
145
|
const params = typeof args === "object" && args !== null && "params" in args ? args.params : void 0;
|
|
137
|
-
const
|
|
146
|
+
const contentTypeResolver = (options == null ? void 0 : options.contentTypeResolver) ?? getContentTypeWithMethod;
|
|
147
|
+
const contentType = (headers == null ? void 0 : headers.contentType) ?? contentTypeResolver(method.toUpperCase());
|
|
138
148
|
const config = {
|
|
139
149
|
url: document2.url,
|
|
140
150
|
method,
|
|
141
151
|
params,
|
|
142
152
|
data: getDataWithContentType(contentType, body),
|
|
143
|
-
|
|
153
|
+
fetchOptions,
|
|
144
154
|
headers: {
|
|
145
|
-
...
|
|
155
|
+
...headers,
|
|
146
156
|
"Content-Type": contentType
|
|
147
157
|
}
|
|
148
158
|
};
|
|
149
159
|
const [res] = await Promise.all([
|
|
150
160
|
axiosInstance(config),
|
|
151
|
-
r$1((
|
|
161
|
+
r$1((fetchOptions == null ? void 0 : fetchOptions.leastTime) ?? (options == null ? void 0 : options.fetcherLeastTime) ?? 100)
|
|
152
162
|
]);
|
|
153
163
|
return res.data;
|
|
154
164
|
};
|
|
@@ -3182,7 +3192,7 @@ const FetcherProvider = ({
|
|
|
3182
3192
|
isTokenRefreshing = false;
|
|
3183
3193
|
if (isDebug) u.warning("[FetcherProvider] no refreshToken/refreshAPI|pendingRequest fail, force logout");
|
|
3184
3194
|
forceLogout();
|
|
3185
|
-
if (originalConfig.
|
|
3195
|
+
if (originalConfig.ignoreGlobalError !== true) handleOnResponseError(responseFirstError);
|
|
3186
3196
|
return Promise.reject(new FetcherException(responseFirstError));
|
|
3187
3197
|
}
|
|
3188
3198
|
if (!isTokenRefreshing) {
|
|
@@ -3201,7 +3211,7 @@ const FetcherProvider = ({
|
|
|
3201
3211
|
});
|
|
3202
3212
|
}
|
|
3203
3213
|
}
|
|
3204
|
-
if (originalConfig.
|
|
3214
|
+
if (originalConfig.ignoreGlobalError !== true) handleOnResponseError(responseFirstError);
|
|
3205
3215
|
return Promise.reject(new FetcherException(responseFirstError));
|
|
3206
3216
|
};
|
|
3207
3217
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|