@ichaingo/request 1.2.9 → 1.3.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/index.js +16 -15
- package/dist/interceptors/refreshToken.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@ import $, { isAxiosError as C, AxiosError as w } from "axios";
|
|
|
2
2
|
import N from "qs";
|
|
3
3
|
import x from "js-cookie";
|
|
4
4
|
import { logger as R } from "@ichaingo/logger";
|
|
5
|
-
import q, { isTokenExpired as O, getToken as b } from "@ichaingo/token";
|
|
6
|
-
const
|
|
7
|
-
async function
|
|
5
|
+
import q, { isTokenExpired as O, getToken as b, setToken as B } from "@ichaingo/token";
|
|
6
|
+
const P = () => /^(zh-hans|zh-cn|zh-sg|zh-my)$/.test(window == null ? void 0 : window.navigator.language.toLowerCase()), S = () => P() ? "zh-hans" : "";
|
|
7
|
+
async function z(e) {
|
|
8
8
|
var n;
|
|
9
9
|
let t = "", o = "";
|
|
10
10
|
if (process.env.IS_SERVER) {
|
|
@@ -23,13 +23,13 @@ async function S(e) {
|
|
|
23
23
|
console.error("Error accessing cookies in server component:", s);
|
|
24
24
|
}
|
|
25
25
|
} else
|
|
26
|
-
t = x.get("access_token") || "", o = x.get("NEXT_LOCALE") ||
|
|
26
|
+
t = x.get("access_token") || "", o = x.get("NEXT_LOCALE") || S() || "en";
|
|
27
27
|
const i = e.headers.isRefreshToken;
|
|
28
28
|
return e.headers["Accept-Language"] = o, t && !i && (e.headers.Authorization = `Bearer ${t}`), e.headers.devicetype = 1, e;
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
var g, r, T, y, L, h, f, _, I,
|
|
32
|
-
const t = (r = (g = e.config) == null ? void 0 : g.method) == null ? void 0 : r.toUpperCase(), o = ((T = e.config) == null ? void 0 : T.baseURL) || "", i = (y = e.config) != null && y.url ? `${o || ""}${e.config.url}` : "", n = (L = e.response) == null ? void 0 : L.status, c = (h = e.response) == null ? void 0 : h.statusText, s = (f = e.response) == null ? void 0 : f.data, a = ((I = (_ = e.response) == null ? void 0 : _.headers) == null ? void 0 : I["x-request-id"]) || ((
|
|
30
|
+
function H(e) {
|
|
31
|
+
var g, r, T, y, L, h, f, _, I, k, v;
|
|
32
|
+
const t = (r = (g = e.config) == null ? void 0 : g.method) == null ? void 0 : r.toUpperCase(), o = ((T = e.config) == null ? void 0 : T.baseURL) || "", i = (y = e.config) != null && y.url ? `${o || ""}${e.config.url}` : "", n = (L = e.response) == null ? void 0 : L.status, c = (h = e.response) == null ? void 0 : h.statusText, s = (f = e.response) == null ? void 0 : f.data, a = ((I = (_ = e.response) == null ? void 0 : _.headers) == null ? void 0 : I["x-request-id"]) || ((k = s == null ? void 0 : s.status) == null ? void 0 : k.requestId), u = (s == null ? void 0 : s.message) || (s == null ? void 0 : s.msg) || ((v = s == null ? void 0 : s.status) == null ? void 0 : v.msg), m = [
|
|
33
33
|
n ? `HTTP ${n}` : "HTTP ERROR",
|
|
34
34
|
t,
|
|
35
35
|
i,
|
|
@@ -65,10 +65,10 @@ function A(e) {
|
|
|
65
65
|
const u = (c = (n = t.config) == null ? void 0 : n.method) == null ? void 0 : c.toUpperCase(), m = ((s = t.config) == null ? void 0 : s.baseURL) || "", d = (a = t.config) != null && a.url ? `${m || ""}${t.config.url}` : "", l = ["TIMEOUT", u, d].filter(Boolean).join(" | ");
|
|
66
66
|
return t.summary = l, t.details = JSON.stringify(E(t)), R.error({ message: l, details: t.details, errType: "timeout" }), Promise.reject(t);
|
|
67
67
|
}
|
|
68
|
-
const i =
|
|
68
|
+
const i = H(t);
|
|
69
69
|
return t.summary = i, t.details = JSON.stringify(E(t)), R.error({ message: i, details: t.details, errType: "server error" }), Promise.reject(t);
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function j(e) {
|
|
72
72
|
var o, i, n, c, s, a, u, m, d, l;
|
|
73
73
|
if (e.config.returnFullResponse)
|
|
74
74
|
return e;
|
|
@@ -111,7 +111,7 @@ function H(e) {
|
|
|
111
111
|
return e;
|
|
112
112
|
}
|
|
113
113
|
let p = null;
|
|
114
|
-
const
|
|
114
|
+
const M = $.create({
|
|
115
115
|
baseURL: process.env.NEXT_PUBLIC_AUTH_URL,
|
|
116
116
|
timeout: 1e4,
|
|
117
117
|
withCredentials: !0,
|
|
@@ -120,10 +120,10 @@ const j = $.create({
|
|
|
120
120
|
return N.stringify(e, { arrayFormat: "brackets" });
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
|
-
async function
|
|
123
|
+
async function J(e) {
|
|
124
124
|
const t = e.headers;
|
|
125
125
|
return p ? (await p, e) : (O() && (p = (async () => {
|
|
126
|
-
await
|
|
126
|
+
const o = await M.get("/api/refresh/token", {
|
|
127
127
|
params: {
|
|
128
128
|
grant_type: "refresh_token",
|
|
129
129
|
refresh_token: b("refresh_token")
|
|
@@ -132,6 +132,7 @@ async function M(e) {
|
|
|
132
132
|
...t
|
|
133
133
|
}
|
|
134
134
|
});
|
|
135
|
+
B(o.data);
|
|
135
136
|
})().finally(() => {
|
|
136
137
|
p = null;
|
|
137
138
|
}), await p), e);
|
|
@@ -145,9 +146,9 @@ const U = $.create({
|
|
|
145
146
|
return N.stringify(e, { arrayFormat: "brackets" });
|
|
146
147
|
}
|
|
147
148
|
});
|
|
148
|
-
U.interceptors.request.use(
|
|
149
|
-
U.interceptors.request.use(
|
|
150
|
-
U.interceptors.response.use(
|
|
149
|
+
U.interceptors.request.use(J);
|
|
150
|
+
U.interceptors.request.use(z, A);
|
|
151
|
+
U.interceptors.response.use(j, A);
|
|
151
152
|
export {
|
|
152
153
|
U as default
|
|
153
154
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refreshToken.d.ts","sourceRoot":"","sources":["../../src/interceptors/refreshToken.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,0BAA0B,EAAE,MAAM,OAAO,CAAC;AAY1D,wBAA8B,YAAY,CACxC,MAAM,EAAE,0BAA0B,
|
|
1
|
+
{"version":3,"file":"refreshToken.d.ts","sourceRoot":"","sources":["../../src/interceptors/refreshToken.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,0BAA0B,EAAE,MAAM,OAAO,CAAC;AAY1D,wBAA8B,YAAY,CACxC,MAAM,EAAE,0BAA0B,4CA2BnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ichaingo/request",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"js-cookie": "3.0.5",
|
|
23
23
|
"next": "^15.4.5",
|
|
24
24
|
"qs": "6.14.0",
|
|
25
|
-
"@ichaingo/logger": "1.
|
|
26
|
-
"@ichaingo/token": "1.
|
|
25
|
+
"@ichaingo/logger": "1.3.1",
|
|
26
|
+
"@ichaingo/token": "1.3.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/js-cookie": "^3.0.6",
|