@noah-libjs/request 0.0.4
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/README.md +23 -0
- package/dist/Request.d.ts +43 -0
- package/dist/constant.d.ts +17 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +280 -0
- package/dist/types.d.ts +26 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Lam
|
|
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/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Rslib project
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
Install the dependencies:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Get started
|
|
12
|
+
|
|
13
|
+
Build the library:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm build
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Build the library in watch mode:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm dev
|
|
23
|
+
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
+
import { IRequest_ResponseError, IRequest_SpawnConfig, TRequest_PreReq, TRequest_SimpleReq } from './types';
|
|
3
|
+
import { EventEmitter, MyLog } from '@noah-libjs/utils';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export declare class Request extends EventEmitter<{
|
|
6
|
+
request: any;
|
|
7
|
+
response: any;
|
|
8
|
+
error: any;
|
|
9
|
+
message: [boolean, string, any];
|
|
10
|
+
}> {
|
|
11
|
+
ins: AxiosInstance;
|
|
12
|
+
token?: string;
|
|
13
|
+
constructor(config?: IRequest_SpawnConfig);
|
|
14
|
+
static CONFIG: {
|
|
15
|
+
successCode: number[];
|
|
16
|
+
};
|
|
17
|
+
static logger: MyLog;
|
|
18
|
+
static checkRTCode(res?: AxiosResponse<any>): boolean;
|
|
19
|
+
static genErrMsg(res?: AxiosResponse<any>, error?: AxiosError): string;
|
|
20
|
+
static createErr(res?: AxiosResponse<any>, error?: AxiosError): IRequest_ResponseError;
|
|
21
|
+
static getMsg(res?: AxiosResponse<{
|
|
22
|
+
data?: any;
|
|
23
|
+
code?: number;
|
|
24
|
+
msg?: string;
|
|
25
|
+
message?: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
}>): any;
|
|
28
|
+
static getRemoteMessage(res?: AxiosResponse<any>): any;
|
|
29
|
+
static getHeaderMessage(res?: AxiosResponse<any>): string | undefined;
|
|
30
|
+
displayMsg(res?: AxiosResponse<{
|
|
31
|
+
data?: any;
|
|
32
|
+
code?: number;
|
|
33
|
+
msg?: string;
|
|
34
|
+
}>): void;
|
|
35
|
+
config: IRequest_SpawnConfig;
|
|
36
|
+
spawn(spawnConfig?: IRequest_SpawnConfig): AxiosInstance;
|
|
37
|
+
gen(spawnConfig?: IRequest_SpawnConfig): AxiosInstance;
|
|
38
|
+
get: TRequest_SimpleReq;
|
|
39
|
+
delete: TRequest_SimpleReq;
|
|
40
|
+
head: TRequest_SimpleReq;
|
|
41
|
+
post: TRequest_PreReq;
|
|
42
|
+
put: TRequest_PreReq;
|
|
43
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const codeMessage: {
|
|
2
|
+
200: string;
|
|
3
|
+
201: string;
|
|
4
|
+
202: string;
|
|
5
|
+
204: string;
|
|
6
|
+
400: string;
|
|
7
|
+
401: string;
|
|
8
|
+
403: string;
|
|
9
|
+
404: string;
|
|
10
|
+
406: string;
|
|
11
|
+
410: string;
|
|
12
|
+
422: string;
|
|
13
|
+
500: string;
|
|
14
|
+
502: string;
|
|
15
|
+
503: string;
|
|
16
|
+
504: string;
|
|
17
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { Request } from './Request';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export { codeMessage } from './constant';
|
|
5
|
+
declare function createInstance(defaultConfig?: {}): AxiosInstance;
|
|
6
|
+
declare const request: Request;
|
|
7
|
+
export { Request, createInstance, request };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
4
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
5
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
7
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
8
|
+
import axios, { Axios } from 'axios';
|
|
9
|
+
import utils from 'axios/lib/utils';
|
|
10
|
+
import { MyLog, EventEmitter } from '@noah-libjs/utils';
|
|
11
|
+
import bind from 'axios/lib/helpers/bind';
|
|
12
|
+
var codeMessage = {
|
|
13
|
+
200: '服务器成功返回请求的数据。',
|
|
14
|
+
201: '新建或修改数据成功。',
|
|
15
|
+
202: '一个请求已经进入后台排队(异步任务)。',
|
|
16
|
+
204: '删除数据成功。',
|
|
17
|
+
400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
|
|
18
|
+
401: '用户没有权限(令牌、用户名、密码错误)。',
|
|
19
|
+
403: '用户得到授权,但是访问是被禁止的。',
|
|
20
|
+
404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
|
|
21
|
+
406: '请求的格式不可得。',
|
|
22
|
+
410: '请求的资源被永久删除,且不会再得到的。',
|
|
23
|
+
422: '当创建一个对象时,发生一个验证错误。',
|
|
24
|
+
500: '服务器发生错误,请检查服务器。',
|
|
25
|
+
502: '网关错误。',
|
|
26
|
+
503: '服务不可用,服务器暂时过载或维护。',
|
|
27
|
+
504: '网关超时。'
|
|
28
|
+
};
|
|
29
|
+
var Request = /*#__PURE__*/function (_EventEmitter) {
|
|
30
|
+
function Request() {
|
|
31
|
+
var _this;
|
|
32
|
+
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
33
|
+
_classCallCheck(this, Request);
|
|
34
|
+
_this = _callSuper(this, Request);
|
|
35
|
+
Object.defineProperty(_this, "ins", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: void 0
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(_this, "token", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: ''
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(_this, "config", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: {}
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(_this, "get", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: void 0
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(_this, "delete", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: void 0
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(_this, "head", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(_this, "post", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
writable: true,
|
|
75
|
+
value: void 0
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(_this, "put", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: void 0
|
|
82
|
+
});
|
|
83
|
+
_this.spawn(config);
|
|
84
|
+
return _this;
|
|
85
|
+
}
|
|
86
|
+
_inherits(Request, _EventEmitter);
|
|
87
|
+
return _createClass(Request, [{
|
|
88
|
+
key: "displayMsg",
|
|
89
|
+
value: function displayMsg(res) {
|
|
90
|
+
var isSuccessful = Request.checkRTCode(res);
|
|
91
|
+
var msg = Request.getMsg(res);
|
|
92
|
+
if (!msg) return;
|
|
93
|
+
this.emit('message', isSuccessful, msg, res);
|
|
94
|
+
// if (isSuccessful) {
|
|
95
|
+
// message.success(msg)
|
|
96
|
+
// } else {
|
|
97
|
+
// message.warning(msg)
|
|
98
|
+
// }
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "spawn",
|
|
102
|
+
value: function spawn() {
|
|
103
|
+
var spawnConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
104
|
+
var ins = this.gen(spawnConfig);
|
|
105
|
+
this.ins = ins;
|
|
106
|
+
this.config = spawnConfig;
|
|
107
|
+
utils.extend(this, Axios.prototype, this.ins);
|
|
108
|
+
return this.ins;
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
key: "gen",
|
|
112
|
+
value: function gen() {
|
|
113
|
+
var _this2 = this;
|
|
114
|
+
var spawnConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
115
|
+
var _spawnConfig$config = spawnConfig.config,
|
|
116
|
+
config = _spawnConfig$config === void 0 ? {} : _spawnConfig$config,
|
|
117
|
+
_spawnConfig$onReques = spawnConfig.onRequest,
|
|
118
|
+
onRequest = _spawnConfig$onReques === void 0 ? function (value) {
|
|
119
|
+
return value;
|
|
120
|
+
} : _spawnConfig$onReques,
|
|
121
|
+
_spawnConfig$onRespon = spawnConfig.onResponse,
|
|
122
|
+
onResponse = _spawnConfig$onRespon === void 0 ? function (value) {
|
|
123
|
+
return value;
|
|
124
|
+
} : _spawnConfig$onRespon,
|
|
125
|
+
_spawnConfig$onReject = spawnConfig.onRejected,
|
|
126
|
+
onRejected = _spawnConfig$onReject === void 0 ? function (error) {
|
|
127
|
+
return Promise.reject(error);
|
|
128
|
+
} : _spawnConfig$onReject;
|
|
129
|
+
var ins = axios.create(config);
|
|
130
|
+
var _onErr = function _onErr(e) {
|
|
131
|
+
_this2.emit('error', e);
|
|
132
|
+
config.logger && Request.logger.error(e);
|
|
133
|
+
return onRejected(e);
|
|
134
|
+
};
|
|
135
|
+
ins.interceptors.request.use(function (config) {
|
|
136
|
+
_this2.emit('request', config);
|
|
137
|
+
// TODO: remove
|
|
138
|
+
config.headers.Authorization = config.headers.Authorization || _this2.token || '';
|
|
139
|
+
// params.pathname = location.pathname
|
|
140
|
+
return onRequest(config);
|
|
141
|
+
});
|
|
142
|
+
ins.interceptors.response.use(function (response) {
|
|
143
|
+
var axiosConfig = response.config,
|
|
144
|
+
headers = response.headers;
|
|
145
|
+
var config = axiosConfig;
|
|
146
|
+
var url = config.url,
|
|
147
|
+
data = config.data,
|
|
148
|
+
params = config.params,
|
|
149
|
+
method = config.method,
|
|
150
|
+
logger = config.logger,
|
|
151
|
+
unboxing = config.unboxing;
|
|
152
|
+
_this2.displayMsg(response);
|
|
153
|
+
if (Request.checkRTCode(response)) {
|
|
154
|
+
logger && Request.logger.log({
|
|
155
|
+
url: url,
|
|
156
|
+
data: data,
|
|
157
|
+
params: params,
|
|
158
|
+
method: method
|
|
159
|
+
}, response.data);
|
|
160
|
+
_this2.emit('response', response);
|
|
161
|
+
var isSameOrigin = (url === null || url === void 0 ? void 0 : url.startsWith('http')) ? new URL(url).origin === location.origin : true;
|
|
162
|
+
if (isSameOrigin) {
|
|
163
|
+
var token = headers['Authorization'] || headers['authorization'];
|
|
164
|
+
_this2.token = token;
|
|
165
|
+
}
|
|
166
|
+
if (unboxing) {
|
|
167
|
+
response.data = doUnboxing(response.data);
|
|
168
|
+
}
|
|
169
|
+
return onResponse(response);
|
|
170
|
+
}
|
|
171
|
+
var e = Request.createErr(response);
|
|
172
|
+
return _onErr(e);
|
|
173
|
+
}, function (error) {
|
|
174
|
+
Request.logger.error('请求出错:', {
|
|
175
|
+
error: error
|
|
176
|
+
});
|
|
177
|
+
_this2.displayMsg(error.response);
|
|
178
|
+
var response = error === null || error === void 0 ? void 0 : error.response;
|
|
179
|
+
var e = Request.createErr(response, error);
|
|
180
|
+
return _onErr(e);
|
|
181
|
+
});
|
|
182
|
+
return ins;
|
|
183
|
+
}
|
|
184
|
+
}], [{
|
|
185
|
+
key: "checkRTCode",
|
|
186
|
+
value: function checkRTCode(res) {
|
|
187
|
+
var _a, _b, _c, _d;
|
|
188
|
+
if (!res) return false;
|
|
189
|
+
var headerCode = res.headers['lm-code'];
|
|
190
|
+
var rawCode = ((_a = res.data) === null || _a === void 0 ? void 0 : _a.id) ? 200 : (_b = res.data) === null || _b === void 0 ? void 0 : _b.code;
|
|
191
|
+
// 某些数据返回 status
|
|
192
|
+
var rawStatus = ((_c = res.data) === null || _c === void 0 ? void 0 : _c.id) ? 200 : (_d = res.data) === null || _d === void 0 ? void 0 : _d.status;
|
|
193
|
+
var _code = typeof rawCode === 'number' ? rawCode : rawStatus !== null && rawStatus !== void 0 ? rawStatus : 1;
|
|
194
|
+
var code = headerCode ? Number(headerCode) : _code;
|
|
195
|
+
// console.log('isSuccessful', { headerCode, _code,h:res.headers})
|
|
196
|
+
return Request.CONFIG.successCode.includes(code);
|
|
197
|
+
}
|
|
198
|
+
}, {
|
|
199
|
+
key: "genErrMsg",
|
|
200
|
+
value: function genErrMsg(res, error) {
|
|
201
|
+
var _a, _b, _c;
|
|
202
|
+
var status = (res === null || res === void 0 ? void 0 : res.status) || -1;
|
|
203
|
+
var rawMessage = (error === null || error === void 0 ? void 0 : error.message) === 'Network Error' ? '网络连接异常 ' : '';
|
|
204
|
+
var msg = (_c = (_b = (_a = Request.getMsg(res)) !== null && _a !== void 0 ? _a : codeMessage[status]) !== null && _b !== void 0 ? _b : rawMessage) !== null && _c !== void 0 ? _c : '未知错误';
|
|
205
|
+
return msg;
|
|
206
|
+
}
|
|
207
|
+
}, {
|
|
208
|
+
key: "createErr",
|
|
209
|
+
value: function createErr(res, error) {
|
|
210
|
+
var _a;
|
|
211
|
+
return {
|
|
212
|
+
error: error,
|
|
213
|
+
msg: Request.genErrMsg(res, error),
|
|
214
|
+
url: (_a = res === null || res === void 0 ? void 0 : res.config) === null || _a === void 0 ? void 0 : _a.url,
|
|
215
|
+
data: res === null || res === void 0 ? void 0 : res.data,
|
|
216
|
+
status: res === null || res === void 0 ? void 0 : res.status
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}, {
|
|
220
|
+
key: "getMsg",
|
|
221
|
+
value: function getMsg(res) {
|
|
222
|
+
if (!res) return '';
|
|
223
|
+
var _ref = res === null || res === void 0 ? void 0 : res.config,
|
|
224
|
+
_ref$showMsg = _ref.showMsg,
|
|
225
|
+
showMsg = _ref$showMsg === void 0 ? true : _ref$showMsg,
|
|
226
|
+
successText = _ref.successText,
|
|
227
|
+
errText = _ref.errText;
|
|
228
|
+
var remoteMsg = showMsg ? Request.getRemoteMessage(res) : '';
|
|
229
|
+
var isSuccessful = Request.checkRTCode(res);
|
|
230
|
+
var configMsg = isSuccessful ? successText : errText;
|
|
231
|
+
return configMsg !== null && configMsg !== void 0 ? configMsg : remoteMsg;
|
|
232
|
+
}
|
|
233
|
+
}, {
|
|
234
|
+
key: "getRemoteMessage",
|
|
235
|
+
value: function getRemoteMessage(res) {
|
|
236
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
237
|
+
var headerMessage = Request.getHeaderMessage(res);
|
|
238
|
+
var remoteMsg = (_f = (_d = (_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.msg) !== null && _b !== void 0 ? _b : (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.detail) !== null && _d !== void 0 ? _d : (_e = res === null || res === void 0 ? void 0 : res.data) === null || _e === void 0 ? void 0 : _e.message) !== null && _f !== void 0 ? _f : (_g = res === null || res === void 0 ? void 0 : res.data) === null || _g === void 0 ? void 0 : _g.title;
|
|
239
|
+
return headerMessage !== null && headerMessage !== void 0 ? headerMessage : remoteMsg;
|
|
240
|
+
}
|
|
241
|
+
}, {
|
|
242
|
+
key: "getHeaderMessage",
|
|
243
|
+
value: function getHeaderMessage(res) {
|
|
244
|
+
if (!res) return;
|
|
245
|
+
var headerMessageRaw = res.headers['lm-message'];
|
|
246
|
+
var headerMessage = headerMessageRaw ? decodeURIComponent(headerMessageRaw) : undefined;
|
|
247
|
+
return headerMessage;
|
|
248
|
+
}
|
|
249
|
+
}]);
|
|
250
|
+
}(EventEmitter);
|
|
251
|
+
Object.defineProperty(Request, "CONFIG", {
|
|
252
|
+
enumerable: true,
|
|
253
|
+
configurable: true,
|
|
254
|
+
writable: true,
|
|
255
|
+
value: {
|
|
256
|
+
successCode: [200, 1, 0]
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
Object.defineProperty(Request, "logger", {
|
|
260
|
+
enumerable: true,
|
|
261
|
+
configurable: true,
|
|
262
|
+
writable: true,
|
|
263
|
+
value: new MyLog('Request')
|
|
264
|
+
});
|
|
265
|
+
function doUnboxing(res) {
|
|
266
|
+
var isBoxing = typeof (res === null || res === void 0 ? void 0 : res.code) === 'number' && !!res.data;
|
|
267
|
+
if (isBoxing) {
|
|
268
|
+
return res.data;
|
|
269
|
+
}
|
|
270
|
+
return res;
|
|
271
|
+
}
|
|
272
|
+
function createInstance() {
|
|
273
|
+
var defaultConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
274
|
+
var instance = bind(Axios.prototype.request, request.ins);
|
|
275
|
+
utils.extend(instance, Axios.prototype, request.ins);
|
|
276
|
+
utils.extend(instance, request.ins);
|
|
277
|
+
return instance;
|
|
278
|
+
}
|
|
279
|
+
var request = new Request();
|
|
280
|
+
export { Request, codeMessage, createInstance, request };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
export type { AxiosError, AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios';
|
|
3
|
+
export interface IRequest_AxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
|
|
4
|
+
logger?: boolean;
|
|
5
|
+
unboxing?: boolean;
|
|
6
|
+
showMsg?: boolean;
|
|
7
|
+
successText?: string;
|
|
8
|
+
errText?: string;
|
|
9
|
+
ignore_usr?: boolean;
|
|
10
|
+
ignore_env?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface IRequest_ResponseError<D = any> {
|
|
13
|
+
msg: string;
|
|
14
|
+
data?: D;
|
|
15
|
+
status?: number;
|
|
16
|
+
url?: string;
|
|
17
|
+
error?: AxiosError<any, any>;
|
|
18
|
+
}
|
|
19
|
+
export interface IRequest_SpawnConfig {
|
|
20
|
+
config?: IRequest_AxiosRequestConfig;
|
|
21
|
+
onRequest?(value: IRequest_AxiosRequestConfig): IRequest_AxiosRequestConfig;
|
|
22
|
+
onResponse?(value: AxiosResponse): any;
|
|
23
|
+
onRejected?(err: IRequest_ResponseError): Promise<any>;
|
|
24
|
+
}
|
|
25
|
+
export type TRequest_SimpleReq = <T = any, R = AxiosResponse<T>, D = any>(url: string, config?: IRequest_AxiosRequestConfig<D>) => Promise<R>;
|
|
26
|
+
export type TRequest_PreReq = <T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: IRequest_AxiosRequestConfig<D>) => Promise<R>;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@noah-libjs/request",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"build": "rollup -c rollup.config.js",
|
|
8
|
+
"build:watch": "rollup -c rollup.config.js --watch",
|
|
9
|
+
"clean": "rimraf dist -rf",
|
|
10
|
+
"prebuild": "pnpm clean",
|
|
11
|
+
"build:types": "api-extractor run"
|
|
12
|
+
},
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"directories": {
|
|
15
|
+
"lib": "dist"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@noah-libjs/utils": "0.0.4",
|
|
25
|
+
"axios": "^0.26.1",
|
|
26
|
+
"store": "2.x"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/store": "^2.0.2",
|
|
30
|
+
"rollup": "^2.70.2"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [],
|
|
33
|
+
"author": "",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"gitHead": "b8d5927252929299ee101fd2a20e126f635e2442"
|
|
36
|
+
}
|