abbot-http-client 0.0.5 → 0.0.7

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 (user.trackingId) {
197
+ req.headers.set("X-Trace-Id", user.trackingId);
203
198
  }
204
199
  if (user.token) {
205
200
  req.headers.setAuthorization(`Bearer ${user.token}`);
@@ -377,8 +372,7 @@ var cfg = {
377
372
  app: {
378
373
  redirectUrl: "/login",
379
374
  apiKey: "",
380
- timezone: "Asia/Bangkok",
381
- allowTracking: false
375
+ timezone: "Asia/Bangkok"
382
376
  }
383
377
  };
384
378
  function getConfig() {
@@ -386,11 +380,7 @@ function getConfig() {
386
380
  }
387
381
  function create(config) {
388
382
  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);
383
+ const http = new CoreHttp(cfg);
394
384
  return http;
395
385
  }
396
386
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.d.cts CHANGED
@@ -5,11 +5,11 @@ declare function catchError<T, E extends new (err?: any) => Error>(promise: Prom
5
5
  interface credential {
6
6
  key: string | undefined;
7
7
  token: string | undefined;
8
+ trackingId?: string;
8
9
  }
9
10
  declare class CoreHttp {
10
11
  private config;
11
- private uuid;
12
- constructor(config: AbbotConfig, uuid: string);
12
+ constructor(config: AbbotConfig);
13
13
  private createAxiosInstance;
14
14
  post<T, U extends credential = credential>(middleware: () => U | null, url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
15
15
  post<T, U extends credential = credential>(user: U | null, url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
@@ -38,7 +38,6 @@ interface AbbotConfig {
38
38
  redirectUrl?: string;
39
39
  apiKey?: string;
40
40
  timezone?: string;
41
- allowTracking?: boolean;
42
41
  };
43
42
  }
44
43
  declare function create(config: AbbotConfig): CoreHttp;
package/dist/index.d.ts CHANGED
@@ -5,11 +5,11 @@ declare function catchError<T, E extends new (err?: any) => Error>(promise: Prom
5
5
  interface credential {
6
6
  key: string | undefined;
7
7
  token: string | undefined;
8
+ trackingId?: string;
8
9
  }
9
10
  declare class CoreHttp {
10
11
  private config;
11
- private uuid;
12
- constructor(config: AbbotConfig, uuid: string);
12
+ constructor(config: AbbotConfig);
13
13
  private createAxiosInstance;
14
14
  post<T, U extends credential = credential>(middleware: () => U | null, url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
15
15
  post<T, U extends credential = credential>(user: U | null, url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
@@ -38,7 +38,6 @@ interface AbbotConfig {
38
38
  redirectUrl?: string;
39
39
  apiKey?: string;
40
40
  timezone?: string;
41
- allowTracking?: boolean;
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 (user.trackingId) {
160
+ req.headers.set("X-Trace-Id", user.trackingId);
166
161
  }
167
162
  if (user.token) {
168
163
  req.headers.setAuthorization(`Bearer ${user.token}`);
@@ -340,8 +335,7 @@ var cfg = {
340
335
  app: {
341
336
  redirectUrl: "/login",
342
337
  apiKey: "",
343
- timezone: "Asia/Bangkok",
344
- allowTracking: false
338
+ timezone: "Asia/Bangkok"
345
339
  }
346
340
  };
347
341
  function getConfig() {
@@ -349,11 +343,7 @@ function getConfig() {
349
343
  }
350
344
  function create(config) {
351
345
  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);
346
+ const http = new CoreHttp(cfg);
357
347
  return http;
358
348
  }
359
349
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abbot-http-client",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
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",