@kantadev/cli 0.1.5 → 0.1.7
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/README.md +5 -4
- package/package.json +1 -1
- package/server.json +2 -2
- package/src/cli/commands/db/companies.js +0 -1
- package/src/cli/commands/login.js +33 -6
- package/src/cli/context.js +4 -2
- package/src/core/browserLogin.js +52 -0
- package/src/core/dbFilter.js +0 -1
- package/src/mcp/tools/database.js +2 -2
package/README.md
CHANGED
|
@@ -13,7 +13,8 @@ Find**, and the **Kanta Database**. Thin wrapper over the `api.kanta.dev` and
|
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
15
|
npm install -g @kantadev/cli
|
|
16
|
-
kanta login #
|
|
16
|
+
kanta login # opens app.kanta.dev in your browser; approve the code shown
|
|
17
|
+
# --no-browser prints the link; --key pastes an API key instead
|
|
17
18
|
```
|
|
18
19
|
|
|
19
20
|
Local/dev:
|
|
@@ -71,7 +72,7 @@ same key: `--db-url` → `KANTA_DB_URL` → profile `db_base_url` →
|
|
|
71
72
|
```
|
|
72
73
|
|
|
73
74
|
```bash
|
|
74
|
-
kanta login --profile personal #
|
|
75
|
+
kanta login --profile personal # browser sign-in, saved as the "personal" profile
|
|
75
76
|
kanta whoami
|
|
76
77
|
kanta config show # resolved config, key masked
|
|
77
78
|
kanta logout --profile personal
|
|
@@ -141,7 +142,7 @@ kanta --profile admin db ca-count # CCPA California-record monitor (admin)
|
|
|
141
142
|
| `--filter-file <path>` | raw JSON filter object, merged under the flags |
|
|
142
143
|
|
|
143
144
|
Company flags: `--query`, `--domain`, `--industry`, `--employee-range`,
|
|
144
|
-
`--hq-country`, `--hq-state`, `--
|
|
145
|
+
`--hq-country`, `--hq-state`, `--employees-min/max`,
|
|
145
146
|
`--revenue-min-k/max-k`, `--founded-after`, `--min-contacts`, `--filter-file`.
|
|
146
147
|
|
|
147
148
|
The `db export` flow prints the match count and credit cost, prompts for
|
|
@@ -176,7 +177,7 @@ Admin capability is **not** self-service. It requires an `api_keys` row with
|
|
|
176
177
|
2. Generate a normal key from `app.kanta.dev` for the operator.
|
|
177
178
|
3. In Supabase Studio → Table Editor → `api_keys`, find that row (match on
|
|
178
179
|
`label` or `last_used_at`) and set `scope` to `admin`. Save.
|
|
179
|
-
4. `kanta login --profile admin` with that key.
|
|
180
|
+
4. `kanta login --profile admin --key` with that key.
|
|
180
181
|
|
|
181
182
|
Revoke by setting `scope` back to `user`. No API path or dashboard UI reads or
|
|
182
183
|
writes `scope`, so a leaked standard key can never reach `/admin/*`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kantadev/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Kanta CLI + MCP server — email verification, email finding, and the Kanta B2B contact database from your terminal or an MCP client.",
|
|
5
5
|
"mcpName": "dev.kanta/cli",
|
|
6
6
|
"type": "module",
|
package/server.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "dev.kanta/cli",
|
|
4
4
|
"description": "Kanta Verify, Find, and Database: email verification, email finding, and B2B contact search.",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.7",
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "https://github.com/griffinkanta/kanta-dev",
|
|
8
8
|
"source": "github",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
{
|
|
13
13
|
"registryType": "npm",
|
|
14
14
|
"identifier": "@kantadev/cli",
|
|
15
|
-
"version": "0.1.
|
|
15
|
+
"version": "0.1.7",
|
|
16
16
|
"runtimeHint": "npx",
|
|
17
17
|
"packageArguments": [
|
|
18
18
|
{
|
|
@@ -12,7 +12,6 @@ function companyFilterOptions(cmd) {
|
|
|
12
12
|
.option('--employee-range <range...>', 'employee range(s)')
|
|
13
13
|
.option('--hq-country <c...>', 'HQ country/countries')
|
|
14
14
|
.option('--hq-state <s...>', 'HQ state(s)')
|
|
15
|
-
.option('--funding-stage <s...>', 'latest funding stage(s)')
|
|
16
15
|
.option('--employees-min <n>', 'minimum employee count')
|
|
17
16
|
.option('--employees-max <n>', 'maximum employee count')
|
|
18
17
|
.option('--revenue-min-k <n>', 'minimum revenue (thousands)')
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createInterface } from 'node:readline';
|
|
2
|
+
import { hostname } from 'node:os';
|
|
2
3
|
import { action, globalOpts, rootProgram, CliExit } from '../context.js';
|
|
3
4
|
import {
|
|
4
5
|
loadConfig,
|
|
@@ -43,20 +44,46 @@ async function readKey() {
|
|
|
43
44
|
export function registerLogin(program) {
|
|
44
45
|
program
|
|
45
46
|
.command('login')
|
|
46
|
-
.description('
|
|
47
|
+
.description('Sign in through your browser (or paste a key with --key) and save it as a profile')
|
|
47
48
|
.option('--profile <name>', 'profile name to save under', 'personal')
|
|
48
49
|
.option('--base-url <url>', 'API base URL', DEFAULT_BASE_URL)
|
|
50
|
+
.option('--key', 'paste an API key instead of signing in through the browser')
|
|
51
|
+
.option('--no-browser', 'print the sign-in link instead of opening a browser')
|
|
49
52
|
.action(
|
|
50
53
|
action(async (opts, cmd) => {
|
|
54
|
+
const deps = rootProgram(cmd)._deps;
|
|
55
|
+
// `--profile` also exists on the root program and is parsed there first.
|
|
56
|
+
const profile = globalOpts(cmd).profile || opts.profile;
|
|
57
|
+
const baseUrl = opts.baseUrl || DEFAULT_BASE_URL;
|
|
58
|
+
const json = globalOpts(cmd).json;
|
|
59
|
+
// Piped input (echo $KEY | kanta login) keeps working as a key login.
|
|
60
|
+
if (!opts.key && deps.stdinIsTTY) {
|
|
61
|
+
const { apiKey, email } = await deps.browserLogin({
|
|
62
|
+
baseUrl,
|
|
63
|
+
clientName: `${hostname()} (kanta CLI)`.slice(0, 64),
|
|
64
|
+
openUrl: opts.browser ? undefined : () => { throw new Error('no browser'); },
|
|
65
|
+
onCode: (s) => {
|
|
66
|
+
if (json) return;
|
|
67
|
+
process.stdout.write(
|
|
68
|
+
`Your code: ${s.user_code}\n` +
|
|
69
|
+
`${opts.browser ? 'Opening' : 'Open'} ${s.verification_uri_complete}\n` +
|
|
70
|
+
'Approve it in the browser; waiting...\n',
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
}).catch((err) => { throw new CliExit(err.message); });
|
|
74
|
+
setProfile(profile, { key: apiKey, base_url: baseUrl });
|
|
75
|
+
if (json) return printJson({ saved: profile, email });
|
|
76
|
+
process.stdout.write(`Signed in as ${email || 'your account'}. Saved profile "${profile}" to ${configPath()}\n`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
51
79
|
const key = await readKey();
|
|
52
80
|
if (!key) throw new CliExit('No key entered.');
|
|
53
|
-
const baseUrl = opts.baseUrl || DEFAULT_BASE_URL;
|
|
54
81
|
const client = new KantaClient({ key, baseUrl });
|
|
55
82
|
const me = await client.getMe();
|
|
56
|
-
setProfile(
|
|
57
|
-
if (globalOpts(cmd).json) return printJson({ saved:
|
|
83
|
+
setProfile(profile, { key, base_url: baseUrl });
|
|
84
|
+
if (globalOpts(cmd).json) return printJson({ saved: profile, email: me.email, scope: me.scope });
|
|
58
85
|
process.stdout.write(
|
|
59
|
-
`Saved profile "${
|
|
86
|
+
`Saved profile "${profile}" (${me.email}, scope: ${me.scope}) to ${configPath()}\n`,
|
|
60
87
|
);
|
|
61
88
|
}),
|
|
62
89
|
);
|
|
@@ -68,7 +95,7 @@ export function registerLogin(program) {
|
|
|
68
95
|
.action(
|
|
69
96
|
action(async (opts, cmd) => {
|
|
70
97
|
const config = loadConfig();
|
|
71
|
-
const name = opts.profile || config.default_profile;
|
|
98
|
+
const name = globalOpts(cmd).profile || opts.profile || config.default_profile;
|
|
72
99
|
if (!name) throw new CliExit('No profile specified and no default set.');
|
|
73
100
|
removeProfile(name);
|
|
74
101
|
if (globalOpts(cmd).json) return printJson({ removed: name });
|
package/src/cli/context.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Shared helpers for CLI commands.
|
|
2
|
+
import { browserLogin as realBrowserLogin } from '../core/browserLogin.js';
|
|
2
3
|
import { resolveColumns } from '../core/bulkInput.js';
|
|
3
4
|
import { readFileSync, existsSync, writeFileSync } from 'node:fs';
|
|
4
5
|
import { createInterface } from 'node:readline';
|
|
@@ -41,9 +42,10 @@ export function defaultDeps() {
|
|
|
41
42
|
whoamiFn(o) {
|
|
42
43
|
return whoami({ profile: o.profile, apiKey: o.apiKey, baseUrl: o.baseUrl });
|
|
43
44
|
},
|
|
44
|
-
|
|
45
|
-
return
|
|
45
|
+
browserLogin(opts) {
|
|
46
|
+
return realBrowserLogin(opts);
|
|
46
47
|
},
|
|
48
|
+
stdinIsTTY: Boolean(process.stdin.isTTY),
|
|
47
49
|
confirm(question) {
|
|
48
50
|
return defaultConfirm(question);
|
|
49
51
|
},
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Browser sign-in (device authorization flow) against the Kanta API:
|
|
2
|
+
// start -> show the code and open the approval page -> poll until the user
|
|
3
|
+
// approves in the web app -> receive a freshly created API key (handed out once).
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
|
|
6
|
+
export function openInBrowser(url) {
|
|
7
|
+
const [cmd, args] = process.platform === 'darwin' ? ['open', [url]]
|
|
8
|
+
: process.platform === 'win32' ? ['cmd', ['/c', 'start', '', url]]
|
|
9
|
+
: ['xdg-open', [url]];
|
|
10
|
+
const child = spawn(cmd, args, { stdio: 'ignore', detached: true });
|
|
11
|
+
child.on('error', () => {});
|
|
12
|
+
child.unref();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const realSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
16
|
+
|
|
17
|
+
async function post(fetchImpl, url, body) {
|
|
18
|
+
const res = await fetchImpl(url, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
21
|
+
body: JSON.stringify(body),
|
|
22
|
+
});
|
|
23
|
+
let data = {};
|
|
24
|
+
try { data = await res.json(); } catch { /* empty body */ }
|
|
25
|
+
return { status: res.status, ok: res.ok, data };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function browserLogin({
|
|
29
|
+
baseUrl, clientName, fetchImpl = globalThis.fetch, openUrl = openInBrowser,
|
|
30
|
+
onCode = () => {}, sleep = realSleep, now = Date.now,
|
|
31
|
+
}) {
|
|
32
|
+
const base = String(baseUrl).replace(/\/+$/, '');
|
|
33
|
+
const start = await post(fetchImpl, `${base}/cli/auth/start`, { client_name: clientName });
|
|
34
|
+
if (!start.ok) throw new Error(`Could not start sign-in (${start.data.error || `HTTP ${start.status}`}).`);
|
|
35
|
+
const s = start.data;
|
|
36
|
+
onCode(s);
|
|
37
|
+
try { openUrl(s.verification_uri_complete); } catch { /* headless: the URL is printed */ }
|
|
38
|
+
|
|
39
|
+
let intervalMs = (s.interval || 3) * 1000;
|
|
40
|
+
const deadline = now() + (s.expires_in || 600) * 1000;
|
|
41
|
+
while (now() < deadline) {
|
|
42
|
+
await sleep(intervalMs);
|
|
43
|
+
const p = await post(fetchImpl, `${base}/cli/auth/poll`, { device_code: s.device_code });
|
|
44
|
+
if (p.status === 429) { intervalMs += 5000; continue; }
|
|
45
|
+
if (!p.ok) throw new Error(`Sign-in failed (${p.data.error || `HTTP ${p.status}`}).`);
|
|
46
|
+
const st = p.data.status;
|
|
47
|
+
if (st === 'approved') return { apiKey: p.data.api_key, email: p.data.email };
|
|
48
|
+
if (st === 'denied') throw new Error('Sign-in was denied in the browser.');
|
|
49
|
+
if (st === 'expired') throw new Error('The sign-in code expired. Run kanta login again.');
|
|
50
|
+
}
|
|
51
|
+
throw new Error('The sign-in code expired. Run kanta login again.');
|
|
52
|
+
}
|
package/src/core/dbFilter.js
CHANGED
|
@@ -26,10 +26,10 @@ const COMPANY_FILTER_SCHEMA = {
|
|
|
26
26
|
additionalProperties: true,
|
|
27
27
|
description:
|
|
28
28
|
'Kanta DB company filter. Keys: query, domain[], industry[], employee_range[], hq_country[], ' +
|
|
29
|
-
'hq_state[],
|
|
29
|
+
'hq_state[], employees_min, employees_max, revenue_min_k, revenue_max_k, ' +
|
|
30
30
|
'founded_after (year), min_contacts. industry takes industry names case-insensitively and includes ' +
|
|
31
31
|
'sub-industries; hq_country / hq_state accept aliases and abbreviations; employee_range takes the ' +
|
|
32
|
-
'size bands 1-10 ... 10001+.
|
|
32
|
+
'size bands 1-10 ... 10001+. domain matches stored values exactly.',
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
const realSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|