@meowpanel/api 0.1.0-alpha.11 → 1.0.0-beta.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 (297) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +40 -0
  3. package/esm/mod.d.ts +87 -1
  4. package/esm/mod.d.ts.map +1 -1
  5. package/esm/mod.js +85 -1
  6. package/esm/src/client.d.ts +248 -0
  7. package/esm/src/client.d.ts.map +1 -0
  8. package/esm/src/client.js +235 -0
  9. package/esm/src/emitter.d.ts +53 -0
  10. package/esm/src/emitter.d.ts.map +1 -0
  11. package/esm/src/emitter.js +55 -0
  12. package/esm/src/errors.d.ts +42 -0
  13. package/esm/src/errors.d.ts.map +1 -0
  14. package/esm/src/errors.js +45 -0
  15. package/esm/src/http.d.ts +157 -0
  16. package/esm/src/http.d.ts.map +1 -0
  17. package/esm/src/http.js +317 -0
  18. package/esm/src/namespace.d.ts +59 -0
  19. package/esm/src/namespace.d.ts.map +1 -0
  20. package/esm/src/namespace.js +79 -0
  21. package/esm/src/reactive.d.ts +29 -0
  22. package/esm/src/reactive.d.ts.map +1 -0
  23. package/esm/src/reactive.js +35 -0
  24. package/esm/src/resources/account.d.ts +125 -0
  25. package/esm/src/resources/account.d.ts.map +1 -0
  26. package/esm/src/resources/account.js +151 -0
  27. package/esm/src/resources/api-keys.d.ts +116 -0
  28. package/esm/src/resources/api-keys.d.ts.map +1 -0
  29. package/esm/src/resources/api-keys.js +105 -0
  30. package/esm/src/resources/auth.d.ts +57 -0
  31. package/esm/src/resources/auth.d.ts.map +1 -0
  32. package/esm/src/resources/auth.js +39 -0
  33. package/esm/src/resources/eggs.d.ts +238 -0
  34. package/esm/src/resources/eggs.d.ts.map +1 -0
  35. package/esm/src/resources/eggs.js +187 -0
  36. package/esm/src/resources/hosts.d.ts +62 -0
  37. package/esm/src/resources/hosts.d.ts.map +1 -0
  38. package/esm/src/resources/hosts.js +62 -0
  39. package/esm/src/resources/members.d.ts +138 -0
  40. package/esm/src/resources/members.d.ts.map +1 -0
  41. package/esm/src/resources/members.js +122 -0
  42. package/esm/src/resources/nodes.d.ts +397 -0
  43. package/esm/src/resources/nodes.d.ts.map +1 -0
  44. package/esm/src/resources/nodes.js +352 -0
  45. package/esm/src/resources/server-groups.d.ts +150 -0
  46. package/esm/src/resources/server-groups.d.ts.map +1 -0
  47. package/esm/src/resources/server-groups.js +111 -0
  48. package/esm/src/resources/servers/activity.d.ts +120 -0
  49. package/esm/src/resources/servers/activity.d.ts.map +1 -0
  50. package/esm/src/resources/servers/activity.js +163 -0
  51. package/esm/src/resources/servers/allocations.d.ts +125 -0
  52. package/esm/src/resources/servers/allocations.d.ts.map +1 -0
  53. package/esm/src/resources/servers/allocations.js +137 -0
  54. package/esm/src/resources/servers/connection.d.ts +108 -0
  55. package/esm/src/resources/servers/connection.d.ts.map +1 -0
  56. package/esm/src/resources/servers/connection.js +169 -0
  57. package/esm/src/resources/servers/files.d.ts +164 -0
  58. package/esm/src/resources/servers/files.d.ts.map +1 -0
  59. package/esm/src/resources/servers/files.js +281 -0
  60. package/esm/src/resources/servers/index.d.ts +126 -0
  61. package/esm/src/resources/servers/index.d.ts.map +1 -0
  62. package/esm/src/resources/servers/index.js +135 -0
  63. package/esm/src/resources/servers/profiles.d.ts +138 -0
  64. package/esm/src/resources/servers/profiles.d.ts.map +1 -0
  65. package/esm/src/resources/servers/profiles.js +177 -0
  66. package/esm/src/resources/servers/server.d.ts +136 -0
  67. package/esm/src/resources/servers/server.d.ts.map +1 -0
  68. package/esm/src/resources/servers/server.js +202 -0
  69. package/esm/src/resources/servers/sftp.d.ts +147 -0
  70. package/esm/src/resources/servers/sftp.d.ts.map +1 -0
  71. package/esm/src/resources/servers/sftp.js +153 -0
  72. package/esm/src/resources/servers/types.d.ts +199 -0
  73. package/esm/src/resources/servers/types.d.ts.map +1 -0
  74. package/esm/src/resources/servers/types.js +1 -0
  75. package/esm/src/sse.d.ts +53 -0
  76. package/esm/src/sse.d.ts.map +1 -0
  77. package/esm/src/sse.js +133 -0
  78. package/esm/src/types.d.ts +126 -0
  79. package/esm/src/types.d.ts.map +1 -0
  80. package/esm/src/types.js +21 -0
  81. package/package.json +4 -92
  82. package/script/mod.d.ts +87 -1
  83. package/script/mod.d.ts.map +1 -1
  84. package/script/mod.js +132 -3
  85. package/script/src/client.d.ts +248 -0
  86. package/script/src/client.d.ts.map +1 -0
  87. package/script/src/client.js +239 -0
  88. package/script/src/emitter.d.ts +53 -0
  89. package/script/src/emitter.d.ts.map +1 -0
  90. package/script/src/emitter.js +59 -0
  91. package/script/src/errors.d.ts +42 -0
  92. package/script/src/errors.d.ts.map +1 -0
  93. package/script/src/errors.js +49 -0
  94. package/script/src/http.d.ts +157 -0
  95. package/script/src/http.d.ts.map +1 -0
  96. package/script/src/http.js +321 -0
  97. package/script/src/namespace.d.ts +59 -0
  98. package/script/src/namespace.d.ts.map +1 -0
  99. package/script/src/namespace.js +83 -0
  100. package/script/src/reactive.d.ts +29 -0
  101. package/script/src/reactive.d.ts.map +1 -0
  102. package/script/src/reactive.js +39 -0
  103. package/script/src/resources/account.d.ts +125 -0
  104. package/script/src/resources/account.d.ts.map +1 -0
  105. package/script/src/resources/account.js +158 -0
  106. package/script/src/resources/api-keys.d.ts +116 -0
  107. package/script/src/resources/api-keys.d.ts.map +1 -0
  108. package/script/src/resources/api-keys.js +110 -0
  109. package/script/src/resources/auth.d.ts +57 -0
  110. package/script/src/resources/auth.d.ts.map +1 -0
  111. package/script/src/resources/auth.js +43 -0
  112. package/script/src/resources/eggs.d.ts +238 -0
  113. package/script/src/resources/eggs.d.ts.map +1 -0
  114. package/script/src/resources/eggs.js +193 -0
  115. package/script/src/resources/hosts.d.ts +62 -0
  116. package/script/src/resources/hosts.d.ts.map +1 -0
  117. package/script/src/resources/hosts.js +67 -0
  118. package/script/src/resources/members.d.ts +138 -0
  119. package/script/src/resources/members.d.ts.map +1 -0
  120. package/script/src/resources/members.js +127 -0
  121. package/script/src/resources/nodes.d.ts +397 -0
  122. package/script/src/resources/nodes.d.ts.map +1 -0
  123. package/script/src/resources/nodes.js +362 -0
  124. package/script/src/resources/server-groups.d.ts +150 -0
  125. package/script/src/resources/server-groups.d.ts.map +1 -0
  126. package/script/src/resources/server-groups.js +116 -0
  127. package/script/src/resources/servers/activity.d.ts +120 -0
  128. package/script/src/resources/servers/activity.d.ts.map +1 -0
  129. package/script/src/resources/servers/activity.js +170 -0
  130. package/script/src/resources/servers/allocations.d.ts +125 -0
  131. package/script/src/resources/servers/allocations.d.ts.map +1 -0
  132. package/script/src/resources/servers/allocations.js +142 -0
  133. package/script/src/resources/servers/connection.d.ts +108 -0
  134. package/script/src/resources/servers/connection.d.ts.map +1 -0
  135. package/script/src/resources/servers/connection.js +173 -0
  136. package/script/src/resources/servers/files.d.ts +164 -0
  137. package/script/src/resources/servers/files.d.ts.map +1 -0
  138. package/script/src/resources/servers/files.js +286 -0
  139. package/script/src/resources/servers/index.d.ts +126 -0
  140. package/script/src/resources/servers/index.d.ts.map +1 -0
  141. package/script/src/resources/servers/index.js +139 -0
  142. package/script/src/resources/servers/profiles.d.ts +138 -0
  143. package/script/src/resources/servers/profiles.d.ts.map +1 -0
  144. package/script/src/resources/servers/profiles.js +182 -0
  145. package/script/src/resources/servers/server.d.ts +136 -0
  146. package/script/src/resources/servers/server.d.ts.map +1 -0
  147. package/script/src/resources/servers/server.js +206 -0
  148. package/script/src/resources/servers/sftp.d.ts +147 -0
  149. package/script/src/resources/servers/sftp.d.ts.map +1 -0
  150. package/script/src/resources/servers/sftp.js +158 -0
  151. package/script/src/resources/servers/types.d.ts +199 -0
  152. package/script/src/resources/servers/types.d.ts.map +1 -0
  153. package/script/src/resources/servers/types.js +2 -0
  154. package/script/src/sse.d.ts +53 -0
  155. package/script/src/sse.d.ts.map +1 -0
  156. package/script/src/sse.js +137 -0
  157. package/script/src/types.d.ts +126 -0
  158. package/script/src/types.d.ts.map +1 -0
  159. package/script/src/types.js +25 -0
  160. package/esm/api.d.ts +0 -76
  161. package/esm/api.d.ts.map +0 -1
  162. package/esm/api.js +0 -187
  163. package/esm/components/auth.d.ts +0 -15
  164. package/esm/components/auth.d.ts.map +0 -1
  165. package/esm/components/auth.js +0 -13
  166. package/esm/components/connection/abstract.d.ts +0 -23
  167. package/esm/components/connection/abstract.d.ts.map +0 -1
  168. package/esm/components/connection/abstract.js +0 -43
  169. package/esm/components/connection/sse.d.ts +0 -20
  170. package/esm/components/connection/sse.d.ts.map +0 -1
  171. package/esm/components/connection/sse.js +0 -65
  172. package/esm/components/egg/egg.d.ts +0 -32
  173. package/esm/components/egg/egg.d.ts.map +0 -1
  174. package/esm/components/egg/egg.js +0 -70
  175. package/esm/components/group.d.ts +0 -14
  176. package/esm/components/group.d.ts.map +0 -1
  177. package/esm/components/group.js +0 -33
  178. package/esm/components/member_2.d.ts +0 -69
  179. package/esm/components/member_2.d.ts.map +0 -1
  180. package/esm/components/member_2.js +0 -140
  181. package/esm/components/node.d.ts +0 -78
  182. package/esm/components/node.d.ts.map +0 -1
  183. package/esm/components/node.js +0 -342
  184. package/esm/components/server/activity.d.ts +0 -45
  185. package/esm/components/server/activity.d.ts.map +0 -1
  186. package/esm/components/server/activity.js +0 -158
  187. package/esm/components/server/allocations.d.ts +0 -45
  188. package/esm/components/server/allocations.d.ts.map +0 -1
  189. package/esm/components/server/allocations.js +0 -146
  190. package/esm/components/server/files.d.ts +0 -50
  191. package/esm/components/server/files.d.ts.map +0 -1
  192. package/esm/components/server/files.js +0 -90
  193. package/esm/components/server/power.d.ts +0 -21
  194. package/esm/components/server/power.d.ts.map +0 -1
  195. package/esm/components/server/power.js +0 -43
  196. package/esm/components/server/profiles.d.ts +0 -63
  197. package/esm/components/server/profiles.d.ts.map +0 -1
  198. package/esm/components/server/profiles.js +0 -163
  199. package/esm/components/server/server.d.ts +0 -141
  200. package/esm/components/server/server.d.ts.map +0 -1
  201. package/esm/components/server/server.js +0 -358
  202. package/esm/components/server/sftp.d.ts +0 -31
  203. package/esm/components/server/sftp.d.ts.map +0 -1
  204. package/esm/components/server/sftp.js +0 -84
  205. package/esm/components/server/startup.d.ts +0 -17
  206. package/esm/components/server/startup.d.ts.map +0 -1
  207. package/esm/components/server/startup.js +0 -21
  208. package/esm/components/server/stats.d.ts +0 -19
  209. package/esm/components/server/stats.d.ts.map +0 -1
  210. package/esm/components/server/stats.js +0 -46
  211. package/esm/utils/cache.d.ts +0 -20
  212. package/esm/utils/cache.d.ts.map +0 -1
  213. package/esm/utils/cache.js +0 -66
  214. package/esm/utils/event.d.ts +0 -38
  215. package/esm/utils/event.d.ts.map +0 -1
  216. package/esm/utils/event.js +0 -71
  217. package/esm/utils/object.d.ts +0 -58
  218. package/esm/utils/object.d.ts.map +0 -1
  219. package/esm/utils/object.js +0 -86
  220. package/esm/utils/subscribe.d.ts +0 -37
  221. package/esm/utils/subscribe.d.ts.map +0 -1
  222. package/esm/utils/subscribe.js +0 -29
  223. package/esm/utils/timer.d.ts +0 -13
  224. package/esm/utils/timer.d.ts.map +0 -1
  225. package/esm/utils/timer.js +0 -32
  226. package/esm/utils/units.d.ts +0 -18
  227. package/esm/utils/units.d.ts.map +0 -1
  228. package/esm/utils/units.js +0 -82
  229. package/script/api.d.ts +0 -76
  230. package/script/api.d.ts.map +0 -1
  231. package/script/api.js +0 -192
  232. package/script/components/auth.d.ts +0 -15
  233. package/script/components/auth.d.ts.map +0 -1
  234. package/script/components/auth.js +0 -17
  235. package/script/components/connection/abstract.d.ts +0 -23
  236. package/script/components/connection/abstract.d.ts.map +0 -1
  237. package/script/components/connection/abstract.js +0 -47
  238. package/script/components/connection/sse.d.ts +0 -20
  239. package/script/components/connection/sse.d.ts.map +0 -1
  240. package/script/components/connection/sse.js +0 -69
  241. package/script/components/egg/egg.d.ts +0 -32
  242. package/script/components/egg/egg.d.ts.map +0 -1
  243. package/script/components/egg/egg.js +0 -74
  244. package/script/components/group.d.ts +0 -14
  245. package/script/components/group.d.ts.map +0 -1
  246. package/script/components/group.js +0 -37
  247. package/script/components/member_2.d.ts +0 -69
  248. package/script/components/member_2.d.ts.map +0 -1
  249. package/script/components/member_2.js +0 -146
  250. package/script/components/node.d.ts +0 -78
  251. package/script/components/node.d.ts.map +0 -1
  252. package/script/components/node.js +0 -349
  253. package/script/components/server/activity.d.ts +0 -45
  254. package/script/components/server/activity.d.ts.map +0 -1
  255. package/script/components/server/activity.js +0 -164
  256. package/script/components/server/allocations.d.ts +0 -45
  257. package/script/components/server/allocations.d.ts.map +0 -1
  258. package/script/components/server/allocations.js +0 -152
  259. package/script/components/server/files.d.ts +0 -50
  260. package/script/components/server/files.d.ts.map +0 -1
  261. package/script/components/server/files.js +0 -94
  262. package/script/components/server/power.d.ts +0 -21
  263. package/script/components/server/power.d.ts.map +0 -1
  264. package/script/components/server/power.js +0 -47
  265. package/script/components/server/profiles.d.ts +0 -63
  266. package/script/components/server/profiles.d.ts.map +0 -1
  267. package/script/components/server/profiles.js +0 -168
  268. package/script/components/server/server.d.ts +0 -141
  269. package/script/components/server/server.d.ts.map +0 -1
  270. package/script/components/server/server.js +0 -362
  271. package/script/components/server/sftp.d.ts +0 -31
  272. package/script/components/server/sftp.d.ts.map +0 -1
  273. package/script/components/server/sftp.js +0 -88
  274. package/script/components/server/startup.d.ts +0 -17
  275. package/script/components/server/startup.d.ts.map +0 -1
  276. package/script/components/server/startup.js +0 -25
  277. package/script/components/server/stats.d.ts +0 -19
  278. package/script/components/server/stats.d.ts.map +0 -1
  279. package/script/components/server/stats.js +0 -50
  280. package/script/utils/cache.d.ts +0 -20
  281. package/script/utils/cache.d.ts.map +0 -1
  282. package/script/utils/cache.js +0 -70
  283. package/script/utils/event.d.ts +0 -38
  284. package/script/utils/event.d.ts.map +0 -1
  285. package/script/utils/event.js +0 -75
  286. package/script/utils/object.d.ts +0 -58
  287. package/script/utils/object.d.ts.map +0 -1
  288. package/script/utils/object.js +0 -90
  289. package/script/utils/subscribe.d.ts +0 -37
  290. package/script/utils/subscribe.d.ts.map +0 -1
  291. package/script/utils/subscribe.js +0 -32
  292. package/script/utils/timer.d.ts +0 -13
  293. package/script/utils/timer.d.ts.map +0 -1
  294. package/script/utils/timer.js +0 -36
  295. package/script/utils/units.d.ts +0 -18
  296. package/script/utils/units.d.ts.map +0 -1
  297. package/script/utils/units.js +0 -86
@@ -0,0 +1,136 @@
1
+ import type { HttpClient } from '../../http.js';
2
+ import { ReactiveResource } from '../../reactive.js';
3
+ import type { NanoID, PowerSignal, PowerState, ServerRestrictedState } from '../../types.js';
4
+ import { Egg } from '../eggs.js';
5
+ import { ServerGroup } from '../server-groups.js';
6
+ import { ServerActivityManager } from './activity.js';
7
+ import { ServerAllocationsManager } from './allocations.js';
8
+ import { ServerConnection } from './connection.js';
9
+ import { ServerFilesManager } from './files.js';
10
+ import { ServerProfilesManager } from './profiles.js';
11
+ import { ServerSftpManager } from './sftp.js';
12
+ import type { ServerAllocationsData, ServerData, UpdateServerPayload } from './types.js';
13
+ /** An egg environment variable configured for a server. */
14
+ export interface StartupVariable {
15
+ key: string;
16
+ name: string;
17
+ description: string;
18
+ value: string;
19
+ default: string;
20
+ /** Laravel validation rules, e.g. `"required|numeric|min:1"`. */
21
+ rules: string;
22
+ }
23
+ /** Real-time power state and utilization. Populated via `include=status`. */
24
+ export interface ServerStatus {
25
+ state: PowerState;
26
+ /** `null` when the server is offline. */
27
+ utilization: {
28
+ memoryBytes: number;
29
+ memoryLimitBytes: number;
30
+ cpuAbsolute: number;
31
+ networkRxBytes: number;
32
+ networkTxBytes: number;
33
+ uptimeSeconds: number;
34
+ diskBytes: number;
35
+ } | null;
36
+ }
37
+ /** Build and resource limit configuration. Populated via `include=build`. */
38
+ export interface ServerBuild {
39
+ cpuThreads: number | null | undefined;
40
+ /** Block IO weight (1–1000). */
41
+ ioWeight: number | null | undefined;
42
+ /** `null` disables the OOM killer. */
43
+ oomType: string | null | undefined;
44
+ skipInstallScripts: boolean | undefined;
45
+ limits: {
46
+ cpuPercent: number | null | undefined;
47
+ ramMb: number | null | undefined;
48
+ swapMb: number | null | undefined;
49
+ storageMb: number | null | undefined;
50
+ allocation: number | null | undefined;
51
+ database: number | null | undefined;
52
+ backup: number | null | undefined;
53
+ } | null | undefined;
54
+ }
55
+ /** Startup command and egg variables. Populated via `include=startup`. */
56
+ export interface ServerStartup {
57
+ command: string;
58
+ variables: Record<string, StartupVariable>;
59
+ }
60
+ /**
61
+ * A MeowPanel game server.
62
+ *
63
+ * @example
64
+ * ```ts ignore
65
+ * const server = await api.servers.get(id, { include: ['status', 'startup'] });
66
+ * server.status; // ServerStatus (guaranteed by include)
67
+ *
68
+ * await server.sendPower('start');
69
+ * await server.sendCommand('say Hello!');
70
+ *
71
+ * const conn = await server.createConnection();
72
+ * conn.on('console_output', (line) => console.log(line));
73
+ * await conn.open();
74
+ * ```
75
+ */
76
+ export declare class Server extends ReactiveResource {
77
+ private readonly http;
78
+ private readonly resolveNodeUrl;
79
+ private readonly onMutated;
80
+ readonly id: NanoID;
81
+ name: string;
82
+ description: string | null;
83
+ /** Only visible with `server.notes.read` permission. */
84
+ notes: string | null | undefined;
85
+ /** When non-null, overrides the node's reported power state for display. */
86
+ restrictedState: ServerRestrictedState;
87
+ readonly groupId: NanoID;
88
+ readonly eggId: NanoID;
89
+ eggImageId: NanoID | undefined;
90
+ /** Populated with `include=group`. */
91
+ group: ServerGroup | undefined;
92
+ /** Populated with `include=egg`. */
93
+ egg: Egg | undefined;
94
+ eggImageOverride: string | null | undefined;
95
+ /** Populated with `include=status`. Use {@link getStatus} to fetch on demand. */
96
+ status: ServerStatus | undefined;
97
+ /** Populated with `include=build`. */
98
+ build: ServerBuild | undefined;
99
+ /** Populated with `include=startup`. */
100
+ startup: ServerStartup | undefined;
101
+ /** Populated with `include=allocations`. */
102
+ allocationPorts: ServerAllocationsData | undefined;
103
+ createdAt: Date;
104
+ updatedAt: Date;
105
+ readonly allocations: ServerAllocationsManager;
106
+ readonly sftp: ServerSftpManager;
107
+ readonly profiles: ServerProfilesManager;
108
+ readonly activity: ServerActivityManager;
109
+ readonly files: ServerFilesManager;
110
+ /** @internal */
111
+ constructor(data: ServerData, http: HttpClient, resolveNodeUrl: () => Promise<string>, onMutated: () => void);
112
+ /** Apply raw API data, updating all mutable fields. */
113
+ applyData(data: ServerData): void;
114
+ /** Update this server's details, startup config, or primary allocation. */
115
+ update(payload: UpdateServerPayload): Promise<void>;
116
+ /** Fetch current power state and utilization from the node. */
117
+ getStatus(): Promise<ServerStatus>;
118
+ /** Send a power signal: `start`, `stop`, `restart`, or `kill`. */
119
+ sendPower(signal: PowerSignal): Promise<void>;
120
+ /** Send one or more console commands. */
121
+ sendCommand(command: string | string[]): Promise<void>;
122
+ /**
123
+ * Create a real-time SSE connection to this server's node daemon.
124
+ *
125
+ * Not yet open - call {@link ServerConnection.open} to start streaming.
126
+ *
127
+ * @example
128
+ * ```ts ignore
129
+ * const conn = await server.createConnection();
130
+ * conn.on('stats', ({ cpuAbsolute }) => console.log(`CPU: ${cpuAbsolute}%`));
131
+ * await conn.open();
132
+ * ```
133
+ */
134
+ createConnection(): Promise<ServerConnection>;
135
+ }
136
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../src/src/resources/servers/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAE7F,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE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AAsC;IAC/B,KAAK,EAAE,WAAW,GAAG,SAAS,CAAC;IACtC,wCAAwC;IACjC,OAAO,EAAE,aAAa,GAAG,SAAS,CAAC;IAC1C,4CAA4C;IACrC,eAAe,EAAE,qBAAqB,GAAG,SAAS,CAAC;IACnD,SAAS,EAAG,IAAI,CAAC;IACjB,SAAS,EAAG,IAAI,CAAC;IAExB,SAAgB,WAAW,EAAE,wBAAwB,CAAC;IACtD,SAAgB,IAAI,EAAE,iBAAiB,CAAC;IACxC,SAAgB,QAAQ,EAAE,qBAAqB,CAAC;IAChD,SAAgB,QAAQ,EAAE,qBAAqB,CAAC;IAChD,SAAgB,KAAK,EAAE,kBAAkB,CAAC;IAE1C,gBAAgB;gBAEf,IAAI,EAAE,UAAU,EACC,IAAI,EAAE,UAAU,EAChB,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACrC,SAAS,EAAE,MAAM,IAAI;IAoBvC,uDAAuD;IAChD,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAuCxC,2EAA2E;IAC9D,MAAM,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBhE,+DAA+D;IAClD,SAAS,IAAI,OAAO,CAAC,YAAY,CAAC;IAO/C,kEAAkE;IACrD,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1D,yCAAyC;IAC5B,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKnE;;;;;;;;;;;OAWG;IACU,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAI1D"}
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Server = void 0;
4
+ const reactive_js_1 = require("../../reactive.js");
5
+ const types_js_1 = require("../../types.js");
6
+ const eggs_js_1 = require("../eggs.js");
7
+ const server_groups_js_1 = require("../server-groups.js");
8
+ const activity_js_1 = require("./activity.js");
9
+ const allocations_js_1 = require("./allocations.js");
10
+ const connection_js_1 = require("./connection.js");
11
+ const files_js_1 = require("./files.js");
12
+ const profiles_js_1 = require("./profiles.js");
13
+ const sftp_js_1 = require("./sftp.js");
14
+ /**
15
+ * A MeowPanel game server.
16
+ *
17
+ * @example
18
+ * ```ts ignore
19
+ * const server = await api.servers.get(id, { include: ['status', 'startup'] });
20
+ * server.status; // ServerStatus (guaranteed by include)
21
+ *
22
+ * await server.sendPower('start');
23
+ * await server.sendCommand('say Hello!');
24
+ *
25
+ * const conn = await server.createConnection();
26
+ * conn.on('console_output', (line) => console.log(line));
27
+ * await conn.open();
28
+ * ```
29
+ */
30
+ class Server extends reactive_js_1.ReactiveResource {
31
+ http;
32
+ resolveNodeUrl;
33
+ onMutated;
34
+ id;
35
+ name;
36
+ description;
37
+ /** Only visible with `server.notes.read` permission. */
38
+ notes;
39
+ /** When non-null, overrides the node's reported power state for display. */
40
+ restrictedState;
41
+ groupId;
42
+ eggId;
43
+ eggImageId;
44
+ /** Populated with `include=group`. */
45
+ group;
46
+ /** Populated with `include=egg`. */
47
+ egg;
48
+ eggImageOverride;
49
+ /** Populated with `include=status`. Use {@link getStatus} to fetch on demand. */
50
+ status;
51
+ /** Populated with `include=build`. */
52
+ build;
53
+ /** Populated with `include=startup`. */
54
+ startup;
55
+ /** Populated with `include=allocations`. */
56
+ allocationPorts;
57
+ createdAt;
58
+ updatedAt;
59
+ allocations;
60
+ sftp;
61
+ profiles;
62
+ activity;
63
+ files;
64
+ /** @internal */
65
+ constructor(data, http, resolveNodeUrl, onMutated) {
66
+ super();
67
+ this.http = http;
68
+ this.resolveNodeUrl = resolveNodeUrl;
69
+ this.onMutated = onMutated;
70
+ this.id = (0, types_js_1.toNanoID)(data.id);
71
+ this.groupId = (0, types_js_1.toNanoID)(data.group_id);
72
+ this.eggId = (0, types_js_1.toNanoID)(data.egg_id);
73
+ this.allocations = new allocations_js_1.ServerAllocationsManager(this.id, http);
74
+ this.sftp = new sftp_js_1.ServerSftpManager(this.id, http);
75
+ this.profiles = new profiles_js_1.ServerProfilesManager(this.id, http);
76
+ this.activity = new activity_js_1.ServerActivityManager(this.id, http);
77
+ this.files = new files_js_1.ServerFilesManager(this.id, http.getToken(), resolveNodeUrl);
78
+ this.applyData(data);
79
+ }
80
+ /** Apply raw API data, updating all mutable fields. */
81
+ applyData(data) {
82
+ this.name = data.name;
83
+ this.description = data.description;
84
+ this.notes = data.notes;
85
+ this.restrictedState = data.restricted_state;
86
+ this.eggImageId = data.egg_image_id ? (0, types_js_1.toNanoID)(data.egg_image_id) : undefined;
87
+ this.eggImageOverride = data.egg_image_override;
88
+ // Include-gated fields: only overwrite if present in response
89
+ if (data.group)
90
+ this.group = new server_groups_js_1.ServerGroup(data.group);
91
+ if (data.egg)
92
+ this.egg = new eggs_js_1.Egg(data.egg);
93
+ if (data.status !== undefined) {
94
+ this.status = data.status ? parseStatus(data.status) : undefined;
95
+ }
96
+ if (data.build !== undefined) {
97
+ this.build = data.build ? parseBuild(data.build) : undefined;
98
+ }
99
+ if (data.startup !== undefined) {
100
+ this.startup = data.startup
101
+ ? {
102
+ command: data.startup.command,
103
+ variables: Object.fromEntries(Object.entries(data.startup.variables).map(([k, v]) => [
104
+ k,
105
+ { key: k, ...v, default: v.default },
106
+ ])),
107
+ }
108
+ : undefined;
109
+ }
110
+ if (data.allocations !== undefined) {
111
+ this.allocationPorts = data.allocations ?? undefined;
112
+ }
113
+ this.createdAt = new Date(data.created_at);
114
+ this.updatedAt = new Date(data.updated_at);
115
+ this.notify();
116
+ }
117
+ /** Update this server's details, startup config, or primary allocation. */
118
+ async update(payload) {
119
+ const body = {};
120
+ if (payload.name !== undefined)
121
+ body['name'] = payload.name;
122
+ if (payload.description !== undefined) {
123
+ body['description'] = payload.description;
124
+ }
125
+ if (payload.notes !== undefined)
126
+ body['notes'] = payload.notes;
127
+ if (payload.allocationPrimary) {
128
+ body['allocation_primary'] = payload.allocationPrimary;
129
+ }
130
+ if (payload.startup) {
131
+ body['startup'] = {
132
+ command: payload.startup.command,
133
+ variables: payload.startup.variables,
134
+ };
135
+ }
136
+ const data = await this.http.patch(`/servers/${this.id}`, body);
137
+ this.applyData(data);
138
+ this.onMutated();
139
+ }
140
+ /** Fetch current power state and utilization from the node. */
141
+ async getStatus() {
142
+ const data = await this.http.get(`/servers/${this.id}/status`);
143
+ return parseStatus(data);
144
+ }
145
+ /** Send a power signal: `start`, `stop`, `restart`, or `kill`. */
146
+ async sendPower(signal) {
147
+ await this.http.post(`/servers/${this.id}/power`, { signal });
148
+ }
149
+ /** Send one or more console commands. */
150
+ async sendCommand(command) {
151
+ const commands = Array.isArray(command) ? command : [command];
152
+ await this.http.post(`/servers/${this.id}/commands`, { commands });
153
+ }
154
+ /**
155
+ * Create a real-time SSE connection to this server's node daemon.
156
+ *
157
+ * Not yet open - call {@link ServerConnection.open} to start streaming.
158
+ *
159
+ * @example
160
+ * ```ts ignore
161
+ * const conn = await server.createConnection();
162
+ * conn.on('stats', ({ cpuAbsolute }) => console.log(`CPU: ${cpuAbsolute}%`));
163
+ * await conn.open();
164
+ * ```
165
+ */
166
+ async createConnection() {
167
+ const nodeUrl = await this.resolveNodeUrl();
168
+ return new connection_js_1.ServerConnection(this.id, nodeUrl, this.http.getToken());
169
+ }
170
+ }
171
+ exports.Server = Server;
172
+ function parseStatus(data) {
173
+ return {
174
+ state: data.state,
175
+ utilization: data.utilization
176
+ ? {
177
+ memoryBytes: data.utilization.memory_bytes,
178
+ memoryLimitBytes: data.utilization.memory_limit_bytes,
179
+ cpuAbsolute: data.utilization.cpu_absolute,
180
+ networkRxBytes: data.utilization.network.rx_bytes,
181
+ networkTxBytes: data.utilization.network.tx_bytes,
182
+ uptimeSeconds: data.utilization.uptime,
183
+ diskBytes: data.utilization.disk_bytes,
184
+ }
185
+ : null,
186
+ };
187
+ }
188
+ function parseBuild(data) {
189
+ return {
190
+ cpuThreads: data.cpu_threads,
191
+ ioWeight: data.io_weight,
192
+ oomType: data.oom_type,
193
+ skipInstallScripts: data.skip_install_scripts,
194
+ limits: data.limits
195
+ ? {
196
+ cpuPercent: data.limits.cpu_percent,
197
+ ramMb: data.limits.ram_mb,
198
+ swapMb: data.limits.swap_mb,
199
+ storageMb: data.limits.storage_mb,
200
+ allocation: data.limits.allocation,
201
+ database: data.limits.database,
202
+ backup: data.limits.backup,
203
+ }
204
+ : data.limits,
205
+ };
206
+ }
@@ -0,0 +1,147 @@
1
+ import type { HttpClient } from '../../http.js';
2
+ import { ReactiveResource } from '../../reactive.js';
3
+ import type { IncludeOptions, ListOptions, NanoID, Paginated, ResourceWith, SftpPermission } from '../../types.js';
4
+ import { Member } from '../members.js';
5
+ import type { SftpUserData } from './types.js';
6
+ /**
7
+ * Connection details for the SFTP server on a node.
8
+ */
9
+ export interface SftpConnection {
10
+ /** Full SFTP URL, e.g. `"sftp://1.2.3.4:2022"`. */
11
+ url: string;
12
+ /** Hostname or IP of the SFTP server. */
13
+ fqdn: string;
14
+ /** Port the SFTP server listens on. */
15
+ port: number;
16
+ }
17
+ /**
18
+ * An SFTP user credential scoped to a specific server with path-level permissions.
19
+ *
20
+ * Retrieved via {@link ServerSftpManager.list} or {@link ServerSftpManager.create}.
21
+ *
22
+ * > **Note:** The `password` field is automatically included in the creation response.
23
+ * > On subsequent fetches it requires `include=password` to be populated.
24
+ */
25
+ export declare class SftpUser extends ReactiveResource {
26
+ /** The SFTP user's unique NanoID. */
27
+ readonly id: NanoID;
28
+ /** Display name for this SFTP user. */
29
+ name: string;
30
+ /** The SFTP login username (typically prefixed with the server ID). */
31
+ username: string;
32
+ /**
33
+ * The plaintext password.
34
+ *
35
+ * Automatically included on creation. Requires `include=password` on subsequent fetches.
36
+ */
37
+ password: string | undefined;
38
+ /**
39
+ * A map of path glob patterns to the set of permissions granted for that path.
40
+ *
41
+ * Keys are glob patterns (e.g. `"/"`, `"/logs/*"`).
42
+ * Values are arrays of {@link SftpPermission} scopes.
43
+ */
44
+ paths: Record<string, SftpPermission[]>;
45
+ /** NanoID of the member who owns this SFTP user. */
46
+ ownerId: NanoID;
47
+ /** The owner member. */
48
+ owner: Member | null | undefined;
49
+ /** When this SFTP user last logged in, or `null` if never. */
50
+ lastLoginAt: Date | null;
51
+ /** When this SFTP user was created. */
52
+ createdAt: Date;
53
+ /** When this SFTP user was last updated. */
54
+ updatedAt: Date;
55
+ /** @internal */
56
+ constructor(data: SftpUserData);
57
+ }
58
+ /** Valid include keys for SFTP user endpoints. */
59
+ export type SftpUserInclude = 'password';
60
+ /** Maps each {@link SftpUserInclude} key to the field(s) it guarantees on the {@link SftpUser} instance. */
61
+ interface SftpUserIncludeMap {
62
+ password: {
63
+ password: string;
64
+ };
65
+ }
66
+ /** A {@link SftpUser} with specific include fields guaranteed to be populated. */
67
+ export type SftpUserWith<I extends readonly SftpUserInclude[] = []> = ResourceWith<SftpUser, SftpUserIncludeMap, I>;
68
+ /**
69
+ * The full SFTP details for a server: connection info and the list of SFTP users.
70
+ */
71
+ export interface SftpDetails {
72
+ /** How to connect to this server's SFTP endpoint. */
73
+ connection: SftpConnection;
74
+ /** All SFTP users configured for this server. */
75
+ users: SftpUser[];
76
+ }
77
+ /**
78
+ * Manages SFTP users and credentials for a specific server.
79
+ *
80
+ * Access via `server.sftp`.
81
+ *
82
+ * @example
83
+ * ```ts ignore
84
+ * const details = await server.sftp.details();
85
+ * console.log(`Connect to: ${details.connection.url}`);
86
+ *
87
+ * const user = await server.sftp.create('deploy', {
88
+ * '/': ['sftp.content.list', 'sftp.content.read'],
89
+ * '/logs': ['sftp.content.list', 'sftp.content.read', 'sftp.content.delete'],
90
+ * });
91
+ * console.log(user.password); // Save this!
92
+ * ```
93
+ */
94
+ export declare class ServerSftpManager {
95
+ private readonly serverId;
96
+ private readonly http;
97
+ /** @internal */
98
+ constructor(serverId: NanoID, http: HttpClient);
99
+ /**
100
+ * Fetch the SFTP connection details and all SFTP users for this server.
101
+ */
102
+ details(): Promise<SftpDetails>;
103
+ /**
104
+ * Fetch all SFTP users for this server without the connection details.
105
+ *
106
+ * @param opts Pagination and include options.
107
+ */
108
+ list<const I extends readonly SftpUserInclude[] = []>(opts?: ListOptions & IncludeOptions<SftpUserInclude, I>): Promise<Paginated<SftpUserWith<I>>>;
109
+ /**
110
+ * Fetch a single SFTP user by ID.
111
+ *
112
+ * @param userId The SFTP user's NanoID.
113
+ * @param opts Include options.
114
+ */
115
+ get<const I extends readonly SftpUserInclude[] = []>(userId: NanoID, opts?: IncludeOptions<SftpUserInclude, I>): Promise<SftpUserWith<I>>;
116
+ /**
117
+ * Create a new SFTP user for this server.
118
+ *
119
+ * The returned {@link SftpUser} includes the `password` field automatically.
120
+ * On subsequent fetches, request it explicitly with `include=password`.
121
+ *
122
+ * @param name Display name for the SFTP user.
123
+ * @param paths A map of path glob patterns to an array of {@link SftpPermission} scopes.
124
+ * At least one path with at least one permission is required.
125
+ */
126
+ create(name: string, paths: Record<string, SftpPermission[]>): Promise<SftpUser>;
127
+ /**
128
+ * Update an SFTP user's name and/or path permissions.
129
+ *
130
+ * To remove a path, set its permissions array to `[]`.
131
+ *
132
+ * @param userId The SFTP user's NanoID.
133
+ * @param payload Fields to update.
134
+ */
135
+ update(userId: NanoID, payload: {
136
+ name?: string;
137
+ paths?: Record<string, SftpPermission[]>;
138
+ }): Promise<SftpUser>;
139
+ /**
140
+ * Delete an SFTP user permanently.
141
+ *
142
+ * @param userId The SFTP user's NanoID.
143
+ */
144
+ delete(userId: NanoID): Promise<void>;
145
+ }
146
+ export {};
147
+ //# sourceMappingURL=sftp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sftp.d.ts","sourceRoot":"","sources":["../../../../src/src/resources/servers/sftp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,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,CAAC;KACzC,GACC,OAAO,CAAC,QAAQ,CAAC;IAQpB;;;;OAIG;IACU,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlD"}
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServerSftpManager = exports.SftpUser = void 0;
4
+ const reactive_js_1 = require("../../reactive.js");
5
+ const types_js_1 = require("../../types.js");
6
+ const members_js_1 = require("../members.js");
7
+ /**
8
+ * An SFTP user credential scoped to a specific server with path-level permissions.
9
+ *
10
+ * Retrieved via {@link ServerSftpManager.list} or {@link ServerSftpManager.create}.
11
+ *
12
+ * > **Note:** The `password` field is automatically included in the creation response.
13
+ * > On subsequent fetches it requires `include=password` to be populated.
14
+ */
15
+ class SftpUser extends reactive_js_1.ReactiveResource {
16
+ /** The SFTP user's unique NanoID. */
17
+ id;
18
+ /** Display name for this SFTP user. */
19
+ name;
20
+ /** The SFTP login username (typically prefixed with the server ID). */
21
+ username;
22
+ /**
23
+ * The plaintext password.
24
+ *
25
+ * Automatically included on creation. Requires `include=password` on subsequent fetches.
26
+ */
27
+ password;
28
+ /**
29
+ * A map of path glob patterns to the set of permissions granted for that path.
30
+ *
31
+ * Keys are glob patterns (e.g. `"/"`, `"/logs/*"`).
32
+ * Values are arrays of {@link SftpPermission} scopes.
33
+ */
34
+ paths;
35
+ /** NanoID of the member who owns this SFTP user. */
36
+ ownerId;
37
+ /** The owner member. */
38
+ owner;
39
+ /** When this SFTP user last logged in, or `null` if never. */
40
+ lastLoginAt;
41
+ /** When this SFTP user was created. */
42
+ createdAt;
43
+ /** When this SFTP user was last updated. */
44
+ updatedAt;
45
+ /** @internal */
46
+ constructor(data) {
47
+ super();
48
+ this.id = (0, types_js_1.toNanoID)(data.id);
49
+ this.name = data.name;
50
+ this.username = data.username;
51
+ this.password = data.password;
52
+ this.paths = data.paths;
53
+ this.ownerId = (0, types_js_1.toNanoID)(data.owner_id);
54
+ this.owner = data.owner ? new members_js_1.Member(data.owner) : data.owner;
55
+ this.lastLoginAt = data.last_login_at ? new Date(data.last_login_at) : null;
56
+ this.createdAt = new Date(data.created_at);
57
+ this.updatedAt = new Date(data.updated_at);
58
+ }
59
+ }
60
+ exports.SftpUser = SftpUser;
61
+ /**
62
+ * Manages SFTP users and credentials for a specific server.
63
+ *
64
+ * Access via `server.sftp`.
65
+ *
66
+ * @example
67
+ * ```ts ignore
68
+ * const details = await server.sftp.details();
69
+ * console.log(`Connect to: ${details.connection.url}`);
70
+ *
71
+ * const user = await server.sftp.create('deploy', {
72
+ * '/': ['sftp.content.list', 'sftp.content.read'],
73
+ * '/logs': ['sftp.content.list', 'sftp.content.read', 'sftp.content.delete'],
74
+ * });
75
+ * console.log(user.password); // Save this!
76
+ * ```
77
+ */
78
+ class ServerSftpManager {
79
+ serverId;
80
+ http;
81
+ /** @internal */
82
+ constructor(serverId, http) {
83
+ this.serverId = serverId;
84
+ this.http = http;
85
+ }
86
+ /**
87
+ * Fetch the SFTP connection details and all SFTP users for this server.
88
+ */
89
+ async details() {
90
+ const data = await this.http.get(`/servers/${this.serverId}/sftp`);
91
+ return {
92
+ connection: data.connection,
93
+ users: data.users.map((u) => new SftpUser(u)),
94
+ };
95
+ }
96
+ /**
97
+ * Fetch all SFTP users for this server without the connection details.
98
+ *
99
+ * @param opts Pagination and include options.
100
+ */
101
+ async list(opts = {}) {
102
+ const extra = {};
103
+ const include = (0, types_js_1.joinIncludes)(opts);
104
+ if (include)
105
+ extra['include'] = include;
106
+ const result = await this.http.list(`/servers/${this.serverId}/sftp/users`, opts, extra);
107
+ return { ...result, data: result.data.map((d) => new SftpUser(d)) };
108
+ }
109
+ /**
110
+ * Fetch a single SFTP user by ID.
111
+ *
112
+ * @param userId The SFTP user's NanoID.
113
+ * @param opts Include options.
114
+ */
115
+ async get(userId, opts = {}) {
116
+ const params = {};
117
+ const include = (0, types_js_1.joinIncludes)(opts);
118
+ if (include)
119
+ params['include'] = include;
120
+ const data = await this.http.get(`/servers/${this.serverId}/sftp/users/${userId}`, { params });
121
+ return new SftpUser(data);
122
+ }
123
+ /**
124
+ * Create a new SFTP user for this server.
125
+ *
126
+ * The returned {@link SftpUser} includes the `password` field automatically.
127
+ * On subsequent fetches, request it explicitly with `include=password`.
128
+ *
129
+ * @param name Display name for the SFTP user.
130
+ * @param paths A map of path glob patterns to an array of {@link SftpPermission} scopes.
131
+ * At least one path with at least one permission is required.
132
+ */
133
+ async create(name, paths) {
134
+ const data = await this.http.post(`/servers/${this.serverId}/sftp/users`, { name, paths });
135
+ return new SftpUser(data);
136
+ }
137
+ /**
138
+ * Update an SFTP user's name and/or path permissions.
139
+ *
140
+ * To remove a path, set its permissions array to `[]`.
141
+ *
142
+ * @param userId The SFTP user's NanoID.
143
+ * @param payload Fields to update.
144
+ */
145
+ async update(userId, payload) {
146
+ const data = await this.http.patch(`/servers/${this.serverId}/sftp/users/${userId}`, payload);
147
+ return new SftpUser(data);
148
+ }
149
+ /**
150
+ * Delete an SFTP user permanently.
151
+ *
152
+ * @param userId The SFTP user's NanoID.
153
+ */
154
+ async delete(userId) {
155
+ await this.http.delete(`/servers/${this.serverId}/sftp/users/${userId}`);
156
+ }
157
+ }
158
+ exports.ServerSftpManager = ServerSftpManager;