@0xchain/request 1.1.0-beta.35 → 1.1.0-beta.36
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/index.js +24 -3
- package/dist/interceptors/refreshToken.d.ts.map +1 -1
- package/package.json +14 -14
- package/LICENSE +0 -21
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios, { isAxiosError, AxiosError } from "axios";
|
|
2
2
|
import qs from "qs";
|
|
3
|
-
import
|
|
3
|
+
import Cookies from "js-cookie";
|
|
4
4
|
import { logger } from "@0xchain/logger";
|
|
5
5
|
import TokenManager, { isTokenExpired, getToken, removeAllToken, setToken } from "@0xchain/token";
|
|
6
6
|
const isSimplifiedChinese = () => {
|
|
@@ -76,8 +76,8 @@ async function commonHeader(config) {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
} else {
|
|
79
|
-
access_token =
|
|
80
|
-
language =
|
|
79
|
+
access_token = Cookies.get("access_token") || "";
|
|
80
|
+
language = Cookies.get("NEXT_LOCALE") || matchSystemLanguage() || "en";
|
|
81
81
|
}
|
|
82
82
|
const isRefreshToken = config.headers?.["isRefreshToken"];
|
|
83
83
|
setHeader(config, "Accept-Language", language);
|
|
@@ -244,6 +244,15 @@ function ResponseInterceptor(response) {
|
|
|
244
244
|
}
|
|
245
245
|
return response;
|
|
246
246
|
}
|
|
247
|
+
function setAuthHeader(config, accessToken) {
|
|
248
|
+
const value = `Bearer ${accessToken}`;
|
|
249
|
+
const h = config.headers;
|
|
250
|
+
if (h?.set && typeof h.set === "function") {
|
|
251
|
+
h.set("Authorization", value);
|
|
252
|
+
} else {
|
|
253
|
+
h.Authorization = value;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
247
256
|
let refreshPromise = null;
|
|
248
257
|
const axiosInstance$1 = axios.create({
|
|
249
258
|
baseURL: process.env.AUTH_INNER_API_URL || process.env.NEXT_PUBLIC_AUTH_URL,
|
|
@@ -264,6 +273,10 @@ async function refreshToken(config) {
|
|
|
264
273
|
const headers = config.headers;
|
|
265
274
|
if (refreshPromise) {
|
|
266
275
|
await refreshPromise;
|
|
276
|
+
const accessAfterWait = Cookies.get("access_token") || getToken("access_token");
|
|
277
|
+
if (accessAfterWait) {
|
|
278
|
+
setAuthHeader(config, accessAfterWait);
|
|
279
|
+
}
|
|
267
280
|
return config;
|
|
268
281
|
}
|
|
269
282
|
let expired = false;
|
|
@@ -280,6 +293,10 @@ async function refreshToken(config) {
|
|
|
280
293
|
}
|
|
281
294
|
if (refreshPromise) {
|
|
282
295
|
await refreshPromise;
|
|
296
|
+
const accessAfterWait = Cookies.get("access_token") || getToken("access_token");
|
|
297
|
+
if (accessAfterWait) {
|
|
298
|
+
setAuthHeader(config, accessAfterWait);
|
|
299
|
+
}
|
|
283
300
|
return config;
|
|
284
301
|
}
|
|
285
302
|
const refreshHeaders = { ...headers };
|
|
@@ -309,6 +326,10 @@ async function refreshToken(config) {
|
|
|
309
326
|
refreshPromise = null;
|
|
310
327
|
});
|
|
311
328
|
await refreshPromise;
|
|
329
|
+
const accessAfterRefresh = Cookies.get("access_token") || getToken("access_token");
|
|
330
|
+
if (accessAfterRefresh) {
|
|
331
|
+
setAuthHeader(config, accessAfterRefresh);
|
|
332
|
+
}
|
|
312
333
|
}
|
|
313
334
|
return config;
|
|
314
335
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refreshToken.d.ts","sourceRoot":"","sources":["../../src/interceptors/refreshToken.ts"],"names":[],"mappings":"AAAA,OAAc,
|
|
1
|
+
{"version":3,"file":"refreshToken.d.ts","sourceRoot":"","sources":["../../src/interceptors/refreshToken.ts"],"names":[],"mappings":"AAAA,OAAc,EAAoB,0BAA0B,EAAE,MAAM,OAAO,CAAC;AAuB5E,wBAA8B,YAAY,CACxC,MAAM,EAAE,0BAA0B,4CAkFnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xchain/request",
|
|
3
|
-
"version": "1.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.36",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -18,22 +18,22 @@
|
|
|
18
18
|
"!**/*.tsbuildinfo"
|
|
19
19
|
],
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"axios": "
|
|
22
|
-
"js-cookie": "
|
|
23
|
-
"next": "
|
|
24
|
-
"qs": "
|
|
21
|
+
"axios": "catalog:",
|
|
22
|
+
"js-cookie": "catalog:",
|
|
23
|
+
"next": "catalog:",
|
|
24
|
+
"qs": "catalog:"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@types/js-cookie": "
|
|
28
|
-
"@types/qs": "
|
|
29
|
-
"axios": "
|
|
30
|
-
"js-cookie": "
|
|
31
|
-
"next": "
|
|
32
|
-
"qs": "
|
|
27
|
+
"@types/js-cookie": "catalog:",
|
|
28
|
+
"@types/qs": "catalog:",
|
|
29
|
+
"axios": "catalog:",
|
|
30
|
+
"js-cookie": "catalog:",
|
|
31
|
+
"next": "catalog:",
|
|
32
|
+
"qs": "catalog:"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@0xchain/logger": "
|
|
36
|
-
"@0xchain/token": "
|
|
35
|
+
"@0xchain/logger": "workspace:*",
|
|
36
|
+
"@0xchain/token": "workspace:*"
|
|
37
37
|
},
|
|
38
38
|
"nx": {
|
|
39
39
|
"tags": [
|
|
@@ -43,4 +43,4 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024-present 0xchain
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|