@0xchain/request 0.0.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/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # request
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ 一个基于 Axios 的 HTTP 请求库,提供了统一的请求拦截器和响应处理。
6
+
7
+ ## 功能特性
8
+
9
+ - 基于 Axios 的 HTTP 客户端
10
+ - 自动添加通用请求头
11
+ - 统一的错误处理
12
+ - 支持返回完整响应对象(包含 headers 信息)
13
+
14
+ ## 使用方法
15
+
16
+ ### 基本用法
17
+
18
+ ```typescript
19
+ import axiosInstance from '@0xchain/request';
20
+
21
+ // 普通请求,返回 response.data
22
+ const data = await axiosInstance.get('/api/users');
23
+ console.log(data); // 直接是响应数据
24
+ ```
25
+
26
+ ### 获取完整响应对象
27
+
28
+ 当你需要访问响应头信息时,可以使用 `returnFullResponse` 选项:
29
+
30
+ ```typescript
31
+ import axiosInstance from '@0xchain/request';
32
+ import { ApiRequestConfig } from '@0xchain/request/types';
33
+
34
+ const config: ApiRequestConfig = {
35
+ returnFullResponse: true // 返回完整的 response 对象
36
+ };
37
+
38
+ const response = await axiosInstance.get('/api/users', config);
39
+
40
+ // 现在可以访问完整的响应信息
41
+ console.log('状态码:', response.status);
42
+ console.log('响应头:', response.headers);
43
+ console.log('响应数据:', response.data);
44
+
45
+ // 读取特定的 header 信息
46
+ const contentType = response.headers['content-type'];
47
+ const customHeader = response.headers['x-custom-header'];
48
+ ```
49
+
50
+ ### POST 请求示例
51
+
52
+ ```typescript
53
+ const config: ApiRequestConfig = {
54
+ returnFullResponse: true,
55
+ headers: {
56
+ 'Content-Type': 'application/json'
57
+ }
58
+ };
59
+
60
+ const response = await axiosInstance.post('/api/users', {
61
+ name: 'John Doe',
62
+ email: 'john@example.com'
63
+ }, config);
64
+
65
+ if (response.status === 201) {
66
+ console.log('用户创建成功');
67
+ console.log('Location header:', response.headers['location']);
68
+ }
69
+ ```
70
+
71
+ ## API 配置选项
72
+
73
+ ### ApiRequestConfig
74
+
75
+ 继承自 Axios 的 `AxiosRequestConfig`,并添加了以下选项:
76
+
77
+ - `withCredentials?: boolean` - 是否包含凭据
78
+ - `returnFullResponse?: boolean` - 是否返回完整的响应对象(默认为 false)
79
+
80
+ 当 `returnFullResponse` 为 `true` 时,请求将返回完整的 Axios 响应对象,包含:
81
+ - `data` - 响应数据
82
+ - `status` - HTTP 状态码
83
+ - `statusText` - HTTP 状态文本
84
+ - `headers` - 响应头信息
85
+ - `config` - 请求配置
86
+
87
+ ## Building
88
+
89
+ Run `nx build request` to build the library.
90
+
91
+ ## Running unit tests
92
+
93
+ Run `nx test request` to execute the unit tests via [Vitest](https://vitest.dev/).
94
+
95
+ ## 更多示例
96
+
97
+ 查看 `example.ts` 文件获取更多使用示例。
@@ -0,0 +1,4 @@
1
+ const __viteBrowserExternal = {};
2
+ export {
3
+ __viteBrowserExternal as default
4
+ };
@@ -0,0 +1,15 @@
1
+ import { AxiosError } from 'axios';
2
+ export interface ApiResponse<T> {
3
+ status: {
4
+ code: number;
5
+ msg: string;
6
+ };
7
+ data: T;
8
+ }
9
+ export interface ApiError extends AxiosError {
10
+ need?: boolean;
11
+ }
12
+ declare const axiosInstance: import('axios').AxiosInstance;
13
+ export default axiosInstance;
14
+ export type { ApiRequestConfig, Pagination, Status, IResponse, IFilters, IPageRequest, } from './types';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
package/dist/index.js ADDED
@@ -0,0 +1,325 @@
1
+ import axios, { isAxiosError, AxiosError } from "axios";
2
+ import qs from "qs";
3
+ import jsCookie from "js-cookie";
4
+ import { logger } from "@0xchain/logger";
5
+ import TokenManager, { isTokenExpired, getToken, removeAllToken } from "@0xchain/token";
6
+ const isSimplifiedChinese = () => {
7
+ return /^(zh-hans|zh-cn|zh-sg|zh-my)$/.test(window == null ? void 0 : window.navigator.language.toLowerCase());
8
+ };
9
+ const matchSystemLanguage = () => {
10
+ return isSimplifiedChinese() ? "zh-hans" : "";
11
+ };
12
+ let httpAgent;
13
+ let httpsAgent;
14
+ function isServerRuntime() {
15
+ return typeof window === "undefined" || process.env.IS_SERVER === "true";
16
+ }
17
+ function isEdgeRuntime() {
18
+ return process.env.NEXT_RUNTIME === "edge" || typeof globalThis.EdgeRuntime !== "undefined";
19
+ }
20
+ function isNodeRuntime() {
21
+ return typeof process !== "undefined" && !!(process.versions && process.versions.node) && !isEdgeRuntime();
22
+ }
23
+ function getHeader(config, key) {
24
+ const h = config.headers;
25
+ if ((h == null ? void 0 : h.get) && typeof h.get === "function") return h.get(key);
26
+ return h == null ? void 0 : h[key];
27
+ }
28
+ function setHeader(config, key, value) {
29
+ const h = config.headers;
30
+ if ((h == null ? void 0 : h.set) && typeof h.set === "function") {
31
+ h.set(key, value);
32
+ } else {
33
+ h[key] = value;
34
+ }
35
+ }
36
+ async function commonHeader(config) {
37
+ var _a, _b;
38
+ let access_token = "";
39
+ let language = "";
40
+ if (isServerRuntime()) {
41
+ if (isNodeRuntime()) {
42
+ try {
43
+ const http = await import("http");
44
+ const https = await import("./__vite-browser-external-2Ng8QIWW.js");
45
+ const baseURL = config == null ? void 0 : config.baseURL;
46
+ const isHttps = typeof baseURL === "string" ? baseURL.startsWith("https://") : false;
47
+ if (!httpAgent && (http == null ? void 0 : http.Agent)) httpAgent = new http.Agent({ keepAlive: true });
48
+ if (!httpsAgent && (https == null ? void 0 : https.Agent)) httpsAgent = new https.Agent({ keepAlive: true });
49
+ config.httpAgent = isHttps ? void 0 : httpAgent;
50
+ config.httpsAgent = isHttps ? httpsAgent : void 0;
51
+ } catch {
52
+ }
53
+ }
54
+ try {
55
+ const startLanguage = getHeader(config, "Accept-Language");
56
+ setHeader(config, "x-whistle-nohost-env", process.env.NO_HOST_ENV || "ichaingo");
57
+ const { cookies, headers } = await import("next/headers");
58
+ const cookieStore = await cookies();
59
+ access_token = ((_a = cookieStore.get("access_token")) == null ? void 0 : _a.value) || "";
60
+ const hList = await headers();
61
+ language = startLanguage || hList.get("x-next-intl-locale") || "en";
62
+ } catch (error) {
63
+ console.error("Error accessing cookies in server component:", error);
64
+ }
65
+ } else {
66
+ access_token = jsCookie.get("access_token") || "";
67
+ language = jsCookie.get("NEXT_LOCALE") || matchSystemLanguage() || "en";
68
+ }
69
+ const isRefreshToken = (_b = config.headers) == null ? void 0 : _b["isRefreshToken"];
70
+ setHeader(config, "Accept-Language", language);
71
+ if (access_token && !isRefreshToken) {
72
+ setHeader(config, "Authorization", `Bearer ${access_token}`);
73
+ }
74
+ setHeader(config, "devicetype", 1);
75
+ return config;
76
+ }
77
+ function toUpperMethod(m) {
78
+ return m ? m.toUpperCase() : void 0;
79
+ }
80
+ function getTypeName(v) {
81
+ var _a;
82
+ if (v === null) return "null";
83
+ if (v === void 0) return "undefined";
84
+ const t = typeof v;
85
+ if (t !== "object") return t;
86
+ try {
87
+ return ((_a = v == null ? void 0 : v.constructor) == null ? void 0 : _a.name) || "object";
88
+ } catch {
89
+ return "object";
90
+ }
91
+ }
92
+ function truncateString(s, max = 2e3) {
93
+ if (s.length <= max) return s;
94
+ return `${s.slice(0, max)}...[truncated,len=${s.length}]`;
95
+ }
96
+ function safeResponseData(data) {
97
+ const typeName = getTypeName(data);
98
+ if (typeof data === "string") return truncateString(data);
99
+ if (typeName === "Blob" || typeName === "FormData" || typeName === "ArrayBuffer") {
100
+ return `[${typeName}]`;
101
+ }
102
+ return data;
103
+ }
104
+ function n(v) {
105
+ return v === void 0 ? null : v;
106
+ }
107
+ function buildErrorMessage(err) {
108
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
109
+ const method = toUpperMethod((_a = err.config) == null ? void 0 : _a.method);
110
+ const baseURL = ((_b = err.config) == null ? void 0 : _b.baseURL) || "";
111
+ const url = ((_c = err.config) == null ? void 0 : _c.url) ? `${baseURL || ""}${err.config.url}` : "";
112
+ const status = (_d = err.response) == null ? void 0 : _d.status;
113
+ const statusText = (_e = err.response) == null ? void 0 : _e.statusText;
114
+ const respData = (_f = err.response) == null ? void 0 : _f.data;
115
+ const requestId = ((_h = (_g = err.response) == null ? void 0 : _g.headers) == null ? void 0 : _h["x-request-id"]) || ((_i = respData == null ? void 0 : respData.status) == null ? void 0 : _i.requestId);
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);
117
+ const summary = [
118
+ status ? `HTTP ${status}` : "HTTP ERROR",
119
+ method,
120
+ url,
121
+ statusText
122
+ ].filter(Boolean).join(" | ");
123
+ const shortMsg = serverMsg ? `server: ${serverMsg}` : void 0;
124
+ const ridMsg = requestId ? `requestId=${requestId}` : void 0;
125
+ const codeMsg = err.code ? `code=${err.code}` : void 0;
126
+ const localMsg = !status && err.message ? `msg=${err.message}` : void 0;
127
+ return [summary, shortMsg, ridMsg, codeMsg, localMsg].filter(Boolean).join(" | ");
128
+ }
129
+ function buildDetails(err) {
130
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
131
+ const cfg = err.config;
132
+ let body = cfg == null ? void 0 : cfg.data;
133
+ if (typeof body === "string") {
134
+ try {
135
+ body = JSON.parse(body);
136
+ } catch {
137
+ }
138
+ }
139
+ const baseURL = cfg == null ? void 0 : cfg.baseURL;
140
+ const url = (cfg == null ? void 0 : cfg.url) ? baseURL ? `${baseURL}${cfg.url}` : cfg.url : void 0;
141
+ const requestId = ((_b = (_a = err.response) == null ? void 0 : _a.headers) == null ? void 0 : _b["x-request-id"]) || ((_e = (_d = (_c = err.response) == null ? void 0 : _c.data) == null ? void 0 : _d.status) == null ? void 0 : _e.requestId);
142
+ return {
143
+ // error 基础信息(保证不会被 stringify 成 {})
144
+ name: n(err.name),
145
+ message: n(err.message),
146
+ code: n(err.code),
147
+ stack: n(err.stack),
148
+ // request 信息
149
+ method: n(toUpperMethod(cfg == null ? void 0 : cfg.method)),
150
+ baseURL: n(baseURL),
151
+ url: n(url),
152
+ timeout: n(cfg == null ? void 0 : cfg.timeout),
153
+ withCredentials: n(cfg == null ? void 0 : cfg.withCredentials),
154
+ params: n(cfg == null ? void 0 : cfg.params),
155
+ data: n(body),
156
+ // response 信息
157
+ status: n((_f = err.response) == null ? void 0 : _f.status),
158
+ statusText: n((_g = err.response) == null ? void 0 : _g.statusText),
159
+ requestId: n(requestId),
160
+ responseDataType: n(getTypeName((_h = err.response) == null ? void 0 : _h.data)),
161
+ responseData: n(safeResponseData((_i = err.response) == null ? void 0 : _i.data))
162
+ };
163
+ }
164
+ function errorInterceptor(error) {
165
+ var _a, _b, _c;
166
+ const err = isAxiosError(error) ? error : new AxiosError(String(error));
167
+ const isTimeout = err.code === "ECONNABORTED" || /timeout/i.test(err.message || "");
168
+ if (isTimeout) {
169
+ const method = toUpperMethod((_a = err.config) == null ? void 0 : _a.method);
170
+ const baseURL = ((_b = err.config) == null ? void 0 : _b.baseURL) || "";
171
+ const url = ((_c = err.config) == null ? void 0 : _c.url) ? `${baseURL || ""}${err.config.url}` : "";
172
+ const summary = [`TIMEOUT`, method, url].filter(Boolean).join(" | ");
173
+ err.summary = summary;
174
+ err.details = buildDetails(err);
175
+ logger.error({ message: summary, details: err.details, errType: "timeout" });
176
+ return Promise.reject(err);
177
+ }
178
+ const message = buildErrorMessage(err);
179
+ err.summary = message;
180
+ err.details = buildDetails(err);
181
+ logger.error({ message, details: err.details, errType: "server error" });
182
+ return Promise.reject(err);
183
+ }
184
+ function ResponseInterceptor(response) {
185
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
186
+ const config = response.config;
187
+ if (config.returnFullResponse) {
188
+ return response;
189
+ }
190
+ if (response.status === 401) {
191
+ if (typeof window !== "undefined") {
192
+ TokenManager.removeAllToken();
193
+ }
194
+ return response;
195
+ }
196
+ if (response.status === 200) {
197
+ if ((_a = response.headers["content-type"]) == null ? void 0 : _a.includes("text/event-stream")) {
198
+ return response;
199
+ }
200
+ const data = response.data;
201
+ const businessStatus = data.status;
202
+ if (businessStatus && typeof businessStatus.code === "number" && ![0, 200].includes(businessStatus.code) && businessStatus.code !== 401) {
203
+ const err = new AxiosError(
204
+ (businessStatus == null ? void 0 : businessStatus.msg) || "Business error",
205
+ String(businessStatus.code),
206
+ response.config,
207
+ response.request,
208
+ response
209
+ );
210
+ const summary = `BIZ ${businessStatus.code} | ${(_c = (_b = response.config) == null ? void 0 : _b.method) == null ? void 0 : _c.toUpperCase()} | ${((_d = response.config) == null ? void 0 : _d.baseURL) || ""}${((_e = response.config) == null ? void 0 : _e.url) || ""} | server: ${businessStatus == null ? void 0 : businessStatus.msg}`;
211
+ const details = {
212
+ method: (_g = (_f = response.config) == null ? void 0 : _f.method) == null ? void 0 : _g.toUpperCase(),
213
+ url: ((_h = response.config) == null ? void 0 : _h.baseURL) ? `${response.config.baseURL}${response.config.url || ""}` : response.config.url,
214
+ params: (_i = response.config) == null ? void 0 : _i.params,
215
+ data: (() => {
216
+ var _a2;
217
+ let d = (_a2 = response.config) == null ? void 0 : _a2.data;
218
+ if (typeof d === "string") {
219
+ try {
220
+ d = JSON.parse(d);
221
+ } catch {
222
+ }
223
+ }
224
+ return d;
225
+ })(),
226
+ status: response.status,
227
+ statusText: response.statusText,
228
+ requestId: ((_j = response.headers) == null ? void 0 : _j["x-request-id"]) || (businessStatus == null ? void 0 : businessStatus.requestId),
229
+ responseData: data
230
+ };
231
+ if (process.env.NODE_ENV !== "development") {
232
+ logger.error({ summary, details, errType: "business error" });
233
+ }
234
+ throw err;
235
+ }
236
+ return data;
237
+ }
238
+ return response;
239
+ }
240
+ let refreshPromise = null;
241
+ const axiosInstance$1 = axios.create({
242
+ baseURL: process.env.AUTH_INNER_API_URL || process.env.NEXT_PUBLIC_AUTH_URL,
243
+ timeout: 1e4,
244
+ withCredentials: true,
245
+ // Always include credentials by default
246
+ paramsSerializer: function(params) {
247
+ return qs.stringify(params, { arrayFormat: "brackets" });
248
+ }
249
+ });
250
+ async function refreshToken(config) {
251
+ if (typeof window === "undefined" || process.env.IS_SERVER === "true") {
252
+ return config;
253
+ }
254
+ if (typeof config.url === "string" && config.url.includes("/api/refresh/token")) {
255
+ return config;
256
+ }
257
+ const headers = config.headers;
258
+ if (refreshPromise) {
259
+ await refreshPromise;
260
+ return config;
261
+ }
262
+ let expired = false;
263
+ try {
264
+ expired = await isTokenExpired();
265
+ } catch {
266
+ expired = false;
267
+ }
268
+ if (expired) {
269
+ const refresh_token = getToken("refresh_token");
270
+ if (!refresh_token) {
271
+ removeAllToken();
272
+ return config;
273
+ }
274
+ if (refreshPromise) {
275
+ await refreshPromise;
276
+ return config;
277
+ }
278
+ const refreshHeaders = { ...headers };
279
+ delete refreshHeaders.Authorization;
280
+ delete refreshHeaders.authorization;
281
+ refreshHeaders.isRefreshToken = true;
282
+ refreshPromise = axiosInstance$1.get(`/api/refresh/token`, {
283
+ params: {
284
+ grant_type: "refresh_token",
285
+ refresh_token
286
+ },
287
+ headers: {
288
+ ...refreshHeaders
289
+ }
290
+ }).then((res) => {
291
+ var _a;
292
+ if ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.data) {
293
+ return res.data.data;
294
+ } else {
295
+ removeAllToken();
296
+ return null;
297
+ }
298
+ }).catch(() => {
299
+ removeAllToken();
300
+ return null;
301
+ }).finally(() => {
302
+ refreshPromise = null;
303
+ });
304
+ await refreshPromise;
305
+ }
306
+ return config;
307
+ }
308
+ const axiosInstance = axios.create({
309
+ baseURL: process.env.INNER_API_URL || process.env.NEXT_PUBLIC_API_URL,
310
+ timeout: Number(process.env.NEXT_PUBLIC_REQUEST_TIMEOUT_MS) || 1e4,
311
+ withCredentials: true,
312
+ // Always include credentials by default
313
+ // Treat HTTP 401 as a non-error response so it goes through responseInterceptor.
314
+ // This allows callers to handle 401 via the returned AxiosResponse instead of catch().
315
+ validateStatus: (status) => status >= 200 && status < 300 || status === 401,
316
+ paramsSerializer: function(params) {
317
+ return qs.stringify(params, { arrayFormat: "brackets" });
318
+ }
319
+ });
320
+ axiosInstance.interceptors.request.use(refreshToken);
321
+ axiosInstance.interceptors.request.use(commonHeader, errorInterceptor);
322
+ axiosInstance.interceptors.response.use(ResponseInterceptor, errorInterceptor);
323
+ export {
324
+ axiosInstance as default
325
+ };
@@ -0,0 +1,3 @@
1
+ import { InternalAxiosRequestConfig } from 'axios';
2
+ export declare function commonHeader(config: InternalAxiosRequestConfig): Promise<InternalAxiosRequestConfig<any>>;
3
+ //# sourceMappingURL=commonHeader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commonHeader.d.ts","sourceRoot":"","sources":["../../src/interceptors/commonHeader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,0BAA0B,EAAE,MAAM,OAAO,CAAC;AAiCrE,wBAAsB,YAAY,CAChC,MAAM,EAAE,0BAA0B,4CA+CnC"}
@@ -0,0 +1,3 @@
1
+ import { AxiosError } from 'axios';
2
+ export declare function errorInterceptor(error: AxiosError): Promise<never>;
3
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/interceptors/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4C,MAAM,OAAO,CAAC;AA8G7E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,kBA2BjD"}
@@ -0,0 +1,3 @@
1
+ import { InternalAxiosRequestConfig } from 'axios';
2
+ export default function refreshToken(config: InternalAxiosRequestConfig): Promise<InternalAxiosRequestConfig<any>>;
3
+ //# sourceMappingURL=refreshToken.d.ts.map
@@ -0,0 +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,4CAqEnC"}
@@ -0,0 +1,3 @@
1
+ import { AxiosResponse } from 'axios';
2
+ export default function ResponseInterceptor(response: AxiosResponse): any;
3
+ //# sourceMappingURL=response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/interceptors/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,aAAa,EAAE,MAAM,OAAO,CAAC;AAKlD,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,QAAQ,EAAE,aAAa,GAAG,GAAG,CAuDxE"}
@@ -0,0 +1,17 @@
1
+ import { AxiosRequestConfig, AxiosError } from 'axios';
2
+ export interface ApiRequestConfig extends AxiosRequestConfig {
3
+ withCredentials?: boolean;
4
+ }
5
+ export interface ApiResponse<T> {
6
+ status: {
7
+ code: number;
8
+ msg: string;
9
+ };
10
+ data: T;
11
+ }
12
+ export interface ApiError extends AxiosError {
13
+ need?: boolean;
14
+ }
15
+ declare const axiosInstance: import('axios').AxiosInstance;
16
+ export default axiosInstance;
17
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/lib/request.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,kBAAkB,EAAE,KAAK,UAAU,EAAE,MAAM,OAAO,CAAC;AAMxE,MAAM,WAAW,gBAAiB,SAAQ,kBAAkB;IAC1D,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,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,+BASjB,CAAC;AAYH,eAAe,aAAa,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ export interface ApiRequestConfig extends AxiosRequestConfig {
3
+ withCredentials?: boolean;
4
+ returnFullResponse?: boolean;
5
+ }
6
+ export interface Pagination {
7
+ hasMore?: boolean;
8
+ limit: number;
9
+ page: number;
10
+ snapshotTime: number;
11
+ totalCount: number;
12
+ [property: string]: any;
13
+ }
14
+ /**
15
+ * Status
16
+ */
17
+ export interface Status {
18
+ code: number;
19
+ creditCount: number;
20
+ msg: string;
21
+ requestId: string;
22
+ [property: string]: any;
23
+ }
24
+ /**
25
+ * 后端接口返回的格式
26
+ */
27
+ export interface IResponse<T> {
28
+ data: T;
29
+ pagination?: null | Pagination;
30
+ status: Status;
31
+ [property: string]: any;
32
+ }
33
+ /**
34
+ * 过滤条件
35
+ */
36
+ export interface IFilters {
37
+ /**
38
+ * 最大数量
39
+ */
40
+ maxAmount?: number;
41
+ /**
42
+ * 最大价值
43
+ */
44
+ maxValue?: number;
45
+ /**
46
+ * 最小数量
47
+ */
48
+ minAmount?: number;
49
+ /**
50
+ * 最小价值
51
+ */
52
+ minValue?: number;
53
+ /**
54
+ * token列表
55
+ */
56
+ tokenList?: string[];
57
+ [property: string]: any;
58
+ }
59
+ /**
60
+ * 分页请求
61
+ */
62
+ export interface IPageRequest {
63
+ /**
64
+ * 过滤条件
65
+ */
66
+ filters?: IFilters;
67
+ limit: number;
68
+ page: number;
69
+ /**
70
+ * 秒级时间戳
71
+ */
72
+ snapshotTime?: number;
73
+ [property: string]: any;
74
+ }
75
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACzB;AACD;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,IAAI,EAAE,CAAC,CAAC;IACR,UAAU,CAAC,EAAE,IAAI,GAAG,UAAU,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACzB;AAED;;EAEE;AACF,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACzB;AACD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACzB"}
@@ -0,0 +1,3 @@
1
+ export declare const isSimplifiedChinese: () => boolean;
2
+ export declare const matchSystemLanguage: () => "zh-hans" | "";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,eAE/B,CAAC;AAEF,eAAO,MAAM,mBAAmB,sBAE/B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@0xchain/request",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "!**/*.tsbuildinfo"
19
+ ],
20
+ "devDependencies": {
21
+ "@types/js-cookie": "3.0.6",
22
+ "@types/qs": "6.14.0"
23
+ },
24
+ "dependencies": {
25
+ "axios": "1.13.2",
26
+ "js-cookie": "3.0.5",
27
+ "next": "15.5.6",
28
+ "qs": "6.14.0",
29
+ "@0xchain/logger": "0.0.1",
30
+ "@0xchain/token": "0.0.1"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }