abbot-http-client 0.0.44 → 0.0.46
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.cjs +55 -53
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +55 -60
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -84,39 +84,6 @@ function deepMerge(target, source) {
|
|
|
84
84
|
return target;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
// src/log/core.ts
|
|
88
|
-
var import_console_log_colors = require("console-log-colors");
|
|
89
|
-
var AbbLog = class {
|
|
90
|
-
LogRequest = (cryp, method, path, req, res) => {
|
|
91
|
-
const log = [];
|
|
92
|
-
const isErr = res.status !== "ok";
|
|
93
|
-
log.push(`[${(0, import_console_log_colors.blueBright)(cryp.ivText)}]`);
|
|
94
|
-
log.push((0, import_console_log_colors.cyan)(this.getDate()));
|
|
95
|
-
log.push((0, import_console_log_colors.green)(`[${method}]`));
|
|
96
|
-
log.push((0, import_console_log_colors.magenta)(`[${path}]`));
|
|
97
|
-
console.log(log.join(""));
|
|
98
|
-
console.log(
|
|
99
|
-
`[${(0, import_console_log_colors.blueBright)(cryp.ivText)}] ${(0, import_console_log_colors.blue)("req:")} ${JSON.stringify(req)}`
|
|
100
|
-
);
|
|
101
|
-
console.log(
|
|
102
|
-
`[${(0, import_console_log_colors.blueBright)(cryp.ivText)}] ${isErr ? (0, import_console_log_colors.red)("res:") : (0, import_console_log_colors.blue)("res:")} ${JSON.stringify(res)}`
|
|
103
|
-
);
|
|
104
|
-
};
|
|
105
|
-
Info = (cryp, txt) => {
|
|
106
|
-
const log = [];
|
|
107
|
-
log.push(`[${(0, import_console_log_colors.blueBright)(cryp.ivText)}]`);
|
|
108
|
-
log.push((0, import_console_log_colors.cyan)(this.getDate()));
|
|
109
|
-
log.push((0, import_console_log_colors.green)(`[${txt}]`));
|
|
110
|
-
};
|
|
111
|
-
getDate = () => {
|
|
112
|
-
const today = /* @__PURE__ */ new Date();
|
|
113
|
-
const hours = String(today.getHours()).padStart(2, "0");
|
|
114
|
-
const minutes = String(today.getMinutes()).padStart(2, "0");
|
|
115
|
-
const seconds = String(today.getSeconds()).padStart(2, "0");
|
|
116
|
-
return `[${hours}:${minutes}:${seconds}]`;
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
|
|
120
87
|
// src/config/axiosFn.ts
|
|
121
88
|
function axiosConf(cfg) {
|
|
122
89
|
return import_axios.default.create({
|
|
@@ -140,9 +107,7 @@ var Axios = class {
|
|
|
140
107
|
this.config = deepMerge(this.config, config);
|
|
141
108
|
}
|
|
142
109
|
axiosInstance() {
|
|
143
|
-
|
|
144
|
-
ist.log = new AbbLog();
|
|
145
|
-
return ist;
|
|
110
|
+
return axiosConf(this.config);
|
|
146
111
|
}
|
|
147
112
|
};
|
|
148
113
|
|
|
@@ -239,6 +204,44 @@ var Secure = class {
|
|
|
239
204
|
|
|
240
205
|
// src/http/core.ts
|
|
241
206
|
var import_axios2 = require("axios");
|
|
207
|
+
|
|
208
|
+
// src/log/core.ts
|
|
209
|
+
var import_console_log_colors = require("console-log-colors");
|
|
210
|
+
var AbbLog = class {
|
|
211
|
+
cryp;
|
|
212
|
+
log = [];
|
|
213
|
+
constructor(cryp) {
|
|
214
|
+
this.cryp = cryp;
|
|
215
|
+
this.log.push(`[${(0, import_console_log_colors.blueBright)(cryp.ivText)}]`);
|
|
216
|
+
this.log.push(`[${(0, import_console_log_colors.blueBright)(cryp.key)}]`);
|
|
217
|
+
}
|
|
218
|
+
logRequest(path, req) {
|
|
219
|
+
const temp = [...this.log];
|
|
220
|
+
temp.push((0, import_console_log_colors.cyan)(this.getDate()));
|
|
221
|
+
temp.push((0, import_console_log_colors.magenta)(`[${path}]`));
|
|
222
|
+
console.log(
|
|
223
|
+
`${temp.join("")}
|
|
224
|
+
${(0, import_console_log_colors.blue)("req:")} ${req ? JSON.stringify(req) : "no data from log request"}`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
logResponse(res) {
|
|
228
|
+
const temp = [...this.log];
|
|
229
|
+
temp.push((0, import_console_log_colors.cyan)(this.getDate()));
|
|
230
|
+
console.log(
|
|
231
|
+
`${temp.join("")}
|
|
232
|
+
${(0, import_console_log_colors.blue)("res:")} ${res ? JSON.stringify(res) : "no data from log response"}`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
getDate = () => {
|
|
236
|
+
const today = /* @__PURE__ */ new Date();
|
|
237
|
+
const hours = String(today.getHours()).padStart(2, "0");
|
|
238
|
+
const minutes = String(today.getMinutes()).padStart(2, "0");
|
|
239
|
+
const seconds = String(today.getSeconds()).padStart(2, "0");
|
|
240
|
+
return `[${hours}:${minutes}:${seconds}]`;
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// src/http/core.ts
|
|
242
245
|
var AbbotHttp = class extends Axios {
|
|
243
246
|
constructor(config) {
|
|
244
247
|
super(config);
|
|
@@ -250,11 +253,15 @@ var AbbotHttp = class extends Axios {
|
|
|
250
253
|
const axios2 = this.axiosInstance();
|
|
251
254
|
const { cryp, iv } = this.prepareRequestConfig(option);
|
|
252
255
|
axios2.cryp = cryp;
|
|
256
|
+
axios2.log = new AbbLog(cryp);
|
|
253
257
|
axios2.interceptors.request.use(
|
|
254
258
|
(config) => {
|
|
255
259
|
const req = { ...config };
|
|
256
260
|
if (req.method && req.method.toLowerCase() === "post") {
|
|
257
261
|
req.responseType = option?.responseType ?? "json";
|
|
262
|
+
if (this.config.devMode) {
|
|
263
|
+
axios2.log.logRequest(config.url ?? "", req.data);
|
|
264
|
+
}
|
|
258
265
|
if (req.data) {
|
|
259
266
|
if (req.data instanceof FormData) {
|
|
260
267
|
if (req.data.get("param")) {
|
|
@@ -286,19 +293,29 @@ var AbbotHttp = class extends Axios {
|
|
|
286
293
|
(error) => Promise.reject(error)
|
|
287
294
|
);
|
|
288
295
|
axios2.interceptors.response.use(
|
|
289
|
-
(response) => {
|
|
296
|
+
async (response) => {
|
|
290
297
|
const res = { ...response };
|
|
291
298
|
if (option?.isDownload) {
|
|
292
299
|
const contentTypes = ["application/json", "text/plain"];
|
|
293
300
|
if (contentTypes.includes(response.headers["content-type"])) {
|
|
294
|
-
|
|
301
|
+
const result = response.data instanceof Blob ? await response.data.text() : response.data;
|
|
302
|
+
res.data = cryp.decrypt(result);
|
|
303
|
+
if (this.config.devMode) {
|
|
304
|
+
axios2.log.logResponse(res.data);
|
|
305
|
+
}
|
|
295
306
|
}
|
|
296
307
|
return res;
|
|
297
308
|
}
|
|
298
309
|
res.data = cryp.decrypt(response.data);
|
|
310
|
+
if (this.config.devMode) {
|
|
311
|
+
axios2.log.logResponse(res.data);
|
|
312
|
+
}
|
|
299
313
|
return res.data;
|
|
300
314
|
},
|
|
301
315
|
(error) => {
|
|
316
|
+
if (this.config.devMode) {
|
|
317
|
+
axios2.log.logResponse(error);
|
|
318
|
+
}
|
|
302
319
|
return this.handleError(error, cryp);
|
|
303
320
|
}
|
|
304
321
|
);
|
|
@@ -390,17 +407,11 @@ var AbbotHttp = class extends Axios {
|
|
|
390
407
|
async post(url, param, option) {
|
|
391
408
|
const axios2 = this.createAxiosInstance(option);
|
|
392
409
|
const response = await axios2.post(url, param);
|
|
393
|
-
if (this.config.devMode) {
|
|
394
|
-
axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
|
|
395
|
-
}
|
|
396
410
|
return response;
|
|
397
411
|
}
|
|
398
412
|
async get(url, option) {
|
|
399
413
|
const axios2 = this.createAxiosInstance(option);
|
|
400
414
|
const response = await axios2.get(url);
|
|
401
|
-
if (this.config.devMode) {
|
|
402
|
-
axios2.log.LogRequest(axios2.cryp, "GET", url, {}, response);
|
|
403
|
-
}
|
|
404
415
|
return response;
|
|
405
416
|
}
|
|
406
417
|
async download(url, param, option) {
|
|
@@ -410,9 +421,6 @@ var AbbotHttp = class extends Axios {
|
|
|
410
421
|
responseType: "blob"
|
|
411
422
|
});
|
|
412
423
|
const response = await axios2.post(url, param);
|
|
413
|
-
if (this.config.devMode) {
|
|
414
|
-
axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
|
|
415
|
-
}
|
|
416
424
|
return response;
|
|
417
425
|
}
|
|
418
426
|
async uploadFile(url, file, param1, param2, param3) {
|
|
@@ -433,9 +441,6 @@ var AbbotHttp = class extends Axios {
|
|
|
433
441
|
formData.append("param", JSON.stringify(param));
|
|
434
442
|
}
|
|
435
443
|
response = await axios2.post(url, formData);
|
|
436
|
-
if (this.config.devMode) {
|
|
437
|
-
axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
|
|
438
|
-
}
|
|
439
444
|
} else {
|
|
440
445
|
const param = param1;
|
|
441
446
|
const opt = param2;
|
|
@@ -445,9 +450,6 @@ var AbbotHttp = class extends Axios {
|
|
|
445
450
|
formData.append("param", JSON.stringify(param));
|
|
446
451
|
}
|
|
447
452
|
response = await axios2.post(url, formData);
|
|
448
|
-
if (this.config.devMode) {
|
|
449
|
-
axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
|
|
450
|
-
}
|
|
451
453
|
}
|
|
452
454
|
return response;
|
|
453
455
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ResponseType, AxiosResponse, AxiosInstance, AxiosError } from 'axios';
|
|
2
2
|
|
|
3
3
|
interface AbbotConfig {
|
|
4
4
|
axios: {
|
|
@@ -75,9 +75,12 @@ declare class Secure {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
declare class AbbLog {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
private cryp;
|
|
79
|
+
private log;
|
|
80
|
+
constructor(cryp: Cryp);
|
|
81
|
+
logRequest(path: string, req: any): void;
|
|
82
|
+
logResponse(res: any): void;
|
|
83
|
+
private getDate;
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
interface HttpInstance extends AxiosInstance {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ResponseType, AxiosResponse, AxiosInstance, AxiosError } from 'axios';
|
|
2
2
|
|
|
3
3
|
interface AbbotConfig {
|
|
4
4
|
axios: {
|
|
@@ -75,9 +75,12 @@ declare class Secure {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
declare class AbbLog {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
private cryp;
|
|
79
|
+
private log;
|
|
80
|
+
constructor(cryp: Cryp);
|
|
81
|
+
logRequest(path: string, req: any): void;
|
|
82
|
+
logResponse(res: any): void;
|
|
83
|
+
private getDate;
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
interface HttpInstance extends AxiosInstance {
|
package/dist/index.js
CHANGED
|
@@ -38,46 +38,6 @@ function deepMerge(target, source) {
|
|
|
38
38
|
return target;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
// src/log/core.ts
|
|
42
|
-
import {
|
|
43
|
-
red,
|
|
44
|
-
green,
|
|
45
|
-
magenta,
|
|
46
|
-
cyan,
|
|
47
|
-
blueBright,
|
|
48
|
-
blue
|
|
49
|
-
} from "console-log-colors";
|
|
50
|
-
var AbbLog = class {
|
|
51
|
-
LogRequest = (cryp, method, path, req, res) => {
|
|
52
|
-
const log = [];
|
|
53
|
-
const isErr = res.status !== "ok";
|
|
54
|
-
log.push(`[${blueBright(cryp.ivText)}]`);
|
|
55
|
-
log.push(cyan(this.getDate()));
|
|
56
|
-
log.push(green(`[${method}]`));
|
|
57
|
-
log.push(magenta(`[${path}]`));
|
|
58
|
-
console.log(log.join(""));
|
|
59
|
-
console.log(
|
|
60
|
-
`[${blueBright(cryp.ivText)}] ${blue("req:")} ${JSON.stringify(req)}`
|
|
61
|
-
);
|
|
62
|
-
console.log(
|
|
63
|
-
`[${blueBright(cryp.ivText)}] ${isErr ? red("res:") : blue("res:")} ${JSON.stringify(res)}`
|
|
64
|
-
);
|
|
65
|
-
};
|
|
66
|
-
Info = (cryp, txt) => {
|
|
67
|
-
const log = [];
|
|
68
|
-
log.push(`[${blueBright(cryp.ivText)}]`);
|
|
69
|
-
log.push(cyan(this.getDate()));
|
|
70
|
-
log.push(green(`[${txt}]`));
|
|
71
|
-
};
|
|
72
|
-
getDate = () => {
|
|
73
|
-
const today = /* @__PURE__ */ new Date();
|
|
74
|
-
const hours = String(today.getHours()).padStart(2, "0");
|
|
75
|
-
const minutes = String(today.getMinutes()).padStart(2, "0");
|
|
76
|
-
const seconds = String(today.getSeconds()).padStart(2, "0");
|
|
77
|
-
return `[${hours}:${minutes}:${seconds}]`;
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
|
|
81
41
|
// src/config/axiosFn.ts
|
|
82
42
|
function axiosConf(cfg) {
|
|
83
43
|
return axios.create({
|
|
@@ -101,9 +61,7 @@ var Axios = class {
|
|
|
101
61
|
this.config = deepMerge(this.config, config);
|
|
102
62
|
}
|
|
103
63
|
axiosInstance() {
|
|
104
|
-
|
|
105
|
-
ist.log = new AbbLog();
|
|
106
|
-
return ist;
|
|
64
|
+
return axiosConf(this.config);
|
|
107
65
|
}
|
|
108
66
|
};
|
|
109
67
|
|
|
@@ -200,6 +158,44 @@ var Secure = class {
|
|
|
200
158
|
|
|
201
159
|
// src/http/core.ts
|
|
202
160
|
import { AxiosError } from "axios";
|
|
161
|
+
|
|
162
|
+
// src/log/core.ts
|
|
163
|
+
import { magenta, cyan, blueBright, blue } from "console-log-colors";
|
|
164
|
+
var AbbLog = class {
|
|
165
|
+
cryp;
|
|
166
|
+
log = [];
|
|
167
|
+
constructor(cryp) {
|
|
168
|
+
this.cryp = cryp;
|
|
169
|
+
this.log.push(`[${blueBright(cryp.ivText)}]`);
|
|
170
|
+
this.log.push(`[${blueBright(cryp.key)}]`);
|
|
171
|
+
}
|
|
172
|
+
logRequest(path, req) {
|
|
173
|
+
const temp = [...this.log];
|
|
174
|
+
temp.push(cyan(this.getDate()));
|
|
175
|
+
temp.push(magenta(`[${path}]`));
|
|
176
|
+
console.log(
|
|
177
|
+
`${temp.join("")}
|
|
178
|
+
${blue("req:")} ${req ? JSON.stringify(req) : "no data from log request"}`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
logResponse(res) {
|
|
182
|
+
const temp = [...this.log];
|
|
183
|
+
temp.push(cyan(this.getDate()));
|
|
184
|
+
console.log(
|
|
185
|
+
`${temp.join("")}
|
|
186
|
+
${blue("res:")} ${res ? JSON.stringify(res) : "no data from log response"}`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
getDate = () => {
|
|
190
|
+
const today = /* @__PURE__ */ new Date();
|
|
191
|
+
const hours = String(today.getHours()).padStart(2, "0");
|
|
192
|
+
const minutes = String(today.getMinutes()).padStart(2, "0");
|
|
193
|
+
const seconds = String(today.getSeconds()).padStart(2, "0");
|
|
194
|
+
return `[${hours}:${minutes}:${seconds}]`;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// src/http/core.ts
|
|
203
199
|
var AbbotHttp = class extends Axios {
|
|
204
200
|
constructor(config) {
|
|
205
201
|
super(config);
|
|
@@ -211,11 +207,15 @@ var AbbotHttp = class extends Axios {
|
|
|
211
207
|
const axios2 = this.axiosInstance();
|
|
212
208
|
const { cryp, iv } = this.prepareRequestConfig(option);
|
|
213
209
|
axios2.cryp = cryp;
|
|
210
|
+
axios2.log = new AbbLog(cryp);
|
|
214
211
|
axios2.interceptors.request.use(
|
|
215
212
|
(config) => {
|
|
216
213
|
const req = { ...config };
|
|
217
214
|
if (req.method && req.method.toLowerCase() === "post") {
|
|
218
215
|
req.responseType = option?.responseType ?? "json";
|
|
216
|
+
if (this.config.devMode) {
|
|
217
|
+
axios2.log.logRequest(config.url ?? "", req.data);
|
|
218
|
+
}
|
|
219
219
|
if (req.data) {
|
|
220
220
|
if (req.data instanceof FormData) {
|
|
221
221
|
if (req.data.get("param")) {
|
|
@@ -247,19 +247,29 @@ var AbbotHttp = class extends Axios {
|
|
|
247
247
|
(error) => Promise.reject(error)
|
|
248
248
|
);
|
|
249
249
|
axios2.interceptors.response.use(
|
|
250
|
-
(response) => {
|
|
250
|
+
async (response) => {
|
|
251
251
|
const res = { ...response };
|
|
252
252
|
if (option?.isDownload) {
|
|
253
253
|
const contentTypes = ["application/json", "text/plain"];
|
|
254
254
|
if (contentTypes.includes(response.headers["content-type"])) {
|
|
255
|
-
|
|
255
|
+
const result = response.data instanceof Blob ? await response.data.text() : response.data;
|
|
256
|
+
res.data = cryp.decrypt(result);
|
|
257
|
+
if (this.config.devMode) {
|
|
258
|
+
axios2.log.logResponse(res.data);
|
|
259
|
+
}
|
|
256
260
|
}
|
|
257
261
|
return res;
|
|
258
262
|
}
|
|
259
263
|
res.data = cryp.decrypt(response.data);
|
|
264
|
+
if (this.config.devMode) {
|
|
265
|
+
axios2.log.logResponse(res.data);
|
|
266
|
+
}
|
|
260
267
|
return res.data;
|
|
261
268
|
},
|
|
262
269
|
(error) => {
|
|
270
|
+
if (this.config.devMode) {
|
|
271
|
+
axios2.log.logResponse(error);
|
|
272
|
+
}
|
|
263
273
|
return this.handleError(error, cryp);
|
|
264
274
|
}
|
|
265
275
|
);
|
|
@@ -351,17 +361,11 @@ var AbbotHttp = class extends Axios {
|
|
|
351
361
|
async post(url, param, option) {
|
|
352
362
|
const axios2 = this.createAxiosInstance(option);
|
|
353
363
|
const response = await axios2.post(url, param);
|
|
354
|
-
if (this.config.devMode) {
|
|
355
|
-
axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
|
|
356
|
-
}
|
|
357
364
|
return response;
|
|
358
365
|
}
|
|
359
366
|
async get(url, option) {
|
|
360
367
|
const axios2 = this.createAxiosInstance(option);
|
|
361
368
|
const response = await axios2.get(url);
|
|
362
|
-
if (this.config.devMode) {
|
|
363
|
-
axios2.log.LogRequest(axios2.cryp, "GET", url, {}, response);
|
|
364
|
-
}
|
|
365
369
|
return response;
|
|
366
370
|
}
|
|
367
371
|
async download(url, param, option) {
|
|
@@ -371,9 +375,6 @@ var AbbotHttp = class extends Axios {
|
|
|
371
375
|
responseType: "blob"
|
|
372
376
|
});
|
|
373
377
|
const response = await axios2.post(url, param);
|
|
374
|
-
if (this.config.devMode) {
|
|
375
|
-
axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
|
|
376
|
-
}
|
|
377
378
|
return response;
|
|
378
379
|
}
|
|
379
380
|
async uploadFile(url, file, param1, param2, param3) {
|
|
@@ -394,9 +395,6 @@ var AbbotHttp = class extends Axios {
|
|
|
394
395
|
formData.append("param", JSON.stringify(param));
|
|
395
396
|
}
|
|
396
397
|
response = await axios2.post(url, formData);
|
|
397
|
-
if (this.config.devMode) {
|
|
398
|
-
axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
|
|
399
|
-
}
|
|
400
398
|
} else {
|
|
401
399
|
const param = param1;
|
|
402
400
|
const opt = param2;
|
|
@@ -406,9 +404,6 @@ var AbbotHttp = class extends Axios {
|
|
|
406
404
|
formData.append("param", JSON.stringify(param));
|
|
407
405
|
}
|
|
408
406
|
response = await axios2.post(url, formData);
|
|
409
|
-
if (this.config.devMode) {
|
|
410
|
-
axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
|
|
411
|
-
}
|
|
412
407
|
}
|
|
413
408
|
return response;
|
|
414
409
|
}
|