vpsgui 1.2.0

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.
@@ -0,0 +1,199 @@
1
+ import type { VpsguiClientConfig, NodeSpec, ContainerItem, DockerImageItem, TelemetryPoint, ProcessItem, HealthCheck, FileItem, FileReadResult, FirewallRule, FirewallRuleInput, SecretItem, AuditLogEvent, CatalogItem, AutomationWorkflow, QueueJob, StoragePartition, NetworkInterfaceInfo, IpInfoResult, BackupItem, DatabaseInstance, Deployment, ProxyRule, SystemUser, TopologyLayer, PackagesResult, AgentInfo, CommandResult, MutationResult } from './types';
2
+ /** Error carrying the HTTP status returned by the agent. */
3
+ export declare class VpsguiError extends Error {
4
+ readonly status: number;
5
+ readonly endpoint: string;
6
+ constructor(message: string, status: number, endpoint: string);
7
+ /** The agent token is missing, wrong, or temporarily locked out after repeated failures. */
8
+ get isAuthError(): boolean;
9
+ }
10
+ /**
11
+ * Official VPSGUI Node.js/TypeScript SDK.
12
+ *
13
+ * Every endpoint except `health()` requires the agent token, which grants root-equivalent control
14
+ * of the host - treat it as a root password and never commit it.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { VpsguiClient } from 'vpsgui';
19
+ *
20
+ * const client = new VpsguiClient({
21
+ * baseUrl: 'https://vps.example.com/api/v1',
22
+ * token: process.env.VPSGUI_AGENT_TOKEN,
23
+ * });
24
+ *
25
+ * const telemetry = await client.system.telemetry();
26
+ * const containers = await client.docker.listContainers();
27
+ * ```
28
+ */
29
+ export declare class VpsguiClient {
30
+ private readonly baseUrl;
31
+ private readonly token?;
32
+ private readonly timeout;
33
+ readonly nodes: NodesResource;
34
+ readonly system: SystemResource;
35
+ readonly docker: DockerResource;
36
+ readonly files: FilesResource;
37
+ readonly security: SecurityResource;
38
+ readonly network: NetworkResource;
39
+ readonly storage: StorageResource;
40
+ readonly backups: BackupsResource;
41
+ readonly deployments: DeploymentsResource;
42
+ readonly catalog: CatalogResource;
43
+ readonly automation: AutomationResource;
44
+ readonly queue: QueueResource;
45
+ readonly databases: DatabasesResource;
46
+ readonly proxy: ProxyResource;
47
+ readonly terminal: TerminalResource;
48
+ constructor(config: VpsguiClientConfig);
49
+ /** @internal */
50
+ request<T>(method: 'GET' | 'POST', endpoint: string, body?: unknown, timeoutMs?: number): Promise<T>;
51
+ /** Liveness probe. The only endpoint that does not require a token. */
52
+ health(): Promise<{
53
+ status: string;
54
+ }>;
55
+ /** Agent version, configured file roots, and whether optional integrations are set up. */
56
+ info(): Promise<AgentInfo>;
57
+ }
58
+ /** @internal */
59
+ declare abstract class Resource {
60
+ protected readonly client: VpsguiClient;
61
+ constructor(client: VpsguiClient);
62
+ }
63
+ declare class NodesResource extends Resource {
64
+ /** The host this agent runs on. */
65
+ get(): Promise<NodeSpec>;
66
+ /** VPSGUI manages a single host, so this always returns exactly one entry. */
67
+ list(): Promise<NodeSpec[]>;
68
+ /** Derived topology: the host, its containers, and detected database engines. */
69
+ topology(): Promise<TopologyLayer[]>;
70
+ /** Computed health checks (memory, disk, load, failed units, Docker). */
71
+ health(): Promise<HealthCheck[]>;
72
+ }
73
+ declare class SystemResource extends Resource {
74
+ telemetry(): Promise<TelemetryPoint>;
75
+ processes(): Promise<ProcessItem[]>;
76
+ services(): Promise<Array<{
77
+ id: string;
78
+ name: string;
79
+ alias: string;
80
+ status: string;
81
+ enabled: boolean | null;
82
+ }>>;
83
+ /** `systemctl <action> <name>` on the host. */
84
+ serviceAction(name: string, action: 'start' | 'stop' | 'restart' | 'reload'): Promise<CommandResult>;
85
+ packages(): Promise<PackagesResult>;
86
+ /** `apt-get install -y <packageName>`. Can take minutes. */
87
+ installPackage(packageName: string): Promise<CommandResult>;
88
+ /** Host accounts from /etc/passwd. */
89
+ users(): Promise<SystemUser[]>;
90
+ }
91
+ declare class DockerResource extends Resource {
92
+ listContainers(): Promise<ContainerItem[]>;
93
+ listImages(): Promise<DockerImageItem[]>;
94
+ containerAction(id: string, action: 'start' | 'stop' | 'restart' | 'remove'): Promise<CommandResult>;
95
+ /** `docker rmi`. Without `force`, Docker refuses while a container still references the image. */
96
+ removeImage(id: string, force?: boolean): Promise<CommandResult>;
97
+ }
98
+ declare class FilesResource extends Resource {
99
+ /** Directory entries. Contents are NOT included - use `read` for that. */
100
+ list(path: string): Promise<FileItem[]>;
101
+ /** Full file contents. `truncated` is true when the file exceeded the agent's read cap. */
102
+ read(path: string): Promise<FileReadResult>;
103
+ write(path: string, content: string): Promise<MutationResult>;
104
+ mkdir(path: string): Promise<MutationResult>;
105
+ /** Without `recursive` the agent refuses to remove a non-empty directory. */
106
+ delete(path: string, recursive?: boolean): Promise<MutationResult>;
107
+ rename(from: string, to: string): Promise<MutationResult>;
108
+ }
109
+ declare class SecurityResource extends Resource {
110
+ firewallRules(): Promise<FirewallRule[]>;
111
+ /** Applies a real ufw rule change. */
112
+ applyFirewallRule(input: FirewallRuleInput): Promise<CommandResult>;
113
+ sshKeys(): Promise<Array<{
114
+ id: string;
115
+ user: string;
116
+ label: string;
117
+ algorithm: string;
118
+ fingerprint: string;
119
+ path: string;
120
+ }>>;
121
+ /** SSH and sudo events from the host journal. */
122
+ auditLogs(): Promise<AuditLogEvent[]>;
123
+ /** Secret metadata. Values are never included - use `revealSecret`. */
124
+ listSecrets(): Promise<SecretItem[]>;
125
+ /** Create or overwrite a secret. The agent encrypts the value before it touches disk. */
126
+ saveSecret(input: {
127
+ name: string;
128
+ value: string;
129
+ environment?: string;
130
+ type?: string;
131
+ }): Promise<MutationResult>;
132
+ deleteSecret(name: string): Promise<MutationResult>;
133
+ /** Decrypt one secret. Deliberately separate so values are never fetched in bulk. */
134
+ revealSecret(name: string): Promise<{
135
+ success: boolean;
136
+ name?: string;
137
+ value?: string;
138
+ error?: string;
139
+ }>;
140
+ }
141
+ declare class NetworkResource extends Resource {
142
+ interfaces(): Promise<NetworkInterfaceInfo[]>;
143
+ /** Geolocate an address. Omit `ip` to look up the host's own public address. */
144
+ ipInfo(ip?: string): Promise<IpInfoResult>;
145
+ }
146
+ declare class StorageResource extends Resource {
147
+ partitions(): Promise<StoragePartition[]>;
148
+ }
149
+ declare class BackupsResource extends Resource {
150
+ list(): Promise<BackupItem[]>;
151
+ /** Creates a tar.gz of `sourcePath`. Large trees can take minutes. */
152
+ create(sourcePath: string, label?: string): Promise<MutationResult & {
153
+ name?: string;
154
+ path?: string;
155
+ }>;
156
+ delete(name: string): Promise<MutationResult>;
157
+ /** Extracts an archive into `destination`. Existing files may be overwritten. */
158
+ restore(name: string, destination: string): Promise<MutationResult & {
159
+ restoredTo?: string;
160
+ }>;
161
+ }
162
+ declare class DeploymentsResource extends Resource {
163
+ /** Git checkouts found on the host. */
164
+ list(): Promise<Deployment[]>;
165
+ /** `git pull --ff-only`, accepted only for a path `list()` already reported. */
166
+ pull(path: string): Promise<CommandResult>;
167
+ }
168
+ declare class CatalogResource extends Resource {
169
+ list(): Promise<CatalogItem[]>;
170
+ }
171
+ declare class AutomationResource extends Resource {
172
+ /** cron entries from /etc/crontab, /etc/cron.d and root's crontab. */
173
+ workflows(): Promise<AutomationWorkflow[]>;
174
+ }
175
+ declare class QueueResource extends Resource {
176
+ /** systemd timers. */
177
+ jobs(): Promise<QueueJob[]>;
178
+ }
179
+ declare class DatabasesResource extends Resource {
180
+ /** Engines detected from listening TCP ports. */
181
+ list(): Promise<DatabaseInstance[]>;
182
+ }
183
+ declare class ProxyResource extends Resource {
184
+ /** Reverse-proxy rules parsed from the live nginx configuration. */
185
+ rules(): Promise<ProxyRule[]>;
186
+ }
187
+ declare class TerminalResource extends Resource {
188
+ /**
189
+ * Run a shell command on the host.
190
+ *
191
+ * This is arbitrary remote code execution by design, gated by the agent token. It can be disabled
192
+ * server-side with `AGENT_ENABLE_SHELL=0`, in which case this returns HTTP 403.
193
+ */
194
+ exec(command: string): Promise<CommandResult & {
195
+ command: string;
196
+ }>;
197
+ }
198
+ export {};
199
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.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,SAAQ,QAAQ;IAClC,sBAAsB;IACtB,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;CAG5B;AAED,cAAM,iBAAkB,SAAQ,QAAQ;IACtC,iDAAiD;IACjD,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;CAGpC;AAED,cAAM,aAAc,SAAQ,QAAQ;IAClC,oEAAoE;IACpE,KAAK,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CAG9B;AAED,cAAM,gBAAiB,SAAQ,QAAQ;IACrC;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAGpE"}
package/dist/client.js ADDED
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VpsguiClient = exports.VpsguiError = void 0;
4
+ /** Error carrying the HTTP status returned by the agent. */
5
+ class VpsguiError extends Error {
6
+ constructor(message, status, endpoint) {
7
+ super(message);
8
+ this.name = 'VpsguiError';
9
+ this.status = status;
10
+ this.endpoint = endpoint;
11
+ }
12
+ /** The agent token is missing, wrong, or temporarily locked out after repeated failures. */
13
+ get isAuthError() {
14
+ return this.status === 401 || this.status === 403 || this.status === 429;
15
+ }
16
+ }
17
+ exports.VpsguiError = VpsguiError;
18
+ /**
19
+ * Official VPSGUI Node.js/TypeScript SDK.
20
+ *
21
+ * Every endpoint except `health()` requires the agent token, which grants root-equivalent control
22
+ * of the host - treat it as a root password and never commit it.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { VpsguiClient } from 'vpsgui';
27
+ *
28
+ * const client = new VpsguiClient({
29
+ * baseUrl: 'https://vps.example.com/api/v1',
30
+ * token: process.env.VPSGUI_AGENT_TOKEN,
31
+ * });
32
+ *
33
+ * const telemetry = await client.system.telemetry();
34
+ * const containers = await client.docker.listContainers();
35
+ * ```
36
+ */
37
+ class VpsguiClient {
38
+ constructor(config) {
39
+ if (!config?.baseUrl)
40
+ throw new Error('VpsguiClient requires a baseUrl');
41
+ this.baseUrl = config.baseUrl.replace(/\/+$/, '');
42
+ this.token = config.token;
43
+ this.timeout = config.timeout ?? 15000;
44
+ this.nodes = new NodesResource(this);
45
+ this.system = new SystemResource(this);
46
+ this.docker = new DockerResource(this);
47
+ this.files = new FilesResource(this);
48
+ this.security = new SecurityResource(this);
49
+ this.network = new NetworkResource(this);
50
+ this.storage = new StorageResource(this);
51
+ this.backups = new BackupsResource(this);
52
+ this.deployments = new DeploymentsResource(this);
53
+ this.catalog = new CatalogResource(this);
54
+ this.automation = new AutomationResource(this);
55
+ this.queue = new QueueResource(this);
56
+ this.databases = new DatabasesResource(this);
57
+ this.proxy = new ProxyResource(this);
58
+ this.terminal = new TerminalResource(this);
59
+ }
60
+ /** @internal */
61
+ async request(method, endpoint, body, timeoutMs) {
62
+ const controller = new AbortController();
63
+ const timer = setTimeout(() => controller.abort(), timeoutMs ?? this.timeout);
64
+ let response;
65
+ try {
66
+ response = await fetch(`${this.baseUrl}${endpoint}`, {
67
+ method,
68
+ headers: {
69
+ Accept: 'application/json',
70
+ ...(body !== undefined ? { 'Content-Type': 'application/json' } : {}),
71
+ ...(this.token ? { Authorization: `Bearer ${this.token}` } : {}),
72
+ },
73
+ body: body !== undefined ? JSON.stringify(body) : undefined,
74
+ signal: controller.signal,
75
+ });
76
+ }
77
+ catch (error) {
78
+ if (error instanceof Error && error.name === 'AbortError') {
79
+ throw new VpsguiError(`Request timed out after ${timeoutMs ?? this.timeout}ms`, 0, endpoint);
80
+ }
81
+ throw new VpsguiError(error instanceof Error ? error.message : 'Network request failed', 0, endpoint);
82
+ }
83
+ finally {
84
+ clearTimeout(timer);
85
+ }
86
+ if (response.status === 204)
87
+ return undefined;
88
+ const raw = await response.text();
89
+ let parsed;
90
+ if (raw) {
91
+ try {
92
+ parsed = JSON.parse(raw);
93
+ }
94
+ catch {
95
+ // Non-JSON body (e.g. a proxy error page); fall through to the status-based message.
96
+ }
97
+ }
98
+ if (!response.ok) {
99
+ const detail = parsed && typeof parsed === 'object' && 'error' in parsed
100
+ ? String(parsed.error)
101
+ : `HTTP ${response.status} ${response.statusText}`;
102
+ throw new VpsguiError(detail, response.status, endpoint);
103
+ }
104
+ return parsed;
105
+ }
106
+ /** Liveness probe. The only endpoint that does not require a token. */
107
+ health() {
108
+ return this.request('GET', '/health');
109
+ }
110
+ /** Agent version, configured file roots, and whether optional integrations are set up. */
111
+ info() {
112
+ return this.request('GET', '/agent/info');
113
+ }
114
+ }
115
+ exports.VpsguiClient = VpsguiClient;
116
+ /** @internal */
117
+ class Resource {
118
+ constructor(client) {
119
+ this.client = client;
120
+ }
121
+ }
122
+ class NodesResource extends Resource {
123
+ /** The host this agent runs on. */
124
+ get() {
125
+ return this.client.request('GET', '/node');
126
+ }
127
+ /** VPSGUI manages a single host, so this always returns exactly one entry. */
128
+ list() {
129
+ return this.client.request('GET', '/nodes');
130
+ }
131
+ /** Derived topology: the host, its containers, and detected database engines. */
132
+ topology() {
133
+ return this.client.request('GET', '/topology');
134
+ }
135
+ /** Computed health checks (memory, disk, load, failed units, Docker). */
136
+ health() {
137
+ return this.client.request('GET', '/health/matrix');
138
+ }
139
+ }
140
+ class SystemResource extends Resource {
141
+ telemetry() {
142
+ return this.client.request('GET', '/system/telemetry');
143
+ }
144
+ processes() {
145
+ return this.client.request('GET', '/system/processes');
146
+ }
147
+ services() {
148
+ return this.client.request('GET', '/system/services');
149
+ }
150
+ /** `systemctl <action> <name>` on the host. */
151
+ serviceAction(name, action) {
152
+ return this.client.request('POST', '/system/services/action', { name, action }, 60000);
153
+ }
154
+ packages() {
155
+ return this.client.request('GET', '/system/packages');
156
+ }
157
+ /** `apt-get install -y <packageName>`. Can take minutes. */
158
+ installPackage(packageName) {
159
+ return this.client.request('POST', '/system/packages/install', { packageName }, 300000);
160
+ }
161
+ /** Host accounts from /etc/passwd. */
162
+ users() {
163
+ return this.client.request('GET', '/users');
164
+ }
165
+ }
166
+ class DockerResource extends Resource {
167
+ listContainers() {
168
+ return this.client.request('GET', '/docker/containers');
169
+ }
170
+ listImages() {
171
+ return this.client.request('GET', '/docker/images');
172
+ }
173
+ containerAction(id, action) {
174
+ return this.client.request('POST', '/docker/containers/action', { id, action }, 60000);
175
+ }
176
+ /** `docker rmi`. Without `force`, Docker refuses while a container still references the image. */
177
+ removeImage(id, force = false) {
178
+ return this.client.request('POST', '/docker/images/action', { id, action: 'remove', force }, 60000);
179
+ }
180
+ }
181
+ class FilesResource extends Resource {
182
+ /** Directory entries. Contents are NOT included - use `read` for that. */
183
+ list(path) {
184
+ return this.client.request('GET', `/files?path=${encodeURIComponent(path)}`);
185
+ }
186
+ /** Full file contents. `truncated` is true when the file exceeded the agent's read cap. */
187
+ read(path) {
188
+ return this.client.request('GET', `/files/read?path=${encodeURIComponent(path)}`);
189
+ }
190
+ write(path, content) {
191
+ return this.client.request('POST', '/files/write', { path, content });
192
+ }
193
+ mkdir(path) {
194
+ return this.client.request('POST', '/files/mkdir', { path });
195
+ }
196
+ /** Without `recursive` the agent refuses to remove a non-empty directory. */
197
+ delete(path, recursive = false) {
198
+ return this.client.request('POST', '/files/delete', { path, recursive });
199
+ }
200
+ rename(from, to) {
201
+ return this.client.request('POST', '/files/rename', { from, to });
202
+ }
203
+ }
204
+ class SecurityResource extends Resource {
205
+ firewallRules() {
206
+ return this.client.request('GET', '/security/firewall');
207
+ }
208
+ /** Applies a real ufw rule change. */
209
+ applyFirewallRule(input) {
210
+ return this.client.request('POST', '/security/firewall/action', input, 30000);
211
+ }
212
+ sshKeys() {
213
+ return this.client.request('GET', '/security/ssh-keys');
214
+ }
215
+ /** SSH and sudo events from the host journal. */
216
+ auditLogs() {
217
+ return this.client.request('GET', '/security/audit-logs');
218
+ }
219
+ /** Secret metadata. Values are never included - use `revealSecret`. */
220
+ listSecrets() {
221
+ return this.client.request('GET', '/security/secrets');
222
+ }
223
+ /** Create or overwrite a secret. The agent encrypts the value before it touches disk. */
224
+ saveSecret(input) {
225
+ return this.client.request('POST', '/security/secrets', input);
226
+ }
227
+ deleteSecret(name) {
228
+ return this.client.request('POST', '/security/secrets/delete', { name });
229
+ }
230
+ /** Decrypt one secret. Deliberately separate so values are never fetched in bulk. */
231
+ revealSecret(name) {
232
+ return this.client.request('POST', '/security/secrets/reveal', { name });
233
+ }
234
+ }
235
+ class NetworkResource extends Resource {
236
+ interfaces() {
237
+ return this.client.request('GET', '/network/interfaces');
238
+ }
239
+ /** Geolocate an address. Omit `ip` to look up the host's own public address. */
240
+ ipInfo(ip) {
241
+ return this.client.request('GET', `/network/ip-info${ip ? `?ip=${encodeURIComponent(ip)}` : ''}`);
242
+ }
243
+ }
244
+ class StorageResource extends Resource {
245
+ partitions() {
246
+ return this.client.request('GET', '/storage/partitions');
247
+ }
248
+ }
249
+ class BackupsResource extends Resource {
250
+ list() {
251
+ return this.client.request('GET', '/backups');
252
+ }
253
+ /** Creates a tar.gz of `sourcePath`. Large trees can take minutes. */
254
+ create(sourcePath, label) {
255
+ return this.client.request('POST', '/backups/create', { sourcePath, label }, 600000);
256
+ }
257
+ delete(name) {
258
+ return this.client.request('POST', '/backups/delete', { name });
259
+ }
260
+ /** Extracts an archive into `destination`. Existing files may be overwritten. */
261
+ restore(name, destination) {
262
+ return this.client.request('POST', '/backups/restore', { name, destination }, 600000);
263
+ }
264
+ }
265
+ class DeploymentsResource extends Resource {
266
+ /** Git checkouts found on the host. */
267
+ list() {
268
+ return this.client.request('GET', '/deployments', undefined, 30000);
269
+ }
270
+ /** `git pull --ff-only`, accepted only for a path `list()` already reported. */
271
+ pull(path) {
272
+ return this.client.request('POST', '/deployments/pull', { path }, 120000);
273
+ }
274
+ }
275
+ class CatalogResource extends Resource {
276
+ list() {
277
+ return this.client.request('GET', '/catalog');
278
+ }
279
+ }
280
+ class AutomationResource extends Resource {
281
+ /** cron entries from /etc/crontab, /etc/cron.d and root's crontab. */
282
+ workflows() {
283
+ return this.client.request('GET', '/automation/workflows');
284
+ }
285
+ }
286
+ class QueueResource extends Resource {
287
+ /** systemd timers. */
288
+ jobs() {
289
+ return this.client.request('GET', '/queue/jobs');
290
+ }
291
+ }
292
+ class DatabasesResource extends Resource {
293
+ /** Engines detected from listening TCP ports. */
294
+ list() {
295
+ return this.client.request('GET', '/databases');
296
+ }
297
+ }
298
+ class ProxyResource extends Resource {
299
+ /** Reverse-proxy rules parsed from the live nginx configuration. */
300
+ rules() {
301
+ return this.client.request('GET', '/proxy/rules');
302
+ }
303
+ }
304
+ class TerminalResource extends Resource {
305
+ /**
306
+ * Run a shell command on the host.
307
+ *
308
+ * This is arbitrary remote code execution by design, gated by the agent token. It can be disabled
309
+ * server-side with `AGENT_ENABLE_SHELL=0`, in which case this returns HTTP 403.
310
+ */
311
+ exec(command) {
312
+ return this.client.request('POST', '/terminal/exec', { command }, 20000);
313
+ }
314
+ }
315
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAgCA,4DAA4D;AAC5D,MAAa,WAAY,SAAQ,KAAK;IAIpC,YAAY,OAAe,EAAE,MAAc,EAAE,QAAgB;QAC3D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,4FAA4F;IAC5F,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG,CAAC;IAC3E,CAAC;CACF;AAfD,kCAeC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,YAAY;IAqBvB,YAAY,MAA0B;QACpC,IAAI,CAAC,MAAM,EAAE,OAAO;YAAE,MAAM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Q,QAAQ;IACtC,iDAAiD;IACjD,IAAI;QACF,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAClD,CAAC;CACF;AAED,MAAM,aAAc,SAAQ,QAAQ;IAClC,oEAAoE;IACpE,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACpD,CAAC;CACF;AAED,MAAM,gBAAiB,SAAQ,QAAQ;IACrC;;;;;OAKG;IACH,IAAI,CAAC,OAAe;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;IAC3E,CAAC;CACF"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * On-disk credentials for the CLI.
3
+ *
4
+ * The format is shared verbatim with the Python SDK, because `npm i -g vpsgui`
5
+ * and `pip install vpsgui` both put a `vpsgui` executable on PATH and only one
6
+ * of them can win. Sharing the file means it does not matter which one does:
7
+ * whichever binary runs, `vpsgui login` and every other command see the same
8
+ * profiles. Any change here has to land in sdk/python/vpsgui/config.py too.
9
+ */
10
+ export declare const CONFIG_VERSION = 1;
11
+ export interface Profile {
12
+ /** Full API root, e.g. https://vps.example.com/api/v1 */
13
+ url: string;
14
+ /** Agent token. Root-equivalent - this is why the file is 0600. */
15
+ token: string;
16
+ /** Recorded at login, for `vpsgui whoami`. Not trusted for anything. */
17
+ hostname?: string;
18
+ agentVersion?: string;
19
+ savedAt?: string;
20
+ }
21
+ export interface Config {
22
+ version: number;
23
+ current: string;
24
+ profiles: Record<string, Profile>;
25
+ }
26
+ export declare function configDir(): string;
27
+ export declare function configPath(): string;
28
+ export declare function readConfig(): Promise<Config>;
29
+ /**
30
+ * Write the config with owner-only permissions.
31
+ *
32
+ * The mode is set on the temp file before any token reaches the disk; creating
33
+ * it 0644 and chmod-ing afterwards would leave a window where any local user
34
+ * could read the token.
35
+ */
36
+ export declare function writeConfig(config: Config): Promise<void>;
37
+ /**
38
+ * The profile to use, honouring `--profile`, then VPSGUI_PROFILE, then the
39
+ * `current` recorded at the last login.
40
+ */
41
+ export declare function resolveProfileName(config: Config, explicit?: string): string;
42
+ /**
43
+ * Credentials for a command, or null when there is no usable source.
44
+ *
45
+ * The environment wins over the config file so CI can run without a login step,
46
+ * and so an operator can override a saved profile for one command.
47
+ */
48
+ export declare function loadCredentials(explicitProfile?: string): Promise<{
49
+ url: string;
50
+ token: string;
51
+ source: string;
52
+ } | null>;
53
+ /**
54
+ * Turn what an operator types into an API root.
55
+ *
56
+ * People paste the address bar - "vps.example.com", "http://1.2.3.4:46509",
57
+ * "https://host/api/v1/" - and every one of those should work rather than
58
+ * producing a 404 they have to debug.
59
+ */
60
+ export declare function normaliseUrl(input: string): string;
61
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AAEH,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,MAAM,WAAW,OAAO;IACtB,yDAAyD;IACzD,GAAG,EAAE,MAAM,CAAC;IACZ,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,wBAAgB,SAAS,IAAI,MAAM,CAIlC;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAMD,wBAAsB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAuBlD;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAe/D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5E;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAahE;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgBlD"}