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.
Files changed (184) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +103 -22
  3. package/deploy/.env.example +86 -0
  4. package/dist/config/index.d.ts +68 -0
  5. package/dist/config/index.d.ts.map +1 -0
  6. package/dist/config/index.js +315 -0
  7. package/dist/config/index.js.map +1 -0
  8. package/dist/config/schema.d.ts +6 -0
  9. package/dist/config/schema.d.ts.map +1 -0
  10. package/dist/config/schema.js +50 -0
  11. package/dist/config/schema.js.map +1 -0
  12. package/dist/core/Bot.d.ts +91 -0
  13. package/dist/core/Bot.d.ts.map +1 -0
  14. package/dist/core/Bot.js +263 -0
  15. package/dist/core/Bot.js.map +1 -0
  16. package/dist/core/ConnectionPool.d.ts +125 -0
  17. package/dist/core/ConnectionPool.d.ts.map +1 -0
  18. package/dist/core/ConnectionPool.js +397 -0
  19. package/dist/core/ConnectionPool.js.map +1 -0
  20. package/dist/core/SSHClient.d.ts +112 -0
  21. package/dist/core/SSHClient.d.ts.map +1 -0
  22. package/dist/core/SSHClient.js +367 -0
  23. package/dist/core/SSHClient.js.map +1 -0
  24. package/dist/core/ServerManager.d.ts +80 -0
  25. package/dist/core/ServerManager.d.ts.map +1 -0
  26. package/dist/core/ServerManager.js +207 -0
  27. package/dist/core/ServerManager.js.map +1 -0
  28. package/dist/core/index.d.ts +8 -0
  29. package/dist/core/index.d.ts.map +1 -0
  30. package/dist/core/index.js +8 -0
  31. package/dist/core/index.js.map +1 -0
  32. package/dist/errors/AuthError.d.ts +30 -0
  33. package/dist/errors/AuthError.d.ts.map +1 -0
  34. package/dist/errors/AuthError.js +35 -0
  35. package/dist/errors/AuthError.js.map +1 -0
  36. package/dist/errors/BaseError.d.ts +17 -0
  37. package/dist/errors/BaseError.d.ts.map +1 -0
  38. package/dist/errors/BaseError.js +34 -0
  39. package/dist/errors/BaseError.js.map +1 -0
  40. package/dist/errors/ConfigurationError.d.ts +24 -0
  41. package/dist/errors/ConfigurationError.d.ts.map +1 -0
  42. package/dist/errors/ConfigurationError.js +24 -0
  43. package/dist/errors/ConfigurationError.js.map +1 -0
  44. package/dist/errors/PoolError.d.ts +21 -0
  45. package/dist/errors/PoolError.d.ts.map +1 -0
  46. package/dist/errors/PoolError.js +30 -0
  47. package/dist/errors/PoolError.js.map +1 -0
  48. package/dist/errors/SSHError.d.ts +24 -0
  49. package/dist/errors/SSHError.d.ts.map +1 -0
  50. package/dist/errors/SSHError.js +38 -0
  51. package/dist/errors/SSHError.js.map +1 -0
  52. package/dist/errors/StorageError.d.ts +24 -0
  53. package/dist/errors/StorageError.d.ts.map +1 -0
  54. package/dist/errors/StorageError.js +35 -0
  55. package/dist/errors/StorageError.js.map +1 -0
  56. package/dist/errors/ValidationError.d.ts +29 -0
  57. package/dist/errors/ValidationError.d.ts.map +1 -0
  58. package/dist/errors/ValidationError.js +35 -0
  59. package/dist/errors/ValidationError.js.map +1 -0
  60. package/dist/errors/index.d.ts +11 -0
  61. package/dist/errors/index.d.ts.map +1 -0
  62. package/dist/errors/index.js +18 -0
  63. package/dist/errors/index.js.map +1 -0
  64. package/dist/handlers/BaseHandler.d.ts +50 -0
  65. package/dist/handlers/BaseHandler.d.ts.map +1 -0
  66. package/dist/handlers/BaseHandler.js +87 -0
  67. package/dist/handlers/BaseHandler.js.map +1 -0
  68. package/dist/handlers/CommandHandler.d.ts +23 -0
  69. package/dist/handlers/CommandHandler.d.ts.map +1 -0
  70. package/dist/handlers/CommandHandler.js +99 -0
  71. package/dist/handlers/CommandHandler.js.map +1 -0
  72. package/dist/handlers/HealthHandler.d.ts +25 -0
  73. package/dist/handlers/HealthHandler.d.ts.map +1 -0
  74. package/dist/handlers/HealthHandler.js +51 -0
  75. package/dist/handlers/HealthHandler.js.map +1 -0
  76. package/dist/handlers/HelpHandler.d.ts +32 -0
  77. package/dist/handlers/HelpHandler.d.ts.map +1 -0
  78. package/dist/handlers/HelpHandler.js +76 -0
  79. package/dist/handlers/HelpHandler.js.map +1 -0
  80. package/dist/handlers/ServerHandler.d.ts +72 -0
  81. package/dist/handlers/ServerHandler.d.ts.map +1 -0
  82. package/dist/handlers/ServerHandler.js +272 -0
  83. package/dist/handlers/ServerHandler.js.map +1 -0
  84. package/dist/handlers/index.d.ts +9 -0
  85. package/dist/handlers/index.d.ts.map +1 -0
  86. package/dist/handlers/index.js +9 -0
  87. package/dist/handlers/index.js.map +1 -0
  88. package/dist/index.d.ts +10 -0
  89. package/dist/index.d.ts.map +1 -0
  90. package/dist/index.js +348 -0
  91. package/dist/index.js.map +1 -0
  92. package/dist/middleware/AuthMiddleware.d.ts +28 -0
  93. package/dist/middleware/AuthMiddleware.d.ts.map +1 -0
  94. package/dist/middleware/AuthMiddleware.js +49 -0
  95. package/dist/middleware/AuthMiddleware.js.map +1 -0
  96. package/dist/middleware/RateLimitMiddleware.d.ts +23 -0
  97. package/dist/middleware/RateLimitMiddleware.d.ts.map +1 -0
  98. package/dist/middleware/RateLimitMiddleware.js +34 -0
  99. package/dist/middleware/RateLimitMiddleware.js.map +1 -0
  100. package/dist/middleware/index.d.ts +6 -0
  101. package/dist/middleware/index.d.ts.map +1 -0
  102. package/dist/middleware/index.js +6 -0
  103. package/dist/middleware/index.js.map +1 -0
  104. package/dist/services/BackupService.d.ts +119 -0
  105. package/dist/services/BackupService.d.ts.map +1 -0
  106. package/dist/services/BackupService.js +313 -0
  107. package/dist/services/BackupService.js.map +1 -0
  108. package/dist/services/CryptoService.d.ts +37 -0
  109. package/dist/services/CryptoService.d.ts.map +1 -0
  110. package/dist/services/CryptoService.js +108 -0
  111. package/dist/services/CryptoService.js.map +1 -0
  112. package/dist/services/HealthService.d.ts +126 -0
  113. package/dist/services/HealthService.d.ts.map +1 -0
  114. package/dist/services/HealthService.js +213 -0
  115. package/dist/services/HealthService.js.map +1 -0
  116. package/dist/services/LoggingService.d.ts +115 -0
  117. package/dist/services/LoggingService.d.ts.map +1 -0
  118. package/dist/services/LoggingService.js +334 -0
  119. package/dist/services/LoggingService.js.map +1 -0
  120. package/dist/services/MonitoringService.d.ts +119 -0
  121. package/dist/services/MonitoringService.d.ts.map +1 -0
  122. package/dist/services/MonitoringService.js +267 -0
  123. package/dist/services/MonitoringService.js.map +1 -0
  124. package/dist/services/NotificationService.d.ts +132 -0
  125. package/dist/services/NotificationService.d.ts.map +1 -0
  126. package/dist/services/NotificationService.js +297 -0
  127. package/dist/services/NotificationService.js.map +1 -0
  128. package/dist/services/RateLimiter.d.ts +51 -0
  129. package/dist/services/RateLimiter.d.ts.map +1 -0
  130. package/dist/services/RateLimiter.js +141 -0
  131. package/dist/services/RateLimiter.js.map +1 -0
  132. package/dist/services/ValidationService.d.ts +49 -0
  133. package/dist/services/ValidationService.d.ts.map +1 -0
  134. package/dist/services/ValidationService.js +158 -0
  135. package/dist/services/ValidationService.js.map +1 -0
  136. package/dist/services/index.d.ts +12 -0
  137. package/dist/services/index.d.ts.map +1 -0
  138. package/dist/services/index.js +12 -0
  139. package/dist/services/index.js.map +1 -0
  140. package/dist/types/Bot.d.ts +63 -0
  141. package/dist/types/Bot.d.ts.map +1 -0
  142. package/dist/types/Bot.js +5 -0
  143. package/dist/types/Bot.js.map +1 -0
  144. package/dist/types/Config.d.ts +57 -0
  145. package/dist/types/Config.d.ts.map +1 -0
  146. package/dist/types/Config.js +5 -0
  147. package/dist/types/Config.js.map +1 -0
  148. package/dist/types/Errors.d.ts +37 -0
  149. package/dist/types/Errors.d.ts.map +1 -0
  150. package/dist/types/Errors.js +34 -0
  151. package/dist/types/Errors.js.map +1 -0
  152. package/dist/types/SSH.d.ts +56 -0
  153. package/dist/types/SSH.d.ts.map +1 -0
  154. package/dist/types/SSH.js +6 -0
  155. package/dist/types/SSH.js.map +1 -0
  156. package/dist/types/Server.d.ts +39 -0
  157. package/dist/types/Server.d.ts.map +1 -0
  158. package/dist/types/Server.js +5 -0
  159. package/dist/types/Server.js.map +1 -0
  160. package/dist/types/index.d.ts +10 -0
  161. package/dist/types/index.d.ts.map +1 -0
  162. package/dist/types/index.js +6 -0
  163. package/dist/types/index.js.map +1 -0
  164. package/dist/utils/commandUtils.d.ts +25 -0
  165. package/dist/utils/commandUtils.d.ts.map +1 -0
  166. package/dist/utils/commandUtils.js +94 -0
  167. package/dist/utils/commandUtils.js.map +1 -0
  168. package/dist/utils/fileUtils.d.ts +40 -0
  169. package/dist/utils/fileUtils.d.ts.map +1 -0
  170. package/dist/utils/fileUtils.js +114 -0
  171. package/dist/utils/fileUtils.js.map +1 -0
  172. package/dist/utils/index.d.ts +7 -0
  173. package/dist/utils/index.d.ts.map +1 -0
  174. package/dist/utils/index.js +7 -0
  175. package/dist/utils/index.js.map +1 -0
  176. package/dist/utils/pathUtils.d.ts +40 -0
  177. package/dist/utils/pathUtils.d.ts.map +1 -0
  178. package/dist/utils/pathUtils.js +140 -0
  179. package/dist/utils/pathUtils.js.map +1 -0
  180. package/package.json +31 -5
  181. package/scripts/build.sh +20 -0
  182. package/scripts/postinstall.js +87 -0
  183. package/scripts/release.sh +22 -0
  184. package/scripts/setup-env.js +237 -0
@@ -0,0 +1,297 @@
1
+ /**
2
+ * Notification Service
3
+ * Provides admin notifications for important events
4
+ */
5
+ /**
6
+ * Service for sending admin notifications
7
+ */
8
+ export class NotificationService {
9
+ logger;
10
+ config;
11
+ bot = null;
12
+ notificationCount = 0;
13
+ startTime;
14
+ constructor(config, logger) {
15
+ this.config = {
16
+ enabled: config.enabled ?? true,
17
+ notifyOnStartup: config.notifyOnStartup ?? true,
18
+ notifyOnShutdown: config.notifyOnShutdown ?? true,
19
+ notifyOnErrors: config.notifyOnErrors ?? true,
20
+ notifyOnSecurity: config.notifyOnSecurity ?? true,
21
+ adminChatId: config.adminChatId ?? "",
22
+ };
23
+ this.logger = logger;
24
+ this.startTime = new Date();
25
+ }
26
+ /**
27
+ * Set the bot instance for sending messages
28
+ */
29
+ setBot(bot) {
30
+ this.bot = bot;
31
+ }
32
+ /**
33
+ * Send a notification
34
+ */
35
+ async notify(payload) {
36
+ if (!this.config.enabled || !this.bot || !this.config.adminChatId) {
37
+ this.logger.debug("Notification skipped", {
38
+ enabled: this.config.enabled,
39
+ hasBot: !!this.bot,
40
+ hasChatId: !!this.config.adminChatId,
41
+ });
42
+ return false;
43
+ }
44
+ const fullPayload = {
45
+ ...payload,
46
+ timestamp: new Date(),
47
+ };
48
+ try {
49
+ const message = this.formatNotification(fullPayload);
50
+ await this.bot.sendMessage(parseInt(this.config.adminChatId, 10), message, { parseMode: "Markdown" });
51
+ this.notificationCount++;
52
+ this.logger.debug("Notification sent", {
53
+ type: payload.type,
54
+ priority: payload.priority,
55
+ });
56
+ return true;
57
+ }
58
+ catch (error) {
59
+ this.logger.error("Failed to send notification", error, {
60
+ type: payload.type,
61
+ });
62
+ return false;
63
+ }
64
+ }
65
+ /**
66
+ * Send startup notification
67
+ */
68
+ async notifyStartup(version) {
69
+ if (!this.config.notifyOnStartup) {
70
+ return false;
71
+ }
72
+ return this.notify({
73
+ type: "startup",
74
+ priority: "normal",
75
+ title: "🚀 Bot Started",
76
+ message: `Telegram SSH Bot has started successfully.\n\nVersion: ${version}\nStarted at: ${this.startTime.toISOString()}`,
77
+ });
78
+ }
79
+ /**
80
+ * Send shutdown notification
81
+ */
82
+ async notifyShutdown(reason) {
83
+ if (!this.config.notifyOnShutdown) {
84
+ return false;
85
+ }
86
+ const uptime = Math.floor((Date.now() - this.startTime.getTime()) / 1000);
87
+ return this.notify({
88
+ type: "shutdown",
89
+ priority: "high",
90
+ title: "🛑 Bot Shutting Down",
91
+ message: `Telegram SSH Bot is shutting down.\n\nReason: ${reason}\nUptime: ${this.formatUptime(uptime)}`,
92
+ });
93
+ }
94
+ /**
95
+ * Send error notification
96
+ */
97
+ async notifyError(error, context) {
98
+ if (!this.config.notifyOnErrors) {
99
+ return false;
100
+ }
101
+ return this.notify({
102
+ type: "error",
103
+ priority: "high",
104
+ title: "⚠️ Error Occurred",
105
+ message: `An error occurred:\n\n${error.message}\n\nStack: \`${error.stack?.split("\n")[0] ?? "N/A"}\``,
106
+ details: { errorName: error.name, ...context },
107
+ });
108
+ }
109
+ /**
110
+ * Send security notification
111
+ */
112
+ async notifySecurity(event, details) {
113
+ if (!this.config.notifyOnSecurity) {
114
+ return false;
115
+ }
116
+ return this.notify({
117
+ type: "security",
118
+ priority: "critical",
119
+ title: "🔒 Security Event",
120
+ message: `Security event detected:\n\n${event}`,
121
+ details,
122
+ });
123
+ }
124
+ /**
125
+ * Send server added notification
126
+ */
127
+ async notifyServerAdded(server) {
128
+ return this.notify({
129
+ type: "server_added",
130
+ priority: "normal",
131
+ title: "➕ Server Added",
132
+ message: `New server added:\n\nHost: \`${server.host}\`\nUsername: \`${server.username}\`\nPort: ${server.port}`,
133
+ details: { serverId: server.id },
134
+ });
135
+ }
136
+ /**
137
+ * Send server removed notification
138
+ */
139
+ async notifyServerRemoved(server) {
140
+ return this.notify({
141
+ type: "server_removed",
142
+ priority: "normal",
143
+ title: "➖ Server Removed",
144
+ message: `Server removed:\n\nHost: \`${server.host}\`\nUsername: \`${server.username}\``,
145
+ details: { serverId: server.id },
146
+ });
147
+ }
148
+ /**
149
+ * Send connection lost notification
150
+ */
151
+ async notifyConnectionLost(server, error) {
152
+ return this.notify({
153
+ type: "connection_lost",
154
+ priority: "high",
155
+ title: "🔌 Connection Lost",
156
+ message: `Connection lost to server:\n\nHost: \`${server.host}\`\n${error ? `Error: ${error}` : ""}`,
157
+ details: { serverId: server.id, error },
158
+ });
159
+ }
160
+ /**
161
+ * Send connection restored notification
162
+ */
163
+ async notifyConnectionRestored(server) {
164
+ return this.notify({
165
+ type: "connection_restored",
166
+ priority: "normal",
167
+ title: "✅ Connection Restored",
168
+ message: `Connection restored to server:\n\nHost: \`${server.host}\``,
169
+ details: { serverId: server.id },
170
+ });
171
+ }
172
+ /**
173
+ * Send backup created notification
174
+ */
175
+ async notifyBackupCreated(backupId, size) {
176
+ return this.notify({
177
+ type: "backup_created",
178
+ priority: "low",
179
+ title: "💾 Backup Created",
180
+ message: `Backup created successfully.\n\nID: \`${backupId}\`\nSize: ${this.formatBytes(size)}`,
181
+ details: { backupId, size },
182
+ });
183
+ }
184
+ /**
185
+ * Send backup restored notification
186
+ */
187
+ async notifyBackupRestored(backupId) {
188
+ return this.notify({
189
+ type: "backup_restored",
190
+ priority: "normal",
191
+ title: "📂 Backup Restored",
192
+ message: `Backup restored successfully.\n\nID: \`${backupId}\``,
193
+ details: { backupId },
194
+ });
195
+ }
196
+ /**
197
+ * Send config reloaded notification
198
+ */
199
+ async notifyConfigReloaded(success) {
200
+ return this.notify({
201
+ type: "config_reloaded",
202
+ priority: success ? "normal" : "high",
203
+ title: success ? "⚙️ Config Reloaded" : "⚠️ Config Reload Failed",
204
+ message: success
205
+ ? "Configuration reloaded successfully."
206
+ : "Configuration reload failed. Check logs for details.",
207
+ });
208
+ }
209
+ /**
210
+ * Send rate limited notification
211
+ */
212
+ async notifyRateLimited(chatId, command) {
213
+ return this.notify({
214
+ type: "rate_limited",
215
+ priority: "normal",
216
+ title: "⏱️ Rate Limited",
217
+ message: `User rate limited.\n\nChat ID: ${chatId}\nCommand: \`${command}\``,
218
+ details: { chatId, command },
219
+ });
220
+ }
221
+ /**
222
+ * Send unauthorized access notification
223
+ */
224
+ async notifyUnauthorizedAccess(chatId, username, command) {
225
+ return this.notify({
226
+ type: "unauthorized_access",
227
+ priority: "critical",
228
+ title: "🚫 Unauthorized Access",
229
+ message: `Unauthorized access attempt.\n\nChat ID: ${chatId}\nUsername: ${username ?? "Unknown"}\nCommand: \`${command}\``,
230
+ details: { chatId, username, command },
231
+ });
232
+ }
233
+ /**
234
+ * Get notification statistics
235
+ */
236
+ getStats() {
237
+ return {
238
+ enabled: this.config.enabled,
239
+ totalNotifications: this.notificationCount,
240
+ uptime: Math.floor((Date.now() - this.startTime.getTime()) / 1000),
241
+ };
242
+ }
243
+ /**
244
+ * Get log context for notification-related logs
245
+ */
246
+ getLogContext() {
247
+ const stats = this.getStats();
248
+ return {
249
+ notificationsEnabled: stats.enabled,
250
+ totalNotifications: stats.totalNotifications,
251
+ };
252
+ }
253
+ /**
254
+ * Format notification message
255
+ */
256
+ formatNotification(payload) {
257
+ const priorityEmoji = {
258
+ low: "ℹ️",
259
+ normal: "📢",
260
+ high: "⚠️",
261
+ critical: "🚨",
262
+ };
263
+ let message = `${priorityEmoji[payload.priority]} *${payload.title}*\n\n`;
264
+ message += payload.message;
265
+ message += `\n\n_Time: ${payload.timestamp.toISOString()}_`;
266
+ return message;
267
+ }
268
+ /**
269
+ * Format uptime as human-readable string
270
+ */
271
+ formatUptime(seconds) {
272
+ const days = Math.floor(seconds / 86400);
273
+ const hours = Math.floor((seconds % 86400) / 3600);
274
+ const minutes = Math.floor((seconds % 3600) / 60);
275
+ const parts = [];
276
+ if (days > 0)
277
+ parts.push(`${days}d`);
278
+ if (hours > 0)
279
+ parts.push(`${hours}h`);
280
+ parts.push(`${minutes}m`);
281
+ return parts.join(" ");
282
+ }
283
+ /**
284
+ * Format bytes to human-readable string
285
+ */
286
+ formatBytes(bytes) {
287
+ const units = ["B", "KB", "MB", "GB"];
288
+ let value = bytes;
289
+ let unitIndex = 0;
290
+ while (value >= 1024 && unitIndex < units.length - 1) {
291
+ value /= 1024;
292
+ unitIndex++;
293
+ }
294
+ return `${value.toFixed(2)} ${units[unitIndex]}`;
295
+ }
296
+ }
297
+ //# sourceMappingURL=NotificationService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationService.js","sourceRoot":"","sources":["../../src/services/NotificationService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoDH;;GAEG;AACH,MAAM,OAAO,mBAAmB;IACb,MAAM,CAAiB;IACvB,MAAM,CAAqB;IACpC,GAAG,GAAgB,IAAI,CAAC;IACxB,iBAAiB,GAAG,CAAC,CAAC;IACb,SAAS,CAAO;IAEjC,YAAY,MAAmC,EAAE,MAAsB;QACrE,IAAI,CAAC,MAAM,GAAG;Y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ests
4
+ */
5
+ import type { RateLimitConfig } from "../types/index.js";
6
+ /**
7
+ * Rate limiter service for controlling request frequency
8
+ */
9
+ export declare class RateLimiter {
10
+ private readonly config;
11
+ private readonly store;
12
+ private cleanupTimer;
13
+ private static readonly CLEANUP_INTERVAL_MS;
14
+ constructor(config: RateLimitConfig);
15
+ /**
16
+ * Start automatic cleanup timer
17
+ * Runs cleanup periodically to remove expired records
18
+ */
19
+ startAutoCleanup(): void;
20
+ /**
21
+ * Stop automatic cleanup timer
22
+ * Should be called during shutdown
23
+ */
24
+ stopAutoCleanup(): void;
25
+ /**
26
+ * Check if a request is allowed for the given identifier
27
+ * @throws RateLimitedError if rate limit is exceeded
28
+ */
29
+ checkLimit(identifier: string): boolean;
30
+ /**
31
+ * Check if identifier is currently rate limited
32
+ */
33
+ isLimited(identifier: string): boolean;
34
+ /**
35
+ * Get remaining requests for identifier
36
+ */
37
+ getRemaining(identifier: string): number;
38
+ /**
39
+ * Reset rate limit for identifier
40
+ */
41
+ reset(identifier: string): void;
42
+ /**
43
+ * Reset all rate limits
44
+ */
45
+ resetAll(): void;
46
+ /**
47
+ * Clean up expired records
48
+ */
49
+ cleanup(): void;
50
+ }
51
+ //# sourceMappingURL=RateLimiter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RateLimiter.d.ts","sourceRoot":"","sources":["../../src/services/RateLimiter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAWzD;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2C;IACjE,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAiB;gBAEhD,MAAM,EAAE,eAAe;IAInC;;;OAGG;IACH,gBAAgB,IAAI,IAAI;IAexB;;;OAGG;IACH,eAAe,IAAI,IAAI;IAOvB;;;OAGG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IA4CvC;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAatC;;OAEG;IACH,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAcxC;;OAEG;IACH,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAI/B;;OAEG;IACH,QAAQ,IAAI,IAAI;IAIhB;;OAEG;IACH,OAAO,IAAI,IAAI;CAoBhB"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Rate Limiter Service
3
+ * Provides rate limiting for API requests
4
+ */
5
+ import { RateLimitedError } from "../errors/index.js";
6
+ /**
7
+ * Rate limiter service for controlling request frequency
8
+ */
9
+ export class RateLimiter {
10
+ config;
11
+ store = new Map();
12
+ cleanupTimer = null;
13
+ static CLEANUP_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
14
+ constructor(config) {
15
+ this.config = config;
16
+ }
17
+ /**
18
+ * Start automatic cleanup timer
19
+ * Runs cleanup periodically to remove expired records
20
+ */
21
+ startAutoCleanup() {
22
+ if (this.cleanupTimer) {
23
+ return; // Already running
24
+ }
25
+ this.cleanupTimer = setInterval(() => {
26
+ this.cleanup();
27
+ }, RateLimiter.CLEANUP_INTERVAL_MS);
28
+ // Prevent the timer from keeping the process alive
29
+ if (this.cleanupTimer.unref) {
30
+ this.cleanupTimer.unref();
31
+ }
32
+ }
33
+ /**
34
+ * Stop automatic cleanup timer
35
+ * Should be called during shutdown
36
+ */
37
+ stopAutoCleanup() {
38
+ if (this.cleanupTimer) {
39
+ clearInterval(this.cleanupTimer);
40
+ this.cleanupTimer = null;
41
+ }
42
+ }
43
+ /**
44
+ * Check if a request is allowed for the given identifier
45
+ * @throws RateLimitedError if rate limit is exceeded
46
+ */
47
+ checkLimit(identifier) {
48
+ if (!this.config.enabled) {
49
+ return true;
50
+ }
51
+ const now = Date.now();
52
+ // Get or create record
53
+ let record = this.store.get(identifier);
54
+ if (!record) {
55
+ record = { requests: [], blocked: false };
56
+ this.store.set(identifier, record);
57
+ }
58
+ // Check if blocked
59
+ if (record.blocked) {
60
+ if (record.blockedUntil && now < record.blockedUntil) {
61
+ const retryAfter = Math.ceil((record.blockedUntil - now) / 1000);
62
+ throw new RateLimitedError(retryAfter, { context: { identifier } });
63
+ }
64
+ // Reset block
65
+ record.blocked = false;
66
+ record.blockedUntil = undefined;
67
+ }
68
+ // Clean old requests
69
+ record.requests = record.requests.filter((time) => now - time < this.config.windowMs);
70
+ // Check limit
71
+ if (record.requests.length >= this.config.maxRequests) {
72
+ record.blocked = true;
73
+ record.blockedUntil = now + this.config.windowMs;
74
+ throw new RateLimitedError(Math.ceil(this.config.windowMs / 1000), {
75
+ context: { identifier },
76
+ });
77
+ }
78
+ // Record request
79
+ record.requests.push(now);
80
+ return true;
81
+ }
82
+ /**
83
+ * Check if identifier is currently rate limited
84
+ */
85
+ isLimited(identifier) {
86
+ const record = this.store.get(identifier);
87
+ if (!record) {
88
+ return false;
89
+ }
90
+ if (record.blocked && record.blockedUntil) {
91
+ return Date.now() < record.blockedUntil;
92
+ }
93
+ return false;
94
+ }
95
+ /**
96
+ * Get remaining requests for identifier
97
+ */
98
+ getRemaining(identifier) {
99
+ const record = this.store.get(identifier);
100
+ if (!record) {
101
+ return this.config.maxRequests;
102
+ }
103
+ const now = Date.now();
104
+ const validRequests = record.requests.filter((time) => now - time < this.config.windowMs);
105
+ return Math.max(0, this.config.maxRequests - validRequests.length);
106
+ }
107
+ /**
108
+ * Reset rate limit for identifier
109
+ */
110
+ reset(identifier) {
111
+ this.store.delete(identifier);
112
+ }
113
+ /**
114
+ * Reset all rate limits
115
+ */
116
+ resetAll() {
117
+ this.store.clear();
118
+ }
119
+ /**
120
+ * Clean up expired records
121
+ */
122
+ cleanup() {
123
+ const now = Date.now();
124
+ for (const [key, record] of this.store.entries()) {
125
+ // Remove expired blocked records
126
+ if (record.blocked && record.blockedUntil && now >= record.blockedUntil) {
127
+ this.store.delete(key);
128
+ continue;
129
+ }
130
+ // Remove records with no valid requests
131
+ const validRequests = record.requests.filter((time) => now - time < this.config.windowMs);
132
+ if (validRequests.length === 0) {
133
+ this.store.delete(key);
134
+ }
135
+ else {
136
+ record.requests = validRequests;
137
+ }
138
+ }
139
+ }
140
+ }
141
+ //# sourceMappingURL=RateLimiter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RateLimiter.js","sourceRoot":"","sources":["../../src/services/RateLimiter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAYtD;;GAEG;AACH,MAAM,OAAO,WAAW;IACL,MAAM,CAAkB;IACxB,KAAK,GAAiC,IAAI,GAAG,EAAE,CAAC;IACzD,YAAY,GAA0B,IAAI,CAAC;IAC3C,MAAM,CAAU,mBAAmB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;IAEzE,YAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,gBAAgB;QACd,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,OAAO,CAAC,kBAAkB;QAC5B,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE;YACnC,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC,EAAE,WAAW,CAAC,mBAAmB,CAAC,CAAC;QAEpC,mDAAmD;QACnD,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;YAC5B,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,eAAe;QACb,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACjC,IAAI,CAAC,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AAQ,CAC5C,CAAC;QAEF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACrE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAkB;QACtB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,OAAO;QACL,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YACjD,iCAAiC;YACjC,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,YAAY,IAAI,GAAG,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;gBACxE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACvB,SAAS;YACX,CAAC;YAED,wCAAwC;YACxC,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAC1C,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAC5C,CAAC;YACF,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC/B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACzB,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,QAAQ,GAAG,aAAa,CAAC;YAClC,CAAC;QACH,CAAC;IACH,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Validation Service
3
+ * Provides input validation and sanitization
4
+ */
5
+ import type { SanitizedCommand, ServerConfig, SSHConnectionConfig, ValidationResult } from "../types/index.js";
6
+ /**
7
+ * Validation service for input sanitization and validation
8
+ */
9
+ export declare class ValidationService {
10
+ private readonly allowedCommands;
11
+ private readonly blockedCommands;
12
+ constructor(options?: {
13
+ allowedCommands?: string[];
14
+ blockedCommands?: string[];
15
+ });
16
+ /**
17
+ * Validate and sanitize a command
18
+ */
19
+ validateCommand(command: string): ValidationResult<SanitizedCommand>;
20
+ /**
21
+ * Validate server configuration
22
+ */
23
+ validateServerConfig(data: Partial<ServerConfig>): ValidationResult<ServerConfig>;
24
+ /**
25
+ * Validate SSH connection configuration
26
+ */
27
+ validateSSHConfig(config: SSHConnectionConfig): ValidationResult<SSHConnectionConfig>;
28
+ /**
29
+ * Validate a path for file operations
30
+ */
31
+ validatePath(inputPath: string, basePath?: string): ValidationResult<string>;
32
+ /**
33
+ * Validate a host address
34
+ */
35
+ validateHost(host: string): ValidationResult<string>;
36
+ /**
37
+ * Validate a port number
38
+ */
39
+ validatePort(port: number): ValidationResult<number>;
40
+ /**
41
+ * Parse and validate a port from string
42
+ */
43
+ parsePort(portStr: string): ValidationResult<number>;
44
+ /**
45
+ * Sanitize a command string
46
+ */
47
+ sanitizeCommand(command: string): SanitizedCommand;
48
+ }
49
+ //# sourceMappingURL=ValidationService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidationService.d.ts","sourceRoot":"","sources":["../../src/services/ValidationService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAS3B;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAuB;IACvD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAuB;gBAE3C,OAAO,CAAC,EAAE;QACpB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;KAC5B;IAKD;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAAC,gBAAgB,CAAC;IA+BpE;;OAEG;IACH,oBAAoB,CAClB,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,GAC1B,gBAAgB,CAAC,YAAY,CAAC;IAyDjC;;OAEG;IACH,iBAAiB,CACf,MAAM,EAAE,mBAAmB,GAC1B,gBAAgB,CAAC,mBAAmB,CAAC;IAgCxC;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAI5E;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAIpD;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAIpD;;OAEG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAIpD;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB;CAGnD"}