abbot-http-client 0.0.3 → 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 +16 -3
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +16 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -44,6 +44,9 @@ async function catchError(promise, errorToCatch) {
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// src/config/core.ts
|
|
48
|
+
var import_crypto = require("crypto");
|
|
49
|
+
|
|
47
50
|
// src/http.ts
|
|
48
51
|
var import_axios2 = require("axios");
|
|
49
52
|
|
|
@@ -161,8 +164,10 @@ function axiosConf(cfg2) {
|
|
|
161
164
|
// src/http.ts
|
|
162
165
|
var CoreHttp = class {
|
|
163
166
|
config;
|
|
164
|
-
|
|
167
|
+
uuid;
|
|
168
|
+
constructor(config, uuid) {
|
|
165
169
|
this.config = config;
|
|
170
|
+
this.uuid = uuid;
|
|
166
171
|
}
|
|
167
172
|
createAxiosInstance(user) {
|
|
168
173
|
const axios2 = axiosConf(this.config);
|
|
@@ -193,6 +198,9 @@ var CoreHttp = class {
|
|
|
193
198
|
}
|
|
194
199
|
}
|
|
195
200
|
req.headers.set("data-code", iv);
|
|
201
|
+
if (this.config.app?.allowTracking) {
|
|
202
|
+
req.headers.set("X-Trace-Id", this.uuid);
|
|
203
|
+
}
|
|
196
204
|
if (user.token) {
|
|
197
205
|
req.headers.setAuthorization(`Bearer ${user.token}`);
|
|
198
206
|
}
|
|
@@ -369,7 +377,8 @@ var cfg = {
|
|
|
369
377
|
app: {
|
|
370
378
|
redirectUrl: "/login",
|
|
371
379
|
apiKey: "",
|
|
372
|
-
timezone: "Asia/Bangkok"
|
|
380
|
+
timezone: "Asia/Bangkok",
|
|
381
|
+
allowTracking: false
|
|
373
382
|
}
|
|
374
383
|
};
|
|
375
384
|
function getConfig() {
|
|
@@ -377,7 +386,11 @@ function getConfig() {
|
|
|
377
386
|
}
|
|
378
387
|
function create(config) {
|
|
379
388
|
cfg = { ...cfg, ...config };
|
|
380
|
-
|
|
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);
|
|
381
394
|
return http;
|
|
382
395
|
}
|
|
383
396
|
// Annotate the CommonJS export names for ESM import in node:
|
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>>;
|
|
@@ -37,6 +38,7 @@ interface AbbotConfig {
|
|
|
37
38
|
redirectUrl?: string;
|
|
38
39
|
apiKey?: string;
|
|
39
40
|
timezone?: string;
|
|
41
|
+
allowTracking?: boolean;
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
44
|
declare function create(config: AbbotConfig): CoreHttp;
|
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>>;
|
|
@@ -37,6 +38,7 @@ interface AbbotConfig {
|
|
|
37
38
|
redirectUrl?: string;
|
|
38
39
|
apiKey?: string;
|
|
39
40
|
timezone?: string;
|
|
41
|
+
allowTracking?: boolean;
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
44
|
declare function create(config: AbbotConfig): CoreHttp;
|
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
|
}
|
|
@@ -332,7 +340,8 @@ var cfg = {
|
|
|
332
340
|
app: {
|
|
333
341
|
redirectUrl: "/login",
|
|
334
342
|
apiKey: "",
|
|
335
|
-
timezone: "Asia/Bangkok"
|
|
343
|
+
timezone: "Asia/Bangkok",
|
|
344
|
+
allowTracking: false
|
|
336
345
|
}
|
|
337
346
|
};
|
|
338
347
|
function getConfig() {
|
|
@@ -340,7 +349,11 @@ function getConfig() {
|
|
|
340
349
|
}
|
|
341
350
|
function create(config) {
|
|
342
351
|
cfg = { ...cfg, ...config };
|
|
343
|
-
|
|
352
|
+
let uuid = "";
|
|
353
|
+
if (cfg.app?.allowTracking) {
|
|
354
|
+
uuid = randomUUID().split("-").slice(-2).join("");
|
|
355
|
+
}
|
|
356
|
+
const http = new CoreHttp(cfg, uuid);
|
|
344
357
|
return http;
|
|
345
358
|
}
|
|
346
359
|
export {
|