@0xchain/request 1.1.0-beta.6 → 1.1.0-beta.61
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/LICENSE +21 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +99 -67
- package/dist/interceptors/commonHeader.d.ts +2 -0
- package/dist/interceptors/commonHeader.d.ts.map +1 -1
- package/dist/interceptors/refreshToken.d.ts.map +1 -1
- package/dist/runtime.d.ts +9 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +19 -8
- package/dist/__vite-browser-external-2Ng8QIWW.js +0 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
package/dist/index.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ export interface ApiError extends AxiosError {
|
|
|
11
11
|
}
|
|
12
12
|
declare const axiosInstance: import('axios').AxiosInstance;
|
|
13
13
|
export default axiosInstance;
|
|
14
|
-
export
|
|
14
|
+
export { setServerHeaderProvider } from './interceptors/commonHeader';
|
|
15
|
+
export type { ApiRequestConfig, ServerHeaderProvider, Pagination, Status, IResponse, IFilters, IPageRequest, } from './types';
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,UAAU,EAAE,MAAM,OAAO,CAAC;AAQ/C,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,IAAI,EAAE,CAAC,CAAC;CACT;AAED,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAGD,QAAA,MAAM,aAAa,+BAYjB,CAAC;AASH,eAAe,aAAa,CAAC;AAE7B,YAAY,EACV,gBAAgB,EAChB,UAAU,EACV,MAAM,EACN,SAAS,EACT,QAAQ,EACR,YAAY,GACb,MAAM,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,UAAU,EAAE,MAAM,OAAO,CAAC;AAQ/C,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,IAAI,EAAE,CAAC,CAAC;CACT;AAED,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAGD,QAAA,MAAM,aAAa,+BAYjB,CAAC;AASH,eAAe,aAAa,CAAC;AAE7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,UAAU,EACV,MAAM,EACN,SAAS,EACT,QAAQ,EACR,YAAY,GACb,MAAM,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
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
|
-
import TokenManager, { isTokenExpired, getToken, removeAllToken } from "@0xchain/token";
|
|
5
|
+
import TokenManager, { isTokenExpired, getToken, removeAllToken, setToken } from "@0xchain/token";
|
|
6
6
|
const isSimplifiedChinese = () => {
|
|
7
|
-
return /^(zh-hans|zh-cn|zh-sg|zh-my)$/.test(window
|
|
7
|
+
return /^(zh-hans|zh-cn|zh-sg|zh-my)$/.test(window?.navigator.language.toLowerCase());
|
|
8
8
|
};
|
|
9
9
|
const matchSystemLanguage = () => {
|
|
10
10
|
return isSimplifiedChinese() ? "zh-hans" : "";
|
|
11
11
|
};
|
|
12
|
+
function isServerRuntime() {
|
|
13
|
+
if (typeof window !== "undefined") {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
12
18
|
let httpAgent;
|
|
13
19
|
let httpsAgent;
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
let serverHeaderProvider;
|
|
21
|
+
function setServerHeaderProvider(provider) {
|
|
22
|
+
serverHeaderProvider = provider;
|
|
16
23
|
}
|
|
17
24
|
function isEdgeRuntime() {
|
|
18
25
|
return process.env.NEXT_RUNTIME === "edge" || typeof globalThis.EdgeRuntime !== "undefined";
|
|
@@ -22,51 +29,60 @@ function isNodeRuntime() {
|
|
|
22
29
|
}
|
|
23
30
|
function getHeader(config, key) {
|
|
24
31
|
const h = config.headers;
|
|
25
|
-
if (
|
|
26
|
-
return h
|
|
32
|
+
if (h?.get && typeof h.get === "function") return h.get(key);
|
|
33
|
+
return h?.[key];
|
|
27
34
|
}
|
|
28
35
|
function setHeader(config, key, value) {
|
|
29
36
|
const h = config.headers;
|
|
30
|
-
if (
|
|
37
|
+
if (h?.set && typeof h.set === "function") {
|
|
31
38
|
h.set(key, value);
|
|
32
39
|
} else {
|
|
33
40
|
h[key] = value;
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
43
|
async function commonHeader(config) {
|
|
37
|
-
var _a, _b;
|
|
38
44
|
let access_token = "";
|
|
39
45
|
let language = "";
|
|
40
46
|
if (isServerRuntime()) {
|
|
41
47
|
if (isNodeRuntime()) {
|
|
42
48
|
try {
|
|
43
49
|
const http = await import("http");
|
|
44
|
-
const https = await import("
|
|
45
|
-
const baseURL = config
|
|
50
|
+
const https = await import("https");
|
|
51
|
+
const baseURL = config?.baseURL;
|
|
46
52
|
const isHttps = typeof baseURL === "string" ? baseURL.startsWith("https://") : false;
|
|
47
|
-
if (!httpAgent &&
|
|
48
|
-
if (!httpsAgent &&
|
|
53
|
+
if (!httpAgent && http?.Agent) httpAgent = new http.Agent({ keepAlive: true });
|
|
54
|
+
if (!httpsAgent && https?.Agent) httpsAgent = new https.Agent({ keepAlive: true });
|
|
49
55
|
config.httpAgent = isHttps ? void 0 : httpAgent;
|
|
50
56
|
config.httpsAgent = isHttps ? httpsAgent : void 0;
|
|
51
57
|
} catch {
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
|
-
|
|
60
|
+
setHeader(config, "x-whistle-nohost-env", process.env.NO_HOST_ENV || "ichaingo");
|
|
61
|
+
if (serverHeaderProvider) {
|
|
55
62
|
const startLanguage = getHeader(config, "Accept-Language");
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
63
|
+
try {
|
|
64
|
+
access_token = await serverHeaderProvider.getAccessToken() || "";
|
|
65
|
+
language = startLanguage || await serverHeaderProvider.getLanguage() || "en";
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error("Error accessing server headers via provider:", error);
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
try {
|
|
71
|
+
const startLanguage = getHeader(config, "Accept-Language");
|
|
72
|
+
const { cookies, headers } = await import("next/headers");
|
|
73
|
+
const cookieStore = await cookies();
|
|
74
|
+
access_token = cookieStore.get("access_token")?.value || "";
|
|
75
|
+
const hList = await headers();
|
|
76
|
+
language = startLanguage || hList.get("x-next-intl-locale") || "en";
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error("Error accessing cookies in server component:", error);
|
|
79
|
+
}
|
|
64
80
|
}
|
|
65
81
|
} else {
|
|
66
|
-
access_token =
|
|
67
|
-
language =
|
|
82
|
+
access_token = Cookies.get("access_token") || "";
|
|
83
|
+
language = Cookies.get("NEXT_LOCALE") || matchSystemLanguage() || "en";
|
|
68
84
|
}
|
|
69
|
-
const isRefreshToken =
|
|
85
|
+
const isRefreshToken = config.headers?.["isRefreshToken"];
|
|
70
86
|
setHeader(config, "Accept-Language", language);
|
|
71
87
|
if (access_token && !isRefreshToken) {
|
|
72
88
|
setHeader(config, "Authorization", `Bearer ${access_token}`);
|
|
@@ -78,13 +94,12 @@ function toUpperMethod(m) {
|
|
|
78
94
|
return m ? m.toUpperCase() : void 0;
|
|
79
95
|
}
|
|
80
96
|
function getTypeName(v) {
|
|
81
|
-
var _a;
|
|
82
97
|
if (v === null) return "null";
|
|
83
98
|
if (v === void 0) return "undefined";
|
|
84
99
|
const t = typeof v;
|
|
85
100
|
if (t !== "object") return t;
|
|
86
101
|
try {
|
|
87
|
-
return
|
|
102
|
+
return v?.constructor?.name || "object";
|
|
88
103
|
} catch {
|
|
89
104
|
return "object";
|
|
90
105
|
}
|
|
@@ -105,15 +120,14 @@ function n(v) {
|
|
|
105
120
|
return v === void 0 ? null : v;
|
|
106
121
|
}
|
|
107
122
|
function buildErrorMessage(err) {
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
const serverMsg = (respData == null ? void 0 : respData.message) || (respData == null ? void 0 : respData.msg) || ((_j = respData == null ? void 0 : respData.status) == null ? void 0 : _j.msg);
|
|
123
|
+
const method = toUpperMethod(err.config?.method);
|
|
124
|
+
const baseURL = err.config?.baseURL || "";
|
|
125
|
+
const url = err.config?.url ? `${baseURL || ""}${err.config.url}` : "";
|
|
126
|
+
const status = err.response?.status;
|
|
127
|
+
const statusText = err.response?.statusText;
|
|
128
|
+
const respData = err.response?.data;
|
|
129
|
+
const requestId = err.response?.headers?.["x-request-id"] || respData?.status?.requestId;
|
|
130
|
+
const serverMsg = respData?.message || respData?.msg || respData?.status?.msg;
|
|
117
131
|
const summary = [
|
|
118
132
|
status ? `HTTP ${status}` : "HTTP ERROR",
|
|
119
133
|
method,
|
|
@@ -127,18 +141,17 @@ function buildErrorMessage(err) {
|
|
|
127
141
|
return [summary, shortMsg, ridMsg, codeMsg, localMsg].filter(Boolean).join(" | ");
|
|
128
142
|
}
|
|
129
143
|
function buildDetails(err) {
|
|
130
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
131
144
|
const cfg = err.config;
|
|
132
|
-
let body = cfg
|
|
145
|
+
let body = cfg?.data;
|
|
133
146
|
if (typeof body === "string") {
|
|
134
147
|
try {
|
|
135
148
|
body = JSON.parse(body);
|
|
136
149
|
} catch {
|
|
137
150
|
}
|
|
138
151
|
}
|
|
139
|
-
const baseURL = cfg
|
|
140
|
-
const url =
|
|
141
|
-
const requestId =
|
|
152
|
+
const baseURL = cfg?.baseURL;
|
|
153
|
+
const url = cfg?.url ? baseURL ? `${baseURL}${cfg.url}` : cfg.url : void 0;
|
|
154
|
+
const requestId = err.response?.headers?.["x-request-id"] || err.response?.data?.status?.requestId;
|
|
142
155
|
return {
|
|
143
156
|
// error 基础信息(保证不会被 stringify 成 {})
|
|
144
157
|
name: n(err.name),
|
|
@@ -146,29 +159,28 @@ function buildDetails(err) {
|
|
|
146
159
|
code: n(err.code),
|
|
147
160
|
stack: n(err.stack),
|
|
148
161
|
// request 信息
|
|
149
|
-
method: n(toUpperMethod(cfg
|
|
162
|
+
method: n(toUpperMethod(cfg?.method)),
|
|
150
163
|
baseURL: n(baseURL),
|
|
151
164
|
url: n(url),
|
|
152
|
-
timeout: n(cfg
|
|
153
|
-
withCredentials: n(cfg
|
|
154
|
-
params: n(cfg
|
|
165
|
+
timeout: n(cfg?.timeout),
|
|
166
|
+
withCredentials: n(cfg?.withCredentials),
|
|
167
|
+
params: n(cfg?.params),
|
|
155
168
|
data: n(body),
|
|
156
169
|
// response 信息
|
|
157
|
-
status: n(
|
|
158
|
-
statusText: n(
|
|
170
|
+
status: n(err.response?.status),
|
|
171
|
+
statusText: n(err.response?.statusText),
|
|
159
172
|
requestId: n(requestId),
|
|
160
|
-
responseDataType: n(getTypeName(
|
|
161
|
-
responseData: n(safeResponseData(
|
|
173
|
+
responseDataType: n(getTypeName(err.response?.data)),
|
|
174
|
+
responseData: n(safeResponseData(err.response?.data))
|
|
162
175
|
};
|
|
163
176
|
}
|
|
164
177
|
function errorInterceptor(error) {
|
|
165
|
-
var _a, _b, _c;
|
|
166
178
|
const err = isAxiosError(error) ? error : new AxiosError(String(error));
|
|
167
179
|
const isTimeout = err.code === "ECONNABORTED" || /timeout/i.test(err.message || "");
|
|
168
180
|
if (isTimeout) {
|
|
169
|
-
const method = toUpperMethod(
|
|
170
|
-
const baseURL =
|
|
171
|
-
const url =
|
|
181
|
+
const method = toUpperMethod(err.config?.method);
|
|
182
|
+
const baseURL = err.config?.baseURL || "";
|
|
183
|
+
const url = err.config?.url ? `${baseURL || ""}${err.config.url}` : "";
|
|
172
184
|
const summary = [`TIMEOUT`, method, url].filter(Boolean).join(" | ");
|
|
173
185
|
err.summary = summary;
|
|
174
186
|
err.details = buildDetails(err);
|
|
@@ -182,7 +194,6 @@ function errorInterceptor(error) {
|
|
|
182
194
|
return Promise.reject(err);
|
|
183
195
|
}
|
|
184
196
|
function ResponseInterceptor(response) {
|
|
185
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
186
197
|
const config = response.config;
|
|
187
198
|
if (config.returnFullResponse) {
|
|
188
199
|
return response;
|
|
@@ -194,27 +205,26 @@ function ResponseInterceptor(response) {
|
|
|
194
205
|
return response;
|
|
195
206
|
}
|
|
196
207
|
if (response.status === 200) {
|
|
197
|
-
if (
|
|
208
|
+
if (response.headers["content-type"]?.includes("text/event-stream")) {
|
|
198
209
|
return response;
|
|
199
210
|
}
|
|
200
211
|
const data = response.data;
|
|
201
212
|
const businessStatus = data.status;
|
|
202
213
|
if (businessStatus && typeof businessStatus.code === "number" && ![0, 200].includes(businessStatus.code) && businessStatus.code !== 401) {
|
|
203
214
|
const err = new AxiosError(
|
|
204
|
-
|
|
215
|
+
businessStatus?.msg || "Business error",
|
|
205
216
|
String(businessStatus.code),
|
|
206
217
|
response.config,
|
|
207
218
|
response.request,
|
|
208
219
|
response
|
|
209
220
|
);
|
|
210
|
-
const summary = `BIZ ${businessStatus.code} | ${
|
|
221
|
+
const summary = `BIZ ${businessStatus.code} | ${response.config?.method?.toUpperCase()} | ${response.config?.baseURL || ""}${response.config?.url || ""} | server: ${businessStatus?.msg}`;
|
|
211
222
|
const details = {
|
|
212
|
-
method:
|
|
213
|
-
url:
|
|
214
|
-
params:
|
|
223
|
+
method: response.config?.method?.toUpperCase(),
|
|
224
|
+
url: response.config?.baseURL ? `${response.config.baseURL}${response.config.url || ""}` : response.config.url,
|
|
225
|
+
params: response.config?.params,
|
|
215
226
|
data: (() => {
|
|
216
|
-
|
|
217
|
-
let d = (_a2 = response.config) == null ? void 0 : _a2.data;
|
|
227
|
+
let d = response.config?.data;
|
|
218
228
|
if (typeof d === "string") {
|
|
219
229
|
try {
|
|
220
230
|
d = JSON.parse(d);
|
|
@@ -225,7 +235,7 @@ function ResponseInterceptor(response) {
|
|
|
225
235
|
})(),
|
|
226
236
|
status: response.status,
|
|
227
237
|
statusText: response.statusText,
|
|
228
|
-
requestId:
|
|
238
|
+
requestId: response.headers?.["x-request-id"] || businessStatus?.requestId,
|
|
229
239
|
responseData: data
|
|
230
240
|
};
|
|
231
241
|
if (process.env.NODE_ENV !== "development") {
|
|
@@ -237,6 +247,15 @@ function ResponseInterceptor(response) {
|
|
|
237
247
|
}
|
|
238
248
|
return response;
|
|
239
249
|
}
|
|
250
|
+
function setAuthHeader(config, accessToken) {
|
|
251
|
+
const value = `Bearer ${accessToken}`;
|
|
252
|
+
const h = config.headers;
|
|
253
|
+
if (h?.set && typeof h.set === "function") {
|
|
254
|
+
h.set("Authorization", value);
|
|
255
|
+
} else {
|
|
256
|
+
h.Authorization = value;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
240
259
|
let refreshPromise = null;
|
|
241
260
|
const axiosInstance$1 = axios.create({
|
|
242
261
|
baseURL: process.env.AUTH_INNER_API_URL || process.env.NEXT_PUBLIC_AUTH_URL,
|
|
@@ -248,7 +267,7 @@ const axiosInstance$1 = axios.create({
|
|
|
248
267
|
}
|
|
249
268
|
});
|
|
250
269
|
async function refreshToken(config) {
|
|
251
|
-
if (
|
|
270
|
+
if (isServerRuntime()) {
|
|
252
271
|
return config;
|
|
253
272
|
}
|
|
254
273
|
if (typeof config.url === "string" && config.url.includes("/api/refresh/token")) {
|
|
@@ -257,6 +276,10 @@ async function refreshToken(config) {
|
|
|
257
276
|
const headers = config.headers;
|
|
258
277
|
if (refreshPromise) {
|
|
259
278
|
await refreshPromise;
|
|
279
|
+
const accessAfterWait = Cookies.get("access_token") || getToken("access_token");
|
|
280
|
+
if (accessAfterWait) {
|
|
281
|
+
setAuthHeader(config, accessAfterWait);
|
|
282
|
+
}
|
|
260
283
|
return config;
|
|
261
284
|
}
|
|
262
285
|
let expired = false;
|
|
@@ -273,6 +296,10 @@ async function refreshToken(config) {
|
|
|
273
296
|
}
|
|
274
297
|
if (refreshPromise) {
|
|
275
298
|
await refreshPromise;
|
|
299
|
+
const accessAfterWait = Cookies.get("access_token") || getToken("access_token");
|
|
300
|
+
if (accessAfterWait) {
|
|
301
|
+
setAuthHeader(config, accessAfterWait);
|
|
302
|
+
}
|
|
276
303
|
return config;
|
|
277
304
|
}
|
|
278
305
|
const refreshHeaders = { ...headers };
|
|
@@ -288,8 +315,8 @@ async function refreshToken(config) {
|
|
|
288
315
|
...refreshHeaders
|
|
289
316
|
}
|
|
290
317
|
}).then((res) => {
|
|
291
|
-
|
|
292
|
-
|
|
318
|
+
if (res?.data?.data) {
|
|
319
|
+
setToken(res.data.data);
|
|
293
320
|
return res.data.data;
|
|
294
321
|
} else {
|
|
295
322
|
removeAllToken();
|
|
@@ -302,6 +329,10 @@ async function refreshToken(config) {
|
|
|
302
329
|
refreshPromise = null;
|
|
303
330
|
});
|
|
304
331
|
await refreshPromise;
|
|
332
|
+
const accessAfterRefresh = Cookies.get("access_token") || getToken("access_token");
|
|
333
|
+
if (accessAfterRefresh) {
|
|
334
|
+
setAuthHeader(config, accessAfterRefresh);
|
|
335
|
+
}
|
|
305
336
|
}
|
|
306
337
|
return config;
|
|
307
338
|
}
|
|
@@ -321,5 +352,6 @@ axiosInstance.interceptors.request.use(refreshToken);
|
|
|
321
352
|
axiosInstance.interceptors.request.use(commonHeader, errorInterceptor);
|
|
322
353
|
axiosInstance.interceptors.response.use(ResponseInterceptor, errorInterceptor);
|
|
323
354
|
export {
|
|
324
|
-
axiosInstance as default
|
|
355
|
+
axiosInstance as default,
|
|
356
|
+
setServerHeaderProvider
|
|
325
357
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import { ServerHeaderProvider } from '../types';
|
|
3
|
+
export declare function setServerHeaderProvider(provider: ServerHeaderProvider): void;
|
|
2
4
|
export declare function commonHeader(config: InternalAxiosRequestConfig): Promise<InternalAxiosRequestConfig<any>>;
|
|
3
5
|
//# sourceMappingURL=commonHeader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commonHeader.d.ts","sourceRoot":"","sources":["../../src/interceptors/commonHeader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,0BAA0B,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"commonHeader.d.ts","sourceRoot":"","sources":["../../src/interceptors/commonHeader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,0BAA0B,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAQrD,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,oBAAoB,QAErE;AAyBD,wBAAsB,YAAY,CAChC,MAAM,EAAE,0BAA0B,4CAwDnC"}
|
|
@@ -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;AAwB5E,wBAA8B,YAAY,CACxC,MAAM,EAAE,0BAA0B,4CAkFnC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断是否处于“服务端运行时”。
|
|
3
|
+
*
|
|
4
|
+
* 关键点:只要存在真实浏览器 window,就一律视为客户端,
|
|
5
|
+
* 避免业务方在客户端 bundle 中固化 IS_SERVER=true 时被误判为服务端,
|
|
6
|
+
* 从而走 next/headers 读 cookie 失败、请求不带 Authorization。
|
|
7
|
+
*/
|
|
8
|
+
export declare function isServerRuntime(): boolean;
|
|
9
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAKzC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
export interface ServerHeaderProvider {
|
|
3
|
+
getAccessToken(): Promise<string | undefined>;
|
|
4
|
+
getLanguage(): Promise<string | undefined>;
|
|
5
|
+
}
|
|
2
6
|
export interface ApiRequestConfig extends AxiosRequestConfig {
|
|
3
7
|
withCredentials?: boolean;
|
|
4
8
|
returnFullResponse?: boolean;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3C,MAAM,WAAW,gBAAiB,SAAQ,kBAAkB;IAC1D,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACzB;AAED;;EAEE;AACF,MAAM,WAAW,MAAM;IACrB,IAAI,E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M,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACzB"}
|
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.61",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -17,17 +17,28 @@
|
|
|
17
17
|
"dist",
|
|
18
18
|
"!**/*.tsbuildinfo"
|
|
19
19
|
],
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"axios": "1.13.2",
|
|
22
|
+
"js-cookie": "3.0.5",
|
|
23
|
+
"next": "16.1.6",
|
|
24
|
+
"qs": "6.14.0"
|
|
25
|
+
},
|
|
20
26
|
"devDependencies": {
|
|
21
27
|
"@types/js-cookie": "3.0.6",
|
|
22
|
-
"@types/qs": "6.14.0"
|
|
23
|
-
},
|
|
24
|
-
"dependencies": {
|
|
28
|
+
"@types/qs": "6.14.0",
|
|
25
29
|
"axios": "1.13.2",
|
|
26
30
|
"js-cookie": "3.0.5",
|
|
27
|
-
"next": "
|
|
28
|
-
"qs": "6.14.0"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
"next": "16.1.6",
|
|
32
|
+
"qs": "6.14.0"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@0xchain/logger": "1.1.0-beta.61",
|
|
36
|
+
"@0xchain/token": "1.1.0-beta.61"
|
|
37
|
+
},
|
|
38
|
+
"nx": {
|
|
39
|
+
"tags": [
|
|
40
|
+
"type:util"
|
|
41
|
+
]
|
|
31
42
|
},
|
|
32
43
|
"publishConfig": {
|
|
33
44
|
"access": "public"
|