abbot-http-client 0.0.4 → 0.0.6

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
@@ -44,9 +44,6 @@ async function catchError(promise, errorToCatch) {
44
44
  });
45
45
  }
46
46
 
47
- // src/config/core.ts
48
- var import_crypto = require("crypto");
49
-
50
47
  // src/http.ts
51
48
  var import_axios2 = require("axios");
52
49
 
@@ -164,10 +161,8 @@ function axiosConf(cfg2) {
164
161
  // src/http.ts
165
162
  var CoreHttp = class {
166
163
  config;
167
- uuid;
168
- constructor(config, uuid) {
164
+ constructor(config) {
169
165
  this.config = config;
170
- this.uuid = uuid;
171
166
  }
172
167
  createAxiosInstance(user) {
173
168
  const axios2 = axiosConf(this.config);
@@ -198,8 +193,8 @@ var CoreHttp = class {
198
193
  }
199
194
  }
200
195
  req.headers.set("data-code", iv);
201
- if (this.config.app?.allowTracking) {
202
- req.headers.set("X-Trace-Id", this.uuid);
196
+ if (this.config.app?.trackingId) {
197
+ req.headers.set("X-Trace-Id", this.config.app.trackingId);
203
198
  }
204
199
  if (user.token) {
205
200
  req.headers.setAuthorization(`Bearer ${user.token}`);
@@ -378,7 +373,7 @@ var cfg = {
378
373
  redirectUrl: "/login",
379
374
  apiKey: "",
380
375
  timezone: "Asia/Bangkok",
381
- allowTracking: false
376
+ trackingId: ""
382
377
  }
383
378
  };
384
379
  function getConfig() {
@@ -386,11 +381,7 @@ function getConfig() {
386
381
  }
387
382
  function create(config) {
388
383
  cfg = { ...cfg, ...config };
389
- let uuid = "";
390
- if (cfg.app?.allowTracking) {
391
- uuid = (0, import_crypto.randomUUID)().split("-").slice(-2).join("");
392
- }
393
- const http = new CoreHttp(cfg, uuid);
384
+ const http = new CoreHttp(cfg);
394
385
  return http;
395
386
  }
396
387
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.d.cts CHANGED
@@ -8,8 +8,7 @@ interface credential {
8
8
  }
9
9
  declare class CoreHttp {
10
10
  private config;
11
- private uuid;
12
- constructor(config: AbbotConfig, uuid: string);
11
+ constructor(config: AbbotConfig);
13
12
  private createAxiosInstance;
14
13
  post<T, U extends credential = credential>(middleware: () => U | null, url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
15
14
  post<T, U extends credential = credential>(user: U | null, url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
@@ -38,7 +37,7 @@ interface AbbotConfig {
38
37
  redirectUrl?: string;
39
38
  apiKey?: string;
40
39
  timezone?: string;
41
- allowTracking?: boolean;
40
+ trackingId?: string;
42
41
  };
43
42
  }
44
43
  declare function create(config: AbbotConfig): CoreHttp;
package/dist/index.d.ts CHANGED
@@ -8,8 +8,7 @@ interface credential {
8
8
  }
9
9
  declare class CoreHttp {
10
10
  private config;
11
- private uuid;
12
- constructor(config: AbbotConfig, uuid: string);
11
+ constructor(config: AbbotConfig);
13
12
  private createAxiosInstance;
14
13
  post<T, U extends credential = credential>(middleware: () => U | null, url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
15
14
  post<T, U extends credential = credential>(user: U | null, url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
@@ -38,7 +37,7 @@ interface AbbotConfig {
38
37
  redirectUrl?: string;
39
38
  apiKey?: string;
40
39
  timezone?: string;
41
- allowTracking?: boolean;
40
+ trackingId?: string;
42
41
  };
43
42
  }
44
43
  declare function create(config: AbbotConfig): CoreHttp;
package/dist/index.js CHANGED
@@ -7,9 +7,6 @@ async function catchError(promise, errorToCatch) {
7
7
  });
8
8
  }
9
9
 
10
- // src/config/core.ts
11
- import { randomUUID } from "crypto";
12
-
13
10
  // src/http.ts
14
11
  import { AxiosError } from "axios";
15
12
 
@@ -127,10 +124,8 @@ function axiosConf(cfg2) {
127
124
  // src/http.ts
128
125
  var CoreHttp = class {
129
126
  config;
130
- uuid;
131
- constructor(config, uuid) {
127
+ constructor(config) {
132
128
  this.config = config;
133
- this.uuid = uuid;
134
129
  }
135
130
  createAxiosInstance(user) {
136
131
  const axios2 = axiosConf(this.config);
@@ -161,8 +156,8 @@ var CoreHttp = class {
161
156
  }
162
157
  }
163
158
  req.headers.set("data-code", iv);
164
- if (this.config.app?.allowTracking) {
165
- req.headers.set("X-Trace-Id", this.uuid);
159
+ if (this.config.app?.trackingId) {
160
+ req.headers.set("X-Trace-Id", this.config.app.trackingId);
166
161
  }
167
162
  if (user.token) {
168
163
  req.headers.setAuthorization(`Bearer ${user.token}`);
@@ -341,7 +336,7 @@ var cfg = {
341
336
  redirectUrl: "/login",
342
337
  apiKey: "",
343
338
  timezone: "Asia/Bangkok",
344
- allowTracking: false
339
+ trackingId: ""
345
340
  }
346
341
  };
347
342
  function getConfig() {
@@ -349,11 +344,7 @@ function getConfig() {
349
344
  }
350
345
  function create(config) {
351
346
  cfg = { ...cfg, ...config };
352
- let uuid = "";
353
- if (cfg.app?.allowTracking) {
354
- uuid = randomUUID().split("-").slice(-2).join("");
355
- }
356
- const http = new CoreHttp(cfg, uuid);
347
+ const http = new CoreHttp(cfg);
357
348
  return http;
358
349
  }
359
350
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abbot-http-client",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
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",