navi-hey 1.2.0 → 1.3.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.
Files changed (74) hide show
  1. package/lib/common/server/HandlerConfig.js +30 -0
  2. package/lib/common/server/RequestHandler.js +13 -0
  3. package/lib/common/utils/EnvResolver.js +26 -0
  4. package/lib/common/utils/env_resolver/EnvStringResolver.js +52 -0
  5. package/lib/common/utils/logging/BaseLogger.js +98 -0
  6. package/lib/common/utils/logging/BufferedLogger.js +100 -0
  7. package/lib/common/utils/logging/ConsoleLogger.js +20 -0
  8. package/lib/common/utils/logging/Log.js +82 -0
  9. package/lib/common/utils/logging/LogBuffer.js +122 -0
  10. package/lib/common/utils/logging/LogBufferCollection.js +56 -0
  11. package/lib/common/utils/logging/LogContext.js +51 -0
  12. package/lib/common/utils/logging/LogFactory.js +33 -0
  13. package/lib/common/utils/logging/LogFilter.js +34 -0
  14. package/lib/common/utils/logging/Logger.js +138 -0
  15. package/lib/common/utils/logging/LoggerGroup.js +104 -0
  16. package/lib/models/configs/Link.js +36 -0
  17. package/lib/models/configs/WebConfig.js +5 -1
  18. package/lib/serializers/LinksSerializer.js +19 -0
  19. package/lib/server/Router.js +39 -35
  20. package/lib/server/handlers/AssetsHandler.js +51 -0
  21. package/lib/server/handlers/IndexHandler.js +33 -0
  22. package/lib/server/handlers/LinksHandler.js +50 -0
  23. package/lib/server/handlers/LogsHandler.js +57 -0
  24. package/lib/server/handlers/SettingsHandler.js +34 -0
  25. package/lib/server/handlers/StatsHandler.js +33 -0
  26. package/lib/server/handlers/engine/EngineContinueHandler.js +32 -0
  27. package/lib/server/handlers/engine/EnginePauseHandler.js +32 -0
  28. package/lib/server/handlers/engine/EngineRestartHandler.js +32 -0
  29. package/lib/server/handlers/engine/EngineShutdownHandler.js +30 -0
  30. package/lib/server/handlers/engine/EngineStartHandler.js +32 -0
  31. package/lib/server/handlers/engine/EngineStatusHandler.js +29 -0
  32. package/lib/server/handlers/engine/EngineStopHandler.js +32 -0
  33. package/lib/server/handlers/jobs/JobHandler.js +35 -0
  34. package/lib/server/handlers/jobs/JobLogsHandler.js +38 -0
  35. package/lib/server/handlers/jobs/{JobRetryRequestHandler.js → JobRetryHandler.js} +15 -13
  36. package/lib/server/handlers/jobs/JobsHandler.js +37 -0
  37. package/lib/services/ApplicationInstance.js +28 -4
  38. package/lib/services/Client.js +6 -2
  39. package/lib/services/ConfigLoader.js +3 -3
  40. package/lib/services/RunSummary.js +70 -0
  41. package/lib/utils/logging/BaseLogger.js +1 -98
  42. package/lib/utils/logging/BufferedLogger.js +1 -100
  43. package/lib/utils/logging/ConsoleLogger.js +1 -20
  44. package/lib/utils/logging/Log.js +1 -82
  45. package/lib/utils/logging/LogBuffer.js +1 -122
  46. package/lib/utils/logging/LogBufferCollection.js +1 -56
  47. package/lib/utils/logging/LogContext.js +1 -51
  48. package/lib/utils/logging/LogFactory.js +1 -33
  49. package/lib/utils/logging/LogFilter.js +1 -34
  50. package/lib/utils/logging/Logger.js +1 -138
  51. package/lib/utils/logging/LoggerGroup.js +1 -104
  52. package/package.json +1 -1
  53. package/static/assets/{index-D5tOOLpl.js → index-BnMGdHFP.js} +7 -7
  54. package/static/favicon.png +0 -0
  55. package/static/index.html +2 -1
  56. package/lib/serializers/BaseUrlsSerializer.js +0 -18
  57. package/lib/server/RequestHandler.js +0 -15
  58. package/lib/server/handlers/AssetsRequestHandler.js +0 -50
  59. package/lib/server/handlers/BaseUrlsRequestHandler.js +0 -33
  60. package/lib/server/handlers/IndexRequestHandler.js +0 -31
  61. package/lib/server/handlers/LogsRequestHandler.js +0 -55
  62. package/lib/server/handlers/SettingsRequestHandler.js +0 -35
  63. package/lib/server/handlers/StatsRequestHandler.js +0 -31
  64. package/lib/server/handlers/engine/EngineContinueRequestHandler.js +0 -34
  65. package/lib/server/handlers/engine/EnginePauseRequestHandler.js +0 -34
  66. package/lib/server/handlers/engine/EngineRestartRequestHandler.js +0 -34
  67. package/lib/server/handlers/engine/EngineShutdownRequestHandler.js +0 -29
  68. package/lib/server/handlers/engine/EngineStartRequestHandler.js +0 -34
  69. package/lib/server/handlers/engine/EngineStatusRequestHandler.js +0 -27
  70. package/lib/server/handlers/engine/EngineStopRequestHandler.js +0 -34
  71. package/lib/server/handlers/jobs/JobLogsRequestHandler.js +0 -39
  72. package/lib/server/handlers/jobs/JobRequestHandler.js +0 -33
  73. package/lib/server/handlers/jobs/JobsRequestHandler.js +0 -33
  74. package/lib/utils/EnvResolver.js +0 -75
@@ -0,0 +1,34 @@
1
+ import { RequestHandler } from '../../common/server/RequestHandler.js';
2
+ import { ForbiddenError } from '../../exceptions/http/ForbiddenError.js';
3
+
4
+ /**
5
+ * Executes request-handling behaviour for GET /settings.json.
6
+ * Throws ForbiddenError when shutdown is disabled.
7
+ * @author darthjee
8
+ */
9
+ class SettingsHandler extends RequestHandler {
10
+ #response;
11
+ #enableShutdown;
12
+
13
+ /**
14
+ * @param {object} _request - The Express request object.
15
+ * @param {object} response - The Express response object.
16
+ * @param {boolean} enableShutdown - Whether shutdown is permitted.
17
+ */
18
+ constructor(_request, response, enableShutdown) {
19
+ super();
20
+ this.#response = response;
21
+ this.#enableShutdown = enableShutdown;
22
+ }
23
+
24
+ /**
25
+ * Responds with the application settings JSON.
26
+ * @returns {void}
27
+ */
28
+ handle() {
29
+ if (!this.#enableShutdown) throw new ForbiddenError();
30
+ this.#response.json({ enable_shutdown: true });
31
+ }
32
+ }
33
+
34
+ export { SettingsHandler };
@@ -0,0 +1,33 @@
1
+ import { JobRegistry } from '../../background/JobRegistry.js';
2
+ import { WorkersRegistry } from '../../background/WorkersRegistry.js';
3
+ import { RequestHandler } from '../../common/server/RequestHandler.js';
4
+
5
+ /**
6
+ * Executes request-handling behaviour for GET /stats.json.
7
+ * @author darthjee
8
+ */
9
+ class StatsHandler extends RequestHandler {
10
+ #response;
11
+
12
+ /**
13
+ * @param {object} _request - The Express request object.
14
+ * @param {object} response - The Express response object.
15
+ */
16
+ constructor(_request, response) {
17
+ super();
18
+ this.#response = response;
19
+ }
20
+
21
+ /**
22
+ * Responds with combined job and worker stats.
23
+ * @returns {void}
24
+ */
25
+ handle() {
26
+ this.#response.json({
27
+ jobs: JobRegistry.stats(),
28
+ workers: WorkersRegistry.stats(),
29
+ });
30
+ }
31
+ }
32
+
33
+ export { StatsHandler };
@@ -0,0 +1,32 @@
1
+ import { RequestHandler } from '../../../common/server/RequestHandler.js';
2
+ import { ConflictError } from '../../../exceptions/http/ConflictError.js';
3
+ import { Application } from '../../../services/Application.js';
4
+
5
+ /**
6
+ * Executes request-handling behaviour for PATCH /engine/continue.
7
+ * @author darthjee
8
+ */
9
+ class EngineContinueHandler extends RequestHandler {
10
+ #response;
11
+
12
+ /**
13
+ * @param {object} _request - The Express request object.
14
+ * @param {object} response - The Express response object.
15
+ */
16
+ constructor(_request, response) {
17
+ super();
18
+ this.#response = response;
19
+ }
20
+
21
+ /**
22
+ * Resumes engine processing after a pause.
23
+ * @returns {Promise<void>}
24
+ */
25
+ async handle() {
26
+ if (!Application.isPaused()) throw new ConflictError();
27
+ await Application.continue();
28
+ this.#response.json({ status: 'running' });
29
+ }
30
+ }
31
+
32
+ export { EngineContinueHandler };
@@ -0,0 +1,32 @@
1
+ import { RequestHandler } from '../../../common/server/RequestHandler.js';
2
+ import { ConflictError } from '../../../exceptions/http/ConflictError.js';
3
+ import { Application } from '../../../services/Application.js';
4
+
5
+ /**
6
+ * Executes request-handling behaviour for PATCH /engine/pause.
7
+ * @author darthjee
8
+ */
9
+ class EnginePauseHandler extends RequestHandler {
10
+ #response;
11
+
12
+ /**
13
+ * @param {object} _request - The Express request object.
14
+ * @param {object} response - The Express response object.
15
+ */
16
+ constructor(_request, response) {
17
+ super();
18
+ this.#response = response;
19
+ }
20
+
21
+ /**
22
+ * Initiates engine pause. Responds immediately with the transitional status.
23
+ * @returns {Promise<void>}
24
+ */
25
+ async handle() {
26
+ if (!Application.isRunning()) throw new ConflictError();
27
+ Application.pause();
28
+ this.#response.json({ status: 'pausing' });
29
+ }
30
+ }
31
+
32
+ export { EnginePauseHandler };
@@ -0,0 +1,32 @@
1
+ import { RequestHandler } from '../../../common/server/RequestHandler.js';
2
+ import { ConflictError } from '../../../exceptions/http/ConflictError.js';
3
+ import { Application } from '../../../services/Application.js';
4
+
5
+ /**
6
+ * Executes request-handling behaviour for PATCH /engine/restart.
7
+ * @author darthjee
8
+ */
9
+ class EngineRestartHandler extends RequestHandler {
10
+ #response;
11
+
12
+ /**
13
+ * @param {object} _request - The Express request object.
14
+ * @param {object} response - The Express response object.
15
+ */
16
+ constructor(_request, response) {
17
+ super();
18
+ this.#response = response;
19
+ }
20
+
21
+ /**
22
+ * Initiates engine restart. Responds immediately with the transitional status.
23
+ * @returns {Promise<void>}
24
+ */
25
+ async handle() {
26
+ if (!Application.isRunning()) throw new ConflictError();
27
+ Application.restart();
28
+ this.#response.json({ status: 'stopping' });
29
+ }
30
+ }
31
+
32
+ export { EngineRestartHandler };
@@ -0,0 +1,30 @@
1
+ import { RequestHandler } from '../../../common/server/RequestHandler.js';
2
+ import { Application } from '../../../services/Application.js';
3
+
4
+ /**
5
+ * Executes request-handling behaviour for PATCH /engine/shutdown.
6
+ * @author darthjee
7
+ */
8
+ class EngineShutdownHandler extends RequestHandler {
9
+ #response;
10
+
11
+ /**
12
+ * @param {object} _request - The Express request object.
13
+ * @param {object} response - The Express response object.
14
+ */
15
+ constructor(_request, response) {
16
+ super();
17
+ this.#response = response;
18
+ }
19
+
20
+ /**
21
+ * Initiates server shutdown. Responds immediately with the transitional status.
22
+ * @returns {void}
23
+ */
24
+ handle() {
25
+ Application.shutdown();
26
+ this.#response.json({ status: 'stopping' });
27
+ }
28
+ }
29
+
30
+ export { EngineShutdownHandler };
@@ -0,0 +1,32 @@
1
+ import { RequestHandler } from '../../../common/server/RequestHandler.js';
2
+ import { ConflictError } from '../../../exceptions/http/ConflictError.js';
3
+ import { Application } from '../../../services/Application.js';
4
+
5
+ /**
6
+ * Executes request-handling behaviour for PATCH /engine/start.
7
+ * @author darthjee
8
+ */
9
+ class EngineStartHandler extends RequestHandler {
10
+ #response;
11
+
12
+ /**
13
+ * @param {object} _request - The Express request object.
14
+ * @param {object} response - The Express response object.
15
+ */
16
+ constructor(_request, response) {
17
+ super();
18
+ this.#response = response;
19
+ }
20
+
21
+ /**
22
+ * Starts engine processing from a stopped state.
23
+ * @returns {Promise<void>}
24
+ */
25
+ async handle() {
26
+ if (!Application.isStopped()) throw new ConflictError();
27
+ await Application.start();
28
+ this.#response.json({ status: 'running' });
29
+ }
30
+ }
31
+
32
+ export { EngineStartHandler };
@@ -0,0 +1,29 @@
1
+ import { RequestHandler } from '../../../common/server/RequestHandler.js';
2
+ import { Application } from '../../../services/Application.js';
3
+
4
+ /**
5
+ * Executes request-handling behaviour for GET /engine/status.
6
+ * @author darthjee
7
+ */
8
+ class EngineStatusHandler extends RequestHandler {
9
+ #response;
10
+
11
+ /**
12
+ * @param {object} _request - The Express request object.
13
+ * @param {object} response - The Express response object.
14
+ */
15
+ constructor(_request, response) {
16
+ super();
17
+ this.#response = response;
18
+ }
19
+
20
+ /**
21
+ * Responds with the current engine status.
22
+ * @returns {void}
23
+ */
24
+ handle() {
25
+ this.#response.json({ status: Application.status() });
26
+ }
27
+ }
28
+
29
+ export { EngineStatusHandler };
@@ -0,0 +1,32 @@
1
+ import { RequestHandler } from '../../../common/server/RequestHandler.js';
2
+ import { ConflictError } from '../../../exceptions/http/ConflictError.js';
3
+ import { Application } from '../../../services/Application.js';
4
+
5
+ /**
6
+ * Executes request-handling behaviour for PATCH /engine/stop.
7
+ * @author darthjee
8
+ */
9
+ class EngineStopHandler extends RequestHandler {
10
+ #response;
11
+
12
+ /**
13
+ * @param {object} _request - The Express request object.
14
+ * @param {object} response - The Express response object.
15
+ */
16
+ constructor(_request, response) {
17
+ super();
18
+ this.#response = response;
19
+ }
20
+
21
+ /**
22
+ * Initiates engine stop. Responds immediately with the transitional status.
23
+ * @returns {Promise<void>}
24
+ */
25
+ async handle() {
26
+ if (!Application.isRunning()) throw new ConflictError();
27
+ Application.stop();
28
+ this.#response.json({ status: 'stopping' });
29
+ }
30
+ }
31
+
32
+ export { EngineStopHandler };
@@ -0,0 +1,35 @@
1
+ import { JobRegistry } from '../../../background/JobRegistry.js';
2
+ import { RequestHandler } from '../../../common/server/RequestHandler.js';
3
+ import { NotFoundError } from '../../../exceptions/http/NotFoundError.js';
4
+ import { JobSerializer } from '../../../serializers/JobSerializer.js';
5
+
6
+ /**
7
+ * Executes request-handling behaviour for GET /job/:id.json.
8
+ * @author darthjee
9
+ */
10
+ class JobHandler extends RequestHandler {
11
+ #request;
12
+ #response;
13
+
14
+ /**
15
+ * @param {object} request - The Express request object.
16
+ * @param {object} response - The Express response object.
17
+ */
18
+ constructor(request, response) {
19
+ super();
20
+ this.#request = request;
21
+ this.#response = response;
22
+ }
23
+
24
+ /**
25
+ * Responds with the job details for the given ID, or 404 if not found.
26
+ * @returns {void}
27
+ */
28
+ handle() {
29
+ const result = JobRegistry.jobById(this.#request.params.id);
30
+ if (!result) throw new NotFoundError('Job not found');
31
+ this.#response.json(JobSerializer.serialize(result.job, { status: result.status, view: 'show' }));
32
+ }
33
+ }
34
+
35
+ export { JobHandler };
@@ -0,0 +1,38 @@
1
+ import { RequestHandler } from '../../../common/server/RequestHandler.js';
2
+ import { LogRegistry } from '../../../registry/LogRegistry.js';
3
+ import { LogSerializer } from '../../../serializers/LogSerializer.js';
4
+
5
+ /**
6
+ * Executes request-handling behaviour for GET /jobs/:job_id/logs.json.
7
+ * @author darthjee
8
+ */
9
+ class JobLogsHandler extends RequestHandler {
10
+ #request;
11
+ #response;
12
+ #pageSize;
13
+
14
+ /**
15
+ * @param {object} request - The Express request object.
16
+ * @param {object} response - The Express response object.
17
+ * @param {number} pageSize - Maximum number of log entries to return.
18
+ */
19
+ constructor(request, response, pageSize) {
20
+ super();
21
+ this.#request = request;
22
+ this.#response = response;
23
+ this.#pageSize = pageSize;
24
+ }
25
+
26
+ /**
27
+ * Responds with a paginated JSON array of log entries for the given job.
28
+ * @returns {void}
29
+ */
30
+ handle() {
31
+ const { job_id: jobId } = this.#request.params;
32
+ const { last_id: lastId } = this.#request.query;
33
+ const logs = LogRegistry.getLogsByJobId(jobId, { lastId });
34
+ this.#response.json(LogSerializer.serialize(logs.slice(0, this.#pageSize)));
35
+ }
36
+ }
37
+
38
+ export { JobLogsHandler };
@@ -1,40 +1,42 @@
1
1
  import { JobRegistry } from '../../../background/JobRegistry.js';
2
+ import { RequestHandler } from '../../../common/server/RequestHandler.js';
2
3
  import { ConflictError } from '../../../exceptions/http/ConflictError.js';
3
4
  import { NotFoundError } from '../../../exceptions/http/NotFoundError.js';
4
- import { RequestHandler } from '../../RequestHandler.js';
5
5
 
6
6
  const RETRYABLE_STATUSES = new Set(['failed', 'dead']);
7
7
 
8
8
  /**
9
- * Handles PATCH /jobs/:id/retry requests.
10
- * Moves a failed or dead job directly to the retry queue.
11
- * Returns 404 if the job does not exist, 409 if it is not in a retryable state.
9
+ * Executes request-handling behaviour for PATCH /jobs/:id/retry.
12
10
  * @author darthjee
13
11
  */
14
- class JobRetryRequestHandler extends RequestHandler {
12
+ class JobRetryHandler extends RequestHandler {
13
+ #request;
14
+ #response;
15
+
15
16
  /**
16
- * Creates a new JobRetryRequestHandler instance.
17
+ * @param {object} request - The Express request object.
18
+ * @param {object} response - The Express response object.
17
19
  */
18
- constructor() {
20
+ constructor(request, response) {
19
21
  super();
22
+ this.#request = request;
23
+ this.#response = response;
20
24
  }
21
25
 
22
26
  /**
23
27
  * Retries the specified job by moving it to the retry queue.
24
- * @param {object} req - The Express request object.
25
- * @param {object} res - The Express response object.
26
28
  * @returns {void}
27
29
  */
28
- handle(req, res) {
29
- const { id } = req.params;
30
+ handle() {
31
+ const { id } = this.#request.params;
30
32
  const result = JobRegistry.jobById(id);
31
33
 
32
34
  if (!result) throw new NotFoundError('Job not found');
33
35
  if (!RETRYABLE_STATUSES.has(result.status)) throw new ConflictError();
34
36
 
35
37
  JobRegistry.retryJob(id);
36
- res.json({ status: 'enqueued' });
38
+ this.#response.json({ status: 'enqueued' });
37
39
  }
38
40
  }
39
41
 
40
- export { JobRetryRequestHandler };
42
+ export { JobRetryHandler };
@@ -0,0 +1,37 @@
1
+ import { JobRegistry } from '../../../background/JobRegistry.js';
2
+ import { RequestHandler } from '../../../common/server/RequestHandler.js';
3
+ import { JobSerializer } from '../../../serializers/JobSerializer.js';
4
+ import { JobsFilter } from '../JobsFilter.js';
5
+
6
+ /**
7
+ * Executes request-handling behaviour for GET /jobs/:status.json.
8
+ * @author darthjee
9
+ */
10
+ class JobsHandler extends RequestHandler {
11
+ #request;
12
+ #response;
13
+
14
+ /**
15
+ * @param {object} request - The Express request object.
16
+ * @param {object} response - The Express response object.
17
+ */
18
+ constructor(request, response) {
19
+ super();
20
+ this.#request = request;
21
+ this.#response = response;
22
+ }
23
+
24
+ /**
25
+ * Responds with the list of jobs in the given status queue.
26
+ * @returns {void}
27
+ */
28
+ handle() {
29
+ const { status } = this.#request.params;
30
+ const jobs = JobRegistry.jobsByStatus(status);
31
+ const filters = this.#request.query.filters || {};
32
+ const filteredJobs = new JobsFilter(jobs, filters).filter();
33
+ this.#response.json(JobSerializer.serialize(filteredJobs, { status, view: 'index' }));
34
+ }
35
+ }
36
+
37
+ export { JobsHandler };
@@ -1,6 +1,7 @@
1
1
  import { Engine } from './Engine.js';
2
2
  import { EngineEvents } from './EngineEvents.js';
3
3
  import { FailureChecker } from './FailureChecker.js';
4
+ import { RunSummary } from './RunSummary.js';
4
5
  import { JobFactory } from '../background/JobFactory.js';
5
6
  import { JobRegistry } from '../background/JobRegistry.js';
6
7
  import { WorkersRegistry } from '../background/WorkersRegistry.js';
@@ -75,10 +76,7 @@ class ApplicationInstance {
75
76
  this.#aggregator.add(this.#enginePromise);
76
77
 
77
78
  await this.#aggregator.wait();
78
- this.#engineStatus = 'stopped';
79
- EngineEvents.emit('stop');
80
-
81
- new FailureChecker({ failureConfig: this.config.failureConfig }).check();
79
+ this.#finishRun();
82
80
  }
83
81
 
84
82
  /**
@@ -269,6 +267,32 @@ class ApplicationInstance {
269
267
  });
270
268
  WorkersRegistry.initWorkers();
271
269
  }
270
+
271
+ /**
272
+ * Finalizes the run lifecycle by emitting stop events and evaluating failures.
273
+ * @returns {void}
274
+ */
275
+ #finishRun() {
276
+ this.#engineStatus = 'stopped';
277
+ EngineEvents.emit('stop');
278
+ this.#printRunSummary();
279
+ new FailureChecker({ failureConfig: this.config.failureConfig }).check();
280
+ }
281
+
282
+ /**
283
+ * Prints the final run summary before threshold checking.
284
+ * @returns {void}
285
+ */
286
+ #printRunSummary() {
287
+ const stats = JobRegistry.stats();
288
+ const summary = new RunSummary({
289
+ totalJobs: stats.total,
290
+ failedJobs: stats.failed + stats.retryQueue + stats.dead,
291
+ threshold: this.config.failureConfig?.threshold,
292
+ });
293
+
294
+ LogRegistry.info(summary.report());
295
+ }
272
296
  }
273
297
 
274
298
  export { ApplicationInstance };
@@ -13,12 +13,14 @@ class Client {
13
13
  * @param {object} attributes Client attributes.
14
14
  * @param {string} attributes.name Name identifying this client.
15
15
  * @param {string} attributes.baseUrl Base URL used to build full request URLs.
16
+ * @param {string|null} [attributes.linkText] Optional display text for UI links.
16
17
  * @param {number} [attributes.timeout] Optional request timeout in milliseconds.
17
18
  * @param {object} [attributes.headers] Optional HTTP headers sent with every request.
18
19
  */
19
- constructor({ name, baseUrl, timeout = 5000, headers = {} }) {
20
+ constructor({ name, baseUrl, linkText = null, timeout = 5000, headers = {} }) {
20
21
  this.name = name;
21
22
  this.baseUrl = baseUrl;
23
+ this.linkText = linkText;
22
24
  this.timeout = timeout;
23
25
  this.headers = headers;
24
26
  }
@@ -29,6 +31,7 @@ class Client {
29
31
  * @param {string} name The name identifying the client.
30
32
  * @param {object} config Client configuration object.
31
33
  * @param {string} config.base_url Base URL for the client.
34
+ * @param {string} [config.linkText] Optional display text for UI links.
32
35
  * @param {number} [config.timeout] Optional request timeout in milliseconds.
33
36
  * @param {object} [config.headers] Optional HTTP headers.
34
37
  * @returns {Client} A new Client instance.
@@ -36,7 +39,8 @@ class Client {
36
39
  static fromObject(name, config) {
37
40
  const headers = config.headers || {};
38
41
  const baseUrl = config.base_url;
39
- return new Client({ name, baseUrl, timeout: config.timeout, headers });
42
+ const linkText = config.linkText ?? null;
43
+ return new Client({ name, baseUrl, linkText, timeout: config.timeout, headers });
40
44
  }
41
45
 
42
46
  /**
@@ -1,8 +1,8 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import YAML from 'yaml';
3
3
  import { ConfigParser } from './ConfigParser.js';
4
+ import { EnvStringResolver } from '../common/utils/env_resolver/EnvStringResolver.js';
4
5
  import { ConfigurationFileNotFound } from '../exceptions/config/ConfigurationFileNotFound.js';
5
- import { EnvResolver } from '../utils/EnvResolver.js';
6
6
  import { Logger } from '../utils/logging/Logger.js';
7
7
 
8
8
  /**
@@ -55,7 +55,7 @@ class ConfigLoader {
55
55
  * @throws {ConfigurationFileNotFound} If the configuration file is not found at the specified path.
56
56
  */
57
57
  #parseYaml() {
58
- return YAML.parse(EnvResolver.resolveString(this.#yamlContent()));
58
+ return YAML.parse(EnvStringResolver.resolve(this.#yamlContent()));
59
59
  }
60
60
 
61
61
  /**
@@ -73,4 +73,4 @@ class ConfigLoader {
73
73
  }
74
74
  }
75
75
 
76
- export { ConfigLoader };
76
+ export { ConfigLoader };
@@ -0,0 +1,70 @@
1
+ /**
2
+ * RunSummary computes and formats final run metrics for output at application end.
3
+ * @author darthjee
4
+ */
5
+ class RunSummary {
6
+ #totalJobs;
7
+ #failedJobs;
8
+ #threshold;
9
+
10
+ /**
11
+ * @param {object} params - Construction parameters.
12
+ * @param {number} params.totalJobs - Total processed jobs.
13
+ * @param {number} params.failedJobs - Total failed jobs (failed + retry + dead).
14
+ * @param {number|null} [params.threshold=null] - Failure threshold percentage.
15
+ */
16
+ constructor({ totalJobs, failedJobs, threshold = null }) {
17
+ this.#totalJobs = totalJobs;
18
+ this.#failedJobs = failedJobs;
19
+ this.#threshold = threshold;
20
+ }
21
+
22
+ /**
23
+ * Returns the failure percentage for this run.
24
+ * @returns {number} Failure percentage (0–100).
25
+ */
26
+ percentage() {
27
+ if (this.#totalJobs === 0) return 0;
28
+ return (this.#failedJobs / this.#totalJobs) * 100;
29
+ }
30
+
31
+ /**
32
+ * Returns the run result according to the configured threshold.
33
+ * @returns {'Success'|'Failure'} Run result label.
34
+ */
35
+ result() {
36
+ if (this.#threshold === null || this.#threshold === undefined) return 'Success';
37
+ return this.percentage() > this.#threshold ? 'Failure' : 'Success';
38
+ }
39
+
40
+ /**
41
+ * Returns the multi-line summary message.
42
+ * @returns {string} Formatted run summary.
43
+ */
44
+ report() {
45
+ return [
46
+ `Total: ${this.#totalJobs}`,
47
+ `Failed: ${this.#failedJobs} (${this.#format(this.percentage())}%)`,
48
+ `Threshold: ${this.#formatThreshold()}`,
49
+ `Result: ${this.result()}`,
50
+ ].join('\n');
51
+ }
52
+
53
+ /**
54
+ * @param {number} value - Numeric value to format.
55
+ * @returns {string} Rounded string without unnecessary trailing zeroes.
56
+ */
57
+ #format(value) {
58
+ return `${Number(value.toFixed(2))}`;
59
+ }
60
+
61
+ /**
62
+ * @returns {string} Formatted threshold line value.
63
+ */
64
+ #formatThreshold() {
65
+ if (this.#threshold === null || this.#threshold === undefined) return 'N/A';
66
+ return `${this.#format(this.#threshold)}%`;
67
+ }
68
+ }
69
+
70
+ export { RunSummary };