@kantadev/cli 0.1.5 → 0.1.6

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 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 # paste your API key from app.kanta.dev
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 # prompts for the key (hidden), validates via GET /me
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
@@ -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.5",
3
+ "version": "0.1.6",
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",
5
+ "version": "0.1.6",
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.5",
15
+ "version": "0.1.6",
16
16
  "runtimeHint": "npx",
17
17
  "packageArguments": [
18
18
  {
@@ -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('Validate an API key and save it as a profile')
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(opts.profile, { key, base_url: baseUrl });
57
- if (globalOpts(cmd).json) return printJson({ saved: opts.profile, email: me.email, scope: me.scope });
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 "${opts.profile}" (${me.email}, scope: ${me.scope}) to ${configPath()}\n`,
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 });
@@ -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
- sleep(ms) {
45
- return new Promise((r) => setTimeout(r, ms));
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
+ }