@minecraft-docker/shared 1.6.0 → 1.6.2

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 (261) hide show
  1. package/dist/application/index.d.ts +3 -0
  2. package/dist/application/index.d.ts.map +1 -0
  3. package/dist/application/index.js +5 -0
  4. package/dist/application/index.js.map +1 -0
  5. package/dist/application/ports/inbound/IBackupUseCase.d.ts +69 -0
  6. package/dist/application/ports/inbound/IBackupUseCase.d.ts.map +1 -0
  7. package/dist/application/ports/inbound/IBackupUseCase.js +2 -0
  8. package/dist/application/ports/inbound/IBackupUseCase.js.map +1 -0
  9. package/dist/application/ports/inbound/ICreateServerUseCase.d.ts +32 -0
  10. package/dist/application/ports/inbound/ICreateServerUseCase.d.ts.map +1 -0
  11. package/dist/application/ports/inbound/ICreateServerUseCase.js +2 -0
  12. package/dist/application/ports/inbound/ICreateServerUseCase.js.map +1 -0
  13. package/dist/application/ports/inbound/IDeleteServerUseCase.d.ts +26 -0
  14. package/dist/application/ports/inbound/IDeleteServerUseCase.d.ts.map +1 -0
  15. package/dist/application/ports/inbound/IDeleteServerUseCase.js +2 -0
  16. package/dist/application/ports/inbound/IDeleteServerUseCase.js.map +1 -0
  17. package/dist/application/ports/inbound/IPlayerLookupUseCase.d.ts +47 -0
  18. package/dist/application/ports/inbound/IPlayerLookupUseCase.d.ts.map +1 -0
  19. package/dist/application/ports/inbound/IPlayerLookupUseCase.js +2 -0
  20. package/dist/application/ports/inbound/IPlayerLookupUseCase.js.map +1 -0
  21. package/dist/application/ports/inbound/IServerStatusUseCase.d.ts +34 -0
  22. package/dist/application/ports/inbound/IServerStatusUseCase.d.ts.map +1 -0
  23. package/dist/application/ports/inbound/IServerStatusUseCase.js +2 -0
  24. package/dist/application/ports/inbound/IServerStatusUseCase.js.map +1 -0
  25. package/dist/application/ports/inbound/IWorldManagementUseCase.d.ts +97 -0
  26. package/dist/application/ports/inbound/IWorldManagementUseCase.d.ts.map +1 -0
  27. package/dist/application/ports/inbound/IWorldManagementUseCase.js +2 -0
  28. package/dist/application/ports/inbound/IWorldManagementUseCase.js.map +1 -0
  29. package/dist/application/ports/inbound/index.d.ts +7 -0
  30. package/dist/application/ports/inbound/index.d.ts.map +1 -0
  31. package/dist/application/ports/inbound/index.js +2 -0
  32. package/dist/application/ports/inbound/index.js.map +1 -0
  33. package/dist/application/ports/index.d.ts +3 -0
  34. package/dist/application/ports/index.d.ts.map +1 -0
  35. package/dist/application/ports/index.js +2 -0
  36. package/dist/application/ports/index.js.map +1 -0
  37. package/dist/application/ports/outbound/IDocProvider.d.ts +73 -0
  38. package/dist/application/ports/outbound/IDocProvider.d.ts.map +1 -0
  39. package/dist/application/ports/outbound/IDocProvider.js +2 -0
  40. package/dist/application/ports/outbound/IDocProvider.js.map +1 -0
  41. package/dist/application/ports/outbound/IModSourcePort.d.ts +71 -0
  42. package/dist/application/ports/outbound/IModSourcePort.d.ts.map +1 -0
  43. package/dist/application/ports/outbound/IModSourcePort.js +19 -0
  44. package/dist/application/ports/outbound/IModSourcePort.js.map +1 -0
  45. package/dist/application/ports/outbound/IPromptPort.d.ts +148 -0
  46. package/dist/application/ports/outbound/IPromptPort.d.ts.map +1 -0
  47. package/dist/application/ports/outbound/IPromptPort.js +2 -0
  48. package/dist/application/ports/outbound/IPromptPort.js.map +1 -0
  49. package/dist/application/ports/outbound/IServerRepository.d.ts +54 -0
  50. package/dist/application/ports/outbound/IServerRepository.d.ts.map +1 -0
  51. package/dist/application/ports/outbound/IServerRepository.js +2 -0
  52. package/dist/application/ports/outbound/IServerRepository.js.map +1 -0
  53. package/dist/application/ports/outbound/IServiceManagerPort.d.ts +115 -0
  54. package/dist/application/ports/outbound/IServiceManagerPort.d.ts.map +1 -0
  55. package/dist/application/ports/outbound/IServiceManagerPort.js +2 -0
  56. package/dist/application/ports/outbound/IServiceManagerPort.js.map +1 -0
  57. package/dist/application/ports/outbound/IShellPort.d.ts +114 -0
  58. package/dist/application/ports/outbound/IShellPort.d.ts.map +1 -0
  59. package/dist/application/ports/outbound/IShellPort.js +2 -0
  60. package/dist/application/ports/outbound/IShellPort.js.map +1 -0
  61. package/dist/application/ports/outbound/IUserRepository.d.ts +42 -0
  62. package/dist/application/ports/outbound/IUserRepository.d.ts.map +1 -0
  63. package/dist/application/ports/outbound/IUserRepository.js +2 -0
  64. package/dist/application/ports/outbound/IUserRepository.js.map +1 -0
  65. package/dist/application/ports/outbound/IWorldRepository.d.ts +90 -0
  66. package/dist/application/ports/outbound/IWorldRepository.d.ts.map +1 -0
  67. package/dist/application/ports/outbound/IWorldRepository.js +2 -0
  68. package/dist/application/ports/outbound/IWorldRepository.js.map +1 -0
  69. package/dist/application/ports/outbound/index.d.ts +9 -0
  70. package/dist/application/ports/outbound/index.d.ts.map +1 -0
  71. package/dist/application/ports/outbound/index.js +2 -0
  72. package/dist/application/ports/outbound/index.js.map +1 -0
  73. package/dist/application/use-cases/BackupUseCase.d.ts +35 -0
  74. package/dist/application/use-cases/BackupUseCase.d.ts.map +1 -0
  75. package/dist/application/use-cases/BackupUseCase.js +222 -0
  76. package/dist/application/use-cases/BackupUseCase.js.map +1 -0
  77. package/dist/application/use-cases/CreateServerUseCase.d.ts +22 -0
  78. package/dist/application/use-cases/CreateServerUseCase.d.ts.map +1 -0
  79. package/dist/application/use-cases/CreateServerUseCase.js +144 -0
  80. package/dist/application/use-cases/CreateServerUseCase.js.map +1 -0
  81. package/dist/application/use-cases/DeleteServerUseCase.d.ts +24 -0
  82. package/dist/application/use-cases/DeleteServerUseCase.d.ts.map +1 -0
  83. package/dist/application/use-cases/DeleteServerUseCase.js +108 -0
  84. package/dist/application/use-cases/DeleteServerUseCase.js.map +1 -0
  85. package/dist/application/use-cases/PlayerLookupUseCase.d.ts +23 -0
  86. package/dist/application/use-cases/PlayerLookupUseCase.d.ts.map +1 -0
  87. package/dist/application/use-cases/PlayerLookupUseCase.js +130 -0
  88. package/dist/application/use-cases/PlayerLookupUseCase.js.map +1 -0
  89. package/dist/application/use-cases/ServerStatusUseCase.d.ts +30 -0
  90. package/dist/application/use-cases/ServerStatusUseCase.d.ts.map +1 -0
  91. package/dist/application/use-cases/ServerStatusUseCase.js +117 -0
  92. package/dist/application/use-cases/ServerStatusUseCase.js.map +1 -0
  93. package/dist/application/use-cases/WorldManagementUseCase.d.ts +50 -0
  94. package/dist/application/use-cases/WorldManagementUseCase.d.ts.map +1 -0
  95. package/dist/application/use-cases/WorldManagementUseCase.js +571 -0
  96. package/dist/application/use-cases/WorldManagementUseCase.js.map +1 -0
  97. package/dist/application/use-cases/index.d.ts +7 -0
  98. package/dist/application/use-cases/index.d.ts.map +1 -0
  99. package/dist/application/use-cases/index.js +7 -0
  100. package/dist/application/use-cases/index.js.map +1 -0
  101. package/dist/docker/index.d.ts +125 -0
  102. package/dist/docker/index.d.ts.map +1 -0
  103. package/dist/docker/index.js +557 -0
  104. package/dist/docker/index.js.map +1 -0
  105. package/dist/domain/entities/Server.d.ts +77 -0
  106. package/dist/domain/entities/Server.d.ts.map +1 -0
  107. package/dist/domain/entities/Server.js +138 -0
  108. package/dist/domain/entities/Server.js.map +1 -0
  109. package/dist/domain/entities/User.d.ts +77 -0
  110. package/dist/domain/entities/User.d.ts.map +1 -0
  111. package/dist/domain/entities/User.js +121 -0
  112. package/dist/domain/entities/User.js.map +1 -0
  113. package/dist/domain/entities/World.d.ts +76 -0
  114. package/dist/domain/entities/World.d.ts.map +1 -0
  115. package/dist/domain/entities/World.js +141 -0
  116. package/dist/domain/entities/World.js.map +1 -0
  117. package/dist/domain/entities/index.d.ts +4 -0
  118. package/dist/domain/entities/index.d.ts.map +1 -0
  119. package/dist/domain/entities/index.js +4 -0
  120. package/dist/domain/entities/index.js.map +1 -0
  121. package/dist/domain/index.d.ts +3 -0
  122. package/dist/domain/index.d.ts.map +1 -0
  123. package/dist/domain/index.js +7 -0
  124. package/dist/domain/index.js.map +1 -0
  125. package/dist/domain/mod/ModDependency.d.ts +18 -0
  126. package/dist/domain/mod/ModDependency.d.ts.map +1 -0
  127. package/dist/domain/mod/ModDependency.js +5 -0
  128. package/dist/domain/mod/ModDependency.js.map +1 -0
  129. package/dist/domain/mod/ModFile.d.ts +27 -0
  130. package/dist/domain/mod/ModFile.d.ts.map +1 -0
  131. package/dist/domain/mod/ModFile.js +5 -0
  132. package/dist/domain/mod/ModFile.js.map +1 -0
  133. package/dist/domain/mod/ModProject.d.ts +36 -0
  134. package/dist/domain/mod/ModProject.d.ts.map +1 -0
  135. package/dist/domain/mod/ModProject.js +5 -0
  136. package/dist/domain/mod/ModProject.js.map +1 -0
  137. package/dist/domain/mod/ModSearchResult.d.ts +18 -0
  138. package/dist/domain/mod/ModSearchResult.d.ts.map +1 -0
  139. package/dist/domain/mod/ModSearchResult.js +5 -0
  140. package/dist/domain/mod/ModSearchResult.js.map +1 -0
  141. package/dist/domain/mod/ModVersion.d.ts +36 -0
  142. package/dist/domain/mod/ModVersion.d.ts.map +1 -0
  143. package/dist/domain/mod/ModVersion.js +5 -0
  144. package/dist/domain/mod/ModVersion.js.map +1 -0
  145. package/dist/domain/mod/index.d.ts +11 -0
  146. package/dist/domain/mod/index.d.ts.map +1 -0
  147. package/dist/domain/mod/index.js +6 -0
  148. package/dist/domain/mod/index.js.map +1 -0
  149. package/dist/domain/mod/types.d.ts +43 -0
  150. package/dist/domain/mod/types.d.ts.map +1 -0
  151. package/dist/domain/mod/types.js +6 -0
  152. package/dist/domain/mod/types.js.map +1 -0
  153. package/dist/domain/value-objects/McVersion.d.ts +35 -0
  154. package/dist/domain/value-objects/McVersion.d.ts.map +1 -0
  155. package/dist/domain/value-objects/McVersion.js +117 -0
  156. package/dist/domain/value-objects/McVersion.js.map +1 -0
  157. package/dist/domain/value-objects/Memory.d.ts +37 -0
  158. package/dist/domain/value-objects/Memory.d.ts.map +1 -0
  159. package/dist/domain/value-objects/Memory.js +107 -0
  160. package/dist/domain/value-objects/Memory.js.map +1 -0
  161. package/dist/domain/value-objects/ProcessInfo.d.ts +99 -0
  162. package/dist/domain/value-objects/ProcessInfo.d.ts.map +1 -0
  163. package/dist/domain/value-objects/ProcessInfo.js +171 -0
  164. package/dist/domain/value-objects/ProcessInfo.js.map +1 -0
  165. package/dist/domain/value-objects/Role.d.ts +41 -0
  166. package/dist/domain/value-objects/Role.d.ts.map +1 -0
  167. package/dist/domain/value-objects/Role.js +66 -0
  168. package/dist/domain/value-objects/Role.js.map +1 -0
  169. package/dist/domain/value-objects/ServerName.d.ts +21 -0
  170. package/dist/domain/value-objects/ServerName.d.ts.map +1 -0
  171. package/dist/domain/value-objects/ServerName.js +58 -0
  172. package/dist/domain/value-objects/ServerName.js.map +1 -0
  173. package/dist/domain/value-objects/ServerType.d.ts +40 -0
  174. package/dist/domain/value-objects/ServerType.d.ts.map +1 -0
  175. package/dist/domain/value-objects/ServerType.js +136 -0
  176. package/dist/domain/value-objects/ServerType.js.map +1 -0
  177. package/dist/domain/value-objects/ServiceStatus.d.ts +64 -0
  178. package/dist/domain/value-objects/ServiceStatus.d.ts.map +1 -0
  179. package/dist/domain/value-objects/ServiceStatus.js +99 -0
  180. package/dist/domain/value-objects/ServiceStatus.js.map +1 -0
  181. package/dist/domain/value-objects/UserId.d.ts +21 -0
  182. package/dist/domain/value-objects/UserId.d.ts.map +1 -0
  183. package/dist/domain/value-objects/UserId.js +43 -0
  184. package/dist/domain/value-objects/UserId.js.map +1 -0
  185. package/dist/domain/value-objects/Username.d.ts +16 -0
  186. package/dist/domain/value-objects/Username.d.ts.map +1 -0
  187. package/dist/domain/value-objects/Username.js +46 -0
  188. package/dist/domain/value-objects/Username.js.map +1 -0
  189. package/dist/domain/value-objects/WorldOptions.d.ts +49 -0
  190. package/dist/domain/value-objects/WorldOptions.d.ts.map +1 -0
  191. package/dist/domain/value-objects/WorldOptions.js +149 -0
  192. package/dist/domain/value-objects/WorldOptions.js.map +1 -0
  193. package/dist/domain/value-objects/index.d.ts +11 -0
  194. package/dist/domain/value-objects/index.d.ts.map +1 -0
  195. package/dist/domain/value-objects/index.js +13 -0
  196. package/dist/domain/value-objects/index.js.map +1 -0
  197. package/dist/index.d.ts +9 -0
  198. package/dist/index.d.ts.map +1 -0
  199. package/dist/index.js +21 -0
  200. package/dist/index.js.map +1 -0
  201. package/dist/infrastructure/adapters/ApiPromptAdapter.d.ts +115 -0
  202. package/dist/infrastructure/adapters/ApiPromptAdapter.d.ts.map +1 -0
  203. package/dist/infrastructure/adapters/ApiPromptAdapter.js +268 -0
  204. package/dist/infrastructure/adapters/ApiPromptAdapter.js.map +1 -0
  205. package/dist/infrastructure/adapters/DocsAdapter.d.ts +45 -0
  206. package/dist/infrastructure/adapters/DocsAdapter.d.ts.map +1 -0
  207. package/dist/infrastructure/adapters/DocsAdapter.js +490 -0
  208. package/dist/infrastructure/adapters/DocsAdapter.js.map +1 -0
  209. package/dist/infrastructure/adapters/ServerRepository.d.ts +49 -0
  210. package/dist/infrastructure/adapters/ServerRepository.d.ts.map +1 -0
  211. package/dist/infrastructure/adapters/ServerRepository.js +206 -0
  212. package/dist/infrastructure/adapters/ServerRepository.js.map +1 -0
  213. package/dist/infrastructure/adapters/ShellAdapter.d.ts +41 -0
  214. package/dist/infrastructure/adapters/ShellAdapter.d.ts.map +1 -0
  215. package/dist/infrastructure/adapters/ShellAdapter.js +198 -0
  216. package/dist/infrastructure/adapters/ShellAdapter.js.map +1 -0
  217. package/dist/infrastructure/adapters/SqliteUserRepository.d.ts +70 -0
  218. package/dist/infrastructure/adapters/SqliteUserRepository.d.ts.map +1 -0
  219. package/dist/infrastructure/adapters/SqliteUserRepository.js +149 -0
  220. package/dist/infrastructure/adapters/SqliteUserRepository.js.map +1 -0
  221. package/dist/infrastructure/adapters/WorldRepository.d.ts +67 -0
  222. package/dist/infrastructure/adapters/WorldRepository.d.ts.map +1 -0
  223. package/dist/infrastructure/adapters/WorldRepository.js +283 -0
  224. package/dist/infrastructure/adapters/WorldRepository.js.map +1 -0
  225. package/dist/infrastructure/adapters/YamlUserRepository.d.ts +67 -0
  226. package/dist/infrastructure/adapters/YamlUserRepository.d.ts.map +1 -0
  227. package/dist/infrastructure/adapters/YamlUserRepository.js +161 -0
  228. package/dist/infrastructure/adapters/YamlUserRepository.js.map +1 -0
  229. package/dist/infrastructure/adapters/index.d.ts +12 -0
  230. package/dist/infrastructure/adapters/index.d.ts.map +1 -0
  231. package/dist/infrastructure/adapters/index.js +12 -0
  232. package/dist/infrastructure/adapters/index.js.map +1 -0
  233. package/dist/infrastructure/config/Pm2EcosystemConfig.d.ts +192 -0
  234. package/dist/infrastructure/config/Pm2EcosystemConfig.d.ts.map +1 -0
  235. package/dist/infrastructure/config/Pm2EcosystemConfig.js +48 -0
  236. package/dist/infrastructure/config/Pm2EcosystemConfig.js.map +1 -0
  237. package/dist/infrastructure/config/index.d.ts +6 -0
  238. package/dist/infrastructure/config/index.d.ts.map +1 -0
  239. package/dist/infrastructure/config/index.js +6 -0
  240. package/dist/infrastructure/config/index.js.map +1 -0
  241. package/dist/infrastructure/factories/ModSourceFactory.d.ts +73 -0
  242. package/dist/infrastructure/factories/ModSourceFactory.d.ts.map +1 -0
  243. package/dist/infrastructure/factories/ModSourceFactory.js +98 -0
  244. package/dist/infrastructure/factories/ModSourceFactory.js.map +1 -0
  245. package/dist/infrastructure/factories/index.d.ts +5 -0
  246. package/dist/infrastructure/factories/index.d.ts.map +1 -0
  247. package/dist/infrastructure/factories/index.js +5 -0
  248. package/dist/infrastructure/factories/index.js.map +1 -0
  249. package/dist/infrastructure/index.d.ts +7 -0
  250. package/dist/infrastructure/index.d.ts.map +1 -0
  251. package/dist/infrastructure/index.js +7 -0
  252. package/dist/infrastructure/index.js.map +1 -0
  253. package/dist/types/index.d.ts +151 -0
  254. package/dist/types/index.d.ts.map +1 -0
  255. package/dist/types/index.js +2 -0
  256. package/dist/types/index.js.map +1 -0
  257. package/dist/utils/index.d.ts +81 -0
  258. package/dist/utils/index.d.ts.map +1 -0
  259. package/dist/utils/index.js +200 -0
  260. package/dist/utils/index.js.map +1 -0
  261. package/package.json +10 -2
@@ -0,0 +1,125 @@
1
+ import type { ContainerStatus, HealthStatus, ServerInfo, RouterInfo, PlatformStatus, ContainerStats, PlayerListResult, DetailedServerInfo, RouterDetailInfo } from '../types/index.js';
2
+ /**
3
+ * Execute a command and return stdout
4
+ * Uses spawnSync to properly handle arguments with special characters
5
+ */
6
+ export declare function execCommand(command: string, args: string[]): string;
7
+ /**
8
+ * Check if Docker is available
9
+ */
10
+ export declare function checkDocker(): boolean;
11
+ /**
12
+ * Check if Docker Compose is available
13
+ */
14
+ export declare function checkDockerCompose(): boolean;
15
+ /**
16
+ * Get container status
17
+ */
18
+ export declare function getContainerStatus(container: string): ContainerStatus;
19
+ /**
20
+ * Get container health status
21
+ */
22
+ export declare function getContainerHealth(container: string): HealthStatus;
23
+ /**
24
+ * Check mc-router health via management API
25
+ * mc-router uses distroless image, so Docker healthcheck doesn't work
26
+ * Instead, we check the management API on localhost:25580
27
+ */
28
+ export declare function getRouterHealthViaApi(): HealthStatus;
29
+ /**
30
+ * Check if container exists
31
+ */
32
+ export declare function containerExists(container: string): boolean;
33
+ /**
34
+ * Get container's hostname label (mc-router.host)
35
+ */
36
+ export declare function getContainerHostname(container: string): string;
37
+ /**
38
+ * Get all minecraft server containers (mc-* except mc-router)
39
+ */
40
+ export declare function getMcContainers(): string[];
41
+ /**
42
+ * Get running minecraft server containers
43
+ */
44
+ export declare function getRunningMcContainers(): string[];
45
+ /**
46
+ * Get server info for a container
47
+ */
48
+ export declare function getServerInfo(container: string): ServerInfo;
49
+ /**
50
+ * Get router info
51
+ */
52
+ export declare function getRouterInfo(): RouterInfo;
53
+ /**
54
+ * Get avahi-daemon status
55
+ */
56
+ export declare function getAvahiStatus(): string;
57
+ /**
58
+ * Get full platform status
59
+ */
60
+ export declare function getPlatformStatus(): PlatformStatus;
61
+ /**
62
+ * Start a container
63
+ */
64
+ export declare function startContainer(container: string): boolean;
65
+ /**
66
+ * Stop a container
67
+ */
68
+ export declare function stopContainer(container: string): boolean;
69
+ /**
70
+ * Get container logs
71
+ */
72
+ export declare function getContainerLogs(container: string, lines?: number): string;
73
+ /**
74
+ * Execute a command asynchronously and return result
75
+ * For docker commands that need async/await pattern
76
+ */
77
+ export declare function execCommandAsync(command: string, args: string[]): Promise<{
78
+ code: number;
79
+ stdout: string;
80
+ stderr: string;
81
+ }>;
82
+ /**
83
+ * Execute shell script with environment variables
84
+ */
85
+ export declare function execScript(scriptPath: string, args: string[], env?: Record<string, string>): Promise<{
86
+ code: number;
87
+ stdout: string;
88
+ stderr: string;
89
+ }>;
90
+ /**
91
+ * Execute shell script with inherited stdio (interactive)
92
+ */
93
+ export declare function execScriptInteractive(scriptPath: string, args: string[], env?: Record<string, string>): Promise<number>;
94
+ /**
95
+ * Get container resource stats (memory, CPU)
96
+ */
97
+ export declare function getContainerStats(container: string): ContainerStats | null;
98
+ /**
99
+ * Get container uptime (time since start)
100
+ */
101
+ export declare function getContainerUptime(container: string): {
102
+ uptime: string;
103
+ seconds: number;
104
+ } | null;
105
+ /**
106
+ * Get online players via RCON
107
+ */
108
+ export declare function getOnlinePlayers(container: string): Promise<PlayerListResult | null>;
109
+ /**
110
+ * Get detailed server info
111
+ */
112
+ export declare function getDetailedServerInfo(container: string, configEnv?: Record<string, string>): DetailedServerInfo;
113
+ /**
114
+ * Get detailed server info with players (async)
115
+ */
116
+ export declare function getDetailedServerInfoWithPlayers(container: string, configEnv?: Record<string, string>): Promise<DetailedServerInfo>;
117
+ /**
118
+ * Get router detailed info
119
+ */
120
+ export declare function getRouterDetailInfo(): RouterDetailInfo;
121
+ /**
122
+ * Format bytes to human readable string
123
+ */
124
+ export declare function formatBytes(bytes: number): string;
125
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/docker/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,UAAU,EACV,UAAU,EACV,cAAc,EACd,cAAc,EACd,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C,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC,OAAO,CAAC,kBAAkB,CAAC,CAY7B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,CAqCtD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMjD"}
@@ -0,0 +1,557 @@
1
+ import { spawn, execSync, spawnSync } from 'node:child_process';
2
+ /**
3
+ * Execute a command and return stdout
4
+ * Uses spawnSync to properly handle arguments with special characters
5
+ */
6
+ export function execCommand(command, args) {
7
+ try {
8
+ const result = spawnSync(command, args, {
9
+ encoding: 'utf-8',
10
+ stdio: ['pipe', 'pipe', 'pipe'],
11
+ });
12
+ if (result.error || result.status !== 0) {
13
+ return '';
14
+ }
15
+ return (result.stdout ?? '').trim();
16
+ }
17
+ catch {
18
+ return '';
19
+ }
20
+ }
21
+ /**
22
+ * Check if Docker is available
23
+ */
24
+ export function checkDocker() {
25
+ try {
26
+ execSync('docker info', { stdio: 'pipe' });
27
+ return true;
28
+ }
29
+ catch {
30
+ return false;
31
+ }
32
+ }
33
+ /**
34
+ * Check if Docker Compose is available
35
+ */
36
+ export function checkDockerCompose() {
37
+ try {
38
+ execSync('docker compose version', { stdio: 'pipe' });
39
+ return true;
40
+ }
41
+ catch {
42
+ return false;
43
+ }
44
+ }
45
+ /**
46
+ * Get container status
47
+ */
48
+ export function getContainerStatus(container) {
49
+ const result = execCommand('docker', [
50
+ 'inspect',
51
+ '--format',
52
+ '{{.State.Status}}',
53
+ container,
54
+ ]);
55
+ if (!result)
56
+ return 'not_found';
57
+ return result;
58
+ }
59
+ /**
60
+ * Get container health status
61
+ */
62
+ export function getContainerHealth(container) {
63
+ const result = execCommand('docker', [
64
+ 'inspect',
65
+ '--format',
66
+ '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}',
67
+ container,
68
+ ]);
69
+ if (!result)
70
+ return 'unknown';
71
+ return result;
72
+ }
73
+ /**
74
+ * Check mc-router health via management API
75
+ * mc-router uses distroless image, so Docker healthcheck doesn't work
76
+ * Instead, we check the management API on localhost:25580
77
+ */
78
+ export function getRouterHealthViaApi() {
79
+ try {
80
+ // Check if mc-router is running first
81
+ const status = getContainerStatus('mc-router');
82
+ if (status !== 'running') {
83
+ return 'unknown';
84
+ }
85
+ // Try to connect to management API
86
+ const result = spawnSync('curl', ['-s', '-o', '/dev/null', '-w', '%{http_code}', 'http://127.0.0.1:25580/routes'], {
87
+ encoding: 'utf-8',
88
+ timeout: 3000,
89
+ stdio: ['pipe', 'pipe', 'pipe'],
90
+ });
91
+ if (result.error || result.status !== 0) {
92
+ // curl failed, try wget
93
+ const wgetResult = spawnSync('wget', ['-q', '-O', '/dev/null', 'http://127.0.0.1:25580/routes'], {
94
+ encoding: 'utf-8',
95
+ timeout: 3000,
96
+ stdio: ['pipe', 'pipe', 'pipe'],
97
+ });
98
+ if (wgetResult.error || wgetResult.status !== 0) {
99
+ return 'unhealthy';
100
+ }
101
+ return 'healthy';
102
+ }
103
+ const httpCode = (result.stdout ?? '').trim();
104
+ if (httpCode === '200') {
105
+ return 'healthy';
106
+ }
107
+ return 'unhealthy';
108
+ }
109
+ catch {
110
+ return 'unknown';
111
+ }
112
+ }
113
+ /**
114
+ * Check if container exists
115
+ */
116
+ export function containerExists(container) {
117
+ try {
118
+ execSync(`docker inspect ${container}`, { stdio: 'pipe' });
119
+ return true;
120
+ }
121
+ catch {
122
+ return false;
123
+ }
124
+ }
125
+ /**
126
+ * Get container's hostname label (mc-router.host)
127
+ */
128
+ export function getContainerHostname(container) {
129
+ const result = execCommand('docker', [
130
+ 'inspect',
131
+ '--format',
132
+ '{{index .Config.Labels "mc-router.host"}}',
133
+ container,
134
+ ]);
135
+ return result || '-';
136
+ }
137
+ /**
138
+ * Get all minecraft server containers (mc-* except mc-router)
139
+ */
140
+ export function getMcContainers() {
141
+ const result = execCommand('docker', [
142
+ 'ps',
143
+ '-a',
144
+ '--filter',
145
+ 'name=mc-',
146
+ '--format',
147
+ '{{.Names}}',
148
+ ]);
149
+ if (!result)
150
+ return [];
151
+ return result
152
+ .split('\n')
153
+ .filter(name => name && name !== 'mc-router')
154
+ .sort();
155
+ }
156
+ /**
157
+ * Get running minecraft server containers
158
+ */
159
+ export function getRunningMcContainers() {
160
+ const result = execCommand('docker', [
161
+ 'ps',
162
+ '--filter',
163
+ 'name=mc-',
164
+ '--filter',
165
+ 'status=running',
166
+ '--format',
167
+ '{{.Names}}',
168
+ ]);
169
+ if (!result)
170
+ return [];
171
+ return result
172
+ .split('\n')
173
+ .filter(name => name && name !== 'mc-router')
174
+ .sort();
175
+ }
176
+ /**
177
+ * Get server info for a container
178
+ */
179
+ export function getServerInfo(container) {
180
+ const serverName = container.replace(/^mc-/, '');
181
+ return {
182
+ name: serverName,
183
+ container,
184
+ status: getContainerStatus(container),
185
+ health: getContainerHealth(container),
186
+ hostname: getContainerHostname(container),
187
+ };
188
+ }
189
+ /**
190
+ * Get router info
191
+ */
192
+ export function getRouterInfo() {
193
+ return {
194
+ name: 'mc-router',
195
+ status: getContainerStatus('mc-router'),
196
+ health: getRouterHealthViaApi(),
197
+ port: 25565,
198
+ };
199
+ }
200
+ /**
201
+ * Get avahi-daemon status
202
+ */
203
+ export function getAvahiStatus() {
204
+ // Try systemctl first
205
+ try {
206
+ execSync('systemctl is-active --quiet avahi-daemon', { stdio: 'pipe' });
207
+ return 'running';
208
+ }
209
+ catch {
210
+ // Not running via systemctl
211
+ }
212
+ // Try OpenRC
213
+ try {
214
+ execSync('rc-service avahi-daemon status', { stdio: 'pipe' });
215
+ return 'running';
216
+ }
217
+ catch {
218
+ // Not running via OpenRC
219
+ }
220
+ // Check if installed
221
+ try {
222
+ execSync('which avahi-daemon', { stdio: 'pipe' });
223
+ return 'installed (not running)';
224
+ }
225
+ catch {
226
+ return 'not installed';
227
+ }
228
+ }
229
+ /**
230
+ * Get full platform status
231
+ */
232
+ export function getPlatformStatus() {
233
+ const containers = getMcContainers();
234
+ return {
235
+ router: getRouterInfo(),
236
+ avahi_daemon: {
237
+ name: 'avahi-daemon',
238
+ status: getAvahiStatus(),
239
+ type: 'system',
240
+ },
241
+ servers: containers.map(getServerInfo),
242
+ };
243
+ }
244
+ /**
245
+ * Start a container
246
+ */
247
+ export function startContainer(container) {
248
+ try {
249
+ execSync(`docker start ${container}`, { stdio: 'pipe' });
250
+ return true;
251
+ }
252
+ catch {
253
+ return false;
254
+ }
255
+ }
256
+ /**
257
+ * Stop a container
258
+ */
259
+ export function stopContainer(container) {
260
+ try {
261
+ execSync(`docker stop ${container}`, { stdio: 'pipe' });
262
+ return true;
263
+ }
264
+ catch {
265
+ return false;
266
+ }
267
+ }
268
+ /**
269
+ * Get container logs
270
+ */
271
+ export function getContainerLogs(container, lines = 50) {
272
+ return execCommand('docker', ['logs', '--tail', String(lines), container]);
273
+ }
274
+ /**
275
+ * Execute a command asynchronously and return result
276
+ * For docker commands that need async/await pattern
277
+ */
278
+ export function execCommandAsync(command, args) {
279
+ return new Promise((resolve) => {
280
+ const child = spawn(command, args, {
281
+ stdio: ['pipe', 'pipe', 'pipe'],
282
+ });
283
+ let stdout = '';
284
+ let stderr = '';
285
+ child.stdout?.on('data', (data) => {
286
+ stdout += data.toString();
287
+ });
288
+ child.stderr?.on('data', (data) => {
289
+ stderr += data.toString();
290
+ });
291
+ child.on('close', (code) => {
292
+ resolve({ code: code ?? 1, stdout: stdout.trim(), stderr: stderr.trim() });
293
+ });
294
+ child.on('error', () => {
295
+ resolve({ code: 1, stdout: '', stderr: 'Failed to execute command' });
296
+ });
297
+ });
298
+ }
299
+ /**
300
+ * Execute shell script with environment variables
301
+ */
302
+ export function execScript(scriptPath, args, env = {}) {
303
+ return new Promise((resolve) => {
304
+ const child = spawn('bash', [scriptPath, ...args], {
305
+ env: { ...process.env, ...env },
306
+ stdio: ['inherit', 'pipe', 'pipe'],
307
+ });
308
+ let stdout = '';
309
+ let stderr = '';
310
+ child.stdout?.on('data', (data) => {
311
+ stdout += data.toString();
312
+ process.stdout.write(data);
313
+ });
314
+ child.stderr?.on('data', (data) => {
315
+ stderr += data.toString();
316
+ process.stderr.write(data);
317
+ });
318
+ child.on('close', (code) => {
319
+ resolve({ code: code ?? 1, stdout, stderr });
320
+ });
321
+ child.on('error', () => {
322
+ resolve({ code: 1, stdout, stderr: 'Failed to execute script' });
323
+ });
324
+ });
325
+ }
326
+ /**
327
+ * Execute shell script with inherited stdio (interactive)
328
+ */
329
+ export function execScriptInteractive(scriptPath, args, env = {}) {
330
+ return new Promise((resolve) => {
331
+ const child = spawn('bash', [scriptPath, ...args], {
332
+ env: { ...process.env, ...env },
333
+ stdio: 'inherit',
334
+ });
335
+ child.on('close', (code) => {
336
+ resolve(code ?? 1);
337
+ });
338
+ child.on('error', () => {
339
+ resolve(1);
340
+ });
341
+ });
342
+ }
343
+ /**
344
+ * Get container resource stats (memory, CPU)
345
+ */
346
+ export function getContainerStats(container) {
347
+ // docker stats --no-stream --format "{{.MemUsage}},{{.CPUPerc}}"
348
+ // Example output: "2.1GiB / 4GiB,15.23%"
349
+ const result = execCommand('docker', [
350
+ 'stats',
351
+ '--no-stream',
352
+ '--format',
353
+ '{{.MemUsage}},{{.CPUPerc}}',
354
+ container,
355
+ ]);
356
+ if (!result)
357
+ return null;
358
+ try {
359
+ const [memUsage, cpuPerc] = result.split(',');
360
+ if (!memUsage || !cpuPerc)
361
+ return null;
362
+ // Parse memory: "2.1GiB / 4GiB" or "512MiB / 4GiB"
363
+ const memParts = memUsage.split('/').map((s) => s.trim());
364
+ if (memParts.length !== 2)
365
+ return null;
366
+ const parseMemory = (mem) => {
367
+ const match = mem.match(/^([\d.]+)\s*(B|KiB|MiB|GiB|TiB|KB|MB|GB|TB)?$/i);
368
+ if (!match || !match[1])
369
+ return 0;
370
+ const value = parseFloat(match[1]);
371
+ const unit = (match[2] ?? 'B').toUpperCase();
372
+ const multipliers = {
373
+ B: 1,
374
+ KIB: 1024,
375
+ MIB: 1024 ** 2,
376
+ GIB: 1024 ** 3,
377
+ TIB: 1024 ** 4,
378
+ KB: 1000,
379
+ MB: 1000 ** 2,
380
+ GB: 1000 ** 3,
381
+ TB: 1000 ** 4,
382
+ };
383
+ return value * (multipliers[unit] || 1);
384
+ };
385
+ const memoryUsage = parseMemory(memParts[0]);
386
+ const memoryLimit = parseMemory(memParts[1]);
387
+ const memoryPercent = memoryLimit > 0 ? (memoryUsage / memoryLimit) * 100 : 0;
388
+ // Parse CPU: "15.23%" or "0.00%"
389
+ const cpuPercent = parseFloat(cpuPerc.replace('%', '')) || 0;
390
+ return {
391
+ memoryUsage,
392
+ memoryLimit,
393
+ memoryPercent,
394
+ cpuPercent,
395
+ };
396
+ }
397
+ catch {
398
+ return null;
399
+ }
400
+ }
401
+ /**
402
+ * Get container uptime (time since start)
403
+ */
404
+ export function getContainerUptime(container) {
405
+ // docker inspect --format '{{.State.StartedAt}}'
406
+ const result = execCommand('docker', [
407
+ 'inspect',
408
+ '--format',
409
+ '{{.State.StartedAt}}',
410
+ container,
411
+ ]);
412
+ if (!result || result === '0001-01-01T00:00:00Z')
413
+ return null;
414
+ try {
415
+ const startedAt = new Date(result);
416
+ const now = new Date();
417
+ const diffMs = now.getTime() - startedAt.getTime();
418
+ const diffSeconds = Math.floor(diffMs / 1000);
419
+ // Format uptime
420
+ const days = Math.floor(diffSeconds / 86400);
421
+ const hours = Math.floor((diffSeconds % 86400) / 3600);
422
+ const minutes = Math.floor((diffSeconds % 3600) / 60);
423
+ let uptime = '';
424
+ if (days > 0)
425
+ uptime += `${days}d `;
426
+ if (hours > 0 || days > 0)
427
+ uptime += `${hours}h `;
428
+ uptime += `${minutes}m`;
429
+ return { uptime: uptime.trim(), seconds: diffSeconds };
430
+ }
431
+ catch {
432
+ return null;
433
+ }
434
+ }
435
+ /**
436
+ * Get online players via RCON
437
+ */
438
+ export async function getOnlinePlayers(container) {
439
+ try {
440
+ const result = execSync(`docker exec ${container} rcon-cli list`, {
441
+ encoding: 'utf-8',
442
+ timeout: 5000,
443
+ stdio: ['pipe', 'pipe', 'pipe'],
444
+ });
445
+ // Parse: "There are 3 of a max of 20 players online: Notch, Steve, Alex"
446
+ // Or: "There are 0 of a max of 20 players online:"
447
+ const countMatch = result.match(/There are (\d+)(?:\s+of a max of\s+|\/)(\d+) players? online/i);
448
+ if (!countMatch || !countMatch[1] || !countMatch[2])
449
+ return null;
450
+ const online = parseInt(countMatch[1], 10);
451
+ const max = parseInt(countMatch[2], 10);
452
+ // Extract player names after the colon
453
+ const playersMatch = result.match(/:\s*(.*)$/);
454
+ let players = [];
455
+ if (playersMatch && playersMatch[1]) {
456
+ players = playersMatch[1]
457
+ .split(',')
458
+ .map((s) => s.trim())
459
+ .filter(Boolean);
460
+ }
461
+ return { online, max, players };
462
+ }
463
+ catch {
464
+ return null;
465
+ }
466
+ }
467
+ /**
468
+ * Get detailed server info
469
+ */
470
+ export function getDetailedServerInfo(container, configEnv) {
471
+ const basic = getServerInfo(container);
472
+ const detailed = { ...basic };
473
+ // Only get extended info if container is running
474
+ if (basic.status === 'running') {
475
+ // Get stats
476
+ const stats = getContainerStats(container);
477
+ if (stats) {
478
+ detailed.stats = stats;
479
+ }
480
+ // Get uptime
481
+ const uptimeInfo = getContainerUptime(container);
482
+ if (uptimeInfo) {
483
+ detailed.uptime = uptimeInfo.uptime;
484
+ detailed.uptimeSeconds = uptimeInfo.seconds;
485
+ }
486
+ }
487
+ // Get config info if provided
488
+ if (configEnv) {
489
+ detailed.type = configEnv['TYPE'];
490
+ detailed.version = configEnv['VERSION'];
491
+ detailed.memory = configEnv['MEMORY'];
492
+ }
493
+ return detailed;
494
+ }
495
+ /**
496
+ * Get detailed server info with players (async)
497
+ */
498
+ export async function getDetailedServerInfoWithPlayers(container, configEnv) {
499
+ const detailed = getDetailedServerInfo(container, configEnv);
500
+ // Get players if running
501
+ if (detailed.status === 'running') {
502
+ const players = await getOnlinePlayers(container);
503
+ if (players) {
504
+ detailed.players = players;
505
+ }
506
+ }
507
+ return detailed;
508
+ }
509
+ /**
510
+ * Get router detailed info
511
+ */
512
+ export function getRouterDetailInfo() {
513
+ const basic = getRouterInfo();
514
+ const detailed = {
515
+ ...basic,
516
+ routes: [],
517
+ mode: '--in-docker (auto-discovery)',
518
+ };
519
+ // Get uptime
520
+ if (basic.status === 'running') {
521
+ const uptimeInfo = getContainerUptime('mc-router');
522
+ if (uptimeInfo) {
523
+ detailed.uptime = uptimeInfo.uptime;
524
+ detailed.uptimeSeconds = uptimeInfo.seconds;
525
+ }
526
+ }
527
+ // Get routes from all mc-* containers
528
+ const containers = getMcContainers();
529
+ for (const container of containers) {
530
+ const hostname = getContainerHostname(container);
531
+ if (hostname && hostname !== '-') {
532
+ // hostname might be comma-separated (e.g., "server.local,server.192.168.1.10.nip.io")
533
+ const hostnames = hostname.split(',').map((h) => h.trim());
534
+ const serverStatus = getContainerStatus(container);
535
+ for (const h of hostnames) {
536
+ detailed.routes.push({
537
+ hostname: h,
538
+ target: `${container}:25565`,
539
+ serverStatus,
540
+ });
541
+ }
542
+ }
543
+ }
544
+ return detailed;
545
+ }
546
+ /**
547
+ * Format bytes to human readable string
548
+ */
549
+ export function formatBytes(bytes) {
550
+ if (bytes === 0)
551
+ return '0 B';
552
+ const k = 1024;
553
+ const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
554
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
555
+ return `${(bytes / Math.pow(k, i)).toFixed(1)} ${sizes[i]}`;
556
+ }
557
+ //# sourceMappingURL=index.js.map