@meowpanel/api 0.1.0-alpha.10

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 (148) hide show
  1. package/LICENSE +21 -0
  2. package/esm/api.d.ts +76 -0
  3. package/esm/api.d.ts.map +1 -0
  4. package/esm/api.js +187 -0
  5. package/esm/components/auth.d.ts +15 -0
  6. package/esm/components/auth.d.ts.map +1 -0
  7. package/esm/components/auth.js +13 -0
  8. package/esm/components/connection/abstract.d.ts +23 -0
  9. package/esm/components/connection/abstract.d.ts.map +1 -0
  10. package/esm/components/connection/abstract.js +43 -0
  11. package/esm/components/connection/sse.d.ts +20 -0
  12. package/esm/components/connection/sse.d.ts.map +1 -0
  13. package/esm/components/connection/sse.js +65 -0
  14. package/esm/components/egg/egg.d.ts +32 -0
  15. package/esm/components/egg/egg.d.ts.map +1 -0
  16. package/esm/components/egg/egg.js +70 -0
  17. package/esm/components/group.d.ts +14 -0
  18. package/esm/components/group.d.ts.map +1 -0
  19. package/esm/components/group.js +33 -0
  20. package/esm/components/member_2.d.ts +69 -0
  21. package/esm/components/member_2.d.ts.map +1 -0
  22. package/esm/components/member_2.js +140 -0
  23. package/esm/components/node.d.ts +78 -0
  24. package/esm/components/node.d.ts.map +1 -0
  25. package/esm/components/node.js +342 -0
  26. package/esm/components/server/activity.d.ts +45 -0
  27. package/esm/components/server/activity.d.ts.map +1 -0
  28. package/esm/components/server/activity.js +158 -0
  29. package/esm/components/server/allocations.d.ts +45 -0
  30. package/esm/components/server/allocations.d.ts.map +1 -0
  31. package/esm/components/server/allocations.js +146 -0
  32. package/esm/components/server/files.d.ts +50 -0
  33. package/esm/components/server/files.d.ts.map +1 -0
  34. package/esm/components/server/files.js +90 -0
  35. package/esm/components/server/power.d.ts +21 -0
  36. package/esm/components/server/power.d.ts.map +1 -0
  37. package/esm/components/server/power.js +43 -0
  38. package/esm/components/server/profiles.d.ts +63 -0
  39. package/esm/components/server/profiles.d.ts.map +1 -0
  40. package/esm/components/server/profiles.js +163 -0
  41. package/esm/components/server/server.d.ts +141 -0
  42. package/esm/components/server/server.d.ts.map +1 -0
  43. package/esm/components/server/server.js +358 -0
  44. package/esm/components/server/sftp.d.ts +31 -0
  45. package/esm/components/server/sftp.d.ts.map +1 -0
  46. package/esm/components/server/sftp.js +84 -0
  47. package/esm/components/server/startup.d.ts +17 -0
  48. package/esm/components/server/startup.d.ts.map +1 -0
  49. package/esm/components/server/startup.js +21 -0
  50. package/esm/components/server/stats.d.ts +19 -0
  51. package/esm/components/server/stats.d.ts.map +1 -0
  52. package/esm/components/server/stats.js +46 -0
  53. package/esm/mod.d.ts +2 -0
  54. package/esm/mod.d.ts.map +1 -0
  55. package/esm/mod.js +1 -0
  56. package/esm/package.json +3 -0
  57. package/esm/utils/cache.d.ts +20 -0
  58. package/esm/utils/cache.d.ts.map +1 -0
  59. package/esm/utils/cache.js +66 -0
  60. package/esm/utils/event.d.ts +38 -0
  61. package/esm/utils/event.d.ts.map +1 -0
  62. package/esm/utils/event.js +71 -0
  63. package/esm/utils/object.d.ts +58 -0
  64. package/esm/utils/object.d.ts.map +1 -0
  65. package/esm/utils/object.js +86 -0
  66. package/esm/utils/subscribe.d.ts +37 -0
  67. package/esm/utils/subscribe.d.ts.map +1 -0
  68. package/esm/utils/subscribe.js +29 -0
  69. package/esm/utils/timer.d.ts +13 -0
  70. package/esm/utils/timer.d.ts.map +1 -0
  71. package/esm/utils/timer.js +32 -0
  72. package/esm/utils/units.d.ts +18 -0
  73. package/esm/utils/units.d.ts.map +1 -0
  74. package/esm/utils/units.js +82 -0
  75. package/package.json +107 -0
  76. package/script/api.d.ts +76 -0
  77. package/script/api.d.ts.map +1 -0
  78. package/script/api.js +192 -0
  79. package/script/components/auth.d.ts +15 -0
  80. package/script/components/auth.d.ts.map +1 -0
  81. package/script/components/auth.js +17 -0
  82. package/script/components/connection/abstract.d.ts +23 -0
  83. package/script/components/connection/abstract.d.ts.map +1 -0
  84. package/script/components/connection/abstract.js +47 -0
  85. package/script/components/connection/sse.d.ts +20 -0
  86. package/script/components/connection/sse.d.ts.map +1 -0
  87. package/script/components/connection/sse.js +69 -0
  88. package/script/components/egg/egg.d.ts +32 -0
  89. package/script/components/egg/egg.d.ts.map +1 -0
  90. package/script/components/egg/egg.js +74 -0
  91. package/script/components/group.d.ts +14 -0
  92. package/script/components/group.d.ts.map +1 -0
  93. package/script/components/group.js +37 -0
  94. package/script/components/member_2.d.ts +69 -0
  95. package/script/components/member_2.d.ts.map +1 -0
  96. package/script/components/member_2.js +146 -0
  97. package/script/components/node.d.ts +78 -0
  98. package/script/components/node.d.ts.map +1 -0
  99. package/script/components/node.js +349 -0
  100. package/script/components/server/activity.d.ts +45 -0
  101. package/script/components/server/activity.d.ts.map +1 -0
  102. package/script/components/server/activity.js +164 -0
  103. package/script/components/server/allocations.d.ts +45 -0
  104. package/script/components/server/allocations.d.ts.map +1 -0
  105. package/script/components/server/allocations.js +152 -0
  106. package/script/components/server/files.d.ts +50 -0
  107. package/script/components/server/files.d.ts.map +1 -0
  108. package/script/components/server/files.js +94 -0
  109. package/script/components/server/power.d.ts +21 -0
  110. package/script/components/server/power.d.ts.map +1 -0
  111. package/script/components/server/power.js +47 -0
  112. package/script/components/server/profiles.d.ts +63 -0
  113. package/script/components/server/profiles.d.ts.map +1 -0
  114. package/script/components/server/profiles.js +168 -0
  115. package/script/components/server/server.d.ts +141 -0
  116. package/script/components/server/server.d.ts.map +1 -0
  117. package/script/components/server/server.js +362 -0
  118. package/script/components/server/sftp.d.ts +31 -0
  119. package/script/components/server/sftp.d.ts.map +1 -0
  120. package/script/components/server/sftp.js +88 -0
  121. package/script/components/server/startup.d.ts +17 -0
  122. package/script/components/server/startup.d.ts.map +1 -0
  123. package/script/components/server/startup.js +25 -0
  124. package/script/components/server/stats.d.ts +19 -0
  125. package/script/components/server/stats.d.ts.map +1 -0
  126. package/script/components/server/stats.js +50 -0
  127. package/script/mod.d.ts +2 -0
  128. package/script/mod.d.ts.map +1 -0
  129. package/script/mod.js +5 -0
  130. package/script/package.json +3 -0
  131. package/script/utils/cache.d.ts +20 -0
  132. package/script/utils/cache.d.ts.map +1 -0
  133. package/script/utils/cache.js +70 -0
  134. package/script/utils/event.d.ts +38 -0
  135. package/script/utils/event.d.ts.map +1 -0
  136. package/script/utils/event.js +75 -0
  137. package/script/utils/object.d.ts +58 -0
  138. package/script/utils/object.d.ts.map +1 -0
  139. package/script/utils/object.js +90 -0
  140. package/script/utils/subscribe.d.ts +37 -0
  141. package/script/utils/subscribe.d.ts.map +1 -0
  142. package/script/utils/subscribe.js +32 -0
  143. package/script/utils/timer.d.ts +13 -0
  144. package/script/utils/timer.d.ts.map +1 -0
  145. package/script/utils/timer.js +36 -0
  146. package/script/utils/units.d.ts +18 -0
  147. package/script/utils/units.d.ts.map +1 -0
  148. package/script/utils/units.js +86 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 - Present HostVenom, LLC. DBA WinterNode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/esm/api.d.ts ADDED
@@ -0,0 +1,76 @@
1
+ import { AuthApi } from './components/auth.js';
2
+ import { ServerGroup } from './components/group.js';
3
+ import { Member, type MemberInclude } from './components/member_2.js';
4
+ import { Node, type NodeInclude } from './components/node.js';
5
+ import { Server, type ServerInclude } from './components/server/server.js';
6
+ import { type EventFunction, EventManager, type EventManagerListener } from './utils/event.js';
7
+ export declare class ApiError extends Error {
8
+ readonly error: string;
9
+ readonly status: number;
10
+ constructor(response: Response, error: string);
11
+ }
12
+ export interface MainEvents {
13
+ error: ApiError;
14
+ }
15
+ export interface MeowPanelApiRequestData {
16
+ body?: Record<string, unknown> | FormData | ArrayBuffer | string;
17
+ params?: Record<string, string | undefined>;
18
+ }
19
+ export declare class MeowPanelApi implements EventManagerListener<MainEvents> {
20
+ private static isPlainJson;
21
+ protected readonly url: string | URL;
22
+ protected readonly token: string | undefined;
23
+ protected readonly fetch: typeof fetch;
24
+ protected readonly eventManager: EventManager<MainEvents>;
25
+ on<K extends keyof MainEvents>(event: K, func: EventFunction<MainEvents, K>): number;
26
+ off<K extends keyof MainEvents>(event: K, func: number | EventFunction<MainEvents, K>): boolean;
27
+ requestUrl(method: string, url: URL | string, data?: MeowPanelApiRequestData): Promise<Response>;
28
+ request<T>(method: string, endpoint: `/${string}`, init?: {
29
+ body?: Record<string, unknown>;
30
+ pagination?: Pagination;
31
+ params?: Record<string, string | undefined>;
32
+ }): Promise<ApiResponse<T>>;
33
+ constructor(options: Options);
34
+ /**
35
+ * Fetches the current logged in account
36
+ */
37
+ me(include?: MemberInclude[]): Promise<Member>;
38
+ readonly members: {
39
+ list: (pagination: Pagination) => Promise<{
40
+ data: Member[];
41
+ page: Page | undefined;
42
+ }>;
43
+ get: (id: string) => Promise<Member>;
44
+ };
45
+ readonly getNode: (id: string, include?: NodeInclude[]) => Promise<Node>;
46
+ readonly getServers: (page: number, include?: ServerInclude[], query?: string) => Promise<{
47
+ servers: Server[];
48
+ page: Page;
49
+ }>;
50
+ readonly getServer: (id: string, include?: ServerInclude[]) => Promise<Server>;
51
+ readonly getServerGroups: (page: number) => Promise<{
52
+ groups: ServerGroup[];
53
+ page: Page;
54
+ }>;
55
+ readonly getServerGroup: (id: string) => Promise<ServerGroup>;
56
+ readonly auth: AuthApi;
57
+ }
58
+ export interface Options {
59
+ url: string | URL;
60
+ token?: string;
61
+ fetch?: typeof fetch;
62
+ }
63
+ export interface ApiResponse<T> {
64
+ data: T;
65
+ page?: Page;
66
+ }
67
+ export interface Pagination {
68
+ page: number;
69
+ perPage?: number;
70
+ }
71
+ export interface Page {
72
+ total: number;
73
+ from: number;
74
+ to: number;
75
+ }
76
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"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"}
package/esm/api.js ADDED
@@ -0,0 +1,187 @@
1
+ import { AuthApi } from './components/auth.js';
2
+ import { ServerGroup } from './components/group.js';
3
+ import { Member } from './components/member_2.js';
4
+ import { Node } from './components/node.js';
5
+ import { Server } from './components/server/server.js';
6
+ import { EventManager } from './utils/event.js';
7
+ export class ApiError extends Error {
8
+ constructor(response, error) {
9
+ super(`${response.status}: ${error}`);
10
+ Object.defineProperty(this, "error", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: error
15
+ });
16
+ Object.defineProperty(this, "status", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ this.status = response.status;
23
+ }
24
+ }
25
+ export class MeowPanelApi {
26
+ static isPlainJson(value) {
27
+ return typeof value === 'object' && value !== null &&
28
+ value.constructor === Object;
29
+ }
30
+ on(event, func) {
31
+ return this.eventManager.on(event, func);
32
+ }
33
+ off(event, func) {
34
+ return this.eventManager.off(event, func);
35
+ }
36
+ async requestUrl(method, url, data = {}) {
37
+ const headers = {};
38
+ if (this.token) {
39
+ headers.Authorization = `Bearer ${this.token}`;
40
+ }
41
+ const requestUrl = new URL(url.toString());
42
+ if (data.params) {
43
+ for (const [key, value] of Object.entries(data.params)) {
44
+ if (value !== undefined) {
45
+ requestUrl.searchParams.set(key, value);
46
+ }
47
+ }
48
+ }
49
+ const response = await this.fetch(requestUrl, {
50
+ body: MeowPanelApi.isPlainJson(data.body) ? JSON.stringify(data.body) : data.body,
51
+ credentials: 'include',
52
+ headers,
53
+ method,
54
+ });
55
+ if (!response.ok) {
56
+ let message;
57
+ try {
58
+ const json = await response.json();
59
+ message = json.error;
60
+ }
61
+ catch (_) {
62
+ console.warn('Failed to parse error response');
63
+ message = 'Unknown error';
64
+ }
65
+ const error = new ApiError(response, message);
66
+ this.eventManager.dispatch('error', error);
67
+ throw error;
68
+ }
69
+ return response;
70
+ }
71
+ async request(method, endpoint, init = {}) {
72
+ const url = new URL(this.url.toString());
73
+ url.pathname = `${url.pathname}/${endpoint}`.replace(/\/+/g, '/');
74
+ if (init.params) {
75
+ Object.entries(init.params).forEach(([key, value]) => value !== undefined && url.searchParams.set(key, value));
76
+ }
77
+ init.pagination &&
78
+ url.searchParams.set('page', `${init.pagination.page}`);
79
+ init.pagination?.perPage &&
80
+ url.searchParams.set('perPage', `${init.pagination.perPage}`);
81
+ const response = await this.requestUrl(method, url.toString(), init);
82
+ if (response.status === 204)
83
+ return {};
84
+ const json = await response.json();
85
+ let page = undefined;
86
+ if (init.pagination) {
87
+ const contentRange = response.headers.get('content-range');
88
+ if (!contentRange) {
89
+ throw new Error('Expected content-range header not found');
90
+ }
91
+ const [range, total] = contentRange.split('/') ??
92
+ ['items 0-0', '0'];
93
+ const [from, to] = range.split(' ')[1].split('-').map(Number);
94
+ page = { total: Number(total), from, to };
95
+ }
96
+ return {
97
+ page,
98
+ data: json,
99
+ };
100
+ }
101
+ constructor(options) {
102
+ Object.defineProperty(this, "url", {
103
+ enumerable: true,
104
+ configurable: true,
105
+ writable: true,
106
+ value: void 0
107
+ });
108
+ Object.defineProperty(this, "token", {
109
+ enumerable: true,
110
+ configurable: true,
111
+ writable: true,
112
+ value: void 0
113
+ });
114
+ Object.defineProperty(this, "fetch", {
115
+ enumerable: true,
116
+ configurable: true,
117
+ writable: true,
118
+ value: void 0
119
+ });
120
+ Object.defineProperty(this, "eventManager", {
121
+ enumerable: true,
122
+ configurable: true,
123
+ writable: true,
124
+ value: new EventManager()
125
+ });
126
+ Object.defineProperty(this, "members", {
127
+ enumerable: true,
128
+ configurable: true,
129
+ writable: true,
130
+ value: {
131
+ list: (pagination) => Member.list(this, pagination),
132
+ get: (id) => Member.get(this, id),
133
+ }
134
+ });
135
+ Object.defineProperty(this, "getNode", {
136
+ enumerable: true,
137
+ configurable: true,
138
+ writable: true,
139
+ value: (id, include) => Node.get(this, id, include)
140
+ });
141
+ Object.defineProperty(this, "getServers", {
142
+ enumerable: true,
143
+ configurable: true,
144
+ writable: true,
145
+ value: (page, include, query) => Server.getPaged(this, page, include, query)
146
+ });
147
+ Object.defineProperty(this, "getServer", {
148
+ enumerable: true,
149
+ configurable: true,
150
+ writable: true,
151
+ value: (id, include) => Server.get(this, id, include)
152
+ });
153
+ Object.defineProperty(this, "getServerGroups", {
154
+ enumerable: true,
155
+ configurable: true,
156
+ writable: true,
157
+ value: (page) => ServerGroup.getPaged(this, page)
158
+ });
159
+ Object.defineProperty(this, "getServerGroup", {
160
+ enumerable: true,
161
+ configurable: true,
162
+ writable: true,
163
+ value: (id) => ServerGroup.get(this, id)
164
+ });
165
+ Object.defineProperty(this, "auth", {
166
+ enumerable: true,
167
+ configurable: true,
168
+ writable: true,
169
+ value: new AuthApi(this)
170
+ });
171
+ this.url = options.url;
172
+ this.token = options.token;
173
+ this.fetch = options.fetch ?? fetch;
174
+ }
175
+ /**
176
+ * Fetches the current logged in account
177
+ */
178
+ // TODO: update to accept API key response
179
+ async me(include) {
180
+ const response = await this.request('GET', '/v1/account', {
181
+ params: {
182
+ include: include?.join(','),
183
+ },
184
+ });
185
+ return new Member(this, response.data);
186
+ }
187
+ }
@@ -0,0 +1,15 @@
1
+ import type { MeowPanelApi } from '../mod.js';
2
+ import type { ApiResponse } from '../api.js';
3
+ export interface AuthProvider {
4
+ fields: Record<string, string>;
5
+ url: string;
6
+ }
7
+ export interface AuthGetMeta {
8
+ providers: Record<string, AuthProvider>;
9
+ }
10
+ export declare class AuthApi {
11
+ protected readonly api: MeowPanelApi;
12
+ getMeta(): Promise<ApiResponse<AuthGetMeta>>;
13
+ constructor(api: MeowPanelApi);
14
+ }
15
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/components/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,WAAW;IAC3B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACxC;AAED,qBAAa,OAAO;IAKA,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,YAAY;IAJ1C,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;gBAInB,GAAG,EAAE,YAAY;CACvD"}
@@ -0,0 +1,13 @@
1
+ export class AuthApi {
2
+ async getMeta() {
3
+ return await this.api.request('GET', '/v1/auth');
4
+ }
5
+ constructor(api) {
6
+ Object.defineProperty(this, "api", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: api
11
+ });
12
+ }
13
+ }
@@ -0,0 +1,23 @@
1
+ import { type EventFunction, EventManager, type EventManagerListener } from '../../utils/event.js';
2
+ import type { Server } from '../server/server.js';
3
+ import type { NodeServerEvents } from './node';
4
+ export declare abstract class ServerConnection implements EventManagerListener<NodeServerEvents> {
5
+ protected readonly subSystemName: string;
6
+ protected readonly server: Server;
7
+ constructor(subSystemName: string, server: Server);
8
+ readonly eventManager: EventManager<NodeServerEvents>;
9
+ on<K extends keyof NodeServerEvents>(event: K, func: EventFunction<NodeServerEvents, K>): number;
10
+ off<K extends keyof NodeServerEvents>(event: K | number, func?: EventFunction<NodeServerEvents, K> | number): boolean;
11
+ abstract connect(): Promise<void> | void;
12
+ abstract disconnect(): Promise<void> | void;
13
+ abstract isConnected: boolean;
14
+ logger: Logger;
15
+ private log;
16
+ }
17
+ export interface Logger {
18
+ debug: (message: string) => void;
19
+ info: (message: string) => void;
20
+ warn: (message: string) => void;
21
+ error: (message: string) => void;
22
+ }
23
+ //# sourceMappingURL=abstract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract.d.ts","sourceRoot":"","sources":["../../../src/components/connection/abstract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAE/C,8BAAsB,gBAAiB,YAAW,oBAAoB,CAAC,gBAAgB,CAAC;IAEtF,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM;IACxC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;gBADd,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM;IAGlC,SAAgB,YAAY,iCAAwC;IAC7D,EAAE,CAAC,CAAC,SAAS,MAAM,gBAAgB,EACzC,KAAK,EAAE,CAAC,EACR,IAAI,EAAE,aAAa,CAAC,gBAAgB,EAAE,CAAC,CAAC,GACtC,MAAM;IAIF,GAAG,CAAC,CAAC,SAAS,MAAM,gBAAgB,EAC1C,KAAK,EAAE,CAAC,GAAG,MAAM,EACjB,IAAI,CAAC,EAAE,aAAa,CAAC,gBAAgB,EAAE,CAAC,CAAC,GAAG,MAAM,GAChD,OAAO;aAIM,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;aAC/B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAClD,SAAgB,WAAW,EAAE,OAAO,CAAC;IAE9B,MAAM,EAAE,MAAM,CAKnB;IAEF,OAAO,CAAC,GAAG;CAGX;AAED,MAAM,WAAW,MAAM;IACtB,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC"}
@@ -0,0 +1,43 @@
1
+ import { EventManager } from '../../utils/event.js';
2
+ export class ServerConnection {
3
+ constructor(subSystemName, server) {
4
+ Object.defineProperty(this, "subSystemName", {
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true,
8
+ value: subSystemName
9
+ });
10
+ Object.defineProperty(this, "server", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: server
15
+ });
16
+ Object.defineProperty(this, "eventManager", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: new EventManager()
21
+ });
22
+ Object.defineProperty(this, "logger", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: {
27
+ debug: (message) => this.log('debug', message),
28
+ info: (message) => this.log('info', message),
29
+ warn: (message) => this.log('warn', message),
30
+ error: (message) => this.log('error', message),
31
+ }
32
+ });
33
+ }
34
+ on(event, func) {
35
+ return this.eventManager.on(event, func);
36
+ }
37
+ off(event, func) {
38
+ return this.eventManager.off(event, func);
39
+ }
40
+ log(level, message) {
41
+ console[level](`[${this.server.id}/${this.subSystemName}] ${message}`);
42
+ }
43
+ }
@@ -0,0 +1,20 @@
1
+ import type { EventFunction } from '../../utils/event.js';
2
+ import type { Server } from '../server/server.js';
3
+ import { ServerConnection } from './abstract.js';
4
+ import type { NodeServerEvents } from './node';
5
+ export declare class SseServerConnection extends ServerConnection {
6
+ private eventSource;
7
+ constructor(server: Server);
8
+ connect(): Promise<void>;
9
+ disconnect(): void;
10
+ get isConnected(): boolean;
11
+ protected readonly eventSourceListenerTracker: Array<{
12
+ id: number;
13
+ func: EventFunction<NodeServerEvents, keyof NodeServerEvents>;
14
+ wrapper: (message: MessageEvent) => unknown;
15
+ }>;
16
+ protected registerEventToSource<K extends keyof NodeServerEvents>(event: K, id: number, func: (value: NodeServerEvents[K]) => unknown): void;
17
+ on<K extends keyof NodeServerEvents>(event: K, func: EventFunction<NodeServerEvents, K>): number;
18
+ off<K extends keyof NodeServerEvents>(event: K, func: number | EventFunction<NodeServerEvents, K>): boolean;
19
+ }
20
+ //# sourceMappingURL=sse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/components/connection/sse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAE/C,qBAAa,mBAAoB,SAAQ,gBAAgB;IACxD,OAAO,CAAC,WAAW,CAA0B;gBAE1B,MAAM,EAAE,MAAM;IAIpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB9B,UAAU,IAAI,IAAI;IAOzB,IAAoB,WAAW,YAG9B;IAED,SAAS,CAAC,QAAQ,CAAC,0BAA0B,EAAE,KAAK,CAAC;QACpD,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,aAAa,CAAC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC,CAAC;QAC9D,OAAO,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC;KAC5C,CAAC,CAAM;IAER,SAAS,CAAC,qBAAqB,CAAC,CAAC,SAAS,MAAM,gBAAgB,EAC/D,KAAK,EAAE,CAAC,EACR,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,OAAO,GAC3C,IAAI;IASS,EAAE,CAAC,CAAC,SAAS,MAAM,gBAAgB,EAClD,KAAK,EAAE,CAAC,EACR,IAAI,EAAE,aAAa,CAAC,gBAAgB,EAAE,CAAC,CAAC,GACtC,MAAM;IAMO,GAAG,CAAC,CAAC,SAAS,MAAM,gBAAgB,EACnD,KAAK,EAAE,CAAC,EACR,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC,gBAAgB,EAAE,CAAC,CAAC,GAC/C,OAAO;CAUV"}
@@ -0,0 +1,65 @@
1
+ import { ServerConnection } from './abstract.js';
2
+ export class SseServerConnection extends ServerConnection {
3
+ constructor(server) {
4
+ super('sse', server);
5
+ Object.defineProperty(this, "eventSource", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: void 0
10
+ });
11
+ Object.defineProperty(this, "eventSourceListenerTracker", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: []
16
+ });
17
+ }
18
+ async connect() {
19
+ this.disconnect();
20
+ this.logger.debug('Connecting to SSE');
21
+ const group = await this.server.group.get();
22
+ const node = await group.node.get();
23
+ const { connection } = node; // TODO: use Cache Relation for connection
24
+ if (!connection)
25
+ throw new Error('No permission to connect to server');
26
+ const url = new URL(connection.url);
27
+ url.pathname = `/api/servers/${this.server.id}/sse`;
28
+ this.eventSource = new EventSource(url, { withCredentials: true });
29
+ this.logger.info('Connected to SSE');
30
+ this.eventManager.assignAllEvents((event, id, func) => this.registerEventToSource(event, id, func));
31
+ }
32
+ disconnect() {
33
+ if (!this.eventSource)
34
+ return;
35
+ this.logger.info('Closing SSE connection');
36
+ this.eventSource.close();
37
+ this.eventSource = undefined;
38
+ }
39
+ get isConnected() {
40
+ return !!this.eventSource &&
41
+ this.eventSource.readyState === EventSource.OPEN;
42
+ }
43
+ registerEventToSource(event, id, func) {
44
+ if (!this.eventSource)
45
+ return;
46
+ const wrapper = (message) => func(JSON.parse(message.data));
47
+ this.eventSource.addEventListener(event, wrapper);
48
+ this.eventSourceListenerTracker.push({ id, func, wrapper });
49
+ this.logger.debug(`Registered: ${event}`);
50
+ }
51
+ on(event, func) {
52
+ const id = super.on(event, func);
53
+ this.registerEventToSource(event, id, func);
54
+ return id;
55
+ }
56
+ off(event, func) {
57
+ const i = this.eventSourceListenerTracker.findIndex((v) => v.id === func || v.func === func);
58
+ if (i >= 0) {
59
+ const { wrapper } = this.eventSourceListenerTracker[i];
60
+ this.eventSource?.removeEventListener(event, wrapper);
61
+ this.eventSourceListenerTracker.splice(i, 1);
62
+ }
63
+ return super.off(event, func);
64
+ }
65
+ }
@@ -0,0 +1,32 @@
1
+ import type { MeowPanelApi, Page } from '../../api.js';
2
+ import { CachedRelation } from '../../utils/cache.js';
3
+ import { UpdatableObject } from '../../utils/object.js';
4
+ import type { Subscription } from '../../utils/subscribe.js';
5
+ import type { Extended } from '../../utils/types';
6
+ export type EggInclude = 'app_background_url';
7
+ interface Modified {
8
+ app_background_url: CachedRelation<string | null>;
9
+ }
10
+ export declare class Egg extends UpdatableObject<EggResponse, Modified, EggInclude> implements Subscription<Egg> {
11
+ static getPaged(api: MeowPanelApi, page: number, include?: EggInclude[]): Promise<{
12
+ groups: Egg[];
13
+ page: Page;
14
+ }>;
15
+ static get(api: MeowPanelApi, id: string, include?: EggInclude[]): Promise<Egg>;
16
+ constructor(api: MeowPanelApi, data: EggResponse);
17
+ protected applyResponse(oldData: Extended<EggResponse, Modified> | undefined, _newData: EggResponse): Modified;
18
+ subscribe(_fn: (value: Egg) => void): () => void;
19
+ get id(): string;
20
+ get name(): string;
21
+ get description(): string;
22
+ get appBackgroundUrl(): CachedRelation<string | null>;
23
+ get nest(): string;
24
+ get images(): EggDockerImage[];
25
+ get startupCommand(): string;
26
+ get stopCommand(): string;
27
+ get forceOutgoingIp(): boolean;
28
+ get createdAt(): string;
29
+ get updatedAt(): string;
30
+ }
31
+ export {};
32
+ //# sourceMappingURL=egg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"egg.d.ts","sourceRoot":"","sources":["../../../src/components/egg/egg.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,UAAU,GAAG,oBAAoB,CAAC;AAE9C,UAAU,QAAQ;IACjB,kBAAkB,EAAE,cAAc,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAClD;AAED,qBAAa,GAAI,SAAQ,eAAe,CAAC,WAAW,EAAE,QAAQ,EAAE,UAAU,CAAE,YAAW,YAAY,CAAC,GAAG,CAAC;WACnF,QAAQ,CAC3B,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,UAAU,EAAO,GACxB,OAAO,CAAC;QAAE,MAAM,EAAE,GAAG,EAAE,CAAC;QAAC,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC;WAYrB,GAAG,CACtB,GAAG,EAAE,YAAY,EACjB,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,UAAU,EAAO,GACxB,OAAO,CAAC,GAAG,CAAC;gBAQI,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW;cAIpC,aAAa,CAC/B,OAAO,EAAE,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,SAAS,EACpD,QAAQ,EAAE,WAAW,GACnB,QAAQ;IAWJ,SAAS,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,GAAG,MAAM,IAAI;IAIvD,IAAW,EAAE,IAAI,MAAM,CAEtB;IAED,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,WAAW,IAAI,MAAM,CAE/B;IAED,IAAW,gBAAgB,IAAI,cAAc,CAAC,MAAM,GAAG,IAAI,CAAC,CAE3D;IAED,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,MAAM,IAAI,cAAc,EAAE,CAEpC;IAED,IAAW,cAAc,IAAI,MAAM,CAElC;IAED,IAAW,WAAW,IAAI,MAAM,CAE/B;IAED,IAAW,eAAe,IAAI,OAAO,CAEpC;IAED,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED,IAAW,SAAS,IAAI,MAAM,CAE7B;CACD"}
@@ -0,0 +1,70 @@
1
+ /// <reference path="./egg.d.ts" />
2
+ import { CachedRelation } from '../../utils/cache.js';
3
+ import { UpdatableObject } from '../../utils/object.js';
4
+ export class Egg extends UpdatableObject {
5
+ static async getPaged(api, page, include = []) {
6
+ const response = await api.request('GET', `/v1/eggs`, {
7
+ pagination: { page },
8
+ params: { include: include?.join(',') },
9
+ });
10
+ return {
11
+ groups: response.data.map((data) => new Egg(api, data)),
12
+ page: response.page,
13
+ };
14
+ }
15
+ static async get(api, id, include = []) {
16
+ const response = await api.request('GET', `/v1/eggs/${id}`, {
17
+ params: { include: include?.join(',') },
18
+ });
19
+ return new Egg(api, response.data);
20
+ }
21
+ constructor(api, data) {
22
+ super(api, data, `/v1/eggs/${data.id}`);
23
+ }
24
+ applyResponse(oldData, _newData) {
25
+ const response = {
26
+ app_background_url: oldData?.app_background_url ??
27
+ new CachedRelation(async () => {
28
+ const response = await this.fetchSelf(['app_background_url']);
29
+ return response.app_background_url;
30
+ }),
31
+ };
32
+ return response;
33
+ }
34
+ subscribe(_fn) {
35
+ throw new Error('Method not implemented.');
36
+ }
37
+ get id() {
38
+ return this.response.id;
39
+ }
40
+ get name() {
41
+ return this.response.name;
42
+ }
43
+ get description() {
44
+ return this.response.description;
45
+ }
46
+ get appBackgroundUrl() {
47
+ return this.response.app_background_url;
48
+ }
49
+ get nest() {
50
+ return this.response.nest;
51
+ }
52
+ get images() {
53
+ return this.response.images;
54
+ }
55
+ get startupCommand() {
56
+ return this.response.startup_command;
57
+ }
58
+ get stopCommand() {
59
+ return this.response.stop_command;
60
+ }
61
+ get forceOutgoingIp() {
62
+ return this.response.force_outgoing_ip;
63
+ }
64
+ get createdAt() {
65
+ return this.response.created_at;
66
+ }
67
+ get updatedAt() {
68
+ return this.response.updated_at;
69
+ }
70
+ }
@@ -0,0 +1,14 @@
1
+ import type { MeowPanelApi, Page } from '../api.js';
2
+ import { CachedRelation } from '../utils/cache.js';
3
+ import { Node } from './node.js';
4
+ export declare class ServerGroup {
5
+ protected readonly api: MeowPanelApi;
6
+ static getPaged(api: MeowPanelApi, page: number): Promise<{
7
+ groups: ServerGroup[];
8
+ page: Page;
9
+ }>;
10
+ static get(api: MeowPanelApi, id: string): Promise<ServerGroup>;
11
+ constructor(api: MeowPanelApi, data: Record<string, never>);
12
+ readonly node: CachedRelation<Node>;
13
+ }
14
+ //# sourceMappingURL=group.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/components/group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,qBAAa,WAAW;IA0BtB,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,YAAY;WAzBjB,QAAQ,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,WAAW,EAAE,CAAC;QAAC,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC;WAezF,GAAG,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;gBAUxD,GAAG,EAAE,YAAY,EACpC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IAM5B,SAAgB,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;CAC3C"}
@@ -0,0 +1,33 @@
1
+ import { CachedRelation } from '../utils/cache.js';
2
+ import { Node } from './node.js';
3
+ export class ServerGroup {
4
+ static async getPaged(api, page) {
5
+ const response = await api.request('GET', `/v1/servers/groups`, {
6
+ pagination: { page },
7
+ });
8
+ return {
9
+ groups: response.data.map((data) => new ServerGroup(api, data)),
10
+ page: response.page,
11
+ };
12
+ }
13
+ static async get(api, id) {
14
+ const response = await api.request('GET', `/v1/servers/groups/${id}`);
15
+ return new ServerGroup(api, response.data);
16
+ }
17
+ constructor(api, data) {
18
+ Object.defineProperty(this, "api", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: api
23
+ });
24
+ Object.defineProperty(this, "node", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ this.node = new CachedRelation(() => Node.get(api, data.node_id, ['connection']));
31
+ this.node.setCache(data.node);
32
+ }
33
+ }