runcloud 0.1.92 → 0.1.93

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.
@@ -3,7 +3,7 @@ import crypto from 'node:crypto';
3
3
  import { hostname } from 'node:os';
4
4
  import { spawn } from 'node:child_process';
5
5
  import { ApiClient, ApiError } from '../api.js';
6
- import { clearCredentials, credentialsDisplayPath, loadCredentials, loginCommandName, normalizeApiUrl, saveCredentials, } from '../config.js';
6
+ import { clearCredentials, credentialsDisplayPath, loadCredentials, loginCommandName, normalizeApiUrl, sanitizeAccount, saveCredentials, } from '../config.js';
7
7
  import { acquirePromptIO, ask, PromptAbortedError, select, } from '../prompt.js';
8
8
  import { AuthError, createApiKey, fetchProviders, isValidEmail, isValidOtp, normalizeOtp, sendEmailCode, verifyEmailCode, } from '../runCloudAuth.js';
9
9
  const LOGIN_TIMEOUT_MS = 5 * 60 * 1000;
@@ -91,7 +91,13 @@ export async function startCallbackServer(state, appOrigin, timeoutMs) {
91
91
  res.writeHead(200, { ...corsHeaders, 'Content-Type': 'application/json' });
92
92
  res.end(JSON.stringify({ ok: true }));
93
93
  clearTimeout(timer);
94
- resolvePayload(parsed);
94
+ const account = sanitizeAccount(parsed.account);
95
+ resolvePayload({
96
+ token: parsed.token,
97
+ expiresIn: parsed.expiresIn,
98
+ apiUrl: parsed.apiUrl,
99
+ ...(account ? { account } : {}),
100
+ });
95
101
  }
96
102
  catch {
97
103
  res.writeHead(400, corsHeaders);
@@ -186,7 +192,13 @@ export function parseManualCredential(blob) {
186
192
  throw new Error('Pasted credential is missing required fields (expected JSON with token, expiresIn, apiUrl). ' +
187
193
  'Copy the entire blob shown in the browser.');
188
194
  }
189
- return { token: c.token, expiresIn: c.expiresIn, apiUrl: c.apiUrl };
195
+ const account = sanitizeAccount(c.account);
196
+ return {
197
+ token: c.token,
198
+ expiresIn: c.expiresIn,
199
+ apiUrl: c.apiUrl,
200
+ ...(account ? { account } : {}),
201
+ };
190
202
  }
191
203
  export async function verifyRunCloudCredential(apiUrl, token) {
192
204
  try {
@@ -318,6 +330,7 @@ export function registerLogin(program) {
318
330
  apiUrl: parsed.apiUrl,
319
331
  appUrl: opts.appUrl,
320
332
  expiresAt: Math.floor(Date.now() / 1000) + parsed.expiresIn,
333
+ ...(parsed.account ? { account: parsed.account } : {}),
321
334
  });
322
335
  console.log('Logged in.');
323
336
  return;
@@ -380,6 +393,7 @@ export function registerLogin(program) {
380
393
  appUrl: opts.appUrl,
381
394
  expiresAt: Math.floor(Date.now() / 1000) + payload.expiresIn,
382
395
  revocable: true,
396
+ ...(payload.account ? { account: payload.account } : {}),
383
397
  });
384
398
  console.log(`Logged in. Credentials saved to ${credentialsDisplayPath()}`);
385
399
  return;
@@ -400,8 +414,10 @@ export function registerLogin(program) {
400
414
  apiUrl: payload.apiUrl,
401
415
  appUrl: opts.appUrl,
402
416
  expiresAt: Math.floor(Date.now() / 1000) + payload.expiresIn,
417
+ ...(payload.account ? { account: payload.account } : {}),
403
418
  });
404
- console.log(`Logged in. Credentials saved to ${credentialsDisplayPath()}`);
419
+ console.log(`Logged in${payload.account ? ` as ${payload.account}` : ''}. ` +
420
+ `Credentials saved to ${credentialsDisplayPath()}`);
405
421
  }
406
422
  finally {
407
423
  close();
package/dist/config.js CHANGED
@@ -1,6 +1,15 @@
1
1
  import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
3
  import { basename, join } from 'node:path';
4
+ const MAX_ACCOUNT_LENGTH = 320;
5
+ export function sanitizeAccount(value) {
6
+ if (typeof value !== 'string')
7
+ return undefined;
8
+ const trimmed = value.trim();
9
+ if (trimmed.length === 0 || trimmed.length > MAX_ACCOUNT_LENGTH)
10
+ return undefined;
11
+ return trimmed;
12
+ }
4
13
  export function isRunCloud() {
5
14
  const names = [process.argv[1], process.execPath].map((path) => basename(path ?? ''));
6
15
  return names.some((name) => name === 'runcloud' || name === 'run-cloud' || name === 'run-cloud.js');
@@ -1,4 +1,4 @@
1
- import { normalizeApiUrl } from "./config.js";
1
+ import { normalizeApiUrl, sanitizeAccount } from "./config.js";
2
2
  export async function runDeviceLogin(deps) {
3
3
  const fetchFn = deps.fetchFn ?? fetch;
4
4
  const log = deps.log ?? ((m) => console.log(m));
@@ -32,7 +32,13 @@ export async function runDeviceLogin(deps) {
32
32
  });
33
33
  if (res.ok) {
34
34
  const body = (await res.json());
35
- return { token: body.token, apiUrl: body.apiUrl, expiresIn: body.expiresIn };
35
+ const account = sanitizeAccount(body.account);
36
+ return {
37
+ token: body.token,
38
+ apiUrl: body.apiUrl,
39
+ expiresIn: body.expiresIn,
40
+ ...(account ? { account } : {}),
41
+ };
36
42
  }
37
43
  const { error } = (await res.json().catch(() => ({ error: "unknown" })));
38
44
  if (error === "authorization_pending")
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = '0.1.92';
1
+ export const CLI_VERSION = '0.1.93';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runcloud",
3
- "version": "0.1.92",
3
+ "version": "0.1.93",
4
4
  "description": "Create and control run.cloud remote mobile simulators and cloud sandboxes",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [