navi-hey 1.1.0 → 1.2.1

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 (109) hide show
  1. package/README.md +38 -4
  2. package/lib/common/utils/EnvResolver.js +26 -0
  3. package/lib/common/utils/env_resolver/EnvStringResolver.js +52 -0
  4. package/lib/common/utils/logging/BaseLogger.js +98 -0
  5. package/lib/common/utils/logging/BufferedLogger.js +100 -0
  6. package/lib/common/utils/logging/ConsoleLogger.js +20 -0
  7. package/lib/common/utils/logging/Log.js +82 -0
  8. package/lib/common/utils/logging/LogBuffer.js +122 -0
  9. package/lib/common/utils/logging/LogBufferCollection.js +56 -0
  10. package/lib/common/utils/logging/LogContext.js +51 -0
  11. package/lib/common/utils/logging/LogFactory.js +33 -0
  12. package/lib/common/utils/logging/LogFilter.js +34 -0
  13. package/lib/common/utils/logging/Logger.js +138 -0
  14. package/lib/common/utils/logging/LoggerGroup.js +104 -0
  15. package/lib/enqueuers/ActionEnqueuer.js +18 -2
  16. package/lib/enqueuers/ActionsEnqueuer.js +6 -3
  17. package/lib/enqueuers/PaginatedActionEnqueuer.js +53 -0
  18. package/lib/enqueuers/PaginatedActionsEnqueuer.js +47 -0
  19. package/lib/exceptions/{ConfigurationFileNotFound.js → config/ConfigurationFileNotFound.js} +1 -1
  20. package/lib/exceptions/{ConfigurationFileNotProvided.js → config/ConfigurationFileNotProvided.js} +1 -1
  21. package/lib/exceptions/{MissingTopLevelConfgKey.js → config/MissingTopLevelConfgKey.js} +1 -1
  22. package/lib/exceptions/{ConflictError.js → http/ConflictError.js} +1 -1
  23. package/lib/exceptions/{ForbiddenError.js → http/ForbiddenError.js} +1 -1
  24. package/lib/exceptions/{NotFoundError.js → http/NotFoundError.js} +1 -1
  25. package/lib/exceptions/{ItemNotFound.js → registry/ItemNotFound.js} +1 -1
  26. package/lib/exceptions/{MissingActionResource.js → registry/MissingActionResource.js} +1 -1
  27. package/lib/exceptions/{MissingMappingVariable.js → registry/MissingMappingVariable.js} +1 -1
  28. package/lib/exceptions/{InvalidHtmlResponseBody.js → request/InvalidHtmlResponseBody.js} +1 -1
  29. package/lib/exceptions/{InvalidResponseBody.js → request/InvalidResponseBody.js} +1 -1
  30. package/lib/exceptions/{NullResponse.js → request/NullResponse.js} +1 -1
  31. package/lib/exceptions/{RequestFailed.js → request/RequestFailed.js} +1 -1
  32. package/lib/jobs/ActionProcessingJob.js +17 -3
  33. package/lib/jobs/HtmlParseJob.js +17 -4
  34. package/lib/jobs/PaginatedActionProcessingJob.js +77 -0
  35. package/lib/jobs/ResourceRequestJob.js +8 -5
  36. package/lib/models/{Config.js → configs/Config.js} +3 -3
  37. package/lib/models/configs/Link.js +36 -0
  38. package/lib/models/configs/PaginationConfig.js +63 -0
  39. package/lib/models/{WebConfig.js → configs/WebConfig.js} +5 -1
  40. package/lib/models/{ResourceRequest.js → request/ResourceRequest.js} +30 -8
  41. package/lib/models/{ResourceRequestAction.js → request/ResourceRequestAction.js} +6 -6
  42. package/lib/models/request/ResourceRequestPaginatedAction.js +81 -0
  43. package/lib/models/{PathSegmentTraverser.js → response/PathSegmentTraverser.js} +1 -1
  44. package/lib/models/{ResponseParser.js → response/ResponseParser.js} +1 -1
  45. package/lib/registry/ClientRegistry.js +1 -1
  46. package/lib/registry/LogRegistry.js +13 -13
  47. package/lib/registry/LogRegistryInstance.js +16 -16
  48. package/lib/registry/NamedRegistry.js +1 -1
  49. package/lib/registry/ResourceRegistry.js +1 -1
  50. package/lib/serializers/JobIndexSerializer.js +3 -0
  51. package/lib/serializers/LogSerializer.js +1 -1
  52. package/lib/server/PathValidator.js +1 -1
  53. package/lib/server/RouteRegister.js +3 -3
  54. package/lib/server/Router.js +20 -18
  55. package/lib/server/{AssetsRequestHandler.js → handlers/AssetsRequestHandler.js} +3 -3
  56. package/lib/server/{BaseUrlsRequestHandler.js → handlers/BaseUrlsRequestHandler.js} +3 -3
  57. package/lib/server/{IndexRequestHandler.js → handlers/IndexRequestHandler.js} +2 -2
  58. package/lib/server/{JobsFilter.js → handlers/JobsFilter.js} +1 -1
  59. package/lib/server/handlers/LinksRequestHandler.js +32 -0
  60. package/lib/server/{LogsRequestHandler.js → handlers/LogsRequestHandler.js} +4 -4
  61. package/lib/server/{SettingsRequestHandler.js → handlers/SettingsRequestHandler.js} +4 -3
  62. package/lib/server/{StatsRequestHandler.js → handlers/StatsRequestHandler.js} +3 -3
  63. package/lib/server/{EngineContinueRequestHandler.js → handlers/engine/EngineContinueRequestHandler.js} +3 -3
  64. package/lib/server/{EnginePauseRequestHandler.js → handlers/engine/EnginePauseRequestHandler.js} +3 -3
  65. package/lib/server/{EngineRestartRequestHandler.js → handlers/engine/EngineRestartRequestHandler.js} +3 -3
  66. package/lib/server/{EngineShutdownRequestHandler.js → handlers/engine/EngineShutdownRequestHandler.js} +2 -2
  67. package/lib/server/{EngineStartRequestHandler.js → handlers/engine/EngineStartRequestHandler.js} +3 -3
  68. package/lib/server/{EngineStatusRequestHandler.js → handlers/engine/EngineStatusRequestHandler.js} +2 -2
  69. package/lib/server/{EngineStopRequestHandler.js → handlers/engine/EngineStopRequestHandler.js} +3 -3
  70. package/lib/server/{JobLogsRequestHandler.js → handlers/jobs/JobLogsRequestHandler.js} +4 -4
  71. package/lib/server/{JobRequestHandler.js → handlers/jobs/JobRequestHandler.js} +4 -4
  72. package/lib/server/{JobRetryRequestHandler.js → handlers/jobs/JobRetryRequestHandler.js} +4 -4
  73. package/lib/server/{JobsRequestHandler.js → handlers/jobs/JobsRequestHandler.js} +4 -4
  74. package/lib/services/ApplicationInstance.js +4 -2
  75. package/lib/services/Client.js +1 -1
  76. package/lib/services/ConfigLoader.js +4 -4
  77. package/lib/services/ConfigParser.js +7 -7
  78. package/lib/services/Engine.js +1 -1
  79. package/lib/utils/HtmlParser.js +1 -1
  80. package/lib/utils/logging/BaseLogger.js +1 -98
  81. package/lib/utils/logging/BufferedLogger.js +1 -100
  82. package/lib/utils/logging/ConsoleLogger.js +1 -20
  83. package/lib/utils/logging/Log.js +1 -82
  84. package/lib/utils/logging/LogBuffer.js +1 -122
  85. package/lib/utils/logging/LogBufferCollection.js +1 -56
  86. package/lib/utils/logging/LogContext.js +1 -51
  87. package/lib/utils/logging/LogFactory.js +1 -33
  88. package/lib/utils/logging/LogFilter.js +1 -34
  89. package/lib/utils/logging/Logger.js +1 -138
  90. package/lib/utils/logging/LoggerGroup.js +1 -104
  91. package/package.json +1 -1
  92. package/static/assets/index-CX_uXu4Q.js +11 -0
  93. package/static/favicon.png +0 -0
  94. package/static/index.html +2 -1
  95. package/lib/exceptions/LockedByOtherWorker.js +0 -14
  96. package/lib/utils/EnvResolver.js +0 -75
  97. package/static/assets/index-BfggoMvd.js +0 -11
  98. /package/lib/exceptions/{MissingClientsConfig.js → config/MissingClientsConfig.js} +0 -0
  99. /package/lib/exceptions/{MissingResourceConfig.js → config/MissingResourceConfig.js} +0 -0
  100. /package/lib/exceptions/{ClientNotFound.js → registry/ClientNotFound.js} +0 -0
  101. /package/lib/exceptions/{ResourceNotFound.js → registry/ResourceNotFound.js} +0 -0
  102. /package/lib/models/{FailureConfig.js → configs/FailureConfig.js} +0 -0
  103. /package/lib/models/{LogConfig.js → configs/LogConfig.js} +0 -0
  104. /package/lib/models/{WorkersConfig.js → configs/WorkersConfig.js} +0 -0
  105. /package/lib/models/{AssetRequest.js → request/AssetRequest.js} +0 -0
  106. /package/lib/models/{Resource.js → request/Resource.js} +0 -0
  107. /package/lib/models/{ParametersMapper.js → response/ParametersMapper.js} +0 -0
  108. /package/lib/models/{PathResolver.js → response/PathResolver.js} +0 -0
  109. /package/lib/models/{ResponseWrapper.js → response/ResponseWrapper.js} +0 -0
@@ -0,0 +1,33 @@
1
+ import { Log } from './Log.js';
2
+ import { IncrementalIdGenerator } from '../../../utils/generators/IncrementalIdGenerator.js';
3
+
4
+ /**
5
+ * LogFactory creates Log instances with automatically assigned incremental IDs.
6
+ * @author darthjee
7
+ */
8
+ class LogFactory {
9
+ #idGenerator;
10
+
11
+ /**
12
+ * Creates a new LogFactory instance.
13
+ * @param {object} [params={}] - Construction parameters.
14
+ * @param {IncrementalIdGenerator} [params.idGenerator] - The id generator to use.
15
+ */
16
+ constructor({ idGenerator = new IncrementalIdGenerator() } = {}) {
17
+ this.#idGenerator = idGenerator;
18
+ }
19
+
20
+ /**
21
+ * Builds a new Log entry with an auto-assigned id.
22
+ * @param {string} level - The log level.
23
+ * @param {string} message - The log message.
24
+ * @param {object} [attributes={}] - Optional structured metadata for the log entry.
25
+ * @returns {Log} The created log entry.
26
+ */
27
+ build(level, message, attributes = {}) {
28
+ const id = this.#idGenerator.generate();
29
+ return new Log(id, level, message, attributes);
30
+ }
31
+ }
32
+
33
+ export { LogFactory };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Filters a list of log entries based on query options.
3
+ * @author darthjee
4
+ */
5
+ class LogFilter {
6
+ #logs;
7
+
8
+ /**
9
+ * @param {Array<import('./Log.js').Log>} logs - The full list of logs to filter (oldest first).
10
+ */
11
+ constructor(logs) {
12
+ this.#logs = logs;
13
+ }
14
+
15
+ /**
16
+ * Returns the filtered log list.
17
+ * @param {object} [options={}] - Filter options.
18
+ * @param {number|string} [options.lastId] - When provided, returns only logs newer than this ID.
19
+ * Returns an empty array if the ID is not found.
20
+ * @returns {Array<import('./Log.js').Log>} Filtered array of log entries.
21
+ */
22
+ filter({ lastId } = {}) {
23
+ if (lastId === undefined) return this.#logs;
24
+
25
+ const id = parseInt(lastId, 10);
26
+ const index = this.#logs.findIndex(log => log.id === id);
27
+
28
+ if (index === -1) return [];
29
+
30
+ return this.#logs.slice(index + 1);
31
+ }
32
+ }
33
+
34
+ export { LogFilter };
@@ -0,0 +1,138 @@
1
+ import { ConsoleLogger } from './ConsoleLogger.js';
2
+ import { LoggerGroup } from './LoggerGroup.js';
3
+
4
+ /**
5
+ * Static facade for the default LoggerGroup singleton.
6
+ * All instance-level log logic lives in BaseLogger / ConsoleLogger / LoggerGroup.
7
+ *
8
+ * @example <caption>Basic logging (default ConsoleLogger)</caption>
9
+ * Logger.info('Server started');
10
+ * Logger.warn('Low memory');
11
+ * Logger.error('Request failed');
12
+ *
13
+ * @example <caption>Swap to a custom logger</caption>
14
+ * Logger.setLogger(myCustomLogger);
15
+ * Logger.info('Now routed through myCustomLogger');
16
+ *
17
+ * @example <caption>Add an extra log destination</caption>
18
+ * const buffered = new BufferedLogger();
19
+ * Logger.addLogger(buffered);
20
+ * Logger.info('Goes to console and buffered logger');
21
+ *
22
+ * @example <caption>Suppress all output</caption>
23
+ * Logger.suppress();
24
+ * Logger.info('This will not be printed');
25
+ * Logger.suppress(false); // restore output
26
+ *
27
+ * @author darthjee
28
+ */
29
+ class Logger {
30
+ static #loggerGroup;
31
+
32
+ /**
33
+ * Returns the default LoggerGroup instance (singleton).
34
+ * Initialized with a ConsoleLogger on first access.
35
+ * @returns {LoggerGroup} The default logger group instance.
36
+ */
37
+ static default() {
38
+ this.#ensureLoggerGroup();
39
+ return this.#loggerGroup;
40
+ }
41
+
42
+ /**
43
+ * Logs a debug message using the default logger instance.
44
+ * @param {string} message - The message to log.
45
+ * @param {object} [attributes={}] - Optional structured metadata.
46
+ * @returns {void}
47
+ */
48
+ static debug(message, attributes = {}) {
49
+ this.default().debug(message, attributes);
50
+ }
51
+
52
+ /**
53
+ * Logs an info message using the default logger instance.
54
+ * @param {string} message - The message to log.
55
+ * @param {object} [attributes={}] - Optional structured metadata.
56
+ * @returns {void}
57
+ */
58
+ static info(message, attributes = {}) {
59
+ this.default().info(message, attributes);
60
+ }
61
+
62
+ /**
63
+ * Logs a warn message using the default logger instance.
64
+ * @param {string} message - The message to log.
65
+ * @param {object} [attributes={}] - Optional structured metadata.
66
+ * @returns {void}
67
+ */
68
+ static warn(message, attributes = {}) {
69
+ this.default().warn(message, attributes);
70
+ }
71
+
72
+ /**
73
+ * Logs an error message using the default logger instance.
74
+ * @param {string} message - The message to log.
75
+ * @param {object} [attributes={}] - Optional structured metadata.
76
+ * @returns {void}
77
+ */
78
+ static error(message, attributes = {}) {
79
+ this.default().error(message, attributes);
80
+ }
81
+
82
+ /**
83
+ * Suppresses or restores log output on the default logger instance.
84
+ * @param {boolean} [value=true] - When true, all log output is suppressed.
85
+ * @returns {void}
86
+ */
87
+ static suppress(value = true) {
88
+ this.default().suppress(value);
89
+ }
90
+
91
+ /**
92
+ * Sets the log level threshold on the default logger instance.
93
+ * @param {string} level - The new log level ('debug', 'info', 'warn', 'error', 'silent').
94
+ * @returns {void}
95
+ */
96
+ static setLevel(level) {
97
+ this.default().setLevel(level);
98
+ }
99
+
100
+ /**
101
+ * Resets the default logger group so a new one is created on the next call to default().
102
+ * Useful in tests to ensure a clean singleton state.
103
+ * @returns {void}
104
+ */
105
+ static reset() {
106
+ this.#loggerGroup = null;
107
+ }
108
+
109
+ /**
110
+ * Replaces the default logger group with a new LoggerGroup containing the provided logger.
111
+ * @param {BaseLogger} logger - The logger instance to use in the new group.
112
+ * @returns {void}
113
+ */
114
+ static setLogger(logger) {
115
+ this.#loggerGroup = new LoggerGroup([logger]);
116
+ }
117
+
118
+ /**
119
+ * Adds a logger to the default logger group.
120
+ * @param {BaseLogger} logger - The logger instance to add.
121
+ * @returns {void}
122
+ */
123
+ static addLogger(logger) {
124
+ this.default().addLogger(logger);
125
+ }
126
+
127
+ /**
128
+ * Ensures the default LoggerGroup instance exists, creating one with a ConsoleLogger if needed.
129
+ * @returns {void}
130
+ */
131
+ static #ensureLoggerGroup() {
132
+ if (!this.#loggerGroup) {
133
+ this.#loggerGroup = new LoggerGroup([new ConsoleLogger()]);
134
+ }
135
+ }
136
+ }
137
+
138
+ export { Logger };
@@ -0,0 +1,104 @@
1
+ /**
2
+ * LoggerGroup broadcasts log messages to multiple Logger instances.
3
+ * Useful for sending the same log output to multiple destinations (console, web, file, etc.).
4
+ * @author darthjee
5
+ */
6
+ class LoggerGroup {
7
+ #loggers;
8
+
9
+ /**
10
+ * Creates a new LoggerGroup instance.
11
+ * @param {Array<Logger>} [loggers=[]] - Array of Logger instances to broadcast to.
12
+ */
13
+ constructor(loggers = []) {
14
+ this.#loggers = loggers;
15
+ }
16
+
17
+ /**
18
+ * Adds a logger to the group.
19
+ * @param {Logger} logger - The Logger instance to add.
20
+ * @returns {LoggerGroup} This instance for method chaining.
21
+ */
22
+ addLogger(logger) {
23
+ this.#loggers.push(logger);
24
+ return this;
25
+ }
26
+
27
+ /**
28
+ * Removes a logger from the group.
29
+ * @param {Logger} logger - The Logger instance to remove.
30
+ * @returns {LoggerGroup} This instance for method chaining.
31
+ */
32
+ removeLogger(logger) {
33
+ this.#loggers = this.#loggers.filter(l => l !== logger);
34
+ return this;
35
+ }
36
+
37
+ /**
38
+ * Returns all loggers in the group.
39
+ * @returns {Array<Logger>} Array of Logger instances.
40
+ */
41
+ getLoggers() {
42
+ return [...this.#loggers];
43
+ }
44
+
45
+ /**
46
+ * Broadcasts a debug message to all loggers in the group.
47
+ * @param {string} message - The message to log.
48
+ * @param {object} [attributes={}] - Optional structured metadata.
49
+ * @returns {void}
50
+ */
51
+ debug(message, attributes = {}) {
52
+ this.#loggers.forEach(logger => logger.debug(message, attributes));
53
+ }
54
+
55
+ /**
56
+ * Broadcasts an info message to all loggers in the group.
57
+ * @param {string} message - The message to log.
58
+ * @param {object} [attributes={}] - Optional structured metadata.
59
+ * @returns {void}
60
+ */
61
+ info(message, attributes = {}) {
62
+ this.#loggers.forEach(logger => logger.info(message, attributes));
63
+ }
64
+
65
+ /**
66
+ * Broadcasts a warn message to all loggers in the group.
67
+ * @param {string} message - The message to log.
68
+ * @param {object} [attributes={}] - Optional structured metadata.
69
+ * @returns {void}
70
+ */
71
+ warn(message, attributes = {}) {
72
+ this.#loggers.forEach(logger => logger.warn(message, attributes));
73
+ }
74
+
75
+ /**
76
+ * Broadcasts an error message to all loggers in the group.
77
+ * @param {string} message - The message to log.
78
+ * @param {object} [attributes={}] - Optional structured metadata.
79
+ * @returns {void}
80
+ */
81
+ error(message, attributes = {}) {
82
+ this.#loggers.forEach(logger => logger.error(message, attributes));
83
+ }
84
+
85
+ /**
86
+ * Suppresses or restores log output on all loggers in the group.
87
+ * @param {boolean} [value=true] - When true, all log output is suppressed.
88
+ * @returns {void}
89
+ */
90
+ suppress(value = true) {
91
+ this.#loggers.forEach(logger => logger.suppress(value));
92
+ }
93
+
94
+ /**
95
+ * Sets the log level threshold on all loggers in the group.
96
+ * @param {string} level - The new log level ('debug', 'info', 'warn', 'error', 'silent').
97
+ * @returns {void}
98
+ */
99
+ setLevel(level) {
100
+ this.#loggers.forEach(logger => logger.setLevel(level));
101
+ }
102
+ }
103
+
104
+ export { LoggerGroup };
@@ -9,16 +9,19 @@ class ActionEnqueuer {
9
9
  #action;
10
10
  #items;
11
11
  #jobRegistry;
12
+ #originUrl;
12
13
 
13
14
  /**
14
15
  * @param {ResourceRequestAction} action The action to enqueue for each item.
15
16
  * @param {Array} items List of parsed response items.
16
17
  * @param {object} [jobRegistry=JobRegistry] The job registry to enqueue jobs to.
18
+ * @param {string|null} [originUrl=null] The URL of the ResourceRequestJob that triggered this enqueue.
17
19
  */
18
- constructor(action, items, jobRegistry = DefaultJobRegistry) {
20
+ constructor(action, items, jobRegistry = DefaultJobRegistry, originUrl = null) {
19
21
  this.#action = action;
20
22
  this.#items = items;
21
23
  this.#jobRegistry = jobRegistry;
24
+ this.#originUrl = originUrl;
22
25
  }
23
26
 
24
27
  /**
@@ -29,9 +32,22 @@ class ActionEnqueuer {
29
32
  enqueue() {
30
33
  if (Application.isStopped()) return;
31
34
  for (const item of this.#items) {
32
- this.#jobRegistry.enqueue('Action', { action: this.#action, item });
35
+ this.#jobRegistry.enqueue('Action', this.#buildParams(item));
33
36
  }
34
37
  }
38
+
39
+ /**
40
+ * Builds the job params object for a single item, including originUrl when present.
41
+ * @param {object} item The parsed response item.
42
+ * @returns {object} The params object for the job registry.
43
+ * @private
44
+ */
45
+ #buildParams(item) {
46
+ const params = { action: this.#action, item };
47
+ if (this.#originUrl !== null) params.originUrl = this.#originUrl;
48
+ return params;
49
+ }
50
+
35
51
  }
36
52
 
37
53
  export { ActionEnqueuer };
@@ -1,5 +1,5 @@
1
1
  import { ActionEnqueuer } from './ActionEnqueuer.js';
2
- import { NullResponse } from '../exceptions/NullResponse.js';
2
+ import { NullResponse } from '../exceptions/request/NullResponse.js';
3
3
 
4
4
  /**
5
5
  * ActionsEnqueuer enqueues one ActionProcessingJob per (item × action) pair.
@@ -12,16 +12,19 @@ class ActionsEnqueuer {
12
12
  #actions;
13
13
  #items;
14
14
  #jobRegistry;
15
+ #originUrl;
15
16
 
16
17
  /**
17
18
  * @param {Array} actions List of ResourceRequestAction instances.
18
19
  * @param {Array} items List of ResponseWrapper instances (one per response item).
19
20
  * @param {object} [jobRegistry] The job registry to enqueue jobs to. Defaults to global JobRegistry.
21
+ * @param {string|null} [originUrl=null] The URL of the ResourceRequestJob that triggered this enqueue.
20
22
  */
21
- constructor(actions, items, jobRegistry) {
23
+ constructor(actions, items, jobRegistry, originUrl = null) {
22
24
  this.#actions = actions;
23
25
  this.#items = items;
24
26
  this.#jobRegistry = jobRegistry;
27
+ this.#originUrl = originUrl;
25
28
  }
26
29
 
27
30
  /**
@@ -34,7 +37,7 @@ class ActionsEnqueuer {
34
37
  if (this.#items === null) throw new NullResponse();
35
38
 
36
39
  for (const action of this.#actions) {
37
- new ActionEnqueuer(action, this.#items, this.#jobRegistry).enqueue();
40
+ new ActionEnqueuer(action, this.#items, this.#jobRegistry, this.#originUrl).enqueue();
38
41
  }
39
42
  }
40
43
  }
@@ -0,0 +1,53 @@
1
+ import { JobRegistry as DefaultJobRegistry } from '../background/JobRegistry.js';
2
+ import { Application } from '../services/Application.js';
3
+
4
+ /**
5
+ * Enqueues one PaginatedActionProcessingJob for a single paginated action.
6
+ * @author darthjee
7
+ */
8
+ class PaginatedActionEnqueuer {
9
+ #paginatedAction;
10
+ #responseWrapper;
11
+ #parameters;
12
+ #jobRegistry;
13
+ #originUrl;
14
+
15
+ /**
16
+ * @param {ResourceRequestPaginatedAction} paginatedAction The paginated action to enqueue.
17
+ * @param {ResponseWrapper} responseWrapper The response wrapper carrying response data.
18
+ * @param {object} [parameters={}] The original request parameters (key-value map for URL template resolution).
19
+ * @param {object} [jobRegistry=JobRegistry] The job registry to enqueue jobs to.
20
+ * @param {string|null} [originUrl=null] The URL of the ResourceRequestJob that triggered this enqueue.
21
+ */
22
+ constructor(paginatedAction, responseWrapper, parameters = {}, jobRegistry = DefaultJobRegistry, originUrl = null) {
23
+ this.#paginatedAction = paginatedAction;
24
+ this.#responseWrapper = responseWrapper;
25
+ this.#parameters = parameters;
26
+ this.#jobRegistry = jobRegistry;
27
+ this.#originUrl = originUrl;
28
+ }
29
+
30
+ /**
31
+ * Enqueues one PaginatedActionProcessingJob for the configured paginated action.
32
+ * Does nothing if the application is in 'stopped' status.
33
+ * @returns {void}
34
+ */
35
+ enqueue() {
36
+ if (Application.isStopped()) return;
37
+ this.#jobRegistry.enqueue('PaginatedAction', this.#buildParams());
38
+ }
39
+
40
+ /**
41
+ * Builds the job params object, including originUrl when present.
42
+ * @returns {object} The params object for the job registry.
43
+ * @private
44
+ */
45
+ #buildParams() {
46
+ const params = { paginatedAction: this.#paginatedAction, responseWrapper: this.#responseWrapper, parameters: this.#parameters };
47
+ if (this.#originUrl !== null) params.originUrl = this.#originUrl;
48
+ return params;
49
+ }
50
+
51
+ }
52
+
53
+ export { PaginatedActionEnqueuer };
@@ -0,0 +1,47 @@
1
+ import { PaginatedActionEnqueuer } from './PaginatedActionEnqueuer.js';
2
+ import { NullResponse } from '../exceptions/request/NullResponse.js';
3
+
4
+ /**
5
+ * Enqueues one PaginatedActionProcessingJob per paginated action for the given parameters.
6
+ *
7
+ * Delegates execution to the job queue instead of running paginated actions inline.
8
+ * Each paginated action is handled by a dedicated PaginatedActionEnqueuer.
9
+ * @author darthjee
10
+ */
11
+ class PaginatedActionsEnqueuer {
12
+ #paginatedActions;
13
+ #responseWrapper;
14
+ #parameters;
15
+ #jobRegistry;
16
+ #originUrl;
17
+
18
+ /**
19
+ * @param {Array<ResourceRequestPaginatedAction>} paginatedActions List of paginated action instances.
20
+ * @param {ResponseWrapper} responseWrapper The response wrapper carrying response data.
21
+ * @param {object} [parameters={}] The original request parameters (key-value map for URL template resolution).
22
+ * @param {object} [jobRegistry] The job registry to enqueue jobs to. Defaults to global JobRegistry.
23
+ * @param {string|null} [originUrl=null] The URL of the ResourceRequestJob that triggered this enqueue.
24
+ */
25
+ constructor(paginatedActions, responseWrapper, parameters = {}, jobRegistry, originUrl = null) {
26
+ this.#paginatedActions = paginatedActions;
27
+ this.#responseWrapper = responseWrapper;
28
+ this.#parameters = parameters;
29
+ this.#jobRegistry = jobRegistry;
30
+ this.#originUrl = originUrl;
31
+ }
32
+
33
+ /**
34
+ * Enqueues one PaginatedActionProcessingJob per paginated action.
35
+ * @returns {void}
36
+ * @throws {NullResponse} If the responseWrapper is null.
37
+ */
38
+ enqueue() {
39
+ if (this.#responseWrapper === null) throw new NullResponse();
40
+
41
+ for (const paginatedAction of this.#paginatedActions) {
42
+ new PaginatedActionEnqueuer(paginatedAction, this.#responseWrapper, this.#parameters, this.#jobRegistry, this.#originUrl).enqueue();
43
+ }
44
+ }
45
+ }
46
+
47
+ export { PaginatedActionsEnqueuer };
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  class ConfigurationFileNotFound extends AppError {
4
4
  constructor(file) {
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  class ConfigurationFileNotProvided extends AppError {
4
4
  constructor() {
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  /**
4
4
  * ItemNotFound is a custom error class thrown when a requested item
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  /**
4
4
  * ConflictError is thrown when a requested state transition is not valid
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  /**
4
4
  * ForbiddenError is thrown when a request is rejected due to a security
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  /**
4
4
  * NotFoundError is thrown when a requested resource cannot be found.
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  /**
4
4
  * ItemNotFound is a custom error class thrown when a requested item
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  /**
4
4
  * Thrown when an action config entry is missing the required "resource" field.
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  /**
4
4
  * Thrown when a parameters path expression cannot be resolved against the response wrapper.
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  /**
4
4
  * Thrown when an HTML response body cannot be parsed.
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  /**
4
4
  * Thrown when a response body cannot be parsed as JSON.
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  /**
4
4
  * Thrown when a parsed response body is null.
@@ -1,4 +1,4 @@
1
- import { AppError } from './AppError.js';
1
+ import { AppError } from '../AppError.js';
2
2
 
3
3
  /**
4
4
  * RequestFailed is a custom error class that represents a failed HTTP request.
@@ -9,6 +9,7 @@ import { Job } from '../background/Job.js';
9
9
  class ActionProcessingJob extends Job {
10
10
  #action;
11
11
  #item;
12
+ #originUrl;
12
13
 
13
14
  /**
14
15
  * Creates a new ActionProcessingJob instance.
@@ -16,19 +17,21 @@ class ActionProcessingJob extends Job {
16
17
  * @param {string} params.id - The unique identifier for this job.
17
18
  * @param {ResourceRequestAction} params.action - The action to execute.
18
19
  * @param {object} params.item - The parsed response item to pass to the action.
20
+ * @param {string|null} [params.originUrl=null] - The URL of the ResourceRequestJob that triggered this job.
19
21
  */
20
- constructor({ id, action, item }) {
22
+ constructor({ id, action, item, originUrl = null }) {
21
23
  super({ id });
22
24
  this.#action = action;
23
25
  this.#item = item;
26
+ this.#originUrl = originUrl;
24
27
  }
25
28
 
26
29
  /**
27
30
  * Returns the job-specific arguments for serialization.
28
- * @returns {{ item: object }} The job arguments.
31
+ * @returns {{ item: object, originUrl?: string }} The job arguments.
29
32
  */
30
33
  get arguments() {
31
- return { item: this.#item };
34
+ return { item: this.#item, ...this.#originUrlField() };
32
35
  }
33
36
 
34
37
  /**
@@ -55,6 +58,17 @@ class ActionProcessingJob extends Job {
55
58
  this._fail(error);
56
59
  }
57
60
  }
61
+
62
+ /**
63
+ * Returns an object containing the originUrl field when an origin URL is set,
64
+ * or an empty object otherwise.
65
+ * @returns {{ originUrl: string }|{}} The origin URL field or empty object.
66
+ * @private
67
+ */
68
+ #originUrlField() {
69
+ return this.#originUrl !== null ? { originUrl: this.#originUrl } : {};
70
+ }
71
+
58
72
  }
59
73
 
60
74
  export { ActionProcessingJob };