fix(core): fix lint/type issues and small refactors
This commit is contained in:
@@ -10,6 +10,7 @@ import { fileURLToPath } from 'url';
|
|||||||
import { dirname, join } from 'path';
|
import { dirname, join } from 'path';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { arch, platform } from 'os';
|
import { arch, platform } from 'os';
|
||||||
|
import process from "node:process";
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
|
|||||||
10
changelog.md
10
changelog.md
@@ -1,5 +1,15 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-01-29 - 5.2.3 - fix(core)
|
||||||
|
fix lint/type issues and small refactors
|
||||||
|
|
||||||
|
- Add missing node:process imports in bin and scripts to ensure process is available
|
||||||
|
- Remove unused imports and unused type imports (e.g. writeFileSync, IActionConfig) to reduce noise
|
||||||
|
- Make some methods synchronous (service update, webhook call) to match actual usage
|
||||||
|
- Tighten SNMP typings and linting: added deno-lint-ignore comments, renamed unused params with leading underscore, and use `as const` for securityLevel fallbacks
|
||||||
|
- Improve error handling variable naming in systemd (use error instead of _error)
|
||||||
|
- Annotate ANSI regex with deno-lint-ignore no-control-regex and remove unused color/symbol imports across CLI/daemon/logger
|
||||||
|
|
||||||
## 2026-01-29 - 5.2.2 - fix(core)
|
## 2026-01-29 - 5.2.2 - fix(core)
|
||||||
tidy formatting and minor fixes across CLI, SNMP, HTTP server, migrations and packaging
|
tidy formatting and minor fixes across CLI, SNMP, HTTP server, migrations and packaging
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
// deno-lint-ignore-file no-unused-vars
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NUPST npm postinstall script
|
* NUPST npm postinstall script
|
||||||
@@ -6,13 +7,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { arch, platform } from 'os';
|
import { arch, platform } from 'os';
|
||||||
import { chmodSync, existsSync, mkdirSync, unlinkSync, writeFileSync } from 'fs';
|
import { chmodSync, existsSync, mkdirSync, unlinkSync } from 'fs';
|
||||||
import { dirname, join } from 'path';
|
import { dirname, join } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import https from 'https';
|
import https from 'https';
|
||||||
import { pipeline } from 'stream';
|
import { pipeline } from 'stream';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import { createWriteStream } from 'fs';
|
import { createWriteStream } from 'fs';
|
||||||
|
import process from "node:process";
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@serve.zone/nupst',
|
name: '@serve.zone/nupst',
|
||||||
version: '5.2.2',
|
version: '5.2.3',
|
||||||
description: 'Network UPS Shutdown Tool - Monitor SNMP-enabled UPS devices and orchestrate graceful system shutdowns during power emergencies'
|
description: 'Network UPS Shutdown Tool - Monitor SNMP-enabled UPS devices and orchestrate graceful system shutdowns during power emergencies'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import * as fs from 'node:fs';
|
|||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
import { exec } from 'node:child_process';
|
import { exec } from 'node:child_process';
|
||||||
import { promisify } from 'node:util';
|
import { promisify } from 'node:util';
|
||||||
import { Action, type IActionConfig, type IActionContext } from './base-action.ts';
|
import { Action, type IActionContext } from './base-action.ts';
|
||||||
import { logger } from '../logger.ts';
|
import { logger } from '../logger.ts';
|
||||||
|
|
||||||
const execAsync = promisify(exec);
|
const execAsync = promisify(exec);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as http from 'node:http';
|
import * as http from 'node:http';
|
||||||
import * as https from 'node:https';
|
import * as https from 'node:https';
|
||||||
import { URL } from 'node:url';
|
import { URL } from 'node:url';
|
||||||
import { Action, type IActionConfig, type IActionContext } from './base-action.ts';
|
import { Action, type IActionContext } from './base-action.ts';
|
||||||
import { logger } from '../logger.ts';
|
import { logger } from '../logger.ts';
|
||||||
import { WEBHOOK } from '../constants.ts';
|
import { WEBHOOK } from '../constants.ts';
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ export class WebhookAction extends Action {
|
|||||||
* @param method HTTP method (GET or POST)
|
* @param method HTTP method (GET or POST)
|
||||||
* @param timeout Request timeout in milliseconds
|
* @param timeout Request timeout in milliseconds
|
||||||
*/
|
*/
|
||||||
private async callWebhook(
|
private callWebhook(
|
||||||
context: IActionContext,
|
context: IActionContext,
|
||||||
method: 'GET' | 'POST',
|
method: 'GET' | 'POST',
|
||||||
timeout: number,
|
timeout: number,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { execSync } from 'node:child_process';
|
import { execSync } from 'node:child_process';
|
||||||
import { Nupst } from './nupst.ts';
|
import { Nupst } from './nupst.ts';
|
||||||
import { type ITableColumn, logger } from './logger.ts';
|
import { type ITableColumn, logger } from './logger.ts';
|
||||||
import { symbols, theme } from './colors.ts';
|
import { theme } from './colors.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for handling CLI commands
|
* Class for handling CLI commands
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import process from 'node:process';
|
|
||||||
import { execSync } from 'node:child_process';
|
import { execSync } from 'node:child_process';
|
||||||
import { Nupst } from '../nupst.ts';
|
import { Nupst } from '../nupst.ts';
|
||||||
import { logger } from '../logger.ts';
|
import { logger } from '../logger.ts';
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import process from 'node:process';
|
|
||||||
import { Nupst } from '../nupst.ts';
|
import { Nupst } from '../nupst.ts';
|
||||||
import { type ITableColumn, logger } from '../logger.ts';
|
import { type ITableColumn, logger } from '../logger.ts';
|
||||||
import { theme } from '../colors.ts';
|
import { theme } from '../colors.ts';
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ export class ServiceHandler {
|
|||||||
/**
|
/**
|
||||||
* Update NUPST from repository and refresh systemd service
|
* Update NUPST from repository and refresh systemd service
|
||||||
*/
|
*/
|
||||||
public async update(): Promise<void> {
|
public update(): void {
|
||||||
try {
|
try {
|
||||||
// Check if running as root
|
// Check if running as root
|
||||||
this.checkRootAccess(
|
this.checkRootAccess(
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { type ITableColumn, logger } from '../logger.ts';
|
|||||||
import { theme } from '../colors.ts';
|
import { theme } from '../colors.ts';
|
||||||
import * as helpers from '../helpers/index.ts';
|
import * as helpers from '../helpers/index.ts';
|
||||||
import type { ISnmpConfig, IUpsStatus as ISnmpUpsStatus, TUpsModel } from '../snmp/types.ts';
|
import type { ISnmpConfig, IUpsStatus as ISnmpUpsStatus, TUpsModel } from '../snmp/types.ts';
|
||||||
import type { INupstConfig, IUpsConfig, IUpsStatus } from '../daemon.ts';
|
import type { INupstConfig, IUpsConfig } from '../daemon.ts';
|
||||||
import type { IActionConfig } from '../actions/base-action.ts';
|
import type { IActionConfig } from '../actions/base-action.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import { exec, execFile } from 'node:child_process';
|
|||||||
import { promisify } from 'node:util';
|
import { promisify } from 'node:util';
|
||||||
import { NupstSnmp } from './snmp/manager.ts';
|
import { NupstSnmp } from './snmp/manager.ts';
|
||||||
import type { ISnmpConfig, IUpsStatus as ISnmpUpsStatus } from './snmp/types.ts';
|
import type { ISnmpConfig, IUpsStatus as ISnmpUpsStatus } from './snmp/types.ts';
|
||||||
import { type ITableColumn, logger } from './logger.ts';
|
import { logger } from './logger.ts';
|
||||||
import { MigrationRunner } from './migrations/index.ts';
|
import { MigrationRunner } from './migrations/index.ts';
|
||||||
import { formatPowerStatus, getBatteryColor, getRuntimeColor, symbols, theme } from './colors.ts';
|
import { formatPowerStatus, getBatteryColor, getRuntimeColor, theme } from './colors.ts';
|
||||||
import type { IActionConfig } from './actions/base-action.ts';
|
import type { IActionConfig } from './actions/base-action.ts';
|
||||||
import { ActionManager, type IActionContext, type TPowerStatus } from './actions/index.ts';
|
import { ActionManager, type IActionContext, type TPowerStatus } from './actions/index.ts';
|
||||||
import { NupstHttpServer } from './http-server.ts';
|
import { NupstHttpServer } from './http-server.ts';
|
||||||
|
|||||||
@@ -230,7 +230,8 @@ export class Logger {
|
|||||||
* Strip ANSI color codes from string for accurate length calculation
|
* Strip ANSI color codes from string for accurate length calculation
|
||||||
*/
|
*/
|
||||||
private stripAnsi(text: string): string {
|
private stripAnsi(text: string): string {
|
||||||
// Remove ANSI escape codes
|
// Remove ANSI escape codes (intentional control character regex)
|
||||||
|
// deno-lint-ignore no-control-regex
|
||||||
return text.replace(/\x1b\[[0-9;]*m/g, '');
|
return text.replace(/\x1b\[[0-9;]*m/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,8 @@ export class NupstSnmp {
|
|||||||
public snmpGet(
|
public snmpGet(
|
||||||
oid: string,
|
oid: string,
|
||||||
config = this.DEFAULT_CONFIG,
|
config = this.DEFAULT_CONFIG,
|
||||||
retryCount = 0,
|
_retryCount = 0,
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
@@ -105,6 +106,7 @@ export class NupstSnmp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create SNMP options based on configuration
|
// Create SNMP options based on configuration
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
const options: any = {
|
const options: any = {
|
||||||
port: config.port,
|
port: config.port,
|
||||||
retries: SNMP.RETRIES, // Number of retries
|
retries: SNMP.RETRIES, // Number of retries
|
||||||
@@ -132,6 +134,7 @@ export class NupstSnmp {
|
|||||||
const securityLevel = config.securityLevel || 'noAuthNoPriv';
|
const securityLevel = config.securityLevel || 'noAuthNoPriv';
|
||||||
|
|
||||||
// Create the user object with required structure for net-snmp
|
// Create the user object with required structure for net-snmp
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
const user: any = {
|
const user: any = {
|
||||||
name: config.username || '',
|
name: config.username || '',
|
||||||
};
|
};
|
||||||
@@ -214,7 +217,8 @@ export class NupstSnmp {
|
|||||||
const oids = [oid];
|
const oids = [oid];
|
||||||
|
|
||||||
// Send the GET request
|
// Send the GET request
|
||||||
session.get(oids, (error: any, varbinds: any[]) => {
|
// deno-lint-ignore no-explicit-any
|
||||||
|
session.get(oids, (error: Error | null, varbinds: any[]) => {
|
||||||
// Close the session to release resources
|
// Close the session to release resources
|
||||||
session.close();
|
session.close();
|
||||||
|
|
||||||
@@ -428,6 +432,7 @@ export class NupstSnmp {
|
|||||||
oid: string,
|
oid: string,
|
||||||
description: string,
|
description: string,
|
||||||
config: ISnmpConfig,
|
config: ISnmpConfig,
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
if (oid === '') {
|
if (oid === '') {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
@@ -482,6 +487,7 @@ export class NupstSnmp {
|
|||||||
oid: string,
|
oid: string,
|
||||||
description: string,
|
description: string,
|
||||||
config: ISnmpConfig,
|
config: ISnmpConfig,
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
logger.dim(`Retrying ${description} with fallback security level...`);
|
logger.dim(`Retrying ${description} with fallback security level...`);
|
||||||
@@ -489,7 +495,7 @@ export class NupstSnmp {
|
|||||||
|
|
||||||
// Try with authNoPriv if current level is authPriv
|
// Try with authNoPriv if current level is authPriv
|
||||||
if (config.securityLevel === 'authPriv') {
|
if (config.securityLevel === 'authPriv') {
|
||||||
const retryConfig = { ...config, securityLevel: 'authNoPriv' as 'authNoPriv' };
|
const retryConfig = { ...config, securityLevel: 'authNoPriv' as const };
|
||||||
try {
|
try {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
logger.dim(`Retrying with authNoPriv security level`);
|
logger.dim(`Retrying with authNoPriv security level`);
|
||||||
@@ -512,7 +518,7 @@ export class NupstSnmp {
|
|||||||
|
|
||||||
// Try with noAuthNoPriv as a last resort
|
// Try with noAuthNoPriv as a last resort
|
||||||
if (config.securityLevel === 'authPriv' || config.securityLevel === 'authNoPriv') {
|
if (config.securityLevel === 'authPriv' || config.securityLevel === 'authNoPriv') {
|
||||||
const retryConfig = { ...config, securityLevel: 'noAuthNoPriv' as 'noAuthNoPriv' };
|
const retryConfig = { ...config, securityLevel: 'noAuthNoPriv' as const };
|
||||||
try {
|
try {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
logger.dim(`Retrying with noAuthNoPriv security level`);
|
logger.dim(`Retrying with noAuthNoPriv security level`);
|
||||||
@@ -538,15 +544,16 @@ export class NupstSnmp {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Try standard OIDs as fallback
|
* Try standard OIDs as fallback
|
||||||
* @param oid OID to query
|
* @param _oid Original OID (unused, kept for method signature consistency)
|
||||||
* @param description Description of the value for logging
|
* @param description Description of the value for logging
|
||||||
* @param config SNMP configuration
|
* @param config SNMP configuration
|
||||||
* @returns Promise resolving to the SNMP value
|
* @returns Promise resolving to the SNMP value
|
||||||
*/
|
*/
|
||||||
private async tryStandardOids(
|
private async tryStandardOids(
|
||||||
oid: string,
|
_oid: string,
|
||||||
description: string,
|
description: string,
|
||||||
config: ISnmpConfig,
|
config: ISnmpConfig,
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
try {
|
try {
|
||||||
// Try RFC 1628 standard UPS MIB OIDs
|
// Try RFC 1628 standard UPS MIB OIDs
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ WantedBy=multi-user.target
|
|||||||
}`,
|
}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (_error) {
|
} catch (error) {
|
||||||
// If version check fails, show at least the current version
|
// If version check fails, show at least the current version
|
||||||
try {
|
try {
|
||||||
const nupst = this.daemon.getNupstSnmp().getNupst();
|
const nupst = this.daemon.getNupstSnmp().getNupst();
|
||||||
|
|||||||
Reference in New Issue
Block a user