@ichaingo/request 1.3.7 → 1.3.72
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 +33 -33
- package/dist/interceptors/refreshToken.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2,34 +2,34 @@ import E, { isAxiosError as C, AxiosError as w } from "axios";
|
|
|
2
2
|
import A from "qs";
|
|
3
3
|
import $ from "js-cookie";
|
|
4
4
|
import { logger as U } from "@ichaingo/logger";
|
|
5
|
-
import q, { isTokenExpired as O, getToken as b,
|
|
6
|
-
const
|
|
7
|
-
async function
|
|
5
|
+
import q, { isTokenExpired as O, getToken as b, removeAllToken as P } from "@ichaingo/token";
|
|
6
|
+
const B = () => /^(zh-hans|zh-cn|zh-sg|zh-my)$/.test(window == null ? void 0 : window.navigator.language.toLowerCase()), S = () => B() ? "zh-hans" : "";
|
|
7
|
+
async function z(e) {
|
|
8
8
|
var n;
|
|
9
|
-
let t = "",
|
|
9
|
+
let t = "", s = "";
|
|
10
10
|
if (process.env.IS_SERVER) {
|
|
11
11
|
const c = await import("http");
|
|
12
12
|
e.httpAgent = new c.Agent({
|
|
13
13
|
keepAlive: !0
|
|
14
14
|
});
|
|
15
15
|
try {
|
|
16
|
-
const
|
|
16
|
+
const r = e.headers.get("Accept-Language");
|
|
17
17
|
e.headers["x-whistle-nohost-env"] = process.env.NO_HOST_ENV || "ichaingo";
|
|
18
18
|
const { cookies: i, headers: u } = await import("next/headers");
|
|
19
19
|
t = ((n = (await i()).get("access_token")) == null ? void 0 : n.value) || "";
|
|
20
20
|
const d = await u();
|
|
21
|
-
|
|
22
|
-
} catch (
|
|
23
|
-
console.error("Error accessing cookies in server component:",
|
|
21
|
+
s = r || d.get("x-next-intl-locale") || "en";
|
|
22
|
+
} catch (r) {
|
|
23
|
+
console.error("Error accessing cookies in server component:", r);
|
|
24
24
|
}
|
|
25
25
|
} else
|
|
26
|
-
t = $.get("access_token") || "",
|
|
26
|
+
t = $.get("access_token") || "", s = $.get("NEXT_LOCALE") || S() || "en";
|
|
27
27
|
const a = e.headers.isRefreshToken;
|
|
28
|
-
return e.headers["Accept-Language"] =
|
|
28
|
+
return e.headers["Accept-Language"] = s, t && !a && (e.headers.Authorization = `Bearer ${t}`), e.headers.devicetype = 1, e;
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
var g, l, o, y, L, R, f, p, _,
|
|
32
|
-
const t = (l = (g = e.config) == null ? void 0 : g.method) == null ? void 0 : l.toUpperCase(),
|
|
30
|
+
function H(e) {
|
|
31
|
+
var g, l, o, y, L, R, f, p, _, I, k;
|
|
32
|
+
const t = (l = (g = e.config) == null ? void 0 : g.method) == null ? void 0 : l.toUpperCase(), s = ((o = e.config) == null ? void 0 : o.baseURL) || "", a = (y = e.config) != null && y.url ? `${s || ""}${e.config.url}` : "", n = (L = e.response) == null ? void 0 : L.status, c = (R = e.response) == null ? void 0 : R.statusText, r = (f = e.response) == null ? void 0 : f.data, i = ((_ = (p = e.response) == null ? void 0 : p.headers) == null ? void 0 : _["x-request-id"]) || ((I = r == null ? void 0 : r.status) == null ? void 0 : I.requestId), u = (r == null ? void 0 : r.message) || (r == null ? void 0 : r.msg) || ((k = r == null ? void 0 : r.status) == null ? void 0 : k.msg), m = [
|
|
33
33
|
n ? `HTTP ${n}` : "HTTP ERROR",
|
|
34
34
|
t,
|
|
35
35
|
a,
|
|
@@ -38,12 +38,12 @@ function j(e) {
|
|
|
38
38
|
return [m, d, h].filter(Boolean).join(" | ");
|
|
39
39
|
}
|
|
40
40
|
function x(e) {
|
|
41
|
-
var c,
|
|
41
|
+
var c, r, i, u, m, d, h, g, l;
|
|
42
42
|
const t = e.config;
|
|
43
|
-
let
|
|
44
|
-
if (typeof
|
|
43
|
+
let s = t == null ? void 0 : t.data;
|
|
44
|
+
if (typeof s == "string")
|
|
45
45
|
try {
|
|
46
|
-
|
|
46
|
+
s = JSON.parse(s);
|
|
47
47
|
} catch {
|
|
48
48
|
}
|
|
49
49
|
const a = t == null ? void 0 : t.baseURL, n = t != null && t.url ? a ? `${a}${t.url}` : t.url : void 0;
|
|
@@ -51,31 +51,31 @@ function x(e) {
|
|
|
51
51
|
method: (c = t == null ? void 0 : t.method) == null ? void 0 : c.toUpperCase(),
|
|
52
52
|
url: n,
|
|
53
53
|
params: t == null ? void 0 : t.params,
|
|
54
|
-
data:
|
|
55
|
-
status: (
|
|
54
|
+
data: s,
|
|
55
|
+
status: (r = e.response) == null ? void 0 : r.status,
|
|
56
56
|
statusText: (i = e.response) == null ? void 0 : i.statusText,
|
|
57
57
|
requestId: ((m = (u = e.response) == null ? void 0 : u.headers) == null ? void 0 : m["x-request-id"]) || ((g = (h = (d = e.response) == null ? void 0 : d.data) == null ? void 0 : h.status) == null ? void 0 : g.requestId),
|
|
58
58
|
responseData: (l = e.response) == null ? void 0 : l.data
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
function N(e) {
|
|
62
|
-
var n, c,
|
|
62
|
+
var n, c, r, i;
|
|
63
63
|
const t = C(e) ? e : new w(String(e));
|
|
64
64
|
if (t.code === "ECONNABORTED" || /timeout/i.test(t.message || "")) {
|
|
65
|
-
const u = (c = (n = t.config) == null ? void 0 : n.method) == null ? void 0 : c.toUpperCase(), m = ((
|
|
65
|
+
const u = (c = (n = t.config) == null ? void 0 : n.method) == null ? void 0 : c.toUpperCase(), m = ((r = t.config) == null ? void 0 : r.baseURL) || "", d = (i = t.config) != null && i.url ? `${m || ""}${t.config.url}` : "", h = ["TIMEOUT", u, d].filter(Boolean).join(" | ");
|
|
66
66
|
return t.summary = h, t.details = JSON.stringify(x(t)), U.error({ message: h, details: t.details, errType: "timeout" }), Promise.reject(t);
|
|
67
67
|
}
|
|
68
|
-
const a =
|
|
68
|
+
const a = H(t);
|
|
69
69
|
return t.summary = a, t.details = JSON.stringify(x(t)), U.error({ message: a, details: t.details, errType: "server error" }), Promise.reject(t);
|
|
70
70
|
}
|
|
71
|
-
function
|
|
72
|
-
var
|
|
71
|
+
function j(e) {
|
|
72
|
+
var s, a, n, c, r, i, u, m, d, h, g;
|
|
73
73
|
const t = e.config;
|
|
74
74
|
if (t.returnFullResponse)
|
|
75
75
|
return e;
|
|
76
76
|
if (e.status === 401) {
|
|
77
77
|
q.removeAllToken();
|
|
78
|
-
const l = ((
|
|
78
|
+
const l = ((s = t == null ? void 0 : t.headers) == null ? void 0 : s["Accept-Language"]) || "en";
|
|
79
79
|
return window.location.href = `${process.env.NEXT_PUBLIC_AUTH_URL}/${l}/login`, e;
|
|
80
80
|
}
|
|
81
81
|
if (e.status === 200) {
|
|
@@ -89,7 +89,7 @@ function M(e) {
|
|
|
89
89
|
e.config,
|
|
90
90
|
e.request,
|
|
91
91
|
e
|
|
92
|
-
), L = `BIZ ${o.code} | ${(c = (n = e.config) == null ? void 0 : n.method) == null ? void 0 : c.toUpperCase()} | ${((
|
|
92
|
+
), L = `BIZ ${o.code} | ${(c = (n = e.config) == null ? void 0 : n.method) == null ? void 0 : c.toUpperCase()} | ${((r = e.config) == null ? void 0 : r.baseURL) || ""}${((i = e.config) == null ? void 0 : i.url) || ""} | server: ${o == null ? void 0 : o.msg}`, R = {
|
|
93
93
|
method: (m = (u = e.config) == null ? void 0 : u.method) == null ? void 0 : m.toUpperCase(),
|
|
94
94
|
url: (d = e.config) != null && d.baseURL ? `${e.config.baseURL}${e.config.url || ""}` : e.config.url,
|
|
95
95
|
params: (h = e.config) == null ? void 0 : h.params,
|
|
@@ -115,7 +115,7 @@ function M(e) {
|
|
|
115
115
|
return e;
|
|
116
116
|
}
|
|
117
117
|
let T = null;
|
|
118
|
-
const
|
|
118
|
+
const M = E.create({
|
|
119
119
|
baseURL: process.env.NEXT_PUBLIC_AUTH_URL,
|
|
120
120
|
timeout: 1e4,
|
|
121
121
|
withCredentials: !0,
|
|
@@ -124,11 +124,11 @@ const J = E.create({
|
|
|
124
124
|
return A.stringify(e, { arrayFormat: "brackets" });
|
|
125
125
|
}
|
|
126
126
|
});
|
|
127
|
-
async function
|
|
127
|
+
async function J(e) {
|
|
128
128
|
const t = e.headers;
|
|
129
129
|
return T ? (await T, e) : (O() && (T = (async () => {
|
|
130
130
|
var a;
|
|
131
|
-
const
|
|
131
|
+
const s = await M.get("/api/refresh/token", {
|
|
132
132
|
params: {
|
|
133
133
|
grant_type: "refresh_token",
|
|
134
134
|
refresh_token: b("refresh_token")
|
|
@@ -137,7 +137,7 @@ async function X(e) {
|
|
|
137
137
|
...t
|
|
138
138
|
}
|
|
139
139
|
});
|
|
140
|
-
return (a =
|
|
140
|
+
return (a = s == null ? void 0 : s.data) != null && a.data || P(), Promise.resolve();
|
|
141
141
|
})().finally(() => {
|
|
142
142
|
T = null;
|
|
143
143
|
}), await T), e);
|
|
@@ -151,9 +151,9 @@ const v = E.create({
|
|
|
151
151
|
return A.stringify(e, { arrayFormat: "brackets" });
|
|
152
152
|
}
|
|
153
153
|
});
|
|
154
|
-
v.interceptors.request.use(
|
|
155
|
-
v.interceptors.request.use(
|
|
156
|
-
v.interceptors.response.use(
|
|
154
|
+
v.interceptors.request.use(J);
|
|
155
|
+
v.interceptors.request.use(z, N);
|
|
156
|
+
v.interceptors.response.use(j, N);
|
|
157
157
|
export {
|
|
158
158
|
v as default
|
|
159
159
|
};
|
|
@@ -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,4CA8BnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ichaingo/request",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.72",
|
|
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.3.
|
|
26
|
-
"@ichaingo/token": "1.3.
|
|
25
|
+
"@ichaingo/logger": "1.3.72",
|
|
26
|
+
"@ichaingo/token": "1.3.72"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/js-cookie": "^3.0.6",
|