@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,126 @@
|
|
|
1
|
+
import type { HttpClient } from '../../http.js';
|
|
2
|
+
import { ResourceNamespace } from '../../namespace.js';
|
|
3
|
+
import type { IncludeOptions, ListOptions, NanoID, Paginated } from '../../types.js';
|
|
4
|
+
import type { ResourceWith } from '../../types.js';
|
|
5
|
+
import type { ServerBuild, ServerStartup, ServerStatus } from './server.js';
|
|
6
|
+
import { Server } from './server.js';
|
|
7
|
+
import type { ServerAllocationsData, ServerProfileData, UpdateServerPayload } from './types.js';
|
|
8
|
+
import type { Egg } from '../eggs.js';
|
|
9
|
+
import type { ServerGroup } from '../server-groups.js';
|
|
10
|
+
export type { UpdateServerPayload };
|
|
11
|
+
/**
|
|
12
|
+
* Valid include keys for server endpoints.
|
|
13
|
+
*
|
|
14
|
+
* Each include adds extra data to the response (at a small performance cost).
|
|
15
|
+
* When an include is requested, the corresponding field on {@link Server} is guaranteed
|
|
16
|
+
* to be populated (non-undefined).
|
|
17
|
+
*/
|
|
18
|
+
export type ServerInclude = 'group' | 'egg' | 'status' | 'build' | 'startup' | 'allocations' | 'profiles';
|
|
19
|
+
/**
|
|
20
|
+
* Maps each {@link ServerInclude} key to the field(s) it guarantees on the {@link Server} instance.
|
|
21
|
+
*
|
|
22
|
+
* Used by {@link ServerWith} to narrow the return type based on the requested includes.
|
|
23
|
+
*/
|
|
24
|
+
interface ServerIncludeMap {
|
|
25
|
+
group: {
|
|
26
|
+
group: ServerGroup;
|
|
27
|
+
};
|
|
28
|
+
egg: {
|
|
29
|
+
egg: Egg;
|
|
30
|
+
};
|
|
31
|
+
status: {
|
|
32
|
+
status: ServerStatus;
|
|
33
|
+
};
|
|
34
|
+
build: {
|
|
35
|
+
build: ServerBuild;
|
|
36
|
+
};
|
|
37
|
+
startup: {
|
|
38
|
+
startup: ServerStartup;
|
|
39
|
+
};
|
|
40
|
+
allocations: {
|
|
41
|
+
allocationPorts: ServerAllocationsData;
|
|
42
|
+
};
|
|
43
|
+
profiles: {
|
|
44
|
+
profiles: ServerProfileData[];
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A {@link Server} with specific include fields guaranteed to be populated.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts ignore
|
|
52
|
+
* // server.group is `ServerGroup`, not `ServerGroup | undefined`
|
|
53
|
+
* type S = ServerWith<['group', 'status']>;
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export type ServerWith<I extends readonly ServerInclude[] = []> = ResourceWith<Server, ServerIncludeMap, I>;
|
|
57
|
+
/** Payload for creating a new server. */
|
|
58
|
+
export interface CreateServerPayload {
|
|
59
|
+
name: string;
|
|
60
|
+
nodeId: NanoID;
|
|
61
|
+
description?: string;
|
|
62
|
+
notes?: string;
|
|
63
|
+
limits: {
|
|
64
|
+
ramMb: number;
|
|
65
|
+
swapMb: number;
|
|
66
|
+
storageMb: number;
|
|
67
|
+
/** IO weight (1–1000). */
|
|
68
|
+
weightIo: number;
|
|
69
|
+
cpuPercent: number;
|
|
70
|
+
cpuThreads?: string;
|
|
71
|
+
backup?: number;
|
|
72
|
+
database?: number;
|
|
73
|
+
allocation?: number;
|
|
74
|
+
};
|
|
75
|
+
eggId: NanoID;
|
|
76
|
+
allocationPrimaryId: NanoID;
|
|
77
|
+
imageOverride?: string;
|
|
78
|
+
forceOutgoingIp?: boolean;
|
|
79
|
+
oomType?: 'docker';
|
|
80
|
+
shouldSkipEggScripts?: boolean;
|
|
81
|
+
startupCommandOverride?: string;
|
|
82
|
+
expiresAt?: Date;
|
|
83
|
+
}
|
|
84
|
+
export interface ServerEvents {
|
|
85
|
+
created: Server;
|
|
86
|
+
updated: Server;
|
|
87
|
+
deleted: NanoID;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Namespace for server management.
|
|
91
|
+
*
|
|
92
|
+
* Access via `api.servers`.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts ignore
|
|
96
|
+
* // Type-safe includes: group and status are guaranteed on the result
|
|
97
|
+
* const servers = await api.servers.list({ include: ['group', 'status'] });
|
|
98
|
+
* servers.data[0].group; // ServerGroup (not undefined)
|
|
99
|
+
* servers.data[0].status; // ServerStatus (not undefined)
|
|
100
|
+
*
|
|
101
|
+
* // Without includes: include-gated fields are undefined
|
|
102
|
+
* const bare = await api.servers.list();
|
|
103
|
+
* bare.data[0].groupId; // NanoID (always present)
|
|
104
|
+
* bare.data[0].group; // ServerGroup | undefined
|
|
105
|
+
*
|
|
106
|
+
* // Events
|
|
107
|
+
* api.servers.on('created', (server) => console.log('New server:', server.name));
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare class ServersNamespace extends ResourceNamespace<Server, ServerEvents> {
|
|
111
|
+
private readonly nodeUrlCache;
|
|
112
|
+
/** @internal */
|
|
113
|
+
constructor(http: HttpClient);
|
|
114
|
+
/** Resolve the node daemon URL: groupId → nodeId → node connection URL. */
|
|
115
|
+
private resolveNodeUrl;
|
|
116
|
+
private makeServer;
|
|
117
|
+
/** Fetch a paginated list of servers. */
|
|
118
|
+
list<const I extends readonly ServerInclude[] = []>(opts?: ListOptions & IncludeOptions<ServerInclude, I>): Promise<Paginated<ServerWith<I>>>;
|
|
119
|
+
/** Fetch a single server by ID. */
|
|
120
|
+
get<const I extends readonly ServerInclude[] = []>(id: NanoID, opts?: IncludeOptions<ServerInclude, I>): Promise<ServerWith<I>>;
|
|
121
|
+
/** Create a new server (also creates its server group). */
|
|
122
|
+
create(payload: CreateServerPayload): Promise<Server>;
|
|
123
|
+
/** Update a server's details, startup config, or primary allocation. */
|
|
124
|
+
update(id: NanoID, payload: UpdateServerPayload): Promise<Server>;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/resources/servers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAErF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,EAAE,qBAAqB,EAAc,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,WAA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IAC9C,MAAM,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC;IAiClE,wEAAwE;IAC3D,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC;CA0B9E"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServersNamespace = void 0;
|
|
4
|
+
const namespace_js_1 = require("../../namespace.js");
|
|
5
|
+
const types_js_1 = require("../../types.js");
|
|
6
|
+
const server_js_1 = require("./server.js");
|
|
7
|
+
/**
|
|
8
|
+
* Namespace for server management.
|
|
9
|
+
*
|
|
10
|
+
* Access via `api.servers`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts ignore
|
|
14
|
+
* // Type-safe includes: group and status are guaranteed on the result
|
|
15
|
+
* const servers = await api.servers.list({ include: ['group', 'status'] });
|
|
16
|
+
* servers.data[0].group; // ServerGroup (not undefined)
|
|
17
|
+
* servers.data[0].status; // ServerStatus (not undefined)
|
|
18
|
+
*
|
|
19
|
+
* // Without includes: include-gated fields are undefined
|
|
20
|
+
* const bare = await api.servers.list();
|
|
21
|
+
* bare.data[0].groupId; // NanoID (always present)
|
|
22
|
+
* bare.data[0].group; // ServerGroup | undefined
|
|
23
|
+
*
|
|
24
|
+
* // Events
|
|
25
|
+
* api.servers.on('created', (server) => console.log('New server:', server.name));
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
class ServersNamespace extends namespace_js_1.ResourceNamespace {
|
|
29
|
+
nodeUrlCache = new Map();
|
|
30
|
+
/** @internal */
|
|
31
|
+
constructor(http) {
|
|
32
|
+
super(http);
|
|
33
|
+
}
|
|
34
|
+
/** Resolve the node daemon URL: groupId → nodeId → node connection URL. */
|
|
35
|
+
resolveNodeUrl(serverId, groupId) {
|
|
36
|
+
return async () => {
|
|
37
|
+
if (this.nodeUrlCache.has(serverId))
|
|
38
|
+
return this.nodeUrlCache.get(serverId);
|
|
39
|
+
// Fetch the group to get the nodeId, then the node connection URL
|
|
40
|
+
const groupData = await this.http.get(`/servers/groups/${groupId}`);
|
|
41
|
+
const nodeId = (0, types_js_1.toNanoID)(groupData.node_id);
|
|
42
|
+
const nodeData = await this.http.get(`/nodes/${nodeId}`, { params: { include: 'connection' } });
|
|
43
|
+
const url = nodeData.connection?.url;
|
|
44
|
+
if (!url)
|
|
45
|
+
throw new Error(`Node connection URL is not available for server ${serverId}`);
|
|
46
|
+
this.nodeUrlCache.set(serverId, url);
|
|
47
|
+
return url;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
makeServer(data) {
|
|
51
|
+
const id = (0, types_js_1.toNanoID)(data.id);
|
|
52
|
+
const groupId = (0, types_js_1.toNanoID)(data.group_id);
|
|
53
|
+
return new server_js_1.Server(data, this.http, this.resolveNodeUrl(id, groupId), () => this.notifySubs());
|
|
54
|
+
}
|
|
55
|
+
/** Fetch a paginated list of servers. */
|
|
56
|
+
async list(opts = {}) {
|
|
57
|
+
const extra = {};
|
|
58
|
+
const include = (0, types_js_1.joinIncludes)(opts);
|
|
59
|
+
if (include)
|
|
60
|
+
extra['include'] = include;
|
|
61
|
+
const result = await this.http.list('/servers', opts, extra);
|
|
62
|
+
const servers = result.data.map((d) => this.makeServer(d));
|
|
63
|
+
this.setCache(servers);
|
|
64
|
+
return { ...result, data: servers };
|
|
65
|
+
}
|
|
66
|
+
/** Fetch a single server by ID. */
|
|
67
|
+
async get(id, opts = {}) {
|
|
68
|
+
const params = {};
|
|
69
|
+
const include = (0, types_js_1.joinIncludes)(opts);
|
|
70
|
+
if (include)
|
|
71
|
+
params['include'] = include;
|
|
72
|
+
const data = await this.http.get(`/servers/${id}`, { params });
|
|
73
|
+
return this.makeServer(data);
|
|
74
|
+
}
|
|
75
|
+
/** Create a new server (also creates its server group). */
|
|
76
|
+
async create(payload) {
|
|
77
|
+
const body = {
|
|
78
|
+
name: payload.name,
|
|
79
|
+
node_id: payload.nodeId,
|
|
80
|
+
description: payload.description,
|
|
81
|
+
notes: payload.notes,
|
|
82
|
+
limits: {
|
|
83
|
+
ram_mb: payload.limits.ramMb,
|
|
84
|
+
swap_mb: payload.limits.swapMb,
|
|
85
|
+
storage_mb: payload.limits.storageMb,
|
|
86
|
+
weight_io: payload.limits.weightIo,
|
|
87
|
+
cpu_percent: payload.limits.cpuPercent,
|
|
88
|
+
cpu_threads: payload.limits.cpuThreads,
|
|
89
|
+
backup: payload.limits.backup,
|
|
90
|
+
database: payload.limits.database,
|
|
91
|
+
allocation: payload.limits.allocation,
|
|
92
|
+
},
|
|
93
|
+
egg_id: payload.eggId,
|
|
94
|
+
allocation_primary_id: payload.allocationPrimaryId,
|
|
95
|
+
image_override: payload.imageOverride,
|
|
96
|
+
force_outgoing_ip: payload.forceOutgoingIp,
|
|
97
|
+
oom_type: payload.oomType,
|
|
98
|
+
should_skip_egg_scripts: payload.shouldSkipEggScripts,
|
|
99
|
+
startup_command_override: payload.startupCommandOverride,
|
|
100
|
+
expires_at: payload.expiresAt,
|
|
101
|
+
};
|
|
102
|
+
const data = await this.http.post('/servers', body);
|
|
103
|
+
const server = this.makeServer(data);
|
|
104
|
+
this.addToCache(server);
|
|
105
|
+
this.emit('created', server);
|
|
106
|
+
return server;
|
|
107
|
+
}
|
|
108
|
+
/** Update a server's details, startup config, or primary allocation. */
|
|
109
|
+
async update(id, payload) {
|
|
110
|
+
const body = {};
|
|
111
|
+
if (payload.name !== undefined)
|
|
112
|
+
body['name'] = payload.name;
|
|
113
|
+
if (payload.description !== undefined)
|
|
114
|
+
body['description'] = payload.description;
|
|
115
|
+
if (payload.notes !== undefined)
|
|
116
|
+
body['notes'] = payload.notes;
|
|
117
|
+
if (payload.allocationPrimary)
|
|
118
|
+
body['allocation_primary'] = payload.allocationPrimary;
|
|
119
|
+
if (payload.startup) {
|
|
120
|
+
body['startup'] = {
|
|
121
|
+
command: payload.startup.command,
|
|
122
|
+
variables: payload.startup.variables,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const data = await this.http.patch(`/servers/${id}`, body);
|
|
126
|
+
const existing = this.cache.find((s) => s.id === id);
|
|
127
|
+
if (existing) {
|
|
128
|
+
existing.applyData(data);
|
|
129
|
+
this.upsertCache(existing);
|
|
130
|
+
this.emit('updated', existing);
|
|
131
|
+
return existing;
|
|
132
|
+
}
|
|
133
|
+
const server = this.makeServer(data);
|
|
134
|
+
this.upsertCache(server);
|
|
135
|
+
this.emit('updated', server);
|
|
136
|
+
return server;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.ServersNamespace = ServersNamespace;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { HttpClient } from '../../http.js';
|
|
2
|
+
import { ReactiveResource } from '../../reactive.js';
|
|
3
|
+
import type { ListOptions, NanoID, Paginated } from '../../types.js';
|
|
4
|
+
import type { ServerProfileData } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* A named configuration profile for a server.
|
|
7
|
+
*
|
|
8
|
+
* Profiles allow a server to switch between different file sets (e.g. different
|
|
9
|
+
* game versions or configurations) stored in separate folders.
|
|
10
|
+
*
|
|
11
|
+
* Retrieved via {@link ServerProfilesManager.list} or {@link ServerProfilesManager.get}.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ServerProfile extends ReactiveResource {
|
|
14
|
+
private readonly serverId;
|
|
15
|
+
private readonly http;
|
|
16
|
+
/** The profile's unique NanoID. */
|
|
17
|
+
readonly id: NanoID;
|
|
18
|
+
/** Display name for this profile, e.g. `"1.20.4 Vanilla"`. */
|
|
19
|
+
name: string;
|
|
20
|
+
/** Optional description of this profile. */
|
|
21
|
+
description: string | null;
|
|
22
|
+
/** Internal notes for this profile. */
|
|
23
|
+
notes: string | null | undefined;
|
|
24
|
+
/** The folder name used to store this profile's files on disk. */
|
|
25
|
+
folder: string | null | undefined;
|
|
26
|
+
/** `true` if this is the currently active profile for the server. */
|
|
27
|
+
isActive: boolean;
|
|
28
|
+
/** When this profile was created. */
|
|
29
|
+
readonly createdAt: Date;
|
|
30
|
+
/** When this profile was last updated. */
|
|
31
|
+
updatedAt: Date;
|
|
32
|
+
/** @internal */
|
|
33
|
+
constructor(data: ServerProfileData, serverId: NanoID, http: HttpClient);
|
|
34
|
+
/**
|
|
35
|
+
* Apply raw API data to this profile instance, updating all mutable fields.
|
|
36
|
+
*
|
|
37
|
+
* Called by the constructor and by instance methods after server responses.
|
|
38
|
+
*
|
|
39
|
+
* @param data The raw API response data.
|
|
40
|
+
*/
|
|
41
|
+
applyData(data: ServerProfileData): void;
|
|
42
|
+
/**
|
|
43
|
+
* Set this profile as the active profile for the server.
|
|
44
|
+
*
|
|
45
|
+
* Triggers the node to sync the server's container to this profile's folder.
|
|
46
|
+
*/
|
|
47
|
+
setAsActive(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Update this profile's name, description, or notes.
|
|
50
|
+
*
|
|
51
|
+
* @param payload Fields to update.
|
|
52
|
+
*/
|
|
53
|
+
update(payload: {
|
|
54
|
+
name?: string;
|
|
55
|
+
description?: string | null;
|
|
56
|
+
notes?: string | null;
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Delete this profile permanently.
|
|
60
|
+
*/
|
|
61
|
+
delete(): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Manages configuration profiles for a specific server.
|
|
65
|
+
*
|
|
66
|
+
* Access via `server.profiles`.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts ignore
|
|
70
|
+
* const profiles = await server.profiles.list();
|
|
71
|
+
* const active = await server.profiles.getActive();
|
|
72
|
+
*
|
|
73
|
+
* const profile = await server.profiles.create({ name: '1.20.4', description: 'Latest stable' });
|
|
74
|
+
* await server.profiles.setActive(profile.id);
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare class ServerProfilesManager {
|
|
78
|
+
private readonly serverId;
|
|
79
|
+
private readonly http;
|
|
80
|
+
/** @internal */
|
|
81
|
+
constructor(serverId: NanoID, http: HttpClient);
|
|
82
|
+
/** Create a {@link ServerProfile} with the correct server context wired in. @internal */
|
|
83
|
+
private makeProfile;
|
|
84
|
+
/**
|
|
85
|
+
* Fetch all profiles for this server.
|
|
86
|
+
*
|
|
87
|
+
* @param opts Pagination options.
|
|
88
|
+
*/
|
|
89
|
+
list(opts?: ListOptions): Promise<Paginated<ServerProfile>>;
|
|
90
|
+
/**
|
|
91
|
+
* Fetch the currently active profile.
|
|
92
|
+
*
|
|
93
|
+
* @throws {@link ApiError} with `isNotFound === true` if no profile is active.
|
|
94
|
+
*/
|
|
95
|
+
getActive(): Promise<ServerProfile>;
|
|
96
|
+
/**
|
|
97
|
+
* Fetch a single profile by ID.
|
|
98
|
+
*
|
|
99
|
+
* @param profileId The profile's NanoID.
|
|
100
|
+
*/
|
|
101
|
+
get(profileId: NanoID): Promise<ServerProfile>;
|
|
102
|
+
/**
|
|
103
|
+
* Create a new profile for this server.
|
|
104
|
+
*
|
|
105
|
+
* @param payload Profile creation parameters.
|
|
106
|
+
*/
|
|
107
|
+
create(payload: {
|
|
108
|
+
name: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
notes?: string;
|
|
111
|
+
}): Promise<ServerProfile>;
|
|
112
|
+
/**
|
|
113
|
+
* Update a profile's name, description, or notes.
|
|
114
|
+
*
|
|
115
|
+
* @param profileId The profile's NanoID.
|
|
116
|
+
* @param payload Fields to update.
|
|
117
|
+
*/
|
|
118
|
+
update(profileId: NanoID, payload: {
|
|
119
|
+
name?: string;
|
|
120
|
+
description?: string;
|
|
121
|
+
notes?: string;
|
|
122
|
+
}): Promise<ServerProfile>;
|
|
123
|
+
/**
|
|
124
|
+
* Set a profile as the active profile for this server.
|
|
125
|
+
*
|
|
126
|
+
* Triggers the node to sync the server's container to the new profile folder.
|
|
127
|
+
*
|
|
128
|
+
* @param profileId The profile's NanoID, or `null` to clear the active profile.
|
|
129
|
+
*/
|
|
130
|
+
setActive(profileId: NanoID | null): Promise<ServerProfile | null>;
|
|
131
|
+
/**
|
|
132
|
+
* Delete a profile permanently.
|
|
133
|
+
*
|
|
134
|
+
* @param profileId The profile's NanoID.
|
|
135
|
+
*/
|
|
136
|
+
delete(profileId: NanoID): Promise<void>;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=profiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../../../../src/src/resources/servers/profiles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAErE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;;;GAOG;AACH,qBAAa,aAAc,SAAQ,gBAAgB;IAqBjD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,IAAI;IArBtB,mCAAmC;IACnC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,8DAA8D;IACvD,IAAI,EAAG,MAAM,CAAC;IACrB,4CAA4C;IACrC,WAAW,EAAG,MAAM,GAAG,IAAI,CAAC;IACnC,uCAAuC;IAChC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACxC,kEAAkE;IAC3D,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,qEAAqE;IAC9D,QAAQ,EAAG,OAAO,CAAC;IAC1B,qCAAqC;IACrC,SAAgB,SAAS,EAAE,IAAI,CAAC;IAChC,0CAA0C;IACnC,SAAS,EAAG,IAAI,CAAC;IAExB,gBAAgB;gBA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C;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAC9D,OAAO,CAAC,aAAa,CAAC;IAKzB;;;;;;OAMG;IACU,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAW/E;;;;OAIG;IACU,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGrD"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerProfilesManager = exports.ServerProfile = void 0;
|
|
4
|
+
const reactive_js_1 = require("../../reactive.js");
|
|
5
|
+
const types_js_1 = require("../../types.js");
|
|
6
|
+
/**
|
|
7
|
+
* A named configuration profile for a server.
|
|
8
|
+
*
|
|
9
|
+
* Profiles allow a server to switch between different file sets (e.g. different
|
|
10
|
+
* game versions or configurations) stored in separate folders.
|
|
11
|
+
*
|
|
12
|
+
* Retrieved via {@link ServerProfilesManager.list} or {@link ServerProfilesManager.get}.
|
|
13
|
+
*/
|
|
14
|
+
class ServerProfile extends reactive_js_1.ReactiveResource {
|
|
15
|
+
serverId;
|
|
16
|
+
http;
|
|
17
|
+
/** The profile's unique NanoID. */
|
|
18
|
+
id;
|
|
19
|
+
/** Display name for this profile, e.g. `"1.20.4 Vanilla"`. */
|
|
20
|
+
name;
|
|
21
|
+
/** Optional description of this profile. */
|
|
22
|
+
description;
|
|
23
|
+
/** Internal notes for this profile. */
|
|
24
|
+
notes;
|
|
25
|
+
/** The folder name used to store this profile's files on disk. */
|
|
26
|
+
folder;
|
|
27
|
+
/** `true` if this is the currently active profile for the server. */
|
|
28
|
+
isActive;
|
|
29
|
+
/** When this profile was created. */
|
|
30
|
+
createdAt;
|
|
31
|
+
/** When this profile was last updated. */
|
|
32
|
+
updatedAt;
|
|
33
|
+
/** @internal */
|
|
34
|
+
constructor(data, serverId, http) {
|
|
35
|
+
super();
|
|
36
|
+
this.serverId = serverId;
|
|
37
|
+
this.http = http;
|
|
38
|
+
this.id = (0, types_js_1.toNanoID)(data.id);
|
|
39
|
+
this.createdAt = new Date(data.created_at);
|
|
40
|
+
this.applyData(data);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Apply raw API data to this profile instance, updating all mutable fields.
|
|
44
|
+
*
|
|
45
|
+
* Called by the constructor and by instance methods after server responses.
|
|
46
|
+
*
|
|
47
|
+
* @param data The raw API response data.
|
|
48
|
+
*/
|
|
49
|
+
applyData(data) {
|
|
50
|
+
this.name = data.name;
|
|
51
|
+
this.description = data.description ?? null;
|
|
52
|
+
this.notes = data.notes;
|
|
53
|
+
this.folder = data.folder;
|
|
54
|
+
this.isActive = data.is_active;
|
|
55
|
+
this.updatedAt = new Date(data.updated_at);
|
|
56
|
+
this.notify();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Set this profile as the active profile for the server.
|
|
60
|
+
*
|
|
61
|
+
* Triggers the node to sync the server's container to this profile's folder.
|
|
62
|
+
*/
|
|
63
|
+
async setAsActive() {
|
|
64
|
+
const data = await this.http.patch(`/servers/${this.serverId}/profiles/active`, { id: this.id });
|
|
65
|
+
this.applyData(data);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Update this profile's name, description, or notes.
|
|
69
|
+
*
|
|
70
|
+
* @param payload Fields to update.
|
|
71
|
+
*/
|
|
72
|
+
async update(payload) {
|
|
73
|
+
const data = await this.http.patch(`/servers/${this.serverId}/profiles/${this.id}`, payload);
|
|
74
|
+
this.applyData(data);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Delete this profile permanently.
|
|
78
|
+
*/
|
|
79
|
+
async delete() {
|
|
80
|
+
await this.http.delete(`/servers/${this.serverId}/profiles/${this.id}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.ServerProfile = ServerProfile;
|
|
84
|
+
/**
|
|
85
|
+
* Manages configuration profiles for a specific server.
|
|
86
|
+
*
|
|
87
|
+
* Access via `server.profiles`.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts ignore
|
|
91
|
+
* const profiles = await server.profiles.list();
|
|
92
|
+
* const active = await server.profiles.getActive();
|
|
93
|
+
*
|
|
94
|
+
* const profile = await server.profiles.create({ name: '1.20.4', description: 'Latest stable' });
|
|
95
|
+
* await server.profiles.setActive(profile.id);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
class ServerProfilesManager {
|
|
99
|
+
serverId;
|
|
100
|
+
http;
|
|
101
|
+
/** @internal */
|
|
102
|
+
constructor(serverId, http) {
|
|
103
|
+
this.serverId = serverId;
|
|
104
|
+
this.http = http;
|
|
105
|
+
}
|
|
106
|
+
/** Create a {@link ServerProfile} with the correct server context wired in. @internal */
|
|
107
|
+
makeProfile(data) {
|
|
108
|
+
return new ServerProfile(data, this.serverId, this.http);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Fetch all profiles for this server.
|
|
112
|
+
*
|
|
113
|
+
* @param opts Pagination options.
|
|
114
|
+
*/
|
|
115
|
+
async list(opts = {}) {
|
|
116
|
+
const result = await this.http.list(`/servers/${this.serverId}/profiles`, opts);
|
|
117
|
+
return { ...result, data: result.data.map((d) => this.makeProfile(d)) };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Fetch the currently active profile.
|
|
121
|
+
*
|
|
122
|
+
* @throws {@link ApiError} with `isNotFound === true` if no profile is active.
|
|
123
|
+
*/
|
|
124
|
+
async getActive() {
|
|
125
|
+
const data = await this.http.get(`/servers/${this.serverId}/profiles/active`);
|
|
126
|
+
return this.makeProfile(data);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Fetch a single profile by ID.
|
|
130
|
+
*
|
|
131
|
+
* @param profileId The profile's NanoID.
|
|
132
|
+
*/
|
|
133
|
+
async get(profileId) {
|
|
134
|
+
const data = await this.http.get(`/servers/${this.serverId}/profiles/${profileId}`);
|
|
135
|
+
return this.makeProfile(data);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Create a new profile for this server.
|
|
139
|
+
*
|
|
140
|
+
* @param payload Profile creation parameters.
|
|
141
|
+
*/
|
|
142
|
+
async create(payload) {
|
|
143
|
+
const data = await this.http.post(`/servers/${this.serverId}/profiles`, payload);
|
|
144
|
+
return this.makeProfile(data);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Update a profile's name, description, or notes.
|
|
148
|
+
*
|
|
149
|
+
* @param profileId The profile's NanoID.
|
|
150
|
+
* @param payload Fields to update.
|
|
151
|
+
*/
|
|
152
|
+
async update(profileId, payload) {
|
|
153
|
+
const data = await this.http.patch(`/servers/${this.serverId}/profiles/${profileId}`, payload);
|
|
154
|
+
return this.makeProfile(data);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Set a profile as the active profile for this server.
|
|
158
|
+
*
|
|
159
|
+
* Triggers the node to sync the server's container to the new profile folder.
|
|
160
|
+
*
|
|
161
|
+
* @param profileId The profile's NanoID, or `null` to clear the active profile.
|
|
162
|
+
*/
|
|
163
|
+
async setActive(profileId) {
|
|
164
|
+
if (profileId === null) {
|
|
165
|
+
await this.http.delete(`/servers/${this.serverId}/profiles/active`);
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
const data = await this.http.patch(`/servers/${this.serverId}/profiles/active`, {
|
|
169
|
+
id: profileId,
|
|
170
|
+
});
|
|
171
|
+
return this.makeProfile(data);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Delete a profile permanently.
|
|
175
|
+
*
|
|
176
|
+
* @param profileId The profile's NanoID.
|
|
177
|
+
*/
|
|
178
|
+
async delete(profileId) {
|
|
179
|
+
await this.http.delete(`/servers/${this.serverId}/profiles/${profileId}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.ServerProfilesManager = ServerProfilesManager;
|