latinfo 0.5.8 → 0.6.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.
Files changed (3) hide show
  1. package/README.md +7 -7
  2. package/dist/index.js +39 -9
  3. package/package.json +21 -4
package/README.md CHANGED
@@ -24,7 +24,7 @@ latinfo search "banco de credito" # Search by company name
24
24
  latinfo ruc 20100047218 --json # JSON output (for scripts and AI agents)
25
25
  ```
26
26
 
27
- 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.
28
28
 
29
29
  ## SDK
30
30
 
@@ -78,18 +78,18 @@ Full API reference: [latinfo.dev/docs](https://latinfo.dev/docs)
78
78
  | `ruc` | RUC number (11 digits) | `20100047218` |
79
79
  | `razon_social` | Business name | `BANCO DE CREDITO DEL PERU` |
80
80
  | `estado` | Tax status | `ACTIVO` |
81
- | `condicion` | Condition | `HABIDO` |
82
- | `ubigeo` | Location code | `150114` |
81
+ | `condicion` | Domicile condition | `HABIDO` |
82
+ | `ubigeo` | Location code (6 digits) | `150114` |
83
83
  | `tipo_via` | Street type | `JR.` |
84
84
  | `nombre_via` | Street name | `CENTENARIO` |
85
+ | `codigo_zona` | Zone code | `URB.` |
86
+ | `tipo_zona` | Zone name | `BALCONCILLO` |
85
87
  | `numero` | Street number | `156` |
86
88
  | `interior` | Interior / apt | `-` |
87
89
  | `lote` | Lot | `-` |
88
- | `codigo_zona` | Zone code | `URB.` |
89
- | `tipo_zona` | Zone name | `BALCONCILLO` |
90
- | `departamento` | Department | `-` |
90
+ | `departamento` | Dept (within building) | `-` |
91
91
  | `manzana` | Block | `-` |
92
- | `kilometro` | Kilometer | `-` |
92
+ | `kilometro` | Kilometer marker | `-` |
93
93
 
94
94
  ## What you don't have to do
95
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.8';
13
+ const VERSION = '0.6.0';
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');
@@ -45,8 +45,13 @@ function deleteConfig() {
45
45
  }
46
46
  // --- GitHub Authorization Code Flow ---
47
47
  function openBrowser(url) {
48
- const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';
49
- (0, child_process_1.exec)(`${cmd} "${url}"`);
48
+ if (process.platform === 'win32') {
49
+ (0, child_process_1.exec)(`start "" "${url}"`);
50
+ }
51
+ else {
52
+ const cmd = process.platform === 'darwin' ? 'open' : 'xdg-open';
53
+ (0, child_process_1.exec)(`${cmd} "${url}"`);
54
+ }
50
55
  }
51
56
  async function waitForCallback(port, expectedState) {
52
57
  return new Promise((resolve, reject) => {
@@ -67,6 +72,14 @@ async function waitForCallback(port, expectedState) {
67
72
  reject(new Error('Invalid state or missing code'));
68
73
  }
69
74
  });
75
+ server.on('error', (err) => {
76
+ if (err.code === 'EADDRINUSE' || err.code === 'EACCES') {
77
+ reject(new Error(`Cannot listen on port ${port}. ${err.code === 'EADDRINUSE' ? 'Port already in use.' : 'Permission denied.'} Try: latinfo login --token <github_pat>`));
78
+ }
79
+ else {
80
+ reject(err);
81
+ }
82
+ });
70
83
  server.listen(port, () => { });
71
84
  setTimeout(() => { server.close(); reject(new Error('Timeout waiting for authorization')); }, 120_000);
72
85
  });
@@ -130,6 +143,8 @@ async function login(token) {
130
143
  const state = crypto.randomUUID();
131
144
  const authUrl = `https://github.com/login/oauth/authorize?client_id=${GITHUB_CLIENT_ID}&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${scope}&state=${state}`;
132
145
  console.log('Opening GitHub...');
146
+ console.log('If your browser does not open, visit this URL:\n');
147
+ console.log(authUrl + '\n');
133
148
  openBrowser(authUrl);
134
149
  const code = await waitForCallback(port, state);
135
150
  const authRes = await fetch(`${API_URL}/auth/github`, {
@@ -276,16 +291,31 @@ function whoami() {
276
291
  }
277
292
  console.log(config.github_username);
278
293
  }
279
- function plan() {
294
+ async function plan() {
280
295
  const config = requireAuth();
296
+ const res = await fetch(`${API_URL}/payments/plan`, {
297
+ headers: { Authorization: `Bearer ${config.api_key}` },
298
+ });
299
+ if (!res.ok) {
300
+ const body = await res.json();
301
+ if (jsonFlag)
302
+ return jsonError(body.error, body.message || 'Failed to fetch plan');
303
+ console.error(`Error: ${body.message || body.error}`);
304
+ process.exit(1);
305
+ }
306
+ const data = await res.json();
281
307
  if (jsonFlag) {
282
- console.log(JSON.stringify({ plan: 'free', limit: '1M requests/month' }));
308
+ console.log(JSON.stringify(data));
283
309
  return;
284
310
  }
311
+ const fmt = (n) => n.toLocaleString();
285
312
  console.log(`
286
- User: ${config.github_username}
287
- Plan: free
288
- Limit: 1M requests/month
313
+ User: ${config.github_username}
314
+ Plan: ${data.plan}
315
+ Limit: ${fmt(data.limit)} requests/${data.usage.type === 'daily' ? 'day' : 'month'}
316
+ Used: ${fmt(data.usage.used)}
317
+ Remaining: ${fmt(data.usage.remaining)}
318
+ Period: ${data.usage.period}${data.pro_until ? `\n Pro until: ${data.pro_until}` : ''}
289
319
  `.trim());
290
320
  }
291
321
  function calcCf(requests) {
@@ -469,7 +499,7 @@ else {
469
499
  whoami();
470
500
  break;
471
501
  case 'plan':
472
- plan();
502
+ plan().catch(e => { console.error(e); process.exit(1); });
473
503
  break;
474
504
  case 'costs':
475
505
  (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.8",
3
+ "version": "0.6.0",
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
- "url": "https://github.com/latinfo/latinfo"
8
+ "url": "git+https://github.com/latinfo/latinfo.git"
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",