@xrystal/core 3.9.4 → 3.9.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/package.json
CHANGED
|
@@ -7,6 +7,7 @@ export default class ConfigsService {
|
|
|
7
7
|
this._systemService = systemService;
|
|
8
8
|
const rawConfigs = tmp?.configs || tmp?.configs || {};
|
|
9
9
|
this.config = {
|
|
10
|
+
debug: process.env.SYSTEM_LOGGER_LAYER,
|
|
10
11
|
rootFolderPath: rawConfigs.rootFolderPath || 'x',
|
|
11
12
|
projectName: tmp.project.name,
|
|
12
13
|
serviceName: rawConfigs.service,
|
|
@@ -11,6 +11,7 @@ export declare abstract class Client {
|
|
|
11
11
|
protected baseURL: string;
|
|
12
12
|
protected version: string | null;
|
|
13
13
|
protected timeout: number;
|
|
14
|
+
protected debug: boolean;
|
|
14
15
|
protected authConfigs: any;
|
|
15
16
|
protected breaker: {
|
|
16
17
|
failures: number;
|
|
@@ -19,7 +20,7 @@ export declare abstract class Client {
|
|
|
19
20
|
threshold: number;
|
|
20
21
|
cooldown: number;
|
|
21
22
|
};
|
|
22
|
-
constructor({ clientName, baseURL, version, timeout, auth }: any);
|
|
23
|
+
constructor({ clientName, baseURL, version, timeout, auth, debug }: any);
|
|
23
24
|
protected resolvePath(obj: any, path: string): any;
|
|
24
25
|
static cryptoHashGenerate: ({ algorithm, input, digest }: {
|
|
25
26
|
algorithm: string;
|
|
@@ -32,6 +33,7 @@ export declare class BaseApiClient extends Client {
|
|
|
32
33
|
request(path: string, options?: RequestInit & {
|
|
33
34
|
version?: string;
|
|
34
35
|
retries?: number;
|
|
36
|
+
debug?: boolean;
|
|
35
37
|
}): Promise<Response>;
|
|
36
38
|
private _execute;
|
|
37
39
|
}
|
|
@@ -41,6 +43,7 @@ export declare abstract class AuthenticatedApiClient extends BaseApiClient {
|
|
|
41
43
|
request(path: string, options?: RequestInit & {
|
|
42
44
|
version?: string;
|
|
43
45
|
retries?: number;
|
|
46
|
+
debug?: boolean;
|
|
44
47
|
}): Promise<Response>;
|
|
45
48
|
private _synchronizedAuthentication;
|
|
46
49
|
private internalLogin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash, createHmac } from 'node:crypto';
|
|
2
2
|
import soap from 'soap';
|
|
3
3
|
import { ConfigsService, LoggerService } from '../../../loader';
|
|
4
|
-
import { x } from '../../index';
|
|
4
|
+
import { LoggerLayerEnum, x } from '../../index';
|
|
5
5
|
export class ClientStore {
|
|
6
6
|
static _store = {};
|
|
7
7
|
static get(clientName) { return this._store[clientName] || {}; }
|
|
@@ -16,6 +16,7 @@ export class Client {
|
|
|
16
16
|
baseURL;
|
|
17
17
|
version = null;
|
|
18
18
|
timeout = 15000;
|
|
19
|
+
debug = Number(this.configService.all.debug) >= LoggerLayerEnum.DEBUG;
|
|
19
20
|
authConfigs;
|
|
20
21
|
breaker = {
|
|
21
22
|
failures: 0,
|
|
@@ -24,11 +25,12 @@ export class Client {
|
|
|
24
25
|
threshold: 5,
|
|
25
26
|
cooldown: 30000
|
|
26
27
|
};
|
|
27
|
-
constructor({ clientName, baseURL, version, timeout, auth }) {
|
|
28
|
+
constructor({ clientName, baseURL, version, timeout, auth, debug }) {
|
|
28
29
|
this.clientName = clientName;
|
|
29
30
|
this.baseURL = baseURL;
|
|
30
31
|
this.version = version || null;
|
|
31
32
|
this.authConfigs = auth;
|
|
33
|
+
this.debug = debug ?? this.debug;
|
|
32
34
|
if (timeout)
|
|
33
35
|
this.timeout = timeout;
|
|
34
36
|
if (auth?.token)
|
|
@@ -71,9 +73,8 @@ export class BaseApiClient extends Client {
|
|
|
71
73
|
attempt++;
|
|
72
74
|
this.breaker.failures++;
|
|
73
75
|
this.breaker.lastFailure = Date.now();
|
|
74
|
-
if (this.breaker.failures >= this.breaker.threshold)
|
|
76
|
+
if (this.breaker.failures >= this.breaker.threshold)
|
|
75
77
|
this.breaker.state = 'OPEN';
|
|
76
|
-
}
|
|
77
78
|
if (attempt >= maxRetries)
|
|
78
79
|
throw error;
|
|
79
80
|
const backoff = Math.pow(2, attempt) * 500;
|
|
@@ -103,9 +104,18 @@ export class BaseApiClient extends Client {
|
|
|
103
104
|
headers.set('x-internal-timestamp', timestamp);
|
|
104
105
|
headers.set('x-internal-client', this.clientName);
|
|
105
106
|
}
|
|
107
|
+
const isDebugMode = options.debug !== undefined ? options.debug : this.debug;
|
|
108
|
+
if (isDebugMode) {
|
|
109
|
+
this.logger.winston.info(`${this.clientName} Request Details`, {
|
|
110
|
+
method: options.method || 'GET',
|
|
111
|
+
url,
|
|
112
|
+
headers: Object.fromEntries(headers.entries()),
|
|
113
|
+
body: options.body ? (typeof options.body === 'string' ? JSON.parse(options.body) : 'Data') : null
|
|
114
|
+
});
|
|
115
|
+
}
|
|
106
116
|
const controller = new AbortController();
|
|
107
117
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
108
|
-
const { version, retries, ...fetchOptions } = options;
|
|
118
|
+
const { version, retries, debug, ...fetchOptions } = options;
|
|
109
119
|
const response = await fetch(url, { ...fetchOptions, headers, signal: controller.signal });
|
|
110
120
|
clearTimeout(timeoutId);
|
|
111
121
|
return response;
|