abbot-http-client 0.0.2 → 0.0.4
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 +21 -7
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +20 -5
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -31,8 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
catchError: () => catchError,
|
|
34
|
-
create: () => create
|
|
35
|
-
getConfig: () => getConfig
|
|
34
|
+
create: () => create
|
|
36
35
|
});
|
|
37
36
|
module.exports = __toCommonJS(index_exports);
|
|
38
37
|
|
|
@@ -45,6 +44,9 @@ async function catchError(promise, errorToCatch) {
|
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
46
|
|
|
47
|
+
// src/config/core.ts
|
|
48
|
+
var import_crypto = require("crypto");
|
|
49
|
+
|
|
48
50
|
// src/http.ts
|
|
49
51
|
var import_axios2 = require("axios");
|
|
50
52
|
|
|
@@ -162,8 +164,10 @@ function axiosConf(cfg2) {
|
|
|
162
164
|
// src/http.ts
|
|
163
165
|
var CoreHttp = class {
|
|
164
166
|
config;
|
|
165
|
-
|
|
167
|
+
uuid;
|
|
168
|
+
constructor(config, uuid) {
|
|
166
169
|
this.config = config;
|
|
170
|
+
this.uuid = uuid;
|
|
167
171
|
}
|
|
168
172
|
createAxiosInstance(user) {
|
|
169
173
|
const axios2 = axiosConf(this.config);
|
|
@@ -194,6 +198,9 @@ var CoreHttp = class {
|
|
|
194
198
|
}
|
|
195
199
|
}
|
|
196
200
|
req.headers.set("data-code", iv);
|
|
201
|
+
if (this.config.app?.allowTracking) {
|
|
202
|
+
req.headers.set("X-Trace-Id", this.uuid);
|
|
203
|
+
}
|
|
197
204
|
if (user.token) {
|
|
198
205
|
req.headers.setAuthorization(`Bearer ${user.token}`);
|
|
199
206
|
}
|
|
@@ -349,6 +356,9 @@ var CoreHttp = class {
|
|
|
349
356
|
const response = await axios2.post(url, formData);
|
|
350
357
|
return response;
|
|
351
358
|
}
|
|
359
|
+
getConfig() {
|
|
360
|
+
return this.config;
|
|
361
|
+
}
|
|
352
362
|
};
|
|
353
363
|
|
|
354
364
|
// src/config/core.ts
|
|
@@ -367,7 +377,8 @@ var cfg = {
|
|
|
367
377
|
app: {
|
|
368
378
|
redirectUrl: "/login",
|
|
369
379
|
apiKey: "",
|
|
370
|
-
timezone: "Asia/Bangkok"
|
|
380
|
+
timezone: "Asia/Bangkok",
|
|
381
|
+
allowTracking: false
|
|
371
382
|
}
|
|
372
383
|
};
|
|
373
384
|
function getConfig() {
|
|
@@ -375,12 +386,15 @@ function getConfig() {
|
|
|
375
386
|
}
|
|
376
387
|
function create(config) {
|
|
377
388
|
cfg = { ...cfg, ...config };
|
|
378
|
-
|
|
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);
|
|
379
394
|
return http;
|
|
380
395
|
}
|
|
381
396
|
// Annotate the CommonJS export names for ESM import in node:
|
|
382
397
|
0 && (module.exports = {
|
|
383
398
|
catchError,
|
|
384
|
-
create
|
|
385
|
-
getConfig
|
|
399
|
+
create
|
|
386
400
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -8,7 +8,8 @@ interface credential {
|
|
|
8
8
|
}
|
|
9
9
|
declare class CoreHttp {
|
|
10
10
|
private config;
|
|
11
|
-
|
|
11
|
+
private uuid;
|
|
12
|
+
constructor(config: AbbotConfig, uuid: string);
|
|
12
13
|
private createAxiosInstance;
|
|
13
14
|
post<T, U extends credential = credential>(middleware: () => U | null, url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
14
15
|
post<T, U extends credential = credential>(user: U | null, url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
@@ -18,6 +19,7 @@ declare class CoreHttp {
|
|
|
18
19
|
uploadFile<T, U extends credential = credential>(middleware: () => U | null, url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
19
20
|
uploadFile<T, U extends credential = credential>(user: U | null, url: string, file: File, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
20
21
|
uploadFile<T, U extends credential = credential>(user: U | null, url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
22
|
+
getConfig(): AbbotConfig;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
interface AbbotConfig {
|
|
@@ -36,9 +38,9 @@ interface AbbotConfig {
|
|
|
36
38
|
redirectUrl?: string;
|
|
37
39
|
apiKey?: string;
|
|
38
40
|
timezone?: string;
|
|
41
|
+
allowTracking?: boolean;
|
|
39
42
|
};
|
|
40
43
|
}
|
|
41
|
-
declare function getConfig(): AbbotConfig;
|
|
42
44
|
declare function create(config: AbbotConfig): CoreHttp;
|
|
43
45
|
|
|
44
|
-
export { type AbbotConfig, catchError, create
|
|
46
|
+
export { type AbbotConfig, catchError, create };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ interface credential {
|
|
|
8
8
|
}
|
|
9
9
|
declare class CoreHttp {
|
|
10
10
|
private config;
|
|
11
|
-
|
|
11
|
+
private uuid;
|
|
12
|
+
constructor(config: AbbotConfig, uuid: string);
|
|
12
13
|
private createAxiosInstance;
|
|
13
14
|
post<T, U extends credential = credential>(middleware: () => U | null, url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
14
15
|
post<T, U extends credential = credential>(user: U | null, url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
@@ -18,6 +19,7 @@ declare class CoreHttp {
|
|
|
18
19
|
uploadFile<T, U extends credential = credential>(middleware: () => U | null, url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
19
20
|
uploadFile<T, U extends credential = credential>(user: U | null, url: string, file: File, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
20
21
|
uploadFile<T, U extends credential = credential>(user: U | null, url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
22
|
+
getConfig(): AbbotConfig;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
interface AbbotConfig {
|
|
@@ -36,9 +38,9 @@ interface AbbotConfig {
|
|
|
36
38
|
redirectUrl?: string;
|
|
37
39
|
apiKey?: string;
|
|
38
40
|
timezone?: string;
|
|
41
|
+
allowTracking?: boolean;
|
|
39
42
|
};
|
|
40
43
|
}
|
|
41
|
-
declare function getConfig(): AbbotConfig;
|
|
42
44
|
declare function create(config: AbbotConfig): CoreHttp;
|
|
43
45
|
|
|
44
|
-
export { type AbbotConfig, catchError, create
|
|
46
|
+
export { type AbbotConfig, catchError, create };
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,9 @@ async function catchError(promise, errorToCatch) {
|
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
// src/config/core.ts
|
|
11
|
+
import { randomUUID } from "crypto";
|
|
12
|
+
|
|
10
13
|
// src/http.ts
|
|
11
14
|
import { AxiosError } from "axios";
|
|
12
15
|
|
|
@@ -124,8 +127,10 @@ function axiosConf(cfg2) {
|
|
|
124
127
|
// src/http.ts
|
|
125
128
|
var CoreHttp = class {
|
|
126
129
|
config;
|
|
127
|
-
|
|
130
|
+
uuid;
|
|
131
|
+
constructor(config, uuid) {
|
|
128
132
|
this.config = config;
|
|
133
|
+
this.uuid = uuid;
|
|
129
134
|
}
|
|
130
135
|
createAxiosInstance(user) {
|
|
131
136
|
const axios2 = axiosConf(this.config);
|
|
@@ -156,6 +161,9 @@ var CoreHttp = class {
|
|
|
156
161
|
}
|
|
157
162
|
}
|
|
158
163
|
req.headers.set("data-code", iv);
|
|
164
|
+
if (this.config.app?.allowTracking) {
|
|
165
|
+
req.headers.set("X-Trace-Id", this.uuid);
|
|
166
|
+
}
|
|
159
167
|
if (user.token) {
|
|
160
168
|
req.headers.setAuthorization(`Bearer ${user.token}`);
|
|
161
169
|
}
|
|
@@ -311,6 +319,9 @@ var CoreHttp = class {
|
|
|
311
319
|
const response = await axios2.post(url, formData);
|
|
312
320
|
return response;
|
|
313
321
|
}
|
|
322
|
+
getConfig() {
|
|
323
|
+
return this.config;
|
|
324
|
+
}
|
|
314
325
|
};
|
|
315
326
|
|
|
316
327
|
// src/config/core.ts
|
|
@@ -329,7 +340,8 @@ var cfg = {
|
|
|
329
340
|
app: {
|
|
330
341
|
redirectUrl: "/login",
|
|
331
342
|
apiKey: "",
|
|
332
|
-
timezone: "Asia/Bangkok"
|
|
343
|
+
timezone: "Asia/Bangkok",
|
|
344
|
+
allowTracking: false
|
|
333
345
|
}
|
|
334
346
|
};
|
|
335
347
|
function getConfig() {
|
|
@@ -337,11 +349,14 @@ function getConfig() {
|
|
|
337
349
|
}
|
|
338
350
|
function create(config) {
|
|
339
351
|
cfg = { ...cfg, ...config };
|
|
340
|
-
|
|
352
|
+
let uuid = "";
|
|
353
|
+
if (cfg.app?.allowTracking) {
|
|
354
|
+
uuid = randomUUID().split("-").slice(-2).join("");
|
|
355
|
+
}
|
|
356
|
+
const http = new CoreHttp(cfg, uuid);
|
|
341
357
|
return http;
|
|
342
358
|
}
|
|
343
359
|
export {
|
|
344
360
|
catchError,
|
|
345
|
-
create
|
|
346
|
-
getConfig
|
|
361
|
+
create
|
|
347
362
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "abbot-http-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
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",
|
|
@@ -17,18 +17,18 @@
|
|
|
17
17
|
"author": "Sahasawat",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@types/node": "^24.0.
|
|
20
|
+
"@types/node": "^24.0.14",
|
|
21
21
|
"axios": "^1.10.0",
|
|
22
22
|
"crypto-ts": "^1.0.2",
|
|
23
23
|
"ts-node": "^10.9.2",
|
|
24
24
|
"typescript": "^5.8.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@eslint/js": "^9.
|
|
28
|
-
"@eslint/json": "^0.
|
|
29
|
-
"eslint": "^9.
|
|
30
|
-
"globals": "^16.
|
|
27
|
+
"@eslint/js": "^9.31.0",
|
|
28
|
+
"@eslint/json": "^0.13.0",
|
|
29
|
+
"eslint": "^9.31.0",
|
|
30
|
+
"globals": "^16.3.0",
|
|
31
31
|
"tsup": "^8.5.0",
|
|
32
|
-
"typescript-eslint": "^8.
|
|
32
|
+
"typescript-eslint": "^8.37.0"
|
|
33
33
|
}
|
|
34
34
|
}
|