abbot-http-client 0.0.36 → 0.0.38

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 CHANGED
@@ -84,9 +84,42 @@ 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
+
87
120
  // src/config/axiosFn.ts
88
121
  function axiosConf(cfg) {
89
- const axiosObj = import_axios.default.create({
122
+ return import_axios.default.create({
90
123
  baseURL: cfg.axios?.baseUrl,
91
124
  headers: {
92
125
  common: {
@@ -100,7 +133,6 @@ function axiosConf(cfg) {
100
133
  timeout: cfg.axios?.timeout,
101
134
  withCredentials: true
102
135
  });
103
- return axiosObj;
104
136
  }
105
137
  var Axios = class {
106
138
  config = defaultConfig;
@@ -108,8 +140,9 @@ var Axios = class {
108
140
  this.config = deepMerge(this.config, config);
109
141
  }
110
142
  axiosInstance() {
111
- const axios2 = axiosConf(this.config);
112
- return axios2;
143
+ const ist = axiosConf(this.config);
144
+ ist.log = new AbbLog();
145
+ return ist;
113
146
  }
114
147
  };
115
148
 
@@ -216,6 +249,7 @@ var AbbotHttp = class extends Axios {
216
249
  createAxiosInstance(option) {
217
250
  const axios2 = this.axiosInstance();
218
251
  const { cryp, iv } = this.prepareRequestConfig(option);
252
+ axios2.cryp = cryp;
219
253
  axios2.interceptors.request.use(
220
254
  (config) => {
221
255
  const req = { ...config };
@@ -264,12 +298,6 @@ var AbbotHttp = class extends Axios {
264
298
  }
265
299
  prepareRequestConfig(option) {
266
300
  const iv = Secure.createId();
267
- if (this.config.devMode) {
268
- console.log({
269
- iv,
270
- keyValue: option?.isInit ? void 0 : this.config.app.encKey
271
- });
272
- }
273
301
  const cryp = new Cryp(
274
302
  {
275
303
  iv,
@@ -354,11 +382,17 @@ var AbbotHttp = class extends Axios {
354
382
  async post(url, param, option) {
355
383
  const axios2 = this.createAxiosInstance(option);
356
384
  const response = await axios2.post(url, param);
385
+ if (this.config.devMode) {
386
+ axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
387
+ }
357
388
  return response;
358
389
  }
359
390
  async get(url, option) {
360
391
  const axios2 = this.createAxiosInstance(option);
361
392
  const response = await axios2.get(url);
393
+ if (this.config.devMode) {
394
+ axios2.log.LogRequest(axios2.cryp, "GET", url, {}, response);
395
+ }
362
396
  return response;
363
397
  }
364
398
  async uploadFile(url, file, param1, param2, param3) {
@@ -379,14 +413,21 @@ var AbbotHttp = class extends Axios {
379
413
  formData.append("param", JSON.stringify(param));
380
414
  }
381
415
  response = await axios2.post(url, formData);
416
+ if (this.config.devMode) {
417
+ axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
418
+ }
382
419
  } else {
383
420
  const param = param1;
384
421
  const opt = param2;
385
422
  const axios2 = this.createAxiosInstance(opt);
423
+ formData.append("file", file);
386
424
  if (param) {
387
425
  formData.append("param", JSON.stringify(param));
388
426
  }
389
427
  response = await axios2.post(url, formData);
428
+ if (this.config.devMode) {
429
+ axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
430
+ }
390
431
  }
391
432
  return response;
392
433
  }
package/dist/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
- import * as axios from 'axios';
2
- import { AxiosResponse, AxiosError } from 'axios';
1
+ import { AxiosResponse, AxiosInstance, AxiosError } from 'axios';
3
2
 
4
3
  interface AbbotConfig {
5
4
  axios: {
@@ -30,12 +29,6 @@ type DeepPartial<T> = T extends object ? {
30
29
  } : T;
31
30
  declare function deepMerge<T>(target: T, source: DeepPartial<T>): T;
32
31
 
33
- declare class Axios {
34
- config: AbbotConfig;
35
- constructor(config: DeepPartial<AbbotConfig>);
36
- axiosInstance(): axios.AxiosInstance;
37
- }
38
-
39
32
  declare class Cryp {
40
33
  ivText: string;
41
34
  key: string;
@@ -50,6 +43,18 @@ declare class Cryp {
50
43
  decrypt<T>(encryptedValue?: string): T | null;
51
44
  }
52
45
 
46
+ interface MethodOption {
47
+ isInit: boolean;
48
+ contentType: string;
49
+ }
50
+ interface AbbotResponse<T> {
51
+ code: AxiosResponse["status"];
52
+ detail: string | null;
53
+ message: string;
54
+ status: string;
55
+ data: T;
56
+ }
57
+
53
58
  declare class ES {
54
59
  static e(value: string): number[];
55
60
  static d(value: number[]): string;
@@ -67,18 +72,16 @@ declare class Secure {
67
72
  static toBase64Length16: (text: string | undefined) => string;
68
73
  }
69
74
 
70
- interface MethodOption {
71
- isInit: boolean;
72
- contentType: string;
73
- }
74
- interface AbbotResponse<T> {
75
- code: AxiosResponse["status"];
76
- detail: string | null;
77
- message: string;
78
- status: string;
79
- data: T;
75
+ declare class AbbLog {
76
+ LogRequest: <T>(cryp: Cryp, method: "POST" | "GET", path: string, req: any, res: AbbotResponse<T>) => void;
77
+ Info: (cryp: Cryp, txt: string) => void;
78
+ getDate: () => string;
80
79
  }
81
80
 
81
+ interface HttpInstance extends AxiosInstance {
82
+ cryp: Cryp;
83
+ log: AbbLog;
84
+ }
82
85
  declare class AbbotHttp extends Axios {
83
86
  constructor(config: DeepPartial<AbbotConfig>);
84
87
  getConfig(): AbbotConfig;
@@ -91,6 +94,12 @@ declare class AbbotHttp extends Axios {
91
94
  uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
92
95
  }
93
96
 
97
+ declare class Axios {
98
+ config: AbbotConfig;
99
+ constructor(config: DeepPartial<AbbotConfig>);
100
+ axiosInstance(): HttpInstance;
101
+ }
102
+
94
103
  declare function catchError<T, E extends new (err?: any) => Error>(promise: Promise<T>, errorToCatch?: E[]): Promise<[undefined, T] | [InstanceType<E>]>;
95
104
 
96
105
  declare class AppError extends Error {
@@ -104,4 +113,4 @@ declare class RestError<T extends AxiosError> extends Error {
104
113
 
105
114
  declare function create(config: DeepPartial<AbbotConfig>): AbbotHttp;
106
115
 
107
- export { type AbbotConfig, AbbotHttp, type AbbotResponse, AppError, Axios, Cryp, type DeepPartial, ES, type MethodOption, RestError, Secure, catchError, create, deepMerge, defaultConfig };
116
+ export { type AbbotConfig, AbbotHttp, type AbbotResponse, AppError, Axios, Cryp, type DeepPartial, ES, type HttpInstance, type MethodOption, RestError, Secure, catchError, create, deepMerge, defaultConfig };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import * as axios from 'axios';
2
- import { AxiosResponse, AxiosError } from 'axios';
1
+ import { AxiosResponse, AxiosInstance, AxiosError } from 'axios';
3
2
 
4
3
  interface AbbotConfig {
5
4
  axios: {
@@ -30,12 +29,6 @@ type DeepPartial<T> = T extends object ? {
30
29
  } : T;
31
30
  declare function deepMerge<T>(target: T, source: DeepPartial<T>): T;
32
31
 
33
- declare class Axios {
34
- config: AbbotConfig;
35
- constructor(config: DeepPartial<AbbotConfig>);
36
- axiosInstance(): axios.AxiosInstance;
37
- }
38
-
39
32
  declare class Cryp {
40
33
  ivText: string;
41
34
  key: string;
@@ -50,6 +43,18 @@ declare class Cryp {
50
43
  decrypt<T>(encryptedValue?: string): T | null;
51
44
  }
52
45
 
46
+ interface MethodOption {
47
+ isInit: boolean;
48
+ contentType: string;
49
+ }
50
+ interface AbbotResponse<T> {
51
+ code: AxiosResponse["status"];
52
+ detail: string | null;
53
+ message: string;
54
+ status: string;
55
+ data: T;
56
+ }
57
+
53
58
  declare class ES {
54
59
  static e(value: string): number[];
55
60
  static d(value: number[]): string;
@@ -67,18 +72,16 @@ declare class Secure {
67
72
  static toBase64Length16: (text: string | undefined) => string;
68
73
  }
69
74
 
70
- interface MethodOption {
71
- isInit: boolean;
72
- contentType: string;
73
- }
74
- interface AbbotResponse<T> {
75
- code: AxiosResponse["status"];
76
- detail: string | null;
77
- message: string;
78
- status: string;
79
- data: T;
75
+ declare class AbbLog {
76
+ LogRequest: <T>(cryp: Cryp, method: "POST" | "GET", path: string, req: any, res: AbbotResponse<T>) => void;
77
+ Info: (cryp: Cryp, txt: string) => void;
78
+ getDate: () => string;
80
79
  }
81
80
 
81
+ interface HttpInstance extends AxiosInstance {
82
+ cryp: Cryp;
83
+ log: AbbLog;
84
+ }
82
85
  declare class AbbotHttp extends Axios {
83
86
  constructor(config: DeepPartial<AbbotConfig>);
84
87
  getConfig(): AbbotConfig;
@@ -91,6 +94,12 @@ declare class AbbotHttp extends Axios {
91
94
  uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
92
95
  }
93
96
 
97
+ declare class Axios {
98
+ config: AbbotConfig;
99
+ constructor(config: DeepPartial<AbbotConfig>);
100
+ axiosInstance(): HttpInstance;
101
+ }
102
+
94
103
  declare function catchError<T, E extends new (err?: any) => Error>(promise: Promise<T>, errorToCatch?: E[]): Promise<[undefined, T] | [InstanceType<E>]>;
95
104
 
96
105
  declare class AppError extends Error {
@@ -104,4 +113,4 @@ declare class RestError<T extends AxiosError> extends Error {
104
113
 
105
114
  declare function create(config: DeepPartial<AbbotConfig>): AbbotHttp;
106
115
 
107
- export { type AbbotConfig, AbbotHttp, type AbbotResponse, AppError, Axios, Cryp, type DeepPartial, ES, type MethodOption, RestError, Secure, catchError, create, deepMerge, defaultConfig };
116
+ export { type AbbotConfig, AbbotHttp, type AbbotResponse, AppError, Axios, Cryp, type DeepPartial, ES, type HttpInstance, type MethodOption, RestError, Secure, catchError, create, deepMerge, defaultConfig };
package/dist/index.js CHANGED
@@ -38,9 +38,49 @@ 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
+
41
81
  // src/config/axiosFn.ts
42
82
  function axiosConf(cfg) {
43
- const axiosObj = axios.create({
83
+ return axios.create({
44
84
  baseURL: cfg.axios?.baseUrl,
45
85
  headers: {
46
86
  common: {
@@ -54,7 +94,6 @@ function axiosConf(cfg) {
54
94
  timeout: cfg.axios?.timeout,
55
95
  withCredentials: true
56
96
  });
57
- return axiosObj;
58
97
  }
59
98
  var Axios = class {
60
99
  config = defaultConfig;
@@ -62,8 +101,9 @@ var Axios = class {
62
101
  this.config = deepMerge(this.config, config);
63
102
  }
64
103
  axiosInstance() {
65
- const axios2 = axiosConf(this.config);
66
- return axios2;
104
+ const ist = axiosConf(this.config);
105
+ ist.log = new AbbLog();
106
+ return ist;
67
107
  }
68
108
  };
69
109
 
@@ -170,6 +210,7 @@ var AbbotHttp = class extends Axios {
170
210
  createAxiosInstance(option) {
171
211
  const axios2 = this.axiosInstance();
172
212
  const { cryp, iv } = this.prepareRequestConfig(option);
213
+ axios2.cryp = cryp;
173
214
  axios2.interceptors.request.use(
174
215
  (config) => {
175
216
  const req = { ...config };
@@ -218,12 +259,6 @@ var AbbotHttp = class extends Axios {
218
259
  }
219
260
  prepareRequestConfig(option) {
220
261
  const iv = Secure.createId();
221
- if (this.config.devMode) {
222
- console.log({
223
- iv,
224
- keyValue: option?.isInit ? void 0 : this.config.app.encKey
225
- });
226
- }
227
262
  const cryp = new Cryp(
228
263
  {
229
264
  iv,
@@ -308,11 +343,17 @@ var AbbotHttp = class extends Axios {
308
343
  async post(url, param, option) {
309
344
  const axios2 = this.createAxiosInstance(option);
310
345
  const response = await axios2.post(url, param);
346
+ if (this.config.devMode) {
347
+ axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
348
+ }
311
349
  return response;
312
350
  }
313
351
  async get(url, option) {
314
352
  const axios2 = this.createAxiosInstance(option);
315
353
  const response = await axios2.get(url);
354
+ if (this.config.devMode) {
355
+ axios2.log.LogRequest(axios2.cryp, "GET", url, {}, response);
356
+ }
316
357
  return response;
317
358
  }
318
359
  async uploadFile(url, file, param1, param2, param3) {
@@ -333,14 +374,21 @@ var AbbotHttp = class extends Axios {
333
374
  formData.append("param", JSON.stringify(param));
334
375
  }
335
376
  response = await axios2.post(url, formData);
377
+ if (this.config.devMode) {
378
+ axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
379
+ }
336
380
  } else {
337
381
  const param = param1;
338
382
  const opt = param2;
339
383
  const axios2 = this.createAxiosInstance(opt);
384
+ formData.append("file", file);
340
385
  if (param) {
341
386
  formData.append("param", JSON.stringify(param));
342
387
  }
343
388
  response = await axios2.post(url, formData);
389
+ if (this.config.devMode) {
390
+ axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
391
+ }
344
392
  }
345
393
  return response;
346
394
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abbot-http-client",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "description": "This package helps Abbot team to handle all the axios requests.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -19,6 +19,7 @@
19
19
  "dependencies": {
20
20
  "@types/node": "^24.0.14",
21
21
  "axios": "^1.10.0",
22
+ "console-log-colors": "^0.5.0",
22
23
  "crypto-ts": "^1.0.2",
23
24
  "ts-node": "^10.9.2",
24
25
  "typescript": "^5.8.3"