@zintrust/workers 0.1.27

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 (178) hide show
  1. package/README.md +861 -0
  2. package/dist/AnomalyDetection.d.ts +102 -0
  3. package/dist/AnomalyDetection.js +321 -0
  4. package/dist/AutoScaler.d.ts +127 -0
  5. package/dist/AutoScaler.js +425 -0
  6. package/dist/BroadcastWorker.d.ts +21 -0
  7. package/dist/BroadcastWorker.js +24 -0
  8. package/dist/CanaryController.d.ts +103 -0
  9. package/dist/CanaryController.js +380 -0
  10. package/dist/ChaosEngineering.d.ts +79 -0
  11. package/dist/ChaosEngineering.js +216 -0
  12. package/dist/CircuitBreaker.d.ts +106 -0
  13. package/dist/CircuitBreaker.js +374 -0
  14. package/dist/ClusterLock.d.ts +90 -0
  15. package/dist/ClusterLock.js +385 -0
  16. package/dist/ComplianceManager.d.ts +177 -0
  17. package/dist/ComplianceManager.js +556 -0
  18. package/dist/DatacenterOrchestrator.d.ts +133 -0
  19. package/dist/DatacenterOrchestrator.js +404 -0
  20. package/dist/DeadLetterQueue.d.ts +122 -0
  21. package/dist/DeadLetterQueue.js +539 -0
  22. package/dist/HealthMonitor.d.ts +42 -0
  23. package/dist/HealthMonitor.js +301 -0
  24. package/dist/MultiQueueWorker.d.ts +89 -0
  25. package/dist/MultiQueueWorker.js +277 -0
  26. package/dist/NotificationWorker.d.ts +21 -0
  27. package/dist/NotificationWorker.js +23 -0
  28. package/dist/Observability.d.ts +153 -0
  29. package/dist/Observability.js +530 -0
  30. package/dist/PluginManager.d.ts +123 -0
  31. package/dist/PluginManager.js +392 -0
  32. package/dist/PriorityQueue.d.ts +117 -0
  33. package/dist/PriorityQueue.js +244 -0
  34. package/dist/ResourceMonitor.d.ts +164 -0
  35. package/dist/ResourceMonitor.js +605 -0
  36. package/dist/SLAMonitor.d.ts +110 -0
  37. package/dist/SLAMonitor.js +274 -0
  38. package/dist/WorkerFactory.d.ts +193 -0
  39. package/dist/WorkerFactory.js +1507 -0
  40. package/dist/WorkerInit.d.ts +85 -0
  41. package/dist/WorkerInit.js +223 -0
  42. package/dist/WorkerMetrics.d.ts +114 -0
  43. package/dist/WorkerMetrics.js +509 -0
  44. package/dist/WorkerRegistry.d.ts +145 -0
  45. package/dist/WorkerRegistry.js +319 -0
  46. package/dist/WorkerShutdown.d.ts +61 -0
  47. package/dist/WorkerShutdown.js +159 -0
  48. package/dist/WorkerVersioning.d.ts +107 -0
  49. package/dist/WorkerVersioning.js +300 -0
  50. package/dist/build-manifest.json +462 -0
  51. package/dist/config/workerConfig.d.ts +3 -0
  52. package/dist/config/workerConfig.js +19 -0
  53. package/dist/createQueueWorker.d.ts +23 -0
  54. package/dist/createQueueWorker.js +113 -0
  55. package/dist/dashboard/index.d.ts +1 -0
  56. package/dist/dashboard/index.js +1 -0
  57. package/dist/dashboard/types.d.ts +117 -0
  58. package/dist/dashboard/types.js +1 -0
  59. package/dist/dashboard/workers-api.d.ts +4 -0
  60. package/dist/dashboard/workers-api.js +638 -0
  61. package/dist/dashboard/workers-dashboard-ui.d.ts +3 -0
  62. package/dist/dashboard/workers-dashboard-ui.js +1026 -0
  63. package/dist/dashboard/workers-dashboard.d.ts +4 -0
  64. package/dist/dashboard/workers-dashboard.js +904 -0
  65. package/dist/helper/index.d.ts +5 -0
  66. package/dist/helper/index.js +10 -0
  67. package/dist/http/WorkerApiController.d.ts +38 -0
  68. package/dist/http/WorkerApiController.js +312 -0
  69. package/dist/http/WorkerController.d.ts +374 -0
  70. package/dist/http/WorkerController.js +1351 -0
  71. package/dist/http/middleware/CustomValidation.d.ts +92 -0
  72. package/dist/http/middleware/CustomValidation.js +270 -0
  73. package/dist/http/middleware/DatacenterValidator.d.ts +3 -0
  74. package/dist/http/middleware/DatacenterValidator.js +94 -0
  75. package/dist/http/middleware/EditWorkerValidation.d.ts +7 -0
  76. package/dist/http/middleware/EditWorkerValidation.js +55 -0
  77. package/dist/http/middleware/FeaturesValidator.d.ts +3 -0
  78. package/dist/http/middleware/FeaturesValidator.js +60 -0
  79. package/dist/http/middleware/InfrastructureValidator.d.ts +31 -0
  80. package/dist/http/middleware/InfrastructureValidator.js +226 -0
  81. package/dist/http/middleware/OptionsValidator.d.ts +3 -0
  82. package/dist/http/middleware/OptionsValidator.js +112 -0
  83. package/dist/http/middleware/PayloadSanitizer.d.ts +7 -0
  84. package/dist/http/middleware/PayloadSanitizer.js +42 -0
  85. package/dist/http/middleware/ProcessorPathSanitizer.d.ts +3 -0
  86. package/dist/http/middleware/ProcessorPathSanitizer.js +74 -0
  87. package/dist/http/middleware/QueueNameSanitizer.d.ts +3 -0
  88. package/dist/http/middleware/QueueNameSanitizer.js +45 -0
  89. package/dist/http/middleware/ValidateDriver.d.ts +7 -0
  90. package/dist/http/middleware/ValidateDriver.js +20 -0
  91. package/dist/http/middleware/VersionSanitizer.d.ts +3 -0
  92. package/dist/http/middleware/VersionSanitizer.js +25 -0
  93. package/dist/http/middleware/WorkerNameSanitizer.d.ts +3 -0
  94. package/dist/http/middleware/WorkerNameSanitizer.js +46 -0
  95. package/dist/http/middleware/WorkerValidationChain.d.ts +27 -0
  96. package/dist/http/middleware/WorkerValidationChain.js +185 -0
  97. package/dist/index.d.ts +46 -0
  98. package/dist/index.js +48 -0
  99. package/dist/routes/workers.d.ts +12 -0
  100. package/dist/routes/workers.js +81 -0
  101. package/dist/storage/WorkerStore.d.ts +45 -0
  102. package/dist/storage/WorkerStore.js +195 -0
  103. package/dist/type.d.ts +76 -0
  104. package/dist/type.js +1 -0
  105. package/dist/ui/router/ui.d.ts +3 -0
  106. package/dist/ui/router/ui.js +83 -0
  107. package/dist/ui/types/worker-ui.d.ts +229 -0
  108. package/dist/ui/types/worker-ui.js +5 -0
  109. package/package.json +53 -0
  110. package/src/AnomalyDetection.ts +434 -0
  111. package/src/AutoScaler.ts +654 -0
  112. package/src/BroadcastWorker.ts +34 -0
  113. package/src/CanaryController.ts +531 -0
  114. package/src/ChaosEngineering.ts +301 -0
  115. package/src/CircuitBreaker.ts +495 -0
  116. package/src/ClusterLock.ts +499 -0
  117. package/src/ComplianceManager.ts +815 -0
  118. package/src/DatacenterOrchestrator.ts +561 -0
  119. package/src/DeadLetterQueue.ts +733 -0
  120. package/src/HealthMonitor.ts +390 -0
  121. package/src/MultiQueueWorker.ts +431 -0
  122. package/src/NotificationWorker.ts +33 -0
  123. package/src/Observability.ts +696 -0
  124. package/src/PluginManager.ts +551 -0
  125. package/src/PriorityQueue.ts +351 -0
  126. package/src/ResourceMonitor.ts +769 -0
  127. package/src/SLAMonitor.ts +408 -0
  128. package/src/WorkerFactory.ts +2108 -0
  129. package/src/WorkerInit.ts +313 -0
  130. package/src/WorkerMetrics.ts +709 -0
  131. package/src/WorkerRegistry.ts +443 -0
  132. package/src/WorkerShutdown.ts +210 -0
  133. package/src/WorkerVersioning.ts +422 -0
  134. package/src/config/workerConfig.ts +25 -0
  135. package/src/createQueueWorker.ts +174 -0
  136. package/src/dashboard/index.ts +6 -0
  137. package/src/dashboard/types.ts +141 -0
  138. package/src/dashboard/workers-api.ts +785 -0
  139. package/src/dashboard/zintrust.svg +30 -0
  140. package/src/helper/index.ts +11 -0
  141. package/src/http/WorkerApiController.ts +369 -0
  142. package/src/http/WorkerController.ts +1512 -0
  143. package/src/http/middleware/CustomValidation.ts +360 -0
  144. package/src/http/middleware/DatacenterValidator.ts +124 -0
  145. package/src/http/middleware/EditWorkerValidation.ts +74 -0
  146. package/src/http/middleware/FeaturesValidator.ts +82 -0
  147. package/src/http/middleware/InfrastructureValidator.ts +295 -0
  148. package/src/http/middleware/OptionsValidator.ts +144 -0
  149. package/src/http/middleware/PayloadSanitizer.ts +52 -0
  150. package/src/http/middleware/ProcessorPathSanitizer.ts +86 -0
  151. package/src/http/middleware/QueueNameSanitizer.ts +55 -0
  152. package/src/http/middleware/ValidateDriver.ts +29 -0
  153. package/src/http/middleware/VersionSanitizer.ts +30 -0
  154. package/src/http/middleware/WorkerNameSanitizer.ts +56 -0
  155. package/src/http/middleware/WorkerValidationChain.ts +230 -0
  156. package/src/index.ts +98 -0
  157. package/src/routes/workers.ts +154 -0
  158. package/src/storage/WorkerStore.ts +240 -0
  159. package/src/type.ts +89 -0
  160. package/src/types/queue-monitor.d.ts +38 -0
  161. package/src/types/queue-redis.d.ts +38 -0
  162. package/src/ui/README.md +13 -0
  163. package/src/ui/components/JsonEditor.js +670 -0
  164. package/src/ui/components/JsonViewer.js +387 -0
  165. package/src/ui/components/WorkerCard.js +178 -0
  166. package/src/ui/components/WorkerExpandPanel.js +257 -0
  167. package/src/ui/components/fetcher.js +42 -0
  168. package/src/ui/components/sla-scorecard.js +32 -0
  169. package/src/ui/components/styles.css +30 -0
  170. package/src/ui/components/table-expander.js +34 -0
  171. package/src/ui/integration/worker-ui-integration.js +565 -0
  172. package/src/ui/router/ui.ts +99 -0
  173. package/src/ui/services/workerApi.js +240 -0
  174. package/src/ui/types/worker-ui.ts +283 -0
  175. package/src/ui/utils/jsonValidator.js +444 -0
  176. package/src/ui/workers/index.html +202 -0
  177. package/src/ui/workers/main.js +1781 -0
  178. package/src/ui/workers/styles.css +1350 -0
@@ -0,0 +1,56 @@
1
+ import { Logger, type IRequest, type IResponse } from '@zintrust/core';
2
+
3
+ export type RouteHandler = (req: IRequest, res: IResponse) => Promise<void> | void;
4
+
5
+ const WORKER_NAME_PATTERN = /^[a-zA-Z0-9_-]{3,50}$/;
6
+
7
+ export const withWorkerNameValidation = (handler: RouteHandler): RouteHandler => {
8
+ return async (req: IRequest, res: IResponse): Promise<void> => {
9
+ try {
10
+ const data = req.data();
11
+ const workerName = data['name'] as string;
12
+
13
+ if (!workerName) {
14
+ return res.setStatus(400).json({
15
+ error: 'Worker name is required',
16
+ code: 'MISSING_WORKER_NAME',
17
+ });
18
+ }
19
+
20
+ if (!WORKER_NAME_PATTERN.test(workerName)) {
21
+ return res.setStatus(400).json({
22
+ error: 'Invalid worker name',
23
+ message:
24
+ 'Worker name must be 3-50 characters long and contain only letters, numbers, hyphens, and underscores',
25
+ code: 'INVALID_WORKER_NAME',
26
+ });
27
+ }
28
+
29
+ // Sanitize the name
30
+ const sanitizedName = workerName
31
+ .trim()
32
+ .replaceAll(/[^a-zA-Z0-9_-]/g, '')
33
+ .substring(0, 50);
34
+
35
+ if (sanitizedName.length < 3) {
36
+ return res.setStatus(400).json({
37
+ error: 'Worker name too short after sanitization',
38
+ message: 'Worker name must be at least 3 characters long',
39
+ code: 'WORKER_NAME_TOO_SHORT',
40
+ });
41
+ }
42
+
43
+ // Update the request data with sanitized value
44
+ const currentBody = req.getBody() as Record<string, unknown>;
45
+ req.setBody({ ...currentBody, name: sanitizedName });
46
+
47
+ return handler(req, res);
48
+ } catch (error) {
49
+ Logger.error('Worker name validation failed', error);
50
+ return res.setStatus(500).json({
51
+ error: 'Internal validation error',
52
+ code: 'VALIDATION_ERROR',
53
+ });
54
+ }
55
+ };
56
+ };
@@ -0,0 +1,230 @@
1
+ import { Logger, type IRequest, type IResponse } from '@zintrust/core';
2
+
3
+ export type RouteHandler = (req: IRequest, res: IResponse) => Promise<void> | void;
4
+
5
+ // Import individual validators
6
+ import { withDatacenterValidation } from './DatacenterValidator';
7
+ import { withFeaturesValidation } from './FeaturesValidator';
8
+ import { withInfrastructureValidation } from './InfrastructureValidator';
9
+ import { withOptionsValidation } from './OptionsValidator';
10
+ import { withStrictPayloadKeys } from './PayloadSanitizer';
11
+ import { withProcessorPathValidation } from './ProcessorPathSanitizer';
12
+ import { withQueueNameValidation } from './QueueNameSanitizer';
13
+ import { withVersionValidation } from './VersionSanitizer';
14
+ import { withWorkerNameValidation } from './WorkerNameSanitizer';
15
+
16
+ /**
17
+ * Composite middleware for worker creation validation
18
+ * Validates all required fields for creating a new worker
19
+ */
20
+ export const withCreateWorkerValidation = (handler: RouteHandler): RouteHandler => {
21
+ return withStrictPayloadKeys(
22
+ [
23
+ 'name',
24
+ 'queueName',
25
+ 'processor',
26
+ 'version',
27
+ 'options',
28
+ 'infrastructure',
29
+ 'features',
30
+ 'datacenter',
31
+ ],
32
+ withProcessorPathValidation(
33
+ withWorkerNameValidation(
34
+ withQueueNameValidation(
35
+ withVersionValidation(
36
+ withOptionsValidation(
37
+ withInfrastructureValidation(
38
+ withFeaturesValidation(withDatacenterValidation(handler))
39
+ )
40
+ )
41
+ )
42
+ )
43
+ )
44
+ )
45
+ );
46
+ };
47
+
48
+ /**
49
+ * Composite middleware for worker update validation
50
+ * Validates optional fields for updating an existing worker
51
+ */
52
+ export const withUpdateWorkerValidation = (handler: RouteHandler): RouteHandler => {
53
+ return withVersionValidation(
54
+ withInfrastructureValidation(withFeaturesValidation(withDatacenterValidation(handler)))
55
+ );
56
+ };
57
+
58
+ /**
59
+ * Composite middleware for worker operation validation
60
+ * Validates worker name for operations like start, stop, restart, etc.
61
+ */
62
+ export const withWorkerOperationValidation = (handler: RouteHandler): RouteHandler => {
63
+ return withWorkerNameValidation(handler);
64
+ };
65
+
66
+ /**
67
+ * Composite middleware for bulk operations validation
68
+ * Validates arrays of worker names and operation parameters
69
+ */
70
+ export const withBulkOperationValidation = (handler: RouteHandler): RouteHandler => {
71
+ return async (req: IRequest, res: IResponse): Promise<void> => {
72
+ try {
73
+ const data = req.data();
74
+ const workerNames = data['workerNames'] as string[] | string;
75
+
76
+ // Handle single worker name or array of names
77
+ const names = Array.isArray(workerNames) ? workerNames : [workerNames];
78
+
79
+ // Prevent enormous bulk operations
80
+ const MAX_BULK_NAMES = 1000;
81
+ if (names.length > MAX_BULK_NAMES) {
82
+ return res.setStatus(413).json({
83
+ error: 'Too many worker names',
84
+ message: `Bulk operation exceeds maximum allowed names (${MAX_BULK_NAMES})`,
85
+ code: 'BULK_OPERATION_TOO_LARGE',
86
+ });
87
+ }
88
+
89
+ if (!names || names.length === 0) {
90
+ return res.setStatus(400).json({
91
+ error: 'Worker names are required',
92
+ message: 'At least one worker name must be provided',
93
+ code: 'MISSING_WORKER_NAMES',
94
+ });
95
+ }
96
+
97
+ // Validate each worker name
98
+ const WORKER_NAME_PATTERN = /^[a-zA-Z0-9_-]{3,50}$/;
99
+ for (const name of names) {
100
+ if (!name || typeof name !== 'string') {
101
+ return res.setStatus(400).json({
102
+ error: 'Invalid worker name',
103
+ message: 'Worker name must be a string',
104
+ code: 'INVALID_WORKER_NAME_TYPE',
105
+ });
106
+ }
107
+
108
+ if (!WORKER_NAME_PATTERN.test(name)) {
109
+ return res.setStatus(400).json({
110
+ error: 'Invalid worker name',
111
+ message: `Worker name "${name}" must be 3-50 characters long and contain only letters, numbers, hyphens, and underscores`,
112
+ code: 'INVALID_WORKER_NAME',
113
+ });
114
+ }
115
+ }
116
+
117
+ // Sanitize worker names
118
+ const sanitizedNames = names
119
+ .map((name) =>
120
+ name
121
+ .trim()
122
+ .replaceAll(/[^a-zA-Z0-9_-]/g, '')
123
+ .substring(0, 50)
124
+ )
125
+ .filter((name) => name.length >= 3);
126
+
127
+ if (sanitizedNames.length === 0) {
128
+ return res.setStatus(400).json({
129
+ error: 'No valid worker names after sanitization',
130
+ message: 'All worker names were invalid after sanitization',
131
+ code: 'NO_VALID_WORKER_NAMES',
132
+ });
133
+ }
134
+
135
+ // Update request data with sanitized names
136
+ const currentBody = req.getBody() as Record<string, unknown>;
137
+ req.setBody({ ...currentBody, workerNames: sanitizedNames });
138
+
139
+ return handler(req, res);
140
+ } catch (error) {
141
+ Logger.error('Bulk operation validation failed', error);
142
+ return res.setStatus(500).json({
143
+ error: 'Internal validation error',
144
+ code: 'VALIDATION_ERROR',
145
+ });
146
+ }
147
+ };
148
+ };
149
+
150
+ /**
151
+ * Composite middleware for canary deployment validation
152
+ * Validates canary-specific parameters
153
+ */
154
+ export const withCanaryDeploymentValidation = (handler: RouteHandler): RouteHandler => {
155
+ return async (req: IRequest, res: IResponse): Promise<void> => {
156
+ try {
157
+ const data = req.data();
158
+ const newVersion = data['newVersion'] as string;
159
+ const initialTrafficPercent = data['initialTrafficPercent'] as number;
160
+ const targetTrafficPercent = data['targetTrafficPercent'] as number;
161
+
162
+ // Validate new version
163
+ if (!newVersion) {
164
+ return res.setStatus(400).json({
165
+ error: 'New version is required',
166
+ code: 'MISSING_NEW_VERSION',
167
+ });
168
+ }
169
+
170
+ const VERSION_PATTERN = /^\d+\.\d+\.\d+$/;
171
+ if (!VERSION_PATTERN.test(newVersion)) {
172
+ return res.setStatus(400).json({
173
+ error: 'Invalid version format',
174
+ message: 'Version must follow semantic versioning (e.g., 1.0.0)',
175
+ code: 'INVALID_VERSION_FORMAT',
176
+ });
177
+ }
178
+
179
+ // Validate initial traffic percent
180
+ if (initialTrafficPercent !== undefined) {
181
+ if (
182
+ typeof initialTrafficPercent !== 'number' ||
183
+ initialTrafficPercent < 0 ||
184
+ initialTrafficPercent > 100
185
+ ) {
186
+ return res.setStatus(400).json({
187
+ error: 'Invalid initial traffic percent',
188
+ message: 'Initial traffic percent must be a number between 0 and 100',
189
+ code: 'INVALID_INITIAL_TRAFFIC_PERCENT',
190
+ });
191
+ }
192
+ }
193
+
194
+ // Validate target traffic percent
195
+ if (targetTrafficPercent !== undefined) {
196
+ if (
197
+ typeof targetTrafficPercent !== 'number' ||
198
+ targetTrafficPercent < 0 ||
199
+ targetTrafficPercent > 100
200
+ ) {
201
+ return res.setStatus(400).json({
202
+ error: 'Invalid target traffic percent',
203
+ message: 'Target traffic percent must be a number between 0 and 100',
204
+ code: 'INVALID_TARGET_TRAFFIC_PERCENT',
205
+ });
206
+ }
207
+ }
208
+
209
+ // Validate traffic progression
210
+ if (initialTrafficPercent !== undefined && targetTrafficPercent !== undefined) {
211
+ if (targetTrafficPercent < initialTrafficPercent) {
212
+ return res.setStatus(400).json({
213
+ error: 'Invalid traffic progression',
214
+ message:
215
+ 'Target traffic percent must be greater than or equal to initial traffic percent',
216
+ code: 'INVALID_TRAFFIC_PROGRESSION',
217
+ });
218
+ }
219
+ }
220
+
221
+ return handler(req, res);
222
+ } catch (error) {
223
+ Logger.error('Canary deployment validation failed', error);
224
+ return res.setStatus(500).json({
225
+ error: 'Internal validation error',
226
+ code: 'VALIDATION_ERROR',
227
+ });
228
+ }
229
+ };
230
+ };
package/src/index.ts ADDED
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Worker Management System - Public API
3
+ *
4
+ * Central export file for all worker management modules.
5
+ */
6
+
7
+ // Core Infrastructure
8
+ export { ClusterLock } from './ClusterLock';
9
+ export { PriorityQueue } from './PriorityQueue';
10
+ export { WorkerMetrics } from './WorkerMetrics';
11
+ export { WorkerRegistry } from './WorkerRegistry';
12
+
13
+ // Resilience & Recovery
14
+ export { AutoScaler } from './AutoScaler';
15
+ export { CircuitBreaker } from './CircuitBreaker';
16
+ export { DeadLetterQueue } from './DeadLetterQueue';
17
+
18
+ // Monitoring & Resources
19
+ export { HealthMonitor } from './HealthMonitor';
20
+ export { ResourceMonitor } from './ResourceMonitor';
21
+ export { SLAMonitor } from './SLAMonitor';
22
+
23
+ // Compliance & Security
24
+ export { ComplianceManager } from './ComplianceManager';
25
+
26
+ // Observability
27
+ export { Observability } from './Observability';
28
+
29
+ // Plugin System
30
+ export { PluginManager } from './PluginManager';
31
+
32
+ // Advanced Features
33
+ export { AnomalyDetection } from './AnomalyDetection';
34
+ export { CanaryController } from './CanaryController';
35
+ export { ChaosEngineering } from './ChaosEngineering';
36
+ export { DatacenterOrchestrator } from './DatacenterOrchestrator';
37
+ export { MultiQueueWorker } from './MultiQueueWorker';
38
+ export { WorkerVersioning } from './WorkerVersioning';
39
+
40
+ // Factory & Lifecycle
41
+ export { WorkerFactory } from './WorkerFactory';
42
+ export type { WorkerPersistenceConfig } from './WorkerFactory';
43
+ export { WorkerInit } from './WorkerInit';
44
+ export { WorkerShutdown } from './WorkerShutdown';
45
+
46
+ // HTTP Controllers & Routes
47
+ export { WorkerController } from './http/WorkerController';
48
+ export { registerWorkerRoutes } from './routes/workers';
49
+
50
+ // Queue Workers
51
+ export { BroadcastWorker } from './BroadcastWorker';
52
+ export { createQueueWorker } from './createQueueWorker';
53
+ export type { CreateQueueWorkerOptions } from './createQueueWorker';
54
+
55
+ export { NotificationWorker } from './NotificationWorker';
56
+
57
+ // Re-export types from core config
58
+ export type {
59
+ RedisConfig,
60
+ WorkerAutoScalingConfig,
61
+ WorkerComplianceConfig,
62
+ WorkerConfig,
63
+ WorkerCostConfig,
64
+ WorkerObservabilityConfig,
65
+ WorkersConfigOverrides,
66
+ WorkersGlobalConfig,
67
+ WorkerStatus,
68
+ WorkerVersioningConfig,
69
+ } from '@zintrust/core';
70
+
71
+ // Re-export bullmq types for type compatibility
72
+ export type { Job, Worker, WorkerOptions } from 'bullmq';
73
+
74
+ export type {
75
+ IAnomaly,
76
+ IAnomalyConfig,
77
+ IForecast,
78
+ IMetric,
79
+ IPrediction,
80
+ IRecommendation,
81
+ IRootCauseAnalysis,
82
+ } from './AnomalyDetection';
83
+ export type {
84
+ IChaosComparison,
85
+ IChaosExperiment,
86
+ IChaosReport,
87
+ IChaosStatus,
88
+ } from './ChaosEngineering';
89
+ export type { ISLAConfig, ISLAReport, ISLAStatus, ISLAViolation, ITimeRange } from './SLAMonitor';
90
+
91
+ export type * from './type';
92
+
93
+ /**
94
+ * Package version and build metadata
95
+ * Available at runtime for debugging and health checks
96
+ */
97
+ export const _ZINTRUST_WORKERS_VERSION = '0.1.0';
98
+ export const _ZINTRUST_WORKERS_BUILD_DATE = '__BUILD_DATE__';
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Worker Management Routes
3
+ * HTTP API for managing workers with dashboard functionality
4
+ */
5
+
6
+ import type { IRouter } from '@zintrust/core';
7
+ import { Logger, Router } from '@zintrust/core';
8
+ import { type WorkersDashboardUiOptions } from '../dashboard';
9
+ import { WorkerApiController } from '../http/WorkerApiController';
10
+ import { WorkerController } from '../http/WorkerController';
11
+ import { ValidationSchemas, withCustomValidation } from '../http/middleware/CustomValidation';
12
+ import { withEditWorkerValidation } from '../http/middleware/EditWorkerValidation';
13
+ import { withDriverValidation } from '../http/middleware/ValidateDriver';
14
+ import {
15
+ withCreateWorkerValidation,
16
+ withWorkerOperationValidation,
17
+ } from '../http/middleware/WorkerValidationChain';
18
+ import { registerStaticAssets } from '../ui/router/ui';
19
+
20
+ type WorkerUiOptions = WorkersDashboardUiOptions;
21
+ type RouteOptions = { middleware?: ReadonlyArray<string> } | undefined;
22
+
23
+ const controller = WorkerController.create();
24
+ const apiController = WorkerApiController.create();
25
+
26
+ function registerCoreWorkerRoutes(r: IRouter): void {
27
+ // Core worker operations
28
+ Router.post(r, '/create', withCreateWorkerValidation(controller.create));
29
+ Router.put(r, '/:name', withCreateWorkerValidation(controller.update));
30
+
31
+ // Worker editing with custom validation that handles processorPath mapping
32
+ Router.put(r, '/:name/edit', withEditWorkerValidation(controller.update));
33
+ Router.post(
34
+ r,
35
+ '/:name/start',
36
+ withDriverValidation(withWorkerOperationValidation(controller.start))
37
+ );
38
+ Router.post(
39
+ r,
40
+ '/:name/auto-start',
41
+ withDriverValidation(withWorkerOperationValidation(controller.setAutoStart))
42
+ );
43
+ Router.post(
44
+ r,
45
+ '/:name/stop',
46
+ withDriverValidation(withWorkerOperationValidation(controller.stop))
47
+ );
48
+ Router.post(
49
+ r,
50
+ '/:name/restart',
51
+ withDriverValidation(withWorkerOperationValidation(controller.restart))
52
+ );
53
+ Router.post(
54
+ r,
55
+ '/:name/pause',
56
+ withDriverValidation(withWorkerOperationValidation(controller.pause))
57
+ );
58
+ Router.post(
59
+ r,
60
+ '/:name/resume',
61
+ withDriverValidation(withWorkerOperationValidation(controller.resume))
62
+ );
63
+ Router.del(r, '/:name', withDriverValidation(withWorkerOperationValidation(controller.remove)));
64
+ }
65
+
66
+ function registerWorkerQueryRoutes(r: IRouter): void {
67
+ // Worker listing and filtering
68
+ Router.get(
69
+ r,
70
+ '/',
71
+ withDriverValidation(
72
+ withCustomValidation(ValidationSchemas.workerFilter, apiController.listWorkers)
73
+ )
74
+ );
75
+
76
+ Router.get(r, '/:name', withDriverValidation(withWorkerOperationValidation(controller.get)));
77
+
78
+ Router.get(r, '/:name/status', withWorkerOperationValidation(controller.status));
79
+ Router.get(
80
+ r,
81
+ '/:name/creation-status',
82
+ withWorkerOperationValidation(controller.getCreationStatus)
83
+ );
84
+ Router.get(r, '/:name/metrics', withWorkerOperationValidation(controller.metrics));
85
+ Router.get(r, '/:name/health', withWorkerOperationValidation(controller.health));
86
+
87
+ // Worker details
88
+ Router.get(r, '/:name/details', withDriverValidation(apiController.getWorkerDetailsHandler));
89
+
90
+ // Worker driver data for editing
91
+ Router.get(
92
+ r,
93
+ '/:name/driver-data',
94
+ withDriverValidation(apiController.getWorkerDriverDataHandler)
95
+ );
96
+ }
97
+
98
+ function registerMonitoringRoutes(r: IRouter): void {
99
+ // Health monitoring
100
+ Router.post(r, '/:name/monitoring/start', controller.startMonitoring);
101
+ Router.post(r, '/:name/monitoring/stop', controller.stopMonitoring);
102
+ Router.get(r, '/:name/monitoring/history', controller.healthHistory);
103
+ Router.get(r, '/:name/monitoring/trend', controller.healthTrend);
104
+ Router.put(r, '/:name/monitoring/config', controller.updateMonitoringConfig);
105
+
106
+ // SLA monitoring
107
+ Router.get(r, '/:name/sla/status', controller.getSlaStatus);
108
+
109
+ // SSE events stream for monitoring + workers snapshot
110
+ Router.get(r, '/events', controller.eventsStream);
111
+ }
112
+
113
+ function registerVersioningRoutes(r: IRouter): void {
114
+ // Versioning
115
+ Router.post(r, '/:name/versions', controller.registerVersion);
116
+ Router.get(r, '/:name/versions', controller.listVersions);
117
+ Router.get(r, '/:name/versions/:version', controller.getVersion);
118
+ }
119
+
120
+ function registerUtilityRoutes(r: IRouter): void {
121
+ // Utility endpoints
122
+ Router.get(r, '/drivers', apiController.getDriversHandler);
123
+ Router.get(r, '/queue-data', apiController.getQueueDataHandler);
124
+ Router.get(r, '/health', apiController.getHealthSummaryHandler);
125
+ }
126
+
127
+ function registerWorkerLifecycleRoutes(router: IRouter, middleware?: ReadonlyArray<string>): void {
128
+ Router.group(
129
+ router,
130
+ '/api/workers',
131
+ (r: IRouter) => {
132
+ Logger.info('Registering Worker Management Routes');
133
+
134
+ registerCoreWorkerRoutes(r);
135
+ registerWorkerQueryRoutes(r);
136
+ registerMonitoringRoutes(r);
137
+ registerVersioningRoutes(r);
138
+ registerUtilityRoutes(r);
139
+ },
140
+ { middleware: middleware }
141
+ );
142
+ }
143
+
144
+ export function registerWorkerRoutes(
145
+ router: IRouter,
146
+ _options?: WorkerUiOptions,
147
+ routeOptions?: RouteOptions
148
+ ): void {
149
+ registerStaticAssets(router, routeOptions?.middleware ?? []);
150
+ registerWorkerLifecycleRoutes(router, routeOptions?.middleware);
151
+ Logger.info('Worker routes registered at http://127.0.0.1:7777/workers');
152
+ }
153
+
154
+ export default registerWorkerRoutes;