abbot-http-client 0.0.45 → 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 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
- const ist = axiosConf(this.config);
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")) {
@@ -293,13 +300,22 @@ var AbbotHttp = class extends Axios {
293
300
  if (contentTypes.includes(response.headers["content-type"])) {
294
301
  const result = response.data instanceof Blob ? await response.data.text() : response.data;
295
302
  res.data = cryp.decrypt(result);
303
+ if (this.config.devMode) {
304
+ axios2.log.logResponse(res.data);
305
+ }
296
306
  }
297
307
  return res;
298
308
  }
299
309
  res.data = cryp.decrypt(response.data);
310
+ if (this.config.devMode) {
311
+ axios2.log.logResponse(res.data);
312
+ }
300
313
  return res.data;
301
314
  },
302
315
  (error) => {
316
+ if (this.config.devMode) {
317
+ axios2.log.logResponse(error);
318
+ }
303
319
  return this.handleError(error, cryp);
304
320
  }
305
321
  );
@@ -391,17 +407,11 @@ var AbbotHttp = class extends Axios {
391
407
  async post(url, param, option) {
392
408
  const axios2 = this.createAxiosInstance(option);
393
409
  const response = await axios2.post(url, param);
394
- if (this.config.devMode) {
395
- axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
396
- }
397
410
  return response;
398
411
  }
399
412
  async get(url, option) {
400
413
  const axios2 = this.createAxiosInstance(option);
401
414
  const response = await axios2.get(url);
402
- if (this.config.devMode) {
403
- axios2.log.LogRequest(axios2.cryp, "GET", url, {}, response);
404
- }
405
415
  return response;
406
416
  }
407
417
  async download(url, param, option) {
@@ -411,9 +421,6 @@ var AbbotHttp = class extends Axios {
411
421
  responseType: "blob"
412
422
  });
413
423
  const response = await axios2.post(url, param);
414
- if (this.config.devMode) {
415
- axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
416
- }
417
424
  return response;
418
425
  }
419
426
  async uploadFile(url, file, param1, param2, param3) {
@@ -434,9 +441,6 @@ var AbbotHttp = class extends Axios {
434
441
  formData.append("param", JSON.stringify(param));
435
442
  }
436
443
  response = await axios2.post(url, formData);
437
- if (this.config.devMode) {
438
- axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
439
- }
440
444
  } else {
441
445
  const param = param1;
442
446
  const opt = param2;
@@ -446,9 +450,6 @@ var AbbotHttp = class extends Axios {
446
450
  formData.append("param", JSON.stringify(param));
447
451
  }
448
452
  response = await axios2.post(url, formData);
449
- if (this.config.devMode) {
450
- axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
451
- }
452
453
  }
453
454
  return response;
454
455
  }
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { AxiosResponse, ResponseType, AxiosInstance, AxiosError } from 'axios';
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
- LogRequest: <T>(cryp: Cryp, method: "POST" | "GET", path: string, req: any, res: AbbotResponse<T> | AxiosResponse) => void;
79
- Info: (cryp: Cryp, txt: string) => void;
80
- getDate: () => string;
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 { AxiosResponse, ResponseType, AxiosInstance, AxiosError } from 'axios';
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
- LogRequest: <T>(cryp: Cryp, method: "POST" | "GET", path: string, req: any, res: AbbotResponse<T> | AxiosResponse) => void;
79
- Info: (cryp: Cryp, txt: string) => void;
80
- getDate: () => string;
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
- const ist = axiosConf(this.config);
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")) {
@@ -254,13 +254,22 @@ var AbbotHttp = class extends Axios {
254
254
  if (contentTypes.includes(response.headers["content-type"])) {
255
255
  const result = response.data instanceof Blob ? await response.data.text() : response.data;
256
256
  res.data = cryp.decrypt(result);
257
+ if (this.config.devMode) {
258
+ axios2.log.logResponse(res.data);
259
+ }
257
260
  }
258
261
  return res;
259
262
  }
260
263
  res.data = cryp.decrypt(response.data);
264
+ if (this.config.devMode) {
265
+ axios2.log.logResponse(res.data);
266
+ }
261
267
  return res.data;
262
268
  },
263
269
  (error) => {
270
+ if (this.config.devMode) {
271
+ axios2.log.logResponse(error);
272
+ }
264
273
  return this.handleError(error, cryp);
265
274
  }
266
275
  );
@@ -352,17 +361,11 @@ var AbbotHttp = class extends Axios {
352
361
  async post(url, param, option) {
353
362
  const axios2 = this.createAxiosInstance(option);
354
363
  const response = await axios2.post(url, param);
355
- if (this.config.devMode) {
356
- axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
357
- }
358
364
  return response;
359
365
  }
360
366
  async get(url, option) {
361
367
  const axios2 = this.createAxiosInstance(option);
362
368
  const response = await axios2.get(url);
363
- if (this.config.devMode) {
364
- axios2.log.LogRequest(axios2.cryp, "GET", url, {}, response);
365
- }
366
369
  return response;
367
370
  }
368
371
  async download(url, param, option) {
@@ -372,9 +375,6 @@ var AbbotHttp = class extends Axios {
372
375
  responseType: "blob"
373
376
  });
374
377
  const response = await axios2.post(url, param);
375
- if (this.config.devMode) {
376
- axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
377
- }
378
378
  return response;
379
379
  }
380
380
  async uploadFile(url, file, param1, param2, param3) {
@@ -395,9 +395,6 @@ var AbbotHttp = class extends Axios {
395
395
  formData.append("param", JSON.stringify(param));
396
396
  }
397
397
  response = await axios2.post(url, formData);
398
- if (this.config.devMode) {
399
- axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
400
- }
401
398
  } else {
402
399
  const param = param1;
403
400
  const opt = param2;
@@ -407,9 +404,6 @@ var AbbotHttp = class extends Axios {
407
404
  formData.append("param", JSON.stringify(param));
408
405
  }
409
406
  response = await axios2.post(url, formData);
410
- if (this.config.devMode) {
411
- axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
412
- }
413
407
  }
414
408
  return response;
415
409
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abbot-http-client",
3
- "version": "0.0.45",
3
+ "version": "0.0.46",
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",