latinfo 0.5.7 → 0.5.9

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.
Files changed (3) hide show
  1. package/README.md +13 -9
  2. package/dist/index.js +52 -12
  3. package/package.json +20 -3
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # latinfo
1
+ <p align="center">
2
+ <img src="https://latinfo.dev/logo.svg" alt="latinfo" width="120">
3
+ </p>
2
4
 
3
- Tax registry API for Latin America. Query RUC, DNI, and company data from Peru's SUNAT. 18M+ records, updated daily, sub-100ms from anywhere.
5
+ <h1 align="center">latinfo</h1>
6
+
7
+ <p align="center">Tax registry API for Latin America. Query RUC, DNI, and company data from Peru's SUNAT. 18M+ records, updated daily, sub-100ms from anywhere.</p>
4
8
 
5
9
  ## Install
6
10
 
@@ -20,7 +24,7 @@ latinfo search "banco de credito" # Search by company name
20
24
  latinfo ruc 20100047218 --json # JSON output (for scripts and AI agents)
21
25
  ```
22
26
 
23
- No login needed for demo data (5 embedded records). Run `latinfo login` for 18M+ records.
27
+ No login needed for demo data (~95 embedded records). Run `latinfo login` for 18M+ records.
24
28
 
25
29
  ## SDK
26
30
 
@@ -74,18 +78,18 @@ Full API reference: [latinfo.dev/docs](https://latinfo.dev/docs)
74
78
  | `ruc` | RUC number (11 digits) | `20100047218` |
75
79
  | `razon_social` | Business name | `BANCO DE CREDITO DEL PERU` |
76
80
  | `estado` | Tax status | `ACTIVO` |
77
- | `condicion` | Condition | `HABIDO` |
78
- | `ubigeo` | Location code | `150114` |
81
+ | `condicion` | Domicile condition | `HABIDO` |
82
+ | `ubigeo` | Location code (6 digits) | `150114` |
79
83
  | `tipo_via` | Street type | `JR.` |
80
84
  | `nombre_via` | Street name | `CENTENARIO` |
85
+ | `codigo_zona` | Zone code | `URB.` |
86
+ | `tipo_zona` | Zone name | `BALCONCILLO` |
81
87
  | `numero` | Street number | `156` |
82
88
  | `interior` | Interior / apt | `-` |
83
89
  | `lote` | Lot | `-` |
84
- | `codigo_zona` | Zone code | `URB.` |
85
- | `tipo_zona` | Zone name | `BALCONCILLO` |
86
- | `departamento` | Department | `-` |
90
+ | `departamento` | Dept (within building) | `-` |
87
91
  | `manzana` | Block | `-` |
88
- | `kilometro` | Kilometer | `-` |
92
+ | `kilometro` | Kilometer marker | `-` |
89
93
 
90
94
  ## What you don't have to do
91
95
 
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ const path_1 = __importDefault(require("path"));
10
10
  const os_1 = __importDefault(require("os"));
11
11
  const child_process_1 = require("child_process");
12
12
  const demo_data_1 = require("./demo-data");
13
- const VERSION = '0.5.7';
13
+ const VERSION = '0.5.8';
14
14
  const API_URL = process.env.LATINFO_API_URL || 'https://api.latinfo.dev';
15
15
  const GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID || 'Ov23li5fcQaiCsVtaMKK';
16
16
  const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.latinfo');
@@ -18,7 +18,9 @@ const CONFIG_FILE = path_1.default.join(CONFIG_DIR, 'config.json');
18
18
  // --- JSON mode ---
19
19
  const jsonFlag = process.argv.includes('--json');
20
20
  const liveFlag = process.argv.includes('--live');
21
- const rawArgs = process.argv.slice(2).filter(a => a !== '--json' && a !== '--live');
21
+ const tokenIdx = process.argv.indexOf('--token');
22
+ const tokenFlag = tokenIdx !== -1 ? process.argv[tokenIdx + 1] : undefined;
23
+ const rawArgs = process.argv.slice(2).filter(a => a !== '--json' && a !== '--live' && a !== '--token' && a !== tokenFlag);
22
24
  function jsonError(error, message) {
23
25
  process.stderr.write(JSON.stringify({ error, message }) + '\n');
24
26
  process.exit(1);
@@ -101,7 +103,27 @@ async function apiRequest(config, path) {
101
103
  return res;
102
104
  }
103
105
  // --- Commands ---
104
- async function login() {
106
+ async function login(token) {
107
+ // PAT login: no browser needed
108
+ if (token) {
109
+ const authRes = await fetch(`${API_URL}/auth/github`, {
110
+ method: 'POST',
111
+ headers: { 'Content-Type': 'application/json' },
112
+ body: JSON.stringify({ access_token: token }),
113
+ });
114
+ if (!authRes.ok) {
115
+ const text = await authRes.text();
116
+ if (jsonFlag)
117
+ jsonError('auth_failed', text);
118
+ console.error('Error getting API key:', text);
119
+ process.exit(1);
120
+ }
121
+ const authData = await authRes.json();
122
+ saveConfig({ api_key: authData.api_key, github_username: authData.github_username });
123
+ console.log(`Logged in as ${authData.github_username}`);
124
+ return;
125
+ }
126
+ // OAuth login: opens browser
105
127
  const port = 8400;
106
128
  const redirectUri = `http://localhost:${port}/callback`;
107
129
  const scope = 'read:user,user:email';
@@ -254,16 +276,31 @@ function whoami() {
254
276
  }
255
277
  console.log(config.github_username);
256
278
  }
257
- function plan() {
279
+ async function plan() {
258
280
  const config = requireAuth();
281
+ const res = await fetch(`${API_URL}/payments/plan`, {
282
+ headers: { Authorization: `Bearer ${config.api_key}` },
283
+ });
284
+ if (!res.ok) {
285
+ const body = await res.json();
286
+ if (jsonFlag)
287
+ return jsonError(body.error, body.message || 'Failed to fetch plan');
288
+ console.error(`Error: ${body.message || body.error}`);
289
+ process.exit(1);
290
+ }
291
+ const data = await res.json();
259
292
  if (jsonFlag) {
260
- console.log(JSON.stringify({ plan: 'free', limit: '1M requests/month' }));
293
+ console.log(JSON.stringify(data));
261
294
  return;
262
295
  }
296
+ const fmt = (n) => n.toLocaleString();
263
297
  console.log(`
264
- User: ${config.github_username}
265
- Plan: free
266
- Limit: 1M requests/month
298
+ User: ${config.github_username}
299
+ Plan: ${data.plan}
300
+ Limit: ${fmt(data.limit)} requests/${data.usage.type === 'daily' ? 'day' : 'month'}
301
+ Used: ${fmt(data.usage.used)}
302
+ Remaining: ${fmt(data.usage.remaining)}
303
+ Period: ${data.usage.period}${data.pro_until ? `\n Pro until: ${data.pro_until}` : ''}
267
304
  `.trim());
268
305
  }
269
306
  function calcCf(requests) {
@@ -361,8 +398,11 @@ QUICK START
361
398
 
362
399
  COMMANDS
363
400
  login
364
- GitHub OAuth. Opens browser, waits for callback on localhost:8400,
365
- stores API key in ~/.latinfo/config.json.
401
+ GitHub OAuth. Opens browser, stores API key in ~/.latinfo/config.json.
402
+
403
+ login --token <github_pat>
404
+ Login with a GitHub Personal Access Token. No browser needed.
405
+ Create a PAT at github.com/settings/tokens (scope: read:user).
366
406
 
367
407
  logout
368
408
  Remove stored credentials.
@@ -435,7 +475,7 @@ if (rawArgs.includes('--version') || rawArgs.includes('-v')) {
435
475
  else {
436
476
  switch (command) {
437
477
  case 'login':
438
- login().catch(e => { console.error(e); process.exit(1); });
478
+ login(tokenFlag).catch(e => { console.error(e); process.exit(1); });
439
479
  break;
440
480
  case 'logout':
441
481
  logout();
@@ -444,7 +484,7 @@ else {
444
484
  whoami();
445
485
  break;
446
486
  case 'plan':
447
- plan();
487
+ plan().catch(e => { console.error(e); process.exit(1); });
448
488
  break;
449
489
  case 'costs':
450
490
  (liveFlag ? costsLive() : Promise.resolve(costsSimulate(args[0], args[1], args[2]))).catch(e => { console.error(e); process.exit(1); });
package/package.json CHANGED
@@ -1,13 +1,28 @@
1
1
  {
2
2
  "name": "latinfo",
3
- "version": "0.5.7",
3
+ "version": "0.5.9",
4
4
  "description": "Tax registry API for Latin America. Query RUC, DNI, and company data from SUNAT Peru. 18M+ records, updated daily, sub-100ms from anywhere.",
5
5
  "homepage": "https://latinfo.dev",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/latinfo/latinfo"
9
9
  },
10
- "keywords": ["sunat", "ruc", "dni", "consulta-ruc", "peru", "cli", "sunat-ruc", "taxpayer", "padron", "consulta", "api", "latin-america", "latam", "json"],
10
+ "keywords": [
11
+ "sunat",
12
+ "ruc",
13
+ "dni",
14
+ "consulta-ruc",
15
+ "peru",
16
+ "cli",
17
+ "sunat-ruc",
18
+ "taxpayer",
19
+ "padron",
20
+ "consulta",
21
+ "api",
22
+ "latin-america",
23
+ "latam",
24
+ "json"
25
+ ],
11
26
  "main": "dist/sdk.js",
12
27
  "types": "dist/sdk.d.ts",
13
28
  "bin": {
@@ -24,7 +39,9 @@
24
39
  "dev": "tsx src/index.ts"
25
40
  },
26
41
  "license": "MIT",
27
- "files": ["dist"],
42
+ "files": [
43
+ "dist"
44
+ ],
28
45
  "devDependencies": {
29
46
  "tsx": "^4.19.0",
30
47
  "typescript": "^5.6.0",