@seguelac/aca-cli 0.1.0 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to `aca-cli` are documented here. Format loosely follows [Keep a Changelog](https://keepachangelog.com/).
4
4
 
5
+ ## [0.2.0] - 2026-05-26
6
+
7
+ ### Added
8
+ - **API token authentication**: `aca login --token <value>` (or `$ACA_TOKEN`). Works for any user, including Google sign-in. Generate a token at app.aca.io → Settings → CLI Tokens.
9
+ - `aca whoami` now reports the active auth method (`api_token` vs legacy `jwt`).
10
+
11
+ ### Changed
12
+ - Backend: 4 critical edge functions (`enroll-leads`, `bulk-add-to-list`, `crm-send-message`, `inbox-autopilot-trigger`) now accept both Supabase JWTs and CLI tokens via a unified `_shared/cli-auth.ts` helper.
13
+ - `enroll-leads` previously trusted the caller's `organizationId` from the request body. It now requires authentication and rejects cross-org enrollment.
14
+ - Sessions for v0.1.x users are auto-detected as `jwt`; legacy email/password login still works for backwards compatibility.
15
+
16
+ ### Security
17
+ - Closed an authentication gap in `enroll-leads`: the function previously accepted unauthenticated calls and any `organizationId` from the request body.
18
+
5
19
  ## [0.1.0] - 2026-05-25
6
20
 
7
21
  Initial release.
package/README.md CHANGED
@@ -13,19 +13,25 @@ Requires Node.js 18 or later.
13
13
  ## Quick start
14
14
 
15
15
  ```bash
16
- # 1. Log in (same credentials as the app)
17
- aca login
16
+ # 1. Generate a token at app.aca.io → Settings → CLI Tokens
17
+ # (Required for Google sign-in users; recommended for everyone.)
18
+ aca login --token aca_<paste-token-here>
18
19
 
19
- # 2. Pick an organization (skip if you only belong to one)
20
- aca org ls
21
- aca org switch <organizationId>
22
-
23
- # 3. Use it
20
+ # 2. Use it
24
21
  aca leads search --tag warm --has-email
25
22
  aca enroll -c <campaignId> --contacts <id1,id2>
26
23
  aca inbox unread --channel linkedin
27
24
  ```
28
25
 
26
+ **Legacy email/password login** is still supported for accounts that have a password set:
27
+
28
+ ```bash
29
+ aca login # prompts for email + password
30
+ aca login -e you@example.com -p <password>
31
+ ```
32
+
33
+ If your account uses Google sign-in, email/password login won't work — generate a token instead.
34
+
29
35
  Pass `--json` to any command for pipe-friendly output:
30
36
 
31
37
  ```bash
@@ -37,9 +43,10 @@ aca campaign leads <campaignId> --stuck --json | jq '.[] | .contact_id'
37
43
  ### Auth
38
44
  | Command | What it does |
39
45
  |---|---|
40
- | `aca login` | Email + password login. Caches a JWT at `~/.aca/session.json` (auto-refreshing). |
46
+ | `aca login --token <value>` | **Recommended.** Save an API token from app.aca.io. Works for any account (Google, SSO, password). Token is long-lived; revoke at any time in the app. |
47
+ | `aca login` | Email + password login (legacy). Auto-refreshing JWT. Doesn't work for Google sign-in users. |
41
48
  | `aca logout` | Clears the cached session. |
42
- | `aca whoami` | Shows the currently logged-in user. |
49
+ | `aca whoami` | Shows the active auth method (token vs JWT). |
43
50
 
44
51
  ### Organization
45
52
  | Command | What it does |
@@ -135,8 +142,9 @@ aca config set update_check_enabled false
135
142
 
136
143
  | Variable | Purpose |
137
144
  |---|---|
138
- | `ACA_EMAIL` | Skip the email prompt during `aca login` |
139
- | `ACA_PASSWORD` | Skip the password prompt during `aca login` (use with care in shared shells) |
145
+ | `ACA_TOKEN` | Skip `--token` flag. CLI uses this for auth on every command. Useful for CI. |
146
+ | `ACA_EMAIL` | Skip the email prompt during legacy `aca login` |
147
+ | `ACA_PASSWORD` | Skip the password prompt during legacy `aca login` (use with care in shared shells) |
140
148
 
141
149
  ## Development
142
150
 
@@ -1,21 +1,37 @@
1
- import { login, clearSession, readSession } from '../session.js';
1
+ import { loginWithToken, loginWithPassword, clearSession, readSession, } from '../session.js';
2
2
  import { output, fail } from '../output.js';
3
3
  import { silentPrompt, visiblePrompt } from '../prompt.js';
4
4
  export function registerAuth(program) {
5
5
  program
6
6
  .command('login')
7
- .description('Authenticate and cache a session at ~/.aca/session.json')
8
- .option('-e, --email <email>', 'Email (defaults to $ACA_EMAIL or prompt)')
9
- .option('-p, --password <password>', 'Password (defaults to $ACA_PASSWORD or prompt)')
7
+ .description('Authenticate the CLI. Use --token (recommended) or email/password.')
8
+ .option('-t, --token <token>', 'API token from app.aca.io → Settings → CLI Tokens (or $ACA_TOKEN). Works for all auth methods including Google sign-in.')
9
+ .option('-e, --email <email>', 'Email (legacy password login; falls back to $ACA_EMAIL or prompt)')
10
+ .option('-p, --password <password>', 'Password (legacy; falls back to $ACA_PASSWORD or prompt)')
10
11
  .action(async (opts) => {
12
+ const tokenInput = opts.token || process.env.ACA_TOKEN;
13
+ if (tokenInput) {
14
+ const session = loginWithToken(tokenInput.trim());
15
+ output({
16
+ method: 'api_token',
17
+ token_prefix: session.access_token.slice(0, 12) + '…',
18
+ hint: 'Run `aca whoami` to verify, or `aca --help` to see commands.',
19
+ });
20
+ return;
21
+ }
11
22
  const email = opts.email || process.env.ACA_EMAIL || (await visiblePrompt('Email: '));
12
23
  const password = opts.password || process.env.ACA_PASSWORD || (await silentPrompt('Password: '));
13
24
  if (!email || !password)
14
- fail('email and password required');
15
- const session = await login(email, password);
25
+ fail('email and password required (or use --token)');
26
+ const session = await loginWithPassword(email, password);
16
27
  output({
28
+ method: 'jwt',
17
29
  logged_in_as: session.email,
18
- expires_at: new Date(session.expires_at * 1000).toISOString(),
30
+ expires_at: session.expires_at
31
+ ? new Date(session.expires_at * 1000).toISOString()
32
+ : null,
33
+ hint: 'Heads-up: token-based login (`aca login --token <value>`) is recommended. ' +
34
+ 'Generate one at app.aca.io → Settings → CLI Tokens.',
19
35
  });
20
36
  });
21
37
  program
@@ -27,15 +43,24 @@ export function registerAuth(program) {
27
43
  });
28
44
  program
29
45
  .command('whoami')
30
- .description('Show the cached session user')
46
+ .description('Show how the CLI is authenticated')
31
47
  .action(() => {
32
48
  const s = readSession();
33
- if (!s?.email)
34
- fail('Not logged in. Run `aca login`.');
35
- output({
36
- email: s.email,
37
- user_id: s.user_id,
38
- expires_at: new Date(s.expires_at * 1000).toISOString(),
39
- });
49
+ if (!s?.access_token)
50
+ fail('Not logged in. Run `aca login --token <value>`.');
51
+ if (s.auth_method === 'api_token') {
52
+ output({
53
+ method: 'api_token',
54
+ token_prefix: s.access_token.slice(0, 12) + '…',
55
+ });
56
+ }
57
+ else {
58
+ output({
59
+ method: 'jwt',
60
+ email: s.email,
61
+ user_id: s.user_id,
62
+ expires_at: s.expires_at ? new Date(s.expires_at * 1000).toISOString() : null,
63
+ });
64
+ }
40
65
  });
41
66
  }
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import { registerAutopilot } from './commands/autopilot.js';
13
13
  import { registerConfig } from './commands/config.js';
14
14
  import { registerCompletion } from './commands/completion.js';
15
15
  import { maybeCheckForUpdate } from './update-check.js';
16
- const VERSION = '0.1.0';
16
+ const VERSION = '0.2.0';
17
17
  const program = new Command();
18
18
  program
19
19
  .name('aca')
package/dist/session.js CHANGED
@@ -9,6 +9,8 @@ export function readSession() {
9
9
  const data = JSON.parse(readFileSync(path, 'utf8'));
10
10
  if (!data?.access_token)
11
11
  return null;
12
+ if (!data.auth_method)
13
+ data.auth_method = 'jwt';
12
14
  return data;
13
15
  }
14
16
  catch {
@@ -25,7 +27,18 @@ export function clearSession() {
25
27
  if (existsSync(path))
26
28
  writeFileSync(path, '{}', { mode: 0o600 });
27
29
  }
28
- export async function login(email, password) {
30
+ export function loginWithToken(token) {
31
+ if (!token.startsWith('aca_') || token.length < 20) {
32
+ throw new Error('Invalid token format. Expected `aca_<...>`.');
33
+ }
34
+ const session = {
35
+ auth_method: 'api_token',
36
+ access_token: token,
37
+ };
38
+ writeSession(session);
39
+ return session;
40
+ }
41
+ export async function loginWithPassword(email, password) {
29
42
  const res = await fetch(`${SUPABASE_URL}/auth/v1/token?grant_type=password`, {
30
43
  method: 'POST',
31
44
  headers: {
@@ -36,10 +49,16 @@ export async function login(email, password) {
36
49
  });
37
50
  if (!res.ok) {
38
51
  const body = await res.text();
52
+ if (res.status === 400 && /invalid login credentials/i.test(body)) {
53
+ throw new Error('Email/password sign-in failed. If your account uses Google sign-in, ' +
54
+ 'generate a token at app.aca.io → Settings → CLI Tokens and run ' +
55
+ '`aca login --token <value>` instead.');
56
+ }
39
57
  throw new Error(`Login failed (${res.status}): ${body}`);
40
58
  }
41
59
  const data = (await res.json());
42
60
  const session = {
61
+ auth_method: 'jwt',
43
62
  access_token: data.access_token,
44
63
  refresh_token: data.refresh_token,
45
64
  expires_at: Math.floor(Date.now() / 1000) + (data.expires_in ?? 3600),
@@ -49,7 +68,10 @@ export async function login(email, password) {
49
68
  writeSession(session);
50
69
  return session;
51
70
  }
52
- async function refresh(session) {
71
+ async function refreshJwt(session) {
72
+ if (!session.refresh_token) {
73
+ throw new Error('Session has no refresh token. Run `aca login` again.');
74
+ }
53
75
  const res = await fetch(`${SUPABASE_URL}/auth/v1/token?grant_type=refresh_token`, {
54
76
  method: 'POST',
55
77
  headers: { apikey: SUPABASE_ANON_KEY, 'Content-Type': 'application/json' },
@@ -72,9 +94,12 @@ export async function getAccessToken() {
72
94
  if (!session?.access_token) {
73
95
  throw new Error('Not logged in. Run `aca login` first.');
74
96
  }
97
+ if (session.auth_method === 'api_token') {
98
+ return session.access_token;
99
+ }
75
100
  const now = Math.floor(Date.now() / 1000);
76
101
  if (session.expires_at && session.expires_at - now < 60) {
77
- const refreshed = await refresh(session);
102
+ const refreshed = await refreshJwt(session);
78
103
  return refreshed.access_token;
79
104
  }
80
105
  return session.access_token;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seguelac/aca-cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Command-line interface for ACA (Automated Client Acquisition) — push leads to campaigns, triage replies, manage contacts, all from your terminal.",
5
5
  "type": "module",
6
6
  "bin": {