@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
@@ -1,163 +0,0 @@
1
- import { CachedRelation } from '../../utils/cache.js';
2
- import { EventManager } from '../../utils/event.js';
3
- import { UpdatableObject } from '../../utils/object.js';
4
- // TODO: ServerProfile support 'folder' include
5
- export class ServerProfileManager {
6
- constructor(api, server) {
7
- Object.defineProperty(this, "api", {
8
- enumerable: true,
9
- configurable: true,
10
- writable: true,
11
- value: api
12
- });
13
- Object.defineProperty(this, "server", {
14
- enumerable: true,
15
- configurable: true,
16
- writable: true,
17
- value: server
18
- });
19
- Object.defineProperty(this, "profiles", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: {}
24
- });
25
- Object.defineProperty(this, "activeProfile", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: null
30
- });
31
- }
32
- addCached(profile) {
33
- for (const p of profile) {
34
- this.profiles[p.id] = new ServerProfile(this.api, this.server, this, p);
35
- if (p.is_active) {
36
- this.activeProfile = this.profiles[p.id];
37
- }
38
- }
39
- }
40
- async getPaged(page) {
41
- const response = await this.api.request('GET', `/v1/servers/${this.server.id}/profiles`, { pagination: { page } });
42
- this.addCached(response.data);
43
- return {
44
- profiles: response.data,
45
- page: response.page,
46
- };
47
- }
48
- async geAll() {
49
- this.activeProfile = null;
50
- for (const p of Object.values(this.profiles)) {
51
- delete this.profiles[p.id];
52
- }
53
- let page;
54
- let current = 1;
55
- do {
56
- const response = await this.getPaged(current++);
57
- page = response.page;
58
- } while (page.total > page.from && current < 5);
59
- for (const p of Object.values(this.profiles)) {
60
- p._update();
61
- }
62
- return Object.values(this.profiles);
63
- }
64
- get(id) {
65
- return this.profiles[id];
66
- }
67
- getActiveProfile() {
68
- return this.activeProfile;
69
- }
70
- async setActiveProfile(profile) {
71
- await this.api.request('PATCH', `/v1/servers/${this.server.id}/profiles/active`, {
72
- body: { id: profile.id },
73
- });
74
- this.activeProfile = profile;
75
- for (const p of Object.values(this.profiles)) {
76
- p._update();
77
- }
78
- }
79
- async create(data) {
80
- const response = await this.api.request('POST', `/v1/servers/${this.server.id}/profiles`, {
81
- body: data,
82
- });
83
- this.profiles[response.data.id] = new ServerProfile(this.api, this.server, this, response.data);
84
- return this.profiles[response.data.id];
85
- }
86
- }
87
- export class ServerProfile extends UpdatableObject {
88
- constructor(api, server, manager, response) {
89
- super(api, response, `/v1/servers/${server.id}/profiles/${response.id}`);
90
- Object.defineProperty(this, "manager", {
91
- enumerable: true,
92
- configurable: true,
93
- writable: true,
94
- value: manager
95
- });
96
- Object.defineProperty(this, "eventManager", {
97
- enumerable: true,
98
- configurable: true,
99
- writable: true,
100
- value: new EventManager()
101
- });
102
- Object.defineProperty(this, "isActive", {
103
- enumerable: true,
104
- configurable: true,
105
- writable: true,
106
- value: false
107
- });
108
- }
109
- on(event, func) {
110
- return this.eventManager.on(event, func);
111
- }
112
- off(event, func) {
113
- return this.eventManager.off(event, func);
114
- }
115
- subscribe(fn) {
116
- const ids = [];
117
- const update = () => fn(this);
118
- update();
119
- ids.push(this.eventManager.on('active', update));
120
- return () => {
121
- ids.forEach(this.eventManager.off.bind(this.eventManager));
122
- };
123
- }
124
- applyResponse(oldData, _newData) {
125
- return {
126
- folder: oldData?.folder ?? new CachedRelation(async () => {
127
- const response = await this.fetchSelf(['folder']);
128
- return response.folder;
129
- }),
130
- };
131
- }
132
- get id() {
133
- return this.response.id;
134
- }
135
- get name() {
136
- return this.response.name;
137
- }
138
- get description() {
139
- return this.response.description;
140
- }
141
- get notes() {
142
- return this.response.notes;
143
- }
144
- get folder() {
145
- return this.response.folder;
146
- }
147
- async updateDetails(details) {
148
- await this.callPatch({
149
- name: details.name,
150
- description: details.description,
151
- notes: details.notes,
152
- });
153
- }
154
- async setAsActive() {
155
- await this.manager.setActiveProfile(this);
156
- this.response.is_active = true;
157
- }
158
- // TODO: remove this method and replace with better Object management
159
- _update() {
160
- this.isActive = this.manager.getActiveProfile()?.id === this.id;
161
- this.eventManager.dispatch('active', this);
162
- }
163
- }
@@ -1,141 +0,0 @@
1
- import type { MeowPanelApi, MeowPanelApiRequestData, Page, Pagination } from '../../api.js';
2
- import { CachedRelation } from '../../utils/cache.js';
3
- import { type EventFunction, EventManager, type EventManagerListener } from '../../utils/event.js';
4
- import { UpdatableObject } from '../../utils/object.js';
5
- import { type Subscription } from '../../utils/subscribe.js';
6
- import type { Extended } from '../../utils/types';
7
- import type { Logger } from '../connection/abstract.js';
8
- import { Egg, type EggInclude } from '../egg/egg.js';
9
- import { ServerGroup } from '../group.js';
10
- import type { Node } from '../node.js';
11
- import { ServerActivityJob, ServerActivityLog } from './activity.js';
12
- import { ServerAllocationPort, ServerAllocations } from './allocations.js';
13
- import { ServerFileManager } from './files.js';
14
- import { type PowerState, PowerStateEvent } from './power.js';
15
- import { ServerProfileManager } from './profiles.js';
16
- import type { ServerBuildResponse, ServerResponse, ServerRestrictedState, SftpResponse } from './server_2';
17
- import { SftpUser } from './sftp.js';
18
- import { StartupParameters } from './startup.js';
19
- import { ServerStatsEvent } from './stats.js';
20
- export type ServerInclude = 'status' | 'group' | 'startup' | 'egg' | EggInclude | 'group' | 'build' | 'profiles';
21
- interface Modified {
22
- group: CachedRelation<ServerGroup>;
23
- egg: CachedRelation<Egg>;
24
- status: ServerStatsEvent;
25
- startup: CachedRelation<StartupParameters>;
26
- allocations: CachedRelation<ServerAllocations>;
27
- build: CachedRelation<ServerBuildResponse>;
28
- }
29
- type PowerStateResponse = {
30
- state: PowerState;
31
- utilization: {
32
- memory_bytes: 0;
33
- memory_limit_bytes: 0;
34
- cpu_absolute: 0;
35
- network: {
36
- rx_bytes: 0;
37
- tx_bytes: 0;
38
- };
39
- uptime: 0;
40
- state: PowerState;
41
- disk_bytes: 0;
42
- };
43
- };
44
- export declare class Server extends UpdatableObject<ServerResponse, Modified, ServerInclude> implements EventManagerListener<ServerEvents>, Subscription<Server> {
45
- static getPaged(api: MeowPanelApi, page: number, include?: ServerInclude[], query?: string): Promise<{
46
- servers: Server[];
47
- page: Page;
48
- }>;
49
- static get(api: MeowPanelApi, id: string, include?: ServerInclude[]): Promise<Server>;
50
- constructor(api: MeowPanelApi, data: ServerResponse);
51
- protected applyResponse(oldData: Extended<ServerResponse, Modified> | undefined, newData: ServerResponse): Modified;
52
- protected readonly eventManager: EventManager<ServerEvents>;
53
- on<K extends keyof ServerEvents>(event: K, func: EventFunction<ServerEvents, K>): number;
54
- off<K extends keyof ServerEvents>(event: K | number, func?: number | EventFunction<ServerEvents, K>): boolean;
55
- subscribe(fn: (value: Server) => void): () => void;
56
- readonly consoleHistory: Subscription<string[]>;
57
- private connection;
58
- private readonly ids;
59
- connect(options?: Partial<{
60
- logger: Logger;
61
- resetEventListeners: boolean;
62
- }>): Promise<void>;
63
- disconnect(): Promise<void>;
64
- get isConnected(): boolean | undefined;
65
- getNode(): Promise<Node>;
66
- requestNodeApi(method: string, path: `/${string}`, data?: MeowPanelApiRequestData): Promise<Response>;
67
- updateDetails(details: {
68
- name?: string;
69
- description?: string | null;
70
- notes?: string | null;
71
- }): Promise<void>;
72
- updateStartup(startup: {
73
- command?: string;
74
- variables?: Record<string, string>;
75
- }): Promise<void>;
76
- /**
77
- * Get the status of the server such as its power state status and utilization.
78
- *
79
- * Calling this will also update the current power status subscription of the server.
80
- */
81
- getStatus(): Promise<PowerStateResponse>;
82
- /**
83
- * Get the current power status state of the server.
84
- *
85
- * This function is an alias for the `getStatus` function.
86
- */
87
- getPowerState(): Promise<PowerState>;
88
- /**
89
- * Send a power signal to the server.
90
- */
91
- sendPowerSignal(state: 'start' | 'restart' | 'stop' | 'kill'): Promise<void>;
92
- /**
93
- * Send one or multiple commands to the server.
94
- *
95
- * The server must be in the running state for this to work.
96
- */
97
- sendCommand(command: string | string[]): Promise<void>;
98
- getActivityLogs(pagination: Pagination, include?: Array<'jobs' | 'server' | 'node'>, query?: string): Promise<{
99
- logs: ServerActivityLog[];
100
- page: Page;
101
- }>;
102
- getActivityLog(id: string): Promise<ServerActivityLog>;
103
- getActivityJobs(pagination: Pagination, include?: Array<'server' | 'node'>, query?: string): Promise<{
104
- jobs: ServerActivityJob[];
105
- page: Page;
106
- }>;
107
- getActivityJob(id: string): Promise<ServerActivityJob>;
108
- getSftpDetails(): Promise<SftpResponse['connection']>;
109
- getSftpUsers(pagination: Pagination, include?: Array<'password' | 'owner'>, query?: string): Promise<{
110
- users: SftpUser[];
111
- page: Page;
112
- }>;
113
- getAllocations(pagination: Pagination, include?: Array<'meta'>, query?: string): Promise<{
114
- allocations: ServerAllocationPort[];
115
- page: Page;
116
- }>;
117
- readonly profiles: ServerProfileManager;
118
- readonly files: ServerFileManager;
119
- get id(): string;
120
- get name(): string;
121
- get description(): string;
122
- get notes(): string | null | undefined;
123
- get group(): CachedRelation<ServerGroup>;
124
- get restrictedState(): ServerRestrictedState;
125
- get egg(): CachedRelation<Egg>;
126
- get build(): CachedRelation<ServerBuildResponse>;
127
- get allocations(): CachedRelation<ServerAllocations>;
128
- get status(): ServerStatsEvent;
129
- get startup(): CachedRelation<StartupParameters>;
130
- get createdAt(): string;
131
- get updatedAt(): string;
132
- }
133
- interface ServerEvents {
134
- power: PowerStateEvent;
135
- stats: ServerStatsEvent;
136
- console_output: string;
137
- meta_details: Server;
138
- startup_details: StartupParameters;
139
- }
140
- export {};
141
- //# sourceMappingURL=server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/components/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAuB,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,KAAK,aAAa,EAAE,Y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/cache.js';
2
- import { EventManager } from '../../utils/event.js';
3
- import { UpdatableObject } from '../../utils/object.js';
4
- import { createSubscription } from '../../utils/subscribe.js';
5
- import { SseServerConnection } from '../connection/sse.js';
6
- import { Egg } from '../egg/egg.js';
7
- import { ServerGroup } from '../group.js';
8
- import { ServerActivityJob, ServerActivityLog } from './activity.js';
9
- import { ServerAllocationPort, ServerAllocations } from './allocations.js';
10
- import { ServerFileManager } from './files.js';
11
- import { PowerStateEvent } from './power.js';
12
- import { ServerProfileManager } from './profiles.js';
13
- import { SftpUser } from './sftp.js';
14
- import { StartupParameters } from './startup.js';
15
- import { ServerStatsEvent } from './stats.js';
16
- export class Server extends UpdatableObject {
17
- static async getPaged(api, page, include, query) {
18
- const response = await api.request('GET', `/v1/servers`, {
19
- pagination: { page },
20
- params: {
21
- include: include?.join(','),
22
- query,
23
- },
24
- });
25
- return {
26
- servers: response.data.map((data) => new Server(api, data)),
27
- page: response.page,
28
- };
29
- }
30
- static async get(api, id, include) {
31
- const response = await api.request('GET', `/v1/servers/${id}`, {
32
- params: {
33
- include: include?.join(','),
34
- },
35
- });
36
- return new Server(api, response.data);
37
- }
38
- constructor(api, data) {
39
- super(api, data, `/v1/servers/${data.id}`);
40
- Object.defineProperty(this, "eventManager", {
41
- enumerable: true,
42
- configurable: true,
43
- writable: true,
44
- value: new EventManager()
45
- });
46
- Object.defineProperty(this, "consoleHistory", {
47
- enumerable: true,
48
- configurable: true,
49
- writable: true,
50
- value: createSubscription([], (_, update) => {
51
- function updateHistory(message) {
52
- update((history) => {
53
- history.push(message);
54
- if (history.length > 1024) {
55
- history.shift();
56
- }
57
- return history;
58
- });
59
- }
60
- this.eventManager.on('console_output', updateHistory);
61
- return () => this.eventManager.off('console_output', updateHistory);
62
- })
63
- });
64
- Object.defineProperty(this, "connection", {
65
- enumerable: true,
66
- configurable: true,
67
- writable: true,
68
- value: void 0
69
- });
70
- Object.defineProperty(this, "ids", {
71
- enumerable: true,
72
- configurable: true,
73
- writable: true,
74
- value: []
75
- });
76
- Object.defineProperty(this, "profiles", {
77
- enumerable: true,
78
- configurable: true,
79
- writable: true,
80
- value: new ServerProfileManager(this.api, this)
81
- });
82
- Object.defineProperty(this, "files", {
83
- enumerable: true,
84
- configurable: true,
85
- writable: true,
86
- value: new ServerFileManager(this.api, this)
87
- });
88
- }
89
- applyResponse(oldData, newData) {
90
- const response = {
91
- group: oldData?.group ??
92
- new CachedRelation(() => ServerGroup.get(this.api, newData.group_id)),
93
- egg: oldData?.egg ??
94
- new CachedRelation(() => Egg.get(this.api, newData.egg_id)),
95
- status: oldData?.status ?? new ServerStatsEvent(this, newData.status),
96
- startup: oldData?.startup ??
97
- new CachedRelation(async () => {
98
- const response = await this.fetchSelf(['startup']);
99
- return new StartupParameters(response.startup);
100
- }),
101
- allocations: oldData?.allocations ??
102
- new CachedRelation(() => ServerAllocations.get(this.api, this, newData.id)),
103
- build: oldData?.build ??
104
- new CachedRelation(() => this.fetchSelf(['build']).then((v) => v.build)),
105
- };
106
- newData.group &&
107
- response.group.setCache(new ServerGroup(this.api, newData.group));
108
- newData.status &&
109
- this.eventManager?.dispatch('power', new PowerStateEvent(newData.status.state));
110
- newData.startup &&
111
- response.startup.setCache(new StartupParameters(newData.startup));
112
- newData.allocations &&
113
- response.allocations.setCache(new ServerAllocations(this.api, this, newData.allocations));
114
- newData.build && response.build.setCache(newData.build);
115
- newData.profiles && this.profiles.addCached(newData.profiles);
116
- return response;
117
- }
118
- on(event, func) {
119
- return this.eventManager.on(event, func);
120
- }
121
- off(event, func) {
122
- return this.eventManager.off(event, func);
123
- }
124
- subscribe(fn) {
125
- const ids = [];
126
- const update = () => fn(this);
127
- update();
128
- ids.push(this.eventManager.on('stats', (event) => {
129
- this.response.status = event; // received from node
130
- update();
131
- }));
132
- ids.push(this.eventManager.on('meta_details', update));
133
- ids.push(this.eventManager.on('startup_details', update));
134
- return () => {
135
- ids.forEach(this.eventManager.off.bind(this.eventManager));
136
- };
137
- }
138
- async connect(options) {
139
- if (this.connection?.isConnected)
140
- return;
141
- // TODO: Support for Websocket connections
142
- // Have auto-adjustment to connect to WebSocket first and SSE as fallback
143
- // Manually adjustable in the panel settings
144
- this.connection = new SseServerConnection(this);
145
- if (options?.logger)
146
- this.connection.logger = options.logger;
147
- this.ids.push(this.connection.on('console_output', (event) => {
148
- this.eventManager.dispatch('console_output', event.join('\n'));
149
- }));
150
- this.ids.push(this.connection.on('status', (event) => {
151
- this.eventManager.dispatch('power', new PowerStateEvent(event[0]));
152
- }));
153
- this.ids.push(this.connection.on('stats', (event) => {
154
- const data = JSON.parse(event[0]);
155
- const stats = new ServerStatsEvent(this, {
156
- state: data.state,
157
- utilization: {
158
- cpu_absolute: data.cpu_absolute,
159
- disk_bytes: data.disk_bytes,
160
- memory_bytes: data.memory_bytes,
161
- memory_limit_bytes: data.memory_limit_bytes,
162
- network: data.network,
163
- uptime: data.uptime,
164
- state: data.state,
165
- },
166
- });
167
- this.eventManager.dispatch('stats', stats);
168
- }));
169
- await this.connection.connect();
170
- }
171
- async disconnect() {
172
- if (!this.connection)
173
- return;
174
- await this.connection.disconnect();
175
- this.ids.forEach(this.connection.off.bind(this.connection));
176
- this.ids.length = 0;
177
- this.connection = undefined;
178
- }
179
- get isConnected() {
180
- return this.connection?.isConnected;
181
- }
182
- async getNode() {
183
- return await this.group.get().then((v) => v.node.get());
184
- }
185
- async requestNodeApi(method, path, data = {}) {
186
- const node = await this.getNode();
187
- const { connection } = node;
188
- if (!connection)
189
- throw new Error('No permission to connect to server');
190
- const url = new URL(connection.url);
191
- url.pathname = `/api/servers/${this.id}${path}`;
192
- return this.api.requestUrl(method, url, data);
193
- }
194
- async updateDetails(details) {
195
- const response = await this.callPatch(details);
196
- this.response.name = response.name;
197
- this.response.description = response.description;
198
- this.response.notes = response.notes;
199
- this.eventManager.dispatch('meta_details', this);
200
- }
201
- async updateStartup(startup) {
202
- const response = await this.callPatch({ startup });
203
- const startupParameters = new StartupParameters(response.startup);
204
- this.response.startup.setCache(startupParameters);
205
- this.eventManager.dispatch('startup_details', startupParameters);
206
- }
207
- /**
208
- * Get the status of the server such as its power state status and utilization.
209
- *
210
- * Calling this will also update the current power status subscription of the server.
211
- */
212
- async getStatus() {
213
- const response = await this.api.request('GET', `/v1/servers/${this.id}/status`);
214
- this.eventManager.dispatch('power', new PowerStateEvent(response.data.state));
215
- return response.data;
216
- }
217
- /**
218
- * Get the current power status state of the server.
219
- *
220
- * This function is an alias for the `getStatus` function.
221
- */
222
- async getPowerState() {
223
- const status = await this.getStatus();
224
- return status.state;
225
- }
226
- /**
227
- * Send a power signal to the server.
228
- */
229
- async sendPowerSignal(state) {
230
- await this.requestNodeApi('POST', '/power', { body: { action: state } });
231
- await this.getPowerState();
232
- }
233
- /**
234
- * Send one or multiple commands to the server.
235
- *
236
- * The server must be in the running state for this to work.
237
- */
238
- async sendCommand(command) {
239
- const commands = typeof command === 'string' ? [command] : command;
240
- await this.requestNodeApi('POST', '/commands', { body: { commands } });
241
- }
242
- async getActivityLogs(pagination, include, query) {
243
- return await this.api
244
- .request('GET', `/v1/servers/${this.id}/activities`, {
245
- pagination,
246
- params: {
247
- include: include?.join(','),
248
- query,
249
- },
250
- })
251
- .then((v) => ({
252
- logs: v.data.map((v) => new ServerActivityLog(this.api, this, v)),
253
- page: v.page,
254
- }));
255
- }
256
- async getActivityLog(id) {
257
- return await this.api
258
- .request('GET', `/v1/servers/${this.id}/activities/${id}`)
259
- .then((v) => new ServerActivityLog(this.api, this, v.data));
260
- }
261
- // TODO: standardize search functions into one argument
262
- async getActivityJobs(pagination, include, query) {
263
- return await this.api
264
- .request('GET', `/v1/servers/${this.id}/activities/jobs`, {
265
- pagination,
266
- params: {
267
- include: include?.join(','),
268
- query,
269
- },
270
- })
271
- .then((v) => ({
272
- jobs: v.data.map((v) => new ServerActivityJob(this.api, this, v)),
273
- page: v.page,
274
- }));
275
- }
276
- async getActivityJob(id) {
277
- return await this.api
278
- .request('GET', `/v1/servers/${this.id}/activities/jobs/${id}`)
279
- .then((v) => new ServerActivityJob(this.api, this, v.data));
280
- }
281
- async getSftpDetails() {
282
- return await this.api
283
- .request('GET', `/v1/servers/${this.id}/sftp`)
284
- .then((v) => v.data.connection);
285
- }
286
- async getSftpUsers(pagination, include, query) {
287
- return await this.api
288
- .request('GET', `/v1/servers/${this.id}/sftp/users`, {
289
- pagination,
290
- params: {
291
- include: include?.join(','),
292
- query,
293
- },
294
- })
295
- .then((v) => ({
296
- users: v.data.map((v) => new SftpUser(this.api, this, v)),
297
- page: v.page,
298
- }));
299
- }
300
- async getAllocations(pagination, include, query) {
301
- return await this.api
302
- .request('GET', `/v1/servers/${this.id}/allocations`, {
303
- pagination,
304
- params: {
305
- include: include?.join(','),
306
- query,
307
- },
308
- })
309
- .then((v) => ({
310
- allocations: v.data.map((v) => new ServerAllocationPort(this.api, this, v)),
311
- page: v.page,
312
- }));
313
- }
314
- //> Accessors
315
- get id() {
316
- return this.response.id;
317
- }
318
- get name() {
319
- return this.response.name;
320
- }
321
- get description() {
322
- return this.response.description;
323
- }
324
- get notes() {
325
- return this.response.notes;
326
- }
327
- get group() {
328
- return this.response.group;
329
- }
330
- get restrictedState() {
331
- return this.response.restricted_state;
332
- }
333
- get egg() {
334
- return this.response.egg;
335
- }
336
- get build() {
337
- return this.response.build;
338
- }
339
- get allocations() {
340
- return this.response.allocations;
341
- }
342
- get status() {
343
- return this.response.status;
344
- }
345
- // TODO: Add SFTP Credentials
346
- // public get sftp() {
347
- // return this.updatable.sftp;
348
- // }
349
- get startup() {
350
- return this.response.startup;
351
- }
352
- get createdAt() {
353
- return this.response.created_at;
354
- }
355
- get updatedAt() {
356
- return this.response.updated_at;
357
- }
358
- }