@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.
- package/LICENSE +1 -1
- package/README.md +40 -0
- package/esm/mod.d.ts +87 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +85 -1
- package/esm/src/client.d.ts +248 -0
- package/esm/src/client.d.ts.map +1 -0
- package/esm/src/client.js +235 -0
- package/esm/src/emitter.d.ts +53 -0
- package/esm/src/emitter.d.ts.map +1 -0
- package/esm/src/emitter.js +55 -0
- package/esm/src/errors.d.ts +42 -0
- package/esm/src/errors.d.ts.map +1 -0
- package/esm/src/errors.js +45 -0
- package/esm/src/http.d.ts +157 -0
- package/esm/src/http.d.ts.map +1 -0
- package/esm/src/http.js +317 -0
- package/esm/src/namespace.d.ts +59 -0
- package/esm/src/namespace.d.ts.map +1 -0
- package/esm/src/namespace.js +79 -0
- package/esm/src/reactive.d.ts +29 -0
- package/esm/src/reactive.d.ts.map +1 -0
- package/esm/src/reactive.js +35 -0
- package/esm/src/resources/account.d.ts +125 -0
- package/esm/src/resources/account.d.ts.map +1 -0
- package/esm/src/resources/account.js +151 -0
- package/esm/src/resources/api-keys.d.ts +116 -0
- package/esm/src/resources/api-keys.d.ts.map +1 -0
- package/esm/src/resources/api-keys.js +105 -0
- package/esm/src/resources/auth.d.ts +57 -0
- package/esm/src/resources/auth.d.ts.map +1 -0
- package/esm/src/resources/auth.js +39 -0
- package/esm/src/resources/eggs.d.ts +238 -0
- package/esm/src/resources/eggs.d.ts.map +1 -0
- package/esm/src/resources/eggs.js +187 -0
- package/esm/src/resources/hosts.d.ts +62 -0
- package/esm/src/resources/hosts.d.ts.map +1 -0
- package/esm/src/resources/hosts.js +62 -0
- package/esm/src/resources/members.d.ts +138 -0
- package/esm/src/resources/members.d.ts.map +1 -0
- package/esm/src/resources/members.js +122 -0
- package/esm/src/resources/nodes.d.ts +397 -0
- package/esm/src/resources/nodes.d.ts.map +1 -0
- package/esm/src/resources/nodes.js +352 -0
- package/esm/src/resources/server-groups.d.ts +150 -0
- package/esm/src/resources/server-groups.d.ts.map +1 -0
- package/esm/src/resources/server-groups.js +111 -0
- package/esm/src/resources/servers/activity.d.ts +120 -0
- package/esm/src/resources/servers/activity.d.ts.map +1 -0
- package/esm/src/resources/servers/activity.js +163 -0
- package/esm/src/resources/servers/allocations.d.ts +125 -0
- package/esm/src/resources/servers/allocations.d.ts.map +1 -0
- package/esm/src/resources/servers/allocations.js +137 -0
- package/esm/src/resources/servers/connection.d.ts +108 -0
- package/esm/src/resources/servers/connection.d.ts.map +1 -0
- package/esm/src/resources/servers/connection.js +169 -0
- package/esm/src/resources/servers/files.d.ts +164 -0
- package/esm/src/resources/servers/files.d.ts.map +1 -0
- package/esm/src/resources/servers/files.js +281 -0
- package/esm/src/resources/servers/index.d.ts +126 -0
- package/esm/src/resources/servers/index.d.ts.map +1 -0
- package/esm/src/resources/servers/index.js +135 -0
- package/esm/src/resources/servers/profiles.d.ts +138 -0
- package/esm/src/resources/servers/profiles.d.ts.map +1 -0
- package/esm/src/resources/servers/profiles.js +177 -0
- package/esm/src/resources/servers/server.d.ts +136 -0
- package/esm/src/resources/servers/server.d.ts.map +1 -0
- package/esm/src/resources/servers/server.js +202 -0
- package/esm/src/resources/servers/sftp.d.ts +147 -0
- package/esm/src/resources/servers/sftp.d.ts.map +1 -0
- package/esm/src/resources/servers/sftp.js +153 -0
- package/esm/src/resources/servers/types.d.ts +199 -0
- package/esm/src/resources/servers/types.d.ts.map +1 -0
- package/esm/src/resources/servers/types.js +1 -0
- package/esm/src/sse.d.ts +53 -0
- package/esm/src/sse.d.ts.map +1 -0
- package/esm/src/sse.js +133 -0
- package/esm/src/types.d.ts +126 -0
- package/esm/src/types.d.ts.map +1 -0
- package/esm/src/types.js +21 -0
- package/package.json +4 -92
- package/script/mod.d.ts +87 -1
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +132 -3
- package/script/src/client.d.ts +248 -0
- package/script/src/client.d.ts.map +1 -0
- package/script/src/client.js +239 -0
- package/script/src/emitter.d.ts +53 -0
- package/script/src/emitter.d.ts.map +1 -0
- package/script/src/emitter.js +59 -0
- package/script/src/errors.d.ts +42 -0
- package/script/src/errors.d.ts.map +1 -0
- package/script/src/errors.js +49 -0
- package/script/src/http.d.ts +157 -0
- package/script/src/http.d.ts.map +1 -0
- package/script/src/http.js +321 -0
- package/script/src/namespace.d.ts +59 -0
- package/script/src/namespace.d.ts.map +1 -0
- package/script/src/namespace.js +83 -0
- package/script/src/reactive.d.ts +29 -0
- package/script/src/reactive.d.ts.map +1 -0
- package/script/src/reactive.js +39 -0
- package/script/src/resources/account.d.ts +125 -0
- package/script/src/resources/account.d.ts.map +1 -0
- package/script/src/resources/account.js +158 -0
- package/script/src/resources/api-keys.d.ts +116 -0
- package/script/src/resources/api-keys.d.ts.map +1 -0
- package/script/src/resources/api-keys.js +110 -0
- package/script/src/resources/auth.d.ts +57 -0
- package/script/src/resources/auth.d.ts.map +1 -0
- package/script/src/resources/auth.js +43 -0
- package/script/src/resources/eggs.d.ts +238 -0
- package/script/src/resources/eggs.d.ts.map +1 -0
- package/script/src/resources/eggs.js +193 -0
- package/script/src/resources/hosts.d.ts +62 -0
- package/script/src/resources/hosts.d.ts.map +1 -0
- package/script/src/resources/hosts.js +67 -0
- package/script/src/resources/members.d.ts +138 -0
- package/script/src/resources/members.d.ts.map +1 -0
- package/script/src/resources/members.js +127 -0
- package/script/src/resources/nodes.d.ts +397 -0
- package/script/src/resources/nodes.d.ts.map +1 -0
- package/script/src/resources/nodes.js +362 -0
- package/script/src/resources/server-groups.d.ts +150 -0
- package/script/src/resources/server-groups.d.ts.map +1 -0
- package/script/src/resources/server-groups.js +116 -0
- package/script/src/resources/servers/activity.d.ts +120 -0
- package/script/src/resources/servers/activity.d.ts.map +1 -0
- package/script/src/resources/servers/activity.js +170 -0
- package/script/src/resources/servers/allocations.d.ts +125 -0
- package/script/src/resources/servers/allocations.d.ts.map +1 -0
- package/script/src/resources/servers/allocations.js +142 -0
- package/script/src/resources/servers/connection.d.ts +108 -0
- package/script/src/resources/servers/connection.d.ts.map +1 -0
- package/script/src/resources/servers/connection.js +173 -0
- package/script/src/resources/servers/files.d.ts +164 -0
- package/script/src/resources/servers/files.d.ts.map +1 -0
- package/script/src/resources/servers/files.js +286 -0
- package/script/src/resources/servers/index.d.ts +126 -0
- package/script/src/resources/servers/index.d.ts.map +1 -0
- package/script/src/resources/servers/index.js +139 -0
- package/script/src/resources/servers/profiles.d.ts +138 -0
- package/script/src/resources/servers/profiles.d.ts.map +1 -0
- package/script/src/resources/servers/profiles.js +182 -0
- package/script/src/resources/servers/server.d.ts +136 -0
- package/script/src/resources/servers/server.d.ts.map +1 -0
- package/script/src/resources/servers/server.js +206 -0
- package/script/src/resources/servers/sftp.d.ts +147 -0
- package/script/src/resources/servers/sftp.d.ts.map +1 -0
- package/script/src/resources/servers/sftp.js +158 -0
- package/script/src/resources/servers/types.d.ts +199 -0
- package/script/src/resources/servers/types.d.ts.map +1 -0
- package/script/src/resources/servers/types.js +2 -0
- package/script/src/sse.d.ts +53 -0
- package/script/src/sse.d.ts.map +1 -0
- package/script/src/sse.js +137 -0
- package/script/src/types.d.ts +126 -0
- package/script/src/types.d.ts.map +1 -0
- package/script/src/types.js +25 -0
- package/esm/api.d.ts +0 -76
- package/esm/api.d.ts.map +0 -1
- package/esm/api.js +0 -187
- package/esm/components/auth.d.ts +0 -15
- package/esm/components/auth.d.ts.map +0 -1
- package/esm/components/auth.js +0 -13
- package/esm/components/connection/abstract.d.ts +0 -23
- package/esm/components/connection/abstract.d.ts.map +0 -1
- package/esm/components/connection/abstract.js +0 -43
- package/esm/components/connection/sse.d.ts +0 -20
- package/esm/components/connection/sse.d.ts.map +0 -1
- package/esm/components/connection/sse.js +0 -65
- package/esm/components/egg/egg.d.ts +0 -32
- package/esm/components/egg/egg.d.ts.map +0 -1
- package/esm/components/egg/egg.js +0 -70
- package/esm/components/group.d.ts +0 -14
- package/esm/components/group.d.ts.map +0 -1
- package/esm/components/group.js +0 -33
- package/esm/components/member_2.d.ts +0 -69
- package/esm/components/member_2.d.ts.map +0 -1
- package/esm/components/member_2.js +0 -140
- package/esm/components/node.d.ts +0 -78
- package/esm/components/node.d.ts.map +0 -1
- package/esm/components/node.js +0 -342
- package/esm/components/server/activity.d.ts +0 -45
- package/esm/components/server/activity.d.ts.map +0 -1
- package/esm/components/server/activity.js +0 -158
- package/esm/components/server/allocations.d.ts +0 -45
- package/esm/components/server/allocations.d.ts.map +0 -1
- package/esm/components/server/allocations.js +0 -146
- package/esm/components/server/files.d.ts +0 -50
- package/esm/components/server/files.d.ts.map +0 -1
- package/esm/components/server/files.js +0 -90
- package/esm/components/server/power.d.ts +0 -21
- package/esm/components/server/power.d.ts.map +0 -1
- package/esm/components/server/power.js +0 -43
- package/esm/components/server/profiles.d.ts +0 -63
- package/esm/components/server/profiles.d.ts.map +0 -1
- package/esm/components/server/profiles.js +0 -163
- package/esm/components/server/server.d.ts +0 -141
- package/esm/components/server/server.d.ts.map +0 -1
- package/esm/components/server/server.js +0 -358
- package/esm/components/server/sftp.d.ts +0 -31
- package/esm/components/server/sftp.d.ts.map +0 -1
- package/esm/components/server/sftp.js +0 -84
- package/esm/components/server/startup.d.ts +0 -17
- package/esm/components/server/startup.d.ts.map +0 -1
- package/esm/components/server/startup.js +0 -21
- package/esm/components/server/stats.d.ts +0 -19
- package/esm/components/server/stats.d.ts.map +0 -1
- package/esm/components/server/stats.js +0 -46
- package/esm/utils/cache.d.ts +0 -20
- package/esm/utils/cache.d.ts.map +0 -1
- package/esm/utils/cache.js +0 -66
- package/esm/utils/event.d.ts +0 -38
- package/esm/utils/event.d.ts.map +0 -1
- package/esm/utils/event.js +0 -71
- package/esm/utils/object.d.ts +0 -58
- package/esm/utils/object.d.ts.map +0 -1
- package/esm/utils/object.js +0 -86
- package/esm/utils/subscribe.d.ts +0 -37
- package/esm/utils/subscribe.d.ts.map +0 -1
- package/esm/utils/subscribe.js +0 -29
- package/esm/utils/timer.d.ts +0 -13
- package/esm/utils/timer.d.ts.map +0 -1
- package/esm/utils/timer.js +0 -32
- package/esm/utils/units.d.ts +0 -18
- package/esm/utils/units.d.ts.map +0 -1
- package/esm/utils/units.js +0 -82
- package/script/api.d.ts +0 -76
- package/script/api.d.ts.map +0 -1
- package/script/api.js +0 -192
- package/script/components/auth.d.ts +0 -15
- package/script/components/auth.d.ts.map +0 -1
- package/script/components/auth.js +0 -17
- package/script/components/connection/abstract.d.ts +0 -23
- package/script/components/connection/abstract.d.ts.map +0 -1
- package/script/components/connection/abstract.js +0 -47
- package/script/components/connection/sse.d.ts +0 -20
- package/script/components/connection/sse.d.ts.map +0 -1
- package/script/components/connection/sse.js +0 -69
- package/script/components/egg/egg.d.ts +0 -32
- package/script/components/egg/egg.d.ts.map +0 -1
- package/script/components/egg/egg.js +0 -74
- package/script/components/group.d.ts +0 -14
- package/script/components/group.d.ts.map +0 -1
- package/script/components/group.js +0 -37
- package/script/components/member_2.d.ts +0 -69
- package/script/components/member_2.d.ts.map +0 -1
- package/script/components/member_2.js +0 -146
- package/script/components/node.d.ts +0 -78
- package/script/components/node.d.ts.map +0 -1
- package/script/components/node.js +0 -349
- package/script/components/server/activity.d.ts +0 -45
- package/script/components/server/activity.d.ts.map +0 -1
- package/script/components/server/activity.js +0 -164
- package/script/components/server/allocations.d.ts +0 -45
- package/script/components/server/allocations.d.ts.map +0 -1
- package/script/components/server/allocations.js +0 -152
- package/script/components/server/files.d.ts +0 -50
- package/script/components/server/files.d.ts.map +0 -1
- package/script/components/server/files.js +0 -94
- package/script/components/server/power.d.ts +0 -21
- package/script/components/server/power.d.ts.map +0 -1
- package/script/components/server/power.js +0 -47
- package/script/components/server/profiles.d.ts +0 -63
- package/script/components/server/profiles.d.ts.map +0 -1
- package/script/components/server/profiles.js +0 -168
- package/script/components/server/server.d.ts +0 -141
- package/script/components/server/server.d.ts.map +0 -1
- package/script/components/server/server.js +0 -362
- package/script/components/server/sftp.d.ts +0 -31
- package/script/components/server/sftp.d.ts.map +0 -1
- package/script/components/server/sftp.js +0 -88
- package/script/components/server/startup.d.ts +0 -17
- package/script/components/server/startup.d.ts.map +0 -1
- package/script/components/server/startup.js +0 -25
- package/script/components/server/stats.d.ts +0 -19
- package/script/components/server/stats.d.ts.map +0 -1
- package/script/components/server/stats.js +0 -50
- package/script/utils/cache.d.ts +0 -20
- package/script/utils/cache.d.ts.map +0 -1
- package/script/utils/cache.js +0 -70
- package/script/utils/event.d.ts +0 -38
- package/script/utils/event.d.ts.map +0 -1
- package/script/utils/event.js +0 -75
- package/script/utils/object.d.ts +0 -58
- package/script/utils/object.d.ts.map +0 -1
- package/script/utils/object.js +0 -90
- package/script/utils/subscribe.d.ts +0 -37
- package/script/utils/subscribe.d.ts.map +0 -1
- package/script/utils/subscribe.js +0 -32
- package/script/utils/timer.d.ts +0 -13
- package/script/utils/timer.d.ts.map +0 -1
- package/script/utils/timer.js +0 -36
- package/script/utils/units.d.ts +0 -18
- package/script/utils/units.d.ts.map +0 -1
- 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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CAAC;IAKnE;;;;;;;;;;;OAWG;IACU,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAI1D"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { ReactiveResource } from '../../reactive.js';
|
|
2
|
+
import { toNanoID } from '../../types.js';
|
|
3
|
+
import { Egg } from '../eggs.js';
|
|
4
|
+
import { ServerGroup } from '../server-groups.js';
|
|
5
|
+
import { ServerActivityManager } from './activity.js';
|
|
6
|
+
import { ServerAllocationsManager } from './allocations.js';
|
|
7
|
+
import { ServerConnection } from './connection.js';
|
|
8
|
+
import { ServerFilesManager } from './files.js';
|
|
9
|
+
import { ServerProfilesManager } from './profiles.js';
|
|
10
|
+
import { ServerSftpManager } from './sftp.js';
|
|
11
|
+
/**
|
|
12
|
+
* A MeowPanel game server.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts ignore
|
|
16
|
+
* const server = await api.servers.get(id, { include: ['status', 'startup'] });
|
|
17
|
+
* server.status; // ServerStatus (guaranteed by include)
|
|
18
|
+
*
|
|
19
|
+
* await server.sendPower('start');
|
|
20
|
+
* await server.sendCommand('say Hello!');
|
|
21
|
+
*
|
|
22
|
+
* const conn = await server.createConnection();
|
|
23
|
+
* conn.on('console_output', (line) => console.log(line));
|
|
24
|
+
* await conn.open();
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export class Server extends ReactiveResource {
|
|
28
|
+
http;
|
|
29
|
+
resolveNodeUrl;
|
|
30
|
+
onMutated;
|
|
31
|
+
id;
|
|
32
|
+
name;
|
|
33
|
+
description;
|
|
34
|
+
/** Only visible with `server.notes.read` permission. */
|
|
35
|
+
notes;
|
|
36
|
+
/** When non-null, overrides the node's reported power state for display. */
|
|
37
|
+
restrictedState;
|
|
38
|
+
groupId;
|
|
39
|
+
eggId;
|
|
40
|
+
eggImageId;
|
|
41
|
+
/** Populated with `include=group`. */
|
|
42
|
+
group;
|
|
43
|
+
/** Populated with `include=egg`. */
|
|
44
|
+
egg;
|
|
45
|
+
eggImageOverride;
|
|
46
|
+
/** Populated with `include=status`. Use {@link getStatus} to fetch on demand. */
|
|
47
|
+
status;
|
|
48
|
+
/** Populated with `include=build`. */
|
|
49
|
+
build;
|
|
50
|
+
/** Populated with `include=startup`. */
|
|
51
|
+
startup;
|
|
52
|
+
/** Populated with `include=allocations`. */
|
|
53
|
+
allocationPorts;
|
|
54
|
+
createdAt;
|
|
55
|
+
updatedAt;
|
|
56
|
+
allocations;
|
|
57
|
+
sftp;
|
|
58
|
+
profiles;
|
|
59
|
+
activity;
|
|
60
|
+
files;
|
|
61
|
+
/** @internal */
|
|
62
|
+
constructor(data, http, resolveNodeUrl, onMutated) {
|
|
63
|
+
super();
|
|
64
|
+
this.http = http;
|
|
65
|
+
this.resolveNodeUrl = resolveNodeUrl;
|
|
66
|
+
this.onMutated = onMutated;
|
|
67
|
+
this.id = toNanoID(data.id);
|
|
68
|
+
this.groupId = toNanoID(data.group_id);
|
|
69
|
+
this.eggId = toNanoID(data.egg_id);
|
|
70
|
+
this.allocations = new ServerAllocationsManager(this.id, http);
|
|
71
|
+
this.sftp = new ServerSftpManager(this.id, http);
|
|
72
|
+
this.profiles = new ServerProfilesManager(this.id, http);
|
|
73
|
+
this.activity = new ServerActivityManager(this.id, http);
|
|
74
|
+
this.files = new ServerFilesManager(this.id, http.getToken(), resolveNodeUrl);
|
|
75
|
+
this.applyData(data);
|
|
76
|
+
}
|
|
77
|
+
/** Apply raw API data, updating all mutable fields. */
|
|
78
|
+
applyData(data) {
|
|
79
|
+
this.name = data.name;
|
|
80
|
+
this.description = data.description;
|
|
81
|
+
this.notes = data.notes;
|
|
82
|
+
this.restrictedState = data.restricted_state;
|
|
83
|
+
this.eggImageId = data.egg_image_id ? toNanoID(data.egg_image_id) : undefined;
|
|
84
|
+
this.eggImageOverride = data.egg_image_override;
|
|
85
|
+
// Include-gated fields: only overwrite if present in response
|
|
86
|
+
if (data.group)
|
|
87
|
+
this.group = new ServerGroup(data.group);
|
|
88
|
+
if (data.egg)
|
|
89
|
+
this.egg = new Egg(data.egg);
|
|
90
|
+
if (data.status !== undefined) {
|
|
91
|
+
this.status = data.status ? parseStatus(data.status) : undefined;
|
|
92
|
+
}
|
|
93
|
+
if (data.build !== undefined) {
|
|
94
|
+
this.build = data.build ? parseBuild(data.build) : undefined;
|
|
95
|
+
}
|
|
96
|
+
if (data.startup !== undefined) {
|
|
97
|
+
this.startup = data.startup
|
|
98
|
+
? {
|
|
99
|
+
command: data.startup.command,
|
|
100
|
+
variables: Object.fromEntries(Object.entries(data.startup.variables).map(([k, v]) => [
|
|
101
|
+
k,
|
|
102
|
+
{ key: k, ...v, default: v.default },
|
|
103
|
+
])),
|
|
104
|
+
}
|
|
105
|
+
: undefined;
|
|
106
|
+
}
|
|
107
|
+
if (data.allocations !== undefined) {
|
|
108
|
+
this.allocationPorts = data.allocations ?? undefined;
|
|
109
|
+
}
|
|
110
|
+
this.createdAt = new Date(data.created_at);
|
|
111
|
+
this.updatedAt = new Date(data.updated_at);
|
|
112
|
+
this.notify();
|
|
113
|
+
}
|
|
114
|
+
/** Update this server's details, startup config, or primary allocation. */
|
|
115
|
+
async update(payload) {
|
|
116
|
+
const body = {};
|
|
117
|
+
if (payload.name !== undefined)
|
|
118
|
+
body['name'] = payload.name;
|
|
119
|
+
if (payload.description !== undefined) {
|
|
120
|
+
body['description'] = payload.description;
|
|
121
|
+
}
|
|
122
|
+
if (payload.notes !== undefined)
|
|
123
|
+
body['notes'] = payload.notes;
|
|
124
|
+
if (payload.allocationPrimary) {
|
|
125
|
+
body['allocation_primary'] = payload.allocationPrimary;
|
|
126
|
+
}
|
|
127
|
+
if (payload.startup) {
|
|
128
|
+
body['startup'] = {
|
|
129
|
+
command: payload.startup.command,
|
|
130
|
+
variables: payload.startup.variables,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const data = await this.http.patch(`/servers/${this.id}`, body);
|
|
134
|
+
this.applyData(data);
|
|
135
|
+
this.onMutated();
|
|
136
|
+
}
|
|
137
|
+
/** Fetch current power state and utilization from the node. */
|
|
138
|
+
async getStatus() {
|
|
139
|
+
const data = await this.http.get(`/servers/${this.id}/status`);
|
|
140
|
+
return parseStatus(data);
|
|
141
|
+
}
|
|
142
|
+
/** Send a power signal: `start`, `stop`, `restart`, or `kill`. */
|
|
143
|
+
async sendPower(signal) {
|
|
144
|
+
await this.http.post(`/servers/${this.id}/power`, { signal });
|
|
145
|
+
}
|
|
146
|
+
/** Send one or more console commands. */
|
|
147
|
+
async sendCommand(command) {
|
|
148
|
+
const commands = Array.isArray(command) ? command : [command];
|
|
149
|
+
await this.http.post(`/servers/${this.id}/commands`, { commands });
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create a real-time SSE connection to this server's node daemon.
|
|
153
|
+
*
|
|
154
|
+
* Not yet open - call {@link ServerConnection.open} to start streaming.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts ignore
|
|
158
|
+
* const conn = await server.createConnection();
|
|
159
|
+
* conn.on('stats', ({ cpuAbsolute }) => console.log(`CPU: ${cpuAbsolute}%`));
|
|
160
|
+
* await conn.open();
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
async createConnection() {
|
|
164
|
+
const nodeUrl = await this.resolveNodeUrl();
|
|
165
|
+
return new ServerConnection(this.id, nodeUrl, this.http.getToken());
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function parseStatus(data) {
|
|
169
|
+
return {
|
|
170
|
+
state: data.state,
|
|
171
|
+
utilization: data.utilization
|
|
172
|
+
? {
|
|
173
|
+
memoryBytes: data.utilization.memory_bytes,
|
|
174
|
+
memoryLimitBytes: data.utilization.memory_limit_bytes,
|
|
175
|
+
cpuAbsolute: data.utilization.cpu_absolute,
|
|
176
|
+
networkRxBytes: data.utilization.network.rx_bytes,
|
|
177
|
+
networkTxBytes: data.utilization.network.tx_bytes,
|
|
178
|
+
uptimeSeconds: data.utilization.uptime,
|
|
179
|
+
diskBytes: data.utilization.disk_bytes,
|
|
180
|
+
}
|
|
181
|
+
: null,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function parseBuild(data) {
|
|
185
|
+
return {
|
|
186
|
+
cpuThreads: data.cpu_threads,
|
|
187
|
+
ioWeight: data.io_weight,
|
|
188
|
+
oomType: data.oom_type,
|
|
189
|
+
skipInstallScripts: data.skip_install_scripts,
|
|
190
|
+
limits: data.limits
|
|
191
|
+
? {
|
|
192
|
+
cpuPercent: data.limits.cpu_percent,
|
|
193
|
+
ramMb: data.limits.ram_mb,
|
|
194
|
+
swapMb: data.limits.swap_mb,
|
|
195
|
+
storageMb: data.limits.storage_mb,
|
|
196
|
+
allocation: data.limits.allocation,
|
|
197
|
+
database: data.limits.database,
|
|
198
|
+
backup: data.limits.backup,
|
|
199
|
+
}
|
|
200
|
+
: data.limits,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
@@ -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.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;;;;OAOG;IACU,MAAM,CAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC;KACzC,GACC,OAAO,CAAC,QAAQ,CAAC;IAQpB;;;;OAIG;IACU,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlD"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { ReactiveResource } from '../../reactive.js';
|
|
2
|
+
import { joinIncludes, toNanoID } from '../../types.js';
|
|
3
|
+
import { Member } from '../members.js';
|
|
4
|
+
/**
|
|
5
|
+
* An SFTP user credential scoped to a specific server with path-level permissions.
|
|
6
|
+
*
|
|
7
|
+
* Retrieved via {@link ServerSftpManager.list} or {@link ServerSftpManager.create}.
|
|
8
|
+
*
|
|
9
|
+
* > **Note:** The `password` field is automatically included in the creation response.
|
|
10
|
+
* > On subsequent fetches it requires `include=password` to be populated.
|
|
11
|
+
*/
|
|
12
|
+
export class SftpUser extends ReactiveResource {
|
|
13
|
+
/** The SFTP user's unique NanoID. */
|
|
14
|
+
id;
|
|
15
|
+
/** Display name for this SFTP user. */
|
|
16
|
+
name;
|
|
17
|
+
/** The SFTP login username (typically prefixed with the server ID). */
|
|
18
|
+
username;
|
|
19
|
+
/**
|
|
20
|
+
* The plaintext password.
|
|
21
|
+
*
|
|
22
|
+
* Automatically included on creation. Requires `include=password` on subsequent fetches.
|
|
23
|
+
*/
|
|
24
|
+
password;
|
|
25
|
+
/**
|
|
26
|
+
* A map of path glob patterns to the set of permissions granted for that path.
|
|
27
|
+
*
|
|
28
|
+
* Keys are glob patterns (e.g. `"/"`, `"/logs/*"`).
|
|
29
|
+
* Values are arrays of {@link SftpPermission} scopes.
|
|
30
|
+
*/
|
|
31
|
+
paths;
|
|
32
|
+
/** NanoID of the member who owns this SFTP user. */
|
|
33
|
+
ownerId;
|
|
34
|
+
/** The owner member. */
|
|
35
|
+
owner;
|
|
36
|
+
/** When this SFTP user last logged in, or `null` if never. */
|
|
37
|
+
lastLoginAt;
|
|
38
|
+
/** When this SFTP user was created. */
|
|
39
|
+
createdAt;
|
|
40
|
+
/** When this SFTP user was last updated. */
|
|
41
|
+
updatedAt;
|
|
42
|
+
/** @internal */
|
|
43
|
+
constructor(data) {
|
|
44
|
+
super();
|
|
45
|
+
this.id = toNanoID(data.id);
|
|
46
|
+
this.name = data.name;
|
|
47
|
+
this.username = data.username;
|
|
48
|
+
this.password = data.password;
|
|
49
|
+
this.paths = data.paths;
|
|
50
|
+
this.ownerId = toNanoID(data.owner_id);
|
|
51
|
+
this.owner = data.owner ? new Member(data.owner) : data.owner;
|
|
52
|
+
this.lastLoginAt = data.last_login_at ? new Date(data.last_login_at) : null;
|
|
53
|
+
this.createdAt = new Date(data.created_at);
|
|
54
|
+
this.updatedAt = new Date(data.updated_at);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Manages SFTP users and credentials for a specific server.
|
|
59
|
+
*
|
|
60
|
+
* Access via `server.sftp`.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts ignore
|
|
64
|
+
* const details = await server.sftp.details();
|
|
65
|
+
* console.log(`Connect to: ${details.connection.url}`);
|
|
66
|
+
*
|
|
67
|
+
* const user = await server.sftp.create('deploy', {
|
|
68
|
+
* '/': ['sftp.content.list', 'sftp.content.read'],
|
|
69
|
+
* '/logs': ['sftp.content.list', 'sftp.content.read', 'sftp.content.delete'],
|
|
70
|
+
* });
|
|
71
|
+
* console.log(user.password); // Save this!
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export class ServerSftpManager {
|
|
75
|
+
serverId;
|
|
76
|
+
http;
|
|
77
|
+
/** @internal */
|
|
78
|
+
constructor(serverId, http) {
|
|
79
|
+
this.serverId = serverId;
|
|
80
|
+
this.http = http;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Fetch the SFTP connection details and all SFTP users for this server.
|
|
84
|
+
*/
|
|
85
|
+
async details() {
|
|
86
|
+
const data = await this.http.get(`/servers/${this.serverId}/sftp`);
|
|
87
|
+
return {
|
|
88
|
+
connection: data.connection,
|
|
89
|
+
users: data.users.map((u) => new SftpUser(u)),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Fetch all SFTP users for this server without the connection details.
|
|
94
|
+
*
|
|
95
|
+
* @param opts Pagination and include options.
|
|
96
|
+
*/
|
|
97
|
+
async list(opts = {}) {
|
|
98
|
+
const extra = {};
|
|
99
|
+
const include = joinIncludes(opts);
|
|
100
|
+
if (include)
|
|
101
|
+
extra['include'] = include;
|
|
102
|
+
const result = await this.http.list(`/servers/${this.serverId}/sftp/users`, opts, extra);
|
|
103
|
+
return { ...result, data: result.data.map((d) => new SftpUser(d)) };
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Fetch a single SFTP user by ID.
|
|
107
|
+
*
|
|
108
|
+
* @param userId The SFTP user's NanoID.
|
|
109
|
+
* @param opts Include options.
|
|
110
|
+
*/
|
|
111
|
+
async get(userId, opts = {}) {
|
|
112
|
+
const params = {};
|
|
113
|
+
const include = joinIncludes(opts);
|
|
114
|
+
if (include)
|
|
115
|
+
params['include'] = include;
|
|
116
|
+
const data = await this.http.get(`/servers/${this.serverId}/sftp/users/${userId}`, { params });
|
|
117
|
+
return new SftpUser(data);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Create a new SFTP user for this server.
|
|
121
|
+
*
|
|
122
|
+
* The returned {@link SftpUser} includes the `password` field automatically.
|
|
123
|
+
* On subsequent fetches, request it explicitly with `include=password`.
|
|
124
|
+
*
|
|
125
|
+
* @param name Display name for the SFTP user.
|
|
126
|
+
* @param paths A map of path glob patterns to an array of {@link SftpPermission} scopes.
|
|
127
|
+
* At least one path with at least one permission is required.
|
|
128
|
+
*/
|
|
129
|
+
async create(name, paths) {
|
|
130
|
+
const data = await this.http.post(`/servers/${this.serverId}/sftp/users`, { name, paths });
|
|
131
|
+
return new SftpUser(data);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Update an SFTP user's name and/or path permissions.
|
|
135
|
+
*
|
|
136
|
+
* To remove a path, set its permissions array to `[]`.
|
|
137
|
+
*
|
|
138
|
+
* @param userId The SFTP user's NanoID.
|
|
139
|
+
* @param payload Fields to update.
|
|
140
|
+
*/
|
|
141
|
+
async update(userId, payload) {
|
|
142
|
+
const data = await this.http.patch(`/servers/${this.serverId}/sftp/users/${userId}`, payload);
|
|
143
|
+
return new SftpUser(data);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Delete an SFTP user permanently.
|
|
147
|
+
*
|
|
148
|
+
* @param userId The SFTP user's NanoID.
|
|
149
|
+
*/
|
|
150
|
+
async delete(userId) {
|
|
151
|
+
await this.http.delete(`/servers/${this.serverId}/sftp/users/${userId}`);
|
|
152
|
+
}
|
|
153
|
+
}
|