abbot-http-client 0.0.37 → 0.0.39

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
@@ -270,6 +270,7 @@ var AbbotHttp = class extends Axios {
270
270
  req.headers.setContentType(
271
271
  option?.contentType ?? this.config.axios.headers.post.contentType
272
272
  );
273
+ req.responseType = option?.responseType ?? "json";
273
274
  }
274
275
  }
275
276
  }
@@ -288,22 +289,19 @@ var AbbotHttp = class extends Axios {
288
289
  (response) => {
289
290
  const res = { ...response };
290
291
  res.data = cryp.decrypt(response.data);
292
+ if (option?.isDownload) {
293
+ return res;
294
+ }
291
295
  return res.data;
292
296
  },
293
297
  (error) => {
294
- return this.habdleError(error, cryp);
298
+ return this.handleError(error, cryp);
295
299
  }
296
300
  );
297
301
  return axios2;
298
302
  }
299
303
  prepareRequestConfig(option) {
300
304
  const iv = Secure.createId();
301
- if (this.config.devMode) {
302
- console.log({
303
- iv,
304
- keyValue: option?.isInit ? void 0 : this.config.app.encKey
305
- });
306
- }
307
305
  const cryp = new Cryp(
308
306
  {
309
307
  iv,
@@ -314,7 +312,7 @@ var AbbotHttp = class extends Axios {
314
312
  const form = new URLSearchParams();
315
313
  return { cryp, iv, form };
316
314
  }
317
- habdleError(error, cryp) {
315
+ handleError(error, cryp) {
318
316
  const err = {
319
317
  message: error.message,
320
318
  code: error.code,
@@ -401,6 +399,14 @@ var AbbotHttp = class extends Axios {
401
399
  }
402
400
  return response;
403
401
  }
402
+ async download(url, param, option) {
403
+ const axios2 = this.createAxiosInstance({ ...option, isDownload: true });
404
+ const response = await axios2.post(url, param);
405
+ if (this.config.devMode) {
406
+ axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
407
+ }
408
+ return response;
409
+ }
404
410
  async uploadFile(url, file, param1, param2, param3) {
405
411
  let response;
406
412
  const formData = new FormData();
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { AxiosResponse, AxiosInstance, AxiosError } from 'axios';
1
+ import { AxiosResponse, ResponseType, AxiosInstance, AxiosError } from 'axios';
2
2
 
3
3
  interface AbbotConfig {
4
4
  axios: {
@@ -46,6 +46,8 @@ declare class Cryp {
46
46
  interface MethodOption {
47
47
  isInit: boolean;
48
48
  contentType: string;
49
+ responseType: ResponseType;
50
+ isDownload: boolean;
49
51
  }
50
52
  interface AbbotResponse<T> {
51
53
  code: AxiosResponse["status"];
@@ -73,7 +75,7 @@ declare class Secure {
73
75
  }
74
76
 
75
77
  declare class AbbLog {
76
- LogRequest: <T>(cryp: Cryp, method: "POST" | "GET", path: string, req: any, res: AbbotResponse<T>) => void;
78
+ LogRequest: <T>(cryp: Cryp, method: "POST" | "GET", path: string, req: any, res: AbbotResponse<T> | AxiosResponse) => void;
77
79
  Info: (cryp: Cryp, txt: string) => void;
78
80
  getDate: () => string;
79
81
  }
@@ -87,9 +89,12 @@ declare class AbbotHttp extends Axios {
87
89
  getConfig(): AbbotConfig;
88
90
  private createAxiosInstance;
89
91
  private prepareRequestConfig;
90
- private habdleError;
92
+ private handleError;
91
93
  post<T>(url: string, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
92
94
  get<T>(url: string, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
95
+ download(url: string, param?: Record<string, any> | null,
96
+ /** isDownload is set to true mandatory */
97
+ option?: Partial<MethodOption>): Promise<AxiosResponse>;
93
98
  uploadFile<T>(url: string, file: File, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
94
99
  uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
95
100
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AxiosResponse, AxiosInstance, AxiosError } from 'axios';
1
+ import { AxiosResponse, ResponseType, AxiosInstance, AxiosError } from 'axios';
2
2
 
3
3
  interface AbbotConfig {
4
4
  axios: {
@@ -46,6 +46,8 @@ declare class Cryp {
46
46
  interface MethodOption {
47
47
  isInit: boolean;
48
48
  contentType: string;
49
+ responseType: ResponseType;
50
+ isDownload: boolean;
49
51
  }
50
52
  interface AbbotResponse<T> {
51
53
  code: AxiosResponse["status"];
@@ -73,7 +75,7 @@ declare class Secure {
73
75
  }
74
76
 
75
77
  declare class AbbLog {
76
- LogRequest: <T>(cryp: Cryp, method: "POST" | "GET", path: string, req: any, res: AbbotResponse<T>) => void;
78
+ LogRequest: <T>(cryp: Cryp, method: "POST" | "GET", path: string, req: any, res: AbbotResponse<T> | AxiosResponse) => void;
77
79
  Info: (cryp: Cryp, txt: string) => void;
78
80
  getDate: () => string;
79
81
  }
@@ -87,9 +89,12 @@ declare class AbbotHttp extends Axios {
87
89
  getConfig(): AbbotConfig;
88
90
  private createAxiosInstance;
89
91
  private prepareRequestConfig;
90
- private habdleError;
92
+ private handleError;
91
93
  post<T>(url: string, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
92
94
  get<T>(url: string, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
95
+ download(url: string, param?: Record<string, any> | null,
96
+ /** isDownload is set to true mandatory */
97
+ option?: Partial<MethodOption>): Promise<AxiosResponse>;
93
98
  uploadFile<T>(url: string, file: File, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
94
99
  uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
95
100
  }
package/dist/index.js CHANGED
@@ -231,6 +231,7 @@ var AbbotHttp = class extends Axios {
231
231
  req.headers.setContentType(
232
232
  option?.contentType ?? this.config.axios.headers.post.contentType
233
233
  );
234
+ req.responseType = option?.responseType ?? "json";
234
235
  }
235
236
  }
236
237
  }
@@ -249,22 +250,19 @@ var AbbotHttp = class extends Axios {
249
250
  (response) => {
250
251
  const res = { ...response };
251
252
  res.data = cryp.decrypt(response.data);
253
+ if (option?.isDownload) {
254
+ return res;
255
+ }
252
256
  return res.data;
253
257
  },
254
258
  (error) => {
255
- return this.habdleError(error, cryp);
259
+ return this.handleError(error, cryp);
256
260
  }
257
261
  );
258
262
  return axios2;
259
263
  }
260
264
  prepareRequestConfig(option) {
261
265
  const iv = Secure.createId();
262
- if (this.config.devMode) {
263
- console.log({
264
- iv,
265
- keyValue: option?.isInit ? void 0 : this.config.app.encKey
266
- });
267
- }
268
266
  const cryp = new Cryp(
269
267
  {
270
268
  iv,
@@ -275,7 +273,7 @@ var AbbotHttp = class extends Axios {
275
273
  const form = new URLSearchParams();
276
274
  return { cryp, iv, form };
277
275
  }
278
- habdleError(error, cryp) {
276
+ handleError(error, cryp) {
279
277
  const err = {
280
278
  message: error.message,
281
279
  code: error.code,
@@ -362,6 +360,14 @@ var AbbotHttp = class extends Axios {
362
360
  }
363
361
  return response;
364
362
  }
363
+ async download(url, param, option) {
364
+ const axios2 = this.createAxiosInstance({ ...option, isDownload: true });
365
+ const response = await axios2.post(url, param);
366
+ if (this.config.devMode) {
367
+ axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
368
+ }
369
+ return response;
370
+ }
365
371
  async uploadFile(url, file, param1, param2, param3) {
366
372
  let response;
367
373
  const formData = new FormData();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abbot-http-client",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
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",