2.4 KiB
2.4 KiB
NUPST Project Hints
Recent Refactoring (January 2026)
Phase 1 - Quick Wins
-
Prompt Utility (
ts/helpers/prompt.ts)- Extracted readline/prompt pattern from all CLI handlers
- Provides
createPrompt()andwithPrompt()helper functions - Used in:
ups-handler.ts,group-handler.ts,service-handler.ts,action-handler.ts,feature-handler.ts
-
Constants File (
ts/constants.ts)- Centralized all magic numbers (timeouts, intervals, thresholds)
- Contains:
TIMING,SNMP,THRESHOLDS,WEBHOOK,SCRIPT,SHUTDOWN,HTTP_SERVER,UI - Used in:
daemon.ts,snmp/manager.ts,actions/*.ts
-
Logger Consistency
- Replaced all
console.log/console.errorinsnmp/manager.tswith properlogger.*calls - Debug output uses
logger.dim()for less intrusive output
- Replaced all
Phase 2 - Type Safety
-
Circular Dependency Fix (
ts/interfaces/nupst-accessor.ts)- Created
INupstAccessorinterface to break the circular dependency betweenNupstandNupstSnmp NupstSnmp.nupstproperty now uses the interface instead ofany
- Created
-
Webhook Payload Interface (
ts/actions/webhook-action.ts)- Added
IWebhookPayloadinterface for webhook action payloads - Exported from
ts/actions/index.ts
- Added
-
CLI Handler Type Safety
- Replaced
anytypes inups-handler.tsandgroup-handler.tswith proper interfaces - Uses:
IUpsConfig,INupstConfig,ISnmpConfig,IActionConfig,IThresholds,ISnmpUpsStatus
- Replaced
Architecture Notes
- SNMP Manager: Uses
INupstAccessorinterface (not directNupstreference) to avoid circular imports - CLI Handlers: All use the
helpers.withPrompt()utility for interactive input - Constants: All timing values should be referenced from
ts/constants.ts - Actions: Use
IActionConfigfromts/actions/base-action.tsfor action configuration
File Organization
ts/
├── constants.ts # All timing/threshold constants
├── interfaces/
│ └── nupst-accessor.ts # Interface to break circular deps
├── helpers/
│ ├── prompt.ts # Readline utility
│ └── shortid.ts # ID generation
├── actions/
│ ├── base-action.ts # Base action class and interfaces
│ ├── webhook-action.ts # Includes IWebhookPayload
│ └── ...
└── cli/
└── ... # All handlers use helpers.withPrompt()