elestio 1.0.3 → 1.1.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.
@@ -1,132 +1,145 @@
1
- import { apiRequest } from '../api.js';
2
- import { loadConfig } from '../config.js';
3
- import { log, colors, outputJson } from '../utils.js';
4
- import { getServiceDetails } from './services.js';
5
-
6
- export async function getCredentials(vmID, projectId = null, json = false) {
7
- const config = loadConfig();
8
- const pid = projectId || config.defaultProject;
9
- if (!pid) throw new Error('Project ID required');
10
-
11
- const serviceInfo = await getServiceDetails(vmID, pid);
12
- if (!serviceInfo) throw new Error('Failed to get service details');
13
-
14
- const targetPort = serviceInfo.adminInternalPort || 8080;
15
- const srvPort = serviceInfo.adminExternalPort || 443;
16
-
17
- const response = await apiRequest('/api/servers/getAppCredentials', 'POST', {
18
- vmID: String(vmID), targetPort, srvPort,
19
- projectID: String(pid), appID: 'CloudVM',
20
- isServerDeleted: false, mode: 'dbAdmin'
21
- });
22
-
23
- if (!response.url) throw new Error(response.message || 'Failed to get credentials');
24
-
25
- if (json) {
26
- outputJson({
27
- service: { name: serviceInfo.displayName, type: serviceInfo.serverType, ip: serviceInfo.ipv4 },
28
- credentials: { url: response.url, user: response.user, password: response.password },
29
- database: serviceInfo.managedDBPort ? {
30
- host: serviceInfo.cname, port: serviceInfo.managedDBPort
31
- } : null
32
- });
33
- return response;
34
- }
35
-
36
- console.log(`\n${colors.bold}Service Info${colors.reset}\n`);
37
- console.log(` Name: ${serviceInfo.displayName}`);
38
- console.log(` Type: ${serviceInfo.serverType} (${serviceInfo.cores} CPU / ${serviceInfo.ramGB} GB RAM)`);
39
- console.log(` Status: ${serviceInfo.status}`);
40
- console.log(` IP: ${serviceInfo.ipv4}`);
41
- console.log(`\n${colors.bold}App Credentials${colors.reset}\n`);
42
- console.log(` URL: ${colors.cyan}${response.url}${colors.reset}`);
43
- console.log(` User: ${response.user || 'N/A'}`);
44
- console.log(` Password: ${response.password || 'N/A'}`);
45
-
46
- if (serviceInfo.managedDBPort) {
47
- console.log(`\n${colors.bold}Database Connection${colors.reset}`);
48
- console.log(` Host: ${serviceInfo.cname}`);
49
- console.log(` Port: ${serviceInfo.managedDBPort}`);
50
- }
51
- console.log('');
52
- return response;
53
- }
54
-
55
- export async function getSSH(vmID, projectId = null, json = false) {
56
- const config = loadConfig();
57
- const pid = projectId || config.defaultProject;
58
- if (!pid) throw new Error('Project ID required');
59
-
60
- const response = await apiRequest('/api/servers/startSSHDirect', 'POST', {
61
- vmID: String(vmID), projectID: String(pid), path: '/root/'
62
- });
63
-
64
- if (!response.url) throw new Error(response.message || 'Failed to get SSH access');
65
-
66
- if (json) { outputJson({ url: response.url }); return response; }
67
-
68
- console.log(`\n${colors.bold}SSH Access${colors.reset}\n`);
69
- console.log(` Web Terminal: ${colors.cyan}${response.url}${colors.reset}`);
70
- console.log('');
71
- return response;
72
- }
73
-
74
- export async function getSSHDirect(vmID, json = false) {
75
- const response = await apiRequest('/api/servers/startSSHDirect', 'POST', { vmID: String(vmID) });
76
- if (response.status !== 'OK' && !response.ip) throw new Error(response.message || 'Failed to get SSH info');
77
-
78
- if (json) {
79
- outputJson({ host: response.ip || response.host, port: response.port || 22, user: response.user || 'root' });
80
- return response;
81
- }
82
-
83
- console.log(`\n${colors.bold}Direct SSH${colors.reset}\n`);
84
- console.log(` Host: ${response.ip || response.host || 'N/A'}`);
85
- console.log(` Port: ${response.port || 22}`);
86
- console.log(` User: ${response.user || 'root'}`);
87
- console.log(`\n ${colors.dim}ssh ${response.user || 'root'}@${response.ip || response.host} -p ${response.port || 22}${colors.reset}`);
88
- console.log('');
89
- return response;
90
- }
91
-
92
- export async function getVSCode(vmID, projectId = null, json = false) {
93
- const config = loadConfig();
94
- const pid = projectId || config.defaultProject;
95
- if (!pid) throw new Error('Project ID required');
96
-
97
- const response = await apiRequest('/api/servers/startVSCode', 'POST', {
98
- vmID: String(vmID), projectID: String(pid)
99
- });
100
-
101
- if (!response.url) throw new Error(response.message || 'Failed to get VSCode access');
102
-
103
- if (json) { outputJson({ url: response.url, user: response.user, password: response.password }); return response; }
104
-
105
- console.log(`\n${colors.bold}VSCode Web Access${colors.reset}\n`);
106
- console.log(` URL: ${colors.cyan}${response.url}${colors.reset}`);
107
- console.log(` User: ${response.user || 'N/A'}`);
108
- console.log(` Password: ${response.password || 'N/A'}`);
109
- console.log('');
110
- return response;
111
- }
112
-
113
- export async function getFileExplorer(vmID, projectId = null, json = false) {
114
- const config = loadConfig();
115
- const pid = projectId || config.defaultProject;
116
- if (!pid) throw new Error('Project ID required');
117
-
118
- const response = await apiRequest('/api/servers/startFileExplorer', 'POST', {
119
- vmID: String(vmID), projectID: String(pid)
120
- });
121
-
122
- if (!response.url) throw new Error(response.message || 'Failed to get File Explorer access');
123
-
124
- if (json) { outputJson({ url: response.url, user: response.user, password: response.password }); return response; }
125
-
126
- console.log(`\n${colors.bold}File Explorer Access${colors.reset}\n`);
127
- console.log(` URL: ${colors.cyan}${response.url}${colors.reset}`);
128
- console.log(` User: ${response.user || 'N/A'}`);
129
- console.log(` Password: ${response.password || 'N/A'}`);
130
- console.log('');
131
- return response;
132
- }
1
+ import { apiRequest } from '../api.js';
2
+ import { loadConfig } from '../config.js';
3
+ import { colors, outputJson } from '../utils.js';
4
+ import { getServiceDetails } from './services.js';
5
+
6
+ export async function getCredentials(vmID, projectId = null, json = false) {
7
+ const config = loadConfig();
8
+ const pid = projectId || config.defaultProject;
9
+ if (!pid) throw new Error('Project ID required');
10
+
11
+ const serviceInfo = await getServiceDetails(vmID, pid);
12
+ if (!serviceInfo) throw new Error('Failed to get service details');
13
+
14
+ const targetPort = serviceInfo.adminInternalPort || 8080;
15
+ const srvPort = serviceInfo.adminExternalPort || 443;
16
+
17
+ const response = await apiRequest('/api/servers/getAppCredentials', 'POST', {
18
+ vmID: String(vmID), targetPort, srvPort,
19
+ projectID: String(pid), appID: 'CloudVM',
20
+ isServerDeleted: false, mode: 'dbAdmin'
21
+ });
22
+
23
+ if (!response.url) throw new Error(response.message || 'Failed to get credentials');
24
+
25
+ if (json) {
26
+ outputJson({
27
+ service: { name: serviceInfo.displayName, type: serviceInfo.serverType, ip: serviceInfo.ipv4 },
28
+ credentials: { url: response.url, user: response.user, password: response.password },
29
+ database: serviceInfo.managedDBPort ? {
30
+ host: serviceInfo.cname, port: serviceInfo.managedDBPort
31
+ } : null
32
+ });
33
+ return response;
34
+ }
35
+
36
+ console.log(`\n${colors.bold}Service Info${colors.reset}\n`);
37
+ console.log(` Name: ${serviceInfo.displayName}`);
38
+ console.log(` Type: ${serviceInfo.serverType} (${serviceInfo.cores} CPU / ${serviceInfo.ramGB} GB RAM)`);
39
+ console.log(` Status: ${serviceInfo.status}`);
40
+ console.log(` IP: ${serviceInfo.ipv4}`);
41
+ console.log(`\n${colors.bold}App Credentials${colors.reset}\n`);
42
+ console.log(` URL: ${colors.cyan}${response.url}${colors.reset}`);
43
+ console.log(` User: ${response.user || 'N/A'}`);
44
+ console.log(` Password: ${response.password || 'N/A'}`);
45
+
46
+ if (serviceInfo.managedDBPort) {
47
+ console.log(`\n${colors.bold}Database Connection${colors.reset}`);
48
+ console.log(` Host: ${serviceInfo.cname}`);
49
+ console.log(` Port: ${serviceInfo.managedDBPort}`);
50
+ }
51
+ console.log('');
52
+ return response;
53
+ }
54
+
55
+ export async function getSSH(vmID, projectId = null, json = false) {
56
+ const config = loadConfig();
57
+ const pid = projectId || config.defaultProject;
58
+ if (!pid) throw new Error('Project ID required');
59
+
60
+ const response = await apiRequest('/api/servers/startSSHDirect', 'POST', {
61
+ vmID: String(vmID), projectID: String(pid), path: '/root/'
62
+ });
63
+
64
+ if (!response.url) throw new Error(response.message || 'Failed to get SSH access');
65
+
66
+ if (json) { outputJson({ url: response.url }); return response; }
67
+
68
+ console.log(`\n${colors.bold}SSH Access${colors.reset}\n`);
69
+ console.log(` Web Terminal: ${colors.cyan}${response.url}${colors.reset}`);
70
+ console.log('');
71
+ return response;
72
+ }
73
+
74
+ /**
75
+ * `--direct` prints the details for connecting with a local ssh client.
76
+ *
77
+ * These come from the service record: /api/servers/startSSHDirect returns a
78
+ * browser terminal URL, not host/port/user, so it cannot answer this.
79
+ */
80
+ export async function getSSHDirect(vmID, projectId = null, json = false) {
81
+ const config = loadConfig();
82
+ const pid = projectId || config.defaultProject;
83
+ if (!pid) throw new Error('Project ID required');
84
+
85
+ const service = await getServiceDetails(vmID, pid);
86
+ if (!service) throw new Error(`Service with vmID ${vmID} not found`);
87
+
88
+ const host = service.ipv4 || service.cname;
89
+ if (!host) throw new Error(`Service ${vmID} has no IP yet; it may still be deploying`);
90
+
91
+ const details = { host, port: 22, user: 'root', command: `ssh root@${host}` };
92
+
93
+ if (json) { outputJson(details); return details; }
94
+
95
+ console.log(`\n${colors.bold}Direct SSH${colors.reset}\n`);
96
+ console.log(` Host: ${host}`);
97
+ console.log(` Port: 22`);
98
+ console.log(` User: root`);
99
+ console.log(`\n ${colors.cyan}${details.command}${colors.reset}`);
100
+ console.log(`\n ${colors.dim}Add your key first: elestio ssh-keys add ${vmID} --name <n> --key "$(awk '{print $1" "$2}' ~/.ssh/id_ed25519.pub)"${colors.reset}`);
101
+ console.log('');
102
+ return details;
103
+ }
104
+
105
+ export async function getVSCode(vmID, projectId = null, json = false) {
106
+ const config = loadConfig();
107
+ const pid = projectId || config.defaultProject;
108
+ if (!pid) throw new Error('Project ID required');
109
+
110
+ const response = await apiRequest('/api/servers/startVSCode', 'POST', {
111
+ vmID: String(vmID), projectID: String(pid)
112
+ });
113
+
114
+ if (!response.url) throw new Error(response.message || 'Failed to get VSCode access');
115
+
116
+ if (json) { outputJson({ url: response.url, user: response.user, password: response.password }); return response; }
117
+
118
+ console.log(`\n${colors.bold}VSCode Web Access${colors.reset}\n`);
119
+ console.log(` URL: ${colors.cyan}${response.url}${colors.reset}`);
120
+ console.log(` User: ${response.user || 'N/A'}`);
121
+ console.log(` Password: ${response.password || 'N/A'}`);
122
+ console.log('');
123
+ return response;
124
+ }
125
+
126
+ export async function getFileExplorer(vmID, projectId = null, json = false) {
127
+ const config = loadConfig();
128
+ const pid = projectId || config.defaultProject;
129
+ if (!pid) throw new Error('Project ID required');
130
+
131
+ const response = await apiRequest('/api/servers/startFileExplorer', 'POST', {
132
+ vmID: String(vmID), projectID: String(pid)
133
+ });
134
+
135
+ if (!response.url) throw new Error(response.message || 'Failed to get File Explorer access');
136
+
137
+ if (json) { outputJson({ url: response.url, user: response.user, password: response.password }); return response; }
138
+
139
+ console.log(`\n${colors.bold}File Explorer Access${colors.reset}\n`);
140
+ console.log(` URL: ${colors.cyan}${response.url}${colors.reset}`);
141
+ console.log(` User: ${response.user || 'N/A'}`);
142
+ console.log(` Password: ${response.password || 'N/A'}`);
143
+ console.log('');
144
+ return response;
145
+ }