abbot-http-client 0.0.13 → 0.0.14

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
@@ -164,12 +164,12 @@ var CoreHttp = class {
164
164
  constructor(config) {
165
165
  this.config = config;
166
166
  }
167
- createAxiosInstance() {
167
+ createAxiosInstance(option) {
168
168
  const axios2 = axiosConf(this.config);
169
169
  const iv = Secure.createId();
170
170
  const cryp = new Cryp({
171
171
  iv,
172
- keyValue: ""
172
+ keyValue: option?.isInit ? this.config.app.ecnKey : void 0
173
173
  });
174
174
  axios2.interceptors.request.use(
175
175
  (config) => {
@@ -283,23 +283,24 @@ var CoreHttp = class {
283
283
  );
284
284
  return axios2;
285
285
  }
286
- async post(url, param) {
287
- const axios2 = this.createAxiosInstance();
286
+ async post(url, param, option) {
287
+ const axios2 = this.createAxiosInstance(option);
288
288
  const response = await axios2.post(url, param);
289
289
  return response;
290
290
  }
291
- async get(url) {
292
- const axios2 = this.createAxiosInstance();
291
+ async get(url, option) {
292
+ const axios2 = this.createAxiosInstance(option);
293
293
  const response = await axios2.get(url);
294
294
  return response;
295
295
  }
296
- async uploadFile(url, file, param1, param2) {
296
+ async uploadFile(url, file, param1, param2, param3) {
297
297
  let response;
298
298
  const formData = new FormData();
299
299
  if (file instanceof Array) {
300
300
  const fileKeys = param1;
301
301
  const param = param2;
302
- const axios2 = this.createAxiosInstance();
302
+ const opt = param3;
303
+ const axios2 = this.createAxiosInstance(opt);
303
304
  fileKeys.forEach((k, i) => {
304
305
  formData.append(k, file[i]);
305
306
  });
@@ -309,7 +310,8 @@ var CoreHttp = class {
309
310
  response = await axios2.post(url, formData);
310
311
  } else {
311
312
  const param = param1;
312
- const axios2 = this.createAxiosInstance();
313
+ const opt = param2;
314
+ const axios2 = this.createAxiosInstance(opt);
313
315
  if (param) {
314
316
  formData.append("param", JSON.stringify(param));
315
317
  }
@@ -338,10 +340,7 @@ var cfg = {
338
340
  app: {
339
341
  redirectUrl: "/login",
340
342
  apiKey: "",
341
- timezone: "Asia/Bangkok",
342
- trackingId: "",
343
- ecnKey: void 0,
344
- userJwt: void 0
343
+ timezone: "Asia/Bangkok"
345
344
  }
346
345
  };
347
346
  function getConfig() {
package/dist/index.d.cts CHANGED
@@ -2,14 +2,17 @@ import { AxiosResponse } from 'axios';
2
2
 
3
3
  declare function catchError<T, E extends new (err?: any) => Error>(promise: Promise<T>, errorToCatch?: E[]): Promise<[undefined, T] | [InstanceType<E>]>;
4
4
 
5
+ interface MethodOption {
6
+ isInit: boolean;
7
+ }
5
8
  declare class CoreHttp {
6
9
  private config;
7
10
  constructor(config: AbbotConfig);
8
11
  private createAxiosInstance;
9
- post<T>(url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
10
- get<T>(url: string): Promise<AxiosResponse<T>>;
11
- uploadFile<T>(url: string, file: File, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
12
- uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
12
+ post<T>(url: string, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AxiosResponse<T>>;
13
+ get<T>(url: string, option?: Partial<MethodOption>): Promise<AxiosResponse<T>>;
14
+ uploadFile<T>(url: string, file: File, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AxiosResponse<T>>;
15
+ uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AxiosResponse<T>>;
13
16
  getConfig(): AbbotConfig;
14
17
  }
15
18
 
@@ -17,21 +20,21 @@ interface AbbotConfig {
17
20
  axios: {
18
21
  baseUrl: string;
19
22
  headers: {
20
- accept: string;
21
- lang: string;
22
- post: {
23
- contentType: string;
23
+ accept?: string;
24
+ lang?: string;
25
+ post?: {
26
+ contentType?: string;
24
27
  };
25
28
  };
26
- timeout: number;
29
+ timeout?: number;
27
30
  };
28
31
  app: {
29
32
  redirectUrl: string;
30
33
  apiKey: string;
31
34
  timezone: string;
32
- trackingId: string;
33
- ecnKey: string | undefined;
34
- userJwt: string | undefined;
35
+ trackingId?: string;
36
+ ecnKey?: string;
37
+ userJwt?: string;
35
38
  };
36
39
  }
37
40
  declare function create(config: Partial<AbbotConfig>): CoreHttp;
package/dist/index.d.ts CHANGED
@@ -2,14 +2,17 @@ import { AxiosResponse } from 'axios';
2
2
 
3
3
  declare function catchError<T, E extends new (err?: any) => Error>(promise: Promise<T>, errorToCatch?: E[]): Promise<[undefined, T] | [InstanceType<E>]>;
4
4
 
5
+ interface MethodOption {
6
+ isInit: boolean;
7
+ }
5
8
  declare class CoreHttp {
6
9
  private config;
7
10
  constructor(config: AbbotConfig);
8
11
  private createAxiosInstance;
9
- post<T>(url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
10
- get<T>(url: string): Promise<AxiosResponse<T>>;
11
- uploadFile<T>(url: string, file: File, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
12
- uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
12
+ post<T>(url: string, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AxiosResponse<T>>;
13
+ get<T>(url: string, option?: Partial<MethodOption>): Promise<AxiosResponse<T>>;
14
+ uploadFile<T>(url: string, file: File, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AxiosResponse<T>>;
15
+ uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AxiosResponse<T>>;
13
16
  getConfig(): AbbotConfig;
14
17
  }
15
18
 
@@ -17,21 +20,21 @@ interface AbbotConfig {
17
20
  axios: {
18
21
  baseUrl: string;
19
22
  headers: {
20
- accept: string;
21
- lang: string;
22
- post: {
23
- contentType: string;
23
+ accept?: string;
24
+ lang?: string;
25
+ post?: {
26
+ contentType?: string;
24
27
  };
25
28
  };
26
- timeout: number;
29
+ timeout?: number;
27
30
  };
28
31
  app: {
29
32
  redirectUrl: string;
30
33
  apiKey: string;
31
34
  timezone: string;
32
- trackingId: string;
33
- ecnKey: string | undefined;
34
- userJwt: string | undefined;
35
+ trackingId?: string;
36
+ ecnKey?: string;
37
+ userJwt?: string;
35
38
  };
36
39
  }
37
40
  declare function create(config: Partial<AbbotConfig>): CoreHttp;
package/dist/index.js CHANGED
@@ -127,12 +127,12 @@ var CoreHttp = class {
127
127
  constructor(config) {
128
128
  this.config = config;
129
129
  }
130
- createAxiosInstance() {
130
+ createAxiosInstance(option) {
131
131
  const axios2 = axiosConf(this.config);
132
132
  const iv = Secure.createId();
133
133
  const cryp = new Cryp({
134
134
  iv,
135
- keyValue: ""
135
+ keyValue: option?.isInit ? this.config.app.ecnKey : void 0
136
136
  });
137
137
  axios2.interceptors.request.use(
138
138
  (config) => {
@@ -246,23 +246,24 @@ var CoreHttp = class {
246
246
  );
247
247
  return axios2;
248
248
  }
249
- async post(url, param) {
250
- const axios2 = this.createAxiosInstance();
249
+ async post(url, param, option) {
250
+ const axios2 = this.createAxiosInstance(option);
251
251
  const response = await axios2.post(url, param);
252
252
  return response;
253
253
  }
254
- async get(url) {
255
- const axios2 = this.createAxiosInstance();
254
+ async get(url, option) {
255
+ const axios2 = this.createAxiosInstance(option);
256
256
  const response = await axios2.get(url);
257
257
  return response;
258
258
  }
259
- async uploadFile(url, file, param1, param2) {
259
+ async uploadFile(url, file, param1, param2, param3) {
260
260
  let response;
261
261
  const formData = new FormData();
262
262
  if (file instanceof Array) {
263
263
  const fileKeys = param1;
264
264
  const param = param2;
265
- const axios2 = this.createAxiosInstance();
265
+ const opt = param3;
266
+ const axios2 = this.createAxiosInstance(opt);
266
267
  fileKeys.forEach((k, i) => {
267
268
  formData.append(k, file[i]);
268
269
  });
@@ -272,7 +273,8 @@ var CoreHttp = class {
272
273
  response = await axios2.post(url, formData);
273
274
  } else {
274
275
  const param = param1;
275
- const axios2 = this.createAxiosInstance();
276
+ const opt = param2;
277
+ const axios2 = this.createAxiosInstance(opt);
276
278
  if (param) {
277
279
  formData.append("param", JSON.stringify(param));
278
280
  }
@@ -301,10 +303,7 @@ var cfg = {
301
303
  app: {
302
304
  redirectUrl: "/login",
303
305
  apiKey: "",
304
- timezone: "Asia/Bangkok",
305
- trackingId: "",
306
- ecnKey: void 0,
307
- userJwt: void 0
306
+ timezone: "Asia/Bangkok"
308
307
  }
309
308
  };
310
309
  function getConfig() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abbot-http-client",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
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",