telegram-ssh-bot 2.0.0 → 2.2.0
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.
- package/LICENSE +21 -0
- package/README.md +103 -22
- package/deploy/.env.example +86 -0
- package/dist/config/index.d.ts +68 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +315 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/schema.d.ts +6 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +50 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/core/Bot.d.ts +91 -0
- package/dist/core/Bot.d.ts.map +1 -0
- package/dist/core/Bot.js +263 -0
- package/dist/core/Bot.js.map +1 -0
- package/dist/core/ConnectionPool.d.ts +125 -0
- package/dist/core/ConnectionPool.d.ts.map +1 -0
- package/dist/core/ConnectionPool.js +397 -0
- package/dist/core/ConnectionPool.js.map +1 -0
- package/dist/core/SSHClient.d.ts +112 -0
- package/dist/core/SSHClient.d.ts.map +1 -0
- package/dist/core/SSHClient.js +367 -0
- package/dist/core/SSHClient.js.map +1 -0
- package/dist/core/ServerManager.d.ts +80 -0
- package/dist/core/ServerManager.d.ts.map +1 -0
- package/dist/core/ServerManager.js +207 -0
- package/dist/core/ServerManager.js.map +1 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +8 -0
- package/dist/core/index.js.map +1 -0
- package/dist/errors/AuthError.d.ts +30 -0
- package/dist/errors/AuthError.d.ts.map +1 -0
- package/dist/errors/AuthError.js +35 -0
- package/dist/errors/AuthError.js.map +1 -0
- package/dist/errors/BaseError.d.ts +17 -0
- package/dist/errors/BaseError.d.ts.map +1 -0
- package/dist/errors/BaseError.js +34 -0
- package/dist/errors/BaseError.js.map +1 -0
- package/dist/errors/ConfigurationError.d.ts +24 -0
- package/dist/errors/ConfigurationError.d.ts.map +1 -0
- package/dist/errors/ConfigurationError.js +24 -0
- package/dist/errors/ConfigurationError.js.map +1 -0
- package/dist/errors/PoolError.d.ts +21 -0
- package/dist/errors/PoolError.d.ts.map +1 -0
- package/dist/errors/PoolError.js +30 -0
- package/dist/errors/PoolError.js.map +1 -0
- package/dist/errors/SSHError.d.ts +24 -0
- package/dist/errors/SSHError.d.ts.map +1 -0
- package/dist/errors/SSHError.js +38 -0
- package/dist/errors/SSHError.js.map +1 -0
- package/dist/errors/StorageError.d.ts +24 -0
- package/dist/errors/StorageError.d.ts.map +1 -0
- package/dist/errors/StorageError.js +35 -0
- package/dist/errors/StorageError.js.map +1 -0
- package/dist/errors/ValidationError.d.ts +29 -0
- package/dist/errors/ValidationError.d.ts.map +1 -0
- package/dist/errors/ValidationError.js +35 -0
- package/dist/errors/ValidationError.js.map +1 -0
- package/dist/errors/index.d.ts +11 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +18 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/handlers/BaseHandler.d.ts +50 -0
- package/dist/handlers/BaseHandler.d.ts.map +1 -0
- package/dist/handlers/BaseHandler.js +87 -0
- package/dist/handlers/BaseHandler.js.map +1 -0
- package/dist/handlers/CommandHandler.d.ts +23 -0
- package/dist/handlers/CommandHandler.d.ts.map +1 -0
- package/dist/handlers/CommandHandler.js +99 -0
- package/dist/handlers/CommandHandler.js.map +1 -0
- package/dist/handlers/HealthHandler.d.ts +25 -0
- package/dist/handlers/HealthHandler.d.ts.map +1 -0
- package/dist/handlers/HealthHandler.js +51 -0
- package/dist/handlers/HealthHandler.js.map +1 -0
- package/dist/handlers/HelpHandler.d.ts +32 -0
- package/dist/handlers/HelpHandler.d.ts.map +1 -0
- package/dist/handlers/HelpHandler.js +76 -0
- package/dist/handlers/HelpHandler.js.map +1 -0
- package/dist/handlers/ServerHandler.d.ts +72 -0
- package/dist/handlers/ServerHandler.d.ts.map +1 -0
- package/dist/handlers/ServerHandler.js +272 -0
- package/dist/handlers/ServerHandler.js.map +1 -0
- package/dist/handlers/index.d.ts +9 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +9 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +348 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/AuthMiddleware.d.ts +28 -0
- package/dist/middleware/AuthMiddleware.d.ts.map +1 -0
- package/dist/middleware/AuthMiddleware.js +49 -0
- package/dist/middleware/AuthMiddleware.js.map +1 -0
- package/dist/middleware/RateLimitMiddleware.d.ts +23 -0
- package/dist/middleware/RateLimitMiddleware.d.ts.map +1 -0
- package/dist/middleware/RateLimitMiddleware.js +34 -0
- package/dist/middleware/RateLimitMiddleware.js.map +1 -0
- package/dist/middleware/index.d.ts +6 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +6 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/services/BackupService.d.ts +119 -0
- package/dist/services/BackupService.d.ts.map +1 -0
- package/dist/services/BackupService.js +313 -0
- package/dist/services/BackupService.js.map +1 -0
- package/dist/services/CryptoService.d.ts +37 -0
- package/dist/services/CryptoService.d.ts.map +1 -0
- package/dist/services/CryptoService.js +108 -0
- package/dist/services/CryptoService.js.map +1 -0
- package/dist/services/HealthService.d.ts +126 -0
- package/dist/services/HealthService.d.ts.map +1 -0
- package/dist/services/HealthService.js +213 -0
- package/dist/services/HealthService.js.map +1 -0
- package/dist/services/LoggingService.d.ts +115 -0
- package/dist/services/LoggingService.d.ts.map +1 -0
- package/dist/services/LoggingService.js +334 -0
- package/dist/services/LoggingService.js.map +1 -0
- package/dist/services/MonitoringService.d.ts +119 -0
- package/dist/services/MonitoringService.d.ts.map +1 -0
- package/dist/services/MonitoringService.js +267 -0
- package/dist/services/MonitoringService.js.map +1 -0
- package/dist/services/NotificationService.d.ts +132 -0
- package/dist/services/NotificationService.d.ts.map +1 -0
- package/dist/services/NotificationService.js +297 -0
- package/dist/services/NotificationService.js.map +1 -0
- package/dist/services/RateLimiter.d.ts +51 -0
- package/dist/services/RateLimiter.d.ts.map +1 -0
- package/dist/services/RateLimiter.js +141 -0
- package/dist/services/RateLimiter.js.map +1 -0
- package/dist/services/ValidationService.d.ts +49 -0
- package/dist/services/ValidationService.d.ts.map +1 -0
- package/dist/services/ValidationService.js +158 -0
- package/dist/services/ValidationService.js.map +1 -0
- package/dist/services/index.d.ts +12 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +12 -0
- package/dist/services/index.js.map +1 -0
- package/dist/types/Bot.d.ts +63 -0
- package/dist/types/Bot.d.ts.map +1 -0
- package/dist/types/Bot.js +5 -0
- package/dist/types/Bot.js.map +1 -0
- package/dist/types/Config.d.ts +57 -0
- package/dist/types/Config.d.ts.map +1 -0
- package/dist/types/Config.js +5 -0
- package/dist/types/Config.js.map +1 -0
- package/dist/types/Errors.d.ts +37 -0
- package/dist/types/Errors.d.ts.map +1 -0
- package/dist/types/Errors.js +34 -0
- package/dist/types/Errors.js.map +1 -0
- package/dist/types/SSH.d.ts +56 -0
- package/dist/types/SSH.d.ts.map +1 -0
- package/dist/types/SSH.js +6 -0
- package/dist/types/SSH.js.map +1 -0
- package/dist/types/Server.d.ts +39 -0
- package/dist/types/Server.d.ts.map +1 -0
- package/dist/types/Server.js +5 -0
- package/dist/types/Server.js.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/commandUtils.d.ts +25 -0
- package/dist/utils/commandUtils.d.ts.map +1 -0
- package/dist/utils/commandUtils.js +94 -0
- package/dist/utils/commandUtils.js.map +1 -0
- package/dist/utils/fileUtils.d.ts +40 -0
- package/dist/utils/fileUtils.d.ts.map +1 -0
- package/dist/utils/fileUtils.js +114 -0
- package/dist/utils/fileUtils.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/pathUtils.d.ts +40 -0
- package/dist/utils/pathUtils.d.ts.map +1 -0
- package/dist/utils/pathUtils.js +140 -0
- package/dist/utils/pathUtils.js.map +1 -0
- package/package.json +31 -5
- package/scripts/build.sh +20 -0
- package/scripts/postinstall.js +87 -0
- package/scripts/release.sh +22 -0
- package/scripts/setup-env.js +237 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crypto Service
|
|
3
|
+
* Provides AES-256-GCM encryption for credential storage
|
|
4
|
+
*/
|
|
5
|
+
import type { EncryptedData } from '../types/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Crypto service for encrypting and decrypting sensitive data
|
|
8
|
+
*/
|
|
9
|
+
export declare class CryptoService {
|
|
10
|
+
private readonly key;
|
|
11
|
+
constructor(encryptionKey: string);
|
|
12
|
+
/**
|
|
13
|
+
* Encrypt plaintext string using AES-256-GCM
|
|
14
|
+
*/
|
|
15
|
+
encrypt(plaintext: string): EncryptedData;
|
|
16
|
+
/**
|
|
17
|
+
* Decrypt encrypted data using AES-256-GCM
|
|
18
|
+
*/
|
|
19
|
+
decrypt(encrypted: EncryptedData): string;
|
|
20
|
+
/**
|
|
21
|
+
* Hash a string using SHA-256
|
|
22
|
+
*/
|
|
23
|
+
hash(data: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Verify a hash against data
|
|
26
|
+
*/
|
|
27
|
+
verifyHash(data: string, hash: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Generate a random hex string
|
|
30
|
+
*/
|
|
31
|
+
static generateKey(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Generate a random ID
|
|
34
|
+
*/
|
|
35
|
+
static generateId(prefix?: string): string;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=CryptoService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CryptoService.d.ts","sourceRoot":"","sources":["../../src/services/CryptoService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAUvD;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;gBAEjB,aAAa,EAAE,MAAM;IAcjC;;OAEG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa;IAyBzC;;OAEG;IACH,OAAO,CAAC,SAAS,EAAE,aAAa,GAAG,MAAM;IAgCzC;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI1B;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO;IAI/C;;OAEG;IACH,MAAM,CAAC,WAAW,IAAI,MAAM;IAI5B;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM;CAI/C"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crypto Service
|
|
3
|
+
* Provides AES-256-GCM encryption for credential storage
|
|
4
|
+
*/
|
|
5
|
+
import * as crypto from 'crypto';
|
|
6
|
+
import { InvalidConfigError } from '../errors/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Encryption algorithm configuration
|
|
9
|
+
*/
|
|
10
|
+
const ALGORITHM = 'aes-256-gcm';
|
|
11
|
+
const IV_LENGTH = 12; // 12 bytes for GCM
|
|
12
|
+
const AUTH_TAG_LENGTH = 16; // 16 bytes for GCM auth tag
|
|
13
|
+
/**
|
|
14
|
+
* Crypto service for encrypting and decrypting sensitive data
|
|
15
|
+
*/
|
|
16
|
+
export class CryptoService {
|
|
17
|
+
key;
|
|
18
|
+
constructor(encryptionKey) {
|
|
19
|
+
// Validate key length (should be 64 hex characters = 32 bytes)
|
|
20
|
+
if (encryptionKey.length !== 64) {
|
|
21
|
+
throw new InvalidConfigError('Encryption key must be 64 hex characters (32 bytes)');
|
|
22
|
+
}
|
|
23
|
+
// Convert hex string to buffer
|
|
24
|
+
this.key = Buffer.from(encryptionKey, 'hex');
|
|
25
|
+
if (this.key.length !== 32) {
|
|
26
|
+
throw new InvalidConfigError('Encryption key must decode to 32 bytes');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Encrypt plaintext string using AES-256-GCM
|
|
31
|
+
*/
|
|
32
|
+
encrypt(plaintext) {
|
|
33
|
+
// Generate random IV
|
|
34
|
+
const iv = crypto.randomBytes(IV_LENGTH);
|
|
35
|
+
// Create cipher
|
|
36
|
+
const cipher = crypto.createCipheriv(ALGORITHM, this.key, iv, {
|
|
37
|
+
authTagLength: AUTH_TAG_LENGTH,
|
|
38
|
+
});
|
|
39
|
+
// Encrypt
|
|
40
|
+
const encrypted = Buffer.concat([
|
|
41
|
+
cipher.update(plaintext, 'utf8'),
|
|
42
|
+
cipher.final(),
|
|
43
|
+
]);
|
|
44
|
+
// Get auth tag
|
|
45
|
+
const authTag = cipher.getAuthTag();
|
|
46
|
+
return {
|
|
47
|
+
iv: iv.toString('base64'),
|
|
48
|
+
authTag: authTag.toString('base64'),
|
|
49
|
+
data: encrypted.toString('base64'),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Decrypt encrypted data using AES-256-GCM
|
|
54
|
+
*/
|
|
55
|
+
decrypt(encrypted) {
|
|
56
|
+
// Decode from base64
|
|
57
|
+
const iv = Buffer.from(encrypted.iv, 'base64');
|
|
58
|
+
const authTag = Buffer.from(encrypted.authTag, 'base64');
|
|
59
|
+
const data = Buffer.from(encrypted.data, 'base64');
|
|
60
|
+
// Validate IV length
|
|
61
|
+
if (iv.length !== IV_LENGTH) {
|
|
62
|
+
throw new Error('Invalid IV length');
|
|
63
|
+
}
|
|
64
|
+
// Create decipher
|
|
65
|
+
const decipher = crypto.createDecipheriv(ALGORITHM, this.key, iv, {
|
|
66
|
+
authTagLength: AUTH_TAG_LENGTH,
|
|
67
|
+
});
|
|
68
|
+
// Set auth tag
|
|
69
|
+
decipher.setAuthTag(authTag);
|
|
70
|
+
// Decrypt
|
|
71
|
+
try {
|
|
72
|
+
const decrypted = Buffer.concat([
|
|
73
|
+
decipher.update(data),
|
|
74
|
+
decipher.final(),
|
|
75
|
+
]);
|
|
76
|
+
return decrypted.toString('utf8');
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw new Error('Decryption failed: authentication tag verification failed');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Hash a string using SHA-256
|
|
84
|
+
*/
|
|
85
|
+
hash(data) {
|
|
86
|
+
return crypto.createHash('sha256').update(data).digest('hex');
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Verify a hash against data
|
|
90
|
+
*/
|
|
91
|
+
verifyHash(data, hash) {
|
|
92
|
+
return this.hash(data) === hash;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Generate a random hex string
|
|
96
|
+
*/
|
|
97
|
+
static generateKey() {
|
|
98
|
+
return crypto.randomBytes(32).toString('hex');
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Generate a random ID
|
|
102
|
+
*/
|
|
103
|
+
static generateId(prefix = '') {
|
|
104
|
+
const id = crypto.randomBytes(8).toString('hex');
|
|
105
|
+
return prefix ? `${prefix}_${id}` : id;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=CryptoService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CryptoService.js","sourceRoot":"","sources":["../../src/services/CryptoService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD;;GAEG;AACH,MAAM,SAAS,GAAG,aAAa,CAAC;AAChC,MAA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Y,EAAE,IAAY;QACnC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,WAAW;QAChB,OAAO,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,SAAiB,EAAE;QACnC,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACjD,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Health Service
|
|
3
|
+
* Provides system health monitoring and status reporting
|
|
4
|
+
*/
|
|
5
|
+
import type { LogContext } from "../types/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Component health status
|
|
8
|
+
*/
|
|
9
|
+
export interface ComponentHealth {
|
|
10
|
+
status: "up" | "down";
|
|
11
|
+
latency?: number;
|
|
12
|
+
message?: string;
|
|
13
|
+
lastCheck?: Date;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Memory health metrics
|
|
17
|
+
*/
|
|
18
|
+
export interface MemoryHealth {
|
|
19
|
+
heapUsed: number;
|
|
20
|
+
heapTotal: number;
|
|
21
|
+
rss: number;
|
|
22
|
+
external: number;
|
|
23
|
+
arrayBuffers: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Overall health status
|
|
27
|
+
*/
|
|
28
|
+
export interface HealthStatus {
|
|
29
|
+
status: "healthy" | "degraded" | "unhealthy";
|
|
30
|
+
uptime: number;
|
|
31
|
+
timestamp: Date;
|
|
32
|
+
version: string;
|
|
33
|
+
components: {
|
|
34
|
+
bot: ComponentHealth;
|
|
35
|
+
storage: ComponentHealth;
|
|
36
|
+
memory: MemoryHealth;
|
|
37
|
+
};
|
|
38
|
+
metrics: {
|
|
39
|
+
activeConnections: number;
|
|
40
|
+
totalServers: number;
|
|
41
|
+
requestsProcessed: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Health check options
|
|
46
|
+
*/
|
|
47
|
+
export interface HealthCheckOptions {
|
|
48
|
+
version: string;
|
|
49
|
+
startTime: Date;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Service for monitoring application health
|
|
53
|
+
*/
|
|
54
|
+
export declare class HealthService {
|
|
55
|
+
private readonly version;
|
|
56
|
+
private readonly startTime;
|
|
57
|
+
private requestsProcessed;
|
|
58
|
+
private activeConnections;
|
|
59
|
+
private totalServers;
|
|
60
|
+
private storageHealthy;
|
|
61
|
+
private botHealthy;
|
|
62
|
+
private lastStorageCheck;
|
|
63
|
+
private lastBotCheck;
|
|
64
|
+
constructor(options: HealthCheckOptions);
|
|
65
|
+
/**
|
|
66
|
+
* Get current health status
|
|
67
|
+
*/
|
|
68
|
+
getHealthStatus(): HealthStatus;
|
|
69
|
+
/**
|
|
70
|
+
* Get memory health metrics
|
|
71
|
+
*/
|
|
72
|
+
private getMemoryHealth;
|
|
73
|
+
/**
|
|
74
|
+
* Get bot component health
|
|
75
|
+
*/
|
|
76
|
+
private getBotHealth;
|
|
77
|
+
/**
|
|
78
|
+
* Get storage component health
|
|
79
|
+
*/
|
|
80
|
+
private getStorageHealth;
|
|
81
|
+
/**
|
|
82
|
+
* Determine overall health status
|
|
83
|
+
*/
|
|
84
|
+
private determineOverallStatus;
|
|
85
|
+
/**
|
|
86
|
+
* Get uptime in seconds
|
|
87
|
+
*/
|
|
88
|
+
private getUptime;
|
|
89
|
+
/**
|
|
90
|
+
* Format uptime as human-readable string
|
|
91
|
+
*/
|
|
92
|
+
formatUptime(): string;
|
|
93
|
+
/**
|
|
94
|
+
* Format bytes to human-readable string
|
|
95
|
+
*/
|
|
96
|
+
formatBytes(bytes: number): string;
|
|
97
|
+
/**
|
|
98
|
+
* Get formatted health report
|
|
99
|
+
*/
|
|
100
|
+
getFormattedHealthReport(): string;
|
|
101
|
+
/**
|
|
102
|
+
* Update bot health status
|
|
103
|
+
*/
|
|
104
|
+
setBotHealth(healthy: boolean): void;
|
|
105
|
+
/**
|
|
106
|
+
* Update storage health status
|
|
107
|
+
*/
|
|
108
|
+
setStorageHealth(healthy: boolean): void;
|
|
109
|
+
/**
|
|
110
|
+
* Increment request counter
|
|
111
|
+
*/
|
|
112
|
+
incrementRequests(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Set active connections count
|
|
115
|
+
*/
|
|
116
|
+
setActiveConnections(count: number): void;
|
|
117
|
+
/**
|
|
118
|
+
* Set total servers count
|
|
119
|
+
*/
|
|
120
|
+
setTotalServers(count: number): void;
|
|
121
|
+
/**
|
|
122
|
+
* Get log context for health-related logs
|
|
123
|
+
*/
|
|
124
|
+
getLogContext(): LogContext;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=HealthService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HealthService.d.ts","sourceRoot":"","sources":["../../src/services/HealthService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,IAAI,GAAG,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACj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W,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAalC;;OAEG;IACH,wBAAwB,IAAI,MAAM;IAsClC;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAKpC;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAKxC;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAIzB;;OAEG;IACH,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIzC;;OAEG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIpC;;OAEG;IACH,aAAa,IAAI,UAAU;CAS5B"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Health Service
|
|
3
|
+
* Provides system health monitoring and status reporting
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Service for monitoring application health
|
|
7
|
+
*/
|
|
8
|
+
export class HealthService {
|
|
9
|
+
version;
|
|
10
|
+
startTime;
|
|
11
|
+
requestsProcessed = 0;
|
|
12
|
+
activeConnections = 0;
|
|
13
|
+
totalServers = 0;
|
|
14
|
+
storageHealthy = true;
|
|
15
|
+
botHealthy = true;
|
|
16
|
+
lastStorageCheck = null;
|
|
17
|
+
lastBotCheck = null;
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.version = options.version;
|
|
20
|
+
this.startTime = options.startTime;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get current health status
|
|
24
|
+
*/
|
|
25
|
+
getHealthStatus() {
|
|
26
|
+
const memory = this.getMemoryHealth();
|
|
27
|
+
const components = {
|
|
28
|
+
bot: this.getBotHealth(),
|
|
29
|
+
storage: this.getStorageHealth(),
|
|
30
|
+
memory,
|
|
31
|
+
};
|
|
32
|
+
const status = this.determineOverallStatus(components);
|
|
33
|
+
return {
|
|
34
|
+
status,
|
|
35
|
+
uptime: this.getUptime(),
|
|
36
|
+
timestamp: new Date(),
|
|
37
|
+
version: this.version,
|
|
38
|
+
components,
|
|
39
|
+
metrics: {
|
|
40
|
+
activeConnections: this.activeConnections,
|
|
41
|
+
totalServers: this.totalServers,
|
|
42
|
+
requestsProcessed: this.requestsProcessed,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get memory health metrics
|
|
48
|
+
*/
|
|
49
|
+
getMemoryHealth() {
|
|
50
|
+
const memUsage = process.memoryUsage();
|
|
51
|
+
return {
|
|
52
|
+
heapUsed: memUsage.heapUsed,
|
|
53
|
+
heapTotal: memUsage.heapTotal,
|
|
54
|
+
rss: memUsage.rss,
|
|
55
|
+
external: memUsage.external,
|
|
56
|
+
arrayBuffers: memUsage.arrayBuffers,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get bot component health
|
|
61
|
+
*/
|
|
62
|
+
getBotHealth() {
|
|
63
|
+
return {
|
|
64
|
+
status: this.botHealthy ? "up" : "down",
|
|
65
|
+
lastCheck: this.lastBotCheck ?? undefined,
|
|
66
|
+
message: this.botHealthy ? "Bot is running" : "Bot is not responding",
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get storage component health
|
|
71
|
+
*/
|
|
72
|
+
getStorageHealth() {
|
|
73
|
+
return {
|
|
74
|
+
status: this.storageHealthy ? "up" : "down",
|
|
75
|
+
lastCheck: this.lastStorageCheck ?? undefined,
|
|
76
|
+
message: this.storageHealthy
|
|
77
|
+
? "Storage is accessible"
|
|
78
|
+
: "Storage is not accessible",
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Determine overall health status
|
|
83
|
+
*/
|
|
84
|
+
determineOverallStatus(components) {
|
|
85
|
+
// Check if any critical component is down
|
|
86
|
+
if (components.bot.status === "down" ||
|
|
87
|
+
components.storage.status === "down") {
|
|
88
|
+
return "unhealthy";
|
|
89
|
+
}
|
|
90
|
+
// Check memory usage - degraded if heap usage > 85%
|
|
91
|
+
const heapUsagePercent = (components.memory.heapUsed / components.memory.heapTotal) * 100;
|
|
92
|
+
if (heapUsagePercent > 85) {
|
|
93
|
+
return "degraded";
|
|
94
|
+
}
|
|
95
|
+
return "healthy";
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get uptime in seconds
|
|
99
|
+
*/
|
|
100
|
+
getUptime() {
|
|
101
|
+
return Math.floor((Date.now() - this.startTime.getTime()) / 1000);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Format uptime as human-readable string
|
|
105
|
+
*/
|
|
106
|
+
formatUptime() {
|
|
107
|
+
const uptime = this.getUptime();
|
|
108
|
+
const days = Math.floor(uptime / 86400);
|
|
109
|
+
const hours = Math.floor((uptime % 86400) / 3600);
|
|
110
|
+
const minutes = Math.floor((uptime % 3600) / 60);
|
|
111
|
+
const seconds = uptime % 60;
|
|
112
|
+
const parts = [];
|
|
113
|
+
if (days > 0)
|
|
114
|
+
parts.push(`${days}d`);
|
|
115
|
+
if (hours > 0)
|
|
116
|
+
parts.push(`${hours}h`);
|
|
117
|
+
if (minutes > 0)
|
|
118
|
+
parts.push(`${minutes}m`);
|
|
119
|
+
parts.push(`${seconds}s`);
|
|
120
|
+
return parts.join(" ");
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Format bytes to human-readable string
|
|
124
|
+
*/
|
|
125
|
+
formatBytes(bytes) {
|
|
126
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
127
|
+
let value = bytes;
|
|
128
|
+
let unitIndex = 0;
|
|
129
|
+
while (value >= 1024 && unitIndex < units.length - 1) {
|
|
130
|
+
value /= 1024;
|
|
131
|
+
unitIndex++;
|
|
132
|
+
}
|
|
133
|
+
return `${value.toFixed(2)} ${units[unitIndex]}`;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get formatted health report
|
|
137
|
+
*/
|
|
138
|
+
getFormattedHealthReport() {
|
|
139
|
+
const health = this.getHealthStatus();
|
|
140
|
+
const memory = health.components.memory;
|
|
141
|
+
const heapUsagePercent = (memory.heapUsed / memory.heapTotal) * 100;
|
|
142
|
+
const statusEmoji = {
|
|
143
|
+
healthy: "✅",
|
|
144
|
+
degraded: "⚠️",
|
|
145
|
+
unhealthy: "❌",
|
|
146
|
+
};
|
|
147
|
+
const componentEmoji = {
|
|
148
|
+
up: "✅",
|
|
149
|
+
down: "❌",
|
|
150
|
+
};
|
|
151
|
+
let report = `${statusEmoji[health.status]} *System Health*\n\n`;
|
|
152
|
+
report += `📊 *Status:* ${health.status.toUpperCase()}\n`;
|
|
153
|
+
report += `⏱️ *Uptime:* ${this.formatUptime()}\n`;
|
|
154
|
+
report += `📌 *Version:* ${health.version}\n\n`;
|
|
155
|
+
report += `*Components:*\n`;
|
|
156
|
+
report += ` ${componentEmoji[health.components.bot.status]} Bot: ${health.components.bot.message}\n`;
|
|
157
|
+
report += ` ${componentEmoji[health.components.storage.status]} Storage: ${health.components.storage.message}\n\n`;
|
|
158
|
+
report += `*Memory:*\n`;
|
|
159
|
+
report += ` 📦 Heap: ${this.formatBytes(memory.heapUsed)} / ${this.formatBytes(memory.heapTotal)} (${heapUsagePercent.toFixed(1)}%)\n`;
|
|
160
|
+
report += ` 🖥️ RSS: ${this.formatBytes(memory.rss)}\n`;
|
|
161
|
+
report += ` 🔗 External: ${this.formatBytes(memory.external)}\n\n`;
|
|
162
|
+
report += `*Metrics:*\n`;
|
|
163
|
+
report += ` 🔌 Active Connections: ${health.metrics.activeConnections}\n`;
|
|
164
|
+
report += ` 📋 Total Servers: ${health.metrics.totalServers}\n`;
|
|
165
|
+
report += ` 📨 Requests Processed: ${health.metrics.requestsProcessed}\n`;
|
|
166
|
+
return report;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Update bot health status
|
|
170
|
+
*/
|
|
171
|
+
setBotHealth(healthy) {
|
|
172
|
+
this.botHealthy = healthy;
|
|
173
|
+
this.lastBotCheck = new Date();
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Update storage health status
|
|
177
|
+
*/
|
|
178
|
+
setStorageHealth(healthy) {
|
|
179
|
+
this.storageHealthy = healthy;
|
|
180
|
+
this.lastStorageCheck = new Date();
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Increment request counter
|
|
184
|
+
*/
|
|
185
|
+
incrementRequests() {
|
|
186
|
+
this.requestsProcessed++;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Set active connections count
|
|
190
|
+
*/
|
|
191
|
+
setActiveConnections(count) {
|
|
192
|
+
this.activeConnections = count;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Set total servers count
|
|
196
|
+
*/
|
|
197
|
+
setTotalServers(count) {
|
|
198
|
+
this.totalServers = count;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get log context for health-related logs
|
|
202
|
+
*/
|
|
203
|
+
getLogContext() {
|
|
204
|
+
const health = this.getHealthStatus();
|
|
205
|
+
return {
|
|
206
|
+
status: health.status,
|
|
207
|
+
uptime: health.uptime,
|
|
208
|
+
activeConnections: health.metrics.activeConnections,
|
|
209
|
+
heapUsed: health.components.memory.heapUsed,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=HealthService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HealthService.js","sourceRoot":"","sources":["../../src/services/HealthService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqDH;;GAEG;AACH,MAAM,OAAO,aAAa;IACP,OAAO,CAAS;IAChB,SAAS,CAAO;IACzB,iBAAiB,GAAG,CAAC,CAAC;IACtB,iBAAiB,GAAG,CAAC,CAAC;IACtB,YAAY,GAAG,CAAC,CAAC;IACjB,cAAc,GAAG,IAAI,CAAC;IACtB,UAAU,GAAG,IAAI,CAAC;IAClB,gBAAgB,GAAgB,IAAI,CAAC;IACr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1
|
+
/**
|
|
2
|
+
* Logging Service
|
|
3
|
+
* Provides structured logging with multiple output formats, log rotation, and request tracking
|
|
4
|
+
*/
|
|
5
|
+
import type { LogContext, LoggingConfig } from "../types/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Logging service for structured logging with rotation and request tracking
|
|
8
|
+
*/
|
|
9
|
+
export declare class LoggingService {
|
|
10
|
+
private readonly level;
|
|
11
|
+
private readonly format;
|
|
12
|
+
private readonly file?;
|
|
13
|
+
private readonly maxFileSize;
|
|
14
|
+
private readonly maxFiles;
|
|
15
|
+
private currentLogFile;
|
|
16
|
+
private requestCounter;
|
|
17
|
+
private readonly performanceTimers;
|
|
18
|
+
private logCount;
|
|
19
|
+
private errorCount;
|
|
20
|
+
private readonly startTime;
|
|
21
|
+
constructor(config: LoggingConfig);
|
|
22
|
+
/**
|
|
23
|
+
* Log info message
|
|
24
|
+
*/
|
|
25
|
+
info(message: string, context?: LogContext): void;
|
|
26
|
+
/**
|
|
27
|
+
* Log warning message
|
|
28
|
+
*/
|
|
29
|
+
warn(message: string, context?: LogContext): void;
|
|
30
|
+
/**
|
|
31
|
+
* Log error message
|
|
32
|
+
*/
|
|
33
|
+
error(message: string, error?: Error, context?: LogContext): void;
|
|
34
|
+
/**
|
|
35
|
+
* Log debug message
|
|
36
|
+
*/
|
|
37
|
+
debug(message: string, context?: LogContext): void;
|
|
38
|
+
/**
|
|
39
|
+
* Log with request ID tracking
|
|
40
|
+
*/
|
|
41
|
+
withRequestId(requestId: string): {
|
|
42
|
+
info: (message: string, context?: LogContext) => void;
|
|
43
|
+
warn: (message: string, context?: LogContext) => void;
|
|
44
|
+
error: (message: string, error?: Error, context?: LogContext) => void;
|
|
45
|
+
debug: (message: string, context?: LogContext) => void;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Generate a new request ID
|
|
49
|
+
*/
|
|
50
|
+
generateRequestId(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Start a performance timer
|
|
53
|
+
*/
|
|
54
|
+
startTimer(label: string, context?: LogContext): string;
|
|
55
|
+
/**
|
|
56
|
+
* End a performance timer and log the duration
|
|
57
|
+
*/
|
|
58
|
+
endTimer(timerId: string, additionalContext?: LogContext): number | null;
|
|
59
|
+
/**
|
|
60
|
+
* Log performance metrics
|
|
61
|
+
*/
|
|
62
|
+
logPerformance(operation: string, duration: number, context?: LogContext): void;
|
|
63
|
+
/**
|
|
64
|
+
* Log with component context
|
|
65
|
+
*/
|
|
66
|
+
withComponent(component: string): {
|
|
67
|
+
info: (message: string, context?: LogContext) => void;
|
|
68
|
+
warn: (message: string, context?: LogContext) => void;
|
|
69
|
+
error: (message: string, error?: Error, context?: LogContext) => void;
|
|
70
|
+
debug: (message: string, context?: LogContext) => void;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Get logging statistics
|
|
74
|
+
*/
|
|
75
|
+
getStats(): {
|
|
76
|
+
totalLogs: number;
|
|
77
|
+
errorCount: number;
|
|
78
|
+
uptime: number;
|
|
79
|
+
activeTimers: number;
|
|
80
|
+
requestCount: number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Internal log method
|
|
84
|
+
*/
|
|
85
|
+
private log;
|
|
86
|
+
/**
|
|
87
|
+
* Check if should log based on level
|
|
88
|
+
*/
|
|
89
|
+
private shouldLog;
|
|
90
|
+
/**
|
|
91
|
+
* Parse log level from string
|
|
92
|
+
*/
|
|
93
|
+
private parseLevel;
|
|
94
|
+
/**
|
|
95
|
+
* Format log entry as pretty string
|
|
96
|
+
*/
|
|
97
|
+
private formatPretty;
|
|
98
|
+
/**
|
|
99
|
+
* Write log entry to file
|
|
100
|
+
*/
|
|
101
|
+
private writeToFile;
|
|
102
|
+
/**
|
|
103
|
+
* Initialize log file
|
|
104
|
+
*/
|
|
105
|
+
private initializeLogFile;
|
|
106
|
+
/**
|
|
107
|
+
* Rotate log file
|
|
108
|
+
*/
|
|
109
|
+
private rotateLogFile;
|
|
110
|
+
/**
|
|
111
|
+
* Clean up old log files
|
|
112
|
+
*/
|
|
113
|
+
private cleanupOldLogFiles;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=LoggingService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoggingService.d.ts","sourceRoot":"","sources":["../../src/services/LoggingService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAY,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAsC7E;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAW;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAC3C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,cAAc,CAAwB;IAC9C,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA4C;IAC9E,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAO;gBAErB,MAAM,EAAE,aAAa;IASjC;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI;IAIjD;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI;IAIjD;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI;IAIjE;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI;IAIlD;;OAEG;IACH,aAAa,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