@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,92 @@
1
+ import { type IRequest, type IResponse } from '@zintrust/core';
2
+ export type RouteHandler = (req: IRequest, res: IResponse) => Promise<void> | void;
3
+ export interface ValidationSchema {
4
+ [key: string]: {
5
+ required?: boolean;
6
+ default?: unknown;
7
+ type?: 'string' | 'number' | 'boolean' | 'object' | 'array';
8
+ minLength?: number;
9
+ maxLength?: number;
10
+ min?: number;
11
+ max?: number;
12
+ pattern?: RegExp;
13
+ allowedValues?: unknown[];
14
+ custom?: (value: unknown) => string | null;
15
+ };
16
+ }
17
+ export declare const withCustomValidation: (schema: ValidationSchema, handler: RouteHandler) => RouteHandler;
18
+ /**
19
+ * Predefined validation schemas for common use cases
20
+ */
21
+ export declare const ValidationSchemas: {
22
+ /**
23
+ * Schema for pagination parameters
24
+ */
25
+ pagination: {
26
+ page: {
27
+ type: "number";
28
+ min: number;
29
+ default: number;
30
+ };
31
+ limit: {
32
+ type: "number";
33
+ min: number;
34
+ max: number;
35
+ default: number;
36
+ };
37
+ };
38
+ /**
39
+ * Schema for date range filtering
40
+ */
41
+ dateRange: {
42
+ startDate: {
43
+ type: "string";
44
+ pattern: RegExp;
45
+ };
46
+ endDate: {
47
+ type: "string";
48
+ pattern: RegExp;
49
+ };
50
+ };
51
+ /**
52
+ * Schema for sorting parameters
53
+ */
54
+ sorting: {
55
+ sortBy: {
56
+ type: "string";
57
+ allowedValues: string[];
58
+ default: string;
59
+ };
60
+ sortOrder: {
61
+ type: "string";
62
+ allowedValues: string[];
63
+ default: string;
64
+ };
65
+ };
66
+ /**
67
+ * Schema for worker filtering
68
+ */
69
+ workerFilter: {
70
+ status: {
71
+ type: "string";
72
+ allowedValues: string[];
73
+ optional: boolean;
74
+ };
75
+ queueName: {
76
+ type: "string";
77
+ minLength: number;
78
+ maxLength: number;
79
+ optional: boolean;
80
+ };
81
+ driver: {
82
+ type: "string";
83
+ allowedValues: string[];
84
+ optional: boolean;
85
+ };
86
+ search: {
87
+ type: "string";
88
+ maxLength: number;
89
+ optional: boolean;
90
+ };
91
+ };
92
+ };
@@ -0,0 +1,270 @@
1
+ import { Logger } from '@zintrust/core';
2
+ /**
3
+ * Custom validation middleware that accepts a validation schema
4
+ * Provides flexible validation for any request data structure
5
+ */
6
+ const validateRequiredField = (fieldName, value, fieldSchema) => {
7
+ if (fieldSchema.required && (value === undefined || value === null)) {
8
+ return {
9
+ field: fieldName,
10
+ message: `${fieldName} is required`,
11
+ code: 'MISSING_REQUIRED_FIELD',
12
+ };
13
+ }
14
+ return null;
15
+ };
16
+ const validateFieldType = (fieldName, value, fieldSchema) => {
17
+ if (!fieldSchema.type)
18
+ return null;
19
+ const actualType = Array.isArray(value) ? 'array' : typeof value;
20
+ if (actualType !== fieldSchema.type) {
21
+ return {
22
+ field: fieldName,
23
+ message: `${fieldName} must be of type ${fieldSchema.type}`,
24
+ code: 'INVALID_TYPE',
25
+ };
26
+ }
27
+ return null;
28
+ };
29
+ const validateStringField = (fieldName, value, fieldSchema) => {
30
+ const errors = [];
31
+ if (fieldSchema.minLength !== undefined && value.length < fieldSchema.minLength) {
32
+ errors.push({
33
+ field: fieldName,
34
+ message: `${fieldName} must be at least ${fieldSchema.minLength} characters long`,
35
+ code: 'STRING_TOO_SHORT',
36
+ });
37
+ }
38
+ if (fieldSchema.maxLength !== undefined && value.length > fieldSchema.maxLength) {
39
+ errors.push({
40
+ field: fieldName,
41
+ message: `${fieldName} must be at most ${fieldSchema.maxLength} characters long`,
42
+ code: 'STRING_TOO_LONG',
43
+ });
44
+ }
45
+ if (fieldSchema.pattern && !fieldSchema.pattern.test(value)) {
46
+ errors.push({
47
+ field: fieldName,
48
+ message: `${fieldName} format is invalid`,
49
+ code: 'INVALID_FORMAT',
50
+ });
51
+ }
52
+ return errors;
53
+ };
54
+ const validateNumberField = (fieldName, value, fieldSchema) => {
55
+ const errors = [];
56
+ if (fieldSchema.min !== undefined && value < fieldSchema.min) {
57
+ errors.push({
58
+ field: fieldName,
59
+ message: `${fieldName} must be at least ${fieldSchema.min}`,
60
+ code: 'NUMBER_TOO_SMALL',
61
+ });
62
+ }
63
+ if (fieldSchema.max !== undefined && value > fieldSchema.max) {
64
+ errors.push({
65
+ field: fieldName,
66
+ message: `${fieldName} must be at most ${fieldSchema.max}`,
67
+ code: 'NUMBER_TOO_LARGE',
68
+ });
69
+ }
70
+ return errors;
71
+ };
72
+ const validateArrayField = (fieldName, value, fieldSchema) => {
73
+ const errors = [];
74
+ if (fieldSchema.minLength !== undefined && value.length < fieldSchema.minLength) {
75
+ errors.push({
76
+ field: fieldName,
77
+ message: `${fieldName} must contain at least ${fieldSchema.minLength} items`,
78
+ code: 'ARRAY_TOO_SHORT',
79
+ });
80
+ }
81
+ if (fieldSchema.maxLength !== undefined && value.length > fieldSchema.maxLength) {
82
+ errors.push({
83
+ field: fieldName,
84
+ message: `${fieldName} must contain at most ${fieldSchema.maxLength} items`,
85
+ code: 'ARRAY_TOO_LONG',
86
+ });
87
+ }
88
+ return errors;
89
+ };
90
+ const validateAllowedValues = (fieldName, value, fieldSchema) => {
91
+ if (fieldSchema.allowedValues && !fieldSchema.allowedValues.includes(value)) {
92
+ return {
93
+ field: fieldName,
94
+ message: `${fieldName} must be one of: ${fieldSchema.allowedValues.join(', ')}`,
95
+ code: 'INVALID_VALUE',
96
+ };
97
+ }
98
+ return null;
99
+ };
100
+ const validateCustomRule = (fieldName, value, fieldSchema) => {
101
+ if (fieldSchema.custom) {
102
+ const customError = fieldSchema.custom(value);
103
+ if (customError) {
104
+ return {
105
+ field: fieldName,
106
+ message: customError,
107
+ code: 'CUSTOM_VALIDATION_FAILED',
108
+ };
109
+ }
110
+ }
111
+ return null;
112
+ };
113
+ const validateField = (fieldName, value, fieldSchema) => {
114
+ const errors = [];
115
+ // Check required field
116
+ const requiredError = validateRequiredField(fieldName, value, fieldSchema);
117
+ if (requiredError) {
118
+ errors.push(requiredError);
119
+ return errors; // Skip other validations for missing required field
120
+ }
121
+ // Skip validation if field is not provided and not required
122
+ if (value === undefined || value === null) {
123
+ return errors;
124
+ }
125
+ // Type validation
126
+ const typeError = validateFieldType(fieldName, value, fieldSchema);
127
+ if (typeError) {
128
+ errors.push(typeError);
129
+ return errors; // Skip other validations for wrong type
130
+ }
131
+ // String validations
132
+ if (typeof value === 'string') {
133
+ errors.push(...validateStringField(fieldName, value, fieldSchema));
134
+ }
135
+ // Number validations
136
+ if (typeof value === 'number') {
137
+ errors.push(...validateNumberField(fieldName, value, fieldSchema));
138
+ }
139
+ // Array validations
140
+ if (Array.isArray(value)) {
141
+ errors.push(...validateArrayField(fieldName, value, fieldSchema));
142
+ }
143
+ // Allowed values validation
144
+ const allowedValuesError = validateAllowedValues(fieldName, value, fieldSchema);
145
+ if (allowedValuesError) {
146
+ errors.push(allowedValuesError);
147
+ }
148
+ // Custom validation
149
+ const customError = validateCustomRule(fieldName, value, fieldSchema);
150
+ if (customError) {
151
+ errors.push(customError);
152
+ }
153
+ return errors;
154
+ };
155
+ export const withCustomValidation = (schema, handler) => {
156
+ return async (req, res) => {
157
+ try {
158
+ const currentBody = req.getBody();
159
+ const data = { ...req.data() };
160
+ // Apply defaults from schema into request body when missing
161
+ for (const [fieldName, fieldSchema] of Object.entries(schema)) {
162
+ if ((data[fieldName] === undefined || data[fieldName] === null) &&
163
+ fieldSchema.default !== undefined) {
164
+ data[fieldName] = fieldSchema.default;
165
+ }
166
+ }
167
+ // Persist defaults back into request body so downstream handlers see them
168
+ req.setBody({ ...currentBody, ...data });
169
+ const errors = [];
170
+ // Validate each field in the schema
171
+ for (const [fieldName, fieldSchema] of Object.entries(schema)) {
172
+ const value = data[fieldName];
173
+ const fieldErrors = validateField(fieldName, value, fieldSchema);
174
+ errors.push(...fieldErrors);
175
+ }
176
+ // Return errors if any validation failed
177
+ if (errors.length > 0) {
178
+ return res.setStatus(400).json({
179
+ error: 'Validation failed',
180
+ message: 'Request data validation failed',
181
+ code: 'VALIDATION_FAILED',
182
+ details: errors,
183
+ });
184
+ }
185
+ return handler(req, res);
186
+ }
187
+ catch (error) {
188
+ Logger.error('Custom validation failed', error);
189
+ return res.setStatus(500).json({
190
+ error: 'Internal validation error',
191
+ code: 'VALIDATION_ERROR',
192
+ });
193
+ }
194
+ };
195
+ };
196
+ /**
197
+ * Predefined validation schemas for common use cases
198
+ */
199
+ export const ValidationSchemas = {
200
+ /**
201
+ * Schema for pagination parameters
202
+ */
203
+ pagination: {
204
+ page: {
205
+ type: 'number',
206
+ min: 1,
207
+ default: 1,
208
+ },
209
+ limit: {
210
+ type: 'number',
211
+ min: 1,
212
+ max: 100,
213
+ default: 20,
214
+ },
215
+ },
216
+ /**
217
+ * Schema for date range filtering
218
+ */
219
+ dateRange: {
220
+ startDate: {
221
+ type: 'string',
222
+ pattern: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/,
223
+ },
224
+ endDate: {
225
+ type: 'string',
226
+ pattern: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/,
227
+ },
228
+ },
229
+ /**
230
+ * Schema for sorting parameters
231
+ */
232
+ sorting: {
233
+ sortBy: {
234
+ type: 'string',
235
+ allowedValues: ['name', 'status', 'createdAt', 'updatedAt', 'queueName'],
236
+ default: 'createdAt',
237
+ },
238
+ sortOrder: {
239
+ type: 'string',
240
+ allowedValues: ['asc', 'desc'],
241
+ default: 'desc',
242
+ },
243
+ },
244
+ /**
245
+ * Schema for worker filtering
246
+ */
247
+ workerFilter: {
248
+ status: {
249
+ type: 'string',
250
+ allowedValues: ['running', 'stopped', 'failed', 'paused', ''],
251
+ optional: true,
252
+ },
253
+ queueName: {
254
+ type: 'string',
255
+ minLength: 3,
256
+ maxLength: 50,
257
+ optional: true,
258
+ },
259
+ driver: {
260
+ type: 'string',
261
+ allowedValues: ['db', 'redis', 'memory', ''],
262
+ optional: true,
263
+ },
264
+ search: {
265
+ type: 'string',
266
+ maxLength: 100,
267
+ optional: true,
268
+ },
269
+ },
270
+ };
@@ -0,0 +1,3 @@
1
+ import { type IRequest, type IResponse } from '@zintrust/core';
2
+ export type RouteHandler = (req: IRequest, res: IResponse) => Promise<void> | void;
3
+ export declare const withDatacenterValidation: (handler: RouteHandler) => RouteHandler;
@@ -0,0 +1,94 @@
1
+ import { Logger } from '@zintrust/core';
2
+ const validateRegion = (region) => {
3
+ // Allow custom region names but validate format
4
+ return /^[a-z0-9-]+$/.test(region) && region.length >= 3 && region.length <= 20;
5
+ };
6
+ const validatePrimaryRegion = (primaryRegion) => {
7
+ if (!primaryRegion) {
8
+ return 'Primary region is required';
9
+ }
10
+ if (!validateRegion(primaryRegion)) {
11
+ return 'Primary region must be 3-20 characters, lowercase letters, numbers, and hyphens only';
12
+ }
13
+ return null;
14
+ };
15
+ const validateSecondaryRegions = (secondaryRegions) => {
16
+ if (!Array.isArray(secondaryRegions)) {
17
+ return 'Secondary regions must be an array';
18
+ }
19
+ for (const region of secondaryRegions) {
20
+ if (!validateRegion(region)) {
21
+ return `Secondary region '${region}' must be 3-20 characters, lowercase letters, numbers, and hyphens only`;
22
+ }
23
+ }
24
+ return null;
25
+ };
26
+ const validateAffinityRules = (affinityRules) => {
27
+ if (!affinityRules) {
28
+ return 'Affinity rules are required';
29
+ }
30
+ if (typeof affinityRules.preferLocal !== 'boolean') {
31
+ return 'Affinity rule preferLocal must be a boolean';
32
+ }
33
+ if (typeof affinityRules.maxLatency !== 'number' || affinityRules.maxLatency < 0) {
34
+ return 'Affinity rule maxLatency must be a non-negative number';
35
+ }
36
+ if (!Array.isArray(affinityRules.avoidRegions)) {
37
+ return 'Affinity rule avoidRegions must be an array';
38
+ }
39
+ for (const region of affinityRules.avoidRegions) {
40
+ if (!validateRegion(region)) {
41
+ return `Avoid region '${region}' must be 3-20 characters, lowercase letters, numbers, and hyphens only`;
42
+ }
43
+ }
44
+ return null;
45
+ };
46
+ export const withDatacenterValidation = (handler) => {
47
+ return async (req, res) => {
48
+ try {
49
+ const data = req.data();
50
+ const datacenter = data['datacenter'];
51
+ if (!datacenter) {
52
+ return res.setStatus(400).json({
53
+ error: 'Datacenter configuration is required',
54
+ code: 'MISSING_DATACENTER',
55
+ });
56
+ }
57
+ // Validate primary region
58
+ const primaryRegionError = validatePrimaryRegion(datacenter.primaryRegion);
59
+ if (primaryRegionError) {
60
+ return res.setStatus(400).json({
61
+ error: 'Invalid primary region',
62
+ message: primaryRegionError,
63
+ code: 'INVALID_PRIMARY_REGION',
64
+ });
65
+ }
66
+ // Validate secondary regions
67
+ const secondaryRegionsError = validateSecondaryRegions(datacenter.secondaryRegions);
68
+ if (secondaryRegionsError) {
69
+ return res.setStatus(400).json({
70
+ error: 'Invalid secondary regions',
71
+ message: secondaryRegionsError,
72
+ code: 'INVALID_SECONDARY_REGIONS',
73
+ });
74
+ }
75
+ // Validate affinity rules
76
+ const affinityRulesError = validateAffinityRules(datacenter.affinityRules);
77
+ if (affinityRulesError) {
78
+ return res.setStatus(400).json({
79
+ error: 'Invalid affinity rules',
80
+ message: affinityRulesError,
81
+ code: 'INVALID_AFFINITY_RULES',
82
+ });
83
+ }
84
+ return handler(req, res);
85
+ }
86
+ catch (error) {
87
+ Logger.error('Datacenter validation failed', error);
88
+ return res.setStatus(500).json({
89
+ error: 'Internal validation error',
90
+ code: 'VALIDATION_ERROR',
91
+ });
92
+ }
93
+ };
94
+ };
@@ -0,0 +1,7 @@
1
+ import { type IRequest, type IResponse } from '@zintrust/core';
2
+ export type RouteHandler = (req: IRequest, res: IResponse) => Promise<void> | void;
3
+ /**
4
+ * Composite middleware for worker edit validation
5
+ * Maps processorPath to processor for validation and validates all editable fields
6
+ */
7
+ export declare const withEditWorkerValidation: (handler: RouteHandler) => RouteHandler;
@@ -0,0 +1,55 @@
1
+ import { Logger } from '@zintrust/core';
2
+ // Import individual validators
3
+ import { withDatacenterValidation } from './DatacenterValidator';
4
+ import { withFeaturesValidation } from './FeaturesValidator';
5
+ import { withInfrastructureValidation } from './InfrastructureValidator';
6
+ import { withStrictPayloadKeys } from './PayloadSanitizer';
7
+ import { withProcessorPathValidation } from './ProcessorPathSanitizer';
8
+ import { withQueueNameValidation } from './QueueNameSanitizer';
9
+ import { withVersionValidation } from './VersionSanitizer';
10
+ import { withWorkerNameValidation } from './WorkerNameSanitizer';
11
+ /**
12
+ * Composite middleware for worker edit validation
13
+ * Maps processorPath to processor for validation and validates all editable fields
14
+ */
15
+ export const withEditWorkerValidation = (handler) => {
16
+ return async (req, res) => {
17
+ try {
18
+ const data = req.data();
19
+ const currentBody = req.getBody();
20
+ // Map processorPath to processor for validation if processorPath exists
21
+ let mappedBody = { ...currentBody };
22
+ if (data['processorPath'] && !data['processor']) {
23
+ mappedBody = {
24
+ ...mappedBody,
25
+ processor: data['processorPath'], // Map for validation
26
+ };
27
+ }
28
+ // Update the request body with mapped fields
29
+ req.setBody(mappedBody);
30
+ // Apply validation with mapped fields, skipping options validation for editing
31
+ return withStrictPayloadKeys([
32
+ 'name',
33
+ 'queueName',
34
+ 'processor', // Validated field (mapped from processorPath)
35
+ 'processorPath', // Original field
36
+ 'version',
37
+ 'options', // Skip strict validation for editing
38
+ 'infrastructure',
39
+ 'features',
40
+ 'datacenter',
41
+ 'concurrency', // Original field
42
+ 'region',
43
+ 'autoStart',
44
+ 'status',
45
+ ], withProcessorPathValidation(withWorkerNameValidation(withQueueNameValidation(withVersionValidation(withInfrastructureValidation(withFeaturesValidation(withDatacenterValidation(handler))))))))(req, res);
46
+ }
47
+ catch (error) {
48
+ Logger.error('Edit worker validation failed', error);
49
+ return res.setStatus(500).json({
50
+ error: 'Internal validation error',
51
+ code: 'VALIDATION_ERROR',
52
+ });
53
+ }
54
+ };
55
+ };
@@ -0,0 +1,3 @@
1
+ import { type IRequest, type IResponse } from '@zintrust/core';
2
+ export type RouteHandler = (req: IRequest, res: IResponse) => Promise<void> | void;
3
+ export declare const withFeaturesValidation: (handler: RouteHandler) => RouteHandler;
@@ -0,0 +1,60 @@
1
+ import { Logger } from '@zintrust/core';
2
+ const VALID_FEATURES = new Set([
3
+ 'clustering',
4
+ 'metrics',
5
+ 'autoScaling',
6
+ 'circuitBreaker',
7
+ 'deadLetterQueue',
8
+ 'resourceMonitoring',
9
+ 'compliance',
10
+ 'observability',
11
+ 'plugins',
12
+ 'versioning',
13
+ 'datacenterOrchestration',
14
+ ]);
15
+ export const withFeaturesValidation = (handler) => {
16
+ return async (req, res) => {
17
+ try {
18
+ const data = req.data();
19
+ const features = data['features'];
20
+ if (!features) {
21
+ return handler(req, res); // Skip validation if features is not provided
22
+ }
23
+ // Check if features is an object
24
+ if (typeof features !== 'object' || features === null || Array.isArray(features)) {
25
+ return res.setStatus(400).json({
26
+ error: 'Invalid features configuration',
27
+ message: 'Features must be an object',
28
+ code: 'INVALID_FEATURES_TYPE',
29
+ });
30
+ }
31
+ // Validate each feature key and value
32
+ const featureKeys = Object.keys(features);
33
+ for (const key of featureKeys) {
34
+ if (!VALID_FEATURES.has(key)) {
35
+ return res.setStatus(400).json({
36
+ error: 'Invalid feature',
37
+ message: `Unknown feature: ${key}. Valid features are: ${Array.from(VALID_FEATURES).join(', ')}`,
38
+ code: 'INVALID_FEATURE',
39
+ });
40
+ }
41
+ const value = features[key];
42
+ if (typeof value !== 'boolean') {
43
+ return res.setStatus(400).json({
44
+ error: 'Invalid feature value',
45
+ message: `Feature ${key} must be a boolean (true or false)`,
46
+ code: 'INVALID_FEATURE_VALUE',
47
+ });
48
+ }
49
+ }
50
+ return handler(req, res);
51
+ }
52
+ catch (error) {
53
+ Logger.error('Features validation failed', error);
54
+ return res.setStatus(500).json({
55
+ error: 'Internal validation error',
56
+ code: 'VALIDATION_ERROR',
57
+ });
58
+ }
59
+ };
60
+ };
@@ -0,0 +1,31 @@
1
+ import { type IRequest, type IResponse } from '@zintrust/core';
2
+ export type RouteHandler = (req: IRequest, res: IResponse) => Promise<void> | void;
3
+ export interface InfrastructureConfig {
4
+ persistence: {
5
+ driver: string;
6
+ };
7
+ redis: {
8
+ env: boolean;
9
+ host: string;
10
+ port: string;
11
+ db: string;
12
+ password: string;
13
+ };
14
+ deadLetterQueue: {
15
+ policy: string;
16
+ };
17
+ compliance: {
18
+ config: {
19
+ retentionDays: number;
20
+ };
21
+ };
22
+ observability: {
23
+ enabled: boolean;
24
+ };
25
+ autoScaler: {
26
+ enabled: boolean;
27
+ minWorkers: number;
28
+ maxWorkers: number;
29
+ };
30
+ }
31
+ export declare const withInfrastructureValidation: (handler: RouteHandler) => RouteHandler;