phenoml 6.1.0 → 6.2.0
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/cjs/BaseClient.d.ts +2 -0
- package/dist/cjs/Client.js +3 -3
- package/dist/cjs/api/resources/agent/client/Client.js +8 -0
- package/dist/cjs/api/resources/agent/resources/prompts/client/Client.js +7 -0
- package/dist/cjs/api/resources/cohort/client/Client.js +1 -0
- package/dist/cjs/api/resources/construe/client/Client.js +10 -0
- package/dist/cjs/api/resources/fhir/client/Client.js +6 -0
- package/dist/cjs/api/resources/fhirProvider/client/Client.js +7 -0
- package/dist/cjs/api/resources/lang2Fhir/client/Client.js +5 -0
- package/dist/cjs/api/resources/summary/client/Client.js +6 -0
- package/dist/cjs/api/resources/tools/client/Client.js +4 -0
- package/dist/cjs/api/resources/tools/resources/mcpServer/client/Client.js +4 -0
- package/dist/cjs/api/resources/tools/resources/mcpServer/resources/tools/client/Client.js +4 -0
- package/dist/cjs/api/resources/workflows/client/Client.js +6 -0
- package/dist/cjs/core/exports.d.ts +1 -0
- package/dist/cjs/core/exports.js +17 -0
- package/dist/cjs/core/fetcher/Fetcher.d.ts +2 -0
- package/dist/cjs/core/fetcher/Fetcher.js +177 -1
- package/dist/cjs/core/index.d.ts +1 -0
- package/dist/cjs/core/index.js +2 -1
- package/dist/cjs/core/logging/exports.d.ts +18 -0
- package/dist/cjs/core/logging/exports.js +45 -0
- package/dist/cjs/core/logging/index.d.ts +1 -0
- package/dist/cjs/core/logging/index.js +17 -0
- package/dist/cjs/core/logging/logger.d.ts +126 -0
- package/dist/cjs/core/logging/logger.js +144 -0
- package/dist/cjs/exports.d.ts +1 -0
- package/dist/cjs/exports.js +17 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.d.mts +2 -0
- package/dist/esm/Client.mjs +3 -3
- package/dist/esm/api/resources/agent/client/Client.mjs +8 -0
- package/dist/esm/api/resources/agent/resources/prompts/client/Client.mjs +7 -0
- package/dist/esm/api/resources/cohort/client/Client.mjs +1 -0
- package/dist/esm/api/resources/construe/client/Client.mjs +10 -0
- package/dist/esm/api/resources/fhir/client/Client.mjs +6 -0
- package/dist/esm/api/resources/fhirProvider/client/Client.mjs +7 -0
- package/dist/esm/api/resources/lang2Fhir/client/Client.mjs +5 -0
- package/dist/esm/api/resources/summary/client/Client.mjs +6 -0
- package/dist/esm/api/resources/tools/client/Client.mjs +4 -0
- package/dist/esm/api/resources/tools/resources/mcpServer/client/Client.mjs +4 -0
- package/dist/esm/api/resources/tools/resources/mcpServer/resources/tools/client/Client.mjs +4 -0
- package/dist/esm/api/resources/workflows/client/Client.mjs +6 -0
- package/dist/esm/core/exports.d.mts +1 -0
- package/dist/esm/core/exports.mjs +1 -0
- package/dist/esm/core/fetcher/Fetcher.d.mts +2 -0
- package/dist/esm/core/fetcher/Fetcher.mjs +177 -1
- package/dist/esm/core/index.d.mts +1 -0
- package/dist/esm/core/index.mjs +1 -0
- package/dist/esm/core/logging/exports.d.mts +18 -0
- package/dist/esm/core/logging/exports.mjs +9 -0
- package/dist/esm/core/logging/index.d.mts +1 -0
- package/dist/esm/core/logging/index.mjs +1 -0
- package/dist/esm/core/logging/logger.d.mts +126 -0
- package/dist/esm/core/logging/logger.mjs +138 -0
- package/dist/esm/exports.d.mts +1 -0
- package/dist/esm/exports.mjs +1 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +2 -1
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { toJson } from "../json.mjs";
|
|
11
|
+
import { createLogger } from "../logging/logger.mjs";
|
|
11
12
|
import { createRequestUrl } from "./createRequestUrl.mjs";
|
|
12
13
|
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
13
14
|
import { getErrorResponseBody } from "./getErrorResponseBody.mjs";
|
|
@@ -17,6 +18,122 @@ import { getResponseBody } from "./getResponseBody.mjs";
|
|
|
17
18
|
import { makeRequest } from "./makeRequest.mjs";
|
|
18
19
|
import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
|
|
19
20
|
import { requestWithRetries } from "./requestWithRetries.mjs";
|
|
21
|
+
const SENSITIVE_HEADERS = new Set([
|
|
22
|
+
"authorization",
|
|
23
|
+
"x-api-key",
|
|
24
|
+
"api-key",
|
|
25
|
+
"x-auth-token",
|
|
26
|
+
"cookie",
|
|
27
|
+
"set-cookie",
|
|
28
|
+
"proxy-authorization",
|
|
29
|
+
"x-csrf-token",
|
|
30
|
+
"x-xsrf-token",
|
|
31
|
+
]);
|
|
32
|
+
function redactHeaders(headers) {
|
|
33
|
+
const filtered = {};
|
|
34
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
35
|
+
if (SENSITIVE_HEADERS.has(key.toLowerCase())) {
|
|
36
|
+
filtered[key] = "[REDACTED]";
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
filtered[key] = value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return filtered;
|
|
43
|
+
}
|
|
44
|
+
const SENSITIVE_QUERY_PARAMS = new Set([
|
|
45
|
+
"api_key",
|
|
46
|
+
"api-key",
|
|
47
|
+
"apikey",
|
|
48
|
+
"token",
|
|
49
|
+
"access_token",
|
|
50
|
+
"access-token",
|
|
51
|
+
"auth_token",
|
|
52
|
+
"auth-token",
|
|
53
|
+
"password",
|
|
54
|
+
"passwd",
|
|
55
|
+
"secret",
|
|
56
|
+
"api_secret",
|
|
57
|
+
"api-secret",
|
|
58
|
+
"apisecret",
|
|
59
|
+
"key",
|
|
60
|
+
"session",
|
|
61
|
+
"session_id",
|
|
62
|
+
"session-id",
|
|
63
|
+
]);
|
|
64
|
+
function redactQueryParameters(queryParameters) {
|
|
65
|
+
if (queryParameters == null) {
|
|
66
|
+
return queryParameters;
|
|
67
|
+
}
|
|
68
|
+
const redacted = {};
|
|
69
|
+
for (const [key, value] of Object.entries(queryParameters)) {
|
|
70
|
+
if (SENSITIVE_QUERY_PARAMS.has(key.toLowerCase())) {
|
|
71
|
+
redacted[key] = "[REDACTED]";
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
redacted[key] = value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return redacted;
|
|
78
|
+
}
|
|
79
|
+
function redactUrl(url) {
|
|
80
|
+
const protocolIndex = url.indexOf("://");
|
|
81
|
+
if (protocolIndex === -1)
|
|
82
|
+
return url;
|
|
83
|
+
const afterProtocol = protocolIndex + 3;
|
|
84
|
+
const atIndex = url.indexOf("@", afterProtocol);
|
|
85
|
+
if (atIndex !== -1) {
|
|
86
|
+
const pathStart = url.indexOf("/", afterProtocol);
|
|
87
|
+
const queryStart = url.indexOf("?", afterProtocol);
|
|
88
|
+
const fragmentStart = url.indexOf("#", afterProtocol);
|
|
89
|
+
const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
|
|
90
|
+
if (atIndex < firstDelimiter) {
|
|
91
|
+
url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const queryStart = url.indexOf("?");
|
|
95
|
+
if (queryStart === -1)
|
|
96
|
+
return url;
|
|
97
|
+
const fragmentStart = url.indexOf("#", queryStart);
|
|
98
|
+
const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
|
|
99
|
+
const queryString = url.slice(queryStart + 1, queryEnd);
|
|
100
|
+
if (queryString.length === 0)
|
|
101
|
+
return url;
|
|
102
|
+
// FAST PATH: Quick check if any sensitive keywords present
|
|
103
|
+
// Using indexOf is faster than regex for simple substring matching
|
|
104
|
+
const lower = queryString.toLowerCase();
|
|
105
|
+
const hasSensitive = lower.includes("token") || // catches token, access_token, auth_token, etc.
|
|
106
|
+
lower.includes("key") || // catches key, api_key, apikey, api-key, etc.
|
|
107
|
+
lower.includes("password") || // catches password
|
|
108
|
+
lower.includes("passwd") || // catches passwd
|
|
109
|
+
lower.includes("secret") || // catches secret, api_secret, etc.
|
|
110
|
+
lower.includes("session") || // catches session, session_id, session-id
|
|
111
|
+
lower.includes("auth"); // catches auth_token, auth-token, etc.
|
|
112
|
+
if (!hasSensitive) {
|
|
113
|
+
return url; // Early exit - no sensitive params
|
|
114
|
+
}
|
|
115
|
+
// SLOW PATH: Parse and redact
|
|
116
|
+
const redactedParams = [];
|
|
117
|
+
const params = queryString.split("&");
|
|
118
|
+
for (const param of params) {
|
|
119
|
+
const equalIndex = param.indexOf("=");
|
|
120
|
+
if (equalIndex === -1) {
|
|
121
|
+
redactedParams.push(param);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const key = param.slice(0, equalIndex);
|
|
125
|
+
let shouldRedact = SENSITIVE_QUERY_PARAMS.has(key.toLowerCase());
|
|
126
|
+
if (!shouldRedact && key.includes("%")) {
|
|
127
|
+
try {
|
|
128
|
+
const decodedKey = decodeURIComponent(key);
|
|
129
|
+
shouldRedact = SENSITIVE_QUERY_PARAMS.has(decodedKey.toLowerCase());
|
|
130
|
+
}
|
|
131
|
+
catch (_a) { }
|
|
132
|
+
}
|
|
133
|
+
redactedParams.push(shouldRedact ? `${key}=[REDACTED]` : param);
|
|
134
|
+
}
|
|
135
|
+
return url.slice(0, queryStart + 1) + redactedParams.join("&") + url.slice(queryEnd);
|
|
136
|
+
}
|
|
20
137
|
function getHeaders(args) {
|
|
21
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
139
|
var _a;
|
|
@@ -50,11 +167,31 @@ export function fetcherImpl(args) {
|
|
|
50
167
|
type: (_a = args.requestType) !== null && _a !== void 0 ? _a : "other",
|
|
51
168
|
});
|
|
52
169
|
const fetchFn = (_b = args.fetchFn) !== null && _b !== void 0 ? _b : (yield getFetchFn());
|
|
170
|
+
const headers = yield getHeaders(args);
|
|
171
|
+
const logger = createLogger(args.logging);
|
|
172
|
+
if (logger.isDebug()) {
|
|
173
|
+
const metadata = {
|
|
174
|
+
method: args.method,
|
|
175
|
+
url: redactUrl(url),
|
|
176
|
+
headers: redactHeaders(headers),
|
|
177
|
+
queryParameters: redactQueryParameters(args.queryParameters),
|
|
178
|
+
hasBody: requestBody != null,
|
|
179
|
+
};
|
|
180
|
+
logger.debug("Making HTTP request", metadata);
|
|
181
|
+
}
|
|
53
182
|
try {
|
|
54
183
|
const response = yield requestWithRetries(() => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
return makeRequest(fetchFn, url, args.method,
|
|
184
|
+
return makeRequest(fetchFn, url, args.method, headers, requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
|
|
56
185
|
}), args.maxRetries);
|
|
57
186
|
if (response.status >= 200 && response.status < 400) {
|
|
187
|
+
if (logger.isDebug()) {
|
|
188
|
+
const metadata = {
|
|
189
|
+
method: args.method,
|
|
190
|
+
url: redactUrl(url),
|
|
191
|
+
statusCode: response.status,
|
|
192
|
+
};
|
|
193
|
+
logger.debug("HTTP request succeeded", metadata);
|
|
194
|
+
}
|
|
58
195
|
return {
|
|
59
196
|
ok: true,
|
|
60
197
|
body: (yield getResponseBody(response, args.responseType)),
|
|
@@ -63,6 +200,14 @@ export function fetcherImpl(args) {
|
|
|
63
200
|
};
|
|
64
201
|
}
|
|
65
202
|
else {
|
|
203
|
+
if (logger.isError()) {
|
|
204
|
+
const metadata = {
|
|
205
|
+
method: args.method,
|
|
206
|
+
url: redactUrl(url),
|
|
207
|
+
statusCode: response.status,
|
|
208
|
+
};
|
|
209
|
+
logger.error("HTTP request failed with error status", metadata);
|
|
210
|
+
}
|
|
66
211
|
return {
|
|
67
212
|
ok: false,
|
|
68
213
|
error: {
|
|
@@ -76,6 +221,13 @@ export function fetcherImpl(args) {
|
|
|
76
221
|
}
|
|
77
222
|
catch (error) {
|
|
78
223
|
if ((_c = args.abortSignal) === null || _c === void 0 ? void 0 : _c.aborted) {
|
|
224
|
+
if (logger.isError()) {
|
|
225
|
+
const metadata = {
|
|
226
|
+
method: args.method,
|
|
227
|
+
url: redactUrl(url),
|
|
228
|
+
};
|
|
229
|
+
logger.error("HTTP request was aborted", metadata);
|
|
230
|
+
}
|
|
79
231
|
return {
|
|
80
232
|
ok: false,
|
|
81
233
|
error: {
|
|
@@ -86,6 +238,14 @@ export function fetcherImpl(args) {
|
|
|
86
238
|
};
|
|
87
239
|
}
|
|
88
240
|
else if (error instanceof Error && error.name === "AbortError") {
|
|
241
|
+
if (logger.isError()) {
|
|
242
|
+
const metadata = {
|
|
243
|
+
method: args.method,
|
|
244
|
+
url: redactUrl(url),
|
|
245
|
+
timeoutMs: args.timeoutMs,
|
|
246
|
+
};
|
|
247
|
+
logger.error("HTTP request timed out", metadata);
|
|
248
|
+
}
|
|
89
249
|
return {
|
|
90
250
|
ok: false,
|
|
91
251
|
error: {
|
|
@@ -95,6 +255,14 @@ export function fetcherImpl(args) {
|
|
|
95
255
|
};
|
|
96
256
|
}
|
|
97
257
|
else if (error instanceof Error) {
|
|
258
|
+
if (logger.isError()) {
|
|
259
|
+
const metadata = {
|
|
260
|
+
method: args.method,
|
|
261
|
+
url: redactUrl(url),
|
|
262
|
+
errorMessage: error.message,
|
|
263
|
+
};
|
|
264
|
+
logger.error("HTTP request failed with error", metadata);
|
|
265
|
+
}
|
|
98
266
|
return {
|
|
99
267
|
ok: false,
|
|
100
268
|
error: {
|
|
@@ -104,6 +272,14 @@ export function fetcherImpl(args) {
|
|
|
104
272
|
rawResponse: unknownRawResponse,
|
|
105
273
|
};
|
|
106
274
|
}
|
|
275
|
+
if (logger.isError()) {
|
|
276
|
+
const metadata = {
|
|
277
|
+
method: args.method,
|
|
278
|
+
url: redactUrl(url),
|
|
279
|
+
error: toJson(error),
|
|
280
|
+
};
|
|
281
|
+
logger.error("HTTP request failed with unknown error", metadata);
|
|
282
|
+
}
|
|
107
283
|
return {
|
|
108
284
|
ok: false,
|
|
109
285
|
error: {
|
package/dist/esm/core/index.mjs
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as logger from "./logger.mjs";
|
|
2
|
+
export declare namespace logging {
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for logger instances.
|
|
5
|
+
*/
|
|
6
|
+
type LogConfig = logger.LogConfig;
|
|
7
|
+
type LogLevel = logger.LogLevel;
|
|
8
|
+
const LogLevel: typeof logger.LogLevel;
|
|
9
|
+
type ILogger = logger.ILogger;
|
|
10
|
+
/**
|
|
11
|
+
* Console logger implementation that outputs to the console.
|
|
12
|
+
*/
|
|
13
|
+
type ConsoleLogger = logger.ConsoleLogger;
|
|
14
|
+
/**
|
|
15
|
+
* Console logger implementation that outputs to the console.
|
|
16
|
+
*/
|
|
17
|
+
const ConsoleLogger: typeof logger.ConsoleLogger;
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as logger from "./logger.mjs";
|
|
2
|
+
export var logging;
|
|
3
|
+
(function (logging) {
|
|
4
|
+
logging.LogLevel = logger.LogLevel;
|
|
5
|
+
/**
|
|
6
|
+
* Console logger implementation that outputs to the console.
|
|
7
|
+
*/
|
|
8
|
+
logging.ConsoleLogger = logger.ConsoleLogger;
|
|
9
|
+
})(logging || (logging = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./logger.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./logger.mjs";
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export declare const LogLevel: {
|
|
2
|
+
readonly Debug: "debug";
|
|
3
|
+
readonly Info: "info";
|
|
4
|
+
readonly Warn: "warn";
|
|
5
|
+
readonly Error: "error";
|
|
6
|
+
};
|
|
7
|
+
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
|
|
8
|
+
export interface ILogger {
|
|
9
|
+
/**
|
|
10
|
+
* Logs a debug message.
|
|
11
|
+
* @param message - The message to log
|
|
12
|
+
* @param args - Additional arguments to log
|
|
13
|
+
*/
|
|
14
|
+
debug(message: string, ...args: unknown[]): void;
|
|
15
|
+
/**
|
|
16
|
+
* Logs an info message.
|
|
17
|
+
* @param message - The message to log
|
|
18
|
+
* @param args - Additional arguments to log
|
|
19
|
+
*/
|
|
20
|
+
info(message: string, ...args: unknown[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Logs a warning message.
|
|
23
|
+
* @param message - The message to log
|
|
24
|
+
* @param args - Additional arguments to log
|
|
25
|
+
*/
|
|
26
|
+
warn(message: string, ...args: unknown[]): void;
|
|
27
|
+
/**
|
|
28
|
+
* Logs an error message.
|
|
29
|
+
* @param message - The message to log
|
|
30
|
+
* @param args - Additional arguments to log
|
|
31
|
+
*/
|
|
32
|
+
error(message: string, ...args: unknown[]): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Configuration for logger initialization.
|
|
36
|
+
*/
|
|
37
|
+
export interface LogConfig {
|
|
38
|
+
/**
|
|
39
|
+
* Minimum log level to output.
|
|
40
|
+
* @default LogLevel.Info
|
|
41
|
+
*/
|
|
42
|
+
level?: LogLevel;
|
|
43
|
+
/**
|
|
44
|
+
* Logger implementation to use.
|
|
45
|
+
* @default new ConsoleLogger()
|
|
46
|
+
*/
|
|
47
|
+
logger?: ILogger;
|
|
48
|
+
/**
|
|
49
|
+
* Whether logging should be silenced.
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
silent?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Default console-based logger implementation.
|
|
56
|
+
*/
|
|
57
|
+
export declare class ConsoleLogger implements ILogger {
|
|
58
|
+
debug(message: string, ...args: unknown[]): void;
|
|
59
|
+
info(message: string, ...args: unknown[]): void;
|
|
60
|
+
warn(message: string, ...args: unknown[]): void;
|
|
61
|
+
error(message: string, ...args: unknown[]): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Logger class that provides level-based logging functionality.
|
|
65
|
+
*/
|
|
66
|
+
export declare class Logger {
|
|
67
|
+
private readonly level;
|
|
68
|
+
private readonly logger;
|
|
69
|
+
private readonly silent;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new logger instance.
|
|
72
|
+
* @param config - Logger configuration
|
|
73
|
+
*/
|
|
74
|
+
constructor(config: Required<LogConfig>);
|
|
75
|
+
/**
|
|
76
|
+
* Checks if a log level should be output based on configuration.
|
|
77
|
+
* @param level - The log level to check
|
|
78
|
+
* @returns True if the level should be logged
|
|
79
|
+
*/
|
|
80
|
+
shouldLog(level: LogLevel): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Checks if debug logging is enabled.
|
|
83
|
+
* @returns True if debug logs should be output
|
|
84
|
+
*/
|
|
85
|
+
isDebug(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Logs a debug message if debug logging is enabled.
|
|
88
|
+
* @param message - The message to log
|
|
89
|
+
* @param args - Additional arguments to log
|
|
90
|
+
*/
|
|
91
|
+
debug(message: string, ...args: unknown[]): void;
|
|
92
|
+
/**
|
|
93
|
+
* Checks if info logging is enabled.
|
|
94
|
+
* @returns True if info logs should be output
|
|
95
|
+
*/
|
|
96
|
+
isInfo(): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Logs an info message if info logging is enabled.
|
|
99
|
+
* @param message - The message to log
|
|
100
|
+
* @param args - Additional arguments to log
|
|
101
|
+
*/
|
|
102
|
+
info(message: string, ...args: unknown[]): void;
|
|
103
|
+
/**
|
|
104
|
+
* Checks if warning logging is enabled.
|
|
105
|
+
* @returns True if warning logs should be output
|
|
106
|
+
*/
|
|
107
|
+
isWarn(): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Logs a warning message if warning logging is enabled.
|
|
110
|
+
* @param message - The message to log
|
|
111
|
+
* @param args - Additional arguments to log
|
|
112
|
+
*/
|
|
113
|
+
warn(message: string, ...args: unknown[]): void;
|
|
114
|
+
/**
|
|
115
|
+
* Checks if error logging is enabled.
|
|
116
|
+
* @returns True if error logs should be output
|
|
117
|
+
*/
|
|
118
|
+
isError(): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Logs an error message if error logging is enabled.
|
|
121
|
+
* @param message - The message to log
|
|
122
|
+
* @param args - Additional arguments to log
|
|
123
|
+
*/
|
|
124
|
+
error(message: string, ...args: unknown[]): void;
|
|
125
|
+
}
|
|
126
|
+
export declare function createLogger(config?: LogConfig | Logger): Logger;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export const LogLevel = {
|
|
2
|
+
Debug: "debug",
|
|
3
|
+
Info: "info",
|
|
4
|
+
Warn: "warn",
|
|
5
|
+
Error: "error",
|
|
6
|
+
};
|
|
7
|
+
const logLevelMap = {
|
|
8
|
+
[LogLevel.Debug]: 1,
|
|
9
|
+
[LogLevel.Info]: 2,
|
|
10
|
+
[LogLevel.Warn]: 3,
|
|
11
|
+
[LogLevel.Error]: 4,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Default console-based logger implementation.
|
|
15
|
+
*/
|
|
16
|
+
export class ConsoleLogger {
|
|
17
|
+
debug(message, ...args) {
|
|
18
|
+
console.debug(message, ...args);
|
|
19
|
+
}
|
|
20
|
+
info(message, ...args) {
|
|
21
|
+
console.info(message, ...args);
|
|
22
|
+
}
|
|
23
|
+
warn(message, ...args) {
|
|
24
|
+
console.warn(message, ...args);
|
|
25
|
+
}
|
|
26
|
+
error(message, ...args) {
|
|
27
|
+
console.error(message, ...args);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Logger class that provides level-based logging functionality.
|
|
32
|
+
*/
|
|
33
|
+
export class Logger {
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new logger instance.
|
|
36
|
+
* @param config - Logger configuration
|
|
37
|
+
*/
|
|
38
|
+
constructor(config) {
|
|
39
|
+
this.level = logLevelMap[config.level];
|
|
40
|
+
this.logger = config.logger;
|
|
41
|
+
this.silent = config.silent;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Checks if a log level should be output based on configuration.
|
|
45
|
+
* @param level - The log level to check
|
|
46
|
+
* @returns True if the level should be logged
|
|
47
|
+
*/
|
|
48
|
+
shouldLog(level) {
|
|
49
|
+
return !this.silent && this.level >= logLevelMap[level];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Checks if debug logging is enabled.
|
|
53
|
+
* @returns True if debug logs should be output
|
|
54
|
+
*/
|
|
55
|
+
isDebug() {
|
|
56
|
+
return this.shouldLog(LogLevel.Debug);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Logs a debug message if debug logging is enabled.
|
|
60
|
+
* @param message - The message to log
|
|
61
|
+
* @param args - Additional arguments to log
|
|
62
|
+
*/
|
|
63
|
+
debug(message, ...args) {
|
|
64
|
+
if (this.isDebug()) {
|
|
65
|
+
this.logger.debug(message, ...args);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks if info logging is enabled.
|
|
70
|
+
* @returns True if info logs should be output
|
|
71
|
+
*/
|
|
72
|
+
isInfo() {
|
|
73
|
+
return this.shouldLog(LogLevel.Info);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Logs an info message if info logging is enabled.
|
|
77
|
+
* @param message - The message to log
|
|
78
|
+
* @param args - Additional arguments to log
|
|
79
|
+
*/
|
|
80
|
+
info(message, ...args) {
|
|
81
|
+
if (this.isInfo()) {
|
|
82
|
+
this.logger.info(message, ...args);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Checks if warning logging is enabled.
|
|
87
|
+
* @returns True if warning logs should be output
|
|
88
|
+
*/
|
|
89
|
+
isWarn() {
|
|
90
|
+
return this.shouldLog(LogLevel.Warn);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Logs a warning message if warning logging is enabled.
|
|
94
|
+
* @param message - The message to log
|
|
95
|
+
* @param args - Additional arguments to log
|
|
96
|
+
*/
|
|
97
|
+
warn(message, ...args) {
|
|
98
|
+
if (this.isWarn()) {
|
|
99
|
+
this.logger.warn(message, ...args);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Checks if error logging is enabled.
|
|
104
|
+
* @returns True if error logs should be output
|
|
105
|
+
*/
|
|
106
|
+
isError() {
|
|
107
|
+
return this.shouldLog(LogLevel.Error);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Logs an error message if error logging is enabled.
|
|
111
|
+
* @param message - The message to log
|
|
112
|
+
* @param args - Additional arguments to log
|
|
113
|
+
*/
|
|
114
|
+
error(message, ...args) {
|
|
115
|
+
if (this.isError()) {
|
|
116
|
+
this.logger.error(message, ...args);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export function createLogger(config) {
|
|
121
|
+
var _a, _b, _c;
|
|
122
|
+
if (config == null) {
|
|
123
|
+
return defaultLogger;
|
|
124
|
+
}
|
|
125
|
+
if (config instanceof Logger) {
|
|
126
|
+
return config;
|
|
127
|
+
}
|
|
128
|
+
config = config !== null && config !== void 0 ? config : {};
|
|
129
|
+
(_a = config.level) !== null && _a !== void 0 ? _a : (config.level = LogLevel.Info);
|
|
130
|
+
(_b = config.logger) !== null && _b !== void 0 ? _b : (config.logger = new ConsoleLogger());
|
|
131
|
+
(_c = config.silent) !== null && _c !== void 0 ? _c : (config.silent = true);
|
|
132
|
+
return new Logger(config);
|
|
133
|
+
}
|
|
134
|
+
const defaultLogger = new Logger({
|
|
135
|
+
level: LogLevel.Info,
|
|
136
|
+
logger: new ConsoleLogger(),
|
|
137
|
+
silent: true,
|
|
138
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core/exports.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core/exports.mjs";
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "6.
|
|
1
|
+
export declare const SDK_VERSION = "6.2.0";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "6.
|
|
1
|
+
export const SDK_VERSION = "6.2.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phenoml",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": "github:PhenoML/phenoml-ts-sdk",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"test:unit": "vitest --project unit",
|
|
43
43
|
"test:wire": "vitest --project wire"
|
|
44
44
|
},
|
|
45
|
+
"dependencies": {},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"webpack": "^5.97.1",
|
|
47
48
|
"ts-loader": "^9.5.1",
|