@seguelac/aca-cli 0.1.0 → 0.4.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 +23 -0
- package/README.md +19 -11
- package/dist/commands/auth.js +40 -15
- package/dist/commands/contact.js +155 -2
- package/dist/commands/signals.js +117 -0
- package/dist/index.js +3 -1
- package/dist/session.js +28 -3
- package/dist/util.js +70 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
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.4.0] - 2026-07-18
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **`aca contact bulk-create`**: create many CRM contacts from a CSV/JSON file (`--file`) or piped stdin. Splits large inputs into batched requests (`--batch-size`, max 1000), dedups on email by default (`--no-dedupe` to override), supports `--source`, `--no-activity`, and `--dry-run`. CSV tags go in one cell separated by `;`.
|
|
9
|
+
- Backed by a new `bulk-create-contacts` edge function (also usable directly as a REST API) and a matching `bulk_create_contacts` MCP tool — all three share one core so behavior is identical across surfaces.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
- Reconciled the version number: the built binary reported `0.3.0` while `package.json` was `0.2.0`. Both are now `0.4.0`.
|
|
13
|
+
|
|
14
|
+
## [0.2.0] - 2026-05-26
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- **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.
|
|
18
|
+
- `aca whoami` now reports the active auth method (`api_token` vs legacy `jwt`).
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
- 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.
|
|
22
|
+
- `enroll-leads` previously trusted the caller's `organizationId` from the request body. It now requires authentication and rejects cross-org enrollment.
|
|
23
|
+
- Sessions for v0.1.x users are auto-detected as `jwt`; legacy email/password login still works for backwards compatibility.
|
|
24
|
+
|
|
25
|
+
### Security
|
|
26
|
+
- Closed an authentication gap in `enroll-leads`: the function previously accepted unauthenticated calls and any `organizationId` from the request body.
|
|
27
|
+
|
|
5
28
|
## [0.1.0] - 2026-05-25
|
|
6
29
|
|
|
7
30
|
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.
|
|
17
|
-
|
|
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.
|
|
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
|
|
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
|
|
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
|
-
| `
|
|
139
|
-
| `
|
|
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
|
|
package/dist/commands/auth.js
CHANGED
|
@@ -1,21 +1,37 @@
|
|
|
1
|
-
import {
|
|
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
|
|
8
|
-
.option('-
|
|
9
|
-
.option('-
|
|
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
|
|
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:
|
|
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
|
|
46
|
+
.description('Show how the CLI is authenticated')
|
|
31
47
|
.action(() => {
|
|
32
48
|
const s = readSession();
|
|
33
|
-
if (!s?.
|
|
34
|
-
fail('Not logged in. Run `aca login
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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/commands/contact.js
CHANGED
|
@@ -1,7 +1,93 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { extname } from 'node:path';
|
|
3
|
+
import { invokeFn, restGet, restPatch } from '../api.js';
|
|
2
4
|
import { output, fail } from '../output.js';
|
|
3
|
-
import { parseList } from '../util.js';
|
|
5
|
+
import { parseCsv, parseList, readStdinIfPiped } from '../util.js';
|
|
4
6
|
const ALLOWED_STATUSES = ['active', 'archived', 'bounced', 'unsubscribed', 'do_not_contact'];
|
|
7
|
+
const CONTACT_FIELDS = [
|
|
8
|
+
'display_name',
|
|
9
|
+
'first_name',
|
|
10
|
+
'last_name',
|
|
11
|
+
'company',
|
|
12
|
+
'job_title',
|
|
13
|
+
'primary_email',
|
|
14
|
+
'primary_phone',
|
|
15
|
+
'primary_linkedin_url',
|
|
16
|
+
'company_website',
|
|
17
|
+
'city',
|
|
18
|
+
'state',
|
|
19
|
+
'country',
|
|
20
|
+
'pipeline_id',
|
|
21
|
+
'stage_id',
|
|
22
|
+
'tags',
|
|
23
|
+
'source',
|
|
24
|
+
'custom_fields',
|
|
25
|
+
'owner_user_id',
|
|
26
|
+
];
|
|
27
|
+
const DEFAULT_BATCH_SIZE = 500;
|
|
28
|
+
const MAX_BATCH_SIZE = 1000;
|
|
29
|
+
function normalizeContact(raw) {
|
|
30
|
+
const out = {};
|
|
31
|
+
for (const field of CONTACT_FIELDS) {
|
|
32
|
+
const val = raw[field];
|
|
33
|
+
if (val === undefined || val === null || val === '')
|
|
34
|
+
continue;
|
|
35
|
+
if (field === 'tags') {
|
|
36
|
+
const tags = Array.isArray(val) ? val.map(String) : parseListSemicolon(String(val));
|
|
37
|
+
if (tags.length > 0)
|
|
38
|
+
out.tags = tags;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (field === 'custom_fields') {
|
|
42
|
+
if (typeof val === 'object') {
|
|
43
|
+
out.custom_fields = val;
|
|
44
|
+
}
|
|
45
|
+
else if (typeof val === 'string') {
|
|
46
|
+
try {
|
|
47
|
+
out.custom_fields = JSON.parse(val);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
fail(`custom_fields is not valid JSON: ${val}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
out[field] = typeof val === 'string' ? val.trim() : val;
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
function parseListSemicolon(value) {
|
|
60
|
+
return value
|
|
61
|
+
.split(';')
|
|
62
|
+
.map((s) => s.trim())
|
|
63
|
+
.filter(Boolean);
|
|
64
|
+
}
|
|
65
|
+
function parseContactsInput(text, format) {
|
|
66
|
+
const trimmed = text.trim();
|
|
67
|
+
if (!trimmed)
|
|
68
|
+
return [];
|
|
69
|
+
if (format === 'json') {
|
|
70
|
+
const parsed = JSON.parse(trimmed);
|
|
71
|
+
const arr = Array.isArray(parsed) ? parsed : [parsed];
|
|
72
|
+
return arr;
|
|
73
|
+
}
|
|
74
|
+
return parseCsv(trimmed);
|
|
75
|
+
}
|
|
76
|
+
function inferFormat(explicit, filePath, text) {
|
|
77
|
+
if (explicit === 'csv' || explicit === 'json')
|
|
78
|
+
return explicit;
|
|
79
|
+
if (explicit)
|
|
80
|
+
fail(`--format must be 'csv' or 'json'`);
|
|
81
|
+
if (filePath) {
|
|
82
|
+
const ext = extname(filePath).toLowerCase();
|
|
83
|
+
if (ext === '.json')
|
|
84
|
+
return 'json';
|
|
85
|
+
if (ext === '.csv' || ext === '.tsv')
|
|
86
|
+
return 'csv';
|
|
87
|
+
}
|
|
88
|
+
const t = text.trim();
|
|
89
|
+
return t.startsWith('[') || t.startsWith('{') ? 'json' : 'csv';
|
|
90
|
+
}
|
|
5
91
|
export function registerContact(program) {
|
|
6
92
|
const contact = program.command('contact').description('Inspect and mutate a single contact');
|
|
7
93
|
contact
|
|
@@ -55,4 +141,71 @@ export function registerContact(program) {
|
|
|
55
141
|
});
|
|
56
142
|
output(Array.isArray(updated) ? updated[0] : updated, { json: opts.json });
|
|
57
143
|
});
|
|
144
|
+
contact
|
|
145
|
+
.command('bulk-create')
|
|
146
|
+
.description('Create many contacts from a CSV/JSON file or piped stdin')
|
|
147
|
+
.option('-f, --file <path>', 'Path to a .csv or .json file of contacts')
|
|
148
|
+
.option('--format <fmt>', "Force input format: 'csv' or 'json' (else inferred)")
|
|
149
|
+
.option('--source <source>', 'Default source for contacts that omit one')
|
|
150
|
+
.option('--no-dedupe', 'Insert even if a contact with the same email exists')
|
|
151
|
+
.option('--no-activity', "Skip the per-contact 'contact_created' activity log")
|
|
152
|
+
.option('--batch-size <n>', `Contacts per request (max ${MAX_BATCH_SIZE})`, String(DEFAULT_BATCH_SIZE))
|
|
153
|
+
.option('--dry-run', 'Parse and validate only — do not create anything')
|
|
154
|
+
.option('--json', 'Emit JSON')
|
|
155
|
+
.action(async (opts) => {
|
|
156
|
+
let text = null;
|
|
157
|
+
if (opts.file) {
|
|
158
|
+
try {
|
|
159
|
+
text = readFileSync(opts.file, 'utf8');
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
fail(`Could not read file ${opts.file}: ${err.message}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
text = await readStdinIfPiped();
|
|
167
|
+
}
|
|
168
|
+
if (!text || !text.trim()) {
|
|
169
|
+
fail('No input. Pass --file <path> or pipe CSV/JSON via stdin.');
|
|
170
|
+
}
|
|
171
|
+
const format = inferFormat(opts.format, opts.file, text);
|
|
172
|
+
let rawRecords;
|
|
173
|
+
try {
|
|
174
|
+
rawRecords = parseContactsInput(text, format);
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
fail(`Failed to parse ${format.toUpperCase()} input: ${err.message}`);
|
|
178
|
+
}
|
|
179
|
+
const contacts = rawRecords.map(normalizeContact).filter((c) => Object.keys(c).length > 0);
|
|
180
|
+
if (contacts.length === 0) {
|
|
181
|
+
fail('No contacts found in input.');
|
|
182
|
+
}
|
|
183
|
+
const batchSize = Math.min(Math.max(1, parseInt(opts.batchSize ?? String(DEFAULT_BATCH_SIZE), 10) || DEFAULT_BATCH_SIZE), MAX_BATCH_SIZE);
|
|
184
|
+
if (opts.dryRun) {
|
|
185
|
+
output({ parsed: contacts.length, format, batch_size: batchSize, sample: contacts[0] }, { json: opts.json });
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const totals = { created: 0, skipped: 0, total_submitted: 0 };
|
|
189
|
+
const contactIds = [];
|
|
190
|
+
const batches = Math.ceil(contacts.length / batchSize);
|
|
191
|
+
for (let i = 0; i < contacts.length; i += batchSize) {
|
|
192
|
+
const chunk = contacts.slice(i, i + batchSize);
|
|
193
|
+
const batchNo = Math.floor(i / batchSize) + 1;
|
|
194
|
+
if (!opts.json && batches > 1) {
|
|
195
|
+
process.stderr.write(`Batch ${batchNo}/${batches} (${chunk.length} contacts)...\n`);
|
|
196
|
+
}
|
|
197
|
+
const res = await invokeFn('bulk-create-contacts', {
|
|
198
|
+
contacts: chunk,
|
|
199
|
+
dedupe_on_email: opts.dedupe !== false,
|
|
200
|
+
log_activity: opts.activity !== false,
|
|
201
|
+
source: opts.source,
|
|
202
|
+
});
|
|
203
|
+
totals.created += res.created ?? 0;
|
|
204
|
+
totals.skipped += res.skipped ?? 0;
|
|
205
|
+
totals.total_submitted += res.total_submitted ?? chunk.length;
|
|
206
|
+
if (Array.isArray(res.contact_ids))
|
|
207
|
+
contactIds.push(...res.contact_ids);
|
|
208
|
+
}
|
|
209
|
+
output(opts.json ? { ...totals, contact_ids: contactIds } : totals, { json: opts.json });
|
|
210
|
+
});
|
|
58
211
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { invokeFn, restPost } from '../api.js';
|
|
2
|
+
import { output, fail } from '../output.js';
|
|
3
|
+
const SIGNAL_TYPES = [
|
|
4
|
+
'funding', 'acquisition', 'hiring', 'hiring_demand', 'job_change',
|
|
5
|
+
'executive_hire', 'customer_win', 'award', 'growth',
|
|
6
|
+
];
|
|
7
|
+
function parsePerson(raw) {
|
|
8
|
+
const parts = raw.split('|').map((p) => p.trim());
|
|
9
|
+
const [full_name, title, linkedin_url, photo_url] = parts;
|
|
10
|
+
if (!full_name)
|
|
11
|
+
fail(`--person needs a name: "${raw}"`);
|
|
12
|
+
if (!linkedin_url)
|
|
13
|
+
fail(`--person needs a linkedin url (3rd field): "${raw}"`);
|
|
14
|
+
return { full_name, linkedin_url, title: title || undefined, photo_url: photo_url || undefined };
|
|
15
|
+
}
|
|
16
|
+
export function registerSignals(program) {
|
|
17
|
+
const signals = program
|
|
18
|
+
.command('signals')
|
|
19
|
+
.description('Push and curate the public /signals buying-signals feed');
|
|
20
|
+
signals
|
|
21
|
+
.command('push')
|
|
22
|
+
.description('Push a buying signal (with optional people) onto the public feed')
|
|
23
|
+
.requiredOption('--company <name>', 'Company name')
|
|
24
|
+
.requiredOption('--type <type>', `Signal type (${SIGNAL_TYPES.join(', ')})`)
|
|
25
|
+
.requiredOption('--source-url <url>', 'Evidence/source URL')
|
|
26
|
+
.option('--domain <domain>', 'Company domain (used for logo)')
|
|
27
|
+
.option('--country <country>')
|
|
28
|
+
.option('--location <location>', 'Display location, e.g. "Berlin, DE"')
|
|
29
|
+
.option('--title <title>', 'Short headline for the signal')
|
|
30
|
+
.option('--summary <summary>', 'One-to-two sentence summary')
|
|
31
|
+
.option('--why <why>', 'Why it matters for outreach')
|
|
32
|
+
.option('--amount <label>', 'Human amount, e.g. "$12M"')
|
|
33
|
+
.option('--amount-usd <number>', 'Numeric amount in USD', (v) => Number(v))
|
|
34
|
+
.option('--date <YYYY-MM-DD>', 'Signal date (defaults to today, UTC)')
|
|
35
|
+
.option('--source-key <key>', "Machine source key, e.g. 'google_news_rss'")
|
|
36
|
+
.option('--source-label <label>', "Human source label, e.g. 'Google News'")
|
|
37
|
+
.option('--verified', 'Mark the signal verified')
|
|
38
|
+
.option('--quality <number>', '0..1 quality/relevance score', (v) => Number(v))
|
|
39
|
+
.option('--unpublished', 'Stage the row without publishing it')
|
|
40
|
+
.option('--company-linkedin <url>')
|
|
41
|
+
.option('--logo <url>', 'Explicit logo URL')
|
|
42
|
+
.option('--dedup-key <key>', 'Override the idempotency key')
|
|
43
|
+
.option('--person <spec>', 'Decision-maker "Name | Title | linkedin_url | photo_url" (repeatable)', (val, acc) => { acc.push(parsePerson(val)); return acc; }, [])
|
|
44
|
+
.option('--json', 'Emit JSON')
|
|
45
|
+
.action(async (opts) => {
|
|
46
|
+
const type = String(opts.type);
|
|
47
|
+
if (!SIGNAL_TYPES.includes(type)) {
|
|
48
|
+
fail(`--type must be one of: ${SIGNAL_TYPES.join(', ')}`);
|
|
49
|
+
}
|
|
50
|
+
const body = {
|
|
51
|
+
company_name: opts.company,
|
|
52
|
+
signal_type: type,
|
|
53
|
+
source_url: opts.sourceUrl,
|
|
54
|
+
domain: opts.domain,
|
|
55
|
+
country: opts.country,
|
|
56
|
+
location: opts.location,
|
|
57
|
+
title: opts.title,
|
|
58
|
+
summary: opts.summary,
|
|
59
|
+
why_it_matters: opts.why,
|
|
60
|
+
amount_label: opts.amount,
|
|
61
|
+
amount_usd: opts.amountUsd,
|
|
62
|
+
signal_date: opts.date,
|
|
63
|
+
source_key: opts.sourceKey,
|
|
64
|
+
source_label: opts.sourceLabel,
|
|
65
|
+
verified: Boolean(opts.verified),
|
|
66
|
+
quality_score: opts.quality,
|
|
67
|
+
published: opts.unpublished ? false : true,
|
|
68
|
+
company_linkedin_url: opts.companyLinkedin,
|
|
69
|
+
logo_url: opts.logo,
|
|
70
|
+
dedup_key: opts.dedupKey,
|
|
71
|
+
people: opts.person ?? [],
|
|
72
|
+
};
|
|
73
|
+
const res = await invokeFn('push-public-signal', body);
|
|
74
|
+
output(res, { json: Boolean(opts.json) });
|
|
75
|
+
});
|
|
76
|
+
signals
|
|
77
|
+
.command('ls')
|
|
78
|
+
.description('List public signals (includes unpublished)')
|
|
79
|
+
.option('--search <text>', 'Filter by company/domain/summary')
|
|
80
|
+
.option('--limit <n>', 'Max rows (default 50)', (v) => Number(v), 50)
|
|
81
|
+
.option('--offset <n>', 'Offset', (v) => Number(v), 0)
|
|
82
|
+
.option('--published-only', 'Hide staged/unpublished rows')
|
|
83
|
+
.option('--json', 'Emit JSON')
|
|
84
|
+
.action(async (opts) => {
|
|
85
|
+
const res = await restPost('rpc/admin_list_public_signals', {
|
|
86
|
+
p_limit: opts.limit,
|
|
87
|
+
p_offset: opts.offset,
|
|
88
|
+
p_search: opts.search ?? null,
|
|
89
|
+
p_include_unpublished: !opts.publishedOnly,
|
|
90
|
+
});
|
|
91
|
+
if (!res.ok)
|
|
92
|
+
fail(res.error === 'forbidden'
|
|
93
|
+
? 'Forbidden — your account is not a member of the public-signals org.'
|
|
94
|
+
: `Failed: ${res.error}`);
|
|
95
|
+
output(opts.json ? res : (res.signals ?? []), { json: Boolean(opts.json) });
|
|
96
|
+
});
|
|
97
|
+
const setPublished = (publish) => async (id, opts) => {
|
|
98
|
+
const res = await restPost('rpc/admin_set_public_signal_published', { p_id: id, p_published: publish });
|
|
99
|
+
if (!res.ok)
|
|
100
|
+
fail(res.error === 'not_found' ? 'Signal not found.'
|
|
101
|
+
: res.error === 'forbidden' ? 'Forbidden — not a public-signals org member.'
|
|
102
|
+
: `Failed: ${res.error}`);
|
|
103
|
+
output(res, { json: Boolean(opts.json) });
|
|
104
|
+
};
|
|
105
|
+
signals
|
|
106
|
+
.command('hide')
|
|
107
|
+
.description('Unpublish a signal (hide it from the public feed)')
|
|
108
|
+
.argument('<signalId>')
|
|
109
|
+
.option('--json', 'Emit JSON')
|
|
110
|
+
.action(setPublished(false));
|
|
111
|
+
signals
|
|
112
|
+
.command('publish')
|
|
113
|
+
.description('Publish a previously-hidden signal')
|
|
114
|
+
.argument('<signalId>')
|
|
115
|
+
.option('--json', 'Emit JSON')
|
|
116
|
+
.action(setPublished(true));
|
|
117
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -9,11 +9,12 @@ import { registerInbox } from './commands/inbox.js';
|
|
|
9
9
|
import { registerReply } from './commands/reply.js';
|
|
10
10
|
import { registerCampaign } from './commands/campaign.js';
|
|
11
11
|
import { registerContact } from './commands/contact.js';
|
|
12
|
+
import { registerSignals } from './commands/signals.js';
|
|
12
13
|
import { registerAutopilot } from './commands/autopilot.js';
|
|
13
14
|
import { registerConfig } from './commands/config.js';
|
|
14
15
|
import { registerCompletion } from './commands/completion.js';
|
|
15
16
|
import { maybeCheckForUpdate } from './update-check.js';
|
|
16
|
-
const VERSION = '0.
|
|
17
|
+
const VERSION = '0.4.0';
|
|
17
18
|
const program = new Command();
|
|
18
19
|
program
|
|
19
20
|
.name('aca')
|
|
@@ -28,6 +29,7 @@ registerInbox(program);
|
|
|
28
29
|
registerReply(program);
|
|
29
30
|
registerCampaign(program);
|
|
30
31
|
registerContact(program);
|
|
32
|
+
registerSignals(program);
|
|
31
33
|
registerAutopilot(program);
|
|
32
34
|
registerConfig(program);
|
|
33
35
|
registerCompletion(program);
|
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
|
|
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
|
|
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
|
|
102
|
+
const refreshed = await refreshJwt(session);
|
|
78
103
|
return refreshed.access_token;
|
|
79
104
|
}
|
|
80
105
|
return session.access_token;
|
package/dist/util.js
CHANGED
|
@@ -15,3 +15,73 @@ export async function readStdinIfPiped() {
|
|
|
15
15
|
}
|
|
16
16
|
return data.trim() || null;
|
|
17
17
|
}
|
|
18
|
+
function parseCsvRows(text) {
|
|
19
|
+
const rows = [];
|
|
20
|
+
let field = '';
|
|
21
|
+
let row = [];
|
|
22
|
+
let inQuotes = false;
|
|
23
|
+
let started = false;
|
|
24
|
+
for (let i = 0; i < text.length; i++) {
|
|
25
|
+
const ch = text[i];
|
|
26
|
+
if (inQuotes) {
|
|
27
|
+
if (ch === '"') {
|
|
28
|
+
if (text[i + 1] === '"') {
|
|
29
|
+
field += '"';
|
|
30
|
+
i++;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
inQuotes = false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
field += ch;
|
|
38
|
+
}
|
|
39
|
+
started = true;
|
|
40
|
+
}
|
|
41
|
+
else if (ch === '"') {
|
|
42
|
+
inQuotes = true;
|
|
43
|
+
started = true;
|
|
44
|
+
}
|
|
45
|
+
else if (ch === ',') {
|
|
46
|
+
row.push(field);
|
|
47
|
+
field = '';
|
|
48
|
+
started = true;
|
|
49
|
+
}
|
|
50
|
+
else if (ch === '\n') {
|
|
51
|
+
row.push(field);
|
|
52
|
+
rows.push(row);
|
|
53
|
+
row = [];
|
|
54
|
+
field = '';
|
|
55
|
+
started = false;
|
|
56
|
+
}
|
|
57
|
+
else if (ch === '\r') {
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
field += ch;
|
|
61
|
+
started = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (started || field !== '' || row.length > 0) {
|
|
65
|
+
row.push(field);
|
|
66
|
+
rows.push(row);
|
|
67
|
+
}
|
|
68
|
+
return rows;
|
|
69
|
+
}
|
|
70
|
+
export function parseCsv(text) {
|
|
71
|
+
const rows = parseCsvRows(text);
|
|
72
|
+
if (rows.length === 0)
|
|
73
|
+
return [];
|
|
74
|
+
const header = rows[0].map((h) => h.trim());
|
|
75
|
+
const out = [];
|
|
76
|
+
for (let i = 1; i < rows.length; i++) {
|
|
77
|
+
const cells = rows[i];
|
|
78
|
+
if (cells.length === 1 && cells[0].trim() === '')
|
|
79
|
+
continue;
|
|
80
|
+
const rec = {};
|
|
81
|
+
header.forEach((h, j) => {
|
|
82
|
+
rec[h] = (cells[j] ?? '').trim();
|
|
83
|
+
});
|
|
84
|
+
out.push(rec);
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seguelac/aca-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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": {
|