cloud-pc-templates 1.1.0 → 1.1.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.
@@ -19,36 +19,41 @@ function promptForApiKey() {
19
19
  stdin.resume();
20
20
 
21
21
  let apiKey = '';
22
- let isFirstInput = true;
23
22
 
24
- stdin.on('data', (byte) => {
25
- const char = byte.toString();
23
+ stdin.on('data', (buffer) => {
24
+ const chunk = buffer.toString();
26
25
 
27
- if (char === '\n' || char === '\r' || char === '\u0004') {
28
- // Enter or EOF
29
- if (stdin.isTTY) {
30
- stdin.setRawMode(false);
31
- }
32
- stdin.pause();
33
- stdin.removeAllListeners('data');
34
- console.log('');
35
- resolve(apiKey);
36
- } else if (char === '\u0003') {
37
- // Ctrl+C
38
- if (stdin.isTTY) {
39
- stdin.setRawMode(false);
40
- }
41
- process.exit();
42
- } else if (char === '\x7f' || char === '\b') {
43
- // Backspace
44
- if (apiKey.length > 0) {
45
- apiKey = apiKey.slice(0, -1);
46
- process.stdout.write('\x1b[D\x1b[K');
26
+ // Process each character in the chunk (handles pasted text)
27
+ for (let i = 0; i < chunk.length; i++) {
28
+ const char = chunk[i];
29
+
30
+ if (char === '\n' || char === '\r' || char === '\u0004') {
31
+ // Enter or EOF
32
+ if (stdin.isTTY) {
33
+ stdin.setRawMode(false);
34
+ }
35
+ stdin.pause();
36
+ stdin.removeAllListeners('data');
37
+ console.log('');
38
+ resolve(apiKey);
39
+ return;
40
+ } else if (char === '\u0003') {
41
+ // Ctrl+C
42
+ if (stdin.isTTY) {
43
+ stdin.setRawMode(false);
44
+ }
45
+ process.exit();
46
+ } else if (char === '\x7f' || char === '\b') {
47
+ // Backspace
48
+ if (apiKey.length > 0) {
49
+ apiKey = apiKey.slice(0, -1);
50
+ process.stdout.write('\x1b[D\x1b[K');
51
+ }
52
+ } else if (char >= '\x20' && char <= '\x7e') {
53
+ // Printable character
54
+ apiKey += char;
55
+ process.stdout.write('*');
47
56
  }
48
- } else if (char >= '\x20' && char <= '\x7e') {
49
- // Printable character
50
- apiKey += char;
51
- process.stdout.write('*');
52
57
  }
53
58
  });
54
59
  });
@@ -92,30 +97,46 @@ async function downloadAndRunProxy(endpoint) {
92
97
  // Get API key from user
93
98
  const apiKey = await promptForApiKey();
94
99
 
95
- // Run the proxy with API key passed as environment variable
100
+ // Run the proxy with API key passed as command-line argument
96
101
  return new Promise((resolve, reject) => {
97
- const env = Object.assign({}, process.env, { API_KEY: apiKey });
98
- const child = spawn('node', [tempFile], { env });
102
+ const child = spawn('node', [tempFile, apiKey]);
99
103
 
100
- child.on('close', (code) => {
101
- if (code === 0) {
102
- // Wait a bit for the server to start, then validate
103
- setTimeout(async () => {
104
- const isHealthy = await checkHealthEndpoint(endpoint);
105
- if (isHealthy) {
106
- console.log('✓ Logged in');
107
- console.log(` - Endpoint checked: ${endpoint}`);
108
- } else {
109
- console.log('✓ Proxy started');
110
- console.log(` - Endpoint: ${endpoint}`);
111
- }
112
- resolve();
113
- }, 1000);
114
- } else {
115
- reject(new Error('Proxy process failed'));
104
+ let serverReady = false;
105
+
106
+ // Capture stdout to detect when server is ready
107
+ child.stdout.on('data', (data) => {
108
+ const output = data.toString();
109
+ console.log(output);
110
+
111
+ // Check if server indicates it's ready
112
+ if (output.includes('listening') || output.includes('started') || output.includes('running')) {
113
+ serverReady = true;
116
114
  }
117
115
  });
118
116
 
117
+ // Capture stderr for error messages
118
+ child.stderr.on('data', (data) => {
119
+ console.error(data.toString());
120
+ });
121
+
122
+ // Wait a bit for server to start, then validate
123
+ setTimeout(async () => {
124
+ try {
125
+ const isHealthy = await checkHealthEndpoint(endpoint);
126
+ if (isHealthy) {
127
+ console.log('✓ Logged in');
128
+ console.log(` - Endpoint checked: ${endpoint}`);
129
+ resolve();
130
+ } else {
131
+ console.log('✓ Proxy started');
132
+ console.log(` - Endpoint: ${endpoint}`);
133
+ resolve();
134
+ }
135
+ } catch (error) {
136
+ reject(error);
137
+ }
138
+ }, 2000);
139
+
119
140
  child.on('error', reject);
120
141
  });
121
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloud-pc-templates",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {