api-response-manager 2.6.3 → 2.6.4
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/commands/login.js +55 -3
- package/commands/tunnel.js +3 -3
- package/package.json +1 -1
package/commands/login.js
CHANGED
|
@@ -1,10 +1,57 @@
|
|
|
1
1
|
const inquirer = require('inquirer');
|
|
2
2
|
const chalk = require('chalk');
|
|
3
3
|
const ora = require('ora');
|
|
4
|
-
const
|
|
4
|
+
const { spawn } = require('child_process');
|
|
5
5
|
const api = require('../utils/api');
|
|
6
6
|
const config = require('../utils/config');
|
|
7
7
|
|
|
8
|
+
// Safe browser opener that never throws
|
|
9
|
+
function openBrowserSafe(url) {
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
const platform = process.platform;
|
|
12
|
+
let cmd, args;
|
|
13
|
+
|
|
14
|
+
if (platform === 'win32') {
|
|
15
|
+
cmd = 'cmd.exe';
|
|
16
|
+
args = ['/c', 'start', '""', url];
|
|
17
|
+
} else if (platform === 'darwin') {
|
|
18
|
+
cmd = 'open';
|
|
19
|
+
args = [url];
|
|
20
|
+
} else {
|
|
21
|
+
cmd = 'xdg-open';
|
|
22
|
+
args = [url];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const child = spawn(cmd, args, {
|
|
27
|
+
detached: true,
|
|
28
|
+
stdio: 'ignore'
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
let resolved = false;
|
|
32
|
+
|
|
33
|
+
child.on('error', () => {
|
|
34
|
+
if (!resolved) {
|
|
35
|
+
resolved = true;
|
|
36
|
+
resolve(false);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// On successful spawn, unref and resolve after brief delay
|
|
41
|
+
child.unref();
|
|
42
|
+
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
if (!resolved) {
|
|
45
|
+
resolved = true;
|
|
46
|
+
resolve(true);
|
|
47
|
+
}
|
|
48
|
+
}, 100);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
resolve(false);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
8
55
|
async function login(options) {
|
|
9
56
|
// Token-based login for CI/CD automation
|
|
10
57
|
if (options.token) {
|
|
@@ -165,8 +212,13 @@ async function socialLogin(provider) {
|
|
|
165
212
|
]);
|
|
166
213
|
|
|
167
214
|
if (openBrowser) {
|
|
168
|
-
await
|
|
169
|
-
|
|
215
|
+
const browserOpened = await openBrowserSafe(verification_uri);
|
|
216
|
+
|
|
217
|
+
if (browserOpened) {
|
|
218
|
+
console.log(chalk.gray(' ✓ Browser opened\n'));
|
|
219
|
+
} else {
|
|
220
|
+
console.log(chalk.yellow(' ⚠ Could not open browser automatically. Please open the URL manually.\n'));
|
|
221
|
+
}
|
|
170
222
|
}
|
|
171
223
|
|
|
172
224
|
const pollSpinner = ora('Waiting for authentication...').start();
|
package/commands/tunnel.js
CHANGED
|
@@ -160,11 +160,11 @@ async function connectTunnelClient(tunnelId, subdomain, localPort, protocol = 'h
|
|
|
160
160
|
console.log(chalk.white(` TCP Port: ${message.tcpPort}\n`));
|
|
161
161
|
if (message.sshCommand) {
|
|
162
162
|
console.log(chalk.gray('SSH Command (Linux/Mac):'));
|
|
163
|
-
console.log(chalk.cyan(` ${message.
|
|
163
|
+
console.log(chalk.cyan(` ssh -o ProxyCommand="sh -c '{ printf \\"SUBDOMAIN:${subdomain}\\\\n\\"; cat; } | nc %h %p'" user@${message.tcpHost} -p ${message.tcpPort}\n`));
|
|
164
164
|
console.log(chalk.gray('SSH Command (Windows with ncat):'));
|
|
165
|
-
console.log(chalk.cyan(` ssh -o ProxyCommand="ncat ${message.tcpHost} ${message.tcpPort}" user@${message.tcpHost}\n`));
|
|
165
|
+
console.log(chalk.cyan(` ssh -o ProxyCommand="cmd /c \\"(echo SUBDOMAIN:${subdomain}& type CON) | ncat ${message.tcpHost} ${message.tcpPort}\\"" user@${message.tcpHost}\n`));
|
|
166
166
|
console.log(chalk.gray('SSH with Key (passwordless):'));
|
|
167
|
-
console.log(chalk.cyan(` ssh -i ~/.ssh/your_key.pem -o ProxyCommand="
|
|
167
|
+
console.log(chalk.cyan(` ssh -i ~/.ssh/your_key.pem -o ProxyCommand="sh -c '{ printf \\"SUBDOMAIN:${subdomain}\\\\n\\"; cat; } | nc %h %p'" user@${message.tcpHost} -p ${message.tcpPort}\n`));
|
|
168
168
|
}
|
|
169
169
|
} else {
|
|
170
170
|
// Display QR code for HTTP/HTTPS tunnels (not for TCP/SSH)
|