@zintrust/workers 0.4.0 → 0.4.3

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 (38) hide show
  1. package/README.md +9 -0
  2. package/dist/AnomalyDetection.js +2 -2
  3. package/dist/BroadcastWorker.js +1 -1
  4. package/dist/CanaryController.js +1 -1
  5. package/dist/ChaosEngineering.js +4 -4
  6. package/dist/DatacenterOrchestrator.js +1 -1
  7. package/dist/DeadLetterQueue.js +1 -1
  8. package/dist/HealthMonitor.js +1 -1
  9. package/dist/MultiQueueWorker.js +1 -1
  10. package/dist/NotificationWorker.js +1 -1
  11. package/dist/SLAMonitor.js +2 -2
  12. package/dist/WorkerFactory.js +18 -18
  13. package/dist/WorkerInit.js +4 -4
  14. package/dist/WorkerRegistry.js +1 -1
  15. package/dist/WorkerShutdown.js +1 -1
  16. package/dist/WorkerShutdownDurableObject.d.ts +12 -0
  17. package/dist/WorkerShutdownDurableObject.js +41 -0
  18. package/dist/build-manifest.json +558 -0
  19. package/dist/dashboard/workers-api.js +2 -2
  20. package/dist/http/WorkerApiController.js +3 -3
  21. package/dist/http/WorkerController.js +10 -10
  22. package/dist/http/WorkerMonitoringService.js +2 -2
  23. package/dist/http/middleware/EditWorkerValidation.js +8 -8
  24. package/dist/http/middleware/WorkerValidationChain.js +9 -9
  25. package/dist/index.js +39 -28
  26. package/dist/register.d.ts +6 -0
  27. package/dist/register.js +37 -0
  28. package/dist/routes/workers.js +11 -11
  29. package/dist/telemetry/api/TelemetryAPI.js +3 -3
  30. package/dist/telemetry/index.js +3 -3
  31. package/dist/telemetry/routes/dashboard.js +4 -4
  32. package/dist/ui/router/ui.js +1 -1
  33. package/dist/ui/workers/index.html +202 -0
  34. package/dist/ui/workers/main.js +1952 -0
  35. package/dist/ui/workers/styles.css +1350 -0
  36. package/dist/ui/workers/zintrust.svg +30 -0
  37. package/package.json +19 -13
  38. package/src/register.ts +68 -0
package/README.md CHANGED
@@ -36,6 +36,15 @@ npm install brain.js ml.js simple-statistics
36
36
  npm install @tensorflow/tfjs-node
37
37
  ```
38
38
 
39
+ For queue integrations that are lazy-loaded by the workers package:
40
+
41
+ ```bash
42
+ npm install @zintrust/queue-redis
43
+ npm install @zintrust/queue-monitor
44
+ ```
45
+
46
+ These integrations are not auto-installed. `@zintrust/workers` will run without them and enable the related features only when they are present.
47
+
39
48
  ## Quick Start
40
49
 
41
50
  ### Basic Worker Creation
@@ -4,8 +4,8 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger, generateUuid } from '@zintrust/core';
7
- import { ResourceMonitor } from './ResourceMonitor';
8
- import { WorkerMetrics } from './WorkerMetrics';
7
+ import { ResourceMonitor } from './ResourceMonitor.js';
8
+ import { WorkerMetrics } from './WorkerMetrics.js';
9
9
  const configs = new Map();
10
10
  const models = new Map();
11
11
  const updateStats = (stats, value) => {
@@ -5,7 +5,7 @@
5
5
  * Use with Queue.dequeue() in a background process or cron job.
6
6
  */
7
7
  import { Broadcast } from '@zintrust/core';
8
- import { createQueueWorker } from './createQueueWorker';
8
+ import { createQueueWorker } from './createQueueWorker.js';
9
9
  export const BroadcastWorker = Object.freeze({
10
10
  ...createQueueWorker({
11
11
  kindLabel: 'broadcast',
@@ -4,7 +4,7 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger } from '@zintrust/core';
7
- import { CircuitBreaker } from './CircuitBreaker';
7
+ import { CircuitBreaker } from './CircuitBreaker.js';
8
8
  // Internal state
9
9
  const canaryDeployments = new Map();
10
10
  const canaryTimers = new Map();
@@ -4,10 +4,10 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger, generateUuid } from '@zintrust/core';
7
- import { CircuitBreaker } from './CircuitBreaker';
8
- import { Observability } from './Observability';
9
- import { ResourceMonitor } from './ResourceMonitor';
10
- import { WorkerRegistry } from './WorkerRegistry';
7
+ import { CircuitBreaker } from './CircuitBreaker.js';
8
+ import { Observability } from './Observability.js';
9
+ import { ResourceMonitor } from './ResourceMonitor.js';
10
+ import { WorkerRegistry } from './WorkerRegistry.js';
11
11
  const experiments = new Map();
12
12
  const EXPERIMENT_RETENTION_MS = 24 * 60 * 60 * 1000;
13
13
  const cleanupExpiredExperiments = () => {
@@ -4,7 +4,7 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger } from '@zintrust/core';
7
- import { ClusterLock } from './ClusterLock';
7
+ import { ClusterLock } from './ClusterLock.js';
8
8
  // Internal state
9
9
  const regions = new Map();
10
10
  const workerPlacements = new Map();
@@ -4,7 +4,7 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger, createRedisConnection } from '@zintrust/core';
7
- import { keyPrefix } from './config/workerConfig';
7
+ import { keyPrefix } from './config/workerConfig.js';
8
8
  // Redis key prefixes - using workers package prefix system
9
9
  const getDLQPrefix = () => {
10
10
  return keyPrefix() + ':dlq:';
@@ -1,5 +1,5 @@
1
1
  import { ErrorFactory, Logger } from '@zintrust/core';
2
- import { WorkerCreationStatus, WorkerFactory } from './WorkerFactory';
2
+ import { WorkerCreationStatus, WorkerFactory } from './WorkerFactory.js';
3
3
  const DEFAULT_CONFIG = {
4
4
  enabled: true,
5
5
  tickIntervalMs: 1000,
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { ErrorFactory, Logger } from '@zintrust/core';
7
7
  import { Worker } from 'bullmq';
8
- import { PriorityQueue } from './PriorityQueue';
8
+ import { PriorityQueue } from './PriorityQueue.js';
9
9
  // Internal state
10
10
  const multiQueueWorkers = new Map();
11
11
  /**
@@ -5,7 +5,7 @@
5
5
  * Use with Queue.dequeue() in a background process or cron job.
6
6
  */
7
7
  import { Notification } from '@zintrust/core';
8
- import { createQueueWorker } from './createQueueWorker';
8
+ import { createQueueWorker } from './createQueueWorker.js';
9
9
  export const NotificationWorker = Object.freeze({
10
10
  ...createQueueWorker({
11
11
  kindLabel: 'notification',
@@ -4,8 +4,8 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger, generateUuid } from '@zintrust/core';
7
- import { HealthMonitor } from './HealthMonitor';
8
- import { WorkerMetrics } from './WorkerMetrics';
7
+ import { HealthMonitor } from './HealthMonitor.js';
8
+ import { WorkerMetrics } from './WorkerMetrics.js';
9
9
  const slaConfigs = new Map();
10
10
  const violationHistory = new Map();
11
11
  const lastAlertAt = new Map();
@@ -5,24 +5,24 @@
5
5
  */
6
6
  import { Cloudflare, createRedisConnection, databaseConfig, Env, ErrorFactory, generateUuid, getBullMQSafeQueueName, JobStateTracker, Logger, NodeSingletons, queueConfig, registerDatabasesFromRuntimeConfig, useEnsureDbConnected, workersConfig, ZintrustLang, } from '@zintrust/core';
7
7
  import { Worker } from 'bullmq';
8
- import { AutoScaler } from './AutoScaler';
9
- import { CanaryController } from './CanaryController';
10
- import { CircuitBreaker } from './CircuitBreaker';
11
- import { ClusterLock } from './ClusterLock';
12
- import { ComplianceManager } from './ComplianceManager';
13
- import { DatacenterOrchestrator } from './DatacenterOrchestrator';
14
- import { DeadLetterQueue } from './DeadLetterQueue';
15
- import { HealthMonitor } from './HealthMonitor';
16
- import { MultiQueueWorker } from './MultiQueueWorker';
17
- import { Observability } from './Observability';
18
- import { PluginManager } from './PluginManager';
19
- import { PriorityQueue } from './PriorityQueue';
20
- import { ResourceMonitor } from './ResourceMonitor';
21
- import { WorkerMetrics } from './WorkerMetrics';
22
- import { WorkerRegistry } from './WorkerRegistry';
23
- import { WorkerVersioning } from './WorkerVersioning';
24
- import { keyPrefix } from './config/workerConfig';
25
- import { DbWorkerStore, InMemoryWorkerStore, RedisWorkerStore, } from './storage/WorkerStore';
8
+ import { AutoScaler } from './AutoScaler.js';
9
+ import { CanaryController } from './CanaryController.js';
10
+ import { CircuitBreaker } from './CircuitBreaker.js';
11
+ import { ClusterLock } from './ClusterLock.js';
12
+ import { ComplianceManager } from './ComplianceManager.js';
13
+ import { DatacenterOrchestrator } from './DatacenterOrchestrator.js';
14
+ import { DeadLetterQueue } from './DeadLetterQueue.js';
15
+ import { HealthMonitor } from './HealthMonitor.js';
16
+ import { MultiQueueWorker } from './MultiQueueWorker.js';
17
+ import { Observability } from './Observability.js';
18
+ import { PluginManager } from './PluginManager.js';
19
+ import { PriorityQueue } from './PriorityQueue.js';
20
+ import { ResourceMonitor } from './ResourceMonitor.js';
21
+ import { WorkerMetrics } from './WorkerMetrics.js';
22
+ import { WorkerRegistry } from './WorkerRegistry.js';
23
+ import { WorkerVersioning } from './WorkerVersioning.js';
24
+ import { keyPrefix } from './config/workerConfig.js';
25
+ import { DbWorkerStore, InMemoryWorkerStore, RedisWorkerStore, } from './storage/WorkerStore.js';
26
26
  const path = NodeSingletons.path;
27
27
  const isNodeRuntime = () => typeof process !== 'undefined' && Boolean(process.versions?.node);
28
28
  const resolveProjectRoot = () => {
@@ -8,10 +8,10 @@
8
8
  * - Ensures graceful startup and shutdown
9
9
  */
10
10
  import { Env, Logger } from '@zintrust/core';
11
- import { ResourceMonitor } from './ResourceMonitor';
12
- import { WorkerFactory } from './WorkerFactory';
13
- import { WorkerShutdown } from './WorkerShutdown';
14
- import { keyPrefix } from './config/workerConfig';
11
+ import { ResourceMonitor } from './ResourceMonitor.js';
12
+ import { WorkerFactory } from './WorkerFactory.js';
13
+ import { WorkerShutdown } from './WorkerShutdown.js';
14
+ import { keyPrefix } from './config/workerConfig.js';
15
15
  // ============================================================================
16
16
  // State
17
17
  // ============================================================================
@@ -4,7 +4,7 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger } from '@zintrust/core';
7
- import { AnomalyDetection } from './AnomalyDetection';
7
+ import { AnomalyDetection } from './AnomalyDetection.js';
8
8
  // Internal storage
9
9
  const workers = new Map();
10
10
  const registrations = new Map();
@@ -5,7 +5,7 @@
5
5
  * Coordinates orderly shutdown of all worker modules and the WorkerFactory.
6
6
  */
7
7
  import { Logger } from '@zintrust/core';
8
- import { WorkerFactory } from './WorkerFactory';
8
+ import { WorkerFactory } from './WorkerFactory.js';
9
9
  // ============================================================================
10
10
  // Implementation
11
11
  // ============================================================================
@@ -0,0 +1,12 @@
1
+ type DurableObjectState = {
2
+ storage: {
3
+ get: (key: string) => Promise<unknown>;
4
+ put: (key: string, value: unknown) => Promise<void>;
5
+ };
6
+ };
7
+ export declare class ZinTrustWorkerShutdownDurableObject {
8
+ private readonly state;
9
+ constructor(state: DurableObjectState);
10
+ fetch(request: Request): Promise<Response>;
11
+ }
12
+ export {};
@@ -0,0 +1,41 @@
1
+ import { Logger } from '@zintrust/core';
2
+ const loadState = async (state) => {
3
+ const stored = (await state.storage.get('shutdown'));
4
+ return stored ?? { shuttingDown: false };
5
+ };
6
+ const saveState = async (state, value) => {
7
+ await state.storage.put('shutdown', value);
8
+ };
9
+ // eslint-disable-next-line no-restricted-syntax
10
+ export class ZinTrustWorkerShutdownDurableObject {
11
+ state;
12
+ constructor(state) {
13
+ this.state = state;
14
+ }
15
+ async fetch(request) {
16
+ const url = new URL(request.url);
17
+ const path = url.pathname;
18
+ if (request.method === 'GET' && path === '/status') {
19
+ const current = await loadState(this.state);
20
+ return new Response(JSON.stringify(current), {
21
+ status: 200,
22
+ headers: { 'content-type': 'application/json' },
23
+ });
24
+ }
25
+ if (request.method === 'POST' && path === '/shutdown') {
26
+ const payload = (await request.json().catch(() => ({})));
27
+ const next = {
28
+ shuttingDown: true,
29
+ startedAt: new Date().toISOString(),
30
+ reason: payload.reason ?? 'manual',
31
+ };
32
+ await saveState(this.state, next);
33
+ Logger.info('Worker shutdown requested via Durable Object', next);
34
+ return new Response(JSON.stringify({ ok: true }), {
35
+ status: 202,
36
+ headers: { 'content-type': 'application/json' },
37
+ });
38
+ }
39
+ return new Response('Not Found', { status: 404 });
40
+ }
41
+ }