@andocorp/cli 0.3.1 → 0.3.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.
@@ -1,11 +1,26 @@
1
1
  import { spawn } from "node:child_process";
2
2
  const BROWSER_LAUNCH_TIMEOUT_MS = 5_000;
3
+ export class CliLoginBrowserUrlError extends Error {
4
+ }
5
+ export function validateBrowserLoginUrl(url) {
6
+ let parsed;
7
+ try {
8
+ parsed = new URL(url);
9
+ }
10
+ catch {
11
+ throw new CliLoginBrowserUrlError("Refusing to open browser: login URL is not a valid URL.");
12
+ }
13
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
14
+ throw new CliLoginBrowserUrlError("Refusing to open browser: login URL must be http(s).");
15
+ }
16
+ }
3
17
  export async function sleep(ms) {
4
18
  await new Promise((resolve) => {
5
19
  setTimeout(resolve, Math.max(0, ms));
6
20
  });
7
21
  }
8
22
  export async function openBrowser(url, platform = process.platform, launchProcess = spawn) {
23
+ validateBrowserLoginUrl(url);
9
24
  const { args, command } = getBrowserLauncher(platform, url);
10
25
  await new Promise((resolve, reject) => {
11
26
  const child = launchProcess(command, args, {
package/dist/cli-login.js CHANGED
@@ -1,8 +1,8 @@
1
- import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
2
- import path from "node:path";
1
+ import { readFile, rm } from "node:fs/promises";
3
2
  import { sleep } from "./cli-login-browser.js";
4
3
  import { CliLoginRequestError } from "./cli-login-errors.js";
5
4
  import { getPendingCliLoginPath, getPendingCliLoginPaths } from "./cli-login-paths.js";
5
+ import { writeFileSecure } from "./config-secure-write.js";
6
6
  import { DEFAULT_CLI_REQUEST_TIMEOUT_MS } from "./timeouts.js";
7
7
  const CREATE_CLI_LOGIN_SESSION_PATH = "/auth/cli-login/session";
8
8
  const REDEEM_CLI_LOGIN_SESSION_PATH = "/auth/cli-login/redeem";
@@ -30,18 +30,15 @@ const terminalCliLoginErrorMessages = {
30
30
  invalid_request: "CLI login request was invalid. Run `ando login` again.",
31
31
  unsupported_api_key_type: "This API key cannot be revoked by the CLI.",
32
32
  };
33
- export { openBrowser, sleep } from "./cli-login-browser.js";
33
+ export { CliLoginBrowserUrlError, openBrowser, sleep, validateBrowserLoginUrl, } from "./cli-login-browser.js";
34
34
  export { CliLoginRequestError } from "./cli-login-errors.js";
35
35
  export async function savePendingCliLoginSession(session) {
36
36
  const pendingPath = getPendingCliLoginPath();
37
- await mkdir(path.dirname(pendingPath), { recursive: true });
38
37
  const payload = {
39
38
  ...session,
40
39
  savedAt: new Date().toISOString(),
41
40
  };
42
- await writeFile(pendingPath, JSON.stringify(payload, null, 2), {
43
- mode: 0o600,
44
- });
41
+ await writeFileSecure(pendingPath, JSON.stringify(payload, null, 2));
45
42
  }
46
43
  export async function readPendingCliLoginSession() {
47
44
  try {
package/dist/commands.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DEFAULT_ANDO_BASE_URL } from "@andocorp/sdk";
2
2
  import { getStringFlag, hasFlag } from "./args.js";
3
- import { CliLoginRequestError, clearPendingCliLoginSession, createCliLoginSession, openBrowser, pollCliLoginSession, readPendingCliLoginSession, savePendingCliLoginSession, } from "./cli-login.js";
3
+ import { CliLoginBrowserUrlError, CliLoginRequestError, clearPendingCliLoginSession, createCliLoginSession, openBrowser, pollCliLoginSession, readPendingCliLoginSession, savePendingCliLoginSession, validateBrowserLoginUrl, } from "./cli-login.js";
4
4
  import { getConfigPath, readSavedConfigMetadata, saveConfig } from "./config.js";
5
5
  import { getConfiguredApiHost, getConfiguredBaseUrl, getConfiguredRealtimeHost, } from "./session.js";
6
6
  export async function runLogin(parsedArgs, dependencies = {}) {
@@ -31,6 +31,7 @@ async function runBrowserLogin(parsedArgs, dependencies, context) {
31
31
  const session = await (dependencies.createCliLoginSession ?? createCliLoginSession)({
32
32
  baseUrl: context.hosts.baseUrl,
33
33
  });
34
+ validateBrowserLoginUrl(session.browserUrl);
34
35
  if (hasFlag(parsedArgs, "no-browser")) {
35
36
  await (dependencies.savePendingCliLoginSession ?? savePendingCliLoginSession)({
36
37
  ...session,
@@ -43,7 +44,10 @@ async function runBrowserLogin(parsedArgs, dependencies, context) {
43
44
  try {
44
45
  await (dependencies.openBrowser ?? openBrowser)(session.browserUrl);
45
46
  }
46
- catch {
47
+ catch (error) {
48
+ if (error instanceof CliLoginBrowserUrlError) {
49
+ throw error;
50
+ }
47
51
  await (dependencies.savePendingCliLoginSession ?? savePendingCliLoginSession)({
48
52
  ...session,
49
53
  ...context.hosts,
@@ -0,0 +1,8 @@
1
+ import { mkdir, rename, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ export async function writeFileSecure(filePath, contents) {
4
+ await mkdir(path.dirname(filePath), { recursive: true });
5
+ const tempPath = `${filePath}.${process.pid}.tmp`;
6
+ await writeFile(tempPath, contents, { flag: "wx", mode: 0o600 });
7
+ await rename(tempPath, filePath);
8
+ }
package/dist/config.js CHANGED
@@ -1,9 +1,10 @@
1
- import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
1
+ import { readFile, rm } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { deleteKeyringCredentialsForProfile, readKeyringCredential, writeKeyringCredential, } from "./config-keyring.js";
4
4
  import { getAuthPath, getConfigPath, getConfigReadPaths, isFileCredentialStorageEnabled, } from "./config-paths.js";
5
5
  import { DEFAULT_CREDENTIAL_ACCOUNT, } from "./config-types.js";
6
6
  import { buildSavedConfigMetadata, getCredentialMetadataKey, getSaveCredentialMetadata, readCredentialMetadataMap, readCredentialSource, } from "./config-credential-metadata.js";
7
+ import { writeFileSecure } from "./config-secure-write.js";
7
8
  export { getConfigPath } from "./config-paths.js";
8
9
  function isRecord(value) {
9
10
  return value != null && typeof value === "object" && !Array.isArray(value);
@@ -139,8 +140,7 @@ async function writeFileCredential(account, apiKey, configRoot) {
139
140
  }))
140
141
  : {};
141
142
  credentials[account] = { apiKey, savedAt };
142
- await mkdir(path.dirname(authPath), { recursive: true });
143
- await writeFile(authPath, JSON.stringify({ credentials, savedAt, version: 1 }, null, 2), { mode: 0o600 });
143
+ await writeFileSecure(authPath, JSON.stringify({ credentials, savedAt, version: 1 }, null, 2));
144
144
  }
145
145
  async function deleteFileCredential(account, configRoot) {
146
146
  const authPath = getAuthPath(configRoot);
@@ -167,7 +167,7 @@ async function deleteFileCredential(account, configRoot) {
167
167
  await rm(authPath, { force: true });
168
168
  return readFileCredentialFromAuth(existing, account) != null;
169
169
  }
170
- await writeFile(authPath, JSON.stringify({ credentials, savedAt: new Date().toISOString(), version: 1 }, null, 2), { mode: 0o600 });
170
+ await writeFileSecure(authPath, JSON.stringify({ credentials, savedAt: new Date().toISOString(), version: 1 }, null, 2));
171
171
  return true;
172
172
  }
173
173
  async function readCredential(credential, configRoot) {
@@ -326,8 +326,5 @@ export async function saveConfig(config) {
326
326
  setOptionalString(payload, "defaultWorkspaceId", config.defaultWorkspaceId);
327
327
  setOptionalString(payload, "defaultWorkspaceMembershipId", config.defaultWorkspaceMembershipId);
328
328
  setOptionalString(payload, "realtimeHost", config.realtimeHost);
329
- await mkdir(path.dirname(configPath), { recursive: true });
330
- await writeFile(configPath, JSON.stringify(payload, null, 2), {
331
- mode: 0o600,
332
- });
329
+ await writeFileSecure(configPath, JSON.stringify(payload, null, 2));
333
330
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andocorp/cli",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Ando CLI - agent-first terminal commands",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,14 +15,18 @@
15
15
  "author": "Asari Inc.",
16
16
  "license": "MIT",
17
17
  "files": [
18
- "dist"
18
+ "dist",
19
+ "README.md"
19
20
  ],
20
21
  "publishConfig": {
21
22
  "access": "public"
22
23
  },
24
+ "engines": {
25
+ "node": ">=20"
26
+ },
23
27
  "dependencies": {
24
28
  "@napi-rs/keyring": "^1.3.0",
25
- "@andocorp/sdk": "0.2.1"
29
+ "@andocorp/sdk": "0.2.2"
26
30
  },
27
31
  "devDependencies": {
28
32
  "@types/node": "^25.9.4",
@@ -31,11 +35,11 @@
31
35
  "vitest": "^4.1.9"
32
36
  },
33
37
  "scripts": {
34
- "build": "cd ../sdk && pnpm run build && cd ../cli && rm -rf dist && tsc && chmod +x ./dist/index.js",
38
+ "build": "node ../../scripts/ensure-sdk-dist.mjs && rm -rf dist && tsc && chmod +x ./dist/index.js",
35
39
  "dev": "pnpm run build && node ./dist/index.js",
36
40
  "lint": "tsc --noEmit",
37
- "test": "cd ../sdk && pnpm run build && cd ../cli && vitest run",
38
- "test:coverage": "cd ../sdk && pnpm run build && cd ../cli && vitest run --coverage",
39
- "typecheck": "cd ../sdk && pnpm run build && cd ../cli && tsc --noEmit"
41
+ "test": "node ../../scripts/ensure-sdk-dist.mjs && vitest run",
42
+ "test:coverage": "node ../../scripts/ensure-sdk-dist.mjs && vitest run --coverage",
43
+ "typecheck": "node ../../scripts/ensure-sdk-dist.mjs && tsc --noEmit"
40
44
  }
41
45
  }