abbot-http-client 0.0.12 → 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,11 +164,12 @@ var CoreHttp = class {
164
164
  constructor(config) {
165
165
  this.config = config;
166
166
  }
167
- createAxiosInstance(userJWT) {
167
+ createAxiosInstance(option) {
168
168
  const axios2 = axiosConf(this.config);
169
169
  const iv = Secure.createId();
170
170
  const cryp = new Cryp({
171
- iv
171
+ iv,
172
+ keyValue: option?.isInit ? this.config.app.ecnKey : void 0
172
173
  });
173
174
  axios2.interceptors.request.use(
174
175
  (config) => {
@@ -193,10 +194,10 @@ var CoreHttp = class {
193
194
  }
194
195
  req.headers.set("data-code", iv);
195
196
  if (this.config.app?.trackingId) {
196
- req.headers.set("X-Trace-Id", this.config.app.trackingId);
197
+ config.headers.set("X-Trace-Id", this.config.app.trackingId);
197
198
  }
198
- if (userJWT) {
199
- req.headers.setAuthorization(`Bearer ${userJWT}`);
199
+ if (this.config.app.userJwt) {
200
+ config.headers.setAuthorization(`Bearer ${this.config.app.userJwt}`);
200
201
  }
201
202
  return req;
202
203
  },
@@ -282,13 +283,13 @@ var CoreHttp = class {
282
283
  );
283
284
  return axios2;
284
285
  }
285
- async post(url, param, jwt) {
286
- const axios2 = this.createAxiosInstance(jwt);
286
+ async post(url, param, option) {
287
+ const axios2 = this.createAxiosInstance(option);
287
288
  const response = await axios2.post(url, param);
288
289
  return response;
289
290
  }
290
- async get(url, jwt) {
291
- const axios2 = this.createAxiosInstance(jwt);
291
+ async get(url, option) {
292
+ const axios2 = this.createAxiosInstance(option);
292
293
  const response = await axios2.get(url);
293
294
  return response;
294
295
  }
@@ -298,8 +299,8 @@ var CoreHttp = class {
298
299
  if (file instanceof Array) {
299
300
  const fileKeys = param1;
300
301
  const param = param2;
301
- const jwt = param3;
302
- const axios2 = this.createAxiosInstance(jwt);
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,8 +310,8 @@ var CoreHttp = class {
309
310
  response = await axios2.post(url, formData);
310
311
  } else {
311
312
  const param = param1;
312
- const jwt = param2;
313
- const axios2 = this.createAxiosInstance(jwt);
313
+ const opt = param2;
314
+ const axios2 = this.createAxiosInstance(opt);
314
315
  if (param) {
315
316
  formData.append("param", JSON.stringify(param));
316
317
  }
@@ -339,8 +340,7 @@ var cfg = {
339
340
  app: {
340
341
  redirectUrl: "/login",
341
342
  apiKey: "",
342
- timezone: "Asia/Bangkok",
343
- trackingId: ""
343
+ timezone: "Asia/Bangkok"
344
344
  }
345
345
  };
346
346
  function getConfig() {
package/dist/index.d.cts CHANGED
@@ -2,21 +2,24 @@ 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, jwt?: string): Promise<AxiosResponse<T>>;
10
- get<T>(url: string, jwt?: string): Promise<AxiosResponse<T>>;
11
- uploadFile<T>(url: string, file: File, param?: Record<string, any> | null, jwt?: string): Promise<AxiosResponse<T>>;
12
- uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, jwt?: string): 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
 
16
19
  interface AbbotConfig {
17
- axios?: {
18
- baseUrl?: string;
19
- headers?: {
20
+ axios: {
21
+ baseUrl: string;
22
+ headers: {
20
23
  accept?: string;
21
24
  lang?: string;
22
25
  post?: {
@@ -25,13 +28,15 @@ interface AbbotConfig {
25
28
  };
26
29
  timeout?: number;
27
30
  };
28
- app?: {
29
- redirectUrl?: string;
30
- apiKey?: string;
31
- timezone?: string;
31
+ app: {
32
+ redirectUrl: string;
33
+ apiKey: string;
34
+ timezone: string;
32
35
  trackingId?: string;
36
+ ecnKey?: string;
37
+ userJwt?: string;
33
38
  };
34
39
  }
35
- declare function create(config: AbbotConfig): CoreHttp;
40
+ declare function create(config: Partial<AbbotConfig>): CoreHttp;
36
41
 
37
42
  export { type AbbotConfig, catchError, create };
package/dist/index.d.ts CHANGED
@@ -2,21 +2,24 @@ 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, jwt?: string): Promise<AxiosResponse<T>>;
10
- get<T>(url: string, jwt?: string): Promise<AxiosResponse<T>>;
11
- uploadFile<T>(url: string, file: File, param?: Record<string, any> | null, jwt?: string): Promise<AxiosResponse<T>>;
12
- uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, jwt?: string): 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
 
16
19
  interface AbbotConfig {
17
- axios?: {
18
- baseUrl?: string;
19
- headers?: {
20
+ axios: {
21
+ baseUrl: string;
22
+ headers: {
20
23
  accept?: string;
21
24
  lang?: string;
22
25
  post?: {
@@ -25,13 +28,15 @@ interface AbbotConfig {
25
28
  };
26
29
  timeout?: number;
27
30
  };
28
- app?: {
29
- redirectUrl?: string;
30
- apiKey?: string;
31
- timezone?: string;
31
+ app: {
32
+ redirectUrl: string;
33
+ apiKey: string;
34
+ timezone: string;
32
35
  trackingId?: string;
36
+ ecnKey?: string;
37
+ userJwt?: string;
33
38
  };
34
39
  }
35
- declare function create(config: AbbotConfig): CoreHttp;
40
+ declare function create(config: Partial<AbbotConfig>): CoreHttp;
36
41
 
37
42
  export { type AbbotConfig, catchError, create };
package/dist/index.js CHANGED
@@ -127,11 +127,12 @@ var CoreHttp = class {
127
127
  constructor(config) {
128
128
  this.config = config;
129
129
  }
130
- createAxiosInstance(userJWT) {
130
+ createAxiosInstance(option) {
131
131
  const axios2 = axiosConf(this.config);
132
132
  const iv = Secure.createId();
133
133
  const cryp = new Cryp({
134
- iv
134
+ iv,
135
+ keyValue: option?.isInit ? this.config.app.ecnKey : void 0
135
136
  });
136
137
  axios2.interceptors.request.use(
137
138
  (config) => {
@@ -156,10 +157,10 @@ var CoreHttp = class {
156
157
  }
157
158
  req.headers.set("data-code", iv);
158
159
  if (this.config.app?.trackingId) {
159
- req.headers.set("X-Trace-Id", this.config.app.trackingId);
160
+ config.headers.set("X-Trace-Id", this.config.app.trackingId);
160
161
  }
161
- if (userJWT) {
162
- req.headers.setAuthorization(`Bearer ${userJWT}`);
162
+ if (this.config.app.userJwt) {
163
+ config.headers.setAuthorization(`Bearer ${this.config.app.userJwt}`);
163
164
  }
164
165
  return req;
165
166
  },
@@ -245,13 +246,13 @@ var CoreHttp = class {
245
246
  );
246
247
  return axios2;
247
248
  }
248
- async post(url, param, jwt) {
249
- const axios2 = this.createAxiosInstance(jwt);
249
+ async post(url, param, option) {
250
+ const axios2 = this.createAxiosInstance(option);
250
251
  const response = await axios2.post(url, param);
251
252
  return response;
252
253
  }
253
- async get(url, jwt) {
254
- const axios2 = this.createAxiosInstance(jwt);
254
+ async get(url, option) {
255
+ const axios2 = this.createAxiosInstance(option);
255
256
  const response = await axios2.get(url);
256
257
  return response;
257
258
  }
@@ -261,8 +262,8 @@ var CoreHttp = class {
261
262
  if (file instanceof Array) {
262
263
  const fileKeys = param1;
263
264
  const param = param2;
264
- const jwt = param3;
265
- const axios2 = this.createAxiosInstance(jwt);
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,8 +273,8 @@ var CoreHttp = class {
272
273
  response = await axios2.post(url, formData);
273
274
  } else {
274
275
  const param = param1;
275
- const jwt = param2;
276
- const axios2 = this.createAxiosInstance(jwt);
276
+ const opt = param2;
277
+ const axios2 = this.createAxiosInstance(opt);
277
278
  if (param) {
278
279
  formData.append("param", JSON.stringify(param));
279
280
  }
@@ -302,8 +303,7 @@ var cfg = {
302
303
  app: {
303
304
  redirectUrl: "/login",
304
305
  apiKey: "",
305
- timezone: "Asia/Bangkok",
306
- trackingId: ""
306
+ timezone: "Asia/Bangkok"
307
307
  }
308
308
  };
309
309
  function getConfig() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abbot-http-client",
3
- "version": "0.0.12",
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",