@seguelac/aca-cli 0.1.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 ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ All notable changes to `aca-cli` are documented here. Format loosely follows [Keep a Changelog](https://keepachangelog.com/).
4
+
5
+ ## [0.1.0] - 2026-05-25
6
+
7
+ Initial release.
8
+
9
+ ### Added
10
+ - `aca login` / `logout` / `whoami` — email + password authentication, cached at `~/.aca/session.json` with auto-refresh
11
+ - `aca org ls` / `org switch` / `org current` — multi-organization support
12
+ - `aca enroll` — bulk enroll contacts or an entire list into a campaign sequence
13
+ - `aca lists` — create, list, add, remove, list members
14
+ - `aca leads search` / `leads get` — search across name, email, company; filter by tag, status, presence of email/LinkedIn
15
+ - `aca inbox unread` / `inbox show` / `inbox list` — triage CRM conversations across all channels
16
+ - `aca reply` — send a reply to an existing conversation (email, LinkedIn, Instagram, WhatsApp, etc.)
17
+ - `aca campaign ls` / `campaign status` / `campaign leads` — campaign monitoring, including stuck-lead detection
18
+ - `aca contact get` / `contact tag` / `contact set-status` — single-contact ops
19
+ - `aca autopilot ls` / `trigger` / `pause` / `resume` — AI autopilot controls
20
+ - `aca config show` / `set` / `unset` — local CLI configuration
21
+ - `aca completion <shell>` — bash, zsh, and fish completion scripts
22
+ - Daily background update check (disable with `aca config set update_check_enabled false`)
23
+ - `--json` flag on all commands for pipeable output
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Cedric Seguela
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # aca-cli
2
+
3
+ Command-line interface for [ACA](https://app.aca.io) (Automated Client Acquisition) — push leads into campaigns, triage replies, manage contacts, and run autopilot, all from your terminal.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g @seguelac/aca-cli
9
+ ```
10
+
11
+ Requires Node.js 18 or later.
12
+
13
+ ## Quick start
14
+
15
+ ```bash
16
+ # 1. Log in (same credentials as the app)
17
+ aca login
18
+
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
24
+ aca leads search --tag warm --has-email
25
+ aca enroll -c <campaignId> --contacts <id1,id2>
26
+ aca inbox unread --channel linkedin
27
+ ```
28
+
29
+ Pass `--json` to any command for pipe-friendly output:
30
+
31
+ ```bash
32
+ aca campaign leads <campaignId> --stuck --json | jq '.[] | .contact_id'
33
+ ```
34
+
35
+ ## Commands
36
+
37
+ ### Auth
38
+ | Command | What it does |
39
+ |---|---|
40
+ | `aca login` | Email + password login. Caches a JWT at `~/.aca/session.json` (auto-refreshing). |
41
+ | `aca logout` | Clears the cached session. |
42
+ | `aca whoami` | Shows the currently logged-in user. |
43
+
44
+ ### Organization
45
+ | Command | What it does |
46
+ |---|---|
47
+ | `aca org ls` | Lists all organizations you belong to. |
48
+ | `aca org switch <id>` | Sets the active org for subsequent commands. |
49
+ | `aca org current` | Shows the active org. |
50
+
51
+ ### Leads → campaign
52
+ | Command | What it does |
53
+ |---|---|
54
+ | `aca leads search [filters]` | Search contacts. Filters: `--query`, `--tag`, `--status`, `--company`, `--has-email`, `--has-linkedin`. |
55
+ | `aca leads get <contactId>` | Full contact record. |
56
+ | `aca lists ls` | List your lead lists. |
57
+ | `aca lists create -n "Name"` | Create a new list. |
58
+ | `aca lists add -l <listId> --contacts <ids>` | Bulk-add contacts to a list. |
59
+ | `aca lists members -l <listId>` | List members of a list. |
60
+ | `aca lists remove -l <listId> --contacts <ids>` | Remove contacts from a list. |
61
+ | `aca enroll -c <campaignId> -l <listId>` | Enroll an entire list into a campaign. |
62
+ | `aca enroll -c <campaignId> --contacts <ids>` | Enroll specific contacts. |
63
+
64
+ ### Inbox & replies
65
+ | Command | What it does |
66
+ |---|---|
67
+ | `aca inbox unread` | List unread conversations across all channels. `--channel linkedin\|email\|...` to filter. |
68
+ | `aca inbox show <id>` | Show a conversation and its recent messages. |
69
+ | `aca inbox list` | List all conversations. Filters: `--channel`, `--status`, `--intent`. |
70
+ | `aca reply <id> -m "..."` | Reply to a conversation. Also accepts piped stdin. |
71
+
72
+ ### Campaigns
73
+ | Command | What it does |
74
+ |---|---|
75
+ | `aca campaign ls` | List sequences. |
76
+ | `aca campaign status <id>` | Aggregate progress counts (pending, replied, failed, etc.). |
77
+ | `aca campaign leads <id> --stuck` | List stuck leads (status: failed or sender_disconnected). |
78
+
79
+ ### Contacts
80
+ | Command | What it does |
81
+ |---|---|
82
+ | `aca contact get <id>` | Full record. |
83
+ | `aca contact tag <id> --add tag1,tag2 --remove tag3` | Add/remove tags. |
84
+ | `aca contact set-status <id> -s do_not_contact` | Update status. |
85
+
86
+ ### Autopilot
87
+ | Command | What it does |
88
+ |---|---|
89
+ | `aca autopilot ls` | List autopilot configurations. |
90
+ | `aca autopilot trigger <conversationId>` | Queue an AI draft. |
91
+ | `aca autopilot pause <conversationId> --hours 48` | Pause AI on a conversation. |
92
+ | `aca autopilot resume <conversationId>` | Re-enable AI. |
93
+
94
+ ### Config & completion
95
+ | Command | What it does |
96
+ |---|---|
97
+ | `aca config show` | Display current config. |
98
+ | `aca config set <key> <value>` | Set a value. Keys: `active_org_id`, `update_check_enabled`. |
99
+ | `aca config unset <key>` | Remove a value. |
100
+ | `aca completion zsh \| bash \| fish` | Print shell completion script. |
101
+
102
+ To install completions in zsh:
103
+
104
+ ```bash
105
+ aca completion zsh > "${fpath[1]}/_aca"
106
+ ```
107
+
108
+ In bash:
109
+
110
+ ```bash
111
+ aca completion bash > /usr/local/etc/bash_completion.d/aca
112
+ ```
113
+
114
+ In fish:
115
+
116
+ ```bash
117
+ aca completion fish > ~/.config/fish/completions/aca.fish
118
+ ```
119
+
120
+ ## Configuration
121
+
122
+ The CLI stores files under `~/.aca/`:
123
+
124
+ - `session.json` — cached auth token (0600 permissions)
125
+ - `config.json` — local preferences (active org, update-check setting)
126
+ - `update-check.json` — timestamp + cached latest version
127
+
128
+ To disable the daily update check:
129
+
130
+ ```bash
131
+ aca config set update_check_enabled false
132
+ ```
133
+
134
+ ## Environment variables
135
+
136
+ | Variable | Purpose |
137
+ |---|---|
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) |
140
+
141
+ ## Development
142
+
143
+ ```bash
144
+ git clone https://github.com/seguelaCedric/aca-cli
145
+ cd aca-cli
146
+ npm install
147
+ npm run dev # tsc --watch
148
+ npm test # vitest
149
+ npm run build # tsc once
150
+ ```
151
+
152
+ Local dev binary:
153
+
154
+ ```bash
155
+ node dist/index.js <command>
156
+ ```
157
+
158
+ ## Release
159
+
160
+ Bump version in `package.json` + `CHANGELOG.md`, commit, tag, push:
161
+
162
+ ```bash
163
+ npm version patch # or minor / major
164
+ git push --follow-tags
165
+ ```
166
+
167
+ The `Release` GitHub Actions workflow runs tests and publishes to npm on tags matching `v*.*.*`. Requires `NPM_TOKEN` secret in the repo settings.
168
+
169
+ ## License
170
+
171
+ MIT — see [LICENSE](LICENSE).
package/dist/api.js ADDED
@@ -0,0 +1,88 @@
1
+ import { SUPABASE_URL, SUPABASE_ANON_KEY } from './constants.js';
2
+ import { getAccessToken } from './session.js';
3
+ async function authHeaders() {
4
+ const token = await getAccessToken();
5
+ return {
6
+ apikey: SUPABASE_ANON_KEY,
7
+ Authorization: `Bearer ${token}`,
8
+ };
9
+ }
10
+ export async function restGet(path) {
11
+ const headers = await authHeaders();
12
+ const res = await fetch(`${SUPABASE_URL}/rest/v1/${path}`, {
13
+ method: 'GET',
14
+ headers: { ...headers, Accept: 'application/json' },
15
+ });
16
+ if (!res.ok) {
17
+ const body = await res.text();
18
+ throw new Error(`REST GET ${path} -> ${res.status}: ${body}`);
19
+ }
20
+ return (await res.json());
21
+ }
22
+ export async function restPatch(path, body) {
23
+ const headers = await authHeaders();
24
+ const res = await fetch(`${SUPABASE_URL}/rest/v1/${path}`, {
25
+ method: 'PATCH',
26
+ headers: { ...headers, 'Content-Type': 'application/json', Prefer: 'return=representation' },
27
+ body: JSON.stringify(body),
28
+ });
29
+ if (!res.ok) {
30
+ const txt = await res.text();
31
+ throw new Error(`REST PATCH ${path} -> ${res.status}: ${txt}`);
32
+ }
33
+ return (await res.json());
34
+ }
35
+ export async function restPost(path, body, { upsert = false } = {}) {
36
+ const headers = await authHeaders();
37
+ const preferParts = ['return=representation'];
38
+ if (upsert)
39
+ preferParts.push('resolution=merge-duplicates');
40
+ const res = await fetch(`${SUPABASE_URL}/rest/v1/${path}`, {
41
+ method: 'POST',
42
+ headers: {
43
+ ...headers,
44
+ 'Content-Type': 'application/json',
45
+ Prefer: preferParts.join(','),
46
+ },
47
+ body: JSON.stringify(body),
48
+ });
49
+ if (!res.ok) {
50
+ const txt = await res.text();
51
+ throw new Error(`REST POST ${path} -> ${res.status}: ${txt}`);
52
+ }
53
+ return (await res.json());
54
+ }
55
+ export async function restDelete(path) {
56
+ const headers = await authHeaders();
57
+ const res = await fetch(`${SUPABASE_URL}/rest/v1/${path}`, {
58
+ method: 'DELETE',
59
+ headers,
60
+ });
61
+ if (!res.ok) {
62
+ const txt = await res.text();
63
+ throw new Error(`REST DELETE ${path} -> ${res.status}: ${txt}`);
64
+ }
65
+ return res.status === 204 ? null : await res.json();
66
+ }
67
+ export async function invokeFn(name, body) {
68
+ const headers = await authHeaders();
69
+ const res = await fetch(`${SUPABASE_URL}/functions/v1/${name}`, {
70
+ method: 'POST',
71
+ headers: { ...headers, 'Content-Type': 'application/json' },
72
+ body: JSON.stringify(body ?? {}),
73
+ });
74
+ const text = await res.text();
75
+ let parsed;
76
+ try {
77
+ parsed = text ? JSON.parse(text) : null;
78
+ }
79
+ catch {
80
+ parsed = { raw: text };
81
+ }
82
+ if (!res.ok) {
83
+ const obj = parsed;
84
+ const msg = obj?.error || obj?.message || text || `${res.status}`;
85
+ throw new Error(`fn ${name} -> ${res.status}: ${msg}`);
86
+ }
87
+ return parsed;
88
+ }
@@ -0,0 +1,41 @@
1
+ import { login, clearSession, readSession } from '../session.js';
2
+ import { output, fail } from '../output.js';
3
+ import { silentPrompt, visiblePrompt } from '../prompt.js';
4
+ export function registerAuth(program) {
5
+ program
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)')
10
+ .action(async (opts) => {
11
+ const email = opts.email || process.env.ACA_EMAIL || (await visiblePrompt('Email: '));
12
+ const password = opts.password || process.env.ACA_PASSWORD || (await silentPrompt('Password: '));
13
+ if (!email || !password)
14
+ fail('email and password required');
15
+ const session = await login(email, password);
16
+ output({
17
+ logged_in_as: session.email,
18
+ expires_at: new Date(session.expires_at * 1000).toISOString(),
19
+ });
20
+ });
21
+ program
22
+ .command('logout')
23
+ .description('Clear the cached session')
24
+ .action(() => {
25
+ clearSession();
26
+ output({ logged_out: true });
27
+ });
28
+ program
29
+ .command('whoami')
30
+ .description('Show the cached session user')
31
+ .action(() => {
32
+ 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
+ });
40
+ });
41
+ }
@@ -0,0 +1,52 @@
1
+ import { invokeFn, restGet, restPatch } from '../api.js';
2
+ import { output, fail } from '../output.js';
3
+ export function registerAutopilot(program) {
4
+ const autopilot = program.command('autopilot').description('Manage AI autopilot for inbox conversations');
5
+ autopilot
6
+ .command('ls')
7
+ .description('List autopilot configurations')
8
+ .option('--limit <n>', 'Max rows', '50')
9
+ .option('--json', 'Emit JSON')
10
+ .action(async (opts) => {
11
+ const rows = await restGet(`autopilots?select=id,name,status,channel,created_at,updated_at&order=updated_at.desc&limit=${opts.limit}`);
12
+ output(rows, { json: opts.json });
13
+ });
14
+ autopilot
15
+ .command('trigger')
16
+ .description('Trigger AI autopilot on an existing conversation')
17
+ .argument('<conversationId>')
18
+ .option('--json', 'Emit JSON')
19
+ .action(async (conversationId, opts) => {
20
+ const result = await invokeFn('inbox-autopilot-trigger', { conversationId });
21
+ output(result, { json: opts.json });
22
+ });
23
+ autopilot
24
+ .command('pause')
25
+ .description('Pause AI on a conversation')
26
+ .argument('<conversationId>')
27
+ .option('--hours <n>', 'How many hours to pause', '24')
28
+ .option('--json', 'Emit JSON')
29
+ .action(async (conversationId, opts) => {
30
+ const hours = Number(opts.hours);
31
+ if (!Number.isFinite(hours) || hours <= 0)
32
+ fail('--hours must be a positive number');
33
+ const until = new Date(Date.now() + hours * 3600_000).toISOString();
34
+ const updated = await restPatch(`crm_conversations?id=eq.${conversationId}`, {
35
+ ai_enabled: false,
36
+ ai_paused_until: until,
37
+ });
38
+ output(Array.isArray(updated) ? updated[0] : updated, { json: opts.json });
39
+ });
40
+ autopilot
41
+ .command('resume')
42
+ .description('Re-enable AI on a conversation')
43
+ .argument('<conversationId>')
44
+ .option('--json', 'Emit JSON')
45
+ .action(async (conversationId, opts) => {
46
+ const updated = await restPatch(`crm_conversations?id=eq.${conversationId}`, {
47
+ ai_enabled: true,
48
+ ai_paused_until: null,
49
+ });
50
+ output(Array.isArray(updated) ? updated[0] : updated, { json: opts.json });
51
+ });
52
+ }
@@ -0,0 +1,57 @@
1
+ import { restGet } from '../api.js';
2
+ import { output } from '../output.js';
3
+ const STUCK_STATUSES = ['failed', 'sender_disconnected'];
4
+ export function registerCampaign(program) {
5
+ const campaign = program.command('campaign').description('Inspect campaigns / sequences');
6
+ campaign
7
+ .command('ls')
8
+ .description('List sequences for the current org')
9
+ .option('--limit <n>', 'Max rows', '50')
10
+ .option('--json', 'Emit JSON')
11
+ .action(async (opts) => {
12
+ const rows = await restGet(`crm_sequences?select=id,name,status,channel,created_at,updated_at&order=updated_at.desc&limit=${opts.limit}`);
13
+ output(rows, { json: opts.json });
14
+ });
15
+ campaign
16
+ .command('status')
17
+ .description('Aggregate progress counts for a campaign')
18
+ .argument('<campaignId>')
19
+ .option('--json', 'Emit JSON')
20
+ .action(async (campaignId, opts) => {
21
+ const rows = await restGet(`campaign_lead_progress?campaign_id=eq.${campaignId}&select=status&limit=10000`);
22
+ const counts = rows.reduce((acc, row) => {
23
+ acc[row.status] = (acc[row.status] ?? 0) + 1;
24
+ return acc;
25
+ }, {});
26
+ const stuck = STUCK_STATUSES.reduce((n, s) => n + (counts[s] ?? 0), 0);
27
+ output({
28
+ campaign_id: campaignId,
29
+ total_leads: rows.length,
30
+ counts_by_status: counts,
31
+ stuck_leads: stuck,
32
+ }, { json: opts.json });
33
+ });
34
+ campaign
35
+ .command('leads')
36
+ .description('List leads on a campaign (filter by --stuck or --status)')
37
+ .argument('<campaignId>')
38
+ .option('--stuck', 'Only stuck leads (status in failed, sender_disconnected)')
39
+ .option('--status <status>', 'Filter by specific status')
40
+ .option('--limit <n>', 'Max rows', '50')
41
+ .option('--json', 'Emit JSON')
42
+ .action(async (campaignId, opts) => {
43
+ const params = new URLSearchParams();
44
+ params.append('select', 'id,contact_id,status,current_node_id,next_action_at,error_message,retry_count,crm_contacts(display_name,company,primary_email)');
45
+ params.append('campaign_id', `eq.${campaignId}`);
46
+ params.append('order', 'next_action_at.desc.nullslast');
47
+ params.append('limit', String(opts.limit));
48
+ if (opts.stuck) {
49
+ params.append('status', `in.(${STUCK_STATUSES.join(',')})`);
50
+ }
51
+ else if (opts.status) {
52
+ params.append('status', `eq.${opts.status}`);
53
+ }
54
+ const rows = await restGet(`campaign_lead_progress?${params.toString()}`);
55
+ output(rows, { json: opts.json });
56
+ });
57
+ }
@@ -0,0 +1,69 @@
1
+ import { fail } from '../output.js';
2
+ import { CLI_NAME } from '../constants.js';
3
+ function collectCommandNames(program) {
4
+ const names = [];
5
+ const walk = (cmd, prefix) => {
6
+ for (const sub of cmd.commands) {
7
+ const name = sub.name();
8
+ const full = [...prefix, name].join(' ');
9
+ names.push(full);
10
+ walk(sub, [...prefix, name]);
11
+ }
12
+ };
13
+ walk(program, []);
14
+ return names;
15
+ }
16
+ function bash(program) {
17
+ const commands = collectCommandNames(program).join(' ');
18
+ return `# aca-cli bash completion
19
+ _aca_completion() {
20
+ local cur prev words cword
21
+ _init_completion || return
22
+ local commands="${commands}"
23
+ COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
24
+ }
25
+ complete -F _aca_completion ${CLI_NAME}
26
+ `;
27
+ }
28
+ function zsh(program) {
29
+ const commands = collectCommandNames(program)
30
+ .map((c) => `"${c}"`)
31
+ .join(' ');
32
+ return `#compdef ${CLI_NAME}
33
+ # aca-cli zsh completion
34
+ _aca() {
35
+ local -a commands
36
+ commands=(${commands})
37
+ _arguments '*::command:->subcmd'
38
+ case $state in
39
+ subcmd) _describe 'command' commands ;;
40
+ esac
41
+ }
42
+ _aca "$@"
43
+ `;
44
+ }
45
+ function fish(program) {
46
+ const lines = collectCommandNames(program).map((c) => `complete -c ${CLI_NAME} -f -a "${c}"`);
47
+ return `# aca-cli fish completion\n${lines.join('\n')}\n`;
48
+ }
49
+ export function registerCompletion(program) {
50
+ program
51
+ .command('completion')
52
+ .description('Print shell completion script (pipe into your shell rc file)')
53
+ .argument('<shell>', 'bash | zsh | fish')
54
+ .action((shell) => {
55
+ switch (shell) {
56
+ case 'bash':
57
+ process.stdout.write(bash(program));
58
+ break;
59
+ case 'zsh':
60
+ process.stdout.write(zsh(program));
61
+ break;
62
+ case 'fish':
63
+ process.stdout.write(fish(program));
64
+ break;
65
+ default:
66
+ fail(`Unknown shell "${shell}". Supported: bash, zsh, fish`);
67
+ }
68
+ });
69
+ }
@@ -0,0 +1,48 @@
1
+ import { readConfig, updateConfig } from '../config.js';
2
+ import { output, fail } from '../output.js';
3
+ const ALLOWED_KEYS = ['active_org_id', 'update_check_enabled'];
4
+ function coerce(key, raw) {
5
+ if (key === 'update_check_enabled') {
6
+ if (raw === 'true' || raw === '1')
7
+ return true;
8
+ if (raw === 'false' || raw === '0')
9
+ return false;
10
+ fail(`update_check_enabled must be true or false, got "${raw}"`);
11
+ }
12
+ return raw;
13
+ }
14
+ export function registerConfig(program) {
15
+ const config = program.command('config').description('Manage CLI configuration');
16
+ config
17
+ .command('show')
18
+ .description('Show current config')
19
+ .option('--json', 'Emit JSON')
20
+ .action((opts) => {
21
+ output(readConfig(), { json: opts.json });
22
+ });
23
+ config
24
+ .command('set')
25
+ .description(`Set a config key. Allowed: ${ALLOWED_KEYS.join(', ')}`)
26
+ .argument('<key>')
27
+ .argument('<value>')
28
+ .option('--json', 'Emit JSON')
29
+ .action((key, value, opts) => {
30
+ if (!ALLOWED_KEYS.includes(key)) {
31
+ fail(`Unknown key "${key}". Allowed: ${ALLOWED_KEYS.join(', ')}`);
32
+ }
33
+ const next = updateConfig({ [key]: coerce(key, value) });
34
+ output(next, { json: opts.json });
35
+ });
36
+ config
37
+ .command('unset')
38
+ .description('Remove a config key')
39
+ .argument('<key>')
40
+ .option('--json', 'Emit JSON')
41
+ .action((key, opts) => {
42
+ if (!ALLOWED_KEYS.includes(key)) {
43
+ fail(`Unknown key "${key}". Allowed: ${ALLOWED_KEYS.join(', ')}`);
44
+ }
45
+ const next = updateConfig({ [key]: undefined });
46
+ output(next, { json: opts.json });
47
+ });
48
+ }
@@ -0,0 +1,58 @@
1
+ import { restGet, restPatch } from '../api.js';
2
+ import { output, fail } from '../output.js';
3
+ import { parseList } from '../util.js';
4
+ const ALLOWED_STATUSES = ['active', 'archived', 'bounced', 'unsubscribed', 'do_not_contact'];
5
+ export function registerContact(program) {
6
+ const contact = program.command('contact').description('Inspect and mutate a single contact');
7
+ contact
8
+ .command('get')
9
+ .description('Fetch a single contact by ID')
10
+ .argument('<contactId>')
11
+ .option('--json', 'Emit JSON')
12
+ .action(async (contactId, opts) => {
13
+ const rows = await restGet(`crm_contacts?id=eq.${contactId}&select=*`);
14
+ output(rows[0] ?? null, { json: opts.json });
15
+ });
16
+ contact
17
+ .command('tag')
18
+ .description('Add or remove tags on a contact (mutates tags[] column)')
19
+ .argument('<contactId>')
20
+ .option('--add <tags>', 'Comma-separated tags to add')
21
+ .option('--remove <tags>', 'Comma-separated tags to remove')
22
+ .option('--json', 'Emit JSON')
23
+ .action(async (contactId, opts) => {
24
+ const add = parseList(opts.add);
25
+ const remove = parseList(opts.remove);
26
+ if (add.length === 0 && remove.length === 0)
27
+ fail('Provide --add and/or --remove');
28
+ const rows = await restGet(`crm_contacts?id=eq.${contactId}&select=id,tags`);
29
+ const contactRow = rows[0];
30
+ if (!contactRow)
31
+ fail(`Contact ${contactId} not found`);
32
+ const current = new Set(contactRow.tags ?? []);
33
+ for (const t of add)
34
+ current.add(t);
35
+ for (const t of remove)
36
+ current.delete(t);
37
+ const nextTags = Array.from(current);
38
+ const updated = await restPatch(`crm_contacts?id=eq.${contactId}`, {
39
+ tags: nextTags,
40
+ });
41
+ output(Array.isArray(updated) ? updated[0] : updated, { json: opts.json });
42
+ });
43
+ contact
44
+ .command('set-status')
45
+ .description('Update contact status')
46
+ .argument('<contactId>')
47
+ .requiredOption('-s, --status <status>', `New status: ${ALLOWED_STATUSES.join(' | ')}`)
48
+ .option('--json', 'Emit JSON')
49
+ .action(async (contactId, opts) => {
50
+ if (!ALLOWED_STATUSES.includes(opts.status)) {
51
+ fail(`status must be one of: ${ALLOWED_STATUSES.join(', ')}`);
52
+ }
53
+ const updated = await restPatch(`crm_contacts?id=eq.${contactId}`, {
54
+ status: opts.status,
55
+ });
56
+ output(Array.isArray(updated) ? updated[0] : updated, { json: opts.json });
57
+ });
58
+ }
@@ -0,0 +1,32 @@
1
+ import { invokeFn } from '../api.js';
2
+ import { readConfig } from '../config.js';
3
+ import { output, fail } from '../output.js';
4
+ import { parseList } from '../util.js';
5
+ export function registerEnroll(program) {
6
+ program
7
+ .command('enroll')
8
+ .description('Enroll leads into a campaign sequence')
9
+ .requiredOption('-c, --campaign <sequenceId>', 'Campaign / sequence ID')
10
+ .option('-l, --list <listId>', 'Enroll an entire lead list')
11
+ .option('--contacts <ids>', 'Comma-separated contact IDs')
12
+ .option('-o, --organization <orgId>', 'Override active organization')
13
+ .option('--json', 'Emit JSON')
14
+ .action(async (opts) => {
15
+ const orgId = opts.organization || readConfig().active_org_id;
16
+ if (!orgId) {
17
+ fail('No active organization. Run `aca org switch <id>` or pass --organization.');
18
+ }
19
+ const body = {
20
+ sequenceId: opts.campaign,
21
+ organizationId: orgId,
22
+ };
23
+ if (opts.list)
24
+ body.listId = opts.list;
25
+ else if (opts.contacts)
26
+ body.contactIds = parseList(opts.contacts);
27
+ else
28
+ fail('Provide either --list <id> or --contacts <id1,id2,...>');
29
+ const result = await invokeFn('enroll-leads', body);
30
+ output(result, { json: opts.json });
31
+ });
32
+ }